State Transition Configuration Options (#2023)

* logging config options

* tests pass

* better naming

* log proposer idx instead of sig

* log avg balance
This commit is contained in:
Raul Jordan
2019-03-18 00:19:44 -06:00
committed by GitHub
parent 78ff565429
commit a98912ea58
12 changed files with 168 additions and 107 deletions

View File

@@ -127,7 +127,10 @@ func (c *ChainService) runStateTransition(
beaconState,
block,
headRoot,
true, /* sig verify */
&state.TransitionConfig{
VerifySignatures: true, // We activate signature verification in this state transition.
Logging: true, // We enable logging in this state transition call.
},
)
if err != nil {
return nil, fmt.Errorf("could not execute state transition %v", err)

View File

@@ -43,7 +43,10 @@ func GenerateStateFromSlot(ctx context.Context, db *db.BeaconDB, slot uint64) (*
fState,
nil,
root,
true, /* sig verify */
&state.TransitionConfig{
VerifySignatures: true,
Logging: false,
},
)
if err != nil {
return nil, fmt.Errorf("could not execute state transition %v", err)
@@ -56,7 +59,10 @@ func GenerateStateFromSlot(ctx context.Context, db *db.BeaconDB, slot uint64) (*
fState,
blk,
root,
true, /* sig verify */
&state.TransitionConfig{
VerifySignatures: true,
Logging: false,
},
)
if err != nil {
return nil, fmt.Errorf("could not execute state transition %v", err)

View File

@@ -109,7 +109,7 @@ func (sb *SimulatedBackend) GenerateBlockAndAdvanceChain(objects *SimulatedObjec
sb.state,
newBlock,
prevBlockRoot,
false, /* no sig verify */
state.DefaultConfig(),
)
if err != nil {
return fmt.Errorf("could not execute state transition: %v", err)
@@ -133,7 +133,7 @@ func (sb *SimulatedBackend) GenerateNilBlockAndAdvanceChain() error {
sb.state,
nil,
prevBlockRoot,
false, /* no sig verify */
state.DefaultConfig(),
)
if err != nil {
return fmt.Errorf("could not execute state transition: %v", err)

View File

@@ -85,7 +85,13 @@ func ProcessEth1DataInBlock(ctx context.Context, beaconState *pb.BeaconState, bl
// signature=block.randao_reveal, domain=get_domain(state.fork, get_current_epoch(state), DOMAIN_RANDAO)).
// Set state.latest_randao_mixes[get_current_epoch(state) % LATEST_RANDAO_MIXES_LENGTH] =
// xor(get_randao_mix(state, get_current_epoch(state)), hash(block.randao_reveal))
func ProcessBlockRandao(ctx context.Context, beaconState *pb.BeaconState, block *pb.BeaconBlock, verifySignatures bool) (*pb.BeaconState, error) {
func ProcessBlockRandao(
ctx context.Context,
beaconState *pb.BeaconState,
block *pb.BeaconBlock,
verifySignatures bool,
enableLogging bool,
) (*pb.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "beacon-chain.ChainService.state.ProcessBlock.ProcessBlockRandao")
defer span.End()
@@ -93,10 +99,8 @@ func ProcessBlockRandao(ctx context.Context, beaconState *pb.BeaconState, block
if err != nil {
return nil, fmt.Errorf("could not get beacon proposer index: %v", err)
}
log.WithField("proposerIndex", proposerIdx).Info("RANDAO expected proposer")
proposer := beaconState.ValidatorRegistry[proposerIdx]
if verifySignatures {
if err := verifyBlockRandao(beaconState, block, proposer); err != nil {
if err := verifyBlockRandao(beaconState, block, proposerIdx, enableLogging); err != nil {
return nil, fmt.Errorf("could not verify block randao: %v", err)
}
}
@@ -115,7 +119,8 @@ func ProcessBlockRandao(ctx context.Context, beaconState *pb.BeaconState, block
// Verify that bls_verify(pubkey=proposer.pubkey, message_hash=hash_tree_root(get_current_epoch(state)),
// signature=block.randao_reveal, domain=get_domain(state.fork, get_current_epoch(state), DOMAIN_RANDAO))
func verifyBlockRandao(beaconState *pb.BeaconState, block *pb.BeaconBlock, proposer *pb.Validator) error {
func verifyBlockRandao(beaconState *pb.BeaconState, block *pb.BeaconBlock, proposerIdx uint64, enableLogging bool) error {
proposer := beaconState.ValidatorRegistry[proposerIdx]
pub, err := bls.PublicKeyFromBytes(proposer.Pubkey)
if err != nil {
return fmt.Errorf("could not deserialize proposer public key: %v", err)
@@ -128,11 +133,12 @@ func verifyBlockRandao(beaconState *pb.BeaconState, block *pb.BeaconBlock, propo
if err != nil {
return fmt.Errorf("could not deserialize block randao reveal: %v", err)
}
log.WithFields(logrus.Fields{
"epoch": helpers.CurrentEpoch(beaconState) - params.BeaconConfig().GenesisEpoch,
"pubkey": fmt.Sprintf("%#x", proposer.Pubkey),
"epochSig": fmt.Sprintf("%#x", sig.Marshal()),
}).Info("Verifying randao")
if enableLogging {
log.WithFields(logrus.Fields{
"epoch": helpers.CurrentEpoch(beaconState) - params.BeaconConfig().GenesisEpoch,
"proposerIndex": proposerIdx,
}).Info("Verifying randao")
}
if !sig.Verify(buf, pub, domain) {
return fmt.Errorf("block randao reveal signature did not verify")
}

View File

@@ -71,7 +71,8 @@ func TestProcessBlockRandao_IncorrectProposerFailsVerification(t *testing.T) {
context.Background(),
beaconState,
block,
true,
true, /* verify signatures */
false, /* disable logging */
); !strings.Contains(err.Error(), want) {
t.Errorf("Expected %v, received %v", want, err)
}
@@ -102,7 +103,8 @@ func TestProcessBlockRandao_SignatureVerifiesAndUpdatesLatestStateMixes(t *testi
context.Background(),
beaconState,
block,
true,
true, /* verify signatures */
false, /* disable logging */
)
if err != nil {
t.Errorf("Unexpected error processing block randao: %v", err)

View File

@@ -15,7 +15,6 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/validators"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
b "github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/params"
"go.opencensus.io/trace"
)
@@ -86,7 +85,6 @@ func PrevAttestations(ctx context.Context, state *pb.BeaconState) []*pb.PendingA
var prevEpochAttestations []*pb.PendingAttestation
prevEpoch := helpers.PrevEpoch(state)
log.Infof("Fetching prev boundary attestations, prev epoch: %d", helpers.PrevEpoch(state)-params.BeaconConfig().GenesisEpoch)
for _, attestation := range state.LatestAttestations {
if prevEpoch == helpers.SlotToEpoch(attestation.Data.Slot) {

View File

@@ -122,7 +122,9 @@ func ProcessJustification(
thisEpochBoundaryAttestingBalance uint64,
prevEpochBoundaryAttestingBalance uint64,
prevTotalBalance uint64,
totalBalance uint64) *pb.BeaconState {
totalBalance uint64,
enableLogging bool,
) *pb.BeaconState {
ctx, span := trace.StartSpan(ctx, "beacon-chain.ChainService.state.ProcessEpoch.ProcessJustification")
defer span.End()
@@ -132,22 +134,23 @@ func ProcessJustification(
currentEpoch := helpers.CurrentEpoch(state)
// Shifts all the bits over one to create a new bit for the recent epoch.
state.JustificationBitfield <<= 1
log.Infof("Processing Total Balance: %d", totalBalance)
// If prev prev epoch was justified then we ensure the 2nd bit in the bitfield is set,
// assign new justified slot to 2 * SLOTS_PER_EPOCH before.
log.Infof("Previous Epoch Boundary Attesting Balance: %d", prevEpochBoundaryAttestingBalance)
if 3*prevEpochBoundaryAttestingBalance >= 2*prevTotalBalance {
state.JustificationBitfield |= 2
newJustifiedEpoch = prevEpoch
log.Infof("Previous epoch %d was justified", newJustifiedEpoch-params.BeaconConfig().GenesisEpoch)
if enableLogging {
log.Infof("Previous epoch %d was justified", newJustifiedEpoch-params.BeaconConfig().GenesisEpoch)
}
}
log.Infof("Current Epoch Boundary Attesting Balance: %d", thisEpochBoundaryAttestingBalance)
// If this epoch was justified then we ensure the 1st bit in the bitfield is set,
// assign new justified slot to 1 * SLOTS_PER_EPOCH before.
if 3*thisEpochBoundaryAttestingBalance >= 2*totalBalance {
state.JustificationBitfield |= 1
newJustifiedEpoch = currentEpoch
log.Infof("Current epoch %d was justified", newJustifiedEpoch-params.BeaconConfig().GenesisEpoch)
if enableLogging {
log.Infof("Current epoch %d was justified", newJustifiedEpoch-params.BeaconConfig().GenesisEpoch)
}
}
// Process finality.
@@ -156,28 +159,36 @@ func ProcessJustification(
if state.PreviousJustifiedEpoch == prevEpoch-2 &&
(state.JustificationBitfield>>1)%8 == 7 {
state.FinalizedEpoch = state.PreviousJustifiedEpoch
log.Infof("New Finalized Epoch: %d", state.FinalizedEpoch-params.BeaconConfig().GenesisEpoch)
if enableLogging {
log.Infof("New finalized epoch: %d", state.FinalizedEpoch-params.BeaconConfig().GenesisEpoch)
}
}
// When the 2nd and 3rd most epochs are all justified, the 2nd can finalize the 3rd epoch
// as a source.
if state.PreviousJustifiedEpoch == prevEpoch-1 &&
(state.JustificationBitfield>>1)%4 == 3 {
state.FinalizedEpoch = state.PreviousJustifiedEpoch
log.Infof("New Finalized Epoch: %d", state.FinalizedEpoch-params.BeaconConfig().GenesisEpoch)
if enableLogging {
log.Infof("New finalized epoch: %d", state.FinalizedEpoch-params.BeaconConfig().GenesisEpoch)
}
}
// When the 1st, 2nd and 3rd most epochs are all justified, the 1st can finalize the 3rd epoch
// as a source.
if state.JustifiedEpoch == prevEpoch-1 &&
(state.JustificationBitfield>>0)%8 == 7 {
state.FinalizedEpoch = state.JustifiedEpoch
log.Infof("New Finalized Epoch: %d", state.FinalizedEpoch-params.BeaconConfig().GenesisEpoch)
if enableLogging {
log.Infof("New finalized epoch: %d", state.FinalizedEpoch-params.BeaconConfig().GenesisEpoch)
}
}
// When the 1st and 2nd most epochs are all justified, the 1st can finalize the 2nd epoch
// as a source.
if state.JustifiedEpoch == prevEpoch &&
(state.JustificationBitfield>>0)%4 == 3 {
state.FinalizedEpoch = state.JustifiedEpoch
log.Infof("New Finalized Epoch: %d", state.FinalizedEpoch-params.BeaconConfig().GenesisEpoch)
if enableLogging {
log.Infof("New finalized epoch: %d", state.FinalizedEpoch-params.BeaconConfig().GenesisEpoch)
}
}
state.PreviousJustifiedEpoch = state.JustifiedEpoch
state.JustifiedEpoch = newJustifiedEpoch
@@ -253,7 +264,7 @@ func ProcessCrosslinks(
// for index in get_active_validator_indices(state.validator_registry, current_epoch(state)):
// if state.validator_balances[index] < EJECTION_BALANCE:
// exit_validator(state, index)
func ProcessEjections(ctx context.Context, state *pb.BeaconState) (*pb.BeaconState, error) {
func ProcessEjections(ctx context.Context, state *pb.BeaconState, enableLogging bool) (*pb.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "beacon-chain.ChainService.state.ProcessEpoch.ProcessEjections")
defer span.End()
@@ -261,9 +272,11 @@ func ProcessEjections(ctx context.Context, state *pb.BeaconState) (*pb.BeaconSta
activeValidatorIndices := helpers.ActiveValidatorIndices(state.ValidatorRegistry, helpers.CurrentEpoch(state))
for _, index := range activeValidatorIndices {
if state.ValidatorBalances[index] < params.BeaconConfig().EjectionBalance {
log.WithFields(logrus.Fields{
"pubKey": fmt.Sprintf("%#x", state.ValidatorRegistry[index].Pubkey),
"index": index}).Info("Validator ejected")
if enableLogging {
log.WithFields(logrus.Fields{
"pubKey": fmt.Sprintf("%#x", state.ValidatorRegistry[index].Pubkey),
"index": index}).Info("Validator ejected")
}
state = validators.ExitValidator(state, index)
}
}

View File

@@ -215,7 +215,15 @@ func TestProcessJustification_PreviousEpochJustified(t *testing.T) {
JustifiedEpoch: 3,
JustificationBitfield: 4,
}
newState := ProcessJustification(context.Background(), state, 1, 1, 1, 1)
newState := ProcessJustification(
context.Background(),
state,
1,
1,
1,
1,
false, /* disable logging */
)
if newState.PreviousJustifiedEpoch != 3 {
t.Errorf("New state's prev justified slot %d != old state's justified slot %d",
@@ -234,7 +242,15 @@ func TestProcessJustification_PreviousEpochJustified(t *testing.T) {
// Assume for the case where only prev epoch got justified. Verify
// justified_epoch = slot_to_epoch(state.slot) -2.
newState = ProcessJustification(context.Background(), state, 0, 1, 1, 1)
newState = ProcessJustification(
context.Background(),
state,
0,
1,
1,
1,
false, /* disable logging */
)
if newState.JustifiedEpoch != helpers.CurrentEpoch(state)-1 {
t.Errorf("New state's justified epoch %d != state's epoch -2: %d",
newState.JustifiedEpoch, helpers.CurrentEpoch(state)-1)
@@ -319,7 +335,7 @@ func TestProcessEjections_EjectsAtCorrectSlot(t *testing.T) {
{ExitEpoch: params.BeaconConfig().FarFutureEpoch}},
}
state, err := ProcessEjections(context.Background(), state)
state, err := ProcessEjections(context.Background(), state, false /* disable logging */)
if err != nil {
t.Fatalf("Could not execute ProcessEjections: %v", err)
}

View File

@@ -23,6 +23,22 @@ import (
var log = logrus.WithField("prefix", "core/state")
// TransitionConfig defines important configuration options
// for executing a state transition, which can have logging and signature
// verification on or off depending on when and where it is used.
type TransitionConfig struct {
VerifySignatures bool
Logging bool
}
// DefaultConfig option for executing state transitions.
func DefaultConfig() *TransitionConfig {
return &TransitionConfig{
VerifySignatures: false,
Logging: false,
}
}
// ExecuteStateTransition defines the procedure for a state transition function.
// Spec pseudocode definition:
// We now define the state transition function. At a high level the state transition is made up of three parts:
@@ -38,7 +54,7 @@ func ExecuteStateTransition(
state *pb.BeaconState,
block *pb.BeaconBlock,
headRoot [32]byte,
verifySignatures bool,
config *TransitionConfig,
) (*pb.BeaconState, error) {
var err error
@@ -47,7 +63,7 @@ func ExecuteStateTransition(
// Execute per block transition.
if block != nil {
state, err = ProcessBlock(ctx, state, block, verifySignatures)
state, err = ProcessBlock(ctx, state, block, config)
if err != nil {
return nil, fmt.Errorf("could not process block: %v", err)
}
@@ -55,7 +71,7 @@ func ExecuteStateTransition(
// Execute per epoch transition.
if e.CanProcessEpoch(state) {
state, err = ProcessEpoch(ctx, state)
state, err = ProcessEpoch(ctx, state, config)
}
if err != nil {
return nil, fmt.Errorf("could not process epoch: %v", err)
@@ -88,7 +104,8 @@ func ProcessBlock(
ctx context.Context,
state *pb.BeaconState,
block *pb.BeaconBlock,
verifySignatures bool) (*pb.BeaconState, error) {
config *TransitionConfig,
) (*pb.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "beacon-chain.ChainService.state.ProcessBlock")
defer span.End()
@@ -107,38 +124,34 @@ func ProcessBlock(
state.Slot-params.BeaconConfig().GenesisSlot,
)
}
log.WithField("blockRoot", fmt.Sprintf("%#x", r)).Debugf("Verified block slot == state slot")
// Verify block signature.
if verifySignatures {
if config.VerifySignatures {
// TODO(#781): Verify Proposer Signature.
if err := b.VerifyProposerSignature(ctx, block); err != nil {
return nil, fmt.Errorf("could not verify proposer signature: %v", err)
}
}
log.WithField("blockRoot", fmt.Sprintf("%#x", r)).Debugf("Verified block signature")
// Verify block RANDAO.
state, err = b.ProcessBlockRandao(ctx, state, block, verifySignatures)
state, err = b.ProcessBlockRandao(ctx, state, block, config.VerifySignatures, config.Logging)
if err != nil {
return nil, fmt.Errorf("could not verify and process block randao: %v", err)
}
log.WithField("blockRoot", fmt.Sprintf("%#x", r)).Debugf("Verified and processed block RANDAO")
// Process ETH1 data.
state = b.ProcessEth1DataInBlock(ctx, state, block)
state, err = b.ProcessAttesterSlashings(ctx, state, block, verifySignatures)
state, err = b.ProcessAttesterSlashings(ctx, state, block, config.VerifySignatures)
if err != nil {
return nil, fmt.Errorf("could not verify block attester slashings: %v", err)
}
log.WithField("blockRoot", fmt.Sprintf("%#x", r)).Debugf("Processed ETH1 data")
state, err = b.ProcessProposerSlashings(ctx, state, block, verifySignatures)
state, err = b.ProcessProposerSlashings(ctx, state, block, config.VerifySignatures)
if err != nil {
return nil, fmt.Errorf("could not verify block proposer slashings: %v", err)
}
state, err = b.ProcessBlockAttestations(ctx, state, block, verifySignatures)
state, err = b.ProcessBlockAttestations(ctx, state, block, config.VerifySignatures)
if err != nil {
return nil, fmt.Errorf("could not process block attestations: %v", err)
}
@@ -147,17 +160,22 @@ func ProcessBlock(
if err != nil {
return nil, fmt.Errorf("could not process block validator deposits: %v", err)
}
state, err = b.ProcessValidatorExits(ctx, state, block, verifySignatures)
state, err = b.ProcessValidatorExits(ctx, state, block, config.VerifySignatures)
if err != nil {
return nil, fmt.Errorf("could not process validator exits: %v", err)
}
log.WithField(
"attestationsInBlock", len(block.Body.Attestations),
).Info("Block attestations")
log.WithField(
"depositsInBlock", len(block.Body.Deposits),
).Info("Block deposits")
if config.Logging {
log.WithField("blockRoot", fmt.Sprintf("%#x", r)).Debugf("Verified block slot == state slot")
log.WithField("blockRoot", fmt.Sprintf("%#x", r)).Debugf("Verified and processed block RANDAO")
log.WithField("blockRoot", fmt.Sprintf("%#x", r)).Debugf("Processed ETH1 data")
log.WithField(
"attestationsInBlock", len(block.Body.Attestations),
).Info("Block attestations")
log.WithField(
"depositsInBlock", len(block.Body.Deposits),
).Info("Block deposits")
}
return state, nil
}
@@ -173,8 +191,7 @@ func ProcessBlock(
// process_crosslink_reward_penalties(state)
// update_validator_registry(state)
// final_book_keeping(state)
func ProcessEpoch(ctx context.Context, state *pb.BeaconState) (*pb.BeaconState, error) {
func ProcessEpoch(ctx context.Context, state *pb.BeaconState, config *TransitionConfig) (*pb.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "beacon-chain.ChainService.state.ProcessEpoch")
defer span.End()
@@ -188,8 +205,6 @@ func ProcessEpoch(ctx context.Context, state *pb.BeaconState) (*pb.BeaconState,
// Calculate the attesting balances of validators that justified the
// epoch boundary block at the start of the current epoch.
currentEpochAttestations := e.CurrentAttestations(ctx, state)
log.Infof("Number of current epoch attestations: %d", len(currentEpochAttestations))
currentEpochBoundaryAttestations, err := e.CurrentEpochBoundaryAttestations(ctx, state, currentEpochAttestations)
if err != nil {
return nil, fmt.Errorf("could not get current boundary attestations: %v", err)
@@ -199,8 +214,6 @@ func ProcessEpoch(ctx context.Context, state *pb.BeaconState) (*pb.BeaconState,
if err != nil {
return nil, fmt.Errorf("could not get current boundary attester indices: %v", err)
}
log.Infof("Current epoch boundary attester indices: %v", currentBoundaryAttesterIndices)
currentBoundaryAttestingBalances := e.TotalBalance(ctx, state, currentBoundaryAttesterIndices)
// Calculate the attesting balances of validators from previous epoch.
@@ -208,13 +221,10 @@ func ProcessEpoch(ctx context.Context, state *pb.BeaconState) (*pb.BeaconState,
prevTotalBalance := e.TotalBalance(ctx, state, previousActiveValidatorIndices)
prevEpochAttestations := e.PrevAttestations(ctx, state)
log.Infof("Number of prev epoch attestations: %d", len(prevEpochAttestations))
prevEpochAttesterIndices, err := v.ValidatorIndices(ctx, state, prevEpochAttestations)
if err != nil {
return nil, fmt.Errorf("could not get prev epoch attester indices: %v", err)
}
log.Infof("Previous epoch attester indices: %v", prevEpochAttesterIndices)
prevEpochAttestingBalance := e.TotalBalance(ctx, state, prevEpochAttesterIndices)
// Calculate the attesting balances of validator justifying epoch boundary block
@@ -223,14 +233,11 @@ func ProcessEpoch(ctx context.Context, state *pb.BeaconState) (*pb.BeaconState,
if err != nil {
return nil, fmt.Errorf("could not get prev boundary attestations: %v", err)
}
log.Infof("Number of prev epoch boundary attestations: %d", len(prevEpochAttestations))
prevEpochBoundaryAttesterIndices, err := v.ValidatorIndices(ctx, state, prevEpochBoundaryAttestations)
if err != nil {
return nil, fmt.Errorf("could not get prev boundary attester indices: %v", err)
}
log.Infof("Previous epoch boundary attester indices: %v", prevEpochBoundaryAttesterIndices)
prevEpochBoundaryAttestingBalances := e.TotalBalance(ctx, state, prevEpochBoundaryAttesterIndices)
// Calculate attesting balances of validator attesting to expected beacon chain head
@@ -258,6 +265,7 @@ func ProcessEpoch(ctx context.Context, state *pb.BeaconState) (*pb.BeaconState,
prevEpochAttestingBalance,
prevTotalBalance,
totalBalance,
config.Logging,
)
// Process crosslinks records.
@@ -282,7 +290,6 @@ func ProcessEpoch(ctx context.Context, state *pb.BeaconState) (*pb.BeaconState,
prevEpochAttesterIndices,
prevEpochAttestingBalance,
totalBalance)
log.Infof("Balance after FFG src calculation: %v", state.ValidatorBalances)
// Apply rewards/penalties to validators for attesting
// expected FFG target.
state = bal.ExpectedFFGTarget(
@@ -291,7 +298,6 @@ func ProcessEpoch(ctx context.Context, state *pb.BeaconState) (*pb.BeaconState,
prevEpochBoundaryAttesterIndices,
prevEpochBoundaryAttestingBalances,
totalBalance)
log.Infof("Balance after FFG target calculation: %v", state.ValidatorBalances)
// Apply rewards/penalties to validators for attesting
// expected beacon chain head.
state = bal.ExpectedBeaconChainHead(
@@ -300,7 +306,6 @@ func ProcessEpoch(ctx context.Context, state *pb.BeaconState) (*pb.BeaconState,
prevEpochHeadAttesterIndices,
prevEpochHeadAttestingBalances,
totalBalance)
log.Infof("Balance after chain head calculation: %v", state.ValidatorBalances)
// Apply rewards for to validators for including attestations
// based on inclusion distance.
state, err = bal.InclusionDistance(
@@ -311,7 +316,12 @@ func ProcessEpoch(ctx context.Context, state *pb.BeaconState) (*pb.BeaconState,
if err != nil {
return nil, fmt.Errorf("could not calculate inclusion dist rewards: %v", err)
}
log.Infof("Balance after inclusion distance calculation: %v", state.ValidatorBalances)
if config.Logging {
log.Infof("Balance after FFG src calculation: %v", state.ValidatorBalances)
log.Infof("Balance after FFG target calculation: %v", state.ValidatorBalances)
log.Infof("Balance after chain head calculation: %v", state.ValidatorBalances)
log.Infof("Balance after inclusion distance calculation: %v", state.ValidatorBalances)
}
case epochsSinceFinality > 4:
log.Infof("Applying more penalties. ESF %d greater than 4", epochsSinceFinality)
@@ -376,7 +386,7 @@ func ProcessEpoch(ctx context.Context, state *pb.BeaconState) (*pb.BeaconState,
}
// Process ejections.
state, err = e.ProcessEjections(ctx, state)
state, err = e.ProcessEjections(ctx, state, config.Logging)
if err != nil {
return nil, fmt.Errorf("could not process ejections: %v", err)
}
@@ -423,25 +433,33 @@ func ProcessEpoch(ctx context.Context, state *pb.BeaconState) (*pb.BeaconState,
// Clean up processed attestations.
state = e.CleanupAttestations(ctx, state)
log.WithField(
"PreviousJustifiedEpoch", state.PreviousJustifiedEpoch-params.BeaconConfig().GenesisEpoch,
).Info("Previous justified epoch")
log.WithField(
"JustifiedEpoch", state.JustifiedEpoch-params.BeaconConfig().GenesisEpoch,
).Info("Justified epoch")
log.WithField(
"FinalizedEpoch", state.FinalizedEpoch-params.BeaconConfig().GenesisEpoch,
).Info("Finalized epoch")
log.WithField(
"ValidatorRegistryUpdateEpoch", state.ValidatorRegistryUpdateEpoch-params.BeaconConfig().GenesisEpoch,
).Info("Validator Registry Update Epoch")
log.WithField(
"NumValidators", len(state.ValidatorRegistry),
).Info("Validator registry length")
log.Infof("Validator balances: %v", state.ValidatorBalances)
log.WithField(
"ValidatorRegistryUpdateEpoch", state.ValidatorRegistryUpdateEpoch-params.BeaconConfig().GenesisEpoch,
).Info("Validator registry update epoch")
if config.Logging {
log.Infof("Number of current epoch attestations: %d", len(currentEpochAttestations))
log.Infof("Current epoch boundary attester indices: %v", currentBoundaryAttesterIndices)
log.Infof("Number of prev epoch attestations: %d", len(prevEpochAttestations))
log.Infof("Previous epoch attester indices: %v", prevEpochAttesterIndices)
log.Infof("Number of prev epoch boundary attestations: %d", len(prevEpochAttestations))
log.Infof("Previous epoch boundary attester indices: %v", prevEpochBoundaryAttesterIndices)
log.WithField(
"PreviousJustifiedEpoch", state.PreviousJustifiedEpoch-params.BeaconConfig().GenesisEpoch,
).Info("Previous justified epoch")
log.WithField(
"JustifiedEpoch", state.JustifiedEpoch-params.BeaconConfig().GenesisEpoch,
).Info("Justified epoch")
log.WithField(
"FinalizedEpoch", state.FinalizedEpoch-params.BeaconConfig().GenesisEpoch,
).Info("Finalized epoch")
log.WithField(
"ValidatorRegistryUpdateEpoch", state.ValidatorRegistryUpdateEpoch-params.BeaconConfig().GenesisEpoch,
).Info("Validator Registry Update Epoch")
log.WithField(
"NumValidators", len(state.ValidatorRegistry),
).Info("Validator registry length")
log.Infof("Validator balances: %v", state.ValidatorBalances)
log.WithField(
"ValidatorRegistryUpdateEpoch", state.ValidatorRegistryUpdateEpoch-params.BeaconConfig().GenesisEpoch,
).Info("Validator registry update epoch")
}
// Report interesting metrics.
reportEpochTransitionMetrics(state)

View File

@@ -11,10 +11,9 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
"github.com/prysmaticlabs/prysm/shared/forkutil"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/forkutil"
"github.com/prysmaticlabs/prysm/shared/params"
)
@@ -67,7 +66,7 @@ func TestProcessBlock_IncorrectSlot(t *testing.T) {
4,
5,
)
if _, err := state.ProcessBlock(context.Background(), beaconState, block, false); !strings.Contains(err.Error(), want) {
if _, err := state.ProcessBlock(context.Background(), beaconState, block, state.DefaultConfig()); !strings.Contains(err.Error(), want) {
t.Errorf("Expected %s, received %v", want, err)
}
}
@@ -95,7 +94,7 @@ func TestProcessBlock_IncorrectProposerSlashing(t *testing.T) {
},
}
want := "could not verify block proposer slashing"
if _, err := state.ProcessBlock(context.Background(), beaconState, block, false); !strings.Contains(err.Error(), want) {
if _, err := state.ProcessBlock(context.Background(), beaconState, block, state.DefaultConfig()); !strings.Contains(err.Error(), want) {
t.Errorf("Expected %s, received %v", want, err)
}
}
@@ -139,7 +138,7 @@ func TestProcessBlock_IncorrectAttesterSlashing(t *testing.T) {
},
}
want := "could not verify block attester slashing"
if _, err := state.ProcessBlock(context.Background(), beaconState, block, false); !strings.Contains(err.Error(), want) {
if _, err := state.ProcessBlock(context.Background(), beaconState, block, state.DefaultConfig()); !strings.Contains(err.Error(), want) {
t.Errorf("Expected %s, received %v", want, err)
}
}
@@ -207,7 +206,7 @@ func TestProcessBlock_IncorrectProcessBlockAttestations(t *testing.T) {
},
}
want := "could not process block attestations"
if _, err := state.ProcessBlock(context.Background(), beaconState, block, false); !strings.Contains(err.Error(), want) {
if _, err := state.ProcessBlock(context.Background(), beaconState, block, state.DefaultConfig()); !strings.Contains(err.Error(), want) {
t.Errorf("Expected %s, received %v", want, err)
}
}
@@ -299,7 +298,7 @@ func TestProcessBlock_IncorrectProcessExits(t *testing.T) {
},
}
want := "could not process validator exits"
if _, err := state.ProcessBlock(context.Background(), beaconState, block, false); !strings.Contains(err.Error(), want) {
if _, err := state.ProcessBlock(context.Background(), beaconState, block, state.DefaultConfig()); !strings.Contains(err.Error(), want) {
t.Errorf("Expected %s, received %v", want, err)
}
}
@@ -392,7 +391,7 @@ func TestProcessBlock_PassesProcessingConditions(t *testing.T) {
VoluntaryExits: exits,
},
}
if _, err := state.ProcessBlock(context.Background(), beaconState, block, false); err != nil {
if _, err := state.ProcessBlock(context.Background(), beaconState, block, state.DefaultConfig()); err != nil {
t.Errorf("Expected block to pass processing conditions: %v", err)
}
}
@@ -448,7 +447,7 @@ func TestProcessEpoch_PassesProcessingConditions(t *testing.T) {
params.BeaconConfig().LatestSlashedExitLength),
}
_, err := state.ProcessEpoch(context.Background(), newState)
_, err := state.ProcessEpoch(context.Background(), newState, state.DefaultConfig())
if err != nil {
t.Errorf("Expected epoch transition to pass processing conditions: %v", err)
}
@@ -508,7 +507,7 @@ func TestProcessEpoch_InactiveConditions(t *testing.T) {
params.BeaconConfig().LatestSlashedExitLength),
}
_, err := state.ProcessEpoch(context.Background(), newState)
_, err := state.ProcessEpoch(context.Background(), newState, state.DefaultConfig())
if err != nil {
t.Errorf("Expected epoch transition to pass processing conditions: %v", err)
}
@@ -527,7 +526,7 @@ func TestProcessEpoch_CantGetBoundaryAttestation(t *testing.T) {
0,
newState.Slot-params.BeaconConfig().GenesisSlot,
)
if _, err := state.ProcessEpoch(context.Background(), newState); !strings.Contains(err.Error(), want) {
if _, err := state.ProcessEpoch(context.Background(), newState, state.DefaultConfig()); !strings.Contains(err.Error(), want) {
t.Errorf("Expected: %s, received: %v", want, err)
}
}
@@ -557,7 +556,7 @@ func TestProcessEpoch_CantGetCurrentValidatorIndices(t *testing.T) {
}
wanted := fmt.Sprintf("wanted participants bitfield length %d, got: %d", 0, 1)
if _, err := state.ProcessEpoch(context.Background(), newState); !strings.Contains(err.Error(), wanted) {
if _, err := state.ProcessEpoch(context.Background(), newState, state.DefaultConfig()); !strings.Contains(err.Error(), wanted) {
t.Errorf("Expected: %s, received: %v", wanted, err)
}
}

View File

@@ -56,7 +56,7 @@ func (as *AttesterServer) AttestationDataAtSlot(ctx context.Context, req *pb.Att
}
for beaconState.Slot < req.Slot {
beaconState, err = state.ExecuteStateTransition(
ctx, beaconState, nil /* block */, blockRoot, false, /* verify signatures */
ctx, beaconState, nil /* block */, blockRoot, state.DefaultConfig(),
)
if err != nil {
return nil, fmt.Errorf("could not execute head transition: %v", err)

View File

@@ -131,7 +131,7 @@ func (ps *ProposerServer) ComputeStateRoot(ctx context.Context, req *pbp2p.Beaco
beaconState,
nil,
parentHash,
false, /* no sig verify */
state.DefaultConfig(),
)
if err != nil {
return nil, fmt.Errorf("could not execute state transition %v", err)
@@ -142,7 +142,7 @@ func (ps *ProposerServer) ComputeStateRoot(ctx context.Context, req *pbp2p.Beaco
beaconState,
req,
parentHash,
false, /* no sig verification */
state.DefaultConfig(),
)
if err != nil {
return nil, fmt.Errorf("could not execute state transition %v", err)