bump nimbus-eth2 (#1345)

* bump nimbus-eth2
This commit is contained in:
KonradStaniec 2022-12-02 16:09:31 +01:00 committed by GitHub
parent 94a94c5b65
commit f4cacdfc6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 83 additions and 25 deletions

View File

@ -89,8 +89,8 @@ proc new*(
onStoreInitialized, onFinalizedHeader, onOptimisticHeader) onStoreInitialized, onFinalizedHeader, onOptimisticHeader)
proc lightClientVerifier(obj: SomeLightClientObject): proc lightClientVerifier(obj: SomeLightClientObject):
Future[Result[void, BlockError]] = Future[Result[void, VerifierError]] =
let resfut = newFuture[Result[void, BlockError]]("lightClientVerifier") let resfut = newFuture[Result[void, VerifierError]]("lightClientVerifier")
lightClient.processor[].addObject(MsgSource.gossip, obj, resfut) lightClient.processor[].addObject(MsgSource.gossip, obj, resfut)
resfut resfut

View File

@ -16,7 +16,7 @@ import
beacon_chain/beacon_clock, beacon_chain/beacon_clock,
"."/[light_client_network, light_client_content] "."/[light_client_network, light_client_content]
from beacon_chain/consensus_object_pools/block_pools_types import BlockError from beacon_chain/consensus_object_pools/block_pools_types import VerifierError
logScope: logScope:
topics = "lcman" topics = "lcman"
@ -40,7 +40,7 @@ type
Endpoint[Slot, altair.LightClientOptimisticUpdate] Endpoint[Slot, altair.LightClientOptimisticUpdate]
ValueVerifier[V] = ValueVerifier[V] =
proc(v: V): Future[Result[void, BlockError]] {.gcsafe, raises: [Defect].} proc(v: V): Future[Result[void, VerifierError]] {.gcsafe, raises: [Defect].}
BootstrapVerifier* = BootstrapVerifier* =
ValueVerifier[altair.LightClientBootstrap] ValueVerifier[altair.LightClientBootstrap]
UpdateVerifier* = UpdateVerifier* =
@ -204,19 +204,19 @@ proc workerTask[E](
let res = await self.valueVerifier(E)(val) let res = await self.valueVerifier(E)(val)
if res.isErr: if res.isErr:
case res.error case res.error
of BlockError.MissingParent: of VerifierError.MissingParent:
# Stop, requires different request to progress # Stop, requires different request to progress
return didProgress return didProgress
of BlockError.Duplicate: of VerifierError.Duplicate:
# Ignore, a concurrent request may have already fulfilled this # Ignore, a concurrent request may have already fulfilled this
when E.V is altair.LightClientBootstrap: when E.V is altair.LightClientBootstrap:
didProgress = true didProgress = true
else: else:
discard discard
of BlockError.UnviableFork: of VerifierError.UnviableFork:
notice "Received value from an unviable fork", value = val.shortLog notice "Received value from an unviable fork", value = val.shortLog
return didProgress return didProgress
of BlockError.Invalid: of VerifierError.Invalid:
warn "Received invalid value", value = val.shortLog warn "Received invalid value", value = val.shortLog
return didProgress return didProgress
else: else:

View File

@ -13,7 +13,8 @@ else:
import import
std/tables, std/tables,
web3/ethtypes, web3/ethtypes,
stew/[results, keyed_queue] stew/[results, keyed_queue],
./rpc/rpc_utils
## Cache for payloads received through block gossip and validated by the ## Cache for payloads received through block gossip and validated by the
@ -22,7 +23,7 @@ import
## oldest payload is deleted first. ## oldest payload is deleted first.
type BlockCache* = ref object type BlockCache* = ref object
max: int max: int
blocks: KeyedQueue[BlockHash, ExecutionPayloadV1] blocks: KeyedQueue[BlockHash, ExecutionData]
proc `==`(x, y: Quantity): bool {.borrow, noSideEffect.} proc `==`(x, y: Quantity): bool {.borrow, noSideEffect.}
@ -30,7 +31,7 @@ proc new*(T: type BlockCache, max: uint32): T =
let maxAsInt = int(max) let maxAsInt = int(max)
return BlockCache( return BlockCache(
max: maxAsInt, max: maxAsInt,
blocks: KeyedQueue[BlockHash, ExecutionPayloadV1].init(maxAsInt) blocks: KeyedQueue[BlockHash, ExecutionData].init(maxAsInt)
) )
func len*(self: BlockCache): int = func len*(self: BlockCache): int =
@ -39,7 +40,7 @@ func len*(self: BlockCache): int =
func isEmpty*(self: BlockCache): bool = func isEmpty*(self: BlockCache): bool =
return len(self.blocks) == 0 return len(self.blocks) == 0
proc add*(self: BlockCache, payload: ExecutionPayloadV1) = proc add*(self: BlockCache, payload: ExecutionData) =
if self.blocks.hasKey(payload.blockHash): if self.blocks.hasKey(payload.blockHash):
return return
@ -48,15 +49,15 @@ proc add*(self: BlockCache, payload: ExecutionPayloadV1) =
discard self.blocks.append(payload.blockHash, payload) discard self.blocks.append(payload.blockHash, payload)
proc latest*(self: BlockCache): results.Opt[ExecutionPayloadV1] = proc latest*(self: BlockCache): results.Opt[ExecutionData] =
let latestPair = ? self.blocks.last() let latestPair = ? self.blocks.last()
return Opt.some(latestPair.data) return Opt.some(latestPair.data)
proc getByNumber*( proc getByNumber*(
self: BlockCache, self: BlockCache,
number: Quantity): Opt[ExecutionPayloadV1] = number: Quantity): Opt[ExecutionData] =
var payloadResult: Opt[ExecutionPayloadV1] var payloadResult: Opt[ExecutionData]
for payload in self.blocks.prevValues: for payload in self.blocks.prevValues:
if payload.blockNumber == number: if payload.blockNumber == number:
@ -67,5 +68,5 @@ proc getByNumber*(
proc getPayloadByHash*( proc getPayloadByHash*(
self: BlockCache, self: BlockCache,
hash: BlockHash): Opt[ExecutionPayloadV1] = hash: BlockHash): Opt[ExecutionData] =
return self.blocks.eq(hash) return self.blocks.eq(hash)

View File

@ -22,7 +22,7 @@ import
beacon_chain/spec/datatypes/[phase0, altair, bellatrix], beacon_chain/spec/datatypes/[phase0, altair, bellatrix],
beacon_chain/[light_client, nimbus_binary_common, version], beacon_chain/[light_client, nimbus_binary_common, version],
../nimbus/rpc/cors, ../nimbus/rpc/cors,
./rpc/rpc_eth_api, "."/rpc/[rpc_eth_api, rpc_utils],
./nimbus_verified_proxy_conf, ./nimbus_verified_proxy_conf,
./block_cache ./block_cache
@ -119,7 +119,7 @@ proc run() {.raises: [Exception, Defect].} =
when stateFork >= BeaconStateFork.Bellatrix: when stateFork >= BeaconStateFork.Bellatrix:
if blck.message.is_execution_block: if blck.message.is_execution_block:
template payload(): auto = blck.message.body.execution_payload template payload(): auto = blck.message.body.execution_payload
blockCache.add(payload.asEngineExecutionPayload()) blockCache.add(asExecutionData(payload.asEngineExecutionPayload()))
else: discard else: discard
return return

View File

@ -94,7 +94,7 @@ template rpcClient(lcProxy: VerifiedRpcProxy): RpcClient =
proc getPayloadByTag( proc getPayloadByTag(
proxy: VerifiedRpcProxy, proxy: VerifiedRpcProxy,
quantityTag: string): quantityTag: string):
results.Opt[ExecutionPayloadV1] {.raises: [ValueError, Defect].} = results.Opt[ExecutionData] {.raises: [ValueError, Defect].} =
checkPreconditions(proxy) checkPreconditions(proxy)
let tagResult = parseQuantityTag(quantityTag) let tagResult = parseQuantityTag(quantityTag)
@ -113,7 +113,7 @@ proc getPayloadByTag(
proc getPayloadByTagOrThrow( proc getPayloadByTagOrThrow(
proxy: VerifiedRpcProxy, proxy: VerifiedRpcProxy,
quantityTag: string): ExecutionPayloadV1 {.raises: [ValueError, Defect].} = quantityTag: string): ExecutionData {.raises: [ValueError, Defect].} =
let tagResult = getPayloadByTag(proxy, quantityTag) let tagResult = getPayloadByTag(proxy, quantityTag)

View File

@ -17,6 +17,63 @@ import
stint, stint,
web3 web3
type
ExecutionData* = object
parentHash*: BlockHash
feeRecipient*: Address
stateRoot*: BlockHash
receiptsRoot*: BlockHash
logsBloom*: FixedBytes[256]
prevRandao*: FixedBytes[32]
blockNumber*: Quantity
gasLimit*: Quantity
gasUsed*: Quantity
timestamp*: Quantity
extraData*: DynamicBytes[0, 32]
baseFeePerGas*: UInt256
blockHash*: BlockHash
transactions*: seq[TypedTransaction]
withdrawals*: seq[WithdrawalV1]
proc asExecutionData*(
payload: ExecutionPayloadV1 | ExecutionPayloadV2): ExecutionData =
when payload is ExecutionPayloadV1:
return ExecutionData(
parentHash: payload.parentHash,
feeRecipient: payload.feeRecipient,
stateRoot: payload.stateRoot,
receiptsRoot: payload.receiptsRoot,
logsBloom: payload.logsBloom,
prevRandao: payload.prevRandao,
blockNumber: payload.blockNumber,
gasLimit: payload.gasLimit,
gasUsed: payload.gasUsed,
timestamp: payload.timestamp,
extraData: payload.extraData,
baseFeePerGas: payload.baseFeePerGas,
blockHash: payload.blockHash,
transactions: payload.transactions,
withdrawals: @[]
)
else:
return ExecutionData(
parentHash: payload.parentHash,
feeRecipient: payload.feeRecipient,
stateRoot: payload.stateRoot,
receiptsRoot: payload.receiptsRoot,
logsBloom: payload.logsBloom,
prevRandao: payload.prevRandao,
blockNumber: payload.blockNumber,
gasLimit: payload.gasLimit,
gasUsed: payload.gasUsed,
timestamp: payload.timestamp,
extraData: payload.extraData,
baseFeePerGas: payload.baseFeePerGas,
blockHash: payload.blockHash,
transactions: payload.transactions,
withdrawals: payload.withdrawals
)
template unsafeQuantityToInt64(q: Quantity): int64 = template unsafeQuantityToInt64(q: Quantity): int64 =
int64 q int64 q
@ -44,7 +101,7 @@ proc calculateTransactionData(
return (tr.rootHash(), txHashes, txSize) return (tr.rootHash(), txHashes, txSize)
func blockHeaderSize( func blockHeaderSize(
payload: ExecutionPayloadV1, txRoot: etypes.Hash256): uint64 = payload: ExecutionData, txRoot: etypes.Hash256): uint64 =
let bh = etypes.BlockHeader( let bh = etypes.BlockHeader(
parentHash : payload.parentHash.asEthHash, parentHash : payload.parentHash.asEthHash,
ommersHash : etypes.EMPTY_UNCLE_HASH, ommersHash : etypes.EMPTY_UNCLE_HASH,
@ -66,7 +123,7 @@ func blockHeaderSize(
return uint64(len(rlp.encode(bh))) return uint64(len(rlp.encode(bh)))
proc asBlockObject*( proc asBlockObject*(
p: ExecutionPayloadV1): BlockObject {.raises: [Defect, RlpError].} = p: ExecutionData): BlockObject {.raises: [Defect, RlpError].} =
# TODO: currently we always calculate txHashes as BlockObject does not have # TODO: currently we always calculate txHashes as BlockObject does not have
# option of returning full transactions. It needs fixing at nim-web3 library # option of returning full transactions. It needs fixing at nim-web3 library
# level # level

2
vendor/nim-chronos vendored

@ -1 +1 @@
Subproject commit 9df76c39df254c7ff0cec6dec5c9f345f2819c91 Subproject commit 75d030ff71264513fb9701c75a326cd36fcb4692

2
vendor/nim-web3 vendored

@ -1 +1 @@
Subproject commit 16a921168678017c42c1b15617951a88cd8c5705 Subproject commit 1e2e2e6d16a22cfc33f475b293c3ffbce8c46409

2
vendor/nimbus-eth2 vendored

@ -1 +1 @@
Subproject commit f141ae57d36dfa7bb2f26d7dd9fe6789acb3f429 Subproject commit 4e71e77da78d2ee1849facc140fcd06be4248a28