Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wallet TX count and time indexing #605

Closed
wants to merge 70 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
680e20a
test: add utility for test fs cleanup
braydonf Sep 10, 2018
5746ee5
test: add utility to sleep for desired ms
braydonf Sep 10, 2018
248c3d4
wallet: add test cases for wallet tx count and time indexing
braydonf Sep 11, 2018
41a371f
wallet: add db layout for tx count and monotonic time
braydonf Sep 11, 2018
a53f966
wallet: implement monotonic time
braydonf Sep 11, 2018
fe9f3f3
wallet: add tx count index for confirmed txs
braydonf Sep 11, 2018
b5a9074
wallet: add rpc methods for tx count and monotonic time
braydonf Sep 11, 2018
4f96017
test: restore count to generateBlocks regtest util
braydonf Sep 12, 2018
c931791
docs: after is exclusive
braydonf Sep 12, 2018
c289780
wallet: monotonic time indexing
braydonf Sep 13, 2018
56ef021
test: add reorg to wallet time test
braydonf Sep 21, 2018
bbaa222
test: monotonic time reorg, incomplete
braydonf Oct 17, 2018
9b2c585
wallet: rollback monotonic time
braydonf Oct 23, 2018
0f99886
wallet: add spv monotonic time reorg
braydonf Oct 23, 2018
54ff89a
wallet: reorg tx monotonic time and count indexes
braydonf Oct 25, 2018
99a396e
wallet: refactor monotonic index method
braydonf Oct 27, 2018
2c5ddb0
wallet: options for list history methods
braydonf Oct 27, 2018
1def771
wallet: add indexing for unconfirmed count and time
braydonf Nov 6, 2018
f9cc58d
wallet: add methods to query for unconfirmed txs
braydonf Nov 8, 2018
ea7c27c
test: confirm and unconfirm txs
braydonf Nov 12, 2018
9adf54c
wallet: combine `getPending` and `listUnconfirmed`
braydonf Nov 12, 2018
69e2f1b
wallet: http endpoints for history and unconfirmed txs
braydonf Nov 20, 2018
d4afc1d
wallet: test spv node http endpoints and w/ fixes
braydonf Nov 21, 2018
dafad8d
test: remove `.skip` function call, it's not implemented in bmocha
braydonf Dec 5, 2018
9dc1673
test: wallet rescan test
braydonf Dec 18, 2018
e8c6410
wallet: use height + index for count index
braydonf Dec 19, 2018
30d79d4
test: remove spv from wallet rescan test
braydonf Dec 19, 2018
d8ff085
test: assertions for wallet rescan test
braydonf Dec 19, 2018
a0e5729
wallet: use median time past for time indexing
braydonf Dec 20, 2018
d9f4601
wallet: linting
braydonf Dec 20, 2018
857d07c
wallet: use brhash for http after param
braydonf Dec 20, 2018
7b41f51
test: fix spv test when cpu is loaded
braydonf Dec 20, 2018
6d1748c
wallet: minor cleanup
braydonf Dec 20, 2018
bd29e9f
wallet: cleanup indexes
braydonf Dec 20, 2018
00c652a
wallet: make configurable max transactions limits
braydonf Dec 20, 2018
4108b58
wallet: minor cleanup
braydonf Dec 20, 2018
43199ec
wallet: fix configurable txs limits
braydonf Dec 20, 2018
f66c89d
test: bump wallet http before hook time
braydonf Dec 20, 2018
be59b32
wallet: fix http time tx queries
braydonf Dec 21, 2018
ce7ca8b
wallet: minor linting
braydonf Dec 21, 2018
a803c98
wallet: check rpc min args length
braydonf Dec 21, 2018
49cc51b
test: minor linting
braydonf Dec 21, 2018
5b51439
wallet: fix sorting of time indexing
braydonf Dec 21, 2018
abe2353
wallet: use brhash instead of manually reversing
braydonf Dec 21, 2018
3f41dae
docs: minor linting
braydonf Dec 21, 2018
2fe41f2
wallet: fix sorting of confirmed time index
braydonf Dec 21, 2018
f386a39
wallet: refactor date handling for api
braydonf Dec 21, 2018
0974f72
test: refactor utils
braydonf Dec 21, 2018
8de45e5
wallet: minor cleanup and adjustments
braydonf Dec 21, 2018
cda883a
wallet: minor cleanup and update
braydonf Dec 21, 2018
561b1ae
wallet: update rpc methods with new history functions
braydonf Dec 22, 2018
3fd5216
wallet: use unix epoch time in seconds for rpc history cmds
braydonf Dec 23, 2018
fb46596
test: increase lookahead for test wallet
braydonf Dec 23, 2018
794b417
test: refactor initial blocks
braydonf Dec 25, 2018
1dda1a8
wallet client: add getMedianTime
pinheadmz Jan 8, 2019
cfb8359
wallet: list confirmed and unconfirmed history
braydonf Jan 30, 2019
f0cbe7f
test: update for segwit activation on regtest
braydonf Feb 12, 2019
10ee54f
changelog: update for transaction history api changes
braydonf Feb 12, 2019
7d3c403
wallet: check if options available
braydonf Mar 1, 2019
02b3141
test: listtransactions is deprecated
braydonf Mar 21, 2019
4c559f1
changelog: add note about max-txs
braydonf Mar 26, 2019
b14237d
wallet: minor, refactor and comments
braydonf Mar 26, 2019
62b26fd
test: use `testdir` for prefixes
braydonf May 15, 2019
6833408
test: updates wallet tests to use `forValue`
braydonf May 16, 2019
6024507
test: updates for nyc and ci
braydonf Jun 5, 2019
f339e8c
node: restore error logger argument
braydonf Jun 5, 2019
f75a157
wallet: remove http history date argument
braydonf Jun 5, 2019
1d8c94b
wallet: remove deprecated methods
braydonf Jun 5, 2019
069e3d6
test: minor, cleanup todos
braydonf Jun 5, 2019
7d8ddf8
test: use bsert instead of assert util
braydonf Jun 27, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: monotonic time reorg, incomplete
  • Loading branch information
