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 internalPrm = hdaHelper.deriveAddresses(xpub, 1, _.range(gap.internal), scheme)
const external = await externalPrm
const internal = await internalPrm
const addresses = _.flatten([external, internal])
const addresses = _.flatten(await Promise.all([externalPrm, internalPrm]))
return db.addAddressesToHDAccount(xpub, addresses)
}

5
lib/wallet/wallet-service.js

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

3
pushtx/status.js

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

13
tracker/blockchain-processor.js

@ -55,8 +55,7 @@ class BlockchainProcessor extends AbstractProcessor {
* @returns {Promise}
*/
async catchup() {
const highest = await db.getHighestBlock()
const info = await this.client.getblockchaininfo()
const [highest, info] = await Promise.all([db.getHighestBlock(), this.client.getblockchaininfo()])
const daemonNbHeaders = info.headers
// 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 {
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 daemonNbHeaders = info.headers
// Get highest block processed by the tracker
const highest = await db.getHighestBlock()
const dbMaxHeight = highest.blockHeight
let prevBlockId = highest.blockID
@ -151,11 +149,10 @@ class BlockchainProcessor extends AbstractProcessor {
try {
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
// Get highest block processed by the tracker
const highest = await db.getHighestBlock()
if (highest == null) 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.displayStatsId)
resolve(this.txSock.disconnect(keys.bitcoind.zmqTx).close())
resolve(this.pushTxSock.disconnect(keys.ports.notifpushtx).close())
resolve(this.orchestratorSock.disconnect(keys.ports.orchestrator).close())
this.txSock.disconnect(keys.bitcoind.zmqTx).close()
this.pushTxSock.disconnect(keys.ports.notifpushtx).close()
this.orchestratorSock.disconnect(keys.ports.orchestrator).close()
return Promise.resolve();
}
/**
@ -255,11 +257,10 @@ class MempoolProcessor extends AbstractProcessor {
*/
async _refreshActiveStatus() {
// 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
// Get highest block processed by the tracker
const highestBlock = await db.getHighestBlock()
if (highestBlock == null || highestBlock.blockHeight == 0) {
this.isActive = false
return

Loading…
Cancel
Save