Skip to content

Commit ad63ec7

Browse files
authored
fix: stop infinite miles retry when commitment is never opened (#913)
1 parent 16c3532 commit ad63ec7

1 file changed

Lines changed: 32 additions & 18 deletions

File tree

tools/fastswap-miles/miles.go

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,24 @@ WHERE processed = false
117117

118118
if bidCostWei.Sign() == 0 {
119119
if fastRPCSet[strings.ToLower(r.txHash)] {
120-
cfg.Logger.Info("tx in FastRPC but bid not indexed yet, will retry",
120+
if r.blockTS.Valid && time.Since(r.blockTS.Time) > 15*time.Minute {
121+
cfg.Logger.Info("tx in FastRPC but bid never indexed, processing with 0 bid cost",
122+
slog.String("tx", r.txHash), slog.String("user", r.user))
123+
// fall through to normal miles calculation with bidCostWei = 0
124+
} else {
125+
cfg.Logger.Info("tx in FastRPC but bid not indexed yet, will retry",
126+
slog.String("tx", r.txHash), slog.String("user", r.user))
127+
continue
128+
}
129+
} else {
130+
cfg.Logger.Info("tx not in FastRPC, skipping with 0 miles",
121131
slog.String("tx", r.txHash), slog.String("user", r.user))
132+
if !cfg.DryRun {
133+
markProcessed(cfg.DB, r.txHash, weiToEth(surplusWei), 0, 0, "0")
134+
}
135+
processed++
122136
continue
123137
}
124-
cfg.Logger.Info("tx not in FastRPC, skipping with 0 miles",
125-
slog.String("tx", r.txHash), slog.String("user", r.user))
126-
if !cfg.DryRun {
127-
markProcessed(cfg.DB, r.txHash, weiToEth(surplusWei), 0, 0, "0")
128-
}
129-
processed++
130-
continue
131138
}
132139

133140
netProfit := new(big.Int).Sub(surplusWei, gasCostWei)
@@ -265,18 +272,25 @@ WHERE processed = false
265272
bidCostWei := getBidCost(erc20BidMap, r.txHash)
266273
if bidCostWei.Sign() == 0 {
267274
if erc20FastRPCSet[strings.ToLower(r.txHash)] {
268-
cfg.Logger.Info("erc20 tx in FastRPC but bid not indexed yet, will retry",
275+
if r.blockTS.Valid && time.Since(r.blockTS.Time) > 15*time.Minute {
276+
cfg.Logger.Info("erc20 tx in FastRPC but bid never indexed, processing with 0 bid cost",
277+
slog.String("tx", r.txHash), slog.String("user", r.user))
278+
// fall through with bidCostWei = 0
279+
} else {
280+
cfg.Logger.Info("erc20 tx in FastRPC but bid not indexed yet, will retry",
281+
slog.String("tx", r.txHash), slog.String("user", r.user))
282+
continue
283+
}
284+
} else {
285+
cfg.Logger.Info("erc20 tx not in FastRPC, skipping with 0 miles",
269286
slog.String("tx", r.txHash), slog.String("user", r.user))
270-
continue // genuinely skip — will retry next cycle
271-
}
272-
cfg.Logger.Info("erc20 tx not in FastRPC, skipping with 0 miles",
273-
slog.String("tx", r.txHash), slog.String("user", r.user))
274-
surplusWei, _ := new(big.Int).SetString(r.surplus, 10)
275-
if !cfg.DryRun {
276-
markProcessed(cfg.DB, r.txHash, weiToEth(surplusWei), 0, 0, "0")
287+
surplusWei, _ := new(big.Int).SetString(r.surplus, 10)
288+
if !cfg.DryRun {
289+
markProcessed(cfg.DB, r.txHash, weiToEth(surplusWei), 0, 0, "0")
290+
}
291+
processed++
292+
continue
277293
}
278-
processed++
279-
continue
280294
}
281295

282296
userPaysGas := strings.EqualFold(r.inputToken, zeroAddr.Hex())

0 commit comments

Comments
 (0)