braydonf committed Jun 27, 2019
commit bbaa222e1fe234a03b3aef309c6a562f223bb775
2 changes: 0 additions & 2 deletions lib/wallet/walletdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -2110,8 +2110,6 @@ class WalletDB extends EventEmitter {
async _removeBlock(entry) {
const tip = BlockMeta.fromEntry(entry);

// TODO remove monotonic block times or mark as unconfirmed

if (tip.height === 0)
throw new Error('WDB: Bad disconnection (genesis block).');

Expand Down
40 changes: 35 additions & 5 deletions test/util/regtest.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,52 @@ async function generateBlocks(count, nclient, coinbase) {
}

async function generateReorg(depth, nclient, wclient, coinbase) {
let hashes = [];
const blockInterval = 600;

let invalidated = [];
let lastTime = null;

// Invalidate blocks to the depth.
for (let i = 0; i < depth; i++) {
const hash = await nclient.execute('getbestblockhash');
hashes.push(hash);
invalidated.push(hash);

// Get the time for the block before it's removed.
const lastBlock = await nclient.execute('getblock', [hash]);
lastTime = lastBlock.time;

await nclient.execute('invalidateblock', [hash]);
}

// Increase time so that blocks do not have
// the same time stamp as before.
lastTime += 10000;

// Create a new transaction so that the transactions
// order is different after the reorg.
const addr = await wclient.execute('getnewaddress', ['blue']);
const txid = await wclient.execute('sendtoaddress', [addr, 0.11111111]);

const blocks = await generateBlocks(depth, nclient, coinbase);
let validated = [];

// Add new blocks back to the same height plus one
// so that it becomes the chain with the most work.
for (let c = 0; c < depth + 1; c++) {
let blocktime = lastTime + c * blockInterval;
await nclient.execute('setmocktime', [blocktime]);

const blockhashes = await generateBlocks(1, nclient, coinbase);
const block = await nclient.execute('getblock', [blockhashes[0]]);

validated.push(block.hash);

assert(block.time <= blocktime + 1);
assert(block.time >= blocktime);
}

return {
invalidated: hashes,
validated: blocks
invalidated,
validated
}
}

Expand Down
31 changes: 25 additions & 6 deletions test/wallet-time-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ async function testMonotonicTime(wclient) {
assert(monotonic, 'Expected to be monotonic');
}

async function testReorg(wclient, previous, depth) {
const current = await wclient.execute('getblocksbytime', [genesisTime, 1000]);
assert.strictEqual(current.length, previous.length + 1);

const l = current.length;

for (let i = 1; i < depth + 1; i++) {
assert.notStrictEqual(previous[l - i].block, current[l - i].block);
}
}

describe('Wallet Monotonic Time', function() {
this.timeout(10000);

Expand All @@ -64,8 +75,8 @@ describe('Wallet Monotonic Time', function() {
await rimraf(testPrefix);
await rimraf(spvTestPrefix);

node = await initFullNode({ports, prefix: testPrefix});
spvnode = await initSPVNode({ports, prefix: spvTestPrefix});
node = await initFullNode({ports, prefix: testPrefix, logLevel: 'none'});
spvnode = await initSPVNode({ports, prefix: spvTestPrefix, logLevel: 'none'});

nclient = await initNodeClient({ports: ports.full});
wclient = await initWalletClient({ports: ports.full});
Expand Down Expand Up @@ -106,18 +117,26 @@ describe('Wallet Monotonic Time', function() {
await testMonotonicTime(spvwclient);
});

describe('chain reorganizations', function() {
describe.skip('chain reorganizations', function() {
const depth = 3;
let previous = null;

before(async () => {
const result = await generateReorg(1, nclient, wclient, coinbase);
previous = await wclient.execute('getblocksbytime', [genesisTime, 1000]);

const result = await generateReorg(depth, nclient, wclient, coinbase);
assert.notStrictEqual(result.invalidated[0], result.validated[0]);

// TODO remove this
await sleep(5000);
});

it('should reorganize monotonic time for a full node', async() => {
// TODO
await testReorg(wclient, previous, depth);
});

it('should reorganize monotonic time for a spv node', async() => {
// TODO
await testReorg(spvwclient, previous, depth);
});
});
});