diff --git a/lib/mempool/mempool.js b/lib/mempool/mempool.js index 53171fa0a..afcd75745 100644 --- a/lib/mempool/mempool.js +++ b/lib/mempool/mempool.js @@ -10,7 +10,7 @@ const assert = require('bsert'); const path = require('path'); const EventEmitter = require('events'); const bdb = require('bdb'); -const {RollingFilter} = require('bfilter'); +const {RollingFilter} = require('@handshake-org/bfilter'); const Heap = require('bheep'); const {BufferMap, BufferSet} = require('buffer-map'); const random = require('bcrypto/lib/random'); diff --git a/lib/net/packets.js b/lib/net/packets.js index cb3f321f2..5151c3471 100644 --- a/lib/net/packets.js +++ b/lib/net/packets.js @@ -14,7 +14,7 @@ const assert = require('bsert'); const bio = require('bufio'); const blake2b = require('bcrypto/lib/blake2b'); const UrkelProof = require('urkel').Proof; -const {BloomFilter} = require('bfilter'); +const {BloomFilter} = require('@handshake-org/bfilter'); const common = require('./common'); const util = require('../utils/util'); const bip152 = require('./bip152'); diff --git a/lib/net/peer.js b/lib/net/peer.js index 04644c1c3..65ffcafd7 100644 --- a/lib/net/peer.js +++ b/lib/net/peer.js @@ -13,7 +13,7 @@ const {format} = require('util'); const tcp = require('btcp'); const dns = require('bdns'); const Logger = require('blgr'); -const {RollingFilter} = require('bfilter'); +const {RollingFilter} = require('@handshake-org/bfilter'); const {BufferMap} = require('buffer-map'); const Parser = require('./parser'); const Framer = require('./framer'); diff --git a/lib/net/pool.js b/lib/net/pool.js index d12d6f42c..a0b72cfd5 100644 --- a/lib/net/pool.js +++ b/lib/net/pool.js @@ -17,7 +17,7 @@ const List = require('blst'); const base32 = require('bcrypto/lib/encoding/base32'); const {BufferMap, BufferSet} = require('buffer-map'); const blake2b = require('bcrypto/lib/blake2b'); -const {BloomFilter, RollingFilter} = require('bfilter'); +const {BloomFilter, RollingFilter} = require('@handshake-org/bfilter'); const rng = require('bcrypto/lib/random'); const secp256k1 = require('bcrypto/lib/secp256k1'); const {siphash} = require('bcrypto/lib/siphash'); diff --git a/lib/node/http.js b/lib/node/http.js index 78377c3b1..f54c49483 100644 --- a/lib/node/http.js +++ b/lib/node/http.js @@ -11,7 +11,7 @@ const path = require('path'); const {Server} = require('bweb'); const Validator = require('bval'); const base58 = require('bcrypto/lib/encoding/base58'); -const {BloomFilter} = require('bfilter'); +const {BloomFilter} = require('@handshake-org/bfilter'); const sha256 = require('bcrypto/lib/sha256'); const random = require('bcrypto/lib/random'); const {safeEqual} = require('bcrypto/lib/safe'); diff --git a/lib/wallet/walletdb.js b/lib/wallet/walletdb.js index 4c28d12ac..8f809d6bd 100644 --- a/lib/wallet/walletdb.js +++ b/lib/wallet/walletdb.js @@ -10,7 +10,7 @@ const assert = require('bsert'); const path = require('path'); const EventEmitter = require('events'); const bio = require('bufio'); -const {BloomFilter} = require('bfilter'); +const {BloomFilter} = require('@handshake-org/bfilter'); const {Lock, MapLock} = require('bmutex'); const bdb = require('bdb'); const Logger = require('blgr'); @@ -124,6 +124,7 @@ class WalletDB extends EventEmitter { this.client.on('connect', async () => { try { await this.syncNode(); + this.emit('sync done', this.state); } catch (e) { this.emit('error', e); } diff --git a/package-lock.json b/package-lock.json index 5493a5e4d..ac938796b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,14 +9,14 @@ "version": "6.99.0", "license": "MIT", "dependencies": { + "@handshake-org/bfilter": "~2.3.0", "bcfg": "~0.2.1", "bcrypto": "~5.4.0", "bcurl": "^0.2.0", - "bdb": "~1.4.0", + "bdb": "~1.5.1", "bdns": "~0.1.5", "bevent": "~0.1.5", "bfile": "~0.2.3", - "bfilter": "~1.0.5", "bheep": "~0.1.5", "binet": "~0.3.7", "blgr": "~0.2.0", @@ -55,6 +55,19 @@ "node": ">=14.0.0" } }, + "node_modules/@handshake-org/bfilter": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/@handshake-org/bfilter/-/bfilter-2.3.0.tgz", + "integrity": "sha512-vTKTVJvLHz2knpdnYMT0idb6R+HlOCbYKlw2L9Bk9oKOAXwjOIFUp6hnZKIVb87rYW8eEfUROrFG3+DcYwxm7w==", + "dependencies": { + "bcrypto": "~5.4.0", + "bsert": "~0.0.12", + "bufio": "~1.2.1" + }, + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/bcfg": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/bcfg/-/bcfg-0.2.1.tgz", @@ -101,16 +114,16 @@ } }, "node_modules/bdb": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/bdb/-/bdb-1.4.0.tgz", - "integrity": "sha512-NjsvznNQSW419u/VlitEioAglJd44n6MrOI+6Rf9JqlyF6DQytBh8bwCT3axUw095aUlGtvoscJG3C56pIPQ7Q==", + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/bdb/-/bdb-1.5.1.tgz", + "integrity": "sha512-VtXSTtV8fz64Fm1uF84UT461WlmDC3RwKsVamLm/5gSbA2HT4oDz/CGCPMExv9qpcRGd59OkLig61gDfEG+gyA==", "hasInstallScript": true, "dependencies": { - "bsert": "~0.0.10", + "bsert": "~0.0.12", "loady": "~0.0.5" }, "engines": { - "node": ">=8.6.0" + "node": ">=12.0.0" } }, "node_modules/bdns": { @@ -143,27 +156,6 @@ "node": ">=8.0.0" } }, - "node_modules/bfilter": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/bfilter/-/bfilter-1.0.5.tgz", - "integrity": "sha512-GupIidtCvLbKhXnA1sxvrwa+gh95qbjafy7P1U1x/2DHxNabXq4nGW0x3rmgzlJMYlVl+c8fMxoMRIwpKYlgcQ==", - "dependencies": { - "bsert": "~0.0.10", - "bufio": "~1.0.6", - "mrmr": "~0.1.6" - }, - "engines": { - "node": ">=8.0.0" - } - }, - "node_modules/bfilter/node_modules/bufio": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/bufio/-/bufio-1.0.7.tgz", - "integrity": "sha512-bd1dDQhiC+bEbEfg56IdBv7faWa6OipMs/AFFFvtFnB3wAYjlwQpQRZ0pm6ZkgtfL0pILRXhKxOiQj6UzoMR7A==", - "engines": { - "node": ">=8.0.0" - } - }, "node_modules/bheep": { "version": "0.1.5", "resolved": "https://registry.npmjs.org/bheep/-/bheep-0.1.5.tgz", @@ -365,11 +357,11 @@ } }, "node_modules/bufio": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/bufio/-/bufio-1.2.0.tgz", - "integrity": "sha512-UlFk8z/PwdhYQTXSQQagwGAdtRI83gib2n4uy4rQnenxUM2yQi8lBDzF230BNk+3wAoZDxYRoBwVVUPgHa9MCA==", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/bufio/-/bufio-1.2.1.tgz", + "integrity": "sha512-9oR3zNdupcg/Ge2sSHQF3GX+kmvL/fTPvD0nd5AGLq8SjUYnTz+SlFjK/GXidndbZtIj+pVKXiWeR9w6e9wKCA==", "engines": { - "node": ">=8.0.0" + "node": ">=14.0.0" } }, "node_modules/bupnp": { @@ -433,19 +425,6 @@ "node": ">=8.0.0" } }, - "node_modules/mrmr": { - "version": "0.1.10", - "resolved": "https://registry.npmjs.org/mrmr/-/mrmr-0.1.10.tgz", - "integrity": "sha512-NJRJs+yJyRWwcTqLRf7O32n56UP1+UQoTrGVEoB3LMj0h2jlon790drDbxKvi5mK5k4HfC0cpNkxqHcrJK/evg==", - "hasInstallScript": true, - "dependencies": { - "bsert": "~0.0.10", - "loady": "~0.0.5" - }, - "engines": { - "node": ">=8.0.0" - } - }, "node_modules/n64": { "version": "0.2.10", "resolved": "https://registry.npmjs.org/n64/-/n64-0.2.10.tgz", diff --git a/package.json b/package.json index adc20a891..0d4e0de30 100644 --- a/package.json +++ b/package.json @@ -23,11 +23,11 @@ "bcfg": "~0.2.1", "bcrypto": "~5.4.0", "bcurl": "^0.2.0", - "bdb": "~1.4.0", + "bdb": "~1.5.1", "bdns": "~0.1.5", "bevent": "~0.1.5", "bfile": "~0.2.3", - "bfilter": "~1.0.5", + "@handshake-org/bfilter": "~2.3.0", "bheep": "~0.1.5", "binet": "~0.3.7", "blgr": "~0.2.0", diff --git a/test/chain-blockstore-test.js b/test/chain-blockstore-test.js index 4cd0960d6..67ae85a76 100644 --- a/test/chain-blockstore-test.js +++ b/test/chain-blockstore-test.js @@ -1,7 +1,7 @@ 'use strict'; const assert = require('bsert'); -const {BloomFilter} = require('bfilter'); +const {BloomFilter} = require('@handshake-org/bfilter'); const Network = require('../lib/protocol/network'); const {FileBlockStore, LevelBlockStore} = require('../lib/blockstore'); const Chain = require('../lib/blockchain/chain'); diff --git a/test/net-test.js b/test/net-test.js index af74a9104..e3c8a60fd 100644 --- a/test/net-test.js +++ b/test/net-test.js @@ -3,7 +3,7 @@ const assert = require('bsert'); const {resolve} = require('path'); const fs = require('fs'); -const {BloomFilter} = require('bfilter'); +const {BloomFilter} = require('@handshake-org/bfilter'); const {nonce} = require('../lib/net/common'); const consensus = require('../lib/protocol/consensus'); const Parser = require('../lib/net/parser'); diff --git a/test/util/memwallet.js b/test/util/memwallet.js index ff05f72f1..7c37ee210 100644 --- a/test/util/memwallet.js +++ b/test/util/memwallet.js @@ -14,7 +14,7 @@ const rules = require('../../lib/covenants/rules'); const Network = require('../../lib/protocol/network'); const MTX = require('../../lib/primitives/mtx'); const HD = require('../../lib/hd/hd'); -const {BloomFilter} = require('bfilter'); +const {BloomFilter} = require('@handshake-org/bfilter'); const KeyRing = require('../../lib/primitives/keyring'); const Outpoint = require('../../lib/primitives/outpoint'); const CoinView = require('../../lib/coins/coinview'); diff --git a/test/wallet-migration-test.js b/test/wallet-migration-test.js index e4f9f9b1a..c5be2e605 100644 --- a/test/wallet-migration-test.js +++ b/test/wallet-migration-test.js @@ -14,7 +14,7 @@ const { oldLayout } = require('../lib/migrations/migrator'); const {migrationError} = require('./util/migrations'); -const {rimraf, testdir} = require('./util/common'); +const {forEvent, rimraf, testdir} = require('./util/common'); const NETWORK = 'regtest'; const network = Network.get(NETWORK); @@ -77,7 +77,7 @@ describe('Wallet Migrations', function() { return ids; }; - let walletDB, ldb; + let walletDB, ldb, wdbOpenSync; beforeEach(async () => { await fs.mkdirp(location); @@ -85,7 +85,10 @@ describe('Wallet Migrations', function() { ldb = walletDB.db; WalletMigrator.migrations = mockMigrations; - await walletDB.open(); + + wdbOpenSync = wdbOpenSyncFn(walletDB); + + await wdbOpenSync(); }); afterEach(async () => { @@ -173,7 +176,7 @@ describe('Wallet Migrations', function() { walletDB.options.walletMigrate = lastMigrationID; walletDB.version = 1; - await walletDB.open(); + await wdbOpenSync(); const versionData = await ldb.get(layout.V.encode()); const version = getVersion(versionData, 'wallet'); @@ -236,7 +239,7 @@ describe('Wallet Migrations', function() { network: network }; - let walletDB, ldb; + let walletDB, ldb, wdbOpenSync; beforeEach(async () => { await fs.mkdirp(location); @@ -245,6 +248,8 @@ describe('Wallet Migrations', function() { ldb = walletDB.db; WalletMigrator.migrations = testMigrations; + + wdbOpenSync = wdbOpenSyncFn(walletDB); }); afterEach(async () => { @@ -258,7 +263,7 @@ describe('Wallet Migrations', function() { }); it('should initialize fresh walletdb migration state', async () => { - await walletDB.open(); + await wdbOpenSync(); const rawState = await ldb.get(layout.M.encode()); const state = MigrationState.decode(rawState); @@ -271,7 +276,8 @@ describe('Wallet Migrations', function() { }); it('should not migrate pre-old migration state w/o flag', async () => { - await walletDB.open(); + await wdbOpenSync(); + const b = ldb.batch(); b.del(layout.M.encode()); await b.write(); @@ -297,7 +303,8 @@ describe('Wallet Migrations', function() { }); it('should migrate pre-old migration state with flag', async () => { - await walletDB.open(); + await wdbOpenSync(); + const b = ldb.batch(); b.del(layout.M.encode()); writeVersion(b, 'wallet', 0); @@ -305,7 +312,7 @@ describe('Wallet Migrations', function() { await walletDB.close(); walletDB.options.walletMigrate = 1; - await walletDB.open(); + await wdbOpenSync(); const versionData = await ldb.get(layout.V.encode()); const version = getVersion(versionData, 'wallet'); @@ -322,7 +329,7 @@ describe('Wallet Migrations', function() { }); it('should not migrate from last old migration state w/o flag', async () => { - await walletDB.open(); + await wdbOpenSync(); const b = ldb.batch(); b.del(layout.M.encode()); @@ -351,7 +358,7 @@ describe('Wallet Migrations', function() { }); it('should not migrate from last old migration state with flag', async () => { - await walletDB.open(); + await wdbOpenSync(); const b = ldb.batch(); b.del(layout.M.encode()); @@ -360,7 +367,7 @@ describe('Wallet Migrations', function() { await walletDB.close(); walletDB.options.walletMigrate = 1; - await walletDB.open(); + await wdbOpenSync(); const rawState = await ldb.get(layout.M.encode()); const state = MigrationState.decode(rawState); @@ -386,7 +393,7 @@ describe('Wallet Migrations', function() { } }; - await walletDB.open(); + await wdbOpenSync(); const b = ldb.batch(); b.del(layout.M.encode()); @@ -438,7 +445,7 @@ describe('Wallet Migrations', function() { } }; - await walletDB.open(); + await wdbOpenSync(); const b = ldb.batch(); b.del(layout.M.encode()); @@ -448,7 +455,7 @@ describe('Wallet Migrations', function() { await walletDB.close(); walletDB.options.walletMigrate = 2; - await walletDB.open(); + await wdbOpenSync(); assert.strictEqual(migrated1, false); assert.strictEqual(migrated2, true); @@ -480,7 +487,7 @@ describe('Wallet Migrations', function() { const ADD_CHANGE_DEPTH = 10; - let walletDB, ldb; + let walletDB, ldb, wdbOpenSync; const missingAddrs = []; before(async () => { WalletMigrator.migrations = {}; @@ -495,6 +502,7 @@ describe('Wallet Migrations', function() { beforeEach(async () => { walletDB = new WalletDB(walletOptions); ldb = walletDB.db; + wdbOpenSync = wdbOpenSyncFn(walletDB); }); afterEach(async () => { @@ -503,7 +511,7 @@ describe('Wallet Migrations', function() { }); it('should set incorrect walletdb state', async () => { - await walletDB.open(); + await wdbOpenSync(); const wallet = walletDB.primary; const account = await wallet.getAccount(0); @@ -522,7 +530,7 @@ describe('Wallet Migrations', function() { }); it('should have missing addresses', async () => { - await walletDB.open(); + await wdbOpenSync(); const wallet = walletDB.primary; for (const addr of missingAddrs) { @@ -560,7 +568,7 @@ describe('Wallet Migrations', function() { rescan = true; }; - await walletDB.open(); + await wdbOpenSync(); const wallet = walletDB.primary; for (const addr of missingAddrs) { @@ -574,7 +582,7 @@ describe('Wallet Migrations', function() { }); }); - describe('Mirate account lookahead (integration)', function () { + describe('Migrate account lookahead (integration)', function () { const location = testdir('wallet-change'); const migrationsBAK = WalletMigrator.migrations; const TEST_LOOKAHEAD = 150; @@ -585,7 +593,7 @@ describe('Wallet Migrations', function() { network: network }; - let walletDB, ldb; + let walletDB, ldb, wdbOpenSync; before(async () => { WalletMigrator.migrations = {}; await fs.mkdirp(location); @@ -599,6 +607,7 @@ describe('Wallet Migrations', function() { beforeEach(async () => { walletDB = new WalletDB(walletOptions); ldb = walletDB.db; + wdbOpenSync = wdbOpenSyncFn(walletDB); }); afterEach(async () => { @@ -644,7 +653,7 @@ describe('Wallet Migrations', function() { await b.write(); }; - await walletDB.open(); + await wdbOpenSync(); const wallet = walletDB.primary; await wallet.createAccount({}); @@ -689,7 +698,7 @@ describe('Wallet Migrations', function() { walletDB.options.walletMigrate = 0; - await walletDB.open(); + await wdbOpenSync(); const wallet = walletDB.primary; const wallet2 = await walletDB.get(1); await checkLookahead(wallet, TEST_LOOKAHEAD + 0); @@ -719,3 +728,11 @@ function getVersion(data, name) { return data.readUInt32LE(name.length); } + +function wdbOpenSyncFn(wdb) { + return async () => { + const forSync = forEvent(wdb, 'sync done'); + await wdb.open(); + await forSync; + }; +};