Unmarshal Block instead of State (#5246)

* unmarshal block instead of state
* add fallback
* Merge refs/heads/master into dontUnmarshal
* Merge refs/heads/master into dontUnmarshal
* Merge refs/heads/master into dontUnmarshal
* Merge refs/heads/master into dontUnmarshal
* Merge refs/heads/master into dontUnmarshal
* Merge refs/heads/master into dontUnmarshal
* Merge refs/heads/master into dontUnmarshal
* Merge refs/heads/master into dontUnmarshal
This commit is contained in:
Nishant Das 2020-03-31 23:25:58 +08:00 committed by GitHub
parent 3e81afd7ab
commit c8f8e3f1e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -308,20 +308,34 @@ func slotByBlockRoot(ctx context.Context, tx *bolt.Tx, blockRoot []byte) (uint64
return stateSummary.Slot, nil
}
bkt := tx.Bucket(stateBucket)
bkt := tx.Bucket(blocksBucket)
enc := bkt.Get(blockRoot)
if enc == nil {
return 0, errors.New("state enc can't be nil")
// fallback and check the state.
bkt = tx.Bucket(stateBucket)
enc = bkt.Get(blockRoot)
if enc == nil {
return 0, errors.New("state enc can't be nil")
}
s, err := createState(enc)
if err != nil {
return 0, err
}
if s == nil {
return 0, errors.New("state can't be nil")
}
return s.Slot, nil
}
s, err := createState(enc)
b := &ethpb.SignedBeaconBlock{}
err := decode(enc, b)
if err != nil {
return 0, err
}
if s == nil {
return 0, errors.New("state can't be nil")
if b.Block == nil {
return 0, errors.New("block can't be nil")
}
return s.Slot, nil
return b.Block.Slot, nil
}
// HighestSlotStates returns the states with the highest slot from the db.