Skip to content

Commit

Permalink
feat: record blockTimestamp in SeenTxs
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Feb 12, 2025
1 parent f2ed533 commit f9920a8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
19 changes: 12 additions & 7 deletions packages/fast-usdc/src/exos/status-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,18 @@ export const prepareStatusManager = (
/**
* Transactions seen *ever* by the contract.
*
* Note that like all durable stores, this SetStore is stored in IAVL. It
* grows without bound (though the amount of growth per incoming message to
* the contract is bounded). At some point in the future we may want to prune.
* @type {SetStore<EvmHash>}
* Note that like all durable stores, this MapStore is kept in IAVL. It stores
* the `blockTimestamp` so that later we can prune old transactions.
*
* Note that `blockTimestamp` can drift between chains. Fortunately all CCTP
* chains use the same Unix epoch and won't drift more than minutes apart,
* which is more than enough precision for pruning old transaction.
*
* @type {MapStore<EvmHash, NatValue>}
*/
const seenTxs = zone.setStore('SeenTxs', {
const seenTxs = zone.mapStore('SeenTxs', {
keyShape: M.string(),
valueShape: M.nat(),
});

/**
Expand Down Expand Up @@ -160,7 +165,7 @@ export const prepareStatusManager = (
if (seenTxs.has(txHash)) {
throw makeError(`Transaction already seen: ${q(txHash)}`);
}
seenTxs.add(txHash);
seenTxs.init(txHash, evidence.blockTimestamp);

appendToStoredArray(
pendingSettleTxs,
Expand Down Expand Up @@ -305,7 +310,7 @@ export const prepareStatusManager = (
if (seenTxs.has(txHash)) {
throw makeError(`Transaction already seen: ${q(txHash)}`);
}
seenTxs.add(txHash);
seenTxs.init(txHash, evidence.blockTimestamp);
publishEvidence(txHash, evidence);
},

Expand Down
24 changes: 12 additions & 12 deletions packages/fast-usdc/test/snapshots/fast-usdc.contract.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,7 @@ Generated by [AVA](https://avajs.dev).
'Operator Kit_kindHandle': 'Alleged: kind',
PendingSettleTxs: {},
PoolAccount: 'Vow',
SeenTxs: [],
SeenTxs: {},
SettleAccount: 'Vow',
StoredCompletedTxs: [],
mint: {
Expand Down Expand Up @@ -3056,17 +3056,17 @@ Generated by [AVA](https://avajs.dev).
'Operator Kit_kindHandle': 'Alleged: kind',
PendingSettleTxs: {},
PoolAccount: 'Vow',
SeenTxs: [
'0x000001',
'0x0000010',
'0x000002',
'0x000003',
'0x000004',
'0x000005',
'0x000006',
'0x000007',
'0x000008',
],
SeenTxs: {
'0x000001': 1632340000n,
'0x0000010': 1632340000n,
'0x000002': 1632340000n,
'0x000003': 1632340000n,
'0x000004': 1632340000n,
'0x000005': 1632340000n,
'0x000006': 1632340000n,
'0x000007': 1632340000n,
'0x000008': 1632340000n,
},
SettleAccount: 'Vow',
StoredCompletedTxs: [
'0x000001',
Expand Down
Binary file modified packages/fast-usdc/test/snapshots/fast-usdc.contract.test.ts.snap
Binary file not shown.

0 comments on commit f9920a8

Please sign in to comment.