Skip to content

Commit

Permalink
wdb: Add timeCache to the interactive rescan callback.
Browse files Browse the repository at this point in the history
test: fix NodeContext usage and update tests.
  • Loading branch information
nodech committed Aug 29, 2024
1 parent de79842 commit 6aeceed
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 11 deletions.
2 changes: 0 additions & 2 deletions lib/wallet/txdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ class TXDB {
this.db = wdb.db;
this.logger = wdb.logger;
this.nowFn = wdb.options.nowFn || util.now;

this.maxTXs = wdb.options.maxHistoryTXs || 100;
this.nowFn = util.now;

this.wid = wid || 0;
this.bucket = null;
Expand Down
6 changes: 5 additions & 1 deletion lib/wallet/walletdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,13 @@ class WalletDB extends EventEmitter {

this.client.hook('block rescan interactive', async (entry, txs) => {
try {
return await this.rescanBlockInteractive(entry, txs);
this.timeCache.start();
const result = await this.rescanBlockInteractive(entry, txs);
this.timeCache.commit();
return result;
} catch (e) {
this.emit('error', e);
this.timeCache.drop();
return {
type: scanActions.ABORT
};
Expand Down
8 changes: 6 additions & 2 deletions test/node-http-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,8 @@ describe('Node HTTP', function() {
wallet: true
});

nodeCtx.init();

const {nclient} = nodeCtx;

before(async () => {
Expand Down Expand Up @@ -532,6 +534,8 @@ describe('Node HTTP', function() {
wallet: true
});

nodeCtx.init();

const {nclient, network} = nodeCtx;
const genesisBlock = Block.decode(network.genesisBlock);
let minedHashes;
Expand Down Expand Up @@ -705,7 +709,7 @@ async function mineBlocks(nodeCtx, count, address) {
count
);

const hashes = await nodeCtx.mineBlocks(count, address);
const blocks = await nodeCtx.mineBlocks(count, address);
await blockEvents;
return hashes;
return blocks.map(block => block.hash().toString('hex'));
}
5 changes: 5 additions & 0 deletions test/util/node-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,15 @@ class NodeContext {
if (!tip)
tip = this.chain.tip;

const blocks = [];

for (let i = 0; i < count; i++) {
const block = await this.miner.mineBlock(tip, address);
tip = await this.chain.add(block);
blocks.push(block);
}

return blocks;
}
}

Expand Down
3 changes: 2 additions & 1 deletion test/util/pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ exports.generateInitialBlocks = async (options) => {
await nodeCtx.nclient.execute('setmocktime', [blocktime]);

const blocks = await nodeCtx.mineBlocks(1, coinbase);
const block = await nodeCtx.nclient.execute('getblock', [blocks[0]]);
const firstHash = blocks[0].hash().toString('hex');
const block = await nodeCtx.nclient.execute('getblock', [firstHash]);

assert(block.time <= blocktime + 1);
assert(block.time >= blocktime);
Expand Down
2 changes: 0 additions & 2 deletions test/wallet-http-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1189,8 +1189,6 @@ describe('Wallet HTTP', function() {
if (key.startsWith(wid1 + '42'))
dumpSlice[key] = dump[key];
});

console.log(dumpSlice);
});

it('should get auction info', async () => {
Expand Down
3 changes: 2 additions & 1 deletion test/wallet-pagination-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ describe('WalletDB Pagination', function() {

const mtx = await dummyTX(wallet);
const wids = await wdb.addTX(mtx.toTX());
assert.strictEqual(wids.size, 1);
assert(wids);
assert.strictEqual(wids.wids.size, 1);

const txCount = await wallet.txdb.getCountForTX(mtx.hash());
assert.strictEqual(txCount.index, initUCount.index);
Expand Down
2 changes: 2 additions & 0 deletions test/wallet-rpc-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ describe('Wallet RPC Methods', function() {
wallet: true
});

nodeCtx.init();

wclient = nodeCtx.wclient;
nclient = nodeCtx.nclient;
wdb = nodeCtx.wdb;
Expand Down
5 changes: 3 additions & 2 deletions test/wallet-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2061,14 +2061,15 @@ describe('Wallet', function() {
});

it('should pass nowFn to the txdb', async () => {
const nowFn = () => 1;
const NOW = 1;
const nowFn = () => NOW;
const wallet = new Wallet({
options: {
nowFn
}
});

assert.strictEqual(wallet.txdb.nowFn(), nowFn());
assert.strictEqual(wallet.txdb.nowFn(), NOW);
});

it('should cleanup', async () => {
Expand Down

0 comments on commit 6aeceed

Please sign in to comment.