mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-03-25 21:53:12 +00:00
Add cancel on error during filling state
When calling fillSlot, any transaction errors that occur (possibly during estimate gas) will cause that tx to be replaced with a cancellation transaction (a 0-valued tx to ourselves).
This commit is contained in:
parent
c068e7425b
commit
58a97856b4
@ -110,7 +110,14 @@ method getActiveSlot*(market: OnChainMarket,
|
||||
return none Slot
|
||||
raise e
|
||||
|
||||
method fillSlot(market: OnChainMarket,
|
||||
proc cancelTransaction(market: OnChainMarket, nonce: UInt256) {.async.} =
|
||||
let address = await market.getSigner()
|
||||
let cancelTx = Transaction(to: address, value: 0.u256, nonce: some nonce)
|
||||
let populated = await market.signer.populateTransaction(cancelTx)
|
||||
trace "cancelling transaction to prevent stuck transactions", nonce
|
||||
discard market.signer.sendTransaction(populated)
|
||||
|
||||
method fillSlot*(market: OnChainMarket,
|
||||
requestId: RequestId,
|
||||
slotIndex: UInt256,
|
||||
proof: seq[byte],
|
||||
|
||||
@ -76,6 +76,17 @@ method getActiveSlot*(
|
||||
|
||||
raiseAssert("not implemented")
|
||||
|
||||
method cancelTransaction(market: Market, nonce: UInt256) {.base, async.} =
|
||||
raiseAssert("not implemented")
|
||||
|
||||
template cancelOnError*(market: Market, body) =
|
||||
try:
|
||||
body
|
||||
except JsonRpcProviderError as e:
|
||||
if e.nonce.isSome:
|
||||
# send a 0-valued transaction with the errored nonce to prevent stuck txs
|
||||
await market.cancelTransaction(!e.nonce)
|
||||
|
||||
method fillSlot*(market: Market,
|
||||
requestId: RequestId,
|
||||
slotIndex: UInt256,
|
||||
|
||||
@ -36,5 +36,6 @@ method run(state: SaleFilling, machine: Machine): Future[?State] {.async.} =
|
||||
raiseAssert("no slot index assigned")
|
||||
|
||||
debug "Filling slot", requestId = $data.requestId, slotIndex
|
||||
await market.fillSlot(data.requestId, slotIndex, state.proof, collateral)
|
||||
debug "Waiting for slot filled event...", requestId = $data.requestId, slotIndex
|
||||
market.cancelOnError:
|
||||
await market.fillSlot(data.requestId, slotIndex, state.proof, collateral)
|
||||
debug "Waiting for slot filled event...", requestId = $data.requestId, slotIndex
|
||||
|
||||
@ -205,6 +205,9 @@ proc emitRequestFailed*(market: MockMarket, requestId: RequestId) =
|
||||
subscription.requestId.isNone:
|
||||
subscription.callback(requestId)
|
||||
|
||||
proc cancelTransaction(market: Market, nonce: UInt256) {.async.} =
|
||||
discard
|
||||
|
||||
proc fillSlot*(market: MockMarket,
|
||||
requestId: RequestId,
|
||||
slotIndex: UInt256,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user