New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replay blocks and generate state without sig verification #4943
Merged
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
04a3025
New file
terencechain 48c680c
Add transition_stategen.go
terencechain a0e2f6b
Update ProcessBlockForStateRoot
terencechain f0a138d
Feature flags
terencechain aaf4080
Fixed tests
terencechain 8b1d689
Gaz
terencechain af8420a
Make them private
terencechain 36dcea5
E2e flags
terencechain 03c47e1
Gazelle
terencechain 18b37a5
Merge refs/heads/master into state-transition-without-sig-checks
prylabs-bulldozer[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package state | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/pkg/errors" | ||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" | ||
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state" | ||
"go.opencensus.io/trace" | ||
) | ||
|
||
// ExecuteStateTransitionStateGen applies state transition on input historical state and block for state gen usages. | ||
// There's no signature verification involved given state gen only works with stored block and state in DB. | ||
// If the objects are already in stored in DB, one can omit redundant signature checks and ssz hashing calculations. | ||
// WARNING: This method should not be used for new block. | ||
func ExecuteStateTransitionStateGen( | ||
ctx context.Context, | ||
state *stateTrie.BeaconState, | ||
signed *ethpb.SignedBeaconBlock, | ||
) (*stateTrie.BeaconState, error) { | ||
if ctx.Err() != nil { | ||
return nil, ctx.Err() | ||
} | ||
if signed == nil || signed.Block == nil { | ||
return nil, errors.New("nil block") | ||
} | ||
|
||
ctx, span := trace.StartSpan(ctx, "beacon-chain.ChainService.ExecuteStateTransitionStateGen") | ||
defer span.End() | ||
var err error | ||
|
||
// Execute per slots transition. | ||
// Given this is for state gen, a node uses the version process slots without skip slots cache. | ||
state, err = ProcessSlotsStateGen(ctx, state, signed.Block.Slot) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "could not process slot") | ||
} | ||
|
||
// Execute per block transition. | ||
// Given this is for state gen, a node only cares about the post state without proposer | ||
// and randao signature verifications. | ||
state, err = ProcessBlockForStateRoot(ctx, state, signed) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "could not process block") | ||
} | ||
|
||
return state, nil | ||
} | ||
|
||
// ProcessSlotsStateGen to process old slots for state gen usages. | ||
// There's no skip slot cache involved given state gen only works with already stored block and state in DB. | ||
// WARNING: This method should not be used for new slot. | ||
func ProcessSlotsStateGen(ctx context.Context, state *stateTrie.BeaconState, slot uint64) (*stateTrie.BeaconState, error) { | ||
ctx, span := trace.StartSpan(ctx, "beacon-chain.ChainService.ProcessSlotsStateGen") | ||
defer span.End() | ||
if state == nil { | ||
return nil, errors.New("nil state") | ||
} | ||
|
||
if state.Slot() > slot { | ||
err := fmt.Errorf("expected state.slot %d < slot %d", state.Slot(), slot) | ||
return nil, err | ||
} | ||
|
||
if state.Slot() == slot { | ||
return state, nil | ||
} | ||
|
||
for state.Slot() < slot { | ||
state, err := ProcessSlot(ctx, state) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "could not process slot") | ||
} | ||
if CanProcessEpoch(state) { | ||
state, err = ProcessEpochPrecompute(ctx, state) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "could not process epoch with optimizations") | ||
} | ||
} | ||
state.SetSlot(state.Slot() + 1) | ||
} | ||
|
||
return state, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,6 +97,11 @@ var ( | |
Usage: "Enable caching of domain data requests per epoch. This feature reduces the total " + | ||
"calls to the beacon node for each assignment.", | ||
} | ||
enableStateGenSigVerify = cli.BoolFlag{ | ||
Name: "enable-state-gen-sig-verify", | ||
Usage: "Enable signature verification for state gen. This feature increases the cost to generate a historical state," + | ||
"the resulting state is signature verified.", | ||
} | ||
) | ||
|
||
// Deprecated flags list. | ||
|
@@ -205,8 +210,8 @@ var ( | |
Hidden: true, | ||
} | ||
deprecatedInitSyncCacheStateFlag = cli.BoolFlag{ | ||
Name: "initial-sync-cache-state", | ||
Usage: deprecatedUsage, | ||
Name: "initial-sync-cache-state", | ||
Usage: deprecatedUsage, | ||
Hidden: true, | ||
} | ||
) | ||
|
@@ -268,6 +273,7 @@ var BeaconChainFlags = append(deprecatedFlags, []cli.Flag{ | |
disableStrictAttestationPubsubVerificationFlag, | ||
disableUpdateHeadPerAttestation, | ||
enableByteMempool, | ||
enableStateGenSigVerify, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add to e2e flags? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call |
||
}...) | ||
|
||
// E2EBeaconChainFlags contains a list of the beacon chain feature flags to be tested in E2E. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be private? This warning makes me a bit nervous since it is not enforced
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great point. I have moved it to
stategen
package and made it private