-
Notifications
You must be signed in to change notification settings - Fork 3.9k
op-challenger: PoC for super node trace provider #18617
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
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
868e1c6
op-challenger: PoC for super node trace provider.
ajsutton 3d8b678
Add some more TODOs.
ajsutton 0bfaddd
op-challenger: Update unit test a bit
ajsutton 3db588c
Fix spelling
ajsutton f726ae6
Use the right source for optimistic head safety.
ajsutton c64536b
op-challenger: Port unit tests for provider.
ajsutton 355af0e
Lots of JSON tags and opinionated renames.
ajsutton 09d0628
op-challenger: Setup response format to allow returning sync data whe…
ajsutton 45b6fe8
op-supernode: Only return not found responses when the block is not f…
ajsutton ea0caca
op-challenger: Request previous and next roots in a single request.
ajsutton 1f0c0a4
Revert "op-challenger: Request previous and next roots in a single re…
ajsutton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
169 changes: 169 additions & 0 deletions
169
op-challenger/game/fault/trace/super/provider_supernode.go
This file contains hidden or 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,169 @@ | ||
| package super | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/ethereum-optimism/optimism/op-challenger/game/client" | ||
| "github.com/ethereum-optimism/optimism/op-challenger/game/fault/types" | ||
| interopTypes "github.com/ethereum-optimism/optimism/op-program/client/interop/types" | ||
| "github.com/ethereum-optimism/optimism/op-service/eth" | ||
| "github.com/ethereum-optimism/optimism/op-supernode/supernode/activity/superroot" | ||
| "github.com/ethereum/go-ethereum/common" | ||
| "github.com/ethereum/go-ethereum/crypto" | ||
| "github.com/ethereum/go-ethereum/log" | ||
| ) | ||
|
|
||
| type SuperNodeRootProvider interface { | ||
| // TODO: If AtTimestampResponse is being reused it should be put in op-service | ||
| SuperRootAtTimestamp(ctx context.Context, timestamp uint64) (superroot.AtTimestampResponse, error) | ||
| } | ||
|
|
||
| type SuperNodeTraceProvider struct { | ||
| PreimagePrestateProvider | ||
| logger log.Logger | ||
| rootProvider SuperNodeRootProvider | ||
| prestateTimestamp uint64 | ||
| poststateTimestamp uint64 | ||
| l1Head eth.BlockID | ||
| gameDepth types.Depth | ||
| } | ||
|
|
||
| func NewSuperNodeTraceProvider(logger log.Logger, prestateProvider PreimagePrestateProvider, rootProvider SuperNodeRootProvider, l1Head eth.BlockID, gameDepth types.Depth, prestateTimestamp, poststateTimestamp uint64) *SuperNodeTraceProvider { | ||
| return &SuperNodeTraceProvider{ | ||
| logger: logger, | ||
| PreimagePrestateProvider: prestateProvider, | ||
| rootProvider: rootProvider, | ||
| prestateTimestamp: prestateTimestamp, | ||
| poststateTimestamp: poststateTimestamp, | ||
| l1Head: l1Head, | ||
| gameDepth: gameDepth, | ||
| } | ||
| } | ||
|
|
||
| func (s *SuperNodeTraceProvider) Get(ctx context.Context, pos types.Position) (common.Hash, error) { | ||
| preimage, err := s.GetPreimageBytes(ctx, pos) | ||
| if err != nil { | ||
| return common.Hash{}, err | ||
| } | ||
| return crypto.Keccak256Hash(preimage), nil | ||
| } | ||
|
|
||
| func (s *SuperNodeTraceProvider) getPreimageBytesAtTimestampBoundary(ctx context.Context, timestamp uint64) ([]byte, error) { | ||
| root, err := s.rootProvider.SuperRootAtTimestamp(ctx, timestamp) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to retrieve super root at timestamp %v: %w", timestamp, err) | ||
| } | ||
| if root.CurrentL1.Number < s.l1Head.Number { | ||
| // Node has not processed the game's L1 head so it is not safe to play until it syncs further. | ||
| return nil, client.ErrNotInSync | ||
| } | ||
| if root.Data == nil { | ||
| // No block at this timestamp so it must be invalid | ||
| return InvalidTransition, nil | ||
| } | ||
| if root.Data.VerifiedRequiredL1.Number > s.l1Head.Number { | ||
| return InvalidTransition, nil | ||
| } | ||
| return root.Data.Super.Marshal(), nil | ||
| } | ||
|
|
||
| func (s *SuperNodeTraceProvider) GetPreimageBytes(ctx context.Context, pos types.Position) ([]byte, error) { | ||
| // Find the timestamp and step at position | ||
| timestamp, step, err := s.ComputeStep(pos) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| s.logger.Trace("Getting claim", "pos", pos.ToGIndex(), "timestamp", timestamp, "step", step) | ||
| if step == 0 { | ||
| return s.getPreimageBytesAtTimestampBoundary(ctx, timestamp) | ||
| } | ||
| // Fetch the super root at the next timestamp since we are part way through the transition to it | ||
| prevRoot, err := s.rootProvider.SuperRootAtTimestamp(ctx, timestamp) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to retrieve previous super root at timestamp %v: %w", timestamp, err) | ||
| } | ||
| if prevRoot.CurrentL1.Number < s.l1Head.Number { | ||
| return nil, client.ErrNotInSync | ||
| } | ||
| if prevRoot.Data == nil { | ||
| // No block at this timestamp so it must be invalid | ||
| return InvalidTransition, nil | ||
| } | ||
| if prevRoot.Data.VerifiedRequiredL1.Number > s.l1Head.Number { | ||
| // The previous root was not safe at the game L1 head so we must have already transitioned to the invalid hash | ||
| // prior to this step and it then repeats forever. | ||
| return InvalidTransition, nil | ||
| } | ||
| nextTimestamp := timestamp + 1 | ||
| nextRoot, err := s.rootProvider.SuperRootAtTimestamp(ctx, nextTimestamp) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to retrieve next super root at timestamp %v: %w", nextTimestamp, err) | ||
| } | ||
| if nextRoot.CurrentL1.Number < s.l1Head.Number { | ||
| return nil, client.ErrNotInSync | ||
| } | ||
| if nextRoot.Data == nil { | ||
| // No block at this timestamp so it must be invalid | ||
| return InvalidTransition, nil | ||
| } | ||
|
|
||
| prevSuper := prevRoot.Data.Super | ||
| expectedState := interopTypes.TransitionState{ | ||
| SuperRoot: prevSuper.Marshal(), | ||
| PendingProgress: make([]interopTypes.OptimisticBlock, 0, step), | ||
| Step: step, | ||
| } | ||
| nextSuperV1, ok := nextRoot.Data.Super.(*eth.SuperV1) | ||
| if !ok { | ||
| return nil, fmt.Errorf("unsupported super root type %T", nextRoot.Data.Super) | ||
| } | ||
| for i := uint64(0); i < min(step, uint64(len(nextSuperV1.Chains))); i++ { | ||
| chainInfo := nextSuperV1.Chains[i] | ||
| // Check if the chain's optimistic root was safe at the game's L1 head | ||
| optimistic, ok := nextRoot.Data.UnverifiedAtTimestamp[chainInfo.ChainID] | ||
| if !ok { | ||
| return nil, fmt.Errorf("no safe head known for chain %v at %v: %w", chainInfo.ChainID, nextTimestamp, err) | ||
| } | ||
| if optimistic.RequiredL1.Number > s.l1Head.Number { | ||
| // Not enough data on L1 to derive the optimistic block, move to invalid transition. | ||
| return InvalidTransition, nil | ||
| } | ||
|
|
||
| expectedState.PendingProgress = append(expectedState.PendingProgress, interopTypes.OptimisticBlock{ | ||
| BlockHash: optimistic.Output.BlockRef.Hash, | ||
| OutputRoot: optimistic.Output.OutputRoot, | ||
| }) | ||
| } | ||
| return expectedState.Marshal(), nil | ||
| } | ||
|
|
||
| func (s *SuperNodeTraceProvider) ComputeStep(pos types.Position) (timestamp uint64, step uint64, err error) { | ||
| bigIdx := pos.TraceIndex(s.gameDepth) | ||
| if !bigIdx.IsUint64() { | ||
| err = fmt.Errorf("%w: %v", ErrIndexTooBig, bigIdx) | ||
| return | ||
| } | ||
|
|
||
| traceIdx := bigIdx.Uint64() + 1 | ||
| timestampIncrements := traceIdx / StepsPerTimestamp | ||
| timestamp = s.prestateTimestamp + timestampIncrements | ||
| if timestamp >= s.poststateTimestamp { // Apply trace extension once the claimed timestamp is reached | ||
| timestamp = s.poststateTimestamp | ||
| step = 0 | ||
| } else { | ||
| step = traceIdx % StepsPerTimestamp | ||
| } | ||
| return | ||
| } | ||
|
|
||
| func (s *SuperNodeTraceProvider) GetStepData(_ context.Context, _ types.Position) (prestate []byte, proofData []byte, preimageData *types.PreimageOracleData, err error) { | ||
| return nil, nil, nil, ErrGetStepData | ||
| } | ||
|
|
||
| func (s *SuperNodeTraceProvider) GetL2BlockNumberChallenge(_ context.Context) (*types.InvalidL2BlockNumberChallenge, error) { | ||
| // Never need to challenge L2 block number for super root games. | ||
| return nil, types.ErrL2BlockNumberValid | ||
| } | ||
|
|
||
| var _ types.TraceProvider = (*SuperNodeTraceProvider)(nil) | ||
Oops, something went wrong.
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.
a note for the supernode RPC: We expect the chains in the response to be sorted by their chain IDs
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.
Definitely.
eth.NewSuperV1will do that automatically - otherwise you'd get a different (incorrect) super root.