From 38d40e8ae2bda0ae591bec0de6dd8e6f863c0689 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Wed, 15 Jan 2025 21:04:01 +0000 Subject: [PATCH] chore: review devnet-5 branch (#7365) * Remove stale todo * some refactoring * Readd comment, seems somewhat useful * Add alias for getSlotFromOffset * Use parseInt instead of Number * Update return type --- .../beacon-node/src/execution/engine/types.ts | 2 +- .../src/network/processor/gossipHandlers.ts | 1 - packages/beacon-node/src/util/sszBytes.ts | 24 ++++++++++--------- .../crucible/clients/beacon/lighthouse.ts | 1 + 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/packages/beacon-node/src/execution/engine/types.ts b/packages/beacon-node/src/execution/engine/types.ts index 76130dc3ec4..24de1b9e657 100644 --- a/packages/beacon-node/src/execution/engine/types.ts +++ b/packages/beacon-node/src/execution/engine/types.ts @@ -496,7 +496,7 @@ export function deserializeExecutionRequests(serialized: ExecutionRequestsRpc): prefixedRequests = prefixedRequests.slice(2); } - const currentRequestType = Number(prefixedRequests.substring(0, 2)); + const currentRequestType = parseInt(prefixedRequests.substring(0, 2), 16); if (!isExecutionRequestType(currentRequestType)) { throw Error(`Invalid request type currentRequestType=${prefixedRequests.substring(0, 2)}`); diff --git a/packages/beacon-node/src/network/processor/gossipHandlers.ts b/packages/beacon-node/src/network/processor/gossipHandlers.ts index 2a9a9129a98..ec61aa277d0 100644 --- a/packages/beacon-node/src/network/processor/gossipHandlers.ts +++ b/packages/beacon-node/src/network/processor/gossipHandlers.ts @@ -662,7 +662,6 @@ function getBatchHandlers(modules: ValidatorFnsModules, options: GossipHandlerOp // Node may be subscribe to extra subnets (long-lived random subnets). For those, validate the messages // but don't add to attestation pool, to save CPU and RAM if (aggregatorTracker.shouldAggregate(subnet, indexedAttestation.data.slot)) { - // TODO: modify after we change attestationPool due to SingleAttestation const insertOutcome = chain.attestationPool.add( committeeIndex, attestation, diff --git a/packages/beacon-node/src/util/sszBytes.ts b/packages/beacon-node/src/util/sszBytes.ts index ab2b59c6808..13ce4c417ee 100644 --- a/packages/beacon-node/src/util/sszBytes.ts +++ b/packages/beacon-node/src/util/sszBytes.ts @@ -110,8 +110,7 @@ export function getAttDataFromAttestationSerialized(data: Uint8Array): AttDataBa * This is used for GossipQueue. */ export function getBeaconAttestationGossipIndex(fork: ForkName, data: Uint8Array): AttDataBase64 | null { - const forkSeq = ForkSeq[fork]; - return forkSeq >= ForkSeq.electra + return ForkSeq[fork] >= ForkSeq.electra ? getAttDataFromSingleAttestationSerialized(data) : getAttDataFromAttestationSerialized(data); } @@ -120,8 +119,7 @@ export function getBeaconAttestationGossipIndex(fork: ForkName, data: Uint8Array * Extract slot from `beacon_attestation` gossip message serialized bytes. */ export function getSlotFromBeaconAttestationSerialized(fork: ForkName, data: Uint8Array): Slot | null { - const forkSeq = ForkSeq[fork]; - return forkSeq >= ForkSeq.electra + return ForkSeq[fork] >= ForkSeq.electra ? getSlotFromSingleAttestationSerialized(data) : getSlotFromAttestationSerialized(data); } @@ -130,8 +128,7 @@ export function getSlotFromBeaconAttestationSerialized(fork: ForkName, data: Uin * Extract block root from `beacon_attestation` gossip message serialized bytes. */ export function getBlockRootFromBeaconAttestationSerialized(fork: ForkName, data: Uint8Array): BlockRootHex | null { - const forkSeq = ForkSeq[fork]; - return forkSeq >= ForkSeq.electra + return ForkSeq[fork] >= ForkSeq.electra ? getBlockRootFromSingleAttestationSerialized(data) : getBlockRootFromAttestationSerialized(data); } @@ -181,7 +178,6 @@ export function getSlotFromSingleAttestationSerialized(data: Uint8Array): Slot | /** * Extract committee index from SingleAttestation serialized bytes. * Return null if data is not long enough to extract slot. - * TODO Electra: Rename getSlotFromOffset to reflect generic usage */ export function getCommitteeIndexFromSingleAttestationSerialized( fork: ForkName, @@ -192,27 +188,26 @@ export function getCommitteeIndexFromSingleAttestationSerialized( return null; } - return getSlotFromOffset(data, SINGLE_ATTESTATION_COMMITTEE_INDEX_OFFSET); + return getIndexFromOffset(data, SINGLE_ATTESTATION_COMMITTEE_INDEX_OFFSET); } if (data.length < VARIABLE_FIELD_OFFSET + SLOT_SIZE + COMMITTEE_INDEX_SIZE) { return null; } - return getSlotFromOffset(data, VARIABLE_FIELD_OFFSET + SLOT_SIZE); + return getIndexFromOffset(data, VARIABLE_FIELD_OFFSET + SLOT_SIZE); } /** * Extract attester index from SingleAttestation serialized bytes. * Return null if data is not long enough to extract index. - * TODO Electra: Rename getSlotFromOffset to reflect generic usage */ export function getAttesterIndexFromSingleAttestationSerialized(data: Uint8Array): ValidatorIndex | null { if (data.length !== SINGLE_ATTESTATION_SIZE) { return null; } - return getSlotFromOffset(data, SINGLE_ATTESTATION_ATTESTER_INDEX_OFFSET); + return getIndexFromOffset(data, SINGLE_ATTESTATION_ATTESTER_INDEX_OFFSET); } /** @@ -409,6 +404,13 @@ function getSlotFromOffset(data: Uint8Array, offset: number): Slot | null { return checkSlotHighBytes(data, offset) ? getSlotFromOffsetTrusted(data, offset) : null; } +/** + * Alias of `getSlotFromOffset` for readability + */ +function getIndexFromOffset(data: Uint8Array, offset: number): (ValidatorIndex | CommitteeIndex) | null { + return getSlotFromOffset(data, offset); +} + /** * Read only the first 4 bytes of Slot, max value is 4,294,967,295 will be reached 1634 years after genesis */ diff --git a/packages/cli/test/utils/crucible/clients/beacon/lighthouse.ts b/packages/cli/test/utils/crucible/clients/beacon/lighthouse.ts index 4716e8538c3..38329d09a40 100644 --- a/packages/cli/test/utils/crucible/clients/beacon/lighthouse.ts +++ b/packages/cli/test/utils/crucible/clients/beacon/lighthouse.ts @@ -28,6 +28,7 @@ export const generateLighthouseBeaconNode: BeaconNodeGenerator = { "testnet-dir": rootDirMounted, datadir: rootDirMounted, + // Enable the RESTful HTTP API server. Disabled by default. http: null, "http-address": "0.0.0.0", "http-port": ports.beacon.httpPort,