-
Notifications
You must be signed in to change notification settings - Fork 14
WIP:Update AssembleL2Block params #259
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughChanges convert block timestamp handling from Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 1
♻️ Duplicate comments (1)
eth/catalyst/gen_l2blockparams.go (1)
15-24: Generated JSON uses plain numeric timestamp; fix via override, not manual editsThe generated helper structs here use
Timestamp *uint64and assign it directly, sotimestampis encoded as a JSON number. Given the// DO NOT EDITheader and the hexutil override defined for this type, the real fix should be inassembleL2BlockParamsMarshaling(seeeth/catalyst/api_types.go), followed by re-runninggo generate, rather than editing this file directly.Also applies to: 35-49
🧹 Nitpick comments (1)
eth/catalyst/l2_api.go (1)
84-90: Timestamp default/override wiring looks correctDefaulting
timestamptouint64(time.Now().Unix())and conditionally overriding withparams.Timestampbefore callingBuildBlockis sound and matches the new uint64 API. If you ever need stricter control, you could clamp the finaltimestamphere to be at least the parent header timestamp (e.g.,max(parent.Time+1, timestamp)) instead of relying solely on downstream checks, but that’s optional for this change.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
eth/catalyst/api_types.go(1 hunks)eth/catalyst/gen_l2blockparams.go(3 hunks)eth/catalyst/l2_api.go(1 hunks)eth/catalyst/l2_api_test.go(3 hunks)ethclient/authclient/engine.go(2 hunks)miner/miner.go(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
eth/catalyst/l2_api_test.go (1)
common/mclock/mclock.go (1)
Now(34-36)
miner/miner.go (2)
core/types/transaction.go (1)
Transactions(615-615)miner/worker.go (1)
NewBlockResult(73-77)
eth/catalyst/gen_l2blockparams.go (2)
eth/catalyst/api_types.go (1)
AssembleL2BlockParams(41-45)common/hexutil/json.go (1)
Uint64(339-339)
ethclient/authclient/engine.go (2)
eth/catalyst/api_types.go (1)
ExecutableL2Data(91-113)eth/catalyst/gen_l2_ed.go (2)
ExecutableL2Data(18-33)ExecutableL2Data(59-74)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Analyze (go)
🔇 Additional comments (5)
eth/catalyst/l2_api_test.go (3)
111-117: Adaptation to uint64 timestamp in tests is correctPassing
uint64(time.Now().Unix())intoBuildBlockmatches the new signature and preserves prior semantics.
171-176: NewL2Block test updated consistentlyThis
BuildBlockcall is updated to the uint64 timestamp form and remains consistent with the other tests and the miner API.
224-229: NewSafeL2Block test timestamp change is aligned with APIUsing
uint64(time.Now().Unix())here correctly follows the newBuildBlocksignature without altering the test’s intent.ethclient/authclient/engine.go (1)
15-31: Client-side AssembleL2Block wiring and tx marshaling look solidMarshaling each
types.Transactionwith indexed error reporting and threading the optionaltimeStamppointer through toAssembleL2BlockParams.Timestampcleanly match the updated engine API. This method remains straightforward and consistent with the rest of the auth client.miner/miner.go (1)
170-177: BuildBlock API change to uint64 timestamp is correctly implemented across all call sitesThe change to
BuildBlockacceptinguint64timestamp instead oftime.Timeis consistent with howgetPendingusesuint64(time.Now().Unix()), simplifying the API to match the header's native time representation. All call sites in the codebase correctly passuint64timestamps: the catalyst API forwards a properly constructeduint64value, and test code correctly convertstime.Now().Unix()touint64.
| type AssembleL2BlockParams struct { | ||
| Number uint64 `json:"number" gencodec:"required"` | ||
| Transactions [][]byte `json:"transactions"` | ||
| Timestamp *uint64 `json:"timestamp"` | ||
| } |
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.
🧩 Analysis chain
🌐 Web query:
gencodec go-ethereum pointer hexutil override examples
💡 Result:
Summary + minimal example — show how to use gencodec field overrides to make pointer fields marshal/unmarshal with go-ethereum's hexutil types.
Key points
- gencodec supports a "field override" struct: put the alternate (marshal/unmarshal) types there; generated code converts between original and override types. [1]
- Use hexutil types (hexutil.Bytes, hexutil.Big, hexutil.Uint64, etc.) in the override to get 0x-prefixed hex JSON encoding. [2]
- Generated code will use pointer override types for required pointer fields (example of generated code using hexutil shown below). [3]
Minimal example
- Original type (in package types.go)
package mypkg
import "math/big"
type MyStruct struct {
Data []byte json:"data" gencodec:"required"
Amount *big.Int json:"amount" gencodec:"required"
Nonce uint64 json:"nonce" gencodec:"required"
}
-
Override type + go:generate (in same package)
//go:generate gencodec -type MyStruct -field-override mystruct_marshaling -out mystruct_json.go
type mystruct_marshaling struct {
Data hexutil.Bytes // overrides []byte -> hexutil.Bytes
Amount *hexutil.Big // overrides *big.Int -> *hexutil.Big
Nonce hexutil.Uint64json:"nonce"// overrides uint64 -> hexutil.Uint64
} -
Run generator
go generate ./...
What gencodec generates (conceptual)
- MarshalJSON will build an enc struct with the override types and assign:
enc.Data = hexutil.Bytes(m.Data)
enc.Amount = (*hexutil.Big)(m.Amount) // (conversion code is generated)
enc.Nonce = hexutil.Uint64(m.Nonce)
then json.Marshal(&enc) - UnmarshalJSON will decode into pointer override fields (so missing required pointer fields are detected) and convert back into original types. See generated example using hexutil in real projects. [3]
References
- gencodec documentation (field-override behavior, examples). [1]
- go-ethereum hexutil types and behavior (hex marshaling types: Bytes, Big, Uint64). [2]
- Example generated code using hexutil (shows pointer override conversions in generated Marshal/Unmarshal). [3]
🏁 Script executed:
# Search for examples of pointer fields with hexutil in overrides in the repo
rg 'type.*Marshaling\s*struct' -A 10 | head -100Repository: morph-l2/go-ethereum
Length of output: 5492
🏁 Script executed:
# Look for BaseFee patterns in the codebase to see how pointer big.Int fields are overridden
rg 'BaseFee.*\*big.Int' -B 2 -A 5Repository: morph-l2/go-ethereum
Length of output: 15345
🏁 Script executed:
# Find the gen_l2blockparams.go file to see the current generated code
fd 'gen_l2blockparams.go' -x cat {}Repository: morph-l2/go-ethereum
Length of output: 1650
🏁 Script executed:
sed -n '35,60p' eth/catalyst/api_types.goRepository: morph-l2/go-ethereum
Length of output: 1127
🏁 Script executed:
# Also check the override struct to see all override definitions
fd 'api_types.go' -x cat {} | head -100Repository: morph-l2/go-ethereum
Length of output: 4240
🏁 Script executed:
head -80 eth/catalyst/api_types.goRepository: morph-l2/go-ethereum
Length of output: 3321
🏁 Script executed:
# Find the second struct around lines 48-52
sed -n '40,80p' eth/catalyst/api_types.goRepository: morph-l2/go-ethereum
Length of output: 1745
🏁 Script executed:
sed -n '40,80p' eth/catalyst/api_types.goRepository: morph-l2/go-ethereum
Length of output: 1745
🏁 Script executed:
# Look for all override structs
rg 'type.*Marshaling struct' -A 8 eth/catalyst/api_types.goRepository: morph-l2/go-ethereum
Length of output: 1440
🏁 Script executed:
# Get the full content of api_types.go to see both structs
cat eth/catalyst/api_types.goRepository: morph-l2/go-ethereum
Length of output: 5814
Fix pointer/override type mismatch for AssembleL2BlockParams.Timestamp
AssembleL2BlockParams declares Timestamp *uint64 but the override type is non-pointer hexutil.Uint64. gencodec requires matching pointer signatures; this mismatch causes the override to be ignored and timestamp to encode as a plain JSON number instead of a hex quantity like number and other numeric Engine API fields.
Change the override to pointer-typed:
type assembleL2BlockParamsMarshaling struct {
Number hexutil.Uint64
Transactions []hexutil.Bytes
- Timestamp hexutil.Uint64
+ Timestamp *hexutil.Uint64
}Then regenerate with go generate ./... so gen_l2blockparams.go properly encodes/decodes timestamp as a hex quantity.
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In eth/catalyst/api_types.go around lines 41 to 45, the
AssembleL2BlockParams.Timestamp field is declared as *uint64 but the gencodec
override used elsewhere is a non-pointer hexutil.Uint64 which causes the
override to be ignored; update the override type to a pointer form (i.e.
*hexutil.Uint64) so it matches the *uint64 field, then run go generate ./... to
regenerate gen_l2blockparams.go so timestamp is encoded/decoded as a hex
quantity.
1. Purpose or design rationale of this PR
...
2. PR title
Your PR title must follow conventional commits (as we are doing squash merge for each PR), so it must start with one of the following types:
3. Deployment tag versioning
Has the version in
params/version.gobeen updated?4. Breaking change label
Does this PR have the
breaking-changelabel?Summary by CodeRabbit
New Features
Changes
✏️ Tip: You can customize this high-level summary in your review settings.