mirror of https://github.com/status-im/nim-eth.git
Changes required for the latest ETH2 spec
This commit is contained in:
parent
3e1ce94961
commit
1fe3de6c39
|
@ -59,7 +59,7 @@ type
|
||||||
version*: int
|
version*: int
|
||||||
timeouts*: int64
|
timeouts*: int64
|
||||||
useRequestIds*: bool
|
useRequestIds*: bool
|
||||||
shortName*: string
|
rlpxName*: string
|
||||||
outgoingRequestDecorator*: NimNode
|
outgoingRequestDecorator*: NimNode
|
||||||
incomingRequestDecorator*: NimNode
|
incomingRequestDecorator*: NimNode
|
||||||
incomingRequestThunkDecorator*: NimNode
|
incomingRequestThunkDecorator*: NimNode
|
||||||
|
@ -219,7 +219,7 @@ proc processProtocolBody*(p: P2PProtocol, protocolBody: NimNode)
|
||||||
|
|
||||||
proc init*(T: type P2PProtocol, backendFactory: BackendFactory,
|
proc init*(T: type P2PProtocol, backendFactory: BackendFactory,
|
||||||
name: string, version: int, body: NimNode,
|
name: string, version: int, body: NimNode,
|
||||||
timeouts: int64, useRequestIds: bool, shortName: string,
|
timeouts: int64, useRequestIds: bool, rlpxName: string,
|
||||||
outgoingRequestDecorator: NimNode,
|
outgoingRequestDecorator: NimNode,
|
||||||
incomingRequestDecorator: NimNode,
|
incomingRequestDecorator: NimNode,
|
||||||
incomingRequestThunkDecorator: NimNode,
|
incomingRequestThunkDecorator: NimNode,
|
||||||
|
@ -232,7 +232,7 @@ proc init*(T: type P2PProtocol, backendFactory: BackendFactory,
|
||||||
version: version,
|
version: version,
|
||||||
timeouts: timeouts,
|
timeouts: timeouts,
|
||||||
useRequestIds: useRequestIds,
|
useRequestIds: useRequestIds,
|
||||||
shortName: shortName,
|
rlpxName: rlpxName,
|
||||||
outgoingRequestDecorator: outgoingRequestDecorator,
|
outgoingRequestDecorator: outgoingRequestDecorator,
|
||||||
incomingRequestDecorator: incomingRequestDecorator,
|
incomingRequestDecorator: incomingRequestDecorator,
|
||||||
incomingRequestThunkDecorator: incomingRequestThunkDecorator,
|
incomingRequestThunkDecorator: incomingRequestThunkDecorator,
|
||||||
|
@ -510,18 +510,21 @@ proc writeParamsAsRecord*(params: openarray[NimNode],
|
||||||
var
|
var
|
||||||
appendParams = newStmtList()
|
appendParams = newStmtList()
|
||||||
writeField = ident "writeField"
|
writeField = ident "writeField"
|
||||||
|
recordWriterCtx = ident "recordWriterCtx"
|
||||||
writer = ident "writer"
|
writer = ident "writer"
|
||||||
|
|
||||||
for param in params:
|
for param in params:
|
||||||
appendParams.add newCall(writeField, writer, newLit($param), param)
|
appendParams.add newCall(writeField,
|
||||||
|
writer, recordWriterCtx,
|
||||||
|
newLit($param), param)
|
||||||
|
|
||||||
result = quote do:
|
result = quote do:
|
||||||
mixin init, writerType, beginRecord, endRecord
|
mixin init, writerType, beginRecord, endRecord
|
||||||
|
|
||||||
var `writer` = init(WriterType(`Format`), `outputStream`)
|
var `writer` = init(WriterType(`Format`), `outputStream`)
|
||||||
var recordStartMemo = beginRecord(`writer`, `RecordType`)
|
var `recordWriterCtx` = beginRecord(`writer`, `RecordType`)
|
||||||
`appendParams`
|
`appendParams`
|
||||||
endRecord(`writer`, recordStartMemo)
|
endRecord(`writer`, `recordWriterCtx`)
|
||||||
|
|
||||||
proc useStandardBody*(sendProc: SendProc,
|
proc useStandardBody*(sendProc: SendProc,
|
||||||
preSerializationStep: proc(stream: NimNode): NimNode,
|
preSerializationStep: proc(stream: NimNode): NimNode,
|
||||||
|
@ -839,7 +842,7 @@ macro emitForSingleBackend(
|
||||||
# TODO Nim can't handle a proper duration paramter here
|
# TODO Nim can't handle a proper duration paramter here
|
||||||
timeouts: static[int64] = defaultReqTimeout.milliseconds,
|
timeouts: static[int64] = defaultReqTimeout.milliseconds,
|
||||||
useRequestIds: static[bool] = true,
|
useRequestIds: static[bool] = true,
|
||||||
shortName: static[string] = "",
|
rlpxName: static[string] = "",
|
||||||
outgoingRequestDecorator: untyped = nil,
|
outgoingRequestDecorator: untyped = nil,
|
||||||
incomingRequestDecorator: untyped = nil,
|
incomingRequestDecorator: untyped = nil,
|
||||||
incomingRequestThunkDecorator: untyped = nil,
|
incomingRequestThunkDecorator: untyped = nil,
|
||||||
|
@ -851,7 +854,7 @@ macro emitForSingleBackend(
|
||||||
var p = P2PProtocol.init(
|
var p = P2PProtocol.init(
|
||||||
backend,
|
backend,
|
||||||
name, version, body, timeouts,
|
name, version, body, timeouts,
|
||||||
useRequestIds, shortName,
|
useRequestIds, rlpxName,
|
||||||
outgoingRequestDecorator,
|
outgoingRequestDecorator,
|
||||||
incomingRequestDecorator,
|
incomingRequestDecorator,
|
||||||
incomingRequestThunkDecorator,
|
incomingRequestThunkDecorator,
|
||||||
|
|
|
@ -579,9 +579,9 @@ proc p2pProtocolBackendImpl*(protocol: P2PProtocol): Backend =
|
||||||
|
|
||||||
isSubprotocol = protocol.version > 0
|
isSubprotocol = protocol.version > 0
|
||||||
|
|
||||||
if protocol.shortName.len == 0: protocol.shortName = protocol.name
|
if protocol.rlpxName.len == 0: protocol.rlpxName = protocol.name
|
||||||
# By convention, all Ethereum protocol names must be abbreviated to 3 letters
|
# By convention, all Ethereum protocol names must be abbreviated to 3 letters
|
||||||
doAssert protocol.shortName.len == 3
|
doAssert protocol.rlpxName.len == 3
|
||||||
|
|
||||||
new result
|
new result
|
||||||
|
|
||||||
|
@ -765,11 +765,11 @@ proc p2pProtocolBackendImpl*(protocol: P2PProtocol): Backend =
|
||||||
|
|
||||||
result.implementProtocolInit = proc (protocol: P2PProtocol): NimNode =
|
result.implementProtocolInit = proc (protocol: P2PProtocol): NimNode =
|
||||||
return newCall(initProtocol,
|
return newCall(initProtocol,
|
||||||
newLit(protocol.shortName),
|
newLit(protocol.rlpxName),
|
||||||
newLit(protocol.version),
|
newLit(protocol.version),
|
||||||
protocol.peerInit, protocol.netInit)
|
protocol.peerInit, protocol.netInit)
|
||||||
|
|
||||||
p2pProtocol devp2p(version = 0, shortName = "p2p"):
|
p2pProtocol devp2p(version = 0, rlpxName = "p2p"):
|
||||||
proc hello(peer: Peer,
|
proc hello(peer: Peer,
|
||||||
version: uint,
|
version: uint,
|
||||||
clientId: string,
|
clientId: string,
|
||||||
|
|
|
@ -359,7 +359,7 @@ when defined(testing):
|
||||||
proc isMax(s: FlowControlState): bool =
|
proc isMax(s: FlowControlState): bool =
|
||||||
s.bufValue == s.bufLimit
|
s.bufValue == s.bufLimit
|
||||||
|
|
||||||
p2pProtocol dummyLes(version = 1, shortName = "abc"):
|
p2pProtocol dummyLes(version = 1, rlpxName = "abc"):
|
||||||
proc a(p: Peer)
|
proc a(p: Peer)
|
||||||
proc b(p: Peer)
|
proc b(p: Peer)
|
||||||
proc c(p: Peer)
|
proc c(p: Peer)
|
||||||
|
|
|
@ -725,7 +725,7 @@ proc initProtocolState*(network: WhisperNetwork, node: EthereumNode) {.gcsafe.}
|
||||||
asyncCheck node.run(network)
|
asyncCheck node.run(network)
|
||||||
|
|
||||||
p2pProtocol Whisper(version = whisperVersion,
|
p2pProtocol Whisper(version = whisperVersion,
|
||||||
shortName = "shh",
|
rlpxName = "shh",
|
||||||
peerState = WhisperPeer,
|
peerState = WhisperPeer,
|
||||||
networkState = WhisperNetwork):
|
networkState = WhisperNetwork):
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ type
|
||||||
count*: int
|
count*: int
|
||||||
|
|
||||||
p2pProtocol abc(version = 1,
|
p2pProtocol abc(version = 1,
|
||||||
shortName = "abc",
|
rlpxName = "abc",
|
||||||
networkState = network):
|
networkState = network):
|
||||||
|
|
||||||
onPeerConnected do (peer: Peer):
|
onPeerConnected do (peer: Peer):
|
||||||
|
@ -28,7 +28,7 @@ p2pProtocol abc(version = 1,
|
||||||
raise newException(CatchableError, "Fake abc exception")
|
raise newException(CatchableError, "Fake abc exception")
|
||||||
|
|
||||||
p2pProtocol xyz(version = 1,
|
p2pProtocol xyz(version = 1,
|
||||||
shortName = "xyz",
|
rlpxName = "xyz",
|
||||||
networkState = network):
|
networkState = network):
|
||||||
|
|
||||||
onPeerConnected do (peer: Peer):
|
onPeerConnected do (peer: Peer):
|
||||||
|
@ -40,7 +40,7 @@ p2pProtocol xyz(version = 1,
|
||||||
raise newException(CatchableError, "Fake xyz exception")
|
raise newException(CatchableError, "Fake xyz exception")
|
||||||
|
|
||||||
p2pProtocol hah(version = 1,
|
p2pProtocol hah(version = 1,
|
||||||
shortName = "hah",
|
rlpxName = "hah",
|
||||||
networkState = network):
|
networkState = network):
|
||||||
|
|
||||||
onPeerConnected do (peer: Peer):
|
onPeerConnected do (peer: Peer):
|
||||||
|
|
Loading…
Reference in New Issue