Skip to content

Commit 3dd7521

Browse files
perf(sync): add utxo cache behavior to coin spend
indexing improvements for coin mints and spends, as well as converting mint operation to insert
1 parent 17eb0d9 commit 3dd7521

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

packages/bitcore-node/src/models/coin.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class Coin extends BaseModel<ICoin> {
4949

5050
onConnect() {
5151
this.collection.createIndex({ mintTxid: 1, mintIndex: 1 });
52+
this.collection.createIndex(
53+
{ mintTxid: 1, mintIndex: 1, chain: 1, network: 1 },
54+
{ partialFilterExpression: { spentHeight: { $lt: 0 } } }
55+
);
5256
this.collection.createIndex(
5357
{ address: 1, chain: 1, network: 1 },
5458
{ partialFilterExpression: { spentHeight: { $lt: 0 } } }

packages/bitcore-node/src/models/transaction.ts

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -210,29 +210,20 @@ export class Transaction extends BaseModel<ITransaction> {
210210
}
211211

212212
mintOps.push({
213-
updateOne: {
214-
filter: {
213+
insertOne: {
214+
document: {
215+
chain,
216+
network,
215217
mintTxid: txid,
216218
mintIndex: index,
217-
spentHeight: { $lt: SpentHeightIndicators.minimum },
218-
chain,
219-
network
220-
},
221-
update: {
222-
$set: {
223-
chain,
224-
network,
225-
mintHeight: height,
226-
coinbase: isCoinbase,
227-
value: output.satoshis,
228-
address,
229-
script: scriptBuffer,
230-
spentHeight: SpentHeightIndicators.unspent,
231-
wallets: []
232-
}
233-
},
234-
upsert: true,
235-
forceServerObjectId: true
219+
mintHeight: height,
220+
address,
221+
coinbase: isCoinbase,
222+
value: output.satoshis,
223+
script: scriptBuffer,
224+
spentHeight: SpentHeightIndicators.unspent,
225+
wallets: []
226+
}
236227
}
237228
});
238229
}

0 commit comments

Comments
 (0)