mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-04 06:23:06 +00:00
* Indicate that slot is being repaired when trying to download * Fix tests * Apply nph * Calculate the repair collateral when adding the item into the queue * Add slotCollateral calculation with getRequest cache and remove populationItem function * Update with pricePerByte * Simplify StorageAsk parameter * Minor fixes * Move cache request to another PR * Rename SlotQueueItem collateral and required in init * Use override func to optimise calls when the slot state is known * Remove unused code * Cosmetic change * Use raiseMarketError helper * Add exceptions to async pragma * Cosmetic change * Use raiseMarketError helper * Let slotCollateral determines the slot sate * Use configSync to avoid async pragma in onStorageRequested * Add loadConfig function * Add CatchableError to async pragma * Add missing pragma raises errors * Move loadConfig * Avoid swallow CancelledError * Avoid swallowing CancelledError * Avoid swallowing CancelledError * Update error messages * Except MarketError instead of CatchableError * Fix merge issue * Log fatal when configuration cannot be loaded * Propagate MarketError in slotCollateral * Remove useless configSync * Use result with explicit error * Fix syntax --------- Signed-off-by: Arnaud <arnaud@status.im>
64 lines
1.9 KiB
Nim
64 lines
1.9 KiB
Nim
import pkg/stint
|
|
import ../../logutils
|
|
import ../../market
|
|
import ../../utils/exceptions
|
|
import ../statemachine
|
|
import ../salesagent
|
|
import ./filled
|
|
import ./cancelled
|
|
import ./failed
|
|
import ./ignored
|
|
import ./errored
|
|
|
|
logScope:
|
|
topics = "marketplace sales filling"
|
|
|
|
type SaleFilling* = ref object of SaleState
|
|
proof*: Groth16Proof
|
|
|
|
method `$`*(state: SaleFilling): string =
|
|
"SaleFilling"
|
|
|
|
method onCancelled*(state: SaleFilling, request: StorageRequest): ?State =
|
|
return some State(SaleCancelled())
|
|
|
|
method onFailed*(state: SaleFilling, request: StorageRequest): ?State =
|
|
return some State(SaleFailed())
|
|
|
|
method run*(
|
|
state: SaleFilling, machine: Machine
|
|
): Future[?State] {.async: (raises: []).} =
|
|
let data = SalesAgent(machine).data
|
|
let market = SalesAgent(machine).context.market
|
|
without (request =? data.request):
|
|
raiseAssert "Request not set"
|
|
|
|
logScope:
|
|
requestId = data.requestId
|
|
slotIndex = data.slotIndex
|
|
|
|
try:
|
|
without collateral =? await market.slotCollateral(data.requestId, data.slotIndex),
|
|
err:
|
|
error "Failure attempting to fill slot: unable to calculate collateral",
|
|
error = err.msg
|
|
return
|
|
|
|
debug "Filling slot"
|
|
try:
|
|
await market.fillSlot(data.requestId, data.slotIndex, state.proof, collateral)
|
|
except MarketError as e:
|
|
if e.msg.contains "Slot is not free":
|
|
debug "Slot is already filled, ignoring slot"
|
|
return some State(SaleIgnored(reprocessSlot: false, returnBytes: true))
|
|
else:
|
|
return some State(SaleErrored(error: e))
|
|
# other CatchableErrors are handled "automatically" by the SaleState
|
|
|
|
return some State(SaleFilled())
|
|
except CancelledError as e:
|
|
trace "SaleFilling.run was cancelled", error = e.msgDetail
|
|
except CatchableError as e:
|
|
error "Error during SaleFilling.run", error = e.msgDetail
|
|
return some State(SaleErrored(error: e))
|