Remove the returnedCollateral when the slot is not filled by the host

This commit is contained in:
Arnaud 2025-05-07 15:54:24 +02:00
parent 05e0192563
commit 2ae617d662
No known key found for this signature in database
GPG Key ID: B8FBC178F10CA7AE

View File

@ -31,24 +31,22 @@ method run*(
raiseAssert "no sale request"
try:
debug "Collecting collateral and partial payout",
requestId = data.requestId, slotIndex = data.slotIndex
# The returnedCollateral is needed even if the slot is not filled by the host
# because a reservation could be created and the collateral assigned
# to that reservation. So if the slot is not filled by that host,
# the reservation will be deleted during cleanup and the collateral
# must be returned to the host.
let slot = Slot(request: request, slotIndex: data.slotIndex)
let currentCollateral = await market.currentCollateral(slot.id)
let returnedCollateral = currentCollateral.some
var returnedCollateral = UInt256.none
if await slotIsFilledByMe(market, data.requestId, data.slotIndex):
debug "Collecting collateral and partial payout",
requestId = data.requestId, slotIndex = data.slotIndex
let slot = Slot(request: request, slotIndex: data.slotIndex)
let currentCollateral = await market.currentCollateral(slot.id)
try:
await market.freeSlot(slot.id)
except SlotStateMismatchError as e:
warn "Failed to free slot because slot is already free", error = e.msg
returnedCollateral = currentCollateral.some
if onClear =? agent.context.onClear and request =? data.request:
onClear(request, data.slotIndex)