From 00a45a7b91166e2023216a3a866d5f84a8afc14c Mon Sep 17 00:00:00 2001 From: kdeme Date: Tue, 11 May 2021 09:59:58 +0200 Subject: [PATCH] Remove inline pragmas --- eth/p2p/blockchain_sync.nim | 2 +- eth/p2p/discoveryv5/encoding.nim | 2 +- eth/p2p/discoveryv5/enr.nim | 2 +- eth/p2p/discoveryv5/protocol.nim | 2 +- eth/p2p/discoveryv5/routing_table.nim | 8 ++++---- eth/p2p/peer_pool.nim | 6 +++--- eth/p2p/rlpx.nim | 12 +++++------- 7 files changed, 16 insertions(+), 18 deletions(-) diff --git a/eth/p2p/blockchain_sync.nim b/eth/p2p/blockchain_sync.nim index 6e7643d..eeb54b4 100644 --- a/eth/p2p/blockchain_sync.nim +++ b/eth/p2p/blockchain_sync.nim @@ -43,7 +43,7 @@ type trustedPeers: HashSet[Peer] hasOutOfOrderBlocks: bool -proc hash*(p: Peer): Hash {.inline.} = hash(cast[pointer](p)) +proc hash*(p: Peer): Hash = hash(cast[pointer](p)) proc endIndex(b: WantedBlocks): BlockNumber = result = b.startIndex diff --git a/eth/p2p/discoveryv5/encoding.nim b/eth/p2p/discoveryv5/encoding.nim index 53dfd2d..41122f4 100644 --- a/eth/p2p/discoveryv5/encoding.nim +++ b/eth/p2p/discoveryv5/encoding.nim @@ -379,7 +379,7 @@ proc decodeMessage*(body: openarray[byte]): DecodeResult[Message] = return err("Invalid request-id") proc decode[T](rlp: var Rlp, v: var T) - {.inline, nimcall, raises:[RlpError, ValueError, Defect].} = + {.nimcall, raises:[RlpError, ValueError, Defect].} = for k, v in v.fieldPairs: v = rlp.read(typeof(v)) diff --git a/eth/p2p/discoveryv5/enr.nim b/eth/p2p/discoveryv5/enr.nim index abcce24..d92de35 100644 --- a/eth/p2p/discoveryv5/enr.nim +++ b/eth/p2p/discoveryv5/enr.nim @@ -468,7 +468,7 @@ proc `$`*(r: Record): string = proc `==`*(a, b: Record): bool = a.raw == b.raw proc read*(rlp: var Rlp, T: typedesc[Record]): - T {.inline, raises:[RlpError, ValueError, Defect].} = + T {.raises: [RlpError, ValueError, Defect].} = if not rlp.hasData() or not result.fromBytes(rlp.rawData): # TODO: This could also just be an invalid signature, would be cleaner to # split of RLP deserialisation errors from this. diff --git a/eth/p2p/discoveryv5/protocol.nim b/eth/p2p/discoveryv5/protocol.nim index ba61f86..8d67910 100644 --- a/eth/p2p/discoveryv5/protocol.nim +++ b/eth/p2p/discoveryv5/protocol.nim @@ -193,7 +193,7 @@ proc neighbours*(d: Protocol, id: NodeId, k: int = BUCKET_SIZE): seq[Node] = ## Return up to k neighbours (closest node ids) of the given node id. d.routingTable.neighbours(id, k) -proc nodesDiscovered*(d: Protocol): int {.inline.} = d.routingTable.len +proc nodesDiscovered*(d: Protocol): int = d.routingTable.len func privKey*(d: Protocol): lent PrivateKey = d.privateKey diff --git a/eth/p2p/discoveryv5/routing_table.nim b/eth/p2p/discoveryv5/routing_table.nim index 9f26531..52b878d 100644 --- a/eth/p2p/discoveryv5/routing_table.nim +++ b/eth/p2p/discoveryv5/routing_table.nim @@ -132,8 +132,8 @@ proc distanceTo(k: KBucket, id: NodeId): UInt256 = k.midpoint xor id proc nodesByDistanceTo(k: KBucket, id: NodeId): seq[Node] = sortedByIt(k.nodes, it.distanceTo(id)) -proc len(k: KBucket): int {.inline.} = k.nodes.len -proc tail(k: KBucket): Node {.inline.} = k.nodes[high(k.nodes)] +proc len(k: KBucket): int = k.nodes.len +proc tail(k: KBucket): Node = k.nodes[high(k.nodes)] proc ipLimitInc(r: var RoutingTable, b: KBucket, n: Node): bool = ## Check if the ip limits of the routing table and the bucket are reached for @@ -194,7 +194,7 @@ proc split(k: KBucket): tuple[lower, upper: KBucket] = doAssert(bucket.ipLimits.inc(node.address.get().ip), "IpLimit increment should work as all buckets have the same limits") -proc inRange(k: KBucket, n: Node): bool {.inline.} = +proc inRange(k: KBucket, n: Node): bool = k.istart <= n.id and n.id <= k.iend proc contains(k: KBucket, n: Node): bool = n in k.nodes @@ -234,7 +234,7 @@ proc computeSharedPrefixBits(nodes: openarray[NodeId]): int = doAssert(false, "Unable to calculate number of shared prefix bits") proc init*(r: var RoutingTable, thisNode: Node, bitsPerHop = DefaultBitsPerHop, - ipLimits = DefaultTableIpLimits, rng: ref BrHmacDrbgContext) {.inline.} = + ipLimits = DefaultTableIpLimits, rng: ref BrHmacDrbgContext) = ## Initialize the routing table for provided `Node` and bitsPerHop value. ## `bitsPerHop` is default set to 5 as recommended by original Kademlia paper. r.thisNode = thisNode diff --git a/eth/p2p/peer_pool.nim b/eth/p2p/peer_pool.nim index 8b516d6..e2fab15 100644 --- a/eth/p2p/peer_pool.nim +++ b/eth/p2p/peer_pool.nim @@ -33,7 +33,7 @@ proc newPeerPool*(network: EthereumNode, result.observers = initTable[int, PeerObserver]() result.listenPort = listenPort -proc nodesToConnect(p: PeerPool): seq[Node] {.inline.} = +proc nodesToConnect(p: PeerPool): seq[Node] = p.discovery.randomNodes(p.minPeers).filterIt(it notin p.discovery.bootstrapNodes) proc addObserver(p: PeerPool, observerId: int, observer: PeerObserver) = @@ -47,10 +47,10 @@ proc addObserver(p: PeerPool, observerId: int, observer: PeerObserver) = proc delObserver(p: PeerPool, observerId: int) = p.observers.del(observerId) -proc addObserver*(p: PeerPool, observerId: ref, observer: PeerObserver) {.inline.} = +proc addObserver*(p: PeerPool, observerId: ref, observer: PeerObserver) = p.addObserver(cast[int](observerId), observer) -proc delObserver*(p: PeerPool, observerId: ref) {.inline.} = +proc delObserver*(p: PeerPool, observerId: ref) = p.delObserver(cast[int](observerId)) template setProtocol*(observer: PeerObserver, Protocol: type) = diff --git a/eth/p2p/rlpx.nim b/eth/p2p/rlpx.nim index 28e6841..21b6201 100644 --- a/eth/p2p/rlpx.nim +++ b/eth/p2p/rlpx.nim @@ -255,8 +255,6 @@ func nameStr*(p: ProtocolInfo): string = result = newStringOfCap(3) for c in p.name: result.add(c) -# XXX: this used to be inline, but inline procs -# cannot be passed to closure params proc cmp*(lhs, rhs: ProtocolInfo): int = for i in 0..2: if lhs.name[i] != rhs.name[i]: @@ -297,7 +295,7 @@ proc registerProtocol(protocol: ProtocolInfo) = # Message composition and encryption # -proc perPeerMsgIdImpl(peer: Peer, proto: ProtocolInfo, msgId: int): int {.inline.} = +proc perPeerMsgIdImpl(peer: Peer, proto: ProtocolInfo, msgId: int): int = result = msgId if not peer.dispatcher.isNil: result += peer.dispatcher.protocolOffsets[proto.index] @@ -306,10 +304,10 @@ template getPeer(peer: Peer): auto = peer template getPeer(responder: ResponderWithId): auto = responder.peer template getPeer(responder: ResponderWithoutId): auto = Peer(responder) -proc supports*(peer: Peer, proto: ProtocolInfo): bool {.inline.} = +proc supports*(peer: Peer, proto: ProtocolInfo): bool = peer.dispatcher.protocolOffsets[proto.index] != -1 -proc supports*(peer: Peer, Protocol: type): bool {.inline.} = +proc supports*(peer: Peer, Protocol: type): bool = ## Checks whether a Peer supports a particular protocol peer.supports(Protocol.protocolInfo) @@ -514,7 +512,7 @@ proc recvMsg*(peer: Peer): Future[tuple[msgId: int, msgData: Rlp]] {.async.} = await peer.disconnectAndRaise(BreachOfProtocol, "Cannot read RLPx message id") -proc checkedRlpRead(peer: Peer, r: var Rlp, MsgType: type): auto {.inline.} = +proc checkedRlpRead(peer: Peer, r: var Rlp, MsgType: type): auto = when defined(release): return r.read(MsgType) else: @@ -947,7 +945,7 @@ proc validatePubKeyInHello(msg: DevP2P.hello, pubKey: PublicKey): bool = let pk = PublicKey.fromRaw(msg.nodeId) pk.isOk and pk[] == pubKey -proc checkUselessPeer(peer: Peer) {.inline.} = +proc checkUselessPeer(peer: Peer) = if peer.dispatcher.numProtocols == 0: # XXX: Send disconnect + UselessPeer raise newException(UselessPeerError, "Useless peer")