Fix cold state replay to start at correct slot (#6361)

* Fix off by 1
* Regression tests
* Merge branch 'master' of github.com:prysmaticlabs/prysm into fix-offset
* Go fmt
* Merge refs/heads/master into fix-offset
* Merge refs/heads/master into fix-offset
This commit is contained in:
terence tsao 2020-06-23 09:04:42 -07:00 committed by GitHub
parent 81786159e9
commit c417b00675
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View File

@ -312,11 +312,7 @@ func (s *State) genesisRoot(ctx context.Context) ([32]byte, error) {
// If the archived root is not available at that exact input slot due to an event of skip block,
// this will look back and return the last available archived root (ie. the one with the highest slot below input slot).
func (s *State) archivedRoot(ctx context.Context, slot uint64) ([32]byte, error) {
archivedIndex := uint64(0)
if slot/params.BeaconConfig().SlotsPerArchivedPoint > 1 {
archivedIndex = slot/params.BeaconConfig().SlotsPerArchivedPoint - 1
}
archivedIndex := slot / params.BeaconConfig().SlotsPerArchivedPoint
for archivedIndex > 0 {
if ctx.Err() != nil {
return [32]byte{}, ctx.Err()

View File

@ -630,7 +630,14 @@ func TestArchivedState_CanGetSpecificIndex(t *testing.T) {
if err := db.SaveState(ctx, beaconState, r); err != nil {
t.Fatal(err)
}
got, err := service.archivedState(ctx, params.BeaconConfig().SlotsPerArchivedPoint*2)
got, err := service.archivedState(ctx, params.BeaconConfig().SlotsPerArchivedPoint)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(got.InnerStateUnsafe(), beaconState.InnerStateUnsafe()) {
t.Error("Did not get wanted state")
}
got, err = service.archivedState(ctx, params.BeaconConfig().SlotsPerArchivedPoint*2)
if err != nil {
t.Fatal(err)
}