refactor: remove use of getExecutionFromBlockRoot in node client
This commit is contained in:
parent
4dbd3fc51d
commit
f24fdc5489
|
@ -107,10 +107,11 @@ export default class Client extends BaseClient {
|
||||||
console.error(`Invalid Optimistic Update: ${verify?.reason}`);
|
console.error(`Invalid Optimistic Update: ${verify?.reason}`);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return this.getExecutionFromBlockRoot(
|
|
||||||
updateJSON.data.attested_header.beacon.slot,
|
return {
|
||||||
updateJSON.data.attested_header.beacon.body_root,
|
blockHash: toHexString(update.attestedHeader.execution.blockHash),
|
||||||
);
|
blockNumber: update.attestedHeader.execution.blockNumber,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async syncFromGenesis(): Promise<Uint8Array[]> {
|
protected async syncFromGenesis(): Promise<Uint8Array[]> {
|
||||||
|
@ -177,33 +178,4 @@ export default class Client extends BaseClient {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getExecutionFromBlockRoot(
|
|
||||||
slot: bigint,
|
|
||||||
expectedBlockRoot: Bytes32,
|
|
||||||
): Promise<ExecutionInfo> {
|
|
||||||
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<any>(Number(slot), block);
|
|
||||||
this.blockHashCache.set<Bytes32>(Number(slot), expectedBlockRoot);
|
|
||||||
|
|
||||||
return {
|
|
||||||
blockHash: toHexString(block.body.executionPayload.blockHash),
|
|
||||||
blockNumber: block.body.executionPayload.blockNumber,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue