@@ -20,6 +20,8 @@ export const updateMinedTx = async () => {
20
20
return ;
21
21
}
22
22
23
+ const droppedTxs : Transactions [ ] = [ ] ;
24
+
23
25
const txsWithReceipts = (
24
26
await Promise . all (
25
27
txs . map ( async ( tx ) => {
@@ -30,8 +32,16 @@ export const updateMinedTx = async () => {
30
32
. getTransactionReceipt ( tx . transactionHash ! ) ;
31
33
32
34
if ( ! receipt ) {
33
- // If no receipt was received, return undefined to filter out tx
34
- return undefined ;
35
+ // This tx is not yet mined or was dropped.
36
+
37
+ // If the tx was submitted over 1 hour ago, assume it is dropped.
38
+ // @TODO : move duration to config
39
+ const sentAt = new Date ( tx . sentAt ! ) ;
40
+ const ageInMilliseconds = Date . now ( ) - sentAt . getTime ( ) ;
41
+ if ( ageInMilliseconds > 1000 * 60 * 60 * 1 ) {
42
+ droppedTxs . push ( tx ) ;
43
+ }
44
+ return ;
35
45
}
36
46
37
47
const response = ( await sdk
@@ -68,7 +78,7 @@ export const updateMinedTx = async () => {
68
78
minedAt : Date ;
69
79
} [ ] ;
70
80
71
- // Update all transactions with a receipt in parallel
81
+ // Update mined transactions.
72
82
await Promise . all (
73
83
txsWithReceipts . map ( async ( txWithReceipt ) => {
74
84
await updateTx ( {
@@ -94,12 +104,35 @@ export const updateMinedTx = async () => {
94
104
service : "worker" ,
95
105
level : "info" ,
96
106
queueId : txWithReceipt . tx . id ,
97
- message : ` Updated with receipt` ,
107
+ message : " Updated mined tx." ,
98
108
} ) ;
99
109
100
110
sendWebhookForQueueIds . push ( txWithReceipt . tx . id ) ;
101
111
} ) ,
102
112
) ;
113
+
114
+ // Update dropped txs.
115
+ await Promise . all (
116
+ droppedTxs . map ( async ( tx ) => {
117
+ await updateTx ( {
118
+ pgtx,
119
+ queueId : tx . id ,
120
+ data : {
121
+ status : TransactionStatusEnum . Errored ,
122
+ errorMessage : "Transaction timed out." ,
123
+ } ,
124
+ } ) ;
125
+
126
+ logger ( {
127
+ service : "worker" ,
128
+ level : "info" ,
129
+ queueId : tx . id ,
130
+ message : "Update dropped tx." ,
131
+ } ) ;
132
+
133
+ sendWebhookForQueueIds . push ( tx . id ) ;
134
+ } ) ,
135
+ ) ;
103
136
} ,
104
137
{
105
138
timeout : 5 * 60000 ,
0 commit comments