From d3929cbb45179f82c603e60827668e14e966ac79 Mon Sep 17 00:00:00 2001 From: tersec Date: Wed, 10 May 2023 10:20:55 +0000 Subject: [PATCH] update some beacon API spec URLs; fix some Name and DuplicateModuleImport hints (#4929) --- .../consensus_object_pools/consensus_manager.nim | 4 ---- beacon_chain/eth1/eth1_monitor.nim | 2 +- .../gossip_processing/block_processor.nim | 8 +++----- beacon_chain/networking/eth2_network.nim | 4 +--- beacon_chain/networking/network_metadata.nim | 2 +- beacon_chain/nimbus_signing_node.nim | 2 +- beacon_chain/nimbus_validator_client.nim | 4 ++-- beacon_chain/rpc/rest_beacon_api.nim | 2 +- beacon_chain/rpc/rest_validator_api.nim | 2 +- beacon_chain/spec/eth2_apis/rest_types.nim | 4 ++-- beacon_chain/spec/state_transition_block.nim | 3 --- beacon_chain/validator_client/duties_service.nim | 6 +++--- beacon_chain/validators/validator_duties.nim | 15 ++++++--------- tests/testblockutil.nim | 7 +++---- 14 files changed, 25 insertions(+), 40 deletions(-) diff --git a/beacon_chain/consensus_object_pools/consensus_manager.nim b/beacon_chain/consensus_object_pools/consensus_manager.nim index 88cdcbc3c..16373db53 100644 --- a/beacon_chain/consensus_object_pools/consensus_manager.nim +++ b/beacon_chain/consensus_object_pools/consensus_manager.nim @@ -112,10 +112,6 @@ proc expectBlock*(self: var ConsensusManager, expectedSlot: Slot): Future[bool] return fut -from web3/engine_api_types import - ForkchoiceUpdatedResponse, PayloadExecutionStatus, PayloadStatusV1, - PayloadAttributesV1 - func `$`(h: BlockHash): string = $h.asEth2Digest func shouldSyncOptimistically*( diff --git a/beacon_chain/eth1/eth1_monitor.nim b/beacon_chain/eth1/eth1_monitor.nim index dce1ef15c..2336b1a60 100644 --- a/beacon_chain/eth1/eth1_monitor.nim +++ b/beacon_chain/eth1/eth1_monitor.nim @@ -422,7 +422,7 @@ func asConsensusWithdrawal(w: WithdrawalV1): capella.Withdrawal = index: w.index.uint64, validator_index: w.validatorIndex.uint64, address: ExecutionAddress(data: w.address.distinctBase), - amount: GWei w.amount) + amount: Gwei w.amount) func asEngineWithdrawal(w: capella.Withdrawal): WithdrawalV1 = WithdrawalV1( diff --git a/beacon_chain/gossip_processing/block_processor.nim b/beacon_chain/gossip_processing/block_processor.nim index 7ee80f6c8..b3ecc3156 100644 --- a/beacon_chain/gossip_processing/block_processor.nim +++ b/beacon_chain/gossip_processing/block_processor.nim @@ -19,7 +19,8 @@ from ../consensus_object_pools/consensus_manager import runProposalForkchoiceUpdated, shouldSyncOptimistically, updateHead, updateHeadWithExecution from ../consensus_object_pools/blockchain_dag import - getBlockRef, getProposer, forkAtEpoch, validatorKey + getBlockRef, getProposer, forkAtEpoch, is_optimistic, loadExecutionBlockHash, + markBlockVerified, validatorKey from ../beacon_clock import GetBeaconTimeFn, toFloatSeconds from ../consensus_object_pools/block_dag import BlockRef, root, shortLog, slot from ../consensus_object_pools/block_pools_types import @@ -230,7 +231,7 @@ from web3/engine_api_types import PayloadStatusV1 from ../eth1/eth1_monitor import ELManager, asEngineExecutionPayload, forkchoiceUpdated, hasConnection, - sendNewPayload + hasProperlyConfiguredConnection, sendNewPayload proc expectValidForkchoiceUpdated( elManager: ELManager, headBlockPayloadAttributesType: typedesc, @@ -273,8 +274,6 @@ proc expectValidForkchoiceUpdated( from ../consensus_object_pools/attestation_pool import addForkChoice, selectOptimisticHead, BeaconHead -from ../consensus_object_pools/blockchain_dag import - is_optimistic, loadExecutionBlockHash, markBlockVerified from ../consensus_object_pools/spec_cache import get_attesting_indices from ../spec/datatypes/phase0 import TrustedSignedBeaconBlock from ../spec/datatypes/altair import SignedBeaconBlock @@ -287,7 +286,6 @@ from ../spec/datatypes/capella import # directly address deneb.ExecutionPayload when complaint was that it didn't # know about "deneb" from ../spec/datatypes/deneb import SignedBeaconBlock, asTrusted, shortLog -from ../eth1/eth1_monitor import hasProperlyConfiguredConnection proc newExecutionPayload*( elManager: ELManager, diff --git a/beacon_chain/networking/eth2_network.nim b/beacon_chain/networking/eth2_network.nim index 71495c7ce..f5be60074 100644 --- a/beacon_chain/networking/eth2_network.nim +++ b/beacon_chain/networking/eth2_network.nim @@ -2289,7 +2289,7 @@ proc createEth2Node*(rng: ref HmacDrbgContext, func msgIdProvider(m: messages.Message): Result[seq[byte], ValidationResult] = template topic: untyped = - if m.topicIDs.len > 0: m.topicIDs[0] else: "" + if m.topicIds.len > 0: m.topicIds[0] else: "" try: # This doesn't have to be a tight bound, just enough to avoid denial of @@ -2631,8 +2631,6 @@ proc broadcastBeaconBlock*( let topic = getBeaconBlocksTopic(node.forkDigests.deneb) node.broadcast(topic, blck) -from ../spec/datatypes/deneb import SignedBeaconBlock - proc broadcastSyncCommitteeMessage*( node: Eth2Node, msg: SyncCommitteeMessage, subcommitteeIdx: SyncSubcommitteeIndex): Future[SendResult] = diff --git a/beacon_chain/networking/network_metadata.nim b/beacon_chain/networking/network_metadata.nim index 7115e41e1..83225597c 100644 --- a/beacon_chain/networking/network_metadata.nim +++ b/beacon_chain/networking/network_metadata.nim @@ -238,7 +238,7 @@ elif const_preset == "mainnet": for network in [mainnetMetadata, praterMetadata, sepoliaMetadata]: checkForkConsistency(network.cfg) - for network in [mainnetMetadata, praterMetadata, sepoliaMetaData]: + for network in [mainnetMetadata, praterMetadata, sepoliaMetadata]: doAssert network.cfg.ALTAIR_FORK_EPOCH < FAR_FUTURE_EPOCH doAssert network.cfg.BELLATRIX_FORK_EPOCH < FAR_FUTURE_EPOCH doAssert network.cfg.CAPELLA_FORK_EPOCH < FAR_FUTURE_EPOCH diff --git a/beacon_chain/nimbus_signing_node.nim b/beacon_chain/nimbus_signing_node.nim index 118475dbe..5c99cf6ae 100644 --- a/beacon_chain/nimbus_signing_node.nim +++ b/beacon_chain/nimbus_signing_node.nim @@ -411,7 +411,7 @@ proc asyncInit(sn: SigningNodeRef) {.async.} = proc asyncRun*(sn: SigningNodeRef) {.async.} = sn.runKeystoreCachePruningLoopFut = - runKeystorecachePruningLoop(sn.keystoreCache) + runKeystoreCachePruningLoop(sn.keystoreCache) sn.installApiHandlers() sn.start() diff --git a/beacon_chain/nimbus_validator_client.nim b/beacon_chain/nimbus_validator_client.nim index 9d537f7f0..042615faa 100644 --- a/beacon_chain/nimbus_validator_client.nim +++ b/beacon_chain/nimbus_validator_client.nim @@ -1,5 +1,5 @@ # beacon_chain -# Copyright (c) 2018-2021 Status Research & Development GmbH +# Copyright (c) 2018-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). @@ -419,7 +419,7 @@ proc asyncRun*(vc: ValidatorClientRef) {.async.} = # Main processing loop. vc.runSlotLoopFut = vc.runVCSlotLoop() vc.runKeystoreCachePruningLoopFut = - runKeystorecachePruningLoop(vc.keystoreCache) + runKeystoreCachePruningLoop(vc.keystoreCache) discard await race(vc.runSlotLoopFut, doppelEventFut) if not(vc.runSlotLoopFut.finished()): notice "Received shutdown event, exiting" diff --git a/beacon_chain/rpc/rest_beacon_api.nim b/beacon_chain/rpc/rest_beacon_api.nim index fddd57bfb..82c840e0e 100644 --- a/beacon_chain/rpc/rest_beacon_api.nim +++ b/beacon_chain/rpc/rest_beacon_api.nim @@ -862,7 +862,7 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) = return RestApiResponse.jsonMsgResponse(BlockValidationSuccess) # https://ethereum.github.io/beacon-APIs/#/Beacon/publishBlindedBlock - # https://github.com/ethereum/beacon-APIs/blob/v2.3.0/apis/beacon/blocks/blinded_blocks.yaml + # https://github.com/ethereum/beacon-APIs/blob/v2.4.0/apis/beacon/blocks/blinded_blocks.yaml router.api(MethodPost, "/eth/v1/beacon/blinded_blocks") do ( contentBody: Option[ContentBody]) -> RestApiResponse: ## Instructs the beacon node to use the components of the diff --git a/beacon_chain/rpc/rest_validator_api.nim b/beacon_chain/rpc/rest_validator_api.nim index 9645ee85a..1f9eba5ab 100644 --- a/beacon_chain/rpc/rest_validator_api.nim +++ b/beacon_chain/rpc/rest_validator_api.nim @@ -404,7 +404,7 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) = return RestApiResponse.jsonResponsePlain(message) # https://ethereum.github.io/beacon-APIs/#/Validator/produceBlindedBlock - # https://github.com/ethereum/beacon-APIs/blob/v2.3.0/apis/validator/blinded_block.yaml + # https://github.com/ethereum/beacon-APIs/blob/v2.4.0/apis/validator/blinded_block.yaml router.api(MethodGet, "/eth/v1/validator/blinded_blocks/{slot}") do ( slot: Slot, randao_reveal: Option[ValidatorSig], graffiti: Option[GraffitiBytes], diff --git a/beacon_chain/spec/eth2_apis/rest_types.nim b/beacon_chain/spec/eth2_apis/rest_types.nim index 08a75429c..a4c6fce8d 100644 --- a/beacon_chain/spec/eth2_apis/rest_types.nim +++ b/beacon_chain/spec/eth2_apis/rest_types.nim @@ -191,13 +191,13 @@ type validators*: seq[ValidatorIndex] RestErrorMessage* = object - ## https://github.com/ethereum/beacon-APIs/blob/v2.3.0/types/http.yaml#L86 + ## https://github.com/ethereum/beacon-APIs/blob/v2.4.0/types/http.yaml#L130 code*: int message*: string stacktraces*: Option[seq[string]] RestIndexedErrorMessage* = object - ## https://github.com/ethereum/beacon-APIs/blob/v2.3.0/types/http.yaml#L101 + ## https://github.com/ethereum/beacon-APIs/blob/v2.4.0/types/http.yaml#L145 code*: int message*: string failures*: seq[RestIndexedErrorMessageItem] diff --git a/beacon_chain/spec/state_transition_block.nim b/beacon_chain/spec/state_transition_block.nim index e4d774859..4dd831431 100644 --- a/beacon_chain/spec/state_transition_block.nim +++ b/beacon_chain/spec/state_transition_block.nim @@ -273,9 +273,6 @@ func findValidatorIndex*(state: ForkyBeaconState, pubkey: ValidatorPubKey): if state.validators.asSeq[vidx].pubkey == pubkey: return Opt[ValidatorIndex].ok(vidx) -from ./datatypes/deneb import - BLOB_TX_TYPE, BeaconState, KzgCommitment, VersionedHash - proc process_deposit*(cfg: RuntimeConfig, state: var ForkyBeaconState, deposit: Deposit, diff --git a/beacon_chain/validator_client/duties_service.nim b/beacon_chain/validator_client/duties_service.nim index 6ef11ab67..dc67a3804 100644 --- a/beacon_chain/validator_client/duties_service.nim +++ b/beacon_chain/validator_client/duties_service.nim @@ -1,5 +1,5 @@ # beacon_chain -# Copyright (c) 2021-2022 Status Research & Development GmbH +# Copyright (c) 2021-2023 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). @@ -425,10 +425,10 @@ proc pollForSyncCommitteeDuties*(service: DutiesServiceRef) {.async.} = (epoch: currentSlot.epoch(), period: currentPeriod) ) - if lookAheadPeriod > currentPeriod: + if lookaheadPeriod > currentPeriod: res.add( (epoch: lookaheadPeriod.start_epoch(), - period: lookAheadPeriod) + period: lookaheadPeriod) ) res diff --git a/beacon_chain/validators/validator_duties.nim b/beacon_chain/validators/validator_duties.nim index 9d4f77421..a942cb3e4 100644 --- a/beacon_chain/validators/validator_duties.nim +++ b/beacon_chain/validators/validator_duties.nim @@ -1220,7 +1220,7 @@ proc handleSyncCommitteeContributions( genesis_validators_root = node.dag.genesis_validators_root syncCommittee = node.dag.syncCommitteeParticipants(slot + 1) - for subcommitteeIdx in SyncSubCommitteeIndex: + for subcommitteeIdx in SyncSubcommitteeIndex: for valIdx in syncSubcommittee(syncCommittee, subcommitteeIdx): let validator = node.getValidatorForDuties( valIdx, slot, slashingSafe = true).valueOr: @@ -1389,8 +1389,6 @@ proc getValidatorRegistration( return ok validatorRegistration -from std/sequtils import toSeq - proc registerValidators*(node: BeaconNode, epoch: Epoch) {.async.} = try: if (not node.config.payloadBuilderEnable) or @@ -1440,12 +1438,11 @@ proc registerValidators*(node: BeaconNode, epoch: Epoch) {.async.} = withState(node.dag.headState): let currentEpoch = node.currentSlot().epoch for i in 0 ..< forkyState.data.validators.len: - # https://github.com/ethereum/beacon-APIs/blob/v2.3.0/apis/validator/register_validator.yaml - # "requests containing currently inactive or unknown validator - # pubkeys will be accepted, as they may become active at a later - # epoch" which means filtering is needed here, because including - # any validators not pending or active may cause the request, as - # a whole, to fail. + # https://github.com/ethereum/beacon-APIs/blob/v2.4.0/apis/validator/register_validator.yaml + # "Note that only registrations for active or pending validators must + # be sent to the builder network. Registrations for unknown or exited + # validators must be filtered out and not sent to the builder + # network." let pubkey = forkyState.data.validators.item(i).pubkey if pubkey in node.externalBuilderRegistrations and forkyState.data.validators.item(i).exit_epoch > currentEpoch: diff --git a/tests/testblockutil.nim b/tests/testblockutil.nim index 27aa85020..42071f9e7 100644 --- a/tests/testblockutil.nim +++ b/tests/testblockutil.nim @@ -17,9 +17,7 @@ import # TODO remove this dependency from std/random import rand -from eth/common/eth_types import EMPTY_ROOT_HASH from eth/common/eth_types_rlp import rlpHash -from eth/eip1559 import EIP1559_INITIAL_BASE_FEE type MockPrivKeysT = object @@ -87,6 +85,9 @@ func signBlock( ValidatorSig() ForkedSignedBeaconBlock.init(forked, root, signature) +from eth/eip1559 import EIP1559_INITIAL_BASE_FEE, calcEip1599BaseFee +from eth/common/eth_types import EMPTY_ROOT_HASH, GasInt + proc build_empty_merge_execution_payload(state: bellatrix.BeaconState): bellatrix.ExecutionPayloadForSigning = ## Assuming a pre-state of the same slot, build a valid ExecutionPayload @@ -115,8 +116,6 @@ proc build_empty_merge_execution_payload(state: bellatrix.BeaconState): bellatrix.ExecutionPayloadForSigning(executionPayload: payload, blockValue: Wei.zero) -from eth/common/eth_types import GasInt -from eth/eip1559 import calcEip1599BaseFee from stew/saturating_arith import saturate proc build_empty_execution_payload(