From f24fdc5489e4795f872196ed338021ba3f7e4764 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Tue, 11 Jul 2023 01:30:22 -0400 Subject: [PATCH] refactor: remove use of getExecutionFromBlockRoot in node client --- src/node/client.ts | 38 +++++--------------------------------- 1 file changed, 5 insertions(+), 33 deletions(-) diff --git a/src/node/client.ts b/src/node/client.ts index b6b7f94..0b9605c 100644 --- a/src/node/client.ts +++ b/src/node/client.ts @@ -107,10 +107,11 @@ export default class Client extends BaseClient { console.error(`Invalid Optimistic Update: ${verify?.reason}`); return null; } - return this.getExecutionFromBlockRoot( - updateJSON.data.attested_header.beacon.slot, - updateJSON.data.attested_header.beacon.body_root, - ); + + return { + blockHash: toHexString(update.attestedHeader.execution.blockHash), + blockNumber: update.attestedHeader.execution.blockNumber, + }; } protected async syncFromGenesis(): Promise { @@ -177,33 +178,4 @@ export default class Client extends BaseClient { return false; } } - - private async getExecutionFromBlockRoot( - slot: bigint, - expectedBlockRoot: Bytes32, - ): Promise { - const res = await axios.get(`/eth/v2/beacon/blocks/${slot}`); - - if (!res.data) { - throw Error(`fetching block failed`); - } - - const block = capella.ssz.BeaconBlock.fromJson(res.data.message); - const blockRoot = toHexString( - capella.ssz.BeaconBlockBody.hashTreeRoot(block.body), - ); - if (blockRoot !== expectedBlockRoot) { - throw Error( - `block provided by the beacon chain api doesn't match the expected block root`, - ); - } - - this.blockCache.set(Number(slot), block); - this.blockHashCache.set(Number(slot), expectedBlockRoot); - - return { - blockHash: toHexString(block.body.executionPayload.blockHash), - blockNumber: block.body.executionPayload.blockNumber, - }; - } }