State: move state interfaces into state package (#9268)

* Move interfaces from github.com/prysmaticlabs/prysm/beacon-chain/state/interface to github.com/prysmaticlabs/prysm/beacon-chain/state

* remove/rename state2
This commit is contained in:
Preston Van Loon
2021-07-23 11:11:21 -05:00
committed by GitHub
parent a8363405f8
commit c0076cc7a2
173 changed files with 754 additions and 754 deletions

View File

@@ -40,7 +40,7 @@ go_library(
"//beacon-chain/operations/voluntaryexits:go_default_library",
"//beacon-chain/p2p:go_default_library",
"//beacon-chain/powchain:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/stategen:go_default_library",
"//cmd/beacon-chain/flags:go_default_library",
"//proto/eth/v1:go_default_library",

View File

@@ -7,7 +7,7 @@ import (
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/proto/interfaces"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
statepb "github.com/prysmaticlabs/prysm/proto/prysm/v2/state"
@@ -44,7 +44,7 @@ type HeadFetcher interface {
HeadSlot() types.Slot
HeadRoot(ctx context.Context) ([]byte, error)
HeadBlock(ctx context.Context) (interfaces.SignedBeaconBlock, error)
HeadState(ctx context.Context) (iface.BeaconState, error)
HeadState(ctx context.Context) (state.BeaconState, error)
HeadValidatorsIndices(ctx context.Context, epoch types.Epoch) ([]types.ValidatorIndex, error)
HeadSeed(ctx context.Context, epoch types.Epoch) ([32]byte, error)
HeadGenesisValidatorRoot() [32]byte
@@ -154,7 +154,7 @@ func (s *Service) HeadBlock(ctx context.Context) (interfaces.SignedBeaconBlock,
// HeadState returns the head state of the chain.
// If the head is nil from service struct,
// it will attempt to get the head state from DB.
func (s *Service) HeadState(ctx context.Context) (iface.BeaconState, error) {
func (s *Service) HeadState(ctx context.Context) (state.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "blockChain.HeadState")
defer span.End()
s.headLock.RLock()

View File

@@ -11,7 +11,7 @@ import (
statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpbv1 "github.com/prysmaticlabs/prysm/proto/eth/v1"
"github.com/prysmaticlabs/prysm/proto/interfaces"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
@@ -26,7 +26,7 @@ type head struct {
slot types.Slot // current head slot.
root [32]byte // current head root.
block interfaces.SignedBeaconBlock // current head block.
state iface.BeaconState // current head state.
state state.BeaconState // current head state.
}
// Determined the head from the fork choice service and saves its new data
@@ -168,7 +168,7 @@ func (s *Service) saveHead(ctx context.Context, headRoot [32]byte) error {
// This gets called to update canonical root mapping. It does not save head block
// root in DB. With the inception of initial-sync-cache-state flag, it uses finalized
// check point as anchors to resume sync therefore head is no longer needed to be saved on per slot basis.
func (s *Service) saveHeadNoDB(ctx context.Context, b interfaces.SignedBeaconBlock, r [32]byte, hs iface.BeaconState) error {
func (s *Service) saveHeadNoDB(ctx context.Context, b interfaces.SignedBeaconBlock, r [32]byte, hs state.BeaconState) error {
if err := helpers.VerifyNilBeaconBlock(b); err != nil {
return err
}
@@ -185,7 +185,7 @@ func (s *Service) saveHeadNoDB(ctx context.Context, b interfaces.SignedBeaconBlo
}
// This sets head view object which is used to track the head slot, root, block and state.
func (s *Service) setHead(root [32]byte, block interfaces.SignedBeaconBlock, state iface.BeaconState) {
func (s *Service) setHead(root [32]byte, block interfaces.SignedBeaconBlock, state state.BeaconState) {
s.headLock.Lock()
defer s.headLock.Unlock()
@@ -201,7 +201,7 @@ func (s *Service) setHead(root [32]byte, block interfaces.SignedBeaconBlock, sta
// This sets head view object which is used to track the head slot, root, block and state. The method
// assumes that state being passed into the method will not be modified by any other alternate
// caller which holds the state's reference.
func (s *Service) setHeadInitialSync(root [32]byte, block interfaces.SignedBeaconBlock, state iface.BeaconState) {
func (s *Service) setHeadInitialSync(root [32]byte, block interfaces.SignedBeaconBlock, state state.BeaconState) {
s.headLock.Lock()
defer s.headLock.Unlock()
@@ -241,7 +241,7 @@ func (s *Service) headBlock() interfaces.SignedBeaconBlock {
// This returns the head state.
// It does a full copy on head state for immutability.
// This is a lock free version.
func (s *Service) headState(ctx context.Context) iface.BeaconState {
func (s *Service) headState(ctx context.Context) state.BeaconState {
ctx, span := trace.StartSpan(ctx, "blockChain.headState")
defer span.End()
@@ -268,7 +268,7 @@ func (s *Service) cacheJustifiedStateBalances(ctx context.Context, justifiedRoot
s.clearInitSyncBlocks()
var justifiedState iface.BeaconState
var justifiedState state.BeaconState
var err error
if justifiedRoot == s.genesisRoot {
justifiedState, err = s.cfg.BeaconDB.GenesisState(ctx)
@@ -288,7 +288,7 @@ func (s *Service) cacheJustifiedStateBalances(ctx context.Context, justifiedRoot
epoch := helpers.CurrentEpoch(justifiedState)
justifiedBalances := make([]uint64, justifiedState.NumValidators())
if err := justifiedState.ReadFromEveryValidator(func(idx int, val iface.ReadOnlyValidator) error {
if err := justifiedState.ReadFromEveryValidator(func(idx int, val state.ReadOnlyValidator) error {
if helpers.IsActiveValidatorUsingTrie(val, epoch) {
justifiedBalances[idx] = val.EffectiveBalance()
} else {
@@ -315,7 +315,7 @@ func (s *Service) getJustifiedBalances() []uint64 {
// chain head is determined, set, and saved to disk.
func (s *Service) notifyNewHeadEvent(
newHeadSlot types.Slot,
newHeadState iface.BeaconState,
newHeadState state.BeaconState,
newHeadStateRoot,
newHeadRoot []byte,
) error {

View File

@@ -7,7 +7,7 @@ import (
"github.com/prometheus/client_golang/prometheus/promauto"
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch/precompute"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/proto/interfaces"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
@@ -121,7 +121,7 @@ func reportSlotMetrics(stateSlot, headSlot, clockSlot types.Slot, finalizedCheck
}
// reportEpochMetrics reports epoch related metrics.
func reportEpochMetrics(ctx context.Context, postState, headState iface.BeaconState) error {
func reportEpochMetrics(ctx context.Context, postState, headState state.BeaconState) error {
currentEpoch := types.Epoch(postState.Slot() / params.BeaconConfig().SlotsPerEpoch)
// Validator instances

View File

@@ -8,8 +8,8 @@ import (
"github.com/pkg/errors"
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
core "github.com/prysmaticlabs/prysm/beacon-chain/core/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
@@ -18,7 +18,7 @@ import (
)
// getAttPreState retrieves the att pre state by either from the cache or the DB.
func (s *Service) getAttPreState(ctx context.Context, c *ethpb.Checkpoint) (iface.BeaconState, error) {
func (s *Service) getAttPreState(ctx context.Context, c *ethpb.Checkpoint) (state.BeaconState, error) {
// Use a multilock to allow scoped holding of a mutex by a checkpoint root + epoch
// allowing us to behave smarter in terms of how this function is used concurrently.
epochKey := strconv.FormatUint(uint64(c.Epoch), 10 /* base 10 */)
@@ -44,12 +44,12 @@ func (s *Service) getAttPreState(ctx context.Context, c *ethpb.Checkpoint) (ifac
}
if epochStartSlot > baseState.Slot() {
if featureconfig.Get().EnableNextSlotStateCache {
baseState, err = state.ProcessSlotsUsingNextSlotCache(ctx, baseState, c.Root, epochStartSlot)
baseState, err = core.ProcessSlotsUsingNextSlotCache(ctx, baseState, c.Root, epochStartSlot)
if err != nil {
return nil, errors.Wrapf(err, "could not process slots up to epoch %d", c.Epoch)
}
} else {
baseState, err = state.ProcessSlots(ctx, baseState, epochStartSlot)
baseState, err = core.ProcessSlots(ctx, baseState, epochStartSlot)
if err != nil {
return nil, errors.Wrapf(err, "could not process slots up to epoch %d", c.Epoch)
}

View File

@@ -9,8 +9,8 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed"
statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
core "github.com/prysmaticlabs/prysm/beacon-chain/core/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpbv1 "github.com/prysmaticlabs/prysm/proto/eth/v1"
"github.com/prysmaticlabs/prysm/proto/interfaces"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
@@ -97,7 +97,7 @@ func (s *Service) onBlock(ctx context.Context, signed interfaces.SignedBeaconBlo
return err
}
postState, err := state.ExecuteStateTransition(ctx, preState, signed)
postState, err := core.ExecuteStateTransition(ctx, preState, signed)
if err != nil {
return err
}
@@ -114,7 +114,7 @@ func (s *Service) onBlock(ctx context.Context, signed interfaces.SignedBeaconBlo
// with a custom deadline, therefore using the background context instead.
slotCtx, cancel := context.WithTimeout(context.Background(), slotDeadline)
defer cancel()
if err := state.UpdateNextSlotCache(slotCtx, blockRoot[:], postState); err != nil {
if err := core.UpdateNextSlotCache(slotCtx, blockRoot[:], postState); err != nil {
log.WithError(err).Debug("could not update next slot state cache")
}
}()
@@ -228,9 +228,9 @@ func (s *Service) onBlockBatch(ctx context.Context, blks []interfaces.SignedBeac
Messages: [][32]byte{},
}
var set *bls.SignatureSet
boundaries := make(map[[32]byte]iface.BeaconState)
boundaries := make(map[[32]byte]state.BeaconState)
for i, b := range blks {
set, preState, err = state.ExecuteStateTransitionNoVerifyAnySig(ctx, preState, b)
set, preState, err = core.ExecuteStateTransitionNoVerifyAnySig(ctx, preState, b)
if err != nil {
return nil, nil, err
}
@@ -314,14 +314,14 @@ func (s *Service) handleBlockAfterBatchVerify(ctx context.Context, signed interf
}
// Epoch boundary bookkeeping such as logging epoch summaries.
func (s *Service) handleEpochBoundary(ctx context.Context, postState iface.BeaconState) error {
func (s *Service) handleEpochBoundary(ctx context.Context, postState state.BeaconState) error {
if postState.Slot()+1 == s.nextEpochBoundarySlot {
// Update caches for the next epoch at epoch boundary slot - 1.
if err := helpers.UpdateCommitteeCache(postState, helpers.NextEpoch(postState)); err != nil {
return err
}
copied := postState.Copy()
copied, err := state.ProcessSlots(ctx, copied, copied.Slot()+1)
copied, err := core.ProcessSlots(ctx, copied, copied.Slot()+1)
if err != nil {
return err
}
@@ -354,7 +354,7 @@ func (s *Service) handleEpochBoundary(ctx context.Context, postState iface.Beaco
// This feeds in the block and block's attestations to fork choice store. It's allows fork choice store
// to gain information on the most current chain.
func (s *Service) insertBlockAndAttestationsToForkChoiceStore(ctx context.Context, blk interfaces.BeaconBlock, root [32]byte,
st iface.BeaconState) error {
st state.BeaconState) error {
fCheckpoint := st.FinalizedCheckpoint()
jCheckpoint := st.CurrentJustifiedCheckpoint()
if err := s.insertBlockToForkChoiceStore(ctx, blk, root, fCheckpoint, jCheckpoint); err != nil {
@@ -392,7 +392,7 @@ func (s *Service) insertBlockToForkChoiceStore(ctx context.Context, blk interfac
// 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 iface.BeaconState, initSync bool) error {
func (s *Service) savePostStateInfo(ctx context.Context, r [32]byte, b interfaces.SignedBeaconBlock, st state.BeaconState, initSync bool) error {
ctx, span := trace.StartSpan(ctx, "blockChain.savePostStateInfo")
defer span.End()
if initSync {

View File

@@ -8,7 +8,7 @@ import (
"github.com/pkg/errors"
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/proto/interfaces"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/attestationutil"
@@ -27,7 +27,7 @@ func (s *Service) CurrentSlot() types.Slot {
// getBlockPreState returns the pre state of an incoming block. It uses the parent root of the block
// to retrieve the state in DB. It verifies the pre state's validity and the incoming block
// is in the correct time window.
func (s *Service) getBlockPreState(ctx context.Context, b interfaces.BeaconBlock) (iface.BeaconState, error) {
func (s *Service) getBlockPreState(ctx context.Context, b interfaces.BeaconBlock) (state.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "blockChain.getBlockPreState")
defer span.End()
@@ -188,7 +188,7 @@ func (s *Service) shouldUpdateCurrentJustified(ctx context.Context, newJustified
return true, nil
}
func (s *Service) updateJustified(ctx context.Context, state iface.ReadOnlyBeaconState) error {
func (s *Service) updateJustified(ctx context.Context, state state.ReadOnlyBeaconState) error {
cpt := state.CurrentJustifiedCheckpoint()
if cpt.Epoch > s.bestJustifiedCheckpt.Epoch {
s.bestJustifiedCheckpt = cpt
@@ -334,7 +334,7 @@ func (s *Service) ancestorByDB(ctx context.Context, r [32]byte, slot types.Slot)
// ancestor_at_finalized_slot = get_ancestor(store, store.justified_checkpoint.root, finalized_slot)
// if ancestor_at_finalized_slot != store.finalized_checkpoint.root:
// store.justified_checkpoint = state.current_justified_checkpoint
func (s *Service) finalizedImpliesNewJustified(ctx context.Context, state iface.BeaconState) error {
func (s *Service) finalizedImpliesNewJustified(ctx context.Context, state state.BeaconState) error {
// Update justified if it's different than the one cached in the store.
if !attestationutil.CheckPointIsEqual(s.justifiedCheckpt, state.CurrentJustifiedCheckpoint()) {
if state.CurrentJustifiedCheckpoint().Epoch > s.justifiedCheckpt.Epoch {

View File

@@ -13,11 +13,11 @@ import (
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache"
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
core "github.com/prysmaticlabs/prysm/beacon-chain/core/state"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
testDB "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
"github.com/prysmaticlabs/prysm/proto/interfaces"
@@ -69,7 +69,7 @@ func TestStore_OnBlock(t *testing.T) {
tests := []struct {
name string
blk *ethpb.SignedBeaconBlock
s iface.BeaconState
s state.BeaconState
time uint64
wantErrString string
}{
@@ -157,11 +157,11 @@ func TestStore_OnBlockBatch(t *testing.T) {
var blks []interfaces.SignedBeaconBlock
var blkRoots [][32]byte
var firstState iface.BeaconState
var firstState state.BeaconState
for i := 1; i < 10; i++ {
b, err := testutil.GenerateFullBlock(bState, keys, testutil.DefaultBlockGenConfig(), types.Slot(i))
require.NoError(t, err)
bState, err = state.ExecuteStateTransition(ctx, bState, wrapper.WrappedPhase0SignedBeaconBlock(b))
bState, err = core.ExecuteStateTransition(ctx, bState, wrapper.WrappedPhase0SignedBeaconBlock(b))
require.NoError(t, err)
if i == 1 {
firstState = bState.Copy()

View File

@@ -9,7 +9,7 @@ import (
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/params"
@@ -21,7 +21,7 @@ import (
// AttestationReceiver interface defines the methods of chain service receive and processing new attestations.
type AttestationReceiver interface {
ReceiveAttestationNoPubsub(ctx context.Context, att *ethpb.Attestation) error
AttestationPreState(ctx context.Context, att *ethpb.Attestation) (iface.BeaconState, error)
AttestationPreState(ctx context.Context, att *ethpb.Attestation) (state.BeaconState, error)
VerifyLmdFfgConsistency(ctx context.Context, att *ethpb.Attestation) error
VerifyFinalizedConsistency(ctx context.Context, root []byte) error
}
@@ -43,7 +43,7 @@ func (s *Service) ReceiveAttestationNoPubsub(ctx context.Context, att *ethpb.Att
}
// AttestationPreState returns the pre state of attestation.
func (s *Service) AttestationPreState(ctx context.Context, att *ethpb.Attestation) (iface.BeaconState, error) {
func (s *Service) AttestationPreState(ctx context.Context, att *ethpb.Attestation) (state.BeaconState, error) {
ss, err := helpers.StartSlot(att.Data.Target.Epoch)
if err != nil {
return nil, err

View File

@@ -16,7 +16,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/feed"
statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
core "github.com/prysmaticlabs/prysm/beacon-chain/core/state"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
f "github.com/prysmaticlabs/prysm/beacon-chain/forkchoice"
"github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray"
@@ -25,7 +25,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/operations/voluntaryexits"
"github.com/prysmaticlabs/prysm/beacon-chain/p2p"
"github.com/prysmaticlabs/prysm/beacon-chain/powchain"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
"github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags"
"github.com/prysmaticlabs/prysm/proto/interfaces"
@@ -271,14 +271,14 @@ func (s *Service) processChainStartTime(ctx context.Context, genesisTime time.Ti
func (s *Service) initializeBeaconChain(
ctx context.Context,
genesisTime time.Time,
preGenesisState iface.BeaconState,
eth1data *ethpb.Eth1Data) (iface.BeaconState, error) {
preGenesisState state.BeaconState,
eth1data *ethpb.Eth1Data) (state.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "beacon-chain.Service.initializeBeaconChain")
defer span.End()
s.genesisTime = genesisTime
unixTime := uint64(genesisTime.Unix())
genesisState, err := state.OptimizedGenesisBeaconState(unixTime, preGenesisState, eth1data)
genesisState, err := core.OptimizedGenesisBeaconState(unixTime, preGenesisState, eth1data)
if err != nil {
return nil, errors.Wrap(err, "could not initialize genesis state")
}
@@ -332,7 +332,7 @@ func (s *Service) Status() error {
}
// This gets called when beacon chain is first initialized to save genesis data (state, block, and more) in db.
func (s *Service) saveGenesisData(ctx context.Context, genesisState iface.BeaconState) error {
func (s *Service) saveGenesisData(ctx context.Context, genesisState state.BeaconState) error {
if err := s.cfg.BeaconDB.SaveGenesisData(ctx, genesisState); err != nil {
return errors.Wrap(err, "could not save genesis data")
}
@@ -399,7 +399,7 @@ func (s *Service) initializeChainInfo(ctx context.Context) error {
return errors.New("no finalized epoch in the database")
}
finalizedRoot := s.ensureRootNotZeros(bytesutil.ToBytes32(finalized.Root))
var finalizedState iface.BeaconState
var finalizedState state.BeaconState
finalizedState, err = s.cfg.StateGen.Resume(ctx)
if err != nil {

View File

@@ -18,7 +18,7 @@ go_library(
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/db:go_default_library",
"//beacon-chain/forkchoice/protoarray:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/v1:go_default_library",
"//proto/interfaces:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",

View File

@@ -18,7 +18,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
"github.com/prysmaticlabs/prysm/beacon-chain/forkchoice/protoarray"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
"github.com/prysmaticlabs/prysm/proto/interfaces"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
@@ -31,7 +31,7 @@ import (
// ChainService defines the mock interface for testing
type ChainService struct {
State iface.BeaconState
State state.BeaconState
Root []byte
Block interfaces.SignedBeaconBlock
FinalizedCheckPoint *ethpb.Checkpoint
@@ -254,7 +254,7 @@ func (s *ChainService) HeadBlock(context.Context) (interfaces.SignedBeaconBlock,
}
// HeadState mocks HeadState method in chain service.
func (s *ChainService) HeadState(context.Context) (iface.BeaconState, error) {
func (s *ChainService) HeadState(context.Context) (state.BeaconState, error) {
return s.State, nil
}
@@ -289,7 +289,7 @@ func (s *ChainService) ReceiveAttestationNoPubsub(context.Context, *ethpb.Attest
}
// AttestationPreState mocks AttestationPreState method in chain service.
func (s *ChainService) AttestationPreState(_ context.Context, _ *ethpb.Attestation) (iface.BeaconState, error) {
func (s *ChainService) AttestationPreState(_ context.Context, _ *ethpb.Attestation) (state.BeaconState, error) {
return s.State, nil
}

View File

@@ -30,7 +30,7 @@ go_library(
"//tools:__subpackages__",
],
deps = [
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//shared/copyutil:go_default_library",
"//shared/hashutil:go_default_library",
@@ -61,7 +61,7 @@ go_test(
],
embed = [":go_default_library"],
deps = [
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/v1:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v2/state:go_default_library",

View File

@@ -6,7 +6,7 @@ import (
lru "github.com/hashicorp/golang-lru"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/hashutil"
)
@@ -47,7 +47,7 @@ func NewCheckpointStateCache() *CheckpointStateCache {
// StateByCheckpoint fetches state by checkpoint. Returns true with a
// reference to the CheckpointState info, if exists. Otherwise returns false, nil.
func (c *CheckpointStateCache) StateByCheckpoint(cp *ethpb.Checkpoint) (iface.BeaconState, error) {
func (c *CheckpointStateCache) StateByCheckpoint(cp *ethpb.Checkpoint) (state.BeaconState, error) {
c.lock.RLock()
defer c.lock.RUnlock()
h, err := hashutil.HashProto(cp)
@@ -60,7 +60,7 @@ func (c *CheckpointStateCache) StateByCheckpoint(cp *ethpb.Checkpoint) (iface.Be
if exists && item != nil {
checkpointStateHit.Inc()
// Copy here is unnecessary since the return will only be used to verify attestation signature.
return item.(iface.BeaconState), nil
return item.(state.BeaconState), nil
}
checkpointStateMiss.Inc()
@@ -69,7 +69,7 @@ func (c *CheckpointStateCache) StateByCheckpoint(cp *ethpb.Checkpoint) (iface.Be
// AddCheckpointState adds CheckpointState object to the cache. This method also trims the least
// recently added CheckpointState object if the cache size has ready the max cache size limit.
func (c *CheckpointStateCache) AddCheckpointState(cp *ethpb.Checkpoint, s iface.ReadOnlyBeaconState) error {
func (c *CheckpointStateCache) AddCheckpointState(cp *ethpb.Checkpoint, s state.ReadOnlyBeaconState) error {
c.lock.Lock()
defer c.lock.Unlock()
h, err := hashutil.HashProto(cp)

View File

@@ -4,7 +4,7 @@ import (
"testing"
types "github.com/prysmaticlabs/eth2-types"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
statepb "github.com/prysmaticlabs/prysm/proto/prysm/v2/state"
@@ -25,20 +25,20 @@ func TestCheckpointStateCache_StateByCheckpoint(t *testing.T) {
})
require.NoError(t, err)
state, err := cache.StateByCheckpoint(cp1)
s, err := cache.StateByCheckpoint(cp1)
require.NoError(t, err)
assert.Equal(t, iface.BeaconState(nil), state, "Expected state not to exist in empty cache")
assert.Equal(t, state.BeaconState(nil), s, "Expected state not to exist in empty cache")
require.NoError(t, cache.AddCheckpointState(cp1, st))
state, err = cache.StateByCheckpoint(cp1)
s, err = cache.StateByCheckpoint(cp1)
require.NoError(t, err)
pbState1, err := v1.ProtobufBeaconState(state.InnerStateUnsafe())
pbState1, err := v1.ProtobufBeaconState(s.InnerStateUnsafe())
require.NoError(t, err)
pbState2, err := v1.ProtobufBeaconState(st.InnerStateUnsafe())
pbstate, err := v1.ProtobufBeaconState(st.InnerStateUnsafe())
require.NoError(t, err)
if !proto.Equal(pbState1, pbState2) {
if !proto.Equal(pbState1, pbstate) {
t.Error("incorrectly cached state")
}
@@ -49,13 +49,13 @@ func TestCheckpointStateCache_StateByCheckpoint(t *testing.T) {
require.NoError(t, err)
require.NoError(t, cache.AddCheckpointState(cp2, st2))
state, err = cache.StateByCheckpoint(cp2)
s, err = cache.StateByCheckpoint(cp2)
require.NoError(t, err)
assert.DeepEqual(t, st2.CloneInnerState(), state.CloneInnerState(), "incorrectly cached state")
assert.DeepEqual(t, st2.CloneInnerState(), s.CloneInnerState(), "incorrectly cached state")
state, err = cache.StateByCheckpoint(cp1)
s, err = cache.StateByCheckpoint(cp1)
require.NoError(t, err)
assert.DeepEqual(t, st.CloneInnerState(), state.CloneInnerState(), "incorrectly cached state")
assert.DeepEqual(t, st.CloneInnerState(), s.CloneInnerState(), "incorrectly cached state")
}
func TestCheckpointStateCache_MaxSize(t *testing.T) {

View File

@@ -9,7 +9,7 @@ import (
lru "github.com/hashicorp/golang-lru"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"go.opencensus.io/trace"
)
@@ -57,7 +57,7 @@ func (c *SkipSlotCache) Disable() {
// Get waits for any in progress calculation to complete before returning a
// cached response, if any.
func (c *SkipSlotCache) Get(ctx context.Context, r [32]byte) (iface.BeaconState, error) {
func (c *SkipSlotCache) Get(ctx context.Context, r [32]byte) (state.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "skipSlotCache.Get")
defer span.End()
if c.disabled {
@@ -97,7 +97,7 @@ func (c *SkipSlotCache) Get(ctx context.Context, r [32]byte) (iface.BeaconState,
if exists && item != nil {
skipSlotCacheHit.Inc()
span.AddAttributes(trace.BoolAttribute("hit", true))
return item.(iface.BeaconState).Copy(), nil
return item.(state.BeaconState).Copy(), nil
}
skipSlotCacheMiss.Inc()
span.AddAttributes(trace.BoolAttribute("hit", false))
@@ -136,7 +136,7 @@ func (c *SkipSlotCache) MarkNotInProgress(r [32]byte) error {
}
// Put the response in the cache.
func (c *SkipSlotCache) Put(_ context.Context, r [32]byte, state iface.BeaconState) error {
func (c *SkipSlotCache) Put(_ context.Context, r [32]byte, state state.BeaconState) error {
if c.disabled {
return nil
}

View File

@@ -5,7 +5,7 @@ import (
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
statepb "github.com/prysmaticlabs/prysm/proto/prysm/v2/state"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
@@ -17,21 +17,21 @@ func TestSkipSlotCache_RoundTrip(t *testing.T) {
c := cache.NewSkipSlotCache()
r := [32]byte{'a'}
state, err := c.Get(ctx, r)
s, err := c.Get(ctx, r)
require.NoError(t, err)
assert.Equal(t, iface.BeaconState(nil), state, "Empty cache returned an object")
assert.Equal(t, state.BeaconState(nil), s, "Empty cache returned an object")
require.NoError(t, c.MarkInProgress(r))
state, err = v1.InitializeFromProto(&statepb.BeaconState{
s, err = v1.InitializeFromProto(&statepb.BeaconState{
Slot: 10,
})
require.NoError(t, err)
require.NoError(t, c.Put(ctx, r, state))
require.NoError(t, c.Put(ctx, r, s))
require.NoError(t, c.MarkNotInProgress(r))
res, err := c.Get(ctx, r)
require.NoError(t, err)
assert.DeepEqual(t, res.CloneInnerState(), state.CloneInnerState(), "Expected equal protos to return from cache")
assert.DeepEqual(t, res.CloneInnerState(), s.CloneInnerState(), "Expected equal protos to return from cache")
}

View File

@@ -26,7 +26,7 @@ go_library(
deps = [
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/core/validators:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//proto/interfaces:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v2/state:go_default_library",
@@ -74,7 +74,7 @@ go_test(
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/core/validators:go_default_library",
"//beacon-chain/p2p/types:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/v1:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v1alpha1/wrapper:go_default_library",

View File

@@ -7,7 +7,7 @@ import (
"github.com/pkg/errors"
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/proto/interfaces"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
statepb "github.com/prysmaticlabs/prysm/proto/prysm/v2/state"
@@ -21,9 +21,9 @@ import (
// records.
func ProcessAttestations(
ctx context.Context,
beaconState iface.BeaconState,
beaconState state.BeaconState,
b interfaces.SignedBeaconBlock,
) (iface.BeaconState, error) {
) (state.BeaconState, error) {
if err := helpers.VerifyNilBeaconBlock(b); err != nil {
return nil, err
}
@@ -69,9 +69,9 @@ func ProcessAttestations(
// assert is_valid_indexed_attestation(state, get_indexed_attestation(state, attestation))
func ProcessAttestation(
ctx context.Context,
beaconState iface.BeaconState,
beaconState state.BeaconState,
att *ethpb.Attestation,
) (iface.BeaconState, error) {
) (state.BeaconState, error) {
beaconState, err := ProcessAttestationNoVerifySignature(ctx, beaconState, att)
if err != nil {
return nil, err
@@ -83,9 +83,9 @@ func ProcessAttestation(
// records. The only difference would be that the attestation signature would not be verified.
func ProcessAttestationsNoVerifySignature(
ctx context.Context,
beaconState iface.BeaconState,
beaconState state.BeaconState,
b interfaces.SignedBeaconBlock,
) (iface.BeaconState, error) {
) (state.BeaconState, error) {
if err := helpers.VerifyNilBeaconBlock(b); err != nil {
return nil, err
}
@@ -104,7 +104,7 @@ func ProcessAttestationsNoVerifySignature(
// used before processing attestation with the beacon state.
func VerifyAttestationNoVerifySignature(
ctx context.Context,
beaconState iface.ReadOnlyBeaconState,
beaconState state.ReadOnlyBeaconState,
att *ethpb.Attestation,
) error {
ctx, span := trace.StartSpan(ctx, "core.VerifyAttestationNoVerifySignature")
@@ -188,9 +188,9 @@ func VerifyAttestationNoVerifySignature(
// method is used to validate attestations whose signatures have already been verified.
func ProcessAttestationNoVerifySignature(
ctx context.Context,
beaconState iface.BeaconState,
beaconState state.BeaconState,
att *ethpb.Attestation,
) (iface.BeaconState, error) {
) (state.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "core.ProcessAttestationNoVerifySignature")
defer span.End()
@@ -227,7 +227,7 @@ func ProcessAttestationNoVerifySignature(
// VerifyAttestationSignature converts and attestation into an indexed attestation and verifies
// the signature in that attestation.
func VerifyAttestationSignature(ctx context.Context, beaconState iface.ReadOnlyBeaconState, att *ethpb.Attestation) error {
func VerifyAttestationSignature(ctx context.Context, beaconState state.ReadOnlyBeaconState, att *ethpb.Attestation) error {
if err := helpers.ValidateNilAttestation(att); err != nil {
return err
}
@@ -258,7 +258,7 @@ func VerifyAttestationSignature(ctx context.Context, beaconState iface.ReadOnlyB
// domain = get_domain(state, DOMAIN_BEACON_ATTESTER, indexed_attestation.data.target.epoch)
// signing_root = compute_signing_root(indexed_attestation.data, domain)
// return bls.FastAggregateVerify(pubkeys, signing_root, indexed_attestation.signature)
func VerifyIndexedAttestation(ctx context.Context, beaconState iface.ReadOnlyBeaconState, indexedAtt *ethpb.IndexedAttestation) error {
func VerifyIndexedAttestation(ctx context.Context, beaconState state.ReadOnlyBeaconState, indexedAtt *ethpb.IndexedAttestation) error {
ctx, span := trace.StartSpan(ctx, "core.VerifyIndexedAttestation")
defer span.End()

View File

@@ -7,7 +7,7 @@ import (
"github.com/pkg/errors"
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/attestationutil"
"github.com/prysmaticlabs/prysm/shared/slashutil"
@@ -35,10 +35,10 @@ import (
// assert slashed_any
func ProcessAttesterSlashings(
ctx context.Context,
beaconState iface.BeaconState,
beaconState state.BeaconState,
slashings []*ethpb.AttesterSlashing,
slashFunc slashValidatorFunc,
) (iface.BeaconState, error) {
) (state.BeaconState, error) {
for idx, slashing := range slashings {
if err := VerifyAttesterSlashing(ctx, beaconState, slashing); err != nil {
return nil, errors.Wrapf(err, "could not verify attester slashing %d", idx)
@@ -50,7 +50,7 @@ func ProcessAttesterSlashings(
currentEpoch := helpers.SlotToEpoch(beaconState.Slot())
var err error
var slashedAny bool
var val iface.ReadOnlyValidator
var val state.ReadOnlyValidator
for _, validatorIndex := range slashableIndices {
val, err = beaconState.ValidatorAtIndexReadOnly(types.ValidatorIndex(validatorIndex))
if err != nil {
@@ -73,7 +73,7 @@ func ProcessAttesterSlashings(
}
// VerifyAttesterSlashing validates the attestation data in both attestations in the slashing object.
func VerifyAttesterSlashing(ctx context.Context, beaconState iface.ReadOnlyBeaconState, slashing *ethpb.AttesterSlashing) error {
func VerifyAttesterSlashing(ctx context.Context, beaconState state.ReadOnlyBeaconState, slashing *ethpb.AttesterSlashing) error {
if slashing == nil {
return errors.New("nil slashing")
}

View File

@@ -6,7 +6,7 @@ import (
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
statepb "github.com/prysmaticlabs/prysm/proto/prysm/v2/state"
"github.com/prysmaticlabs/prysm/shared/bls"
@@ -20,9 +20,9 @@ import (
// ProcessPreGenesisDeposits processes a deposit for the beacon state before chainstart.
func ProcessPreGenesisDeposits(
ctx context.Context,
beaconState iface.BeaconState,
beaconState state.BeaconState,
deposits []*ethpb.Deposit,
) (iface.BeaconState, error) {
) (state.BeaconState, error) {
var err error
beaconState, err = ProcessDeposits(ctx, beaconState, deposits)
if err != nil {
@@ -36,7 +36,7 @@ func ProcessPreGenesisDeposits(
}
// ActivateValidatorWithEffectiveBalance updates validator's effective balance, and if it's above MaxEffectiveBalance, validator becomes active in genesis.
func ActivateValidatorWithEffectiveBalance(beaconState iface.BeaconState, deposits []*ethpb.Deposit) (iface.BeaconState, error) {
func ActivateValidatorWithEffectiveBalance(beaconState state.BeaconState, deposits []*ethpb.Deposit) (state.BeaconState, error) {
for _, deposit := range deposits {
pubkey := deposit.Data.PublicKey
index, ok := beaconState.ValidatorIndexByPubkey(bytesutil.ToBytes48(pubkey))
@@ -75,9 +75,9 @@ func ActivateValidatorWithEffectiveBalance(beaconState iface.BeaconState, deposi
// process_deposit(state, deposit)
func ProcessDeposits(
ctx context.Context,
beaconState iface.BeaconState,
beaconState state.BeaconState,
deposits []*ethpb.Deposit,
) (iface.BeaconState, error) {
) (state.BeaconState, error) {
// Attempt to verify all deposit signatures at once, if this fails then fall back to processing
// individual deposits with signature verification enabled.
batchVerified, err := BatchVerifyDepositsSignatures(ctx, deposits)
@@ -152,7 +152,7 @@ func BatchVerifyDepositsSignatures(ctx context.Context, deposits []*ethpb.Deposi
// # Increase balance by deposit amount
// index = ValidatorIndex(validator_pubkeys.index(pubkey))
// increase_balance(state, index, amount)
func ProcessDeposit(beaconState iface.BeaconState, deposit *ethpb.Deposit, verifySignature bool) (iface.BeaconState, error) {
func ProcessDeposit(beaconState state.BeaconState, deposit *ethpb.Deposit, verifySignature bool) (state.BeaconState, error) {
if err := verifyDeposit(beaconState, deposit); err != nil {
if deposit == nil || deposit.Data == nil {
return nil, err
@@ -203,7 +203,7 @@ func ProcessDeposit(beaconState iface.BeaconState, deposit *ethpb.Deposit, verif
return beaconState, nil
}
func verifyDeposit(beaconState iface.ReadOnlyBeaconState, deposit *ethpb.Deposit) error {
func verifyDeposit(beaconState state.ReadOnlyBeaconState, deposit *ethpb.Deposit) error {
// Verify Merkle proof of deposit and deposit trie root.
if deposit == nil || deposit.Data == nil {
return errors.New("received nil deposit or nil deposit data")

View File

@@ -5,7 +5,7 @@ import (
"context"
"errors"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/copyutil"
"github.com/prysmaticlabs/prysm/shared/params"
@@ -20,7 +20,7 @@ import (
// state.eth1_data_votes.append(body.eth1_data)
// if state.eth1_data_votes.count(body.eth1_data) * 2 > EPOCHS_PER_ETH1_VOTING_PERIOD * SLOTS_PER_EPOCH:
// state.eth1_data = body.eth1_data
func ProcessEth1DataInBlock(_ context.Context, beaconState iface.BeaconState, eth1Data *ethpb.Eth1Data) (iface.BeaconState, error) {
func ProcessEth1DataInBlock(_ context.Context, beaconState state.BeaconState, eth1Data *ethpb.Eth1Data) (state.BeaconState, error) {
if beaconState == nil || beaconState.IsNil() {
return nil, errors.New("nil state")
}
@@ -56,7 +56,7 @@ func AreEth1DataEqual(a, b *ethpb.Eth1Data) bool {
// eth1 voting period. A vote is cast by including eth1data in a block and part of state processing
// appends eth1data to the state in the Eth1DataVotes list. Iterating through this list checks the
// votes to see if they match the eth1data.
func Eth1DataHasEnoughSupport(beaconState iface.ReadOnlyBeaconState, data *ethpb.Eth1Data) (bool, error) {
func Eth1DataHasEnoughSupport(beaconState state.ReadOnlyBeaconState, data *ethpb.Eth1Data) (bool, error) {
voteCount := uint64(0)
data = copyutil.CopyETH1Data(data)

View File

@@ -8,7 +8,7 @@ import (
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
v "github.com/prysmaticlabs/prysm/beacon-chain/core/validators"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
statepb "github.com/prysmaticlabs/prysm/proto/prysm/v2/state"
"github.com/prysmaticlabs/prysm/shared/params"
@@ -45,9 +45,9 @@ var ValidatorCannotExitYetMsg = "validator has not been active long enough to ex
// initiate_validator_exit(state, voluntary_exit.validator_index)
func ProcessVoluntaryExits(
_ context.Context,
beaconState iface.BeaconState,
beaconState state.BeaconState,
exits []*ethpb.SignedVoluntaryExit,
) (iface.BeaconState, error) {
) (state.BeaconState, error) {
for idx, exit := range exits {
if exit == nil || exit.Exit == nil {
return nil, errors.New("nil voluntary exit in block body")
@@ -88,7 +88,7 @@ func ProcessVoluntaryExits(
// # Initiate exit
// initiate_validator_exit(state, voluntary_exit.validator_index)
func VerifyExitAndSignature(
validator iface.ReadOnlyValidator,
validator state.ReadOnlyValidator,
currentSlot types.Slot,
fork *statepb.Fork,
signed *ethpb.SignedVoluntaryExit,
@@ -133,7 +133,7 @@ func VerifyExitAndSignature(
// assert bls.Verify(validator.pubkey, signing_root, signed_voluntary_exit.signature)
// # Initiate exit
// initiate_validator_exit(state, voluntary_exit.validator_index)
func verifyExitConditions(validator iface.ReadOnlyValidator, currentSlot types.Slot, exit *ethpb.VoluntaryExit) error {
func verifyExitConditions(validator state.ReadOnlyValidator, currentSlot types.Slot, exit *ethpb.VoluntaryExit) error {
currentEpoch := helpers.SlotToEpoch(currentSlot)
// Verify the validator is active.
if !helpers.IsActiveValidatorUsingTrie(validator, currentEpoch) {

View File

@@ -7,7 +7,7 @@ import (
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/proto/interfaces"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/params"
@@ -40,9 +40,9 @@ import (
// assert not proposer.slashed
func ProcessBlockHeader(
_ context.Context,
beaconState iface.BeaconState,
beaconState state.BeaconState,
block interfaces.SignedBeaconBlock,
) (iface.BeaconState, error) {
) (state.BeaconState, error) {
if err := helpers.VerifyNilBeaconBlock(block); err != nil {
return nil, err
}
@@ -92,10 +92,10 @@ func ProcessBlockHeader(
// proposer = state.validators[block.proposer_index]
// assert not proposer.slashed
func ProcessBlockHeaderNoVerify(
beaconState iface.BeaconState,
beaconState state.BeaconState,
slot types.Slot, proposerIndex types.ValidatorIndex,
parentRoot, bodyRoot []byte,
) (iface.BeaconState, error) {
) (state.BeaconState, error) {
if beaconState.Slot() != slot {
return nil, fmt.Errorf("state slot: %d is different than block slot: %d", beaconState.Slot(), slot)
}

View File

@@ -7,13 +7,13 @@ import (
"github.com/pkg/errors"
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/params"
"google.golang.org/protobuf/proto"
)
type slashValidatorFunc func(iface.BeaconState, types.ValidatorIndex) (iface.BeaconState, error)
type slashValidatorFunc func(state.BeaconState, types.ValidatorIndex) (state.BeaconState, error)
// ProcessProposerSlashings is one of the operations performed
// on each processed beacon block to slash proposers based on
@@ -42,10 +42,10 @@ type slashValidatorFunc func(iface.BeaconState, types.ValidatorIndex) (iface.Bea
// slash_validator(state, header_1.proposer_index)
func ProcessProposerSlashings(
_ context.Context,
beaconState iface.BeaconState,
beaconState state.BeaconState,
slashings []*ethpb.ProposerSlashing,
slashFunc slashValidatorFunc,
) (iface.BeaconState, error) {
) (state.BeaconState, error) {
var err error
for idx, slashing := range slashings {
if slashing == nil {
@@ -64,7 +64,7 @@ func ProcessProposerSlashings(
// VerifyProposerSlashing verifies that the data provided from slashing is valid.
func VerifyProposerSlashing(
beaconState iface.BeaconState,
beaconState state.BeaconState,
slashing *ethpb.ProposerSlashing,
) error {
if slashing.Header_1 == nil || slashing.Header_1.Header == nil || slashing.Header_2 == nil || slashing.Header_2.Header == nil {

View File

@@ -9,7 +9,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
v "github.com/prysmaticlabs/prysm/beacon-chain/core/validators"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
statepb "github.com/prysmaticlabs/prysm/proto/prysm/v2/state"
@@ -184,7 +184,7 @@ func TestProcessProposerSlashings_AppliesCorrectStatus(t *testing.T) {
func TestVerifyProposerSlashing(t *testing.T) {
type args struct {
beaconState iface.BeaconState
beaconState state.BeaconState
slashing *ethpb.ProposerSlashing
}

View File

@@ -5,7 +5,7 @@ import (
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/proto/interfaces"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/params"
@@ -27,9 +27,9 @@ import (
// state.randao_mixes[epoch % EPOCHS_PER_HISTORICAL_VECTOR] = mix
func ProcessRandao(
_ context.Context,
beaconState iface.BeaconState,
beaconState state.BeaconState,
b interfaces.SignedBeaconBlock,
) (iface.BeaconState, error) {
) (state.BeaconState, error) {
if err := helpers.VerifyNilBeaconBlock(b); err != nil {
return nil, err
}
@@ -59,9 +59,9 @@ func ProcessRandao(
// hash(body.randao_reveal))
// )
func ProcessRandaoNoVerify(
beaconState iface.BeaconState,
beaconState state.BeaconState,
randaoReveal []byte,
) (iface.BeaconState, error) {
) (state.BeaconState, error) {
currentEpoch := helpers.SlotToEpoch(beaconState.Slot())
// If block randao passed verification, we XOR the state's latest randao mix with the block's
// randao and update the state's corresponding latest randao mix value.

View File

@@ -7,7 +7,7 @@ import (
"github.com/pkg/errors"
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
statepb "github.com/prysmaticlabs/prysm/proto/prysm/v2/state"
"github.com/prysmaticlabs/prysm/shared/attestationutil"
@@ -60,7 +60,7 @@ func verifySignature(signedData, pub, signature, domain []byte) error {
}
// VerifyBlockSignature verifies the proposer signature of a beacon block.
func VerifyBlockSignature(beaconState iface.ReadOnlyBeaconState,
func VerifyBlockSignature(beaconState state.ReadOnlyBeaconState,
proposerIndex types.ValidatorIndex,
sig []byte,
rootFunc func() ([32]byte, error)) error {
@@ -78,7 +78,7 @@ func VerifyBlockSignature(beaconState iface.ReadOnlyBeaconState,
}
// BlockSignatureSet retrieves the block signature set from the provided block and its corresponding state.
func BlockSignatureSet(beaconState iface.ReadOnlyBeaconState,
func BlockSignatureSet(beaconState state.ReadOnlyBeaconState,
proposerIndex types.ValidatorIndex,
sig []byte,
rootFunc func() ([32]byte, error)) (*bls.SignatureSet, error) {
@@ -97,7 +97,7 @@ func BlockSignatureSet(beaconState iface.ReadOnlyBeaconState,
// RandaoSignatureSet retrieves the relevant randao specific signature set object
// from a block and its corresponding state.
func RandaoSignatureSet(beaconState iface.ReadOnlyBeaconState,
func RandaoSignatureSet(beaconState state.ReadOnlyBeaconState,
reveal []byte,
) (*bls.SignatureSet, error) {
buf, proposerPub, domain, err := randaoSigningData(beaconState)
@@ -112,7 +112,7 @@ func RandaoSignatureSet(beaconState iface.ReadOnlyBeaconState,
}
// retrieves the randao related signing data from the state.
func randaoSigningData(beaconState iface.ReadOnlyBeaconState) ([]byte, []byte, []byte, error) {
func randaoSigningData(beaconState state.ReadOnlyBeaconState) ([]byte, []byte, []byte, error) {
proposerIdx, err := helpers.BeaconProposerIndex(beaconState)
if err != nil {
return nil, nil, nil, errors.Wrap(err, "could not get beacon proposer index")
@@ -133,7 +133,7 @@ func randaoSigningData(beaconState iface.ReadOnlyBeaconState) ([]byte, []byte, [
// Method to break down attestations of the same domain and collect them into a single signature set.
func createAttestationSignatureSet(
ctx context.Context,
beaconState iface.ReadOnlyBeaconState,
beaconState state.ReadOnlyBeaconState,
atts []*ethpb.Attestation,
domain []byte,
) (*bls.SignatureSet, error) {
@@ -184,7 +184,7 @@ func createAttestationSignatureSet(
// AttestationSignatureSet retrieves all the related attestation signature data such as the relevant public keys,
// signatures and attestation signing data and collate it into a signature set object.
func AttestationSignatureSet(ctx context.Context, beaconState iface.ReadOnlyBeaconState, atts []*ethpb.Attestation) (*bls.SignatureSet, error) {
func AttestationSignatureSet(ctx context.Context, beaconState state.ReadOnlyBeaconState, atts []*ethpb.Attestation) (*bls.SignatureSet, error) {
if len(atts) == 0 {
return bls.NewSet(), nil
}

View File

@@ -11,7 +11,7 @@ go_library(
deps = [
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/core/validators:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v2/state:go_default_library",
"//shared/attestationutil:go_default_library",
@@ -34,7 +34,7 @@ go_test(
embed = [":go_default_library"],
deps = [
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/v1:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v2/state:go_default_library",

View File

@@ -12,7 +12,7 @@ import (
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/validators"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
statepb "github.com/prysmaticlabs/prysm/proto/prysm/v2/state"
"github.com/prysmaticlabs/prysm/shared/attestationutil"
@@ -56,7 +56,7 @@ func (s sortableIndices) Less(i, j int) bool {
// Note: ``get_total_balance`` returns ``EFFECTIVE_BALANCE_INCREMENT`` Gwei minimum to avoid divisions by zero.
// """
// return get_total_balance(state, get_unslashed_attesting_indices(state, attestations))
func AttestingBalance(state iface.ReadOnlyBeaconState, atts []*statepb.PendingAttestation) (uint64, error) {
func AttestingBalance(state state.ReadOnlyBeaconState, atts []*statepb.PendingAttestation) (uint64, error) {
indices, err := UnslashedAttestingIndices(state, atts)
if err != nil {
return 0, errors.Wrap(err, "could not get attesting indices")
@@ -87,7 +87,7 @@ func AttestingBalance(state iface.ReadOnlyBeaconState, atts []*statepb.PendingAt
// for index in activation_queue[:get_validator_churn_limit(state)]:
// validator = state.validators[index]
// validator.activation_epoch = compute_activation_exit_epoch(get_current_epoch(state))
func ProcessRegistryUpdates(state iface.BeaconState) (iface.BeaconState, error) {
func ProcessRegistryUpdates(state state.BeaconState) (state.BeaconState, error) {
currentEpoch := helpers.CurrentEpoch(state)
vals := state.Validators()
var err error
@@ -166,7 +166,7 @@ func ProcessRegistryUpdates(state iface.BeaconState) (iface.BeaconState, error)
// penalty_numerator = validator.effective_balance // increment * adjusted_total_slashing_balance
// penalty = penalty_numerator // total_balance * increment
// decrease_balance(state, ValidatorIndex(index), penalty)
func ProcessSlashings(state iface.BeaconState) (iface.BeaconState, error) {
func ProcessSlashings(state state.BeaconState) (state.BeaconState, error) {
currentEpoch := helpers.CurrentEpoch(state)
totalBalance, err := helpers.TotalActiveBalance(state)
if err != nil {
@@ -210,7 +210,7 @@ func ProcessSlashings(state iface.BeaconState) (iface.BeaconState, error) {
// # Reset eth1 data votes
// if next_epoch % EPOCHS_PER_ETH1_VOTING_PERIOD == 0:
// state.eth1_data_votes = []
func ProcessEth1DataReset(state iface.BeaconState) (iface.BeaconState, error) {
func ProcessEth1DataReset(state state.BeaconState) (state.BeaconState, error) {
currentEpoch := helpers.CurrentEpoch(state)
nextEpoch := currentEpoch + 1
@@ -239,7 +239,7 @@ func ProcessEth1DataReset(state iface.BeaconState) (iface.BeaconState, error) {
// or validator.effective_balance + UPWARD_THRESHOLD < balance
// ):
// validator.effective_balance = min(balance - balance % EFFECTIVE_BALANCE_INCREMENT, MAX_EFFECTIVE_BALANCE)
func ProcessEffectiveBalanceUpdates(state iface.BeaconState) (iface.BeaconState, error) {
func ProcessEffectiveBalanceUpdates(state state.BeaconState) (state.BeaconState, error) {
effBalanceInc := params.BeaconConfig().EffectiveBalanceIncrement
maxEffBalance := params.BeaconConfig().MaxEffectiveBalance
hysteresisInc := effBalanceInc / params.BeaconConfig().HysteresisQuotient
@@ -308,7 +308,7 @@ func ProcessEffectiveBalanceUpdates(state iface.BeaconState) (iface.BeaconState,
// next_epoch = Epoch(get_current_epoch(state) + 1)
// # Reset slashings
// state.slashings[next_epoch % EPOCHS_PER_SLASHINGS_VECTOR] = Gwei(0)
func ProcessSlashingsReset(state iface.BeaconState) (iface.BeaconState, error) {
func ProcessSlashingsReset(state state.BeaconState) (state.BeaconState, error) {
currentEpoch := helpers.CurrentEpoch(state)
nextEpoch := currentEpoch + 1
@@ -338,7 +338,7 @@ func ProcessSlashingsReset(state iface.BeaconState) (iface.BeaconState, error) {
// next_epoch = Epoch(current_epoch + 1)
// # Set randao mix
// state.randao_mixes[next_epoch % EPOCHS_PER_HISTORICAL_VECTOR] = get_randao_mix(state, current_epoch)
func ProcessRandaoMixesReset(state iface.BeaconState) (iface.BeaconState, error) {
func ProcessRandaoMixesReset(state state.BeaconState) (state.BeaconState, error) {
currentEpoch := helpers.CurrentEpoch(state)
nextEpoch := currentEpoch + 1
@@ -371,7 +371,7 @@ func ProcessRandaoMixesReset(state iface.BeaconState) (iface.BeaconState, error)
// if next_epoch % (SLOTS_PER_HISTORICAL_ROOT // SLOTS_PER_EPOCH) == 0:
// historical_batch = HistoricalBatch(block_roots=state.block_roots, state_roots=state.state_roots)
// state.historical_roots.append(hash_tree_root(historical_batch))
func ProcessHistoricalRootsUpdate(state iface.BeaconState) (iface.BeaconState, error) {
func ProcessHistoricalRootsUpdate(state state.BeaconState) (state.BeaconState, error) {
currentEpoch := helpers.CurrentEpoch(state)
nextEpoch := currentEpoch + 1
@@ -401,7 +401,7 @@ func ProcessHistoricalRootsUpdate(state iface.BeaconState) (iface.BeaconState, e
// # Rotate current/previous epoch attestations
// state.previous_epoch_attestations = state.current_epoch_attestations
// state.current_epoch_attestations = []
func ProcessParticipationRecordUpdates(state iface.BeaconState) (iface.BeaconState, error) {
func ProcessParticipationRecordUpdates(state state.BeaconState) (state.BeaconState, error) {
if err := state.RotateAttestations(); err != nil {
return nil, err
}
@@ -409,7 +409,7 @@ func ProcessParticipationRecordUpdates(state iface.BeaconState) (iface.BeaconSta
}
// ProcessFinalUpdates processes the final updates during epoch processing.
func ProcessFinalUpdates(state iface.BeaconState) (iface.BeaconState, error) {
func ProcessFinalUpdates(state state.BeaconState) (state.BeaconState, error) {
var err error
// Reset ETH1 data votes.
@@ -461,7 +461,7 @@ func ProcessFinalUpdates(state iface.BeaconState) (iface.BeaconState, error) {
// for a in attestations:
// output = output.union(get_attesting_indices(state, a.data, a.aggregation_bits))
// return set(filter(lambda index: not state.validators[index].slashed, output))
func UnslashedAttestingIndices(state iface.ReadOnlyBeaconState, atts []*statepb.PendingAttestation) ([]types.ValidatorIndex, error) {
func UnslashedAttestingIndices(state state.ReadOnlyBeaconState, atts []*statepb.PendingAttestation) ([]types.ValidatorIndex, error) {
var setIndices []types.ValidatorIndex
seen := make(map[uint64]bool)

View File

@@ -8,7 +8,7 @@ import (
"github.com/prysmaticlabs/go-bitfield"
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
statepb "github.com/prysmaticlabs/prysm/proto/prysm/v2/state"
@@ -399,7 +399,7 @@ func TestProcessRegistryUpdates_CanExits(t *testing.T) {
}
}
func buildState(t testing.TB, slot types.Slot, validatorCount uint64) iface.BeaconState {
func buildState(t testing.TB, slot types.Slot, validatorCount uint64) state.BeaconState {
validators := make([]*ethpb.Validator, validatorCount)
for i := 0; i < len(validators); i++ {
validators[i] = &ethpb.Validator{

View File

@@ -17,7 +17,7 @@ go_library(
],
deps = [
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v2/state:go_default_library",
"//shared/attestationutil:go_default_library",
@@ -43,7 +43,7 @@ go_test(
deps = [
"//beacon-chain/core/epoch:go_default_library",
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/v1:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v2/state:go_default_library",

View File

@@ -7,7 +7,7 @@ import (
"github.com/pkg/errors"
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
statepb "github.com/prysmaticlabs/prysm/proto/prysm/v2/state"
"github.com/prysmaticlabs/prysm/shared/attestationutil"
"github.com/prysmaticlabs/prysm/shared/params"
@@ -19,7 +19,7 @@ import (
// it also tracks and updates epoch attesting balances.
func ProcessAttestations(
ctx context.Context,
state iface.ReadOnlyBeaconState,
state state.ReadOnlyBeaconState,
vp []*Validator,
pBal *Balance,
) ([]*Validator, *Balance, error) {
@@ -69,7 +69,7 @@ func ProcessAttestations(
}
// AttestedCurrentEpoch returns true if attestation `a` attested once in current epoch and/or epoch boundary block.
func AttestedCurrentEpoch(s iface.ReadOnlyBeaconState, a *statepb.PendingAttestation) (bool, bool, error) {
func AttestedCurrentEpoch(s state.ReadOnlyBeaconState, a *statepb.PendingAttestation) (bool, bool, error) {
currentEpoch := helpers.CurrentEpoch(s)
var votedCurrentEpoch, votedTarget bool
// Did validator vote current epoch.
@@ -87,7 +87,7 @@ func AttestedCurrentEpoch(s iface.ReadOnlyBeaconState, a *statepb.PendingAttesta
}
// AttestedPrevEpoch returns true if attestation `a` attested once in previous epoch and epoch boundary block and/or the same head.
func AttestedPrevEpoch(s iface.ReadOnlyBeaconState, a *statepb.PendingAttestation) (bool, bool, bool, error) {
func AttestedPrevEpoch(s state.ReadOnlyBeaconState, a *statepb.PendingAttestation) (bool, bool, bool, error) {
prevEpoch := helpers.PrevEpoch(s)
var votedPrevEpoch, votedTarget, votedHead bool
// Did validator vote previous epoch.
@@ -115,7 +115,7 @@ func AttestedPrevEpoch(s iface.ReadOnlyBeaconState, a *statepb.PendingAttestatio
}
// SameTarget returns true if attestation `a` attested to the same target block in state.
func SameTarget(state iface.ReadOnlyBeaconState, a *statepb.PendingAttestation, e types.Epoch) (bool, error) {
func SameTarget(state state.ReadOnlyBeaconState, a *statepb.PendingAttestation, e types.Epoch) (bool, error) {
r, err := helpers.BlockRoot(state, e)
if err != nil {
return false, err
@@ -127,7 +127,7 @@ func SameTarget(state iface.ReadOnlyBeaconState, a *statepb.PendingAttestation,
}
// SameHead returns true if attestation `a` attested to the same block by attestation slot in state.
func SameHead(state iface.ReadOnlyBeaconState, a *statepb.PendingAttestation) (bool, error) {
func SameHead(state state.ReadOnlyBeaconState, a *statepb.PendingAttestation) (bool, error) {
r, err := helpers.BlockRootAtSlot(state, a.Data.Slot)
if err != nil {
return false, err

View File

@@ -3,7 +3,7 @@ package precompute
import (
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
)
@@ -23,7 +23,7 @@ import (
// previous_target_balance = get_attesting_balance(state, previous_attestations)
// current_target_balance = get_attesting_balance(state, current_attestations)
// weigh_justification_and_finalization(state, total_active_balance, previous_target_balance, current_target_balance)
func ProcessJustificationAndFinalizationPreCompute(state iface.BeaconState, pBal *Balance) (iface.BeaconState, error) {
func ProcessJustificationAndFinalizationPreCompute(state state.BeaconState, pBal *Balance) (state.BeaconState, error) {
canProcessSlot, err := helpers.StartSlot(2 /*epoch*/)
if err != nil {
return nil, err
@@ -75,8 +75,8 @@ func ProcessJustificationAndFinalizationPreCompute(state iface.BeaconState, pBal
// # The 1st/2nd most recent epochs are justified, the 1st using the 2nd as source
// if all(bits[0:2]) and old_current_justified_checkpoint.epoch + 1 == current_epoch:
// state.finalized_checkpoint = old_current_justified_checkpoint
func weighJustificationAndFinalization(state iface.BeaconState,
totalActiveBalance, prevEpochTargetBalance, currEpochTargetBalance uint64) (iface.BeaconState, error) {
func weighJustificationAndFinalization(state state.BeaconState,
totalActiveBalance, prevEpochTargetBalance, currEpochTargetBalance uint64) (state.BeaconState, error) {
prevEpoch := helpers.PrevEpoch(state)
currentEpoch := helpers.CurrentEpoch(state)
oldPrevJustifiedCheckpoint := state.PreviousJustifiedCheckpoint()

View File

@@ -8,7 +8,7 @@ import (
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/shared/params"
"go.opencensus.io/trace"
)
@@ -16,17 +16,17 @@ import (
// New gets called at the beginning of process epoch cycle to return
// pre computed instances of validators attesting records and total
// balances attested in an epoch.
func New(ctx context.Context, state iface.BeaconState) ([]*Validator, *Balance, error) {
func New(ctx context.Context, s state.BeaconState) ([]*Validator, *Balance, error) {
ctx, span := trace.StartSpan(ctx, "precomputeEpoch.New")
defer span.End()
pValidators := make([]*Validator, state.NumValidators())
pValidators := make([]*Validator, s.NumValidators())
pBal := &Balance{}
currentEpoch := helpers.CurrentEpoch(state)
prevEpoch := helpers.PrevEpoch(state)
currentEpoch := helpers.CurrentEpoch(s)
prevEpoch := helpers.PrevEpoch(s)
if err := state.ReadFromEveryValidator(func(idx int, val iface.ReadOnlyValidator) error {
if err := s.ReadFromEveryValidator(func(idx int, val state.ReadOnlyValidator) error {
// Was validator withdrawable or slashed
withdrawable := prevEpoch+1 >= val.WithdrawableEpoch()
pVal := &Validator{

View File

@@ -4,23 +4,23 @@ import (
"github.com/pkg/errors"
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/shared/mathutil"
"github.com/prysmaticlabs/prysm/shared/params"
)
type attesterRewardsFunc func(iface.ReadOnlyBeaconState, *Balance, []*Validator) ([]uint64, []uint64, error)
type proposerRewardsFunc func(iface.ReadOnlyBeaconState, *Balance, []*Validator) ([]uint64, error)
type attesterRewardsFunc func(state.ReadOnlyBeaconState, *Balance, []*Validator) ([]uint64, []uint64, error)
type proposerRewardsFunc func(state.ReadOnlyBeaconState, *Balance, []*Validator) ([]uint64, error)
// ProcessRewardsAndPenaltiesPrecompute processes the rewards and penalties of individual validator.
// This is an optimized version by passing in precomputed validator attesting records and and total epoch balances.
func ProcessRewardsAndPenaltiesPrecompute(
state iface.BeaconState,
state state.BeaconState,
pBal *Balance,
vp []*Validator,
attRewardsFunc attesterRewardsFunc,
proRewardsFunc proposerRewardsFunc,
) (iface.BeaconState, error) {
) (state.BeaconState, error) {
// Can't process rewards and penalties in genesis epoch.
if helpers.CurrentEpoch(state) == 0 {
return state, nil
@@ -61,7 +61,7 @@ func ProcessRewardsAndPenaltiesPrecompute(
// AttestationsDelta computes and returns the rewards and penalties differences for individual validators based on the
// voting records.
func AttestationsDelta(state iface.ReadOnlyBeaconState, pBal *Balance, vp []*Validator) ([]uint64, []uint64, error) {
func AttestationsDelta(state state.ReadOnlyBeaconState, pBal *Balance, vp []*Validator) ([]uint64, []uint64, error) {
numOfVals := state.NumValidators()
rewards := make([]uint64, numOfVals)
penalties := make([]uint64, numOfVals)
@@ -152,7 +152,7 @@ func attestationDelta(pBal *Balance, sqrtActiveCurrentEpoch uint64, v *Validator
// ProposersDelta computes and returns the rewards and penalties differences for individual validators based on the
// proposer inclusion records.
func ProposersDelta(state iface.ReadOnlyBeaconState, pBal *Balance, vp []*Validator) ([]uint64, error) {
func ProposersDelta(state state.ReadOnlyBeaconState, pBal *Balance, vp []*Validator) ([]uint64, error) {
numofVals := state.NumValidators()
rewards := make([]uint64, numofVals)

View File

@@ -9,7 +9,7 @@ import (
"github.com/prysmaticlabs/go-bitfield"
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
statepb "github.com/prysmaticlabs/prysm/proto/prysm/v2/state"
@@ -361,7 +361,7 @@ func TestProposerDeltaPrecompute_SlashedCase(t *testing.T) {
// total_balance = get_total_active_balance(state)
// effective_balance = state.validators[index].effective_balance
// return Gwei(effective_balance * BASE_REWARD_FACTOR // integer_squareroot(total_balance) // BASE_REWARDS_PER_EPOCH)
func baseReward(state iface.ReadOnlyBeaconState, index types.ValidatorIndex) (uint64, error) {
func baseReward(state state.ReadOnlyBeaconState, index types.ValidatorIndex) (uint64, error) {
totalBalance, err := helpers.TotalActiveBalance(state)
if err != nil {
return 0, errors.Wrap(err, "could not calculate active balance")

View File

@@ -3,7 +3,7 @@ package precompute
import (
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/mathutil"
"github.com/prysmaticlabs/prysm/shared/params"
@@ -11,12 +11,12 @@ import (
// ProcessSlashingsPrecompute processes the slashed validators during epoch processing.
// This is an optimized version by passing in precomputed total epoch balances.
func ProcessSlashingsPrecompute(state iface.BeaconState, pBal *Balance) error {
currentEpoch := helpers.CurrentEpoch(state)
func ProcessSlashingsPrecompute(s state.BeaconState, pBal *Balance) error {
currentEpoch := helpers.CurrentEpoch(s)
exitLength := params.BeaconConfig().EpochsPerSlashingsVector
// Compute the sum of state slashings
slashings := state.Slashings()
slashings := s.Slashings()
totalSlashing := uint64(0)
for _, slashing := range slashings {
totalSlashing += slashing
@@ -27,7 +27,7 @@ func ProcessSlashingsPrecompute(state iface.BeaconState, pBal *Balance) error {
var hasSlashing bool
// Iterate through validator list in state, stop until a validator satisfies slashing condition of current epoch.
err := state.ReadFromEveryValidator(func(idx int, val iface.ReadOnlyValidator) error {
err := s.ReadFromEveryValidator(func(idx int, val state.ReadOnlyValidator) error {
correctEpoch := epochToWithdraw == val.WithdrawableEpoch()
if val.Slashed() && correctEpoch {
hasSlashing = true
@@ -48,7 +48,7 @@ func ProcessSlashingsPrecompute(state iface.BeaconState, pBal *Balance) error {
if val.Slashed && correctEpoch {
penaltyNumerator := val.EffectiveBalance / increment * minSlashing
penalty := penaltyNumerator / pBal.ActiveCurrentEpoch * increment
if err := helpers.DecreaseBalance(state, types.ValidatorIndex(idx), penalty); err != nil {
if err := helpers.DecreaseBalance(s, types.ValidatorIndex(idx), penalty); err != nil {
return false, val, err
}
return true, val, nil
@@ -56,5 +56,5 @@ func ProcessSlashingsPrecompute(state iface.BeaconState, pBal *Balance) error {
return false, val, nil
}
return state.ApplyToEveryValidator(validatorFunc)
return s.ApplyToEveryValidator(validatorFunc)
}

View File

@@ -35,7 +35,7 @@ go_library(
],
deps = [
"//beacon-chain/cache:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//proto/interfaces:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v2/state:go_default_library",
@@ -74,7 +74,7 @@ go_test(
shard_count = 2,
deps = [
"//beacon-chain/cache:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/v1:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v2/state:go_default_library",

View File

@@ -5,7 +5,7 @@ import (
"github.com/pkg/errors"
types "github.com/prysmaticlabs/eth2-types"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/proto/interfaces"
"github.com/prysmaticlabs/prysm/shared/params"
)
@@ -36,7 +36,7 @@ func VerifyNilBeaconBlock(b interfaces.SignedBeaconBlock) error {
// """
// assert slot < state.slot <= slot + SLOTS_PER_HISTORICAL_ROOT
// return state.block_roots[slot % SLOTS_PER_HISTORICAL_ROOT]
func BlockRootAtSlot(state iface.ReadOnlyBeaconState, slot types.Slot) ([]byte, error) {
func BlockRootAtSlot(state state.ReadOnlyBeaconState, slot types.Slot) ([]byte, error) {
if math.MaxUint64-slot < params.BeaconConfig().SlotsPerHistoricalRoot {
return []byte{}, errors.New("slot overflows uint64")
}
@@ -48,7 +48,7 @@ func BlockRootAtSlot(state iface.ReadOnlyBeaconState, slot types.Slot) ([]byte,
// StateRootAtSlot returns the cached state root at that particular slot. If no state
// root has been cached it will return a zero-hash.
func StateRootAtSlot(state iface.ReadOnlyBeaconState, slot types.Slot) ([]byte, error) {
func StateRootAtSlot(state state.ReadOnlyBeaconState, slot types.Slot) ([]byte, error) {
if slot >= state.Slot() || state.Slot() > slot+params.BeaconConfig().SlotsPerHistoricalRoot {
return []byte{}, errors.Errorf("slot %d out of bounds", slot)
}
@@ -63,7 +63,7 @@ func StateRootAtSlot(state iface.ReadOnlyBeaconState, slot types.Slot) ([]byte,
// Return the block root at the start of a recent ``epoch``.
// """
// return get_block_root_at_slot(state, compute_start_slot_at_epoch(epoch))
func BlockRoot(state iface.ReadOnlyBeaconState, epoch types.Epoch) ([]byte, error) {
func BlockRoot(state state.ReadOnlyBeaconState, epoch types.Epoch) ([]byte, error) {
s, err := StartSlot(epoch)
if err != nil {
return nil, err

View File

@@ -11,7 +11,7 @@ import (
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/go-bitfield"
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/hashutil"
@@ -68,7 +68,7 @@ func SlotCommitteeCount(activeValidatorCount uint64) uint64 {
// index=(slot % SLOTS_PER_EPOCH) * committees_per_slot + index,
// count=committees_per_slot * SLOTS_PER_EPOCH,
// )
func BeaconCommitteeFromState(state iface.ReadOnlyBeaconState, slot types.Slot, committeeIndex types.CommitteeIndex) ([]types.ValidatorIndex, error) {
func BeaconCommitteeFromState(state state.ReadOnlyBeaconState, slot types.Slot, committeeIndex types.CommitteeIndex) ([]types.ValidatorIndex, error) {
epoch := SlotToEpoch(slot)
seed, err := Seed(state, epoch, params.BeaconConfig().DomainBeaconAttester)
if err != nil {
@@ -172,7 +172,7 @@ type CommitteeAssignmentContainer struct {
// 3. Determine the attesting slot for each committee.
// 4. Construct a map of validator indices pointing to the respective committees.
func CommitteeAssignments(
state iface.BeaconState,
state state.BeaconState,
epoch types.Epoch,
) (map[types.ValidatorIndex]*CommitteeAssignmentContainer, map[types.ValidatorIndex][]types.Slot, error) {
nextEpoch := NextEpoch(state)
@@ -255,7 +255,7 @@ func VerifyBitfieldLength(bf bitfield.Bitfield, committeeSize uint64) error {
// VerifyAttestationBitfieldLengths verifies that an attestations aggregation bitfields is
// a valid length matching the size of the committee.
func VerifyAttestationBitfieldLengths(state iface.ReadOnlyBeaconState, att *ethpb.Attestation) error {
func VerifyAttestationBitfieldLengths(state state.ReadOnlyBeaconState, att *ethpb.Attestation) error {
committee, err := BeaconCommitteeFromState(state, att.Data.Slot, att.Data.CommitteeIndex)
if err != nil {
return errors.Wrap(err, "could not retrieve beacon committees")
@@ -273,14 +273,14 @@ func VerifyAttestationBitfieldLengths(state iface.ReadOnlyBeaconState, att *ethp
// ShuffledIndices uses input beacon state and returns the shuffled indices of the input epoch,
// the shuffled indices then can be used to break up into committees.
func ShuffledIndices(state iface.ReadOnlyBeaconState, epoch types.Epoch) ([]types.ValidatorIndex, error) {
seed, err := Seed(state, epoch, params.BeaconConfig().DomainBeaconAttester)
func ShuffledIndices(s state.ReadOnlyBeaconState, epoch types.Epoch) ([]types.ValidatorIndex, error) {
seed, err := Seed(s, epoch, params.BeaconConfig().DomainBeaconAttester)
if err != nil {
return nil, errors.Wrapf(err, "could not get seed for epoch %d", epoch)
}
indices := make([]types.ValidatorIndex, 0, state.NumValidators())
if err := state.ReadFromEveryValidator(func(idx int, val iface.ReadOnlyValidator) error {
indices := make([]types.ValidatorIndex, 0, s.NumValidators())
if err := s.ReadFromEveryValidator(func(idx int, val state.ReadOnlyValidator) error {
if IsActiveValidatorUsingTrie(val, epoch) {
indices = append(indices, types.ValidatorIndex(idx))
}
@@ -295,7 +295,7 @@ func ShuffledIndices(state iface.ReadOnlyBeaconState, epoch types.Epoch) ([]type
// UpdateCommitteeCache gets called at the beginning of every epoch to cache the committee shuffled indices
// list with committee index and epoch number. It caches the shuffled indices for current epoch and next epoch.
func UpdateCommitteeCache(state iface.ReadOnlyBeaconState, epoch types.Epoch) error {
func UpdateCommitteeCache(state state.ReadOnlyBeaconState, epoch types.Epoch) error {
for _, e := range []types.Epoch{epoch, epoch + 1} {
seed, err := Seed(state, e, params.BeaconConfig().DomainBeaconAttester)
if err != nil {
@@ -336,7 +336,7 @@ func UpdateCommitteeCache(state iface.ReadOnlyBeaconState, epoch types.Epoch) er
}
// UpdateProposerIndicesInCache updates proposer indices entry of the committee cache.
func UpdateProposerIndicesInCache(state iface.ReadOnlyBeaconState) error {
func UpdateProposerIndicesInCache(state state.ReadOnlyBeaconState) error {
// The cache uses the state root at the (current epoch - 2)'s slot as key. (e.g. for epoch 2, the key is root at slot 31)
// Which is the reason why we skip genesis epoch.
if CurrentEpoch(state) <= params.BeaconConfig().GenesisEpoch+params.BeaconConfig().MinSeedLookahead {
@@ -391,7 +391,7 @@ func ClearCache() {
// This computes proposer indices of the current epoch and returns a list of proposer indices,
// the index of the list represents the slot number.
func precomputeProposerIndices(state iface.ReadOnlyBeaconState, activeIndices []types.ValidatorIndex) ([]types.ValidatorIndex, error) {
func precomputeProposerIndices(state state.ReadOnlyBeaconState, activeIndices []types.ValidatorIndex) ([]types.ValidatorIndex, error) {
hashFunc := hashutil.CustomSHA256Hasher()
proposerIndices := make([]types.ValidatorIndex, params.BeaconConfig().SlotsPerEpoch)

View File

@@ -4,14 +4,14 @@ import (
"fmt"
"github.com/pkg/errors"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/trieutil"
)
// UpdateGenesisEth1Data updates eth1 data for genesis state.
func UpdateGenesisEth1Data(state iface.BeaconState, deposits []*ethpb.Deposit, eth1Data *ethpb.Eth1Data) (iface.BeaconState, error) {
func UpdateGenesisEth1Data(state state.BeaconState, deposits []*ethpb.Deposit, eth1Data *ethpb.Eth1Data) (state.BeaconState, error) {
if eth1Data == nil {
return nil, errors.New("no eth1data provided for genesis state")
}

View File

@@ -2,7 +2,7 @@ package helpers
import (
types "github.com/prysmaticlabs/eth2-types"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/hashutil"
@@ -18,7 +18,7 @@ import (
// """
// mix = get_randao_mix(state, Epoch(epoch + EPOCHS_PER_HISTORICAL_VECTOR - MIN_SEED_LOOKAHEAD - 1)) # Avoid underflow
// return hash(domain_type + uint_to_bytes(epoch) + mix)
func Seed(state iface.ReadOnlyBeaconState, epoch types.Epoch, domain [bls.DomainByteLength]byte) ([32]byte, error) {
func Seed(state state.ReadOnlyBeaconState, epoch types.Epoch, domain [bls.DomainByteLength]byte) ([32]byte, error) {
// See https://github.com/ethereum/eth2.0-specs/pull/1296 for
// rationale on why offset has to look down by 1.
lookAheadEpoch := epoch + params.BeaconConfig().EpochsPerHistoricalVector -
@@ -45,6 +45,6 @@ func Seed(state iface.ReadOnlyBeaconState, epoch types.Epoch, domain [bls.Domain
// Return the randao mix at a recent ``epoch``.
// """
// return state.randao_mixes[epoch % EPOCHS_PER_HISTORICAL_VECTOR]
func RandaoMix(state iface.ReadOnlyBeaconState, epoch types.Epoch) ([]byte, error) {
func RandaoMix(state state.ReadOnlyBeaconState, epoch types.Epoch) ([]byte, error) {
return state.RandaoMixAtIndex(uint64(epoch % params.BeaconConfig().EpochsPerHistoricalVector))
}

View File

@@ -2,7 +2,7 @@ package helpers
import (
types "github.com/prysmaticlabs/eth2-types"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/shared/params"
)
@@ -17,7 +17,7 @@ import (
// Math safe up to ~10B ETH, afterwhich this overflows uint64.
// """
// return Gwei(max(EFFECTIVE_BALANCE_INCREMENT, sum([state.validators[index].effective_balance for index in indices])))
func TotalBalance(state iface.ReadOnlyValidators, indices []types.ValidatorIndex) uint64 {
func TotalBalance(state state.ReadOnlyValidators, indices []types.ValidatorIndex) uint64 {
total := uint64(0)
for _, idx := range indices {
@@ -46,10 +46,10 @@ func TotalBalance(state iface.ReadOnlyValidators, indices []types.ValidatorIndex
// Note: ``get_total_balance`` returns ``EFFECTIVE_BALANCE_INCREMENT`` Gwei minimum to avoid divisions by zero.
// """
// return get_total_balance(state, set(get_active_validator_indices(state, get_current_epoch(state))))
func TotalActiveBalance(state iface.ReadOnlyBeaconState) (uint64, error) {
func TotalActiveBalance(s state.ReadOnlyBeaconState) (uint64, error) {
total := uint64(0)
epoch := SlotToEpoch(state.Slot())
if err := state.ReadFromEveryValidator(func(idx int, val iface.ReadOnlyValidator) error {
epoch := SlotToEpoch(s.Slot())
if err := s.ReadFromEveryValidator(func(idx int, val state.ReadOnlyValidator) error {
if IsActiveValidatorUsingTrie(val, epoch) {
total += val.EffectiveBalance()
}
@@ -68,7 +68,7 @@ func TotalActiveBalance(state iface.ReadOnlyBeaconState) (uint64, error) {
// Increase the validator balance at index ``index`` by ``delta``.
// """
// state.balances[index] += delta
func IncreaseBalance(state iface.BeaconState, idx types.ValidatorIndex, delta uint64) error {
func IncreaseBalance(state state.BeaconState, idx types.ValidatorIndex, delta uint64) error {
balAtIdx, err := state.BalanceAtIndex(idx)
if err != nil {
return err
@@ -98,7 +98,7 @@ func IncreaseBalanceWithVal(currBalance, delta uint64) uint64 {
// Decrease the validator balance at index ``index`` by ``delta``, with underflow protection.
// """
// state.balances[index] = 0 if delta > state.balances[index] else state.balances[index] - delta
func DecreaseBalance(state iface.BeaconState, idx types.ValidatorIndex, delta uint64) error {
func DecreaseBalance(state state.BeaconState, idx types.ValidatorIndex, delta uint64) error {
balAtIdx, err := state.BalanceAtIndex(idx)
if err != nil {
return err

View File

@@ -4,7 +4,7 @@ import (
fssz "github.com/ferranbt/fastssz"
"github.com/pkg/errors"
types "github.com/prysmaticlabs/eth2-types"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
statepb "github.com/prysmaticlabs/prysm/proto/prysm/v2/state"
"github.com/prysmaticlabs/prysm/shared/bls"
@@ -23,7 +23,7 @@ const DomainByteLength = 4
var ErrSigFailedToVerify = errors.New("signature did not verify")
// ComputeDomainAndSign computes the domain and signing root and sign it using the passed in private key.
func ComputeDomainAndSign(st iface.ReadOnlyBeaconState, epoch types.Epoch, obj fssz.HashRoot, domain [4]byte, key bls.SecretKey) ([]byte, error) {
func ComputeDomainAndSign(st state.ReadOnlyBeaconState, epoch types.Epoch, obj fssz.HashRoot, domain [4]byte, key bls.SecretKey) ([]byte, error) {
d, err := Domain(st.Fork(), epoch, domain, st.GenesisValidatorRoot())
if err != nil {
return nil, err
@@ -65,7 +65,7 @@ func signingData(rootFunc func() ([32]byte, error), domain []byte) ([32]byte, er
}
// ComputeDomainVerifySigningRoot computes domain and verifies signing root of an object given the beacon state, validator index and signature.
func ComputeDomainVerifySigningRoot(st iface.BeaconState, index types.ValidatorIndex, epoch types.Epoch, obj fssz.HashRoot, domain [4]byte, sig []byte) error {
func ComputeDomainVerifySigningRoot(st state.BeaconState, index types.ValidatorIndex, epoch types.Epoch, obj fssz.HashRoot, domain [4]byte, sig []byte) error {
v, err := st.ValidatorAtIndex(index)
if err != nil {
return err

View File

@@ -6,7 +6,7 @@ import (
fuzz "github.com/google/gofuzz"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
statepb "github.com/prysmaticlabs/prysm/proto/prysm/v2/state"
"github.com/prysmaticlabs/prysm/shared/bls"
@@ -47,19 +47,19 @@ func TestSigningRoot_ComputeDomain(t *testing.T) {
func TestSigningRoot_ComputeDomainAndSign(t *testing.T) {
tests := []struct {
name string
genState func(t *testing.T) (iface.BeaconState, []bls.SecretKey)
genBlock func(t *testing.T, st iface.BeaconState, keys []bls.SecretKey) *eth.SignedBeaconBlock
genState func(t *testing.T) (state.BeaconState, []bls.SecretKey)
genBlock func(t *testing.T, st state.BeaconState, keys []bls.SecretKey) *eth.SignedBeaconBlock
domainType [4]byte
want []byte
}{
{
name: "block proposer",
genState: func(t *testing.T) (iface.BeaconState, []bls.SecretKey) {
genState: func(t *testing.T) (state.BeaconState, []bls.SecretKey) {
beaconState, privKeys := testutil.DeterministicGenesisState(t, 100)
require.NoError(t, beaconState.SetSlot(beaconState.Slot()+1))
return beaconState, privKeys
},
genBlock: func(t *testing.T, st iface.BeaconState, keys []bls.SecretKey) *eth.SignedBeaconBlock {
genBlock: func(t *testing.T, st state.BeaconState, keys []bls.SecretKey) *eth.SignedBeaconBlock {
block, err := testutil.GenerateFullBlock(st, keys, nil, 1)
require.NoError(t, err)
return block

View File

@@ -8,7 +8,7 @@ import (
math2 "github.com/ethereum/go-ethereum/common/math"
"github.com/pkg/errors"
types "github.com/prysmaticlabs/eth2-types"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/timeutils"
)
@@ -38,7 +38,7 @@ func SlotToEpoch(slot types.Slot) types.Epoch {
// Return the current epoch.
// """
// return compute_epoch_at_slot(state.slot)
func CurrentEpoch(state iface.ReadOnlyBeaconState) types.Epoch {
func CurrentEpoch(state state.ReadOnlyBeaconState) types.Epoch {
return SlotToEpoch(state.Slot())
}
@@ -53,7 +53,7 @@ func CurrentEpoch(state iface.ReadOnlyBeaconState) types.Epoch {
// """
// current_epoch = get_current_epoch(state)
// return GENESIS_EPOCH if current_epoch == GENESIS_EPOCH else Epoch(current_epoch - 1)
func PrevEpoch(state iface.ReadOnlyBeaconState) types.Epoch {
func PrevEpoch(state state.ReadOnlyBeaconState) types.Epoch {
currentEpoch := CurrentEpoch(state)
if currentEpoch == 0 {
return 0
@@ -63,7 +63,7 @@ func PrevEpoch(state iface.ReadOnlyBeaconState) types.Epoch {
// NextEpoch returns the next epoch number calculated from
// the slot number stored in beacon state.
func NextEpoch(state iface.ReadOnlyBeaconState) types.Epoch {
func NextEpoch(state state.ReadOnlyBeaconState) types.Epoch {
return SlotToEpoch(state.Slot()) + 1
}

View File

@@ -5,7 +5,7 @@ import (
"github.com/pkg/errors"
types "github.com/prysmaticlabs/eth2-types"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
statepb "github.com/prysmaticlabs/prysm/proto/prysm/v2/state"
"github.com/prysmaticlabs/prysm/shared/bls"
@@ -28,7 +28,7 @@ func IsActiveValidator(validator *ethpb.Validator, epoch types.Epoch) bool {
}
// IsActiveValidatorUsingTrie checks if a read only validator is active.
func IsActiveValidatorUsingTrie(validator iface.ReadOnlyValidator, epoch types.Epoch) bool {
func IsActiveValidatorUsingTrie(validator state.ReadOnlyValidator, epoch types.Epoch) bool {
return checkValidatorActiveStatus(validator.ActivationEpoch(), validator.ExitEpoch(), epoch)
}
@@ -50,7 +50,7 @@ func IsSlashableValidator(activationEpoch, withdrawableEpoch types.Epoch, slashe
}
// IsSlashableValidatorUsingTrie checks if a read only validator is slashable.
func IsSlashableValidatorUsingTrie(val iface.ReadOnlyValidator, epoch types.Epoch) bool {
func IsSlashableValidatorUsingTrie(val state.ReadOnlyValidator, epoch types.Epoch) bool {
return checkValidatorSlashable(val.ActivationEpoch(), val.WithdrawableEpoch(), val.Slashed(), epoch)
}
@@ -73,8 +73,8 @@ func checkValidatorSlashable(activationEpoch, withdrawableEpoch types.Epoch, sla
// Return the sequence of active validator indices at ``epoch``.
// """
// return [ValidatorIndex(i) for i, v in enumerate(state.validators) if is_active_validator(v, epoch)]
func ActiveValidatorIndices(state iface.ReadOnlyBeaconState, epoch types.Epoch) ([]types.ValidatorIndex, error) {
seed, err := Seed(state, epoch, params.BeaconConfig().DomainBeaconAttester)
func ActiveValidatorIndices(s state.ReadOnlyBeaconState, epoch types.Epoch) ([]types.ValidatorIndex, error) {
seed, err := Seed(s, epoch, params.BeaconConfig().DomainBeaconAttester)
if err != nil {
return nil, errors.Wrap(err, "could not get seed")
}
@@ -86,7 +86,7 @@ func ActiveValidatorIndices(state iface.ReadOnlyBeaconState, epoch types.Epoch)
return activeIndices, nil
}
var indices []types.ValidatorIndex
if err := state.ReadFromEveryValidator(func(idx int, val iface.ReadOnlyValidator) error {
if err := s.ReadFromEveryValidator(func(idx int, val state.ReadOnlyValidator) error {
if IsActiveValidatorUsingTrie(val, epoch) {
indices = append(indices, types.ValidatorIndex(idx))
}
@@ -95,7 +95,7 @@ func ActiveValidatorIndices(state iface.ReadOnlyBeaconState, epoch types.Epoch)
return nil, err
}
if err := UpdateCommitteeCache(state, epoch); err != nil {
if err := UpdateCommitteeCache(s, epoch); err != nil {
return nil, errors.Wrap(err, "could not update committee cache")
}
@@ -104,8 +104,8 @@ func ActiveValidatorIndices(state iface.ReadOnlyBeaconState, epoch types.Epoch)
// ActiveValidatorCount returns the number of active validators in the state
// at the given epoch.
func ActiveValidatorCount(state iface.ReadOnlyBeaconState, epoch types.Epoch) (uint64, error) {
seed, err := Seed(state, epoch, params.BeaconConfig().DomainBeaconAttester)
func ActiveValidatorCount(s state.ReadOnlyBeaconState, epoch types.Epoch) (uint64, error) {
seed, err := Seed(s, epoch, params.BeaconConfig().DomainBeaconAttester)
if err != nil {
return 0, errors.Wrap(err, "could not get seed")
}
@@ -113,12 +113,12 @@ func ActiveValidatorCount(state iface.ReadOnlyBeaconState, epoch types.Epoch) (u
if err != nil {
return 0, errors.Wrap(err, "could not interface with committee cache")
}
if activeCount != 0 && state.Slot() != 0 {
if activeCount != 0 && s.Slot() != 0 {
return uint64(activeCount), nil
}
count := uint64(0)
if err := state.ReadFromEveryValidator(func(idx int, val iface.ReadOnlyValidator) error {
if err := s.ReadFromEveryValidator(func(idx int, val state.ReadOnlyValidator) error {
if IsActiveValidatorUsingTrie(val, epoch) {
count++
}
@@ -127,7 +127,7 @@ func ActiveValidatorCount(state iface.ReadOnlyBeaconState, epoch types.Epoch) (u
return 0, err
}
if err := UpdateCommitteeCache(state, epoch); err != nil {
if err := UpdateCommitteeCache(s, epoch); err != nil {
return 0, errors.Wrap(err, "could not update committee cache")
}
@@ -176,7 +176,7 @@ func ValidatorChurnLimit(activeValidatorCount uint64) (uint64, error) {
// seed = hash(get_seed(state, epoch, DOMAIN_BEACON_PROPOSER) + uint_to_bytes(state.slot))
// indices = get_active_validator_indices(state, epoch)
// return compute_proposer_index(state, indices, seed)
func BeaconProposerIndex(state iface.ReadOnlyBeaconState) (types.ValidatorIndex, error) {
func BeaconProposerIndex(state state.ReadOnlyBeaconState) (types.ValidatorIndex, error) {
e := CurrentEpoch(state)
// The cache uses the state root of the previous epoch - minimum_seed_lookahead last slot as key. (e.g. Starting epoch 1, slot 32, the key would be block root at slot 31)
// For simplicity, the node will skip caching of genesis epoch.
@@ -244,7 +244,7 @@ func BeaconProposerIndex(state iface.ReadOnlyBeaconState) (types.ValidatorIndex,
// if effective_balance * MAX_RANDOM_BYTE >= MAX_EFFECTIVE_BALANCE * random_byte:
// return candidate_index
// i += 1
func ComputeProposerIndex(bState iface.ReadOnlyValidators, activeIndices []types.ValidatorIndex, seed [32]byte) (types.ValidatorIndex, error) {
func ComputeProposerIndex(bState state.ReadOnlyValidators, activeIndices []types.ValidatorIndex, seed [32]byte) (types.ValidatorIndex, error) {
length := uint64(len(activeIndices))
if length == 0 {
return 0, errors.New("empty active indices list")
@@ -321,7 +321,7 @@ func IsEligibleForActivationQueue(validator *ethpb.Validator) bool {
// IsEligibleForActivationQueueUsingTrie checks if the read-only validator is eligible to
// be placed into the activation queue.
func IsEligibleForActivationQueueUsingTrie(validator iface.ReadOnlyValidator) bool {
func IsEligibleForActivationQueueUsingTrie(validator state.ReadOnlyValidator) bool {
return isEligibileForActivationQueue(validator.ActivationEligibilityEpoch(), validator.EffectiveBalance())
}
@@ -344,13 +344,13 @@ func isEligibileForActivationQueue(activationEligibilityEpoch types.Epoch, effec
// # Has not yet been activated
// and validator.activation_epoch == FAR_FUTURE_EPOCH
// )
func IsEligibleForActivation(state iface.ReadOnlyCheckpoint, validator *ethpb.Validator) bool {
func IsEligibleForActivation(state state.ReadOnlyCheckpoint, validator *ethpb.Validator) bool {
finalizedEpoch := state.FinalizedCheckpointEpoch()
return isEligibleForActivation(validator.ActivationEligibilityEpoch, validator.ActivationEpoch, finalizedEpoch)
}
// IsEligibleForActivationUsingTrie checks if the validator is eligible for activation.
func IsEligibleForActivationUsingTrie(state iface.ReadOnlyCheckpoint, validator iface.ReadOnlyValidator) bool {
func IsEligibleForActivationUsingTrie(state state.ReadOnlyCheckpoint, validator state.ReadOnlyValidator) bool {
cpt := state.FinalizedCheckpoint()
if cpt == nil {
return false

View File

@@ -9,7 +9,7 @@ import (
"strings"
types "github.com/prysmaticlabs/eth2-types"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/mathutil"
"github.com/prysmaticlabs/prysm/shared/params"
@@ -51,7 +51,7 @@ import (
// )
//
// return ws_period
func ComputeWeakSubjectivityPeriod(st iface.ReadOnlyBeaconState) (types.Epoch, error) {
func ComputeWeakSubjectivityPeriod(st state.ReadOnlyBeaconState) (types.Epoch, error) {
// Weak subjectivity period cannot be smaller than withdrawal delay.
wsp := uint64(params.BeaconConfig().MinValidatorWithdrawabilityDelay)
@@ -119,7 +119,7 @@ func ComputeWeakSubjectivityPeriod(st iface.ReadOnlyBeaconState) (types.Epoch, e
// current_epoch = compute_epoch_at_slot(get_current_slot(store))
// return current_epoch <= ws_state_epoch + ws_period
func IsWithinWeakSubjectivityPeriod(
currentEpoch types.Epoch, wsState iface.ReadOnlyBeaconState, wsCheckpoint *eth.WeakSubjectivityCheckpoint) (bool, error) {
currentEpoch types.Epoch, wsState state.ReadOnlyBeaconState, wsCheckpoint *eth.WeakSubjectivityCheckpoint) (bool, error) {
// Make sure that incoming objects are not nil.
if wsState == nil || wsState.IsNil() || wsState.LatestBlockHeader() == nil || wsCheckpoint == nil {
return false, errors.New("invalid weak subjectivity state or checkpoint")
@@ -150,7 +150,7 @@ func IsWithinWeakSubjectivityPeriod(
// Within the weak subjectivity period, if two conflicting blocks are finalized, 1/3 - D (D := safety decay)
// of validators will get slashed. Therefore, it is safe to assume that any finalized checkpoint within that
// period is protected by this safety margin.
func LatestWeakSubjectivityEpoch(st iface.ReadOnlyBeaconState) (types.Epoch, error) {
func LatestWeakSubjectivityEpoch(st state.ReadOnlyBeaconState) (types.Epoch, error) {
wsPeriod, err := ComputeWeakSubjectivityPeriod(st)
if err != nil {
return 0, err

View File

@@ -6,7 +6,7 @@ import (
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/params"
@@ -57,14 +57,14 @@ func TestWeakSubjectivity_IsWithinWeakSubjectivityPeriod(t *testing.T) {
tests := []struct {
name string
epoch types.Epoch
genWsState func() iface.ReadOnlyBeaconState
genWsState func() state.ReadOnlyBeaconState
genWsCheckpoint func() *ethpb.WeakSubjectivityCheckpoint
want bool
wantedErr string
}{
{
name: "nil weak subjectivity state",
genWsState: func() iface.ReadOnlyBeaconState {
genWsState: func() state.ReadOnlyBeaconState {
return nil
},
genWsCheckpoint: func() *ethpb.WeakSubjectivityCheckpoint {
@@ -78,7 +78,7 @@ func TestWeakSubjectivity_IsWithinWeakSubjectivityPeriod(t *testing.T) {
},
{
name: "nil weak subjectivity checkpoint",
genWsState: func() iface.ReadOnlyBeaconState {
genWsState: func() state.ReadOnlyBeaconState {
return genState(t, 128, 32)
},
genWsCheckpoint: func() *ethpb.WeakSubjectivityCheckpoint {
@@ -88,7 +88,7 @@ func TestWeakSubjectivity_IsWithinWeakSubjectivityPeriod(t *testing.T) {
},
{
name: "state and checkpoint roots do not match",
genWsState: func() iface.ReadOnlyBeaconState {
genWsState: func() state.ReadOnlyBeaconState {
beaconState := genState(t, 128, 32)
require.NoError(t, beaconState.SetSlot(42*params.BeaconConfig().SlotsPerEpoch))
err := beaconState.SetLatestBlockHeader(&ethpb.BeaconBlockHeader{
@@ -109,7 +109,7 @@ func TestWeakSubjectivity_IsWithinWeakSubjectivityPeriod(t *testing.T) {
},
{
name: "state and checkpoint epochs do not match",
genWsState: func() iface.ReadOnlyBeaconState {
genWsState: func() state.ReadOnlyBeaconState {
beaconState := genState(t, 128, 32)
require.NoError(t, beaconState.SetSlot(42*params.BeaconConfig().SlotsPerEpoch))
err := beaconState.SetLatestBlockHeader(&ethpb.BeaconBlockHeader{
@@ -129,7 +129,7 @@ func TestWeakSubjectivity_IsWithinWeakSubjectivityPeriod(t *testing.T) {
},
{
name: "no active validators",
genWsState: func() iface.ReadOnlyBeaconState {
genWsState: func() state.ReadOnlyBeaconState {
beaconState := genState(t, 0, 32)
require.NoError(t, beaconState.SetSlot(42*params.BeaconConfig().SlotsPerEpoch))
err := beaconState.SetLatestBlockHeader(&ethpb.BeaconBlockHeader{
@@ -150,7 +150,7 @@ func TestWeakSubjectivity_IsWithinWeakSubjectivityPeriod(t *testing.T) {
{
name: "outside weak subjectivity period",
epoch: 300,
genWsState: func() iface.ReadOnlyBeaconState {
genWsState: func() state.ReadOnlyBeaconState {
beaconState := genState(t, 128, 32)
require.NoError(t, beaconState.SetSlot(42*params.BeaconConfig().SlotsPerEpoch))
err := beaconState.SetLatestBlockHeader(&ethpb.BeaconBlockHeader{
@@ -171,7 +171,7 @@ func TestWeakSubjectivity_IsWithinWeakSubjectivityPeriod(t *testing.T) {
{
name: "within weak subjectivity period",
epoch: 299,
genWsState: func() iface.ReadOnlyBeaconState {
genWsState: func() state.ReadOnlyBeaconState {
beaconState := genState(t, 128, 32)
require.NoError(t, beaconState.SetSlot(42*params.BeaconConfig().SlotsPerEpoch))
err := beaconState.SetLatestBlockHeader(&ethpb.BeaconBlockHeader{
@@ -274,7 +274,7 @@ func TestWeakSubjectivity_ParseWeakSubjectivityInputString(t *testing.T) {
}
}
func genState(t *testing.T, valCount, avgBalance uint64) iface.BeaconState {
func genState(t *testing.T, valCount, avgBalance uint64) state.BeaconState {
beaconState, err := testutil.NewBeaconState()
require.NoError(t, err)

View File

@@ -32,7 +32,7 @@ go_library(
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/core/state/interop:go_default_library",
"//beacon-chain/core/validators:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/v1:go_default_library",
"//proto/interfaces:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
@@ -74,7 +74,7 @@ go_test(
deps = [
"//beacon-chain/core/blocks:go_default_library",
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/v1:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v1alpha1/wrapper:go_default_library",

View File

@@ -6,7 +6,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
coreState "github.com/prysmaticlabs/prysm/beacon-chain/core/state"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
statepb "github.com/prysmaticlabs/prysm/proto/prysm/v2/state"
@@ -61,7 +61,7 @@ func BenchmarkExecuteStateTransition_WithCache(b *testing.B) {
func BenchmarkProcessEpoch_2FullEpochs(b *testing.B) {
benchutil.SetBenchmarkConfig()
beaconState, err := benchutil.PreGenState2FullEpochs()
beaconState, err := benchutil.PreGenstateFullEpochs()
require.NoError(b, err)
// We have to reset slot back to last epoch to hydrate cache. Since
@@ -81,7 +81,7 @@ func BenchmarkProcessEpoch_2FullEpochs(b *testing.B) {
}
func BenchmarkHashTreeRoot_FullState(b *testing.B) {
beaconState, err := benchutil.PreGenState2FullEpochs()
beaconState, err := benchutil.PreGenstateFullEpochs()
require.NoError(b, err)
b.ResetTimer()
@@ -92,7 +92,7 @@ func BenchmarkHashTreeRoot_FullState(b *testing.B) {
}
func BenchmarkHashTreeRootState_FullState(b *testing.B) {
beaconState, err := benchutil.PreGenState2FullEpochs()
beaconState, err := benchutil.PreGenstateFullEpochs()
require.NoError(b, err)
ctx := context.Background()
@@ -109,7 +109,7 @@ func BenchmarkHashTreeRootState_FullState(b *testing.B) {
}
func BenchmarkMarshalState_FullState(b *testing.B) {
beaconState, err := benchutil.PreGenState2FullEpochs()
beaconState, err := benchutil.PreGenstateFullEpochs()
require.NoError(b, err)
natState, err := v1.ProtobufBeaconState(beaconState.InnerStateUnsafe())
require.NoError(b, err)
@@ -133,7 +133,7 @@ func BenchmarkMarshalState_FullState(b *testing.B) {
}
func BenchmarkUnmarshalState_FullState(b *testing.B) {
beaconState, err := benchutil.PreGenState2FullEpochs()
beaconState, err := benchutil.PreGenstateFullEpochs()
require.NoError(b, err)
natState, err := v1.ProtobufBeaconState(beaconState.InnerStateUnsafe())
require.NoError(b, err)
@@ -160,8 +160,8 @@ func BenchmarkUnmarshalState_FullState(b *testing.B) {
})
}
func clonedStates(beaconState iface.BeaconState) []iface.BeaconState {
clonedStates := make([]iface.BeaconState, runAmount)
func clonedStates(beaconState state.BeaconState) []state.BeaconState {
clonedStates := make([]state.BeaconState, runAmount)
for i := 0; i < runAmount; i++ {
clonedStates[i] = beaconState.Copy()
}

View File

@@ -13,7 +13,7 @@ go_library(
"//tools:__subpackages__",
],
deps = [
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//proto/interfaces:go_default_library",
"//shared/featureconfig:go_default_library",
"//shared/fileutil:go_default_library",

View File

@@ -5,13 +5,13 @@ import (
"os"
"path"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/fileutil"
)
// WriteStateToDisk as a state ssz. Writes to temp directory. Debug!
func WriteStateToDisk(state iface.ReadOnlyBeaconState) {
func WriteStateToDisk(state state.ReadOnlyBeaconState) {
if !featureconfig.Get().WriteSSZStateTransitions {
return
}

View File

@@ -5,7 +5,7 @@ import (
"errors"
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/hashutil"
)
@@ -19,7 +19,7 @@ var SkipSlotCache = cache.NewSkipSlotCache()
// The key for skip slot cache is mixed between state root and state slot.
// state root is in the mix to defend against different forks with same skip slots
// to hit the same cache. We don't want beacon states mixed up between different chains.
func cacheKey(ctx context.Context, state iface.ReadOnlyBeaconState) ([32]byte, error) {
func cacheKey(ctx context.Context, state state.ReadOnlyBeaconState) ([32]byte, error) {
bh := state.LatestBlockHeader()
if bh == nil {
return [32]byte{}, errors.New("block head in state can't be nil")

View File

@@ -5,8 +5,8 @@ import (
"sync"
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
core "github.com/prysmaticlabs/prysm/beacon-chain/core/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
"github.com/prysmaticlabs/prysm/shared/params"
@@ -16,8 +16,8 @@ import (
)
func TestSkipSlotCache_OK(t *testing.T) {
state.SkipSlotCache.Enable()
defer state.SkipSlotCache.Disable()
core.SkipSlotCache.Enable()
defer core.SkipSlotCache.Disable()
bState, privs := testutil.DeterministicGenesisState(t, params.MinimalSpecConfig().MinGenesisActiveValidatorCount)
pbState, err := v1.ProtobufBeaconState(bState.CloneInnerState())
require.NoError(t, err)
@@ -31,11 +31,11 @@ func TestSkipSlotCache_OK(t *testing.T) {
// with the state
blk, err := testutil.GenerateFullBlock(bState, privs, blkCfg, originalState.Slot()+10)
require.NoError(t, err)
executedState, err := state.ExecuteStateTransition(context.Background(), originalState, wrapper.WrappedPhase0SignedBeaconBlock(blk))
executedState, err := core.ExecuteStateTransition(context.Background(), originalState, wrapper.WrappedPhase0SignedBeaconBlock(blk))
require.NoError(t, err, "Could not run state transition")
originalState, ok := executedState.(*v1.BeaconState)
require.Equal(t, true, ok)
bState, err = state.ExecuteStateTransition(context.Background(), bState, wrapper.WrappedPhase0SignedBeaconBlock(blk))
bState, err = core.ExecuteStateTransition(context.Background(), bState, wrapper.WrappedPhase0SignedBeaconBlock(blk))
require.NoError(t, err, "Could not process state transition")
assert.DeepEqual(t, originalState.CloneInnerState(), bState.CloneInnerState(), "Skipped slots cache leads to different states")
@@ -51,19 +51,19 @@ func TestSkipSlotCache_ConcurrentMixup(t *testing.T) {
blkCfg := testutil.DefaultBlockGenConfig()
blkCfg.NumAttestations = 1
state.SkipSlotCache.Disable()
core.SkipSlotCache.Disable()
// First transition will be with an empty cache, so the cache becomes populated
// with the state
blk, err := testutil.GenerateFullBlock(bState, privs, blkCfg, originalState.Slot()+10)
require.NoError(t, err)
executedState, err := state.ExecuteStateTransition(context.Background(), originalState, wrapper.WrappedPhase0SignedBeaconBlock(blk))
executedState, err := core.ExecuteStateTransition(context.Background(), originalState, wrapper.WrappedPhase0SignedBeaconBlock(blk))
require.NoError(t, err, "Could not run state transition")
originalState, ok := executedState.(*v1.BeaconState)
require.Equal(t, true, ok)
// Create two shallow but different forks
var state1, state2 iface.BeaconState
var s1, s0 state.BeaconState
{
blk, err := testutil.GenerateFullBlock(originalState.Copy(), privs, blkCfg, originalState.Slot()+10)
require.NoError(t, err)
@@ -71,7 +71,7 @@ func TestSkipSlotCache_ConcurrentMixup(t *testing.T) {
signature, err := testutil.BlockSignature(originalState, blk.Block, privs)
require.NoError(t, err)
blk.Signature = signature.Marshal()
state1, err = state.ExecuteStateTransition(context.Background(), originalState.Copy(), wrapper.WrappedPhase0SignedBeaconBlock(blk))
s1, err = core.ExecuteStateTransition(context.Background(), originalState.Copy(), wrapper.WrappedPhase0SignedBeaconBlock(blk))
require.NoError(t, err, "Could not run state transition")
}
@@ -82,53 +82,53 @@ func TestSkipSlotCache_ConcurrentMixup(t *testing.T) {
signature, err := testutil.BlockSignature(originalState, blk.Block, privs)
require.NoError(t, err)
blk.Signature = signature.Marshal()
state2, err = state.ExecuteStateTransition(context.Background(), originalState.Copy(), wrapper.WrappedPhase0SignedBeaconBlock(blk))
s0, err = core.ExecuteStateTransition(context.Background(), originalState.Copy(), wrapper.WrappedPhase0SignedBeaconBlock(blk))
require.NoError(t, err, "Could not run state transition")
}
r1, err := state1.HashTreeRoot(context.Background())
r1, err := s1.HashTreeRoot(context.Background())
require.NoError(t, err)
r2, err := state2.HashTreeRoot(context.Background())
r2, err := s0.HashTreeRoot(context.Background())
require.NoError(t, err)
if r1 == r2 {
t.Fatalf("need different starting states, got: %x", r1)
}
if state1.Slot() != state2.Slot() {
if s1.Slot() != s0.Slot() {
t.Fatalf("expecting different chains, but states at same slot")
}
// prepare copies for both states
var setups []iface.BeaconState
var setups []state.BeaconState
for i := uint64(0); i < 300; i++ {
var st iface.BeaconState
var st state.BeaconState
if i%2 == 0 {
st = state1
st = s1
} else {
st = state2
st = s0
}
setups = append(setups, st.Copy())
}
problemSlot := state1.Slot() + 2
expected1, err := state.ProcessSlots(context.Background(), state1.Copy(), problemSlot)
problemSlot := s1.Slot() + 2
expected1, err := core.ProcessSlots(context.Background(), s1.Copy(), problemSlot)
require.NoError(t, err)
expectedRoot1, err := expected1.HashTreeRoot(context.Background())
require.NoError(t, err)
t.Logf("chain 1 (even i) expected root %x at slot %d", expectedRoot1[:], problemSlot)
tmp1, err := state.ProcessSlots(context.Background(), expected1.Copy(), problemSlot+1)
tmp1, err := core.ProcessSlots(context.Background(), expected1.Copy(), problemSlot+1)
require.NoError(t, err)
gotRoot := tmp1.StateRoots()[problemSlot]
require.DeepEqual(t, expectedRoot1[:], gotRoot, "State roots for chain 1 are bad, expected root doesn't match")
expected2, err := state.ProcessSlots(context.Background(), state2.Copy(), problemSlot)
expected2, err := core.ProcessSlots(context.Background(), s0.Copy(), problemSlot)
require.NoError(t, err)
expectedRoot2, err := expected2.HashTreeRoot(context.Background())
require.NoError(t, err)
t.Logf("chain 2 (odd i) expected root %x at slot %d", expectedRoot2[:], problemSlot)
tmp2, err := state.ProcessSlots(context.Background(), expected2.Copy(), problemSlot+1)
tmp2, err := core.ProcessSlots(context.Background(), expected2.Copy(), problemSlot+1)
require.NoError(t, err)
gotRoot = tmp2.StateRoots()[problemSlot]
require.DeepEqual(t, expectedRoot2[:], gotRoot, "State roots for chain 2 are bad, expected root doesn't match")
@@ -136,9 +136,9 @@ func TestSkipSlotCache_ConcurrentMixup(t *testing.T) {
var wg sync.WaitGroup
wg.Add(len(setups))
step := func(i int, setup iface.BeaconState) {
step := func(i int, setup state.BeaconState) {
// go at least 1 past problemSlot, to ensure problem slot state root is available
outState, err := state.ProcessSlots(context.Background(), setup, problemSlot.Add(1+uint64(i))) // keep increasing, to hit and extend the cache
outState, err := core.ProcessSlots(context.Background(), setup, problemSlot.Add(1+uint64(i))) // keep increasing, to hit and extend the cache
require.NoError(t, err, "Could not process state transition")
roots := outState.StateRoots()
gotRoot := roots[problemSlot]
@@ -150,7 +150,7 @@ func TestSkipSlotCache_ConcurrentMixup(t *testing.T) {
wg.Done()
}
state.SkipSlotCache.Enable()
core.SkipSlotCache.Enable()
// now concurrently apply the blocks (alternating between states, and increasing skip slots)
for i, setup := range setups {
go step(i, setup)

View File

@@ -9,7 +9,7 @@ import (
"github.com/pkg/errors"
b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
statepb "github.com/prysmaticlabs/prysm/proto/prysm/v2/state"
@@ -56,7 +56,7 @@ import (
//
// return state
// This method differs from the spec so as to process deposits beforehand instead of the end of the function.
func GenesisBeaconState(ctx context.Context, deposits []*ethpb.Deposit, genesisTime uint64, eth1Data *ethpb.Eth1Data) (iface.BeaconState, error) {
func GenesisBeaconState(ctx context.Context, deposits []*ethpb.Deposit, genesisTime uint64, eth1Data *ethpb.Eth1Data) (state.BeaconState, error) {
state, err := EmptyGenesisState()
if err != nil {
return nil, err
@@ -78,7 +78,7 @@ func GenesisBeaconState(ctx context.Context, deposits []*ethpb.Deposit, genesisT
// OptimizedGenesisBeaconState is used to create a state that has already processed deposits. This is to efficiently
// create a mainnet state at chainstart.
func OptimizedGenesisBeaconState(genesisTime uint64, preState iface.BeaconState, eth1Data *ethpb.Eth1Data) (iface.BeaconState, error) {
func OptimizedGenesisBeaconState(genesisTime uint64, preState state.BeaconState, eth1Data *ethpb.Eth1Data) (state.BeaconState, error) {
if eth1Data == nil {
return nil, errors.New("no eth1data provided for genesis state")
}
@@ -183,7 +183,7 @@ func OptimizedGenesisBeaconState(genesisTime uint64, preState iface.BeaconState,
}
// EmptyGenesisState returns an empty beacon state object.
func EmptyGenesisState() (iface.BeaconState, error) {
func EmptyGenesisState() (state.BeaconState, error) {
state := &statepb.BeaconState{
// Misc fields.
Slot: 0,

View File

@@ -96,16 +96,16 @@ func TestGenesisState_HashEquality(t *testing.T) {
require.NoError(t, err)
state1, err := state.GenesisBeaconState(context.Background(), deposits, 0, &ethpb.Eth1Data{BlockHash: make([]byte, 32)})
require.NoError(t, err)
state2, err := state.GenesisBeaconState(context.Background(), deposits, 0, &ethpb.Eth1Data{BlockHash: make([]byte, 32)})
state, err := state.GenesisBeaconState(context.Background(), deposits, 0, &ethpb.Eth1Data{BlockHash: make([]byte, 32)})
require.NoError(t, err)
pbState1, err := v1.ProtobufBeaconState(state1.CloneInnerState())
require.NoError(t, err)
pbState2, err := v1.ProtobufBeaconState(state2.CloneInnerState())
pbstate, err := v1.ProtobufBeaconState(state.CloneInnerState())
require.NoError(t, err)
root1, err1 := hashutil.HashProto(pbState1)
root2, err2 := hashutil.HashProto(pbState2)
root2, err2 := hashutil.HashProto(pbstate)
if err1 != nil || err2 != nil {
t.Fatalf("Failed to marshal state to bytes: %v %v", err1, err2)

View File

@@ -7,13 +7,13 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
)
type nextSlotCache struct {
sync.RWMutex
root []byte
state iface.BeaconState
state state.BeaconState
}
var (
@@ -32,7 +32,7 @@ var (
// NextSlotState returns the saved state if the input root matches the root in `nextSlotCache`. Returns nil otherwise.
// This is useful to check before processing slots. With a cache hit, it will return last processed state with slot plus
// one advancement.
func NextSlotState(ctx context.Context, root []byte) (iface.BeaconState, error) {
func NextSlotState(ctx context.Context, root []byte) (state.BeaconState, error) {
nsc.RLock()
defer nsc.RUnlock()
if !bytes.Equal(root, nsc.root) {
@@ -47,7 +47,7 @@ func NextSlotState(ctx context.Context, root []byte) (iface.BeaconState, error)
// UpdateNextSlotCache updates the `nextSlotCache`. It saves the input state after advancing the state slot by 1
// by calling `ProcessSlots`, it also saves the input root for later look up.
// This is useful to call after successfully processing a block.
func UpdateNextSlotCache(ctx context.Context, root []byte, state iface.BeaconState) error {
func UpdateNextSlotCache(ctx context.Context, root []byte, state state.BeaconState) error {
// Advancing one slot by using a copied state.
copied := state.Copy()
copied, err := ProcessSlots(ctx, copied, copied.Slot()+1)

View File

@@ -16,7 +16,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch/precompute"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
v "github.com/prysmaticlabs/prysm/beacon-chain/core/validators"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/proto/interfaces"
"github.com/prysmaticlabs/prysm/shared/mathutil"
"github.com/prysmaticlabs/prysm/shared/params"
@@ -25,24 +25,24 @@ import (
)
// processFunc is a function that processes a block with a given state. State is mutated.
type processFunc func(context.Context, iface.BeaconState, interfaces.SignedBeaconBlock) (iface.BeaconState, error)
type processFunc func(context.Context, state.BeaconState, interfaces.SignedBeaconBlock) (state.BeaconState, error)
var processDepositsFunc = func(ctx context.Context, s iface.BeaconState, blk interfaces.SignedBeaconBlock) (iface.BeaconState, error) {
var processDepositsFunc = func(ctx context.Context, s state.BeaconState, blk interfaces.SignedBeaconBlock) (state.BeaconState, error) {
return b.ProcessDeposits(ctx, s, blk.Block().Body().Deposits())
}
var processProposerSlashingFunc = func(ctx context.Context, s iface.BeaconState, blk interfaces.SignedBeaconBlock) (iface.BeaconState, error) {
var processProposerSlashingFunc = func(ctx context.Context, s state.BeaconState, blk interfaces.SignedBeaconBlock) (state.BeaconState, error) {
return b.ProcessProposerSlashings(ctx, s, blk.Block().Body().ProposerSlashings(), v.SlashValidator)
}
var processAttesterSlashingFunc = func(ctx context.Context, s iface.BeaconState, blk interfaces.SignedBeaconBlock) (iface.BeaconState, error) {
var processAttesterSlashingFunc = func(ctx context.Context, s state.BeaconState, blk interfaces.SignedBeaconBlock) (state.BeaconState, error) {
return b.ProcessAttesterSlashings(ctx, s, blk.Block().Body().AttesterSlashings(), v.SlashValidator)
}
var processEth1DataFunc = func(ctx context.Context, s iface.BeaconState, blk interfaces.SignedBeaconBlock) (iface.BeaconState, error) {
var processEth1DataFunc = func(ctx context.Context, s state.BeaconState, blk interfaces.SignedBeaconBlock) (state.BeaconState, error) {
return b.ProcessEth1DataInBlock(ctx, s, blk.Block().Body().Eth1Data())
}
var processExitFunc = func(ctx context.Context, s iface.BeaconState, blk interfaces.SignedBeaconBlock) (iface.BeaconState, error) {
var processExitFunc = func(ctx context.Context, s state.BeaconState, blk interfaces.SignedBeaconBlock) (state.BeaconState, error) {
return b.ProcessVoluntaryExits(ctx, s, blk.Block().Body().VoluntaryExits())
}
@@ -80,9 +80,9 @@ var processingPipeline = []processFunc{
// assert block.state_root == hash_tree_root(state)
func ExecuteStateTransition(
ctx context.Context,
state iface.BeaconState,
state state.BeaconState,
signed interfaces.SignedBeaconBlock,
) (iface.BeaconState, error) {
) (state.BeaconState, error) {
if ctx.Err() != nil {
return nil, ctx.Err()
}
@@ -123,7 +123,7 @@ func ExecuteStateTransition(
// # Cache block root
// previous_block_root = hash_tree_root(state.latest_block_header)
// state.block_roots[state.slot % SLOTS_PER_HISTORICAL_ROOT] = previous_block_root
func ProcessSlot(ctx context.Context, state iface.BeaconState) (iface.BeaconState, error) {
func ProcessSlot(ctx context.Context, state state.BeaconState) (state.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "core.state.ProcessSlot")
defer span.End()
span.AddAttributes(trace.Int64Attribute("slot", int64(state.Slot())))
@@ -166,9 +166,9 @@ func ProcessSlot(ctx context.Context, state iface.BeaconState) (iface.BeaconStat
// ProcessSlotsUsingNextSlotCache processes slots by using next slot cache for higher efficiency.
func ProcessSlotsUsingNextSlotCache(
ctx context.Context,
parentState iface.BeaconState,
parentState state.BeaconState,
parentRoot []byte,
slot types.Slot) (iface.BeaconState, error) {
slot types.Slot) (state.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "core.state.ProcessSlotsUsingNextSlotCache")
defer span.End()
@@ -205,7 +205,7 @@ func ProcessSlotsUsingNextSlotCache(
// if (state.slot + 1) % SLOTS_PER_EPOCH == 0:
// process_epoch(state)
// state.slot = Slot(state.slot + 1)
func ProcessSlots(ctx context.Context, state iface.BeaconState, slot types.Slot) (iface.BeaconState, error) {
func ProcessSlots(ctx context.Context, state state.BeaconState, slot types.Slot) (state.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "core.state.ProcessSlots")
defer span.End()
if state == nil || state.IsNil() {
@@ -307,9 +307,9 @@ func ProcessSlots(ctx context.Context, state iface.BeaconState, slot types.Slot)
// process_operations(state, block.body)
func ProcessBlock(
ctx context.Context,
state iface.BeaconState,
state state.BeaconState,
signed interfaces.SignedBeaconBlock,
) (iface.BeaconState, error) {
) (state.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "core.state.ProcessBlock")
defer span.End()
@@ -329,7 +329,7 @@ func ProcessBlock(
}
// VerifyOperationLengths verifies that block operation lengths are valid.
func VerifyOperationLengths(_ context.Context, state iface.BeaconState, b interfaces.SignedBeaconBlock) (iface.BeaconState, error) {
func VerifyOperationLengths(_ context.Context, state state.BeaconState, b interfaces.SignedBeaconBlock) (state.BeaconState, error) {
if err := helpers.VerifyNilBeaconBlock(b); err != nil {
return nil, err
}
@@ -388,13 +388,13 @@ func VerifyOperationLengths(_ context.Context, state iface.BeaconState, b interf
//
// Spec pseudocode definition:
// If (state.slot + 1) % SLOTS_PER_EPOCH == 0:
func CanProcessEpoch(state iface.ReadOnlyBeaconState) bool {
func CanProcessEpoch(state state.ReadOnlyBeaconState) bool {
return (state.Slot()+1)%params.BeaconConfig().SlotsPerEpoch == 0
}
// ProcessEpochPrecompute describes the per epoch operations that are performed on the beacon state.
// It's optimized by pre computing validator attested info and epoch total/attested balances upfront.
func ProcessEpochPrecompute(ctx context.Context, state iface.BeaconState) (iface.BeaconState, error) {
func ProcessEpochPrecompute(ctx context.Context, state state.BeaconState) (state.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "core.state.ProcessEpochPrecompute")
defer span.End()
span.AddAttributes(trace.Int64Attribute("epoch", int64(helpers.CurrentEpoch(state))))

View File

@@ -10,7 +10,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state/interop"
v "github.com/prysmaticlabs/prysm/beacon-chain/core/validators"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/proto/interfaces"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
@@ -41,9 +41,9 @@ import (
// assert block.state_root == hash_tree_root(state)
func ExecuteStateTransitionNoVerifyAnySig(
ctx context.Context,
state iface.BeaconState,
state state.BeaconState,
signed interfaces.SignedBeaconBlock,
) (*bls.SignatureSet, iface.BeaconState, error) {
) (*bls.SignatureSet, state.BeaconState, error) {
if ctx.Err() != nil {
return nil, nil, ctx.Err()
}
@@ -112,7 +112,7 @@ func ExecuteStateTransitionNoVerifyAnySig(
// assert block.state_root == hash_tree_root(state)
func CalculateStateRoot(
ctx context.Context,
state iface.BeaconState,
state state.BeaconState,
signed interfaces.SignedBeaconBlock,
) ([32]byte, error) {
ctx, span := trace.StartSpan(ctx, "core.state.CalculateStateRoot")
@@ -168,9 +168,9 @@ func CalculateStateRoot(
// process_operations(state, block.body)
func ProcessBlockNoVerifyAnySig(
ctx context.Context,
state iface.BeaconState,
state state.BeaconState,
signed interfaces.SignedBeaconBlock,
) (*bls.SignatureSet, iface.BeaconState, error) {
) (*bls.SignatureSet, state.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "core.state.ProcessBlockNoVerifyAnySig")
defer span.End()
if err := helpers.VerifyNilBeaconBlock(signed); err != nil {
@@ -228,8 +228,8 @@ func ProcessBlockNoVerifyAnySig(
// for_ops(body.voluntary_exits, process_voluntary_exit)
func ProcessOperationsNoVerifyAttsSigs(
ctx context.Context,
state iface.BeaconState,
signedBeaconBlock interfaces.SignedBeaconBlock) (iface.BeaconState, error) {
state state.BeaconState,
signedBeaconBlock interfaces.SignedBeaconBlock) (state.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "core.state.ProcessOperationsNoVerifyAttsSigs")
defer span.End()
if err := helpers.VerifyNilBeaconBlock(signedBeaconBlock); err != nil {
@@ -268,9 +268,9 @@ func ProcessOperationsNoVerifyAttsSigs(
// and randao signature verifications.
func ProcessBlockForStateRoot(
ctx context.Context,
state iface.BeaconState,
state state.BeaconState,
signed interfaces.SignedBeaconBlock,
) (iface.BeaconState, error) {
) (state.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "core.state.ProcessBlockForStateRoot")
defer span.End()
if err := helpers.VerifyNilBeaconBlock(signed); err != nil {

View File

@@ -10,8 +10,8 @@ import (
"github.com/prysmaticlabs/go-bitfield"
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
core "github.com/prysmaticlabs/prysm/beacon-chain/core/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
@@ -29,7 +29,7 @@ import (
)
func init() {
state.SkipSlotCache.Disable()
core.SkipSlotCache.Disable()
}
func TestExecuteStateTransition_IncorrectSlot(t *testing.T) {
@@ -45,7 +45,7 @@ func TestExecuteStateTransition_IncorrectSlot(t *testing.T) {
},
}
want := "expected state.slot"
_, err = state.ExecuteStateTransition(context.Background(), beaconState, wrapper.WrappedPhase0SignedBeaconBlock(block))
_, err = core.ExecuteStateTransition(context.Background(), beaconState, wrapper.WrappedPhase0SignedBeaconBlock(block))
assert.ErrorContains(t, want, err)
}
@@ -75,7 +75,7 @@ func TestExecuteStateTransition_FullProcess(t *testing.T) {
require.NoError(t, err)
require.NoError(t, beaconState.SetSlot(beaconState.Slot()-1))
nextSlotState, err := state.ProcessSlots(context.Background(), beaconState.Copy(), beaconState.Slot()+1)
nextSlotState, err := core.ProcessSlots(context.Background(), beaconState.Copy(), beaconState.Slot()+1)
require.NoError(t, err)
parentRoot, err := nextSlotState.LatestBlockHeader().HashTreeRoot()
require.NoError(t, err)
@@ -88,7 +88,7 @@ func TestExecuteStateTransition_FullProcess(t *testing.T) {
block.Block.Body.RandaoReveal = randaoReveal
block.Block.Body.Eth1Data = eth1Data
stateRoot, err := state.CalculateStateRoot(context.Background(), beaconState, wrapper.WrappedPhase0SignedBeaconBlock(block))
stateRoot, err := core.CalculateStateRoot(context.Background(), beaconState, wrapper.WrappedPhase0SignedBeaconBlock(block))
require.NoError(t, err)
block.Block.StateRoot = stateRoot[:]
@@ -97,7 +97,7 @@ func TestExecuteStateTransition_FullProcess(t *testing.T) {
require.NoError(t, err)
block.Signature = sig.Marshal()
beaconState, err = state.ExecuteStateTransition(context.Background(), beaconState, wrapper.WrappedPhase0SignedBeaconBlock(block))
beaconState, err = core.ExecuteStateTransition(context.Background(), beaconState, wrapper.WrappedPhase0SignedBeaconBlock(block))
require.NoError(t, err)
assert.Equal(t, params.BeaconConfig().SlotsPerEpoch, beaconState.Slot(), "Unexpected Slot number")
@@ -133,10 +133,10 @@ func TestProcessBlock_IncorrectProposerSlashing(t *testing.T) {
block.Signature, err = helpers.ComputeDomainAndSign(beaconState, helpers.CurrentEpoch(beaconState), block.Block, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerIdx])
require.NoError(t, err)
beaconState, err = state.ProcessSlots(context.Background(), beaconState, 1)
beaconState, err = core.ProcessSlots(context.Background(), beaconState, 1)
require.NoError(t, err)
want := "could not verify proposer slashing"
_, err = state.ProcessBlock(context.Background(), beaconState, wrapper.WrappedPhase0SignedBeaconBlock(block))
_, err = core.ProcessBlock(context.Background(), beaconState, wrapper.WrappedPhase0SignedBeaconBlock(block))
assert.ErrorContains(t, want, err)
}
@@ -159,11 +159,11 @@ func TestProcessBlock_IncorrectProcessBlockAttestations(t *testing.T) {
block.Signature, err = helpers.ComputeDomainAndSign(beaconState, helpers.CurrentEpoch(beaconState), block.Block, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerIdx])
require.NoError(t, err)
beaconState, err = state.ProcessSlots(context.Background(), beaconState, 1)
beaconState, err = core.ProcessSlots(context.Background(), beaconState, 1)
require.NoError(t, err)
want := "could not verify attestation"
_, err = state.ProcessBlock(context.Background(), beaconState, wrapper.WrappedPhase0SignedBeaconBlock(block))
_, err = core.ProcessBlock(context.Background(), beaconState, wrapper.WrappedPhase0SignedBeaconBlock(block))
assert.ErrorContains(t, want, err)
}
@@ -244,12 +244,12 @@ func TestProcessBlock_IncorrectProcessExits(t *testing.T) {
cp.Root = []byte("hello-world")
require.NoError(t, beaconState.SetCurrentJustifiedCheckpoint(cp))
require.NoError(t, beaconState.AppendCurrentEpochAttestations(&statepb.PendingAttestation{}))
_, err = state.VerifyOperationLengths(context.Background(), beaconState, wrapper.WrappedPhase0SignedBeaconBlock(block))
_, err = core.VerifyOperationLengths(context.Background(), beaconState, wrapper.WrappedPhase0SignedBeaconBlock(block))
wanted := "number of voluntary exits (17) in block body exceeds allowed threshold of 16"
assert.ErrorContains(t, wanted, err)
}
func createFullBlockWithOperations(t *testing.T) (iface.BeaconState,
func createFullBlockWithOperations(t *testing.T) (state.BeaconState,
*ethpb.SignedBeaconBlock, []*ethpb.Attestation, []*ethpb.ProposerSlashing, []*ethpb.SignedVoluntaryExit) {
beaconState, privKeys := testutil.DeterministicGenesisState(t, 32)
genesisBlock := blocks.NewGenesisBlock([]byte{})
@@ -425,7 +425,7 @@ func TestProcessBlock_PassesProcessingConditions(t *testing.T) {
beaconState, block, _, proposerSlashings, exits := createFullBlockWithOperations(t)
exit := exits[0]
beaconState, err := state.ProcessBlock(context.Background(), beaconState, wrapper.WrappedPhase0SignedBeaconBlock(block))
beaconState, err := core.ProcessBlock(context.Background(), beaconState, wrapper.WrappedPhase0SignedBeaconBlock(block))
require.NoError(t, err, "Expected block to pass processing conditions")
v, err := beaconState.ValidatorAtIndex(proposerSlashings[0].Header_1.Header.ProposerIndex)
@@ -460,7 +460,7 @@ func TestProcessEpochPrecompute_CanProcess(t *testing.T) {
s, err := v1.InitializeFromProto(base)
require.NoError(t, err)
require.NoError(t, s.SetValidators([]*ethpb.Validator{}))
newState, err := state.ProcessEpochPrecompute(context.Background(), s)
newState, err := core.ProcessEpochPrecompute(context.Background(), s)
require.NoError(t, err)
assert.Equal(t, uint64(0), newState.Slashings()[2], "Unexpected slashed balance")
}
@@ -617,7 +617,7 @@ func BenchmarkProcessBlk_65536Validators_FullBlock(b *testing.B) {
b.ResetTimer()
for n := 0; n < b.N; n++ {
_, err := state.ProcessBlock(context.Background(), s, wrapper.WrappedPhase0SignedBeaconBlock(blk))
_, err := core.ProcessBlock(context.Background(), s, wrapper.WrappedPhase0SignedBeaconBlock(blk))
require.NoError(b, err)
// Reset state fields to process block again
v := s.Validators()
@@ -701,7 +701,7 @@ func TestProcessBlk_AttsBasedOnValidatorCount(t *testing.T) {
params.OverrideBeaconConfig(config)
require.NoError(t, s.SetSlot(s.Slot()+1))
_, err = state.ProcessBlock(context.Background(), s, wrapper.WrappedPhase0SignedBeaconBlock(blk))
_, err = core.ProcessBlock(context.Background(), s, wrapper.WrappedPhase0SignedBeaconBlock(blk))
require.NoError(t, err)
}
@@ -733,7 +733,7 @@ func TestCanProcessEpoch_TrueOnEpochs(t *testing.T) {
b := &statepb.BeaconState{Slot: tt.slot}
s, err := v1.InitializeFromProto(b)
require.NoError(t, err)
assert.Equal(t, tt.canProcessEpoch, state.CanProcessEpoch(s), "CanProcessEpoch(%d)", tt.slot)
assert.Equal(t, tt.canProcessEpoch, core.CanProcessEpoch(s), "CanProcessEpoch(%d)", tt.slot)
}
}
@@ -748,7 +748,7 @@ func TestProcessBlock_OverMaxProposerSlashings(t *testing.T) {
}
want := fmt.Sprintf("number of proposer slashings (%d) in block body exceeds allowed threshold of %d",
len(b.Block.Body.ProposerSlashings), params.BeaconConfig().MaxProposerSlashings)
_, err := state.VerifyOperationLengths(context.Background(), &v1.BeaconState{}, wrapper.WrappedPhase0SignedBeaconBlock(b))
_, err := core.VerifyOperationLengths(context.Background(), &v1.BeaconState{}, wrapper.WrappedPhase0SignedBeaconBlock(b))
assert.ErrorContains(t, want, err)
}
@@ -763,7 +763,7 @@ func TestProcessBlock_OverMaxAttesterSlashings(t *testing.T) {
}
want := fmt.Sprintf("number of attester slashings (%d) in block body exceeds allowed threshold of %d",
len(b.Block.Body.AttesterSlashings), params.BeaconConfig().MaxAttesterSlashings)
_, err := state.VerifyOperationLengths(context.Background(), &v1.BeaconState{}, wrapper.WrappedPhase0SignedBeaconBlock(b))
_, err := core.VerifyOperationLengths(context.Background(), &v1.BeaconState{}, wrapper.WrappedPhase0SignedBeaconBlock(b))
assert.ErrorContains(t, want, err)
}
@@ -777,7 +777,7 @@ func TestProcessBlock_OverMaxAttestations(t *testing.T) {
}
want := fmt.Sprintf("number of attestations (%d) in block body exceeds allowed threshold of %d",
len(b.Block.Body.Attestations), params.BeaconConfig().MaxAttestations)
_, err := state.VerifyOperationLengths(context.Background(), &v1.BeaconState{}, wrapper.WrappedPhase0SignedBeaconBlock(b))
_, err := core.VerifyOperationLengths(context.Background(), &v1.BeaconState{}, wrapper.WrappedPhase0SignedBeaconBlock(b))
assert.ErrorContains(t, want, err)
}
@@ -792,7 +792,7 @@ func TestProcessBlock_OverMaxVoluntaryExits(t *testing.T) {
}
want := fmt.Sprintf("number of voluntary exits (%d) in block body exceeds allowed threshold of %d",
len(b.Block.Body.VoluntaryExits), maxExits)
_, err := state.VerifyOperationLengths(context.Background(), &v1.BeaconState{}, wrapper.WrappedPhase0SignedBeaconBlock(b))
_, err := core.VerifyOperationLengths(context.Background(), &v1.BeaconState{}, wrapper.WrappedPhase0SignedBeaconBlock(b))
assert.ErrorContains(t, want, err)
}
@@ -812,7 +812,7 @@ func TestProcessBlock_IncorrectDeposits(t *testing.T) {
}
want := fmt.Sprintf("incorrect outstanding deposits in block body, wanted: %d, got: %d",
s.Eth1Data().DepositCount-s.Eth1DepositIndex(), len(b.Block.Body.Deposits))
_, err = state.VerifyOperationLengths(context.Background(), s, wrapper.WrappedPhase0SignedBeaconBlock(b))
_, err = core.VerifyOperationLengths(context.Background(), s, wrapper.WrappedPhase0SignedBeaconBlock(b))
assert.ErrorContains(t, want, err)
}
@@ -821,7 +821,7 @@ func TestProcessSlots_SameSlotAsParentState(t *testing.T) {
parentState, err := v1.InitializeFromProto(&statepb.BeaconState{Slot: slot})
require.NoError(t, err)
_, err = state.ProcessSlots(context.Background(), parentState, slot)
_, err = core.ProcessSlots(context.Background(), parentState, slot)
assert.ErrorContains(t, "expected state.slot 2 < slot 2", err)
}
@@ -830,7 +830,7 @@ func TestProcessSlots_LowerSlotAsParentState(t *testing.T) {
parentState, err := v1.InitializeFromProto(&statepb.BeaconState{Slot: slot})
require.NoError(t, err)
_, err = state.ProcessSlots(context.Background(), parentState, slot-1)
_, err = core.ProcessSlots(context.Background(), parentState, slot-1)
assert.ErrorContains(t, "expected state.slot 2 < slot 1", err)
}
@@ -838,7 +838,7 @@ func TestProcessSlotsUsingNextSlotCache(t *testing.T) {
ctx := context.Background()
s, _ := testutil.DeterministicGenesisState(t, 1)
r := []byte{'a'}
s, err := state.ProcessSlotsUsingNextSlotCache(ctx, s, r, 5)
s, err := core.ProcessSlotsUsingNextSlotCache(ctx, s, r, 5)
require.NoError(t, err)
require.Equal(t, types.Slot(5), s.Slot())
}

View File

@@ -10,7 +10,7 @@ go_library(
],
deps = [
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//shared/params:go_default_library",
"@com_github_pkg_errors//:go_default_library",

View File

@@ -8,7 +8,7 @@ import (
"github.com/pkg/errors"
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/params"
)
@@ -36,16 +36,16 @@ import (
// # Set validator exit epoch and withdrawable epoch
// validator.exit_epoch = exit_queue_epoch
// validator.withdrawable_epoch = Epoch(validator.exit_epoch + MIN_VALIDATOR_WITHDRAWABILITY_DELAY)
func InitiateValidatorExit(state iface.BeaconState, idx types.ValidatorIndex) (iface.BeaconState, error) {
validator, err := state.ValidatorAtIndex(idx)
func InitiateValidatorExit(s state.BeaconState, idx types.ValidatorIndex) (state.BeaconState, error) {
validator, err := s.ValidatorAtIndex(idx)
if err != nil {
return nil, err
}
if validator.ExitEpoch != params.BeaconConfig().FarFutureEpoch {
return state, nil
return s, nil
}
var exitEpochs []types.Epoch
err = state.ReadFromEveryValidator(func(idx int, val iface.ReadOnlyValidator) error {
err = s.ReadFromEveryValidator(func(idx int, val state.ReadOnlyValidator) error {
if val.ExitEpoch() != params.BeaconConfig().FarFutureEpoch {
exitEpochs = append(exitEpochs, val.ExitEpoch())
}
@@ -54,7 +54,7 @@ func InitiateValidatorExit(state iface.BeaconState, idx types.ValidatorIndex) (i
if err != nil {
return nil, err
}
exitEpochs = append(exitEpochs, helpers.ActivationExitEpoch(helpers.CurrentEpoch(state)))
exitEpochs = append(exitEpochs, helpers.ActivationExitEpoch(helpers.CurrentEpoch(s)))
// Obtain the exit queue epoch as the maximum number in the exit epochs array.
exitQueueEpoch := types.Epoch(0)
@@ -66,7 +66,7 @@ func InitiateValidatorExit(state iface.BeaconState, idx types.ValidatorIndex) (i
// We use the exit queue churn to determine if we have passed a churn limit.
exitQueueChurn := uint64(0)
err = state.ReadFromEveryValidator(func(idx int, val iface.ReadOnlyValidator) error {
err = s.ReadFromEveryValidator(func(idx int, val state.ReadOnlyValidator) error {
if val.ExitEpoch() == exitQueueEpoch {
exitQueueChurn++
}
@@ -75,7 +75,7 @@ func InitiateValidatorExit(state iface.BeaconState, idx types.ValidatorIndex) (i
if err != nil {
return nil, err
}
activeValidatorCount, err := helpers.ActiveValidatorCount(state, helpers.CurrentEpoch(state))
activeValidatorCount, err := helpers.ActiveValidatorCount(s, helpers.CurrentEpoch(s))
if err != nil {
return nil, errors.Wrap(err, "could not get active validator count")
}
@@ -89,10 +89,10 @@ func InitiateValidatorExit(state iface.BeaconState, idx types.ValidatorIndex) (i
}
validator.ExitEpoch = exitQueueEpoch
validator.WithdrawableEpoch = exitQueueEpoch + params.BeaconConfig().MinValidatorWithdrawabilityDelay
if err := state.UpdateValidatorAtIndex(idx, validator); err != nil {
if err := s.UpdateValidatorAtIndex(idx, validator); err != nil {
return nil, err
}
return state, nil
return s, nil
}
// SlashValidator slashes the malicious validator's balance and awards
@@ -121,13 +121,13 @@ func InitiateValidatorExit(state iface.BeaconState, idx types.ValidatorIndex) (i
// proposer_reward = Gwei(whistleblower_reward // PROPOSER_REWARD_QUOTIENT)
// increase_balance(state, proposer_index, proposer_reward)
// increase_balance(state, whistleblower_index, Gwei(whistleblower_reward - proposer_reward))
func SlashValidator(state iface.BeaconState, slashedIdx types.ValidatorIndex) (iface.BeaconState, error) {
state, err := InitiateValidatorExit(state, slashedIdx)
func SlashValidator(s state.BeaconState, slashedIdx types.ValidatorIndex) (state.BeaconState, error) {
s, err := InitiateValidatorExit(s, slashedIdx)
if err != nil {
return nil, errors.Wrapf(err, "could not initiate validator %d exit", slashedIdx)
}
currentEpoch := helpers.SlotToEpoch(state.Slot())
validator, err := state.ValidatorAtIndex(slashedIdx)
currentEpoch := helpers.SlotToEpoch(s.Slot())
validator, err := s.ValidatorAtIndex(slashedIdx)
if err != nil {
return nil, err
}
@@ -135,24 +135,24 @@ func SlashValidator(state iface.BeaconState, slashedIdx types.ValidatorIndex) (i
maxWithdrawableEpoch := types.MaxEpoch(validator.WithdrawableEpoch, currentEpoch+params.BeaconConfig().EpochsPerSlashingsVector)
validator.WithdrawableEpoch = maxWithdrawableEpoch
if err := state.UpdateValidatorAtIndex(slashedIdx, validator); err != nil {
if err := s.UpdateValidatorAtIndex(slashedIdx, validator); err != nil {
return nil, err
}
// The slashing amount is represented by epochs per slashing vector. The validator's effective balance is then applied to that amount.
slashings := state.Slashings()
slashings := s.Slashings()
currentSlashing := slashings[currentEpoch%params.BeaconConfig().EpochsPerSlashingsVector]
if err := state.UpdateSlashingsAtIndex(
if err := s.UpdateSlashingsAtIndex(
uint64(currentEpoch%params.BeaconConfig().EpochsPerSlashingsVector),
currentSlashing+validator.EffectiveBalance,
); err != nil {
return nil, err
}
if err := helpers.DecreaseBalance(state, slashedIdx, validator.EffectiveBalance/params.BeaconConfig().MinSlashingPenaltyQuotient); err != nil {
if err := helpers.DecreaseBalance(s, slashedIdx, validator.EffectiveBalance/params.BeaconConfig().MinSlashingPenaltyQuotient); err != nil {
return nil, err
}
proposerIdx, err := helpers.BeaconProposerIndex(state)
proposerIdx, err := helpers.BeaconProposerIndex(s)
if err != nil {
return nil, errors.Wrap(err, "could not get proposer idx")
}
@@ -160,15 +160,15 @@ func SlashValidator(state iface.BeaconState, slashedIdx types.ValidatorIndex) (i
whistleBlowerIdx := proposerIdx
whistleblowerReward := validator.EffectiveBalance / params.BeaconConfig().WhistleBlowerRewardQuotient
proposerReward := whistleblowerReward / params.BeaconConfig().ProposerRewardQuotient
err = helpers.IncreaseBalance(state, proposerIdx, proposerReward)
err = helpers.IncreaseBalance(s, proposerIdx, proposerReward)
if err != nil {
return nil, err
}
err = helpers.IncreaseBalance(state, whistleBlowerIdx, whistleblowerReward-proposerReward)
err = helpers.IncreaseBalance(s, whistleBlowerIdx, whistleblowerReward-proposerReward)
if err != nil {
return nil, err
}
return state, nil
return s, nil
}
// ActivatedValidatorIndices determines the indices activated during the given epoch.

View File

@@ -12,7 +12,7 @@ go_library(
deps = [
"//beacon-chain/db/filters:go_default_library",
"//beacon-chain/slasher/types:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//proto/interfaces:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v2:go_default_library",

View File

@@ -11,7 +11,7 @@ import (
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/beacon-chain/db/filters"
slashertypes "github.com/prysmaticlabs/prysm/beacon-chain/slasher/types"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/proto/interfaces"
eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
v2 "github.com/prysmaticlabs/prysm/proto/prysm/v2"
@@ -33,12 +33,12 @@ type ReadOnlyDatabase interface {
FinalizedChildBlock(ctx context.Context, blockRoot [32]byte) (interfaces.SignedBeaconBlock, error)
HighestSlotBlocksBelow(ctx context.Context, slot types.Slot) ([]interfaces.SignedBeaconBlock, error)
// State related methods.
State(ctx context.Context, blockRoot [32]byte) (iface.BeaconState, error)
GenesisState(ctx context.Context) (iface.BeaconState, error)
State(ctx context.Context, blockRoot [32]byte) (state.BeaconState, error)
GenesisState(ctx context.Context) (state.BeaconState, error)
HasState(ctx context.Context, blockRoot [32]byte) bool
StateSummary(ctx context.Context, blockRoot [32]byte) (*statepb.StateSummary, error)
HasStateSummary(ctx context.Context, blockRoot [32]byte) bool
HighestSlotStatesBelow(ctx context.Context, slot types.Slot) ([]iface.ReadOnlyBeaconState, error)
HighestSlotStatesBelow(ctx context.Context, slot types.Slot) ([]state.ReadOnlyBeaconState, error)
// Slashing operations.
ProposerSlashing(ctx context.Context, slashingRoot [32]byte) (*eth.ProposerSlashing, error)
AttesterSlashing(ctx context.Context, slashingRoot [32]byte) (*eth.AttesterSlashing, error)
@@ -69,8 +69,8 @@ type NoHeadAccessDatabase interface {
SaveBlocks(ctx context.Context, blocks []interfaces.SignedBeaconBlock) error
SaveGenesisBlockRoot(ctx context.Context, blockRoot [32]byte) error
// State related methods.
SaveState(ctx context.Context, state iface.ReadOnlyBeaconState, blockRoot [32]byte) error
SaveStates(ctx context.Context, states []iface.ReadOnlyBeaconState, blockRoots [][32]byte) error
SaveState(ctx context.Context, state state.ReadOnlyBeaconState, blockRoot [32]byte) error
SaveStates(ctx context.Context, states []state.ReadOnlyBeaconState, blockRoots [][32]byte) error
DeleteState(ctx context.Context, blockRoot [32]byte) error
DeleteStates(ctx context.Context, blockRoots [][32]byte) error
SaveStateSummary(ctx context.Context, summary *statepb.StateSummary) error
@@ -103,7 +103,7 @@ type HeadAccessDatabase interface {
// Genesis operations.
LoadGenesis(ctx context.Context, r io.Reader) error
SaveGenesisData(ctx context.Context, state iface.BeaconState) error
SaveGenesisData(ctx context.Context, state state.BeaconState) error
EnsureEmbeddedGenesis(ctx context.Context) error
}

View File

@@ -13,7 +13,7 @@ go_library(
deps = [
"//beacon-chain/db/filters:go_default_library",
"//beacon-chain/db/iface:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//proto/interfaces:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v2:go_default_library",

View File

@@ -7,7 +7,7 @@ import (
"github.com/ethereum/go-ethereum/common"
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/beacon-chain/db/filters"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/proto/interfaces"
eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
v2 "github.com/prysmaticlabs/prysm/proto/prysm/v2"
@@ -65,7 +65,7 @@ func (e Exporter) HasBlock(ctx context.Context, blockRoot [32]byte) bool {
}
// State -- passthrough.
func (e Exporter) State(ctx context.Context, blockRoot [32]byte) (iface.BeaconState, error) {
func (e Exporter) State(ctx context.Context, blockRoot [32]byte) (state.BeaconState, error) {
return e.db.State(ctx, blockRoot)
}
@@ -75,7 +75,7 @@ func (e Exporter) StateSummary(ctx context.Context, blockRoot [32]byte) (*statep
}
// GenesisState -- passthrough.
func (e Exporter) GenesisState(ctx context.Context) (iface.BeaconState, error) {
func (e Exporter) GenesisState(ctx context.Context) (state.BeaconState, error) {
return e.db.GenesisState(ctx)
}
@@ -140,7 +140,7 @@ func (e Exporter) SaveGenesisBlockRoot(ctx context.Context, blockRoot [32]byte)
}
// SaveState -- passthrough.
func (e Exporter) SaveState(ctx context.Context, st iface.ReadOnlyBeaconState, blockRoot [32]byte) error {
func (e Exporter) SaveState(ctx context.Context, st state.ReadOnlyBeaconState, blockRoot [32]byte) error {
return e.db.SaveState(ctx, st, blockRoot)
}
@@ -155,7 +155,7 @@ func (e Exporter) SaveStateSummaries(ctx context.Context, summaries []*statepb.S
}
// SaveStates -- passthrough.
func (e Exporter) SaveStates(ctx context.Context, states []iface.ReadOnlyBeaconState, blockRoots [][32]byte) error {
func (e Exporter) SaveStates(ctx context.Context, states []state.ReadOnlyBeaconState, blockRoots [][32]byte) error {
return e.db.SaveStates(ctx, states, blockRoots)
}
@@ -250,7 +250,7 @@ func (e Exporter) HighestSlotBlocksBelow(ctx context.Context, slot types.Slot) (
}
// HighestSlotStatesBelow -- passthrough
func (e Exporter) HighestSlotStatesBelow(ctx context.Context, slot types.Slot) ([]iface.ReadOnlyBeaconState, error) {
func (e Exporter) HighestSlotStatesBelow(ctx context.Context, slot types.Slot) ([]state.ReadOnlyBeaconState, error) {
return e.db.HighestSlotStatesBelow(ctx, slot)
}
@@ -275,7 +275,7 @@ func (e Exporter) LoadGenesis(ctx context.Context, r io.Reader) error {
}
// SaveGenesisData -- passthrough
func (e Exporter) SaveGenesisData(ctx context.Context, state iface.BeaconState) error {
func (e Exporter) SaveGenesisData(ctx context.Context, state state.BeaconState) error {
return e.db.SaveGenesisData(ctx, state)
}

View File

@@ -36,8 +36,8 @@ go_library(
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/db/filters:go_default_library",
"//beacon-chain/db/iface:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/genesis:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state/v1:go_default_library",
"//proto/interfaces:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
@@ -91,7 +91,7 @@ go_test(
deps = [
"//beacon-chain/db/filters:go_default_library",
"//beacon-chain/db/iface:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//proto/interfaces:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v1alpha1/wrapper:go_default_library",

View File

@@ -10,15 +10,15 @@ import (
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
dbIface "github.com/prysmaticlabs/prysm/beacon-chain/db/iface"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
state "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
statev1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
statepb "github.com/prysmaticlabs/prysm/proto/prysm/v2/state"
"github.com/prysmaticlabs/prysm/shared/params"
)
// SaveGenesisData bootstraps the beaconDB with a given genesis state.
func (s *Store) SaveGenesisData(ctx context.Context, genesisState iface.BeaconState) error {
func (s *Store) SaveGenesisData(ctx context.Context, genesisState state.BeaconState) error {
stateRoot, err := genesisState.HashTreeRoot(ctx)
if err != nil {
return err
@@ -61,7 +61,7 @@ func (s *Store) LoadGenesis(ctx context.Context, r io.Reader) error {
if err := st.UnmarshalSSZ(b); err != nil {
return err
}
gs, err := state.InitializeFromProtoUnsafe(st)
gs, err := statev1.InitializeFromProtoUnsafe(st)
if err != nil {
return err
}

View File

@@ -7,8 +7,8 @@ import (
"github.com/pkg/errors"
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state/genesis"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
@@ -22,7 +22,7 @@ import (
// State returns the saved state using block's signing root,
// this particular block was used to generate the state.
func (s *Store) State(ctx context.Context, blockRoot [32]byte) (iface.BeaconState, error) {
func (s *Store) State(ctx context.Context, blockRoot [32]byte) (state.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "BeaconDB.State")
defer span.End()
var st *statepb.BeaconState
@@ -43,7 +43,7 @@ func (s *Store) State(ctx context.Context, blockRoot [32]byte) (iface.BeaconStat
}
// GenesisState returns the genesis state in beacon chain.
func (s *Store) GenesisState(ctx context.Context) (iface.BeaconState, error) {
func (s *Store) GenesisState(ctx context.Context) (state.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "BeaconDB.GenesisState")
defer span.End()
@@ -84,15 +84,15 @@ func (s *Store) GenesisState(ctx context.Context) (iface.BeaconState, error) {
}
// SaveState stores a state to the db using block's signing root which was used to generate the state.
func (s *Store) SaveState(ctx context.Context, st iface.ReadOnlyBeaconState, blockRoot [32]byte) error {
func (s *Store) SaveState(ctx context.Context, st state.ReadOnlyBeaconState, blockRoot [32]byte) error {
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveState")
defer span.End()
return s.SaveStates(ctx, []iface.ReadOnlyBeaconState{st}, [][32]byte{blockRoot})
return s.SaveStates(ctx, []state.ReadOnlyBeaconState{st}, [][32]byte{blockRoot})
}
// SaveStates stores multiple states to the db using the provided corresponding roots.
func (s *Store) SaveStates(ctx context.Context, states []iface.ReadOnlyBeaconState, blockRoots [][32]byte) error {
func (s *Store) SaveStates(ctx context.Context, states []state.ReadOnlyBeaconState, blockRoots [][32]byte) error {
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveStates")
defer span.End()
if states == nil {
@@ -278,7 +278,7 @@ func slotByBlockRoot(ctx context.Context, tx *bolt.Tx, blockRoot []byte) (types.
// from the db. Ideally there should just be one state per slot, but given validator
// can double propose, a single slot could have multiple block roots and
// results states. This returns a list of states.
func (s *Store) HighestSlotStatesBelow(ctx context.Context, slot types.Slot) ([]iface.ReadOnlyBeaconState, error) {
func (s *Store) HighestSlotStatesBelow(ctx context.Context, slot types.Slot) ([]state.ReadOnlyBeaconState, error) {
ctx, span := trace.StartSpan(ctx, "BeaconDB.HighestSlotStatesBelow")
defer span.End()
@@ -304,7 +304,7 @@ func (s *Store) HighestSlotStatesBelow(ctx context.Context, slot types.Slot) ([]
return nil, err
}
var st iface.ReadOnlyBeaconState
var st state.ReadOnlyBeaconState
var err error
if best != nil {
st, err = s.State(ctx, bytesutil.ToBytes32(best))
@@ -319,7 +319,7 @@ func (s *Store) HighestSlotStatesBelow(ctx context.Context, slot types.Slot) ([]
}
}
return []iface.ReadOnlyBeaconState{st}, nil
return []state.ReadOnlyBeaconState{st}, nil
}
// createStateIndicesFromStateSlot takes in a state slot and returns

View File

@@ -6,7 +6,7 @@ import (
"testing"
types "github.com/prysmaticlabs/eth2-types"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/proto/interfaces"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
@@ -42,7 +42,7 @@ func TestState_CanSaveRetrieve(t *testing.T) {
savedS, err = db.State(context.Background(), [32]byte{'B'})
require.NoError(t, err)
assert.Equal(t, iface.ReadOnlyBeaconState(nil), savedS, "Unsaved state should've been nil")
assert.Equal(t, state.ReadOnlyBeaconState(nil), savedS, "Unsaved state should've been nil")
}
func TestGenesisState_CanSaveRetrieve(t *testing.T) {

View File

@@ -12,7 +12,7 @@ go_library(
"//beacon-chain/cache/depositcache:go_default_library",
"//beacon-chain/db:go_default_library",
"//beacon-chain/powchain:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/v1:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v2/state:go_default_library",

View File

@@ -13,7 +13,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
"github.com/prysmaticlabs/prysm/beacon-chain/powchain"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
statepb "github.com/prysmaticlabs/prysm/proto/prysm/v2/state"
@@ -132,7 +132,7 @@ func (s *Service) ChainStartEth1Data() *ethpb.Eth1Data {
}
// PreGenesisState returns an empty beacon state.
func (s *Service) PreGenesisState() iface.BeaconState {
func (s *Service) PreGenesisState() state.BeaconState {
return &v1.BeaconState{}
}
@@ -161,7 +161,7 @@ func (s *Service) NonFinalizedDeposits(_ context.Context, _ *big.Int) []*ethpb.D
return []*ethpb.Deposit{}
}
func (s *Service) saveGenesisState(ctx context.Context, genesisState iface.BeaconState) error {
func (s *Service) saveGenesisState(ctx context.Context, genesisState state.BeaconState) error {
if err := s.cfg.BeaconDB.SaveGenesisData(ctx, genesisState); err != nil {
return err
}

View File

@@ -18,7 +18,7 @@ go_library(
deps = [
"//beacon-chain/core/blocks:go_default_library",
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//shared/params:go_default_library",
"//shared/sliceutil:go_default_library",
@@ -42,7 +42,7 @@ go_test(
],
embed = [":go_default_library"],
deps = [
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//shared/bls:go_default_library",
"//shared/params:go_default_library",

View File

@@ -3,7 +3,7 @@ package slashings
import (
"context"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
)
@@ -14,23 +14,23 @@ type PoolMock struct {
}
// PendingAttesterSlashings --
func (m *PoolMock) PendingAttesterSlashings(_ context.Context, _ iface.ReadOnlyBeaconState, _ bool) []*ethpb.AttesterSlashing {
func (m *PoolMock) PendingAttesterSlashings(_ context.Context, _ state.ReadOnlyBeaconState, _ bool) []*ethpb.AttesterSlashing {
return m.PendingAttSlashings
}
// PendingProposerSlashings --
func (m *PoolMock) PendingProposerSlashings(_ context.Context, _ iface.ReadOnlyBeaconState, _ bool) []*ethpb.ProposerSlashing {
func (m *PoolMock) PendingProposerSlashings(_ context.Context, _ state.ReadOnlyBeaconState, _ bool) []*ethpb.ProposerSlashing {
return m.PendingPropSlashings
}
// InsertAttesterSlashing --
func (m *PoolMock) InsertAttesterSlashing(_ context.Context, _ iface.ReadOnlyBeaconState, slashing *ethpb.AttesterSlashing) error {
func (m *PoolMock) InsertAttesterSlashing(_ context.Context, _ state.ReadOnlyBeaconState, slashing *ethpb.AttesterSlashing) error {
m.PendingAttSlashings = append(m.PendingAttSlashings, slashing)
return nil
}
// InsertProposerSlashing --
func (m *PoolMock) InsertProposerSlashing(_ context.Context, _ iface.BeaconState, slashing *ethpb.ProposerSlashing) error {
func (m *PoolMock) InsertProposerSlashing(_ context.Context, _ state.BeaconState, slashing *ethpb.ProposerSlashing) error {
m.PendingPropSlashings = append(m.PendingPropSlashings, slashing)
return nil
}

View File

@@ -9,7 +9,7 @@ import (
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/sliceutil"
@@ -29,7 +29,7 @@ func NewPool() *Pool {
// PendingAttesterSlashings returns attester slashings that are able to be included into a block.
// This method will return the amount of pending attester slashings for a block transition unless parameter `noLimit` is true
// to indicate the request is for noLimit pending items.
func (p *Pool) PendingAttesterSlashings(ctx context.Context, state iface.ReadOnlyBeaconState, noLimit bool) []*ethpb.AttesterSlashing {
func (p *Pool) PendingAttesterSlashings(ctx context.Context, state state.ReadOnlyBeaconState, noLimit bool) []*ethpb.AttesterSlashing {
p.lock.Lock()
defer p.lock.Unlock()
ctx, span := trace.StartSpan(ctx, "operations.PendingAttesterSlashing")
@@ -76,7 +76,7 @@ func (p *Pool) PendingAttesterSlashings(ctx context.Context, state iface.ReadOnl
// PendingProposerSlashings returns proposer slashings that are able to be included into a block.
// This method will return the amount of pending proposer slashings for a block transition unless the `noLimit` parameter
// is set to true to indicate the request is for noLimit pending items.
func (p *Pool) PendingProposerSlashings(ctx context.Context, state iface.ReadOnlyBeaconState, noLimit bool) []*ethpb.ProposerSlashing {
func (p *Pool) PendingProposerSlashings(ctx context.Context, state state.ReadOnlyBeaconState, noLimit bool) []*ethpb.ProposerSlashing {
p.lock.Lock()
defer p.lock.Unlock()
ctx, span := trace.StartSpan(ctx, "operations.PendingProposerSlashing")
@@ -116,7 +116,7 @@ func (p *Pool) PendingProposerSlashings(ctx context.Context, state iface.ReadOnl
// has been included into a block recently, or the validator is already exited.
func (p *Pool) InsertAttesterSlashing(
ctx context.Context,
state iface.ReadOnlyBeaconState,
state state.ReadOnlyBeaconState,
slashing *ethpb.AttesterSlashing,
) error {
p.lock.Lock()
@@ -174,7 +174,7 @@ func (p *Pool) InsertAttesterSlashing(
// has been included recently, the validator is already exited, or the validator was already slashed.
func (p *Pool) InsertProposerSlashing(
ctx context.Context,
state iface.BeaconState,
state state.BeaconState,
slashing *ethpb.ProposerSlashing,
) error {
p.lock.Lock()
@@ -258,7 +258,7 @@ func (p *Pool) MarkIncludedProposerSlashing(ps *ethpb.ProposerSlashing) {
// has been recently included in the pool, then it checks if the validator is slashable.
// Note: this method requires caller to hold the lock.
func (p *Pool) validatorSlashingPreconditionCheck(
state iface.ReadOnlyBeaconState,
state state.ReadOnlyBeaconState,
valIdx types.ValidatorIndex,
) (bool, error) {
if !mutexasserts.RWMutexLocked(&p.lock) && !mutexasserts.RWMutexRLocked(&p.lock) {

View File

@@ -5,7 +5,7 @@ import (
"testing"
types "github.com/prysmaticlabs/eth2-types"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/params"
@@ -14,7 +14,7 @@ import (
"github.com/prysmaticlabs/prysm/shared/testutil/require"
)
func validAttesterSlashingForValIdx(t *testing.T, beaconState iface.BeaconState, privs []bls.SecretKey, valIdx ...uint64) *ethpb.AttesterSlashing {
func validAttesterSlashingForValIdx(t *testing.T, beaconState state.BeaconState, privs []bls.SecretKey, valIdx ...uint64) *ethpb.AttesterSlashing {
var slashings []*ethpb.AttesterSlashing
for _, idx := range valIdx {
slashing, err := testutil.GenerateAttesterSlashingForValidator(beaconState, privs[idx], types.ValidatorIndex(idx))

View File

@@ -5,23 +5,23 @@ import (
"sync"
types "github.com/prysmaticlabs/eth2-types"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
)
// PoolManager maintains a pool of pending and recently included attester and proposer slashings.
// This pool is used by proposers to insert data into new blocks.
type PoolManager interface {
PendingAttesterSlashings(ctx context.Context, state iface.ReadOnlyBeaconState, noLimit bool) []*ethpb.AttesterSlashing
PendingProposerSlashings(ctx context.Context, state iface.ReadOnlyBeaconState, noLimit bool) []*ethpb.ProposerSlashing
PendingAttesterSlashings(ctx context.Context, state state.ReadOnlyBeaconState, noLimit bool) []*ethpb.AttesterSlashing
PendingProposerSlashings(ctx context.Context, state state.ReadOnlyBeaconState, noLimit bool) []*ethpb.ProposerSlashing
InsertAttesterSlashing(
ctx context.Context,
state iface.ReadOnlyBeaconState,
state state.ReadOnlyBeaconState,
slashing *ethpb.AttesterSlashing,
) error
InsertProposerSlashing(
ctx context.Context,
state iface.BeaconState,
state state.BeaconState,
slashing *ethpb.ProposerSlashing,
) error
MarkIncludedAttesterSlashing(as *ethpb.AttesterSlashing)

View File

@@ -14,7 +14,7 @@ go_library(
],
deps = [
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//shared/params:go_default_library",
"@com_github_prysmaticlabs_eth2_types//:go_default_library",

View File

@@ -4,7 +4,7 @@ import (
"context"
types "github.com/prysmaticlabs/eth2-types"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
)
@@ -14,12 +14,12 @@ type PoolMock struct {
}
// PendingExits --
func (m *PoolMock) PendingExits(_ iface.ReadOnlyBeaconState, _ types.Slot, _ bool) []*eth.SignedVoluntaryExit {
func (m *PoolMock) PendingExits(_ state.ReadOnlyBeaconState, _ types.Slot, _ bool) []*eth.SignedVoluntaryExit {
return m.Exits
}
// InsertVoluntaryExit --
func (m *PoolMock) InsertVoluntaryExit(_ context.Context, _ iface.ReadOnlyBeaconState, exit *eth.SignedVoluntaryExit) {
func (m *PoolMock) InsertVoluntaryExit(_ context.Context, _ state.ReadOnlyBeaconState, exit *eth.SignedVoluntaryExit) {
m.Exits = append(m.Exits, exit)
}

View File

@@ -7,7 +7,7 @@ import (
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/params"
"go.opencensus.io/trace"
@@ -16,8 +16,8 @@ import (
// PoolManager maintains pending and seen voluntary exits.
// This pool is used by proposers to insert voluntary exits into new blocks.
type PoolManager interface {
PendingExits(state iface.ReadOnlyBeaconState, slot types.Slot, noLimit bool) []*ethpb.SignedVoluntaryExit
InsertVoluntaryExit(ctx context.Context, state iface.ReadOnlyBeaconState, exit *ethpb.SignedVoluntaryExit)
PendingExits(state state.ReadOnlyBeaconState, slot types.Slot, noLimit bool) []*ethpb.SignedVoluntaryExit
InsertVoluntaryExit(ctx context.Context, state state.ReadOnlyBeaconState, exit *ethpb.SignedVoluntaryExit)
MarkIncluded(exit *ethpb.SignedVoluntaryExit)
}
@@ -37,7 +37,7 @@ func NewPool() *Pool {
// PendingExits returns exits that are ready for inclusion at the given slot. This method will not
// return more than the block enforced MaxVoluntaryExits.
func (p *Pool) PendingExits(state iface.ReadOnlyBeaconState, slot types.Slot, noLimit bool) []*ethpb.SignedVoluntaryExit {
func (p *Pool) PendingExits(state state.ReadOnlyBeaconState, slot types.Slot, noLimit bool) []*ethpb.SignedVoluntaryExit {
p.lock.RLock()
defer p.lock.RUnlock()
@@ -65,7 +65,7 @@ func (p *Pool) PendingExits(state iface.ReadOnlyBeaconState, slot types.Slot, no
// InsertVoluntaryExit into the pool. This method is a no-op if the pending exit already exists,
// or the validator is already exited.
func (p *Pool) InsertVoluntaryExit(ctx context.Context, state iface.ReadOnlyBeaconState, exit *ethpb.SignedVoluntaryExit) {
func (p *Pool) InsertVoluntaryExit(ctx context.Context, state state.ReadOnlyBeaconState, exit *ethpb.SignedVoluntaryExit) {
ctx, span := trace.StartSpan(ctx, "exitPool.InsertVoluntaryExit")
defer span.End()
p.lock.Lock()

View File

@@ -26,7 +26,7 @@ go_library(
"//beacon-chain/core/state:go_default_library",
"//beacon-chain/db:go_default_library",
"//beacon-chain/powchain/types:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/stategen:go_default_library",
"//beacon-chain/state/v1:go_default_library",
"//contracts/deposit-contract:go_default_library",

View File

@@ -26,10 +26,10 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/cache/depositcache"
statefeed "github.com/prysmaticlabs/prysm/beacon-chain/core/feed/state"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
core "github.com/prysmaticlabs/prysm/beacon-chain/core/state"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
"github.com/prysmaticlabs/prysm/beacon-chain/powchain/types"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
contracts "github.com/prysmaticlabs/prysm/contracts/deposit-contract"
@@ -81,7 +81,7 @@ var (
type ChainStartFetcher interface {
ChainStartDeposits() []*ethpb.Deposit
ChainStartEth1Data() *ethpb.Eth1Data
PreGenesisState() iface.BeaconState
PreGenesisState() state.BeaconState
ClearPreGenesisData()
}
@@ -146,7 +146,7 @@ type Service struct {
chainStartData *protodb.ChainStartData
lastReceivedMerkleIndex int64 // Keeps track of the last received index to prevent log spam.
runError error
preGenesisState iface.BeaconState
preGenesisState state.BeaconState
bsUpdater BeaconNodeStatsUpdater
}
@@ -172,7 +172,7 @@ func NewService(ctx context.Context, config *Web3ServiceConfig) (*Service, error
cancel()
return nil, errors.Wrap(err, "could not setup deposit trie")
}
genState, err := state.EmptyGenesisState()
genState, err := core.EmptyGenesisState()
if err != nil {
return nil, errors.Wrap(err, "could not setup genesis state")
}
@@ -295,7 +295,7 @@ func (s *Service) ChainStartEth1Data() *ethpb.Eth1Data {
// PreGenesisState returns a state that contains
// pre-chainstart deposits.
func (s *Service) PreGenesisState() iface.BeaconState {
func (s *Service) PreGenesisState() state.BeaconState {
return s.preGenesisState
}

View File

@@ -14,7 +14,7 @@ go_library(
],
deps = [
"//beacon-chain/powchain/types:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/v1:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//shared/bytesutil:go_default_library",

View File

@@ -7,7 +7,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/prysmaticlabs/prysm/beacon-chain/powchain/types"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/event"
@@ -75,7 +75,7 @@ func (f *FaultyMockPOWChain) ChainStartEth1Data() *ethpb.Eth1Data {
}
// PreGenesisState --
func (f *FaultyMockPOWChain) PreGenesisState() iface.BeaconState {
func (f *FaultyMockPOWChain) PreGenesisState() state.BeaconState {
return &v1.BeaconState{}
}

View File

@@ -14,7 +14,7 @@ import (
gethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rpc"
"github.com/prysmaticlabs/prysm/beacon-chain/powchain/types"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/event"
@@ -30,7 +30,7 @@ type POWChain struct {
BlockNumberByTime map[uint64]*big.Int
Eth1Data *ethpb.Eth1Data
GenesisEth1Block *big.Int
GenesisState iface.BeaconState
GenesisState state.BeaconState
}
// GenesisTime represents a static past date - JAN 01 2000.
@@ -120,7 +120,7 @@ func (m *POWChain) ChainStartEth1Data() *ethpb.Eth1Data {
}
// PreGenesisState --
func (m *POWChain) PreGenesisState() iface.BeaconState {
func (m *POWChain) PreGenesisState() state.BeaconState {
return m.GenesisState
}

View File

@@ -26,7 +26,7 @@ go_library(
"//beacon-chain/operations/voluntaryexits:go_default_library",
"//beacon-chain/p2p:go_default_library",
"//beacon-chain/rpc/statefetcher:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/stategen:go_default_library",
"//beacon-chain/state/v1:go_default_library",
"//proto/eth/v1:go_default_library",
@@ -73,7 +73,7 @@ go_test(
"//beacon-chain/p2p/testing:go_default_library",
"//beacon-chain/rpc/statefetcher:go_default_library",
"//beacon-chain/rpc/testutil:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//proto/eth/v1:go_default_library",
"//proto/interfaces:go_default_library",
"//proto/migration:go_default_library",

View File

@@ -5,7 +5,7 @@ import (
"context"
"github.com/prysmaticlabs/prysm/beacon-chain/rpc/statefetcher"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1"
eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/params"
@@ -76,7 +76,7 @@ func (bs *Server) GetStateFork(ctx context.Context, req *ethpb.StateRequest) (*e
defer span.End()
var (
state iface.BeaconState
state state.BeaconState
err error
)
@@ -107,7 +107,7 @@ func (bs *Server) GetFinalityCheckpoints(ctx context.Context, req *ethpb.StateRe
defer span.End()
var (
state iface.BeaconState
state state.BeaconState
err error
)

View File

@@ -8,7 +8,7 @@ import (
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/rpc/statefetcher"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1"
"github.com/prysmaticlabs/prysm/proto/migration"
@@ -190,7 +190,7 @@ func (bs *Server) ListCommittees(ctx context.Context, req *ethpb.StateCommittees
// This function returns the validator object based on the passed in ID. The validator ID could be its public key,
// or its index.
func valContainersByRequestIds(state iface.BeaconState, validatorIds [][]byte) ([]*ethpb.ValidatorContainer, error) {
func valContainersByRequestIds(state state.BeaconState, validatorIds [][]byte) ([]*ethpb.ValidatorContainer, error) {
epoch := helpers.SlotToEpoch(state.Slot())
var valContainers []*ethpb.ValidatorContainer
if len(validatorIds) == 0 {

View File

@@ -12,7 +12,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/rpc/statefetcher"
"github.com/prysmaticlabs/prysm/beacon-chain/rpc/testutil"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1"
ethpb_alpha "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/params"
@@ -24,7 +24,7 @@ import (
func TestGetValidator(t *testing.T) {
ctx := context.Background()
var state iface.BeaconState
var state state.BeaconState
state, _ = sharedtestutil.DeterministicGenesisState(t, 8192)
t.Run("Head Get Validator by index", func(t *testing.T) {
@@ -75,7 +75,7 @@ func TestGetValidator(t *testing.T) {
func TestListValidators(t *testing.T) {
ctx := context.Background()
var state iface.BeaconState
var state state.BeaconState
state, _ = sharedtestutil.DeterministicGenesisState(t, 8192)
t.Run("Head List All Validators", func(t *testing.T) {
@@ -204,7 +204,7 @@ func TestListValidators(t *testing.T) {
func TestListValidators_Status(t *testing.T) {
ctx := context.Background()
var state iface.BeaconState
var state state.BeaconState
state, _ = sharedtestutil.DeterministicGenesisState(t, 8192)
farFutureEpoch := params.BeaconConfig().FarFutureEpoch
@@ -425,7 +425,7 @@ func TestListValidators_Status(t *testing.T) {
func TestListValidatorBalances(t *testing.T) {
ctx := context.Background()
var state iface.BeaconState
var state state.BeaconState
state, _ = sharedtestutil.DeterministicGenesisState(t, 8192)
t.Run("Head List Validators Balance by index", func(t *testing.T) {
@@ -497,7 +497,7 @@ func TestListValidatorBalances(t *testing.T) {
func TestListCommittees(t *testing.T) {
ctx := context.Background()
var state iface.BeaconState
var state state.BeaconState
state, _ = sharedtestutil.DeterministicGenesisState(t, 8192)
epoch := helpers.SlotToEpoch(state.Slot())

View File

@@ -14,7 +14,7 @@ go_library(
"//beacon-chain/core/state:go_default_library",
"//beacon-chain/operations/attestations:go_default_library",
"//beacon-chain/rpc/prysm/v1alpha1/validator:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/v1:go_default_library",
"//beacon-chain/sync:go_default_library",
"//proto/eth/v1:go_default_library",

View File

@@ -9,8 +9,8 @@ import (
"github.com/pkg/errors"
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
core "github.com/prysmaticlabs/prysm/beacon-chain/core/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
statev1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
v1 "github.com/prysmaticlabs/prysm/proto/eth/v1"
"github.com/prysmaticlabs/prysm/proto/migration"
@@ -229,7 +229,7 @@ func (vs *Server) SubmitBeaconCommitteeSubscription(ctx context.Context, req *v1
// attestationDependentRoot is get_block_root_at_slot(state, compute_start_slot_at_epoch(epoch - 1) - 1)
// or the genesis block root in the case of underflow.
func attestationDependentRoot(s iface.BeaconState, epoch types.Epoch) ([]byte, error) {
func attestationDependentRoot(s state.BeaconState, epoch types.Epoch) ([]byte, error) {
var dependentRootSlot types.Slot
if epoch <= 1 {
dependentRootSlot = 0
@@ -249,7 +249,7 @@ func attestationDependentRoot(s iface.BeaconState, epoch types.Epoch) ([]byte, e
// proposalDependentRoot is get_block_root_at_slot(state, compute_start_slot_at_epoch(epoch) - 1)
// or the genesis block root in the case of underflow.
func proposalDependentRoot(s iface.BeaconState, epoch types.Epoch) ([]byte, error) {
func proposalDependentRoot(s state.BeaconState, epoch types.Epoch) ([]byte, error) {
var dependentRootSlot types.Slot
if epoch == 0 {
dependentRootSlot = 0
@@ -270,7 +270,7 @@ func proposalDependentRoot(s iface.BeaconState, epoch types.Epoch) ([]byte, erro
// advanceState advances state with empty transitions up to the requested epoch start slot.
// In case 1 epoch ahead was requested, we take the start slot of the current epoch.
// Taking the start slot of the next epoch would result in an error inside state.ProcessSlots.
func advanceState(ctx context.Context, s iface.BeaconState, requestedEpoch, currentEpoch types.Epoch) (iface.BeaconState, error) {
func advanceState(ctx context.Context, s state.BeaconState, requestedEpoch, currentEpoch types.Epoch) (state.BeaconState, error) {
var epochStartSlot types.Slot
var err error
if requestedEpoch == currentEpoch+1 {
@@ -285,7 +285,7 @@ func advanceState(ctx context.Context, s iface.BeaconState, requestedEpoch, curr
}
}
if s.Slot() < epochStartSlot {
s, err = state.ProcessSlots(ctx, s, epochStartSlot)
s, err = core.ProcessSlots(ctx, s, epochStartSlot)
if err != nil {
return nil, errors.Wrapf(err, "Could not process slots up to %d", epochStartSlot)
}

View File

@@ -34,7 +34,7 @@ go_library(
"//beacon-chain/operations/slashings:go_default_library",
"//beacon-chain/p2p:go_default_library",
"//beacon-chain/powchain:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/stategen:go_default_library",
"//beacon-chain/sync:go_default_library",
"//proto/interfaces:go_default_library",
@@ -90,7 +90,7 @@ go_test(
"//beacon-chain/operations/attestations:go_default_library",
"//beacon-chain/operations/slashings:go_default_library",
"//beacon-chain/p2p/testing:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/stategen:go_default_library",
"//beacon-chain/state/v1:go_default_library",
"//beacon-chain/sync/initial-sync/testing:go_default_library",

View File

@@ -9,7 +9,7 @@ import (
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper"
@@ -194,7 +194,7 @@ func TestRetrieveCommitteesForRoot(t *testing.T) {
assert.DeepEqual(t, wantedRes, receivedRes)
}
func setupActiveValidators(t *testing.T, count int) iface.BeaconState {
func setupActiveValidators(t *testing.T, count int) state.BeaconState {
balances := make([]uint64, count)
validators := make([]*ethpb.Validator, 0, count)
for i := 0; i < count; i++ {

View File

@@ -9,9 +9,9 @@ import (
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/beacon-chain/core/epoch/precompute"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
core "github.com/prysmaticlabs/prysm/beacon-chain/core/state"
"github.com/prysmaticlabs/prysm/beacon-chain/core/validators"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/cmd"
@@ -213,7 +213,7 @@ func (bs *Server) ListValidators(
}
requestedEpoch = q.Epoch
}
var reqState iface.BeaconState
var reqState state.BeaconState
var err error
if requestedEpoch != currentEpoch {
var s types.Slot
@@ -235,7 +235,7 @@ func (bs *Server) ListValidators(
}
if s > reqState.Slot() {
reqState = reqState.Copy()
reqState, err = state.ProcessSlots(ctx, reqState, s)
reqState, err = core.ProcessSlots(ctx, reqState, s)
if err != nil {
return nil, status.Errorf(
codes.Internal,
@@ -654,7 +654,7 @@ func (bs *Server) GetValidatorPerformance(
}
if bs.GenesisTimeFetcher.CurrentSlot() > headState.Slot() {
headState, err = state.ProcessSlots(ctx, headState, bs.GenesisTimeFetcher.CurrentSlot())
headState, err = core.ProcessSlots(ctx, headState, bs.GenesisTimeFetcher.CurrentSlot())
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not process slots: %v", err)
}

View File

@@ -21,7 +21,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
"github.com/prysmaticlabs/prysm/beacon-chain/powchain"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/event"
@@ -300,8 +300,8 @@ func (is *infostream) generateValidatorsInfo(pubKeys [][]byte) ([]*ethpb.Validat
// generateValidatorInfo generates the validator info for a public key.
func (is *infostream) generateValidatorInfo(
pubKey []byte,
validator iface.ReadOnlyValidator,
headState iface.ReadOnlyBeaconState,
validator state.ReadOnlyValidator,
headState state.ReadOnlyBeaconState,
epoch types.Epoch,
) (*ethpb.ValidatorInfo, error) {
info := &ethpb.ValidatorInfo{
@@ -373,7 +373,7 @@ func (is *infostream) generatePendingValidatorInfo(info *ethpb.ValidatorInfo) (*
return info, nil
}
func (is *infostream) calculateActivationTimeForPendingValidators(res []*ethpb.ValidatorInfo, headState iface.ReadOnlyBeaconState, epoch types.Epoch) error {
func (is *infostream) calculateActivationTimeForPendingValidators(res []*ethpb.ValidatorInfo, headState state.ReadOnlyBeaconState, epoch types.Epoch) error {
// pendingValidatorsMap is map from the validator pubkey to the index in our return array
pendingValidatorsMap := make(map[[48]byte]int)
for i, info := range res {
@@ -390,7 +390,7 @@ func (is *infostream) calculateActivationTimeForPendingValidators(res []*ethpb.V
numAttestingValidators := uint64(0)
pendingValidators := make([]types.ValidatorIndex, 0, headState.NumValidators())
err := headState.ReadFromEveryValidator(func(idx int, val iface.ReadOnlyValidator) error {
err := headState.ReadFromEveryValidator(func(idx int, val state.ReadOnlyValidator) error {
if val.IsNil() {
return errors.New("nil validator in state")
}
@@ -481,7 +481,7 @@ func (s indicesSorter) Less(i, j int) bool {
return s.indices[i] < s.indices[j]
}
func (is *infostream) calculateStatusAndTransition(validator iface.ReadOnlyValidator, currentEpoch types.Epoch) (ethpb.ValidatorStatus, uint64) {
func (is *infostream) calculateStatusAndTransition(validator state.ReadOnlyValidator, currentEpoch types.Epoch) (ethpb.ValidatorStatus, uint64) {
farFutureEpoch := params.BeaconConfig().FarFutureEpoch
if validator.IsNil() {

View File

@@ -16,7 +16,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
v1 "github.com/prysmaticlabs/prysm/beacon-chain/state/v1"
mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing"
@@ -1461,7 +1461,7 @@ func TestServer_GetValidatorParticipation_UnknownState(t *testing.T) {
epoch := types.Epoch(50)
slots := params.BeaconConfig().SlotsPerEpoch.Mul(uint64(epoch))
mockStateGen := &stategen.MockStateManager{
StatesBySlot: map[types.Slot]iface.BeaconState{
StatesBySlot: map[types.Slot]state.BeaconState{
0: (*v1.BeaconState)(nil),
},
}
@@ -1904,7 +1904,7 @@ func BenchmarkListValidatorBalances(b *testing.B) {
}
}
func setupValidators(t testing.TB, _ db.Database, count int) ([]*ethpb.Validator, []uint64, iface.BeaconState) {
func setupValidators(t testing.TB, _ db.Database, count int) ([]*ethpb.Validator, []uint64, state.BeaconState) {
balances := make([]uint64, count)
validators := make([]*ethpb.Validator, 0, count)
for i := 0; i < count; i++ {

View File

@@ -17,7 +17,7 @@ go_library(
"//beacon-chain/db:go_default_library",
"//beacon-chain/db/filters:go_default_library",
"//beacon-chain/p2p:go_default_library",
"//beacon-chain/state/interface:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/stategen:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v2:go_default_library",

View File

@@ -7,7 +7,7 @@ import (
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/db/filters"
iface "github.com/prysmaticlabs/prysm/beacon-chain/state/interface"
"github.com/prysmaticlabs/prysm/beacon-chain/state"
pbrpc "github.com/prysmaticlabs/prysm/proto/prysm/v2"
"github.com/prysmaticlabs/prysm/shared/attestationutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
@@ -62,7 +62,7 @@ func (ds *Server) GetInclusionSlot(ctx context.Context, req *pbrpc.InclusionSlot
}
inclusionSlot := types.Slot(1<<64 - 1)
targetStates := make(map[[32]byte]iface.ReadOnlyBeaconState)
targetStates := make(map[[32]byte]state.ReadOnlyBeaconState)
for _, blk := range blks {
for _, a := range blk.Block().Body().Attestations() {
tr := bytesutil.ToBytes32(a.Data.Target.Root)

Some files were not shown because too many files have changed in this diff Show More