Browse Source

Merge branch 'moar-minor-optimizations' into 'develop'

Minor optimizations

See merge request dojo/samourai-dojo!212
umbrel
kenshin-samourai 4 years ago
parent
commit
bd5e7ef949
  1. 5
      lib/bitcoin/hd-accounts-service.js
  2. 5
      lib/wallet/wallet-service.js
  3. 3
      pushtx/status.js
  4. 13
      tracker/blockchain-processor.js
  5. 13
      tracker/mempool-processor.js

5
lib/bitcoin/hd-accounts-service.js

@ -144,10 +144,7 @@ class HDAccountsService {
const externalPrm = hdaHelper.deriveAddresses(xpub, 0, _.range(gap.external), scheme) const externalPrm = hdaHelper.deriveAddresses(xpub, 0, _.range(gap.external), scheme)
const internalPrm = hdaHelper.deriveAddresses(xpub, 1, _.range(gap.internal), scheme) const internalPrm = hdaHelper.deriveAddresses(xpub, 1, _.range(gap.internal), scheme)
const external = await externalPrm const addresses = _.flatten(await Promise.all([externalPrm, internalPrm]))
const internal = await internalPrm
const addresses = _.flatten([external, internal])
return db.addAddressesToHDAccount(xpub, addresses) return db.addAddressesToHDAccount(xpub, addresses)
} }

5
lib/wallet/wallet-service.js

@ -365,10 +365,7 @@ class WalletService {
*/ */
_mergeEntities(active, legacy, bip49, bip84, pubkeys) { _mergeEntities(active, legacy, bip49, bip84, pubkeys) {
// Put all xpub into active.xpubs // Put all xpub into active.xpubs
active.xpubs = active.xpubs active.xpubs = active.xpubs.concat(legacy.xpubs, bip49.xpubs, bip84.xpubs)
.concat(legacy.xpubs)
.concat(bip49.xpubs)
.concat(bip84.xpubs)
// Put addresses and pubkeys into active // Put addresses and pubkeys into active
// but avoid duplicates // but avoid duplicates

3
pushtx/status.js

@ -75,8 +75,7 @@ class Status {
this.status.push.count = this.stats.count this.status.push.count = this.stats.count
try { try {
await this._refreshNetworkInfo() await Promise.all([this._refreshNetworkInfo(), this._refreshBlockchainInfo()])
await this._refreshBlockchainInfo()
} catch (e) { } catch (e) {
Logger.error(e, 'PushTx : Status.getCurrent() : Error') Logger.error(e, 'PushTx : Status.getCurrent() : Error')
} finally { } finally {

13
tracker/blockchain-processor.js

@ -55,8 +55,7 @@ class BlockchainProcessor extends AbstractProcessor {
* @returns {Promise} * @returns {Promise}
*/ */
async catchup() { async catchup() {
const highest = await db.getHighestBlock() const [highest, info] = await Promise.all([db.getHighestBlock(), this.client.getblockchaininfo()])
const info = await this.client.getblockchaininfo()
const daemonNbHeaders = info.headers const daemonNbHeaders = info.headers
// Consider that we are in IBD mode if Dojo is far in the past (> 13,000 blocks) // Consider that we are in IBD mode if Dojo is far in the past (> 13,000 blocks)
@ -80,12 +79,11 @@ class BlockchainProcessor extends AbstractProcessor {
try { try {
Logger.info('Tracker : Tracker Startup (IBD mode)') Logger.info('Tracker : Tracker Startup (IBD mode)')
const info = await this.client.getblockchaininfo() // Get highest block processed by the tracker
const [highest, info] = await Promise.all([db.getHighestBlock(), this.client.getblockchaininfo()])
const daemonNbBlocks = info.blocks const daemonNbBlocks = info.blocks
const daemonNbHeaders = info.headers const daemonNbHeaders = info.headers
// Get highest block processed by the tracker
const highest = await db.getHighestBlock()
const dbMaxHeight = highest.blockHeight const dbMaxHeight = highest.blockHeight
let prevBlockId = highest.blockID let prevBlockId = highest.blockID
@ -151,11 +149,10 @@ class BlockchainProcessor extends AbstractProcessor {
try { try {
Logger.info('Tracker : Tracker Startup (normal mode)') Logger.info('Tracker : Tracker Startup (normal mode)')
const info = await this.client.getblockchaininfo() // Get highest block processed by the tracker
const [highest, info] = await Promise.all([db.getHighestBlock(), this.client.getblockchaininfo()])
const daemonNbBlocks = info.blocks const daemonNbBlocks = info.blocks
// Get highest block processed by the tracker
const highest = await db.getHighestBlock()
if (highest == null) return null if (highest == null) return null
if (daemonNbBlocks == highest.blockHeight) return null if (daemonNbBlocks == highest.blockHeight) return null

13
tracker/mempool-processor.js

@ -75,9 +75,11 @@ class MempoolProcessor extends AbstractProcessor {
clearInterval(this.processMempoolId) clearInterval(this.processMempoolId)
//clearInterval(this.displayStatsId) //clearInterval(this.displayStatsId)
resolve(this.txSock.disconnect(keys.bitcoind.zmqTx).close()) this.txSock.disconnect(keys.bitcoind.zmqTx).close()
resolve(this.pushTxSock.disconnect(keys.ports.notifpushtx).close()) this.pushTxSock.disconnect(keys.ports.notifpushtx).close()
resolve(this.orchestratorSock.disconnect(keys.ports.orchestrator).close()) this.orchestratorSock.disconnect(keys.ports.orchestrator).close()
return Promise.resolve();
} }
/** /**
@ -255,11 +257,10 @@ class MempoolProcessor extends AbstractProcessor {
*/ */
async _refreshActiveStatus() { async _refreshActiveStatus() {
// Get highest header in the blockchain // Get highest header in the blockchain
const info = await this.client.getblockchaininfo() // Get highest block processed by the tracker
const [highestBlock, info] = await Promise.all([db.getHighestBlock(), this.client.getblockchaininfo()])
const highestHeader = info.headers const highestHeader = info.headers
// Get highest block processed by the tracker
const highestBlock = await db.getHighestBlock()
if (highestBlock == null || highestBlock.blockHeight == 0) { if (highestBlock == null || highestBlock.blockHeight == 0) {
this.isActive = false this.isActive = false
return return

Loading…
Cancel
Save