Skip to content

Commit

Permalink
update dre l2 cache with warp cache data - using warp instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Tadeuchi committed Jun 12, 2023
1 parent 4f3b662 commit eeef389
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 39 deletions.
26 changes: 0 additions & 26 deletions src/db/nodeDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const logger = require('../logger')('node-db');

let eventsDb = null;
let stateDb = null;
let warpStateDb = null;

module.exports = {
createNodeDbEventsTables: async (knex) => {
Expand Down Expand Up @@ -91,19 +90,6 @@ module.exports = {
return stateDb;
},

connectWarpCacheDb: () => {
if (warpStateDb == null) {
warpStateDb = knex({
client: 'better-sqlite3',
connection: {
filename: `cache/warp/sqlite/state.db`
},
useNullAsDefault: true
});
}
return warpStateDb;
},

connectEvents: () => {
if (eventsDb == null) {
eventsDb = knex({
Expand Down Expand Up @@ -221,18 +207,6 @@ module.exports = {
await eventsDb.raw('DELETE FROM events WHERE contract_tx_id = ?;', [contractTxId]);
},

getLastStateFromWarpCache: async (nodeDb, contractTxId) => {
const result = await warpStateDb.raw(
`select sort_key AS sortKey, value AS cachedValue
from sort_key_cache
where key = ?
ORDER BY sort_key DESC
LIMIT 1;`,
[contractTxId]
);
return result.length === 0 ? null : result[0];
},

getLastStateFromDreCache: async (nodeDb, contractTxId) => {
const result = await nodeDb('states')
.where({
Expand Down
4 changes: 1 addition & 3 deletions src/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ const {
hasContract,
connectEvents,
createNodeDbEventsTables,
doBlacklist,
connectWarpCacheDb
doBlacklist
} = require('./db/nodeDb');

const logger = require('./logger')('listener');
Expand Down Expand Up @@ -49,7 +48,6 @@ async function runListener() {

const nodeDb = connect();
const nodeDbEvents = connectEvents();
const nodeWarpState = connectWarpCacheDb();

await createNodeDbTables(nodeDb);
await createNodeDbEventsTables(nodeDbEvents);
Expand Down
13 changes: 3 additions & 10 deletions src/routes/contract.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
const { JSONPath } = require('jsonpath-plus');
const {
getLastStateFromDreCache,
getContractErrors,
getFailures,
events,
getLastStateFromWarpCache,
insertState
} = require('../db/nodeDb');
const { getLastStateFromDreCache, getContractErrors, getFailures, events, insertState } = require('../db/nodeDb');
const { config } = require('../config');
const warp = require('../warp');

const registrationStatus = {
'not-registered': 'not-registered',
Expand Down Expand Up @@ -36,11 +30,10 @@ module.exports = async (ctx) => {
response.status = registrationStatus['blacklisted'];
response.errors = await getContractErrors(nodeDb, contractId);
} else {
const warpState = await getLastStateFromWarpCache(nodeDb, contractId);
const warpState = await warp.stateEvaluator.latestAvailableState(contractId);
let result = await getLastStateFromDreCache(nodeDb, contractId);
let parsed = false;
if (warpState && (!result || result.sort_key.localeCompare(warpState.sortKey) < 0)) {
warpState.cachedValue = JSON.parse(warpState.cachedValue);
result = await insertState(nodeDb, contractId, warpState);
parsed = true;
}
Expand Down

0 comments on commit eeef389

Please sign in to comment.