Compare commits

...

2 Commits

Author SHA1 Message Date
terence tsao
dcb1fa5b8a Check migration state before safe 2023-03-26 16:34:10 -07:00
terencechain
b00f7f4592 Update the badges to latest version (#12145)
Co-authored-by: james-prysm <90280386+james-prysm@users.noreply.github.com>
Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
2023-03-24 18:02:53 +00:00
2 changed files with 23 additions and 3 deletions

View File

@@ -2,8 +2,8 @@
[![Build status](https://badge.buildkite.com/b555891daf3614bae4284dcf365b2340cefc0089839526f096.svg?branch=master)](https://buildkite.com/prysmatic-labs/prysm)
[![Go Report Card](https://goreportcard.com/badge/github.com/prysmaticlabs/prysm)](https://goreportcard.com/report/github.com/prysmaticlabs/prysm)
[![Consensus_Spec_Version 1.2.0](https://img.shields.io/badge/Consensus%20Spec%20Version-v1.2.0-blue.svg)](https://github.com/ethereum/consensus-specs/tree/v1.2.0)
[![Execution_API_Version 1.0.0-beta.1](https://img.shields.io/badge/Execution%20API%20Version-v1.0.0.beta.1-blue.svg)](https://github.com/ethereum/execution-apis/tree/v1.0.0-beta.1/src/engine)
[![Consensus_Spec_Version 1.3.0](https://img.shields.io/badge/Consensus%20Spec%20Version-v1.3.0-blue.svg)](https://github.com/ethereum/consensus-specs/tree/v1.3.0)
[![Execution_API_Version 1.0.0-beta.2](https://img.shields.io/badge/Execution%20API%20Version-v1.0.0.beta.2-blue.svg)](https://github.com/ethereum/execution-apis/tree/v1.0.0-beta.2/src/engine)
[![Discord](https://user-images.githubusercontent.com/7288322/34471967-1df7808a-efbb-11e7-9088-ed0b04151291.png)](https://discord.gg/CTYGPUJ)
[![GitPOAP Badge](https://public-api.gitpoap.io/v1/repo/prysmaticlabs/prysm/badge)](https://www.gitpoap.io/gh/prysmaticlabs/prysm)

View File

@@ -1,11 +1,14 @@
package stategen
import (
"bytes"
"context"
"encoding/hex"
"fmt"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v4/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v4/config/params"
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil"
"github.com/sirupsen/logrus"
"go.opencensus.io/trace"
@@ -33,7 +36,7 @@ func (s *State) MigrateToCold(ctx context.Context, fRoot [32]byte) error {
return err
}
fSlot := fBlock.Block().Slot()
if oldFSlot > fSlot {
if oldFSlot >= fSlot {
return nil
}
@@ -98,6 +101,23 @@ func (s *State) MigrateToCold(ctx context.Context, fRoot [32]byte) error {
continue
}
header := aState.LatestBlockHeader()
zeroHash := params.BeaconConfig().ZeroHash
if header.StateRoot == nil || bytes.Equal(header.StateRoot, zeroHash[:]) {
prevStateRoot, err := aState.HashTreeRoot(ctx)
if err != nil {
return errors.Wrap(err, "could not get state root")
}
header.StateRoot = prevStateRoot[:]
}
r, err := header.HashTreeRoot()
if err != nil {
return errors.Wrap(err, "could not get header root")
}
if r != aRoot {
return fmt.Errorf("could not migrate, block root %#x does not match the state root %#x", r, aRoot)
}
if err := s.beaconDB.SaveState(ctx, aState, aRoot); err != nil {
return err
}