From 7aa922b90f0cc3bae66a14785b48255ffba0679e Mon Sep 17 00:00:00 2001 From: gmega Date: Thu, 18 Jan 2024 19:23:11 -0300 Subject: [PATCH] change signatures to async and add raw: true --- codex/blockexchange/engine/engine.nim | 2 +- codex/blockexchange/network/network.nim | 40 ++++++++++----------- codex/blockexchange/network/networkpeer.nim | 4 +-- codex/chunker.nim | 2 +- codex/discovery.nim | 2 +- codex/node.nim | 2 +- codex/sales/salescontext.nim | 13 ++++--- tests/codex/helpers/mockchunker.nim | 10 +++--- tests/codex/helpers/mockdiscovery.nim | 8 ++--- 9 files changed, 41 insertions(+), 42 deletions(-) diff --git a/codex/blockexchange/engine/engine.nim b/codex/blockexchange/engine/engine.nim index dacc7aa9..de4764ab 100644 --- a/codex/blockexchange/engine/engine.nim +++ b/codex/blockexchange/engine/engine.nim @@ -83,7 +83,7 @@ type proc scheduleTask(b: BlockExcEngine, task: BlockExcPeerCtx): bool {.gcsafe} = b.taskQueue.pushOrUpdateNoWait(task).isOk() -proc blockexcTaskRunner(b: BlockExcEngine): Future[void] {.gcsafe, raises: [].} +proc blockexcTaskRunner(b: BlockExcEngine): Future[void] {.gcsafe, async.} proc start*(b: BlockExcEngine) {.async.} = ## Start the blockexc task diff --git a/codex/blockexchange/network/network.nim b/codex/blockexchange/network/network.nim index e829993d..c2a648d3 100644 --- a/codex/blockexchange/network/network.nim +++ b/codex/blockexchange/network/network.nim @@ -34,11 +34,11 @@ const MaxInflight* = 100 type - WantListHandler* = proc(peer: PeerId, wantList: WantList): Future[void] {.gcsafe, raises: [].} - BlocksDeliveryHandler* = proc(peer: PeerId, blocks: seq[BlockDelivery]): Future[void] {.gcsafe, raises: [].} - BlockPresenceHandler* = proc(peer: PeerId, precense: seq[BlockPresence]): Future[void] {.gcsafe, raises: [].} - AccountHandler* = proc(peer: PeerId, account: Account): Future[void] {.gcsafe, raises: [].} - PaymentHandler* = proc(peer: PeerId, payment: SignedState): Future[void] {.gcsafe, raises: [].} + WantListHandler* = proc(peer: PeerId, wantList: WantList): Future[void] {.gcsafe, async.} + BlocksDeliveryHandler* = proc(peer: PeerId, blocks: seq[BlockDelivery]): Future[void] {.gcsafe, async.} + BlockPresenceHandler* = proc(peer: PeerId, precense: seq[BlockPresence]): Future[void] {.gcsafe, async.} + AccountHandler* = proc(peer: PeerId, account: Account): Future[void] {.gcsafe, async.} + PaymentHandler* = proc(peer: PeerId, payment: SignedState): Future[void] {.gcsafe, async.} WantListSender* = proc( id: PeerId, addresses: seq[BlockAddress], @@ -46,7 +46,7 @@ type cancel: bool = false, wantType: WantType = WantType.WantHave, full: bool = false, - sendDontHave: bool = false): Future[void] {.gcsafe, raises: [].} + sendDontHave: bool = false): Future[void] {.gcsafe, async.} BlockExcHandlers* = object onWantList*: WantListHandler @@ -55,10 +55,10 @@ type onAccount*: AccountHandler onPayment*: PaymentHandler - BlocksDeliverySender* = proc(peer: PeerId, blocksDelivery: seq[BlockDelivery]): Future[void] {.gcsafe, raises: [].} - PresenceSender* = proc(peer: PeerId, presence: seq[BlockPresence]): Future[void] {.gcsafe, raises: [].} - AccountSender* = proc(peer: PeerId, account: Account): Future[void] {.gcsafe, raises: [].} - PaymentSender* = proc(peer: PeerId, payment: SignedState): Future[void] {.gcsafe, raises: [].} + BlocksDeliverySender* = proc(peer: PeerId, blocksDelivery: seq[BlockDelivery]): Future[void] {.gcsafe, async.} + PresenceSender* = proc(peer: PeerId, presence: seq[BlockPresence]): Future[void] {.gcsafe, async.} + AccountSender* = proc(peer: PeerId, account: Account): Future[void] {.gcsafe, async.} + PaymentSender* = proc(peer: PeerId, payment: SignedState): Future[void] {.gcsafe, async.} BlockExcRequest* = object sendWantList*: WantListSender @@ -122,7 +122,7 @@ proc sendWantList*( cancel: bool = false, wantType: WantType = WantType.WantHave, full: bool = false, - sendDontHave: bool = false): Future[void] = + sendDontHave: bool = false): Future[void] {.async: (raw: true).}= ## Send a want message to peer ## @@ -154,7 +154,7 @@ proc handleBlocksDelivery( proc sendBlocksDelivery*( b: BlockExcNetwork, id: PeerId, - blocksDelivery: seq[BlockDelivery]): Future[void] = + blocksDelivery: seq[BlockDelivery]): Future[void] {.async: (raw: true).} = ## Send blocks to remote ## @@ -174,7 +174,7 @@ proc handleBlockPresence( proc sendBlockPresence*( b: BlockExcNetwork, id: PeerId, - presence: seq[BlockPresence]): Future[void] = + presence: seq[BlockPresence]): Future[void] {.async: (raw: true).} = ## Send presence to remote ## @@ -193,7 +193,7 @@ proc handleAccount( proc sendAccount*( b: BlockExcNetwork, id: PeerId, - account: Account): Future[void] = + account: Account): Future[void] {.async: (raw: true).} = ## Send account info to remote ## @@ -202,7 +202,7 @@ proc sendAccount*( proc sendPayment*( b: BlockExcNetwork, id: PeerId, - payment: SignedState): Future[void] = + payment: SignedState): Future[void] {.async: (raw: true).} = ## Send payment to remote ## @@ -259,7 +259,7 @@ proc getOrCreatePeer(b: BlockExcNetwork, peer: PeerId): NetworkPeer = if not isNil(b.getConn): getConn = b.getConn - let rpcHandler = proc (p: NetworkPeer, msg: Message): Future[void] = + let rpcHandler = proc (p: NetworkPeer, msg: Message): Future[void] {.async: (raw: true).}= b.rpcHandler(p, msg) # create new pubsub peer @@ -340,16 +340,16 @@ proc new*( id, cids, priority, cancel, wantType, full, sendDontHave) - proc sendBlocksDelivery(id: PeerId, blocksDelivery: seq[BlockDelivery]): Future[void] {.gcsafe.} = + proc sendBlocksDelivery(id: PeerId, blocksDelivery: seq[BlockDelivery]): Future[void] {.gcsafe, async: (raw: true).} = self.sendBlocksDelivery(id, blocksDelivery) - proc sendPresence(id: PeerId, presence: seq[BlockPresence]): Future[void] {.gcsafe.} = + proc sendPresence(id: PeerId, presence: seq[BlockPresence]): Future[void] {.gcsafe, async: (raw: true).} = self.sendBlockPresence(id, presence) - proc sendAccount(id: PeerId, account: Account): Future[void] {.gcsafe.} = + proc sendAccount(id: PeerId, account: Account): Future[void] {.gcsafe, async: (raw: true).} = self.sendAccount(id, account) - proc sendPayment(id: PeerId, payment: SignedState): Future[void] {.gcsafe.} = + proc sendPayment(id: PeerId, payment: SignedState): Future[void] {.gcsafe, async: (raw: true).} = self.sendPayment(id, payment) self.request = BlockExcRequest( diff --git a/codex/blockexchange/network/networkpeer.nim b/codex/blockexchange/network/networkpeer.nim index a13ba92a..fa303db2 100644 --- a/codex/blockexchange/network/networkpeer.nim +++ b/codex/blockexchange/network/networkpeer.nim @@ -22,9 +22,9 @@ logScope: topics = "codex blockexcnetworkpeer" type - ConnProvider* = proc (): Future[Connection] {.gcsafe, closure, raises: [].} + ConnProvider* = proc (): Future[Connection] {.gcsafe, closure, async.} - RPCHandler* = proc (peer: NetworkPeer, msg: Message): Future[void] {.gcsafe, raises: [].} + RPCHandler* = proc (peer: NetworkPeer, msg: Message): Future[void] {.gcsafe, async.} NetworkPeer* = ref object of RootObj id*: PeerId diff --git a/codex/chunker.nim b/codex/chunker.nim index 36f28f7a..420718f9 100644 --- a/codex/chunker.nim +++ b/codex/chunker.nim @@ -29,7 +29,7 @@ const type # default reader type ChunkBuffer* = ptr UncheckedArray[byte] - Reader* = proc(data: ChunkBuffer, len: int): Future[int] {.gcsafe, raises: [Defect].} + Reader* = proc(data: ChunkBuffer, len: int): Future[int] {.gcsafe, async.} # Reader that splits input data into fixed-size chunks Chunker* = ref object diff --git a/codex/discovery.nim b/codex/discovery.nim index 477a4bae..6c2a21b7 100644 --- a/codex/discovery.nim +++ b/codex/discovery.nim @@ -129,7 +129,7 @@ method provide*(d: Discovery, host: ca.Address) {.async, base.} = method removeProvider*( d: Discovery, - peerId: PeerId): Future[void] {.base, raises: [].} = + peerId: PeerId): Future[void] {.base, async: (raw: true).} = ## Remove provider from providers table ## diff --git a/codex/node.nim b/codex/node.nim index e3c6baca..2e7b7b01 100644 --- a/codex/node.nim +++ b/codex/node.nim @@ -70,7 +70,7 @@ type CodexNodeRef* = ref CodexNode OnManifest* = proc(cid: Cid, manifest: Manifest): void {.gcsafe, raises: [].} - BatchProc* = proc(blocks: seq[bt.Block]): Future[?!void] {.gcsafe, raises: [].} + BatchProc* = proc(blocks: seq[bt.Block]): Future[?!void] {.gcsafe, async.} func switch*(self: CodexNodeRef): Switch = return self.switch diff --git a/codex/sales/salescontext.nim b/codex/sales/salescontext.nim index 0c209db7..9798b4b6 100644 --- a/codex/sales/salescontext.nim +++ b/codex/sales/salescontext.nim @@ -1,6 +1,5 @@ import pkg/questionable import pkg/questionable/results -import pkg/upraises import ../market import ../clock @@ -23,13 +22,13 @@ type slotQueue*: SlotQueue simulateProofFailures*: int - BlocksCb* = proc(blocks: seq[bt.Block]): Future[?!void] {.gcsafe, raises: [].} + BlocksCb* = proc(blocks: seq[bt.Block]): Future[?!void] {.gcsafe, async.} OnStore* = proc(request: StorageRequest, slot: UInt256, - blocksCb: BlocksCb): Future[?!void] {.gcsafe, upraises: [].} - OnProve* = proc(slot: Slot, challenge: ProofChallenge): Future[?!seq[byte]] {.gcsafe, upraises: [].} - OnExpiryUpdate* = proc(rootCid: string, expiry: SecondsSince1970): Future[?!void] {.gcsafe, upraises: [].} + blocksCb: BlocksCb): Future[?!void] {.gcsafe, async.} + OnProve* = proc(slot: Slot, challenge: ProofChallenge): Future[seq[byte]] {.gcsafe, async.} + OnExpiryUpdate* = proc(rootCid: string, expiry: SecondsSince1970): Future[?!void] {.gcsafe, async.} OnClear* = proc(request: StorageRequest, - slotIndex: UInt256) {.gcsafe, upraises: [].} + slotIndex: UInt256) {.gcsafe, raises: [].} OnSale* = proc(request: StorageRequest, - slotIndex: UInt256) {.gcsafe, upraises: [].} + slotIndex: UInt256) {.gcsafe, raises: [].} diff --git a/tests/codex/helpers/mockchunker.nim b/tests/codex/helpers/mockchunker.nim index acbe7ab6..77370a3c 100644 --- a/tests/codex/helpers/mockchunker.nim +++ b/tests/codex/helpers/mockchunker.nim @@ -19,23 +19,23 @@ proc new*( ## Create a chunker that produces data ## - let + let chunkSize = chunkSize.NBytes dataset = @dataset - + var consumed = 0 - proc reader(data: ChunkBuffer, len: int): Future[int] {.async, gcsafe, raises: [Defect].} = + proc reader(data: ChunkBuffer, len: int): Future[int] {.async, gcsafe.} = if consumed >= dataset.len: return 0 var read = 0 - while read < len and + while read < len and read < chunkSize.int and (consumed + read) < dataset.len: data[read] = dataset[consumed + read] read.inc - + consumed += read return read diff --git a/tests/codex/helpers/mockdiscovery.nim b/tests/codex/helpers/mockdiscovery.nim index f6ebdf7f..3c79d088 100644 --- a/tests/codex/helpers/mockdiscovery.nim +++ b/tests/codex/helpers/mockdiscovery.nim @@ -16,13 +16,13 @@ import pkg/contractabi/address as ca type MockDiscovery* = ref object of Discovery findBlockProvidersHandler*: proc(d: MockDiscovery, cid: Cid): - Future[seq[SignedPeerRecord]] {.gcsafe, raises: [].} + Future[seq[SignedPeerRecord]] {.gcsafe, async.} publishBlockProvideHandler*: proc(d: MockDiscovery, cid: Cid): - Future[void] {.gcsafe, raises: [].} + Future[void] {.gcsafe, async.} findHostProvidersHandler*: proc(d: MockDiscovery, host: ca.Address): - Future[seq[SignedPeerRecord]] {.gcsafe, raises: [].} + Future[seq[SignedPeerRecord]] {.gcsafe, async.} publishHostProvideHandler*: proc(d: MockDiscovery, host: ca.Address): - Future[void] {.gcsafe, raises: [].} + Future[void] {.gcsafe, async.} proc new*(T: type MockDiscovery): MockDiscovery = MockDiscovery()