From b1a632462f1f11f8a292e4129453041fcde797f0 Mon Sep 17 00:00:00 2001 From: ThatBen Date: Wed, 26 Mar 2025 12:56:52 +0100 Subject: [PATCH] Fixes version mismatch of libp2p --- codexcrawler.nimble | 7 +- codexcrawler/services/marketplace.nim | 3 +- codexcrawler/services/marketplace/market.nim | 104 ++++--------------- 3 files changed, 29 insertions(+), 85 deletions(-) diff --git a/codexcrawler.nimble b/codexcrawler.nimble index 3af92dc..c14c124 100644 --- a/codexcrawler.nimble +++ b/codexcrawler.nimble @@ -16,13 +16,16 @@ requires "nimcrypto >= 0.6.2 & < 0.7.0" requires "bearssl >= 0.2.5 & < 0.3.0" requires "chronicles >= 0.10.2 & < 0.11.0" requires "chronos >= 4.0.3 & < 4.1.0" -requires "libp2p >= 1.5.0 & < 2.0.0" +# requires "libp2p >= 1.5.0 & < 2.0.0" +requires "libp2p#036e110a6080fba1a1662c58cfd8c21f9a548021" # Same as codex-0.2.0 uses. +requires "https://github.com/codex-storage/nim-poseidon2#4e2c6e619b2f2859aaa4b2aed2f346ea4d0c67a3" + requires "metrics >= 0.1.0 & < 0.2.0" requires "stew >= 0.2.0 & < 0.3.0" requires "stint >= 0.8.1 & < 0.9.0" requires "https://github.com/codex-storage/nim-datastore >= 0.2.0 & < 0.3.0" requires "questionable >= 0.10.15 & < 0.11.0" -requires "https://github.com/codex-storage/nim-codex-dht#f6eef1ac95c70053b2518f1e3909c909ed8701a6" +requires "https://github.com/codex-storage/nim-codex-dht#89b281fc8d84097d4cd1f8a53fac68bd23433f59" requires "docopt >= 0.7.1 & < 1.0.0" requires "nph >= 0.6.1 & < 1.0.0" requires "ethers >= 1.0.0 & < 2.0.0" diff --git a/codexcrawler/services/marketplace.nim b/codexcrawler/services/marketplace.nim index 12ebfa7..796709a 100644 --- a/codexcrawler/services/marketplace.nim +++ b/codexcrawler/services/marketplace.nim @@ -71,7 +71,8 @@ method iteratePastNewRequestEvents*( if market =? m.market: try: - let requests = await market.queryPastStorageRequestedEvents(startTime.int64) + let requests = + await market.queryPastStorageRequestedEventsFromTime(startTime.int64) for request in requests: if error =? (await onNewRequest(Rid(request.requestId))).errorOption: return failure(error.msg) diff --git a/codexcrawler/services/marketplace/market.nim b/codexcrawler/services/marketplace/market.nim index c0b88fa..6b00376 100644 --- a/codexcrawler/services/marketplace/market.nim +++ b/codexcrawler/services/marketplace/market.nim @@ -138,16 +138,12 @@ proc periodicity*( let period = config.proofs.period return Periodicity(seconds: period) -proc proofTimeout*( - market: OnChainMarket -): Future[uint64] {.async: (raises: [CancelledError, MarketError]).} = +proc proofTimeout*(market: OnChainMarket): Future[uint64] {.async.} = convertEthersError: let config = await market.config() return config.proofs.timeout -proc repairRewardPercentage*( - market: OnChainMarket -): Future[uint8] {.async: (raises: [CancelledError, MarketError]).} = +proc repairRewardPercentage*(market: OnChainMarket): Future[uint8] {.async.} = convertEthersError: let config = await market.config() return config.collateral.repairRewardPercentage @@ -157,9 +153,7 @@ proc requestDurationLimit*(market: OnChainMarket): Future[uint64] {.async.} = let config = await market.config() return config.requestDurationLimit -proc proofDowntime*( - market: OnChainMarket -): Future[uint8] {.async: (raises: [CancelledError, MarketError]).} = +proc proofDowntime*(market: OnChainMarket): Future[uint8] {.async.} = convertEthersError: let config = await market.config() return config.proofs.downtime @@ -188,25 +182,15 @@ proc requestStorage(market: OnChainMarket, request: StorageRequest) {.async.} = proc getRequest*( market: OnChainMarket, id: RequestId -): Future[?StorageRequest] {.async: (raises: [CancelledError]).} = - try: - let key = $id +): Future[?StorageRequest] {.async.} = + let key = $id - # if key in market.requestCache: - # return some market.requestCache[key] - - let request = await market.contract.getRequest(id) - # market.requestCache[key] = request - return some request - except Marketplace_UnknownRequest, KeyError: - warn "Cannot retrieve the request", error = getCurrentExceptionMsg() - return none StorageRequest - except EthersError, AsyncLockError: - error "Cannot retrieve the request", error = getCurrentExceptionMsg() - return none StorageRequest - except CatchableError as err: - error "Unknown error", error = err.msg - return none StorageRequest + convertEthersError: + try: + let request = await market.contract.getRequest(id) + return some request + except Marketplace_UnknownRequest: + return none StorageRequest proc requestState*( market: OnChainMarket, requestId: RequestId @@ -218,27 +202,18 @@ proc requestState*( except Marketplace_UnknownRequest: return none RequestState -proc slotState*( - market: OnChainMarket, slotId: SlotId -): Future[SlotState] {.async: (raises: [CancelledError, MarketError]).} = +proc slotState*(market: OnChainMarket, slotId: SlotId): Future[SlotState] {.async.} = convertEthersError: - try: - let overrides = CallOverrides(blockTag: some BlockTag.pending) - return await market.contract.slotState(slotId, overrides) - except AsyncLockError as err: - raiseMarketError( - "Failed to fetch the slot state from the Marketplace contract: " & err.msg - ) - except CatchableError as err: - raiseMarketError("Unknown error: " & err.msg) + let overrides = CallOverrides(blockTag: some BlockTag.pending) + return await market.contract.slotState(slotId, overrides) -proc getRequestEnd*(market: OnChainMarket, id: RequestId): Future[int64] {.async.} = +proc getRequestEnd*(market: OnChainMarket, id: RequestId): Future[uint64] {.async.} = convertEthersError: - return await market.contract.requestEnd(id) + return (await market.contract.requestEnd(id)).uint64 -proc requestExpiresAt*(market: OnChainMarket, id: RequestId): Future[int64] {.async.} = +proc requestExpiresAt*(market: OnChainMarket, id: RequestId): Future[uint64] {.async.} = convertEthersError: - return await market.contract.requestExpiry(id) + return (await market.contract.requestExpiry(id)).uint64 proc getHost( market: OnChainMarket, requestId: RequestId, slotIndex: uint64 @@ -282,7 +257,7 @@ proc fillSlot( trace "fillSlot transaction completed" proc freeSlot*(market: OnChainMarket, slotId: SlotId) {.async.} = - raiseAssert("Not available: freeSlot") + raiseAssert("Not supported") proc withdrawFunds(market: OnChainMarket, requestId: RequestId) {.async.} = convertEthersError: @@ -558,48 +533,13 @@ proc queryPastStorageRequestedEvents*( ): Future[seq[StorageRequested]] {.async.} = convertEthersError: let fromBlock = await market.contract.provider.pastBlockTag(blocksAgo) + return await market.queryPastStorageRequestedEvents(fromBlock) -proc queryPastStorageRequestedEvents*( +proc queryPastStorageRequestedEventsFromTime*( market: OnChainMarket, fromTime: int64 ): Future[seq[StorageRequested]] {.async.} = convertEthersError: let fromBlock = await market.contract.provider.blockNumberForEpoch(fromTime) + return await market.queryPastStorageRequestedEvents(BlockTag.init(fromBlock)) - -proc slotCollateral*( - market: OnChainMarket, collateralPerSlot: UInt256, slotState: SlotState -): ?!UInt256 {.raises: [].} = - if slotState == SlotState.Repair: - without repairRewardPercentage =? - market.configuration .? collateral .? repairRewardPercentage: - return failure newException( - MarketError, - "Failure calculating the slotCollateral, cannot get the reward percentage", - ) - - return success ( - collateralPerSlot - (collateralPerSlot * repairRewardPercentage.u256).div( - 100.u256 - ) - ) - - return success(collateralPerSlot) - -proc slotCollateral*( - market: OnChainMarket, requestId: RequestId, slotIndex: uint64 -): Future[?!UInt256] {.async: (raises: [CancelledError]).} = - let slotid = slotId(requestId, slotIndex) - - try: - let slotState = await market.slotState(slotid) - - without request =? await market.getRequest(requestId): - return failure newException( - MarketError, "Failure calculating the slotCollateral, cannot get the request" - ) - - return market.slotCollateral(request.ask.collateralPerSlot, slotState) - except MarketError as error: - error "Error when trying to calculate the slotCollateral", error = error.msg - return failure error