From f0fbbc60a0a566b04a6046c654cff17dc009a909 Mon Sep 17 00:00:00 2001 From: rkapka Date: Tue, 10 Jan 2023 18:33:41 +0100 Subject: [PATCH] Replay state to current slot in `StateBySlot` --- beacon-chain/rpc/statefetcher/fetcher.go | 3 --- beacon-chain/rpc/statefetcher/fetcher_test.go | 15 ++++++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/beacon-chain/rpc/statefetcher/fetcher.go b/beacon-chain/rpc/statefetcher/fetcher.go index 65221d9a900d..3803f5698c09 100644 --- a/beacon-chain/rpc/statefetcher/fetcher.go +++ b/beacon-chain/rpc/statefetcher/fetcher.go @@ -203,9 +203,6 @@ func (p *StateProvider) StateBySlot(ctx context.Context, target types.Slot) (sta if target > p.GenesisTimeFetcher.CurrentSlot() { return nil, errors.New("requested slot is in the future") } - if target > p.ChainInfoFetcher.HeadSlot() { - return nil, errors.New("requested slot number is higher than head slot number") - } st, err := p.ReplayerBuilder.ReplayerForSlot(target).ReplayBlocks(ctx) if err != nil { diff --git a/beacon-chain/rpc/statefetcher/fetcher_test.go b/beacon-chain/rpc/statefetcher/fetcher_test.go index deba4b55717c..d19aa65463b3 100644 --- a/beacon-chain/rpc/statefetcher/fetcher_test.go +++ b/beacon-chain/rpc/statefetcher/fetcher_test.go @@ -387,11 +387,16 @@ func TestStateBySlot_FutureSlot(t *testing.T) { } func TestStateBySlot_AfterHeadSlot(t *testing.T) { - st, err := statenative.InitializeFromProtoPhase0(ðpb.BeaconState{Slot: 100}) + headSt, err := statenative.InitializeFromProtoPhase0(ðpb.BeaconState{Slot: 100}) + require.NoError(t, err) + slotSt, err := statenative.InitializeFromProtoPhase0(ðpb.BeaconState{Slot: 101}) require.NoError(t, err) currentSlot := types.Slot(102) - mock := &chainMock.ChainService{State: st, Slot: ¤tSlot} - p := StateProvider{ChainInfoFetcher: mock, GenesisTimeFetcher: mock} - _, err = p.StateBySlot(context.Background(), 101) - assert.ErrorContains(t, "requested slot number is higher than head slot number", err) + mock := &chainMock.ChainService{State: headSt, Slot: ¤tSlot} + mockReplayer := mockstategen.NewMockReplayerBuilder() + mockReplayer.SetMockStateForSlot(slotSt, 101) + p := StateProvider{ChainInfoFetcher: mock, GenesisTimeFetcher: mock, ReplayerBuilder: mockReplayer} + st, err := p.StateBySlot(context.Background(), 101) + require.NoError(t, err) + assert.Equal(t, types.Slot(101), st.Slot()) }