Compare commits

..

4 Commits

Author SHA1 Message Date
Kasey Kirkham
43659370c1 finish wiring up ugly wrapper hack 2022-08-29 09:04:06 -05:00
Kasey Kirkham
179186109d lint & fmt 2022-08-26 20:50:40 -05:00
Kasey Kirkham
da22052fb9 changed signature of stategen.New, updating calls 2022-08-24 16:34:43 -05:00
Kasey Kirkham
fa70f8c375 wip moving hot state saving logic into own type 2022-08-19 11:16:26 -05:00
73 changed files with 1557 additions and 979 deletions

View File

@@ -5,7 +5,7 @@ import (
"testing"
testDB "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
sgmock "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
"github.com/prysmaticlabs/prysm/v3/consensus-types/blocks"
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v3/testing/require"
@@ -32,7 +32,7 @@ func TestHeadSlot_DataRace(t *testing.T) {
func TestHeadRoot_DataRace(t *testing.T) {
beaconDB := testDB.SetupDB(t)
s := &Service{
cfg: &config{BeaconDB: beaconDB, StateGen: stategen.New(beaconDB)},
cfg: &config{BeaconDB: beaconDB, StateGen: sgmock.NewMockStategen(beaconDB)},
head: &head{root: [32]byte{'A'}},
}
b, err := blocks.NewSignedBeaconBlock(util.NewBeaconBlock())
@@ -54,7 +54,7 @@ func TestHeadBlock_DataRace(t *testing.T) {
wsb, err := blocks.NewSignedBeaconBlock(&ethpb.SignedBeaconBlock{Block: &ethpb.BeaconBlock{Body: &ethpb.BeaconBlockBody{}}})
require.NoError(t, err)
s := &Service{
cfg: &config{BeaconDB: beaconDB, StateGen: stategen.New(beaconDB)},
cfg: &config{BeaconDB: beaconDB, StateGen: sgmock.NewMockStategen(beaconDB)},
head: &head{block: wsb},
}
b, err := blocks.NewSignedBeaconBlock(util.NewBeaconBlock())
@@ -74,7 +74,7 @@ func TestHeadBlock_DataRace(t *testing.T) {
func TestHeadState_DataRace(t *testing.T) {
beaconDB := testDB.SetupDB(t)
s := &Service{
cfg: &config{BeaconDB: beaconDB, StateGen: stategen.New(beaconDB)},
cfg: &config{BeaconDB: beaconDB, StateGen: sgmock.NewMockStategen(beaconDB)},
}
b, err := blocks.NewSignedBeaconBlock(util.NewBeaconBlock())
require.NoError(t, err)

View File

@@ -10,7 +10,7 @@ import (
"github.com/prysmaticlabs/prysm/v3/beacon-chain/forkchoice/protoarray"
forkchoicetypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/forkchoice/types"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
sgmock "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1"
v3 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v3"
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
@@ -86,7 +86,7 @@ func TestFinalizedCheckpt_GenesisRootOk(t *testing.T) {
opts := []Option{
WithDatabase(beaconDB),
WithForkChoiceStore(fcs),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
}
service, err := NewService(ctx, opts...)
require.NoError(t, err)
@@ -111,7 +111,7 @@ func TestCurrentJustifiedCheckpt_CanRetrieve(t *testing.T) {
opts := []Option{
WithDatabase(beaconDB),
WithForkChoiceStore(fcs),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
}
service, err := NewService(ctx, opts...)
require.NoError(t, err)
@@ -138,7 +138,7 @@ func TestHeadRoot_CanRetrieve(t *testing.T) {
opts := []Option{
WithDatabase(beaconDB),
WithForkChoiceStore(fcs),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
}
service, err := NewService(ctx, opts...)
require.NoError(t, err)
@@ -157,7 +157,7 @@ func TestHeadRoot_UseDB(t *testing.T) {
opts := []Option{
WithDatabase(beaconDB),
WithForkChoiceStore(fcs),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
}
service, err := NewService(ctx, opts...)
require.NoError(t, err)

View File

@@ -16,7 +16,7 @@ import (
"github.com/prysmaticlabs/prysm/v3/beacon-chain/forkchoice/protoarray"
forkchoicetypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/forkchoice/types"
bstate "github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
sgmock "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
"github.com/prysmaticlabs/prysm/v3/config/params"
consensusblocks "github.com/prysmaticlabs/prysm/v3/consensus-types/blocks"
@@ -44,7 +44,7 @@ func Test_NotifyForkchoiceUpdate(t *testing.T) {
fcs := doublylinkedtree.New()
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(fcs),
WithProposerIdsCache(cache.NewProposerPayloadIDsCache()),
}
@@ -578,7 +578,7 @@ func Test_NotifyNewPayload(t *testing.T) {
fcs := doublylinkedtree.New()
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(fcs),
}
phase0State, _ := util.DeterministicGenesisState(t, 1)
@@ -824,7 +824,7 @@ func Test_NotifyNewPayload_SetOptimisticToValid(t *testing.T) {
fcs := doublylinkedtree.New()
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(fcs),
}
bellatrixState, _ := util.DeterministicGenesisStateBellatrix(t, 2)
@@ -871,7 +871,7 @@ func Test_IsOptimisticCandidateBlock(t *testing.T) {
fcs := doublylinkedtree.New()
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(fcs),
}
@@ -975,7 +975,7 @@ func Test_IsOptimisticShallowExecutionParent(t *testing.T) {
beaconDB := testDB.SetupDB(t)
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
}
service, err := NewService(ctx, opts...)
@@ -1016,7 +1016,7 @@ func Test_GetPayloadAttribute(t *testing.T) {
beaconDB := testDB.SetupDB(t)
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithProposerIdsCache(cache.NewProposerPayloadIDsCache()),
}
@@ -1058,7 +1058,7 @@ func Test_UpdateLastValidatedCheckpoint(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
stateGen := stategen.New(beaconDB)
stateGen := sgmock.NewMockStategen(beaconDB)
fcs := doublylinkedtree.New()
opts := []Option{
WithDatabase(beaconDB),
@@ -1162,7 +1162,7 @@ func TestService_removeInvalidBlockAndState(t *testing.T) {
beaconDB := testDB.SetupDB(t)
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(doublylinkedtree.New()),
}
service, err := NewService(ctx, opts...)
@@ -1214,7 +1214,7 @@ func TestService_getPayloadHash(t *testing.T) {
beaconDB := testDB.SetupDB(t)
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(doublylinkedtree.New()),
}
service, err := NewService(ctx, opts...)

View File

@@ -87,6 +87,7 @@ func (s *Service) saveHead(ctx context.Context, newHeadRoot [32]byte, headBlock
return nil
}
// A chain re-org occurred, so we fire an event notifying the rest of the services.
s.headLock.RLock()
oldHeadBlock, err := s.headBlock()
if err != nil {
@@ -97,21 +98,11 @@ func (s *Service) saveHead(ctx context.Context, newHeadRoot [32]byte, headBlock
headSlot := s.HeadSlot()
newHeadSlot := headBlock.Block().Slot()
newStateRoot := headBlock.Block().StateRoot()
// A chain re-org occurred, so we fire an event notifying the rest of the services.
if bytesutil.ToBytes32(headBlock.Block().ParentRoot()) != oldHeadRoot {
commonRoot, err := s.ForkChoicer().CommonAncestorRoot(ctx, oldHeadRoot, newHeadRoot)
if err != nil {
log.WithError(err).Error("Could not find common ancestor root")
commonRoot = params.BeaconConfig().ZeroHash
}
log.WithFields(logrus.Fields{
"newSlot": fmt.Sprintf("%d", newHeadSlot),
"newRoot": fmt.Sprintf("%#x", newHeadRoot),
"oldSlot": fmt.Sprintf("%d", headSlot),
"oldRoot": fmt.Sprintf("%#x", oldHeadRoot),
"commonAncestorRoot": fmt.Sprintf("%#x", commonRoot),
}).Info("Chain reorg occurred")
"newSlot": fmt.Sprintf("%d", newHeadSlot),
"oldSlot": fmt.Sprintf("%d", headSlot),
}).Debug("Chain reorg occurred")
absoluteSlotDifference := slots.AbsoluteValueSlotDifference(newHeadSlot, headSlot)
isOptimistic, err := s.IsOptimistic(ctx)
if err != nil {

View File

@@ -7,7 +7,7 @@ import (
"github.com/prysmaticlabs/prysm/v3/beacon-chain/cache"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/signing"
dbtest "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
sgmock "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
"github.com/prysmaticlabs/prysm/v3/config/params"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v3/testing/require"
@@ -19,7 +19,7 @@ func TestService_headSyncCommitteeFetcher_Errors(t *testing.T) {
beaconDB := dbtest.SetupDB(t)
c := &Service{
cfg: &config{
StateGen: stategen.New(beaconDB),
StateGen: sgmock.NewMockStategen(beaconDB),
},
}
c.head = &head{}
@@ -37,7 +37,7 @@ func TestService_HeadDomainFetcher_Errors(t *testing.T) {
beaconDB := dbtest.SetupDB(t)
c := &Service{
cfg: &config{
StateGen: stategen.New(beaconDB),
StateGen: sgmock.NewMockStategen(beaconDB),
},
}
c.head = &head{}

View File

@@ -11,7 +11,7 @@ import (
testDB "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing"
doublylinkedtree "github.com/prysmaticlabs/prysm/v3/beacon-chain/forkchoice/doubly-linked-tree"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/forkchoice/protoarray"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
sgmock "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
"github.com/prysmaticlabs/prysm/v3/config/features"
"github.com/prysmaticlabs/prysm/v3/config/params"
"github.com/prysmaticlabs/prysm/v3/consensus-types/blocks"
@@ -536,7 +536,7 @@ func TestUpdateHead_noSavedChanges(t *testing.T) {
fcs := doublylinkedtree.New()
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(fcs),
}

View File

@@ -8,7 +8,7 @@ import (
testDB "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/forkchoice/protoarray"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
sgmock "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
)
func testServiceOptsWithDB(t *testing.T) []Option {
@@ -16,7 +16,7 @@ func testServiceOptsWithDB(t *testing.T) []Option {
fcs := protoarray.New()
return []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(fcs),
}
}

View File

@@ -11,7 +11,7 @@ import (
testDB "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing"
mocks "github.com/prysmaticlabs/prysm/v3/beacon-chain/execution/testing"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/forkchoice/protoarray"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
sgmock "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
"github.com/prysmaticlabs/prysm/v3/config/params"
"github.com/prysmaticlabs/prysm/v3/consensus-types/blocks"
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
@@ -112,7 +112,7 @@ func Test_validateMergeBlock(t *testing.T) {
fcs := protoarray.New()
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(fcs),
}
service, err := NewService(ctx, opts...)
@@ -162,7 +162,7 @@ func Test_getBlkParentHashAndTD(t *testing.T) {
fcs := protoarray.New()
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(fcs),
}
service, err := NewService(ctx, opts...)

View File

@@ -10,7 +10,7 @@ import (
doublylinkedtree "github.com/prysmaticlabs/prysm/v3/beacon-chain/forkchoice/doubly-linked-tree"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/forkchoice/protoarray"
forkchoicetypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/forkchoice/types"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
sgmock "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
"github.com/prysmaticlabs/prysm/v3/config/params"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
@@ -29,7 +29,7 @@ func TestStore_OnAttestation_ErrorConditions_ProtoArray(t *testing.T) {
opts := []Option{
WithDatabase(beaconDB),
WithForkChoiceStore(doublylinkedtree.New()),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
}
service, err := NewService(ctx, opts...)
require.NoError(t, err)
@@ -135,7 +135,7 @@ func TestStore_OnAttestation_ErrorConditions_DoublyLinkedTree(t *testing.T) {
opts := []Option{
WithDatabase(beaconDB),
WithForkChoiceStore(doublylinkedtree.New()),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
}
service, err := NewService(ctx, opts...)
require.NoError(t, err)
@@ -241,7 +241,7 @@ func TestStore_OnAttestation_Ok_ProtoArray(t *testing.T) {
fcs := protoarray.New()
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(fcs),
}
service, err := NewService(ctx, opts...)
@@ -271,7 +271,7 @@ func TestStore_OnAttestation_Ok_DoublyLinkedTree(t *testing.T) {
fcs := doublylinkedtree.New()
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(fcs),
}
service, err := NewService(ctx, opts...)
@@ -300,7 +300,7 @@ func TestStore_SaveCheckpointState(t *testing.T) {
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
}
service, err := NewService(ctx, opts...)
require.NoError(t, err)
@@ -362,7 +362,7 @@ func TestStore_UpdateCheckpointState(t *testing.T) {
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
}
service, err := NewService(ctx, opts...)
require.NoError(t, err)
@@ -468,7 +468,7 @@ func TestVerifyFinalizedConsistency_InconsistentRoot_ProtoArray(t *testing.T) {
fcs := protoarray.New()
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(fcs),
}
service, err := NewService(ctx, opts...)
@@ -499,7 +499,7 @@ func TestVerifyFinalizedConsistency_InconsistentRoot_DoublyLinkedTree(t *testing
fcs := doublylinkedtree.New()
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(fcs),
}
service, err := NewService(ctx, opts...)

View File

@@ -132,9 +132,6 @@ func (s *Service) onBlock(ctx context.Context, signed interfaces.SignedBeaconBlo
return err
}
}
if err := s.savePostStateInfo(ctx, blockRoot, signed, postState); err != nil {
return err
}
if err := s.insertBlockToForkchoiceStore(ctx, signed.Block(), blockRoot, postState); err != nil {
return errors.Wrapf(err, "could not insert block %d to fork choice store", signed.Block().Slot())
@@ -146,6 +143,13 @@ func (s *Service) onBlock(ctx context.Context, signed interfaces.SignedBeaconBlo
}
}
if err := s.cfg.BeaconDB.SaveBlock(ctx, signed); err != nil {
return errors.Wrapf(err, "could not save block from slot %d", signed.Block().Slot())
}
if err := s.cfg.StateGen.SaveState(ctx, blockRoot, postState); err != nil {
return errors.Wrap(err, "could not save state")
}
// If slasher is configured, forward the attestations in the block via
// an event feed for processing.
if features.Get().EnableSlasher {
@@ -527,20 +531,6 @@ func (s *Service) InsertSlashingsToForkChoiceStore(ctx context.Context, slashing
}
}
// This saves post state info to DB or cache. This also saves post state info to fork choice store.
// Post state info consists of processed block and state. Do not call this method unless the block and state are verified.
func (s *Service) savePostStateInfo(ctx context.Context, r [32]byte, b interfaces.SignedBeaconBlock, st state.BeaconState) error {
ctx, span := trace.StartSpan(ctx, "blockChain.savePostStateInfo")
defer span.End()
if err := s.cfg.BeaconDB.SaveBlock(ctx, b); err != nil {
return errors.Wrapf(err, "could not save block from slot %d", b.Block().Slot())
}
if err := s.cfg.StateGen.SaveState(ctx, r, st); err != nil {
return errors.Wrap(err, "could not save state")
}
return nil
}
// This removes the attestations from the mem pool. It will only remove the attestations if input root `r` is canonical,
// meaning the block `b` is part of the canonical chain.
func (s *Service) pruneCanonicalAttsFromPool(ctx context.Context, r [32]byte, b interfaces.SignedBeaconBlock) error {

View File

@@ -27,7 +27,7 @@ import (
forkchoicetypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/forkchoice/types"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/operations/attestations"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
sgmock "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1"
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
"github.com/prysmaticlabs/prysm/v3/config/params"
@@ -53,7 +53,7 @@ func TestStore_OnBlock_ProtoArray(t *testing.T) {
fcs := protoarray.New()
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(fcs),
}
@@ -149,7 +149,7 @@ func TestStore_OnBlock_DoublyLinkedTree(t *testing.T) {
fcs := doublylinkedtree.New()
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(fcs),
}
@@ -244,7 +244,7 @@ func TestStore_OnBlockBatch_ProtoArray(t *testing.T) {
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(protoarray.New()),
}
service, err := NewService(ctx, opts...)
@@ -285,7 +285,7 @@ func TestStore_OnBlockBatch_PruneOK_Protoarray(t *testing.T) {
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(protoarray.New()),
}
service, err := NewService(ctx, opts...)
@@ -321,7 +321,7 @@ func TestStore_OnBlockBatch_DoublyLinkedTree(t *testing.T) {
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(doublylinkedtree.New()),
}
service, err := NewService(ctx, opts...)
@@ -364,7 +364,7 @@ func TestStore_OnBlockBatch_NotifyNewPayload(t *testing.T) {
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(doublylinkedtree.New()),
}
service, err := NewService(ctx, opts...)
@@ -399,7 +399,7 @@ func TestCachedPreState_CanGetFromStateSummary_ProtoArray(t *testing.T) {
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(protoarray.New()),
}
service, err := NewService(ctx, opts...)
@@ -426,7 +426,7 @@ func TestCachedPreState_CanGetFromStateSummary_DoublyLinkedTree(t *testing.T) {
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(doublylinkedtree.New()),
}
service, err := NewService(ctx, opts...)
@@ -453,7 +453,7 @@ func TestFillForkChoiceMissingBlocks_CanSave_ProtoArray(t *testing.T) {
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
}
service, err := NewService(ctx, opts...)
require.NoError(t, err)
@@ -494,7 +494,7 @@ func TestFillForkChoiceMissingBlocks_CanSave_DoublyLinkedTree(t *testing.T) {
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
}
service, err := NewService(ctx, opts...)
require.NoError(t, err)
@@ -543,7 +543,7 @@ func TestFillForkChoiceMissingBlocks_RootsMatch_ProtoArray(t *testing.T) {
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
}
service, err := NewService(ctx, opts...)
require.NoError(t, err)
@@ -586,7 +586,7 @@ func TestFillForkChoiceMissingBlocks_RootsMatch_DoublyLinkedTree(t *testing.T) {
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
}
service, err := NewService(ctx, opts...)
require.NoError(t, err)
@@ -637,7 +637,7 @@ func TestFillForkChoiceMissingBlocks_FilterFinalized_ProtoArray(t *testing.T) {
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
}
service, err := NewService(ctx, opts...)
require.NoError(t, err)
@@ -694,7 +694,7 @@ func TestFillForkChoiceMissingBlocks_FilterFinalized_DoublyLinkedTree(t *testing
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
}
service, err := NewService(ctx, opts...)
require.NoError(t, err)
@@ -752,7 +752,7 @@ func TestFillForkChoiceMissingBlocks_FinalizedSibling_DoublyLinkedTree(t *testin
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
}
service, err := NewService(ctx, opts...)
require.NoError(t, err)
@@ -897,7 +897,7 @@ func TestAncestor_HandleSkipSlot(t *testing.T) {
fcs := doublylinkedtree.New()
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(fcs),
}
service, err := NewService(ctx, opts...)
@@ -988,7 +988,7 @@ func TestAncestor_CanUseDB(t *testing.T) {
fcs := doublylinkedtree.New()
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(fcs),
}
service, err := NewService(ctx, opts...)
@@ -1050,7 +1050,7 @@ func TestVerifyBlkDescendant(t *testing.T) {
fcs := doublylinkedtree.New()
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(fcs),
}
b := util.NewBeaconBlock()
@@ -1159,7 +1159,7 @@ func TestOnBlock_CanFinalize_WithOnTick(t *testing.T) {
require.NoError(t, err)
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(fcs),
WithDepositCache(depositCache),
WithStateNotifier(&mock.MockStateNotifier{}),
@@ -1208,7 +1208,7 @@ func TestOnBlock_CanFinalize(t *testing.T) {
require.NoError(t, err)
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(fcs),
WithDepositCache(depositCache),
WithStateNotifier(&mock.MockStateNotifier{}),
@@ -1256,7 +1256,7 @@ func TestOnBlock_NilBlock(t *testing.T) {
require.NoError(t, err)
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(fcs),
WithDepositCache(depositCache),
}
@@ -1275,7 +1275,7 @@ func TestOnBlock_InvalidSignature(t *testing.T) {
require.NoError(t, err)
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(fcs),
WithDepositCache(depositCache),
WithStateNotifier(&mock.MockStateNotifier{}),
@@ -1311,7 +1311,7 @@ func TestOnBlock_CallNewPayloadAndForkchoiceUpdated(t *testing.T) {
require.NoError(t, err)
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(fcs),
WithDepositCache(depositCache),
WithStateNotifier(&mock.MockStateNotifier{}),
@@ -1524,7 +1524,7 @@ func Test_validateMergeTransitionBlock(t *testing.T) {
fcs := doublylinkedtree.New()
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(fcs),
WithProposerIdsCache(cache.NewProposerPayloadIDsCache()),
WithAttestationPool(attestations.NewPool()),
@@ -1662,7 +1662,7 @@ func TestService_insertSlashingsToForkChoiceStore(t *testing.T) {
fcs := doublylinkedtree.New()
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(fcs),
WithProposerIdsCache(cache.NewProposerPayloadIDsCache()),
}
@@ -1715,7 +1715,7 @@ func TestOnBlock_ProcessBlocksParallel(t *testing.T) {
require.NoError(t, err)
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(fcs),
WithDepositCache(depositCache),
WithStateNotifier(&mock.MockStateNotifier{}),
@@ -1793,7 +1793,7 @@ func Test_verifyBlkFinalizedSlot_invalidBlock(t *testing.T) {
fcs := doublylinkedtree.New()
opts := []Option{
WithDatabase(beaconDB),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(fcs),
}
service, err := NewService(ctx, opts...)
@@ -1828,7 +1828,7 @@ func TestStore_NoViableHead_FCU_Protoarray(t *testing.T) {
opts := []Option{
WithDatabase(beaconDB),
WithAttestationPool(attestations.NewPool()),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(protoarray.New()),
WithStateNotifier(&mock.MockStateNotifier{}),
WithExecutionEngineCaller(mockEngine),
@@ -1988,7 +1988,7 @@ func TestStore_NoViableHead_FCU_DoublyLinkedTree(t *testing.T) {
opts := []Option{
WithDatabase(beaconDB),
WithAttestationPool(attestations.NewPool()),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(doublylinkedtree.New()),
WithStateNotifier(&mock.MockStateNotifier{}),
WithExecutionEngineCaller(mockEngine),
@@ -2148,7 +2148,7 @@ func TestStore_NoViableHead_NewPayload_DoublyLinkedTree(t *testing.T) {
opts := []Option{
WithDatabase(beaconDB),
WithAttestationPool(attestations.NewPool()),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(doublylinkedtree.New()),
WithStateNotifier(&mock.MockStateNotifier{}),
WithExecutionEngineCaller(mockEngine),
@@ -2308,7 +2308,7 @@ func TestStore_NoViableHead_NewPayload_Protoarray(t *testing.T) {
opts := []Option{
WithDatabase(beaconDB),
WithAttestationPool(attestations.NewPool()),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(protoarray.New()),
WithStateNotifier(&mock.MockStateNotifier{}),
WithExecutionEngineCaller(mockEngine),
@@ -2469,7 +2469,7 @@ func TestStore_NoViableHead_Liveness_DoublyLinkedTree(t *testing.T) {
opts := []Option{
WithDatabase(beaconDB),
WithAttestationPool(attestations.NewPool()),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(doublylinkedtree.New()),
WithStateNotifier(&mock.MockStateNotifier{}),
WithExecutionEngineCaller(mockEngine),
@@ -2679,7 +2679,7 @@ func TestStore_NoViableHead_Liveness_Protoarray(t *testing.T) {
opts := []Option{
WithDatabase(beaconDB),
WithAttestationPool(attestations.NewPool()),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(doublylinkedtree.New()),
WithStateNotifier(&mock.MockStateNotifier{}),
WithExecutionEngineCaller(mockEngine),
@@ -2889,7 +2889,7 @@ func TestStore_NoViableHead_Reboot_DoublyLinkedTree(t *testing.T) {
opts := []Option{
WithDatabase(beaconDB),
WithAttestationPool(attestations.NewPool()),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(doublylinkedtree.New()),
WithStateNotifier(&mock.MockStateNotifier{}),
WithExecutionEngineCaller(mockEngine),
@@ -3114,7 +3114,7 @@ func TestStore_NoViableHead_Reboot_Protoarray(t *testing.T) {
opts := []Option{
WithDatabase(beaconDB),
WithAttestationPool(attestations.NewPool()),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithForkChoiceStore(protoarray.New()),
WithStateNotifier(&mock.MockStateNotifier{}),
WithExecutionEngineCaller(mockEngine),

View File

@@ -11,7 +11,6 @@ import (
"github.com/prysmaticlabs/prysm/v3/monitoring/tracing"
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v3/time"
"github.com/prysmaticlabs/prysm/v3/time/slots"
"go.opencensus.io/trace"
)
@@ -56,11 +55,6 @@ func (s *Service) ReceiveBlock(ctx context.Context, block interfaces.SignedBeaco
return err
}
// Have we been finalizing? Should we start saving hot states to db?
if err := s.checkSaveHotStateDB(ctx); err != nil {
return err
}
// Reports on block and fork choice metrics.
finalized := s.FinalizedCheckpt()
reportSlotMetrics(blockCopy.Block().Slot(), s.HeadSlot(), s.CurrentSlot(), finalized)
@@ -166,25 +160,3 @@ func (s *Service) handlePostBlockOperations(b interfaces.BeaconBlock) error {
}
return nil
}
// This checks whether it's time to start saving hot state to DB.
// It's time when there's `epochsSinceFinalitySaveHotStateDB` epochs of non-finality.
func (s *Service) checkSaveHotStateDB(ctx context.Context) error {
currentEpoch := slots.ToEpoch(s.CurrentSlot())
// Prevent `sinceFinality` going underflow.
var sinceFinality types.Epoch
finalized := s.FinalizedCheckpt()
if finalized == nil {
return errNilFinalizedInStore
}
if currentEpoch > finalized.Epoch {
sinceFinality = currentEpoch - finalized.Epoch
}
if sinceFinality >= epochsSinceFinalitySaveHotStateDB {
s.cfg.StateGen.EnableSaveHotStateToDB(ctx)
return nil
}
return s.cfg.StateGen.DisableSaveHotStateToDB(ctx)
}

View File

@@ -4,14 +4,13 @@ import (
"context"
"sync"
"testing"
"time"
blockchainTesting "github.com/prysmaticlabs/prysm/v3/beacon-chain/blockchain/testing"
testDB "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/forkchoice/protoarray"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/operations/attestations"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/operations/voluntaryexits"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
sgmock "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
"github.com/prysmaticlabs/prysm/v3/config/params"
"github.com/prysmaticlabs/prysm/v3/consensus-types/blocks"
"github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces"
@@ -21,7 +20,6 @@ import (
"github.com/prysmaticlabs/prysm/v3/testing/assert"
"github.com/prysmaticlabs/prysm/v3/testing/require"
"github.com/prysmaticlabs/prysm/v3/testing/util"
logTest "github.com/sirupsen/logrus/hooks/test"
)
func TestService_ReceiveBlock(t *testing.T) {
@@ -133,7 +131,7 @@ func TestService_ReceiveBlock(t *testing.T) {
WithAttestationPool(attestations.NewPool()),
WithExitPool(voluntaryexits.NewPool()),
WithStateNotifier(&blockchainTesting.MockStateNotifier{RecordEvents: true}),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
WithFinalizedStateAtStartUp(genesis),
}
s, err := NewService(ctx, opts...)
@@ -172,7 +170,7 @@ func TestService_ReceiveBlockUpdateHead(t *testing.T) {
WithAttestationPool(attestations.NewPool()),
WithExitPool(voluntaryexits.NewPool()),
WithStateNotifier(&blockchainTesting.MockStateNotifier{RecordEvents: true}),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
}
s, err := NewService(ctx, opts...)
@@ -247,7 +245,7 @@ func TestService_ReceiveBlockBatch(t *testing.T) {
WithDatabase(beaconDB),
WithForkChoiceStore(protoarray.New()),
WithStateNotifier(&blockchainTesting.MockStateNotifier{RecordEvents: true}),
WithStateGen(stategen.New(beaconDB)),
WithStateGen(sgmock.NewMockStategen(beaconDB)),
}
s, err := NewService(ctx, opts...)
require.NoError(t, err)
@@ -292,40 +290,3 @@ func TestService_HasBlock(t *testing.T) {
require.NoError(t, err)
require.Equal(t, true, s.HasBlock(context.Background(), r))
}
func TestCheckSaveHotStateDB_Enabling(t *testing.T) {
opts := testServiceOptsWithDB(t)
hook := logTest.NewGlobal()
s, err := NewService(context.Background(), opts...)
require.NoError(t, err)
st := params.BeaconConfig().SlotsPerEpoch.Mul(uint64(epochsSinceFinalitySaveHotStateDB))
s.genesisTime = time.Now().Add(time.Duration(-1*int64(st)*int64(params.BeaconConfig().SecondsPerSlot)) * time.Second)
require.NoError(t, s.checkSaveHotStateDB(context.Background()))
assert.LogsContain(t, hook, "Entering mode to save hot states in DB")
}
func TestCheckSaveHotStateDB_Disabling(t *testing.T) {
hook := logTest.NewGlobal()
opts := testServiceOptsWithDB(t)
s, err := NewService(context.Background(), opts...)
require.NoError(t, err)
st := params.BeaconConfig().SlotsPerEpoch.Mul(uint64(epochsSinceFinalitySaveHotStateDB))
s.genesisTime = time.Now().Add(time.Duration(-1*int64(st)*int64(params.BeaconConfig().SecondsPerSlot)) * time.Second)
require.NoError(t, s.checkSaveHotStateDB(context.Background()))
s.genesisTime = time.Now()
require.NoError(t, s.checkSaveHotStateDB(context.Background()))
assert.LogsContain(t, hook, "Exiting mode to save hot states in DB")
}
func TestCheckSaveHotStateDB_Overflow(t *testing.T) {
hook := logTest.NewGlobal()
opts := testServiceOptsWithDB(t)
s, err := NewService(context.Background(), opts...)
require.NoError(t, err)
s.genesisTime = time.Now()
require.NoError(t, s.checkSaveHotStateDB(context.Background()))
assert.LogsDoNotContain(t, hook, "Entering mode to save hot states in DB")
}

View File

@@ -176,7 +176,6 @@ func (s *Service) Status() error {
// StartFromSavedState initializes the blockchain using a previously saved finalized checkpoint.
func (s *Service) StartFromSavedState(saved state.BeaconState) error {
log.Info("Blockchain data already exists in DB, initializing...")
s.genesisTime = time.Unix(int64(saved.GenesisTime()), 0) // lint:ignore uintcast -- Genesis time will not exceed int64 in your lifetime.
s.cfg.AttService.SetGenesisTime(saved.GenesisTime())

View File

@@ -24,7 +24,7 @@ import (
"github.com/prysmaticlabs/prysm/v3/beacon-chain/forkchoice/protoarray"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/operations/attestations"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
sgmock "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1"
"github.com/prysmaticlabs/prysm/v3/config/params"
consensusblocks "github.com/prysmaticlabs/prysm/v3/consensus-types/blocks"
@@ -117,7 +117,7 @@ func setupBeaconChain(t *testing.T, beaconDB db.Database) *Service {
depositCache, err := depositcache.New()
require.NoError(t, err)
stateGen := stategen.New(beaconDB)
stateGen := sgmock.NewMockStategen(beaconDB)
// Safe a state in stategen to purposes of testing a service stop / shutdown.
require.NoError(t, stateGen.SaveState(ctx, bytesutil.ToBytes32(bState.FinalizedCheckpoint().Root), bState))
@@ -305,7 +305,7 @@ func TestChainService_InitializeChainInfo(t *testing.T) {
require.NoError(t, beaconDB.SaveFinalizedCheckpoint(ctx, &ethpb.Checkpoint{Epoch: slots.ToEpoch(finalizedSlot), Root: headRoot[:]}))
attSrv, err := attestations.NewService(ctx, &attestations.Config{})
require.NoError(t, err)
stateGen := stategen.New(beaconDB)
stateGen := sgmock.NewMockStategen(beaconDB)
c, err := NewService(ctx, WithDatabase(beaconDB), WithStateGen(stateGen), WithAttestationService(attSrv), WithStateNotifier(&mock.MockStateNotifier{}), WithFinalizedStateAtStartUp(headState))
require.NoError(t, err)
require.NoError(t, stateGen.SaveState(ctx, headRoot, headState))
@@ -358,7 +358,7 @@ func TestChainService_InitializeChainInfo_SetHeadAtGenesis(t *testing.T) {
}
require.NoError(t, beaconDB.SaveStateSummary(ctx, ss))
require.NoError(t, beaconDB.SaveFinalizedCheckpoint(ctx, &ethpb.Checkpoint{Root: headRoot[:], Epoch: slots.ToEpoch(finalizedSlot)}))
stateGen := stategen.New(beaconDB)
stateGen := sgmock.NewMockStategen(beaconDB)
c, err := NewService(ctx, WithDatabase(beaconDB), WithStateGen(stateGen), WithAttestationService(attSrv), WithStateNotifier(&mock.MockStateNotifier{}), WithFinalizedStateAtStartUp(headState))
require.NoError(t, err)
@@ -376,7 +376,7 @@ func TestChainService_SaveHeadNoDB(t *testing.T) {
beaconDB := testDB.SetupDB(t)
ctx := context.Background()
s := &Service{
cfg: &config{BeaconDB: beaconDB, StateGen: stategen.New(beaconDB), ForkChoiceStore: doublylinkedtree.New()},
cfg: &config{BeaconDB: beaconDB, StateGen: sgmock.NewMockStategen(beaconDB), ForkChoiceStore: doublylinkedtree.New()},
}
blk := util.NewBeaconBlock()
blk.Block.Slot = 1
@@ -438,7 +438,7 @@ func TestServiceStop_SaveCachedBlocks(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
beaconDB := testDB.SetupDB(t)
s := &Service{
cfg: &config{BeaconDB: beaconDB, StateGen: stategen.New(beaconDB)},
cfg: &config{BeaconDB: beaconDB, StateGen: sgmock.NewMockStategen(beaconDB)},
ctx: ctx,
cancel: cancel,
initSyncBlocks: make(map[[32]byte]interfaces.SignedBeaconBlock),

View File

@@ -103,7 +103,7 @@ go_test(
"//beacon-chain/db/testing:go_default_library",
"//beacon-chain/execution/testing:go_default_library",
"//beacon-chain/execution/types:go_default_library",
"//beacon-chain/state/stategen:go_default_library",
"//beacon-chain/state/stategen/mock:go_default_library",
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",
"//consensus-types/blocks:go_default_library",

View File

@@ -20,7 +20,7 @@ import (
"github.com/prysmaticlabs/prysm/v3/beacon-chain/cache/depositcache"
dbutil "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing"
mockExecution "github.com/prysmaticlabs/prysm/v3/beacon-chain/execution/testing"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
sgmock "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
"github.com/prysmaticlabs/prysm/v3/config/params"
contracts "github.com/prysmaticlabs/prysm/v3/contracts/deposit"
"github.com/prysmaticlabs/prysm/v3/contracts/deposit/mock"
@@ -469,7 +469,7 @@ func TestInitDepositCacheWithFinalization_OK(t *testing.T) {
headBlock := util.NewBeaconBlock()
headRoot, err := headBlock.Block.HashTreeRoot()
require.NoError(t, err)
stateGen := stategen.New(beaconDB)
stateGen := sgmock.NewMockStategen(beaconDB)
emptyState, err := util.NewBeaconState()
require.NoError(t, err)

View File

@@ -54,7 +54,7 @@ go_test(
"//beacon-chain/core/feed:go_default_library",
"//beacon-chain/core/feed/state:go_default_library",
"//beacon-chain/db/testing:go_default_library",
"//beacon-chain/state/stategen:go_default_library",
"//beacon-chain/state/stategen/mock:go_default_library",
"//config/params:go_default_library",
"//consensus-types/blocks:go_default_library",
"//consensus-types/primitives:go_default_library",

View File

@@ -12,7 +12,7 @@ import (
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/feed"
statefeed "github.com/prysmaticlabs/prysm/v3/beacon-chain/core/feed/state"
testDB "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
sgmock "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
"github.com/prysmaticlabs/prysm/v3/consensus-types/blocks"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
@@ -88,7 +88,7 @@ func setupService(t *testing.T) *Service {
}
return &Service{
config: &ValidatorMonitorConfig{
StateGen: stategen.New(beaconDB),
StateGen: sgmock.NewMockStategen(beaconDB),
StateNotifier: chainService.StateNotifier(),
HeadFetcher: chainService,
AttestationNotifier: chainService.OperationNotifier(),

View File

@@ -204,8 +204,12 @@ func New(cliCtx *cli.Context, opts ...Option) (*BeaconNode, error) {
return nil, errors.Wrap(err, "backfill status initialization error")
}
log.Debugln("Starting Fork Choice")
beacon.startForkChoice()
bw := &blockchainWrapper{}
log.Debugln("Starting State Gen")
if err := beacon.startStateGen(ctx, bfs); err != nil {
if err := beacon.startStateGen(ctx, bfs, bw); err != nil {
return nil, err
}
@@ -229,11 +233,8 @@ func New(cliCtx *cli.Context, opts ...Option) (*BeaconNode, error) {
return nil, err
}
log.Debugln("Starting Fork Choice")
beacon.startForkChoice()
log.Debugln("Registering Blockchain Service")
if err := beacon.registerBlockchainService(); err != nil {
if err := beacon.registerBlockchainService(bw); err != nil {
return nil, err
}
@@ -495,9 +496,28 @@ func (b *BeaconNode) startSlasherDB(cliCtx *cli.Context) error {
return nil
}
func (b *BeaconNode) startStateGen(ctx context.Context, bfs *backfill.Status) error {
opts := []stategen.StateGenOption{stategen.WithBackfillStatus(bfs)}
sg := stategen.New(b.db, opts...)
type blockchainWrapper struct {
blksrv *blockchain.Service
}
func (w *blockchainWrapper) CurrentSlot() types.Slot {
return w.blksrv.CurrentSlot()
}
func (w *blockchainWrapper) IsCanonical(ctx context.Context, root [32]byte) (bool, error) {
return w.blksrv.IsCanonical(ctx, root)
}
var _ stategen.CurrentSlotter = &blockchainWrapper{}
var _ stategen.CanonicalChecker = &blockchainWrapper{}
func (b *BeaconNode) startStateGen(ctx context.Context, bfs *backfill.Status, bw *blockchainWrapper) error {
// we'll update the blockchain service pointer to the blockchain service once it's initialized
// this is weird and gross, but it's an intermediate step between decoupling these two services
rb := stategen.NewCanonicalHistory(b.db, bw, bw)
opts := []stategen.StateGenOption{stategen.WithBackfillStatus(bfs), stategen.WithReplayerBuilder(rb)}
saver := stategen.NewHotStateSaver(b.db, b.forkChoiceStore, bw)
sg := stategen.New(b.db, saver, opts...)
cp, err := b.db.FinalizedCheckpoint(ctx)
if err != nil {
@@ -586,7 +606,7 @@ func (b *BeaconNode) registerAttestationPool() error {
return b.services.RegisterService(s)
}
func (b *BeaconNode) registerBlockchainService() error {
func (b *BeaconNode) registerBlockchainService(bw *blockchainWrapper) error {
var web3Service *execution.Service
if err := b.services.FetchService(&web3Service); err != nil {
return err
@@ -620,6 +640,11 @@ func (b *BeaconNode) registerBlockchainService() error {
if err != nil {
return errors.Wrap(err, "could not register blockchain service")
}
// TODO: file an issue to track the task of moving the implementation of CurrentSlot to
// a separate service.
// fulfill this creepy circular dependency between stategen and the blockchain service
bw.blksrv = blockchainService
return b.services.RegisterService(blockchainService)
}

View File

@@ -68,7 +68,7 @@ go_test(
"//beacon-chain/rpc/prysm/v1alpha1/validator:go_default_library",
"//beacon-chain/rpc/testutil:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/stategen:go_default_library",
"//beacon-chain/state/stategen/mock:go_default_library",
"//beacon-chain/sync/initial-sync/testing:go_default_library",
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",

View File

@@ -28,7 +28,7 @@ import (
v1alpha1validator "github.com/prysmaticlabs/prysm/v3/beacon-chain/rpc/prysm/v1alpha1/validator"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/rpc/testutil"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
sgmock "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
mockSync "github.com/prysmaticlabs/prysm/v3/beacon-chain/sync/initial-sync/testing"
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
"github.com/prysmaticlabs/prysm/v3/config/params"
@@ -675,7 +675,7 @@ func TestProduceBlockV2(t *testing.T) {
AttPool: attestations.NewPool(),
SlashingsPool: slashings.NewPool(),
ExitPool: voluntaryexits.NewPool(),
StateGen: stategen.New(db),
StateGen: sgmock.NewMockStategen(db),
}
proposerSlashings := make([]*ethpbalpha.ProposerSlashing, params.BeaconConfig().MaxProposerSlashings)
@@ -779,7 +779,7 @@ func TestProduceBlockV2(t *testing.T) {
AttPool: attestations.NewPool(),
SlashingsPool: slashings.NewPool(),
ExitPool: voluntaryexits.NewPool(),
StateGen: stategen.New(db),
StateGen: sgmock.NewMockStategen(db),
SyncCommitteePool: synccommittee.NewStore(),
}
@@ -928,7 +928,7 @@ func TestProduceBlockV2(t *testing.T) {
AttPool: attestations.NewPool(),
SlashingsPool: slashings.NewPool(),
ExitPool: voluntaryexits.NewPool(),
StateGen: stategen.New(db),
StateGen: sgmock.NewMockStategen(db),
SyncCommitteePool: synccommittee.NewStore(),
ProposerSlotIndexCache: cache.NewProposerPayloadIDsCache(),
}
@@ -1052,7 +1052,7 @@ func TestProduceBlockV2SSZ(t *testing.T) {
AttPool: attestations.NewPool(),
SlashingsPool: slashings.NewPool(),
ExitPool: voluntaryexits.NewPool(),
StateGen: stategen.New(db),
StateGen: sgmock.NewMockStategen(db),
}
proposerSlashings := make([]*ethpbalpha.ProposerSlashing, 1)
@@ -1213,7 +1213,7 @@ func TestProduceBlockV2SSZ(t *testing.T) {
AttPool: attestations.NewPool(),
SlashingsPool: slashings.NewPool(),
ExitPool: voluntaryexits.NewPool(),
StateGen: stategen.New(db),
StateGen: sgmock.NewMockStategen(db),
SyncCommitteePool: synccommittee.NewStore(),
}
@@ -1417,7 +1417,7 @@ func TestProduceBlockV2SSZ(t *testing.T) {
AttPool: attestations.NewPool(),
SlashingsPool: slashings.NewPool(),
ExitPool: voluntaryexits.NewPool(),
StateGen: stategen.New(db),
StateGen: sgmock.NewMockStategen(db),
SyncCommitteePool: synccommittee.NewStore(),
ProposerSlotIndexCache: cache.NewProposerPayloadIDsCache(),
}
@@ -1635,7 +1635,7 @@ func TestProduceBlindedBlock(t *testing.T) {
AttPool: attestations.NewPool(),
SlashingsPool: slashings.NewPool(),
ExitPool: voluntaryexits.NewPool(),
StateGen: stategen.New(db),
StateGen: sgmock.NewMockStategen(db),
}
proposerSlashings := make([]*ethpbalpha.ProposerSlashing, params.BeaconConfig().MaxProposerSlashings)
@@ -1739,7 +1739,7 @@ func TestProduceBlindedBlock(t *testing.T) {
AttPool: attestations.NewPool(),
SlashingsPool: slashings.NewPool(),
ExitPool: voluntaryexits.NewPool(),
StateGen: stategen.New(db),
StateGen: sgmock.NewMockStategen(db),
SyncCommitteePool: synccommittee.NewStore(),
}
@@ -1888,7 +1888,7 @@ func TestProduceBlindedBlock(t *testing.T) {
AttPool: attestations.NewPool(),
SlashingsPool: slashings.NewPool(),
ExitPool: voluntaryexits.NewPool(),
StateGen: stategen.New(db),
StateGen: sgmock.NewMockStategen(db),
SyncCommitteePool: synccommittee.NewStore(),
ProposerSlotIndexCache: cache.NewProposerPayloadIDsCache(),
}
@@ -2012,7 +2012,7 @@ func TestProduceBlindedBlockSSZ(t *testing.T) {
AttPool: attestations.NewPool(),
SlashingsPool: slashings.NewPool(),
ExitPool: voluntaryexits.NewPool(),
StateGen: stategen.New(db),
StateGen: sgmock.NewMockStategen(db),
}
proposerSlashings := make([]*ethpbalpha.ProposerSlashing, 1)
@@ -2173,7 +2173,7 @@ func TestProduceBlindedBlockSSZ(t *testing.T) {
AttPool: attestations.NewPool(),
SlashingsPool: slashings.NewPool(),
ExitPool: voluntaryexits.NewPool(),
StateGen: stategen.New(db),
StateGen: sgmock.NewMockStategen(db),
SyncCommitteePool: synccommittee.NewStore(),
}
@@ -2377,7 +2377,7 @@ func TestProduceBlindedBlockSSZ(t *testing.T) {
AttPool: attestations.NewPool(),
SlashingsPool: slashings.NewPool(),
ExitPool: voluntaryexits.NewPool(),
StateGen: stategen.New(db),
StateGen: sgmock.NewMockStategen(db),
SyncCommitteePool: synccommittee.NewStore(),
ProposerSlotIndexCache: cache.NewProposerPayloadIDsCache(),
}

View File

@@ -10,7 +10,6 @@ import (
mock "github.com/prysmaticlabs/prysm/v3/beacon-chain/blockchain/testing"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/helpers"
dbTest "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
mockstategen "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
"github.com/prysmaticlabs/prysm/v3/cmd"
"github.com/prysmaticlabs/prysm/v3/config/params"
@@ -60,7 +59,7 @@ func TestServer_ListAssignments_NoResults(t *testing.T) {
bs := &Server{
BeaconDB: db,
GenesisTimeFetcher: &mock.ChainService{},
StateGen: stategen.New(db),
StateGen: mockstategen.NewMockStategen(db),
ReplayerBuilder: mockstategen.NewMockReplayerBuilder(mockstategen.WithMockState(st)),
}
wanted := &ethpb.ValidatorAssignments{
@@ -122,7 +121,7 @@ func TestServer_ListAssignments_Pagination_InputOutOfRange(t *testing.T) {
},
},
GenesisTimeFetcher: &mock.ChainService{},
StateGen: stategen.New(db),
StateGen: mockstategen.NewMockStategen(db),
ReplayerBuilder: mockstategen.NewMockReplayerBuilder(mockstategen.WithMockState(s)),
}
@@ -198,7 +197,7 @@ func TestServer_ListAssignments_Pagination_DefaultPageSize_NoArchive(t *testing.
},
},
GenesisTimeFetcher: &mock.ChainService{},
StateGen: stategen.New(db),
StateGen: mockstategen.NewMockStategen(db),
ReplayerBuilder: mockstategen.NewMockReplayerBuilder(mockstategen.WithMockState(s)),
}
@@ -265,7 +264,7 @@ func TestServer_ListAssignments_FilterPubkeysIndices_NoPagination(t *testing.T)
},
},
GenesisTimeFetcher: &mock.ChainService{},
StateGen: stategen.New(db),
StateGen: mockstategen.NewMockStategen(db),
ReplayerBuilder: mockstategen.NewMockReplayerBuilder(mockstategen.WithMockState(s)),
}
@@ -336,7 +335,7 @@ func TestServer_ListAssignments_CanFilterPubkeysIndices_WithPagination(t *testin
},
},
GenesisTimeFetcher: &mock.ChainService{},
StateGen: stategen.New(db),
StateGen: mockstategen.NewMockStategen(db),
}
addDefaultReplayerBuilder(bs, db)

View File

@@ -17,7 +17,7 @@ import (
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/signing"
dbTest "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/operations/attestations"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
sgmock "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1"
"github.com/prysmaticlabs/prysm/v3/cmd"
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
@@ -569,7 +569,7 @@ func TestServer_ListIndexedAttestations_GenesisEpoch(t *testing.T) {
BeaconDB: db,
GenesisTimeFetcher: &chainMock.ChainService{State: state},
HeadFetcher: &chainMock.ChainService{State: state},
StateGen: stategen.New(db),
StateGen: sgmock.NewMockStategen(db),
}
err := db.SaveStateSummary(ctx, &ethpb.StateSummary{
Root: targetRoot1[:],
@@ -669,7 +669,7 @@ func TestServer_ListIndexedAttestations_OldEpoch(t *testing.T) {
GenesisTimeFetcher: &chainMock.ChainService{
Genesis: time.Now(),
},
StateGen: stategen.New(db),
StateGen: sgmock.NewMockStategen(db),
}
err = db.SaveStateSummary(ctx, &ethpb.StateSummary{
Root: blockRoot[:],
@@ -940,7 +940,7 @@ func TestServer_StreamIndexedAttestations_OK(t *testing.T) {
},
AttestationNotifier: chainService.OperationNotifier(),
CollectedAttestationsBuffer: make(chan []*ethpb.Attestation, 1),
StateGen: stategen.New(db),
StateGen: sgmock.NewMockStategen(db),
}
for dataRoot, sameDataAtts := range atts {

View File

@@ -42,7 +42,7 @@ func TestServer_ListBeaconCommittees_CurrentEpoch(t *testing.T) {
bs := &Server{
HeadFetcher: m,
GenesisTimeFetcher: m,
StateGen: stategen.New(db),
StateGen: mockstategen.NewMockStategen(db),
}
b := util.NewBeaconBlock()
util.SaveBlock(t, ctx, db, b)
@@ -115,7 +115,7 @@ func TestServer_ListBeaconCommittees_PreviousEpoch(t *testing.T) {
bs := &Server{
HeadFetcher: m,
GenesisTimeFetcher: m,
StateGen: stategen.New(db),
StateGen: mockstategen.NewMockStategen(db),
}
addDefaultReplayerBuilder(bs, db)
@@ -170,7 +170,7 @@ func TestRetrieveCommitteesForRoot(t *testing.T) {
bs := &Server{
HeadFetcher: m,
GenesisTimeFetcher: m,
StateGen: stategen.New(db),
StateGen: mockstategen.NewMockStategen(db),
}
b := util.NewBeaconBlock()
util.SaveBlock(t, ctx, db, b)

View File

@@ -754,6 +754,8 @@ func (bs *Server) GetValidatorPerformance(
beforeTransitionBalances := make([]uint64, 0, responseCap)
afterTransitionBalances := make([]uint64, 0, responseCap)
effectiveBalances := make([]uint64, 0, responseCap)
inclusionSlots := make([]types.Slot, 0, responseCap)
inclusionDistances := make([]types.Slot, 0, responseCap)
correctlyVotedSource := make([]bool, 0, responseCap)
correctlyVotedTarget := make([]bool, 0, responseCap)
correctlyVotedHead := make([]bool, 0, responseCap)
@@ -787,6 +789,8 @@ func (bs *Server) GetValidatorPerformance(
if headState.Version() == version.Phase0 {
correctlyVotedSource = append(correctlyVotedSource, summary.IsPrevEpochAttester)
inclusionSlots = append(inclusionSlots, summary.InclusionSlot)
inclusionDistances = append(inclusionDistances, summary.InclusionDistance)
} else {
correctlyVotedSource = append(correctlyVotedSource, summary.IsPrevEpochSourceAttester)
inactivityScores = append(inactivityScores, summary.InactivityScore)
@@ -802,7 +806,9 @@ func (bs *Server) GetValidatorPerformance(
BalancesBeforeEpochTransition: beforeTransitionBalances,
BalancesAfterEpochTransition: afterTransitionBalances,
MissingValidators: missingValidators,
InactivityScores: inactivityScores, // Only populated in Altair
InclusionSlots: inclusionSlots, // Only populated in phase0
InclusionDistances: inclusionDistances, // Only populated in phase 0
InactivityScores: inactivityScores, // Only populated in Altair
}, nil
}

View File

@@ -19,7 +19,6 @@ import (
"github.com/prysmaticlabs/prysm/v3/beacon-chain/db"
dbTest "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
mockstategen "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1"
mockSync "github.com/prysmaticlabs/prysm/v3/beacon-chain/sync/initial-sync/testing"
@@ -107,7 +106,7 @@ func TestServer_ListValidatorBalances_NoResults(t *testing.T) {
require.NoError(t, st.SetSlot(0))
bs := &Server{
GenesisTimeFetcher: &mock.ChainService{},
StateGen: stategen.New(beaconDB),
StateGen: mockstategen.NewMockStategen(beaconDB),
}
headState, err := util.NewBeaconState()
@@ -174,7 +173,7 @@ func TestServer_ListValidatorBalances_DefaultResponse_NoArchive(t *testing.T) {
require.NoError(t, beaconDB.SaveState(ctx, st, gRoot))
bs := &Server{
GenesisTimeFetcher: &mock.ChainService{},
StateGen: stategen.New(beaconDB),
StateGen: mockstategen.NewMockStategen(beaconDB),
HeadFetcher: &mock.ChainService{
State: st,
},
@@ -203,7 +202,7 @@ func TestServer_ListValidatorBalances_PaginationOutOfRange(t *testing.T) {
bs := &Server{
GenesisTimeFetcher: &mock.ChainService{},
StateGen: stategen.New(beaconDB),
StateGen: mockstategen.NewMockStategen(beaconDB),
HeadFetcher: &mock.ChainService{
State: headState,
},
@@ -252,7 +251,7 @@ func TestServer_ListValidatorBalances_Pagination_Default(t *testing.T) {
bs := &Server{
GenesisTimeFetcher: &mock.ChainService{},
StateGen: stategen.New(beaconDB),
StateGen: mockstategen.NewMockStategen(beaconDB),
HeadFetcher: &mock.ChainService{
State: headState,
},
@@ -336,7 +335,7 @@ func TestServer_ListValidatorBalances_Pagination_CustomPageSizes(t *testing.T) {
bs := &Server{
GenesisTimeFetcher: &mock.ChainService{},
StateGen: stategen.New(beaconDB),
StateGen: mockstategen.NewMockStategen(beaconDB),
HeadFetcher: &mock.ChainService{
State: headState,
},
@@ -404,7 +403,7 @@ func TestServer_ListValidatorBalances_OutOfRange(t *testing.T) {
bs := &Server{
GenesisTimeFetcher: &mock.ChainService{},
StateGen: stategen.New(beaconDB),
StateGen: mockstategen.NewMockStategen(beaconDB),
HeadFetcher: &mock.ChainService{
State: headState,
},
@@ -500,7 +499,7 @@ func TestServer_ListValidators_NoResults(t *testing.T) {
HeadFetcher: &mock.ChainService{
State: st,
},
StateGen: stategen.New(beaconDB),
StateGen: mockstategen.NewMockStategen(beaconDB),
}
wanted := &ethpb.Validators{
ValidatorList: make([]*ethpb.Validators_ValidatorContainer, 0),
@@ -567,7 +566,7 @@ func TestServer_ListValidators_OnlyActiveValidators(t *testing.T) {
// We are in epoch 0.
Genesis: time.Now(),
},
StateGen: stategen.New(beaconDB),
StateGen: mockstategen.NewMockStategen(beaconDB),
}
b := util.NewBeaconBlock()
@@ -635,7 +634,7 @@ func TestServer_ListValidators_InactiveInTheMiddle(t *testing.T) {
// We are in epoch 0.
Genesis: time.Now(),
},
StateGen: stategen.New(beaconDB),
StateGen: mockstategen.NewMockStategen(beaconDB),
}
b := util.NewBeaconBlock()
@@ -667,7 +666,7 @@ func TestServer_ListValidatorBalances_UnknownValidatorInResponse(t *testing.T) {
bs := &Server{
GenesisTimeFetcher: &mock.ChainService{},
StateGen: stategen.New(beaconDB),
StateGen: mockstategen.NewMockStategen(beaconDB),
HeadFetcher: &mock.ChainService{
State: headState,
},
@@ -725,7 +724,7 @@ func TestServer_ListValidators_NoPagination(t *testing.T) {
Epoch: 0,
},
},
StateGen: stategen.New(beaconDB),
StateGen: mockstategen.NewMockStategen(beaconDB),
}
received, err := bs.ListValidators(context.Background(), &ethpb.ListValidatorsRequest{})
@@ -791,7 +790,7 @@ func TestServer_ListValidators_IndicesPubKeys(t *testing.T) {
// We are in epoch 0.
Genesis: time.Now(),
},
StateGen: stategen.New(beaconDB),
StateGen: mockstategen.NewMockStategen(beaconDB),
}
pubKeysWanted := make([][]byte, len(pubkeyIndicesWanted))
@@ -827,7 +826,7 @@ func TestServer_ListValidators_Pagination(t *testing.T) {
// We are in epoch 0.
Genesis: time.Now(),
},
StateGen: stategen.New(beaconDB),
StateGen: mockstategen.NewMockStategen(beaconDB),
}
tests := []struct {
@@ -964,7 +963,7 @@ func TestServer_ListValidators_PaginationOutOfRange(t *testing.T) {
// We are in epoch 0.
Genesis: time.Now(),
},
StateGen: stategen.New(beaconDB),
StateGen: mockstategen.NewMockStategen(beaconDB),
}
req := &ethpb.ListValidatorsRequest{PageToken: strconv.Itoa(1), PageSize: 100}
@@ -1008,7 +1007,7 @@ func TestServer_ListValidators_DefaultPageSize(t *testing.T) {
// We are in epoch 0.
Genesis: time.Now(),
},
StateGen: stategen.New(beaconDB),
StateGen: mockstategen.NewMockStategen(beaconDB),
}
req := &ethpb.ListValidatorsRequest{}
@@ -1132,7 +1131,7 @@ func TestServer_ListValidators_ProcessHeadStateSlots(t *testing.T) {
GenesisTimeFetcher: &mock.ChainService{
Genesis: time.Now().Add(time.Duration(-1*int64(secondsPerEpoch)) * time.Second),
},
StateGen: stategen.New(beaconDB),
StateGen: mockstategen.NewMockStategen(beaconDB),
}
req := &ethpb.ListValidatorsRequest{
@@ -1489,7 +1488,7 @@ func TestServer_GetValidatorParticipation_CannotRequestFutureEpoch(t *testing.T)
State: headState,
},
GenesisTimeFetcher: &mock.ChainService{},
StateGen: stategen.New(beaconDB),
StateGen: mockstategen.NewMockStategen(beaconDB),
}
wanted := "Cannot retrieve information about an epoch"
@@ -1554,7 +1553,7 @@ func TestServer_GetValidatorParticipation_CurrentAndPrevEpoch(t *testing.T) {
bs := &Server{
BeaconDB: beaconDB,
HeadFetcher: m,
StateGen: stategen.New(beaconDB),
StateGen: mockstategen.NewMockStategen(beaconDB),
GenesisTimeFetcher: &mock.ChainService{
Genesis: prysmTime.Now().Add(time.Duration(-1*offset) * time.Second),
},
@@ -1633,7 +1632,7 @@ func TestServer_GetValidatorParticipation_OrphanedUntilGenesis(t *testing.T) {
bs := &Server{
BeaconDB: beaconDB,
HeadFetcher: m,
StateGen: stategen.New(beaconDB),
StateGen: mockstategen.NewMockStategen(beaconDB),
GenesisTimeFetcher: &mock.ChainService{
Genesis: prysmTime.Now().Add(time.Duration(-1*offset) * time.Second),
},
@@ -1731,7 +1730,7 @@ func runGetValidatorParticipationCurrentAndPrevEpoch(t *testing.T, genState stat
bs := &Server{
BeaconDB: beaconDB,
HeadFetcher: m,
StateGen: stategen.New(beaconDB),
StateGen: mockstategen.NewMockStategen(beaconDB),
GenesisTimeFetcher: &mock.ChainService{
Genesis: prysmTime.Now().Add(time.Duration(-1*offset) * time.Second),
},
@@ -1846,9 +1845,12 @@ func TestGetValidatorPerformance_OK(t *testing.T) {
GenesisTimeFetcher: &mock.ChainService{Genesis: time.Now().Add(time.Duration(-1*offset) * time.Second)},
SyncChecker: &mockSync.Sync{IsSyncing: false},
}
farFuture := params.BeaconConfig().FarFutureSlot
want := &ethpb.ValidatorPerformanceResponse{
PublicKeys: [][]byte{publicKey2[:], publicKey3[:]},
CurrentEffectiveBalances: []uint64{params.BeaconConfig().MaxEffectiveBalance, params.BeaconConfig().MaxEffectiveBalance},
InclusionSlots: []types.Slot{farFuture, farFuture},
InclusionDistances: []types.Slot{farFuture, farFuture},
CorrectlyVotedSource: []bool{false, false},
CorrectlyVotedTarget: []bool{false, false},
CorrectlyVotedHead: []bool{false, false},
@@ -1915,9 +1917,12 @@ func TestGetValidatorPerformance_Indices(t *testing.T) {
require.NoError(t, err)
_, err = precompute.ProcessRewardsAndPenaltiesPrecompute(c, bp, vp, precompute.AttestationsDelta, precompute.ProposersDelta)
require.NoError(t, err)
farFuture := params.BeaconConfig().FarFutureSlot
want := &ethpb.ValidatorPerformanceResponse{
PublicKeys: [][]byte{publicKey2[:], publicKey3[:]},
CurrentEffectiveBalances: []uint64{params.BeaconConfig().MaxEffectiveBalance, params.BeaconConfig().MaxEffectiveBalance},
InclusionSlots: []types.Slot{farFuture, farFuture},
InclusionDistances: []types.Slot{farFuture, farFuture},
CorrectlyVotedSource: []bool{false, false},
CorrectlyVotedTarget: []bool{false, false},
CorrectlyVotedHead: []bool{false, false},
@@ -1985,9 +1990,12 @@ func TestGetValidatorPerformance_IndicesPubkeys(t *testing.T) {
require.NoError(t, err)
_, err = precompute.ProcessRewardsAndPenaltiesPrecompute(c, bp, vp, precompute.AttestationsDelta, precompute.ProposersDelta)
require.NoError(t, err)
farFuture := params.BeaconConfig().FarFutureSlot
want := &ethpb.ValidatorPerformanceResponse{
PublicKeys: [][]byte{publicKey2[:], publicKey3[:]},
CurrentEffectiveBalances: []uint64{params.BeaconConfig().MaxEffectiveBalance, params.BeaconConfig().MaxEffectiveBalance},
InclusionSlots: []types.Slot{farFuture, farFuture},
InclusionDistances: []types.Slot{farFuture, farFuture},
CorrectlyVotedSource: []bool{false, false},
CorrectlyVotedTarget: []bool{false, false},
CorrectlyVotedHead: []bool{false, false},
@@ -2056,6 +2064,8 @@ func TestGetValidatorPerformanceAltair_OK(t *testing.T) {
want := &ethpb.ValidatorPerformanceResponse{
PublicKeys: [][]byte{publicKey2[:], publicKey3[:]},
CurrentEffectiveBalances: []uint64{params.BeaconConfig().MaxEffectiveBalance, params.BeaconConfig().MaxEffectiveBalance},
InclusionSlots: nil,
InclusionDistances: nil,
CorrectlyVotedSource: []bool{false, false},
CorrectlyVotedTarget: []bool{false, false},
CorrectlyVotedHead: []bool{false, false},
@@ -2124,6 +2134,8 @@ func TestGetValidatorPerformanceBellatrix_OK(t *testing.T) {
want := &ethpb.ValidatorPerformanceResponse{
PublicKeys: [][]byte{publicKey2[:], publicKey3[:]},
CurrentEffectiveBalances: []uint64{params.BeaconConfig().MaxEffectiveBalance, params.BeaconConfig().MaxEffectiveBalance},
InclusionSlots: nil,
InclusionDistances: nil,
CorrectlyVotedSource: []bool{false, false},
CorrectlyVotedTarget: []bool{false, false},
CorrectlyVotedHead: []bool{false, false},
@@ -2212,7 +2224,7 @@ func TestServer_GetIndividualVotes_ValidatorsDontExist(t *testing.T) {
util.SaveBlock(t, ctx, beaconDB, b)
gRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err)
gen := stategen.New(beaconDB)
gen := mockstategen.NewMockStategen(beaconDB)
require.NoError(t, gen.SaveState(ctx, gRoot, beaconState))
require.NoError(t, beaconDB.SaveState(ctx, beaconState, gRoot))
require.NoError(t, beaconDB.SaveGenesisBlockRoot(ctx, gRoot))
@@ -2308,7 +2320,7 @@ func TestServer_GetIndividualVotes_Working(t *testing.T) {
util.SaveBlock(t, ctx, beaconDB, b)
gRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err)
gen := stategen.New(beaconDB)
gen := mockstategen.NewMockStategen(beaconDB)
require.NoError(t, gen.SaveState(ctx, gRoot, beaconState))
require.NoError(t, beaconDB.SaveState(ctx, beaconState, gRoot))
require.NoError(t, beaconDB.SaveGenesisBlockRoot(ctx, gRoot))
@@ -2373,7 +2385,7 @@ func TestServer_GetIndividualVotes_WorkingAltair(t *testing.T) {
util.SaveBlock(t, ctx, beaconDB, b)
gRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err)
gen := stategen.New(beaconDB)
gen := mockstategen.NewMockStategen(beaconDB)
require.NoError(t, gen.SaveState(ctx, gRoot, beaconState))
require.NoError(t, beaconDB.SaveState(ctx, beaconState, gRoot))
require.NoError(t, beaconDB.SaveGenesisBlockRoot(ctx, gRoot))
@@ -2437,7 +2449,7 @@ func TestServer_GetIndividualVotes_AltairEndOfEpoch(t *testing.T) {
util.SaveBlock(t, ctx, beaconDB, b)
gRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err)
gen := stategen.New(beaconDB)
gen := mockstategen.NewMockStategen(beaconDB)
require.NoError(t, gen.SaveState(ctx, gRoot, beaconState))
require.NoError(t, beaconDB.SaveState(ctx, beaconState, gRoot))
require.NoError(t, beaconDB.SaveGenesisBlockRoot(ctx, gRoot))
@@ -2525,7 +2537,7 @@ func TestServer_GetIndividualVotes_BellatrixEndOfEpoch(t *testing.T) {
util.SaveBlock(t, ctx, beaconDB, b)
gRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err)
gen := stategen.New(beaconDB)
gen := mockstategen.NewMockStategen(beaconDB)
require.NoError(t, gen.SaveState(ctx, gRoot, beaconState))
require.NoError(t, beaconDB.SaveState(ctx, beaconState, gRoot))
require.NoError(t, beaconDB.SaveGenesisBlockRoot(ctx, gRoot))

View File

@@ -9,7 +9,7 @@ import (
mock "github.com/prysmaticlabs/prysm/v3/beacon-chain/blockchain/testing"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/helpers"
dbTest "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
sgmock "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
"github.com/prysmaticlabs/prysm/v3/config/params"
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
@@ -53,7 +53,7 @@ func TestServer_GetAttestationInclusionSlot(t *testing.T) {
offset := int64(2 * params.BeaconConfig().SlotsPerEpoch.Mul(params.BeaconConfig().SecondsPerSlot))
bs := &Server{
BeaconDB: db,
StateGen: stategen.New(db),
StateGen: sgmock.NewMockStategen(db),
GenesisTimeFetcher: &mock.ChainService{Genesis: time.Now().Add(time.Duration(-1*offset) * time.Second)},
}

View File

@@ -34,7 +34,7 @@ func TestServer_GetBeaconState(t *testing.T) {
util.SaveBlock(t, ctx, db, b)
gRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err)
gen := stategen.New(db)
gen := mockstategen.NewMockStategen(db)
require.NoError(t, gen.SaveState(ctx, gRoot, st))
require.NoError(t, db.SaveState(ctx, st, gRoot))
bs := &Server{

View File

@@ -141,7 +141,6 @@ go_test(
"//beacon-chain/operations/voluntaryexits:go_default_library",
"//beacon-chain/p2p/testing:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/stategen:go_default_library",
"//beacon-chain/state/stategen/mock:go_default_library",
"//beacon-chain/state/v1:go_default_library",
"//beacon-chain/state/v3:go_default_library",

View File

@@ -12,7 +12,7 @@ import (
dbutil "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/operations/attestations"
mockp2p "github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p/testing"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
sgmock "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1"
mockSync "github.com/prysmaticlabs/prysm/v3/beacon-chain/sync/initial-sync/testing"
"github.com/prysmaticlabs/prysm/v3/config/params"
@@ -423,7 +423,7 @@ func TestServer_GetAttestationData_HeadStateSlotGreaterThanRequestSlot(t *testin
FinalizationFetcher: &mock.ChainService{CurrentJustifiedCheckPoint: beaconState.CurrentJustifiedCheckpoint()},
TimeFetcher: &mock.ChainService{Genesis: time.Now().Add(time.Duration(-1*offset) * time.Second)},
StateNotifier: chainService.StateNotifier(),
StateGen: stategen.New(db),
StateGen: sgmock.NewMockStategen(db),
}
require.NoError(t, db.SaveState(ctx, beaconState, blockRoot))
util.SaveBlock(t, ctx, db, block)

View File

@@ -24,7 +24,7 @@ import (
"github.com/prysmaticlabs/prysm/v3/beacon-chain/operations/synccommittee"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/operations/voluntaryexits"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
sgmock "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
v3 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v3"
mockSync "github.com/prysmaticlabs/prysm/v3/beacon-chain/sync/initial-sync/testing"
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
@@ -58,7 +58,7 @@ func TestServer_buildHeaderBlock(t *testing.T) {
proposerServer := &Server{
BeaconDB: db,
StateGen: stategen.New(db),
StateGen: sgmock.NewMockStategen(db),
}
b, err := util.GenerateFullBlockAltair(copiedState, keys, util.DefaultBlockGenConfig(), 1)
require.NoError(t, err)
@@ -69,7 +69,7 @@ func TestServer_buildHeaderBlock(t *testing.T) {
b1, err := util.GenerateFullBlockAltair(copiedState, keys, util.DefaultBlockGenConfig(), 2)
require.NoError(t, err)
vs := &Server{StateGen: stategen.New(db), BeaconDB: db}
vs := &Server{StateGen: sgmock.NewMockStategen(db), BeaconDB: db}
h := &v1.ExecutionPayloadHeader{
BlockNumber: 123,
GasLimit: 456,
@@ -419,7 +419,7 @@ func TestServer_getAndBuildHeaderBlock(t *testing.T) {
Timestamp: ts,
}
vs.StateGen = stategen.New(vs.BeaconDB)
vs.StateGen = sgmock.NewMockStategen(vs.BeaconDB)
vs.GenesisFetcher = &blockchainTest.ChainService{}
vs.ForkFetcher = &blockchainTest.ChainService{Fork: &ethpb.Fork{}}
@@ -538,7 +538,7 @@ func TestServer_GetBellatrixBeaconBlock_HappyCase(t *testing.T) {
AttPool: attestations.NewPool(),
SlashingsPool: slashings.NewPool(),
ExitPool: voluntaryexits.NewPool(),
StateGen: stategen.New(db),
StateGen: sgmock.NewMockStategen(db),
SyncCommitteePool: synccommittee.NewStore(),
ExecutionEngineCaller: &mockExecution.EngineClient{
PayloadIDBytes: &v1.PayloadIDBytes{1},
@@ -669,7 +669,7 @@ func TestServer_GetBellatrixBeaconBlock_BuilderCase(t *testing.T) {
AttPool: attestations.NewPool(),
SlashingsPool: slashings.NewPool(),
ExitPool: voluntaryexits.NewPool(),
StateGen: stategen.New(db),
StateGen: sgmock.NewMockStategen(db),
SyncCommitteePool: synccommittee.NewStore(),
ExecutionEngineCaller: &mockExecution.EngineClient{
PayloadIDBytes: &v1.PayloadIDBytes{1},

View File

@@ -25,7 +25,7 @@ import (
"github.com/prysmaticlabs/prysm/v3/beacon-chain/operations/synccommittee"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/operations/voluntaryexits"
mockp2p "github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p/testing"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
sgmock "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1"
mockSync "github.com/prysmaticlabs/prysm/v3/beacon-chain/sync/initial-sync/testing"
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
@@ -137,7 +137,7 @@ func TestProposer_ComputeStateRoot_OK(t *testing.T) {
ChainStartFetcher: &mockExecution.Chain{},
Eth1InfoFetcher: &mockExecution.Chain{},
Eth1BlockFetcher: &mockExecution.Chain{},
StateGen: stategen.New(db),
StateGen: sgmock.NewMockStategen(db),
}
req := util.NewBeaconBlock()
req.Block.ProposerIndex = 21
@@ -1928,7 +1928,7 @@ func TestProposer_GetBeaconBlock_PreForkEpoch(t *testing.T) {
AttPool: attestations.NewPool(),
SlashingsPool: slashings.NewPool(),
ExitPool: voluntaryexits.NewPool(),
StateGen: stategen.New(db),
StateGen: sgmock.NewMockStategen(db),
SyncCommitteePool: synccommittee.NewStore(),
}
@@ -2039,7 +2039,7 @@ func TestProposer_GetBeaconBlock_PostForkEpoch(t *testing.T) {
AttPool: attestations.NewPool(),
SlashingsPool: slashings.NewPool(),
ExitPool: voluntaryexits.NewPool(),
StateGen: stategen.New(db),
StateGen: sgmock.NewMockStategen(db),
SyncCommitteePool: synccommittee.NewStore(),
}
@@ -2191,7 +2191,7 @@ func TestProposer_GetBeaconBlock_BellatrixEpoch(t *testing.T) {
AttPool: attestations.NewPool(),
SlashingsPool: slashings.NewPool(),
ExitPool: voluntaryexits.NewPool(),
StateGen: stategen.New(db),
StateGen: sgmock.NewMockStategen(db),
SyncCommitteePool: synccommittee.NewStore(),
ExecutionEngineCaller: &mockExecution.EngineClient{
PayloadIDBytes: &enginev1.PayloadIDBytes{1},

View File

@@ -77,7 +77,7 @@ go_test(
"//beacon-chain/operations/slashings/mock:go_default_library",
"//beacon-chain/slasher/mock:go_default_library",
"//beacon-chain/slasher/types:go_default_library",
"//beacon-chain/state/stategen:go_default_library",
"//beacon-chain/state/stategen/mock:go_default_library",
"//beacon-chain/sync/initial-sync/testing:go_default_library",
"//config/fieldparams:go_default_library",
"//config/params:go_default_library",

View File

@@ -9,7 +9,7 @@ import (
dbtest "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing"
slashingsmock "github.com/prysmaticlabs/prysm/v3/beacon-chain/operations/slashings/mock"
slashertypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/slasher/types"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
sgmock "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
"github.com/prysmaticlabs/prysm/v3/config/params"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v3/crypto/bls"
@@ -60,7 +60,7 @@ func Test_processQueuedBlocks_DetectsDoubleProposals(t *testing.T) {
Database: slasherDB,
StateNotifier: &mock.MockStateNotifier{},
HeadStateFetcher: mockChain,
StateGen: stategen.New(beaconDB),
StateGen: sgmock.NewMockStategen(beaconDB),
SlashingPoolInserter: &slashingsmock.PoolMock{},
},
params: DefaultParams(),

View File

@@ -8,7 +8,7 @@ import (
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/signing"
dbtest "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing"
slashingsmock "github.com/prysmaticlabs/prysm/v3/beacon-chain/operations/slashings/mock"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
sgmock "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
"github.com/prysmaticlabs/prysm/v3/config/params"
"github.com/prysmaticlabs/prysm/v3/crypto/bls"
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
@@ -44,7 +44,7 @@ func TestService_processAttesterSlashings(t *testing.T) {
serviceCfg: &ServiceConfig{
Database: slasherDB,
AttestationStateFetcher: mockChain,
StateGen: stategen.New(beaconDB),
StateGen: sgmock.NewMockStategen(beaconDB),
SlashingPoolInserter: &slashingsmock.PoolMock{},
HeadStateFetcher: mockChain,
},
@@ -151,7 +151,7 @@ func TestService_processProposerSlashings(t *testing.T) {
serviceCfg: &ServiceConfig{
Database: slasherDB,
AttestationStateFetcher: mockChain,
StateGen: stategen.New(beaconDB),
StateGen: sgmock.NewMockStategen(beaconDB),
SlashingPoolInserter: &slashingsmock.PoolMock{},
HeadStateFetcher: mockChain,
},

View File

@@ -26,6 +26,7 @@ go_library(
"//beacon-chain/core/transition:go_default_library",
"//beacon-chain/db:go_default_library",
"//beacon-chain/db/filters:go_default_library",
"//beacon-chain/forkchoice/types:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/sync/backfill:go_default_library",
"//cache/lru:go_default_library",
@@ -62,6 +63,7 @@ go_test(
"replayer_test.go",
"service_test.go",
"setter_test.go",
"shared_test.go",
],
embed = [":go_default_library"],
deps = [
@@ -69,7 +71,10 @@ go_test(
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/core/transition:go_default_library",
"//beacon-chain/db:go_default_library",
"//beacon-chain/db/iface:go_default_library",
"//beacon-chain/db/testing:go_default_library",
"//beacon-chain/forkchoice/doubly-linked-tree:go_default_library",
"//beacon-chain/forkchoice/types:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/v1:go_default_library",
"//config/params:go_default_library",
@@ -84,6 +89,7 @@ go_test(
"//testing/assert:go_default_library",
"//testing/require:go_default_library",
"//testing/util:go_default_library",
"//time/slots:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
"@org_golang_google_protobuf//proto:go_default_library",

View File

@@ -19,7 +19,7 @@ func TestStateByRoot_GenesisState(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
service := New(beaconDB, newTestSaver(beaconDB))
b := util.NewBeaconBlock()
bRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err)
@@ -36,7 +36,7 @@ func TestStateByRoot_ColdState(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
service := New(beaconDB, newTestSaver(beaconDB))
service.finalizedInfo.slot = 2
service.slotsPerArchivedPoint = 1
@@ -59,7 +59,7 @@ func TestStateByRootIfCachedNoCopy_HotState(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
service := New(beaconDB, newTestSaver(beaconDB))
beaconState, _ := util.DeterministicGenesisState(t, 32)
r := [32]byte{'A'}
@@ -74,7 +74,7 @@ func TestStateByRootIfCachedNoCopy_ColdState(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
service := New(beaconDB, newTestSaver(beaconDB))
service.finalizedInfo.slot = 2
service.slotsPerArchivedPoint = 1
@@ -97,7 +97,7 @@ func TestStateByRoot_HotStateUsingEpochBoundaryCacheNoReplay(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
service := New(beaconDB, newTestSaver(beaconDB))
beaconState, _ := util.DeterministicGenesisState(t, 32)
require.NoError(t, beaconState.SetSlot(10))
@@ -115,7 +115,7 @@ func TestStateByRoot_HotStateUsingEpochBoundaryCacheWithReplay(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
service := New(beaconDB, newTestSaver(beaconDB))
beaconState, _ := util.DeterministicGenesisState(t, 32)
blk := util.NewBeaconBlock()
@@ -140,7 +140,7 @@ func TestStateByRoot_HotStateCached(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
service := New(beaconDB, newTestSaver(beaconDB))
beaconState, _ := util.DeterministicGenesisState(t, 32)
r := [32]byte{'A'}
@@ -156,7 +156,7 @@ func TestDeleteStateFromCaches(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
service := New(beaconDB, newTestSaver(beaconDB))
beaconState, _ := util.DeterministicGenesisState(t, 32)
r := [32]byte{'A'}
@@ -185,7 +185,7 @@ func TestStateByRoot_StateByRootInitialSync(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
service := New(beaconDB, newTestSaver(beaconDB))
b := util.NewBeaconBlock()
bRoot, err := b.Block.HashTreeRoot()
require.NoError(t, err)
@@ -202,7 +202,7 @@ func TestStateByRootInitialSync_UseEpochStateCache(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
service := New(beaconDB, newTestSaver(beaconDB))
beaconState, _ := util.DeterministicGenesisState(t, 32)
targetSlot := types.Slot(10)
@@ -220,7 +220,7 @@ func TestStateByRootInitialSync_UseCache(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
service := New(beaconDB, newTestSaver(beaconDB))
beaconState, _ := util.DeterministicGenesisState(t, 32)
r := [32]byte{'A'}
@@ -238,7 +238,7 @@ func TestStateByRootInitialSync_UseCache(t *testing.T) {
func TestStateByRootInitialSync_CanProcessUpTo(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
service := New(beaconDB, newTestSaver(beaconDB))
beaconState, _ := util.DeterministicGenesisState(t, 32)
blk := util.NewBeaconBlock()
@@ -262,7 +262,7 @@ func TestStateByRootInitialSync_CanProcessUpTo(t *testing.T) {
func TestLoadeStateByRoot_Cached(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
service := New(beaconDB, newTestSaver(beaconDB))
beaconState, _ := util.DeterministicGenesisState(t, 32)
r := [32]byte{'A'}
@@ -277,7 +277,7 @@ func TestLoadeStateByRoot_Cached(t *testing.T) {
func TestLoadeStateByRoot_FinalizedState(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
service := New(beaconDB, newTestSaver(beaconDB))
beaconState, _ := util.DeterministicGenesisState(t, 32)
genesisStateRoot, err := beaconState.HashTreeRoot(ctx)
@@ -301,7 +301,7 @@ func TestLoadeStateByRoot_FinalizedState(t *testing.T) {
func TestLoadeStateByRoot_EpochBoundaryStateCanProcess(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
service := New(beaconDB, newTestSaver(beaconDB))
beaconState, _ := util.DeterministicGenesisState(t, 32)
gBlk := util.NewBeaconBlock()
@@ -327,7 +327,7 @@ func TestLoadeStateByRoot_EpochBoundaryStateCanProcess(t *testing.T) {
func TestLoadeStateByRoot_FromDBBoundaryCase(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
service := New(beaconDB, newTestSaver(beaconDB))
beaconState, _ := util.DeterministicGenesisState(t, 32)
gBlk := util.NewBeaconBlock()
@@ -353,7 +353,7 @@ func TestLoadeStateByRoot_FromDBBoundaryCase(t *testing.T) {
func TestLastAncestorState_CanGetUsingDB(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
service := New(beaconDB, newTestSaver(beaconDB))
b0 := util.NewBeaconBlock()
b0.Block.ParentRoot = bytesutil.PadTo([]byte{'a'}, 32)
@@ -393,7 +393,7 @@ func TestLastAncestorState_CanGetUsingDB(t *testing.T) {
func TestLastAncestorState_CanGetUsingCache(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
service := New(beaconDB, newTestSaver(beaconDB))
b0 := util.NewBeaconBlock()
b0.Block.ParentRoot = bytesutil.PadTo([]byte{'a'}, 32)
@@ -433,7 +433,7 @@ func TestLastAncestorState_CanGetUsingCache(t *testing.T) {
func TestState_HasState(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
service := New(beaconDB, newTestSaver(beaconDB))
s, err := util.NewBeaconState()
require.NoError(t, err)
rHit1 := [32]byte{1}
@@ -465,7 +465,7 @@ func TestState_HasState(t *testing.T) {
func TestState_HasStateInCache(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
service := New(beaconDB, newTestSaver(beaconDB))
s, err := util.NewBeaconState()
require.NoError(t, err)
rHit1 := [32]byte{1}

View File

@@ -529,6 +529,25 @@ func (m *mockCanonicalChecker) IsCanonical(_ context.Context, root [32]byte) (bo
return m.is, m.err
}
func newMockCanonicalMap() *mockCanonicalMap {
return &mockCanonicalMap{
canonical: make(map[[32]byte]struct{}),
}
}
type mockCanonicalMap struct {
canonical map[[32]byte]struct{}
}
func (m *mockCanonicalMap) IsCanonical(_ context.Context, root [32]byte) (bool, error) {
_, exists := m.canonical[root]
return exists, nil
}
func (m *mockCanonicalMap) AddCanonical(root [32]byte) {
m.canonical[root] = struct{}{}
}
func TestReverseChain(t *testing.T) {
// test 0,1,2,3 elements to handle: zero case; single element; even number; odd number
for i := 0; i < 4; i++ {

View File

@@ -1,13 +1,21 @@
package stategen
import (
"context"
"sync"
lru "github.com/hashicorp/golang-lru"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/db"
forkchoicetypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/forkchoice/types"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
lruwrpr "github.com/prysmaticlabs/prysm/v3/cache/lru"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v3/time/slots"
"github.com/sirupsen/logrus"
)
var (
@@ -93,3 +101,190 @@ func (c *hotStateCache) delete(blockRoot [32]byte) bool {
defer c.lock.Unlock()
return c.cache.Remove(blockRoot)
}
// FinalizedCheckpointer describes the forkchoice methods needed by the stategen service
type FinalizedCheckpointer interface {
FinalizedCheckpoint() *forkchoicetypes.Checkpoint
}
type PersistenceMode int
const (
// PersistenceModeMemory means the hot state cache does write to the database
PersistenceModeMemory PersistenceMode = iota
PersistenceModeSnapshot
)
func (m PersistenceMode) String() string {
switch m {
case PersistenceModeMemory:
return "memory"
case PersistenceModeSnapshot:
return "snapshot"
default:
return "unknown"
}
}
func NewHotStateSaver(d db.NoHeadAccessDatabase, fc FinalizedCheckpointer, cs CurrentSlotter) *hotStateSaver {
return &hotStateSaver{
snapshotInterval: DefaultSnapshotInterval,
db: d,
fc: fc,
cs: cs,
}
}
// This tracks the config in the event of long non-finality,
// how often does the node save hot states to db? what are
// the saved hot states in db?... etc
type hotStateSaver struct {
m PersistenceMode
lock sync.RWMutex
snapshotInterval types.Slot
savedRoots [][32]byte
db db.NoHeadAccessDatabase
fc FinalizedCheckpointer
cs CurrentSlotter
}
var _ Saver = &hotStateSaver{}
// enable/disable hot state saving m depending on
// whether the size of the gap between finalized and current epochs
// is greater than the threshold.
func (s *hotStateSaver) refreshMode(ctx context.Context) (PersistenceMode, error) {
current := slots.ToEpoch(s.cs.CurrentSlot())
fcp := s.fc.FinalizedCheckpoint()
if fcp == nil {
return PersistenceModeMemory, errForkchoiceFinalizedNil
}
// don't allow underflow
if fcp.Epoch > current {
return PersistenceModeMemory, errCurrentEpochBehindFinalized
}
if current-fcp.Epoch >= hotStateSaveThreshold {
s.enableSnapshots()
return PersistenceModeSnapshot, nil
}
return PersistenceModeMemory, s.disableSnapshots(ctx)
}
func (s *hotStateSaver) mode() PersistenceMode {
s.lock.RLock()
defer s.lock.RUnlock()
return s.m
}
// enableHotStateSaving enters the m that saves hot beacon state to the DB.
// This usually gets triggered when there's long duration since finality.
func (s *hotStateSaver) enableSnapshots() {
if s.mode() == PersistenceModeSnapshot {
return
}
s.lock.Lock()
defer s.lock.Unlock()
s.m = PersistenceModeSnapshot
log.WithFields(logrus.Fields{
"mode": s.m.String(),
"slotsPerSnapshot": s.snapshotInterval,
}).Warn("Enabling state cache db snapshots")
}
// disableHotStateSaving exits the m that saves beacon state to DB for the hot states.
// This usually gets triggered once there's finality after long duration since finality.
func (s *hotStateSaver) disableSnapshots(ctx context.Context) error {
if s.mode() == PersistenceModeMemory {
return nil
}
s.lock.Lock()
defer s.lock.Unlock()
log.WithFields(logrus.Fields{
"mode": PersistenceModeMemory.String(),
"slotsPerSnapshot": s.snapshotInterval,
}).Warn("Disabling state cache db snapshots and removing saved snapshots")
// we have a recent-enough finalized state, so time to clean up the state cache snapshots
if err := s.db.DeleteStates(ctx, s.savedRoots); err != nil {
return err
}
s.savedRoots = nil
s.m = PersistenceModeMemory
return nil
}
func shouldSave(m PersistenceMode, interval types.Slot, st state.BeaconState) bool {
if m != PersistenceModeSnapshot {
// only write full states to the db when in snapshot mode
return false
}
// divide by zero guard
if interval == 0 {
return false
}
// only saving every s.duration slots - typically every 128 slots
// checking this first avoids holding the lock if we aren't on a slot that should be saved
if st.Slot().ModSlot(interval) != 0 {
return false
}
return true
}
func (s *hotStateSaver) Save(ctx context.Context, blockRoot [32]byte, st state.BeaconState) error {
mode, err := s.refreshMode(ctx)
if err != nil {
return errors.Wrap(err, "unable to make hot state saving decision")
}
err = s.db.SaveStateSummary(ctx, &ethpb.StateSummary{Slot: st.Slot(), Root: blockRoot[:]})
if err != nil {
return err
}
if !shouldSave(mode, s.snapshotInterval, st) {
return nil
}
// we need the update to savedRoots to be in the same critical section as db.SaveState
// because in Preserve we need the state bucket to be consistent with the list of saved roots
// so that we can safely confirm the state is present and remove it from the root cleanup list.
s.lock.Lock()
defer s.lock.Unlock()
s.savedRoots = append(s.savedRoots, blockRoot)
log.WithFields(logrus.Fields{
"slot": st.Slot(),
"totalStatesWritten": len(s.savedRoots),
}).Info("Saving hot state to DB")
return s.db.SaveState(ctx, st, blockRoot)
}
// Preserve ensures that the given state is permanently saved in the db. If the state already exists
// and the state saver is in snapshot mode, the block root will be removed from the list of roots to
// clean up when exiting snapshot mode to ensure it won't be deleted in the cleanup procedure.
func (s *hotStateSaver) Preserve(ctx context.Context, root [32]byte, st state.BeaconState) error {
s.lock.Lock()
defer s.lock.Unlock()
exists := s.db.HasState(ctx, root)
if !exists {
if err := s.db.SaveState(ctx, st, root); err != nil {
return err
}
}
// the state exists, and we aren't in snapshot mode, so we shouldn't have to do anything
if s.m != PersistenceModeSnapshot {
return nil
}
// slice the preserved root out of the list of states to delete once the node exists snapshot mode.
for i := 0; i < len(s.savedRoots); i++ {
if s.savedRoots[i] == root {
s.savedRoots = append(s.savedRoots[:i], s.savedRoots[i+1:]...)
return nil
}
}
return nil
}

View File

@@ -1,13 +1,21 @@
package stategen
import (
"context"
"testing"
testDB "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing"
doublylinkedtree "github.com/prysmaticlabs/prysm/v3/beacon-chain/forkchoice/doubly-linked-tree"
forkchoicetypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/forkchoice/types"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
v1 "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/v1"
"github.com/prysmaticlabs/prysm/v3/config/params"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v3/testing/assert"
"github.com/prysmaticlabs/prysm/v3/testing/require"
"github.com/prysmaticlabs/prysm/v3/testing/util"
"github.com/prysmaticlabs/prysm/v3/time/slots"
)
func TestHotStateCache_RoundTrip(t *testing.T) {
@@ -32,3 +40,120 @@ func TestHotStateCache_RoundTrip(t *testing.T) {
c.delete(root)
assert.Equal(t, false, c.has(root), "Cache not supposed to have the object")
}
func TestHotStateSaving_Enabled(t *testing.T) {
h := &hotStateSaver{
db: testDB.SetupDB(t),
}
h.enableSnapshots()
require.Equal(t, PersistenceModeSnapshot, h.mode())
}
func TestHotStateSaving_AlreadyEnabled(t *testing.T) {
h := &hotStateSaver{
db: testDB.SetupDB(t),
m: PersistenceModeSnapshot,
}
h.enableSnapshots()
require.Equal(t, PersistenceModeSnapshot, h.mode())
}
func TestHotStateSaving_Disabled(t *testing.T) {
ctx := context.Background()
h := &hotStateSaver{
db: testDB.SetupDB(t),
m: PersistenceModeSnapshot,
}
b := util.NewBeaconBlock()
util.SaveBlock(t, ctx, h.db, b)
r, err := b.Block.HashTreeRoot()
require.NoError(t, err)
h.savedRoots = [][32]byte{r}
require.NoError(t, h.disableSnapshots(ctx))
require.Equal(t, PersistenceModeMemory, h.mode())
require.Equal(t, 0, len(h.savedRoots))
}
func TestHotStateSaving_AlreadyDisabled(t *testing.T) {
h := &hotStateSaver{}
require.NoError(t, h.disableSnapshots(context.Background()))
require.Equal(t, PersistenceModeMemory, h.mode())
}
func TestHotStateSaving_DisabledByDefault(t *testing.T) {
h := &hotStateSaver{
db: testDB.SetupDB(t),
fc: doublylinkedtree.New(),
}
fin := h.fc.FinalizedCheckpoint()
finslot, err := slots.EpochStart(fin.Epoch)
require.NoError(t, err)
h.cs = &mockCurrentSlotter{Slot: finslot}
require.Equal(t, PersistenceModeMemory, h.mode())
mode, err := h.refreshMode(context.Background())
require.NoError(t, err)
require.Equal(t, PersistenceModeMemory, mode)
}
func TestHotStateSaving_Enabling(t *testing.T) {
h := &hotStateSaver{
db: testDB.SetupDB(t),
fc: doublylinkedtree.New(),
cs: &mockCurrentSlotter{Slot: types.Slot(uint64(params.BeaconConfig().SlotsPerEpoch) * uint64(hotStateSaveThreshold))},
}
mode, err := h.refreshMode(context.Background())
require.NoError(t, err)
require.Equal(t, PersistenceModeSnapshot, mode)
}
func TestHotStateSaving_DisableAfterFinality(t *testing.T) {
h := &hotStateSaver{
db: testDB.SetupDB(t),
fc: doublylinkedtree.New(),
cs: &mockCurrentSlotter{Slot: types.Slot(uint64(params.BeaconConfig().SlotsPerEpoch) * uint64(hotStateSaveThreshold))},
}
mode, err := h.refreshMode(context.Background())
require.NoError(t, err)
require.Equal(t, PersistenceModeSnapshot, mode)
// set current slot equal to finalized and ask for an update, should be disabled
fin := h.fc.FinalizedCheckpoint()
finslot, err := slots.EpochStart(fin.Epoch)
require.NoError(t, err)
h.cs = &mockCurrentSlotter{Slot: finslot}
mode, err = h.refreshMode(context.Background())
require.NoError(t, err)
require.Equal(t, PersistenceModeMemory, mode)
}
type mockFinalizedCheckpointer struct {
c *forkchoicetypes.Checkpoint
}
func (m *mockFinalizedCheckpointer) FinalizedCheckpoint() *forkchoicetypes.Checkpoint {
return m.c
}
var _ FinalizedCheckpointer = &mockFinalizedCheckpointer{}
func TestUpdateHotStateMode_CurrentSlotBeforeFinalized(t *testing.T) {
h := &hotStateSaver{
db: testDB.SetupDB(t),
fc: &mockFinalizedCheckpointer{c: &forkchoicetypes.Checkpoint{Epoch: 1}},
cs: &mockCurrentSlotter{Slot: 0},
}
mode, err := h.refreshMode(context.Background())
require.ErrorIs(t, err, errCurrentEpochBehindFinalized)
require.Equal(t, PersistenceModeMemory, mode)
}
func TestUpdateHotStateMode_NilFinalized(t *testing.T) {
h := &hotStateSaver{
db: testDB.SetupDB(t),
fc: &mockFinalizedCheckpointer{c: nil},
cs: &mockCurrentSlotter{Slot: 0},
}
mode, err := h.refreshMode(context.Background())
require.ErrorIs(t, err, errForkchoiceFinalizedNil)
require.Equal(t, PersistenceModeMemory, mode)
}

View File

@@ -5,6 +5,7 @@ import (
"encoding/hex"
"fmt"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
"github.com/sirupsen/logrus"
@@ -39,62 +40,47 @@ func (s *State) MigrateToCold(ctx context.Context, fRoot [32]byte) error {
}
if slot%s.slotsPerArchivedPoint == 0 && slot != 0 {
var aRoot [32]byte
var aState state.BeaconState
// cases we need to handle:
// 1. state exists in the epoch boundary state cache
// 2. state is in the database due to hot state saver in snapshot mode
// in this case we're looking up by slot, there's no root to look up, so we still have to replay blocks
// so state 2&3 are the same case
// 3. state snapshot is not in the database, rebuild it from stategen
// in all 3 cases we want to make sure the snapshot mode saver does not delete it.
cached, exists, err := s.epochBoundaryStateCache.getBySlot(slot)
if err != nil {
return fmt.Errorf("could not get epoch boundary state for slot %d", slot)
}
var aRoot [32]byte
var aState state.BeaconState
// When the epoch boundary state is not in cache due to skip slot scenario,
// we have to regenerate the state which will represent epoch boundary.
// By finding the highest available block below epoch boundary slot, we
// generate the state for that block root.
if exists {
// case 1 - state in epoch boundary state cache
aRoot = cached.root
aState = cached.state
} else {
_, roots, err := s.beaconDB.HighestRootsBelowSlot(ctx, slot)
// case 3 - state is not in db, we need to rebuild it from the most recent available state
aState, err = s.rb.ReplayerForSlot(slot).ReplayToSlot(ctx, slot)
if err != nil {
return err
}
// Given the block has been finalized, the db should not have more than one block in a given slot.
// We should error out when this happens.
if len(roots) != 1 {
return errUnknownBlock
// compute the block hash from the state
sr, err := aState.HashTreeRoot(ctx)
if err != nil {
return errors.Wrap(err, "error while computing hash_tree_root of state in MigrateToCold")
}
aRoot = roots[0]
// There's no need to generate the state if the state already exists in the DB.
// We can skip saving the state.
if !s.beaconDB.HasState(ctx, aRoot) {
aState, err = s.StateByRoot(ctx, aRoot)
if err != nil {
return err
}
header := aState.LatestBlockHeader()
header.StateRoot = sr[:]
aRoot, err = header.HashTreeRoot()
if err != nil {
return errors.Wrap(err, "error while computing block root using state data")
}
}
if s.beaconDB.HasState(ctx, aRoot) {
// If you are migrating a state and its already part of the hot state cache saved to the db,
// you can just remove it from the hot state cache as it becomes redundant.
s.saveHotStateDB.lock.Lock()
roots := s.saveHotStateDB.blockRootsOfSavedStates
for i := 0; i < len(roots); i++ {
if aRoot == roots[i] {
s.saveHotStateDB.blockRootsOfSavedStates = append(roots[:i], roots[i+1:]...)
// There shouldn't be duplicated roots in `blockRootsOfSavedStates`.
// Break here is ok.
break
}
}
s.saveHotStateDB.lock.Unlock()
continue
}
if err := s.beaconDB.SaveState(ctx, aState, aRoot); err != nil {
if err := s.saver.Preserve(ctx, aRoot, aState); err != nil {
return err
}
log.WithFields(
logrus.Fields{
"slot": aState.Slot(),

View File

@@ -17,7 +17,7 @@ import (
func TestMigrateToCold_CanSaveFinalizedInfo(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
service := New(beaconDB, newTestSaver(beaconDB))
beaconState, _ := util.DeterministicGenesisState(t, 32)
b := util.NewBeaconBlock()
b.Block.Slot = 1
@@ -36,7 +36,20 @@ func TestMigrateToCold_HappyPath(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
var zero, one, two, three, four, five types.Slot = 50, 51, 150, 151, 152, 200
specs := []mockHistorySpec{
{slot: zero},
{slot: one, savedState: true},
{slot: two},
{slot: three},
{slot: four},
{slot: five, canonicalBlock: true},
}
hist := newMockHistory(t, specs, five+1)
ch := NewCanonicalHistory(hist, hist, hist)
service := New(beaconDB, newTestSaver(beaconDB), WithReplayerBuilder(ch))
service.slotsPerArchivedPoint = 1
beaconState, _ := util.DeterministicGenesisState(t, 32)
stateSlot := types.Slot(1)
@@ -66,7 +79,11 @@ func TestMigrateToCold_RegeneratePath(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
mockCanon := newMockCanonicalMap()
// picking 5 because the highest block in the below setup code is 4 and we're not testing
// slot bounds weirdness here.
ch := NewCanonicalHistory(beaconDB, mockCanon, &mockCurrentSlotter{Slot: 5})
service := New(beaconDB, newTestSaver(beaconDB), WithReplayerBuilder(ch))
service.slotsPerArchivedPoint = 1
beaconState, pks := util.DeterministicGenesisState(t, 32)
genesisStateRoot, err := beaconState.HashTreeRoot(ctx)
@@ -82,6 +99,7 @@ func TestMigrateToCold_RegeneratePath(t *testing.T) {
require.NoError(t, err)
r1, err := b1.Block.HashTreeRoot()
require.NoError(t, err)
mockCanon.AddCanonical(r1)
util.SaveBlock(t, ctx, service.beaconDB, b1)
require.NoError(t, service.beaconDB.SaveStateSummary(ctx, &ethpb.StateSummary{Slot: 1, Root: r1[:]}))
@@ -89,6 +107,7 @@ func TestMigrateToCold_RegeneratePath(t *testing.T) {
require.NoError(t, err)
r4, err := b4.Block.HashTreeRoot()
require.NoError(t, err)
mockCanon.AddCanonical(r4)
util.SaveBlock(t, ctx, service.beaconDB, b4)
require.NoError(t, service.beaconDB.SaveStateSummary(ctx, &ethpb.StateSummary{Slot: 4, Root: r4[:]}))
service.finalizedInfo = &finalizedInfo{
@@ -101,16 +120,18 @@ func TestMigrateToCold_RegeneratePath(t *testing.T) {
s1, err := service.beaconDB.State(ctx, r1)
require.NoError(t, err)
assert.Equal(t, s1.Slot(), types.Slot(1), "Did not save state")
gotRoot := service.beaconDB.ArchivedPointRoot(ctx, 1/service.slotsPerArchivedPoint)
assert.Equal(t, r1, gotRoot, "Did not save archived root")
lastIndex, err := service.beaconDB.LastArchivedSlot(ctx)
require.NotEqual(t, nil, s1)
require.Equal(t, false, service.beaconDB.HasState(ctx, r4))
s4, err := service.beaconDB.State(ctx, r4)
require.NoError(t, err)
assert.Equal(t, types.Slot(1), lastIndex, "Did not save last archived index")
require.Equal(t, nil, s4)
require.LogsContain(t, hook, "Saved state in DB")
}
// TODO!!! fix this migrate to cold test
/*
func TestMigrateToCold_StateExistsInDB(t *testing.T) {
hook := logTest.NewGlobal()
ctx := context.Background()
@@ -129,8 +150,9 @@ func TestMigrateToCold_StateExistsInDB(t *testing.T) {
require.NoError(t, service.epochBoundaryStateCache.put(fRoot, beaconState))
require.NoError(t, service.beaconDB.SaveState(ctx, beaconState, fRoot))
service.saveHotStateDB.blockRootsOfSavedStates = [][32]byte{{1}, {2}, {3}, {4}, fRoot}
service.saver.savedRoots = [][32]byte{{1}, {2}, {3}, {4}, fRoot}
require.NoError(t, service.MigrateToCold(ctx, fRoot))
assert.DeepEqual(t, [][32]byte{{1}, {2}, {3}, {4}}, service.saveHotStateDB.blockRootsOfSavedStates)
assert.DeepEqual(t, [][32]byte{{1}, {2}, {3}, {4}}, service.saver.savedRoots)
assert.LogsDoNotContain(t, hook, "Saved state in DB")
}
*/

View File

@@ -6,10 +6,12 @@ go_library(
srcs = [
"mock.go",
"replayer.go",
"saver.go",
],
importpath = "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock",
visibility = ["//visibility:public"],
deps = [
"//beacon-chain/db/iface:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/stategen:go_default_library",
"//consensus-types/primitives:go_default_library",

View File

@@ -71,16 +71,6 @@ func (_ *MockStateManager) ForceCheckpoint(_ context.Context, _ []byte) error {
panic("implement me")
}
// EnableSaveHotStateToDB --
func (_ *MockStateManager) EnableSaveHotStateToDB(_ context.Context) {
panic("implement me")
}
// DisableSaveHotStateToDB --
func (_ *MockStateManager) DisableSaveHotStateToDB(_ context.Context) error {
panic("implement me")
}
// AddStateForRoot --
func (m *MockStateManager) AddStateForRoot(state state.BeaconState, blockRoot [32]byte) {
m.StatesByRoot[blockRoot] = state

View File

@@ -0,0 +1,42 @@
package mock
import (
"context"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/db/iface"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
)
// NewMockSaver creates a value that can be used as a stategen.Saver in tests
func NewMockSaver(d iface.Database) *MockSaver {
return &MockSaver{
db: d,
}
}
type MockSaver struct {
db iface.HeadAccessDatabase
}
// Save just saves everything it is asked to save
func (s *MockSaver) Save(ctx context.Context, root [32]byte, st state.BeaconState) error {
return s.db.SaveState(ctx, st, root)
}
// Preserve just checks to see if the state has been saved before saving it
func (s *MockSaver) Preserve(ctx context.Context, root [32]byte, st state.BeaconState) error {
if !s.db.HasState(ctx, root) {
return s.Save(ctx, root, st)
}
return nil
}
var _ stategen.Saver = &MockSaver{}
// NewMockStategen hides the complexity of preparing all the values needed to construct an
// instance of stategen.State for tests that don't make assumptions about the internal behavior of stategen.
func NewMockStategen(db iface.HeadAccessDatabase, opts ...stategen.StateGenOption) *stategen.State {
saver := &MockSaver{db: db}
return stategen.New(db, saver, opts...)
}

View File

@@ -41,7 +41,7 @@ func TestReplayBlocks_AllSkipSlots(t *testing.T) {
require.NoError(t, beaconState.SetCurrentJustifiedCheckpoint(cp))
require.NoError(t, beaconState.AppendCurrentEpochAttestations(&ethpb.PendingAttestation{}))
service := New(beaconDB)
service := New(beaconDB, newTestSaver(beaconDB))
targetSlot := params.BeaconConfig().SlotsPerEpoch - 1
newState, err := service.replayBlocks(context.Background(), beaconState, []interfaces.SignedBeaconBlock{}, targetSlot)
require.NoError(t, err)
@@ -70,7 +70,7 @@ func TestReplayBlocks_SameSlot(t *testing.T) {
require.NoError(t, beaconState.SetCurrentJustifiedCheckpoint(cp))
require.NoError(t, beaconState.AppendCurrentEpochAttestations(&ethpb.PendingAttestation{}))
service := New(beaconDB)
service := New(beaconDB, newTestSaver(beaconDB))
targetSlot := beaconState.Slot()
newState, err := service.replayBlocks(context.Background(), beaconState, []interfaces.SignedBeaconBlock{}, targetSlot)
require.NoError(t, err)
@@ -100,7 +100,7 @@ func TestReplayBlocks_LowerSlotBlock(t *testing.T) {
require.NoError(t, beaconState.SetCurrentJustifiedCheckpoint(cp))
require.NoError(t, beaconState.AppendCurrentEpochAttestations(&ethpb.PendingAttestation{}))
service := New(beaconDB)
service := New(beaconDB, newTestSaver(beaconDB))
targetSlot := beaconState.Slot()
b := util.NewBeaconBlock()
b.Block.Slot = beaconState.Slot() - 1
@@ -130,7 +130,8 @@ func TestReplayBlocks_ThroughForkBoundary(t *testing.T) {
})
require.NoError(t, err)
service := New(testDB.SetupDB(t))
bdb := testDB.SetupDB(t)
service := New(bdb, newTestSaver(bdb))
targetSlot := params.BeaconConfig().SlotsPerEpoch
newState, err := service.replayBlocks(context.Background(), beaconState, []interfaces.SignedBeaconBlock{}, targetSlot)
require.NoError(t, err)
@@ -160,7 +161,8 @@ func TestReplayBlocks_ThroughBellatrixForkBoundary(t *testing.T) {
})
require.NoError(t, err)
service := New(testDB.SetupDB(t))
bdb := testDB.SetupDB(t)
service := New(bdb, newTestSaver(bdb))
targetSlot := params.BeaconConfig().SlotsPerEpoch * 2
newState, err := service.replayBlocks(context.Background(), beaconState, []interfaces.SignedBeaconBlock{}, targetSlot)
require.NoError(t, err)

View File

@@ -17,14 +17,14 @@ import (
"go.opencensus.io/trace"
)
var defaultHotStateDBInterval types.Slot = 128
// DefaultSnapshotInterval dictates how frequently the state should be saved when the Saver
// goes into snapshot mode. Default value is once every 128 slots.
var DefaultSnapshotInterval types.Slot = 128
// StateManager represents a management object that handles the internal
// logic of maintaining both hot and cold states in DB.
type StateManager interface {
Resume(ctx context.Context, fState state.BeaconState) (state.BeaconState, error)
DisableSaveHotStateToDB(ctx context.Context) error
EnableSaveHotStateToDB(_ context.Context)
HasState(ctx context.Context, blockRoot [32]byte) (bool, error)
DeleteStateFromCaches(ctx context.Context, blockRoot [32]byte) error
ForceCheckpoint(ctx context.Context, root []byte) error
@@ -43,18 +43,9 @@ type State struct {
hotStateCache *hotStateCache
finalizedInfo *finalizedInfo
epochBoundaryStateCache *epochBoundaryState
saveHotStateDB *saveHotStateDbConfig
saver Saver
backfillStatus *backfill.Status
}
// This tracks the config in the event of long non-finality,
// how often does the node save hot states to db? what are
// the saved hot states in db?... etc
type saveHotStateDbConfig struct {
enabled bool
lock sync.Mutex
duration types.Slot
blockRootsOfSavedStates [][32]byte
rb ReplayerBuilder
}
// This tracks the finalized point. It's also the point where slot and the block root of
@@ -75,17 +66,29 @@ func WithBackfillStatus(bfs *backfill.Status) StateGenOption {
}
}
func WithReplayerBuilder(rb ReplayerBuilder) StateGenOption {
return func(sg *State) {
sg.rb = rb
}
}
// Saver is an interface describing the set of methods that stategen needs
// in order to delegate the decision to save hot states to the database. The Strategy is
// responsible for cleaning up the database
type Saver interface {
Save(ctx context.Context, blockRoot [32]byte, st state.BeaconState) error
Preserve(ctx context.Context, root [32]byte, st state.BeaconState) error
}
// New returns a new state management object.
func New(beaconDB db.NoHeadAccessDatabase, opts ...StateGenOption) *State {
func New(beaconDB db.NoHeadAccessDatabase, saver Saver, opts ...StateGenOption) *State {
s := &State{
beaconDB: beaconDB,
hotStateCache: newHotStateCache(),
finalizedInfo: &finalizedInfo{slot: 0, root: params.BeaconConfig().ZeroHash},
slotsPerArchivedPoint: params.BeaconConfig().SlotsPerArchivedPoint,
epochBoundaryStateCache: newBoundaryStateCache(),
saveHotStateDB: &saveHotStateDbConfig{
duration: defaultHotStateDBInterval,
},
saver: saver,
}
for _, o := range opts {
o(s)

View File

@@ -16,7 +16,7 @@ func TestResume(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
service := New(beaconDB, newTestSaver(beaconDB))
b := util.NewBeaconBlock()
util.SaveBlock(t, ctx, service.beaconDB, b)
root, err := b.Block.HashTreeRoot()

View File

@@ -2,17 +2,22 @@ package stategen
import (
"context"
"math"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v3/config/params"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v3/time/slots"
"github.com/sirupsen/logrus"
"go.opencensus.io/trace"
)
var (
errCurrentEpochBehindFinalized = errors.New("finalized epoch must always be before the current epoch")
errForkchoiceFinalizedNil = errors.New("forkchoice store finalized checkpoint is nil")
)
var hotStateSaveThreshold = types.Epoch(100)
// SaveState saves the state in the cache and/or DB.
func (s *State) SaveState(ctx context.Context, blockRoot [32]byte, st state.BeaconState) error {
ctx, span := trace.StartSpan(ctx, "stateGen.SaveState")
@@ -51,29 +56,16 @@ func (s *State) saveStateByRoot(ctx context.Context, blockRoot [32]byte, st stat
ctx, span := trace.StartSpan(ctx, "stateGen.saveStateByRoot")
defer span.End()
// Duration can't be 0 to prevent panic for division.
duration := uint64(math.Max(float64(s.saveHotStateDB.duration), 1))
s.saveHotStateDB.lock.Lock()
if s.saveHotStateDB.enabled && st.Slot().Mod(duration) == 0 {
if err := s.beaconDB.SaveState(ctx, st, blockRoot); err != nil {
s.saveHotStateDB.lock.Unlock()
return err
}
s.saveHotStateDB.blockRootsOfSavedStates = append(s.saveHotStateDB.blockRootsOfSavedStates, blockRoot)
log.WithFields(logrus.Fields{
"slot": st.Slot(),
"totalHotStateSavedInDB": len(s.saveHotStateDB.blockRootsOfSavedStates),
}).Info("Saving hot state to DB")
}
s.saveHotStateDB.lock.Unlock()
// If the hot state is already in cache, one can be sure the state was processed and in the DB.
// this is the only method that puts states in the cache, so if the state is in the cache
// the state has already been processed by this method and there's no need to run again.
if s.hotStateCache.has(blockRoot) {
return nil
}
if err := s.saver.Save(ctx, blockRoot, st); err != nil {
return err
}
// Only on an epoch boundary slot, save epoch boundary state in epoch boundary root state cache.
if slots.IsEpochStart(st.Slot()) {
if err := s.epochBoundaryStateCache.put(blockRoot, st); err != nil {
@@ -81,57 +73,8 @@ func (s *State) saveStateByRoot(ctx context.Context, blockRoot [32]byte, st stat
}
}
// On an intermediate slot, save state summary.
if err := s.beaconDB.SaveStateSummary(ctx, &ethpb.StateSummary{
Slot: st.Slot(),
Root: blockRoot[:],
}); err != nil {
return err
}
// Store the copied state in the hot state cache.
s.hotStateCache.put(blockRoot, st)
return nil
}
// EnableSaveHotStateToDB enters the mode that saves hot beacon state to the DB.
// This usually gets triggered when there's long duration since finality.
func (s *State) EnableSaveHotStateToDB(_ context.Context) {
s.saveHotStateDB.lock.Lock()
defer s.saveHotStateDB.lock.Unlock()
if s.saveHotStateDB.enabled {
return
}
s.saveHotStateDB.enabled = true
log.WithFields(logrus.Fields{
"enabled": s.saveHotStateDB.enabled,
"slotsInterval": s.saveHotStateDB.duration,
}).Warn("Entering mode to save hot states in DB")
}
// DisableSaveHotStateToDB exits the mode that saves beacon state to DB for the hot states.
// This usually gets triggered once there's finality after long duration since finality.
func (s *State) DisableSaveHotStateToDB(ctx context.Context) error {
s.saveHotStateDB.lock.Lock()
defer s.saveHotStateDB.lock.Unlock()
if !s.saveHotStateDB.enabled {
return nil
}
log.WithFields(logrus.Fields{
"enabled": s.saveHotStateDB.enabled,
"deletedHotStates": len(s.saveHotStateDB.blockRootsOfSavedStates),
}).Warn("Exiting mode to save hot states in DB")
// Delete previous saved states in DB as we are turning this mode off.
s.saveHotStateDB.enabled = false
if err := s.beaconDB.DeleteStates(ctx, s.saveHotStateDB.blockRootsOfSavedStates); err != nil {
return err
}
s.saveHotStateDB.blockRootsOfSavedStates = nil
return nil
}

View File

@@ -5,18 +5,29 @@ import (
"testing"
testDB "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing"
forkchoicetypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/forkchoice/types"
"github.com/prysmaticlabs/prysm/v3/config/params"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v3/testing/assert"
"github.com/prysmaticlabs/prysm/v3/testing/require"
"github.com/prysmaticlabs/prysm/v3/testing/util"
"github.com/prysmaticlabs/prysm/v3/time/slots"
logTest "github.com/sirupsen/logrus/hooks/test"
)
func TestSaveState_HotStateCanBeSaved(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
genroot := [32]byte{}
cp := &forkchoicetypes.Checkpoint{Epoch: 0, Root: genroot}
h := newTestSaver(beaconDB, withFinalizedCheckpointer(&mockFinalizedCheckpointer{c: cp}))
stateSlot := firstSaveableSlotAfter(t, h)
h.cs = &mockCurrentSlotter{Slot: stateSlot + h.snapshotInterval}
mode, err := h.refreshMode(ctx)
require.NoError(t, err)
require.Equal(t, PersistenceModeSnapshot, mode)
service := New(beaconDB, h)
service := New(beaconDB)
service.slotsPerArchivedPoint = 1
beaconState, _ := util.DeterministicGenesisState(t, 32)
// This goes to hot section, verify it can save on epoch boundary.
@@ -37,7 +48,7 @@ func TestSaveState_HotStateCached(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
service := New(beaconDB, newTestSaver(beaconDB))
service.slotsPerArchivedPoint = 1
beaconState, _ := util.DeterministicGenesisState(t, 32)
require.NoError(t, beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch))
@@ -57,7 +68,7 @@ func TestState_ForceCheckpoint_SavesStateToDatabase(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
svc := New(beaconDB)
svc := New(beaconDB, newTestSaver(beaconDB))
beaconState, _ := util.DeterministicGenesisState(t, 32)
require.NoError(t, beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch))
@@ -76,7 +87,7 @@ func TestSaveState_Alreadyhas(t *testing.T) {
hook := logTest.NewGlobal()
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
service := New(beaconDB, newTestSaver(beaconDB))
beaconState, _ := util.DeterministicGenesisState(t, 32)
require.NoError(t, beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch))
@@ -95,7 +106,15 @@ func TestSaveState_Alreadyhas(t *testing.T) {
func TestSaveState_CanSaveOnEpochBoundary(t *testing.T) {
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
genroot := [32]byte{}
cp := &forkchoicetypes.Checkpoint{Epoch: 0, Root: genroot}
h := newTestSaver(beaconDB, withFinalizedCheckpointer(&mockFinalizedCheckpointer{c: cp}))
stateSlot := firstSaveableSlotAfter(t, h)
h.cs = &mockCurrentSlotter{Slot: stateSlot + h.snapshotInterval}
mode, err := h.refreshMode(ctx)
require.NoError(t, err)
require.Equal(t, PersistenceModeSnapshot, mode)
service := New(beaconDB, h)
beaconState, _ := util.DeterministicGenesisState(t, 32)
require.NoError(t, beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch))
@@ -116,7 +135,15 @@ func TestSaveState_NoSaveNotEpochBoundary(t *testing.T) {
hook := logTest.NewGlobal()
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
genroot := [32]byte{}
cp := &forkchoicetypes.Checkpoint{Epoch: 0, Root: genroot}
h := newTestSaver(beaconDB, withFinalizedCheckpointer(&mockFinalizedCheckpointer{c: cp}))
stateSlot := firstSaveableSlotAfter(t, h)
h.cs = &mockCurrentSlotter{Slot: stateSlot + h.snapshotInterval}
mode, err := h.refreshMode(ctx)
require.NoError(t, err)
require.Equal(t, PersistenceModeSnapshot, mode)
service := New(beaconDB, h)
beaconState, _ := util.DeterministicGenesisState(t, 32)
require.NoError(t, beaconState.SetSlot(params.BeaconConfig().SlotsPerEpoch-1))
@@ -134,70 +161,44 @@ func TestSaveState_NoSaveNotEpochBoundary(t *testing.T) {
require.LogsDoNotContain(t, hook, "Saved full state on epoch boundary")
// Should have not been saved in DB.
require.Equal(t, false, beaconDB.HasState(ctx, r))
_, ok, err := service.epochBoundaryStateCache.getByBlockRoot(r)
require.NoError(t, err)
require.Equal(t, false, ok, "saved to epoch boundary cache in error")
}
func firstSaveableSlotAfter(t *testing.T, h *hotStateSaver) types.Slot {
min, err := slots.EpochStart(hotStateSaveThreshold)
require.NoError(t, err)
f := h.fc.FinalizedCheckpoint()
require.NotNil(t, f)
fslot, err := slots.EpochStart(f.Epoch)
require.NoError(t, err)
min += fslot
diff := h.snapshotInterval - (min % h.snapshotInterval)
aligned := min + diff
require.Equal(t, types.Slot(0), aligned%h.snapshotInterval)
return min + diff
}
func TestSaveState_CanSaveHotStateToDB(t *testing.T) {
hook := logTest.NewGlobal()
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
service.EnableSaveHotStateToDB(ctx)
genroot := [32]byte{}
cp := &forkchoicetypes.Checkpoint{Epoch: 0, Root: genroot}
h := newTestSaver(beaconDB, withFinalizedCheckpointer(&mockFinalizedCheckpointer{c: cp}))
stateSlot := firstSaveableSlotAfter(t, h)
h.cs = &mockCurrentSlotter{Slot: stateSlot + h.snapshotInterval}
mode, err := h.refreshMode(ctx)
require.NoError(t, err)
require.Equal(t, PersistenceModeSnapshot, mode)
service := New(beaconDB, h)
beaconState, _ := util.DeterministicGenesisState(t, 32)
require.NoError(t, beaconState.SetSlot(defaultHotStateDBInterval))
require.NoError(t, beaconState.SetSlot(stateSlot))
r := [32]byte{'A'}
require.NoError(t, service.saveStateByRoot(ctx, r, beaconState))
require.LogsContain(t, hook, "Saving hot state to DB")
// Should have saved in DB.
require.Equal(t, true, beaconDB.HasState(ctx, r))
}
func TestEnableSaveHotStateToDB_Enabled(t *testing.T) {
hook := logTest.NewGlobal()
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
service.EnableSaveHotStateToDB(ctx)
require.LogsContain(t, hook, "Entering mode to save hot states in DB")
require.Equal(t, true, service.saveHotStateDB.enabled)
}
func TestEnableSaveHotStateToDB_AlreadyEnabled(t *testing.T) {
hook := logTest.NewGlobal()
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
service.saveHotStateDB.enabled = true
service.EnableSaveHotStateToDB(ctx)
require.LogsDoNotContain(t, hook, "Entering mode to save hot states in DB")
require.Equal(t, true, service.saveHotStateDB.enabled)
}
func TestEnableSaveHotStateToDB_Disabled(t *testing.T) {
hook := logTest.NewGlobal()
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
service.saveHotStateDB.enabled = true
b := util.NewBeaconBlock()
util.SaveBlock(t, ctx, beaconDB, b)
r, err := b.Block.HashTreeRoot()
require.NoError(t, err)
service.saveHotStateDB.blockRootsOfSavedStates = [][32]byte{r}
require.NoError(t, service.DisableSaveHotStateToDB(ctx))
require.LogsContain(t, hook, "Exiting mode to save hot states in DB")
require.Equal(t, false, service.saveHotStateDB.enabled)
require.Equal(t, 0, len(service.saveHotStateDB.blockRootsOfSavedStates))
}
func TestEnableSaveHotStateToDB_AlreadyDisabled(t *testing.T) {
hook := logTest.NewGlobal()
ctx := context.Background()
beaconDB := testDB.SetupDB(t)
service := New(beaconDB)
require.NoError(t, service.DisableSaveHotStateToDB(ctx))
require.LogsDoNotContain(t, hook, "Exiting mode to save hot states in DB")
require.Equal(t, false, service.saveHotStateDB.enabled)
require.Equal(t, true, h.db.HasState(ctx, r))
}

View File

@@ -0,0 +1,27 @@
package stategen
import (
"github.com/prysmaticlabs/prysm/v3/beacon-chain/db/iface"
)
type testSaverOpt func(h *hotStateSaver)
func withFinalizedCheckpointer(fc *mockFinalizedCheckpointer) testSaverOpt {
return func(h *hotStateSaver) {
h.fc = fc
}
}
func newTestSaver(db iface.HeadAccessDatabase, opts ...testSaverOpt) *hotStateSaver {
h := &hotStateSaver{
snapshotInterval: DefaultSnapshotInterval,
db: db,
fc: &mockFinalizedCheckpointer{},
cs: &mockCurrentSlotter{},
}
for _, o := range opts {
o(h)
}
return h
}

View File

@@ -190,7 +190,7 @@ go_test(
"//beacon-chain/p2p/testing:go_default_library",
"//beacon-chain/p2p/types:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/stategen:go_default_library",
"//beacon-chain/state/stategen/mock:go_default_library",
"//beacon-chain/state/v1:go_default_library",
"//beacon-chain/sync/initial-sync/testing:go_default_library",
"//cache/lru:go_default_library",

View File

@@ -19,7 +19,7 @@ import (
"github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p/peers"
p2ptest "github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p/testing"
p2ptypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p/types"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
sgmock "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
"github.com/prysmaticlabs/prysm/v3/config/params"
"github.com/prysmaticlabs/prysm/v3/consensus-types/blocks"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
@@ -47,7 +47,7 @@ func TestRegularSyncBeaconBlockSubscriber_ProcessPendingBlocks1(t *testing.T) {
Epoch: 0,
},
},
stateGen: stategen.New(db),
stateGen: sgmock.NewMockStategen(db),
},
slotToPendingBlocks: gcache.New(time.Second, 2*time.Second),
seenPendingBlocks: make(map[[32]byte]bool),
@@ -119,7 +119,7 @@ func TestRegularSyncBeaconBlockSubscriber_OptimisticStatus(t *testing.T) {
Epoch: 0,
},
},
stateGen: stategen.New(db),
stateGen: sgmock.NewMockStategen(db),
},
slotToPendingBlocks: gcache.New(time.Second, 2*time.Second),
seenPendingBlocks: make(map[[32]byte]bool),
@@ -191,7 +191,7 @@ func TestRegularSyncBeaconBlockSubscriber_ExecutionEngineTimesOut(t *testing.T)
},
ReceiveBlockMockErr: execution.ErrHTTPTimeout,
},
stateGen: stategen.New(db),
stateGen: sgmock.NewMockStategen(db),
},
slotToPendingBlocks: gcache.New(time.Second, 2*time.Second),
seenPendingBlocks: make(map[[32]byte]bool),
@@ -318,7 +318,7 @@ func TestRegularSyncBeaconBlockSubscriber_DoNotReprocessBlock(t *testing.T) {
Epoch: 0,
},
},
stateGen: stategen.New(db),
stateGen: sgmock.NewMockStategen(db),
},
slotToPendingBlocks: gcache.New(time.Second, 2*time.Second),
seenPendingBlocks: make(map[[32]byte]bool),
@@ -383,7 +383,7 @@ func TestRegularSyncBeaconBlockSubscriber_ProcessPendingBlocks_2Chains(t *testin
Root: make([]byte, 32),
},
},
stateGen: stategen.New(db),
stateGen: sgmock.NewMockStategen(db),
},
slotToPendingBlocks: gcache.New(time.Second, 2*time.Second),
seenPendingBlocks: make(map[[32]byte]bool),
@@ -703,7 +703,7 @@ func TestService_ProcessPendingBlockOnCorrectSlot(t *testing.T) {
p2p: p1,
beaconDB: db,
chain: &mockChain,
stateGen: stategen.New(db),
stateGen: sgmock.NewMockStategen(db),
},
slotToPendingBlocks: gcache.New(time.Second, 2*time.Second),
seenPendingBlocks: make(map[[32]byte]bool),
@@ -781,7 +781,7 @@ func TestService_ProcessBadPendingBlocks(t *testing.T) {
p2p: p1,
beaconDB: db,
chain: &mockChain,
stateGen: stategen.New(db),
stateGen: sgmock.NewMockStategen(db),
},
slotToPendingBlocks: gcache.New(time.Second, 2*time.Second),
seenPendingBlocks: make(map[[32]byte]bool),

View File

@@ -19,7 +19,7 @@ import (
dbtest "github.com/prysmaticlabs/prysm/v3/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p"
p2ptest "github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p/testing"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
sgmock "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
mockSync "github.com/prysmaticlabs/prysm/v3/beacon-chain/sync/initial-sync/testing"
lruwrpr "github.com/prysmaticlabs/prysm/v3/cache/lru"
"github.com/prysmaticlabs/prysm/v3/config/params"
@@ -51,7 +51,7 @@ func FuzzValidateBeaconBlockPubSub_Phase0(f *testing.F) {
msg.Signature, err = signing.ComputeDomainAndSign(beaconState, 0, msg.Block, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerIdx])
require.NoError(f, err)
stateGen := stategen.New(db)
stateGen := sgmock.NewMockStategen(db)
chainService := &mock.ChainService{Genesis: time.Unix(time.Now().Unix()-int64(params.BeaconConfig().SecondsPerSlot), 0),
State: beaconState,
FinalizedCheckPoint: &ethpb.Checkpoint{
@@ -132,7 +132,7 @@ func FuzzValidateBeaconBlockPubSub_Altair(f *testing.F) {
msg.Signature, err = signing.ComputeDomainAndSign(beaconState, 0, msg.Block, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerIdx])
require.NoError(f, err)
stateGen := stategen.New(db)
stateGen := sgmock.NewMockStategen(db)
chainService := &mock.ChainService{Genesis: time.Unix(time.Now().Unix()-int64(params.BeaconConfig().SecondsPerSlot), 0),
State: beaconState,
FinalizedCheckPoint: &ethpb.Checkpoint{
@@ -213,7 +213,7 @@ func FuzzValidateBeaconBlockPubSub_Bellatrix(f *testing.F) {
msg.Signature, err = signing.ComputeDomainAndSign(beaconState, 0, msg.Block, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerIdx])
require.NoError(f, err)
stateGen := stategen.New(db)
stateGen := sgmock.NewMockStategen(db)
chainService := &mock.ChainService{Genesis: time.Unix(time.Now().Unix()-int64(params.BeaconConfig().SecondsPerSlot), 0),
State: beaconState,
FinalizedCheckPoint: &ethpb.Checkpoint{

View File

@@ -22,7 +22,7 @@ import (
"github.com/prysmaticlabs/prysm/v3/beacon-chain/operations/attestations"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p"
p2ptest "github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p/testing"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
sgmock "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
mockSync "github.com/prysmaticlabs/prysm/v3/beacon-chain/sync/initial-sync/testing"
lruwrpr "github.com/prysmaticlabs/prysm/v3/cache/lru"
"github.com/prysmaticlabs/prysm/v3/config/params"
@@ -64,7 +64,7 @@ func TestValidateBeaconBlockPubSub_InvalidSignature(t *testing.T) {
msg.Signature, err = signing.ComputeDomainAndSign(beaconState, 0, msg.Block, params.BeaconConfig().DomainBeaconProposer, privKeys[badPrivKeyIdx])
require.NoError(t, err)
stateGen := stategen.New(db)
stateGen := sgmock.NewMockStategen(db)
chainService := &mock.ChainService{Genesis: time.Unix(time.Now().Unix()-int64(params.BeaconConfig().SecondsPerSlot), 0),
FinalizedCheckPoint: &ethpb.Checkpoint{
Epoch: 0,
@@ -167,7 +167,7 @@ func TestValidateBeaconBlockPubSub_CanRecoverStateSummary(t *testing.T) {
msg.Signature, err = signing.ComputeDomainAndSign(beaconState, 0, msg.Block, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerIdx])
require.NoError(t, err)
stateGen := stategen.New(db)
stateGen := sgmock.NewMockStategen(db)
chainService := &mock.ChainService{Genesis: time.Unix(time.Now().Unix()-int64(params.BeaconConfig().SecondsPerSlot), 0),
State: beaconState,
FinalizedCheckPoint: &ethpb.Checkpoint{
@@ -231,7 +231,7 @@ func TestValidateBeaconBlockPubSub_IsInCache(t *testing.T) {
msg.Signature, err = signing.ComputeDomainAndSign(beaconState, 0, msg.Block, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerIdx])
require.NoError(t, err)
stateGen := stategen.New(db)
stateGen := sgmock.NewMockStategen(db)
chainService := &mock.ChainService{Genesis: time.Unix(time.Now().Unix()-int64(params.BeaconConfig().SecondsPerSlot), 0),
State: beaconState,
FinalizedCheckPoint: &ethpb.Checkpoint{
@@ -297,7 +297,7 @@ func TestValidateBeaconBlockPubSub_ValidProposerSignature(t *testing.T) {
msg.Signature, err = signing.ComputeDomainAndSign(beaconState, 0, msg.Block, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerIdx])
require.NoError(t, err)
stateGen := stategen.New(db)
stateGen := sgmock.NewMockStategen(db)
chainService := &mock.ChainService{Genesis: time.Unix(time.Now().Unix()-int64(params.BeaconConfig().SecondsPerSlot), 0),
State: beaconState,
FinalizedCheckPoint: &ethpb.Checkpoint{
@@ -365,7 +365,7 @@ func TestValidateBeaconBlockPubSub_WithLookahead(t *testing.T) {
msg.Signature, err = signing.ComputeDomainAndSign(beaconState, 0, msg.Block, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerIdx])
require.NoError(t, err)
stateGen := stategen.New(db)
stateGen := sgmock.NewMockStategen(db)
offset := int64(blkSlot.Mul(params.BeaconConfig().SecondsPerSlot))
chainService := &mock.ChainService{Genesis: time.Unix(time.Now().Unix()-offset, 0),
DB: db,
@@ -433,7 +433,7 @@ func TestValidateBeaconBlockPubSub_AdvanceEpochsForState(t *testing.T) {
msg.Signature, err = signing.ComputeDomainAndSign(beaconState, 0, msg.Block, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerIdx])
require.NoError(t, err)
stateGen := stategen.New(db)
stateGen := sgmock.NewMockStategen(db)
offset := int64(blkSlot.Mul(params.BeaconConfig().SecondsPerSlot))
chainService := &mock.ChainService{Genesis: time.Unix(time.Now().Unix()-offset, 0),
DB: db,
@@ -540,7 +540,7 @@ func TestValidateBeaconBlockPubSub_IgnoreAndQueueBlocksFromNearFuture(t *testing
msg.Signature, err = signing.ComputeDomainAndSign(beaconState, 0, msg.Block, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerIdx])
require.NoError(t, err)
stateGen := stategen.New(db)
stateGen := sgmock.NewMockStategen(db)
chainService := &mock.ChainService{Genesis: time.Now(),
FinalizedCheckPoint: &ethpb.Checkpoint{
Epoch: 0,
@@ -829,7 +829,7 @@ func TestValidateBeaconBlockPubSub_ParentNotFinalizedDescendant(t *testing.T) {
msg.Signature, err = signing.ComputeDomainAndSign(beaconState, 0, msg.Block, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerIdx])
require.NoError(t, err)
stateGen := stategen.New(db)
stateGen := sgmock.NewMockStategen(db)
chainService := &mock.ChainService{Genesis: time.Unix(time.Now().Unix()-int64(params.BeaconConfig().SecondsPerSlot), 0),
State: beaconState,
FinalizedCheckPoint: &ethpb.Checkpoint{
@@ -898,7 +898,7 @@ func TestValidateBeaconBlockPubSub_InvalidParentBlock(t *testing.T) {
currBlockRoot, err := msg.Block.HashTreeRoot()
require.NoError(t, err)
stateGen := stategen.New(db)
stateGen := sgmock.NewMockStategen(db)
chainService := &mock.ChainService{Genesis: time.Unix(time.Now().Unix()-int64(params.BeaconConfig().SecondsPerSlot), 0),
State: beaconState,
FinalizedCheckPoint: &ethpb.Checkpoint{
@@ -1006,7 +1006,7 @@ func TestValidateBeaconBlockPubSub_RejectBlocksFromBadParent(t *testing.T) {
genesisTime := time.Now()
stateGen := stategen.New(db)
stateGen := sgmock.NewMockStategen(db)
chainService := &mock.ChainService{
Genesis: time.Unix(genesisTime.Unix()-int64(slotsSinceGenesis.Mul(perSlot)), 0),
FinalizedCheckPoint: &ethpb.Checkpoint{
@@ -1108,7 +1108,7 @@ func TestValidateBeaconBlockPubSub_ValidExecutionPayload(t *testing.T) {
msg.Signature, err = signing.ComputeDomainAndSign(beaconState, 0, msg.Block, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerIdx])
require.NoError(t, err)
stateGen := stategen.New(db)
stateGen := sgmock.NewMockStategen(db)
chainService := &mock.ChainService{Genesis: time.Unix(presentTime-int64(params.BeaconConfig().SecondsPerSlot), 0),
DB: db,
FinalizedCheckPoint: &ethpb.Checkpoint{
@@ -1180,7 +1180,7 @@ func TestValidateBeaconBlockPubSub_InvalidPayloadTimestamp(t *testing.T) {
msg.Signature, err = signing.ComputeDomainAndSign(beaconState, 0, msg.Block, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerIdx])
require.NoError(t, err)
stateGen := stategen.New(db)
stateGen := sgmock.NewMockStategen(db)
chainService := &mock.ChainService{Genesis: time.Unix(presentTime-int64(params.BeaconConfig().SecondsPerSlot), 0),
DB: db,
FinalizedCheckPoint: &ethpb.Checkpoint{
@@ -1224,7 +1224,7 @@ func Test_validateBellatrixBeaconBlock(t *testing.T) {
db := dbtest.SetupDB(t)
p := p2ptest.NewTestP2P(t)
ctx := context.Background()
stateGen := stategen.New(db)
stateGen := sgmock.NewMockStategen(db)
presentTime := time.Now().Unix()
chainService := &mock.ChainService{Genesis: time.Unix(presentTime-int64(params.BeaconConfig().SecondsPerSlot), 0),
FinalizedCheckPoint: &ethpb.Checkpoint{
@@ -1255,7 +1255,7 @@ func Test_validateBellatrixBeaconBlockParentValidation(t *testing.T) {
db := dbtest.SetupDB(t)
p := p2ptest.NewTestP2P(t)
ctx := context.Background()
stateGen := stategen.New(db)
stateGen := sgmock.NewMockStategen(db)
beaconState, privKeys := util.DeterministicGenesisStateBellatrix(t, 100)
parentBlock := util.NewBeaconBlockBellatrix()
@@ -1311,7 +1311,7 @@ func Test_validateBeaconBlockProcessingWhenParentIsOptimistic(t *testing.T) {
db := dbtest.SetupDB(t)
p := p2ptest.NewTestP2P(t)
ctx := context.Background()
stateGen := stategen.New(db)
stateGen := sgmock.NewMockStategen(db)
beaconState, privKeys := util.DeterministicGenesisStateBellatrix(t, 100)
parentBlock := util.NewBeaconBlockBellatrix()

View File

@@ -19,7 +19,7 @@ import (
"github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p/encoder"
mockp2p "github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p/testing"
p2ptypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p/types"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
sgmock "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
mockSync "github.com/prysmaticlabs/prysm/v3/beacon-chain/sync/initial-sync/testing"
"github.com/prysmaticlabs/prysm/v3/config/params"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
@@ -64,7 +64,7 @@ func TestService_ValidateSyncCommitteeMessage(t *testing.T) {
WithOperationNotifier(chainService.OperationNotifier()),
),
setupSvc: func(s *Service, msg *ethpb.SyncCommitteeMessage, topic string) (*Service, string) {
s.cfg.stateGen = stategen.New(beaconDB)
s.cfg.stateGen = sgmock.NewMockStategen(beaconDB)
msg.BlockRoot = headRoot[:]
s.cfg.beaconDB = beaconDB
s.initCaches()
@@ -92,7 +92,7 @@ func TestService_ValidateSyncCommitteeMessage(t *testing.T) {
WithOperationNotifier(chainService.OperationNotifier()),
),
setupSvc: func(s *Service, msg *ethpb.SyncCommitteeMessage, topic string) (*Service, string) {
s.cfg.stateGen = stategen.New(beaconDB)
s.cfg.stateGen = sgmock.NewMockStategen(beaconDB)
msg.BlockRoot = headRoot[:]
s.cfg.beaconDB = beaconDB
s.initCaches()
@@ -120,7 +120,7 @@ func TestService_ValidateSyncCommitteeMessage(t *testing.T) {
WithOperationNotifier(chainService.OperationNotifier()),
),
setupSvc: func(s *Service, msg *ethpb.SyncCommitteeMessage, topic string) (*Service, string) {
s.cfg.stateGen = stategen.New(beaconDB)
s.cfg.stateGen = sgmock.NewMockStategen(beaconDB)
s.cfg.beaconDB = beaconDB
s.initCaches()
return s, topic
@@ -147,7 +147,7 @@ func TestService_ValidateSyncCommitteeMessage(t *testing.T) {
WithOperationNotifier(chainService.OperationNotifier()),
),
setupSvc: func(s *Service, msg *ethpb.SyncCommitteeMessage, topic string) (*Service, string) {
s.cfg.stateGen = stategen.New(beaconDB)
s.cfg.stateGen = sgmock.NewMockStategen(beaconDB)
s.cfg.beaconDB = beaconDB
s.initCaches()
@@ -176,7 +176,7 @@ func TestService_ValidateSyncCommitteeMessage(t *testing.T) {
WithOperationNotifier(chainService.OperationNotifier()),
),
setupSvc: func(s *Service, msg *ethpb.SyncCommitteeMessage, topic string) (*Service, string) {
s.cfg.stateGen = stategen.New(beaconDB)
s.cfg.stateGen = sgmock.NewMockStategen(beaconDB)
s.cfg.beaconDB = beaconDB
s.initCaches()
s.cfg.chain = &mockChain.ChainService{
@@ -210,7 +210,7 @@ func TestService_ValidateSyncCommitteeMessage(t *testing.T) {
WithOperationNotifier(chainService.OperationNotifier()),
),
setupSvc: func(s *Service, msg *ethpb.SyncCommitteeMessage, topic string) (*Service, string) {
s.cfg.stateGen = stategen.New(beaconDB)
s.cfg.stateGen = sgmock.NewMockStategen(beaconDB)
s.cfg.beaconDB = beaconDB
s.initCaches()
msg.BlockRoot = headRoot[:]
@@ -258,7 +258,7 @@ func TestService_ValidateSyncCommitteeMessage(t *testing.T) {
WithOperationNotifier(chainService.OperationNotifier()),
),
setupSvc: func(s *Service, msg *ethpb.SyncCommitteeMessage, topic string) (*Service, string) {
s.cfg.stateGen = stategen.New(beaconDB)
s.cfg.stateGen = sgmock.NewMockStategen(beaconDB)
s.cfg.beaconDB = beaconDB
s.initCaches()
msg.BlockRoot = headRoot[:]
@@ -305,7 +305,7 @@ func TestService_ValidateSyncCommitteeMessage(t *testing.T) {
WithOperationNotifier(chainService.OperationNotifier()),
),
setupSvc: func(s *Service, msg *ethpb.SyncCommitteeMessage, topic string) (*Service, string) {
s.cfg.stateGen = stategen.New(beaconDB)
s.cfg.stateGen = sgmock.NewMockStategen(beaconDB)
s.cfg.beaconDB = beaconDB
s.initCaches()
msg.BlockRoot = headRoot[:]
@@ -360,7 +360,7 @@ func TestService_ValidateSyncCommitteeMessage(t *testing.T) {
WithOperationNotifier(chainService.OperationNotifier()),
),
setupSvc: func(s *Service, msg *ethpb.SyncCommitteeMessage, topic string) (*Service, string) {
s.cfg.stateGen = stategen.New(beaconDB)
s.cfg.stateGen = sgmock.NewMockStategen(beaconDB)
s.cfg.beaconDB = beaconDB
s.initCaches()
msg.BlockRoot = headRoot[:]

View File

@@ -26,7 +26,7 @@ import (
mockp2p "github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p/testing"
p2ptypes "github.com/prysmaticlabs/prysm/v3/beacon-chain/p2p/types"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
sgmock "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
mockSync "github.com/prysmaticlabs/prysm/v3/beacon-chain/sync/initial-sync/testing"
"github.com/prysmaticlabs/prysm/v3/config/params"
"github.com/prysmaticlabs/prysm/v3/consensus-types/blocks"
@@ -74,7 +74,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) {
WithOperationNotifier(chainService.OperationNotifier()),
),
setupSvc: func(s *Service, msg *ethpb.SignedContributionAndProof) *Service {
s.cfg.stateGen = stategen.New(database)
s.cfg.stateGen = sgmock.NewMockStategen(database)
msg.Message.Contribution.BlockRoot = headRoot[:]
s.cfg.beaconDB = database
s.initCaches()
@@ -110,7 +110,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) {
WithOperationNotifier(chainService.OperationNotifier()),
),
setupSvc: func(s *Service, msg *ethpb.SignedContributionAndProof) *Service {
s.cfg.stateGen = stategen.New(database)
s.cfg.stateGen = sgmock.NewMockStategen(database)
msg.Message.Contribution.BlockRoot = headRoot[:]
s.cfg.beaconDB = database
s.initCaches()
@@ -146,7 +146,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) {
WithOperationNotifier(chainService.OperationNotifier()),
),
setupSvc: func(s *Service, msg *ethpb.SignedContributionAndProof) *Service {
s.cfg.stateGen = stategen.New(database)
s.cfg.stateGen = sgmock.NewMockStategen(database)
s.cfg.beaconDB = database
s.initCaches()
return s
@@ -181,7 +181,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) {
WithOperationNotifier(chainService.OperationNotifier()),
),
setupSvc: func(s *Service, msg *ethpb.SignedContributionAndProof) *Service {
s.cfg.stateGen = stategen.New(database)
s.cfg.stateGen = sgmock.NewMockStategen(database)
s.cfg.beaconDB = database
s.initCaches()
s.cfg.chain = &mockChain.ChainService{
@@ -224,7 +224,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) {
WithOperationNotifier(chainService.OperationNotifier()),
),
setupSvc: func(s *Service, msg *ethpb.SignedContributionAndProof) *Service {
s.cfg.stateGen = stategen.New(database)
s.cfg.stateGen = sgmock.NewMockStategen(database)
s.cfg.beaconDB = database
s.initCaches()
s.cfg.chain = &mockChain.ChainService{
@@ -267,7 +267,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) {
WithOperationNotifier(chainService.OperationNotifier()),
),
setupSvc: func(s *Service, msg *ethpb.SignedContributionAndProof) *Service {
s.cfg.stateGen = stategen.New(database)
s.cfg.stateGen = sgmock.NewMockStategen(database)
s.cfg.beaconDB = database
s.initCaches()
s.cfg.chain = &mockChain.ChainService{
@@ -311,7 +311,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) {
WithOperationNotifier(chainService.OperationNotifier()),
),
setupSvc: func(s *Service, msg *ethpb.SignedContributionAndProof) *Service {
s.cfg.stateGen = stategen.New(database)
s.cfg.stateGen = sgmock.NewMockStategen(database)
s.cfg.beaconDB = database
s.initCaches()
s.cfg.chain = &mockChain.ChainService{
@@ -373,7 +373,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) {
WithOperationNotifier(chainService.OperationNotifier()),
),
setupSvc: func(s *Service, msg *ethpb.SignedContributionAndProof) *Service {
s.cfg.stateGen = stategen.New(database)
s.cfg.stateGen = sgmock.NewMockStategen(database)
s.cfg.beaconDB = database
msg.Message.Contribution.BlockRoot = headRoot[:]
hState, err := database.State(context.Background(), headRoot)
@@ -438,7 +438,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) {
WithOperationNotifier(chainService.OperationNotifier()),
),
setupSvc: func(s *Service, msg *ethpb.SignedContributionAndProof) *Service {
s.cfg.stateGen = stategen.New(database)
s.cfg.stateGen = sgmock.NewMockStategen(database)
s.cfg.beaconDB = database
s.cfg.chain = chainService
msg.Message.Contribution.BlockRoot = headRoot[:]
@@ -518,7 +518,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) {
WithOperationNotifier(chainService.OperationNotifier()),
),
setupSvc: func(s *Service, msg *ethpb.SignedContributionAndProof) *Service {
s.cfg.stateGen = stategen.New(database)
s.cfg.stateGen = sgmock.NewMockStategen(database)
s.cfg.beaconDB = database
msg.Message.Contribution.BlockRoot = headRoot[:]
hState, err := database.State(context.Background(), headRoot)
@@ -600,7 +600,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) {
WithOperationNotifier(chainService.OperationNotifier()),
),
setupSvc: func(s *Service, msg *ethpb.SignedContributionAndProof) *Service {
s.cfg.stateGen = stategen.New(database)
s.cfg.stateGen = sgmock.NewMockStategen(database)
msg.Message.Contribution.BlockRoot = headRoot[:]
s.cfg.beaconDB = database
hState, err := database.State(context.Background(), headRoot)
@@ -684,7 +684,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) {
WithOperationNotifier(chainService.OperationNotifier()),
),
setupSvc: func(s *Service, msg *ethpb.SignedContributionAndProof) *Service {
s.cfg.stateGen = stategen.New(database)
s.cfg.stateGen = sgmock.NewMockStategen(database)
msg.Message.Contribution.BlockRoot = headRoot[:]
s.cfg.beaconDB = database
hState, err := database.State(context.Background(), headRoot)
@@ -780,7 +780,7 @@ func TestService_ValidateSyncContributionAndProof(t *testing.T) {
WithOperationNotifier(chainService.OperationNotifier()),
),
setupSvc: func(s *Service, msg *ethpb.SignedContributionAndProof) *Service {
s.cfg.stateGen = stategen.New(database)
s.cfg.stateGen = sgmock.NewMockStategen(database)
msg.Message.Contribution.BlockRoot = headRoot[:]
s.cfg.beaconDB = database
hState, err := database.State(context.Background(), headRoot)
@@ -927,7 +927,7 @@ func TestValidateSyncContributionAndProof(t *testing.T) {
WithOperationNotifier(chainService.OperationNotifier()),
)
go s.verifierRoutine()
s.cfg.stateGen = stategen.New(database)
s.cfg.stateGen = sgmock.NewMockStategen(database)
msg.Message.Contribution.BlockRoot = headRoot[:]
s.cfg.beaconDB = database
hState, err := database.State(context.Background(), headRoot)

View File

@@ -13,7 +13,6 @@ go_library(
deps = [
"//cmd/prysmctl/checkpoint:go_default_library",
"//cmd/prysmctl/p2p:go_default_library",
"//cmd/prysmctl/testnet:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@com_github_urfave_cli_v2//:go_default_library",
],

View File

@@ -5,7 +5,6 @@ import (
"github.com/prysmaticlabs/prysm/v3/cmd/prysmctl/checkpoint"
"github.com/prysmaticlabs/prysm/v3/cmd/prysmctl/p2p"
"github.com/prysmaticlabs/prysm/v3/cmd/prysmctl/testnet"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
@@ -24,6 +23,5 @@ func main() {
func init() {
prysmctlCommands = append(prysmctlCommands, checkpoint.Commands...)
prysmctlCommands = append(prysmctlCommands, testnet.Commands...)
prysmctlCommands = append(prysmctlCommands, p2p.Commands...)
}

View File

@@ -1,34 +0,0 @@
load("@prysm//tools/go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = [
"generate_genesis.go",
"testnet.go",
],
importpath = "github.com/prysmaticlabs/prysm/v3/cmd/prysmctl/testnet",
visibility = ["//visibility:public"],
deps = [
"//config/params:go_default_library",
"//io/file:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//runtime/interop:go_default_library",
"@com_github_ghodss_yaml//:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@com_github_prysmaticlabs_fastssz//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@com_github_urfave_cli_v2//:go_default_library",
],
)
go_test(
name = "go_default_test",
srcs = ["generate_genesis_test.go"],
embed = [":go_default_library"],
deps = [
"//crypto/bls:go_default_library",
"//runtime/interop:go_default_library",
"//testing/assert:go_default_library",
"//testing/require:go_default_library",
],
)

View File

@@ -1,265 +0,0 @@
package testnet
import (
"context"
"encoding/hex"
"encoding/json"
"fmt"
"io"
"os"
"strings"
"github.com/ghodss/yaml"
"github.com/pkg/errors"
fastssz "github.com/prysmaticlabs/fastssz"
"github.com/prysmaticlabs/prysm/v3/config/params"
"github.com/prysmaticlabs/prysm/v3/io/file"
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v3/runtime/interop"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
var (
generateGenesisStateFlags = struct {
DepositJsonFile string
ChainConfigFile string
ConfigName string
NumValidators uint64
GenesisTime uint64
OutputSSZ string
OutputJSON string
OutputYaml string
}{}
log = logrus.WithField("prefix", "genesis")
outputSSZFlag = &cli.StringFlag{
Name: "output-ssz",
Destination: &generateGenesisStateFlags.OutputSSZ,
Usage: "Output filename of the SSZ marshaling of the generated genesis state",
Value: "",
}
outputYamlFlag = &cli.StringFlag{
Name: "output-yaml",
Destination: &generateGenesisStateFlags.OutputYaml,
Usage: "Output filename of the YAML marshaling of the generated genesis state",
Value: "",
}
outputJsonFlag = &cli.StringFlag{
Name: "output-json",
Destination: &generateGenesisStateFlags.OutputJSON,
Usage: "Output filename of the JSON marshaling of the generated genesis state",
Value: "",
}
generateGenesisStateCmd = &cli.Command{
Name: "generate-genesis",
Usage: "Generate a beacon chain genesis state",
Action: cliActionGenerateGenesisState,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "chain-config-file",
Destination: &generateGenesisStateFlags.ChainConfigFile,
Usage: "The path to a YAML file with chain config values",
},
&cli.StringFlag{
Name: "deposit-json-file",
Destination: &generateGenesisStateFlags.DepositJsonFile,
Usage: "Path to deposit_data.json file generated by the staking-deposit-cli tool for optionally specifying validators in genesis state",
},
&cli.StringFlag{
Name: "config-name",
Usage: "Config kind to be used for generating the genesis state. Default: mainnet. Options include mainnet, interop, minimal, prater, ropsten, sepolia. --chain-config-file will override this flag.",
Destination: &generateGenesisStateFlags.ConfigName,
Value: params.MainnetName,
},
&cli.Uint64Flag{
Name: "num-validators",
Usage: "Number of validators to deterministically generate in the genesis state",
Destination: &generateGenesisStateFlags.NumValidators,
Required: true,
},
&cli.Uint64Flag{
Name: "genesis-time",
Destination: &generateGenesisStateFlags.GenesisTime,
Usage: "Unix timestamp seconds used as the genesis time in the genesis state. If unset, defaults to now()",
},
outputSSZFlag,
outputYamlFlag,
outputJsonFlag,
},
}
)
// Represents a json object of hex string and uint64 values for
// validators on Ethereum. This file can be generated using the official staking-deposit-cli.
type depositDataJSON struct {
PubKey string `json:"pubkey"`
Amount uint64 `json:"amount"`
WithdrawalCredentials string `json:"withdrawal_credentials"`
DepositDataRoot string `json:"deposit_data_root"`
Signature string `json:"signature"`
}
func cliActionGenerateGenesisState(cliCtx *cli.Context) error {
if generateGenesisStateFlags.GenesisTime == 0 {
log.Info("No genesis time specified, defaulting to now()")
}
outputJson := generateGenesisStateFlags.OutputJSON
outputYaml := generateGenesisStateFlags.OutputYaml
outputSSZ := generateGenesisStateFlags.OutputSSZ
noOutputFlag := outputSSZ == "" && outputJson == "" && outputYaml == ""
if noOutputFlag {
return fmt.Errorf(
"no %s, %s, %s flag(s) specified. At least one is required",
outputJsonFlag.Name,
outputYamlFlag.Name,
outputSSZFlag.Name,
)
}
if err := setGlobalParams(); err != nil {
return fmt.Errorf("could not set config params: %v", err)
}
genesisState, err := generateGenesis(cliCtx.Context)
if err != nil {
return fmt.Errorf("could not generate genesis state: %v", err)
}
if outputJson != "" {
if err := writeToOutputFile(outputJson, genesisState, json.Marshal); err != nil {
return err
}
}
if outputYaml != "" {
if err := writeToOutputFile(outputJson, genesisState, yaml.Marshal); err != nil {
return err
}
}
if outputSSZ != "" {
marshalFn := func(o interface{}) ([]byte, error) {
marshaler, ok := o.(fastssz.Marshaler)
if !ok {
return nil, errors.New("not a marshaler")
}
return marshaler.MarshalSSZ()
}
if err := writeToOutputFile(outputSSZ, genesisState, marshalFn); err != nil {
return err
}
}
log.Info("Command completed")
return nil
}
func setGlobalParams() error {
chainConfigFile := generateGenesisStateFlags.ChainConfigFile
if chainConfigFile != "" {
log.Infof("Specified a chain config file: %s", chainConfigFile)
return params.LoadChainConfigFile(chainConfigFile, nil)
}
cfg, err := params.ByName(generateGenesisStateFlags.ConfigName)
if err != nil {
return fmt.Errorf("unable to find config using name %s: %v", generateGenesisStateFlags.ConfigName, err)
}
return params.SetActive(cfg.Copy())
}
func generateGenesis(ctx context.Context) (*ethpb.BeaconState, error) {
genesisTime := generateGenesisStateFlags.GenesisTime
numValidators := generateGenesisStateFlags.NumValidators
depositJsonFile := generateGenesisStateFlags.DepositJsonFile
if depositJsonFile != "" {
expanded, err := file.ExpandPath(depositJsonFile)
if err != nil {
return nil, err
}
inputJSON, err := os.Open(expanded) // #nosec G304
if err != nil {
return nil, err
}
defer func() {
if err := inputJSON.Close(); err != nil {
log.WithError(err).Printf("Could not close file %s", depositJsonFile)
}
}()
log.Printf("Generating genesis state from input JSON deposit data %s", depositJsonFile)
return genesisStateFromJSONValidators(ctx, inputJSON, genesisTime)
}
if numValidators == 0 {
return nil, fmt.Errorf(
"expected --num-validators > 0 to have been provided",
)
}
// If no JSON input is specified, we create the state deterministically from interop keys.
genesisState, _, err := interop.GenerateGenesisState(ctx, genesisTime, numValidators)
if err != nil {
return nil, err
}
return genesisState, err
}
func genesisStateFromJSONValidators(ctx context.Context, r io.Reader, genesisTime uint64) (*ethpb.BeaconState, error) {
enc, err := io.ReadAll(r)
if err != nil {
return nil, err
}
var depositJSON []*depositDataJSON
if err := json.Unmarshal(enc, &depositJSON); err != nil {
return nil, err
}
depositDataList := make([]*ethpb.Deposit_Data, len(depositJSON))
depositDataRoots := make([][]byte, len(depositJSON))
for i, val := range depositJSON {
data, dataRootBytes, err := depositJSONToDepositData(val)
if err != nil {
return nil, err
}
depositDataList[i] = data
depositDataRoots[i] = dataRootBytes
}
beaconState, _, err := interop.GenerateGenesisStateFromDepositData(ctx, genesisTime, depositDataList, depositDataRoots)
if err != nil {
return nil, err
}
return beaconState, nil
}
func depositJSONToDepositData(input *depositDataJSON) (depositData *ethpb.Deposit_Data, dataRoot []byte, err error) {
pubKeyBytes, err := hex.DecodeString(strings.TrimPrefix(input.PubKey, "0x"))
if err != nil {
return
}
withdrawalbytes, err := hex.DecodeString(strings.TrimPrefix(input.WithdrawalCredentials, "0x"))
if err != nil {
return
}
signatureBytes, err := hex.DecodeString(strings.TrimPrefix(input.Signature, "0x"))
if err != nil {
return
}
dataRootBytes, err := hex.DecodeString(strings.TrimPrefix(input.DepositDataRoot, "0x"))
if err != nil {
return
}
depositData = &ethpb.Deposit_Data{
PublicKey: pubKeyBytes,
WithdrawalCredentials: withdrawalbytes,
Amount: input.Amount,
Signature: signatureBytes,
}
dataRoot = dataRootBytes
return
}
func writeToOutputFile(
fPath string,
data interface{},
marshalFn func(o interface{}) ([]byte, error),
) error {
encoded, err := marshalFn(data)
if err != nil {
return err
}
if err := file.WriteFile(fPath, encoded); err != nil {
return err
}
log.Printf("Done writing genesis state to %s", fPath)
return nil
}

View File

@@ -1,13 +0,0 @@
package testnet
import "github.com/urfave/cli/v2"
var Commands = []*cli.Command{
{
Name: "testnet",
Usage: "commands for dealing with Ethereum beacon chain testnets",
Subcommands: []*cli.Command{
generateGenesisStateCmd,
},
},
}

View File

@@ -21,10 +21,12 @@ package features
import (
"os"
"os/signal"
"sync"
"syscall"
"time"
"github.com/prysmaticlabs/gohashtree"
"github.com/prysmaticlabs/prysm/v3/cmd"
"github.com/prysmaticlabs/prysm/v3/config/params"
"github.com/sirupsen/logrus"
@@ -209,7 +211,22 @@ func ConfigureBeaconChain(ctx *cli.Context) error {
if ctx.Bool(disableVecHTR.Name) {
logEnabled(disableVecHTR)
} else {
applyVectorizedHTRConfig(cfg)
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, syscall.SIGILL)
defer signal.Stop(sigc)
buffer := make([][32]byte, 2)
err := gohashtree.Hash(buffer, buffer)
if err != nil {
log.Error("could not test if gohashtree is supported")
} else {
t := time.NewTimer(time.Millisecond * 100)
select {
case <-sigc:
log.Error("gohashtree is not supported in this CPU")
case <-t.C:
cfg.EnableVectorizedHTR = true
}
}
}
if ctx.Bool(disableForkChoiceDoublyLinkedTree.Name) {
logEnabled(disableForkChoiceDoublyLinkedTree)
@@ -299,28 +316,3 @@ func logDisabled(flag cli.DocGenerationFlag) {
}
log.WithField(name, flag.GetUsage()).Warn(disabledFeatureFlag)
}
func applyVectorizedHTRConfig(cfg *Flags) (appliedCfg *Flags) {
defer func() {
if x := recover(); x != nil {
log.Error("gohashtree is not supported in this CPU")
}
}()
appliedCfg = cfg
buffer := make([][32]byte, 2)
err := mockSIGILL(buffer, buffer)
if err != nil {
log.WithError(err).Error("could not test if gohashtree is supported")
return
}
appliedCfg.EnableVectorizedHTR = true
return
}
func mockSIGILL(_, _ [][32]byte) error {
p, err := os.FindProcess(os.Getpid())
if err != nil {
return err
}
return p.Signal(syscall.SIGILL)
}

View File

@@ -11,6 +11,7 @@ import (
reflect "reflect"
sync "sync"
github_com_prysmaticlabs_go_bitfield "github.com/prysmaticlabs/go-bitfield"
github_com_prysmaticlabs_prysm_v3_consensus_types_primitives "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
_ "github.com/prysmaticlabs/prysm/v3/proto/eth/ext"
_ "google.golang.org/genproto/googleapis/api/annotations"
@@ -279,6 +280,173 @@ func (x *HighestAttestation) GetHighestTargetEpoch() github_com_prysmaticlabs_pr
return github_com_prysmaticlabs_prysm_v3_consensus_types_primitives.Epoch(0)
}
type ProposalHistory struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// Deprecated: Do not use.
EpochBits github_com_prysmaticlabs_go_bitfield.Bitlist `protobuf:"bytes,1,opt,name=epoch_bits,json=epochBits,proto3" json:"epoch_bits,omitempty" cast-type:"github.com/prysmaticlabs/go-bitfield.Bitlist"`
// Deprecated: Do not use.
LatestEpochWritten github_com_prysmaticlabs_prysm_v3_consensus_types_primitives.Epoch `protobuf:"varint,2,opt,name=latest_epoch_written,json=latestEpochWritten,proto3" json:"latest_epoch_written,omitempty" cast-type:"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives.Epoch"`
}
func (x *ProposalHistory) Reset() {
*x = ProposalHistory{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_prysm_v1alpha1_slasher_proto_msgTypes[5]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ProposalHistory) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ProposalHistory) ProtoMessage() {}
func (x *ProposalHistory) ProtoReflect() protoreflect.Message {
mi := &file_proto_prysm_v1alpha1_slasher_proto_msgTypes[5]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use ProposalHistory.ProtoReflect.Descriptor instead.
func (*ProposalHistory) Descriptor() ([]byte, []int) {
return file_proto_prysm_v1alpha1_slasher_proto_rawDescGZIP(), []int{5}
}
// Deprecated: Do not use.
func (x *ProposalHistory) GetEpochBits() github_com_prysmaticlabs_go_bitfield.Bitlist {
if x != nil {
return x.EpochBits
}
return github_com_prysmaticlabs_go_bitfield.Bitlist(nil)
}
// Deprecated: Do not use.
func (x *ProposalHistory) GetLatestEpochWritten() github_com_prysmaticlabs_prysm_v3_consensus_types_primitives.Epoch {
if x != nil {
return x.LatestEpochWritten
}
return github_com_prysmaticlabs_prysm_v3_consensus_types_primitives.Epoch(0)
}
type Slashable struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// Deprecated: Do not use.
Slashable bool `protobuf:"varint,1,opt,name=slashable,proto3" json:"slashable,omitempty"`
}
func (x *Slashable) Reset() {
*x = Slashable{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_prysm_v1alpha1_slasher_proto_msgTypes[6]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *Slashable) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Slashable) ProtoMessage() {}
func (x *Slashable) ProtoReflect() protoreflect.Message {
mi := &file_proto_prysm_v1alpha1_slasher_proto_msgTypes[6]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Slashable.ProtoReflect.Descriptor instead.
func (*Slashable) Descriptor() ([]byte, []int) {
return file_proto_prysm_v1alpha1_slasher_proto_rawDescGZIP(), []int{6}
}
// Deprecated: Do not use.
func (x *Slashable) GetSlashable() bool {
if x != nil {
return x.Slashable
}
return false
}
type AttestationHistory struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// Deprecated: Do not use.
TargetToSource map[uint64]uint64 `protobuf:"bytes,1,rep,name=target_to_source,json=targetToSource,proto3" json:"target_to_source,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"`
// Deprecated: Do not use.
LatestEpochWritten github_com_prysmaticlabs_prysm_v3_consensus_types_primitives.Epoch `protobuf:"varint,2,opt,name=latest_epoch_written,json=latestEpochWritten,proto3" json:"latest_epoch_written,omitempty" cast-type:"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives.Epoch"`
}
func (x *AttestationHistory) Reset() {
*x = AttestationHistory{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_prysm_v1alpha1_slasher_proto_msgTypes[7]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *AttestationHistory) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*AttestationHistory) ProtoMessage() {}
func (x *AttestationHistory) ProtoReflect() protoreflect.Message {
mi := &file_proto_prysm_v1alpha1_slasher_proto_msgTypes[7]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use AttestationHistory.ProtoReflect.Descriptor instead.
func (*AttestationHistory) Descriptor() ([]byte, []int) {
return file_proto_prysm_v1alpha1_slasher_proto_rawDescGZIP(), []int{7}
}
// Deprecated: Do not use.
func (x *AttestationHistory) GetTargetToSource() map[uint64]uint64 {
if x != nil {
return x.TargetToSource
}
return nil
}
// Deprecated: Do not use.
func (x *AttestationHistory) GetLatestEpochWritten() github_com_prysmaticlabs_prysm_v3_consensus_types_primitives.Epoch {
if x != nil {
return x.LatestEpochWritten
}
return github_com_prysmaticlabs_prysm_v3_consensus_types_primitives.Epoch(0)
}
var File_proto_prysm_v1alpha1_slasher_proto protoreflect.FileDescriptor
var file_proto_prysm_v1alpha1_slasher_proto_rawDesc = []byte{
@@ -337,50 +505,87 @@ var file_proto_prysm_v1alpha1_slasher_proto_rawDesc = []byte{
0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2f, 0x70, 0x72,
0x69, 0x6d, 0x69, 0x74, 0x69, 0x76, 0x65, 0x73, 0x2e, 0x45, 0x70, 0x6f, 0x63, 0x68, 0x52, 0x12,
0x68, 0x69, 0x67, 0x68, 0x65, 0x73, 0x74, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x45, 0x70, 0x6f,
0x63, 0x68, 0x32, 0x90, 0x04, 0x0a, 0x07, 0x53, 0x6c, 0x61, 0x73, 0x68, 0x65, 0x72, 0x12, 0xad,
0x01, 0x0a, 0x16, 0x49, 0x73, 0x53, 0x6c, 0x61, 0x73, 0x68, 0x61, 0x62, 0x6c, 0x65, 0x41, 0x74,
0x74, 0x65, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x29, 0x2e, 0x65, 0x74, 0x68, 0x65,
0x72, 0x65, 0x75, 0x6d, 0x2e, 0x65, 0x74, 0x68, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61,
0x31, 0x2e, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x65, 0x64, 0x41, 0x74, 0x74, 0x65, 0x73, 0x74, 0x61,
0x74, 0x69, 0x6f, 0x6e, 0x1a, 0x2f, 0x2e, 0x65, 0x74, 0x68, 0x65, 0x72, 0x65, 0x75, 0x6d, 0x2e,
0x65, 0x74, 0x68, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x41, 0x74, 0x74,
0x65, 0x73, 0x74, 0x65, 0x72, 0x53, 0x6c, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73,
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x37, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x31, 0x22, 0x2c, 0x2f,
0x65, 0x74, 0x68, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2f, 0x73, 0x6c, 0x61,
0x73, 0x68, 0x65, 0x72, 0x2f, 0x61, 0x74, 0x74, 0x65, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e,
0x73, 0x2f, 0x73, 0x6c, 0x61, 0x73, 0x68, 0x61, 0x62, 0x6c, 0x65, 0x3a, 0x01, 0x2a, 0x12, 0xa3,
0x01, 0x0a, 0x10, 0x49, 0x73, 0x53, 0x6c, 0x61, 0x73, 0x68, 0x61, 0x62, 0x6c, 0x65, 0x42, 0x6c,
0x6f, 0x63, 0x6b, 0x12, 0x2e, 0x2e, 0x65, 0x74, 0x68, 0x65, 0x72, 0x65, 0x75, 0x6d, 0x2e, 0x65,
0x74, 0x68, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x53, 0x69, 0x67, 0x6e,
0x65, 0x64, 0x42, 0x65, 0x61, 0x63, 0x6f, 0x6e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x65, 0x61,
0x64, 0x65, 0x72, 0x1a, 0x2f, 0x2e, 0x65, 0x74, 0x68, 0x65, 0x72, 0x65, 0x75, 0x6d, 0x2e, 0x65,
0x74, 0x68, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x50, 0x72, 0x6f, 0x70,
0x6f, 0x73, 0x65, 0x72, 0x53, 0x6c, 0x61, 0x73, 0x68, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70,
0x6f, 0x6e, 0x73, 0x65, 0x22, 0x2e, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x28, 0x12, 0x26, 0x2f, 0x65,
0x74, 0x68, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2f, 0x73, 0x6c, 0x61, 0x73,
0x68, 0x65, 0x72, 0x2f, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x73, 0x2f, 0x73, 0x6c, 0x61, 0x73, 0x68,
0x61, 0x62, 0x6c, 0x65, 0x12, 0xae, 0x01, 0x0a, 0x13, 0x48, 0x69, 0x67, 0x68, 0x65, 0x73, 0x74,
0x41, 0x74, 0x74, 0x65, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x30, 0x2e, 0x65,
0x74, 0x68, 0x65, 0x72, 0x65, 0x75, 0x6d, 0x2e, 0x65, 0x74, 0x68, 0x2e, 0x76, 0x31, 0x61, 0x6c,
0x70, 0x68, 0x61, 0x31, 0x2e, 0x48, 0x69, 0x67, 0x68, 0x65, 0x73, 0x74, 0x41, 0x74, 0x74, 0x65,
0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x31,
0x63, 0x68, 0x22, 0xe0, 0x01, 0x0a, 0x0f, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x48,
0x69, 0x73, 0x74, 0x6f, 0x72, 0x79, 0x12, 0x51, 0x0a, 0x0a, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x5f,
0x62, 0x69, 0x74, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x32, 0x18, 0x01, 0x82, 0xb5,
0x18, 0x2c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x72, 0x79,
0x73, 0x6d, 0x61, 0x74, 0x69, 0x63, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x67, 0x6f, 0x2d, 0x62, 0x69,
0x74, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x2e, 0x42, 0x69, 0x74, 0x6c, 0x69, 0x73, 0x74, 0x52, 0x09,
0x65, 0x70, 0x6f, 0x63, 0x68, 0x42, 0x69, 0x74, 0x73, 0x12, 0x7a, 0x0a, 0x14, 0x6c, 0x61, 0x74,
0x65, 0x73, 0x74, 0x5f, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x5f, 0x77, 0x72, 0x69, 0x74, 0x74, 0x65,
0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x42, 0x48, 0x18, 0x01, 0x82, 0xb5, 0x18, 0x42, 0x67,
0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x72, 0x79, 0x73, 0x6d, 0x61,
0x74, 0x69, 0x63, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x70, 0x72, 0x79, 0x73, 0x6d, 0x2f, 0x76, 0x33,
0x2f, 0x63, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x73,
0x2f, 0x70, 0x72, 0x69, 0x6d, 0x69, 0x74, 0x69, 0x76, 0x65, 0x73, 0x2e, 0x45, 0x70, 0x6f, 0x63,
0x68, 0x52, 0x12, 0x6c, 0x61, 0x74, 0x65, 0x73, 0x74, 0x45, 0x70, 0x6f, 0x63, 0x68, 0x57, 0x72,
0x69, 0x74, 0x74, 0x65, 0x6e, 0x22, 0x2d, 0x0a, 0x09, 0x53, 0x6c, 0x61, 0x73, 0x68, 0x61, 0x62,
0x6c, 0x65, 0x12, 0x20, 0x0a, 0x09, 0x73, 0x6c, 0x61, 0x73, 0x68, 0x61, 0x62, 0x6c, 0x65, 0x18,
0x01, 0x20, 0x01, 0x28, 0x08, 0x42, 0x02, 0x18, 0x01, 0x52, 0x09, 0x73, 0x6c, 0x61, 0x73, 0x68,
0x61, 0x62, 0x6c, 0x65, 0x22, 0xc0, 0x02, 0x0a, 0x12, 0x41, 0x74, 0x74, 0x65, 0x73, 0x74, 0x61,
0x74, 0x69, 0x6f, 0x6e, 0x48, 0x69, 0x73, 0x74, 0x6f, 0x72, 0x79, 0x12, 0x6b, 0x0a, 0x10, 0x74,
0x61, 0x72, 0x67, 0x65, 0x74, 0x5f, 0x74, 0x6f, 0x5f, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x18,
0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x3d, 0x2e, 0x65, 0x74, 0x68, 0x65, 0x72, 0x65, 0x75, 0x6d,
0x2e, 0x65, 0x74, 0x68, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x41, 0x74,
0x74, 0x65, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x48, 0x69, 0x73, 0x74, 0x6f, 0x72, 0x79,
0x2e, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x54, 0x6f, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x45,
0x6e, 0x74, 0x72, 0x79, 0x42, 0x02, 0x18, 0x01, 0x52, 0x0e, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74,
0x54, 0x6f, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x12, 0x7a, 0x0a, 0x14, 0x6c, 0x61, 0x74, 0x65,
0x73, 0x74, 0x5f, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x5f, 0x77, 0x72, 0x69, 0x74, 0x74, 0x65, 0x6e,
0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x42, 0x48, 0x18, 0x01, 0x82, 0xb5, 0x18, 0x42, 0x67, 0x69,
0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x72, 0x79, 0x73, 0x6d, 0x61, 0x74,
0x69, 0x63, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x70, 0x72, 0x79, 0x73, 0x6d, 0x2f, 0x76, 0x33, 0x2f,
0x63, 0x6f, 0x6e, 0x73, 0x65, 0x6e, 0x73, 0x75, 0x73, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2f,
0x70, 0x72, 0x69, 0x6d, 0x69, 0x74, 0x69, 0x76, 0x65, 0x73, 0x2e, 0x45, 0x70, 0x6f, 0x63, 0x68,
0x52, 0x12, 0x6c, 0x61, 0x74, 0x65, 0x73, 0x74, 0x45, 0x70, 0x6f, 0x63, 0x68, 0x57, 0x72, 0x69,
0x74, 0x74, 0x65, 0x6e, 0x1a, 0x41, 0x0a, 0x13, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x54, 0x6f,
0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b,
0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a,
0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x76, 0x61,
0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x32, 0x90, 0x04, 0x0a, 0x07, 0x53, 0x6c, 0x61, 0x73,
0x68, 0x65, 0x72, 0x12, 0xad, 0x01, 0x0a, 0x16, 0x49, 0x73, 0x53, 0x6c, 0x61, 0x73, 0x68, 0x61,
0x62, 0x6c, 0x65, 0x41, 0x74, 0x74, 0x65, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x29,
0x2e, 0x65, 0x74, 0x68, 0x65, 0x72, 0x65, 0x75, 0x6d, 0x2e, 0x65, 0x74, 0x68, 0x2e, 0x76, 0x31,
0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x48, 0x69, 0x67, 0x68, 0x65, 0x73, 0x74, 0x41, 0x74,
0x74, 0x65, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x22, 0x32, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x2c, 0x12, 0x2a, 0x2f, 0x65, 0x74, 0x68, 0x2f,
0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2f, 0x73, 0x6c, 0x61, 0x73, 0x68, 0x65, 0x72,
0x2f, 0x61, 0x74, 0x74, 0x65, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x68, 0x69,
0x67, 0x68, 0x65, 0x73, 0x74, 0x42, 0x97, 0x01, 0x0a, 0x19, 0x6f, 0x72, 0x67, 0x2e, 0x65, 0x74,
0x68, 0x65, 0x72, 0x65, 0x75, 0x6d, 0x2e, 0x65, 0x74, 0x68, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70,
0x68, 0x61, 0x31, 0x42, 0x0c, 0x53, 0x6c, 0x61, 0x73, 0x68, 0x65, 0x72, 0x50, 0x72, 0x6f, 0x74,
0x6f, 0x50, 0x01, 0x5a, 0x3a, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f,
0x70, 0x72, 0x79, 0x73, 0x6d, 0x61, 0x74, 0x69, 0x63, 0x6c, 0x61, 0x62, 0x73, 0x2f, 0x70, 0x72,
0x79, 0x73, 0x6d, 0x2f, 0x76, 0x33, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, 0x72, 0x79,
0x73, 0x6d, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x3b, 0x65, 0x74, 0x68, 0xaa,
0x02, 0x15, 0x45, 0x74, 0x68, 0x65, 0x72, 0x65, 0x75, 0x6d, 0x2e, 0x45, 0x74, 0x68, 0x2e, 0x56,
0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0xca, 0x02, 0x15, 0x45, 0x74, 0x68, 0x65, 0x72, 0x65,
0x75, 0x6d, 0x5c, 0x45, 0x74, 0x68, 0x5c, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x62,
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x65, 0x64, 0x41, 0x74,
0x74, 0x65, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x1a, 0x2f, 0x2e, 0x65, 0x74, 0x68, 0x65,
0x72, 0x65, 0x75, 0x6d, 0x2e, 0x65, 0x74, 0x68, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61,
0x31, 0x2e, 0x41, 0x74, 0x74, 0x65, 0x73, 0x74, 0x65, 0x72, 0x53, 0x6c, 0x61, 0x73, 0x68, 0x69,
0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x37, 0x82, 0xd3, 0xe4, 0x93,
0x02, 0x31, 0x22, 0x2c, 0x2f, 0x65, 0x74, 0x68, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61,
0x31, 0x2f, 0x73, 0x6c, 0x61, 0x73, 0x68, 0x65, 0x72, 0x2f, 0x61, 0x74, 0x74, 0x65, 0x73, 0x74,
0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x73, 0x6c, 0x61, 0x73, 0x68, 0x61, 0x62, 0x6c, 0x65,
0x3a, 0x01, 0x2a, 0x12, 0xa3, 0x01, 0x0a, 0x10, 0x49, 0x73, 0x53, 0x6c, 0x61, 0x73, 0x68, 0x61,
0x62, 0x6c, 0x65, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x12, 0x2e, 0x2e, 0x65, 0x74, 0x68, 0x65, 0x72,
0x65, 0x75, 0x6d, 0x2e, 0x65, 0x74, 0x68, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31,
0x2e, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x42, 0x65, 0x61, 0x63, 0x6f, 0x6e, 0x42, 0x6c, 0x6f,
0x63, 0x6b, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x1a, 0x2f, 0x2e, 0x65, 0x74, 0x68, 0x65, 0x72,
0x65, 0x75, 0x6d, 0x2e, 0x65, 0x74, 0x68, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31,
0x2e, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x65, 0x72, 0x53, 0x6c, 0x61, 0x73, 0x68, 0x69, 0x6e,
0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x2e, 0x82, 0xd3, 0xe4, 0x93, 0x02,
0x28, 0x12, 0x26, 0x2f, 0x65, 0x74, 0x68, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31,
0x2f, 0x73, 0x6c, 0x61, 0x73, 0x68, 0x65, 0x72, 0x2f, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x73, 0x2f,
0x73, 0x6c, 0x61, 0x73, 0x68, 0x61, 0x62, 0x6c, 0x65, 0x12, 0xae, 0x01, 0x0a, 0x13, 0x48, 0x69,
0x67, 0x68, 0x65, 0x73, 0x74, 0x41, 0x74, 0x74, 0x65, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e,
0x73, 0x12, 0x30, 0x2e, 0x65, 0x74, 0x68, 0x65, 0x72, 0x65, 0x75, 0x6d, 0x2e, 0x65, 0x74, 0x68,
0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x48, 0x69, 0x67, 0x68, 0x65, 0x73,
0x74, 0x41, 0x74, 0x74, 0x65, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75,
0x65, 0x73, 0x74, 0x1a, 0x31, 0x2e, 0x65, 0x74, 0x68, 0x65, 0x72, 0x65, 0x75, 0x6d, 0x2e, 0x65,
0x74, 0x68, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x48, 0x69, 0x67, 0x68,
0x65, 0x73, 0x74, 0x41, 0x74, 0x74, 0x65, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65,
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x32, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x2c, 0x12, 0x2a,
0x2f, 0x65, 0x74, 0x68, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2f, 0x73, 0x6c,
0x61, 0x73, 0x68, 0x65, 0x72, 0x2f, 0x61, 0x74, 0x74, 0x65, 0x73, 0x74, 0x61, 0x74, 0x69, 0x6f,
0x6e, 0x73, 0x2f, 0x68, 0x69, 0x67, 0x68, 0x65, 0x73, 0x74, 0x42, 0x97, 0x01, 0x0a, 0x19, 0x6f,
0x72, 0x67, 0x2e, 0x65, 0x74, 0x68, 0x65, 0x72, 0x65, 0x75, 0x6d, 0x2e, 0x65, 0x74, 0x68, 0x2e,
0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x42, 0x0c, 0x53, 0x6c, 0x61, 0x73, 0x68, 0x65,
0x72, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3a, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62,
0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x72, 0x79, 0x73, 0x6d, 0x61, 0x74, 0x69, 0x63, 0x6c, 0x61,
0x62, 0x73, 0x2f, 0x70, 0x72, 0x79, 0x73, 0x6d, 0x2f, 0x76, 0x33, 0x2f, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x2f, 0x70, 0x72, 0x79, 0x73, 0x6d, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31,
0x3b, 0x65, 0x74, 0x68, 0xaa, 0x02, 0x15, 0x45, 0x74, 0x68, 0x65, 0x72, 0x65, 0x75, 0x6d, 0x2e,
0x45, 0x74, 0x68, 0x2e, 0x56, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0xca, 0x02, 0x15, 0x45,
0x74, 0x68, 0x65, 0x72, 0x65, 0x75, 0x6d, 0x5c, 0x45, 0x74, 0x68, 0x5c, 0x76, 0x31, 0x61, 0x6c,
0x70, 0x68, 0x61, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@@ -395,33 +600,38 @@ func file_proto_prysm_v1alpha1_slasher_proto_rawDescGZIP() []byte {
return file_proto_prysm_v1alpha1_slasher_proto_rawDescData
}
var file_proto_prysm_v1alpha1_slasher_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
var file_proto_prysm_v1alpha1_slasher_proto_msgTypes = make([]protoimpl.MessageInfo, 9)
var file_proto_prysm_v1alpha1_slasher_proto_goTypes = []interface{}{
(*AttesterSlashingResponse)(nil), // 0: ethereum.eth.v1alpha1.AttesterSlashingResponse
(*ProposerSlashingResponse)(nil), // 1: ethereum.eth.v1alpha1.ProposerSlashingResponse
(*HighestAttestationRequest)(nil), // 2: ethereum.eth.v1alpha1.HighestAttestationRequest
(*HighestAttestationResponse)(nil), // 3: ethereum.eth.v1alpha1.HighestAttestationResponse
(*HighestAttestation)(nil), // 4: ethereum.eth.v1alpha1.HighestAttestation
(*AttesterSlashing)(nil), // 5: ethereum.eth.v1alpha1.AttesterSlashing
(*ProposerSlashing)(nil), // 6: ethereum.eth.v1alpha1.ProposerSlashing
(*IndexedAttestation)(nil), // 7: ethereum.eth.v1alpha1.IndexedAttestation
(*SignedBeaconBlockHeader)(nil), // 8: ethereum.eth.v1alpha1.SignedBeaconBlockHeader
(*ProposalHistory)(nil), // 5: ethereum.eth.v1alpha1.ProposalHistory
(*Slashable)(nil), // 6: ethereum.eth.v1alpha1.Slashable
(*AttestationHistory)(nil), // 7: ethereum.eth.v1alpha1.AttestationHistory
nil, // 8: ethereum.eth.v1alpha1.AttestationHistory.TargetToSourceEntry
(*AttesterSlashing)(nil), // 9: ethereum.eth.v1alpha1.AttesterSlashing
(*ProposerSlashing)(nil), // 10: ethereum.eth.v1alpha1.ProposerSlashing
(*IndexedAttestation)(nil), // 11: ethereum.eth.v1alpha1.IndexedAttestation
(*SignedBeaconBlockHeader)(nil), // 12: ethereum.eth.v1alpha1.SignedBeaconBlockHeader
}
var file_proto_prysm_v1alpha1_slasher_proto_depIdxs = []int32{
5, // 0: ethereum.eth.v1alpha1.AttesterSlashingResponse.attester_slashings:type_name -> ethereum.eth.v1alpha1.AttesterSlashing
6, // 1: ethereum.eth.v1alpha1.ProposerSlashingResponse.proposer_slashings:type_name -> ethereum.eth.v1alpha1.ProposerSlashing
4, // 2: ethereum.eth.v1alpha1.HighestAttestationResponse.attestations:type_name -> ethereum.eth.v1alpha1.HighestAttestation
7, // 3: ethereum.eth.v1alpha1.Slasher.IsSlashableAttestation:input_type -> ethereum.eth.v1alpha1.IndexedAttestation
8, // 4: ethereum.eth.v1alpha1.Slasher.IsSlashableBlock:input_type -> ethereum.eth.v1alpha1.SignedBeaconBlockHeader
2, // 5: ethereum.eth.v1alpha1.Slasher.HighestAttestations:input_type -> ethereum.eth.v1alpha1.HighestAttestationRequest
0, // 6: ethereum.eth.v1alpha1.Slasher.IsSlashableAttestation:output_type -> ethereum.eth.v1alpha1.AttesterSlashingResponse
1, // 7: ethereum.eth.v1alpha1.Slasher.IsSlashableBlock:output_type -> ethereum.eth.v1alpha1.ProposerSlashingResponse
3, // 8: ethereum.eth.v1alpha1.Slasher.HighestAttestations:output_type -> ethereum.eth.v1alpha1.HighestAttestationResponse
6, // [6:9] is the sub-list for method output_type
3, // [3:6] is the sub-list for method input_type
3, // [3:3] is the sub-list for extension type_name
3, // [3:3] is the sub-list for extension extendee
0, // [0:3] is the sub-list for field type_name
9, // 0: ethereum.eth.v1alpha1.AttesterSlashingResponse.attester_slashings:type_name -> ethereum.eth.v1alpha1.AttesterSlashing
10, // 1: ethereum.eth.v1alpha1.ProposerSlashingResponse.proposer_slashings:type_name -> ethereum.eth.v1alpha1.ProposerSlashing
4, // 2: ethereum.eth.v1alpha1.HighestAttestationResponse.attestations:type_name -> ethereum.eth.v1alpha1.HighestAttestation
8, // 3: ethereum.eth.v1alpha1.AttestationHistory.target_to_source:type_name -> ethereum.eth.v1alpha1.AttestationHistory.TargetToSourceEntry
11, // 4: ethereum.eth.v1alpha1.Slasher.IsSlashableAttestation:input_type -> ethereum.eth.v1alpha1.IndexedAttestation
12, // 5: ethereum.eth.v1alpha1.Slasher.IsSlashableBlock:input_type -> ethereum.eth.v1alpha1.SignedBeaconBlockHeader
2, // 6: ethereum.eth.v1alpha1.Slasher.HighestAttestations:input_type -> ethereum.eth.v1alpha1.HighestAttestationRequest
0, // 7: ethereum.eth.v1alpha1.Slasher.IsSlashableAttestation:output_type -> ethereum.eth.v1alpha1.AttesterSlashingResponse
1, // 8: ethereum.eth.v1alpha1.Slasher.IsSlashableBlock:output_type -> ethereum.eth.v1alpha1.ProposerSlashingResponse
3, // 9: ethereum.eth.v1alpha1.Slasher.HighestAttestations:output_type -> ethereum.eth.v1alpha1.HighestAttestationResponse
7, // [7:10] is the sub-list for method output_type
4, // [4:7] is the sub-list for method input_type
4, // [4:4] is the sub-list for extension type_name
4, // [4:4] is the sub-list for extension extendee
0, // [0:4] is the sub-list for field type_name
}
func init() { file_proto_prysm_v1alpha1_slasher_proto_init() }
@@ -491,6 +701,42 @@ func file_proto_prysm_v1alpha1_slasher_proto_init() {
return nil
}
}
file_proto_prysm_v1alpha1_slasher_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ProposalHistory); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_proto_prysm_v1alpha1_slasher_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Slashable); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_proto_prysm_v1alpha1_slasher_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*AttestationHistory); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
@@ -498,7 +744,7 @@ func file_proto_prysm_v1alpha1_slasher_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_proto_prysm_v1alpha1_slasher_proto_rawDesc,
NumEnums: 0,
NumMessages: 5,
NumMessages: 9,
NumExtensions: 0,
NumServices: 1,
},

View File

@@ -82,3 +82,35 @@ message HighestAttestation {
[ (ethereum.eth.ext.cast_type) =
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives.Epoch" ];
}
// ProposalHistory defines the structure for recording a validator's historical
// proposals. Using a bitlist to represent the epochs and an uint64 to mark the
// latest marked epoch of the bitlist, we can easily store which epochs a
// validator has proposed a block for while pruning the older data.
message ProposalHistory {
bytes epoch_bits = 1 [
(ethereum.eth.ext.cast_type) =
"github.com/prysmaticlabs/go-bitfield.Bitlist",
deprecated = true
];
uint64 latest_epoch_written = 2 [
(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives.Epoch",
deprecated = true
];
}
message Slashable { bool slashable = 1 [ deprecated = true ]; }
// AttestationHistory defines the structure for recording a validator's
// historical attestation. Using a map[uint64]uint64 to map its target epoch to
// its source epoch, in order to detect if a vote being created is not a double
// vote and surrounded by, or surrounding any other votes. Using an uint64 to
// mark the latest written epoch, we can safely perform a rolling prune whenever
// the history is updated.
message AttestationHistory {
map<uint64, uint64> target_to_source = 1 [ deprecated = true ];
uint64 latest_epoch_written = 2 [
(ethereum.eth.ext.cast_type) = "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives.Epoch",
deprecated = true
];
}

View File

@@ -22,7 +22,7 @@ go_library(
"//beacon-chain/forkchoice/protoarray:go_default_library",
"//beacon-chain/operations/attestations:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/stategen:go_default_library",
"//beacon-chain/state/stategen/mock:go_default_library",
"//beacon-chain/state/v1:go_default_library",
"//beacon-chain/state/v2:go_default_library",
"//beacon-chain/state/v3:go_default_library",

View File

@@ -17,7 +17,7 @@ import (
"github.com/prysmaticlabs/prysm/v3/beacon-chain/forkchoice/protoarray"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/operations/attestations"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
sgmock "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen/mock"
"github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces"
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
pb "github.com/prysmaticlabs/prysm/v3/proto/engine/v1"
@@ -54,7 +54,7 @@ func startChainService(t testing.TB, st state.BeaconState, block interfaces.Sign
blockchain.WithDatabase(db),
blockchain.WithAttestationService(attPool),
blockchain.WithForkChoiceStore(protoarray.New()),
blockchain.WithStateGen(stategen.New(db)),
blockchain.WithStateGen(sgmock.NewMockStategen(db)),
blockchain.WithStateNotifier(&mock.MockStateNotifier{}),
blockchain.WithAttestationPool(attestations.NewPool()),
blockchain.WithDepositCache(depositCache),

View File

@@ -0,0 +1,65 @@
load("@prysm//tools/go:def.bzl", "go_library", "go_test")
load("@io_bazel_rules_go//go:def.bzl", "go_binary")
load("@io_bazel_rules_docker//go:image.bzl", "go_image")
load("@io_bazel_rules_docker//container:container.bzl", "container_bundle")
load("@io_bazel_rules_docker//contrib:push-all.bzl", "docker_push")
go_library(
name = "go_default_library",
srcs = ["main.go"],
importpath = "github.com/prysmaticlabs/prysm/v3/tools/genesis-state-gen",
visibility = ["//visibility:private"],
deps = [
"//config/params:go_default_library",
"//io/file:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//runtime/interop:go_default_library",
"@com_github_ghodss_yaml//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
],
)
go_binary(
name = "genesis-state-gen",
embed = [":go_default_library"],
visibility = ["//visibility:public"],
)
go_image(
name = "image",
base = select({
"//tools:base_image_alpine": "//tools:alpine_cc_image",
"//tools:base_image_cc": "//tools:cc_image",
"//conditions:default": "//tools:cc_image",
}),
binary = ":genesis-state-gen",
tags = ["manual"],
visibility = ["//visibility:private"],
)
container_bundle(
name = "image_bundle",
images = {
"gcr.io/prysmaticlabs/prysm/genesis-state-gen:latest": ":image",
"gcr.io/prysmaticlabs/prysm/genesis-state-gen:{DOCKER_TAG}": ":image",
},
tags = ["manual"],
)
docker_push(
name = "push_images",
bundle = ":image_bundle",
tags = ["manual"],
)
go_test(
name = "go_default_test",
srcs = ["main_test.go"],
embed = [":go_default_library"],
deps = [
"//crypto/bls:go_default_library",
"//runtime/interop:go_default_library",
"//testing/assert:go_default_library",
"//testing/require:go_default_library",
],
)

View File

@@ -0,0 +1,201 @@
package main
import (
"context"
"encoding/hex"
"encoding/json"
"flag"
"io"
"os"
"strings"
"github.com/ghodss/yaml"
"github.com/prysmaticlabs/prysm/v3/config/params"
"github.com/prysmaticlabs/prysm/v3/io/file"
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v3/runtime/interop"
log "github.com/sirupsen/logrus"
)
// DepositDataJSON representing a json object of hex string and uint64 values for
// validators on Ethereum. This file can be generated using the official eth2.0-deposit-cli.
type DepositDataJSON struct {
PubKey string `json:"pubkey"`
Amount uint64 `json:"amount"`
WithdrawalCredentials string `json:"withdrawal_credentials"`
DepositDataRoot string `json:"deposit_data_root"`
Signature string `json:"signature"`
}
var (
depositJSONFile = flag.String(
"deposit-json-file",
"",
"Path to deposit_data.json file generated by the eth2.0-deposit-cli tool",
)
numValidators = flag.Int("num-validators", 0, "Number of validators to deterministically generate in the generated genesis state")
useMainnetConfig = flag.Bool("mainnet-config", false, "Select whether genesis state should be generated with mainnet or minimal (default) params")
genesisTime = flag.Uint64("genesis-time", 0, "Unix timestamp used as the genesis time in the generated genesis state (defaults to now)")
sszOutputFile = flag.String("output-ssz", "", "Output filename of the SSZ marshaling of the generated genesis state")
yamlOutputFile = flag.String("output-yaml", "", "Output filename of the YAML marshaling of the generated genesis state")
jsonOutputFile = flag.String("output-json", "", "Output filename of the JSON marshaling of the generated genesis state")
configName = flag.String("config-name", params.MinimalName, "ConfigName for the BeaconChainConfig that will be used for interop, inc GenesisForkVersion of generated genesis state")
configFile = flag.String("chain-config-file", "", "Path to a chain config file for setting global params")
)
func main() {
flag.Parse()
if *genesisTime == 0 {
log.Print("No --genesis-time specified, defaulting to now")
}
if *sszOutputFile == "" && *yamlOutputFile == "" && *jsonOutputFile == "" {
log.Println("Expected --output-ssz, --output-yaml, or --output-json to have been provided, received nil")
return
}
if *useMainnetConfig {
if err := params.SetActive(params.MainnetConfig().Copy()); err != nil {
log.Fatalf("unable to set mainnet config active, err=%s", err.Error())
}
} else {
if *configFile != "" {
if err := params.LoadChainConfigFile(*configFile, nil); err != nil {
log.Fatal(err)
}
} else {
cfg, err := params.ByName(*configName)
if err != nil {
log.Fatalf("unable to find config using name %s, err=%s", *configName, err.Error())
}
if err := params.SetActive(cfg.Copy()); err != nil {
log.Fatalf("unable to set %s config active, err=%s", cfg.ConfigName, err.Error())
}
}
}
var genesisState *ethpb.BeaconState
var err error
if *depositJSONFile != "" {
inputFile := *depositJSONFile
expanded, err := file.ExpandPath(inputFile)
if err != nil {
log.WithError(err).Printf("Could not expand file path %s", inputFile)
return
}
inputJSON, err := os.Open(expanded) // #nosec G304
if err != nil {
log.WithError(err).Print("Could not open JSON file for reading")
return
}
defer func() {
if err := inputJSON.Close(); err != nil {
log.WithError(err).Printf("Could not close file %s", inputFile)
}
}()
log.Printf("Generating genesis state from input JSON deposit data %s", inputFile)
genesisState, err = genesisStateFromJSONValidators(inputJSON, *genesisTime)
if err != nil {
log.WithError(err).Print("Could not generate genesis beacon state")
return
}
} else {
if *numValidators == 0 {
log.Println("Expected --num-validators to have been provided, received 0")
return
}
// If no JSON input is specified, we create the state deterministically from interop keys.
genesisState, _, err = interop.GenerateGenesisState(context.Background(), *genesisTime, uint64(*numValidators))
if err != nil {
log.WithError(err).Print("Could not generate genesis beacon state")
return
}
}
if *sszOutputFile != "" {
encodedState, err := genesisState.MarshalSSZ()
if err != nil {
log.WithError(err).Print("Could not ssz marshal the genesis beacon state")
return
}
if err := file.WriteFile(*sszOutputFile, encodedState); err != nil {
log.WithError(err).Print("Could not write encoded genesis beacon state to file")
return
}
log.Printf("Done writing to %s", *sszOutputFile)
}
if *yamlOutputFile != "" {
encodedState, err := yaml.Marshal(genesisState)
if err != nil {
log.WithError(err).Print("Could not yaml marshal the genesis beacon state")
return
}
if err := file.WriteFile(*yamlOutputFile, encodedState); err != nil {
log.WithError(err).Print("Could not write encoded genesis beacon state to file")
return
}
log.Printf("Done writing to %s", *yamlOutputFile)
}
if *jsonOutputFile != "" {
encodedState, err := json.Marshal(genesisState)
if err != nil {
log.WithError(err).Print("Could not json marshal the genesis beacon state")
return
}
if err := file.WriteFile(*jsonOutputFile, encodedState); err != nil {
log.WithError(err).Print("Could not write encoded genesis beacon state to file")
return
}
log.Printf("Done writing to %s", *jsonOutputFile)
}
}
func genesisStateFromJSONValidators(r io.Reader, genesisTime uint64) (*ethpb.BeaconState, error) {
enc, err := io.ReadAll(r)
if err != nil {
return nil, err
}
var depositJSON []*DepositDataJSON
if err := json.Unmarshal(enc, &depositJSON); err != nil {
return nil, err
}
depositDataList := make([]*ethpb.Deposit_Data, len(depositJSON))
depositDataRoots := make([][]byte, len(depositJSON))
for i, val := range depositJSON {
data, dataRootBytes, err := depositJSONToDepositData(val)
if err != nil {
return nil, err
}
depositDataList[i] = data
depositDataRoots[i] = dataRootBytes
}
beaconState, _, err := interop.GenerateGenesisStateFromDepositData(context.Background(), genesisTime, depositDataList, depositDataRoots)
if err != nil {
return nil, err
}
return beaconState, nil
}
func depositJSONToDepositData(input *DepositDataJSON) (depositData *ethpb.Deposit_Data, dataRoot []byte, err error) {
pubKeyBytes, err := hex.DecodeString(strings.TrimPrefix(input.PubKey, "0x"))
if err != nil {
return
}
withdrawalbytes, err := hex.DecodeString(strings.TrimPrefix(input.WithdrawalCredentials, "0x"))
if err != nil {
return
}
signatureBytes, err := hex.DecodeString(strings.TrimPrefix(input.Signature, "0x"))
if err != nil {
return
}
dataRootBytes, err := hex.DecodeString(strings.TrimPrefix(input.DepositDataRoot, "0x"))
if err != nil {
return
}
depositData = &ethpb.Deposit_Data{
PublicKey: pubKeyBytes,
WithdrawalCredentials: withdrawalbytes,
Amount: input.Amount,
Signature: signatureBytes,
}
dataRoot = dataRootBytes
return
}

View File

@@ -1,8 +1,7 @@
package testnet
package main
import (
"bytes"
"context"
"encoding/json"
"fmt"
"testing"
@@ -18,9 +17,8 @@ func Test_genesisStateFromJSONValidators(t *testing.T) {
jsonData := createGenesisDepositData(t, numKeys)
jsonInput, err := json.Marshal(jsonData)
require.NoError(t, err)
ctx := context.Background()
genesisState, err := genesisStateFromJSONValidators(
ctx, bytes.NewReader(jsonInput), 0, /* genesis time defaults to time.Now() */
bytes.NewReader(jsonInput), 0, /* genesis time defaults to time.Now() */
)
require.NoError(t, err)
for i, val := range genesisState.Validators {
@@ -28,7 +26,7 @@ func Test_genesisStateFromJSONValidators(t *testing.T) {
}
}
func createGenesisDepositData(t *testing.T, numKeys int) []*depositDataJSON {
func createGenesisDepositData(t *testing.T, numKeys int) []*DepositDataJSON {
pubKeys := make([]bls.PublicKey, numKeys)
privKeys := make([]bls.SecretKey, numKeys)
for i := 0; i < numKeys; i++ {
@@ -39,11 +37,11 @@ func createGenesisDepositData(t *testing.T, numKeys int) []*depositDataJSON {
}
dataList, _, err := interop.DepositDataFromKeys(privKeys, pubKeys)
require.NoError(t, err)
jsonData := make([]*depositDataJSON, numKeys)
jsonData := make([]*DepositDataJSON, numKeys)
for i := 0; i < numKeys; i++ {
dataRoot, err := dataList[i].HashTreeRoot()
require.NoError(t, err)
jsonData[i] = &depositDataJSON{
jsonData[i] = &DepositDataJSON{
PubKey: fmt.Sprintf("%#x", dataList[i].PublicKey),
Amount: dataList[i].Amount,
WithdrawalCredentials: fmt.Sprintf("%#x", dataList[i].WithdrawalCredentials),

View File

@@ -88,6 +88,17 @@ var (
"pubkey",
},
)
// ValidatorInclusionDistancesGaugeVec used to keep track of validator inclusion distances by public key.
ValidatorInclusionDistancesGaugeVec = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "validator",
Name: "inclusion_distance",
Help: "Inclusion distance of last attestation. Deprecated after Altair hard fork.",
},
[]string{
"pubkey",
},
)
// ValidatorAttestedSlotsGaugeVec used to keep track of validator attested slots by public key.
ValidatorAttestedSlotsGaugeVec = promauto.NewGaugeVec(
prometheus.GaugeOpts{
@@ -321,6 +332,19 @@ func (v *validator) logForEachValidator(index int, pubKey []byte, resp *ethpb.Va
"percentChangeSinceStart": fmt.Sprintf("%.5f%%", percentSinceStart*100),
}
// These fields are deprecated after Altair.
if slots.ToEpoch(slot) < params.BeaconConfig().AltairForkEpoch {
if index < len(resp.InclusionSlots) {
previousEpochSummaryFields["inclusionSlot"] = resp.InclusionSlots[index]
} else {
log.WithField("pubKey", truncatedKey).Warn("Missing inclusion slot")
}
if index < len(resp.InclusionDistances) {
previousEpochSummaryFields["inclusionDistance"] = resp.InclusionDistances[index]
} else {
log.WithField("pubKey", truncatedKey).Warn("Missing inclusion distance")
}
}
if slots.ToEpoch(slot) >= params.BeaconConfig().AltairForkEpoch {
if index < len(resp.InactivityScores) {
previousEpochSummaryFields["inactivityScore"] = resp.InactivityScores[index]
@@ -349,7 +373,13 @@ func (v *validator) logForEachValidator(index int, pubKey []byte, resp *ethpb.Va
}
// Phase0 specific metrics
if slots.ToEpoch(slot) >= params.BeaconConfig().AltairForkEpoch {
if slots.ToEpoch(slot) < params.BeaconConfig().AltairForkEpoch {
if index < len(resp.InclusionDistances) {
ValidatorInclusionDistancesGaugeVec.WithLabelValues(fmtKey).Set(float64(resp.InclusionDistances[index]))
}
} else { // Altair specific metrics.
// Reset phase0 fields that no longer apply
ValidatorInclusionDistancesGaugeVec.DeleteLabelValues(fmtKey)
if index < len(resp.InactivityScores) {
ValidatorInactivityScoreGaugeVec.WithLabelValues(fmtKey).Set(float64(resp.InactivityScores[index]))
}
@@ -366,6 +396,12 @@ func (v *validator) UpdateLogAggregateStats(resp *ethpb.ValidatorPerformanceResp
var attested, correctSource, correctTarget, correctHead, inactivityScore int
for i := range resp.PublicKeys {
if slots.ToEpoch(slot) < params.BeaconConfig().AltairForkEpoch && i < len(resp.InclusionDistances) {
if uint64(resp.InclusionSlots[i]) != ^uint64(0) {
summary.totalDistance += resp.InclusionDistances[i]
}
}
included := false
if i < len(resp.CorrectlyVotedSource) && resp.CorrectlyVotedSource[i] {
included = true

View File

@@ -40,6 +40,8 @@ func TestUpdateLogAggregateStats(t *testing.T) {
bytesutil.FromBytes48(pubKeyBytes[1]),
bytesutil.FromBytes48(pubKeyBytes[2]),
},
InclusionSlots: []types.Slot{types.Slot(^uint64(0)), 10, 11}, // exact slot doesn't matter, only if it is == or != ^uint64(0)
InclusionDistances: []types.Slot{0, 5, 2},
CorrectlyVotedHead: []bool{false, true, false},
CorrectlyVotedSource: []bool{false, true, true},
CorrectlyVotedTarget: []bool{false, true, true},
@@ -50,6 +52,8 @@ func TestUpdateLogAggregateStats(t *testing.T) {
bytesutil.FromBytes48(pubKeyBytes[1]),
bytesutil.FromBytes48(pubKeyBytes[2]),
},
InclusionSlots: []types.Slot{33, 34, 35},
InclusionDistances: []types.Slot{1, 2, 3},
CorrectlyVotedHead: []bool{true, true, true},
CorrectlyVotedSource: []bool{true, true, true},
CorrectlyVotedTarget: []bool{true, true, true},
@@ -60,6 +64,8 @@ func TestUpdateLogAggregateStats(t *testing.T) {
bytesutil.FromBytes48(pubKeyBytes[1]),
bytesutil.FromBytes48(pubKeyBytes[2]),
},
InclusionSlots: []types.Slot{65, types.Slot(^uint64(0)), 67},
InclusionDistances: []types.Slot{1, 0, 2},
CorrectlyVotedHead: []bool{true, false, true},
CorrectlyVotedSource: []bool{true, false, true},
CorrectlyVotedTarget: []bool{false, false, true},
@@ -82,7 +88,7 @@ func TestUpdateLogAggregateStats(t *testing.T) {
require.LogsContain(t, hook, "msg=\"Previous epoch aggregated voting summary\" attestationInclusionPct=\"67%\" "+
"correctlyVotedHeadPct=\"100%\" correctlyVotedSourcePct=\"100%\" correctlyVotedTargetPct=\"50%\" epoch=2")
require.LogsContain(t, hook, "msg=\"Vote summary since launch\" attestationsInclusionPct=\"78%\" "+
"averageInclusionDistance=\"0.00 slots\" correctlyVotedHeadPct=\"86%\" correctlyVotedSourcePct=\"100%\" "+
"averageInclusionDistance=\"2.29 slots\" correctlyVotedHeadPct=\"86%\" correctlyVotedSourcePct=\"100%\" "+
"correctlyVotedTargetPct=\"86%\" numberOfEpochs=3 pctChangeCombinedBalance=\"0.20555%\"")
}