Changes required for the latest ETH2 spec

This commit is contained in:
Zahary Karadjov 2019-08-05 16:31:51 +03:00
parent 3e1ce94961
commit 1fe3de6c39
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
5 changed files with 20 additions and 17 deletions

View File

@ -59,7 +59,7 @@ type
version*: int
timeouts*: int64
useRequestIds*: bool
shortName*: string
rlpxName*: string
outgoingRequestDecorator*: NimNode
incomingRequestDecorator*: NimNode
incomingRequestThunkDecorator*: NimNode
@ -219,7 +219,7 @@ proc processProtocolBody*(p: P2PProtocol, protocolBody: NimNode)
proc init*(T: type P2PProtocol, backendFactory: BackendFactory,
name: string, version: int, body: NimNode,
timeouts: int64, useRequestIds: bool, shortName: string,
timeouts: int64, useRequestIds: bool, rlpxName: string,
outgoingRequestDecorator: NimNode,
incomingRequestDecorator: NimNode,
incomingRequestThunkDecorator: NimNode,
@ -232,7 +232,7 @@ proc init*(T: type P2PProtocol, backendFactory: BackendFactory,
version: version,
timeouts: timeouts,
useRequestIds: useRequestIds,
shortName: shortName,
rlpxName: rlpxName,
outgoingRequestDecorator: outgoingRequestDecorator,
incomingRequestDecorator: incomingRequestDecorator,
incomingRequestThunkDecorator: incomingRequestThunkDecorator,
@ -510,18 +510,21 @@ proc writeParamsAsRecord*(params: openarray[NimNode],
var
appendParams = newStmtList()
writeField = ident "writeField"
recordWriterCtx = ident "recordWriterCtx"
writer = ident "writer"
for param in params:
appendParams.add newCall(writeField, writer, newLit($param), param)
appendParams.add newCall(writeField,
writer, recordWriterCtx,
newLit($param), param)
result = quote do:
mixin init, writerType, beginRecord, endRecord
var `writer` = init(WriterType(`Format`), `outputStream`)
var recordStartMemo = beginRecord(`writer`, `RecordType`)
var `recordWriterCtx` = beginRecord(`writer`, `RecordType`)
`appendParams`
endRecord(`writer`, recordStartMemo)
endRecord(`writer`, `recordWriterCtx`)
proc useStandardBody*(sendProc: SendProc,
preSerializationStep: proc(stream: NimNode): NimNode,
@ -839,7 +842,7 @@ macro emitForSingleBackend(
# TODO Nim can't handle a proper duration paramter here
timeouts: static[int64] = defaultReqTimeout.milliseconds,
useRequestIds: static[bool] = true,
shortName: static[string] = "",
rlpxName: static[string] = "",
outgoingRequestDecorator: untyped = nil,
incomingRequestDecorator: untyped = nil,
incomingRequestThunkDecorator: untyped = nil,
@ -851,7 +854,7 @@ macro emitForSingleBackend(
var p = P2PProtocol.init(
backend,
name, version, body, timeouts,
useRequestIds, shortName,
useRequestIds, rlpxName,
outgoingRequestDecorator,
incomingRequestDecorator,
incomingRequestThunkDecorator,

View File

@ -579,9 +579,9 @@ proc p2pProtocolBackendImpl*(protocol: P2PProtocol): Backend =
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
doAssert protocol.shortName.len == 3
doAssert protocol.rlpxName.len == 3
new result
@ -765,11 +765,11 @@ proc p2pProtocolBackendImpl*(protocol: P2PProtocol): Backend =
result.implementProtocolInit = proc (protocol: P2PProtocol): NimNode =
return newCall(initProtocol,
newLit(protocol.shortName),
newLit(protocol.rlpxName),
newLit(protocol.version),
protocol.peerInit, protocol.netInit)
p2pProtocol devp2p(version = 0, shortName = "p2p"):
p2pProtocol devp2p(version = 0, rlpxName = "p2p"):
proc hello(peer: Peer,
version: uint,
clientId: string,

View File

@ -359,7 +359,7 @@ when defined(testing):
proc isMax(s: FlowControlState): bool =
s.bufValue == s.bufLimit
p2pProtocol dummyLes(version = 1, shortName = "abc"):
p2pProtocol dummyLes(version = 1, rlpxName = "abc"):
proc a(p: Peer)
proc b(p: Peer)
proc c(p: Peer)

View File

@ -725,7 +725,7 @@ proc initProtocolState*(network: WhisperNetwork, node: EthereumNode) {.gcsafe.}
asyncCheck node.run(network)
p2pProtocol Whisper(version = whisperVersion,
shortName = "shh",
rlpxName = "shh",
peerState = WhisperPeer,
networkState = WhisperNetwork):

View File

@ -16,7 +16,7 @@ type
count*: int
p2pProtocol abc(version = 1,
shortName = "abc",
rlpxName = "abc",
networkState = network):
onPeerConnected do (peer: Peer):
@ -28,7 +28,7 @@ p2pProtocol abc(version = 1,
raise newException(CatchableError, "Fake abc exception")
p2pProtocol xyz(version = 1,
shortName = "xyz",
rlpxName = "xyz",
networkState = network):
onPeerConnected do (peer: Peer):
@ -40,7 +40,7 @@ p2pProtocol xyz(version = 1,
raise newException(CatchableError, "Fake xyz exception")
p2pProtocol hah(version = 1,
shortName = "hah",
rlpxName = "hah",
networkState = network):
onPeerConnected do (peer: Peer):