Skip to content

Commit

Permalink
Deneb integration: Beacon API getStateV2 (#12424)
Browse files Browse the repository at this point in the history
Co-authored-by: Nishant Das <nishdas93@gmail.com>
Fix Migration Of State (#12423)
  • Loading branch information
rkapka authored and kasey committed Aug 24, 2023
1 parent c740396 commit bd5d6bc
Show file tree
Hide file tree
Showing 10 changed files with 1,218 additions and 227 deletions.
14 changes: 14 additions & 0 deletions beacon-chain/rpc/eth/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ func (ds *Server) GetBeaconStateV2(ctx context.Context, req *ethpbv2.BeaconState
ExecutionOptimistic: isOptimistic,
Finalized: isFinalized,
}, nil
case version.Deneb:
protoState, err := migration.BeaconStateDenebToProto(beaconSt)
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not convert state to proto: %v", err)
}
return &ethpbv2.BeaconStateResponseV2{
Version: ethpbv2.Version_DENEB,
Data: &ethpbv2.BeaconStateContainer{
State: &ethpbv2.BeaconStateContainer_DenebState{DenebState: protoState},
},
ExecutionOptimistic: isOptimistic,
}, nil
default:
return nil, status.Error(codes.Internal, "Unsupported state version")
}
Expand Down Expand Up @@ -133,6 +145,8 @@ func (ds *Server) GetBeaconStateSSZV2(ctx context.Context, req *ethpbv2.BeaconSt
ver = ethpbv2.Version_BELLATRIX
case version.Capella:
ver = ethpbv2.Version_CAPELLA
case version.Deneb:
ver = ethpbv2.Version_DENEB
default:
return nil, status.Error(codes.Internal, "Unsupported state version")
}
Expand Down
37 changes: 37 additions & 0 deletions beacon-chain/rpc/eth/debug/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,24 @@ func TestGetBeaconStateV2(t *testing.T) {
assert.NotNil(t, resp)
assert.Equal(t, ethpbv2.Version_CAPELLA, resp.Version)
})
t.Run("Deneb", func(t *testing.T) {
fakeState, _ := util.DeterministicGenesisStateDeneb(t, 1)
server := &Server{
Stater: &testutil.MockStater{
BeaconState: fakeState,
},
HeadFetcher: &blockchainmock.ChainService{},
OptimisticModeFetcher: &blockchainmock.ChainService{},
FinalizationFetcher: &blockchainmock.ChainService{},
BeaconDB: db,
}
resp, err := server.GetBeaconStateV2(context.Background(), &ethpbv2.BeaconStateRequestV2{
StateId: []byte("head"),
})
require.NoError(t, err)
assert.NotNil(t, resp)
assert.Equal(t, ethpbv2.Version_DENEB, resp.Version)
})
t.Run("execution optimistic", func(t *testing.T) {
parentRoot := [32]byte{'a'}
blk := util.NewBeaconBlock()
Expand Down Expand Up @@ -256,6 +274,25 @@ func TestGetBeaconStateSSZV2(t *testing.T) {
assert.DeepEqual(t, sszState, resp.Data)
assert.Equal(t, ethpbv2.Version_CAPELLA, resp.Version)
})
t.Run("Deneb", func(t *testing.T) {
fakeState, _ := util.DeterministicGenesisStateDeneb(t, 1)
sszState, err := fakeState.MarshalSSZ()
require.NoError(t, err)

server := &Server{
Stater: &testutil.MockStater{
BeaconState: fakeState,
},
}
resp, err := server.GetBeaconStateSSZV2(context.Background(), &ethpbv2.BeaconStateRequestV2{
StateId: make([]byte, 0),
})
require.NoError(t, err)
assert.NotNil(t, resp)

assert.DeepEqual(t, sszState, resp.Data)
assert.Equal(t, ethpbv2.Version_DENEB, resp.Version)
})
}

func TestListForkChoiceHeadsV2(t *testing.T) {
Expand Down
Loading

0 comments on commit bd5d6bc

Please sign in to comment.