change signatures to async and add raw: true

This commit is contained in:
gmega 2024-01-18 19:23:11 -03:00
parent ec9a9125d3
commit 7aa922b90f
No known key found for this signature in database
GPG Key ID: FFD8DAF00660270F
9 changed files with 41 additions and 42 deletions

View File

@ -83,7 +83,7 @@ type
proc scheduleTask(b: BlockExcEngine, task: BlockExcPeerCtx): bool {.gcsafe} = proc scheduleTask(b: BlockExcEngine, task: BlockExcPeerCtx): bool {.gcsafe} =
b.taskQueue.pushOrUpdateNoWait(task).isOk() 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.} = proc start*(b: BlockExcEngine) {.async.} =
## Start the blockexc task ## Start the blockexc task

View File

@ -34,11 +34,11 @@ const
MaxInflight* = 100 MaxInflight* = 100
type type
WantListHandler* = proc(peer: PeerId, wantList: WantList): Future[void] {.gcsafe, raises: [].} WantListHandler* = proc(peer: PeerId, wantList: WantList): Future[void] {.gcsafe, async.}
BlocksDeliveryHandler* = proc(peer: PeerId, blocks: seq[BlockDelivery]): Future[void] {.gcsafe, raises: [].} BlocksDeliveryHandler* = proc(peer: PeerId, blocks: seq[BlockDelivery]): Future[void] {.gcsafe, async.}
BlockPresenceHandler* = proc(peer: PeerId, precense: seq[BlockPresence]): Future[void] {.gcsafe, raises: [].} BlockPresenceHandler* = proc(peer: PeerId, precense: seq[BlockPresence]): Future[void] {.gcsafe, async.}
AccountHandler* = proc(peer: PeerId, account: Account): Future[void] {.gcsafe, raises: [].} AccountHandler* = proc(peer: PeerId, account: Account): Future[void] {.gcsafe, async.}
PaymentHandler* = proc(peer: PeerId, payment: SignedState): Future[void] {.gcsafe, raises: [].} PaymentHandler* = proc(peer: PeerId, payment: SignedState): Future[void] {.gcsafe, async.}
WantListSender* = proc( WantListSender* = proc(
id: PeerId, id: PeerId,
addresses: seq[BlockAddress], addresses: seq[BlockAddress],
@ -46,7 +46,7 @@ type
cancel: bool = false, cancel: bool = false,
wantType: WantType = WantType.WantHave, wantType: WantType = WantType.WantHave,
full: bool = false, full: bool = false,
sendDontHave: bool = false): Future[void] {.gcsafe, raises: [].} sendDontHave: bool = false): Future[void] {.gcsafe, async.}
BlockExcHandlers* = object BlockExcHandlers* = object
onWantList*: WantListHandler onWantList*: WantListHandler
@ -55,10 +55,10 @@ type
onAccount*: AccountHandler onAccount*: AccountHandler
onPayment*: PaymentHandler onPayment*: PaymentHandler
BlocksDeliverySender* = proc(peer: PeerId, blocksDelivery: seq[BlockDelivery]): 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, raises: [].} PresenceSender* = proc(peer: PeerId, presence: seq[BlockPresence]): Future[void] {.gcsafe, async.}
AccountSender* = proc(peer: PeerId, account: Account): Future[void] {.gcsafe, raises: [].} AccountSender* = proc(peer: PeerId, account: Account): Future[void] {.gcsafe, async.}
PaymentSender* = proc(peer: PeerId, payment: SignedState): Future[void] {.gcsafe, raises: [].} PaymentSender* = proc(peer: PeerId, payment: SignedState): Future[void] {.gcsafe, async.}
BlockExcRequest* = object BlockExcRequest* = object
sendWantList*: WantListSender sendWantList*: WantListSender
@ -122,7 +122,7 @@ proc sendWantList*(
cancel: bool = false, cancel: bool = false,
wantType: WantType = WantType.WantHave, wantType: WantType = WantType.WantHave,
full: bool = false, full: bool = false,
sendDontHave: bool = false): Future[void] = sendDontHave: bool = false): Future[void] {.async: (raw: true).}=
## Send a want message to peer ## Send a want message to peer
## ##
@ -154,7 +154,7 @@ proc handleBlocksDelivery(
proc sendBlocksDelivery*( proc sendBlocksDelivery*(
b: BlockExcNetwork, b: BlockExcNetwork,
id: PeerId, id: PeerId,
blocksDelivery: seq[BlockDelivery]): Future[void] = blocksDelivery: seq[BlockDelivery]): Future[void] {.async: (raw: true).} =
## Send blocks to remote ## Send blocks to remote
## ##
@ -174,7 +174,7 @@ proc handleBlockPresence(
proc sendBlockPresence*( proc sendBlockPresence*(
b: BlockExcNetwork, b: BlockExcNetwork,
id: PeerId, id: PeerId,
presence: seq[BlockPresence]): Future[void] = presence: seq[BlockPresence]): Future[void] {.async: (raw: true).} =
## Send presence to remote ## Send presence to remote
## ##
@ -193,7 +193,7 @@ proc handleAccount(
proc sendAccount*( proc sendAccount*(
b: BlockExcNetwork, b: BlockExcNetwork,
id: PeerId, id: PeerId,
account: Account): Future[void] = account: Account): Future[void] {.async: (raw: true).} =
## Send account info to remote ## Send account info to remote
## ##
@ -202,7 +202,7 @@ proc sendAccount*(
proc sendPayment*( proc sendPayment*(
b: BlockExcNetwork, b: BlockExcNetwork,
id: PeerId, id: PeerId,
payment: SignedState): Future[void] = payment: SignedState): Future[void] {.async: (raw: true).} =
## Send payment to remote ## Send payment to remote
## ##
@ -259,7 +259,7 @@ proc getOrCreatePeer(b: BlockExcNetwork, peer: PeerId): NetworkPeer =
if not isNil(b.getConn): if not isNil(b.getConn):
getConn = 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) b.rpcHandler(p, msg)
# create new pubsub peer # create new pubsub peer
@ -340,16 +340,16 @@ proc new*(
id, cids, priority, cancel, id, cids, priority, cancel,
wantType, full, sendDontHave) 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) 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) 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) 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.sendPayment(id, payment)
self.request = BlockExcRequest( self.request = BlockExcRequest(

View File

@ -22,9 +22,9 @@ logScope:
topics = "codex blockexcnetworkpeer" topics = "codex blockexcnetworkpeer"
type 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 NetworkPeer* = ref object of RootObj
id*: PeerId id*: PeerId

View File

@ -29,7 +29,7 @@ const
type type
# default reader type # default reader type
ChunkBuffer* = ptr UncheckedArray[byte] 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 # Reader that splits input data into fixed-size chunks
Chunker* = ref object Chunker* = ref object

View File

@ -129,7 +129,7 @@ method provide*(d: Discovery, host: ca.Address) {.async, base.} =
method removeProvider*( method removeProvider*(
d: Discovery, d: Discovery,
peerId: PeerId): Future[void] {.base, raises: [].} = peerId: PeerId): Future[void] {.base, async: (raw: true).} =
## Remove provider from providers table ## Remove provider from providers table
## ##

View File

@ -70,7 +70,7 @@ type
CodexNodeRef* = ref CodexNode CodexNodeRef* = ref CodexNode
OnManifest* = proc(cid: Cid, manifest: Manifest): void {.gcsafe, raises: [].} 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 = func switch*(self: CodexNodeRef): Switch =
return self.switch return self.switch

View File

@ -1,6 +1,5 @@
import pkg/questionable import pkg/questionable
import pkg/questionable/results import pkg/questionable/results
import pkg/upraises
import ../market import ../market
import ../clock import ../clock
@ -23,13 +22,13 @@ type
slotQueue*: SlotQueue slotQueue*: SlotQueue
simulateProofFailures*: int 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, OnStore* = proc(request: StorageRequest,
slot: UInt256, slot: UInt256,
blocksCb: BlocksCb): Future[?!void] {.gcsafe, upraises: [].} blocksCb: BlocksCb): Future[?!void] {.gcsafe, async.}
OnProve* = proc(slot: Slot, challenge: ProofChallenge): Future[?!seq[byte]] {.gcsafe, upraises: [].} OnProve* = proc(slot: Slot, challenge: ProofChallenge): Future[seq[byte]] {.gcsafe, async.}
OnExpiryUpdate* = proc(rootCid: string, expiry: SecondsSince1970): Future[?!void] {.gcsafe, upraises: [].} OnExpiryUpdate* = proc(rootCid: string, expiry: SecondsSince1970): Future[?!void] {.gcsafe, async.}
OnClear* = proc(request: StorageRequest, OnClear* = proc(request: StorageRequest,
slotIndex: UInt256) {.gcsafe, upraises: [].} slotIndex: UInt256) {.gcsafe, raises: [].}
OnSale* = proc(request: StorageRequest, OnSale* = proc(request: StorageRequest,
slotIndex: UInt256) {.gcsafe, upraises: [].} slotIndex: UInt256) {.gcsafe, raises: [].}

View File

@ -19,23 +19,23 @@ proc new*(
## Create a chunker that produces data ## Create a chunker that produces data
## ##
let let
chunkSize = chunkSize.NBytes chunkSize = chunkSize.NBytes
dataset = @dataset dataset = @dataset
var consumed = 0 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: if consumed >= dataset.len:
return 0 return 0
var read = 0 var read = 0
while read < len and while read < len and
read < chunkSize.int and read < chunkSize.int and
(consumed + read) < dataset.len: (consumed + read) < dataset.len:
data[read] = dataset[consumed + read] data[read] = dataset[consumed + read]
read.inc read.inc
consumed += read consumed += read
return read return read

View File

@ -16,13 +16,13 @@ import pkg/contractabi/address as ca
type type
MockDiscovery* = ref object of Discovery MockDiscovery* = ref object of Discovery
findBlockProvidersHandler*: proc(d: MockDiscovery, cid: Cid): findBlockProvidersHandler*: proc(d: MockDiscovery, cid: Cid):
Future[seq[SignedPeerRecord]] {.gcsafe, raises: [].} Future[seq[SignedPeerRecord]] {.gcsafe, async.}
publishBlockProvideHandler*: proc(d: MockDiscovery, cid: Cid): publishBlockProvideHandler*: proc(d: MockDiscovery, cid: Cid):
Future[void] {.gcsafe, raises: [].} Future[void] {.gcsafe, async.}
findHostProvidersHandler*: proc(d: MockDiscovery, host: ca.Address): findHostProvidersHandler*: proc(d: MockDiscovery, host: ca.Address):
Future[seq[SignedPeerRecord]] {.gcsafe, raises: [].} Future[seq[SignedPeerRecord]] {.gcsafe, async.}
publishHostProvideHandler*: proc(d: MockDiscovery, host: ca.Address): publishHostProvideHandler*: proc(d: MockDiscovery, host: ca.Address):
Future[void] {.gcsafe, raises: [].} Future[void] {.gcsafe, async.}
proc new*(T: type MockDiscovery): MockDiscovery = proc new*(T: type MockDiscovery): MockDiscovery =
MockDiscovery() MockDiscovery()