Skip to content

Commit

Permalink
Export LoadBlocks and ReplayBlocks (#4898)
Browse files Browse the repository at this point in the history
* Define StateGenerator

* Gaz

* Delete interface.go

* Update BUILD.bazel

Co-authored-by: Nishant Das <nish1993@hotmail.com>
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Feb 18, 2020
1 parent 25308ef commit 0e37b49
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions beacon-chain/stategen/replay.go
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/prysmaticlabs/prysm/shared/bytesutil"
)

// This replays the input blocks on the input state until the target slot is reached.
func (s *State) replayBlocks(ctx context.Context, state *state.BeaconState, signed []*ethpb.SignedBeaconBlock, targetSlot uint64) (*state.BeaconState, error) {
// ReplayBlocks replays the input blocks on the input state until the target slot is reached.
func (s *State) ReplayBlocks(ctx context.Context, state *state.BeaconState, signed []*ethpb.SignedBeaconBlock, targetSlot uint64) (*state.BeaconState, error) {
var err error
// The input block list is sorted in decreasing slots order.
if len(signed) > 0 {
Expand All @@ -33,9 +33,9 @@ func (s *State) replayBlocks(ctx context.Context, state *state.BeaconState, sign
return state, nil
}

// This loads the blocks between start slot and end slot by recursively fetching from end block root.
// LoadBlocks loads the blocks between start slot and end slot by recursively fetching from end block root.
// The Blocks are returned in slot-descending order.
func (s *State) loadBlocks(ctx context.Context, startSlot uint64, endSlot uint64, endBlockRoot [32]byte) ([]*ethpb.SignedBeaconBlock, error) {
func (s *State) LoadBlocks(ctx context.Context, startSlot uint64, endSlot uint64, endBlockRoot [32]byte) ([]*ethpb.SignedBeaconBlock, error) {
filter := filters.NewFilter().SetStartSlot(startSlot).SetEndSlot(endSlot)
blocks, err := s.beaconDB.Blocks(ctx, filter)
if err != nil {
Expand Down
18 changes: 9 additions & 9 deletions beacon-chain/stategen/replay_test.go
Expand Up @@ -43,7 +43,7 @@ func TestReplayBlocks_AllSkipSlots(t *testing.T) {

service := New(db)
targetSlot := params.BeaconConfig().SlotsPerEpoch - 1
newState, err := service.replayBlocks(context.Background(), beaconState, []*ethpb.SignedBeaconBlock{}, targetSlot)
newState, err := service.ReplayBlocks(context.Background(), beaconState, []*ethpb.SignedBeaconBlock{}, targetSlot)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestReplayBlocks_SameSlot(t *testing.T) {

service := New(db)
targetSlot := beaconState.Slot()
newState, err := service.replayBlocks(context.Background(), beaconState, []*ethpb.SignedBeaconBlock{}, targetSlot)
newState, err := service.ReplayBlocks(context.Background(), beaconState, []*ethpb.SignedBeaconBlock{}, targetSlot)
if err != nil {
t.Fatal(err)
}
Expand All @@ -102,7 +102,7 @@ func TestLoadBlocks_FirstBranch(t *testing.T) {
t.Fatal(err)
}

filteredBlocks, err := s.loadBlocks(ctx, 0, 8, roots[len(roots)-1])
filteredBlocks, err := s.LoadBlocks(ctx, 0, 8, roots[len(roots)-1])
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -133,7 +133,7 @@ func TestLoadBlocks_SecondBranch(t *testing.T) {
t.Fatal(err)
}

filteredBlocks, err := s.loadBlocks(ctx, 0, 5, roots[5])
filteredBlocks, err := s.LoadBlocks(ctx, 0, 5, roots[5])
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestLoadBlocks_ThirdBranch(t *testing.T) {
t.Fatal(err)
}

filteredBlocks, err := s.loadBlocks(ctx, 0, 7, roots[7])
filteredBlocks, err := s.LoadBlocks(ctx, 0, 7, roots[7])
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -193,7 +193,7 @@ func TestLoadBlocks_SameSlots(t *testing.T) {
t.Fatal(err)
}

filteredBlocks, err := s.loadBlocks(ctx, 0, 3, roots[6])
filteredBlocks, err := s.LoadBlocks(ctx, 0, 3, roots[6])
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -222,7 +222,7 @@ func TestLoadBlocks_SameEndSlots(t *testing.T) {
t.Fatal(err)
}

filteredBlocks, err := s.loadBlocks(ctx, 0, 2, roots[2])
filteredBlocks, err := s.LoadBlocks(ctx, 0, 2, roots[2])
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -250,7 +250,7 @@ func TestLoadBlocks_SameEndSlotsWith2blocks(t *testing.T) {
t.Fatal(err)
}

filteredBlocks, err := s.loadBlocks(ctx, 0, 2, roots[1])
filteredBlocks, err := s.LoadBlocks(ctx, 0, 2, roots[1])
if err != nil {
t.Fatal(err)
}
Expand All @@ -276,7 +276,7 @@ func TestLoadBlocks_BadStart(t *testing.T) {
if err != nil {
t.Fatal(err)
}
_, err = s.loadBlocks(ctx, 0, 5, roots[8])
_, err = s.LoadBlocks(ctx, 0, 5, roots[8])
if err.Error() != "end block roots don't match" {
t.Error("Did not get wanted error")
}
Expand Down

0 comments on commit 0e37b49

Please sign in to comment.