@@ -6,9 +6,9 @@ import { CctpTxEvidenceShape, PendingTxShape } from '../typeGuards.js';
6
6
import { PendingTxStatus } from '../constants.js' ;
7
7
8
8
/**
9
- * @import {MapStore} from '@agoric/store';
9
+ * @import {MapStore, SetStore } from '@agoric/store';
10
10
* @import {Zone} from '@agoric/zone';
11
- * @import {CctpTxEvidence, NobleAddress, PendingTxKey, PendingTx} from '../types.js';
11
+ * @import {CctpTxEvidence, NobleAddress, SeenTxKey, PendingTxKey, PendingTx} from '../types.js';
12
12
*/
13
13
14
14
/**
@@ -35,6 +35,20 @@ const pendingTxKeyOf = evidence => {
35
35
return makePendingTxKey ( forwardingAddress , amount ) ;
36
36
} ;
37
37
38
+ /**
39
+ * Get the key for the seenTxs SetStore.
40
+ *
41
+ * The key is a composite of `NobleAddress` and transaction `amount` and not
42
+ * meant to be parsable.
43
+ *
44
+ * @param {CctpTxEvidence } evidence
45
+ * @returns {SeenTxKey }
46
+ */
47
+ const seenTxKeyOf = evidence => {
48
+ const { txHash, chainId } = evidence ;
49
+ return `seenTx:${ JSON . stringify ( [ txHash , chainId ] ) } ` ;
50
+ } ;
51
+
38
52
/**
39
53
* The `StatusManager` keeps track of Pending and Seen Transactions
40
54
* via {@link PendingTxStatus} states, aiding in coordination between the `Advancer`
@@ -51,11 +65,27 @@ export const prepareStatusManager = zone => {
51
65
valueShape : M . arrayOf ( PendingTxShape ) ,
52
66
} ) ;
53
67
68
+ /** @type {SetStore<SeenTxKey> } */
69
+ const seenTxs = zone . setStore ( 'SeenTxs' , {
70
+ keyShape : M . string ( ) ,
71
+ } ) ;
72
+
54
73
/**
74
+ * Ensures that `txHash+chainId` has not been processed
75
+ * and adds entry to `seenTxs` set.
76
+ *
77
+ * Also records the CctpTxEvidence and status in `pendingTxs`.
78
+ *
55
79
* @param {CctpTxEvidence } evidence
56
80
* @param {PendingTxStatus } status
57
81
*/
58
82
const recordPendingTx = ( evidence , status ) => {
83
+ const seenKey = seenTxKeyOf ( evidence ) ;
84
+ if ( seenTxs . has ( seenKey ) ) {
85
+ throw makeError ( `Transaction already seen: ${ q ( seenKey ) } ` ) ;
86
+ }
87
+ seenTxs . add ( seenKey ) ;
88
+
59
89
appendToStoredArray (
60
90
pendingTxs ,
61
91
pendingTxKeyOf ( evidence ) ,
0 commit comments