Skip to content

Commit

Permalink
Cleanup process block/operation names (prysmaticlabs#6500)
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain authored Jul 7, 2020
1 parent e96e1f0 commit 7f741e4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 85 deletions.
101 changes: 19 additions & 82 deletions beacon-chain/core/state/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func ExecuteStateTransitionNoVerifyAttSigs(
return state, nil
}

// ExecuteStateTransitionNoVerify defines the procedure for a state transition function.
// ExecuteStateTransitionNoVerifyAnySig defines the procedure for a state transition function.
// This does not validate any BLS signatures of attestations, block proposer signature, randao signature,
// it is used for performing a state transition as quickly as possible. This function also returns a signature
// set of all signatures not verified, so that they can be stored and verified later.
Expand All @@ -145,7 +145,7 @@ func ExecuteStateTransitionNoVerifyAttSigs(
// process_block(state, block)
// # Return post-state
// return state
func ExecuteStateTransitionNoVerify(
func ExecuteStateTransitionNoVerifyAnySig(
ctx context.Context,
state *stateTrie.BeaconState,
signed *ethpb.SignedBeaconBlock,
Expand All @@ -168,7 +168,7 @@ func ExecuteStateTransitionNoVerify(
}

// Execute per block transition.
set, state, err := ProcessBlockNoVerify(ctx, state, signed)
set, state, err := ProcessBlockNoVerifyAnySig(ctx, state, signed)
if err != nil {
return nil, nil, errors.Wrap(err, "could not process block")
}
Expand Down Expand Up @@ -465,7 +465,7 @@ func ProcessBlockNoVerifyAttSigs(
return nil, errors.Wrap(err, "could not process eth1 data")
}

state, err = ProcessOperationsNoVerify(ctx, state, signed.Block.Body)
state, err = ProcessOperationsNoVerifyAttsSigs(ctx, state, signed.Block.Body)
if err != nil {
traceutil.AnnotateError(span, err)
return nil, errors.Wrap(err, "could not process block operation")
Expand All @@ -474,7 +474,7 @@ func ProcessBlockNoVerifyAttSigs(
return state, nil
}

// ProcessBlockNoVerify creates a new, modified beacon state by applying block operation
// ProcessBlockNoVerifyAnySig creates a new, modified beacon state by applying block operation
// transformations as defined in the Ethereum Serenity specification. It does not validate
// any block signature except for deposit and slashing signatures. It also returns the relevant
// signature set from all the respective methods.
Expand All @@ -486,17 +486,14 @@ func ProcessBlockNoVerifyAttSigs(
// process_randao(state, block.body)
// process_eth1_data(state, block.body)
// process_operations(state, block.body)
func ProcessBlockNoVerify(
func ProcessBlockNoVerifyAnySig(
ctx context.Context,
state *stateTrie.BeaconState,
signed *ethpb.SignedBeaconBlock,
) (*bls.SignatureSet, *stateTrie.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "beacon-chain.ChainService.state.ProcessBlock")
defer span.End()

// Empty signature set.
set := bls.NewSet()

state, err := b.ProcessBlockHeaderNoVerify(state, signed.Block)
if err != nil {
traceutil.AnnotateError(span, err)
Expand Down Expand Up @@ -524,13 +521,18 @@ func ProcessBlockNoVerify(
return nil, nil, errors.Wrap(err, "could not process eth1 data")
}

aSet, state, err := ProcessOperationsNoVerifySignatureSet(ctx, state, signed.Block.Body)
state, err = ProcessOperationsNoVerifyAttsSigs(ctx, state, signed.Block.Body)
if err != nil {
traceutil.AnnotateError(span, err)
return nil, nil, errors.Wrap(err, "could not process block operation")
}
aSet, err := b.AttestationSignatureSet(ctx, state, signed.Block.Body.Attestations)
if err != nil {
return nil, nil, errors.Wrap(err, "could not retrieve attestation signature set")
}

// Merge all signature sets
// Merge beacon block, randao and attestations signatures into a set.
set := bls.NewSet()
set.Join(bSet).Join(rSet).Join(aSet)

return set, state, nil
Expand Down Expand Up @@ -596,10 +598,10 @@ func ProcessOperations(
return state, nil
}

// ProcessOperationsNoVerify processes the operations in the beacon block and updates beacon state
// with the operations in block. It does not verify attestation signatures or voluntary exit signatures.
// ProcessOperationsNoVerifyAttsSigs processes the operations in the beacon block and updates beacon state
// with the operations in block. It does not verify attestation signatures.
//
// WARNING: This method does not verify attestation signatures or voluntary exit signatures.
// WARNING: This method does not verify attestation signatures.
// This is used to perform the block operations as fast as possible.
//
// Spec pseudocode definition:
Expand All @@ -621,7 +623,7 @@ func ProcessOperations(
// for operations, function in all_operations:
// for operation in operations:
// function(state, operation)
func ProcessOperationsNoVerify(
func ProcessOperationsNoVerifyAttsSigs(
ctx context.Context,
state *stateTrie.BeaconState,
body *ethpb.BeaconBlockBody) (*stateTrie.BeaconState, error) {
Expand All @@ -648,79 +650,14 @@ func ProcessOperationsNoVerify(
if err != nil {
return nil, errors.Wrap(err, "could not process block validator deposits")
}
state, err = b.ProcessVoluntaryExitsNoVerify(state, body)
state, err = b.ProcessVoluntaryExits(ctx, state, body)
if err != nil {
return nil, errors.Wrap(err, "could not process validator exits")
}

return state, nil
}

// ProcessOperationsNoVerifySignatureSet processes the operations in the beacon block and updates beacon state
// with the operations in block. It does not verify attestation signatures. It instead
// returns the relevant signature set for each of the operations
//
// WARNING: This method does not verify attestation signatures.
// This is used to perform the block operations as fast as possible.
//
// Spec pseudocode definition:
//
// def process_operations(state: BeaconState, body: BeaconBlockBody) -> None:
// # Verify that outstanding deposits are processed up to the maximum number of deposits
// assert len(body.deposits) == min(MAX_DEPOSITS, state.eth1_data.deposit_count - state.eth1_deposit_index)
// # Verify that there are no duplicate transfers
// assert len(body.transfers) == len(set(body.transfers))
//
// all_operations = (
// (body.proposer_slashings, process_proposer_slashing),
// (body.attester_slashings, process_attester_slashing),
// (body.attestations, process_attestation),
// (body.deposits, process_deposit),
// (body.voluntary_exits, process_voluntary_exit),
// (body.transfers, process_transfer),
// ) # type: Sequence[Tuple[List, Callable]]
// for operations, function in all_operations:
// for operation in operations:
// function(state, operation)
func ProcessOperationsNoVerifySignatureSet(
ctx context.Context,
state *stateTrie.BeaconState,
body *ethpb.BeaconBlockBody) (*bls.SignatureSet, *stateTrie.BeaconState, error) {
ctx, span := trace.StartSpan(ctx, "beacon-chain.ChainService.state.ProcessOperations")
defer span.End()

if err := verifyOperationLengths(state, body); err != nil {
return nil, nil, errors.Wrap(err, "could not verify operation lengths")
}

state, err := b.ProcessProposerSlashings(ctx, state, body)
if err != nil {
return nil, nil, errors.Wrap(err, "could not process block proposer slashings")
}
state, err = b.ProcessAttesterSlashings(ctx, state, body)
if err != nil {
return nil, nil, errors.Wrap(err, "could not process block attester slashings")
}
state, err = b.ProcessAttestationsNoVerify(ctx, state, body)
if err != nil {
return nil, nil, errors.Wrap(err, "could not process block attestations")
}
aSet, err := b.AttestationSignatureSet(ctx, state, body.Attestations)
if err != nil {
return nil, nil, errors.Wrap(err, "could not retrieve attestation signature set")
}
state, err = b.ProcessDeposits(ctx, state, body.Deposits)
if err != nil {
return nil, nil, errors.Wrap(err, "could not process block validator deposits")
}
state, err = b.ProcessVoluntaryExits(ctx, state, body)
if err != nil {
return nil, nil, errors.Wrap(err, "could not process validator exits")
}

return aSet, state, nil
}

func verifyOperationLengths(state *stateTrie.BeaconState, body *ethpb.BeaconBlockBody) error {
if uint64(len(body.ProposerSlashings)) > params.BeaconConfig().MaxProposerSlashings {
return fmt.Errorf(
Expand Down Expand Up @@ -853,7 +790,7 @@ func ProcessBlockForStateRoot(
return nil, errors.Wrap(err, "could not process eth1 data")
}

state, err = ProcessOperationsNoVerify(ctx, state, signed.Block.Body)
state, err = ProcessOperationsNoVerifyAttsSigs(ctx, state, signed.Block.Body)
if err != nil {
traceutil.AnnotateError(span, err)
return nil, errors.Wrap(err, "could not process block operation")
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/core/state/transition_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func TestFuzzprocessOperationsNoVerify_1000(t *testing.T) {
for i := 0; i < 1000; i++ {
fuzzer.Fuzz(state)
fuzzer.Fuzz(bb)
s, err := ProcessOperationsNoVerify(ctx, state, bb)
s, err := ProcessOperationsNoVerifyAttsSigs(ctx, state, bb)
if err != nil && s != nil {
t.Fatalf("state should be nil on err. found: %v on error: %v for block body: %v", s, err, bb)
}
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/core/state/transition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func TestExecuteStateTransitionNoVerify_FullProcess(t *testing.T) {
}
block.Signature = sig.Marshal()

set, beaconState, err := state.ExecuteStateTransitionNoVerify(context.Background(), beaconState, block)
set, beaconState, err := state.ExecuteStateTransitionNoVerifyAnySig(context.Background(), beaconState, block)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -713,7 +713,7 @@ func TestProcessBlock_PassesProcessingConditions(t *testing.T) {

func TestProcessBlockNoVerify_PassesProcessingConditions(t *testing.T) {
beaconState, block, _, _, _ := createFullBlockWithOperations(t)
set, _, err := state.ProcessBlockNoVerify(context.Background(), beaconState, block)
set, _, err := state.ProcessBlockNoVerifyAnySig(context.Background(), beaconState, block)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 7f741e4

Please sign in to comment.