Skip to content

Commit

Permalink
perf(sync): add utxo cache behavior to coin spend
Browse files Browse the repository at this point in the history
indexing improvements for coin mints and spends, as well as converting mint operation to insert
  • Loading branch information
nitsujlangston committed Oct 24, 2018
1 parent 17eb0d9 commit 3dd7521
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
4 changes: 4 additions & 0 deletions packages/bitcore-node/src/models/coin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class Coin extends BaseModel<ICoin> {

onConnect() {
this.collection.createIndex({ mintTxid: 1, mintIndex: 1 });
this.collection.createIndex(
{ mintTxid: 1, mintIndex: 1, chain: 1, network: 1 },
{ partialFilterExpression: { spentHeight: { $lt: 0 } } }
);
this.collection.createIndex(
{ address: 1, chain: 1, network: 1 },
{ partialFilterExpression: { spentHeight: { $lt: 0 } } }
Expand Down
33 changes: 12 additions & 21 deletions packages/bitcore-node/src/models/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,29 +210,20 @@ export class Transaction extends BaseModel<ITransaction> {
}

mintOps.push({
updateOne: {
filter: {
insertOne: {
document: {
chain,
network,
mintTxid: txid,
mintIndex: index,
spentHeight: { $lt: SpentHeightIndicators.minimum },
chain,
network
},
update: {
$set: {
chain,
network,
mintHeight: height,
coinbase: isCoinbase,
value: output.satoshis,
address,
script: scriptBuffer,
spentHeight: SpentHeightIndicators.unspent,
wallets: []
}
},
upsert: true,
forceServerObjectId: true
mintHeight: height,
address,
coinbase: isCoinbase,
value: output.satoshis,
script: scriptBuffer,
spentHeight: SpentHeightIndicators.unspent,
wallets: []
}
}
});
}
Expand Down

0 comments on commit 3dd7521

Please sign in to comment.