Skip to content

Commit

Permalink
feat(val-1398): eip-7549 support
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandrMov committed Dec 25, 2024
1 parent 14b9d8b commit 7cd70cb
Show file tree
Hide file tree
Showing 15 changed files with 52,183 additions and 8,756 deletions.
6 changes: 2 additions & 4 deletions packages/consensus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ export class MyService {
- [getBlockHeaders](https://ethereum.github.io/beacon-APIs/#/Beacon/getBlockHeaders)
- [getBlockHeader](https://ethereum.github.io/beacon-APIs/#/Beacon/getBlockHeader)
- [publishBlock](https://ethereum.github.io/beacon-APIs/#/Beacon/publishBlock)
- [getBlock](https://ethereum.github.io/beacon-APIs/#/Beacon/getBlock)
- [getBlockV2](https://ethereum.github.io/beacon-APIs/#/Beacon/getBlockV2)
- [getBlockRoot](https://ethereum.github.io/beacon-APIs/#/Beacon/getBlockRoot)
- [getBlockAttestations](https://ethereum.github.io/beacon-APIs/#/Beacon/getBlockAttestations)
Expand All @@ -173,9 +172,8 @@ export class MyService {

### Debug

- [getState](https://ethereum.github.io/beacon-APIs/#/Debug/getState)
- [getStateV2](https://ethereum.github.io/beacon-APIs/#/Debug/getStateV2)
- [getDebugChainHeads](https://ethereum.github.io/beacon-APIs/#/Debug/getDebugChainHeads)
- [getDebugChainHeadsV2](https://ethereum.github.io/beacon-APIs/#/Debug/getDebugChainHeadsV2)

### Events

Expand All @@ -196,8 +194,8 @@ export class MyService {
- [getAttesterDuties](https://ethereum.github.io/beacon-APIs/#/Validator/getAttesterDuties)
- [getProposerDuties](https://ethereum.github.io/beacon-APIs/#/Validator/getProposerDuties)
- [getSyncCommitteeDuties](https://ethereum.github.io/beacon-APIs/#/Validator/getSyncCommitteeDuties)
- [produceBlock](https://ethereum.github.io/beacon-APIs/#/Validator/produceBlock)
- [produceBlockV2](https://ethereum.github.io/beacon-APIs/#/Validator/produceBlockV2)
- [produceBlockV3](https://ethereum.github.io/beacon-APIs/#/Validator/produceBlockV3)
- [produceAttestationData](https://ethereum.github.io/beacon-APIs/#/Validator/produceAttestationData)
- [getAggregatedAttestation](https://ethereum.github.io/beacon-APIs/#/Validator/getAggregatedAttestation)
- [publishAggregateAndProofs](https://ethereum.github.io/beacon-APIs/#/Validator/publishAggregateAndProofs)
Expand Down
2 changes: 1 addition & 1 deletion packages/consensus/generate.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

oapi="https://github.com/ethereum/beacon-APIs/releases/download/v2.3.0/beacon-node-oapi.json"
oapi="https://github.com/ethereum/beacon-APIs/releases/download/v3.0.0-alpha.9/beacon-node-oapi.json"
tempfile="./api.json"
filename="./src/interfaces/generated.interface.ts"
prettierrc="../../.prettierrc"
Expand Down
60,838 changes: 52,157 additions & 8,681 deletions packages/consensus/src/interfaces/generated.interface.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/consensus/src/interfaces/subscribe.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export interface ConsensusSubscribeCallback {

export type ConsensusSubscribeError = unknown | null;
export type ConsensusSubscribeBlock =
| Awaited<ConsensusMethodResult<'getBlock'>>['data']
| Awaited<ConsensusMethodResult<'getBlockV2'>>['data']
| null;
4 changes: 2 additions & 2 deletions packages/consensus/src/service/base.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class ConsensusBaseService {
public subscribe(
this: ConsensusService,
callback: ConsensusSubscribeCallback,
args?: ConsensusMethodArgs<'getBlock'>,
args?: ConsensusMethodArgs<'getBlockV2'>,
): () => void {
let timer: NodeJS.Timeout | null = null;
let controller: AbortController | null = null;
Expand All @@ -102,7 +102,7 @@ export class ConsensusBaseService {
controller = new AbortController();
const { signal } = controller;

const { data } = await this.getBlock({
const { data } = await this.getBlockV2({
blockId: 'head',
...args,
options: { ...args?.options, signal },
Expand Down
8 changes: 0 additions & 8 deletions packages/consensus/src/service/beacon.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,6 @@ export class ConsensusBeaconService extends ConsensusBaseService {
throw new Error('Method is not implemented');
}

/** Returns the complete `SignedBeaconBlock` for a given block id. */
public async getBlock(
args: ConsensusMethodArgs<'getBlock'>,
): ConsensusMethodResult<'getBlock'> {
const { blockId, options } = args;
return await this.fetch(`/eth/v1/beacon/blocks/${blockId}`, options);
}

/** Retrieves block details for given block id. */
public async getBlockV2(
args: ConsensusMethodArgs<'getBlockV2'>,
Expand Down
16 changes: 0 additions & 16 deletions packages/consensus/src/service/debug.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ import {
import { ConsensusBaseService } from './base.service';

export class ConsensusDebugService extends ConsensusBaseService {
/** Returns full BeaconState object for given stateId. */
public async getState(
args: ConsensusMethodArgs<'getState'>,
): ConsensusMethodResult<'getState'> {
const { stateId, options } = args;
return await this.fetch(`/eth/v1/debug/beacon/states/${stateId}`, options);
}

/** Returns full BeaconState object for given stateId. */
public async getStateV2(
args: ConsensusMethodArgs<'getStateV2'>,
Expand All @@ -21,14 +13,6 @@ export class ConsensusDebugService extends ConsensusBaseService {
return await this.fetch(`/eth/v2/debug/beacon/states/${stateId}`, options);
}

/** Retrieves all possible chain heads (leaves of fork choice tree). */
public async getDebugChainHeads(
args?: ConsensusMethodArgs<'getDebugChainHeads'>,
): ConsensusMethodResult<'getDebugChainHeads'> {
const { options } = args || {};
return await this.fetch(`/eth/v1/debug/beacon/heads`, options);
}

/** Retrieves all possible chain heads (leaves of fork choice tree). */
public async getDebugChainHeadsV2(
args?: ConsensusMethodArgs<'getDebugChainHeadsV2'>,
Expand Down
16 changes: 8 additions & 8 deletions packages/consensus/src/service/validator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@ export class ConsensusValidatorService extends ConsensusBaseService {
}

/** Requests a beacon node to produce a valid block, which can then be signed by a validator. */
public async produceBlock(
args: ConsensusMethodArgs<'produceBlock'>,
): ConsensusMethodResult<'produceBlock'> {
public async produceBlockV2(
args: ConsensusMethodArgs<'produceBlockV2'>,
): ConsensusMethodResult<'produceBlockV2'> {
const { slot, randaoReveal, graffiti, options } = args;
const search = this.getSearchString({ randaoReveal, graffiti });
return await this.fetch(
`/eth/v1/validator/blocks/${slot}${search}`,
`/eth/v2/validator/blocks/${slot}${search}`,
options,
);
}

/** Requests a beacon node to produce a valid block, which can then be signed by a validator. */
public async produceBlockV2(
args: ConsensusMethodArgs<'produceBlockV2'>,
): ConsensusMethodResult<'produceBlockV2'> {
public async produceBlockV3(
args: ConsensusMethodArgs<'produceBlockV3'>,
): ConsensusMethodResult<'produceBlockV3'> {
const { slot, randaoReveal, graffiti, options } = args;
const search = this.getSearchString({ randaoReveal, graffiti });
return await this.fetch(
`/eth/v2/validator/blocks/${slot}${search}`,
`/eth/v3/validator/blocks/${slot}${search}`,
options,
);
}
Expand Down
7 changes: 0 additions & 7 deletions packages/consensus/test/beacon.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,6 @@ describe('Beacon endpoints', () => {
await expect(consensusService.publishBlindedBlock()).rejects.toThrow();
});

test('getBlock', async () => {
await consensusService.getBlock({ blockId: '1' });

expect(mockFetch).toBeCalledTimes(1);
expect(mockFetch).toBeCalledWith('/eth/v1/beacon/blocks/1', undefined);
});

test('getBlockV2', async () => {
await consensusService.getBlockV2({ blockId: '1' });

Expand Down
17 changes: 0 additions & 17 deletions packages/consensus/test/debug.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ describe('Debug endpoints', () => {
.mockImplementation(async () => null);
});

test('getState', async () => {
await consensusService.getState({ stateId: 'head' });

expect(mockFetch).toBeCalledTimes(1);
expect(mockFetch).toBeCalledWith(
'/eth/v1/debug/beacon/states/head',
undefined,
);
});

test('getStateV2', async () => {
await consensusService.getStateV2({ stateId: 'head' });

Expand All @@ -43,13 +33,6 @@ describe('Debug endpoints', () => {
);
});

test('getDebugChainHeads', async () => {
await consensusService.getDebugChainHeads();

expect(mockFetch).toBeCalledTimes(1);
expect(mockFetch).toBeCalledWith('/eth/v1/debug/beacon/heads', undefined);
});

test('getDebugChainHeadsV2', async () => {
await consensusService.getDebugChainHeadsV2();

Expand Down
2 changes: 1 addition & 1 deletion packages/consensus/test/fetch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('Fetch config', () => {
const consensusService = moduleRef.get(ConsensusService);
const fetchService = moduleRef.get(FetchService);

expect(consensusService.getBlock).toBeDefined();
expect(consensusService.getBlockV2).toBeDefined();
expect(consensusService.fetch).toBeDefined();

expect(fetchService.options).toBeDefined();
Expand Down
6 changes: 3 additions & 3 deletions packages/consensus/test/subscribe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('Subscription', () => {
describe('Subscription', () => {
const initSubscription = async (
calls: number,
args?: ConsensusMethodArgs<'getBlock'>,
args?: ConsensusMethodArgs<'getBlockV2'>,
) => {
await initModules([
ConsensusModule.forFeature({
Expand Down Expand Up @@ -141,7 +141,7 @@ describe('Subscription', () => {
const mockFetch = await initSubscription(1, { blockId: 'finalized' });

expect(mockFetch).toBeCalledWith(
'/eth/v1/beacon/blocks/finalized',
'/eth/v2/beacon/blocks/finalized',
expect.any(Object),
);
});
Expand All @@ -150,7 +150,7 @@ describe('Subscription', () => {
const mockFetch = await initSubscription(1, { blockId: 'head' });

expect(mockFetch).toBeCalledWith(
'/eth/v1/beacon/blocks/head',
'/eth/v2/beacon/blocks/head',
expect.any(Object),
);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/consensus/test/sync.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Sync module initializing', () => {

const consensusService = moduleRef.get(ConsensusService);

expect(consensusService.getBlock).toBeDefined();
expect(consensusService.getBlockV2).toBeDefined();
expect(consensusService.fetch).toBeDefined();

return moduleRef;
Expand Down
12 changes: 6 additions & 6 deletions packages/consensus/test/validator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,30 @@ describe('Validator endpoints', () => {
await expect(consensusService.getSyncCommitteeDuties()).rejects.toThrow();
});

test('produceBlock', async () => {
await consensusService.produceBlock({
test('produceBlockV2', async () => {
await consensusService.produceBlockV2({
slot: '1',
randaoReveal: '2',
graffiti: '3',
});

expect(mockFetch).toBeCalledTimes(1);
expect(mockFetch).toBeCalledWith(
'/eth/v1/validator/blocks/1?randao_reveal=2&graffiti=3',
'/eth/v2/validator/blocks/1?randao_reveal=2&graffiti=3',
undefined,
);
});

test('produceBlockV2', async () => {
await consensusService.produceBlockV2({
test('produceBlockV3', async () => {
await consensusService.produceBlockV3({
slot: '1',
randaoReveal: '2',
graffiti: '3',
});

expect(mockFetch).toBeCalledTimes(1);
expect(mockFetch).toBeCalledWith(
'/eth/v2/validator/blocks/1?randao_reveal=2&graffiti=3',
'/eth/v3/validator/blocks/1?randao_reveal=2&graffiti=3',
undefined,
);
});
Expand Down
1 change: 1 addition & 0 deletions packages/execution/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export * from './interfaces/simple-fallback-provider-config';
export * from './interfaces/module.options';
export * from './interfaces/non-empty-array';
export * from './ethers/fee-history';
export * from './ethers/block-tag';
export * from './error';
export * from './events';

0 comments on commit 7cd70cb

Please sign in to comment.