From c8f8e3f1e0365247525e00aa7748a7a921cf910e Mon Sep 17 00:00:00 2001 From: Nishant Das Date: Tue, 31 Mar 2020 23:25:58 +0800 Subject: [PATCH] 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 --- beacon-chain/db/kv/state.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/beacon-chain/db/kv/state.go b/beacon-chain/db/kv/state.go index 5dbae62dd..cde0300e5 100644 --- a/beacon-chain/db/kv/state.go +++ b/beacon-chain/db/kv/state.go @@ -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 := ðpb.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.