-
Notifications
You must be signed in to change notification settings - Fork 624
feat(rollup-relayer): support Validium #1693
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: develop
Are you sure you want to change the base?
Conversation
""" WalkthroughThe changes introduce a "validium mode" to the rollup system, affecting batch proposal, relayer logic, configuration, and ABI handling. This includes new ABI definitions for Validium, configuration flags, mode-aware logic in relayer and batch proposer components, and updated utility functions for batch encoding and metadata extraction in validium mode. Changes
Sequence Diagram(s)sequenceDiagram
participant Config
participant App
participant BatchProposer
participant Relayer
participant Utils
Config->>App: Provide ValidiumMode flag
App->>BatchProposer: SetValidiumMode(ValidiumMode)
BatchProposer->>Utils: CalculateBatchMetrics(..., validiumMode)
Relayer->>Utils: GetBatchMetadata(..., validiumMode)
Relayer->>Relayer: If ValidiumMode, use validium ABI for calldata
Relayer->>ValidiumABI: Pack calldata for commit/finalize (validium mode)
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ 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). (3)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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: 3
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
common/version/version.go
(1 hunks)rollup/abi/validium_abi.go
(1 hunks)rollup/cmd/rollup_relayer/app/app.go
(1 hunks)rollup/conf/config.json
(2 hunks)rollup/internal/config/relayer.go
(1 hunks)rollup/internal/controller/relayer/l2_relayer.go
(9 hunks)rollup/internal/controller/watcher/batch_proposer.go
(7 hunks)rollup/internal/orm/batch.go
(1 hunks)rollup/internal/utils/utils.go
(4 hunks)
🧰 Additional context used
🧠 Learnings (6)
rollup/conf/config.json (1)
Learnt from: colinlyguo
PR: scroll-tech/scroll#1645
File: rollup/proposer-tool-config.json:34-40
Timestamp: 2025-04-15T08:52:44.176Z
Learning: In configuration files like `rollup/proposer-tool-config.json`, placeholders such as `<mainnet read db config>` are intentionally left as-is to be replaced by users with their own configuration values when deploying the tool.
rollup/cmd/rollup_relayer/app/app.go (1)
Learnt from: colinlyguo
PR: scroll-tech/scroll#1530
File: rollup/internal/controller/watcher/batch_proposer.go:291-294
Timestamp: 2024-10-20T16:13:20.397Z
Learning: In `batch_proposer.go`, it's acceptable to call `utils.CalculateBatchMetrics` multiple times within the loop because the batch's chunks are increasing in the loop, and each calculation reflects the updated batch state.
rollup/internal/controller/watcher/batch_proposer.go (1)
Learnt from: colinlyguo
PR: scroll-tech/scroll#1530
File: rollup/internal/controller/watcher/batch_proposer.go:291-294
Timestamp: 2024-10-20T16:13:20.397Z
Learning: In `batch_proposer.go`, it's acceptable to call `utils.CalculateBatchMetrics` multiple times within the loop because the batch's chunks are increasing in the loop, and each calculation reflects the updated batch state.
rollup/internal/orm/batch.go (1)
Learnt from: colinlyguo
PR: scroll-tech/scroll#1530
File: rollup/internal/controller/watcher/batch_proposer.go:291-294
Timestamp: 2024-10-20T16:13:20.397Z
Learning: In `batch_proposer.go`, it's acceptable to call `utils.CalculateBatchMetrics` multiple times within the loop because the batch's chunks are increasing in the loop, and each calculation reflects the updated batch state.
rollup/internal/utils/utils.go (1)
Learnt from: colinlyguo
PR: scroll-tech/scroll#1530
File: rollup/internal/controller/watcher/batch_proposer.go:291-294
Timestamp: 2024-10-20T16:13:20.397Z
Learning: In `batch_proposer.go`, it's acceptable to call `utils.CalculateBatchMetrics` multiple times within the loop because the batch's chunks are increasing in the loop, and each calculation reflects the updated batch state.
rollup/internal/controller/relayer/l2_relayer.go (1)
Learnt from: colinlyguo
PR: scroll-tech/scroll#1530
File: rollup/internal/controller/watcher/batch_proposer.go:291-294
Timestamp: 2024-10-20T16:13:20.397Z
Learning: In `batch_proposer.go`, it's acceptable to call `utils.CalculateBatchMetrics` multiple times within the loop because the batch's chunks are increasing in the loop, and each calculation reflects the updated batch state.
🧬 Code Graph Analysis (3)
rollup/cmd/rollup_relayer/app/app.go (2)
rollup/internal/config/l2.go (1)
L2Config
(10-29)rollup/internal/config/relayer.go (1)
RelayerConfig
(55-82)
rollup/internal/orm/batch.go (1)
rollup/internal/utils/utils.go (1)
GetBatchMetadata
(148-207)
rollup/internal/utils/utils.go (2)
rollup/internal/orm/batch.go (2)
Batch
(22-72)Batch
(80-82)coordinator/internal/types/auth.go (1)
Hash
(134-141)
⏰ 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). (3)
- GitHub Check: tests
- GitHub Check: check
- GitHub Check: tests
🔇 Additional comments (7)
common/version/version.go (1)
8-8
: LGTM: Version bump is correctly implemented.The version increment from v4.5.27 to v4.5.28 properly reflects the addition of new Validium mode functionality.
rollup/conf/config.json (1)
39-39
: LGTM: Well-structured configuration addition.The
validium_mode
field is appropriately placed within the relayer configuration and uses a safe default value offalse
for backward compatibility.rollup/internal/config/relayer.go (1)
56-57
: LGTM: Proper struct field implementation.The
ValidiumMode
field is correctly added with appropriate JSON tagging and a clear descriptive comment. The placement at the beginning of the struct is logical for a fundamental operational mode setting.rollup/cmd/rollup_relayer/app/app.go (1)
111-111
: Confirmed:SetValidiumMode
Exists onBatchProposer
The
SetValidiumMode(validiumMode bool)
method is defined in
rollup/internal/controller/watcher/batch_proposer.go:134
.
The integration inrollup/cmd/rollup_relayer/app/app.go:111
is correct and can be approved.rollup/internal/orm/batch.go (1)
288-288
: LGTM: Correct function signature alignment.The addition of
metrics.ValidiumMode
parameter correctly aligns with the updatedGetBatchMetadata
function signature that now accepts avalidiumMode
boolean parameter.rollup/internal/controller/watcher/batch_proposer.go (1)
35-35
: LGTM! Validium mode integration is clean and consistent.The addition of the
validiumMode
field with proper initialization and the consistent propagation to allCalculateBatchMetrics
calls is well implemented.Also applies to: 67-68, 133-137, 181-181, 297-297, 322-322, 332-332
rollup/internal/controller/relayer/l2_relayer.go (1)
1017-1019
: Confirm EndBlockHash usage as validium commitmentWe weren’t able to locate any in-repo documentation or examples that define how the commitment should be derived for validium mode. The code currently does:
lastChunk := lastBatch.Chunks[len(lastBatch.Chunks)-1] commitment := common.HexToHash(lastChunk.EndBlockHash)Please verify against the official validium protocol specification that using the last chunk’s
EndBlockHash
here is the correct source for the commitment.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1693 +/- ##
===========================================
+ Coverage 39.86% 39.87% +0.01%
===========================================
Files 236 233 -3
Lines 18808 18369 -439
===========================================
- Hits 7498 7325 -173
+ Misses 10575 10336 -239
+ Partials 735 708 -27
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
// Generated manually from abigen. | ||
|
||
// ValidiumMetaData contains all meta data concerning the ScrollChain contract. | ||
var ValidiumMetaData = &bind.MetaData{ |
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 you please generate these from the latest contract version? (Ignore this comment if you already did it.)
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.
Updated with this commit: f4d6e67. We can update it again after contract implementation is finalized (maybe merged).
rollup/cmd/rollup_relayer/app/app.go
Outdated
@@ -108,6 +108,7 @@ func action(ctx *cli.Context) error { | |||
|
|||
chunkProposer := watcher.NewChunkProposer(subCtx, cfg.L2Config.ChunkProposerConfig, minCodecVersion, genesis.Config, db, registry) | |||
batchProposer := watcher.NewBatchProposer(subCtx, cfg.L2Config.BatchProposerConfig, minCodecVersion, genesis.Config, db, registry) | |||
batchProposer.SetValidiumMode(cfg.L2Config.RelayerConfig.ValidiumMode) |
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.
Why not just pass it in NewBatchProposer
?
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.
This is added to not modify the parameters of NewBatchProposer
, but true based on your comment it's clearer, so changed to pass it in NewBatchProposer
with this commit: f4d6e67.
log.Error("failed to construct constructCommitBatchPayloadCodecV7 payload for V7", "codecVersion", codecVersion, "start index", firstBatch.Index, "end index", lastBatch.Index, "err", err) | ||
return | ||
if r.cfg.ValidiumMode { | ||
calldata, maxBlockHeight, totalGasUsed, err = r.constructCommitBatchPayloadValidium(batchesToSubmit, firstBatch) |
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.
This made me think. If we have multiple pending batches, maybe we should actually recreate them into a single batch; there's no point in committing in multiple steps (apart from controlling the prover workload). Something to consider in a later version.
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.
I think currently it's OK because timeout seems to be the only limit of batch proposing, so that the batch can be very large. It would be rare that there are many pending batches in db unless batch commit is stuck. I may misunderstand the real issue and miss some cases.
To apply batch merging, since inter-component coordination, such as freeze batch-proposer
and bundle-proposer
, and tweak db, would be a bit tricky.
Another way is to support commitBatches
in the contract (though this only partially solved the cost problem).
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.
Or do these limits of v7 and v8 chunk/batch still apply?
"chunk_proposer_config": {
"propose_interval_milliseconds": 100,
"max_block_num_per_chunk": 100,
"max_l2_gas_per_chunk": 20000000,
"chunk_timeout_sec": 300,
"max_uncompressed_batch_bytes_size": 4194304
},
"batch_proposer_config": {
"propose_interval_milliseconds": 1000,
"batch_timeout_sec": 300,
"max_chunks_per_batch": 45,
"max_uncompressed_batch_bytes_size": 4194304
},
"bundle_proposer_config": {
"max_batch_num_per_bundle": 20,
"bundle_timeout_sec": 36000
},
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.
Also found that currently it will not commit one batch at a time, fixed in this commit: 7dfb8b5.
rollup/internal/utils/utils.go
Outdated
parentHashSize = 32 | ||
stateRootSize = 32 | ||
withdrawRootSize = 32 | ||
commitmentSize = 32 |
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.
We might use larger commitment in the future; for now let's keep it as 32 bytes.
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.
Added a comment in this commit: f4d6e67, also other TODO comments in related commitment
places.
rollup/internal/utils/utils.go
Outdated
|
||
// For validium mode, use the last block hash as commitment to the off-chain data | ||
var commitment common.Hash | ||
if len(b.Blocks) > 0 { |
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.
We should not allow the case when len(blocks) == 0
.
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.
Added a check and error return in f4d6e67.
Co-authored-by: Péter Garamvölgyi <[email protected]>
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: 0
🧹 Nitpick comments (1)
rollup/internal/controller/relayer/l2_relayer.go (1)
984-1027
: Consider the validium commitment strategy and batch processing differences.The function correctly implements validium-specific logic:
- Uses last block hash as commitment (acknowledged as temporary in TODO)
- Calculates metrics without processing individual L2 blocks (appropriate for validium)
- Validates batch consistency and codec versions
However, consider if the temporary commitment strategy meets security requirements for your use case.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
rollup/abi/validium_abi.go
(1 hunks)rollup/cmd/rollup_relayer/app/app.go
(1 hunks)rollup/internal/controller/relayer/l2_relayer.go
(9 hunks)rollup/internal/controller/watcher/batch_proposer.go
(7 hunks)rollup/internal/controller/watcher/batch_proposer_test.go
(4 hunks)rollup/internal/controller/watcher/bundle_proposer_test.go
(1 hunks)rollup/internal/controller/watcher/proposer_tool.go
(1 hunks)rollup/internal/utils/utils.go
(4 hunks)rollup/tests/rollup_test.go
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
- rollup/cmd/rollup_relayer/app/app.go
- rollup/internal/controller/watcher/batch_proposer.go
- rollup/internal/utils/utils.go
- rollup/abi/validium_abi.go
🧰 Additional context used
🧠 Learnings (5)
rollup/internal/controller/watcher/proposer_tool.go (1)
Learnt from: colinlyguo
PR: scroll-tech/scroll#1530
File: rollup/internal/controller/watcher/batch_proposer.go:291-294
Timestamp: 2024-10-20T16:13:20.397Z
Learning: In `batch_proposer.go`, it's acceptable to call `utils.CalculateBatchMetrics` multiple times within the loop because the batch's chunks are increasing in the loop, and each calculation reflects the updated batch state.
rollup/tests/rollup_test.go (1)
Learnt from: colinlyguo
PR: scroll-tech/scroll#1530
File: rollup/internal/controller/watcher/batch_proposer.go:291-294
Timestamp: 2024-10-20T16:13:20.397Z
Learning: In `batch_proposer.go`, it's acceptable to call `utils.CalculateBatchMetrics` multiple times within the loop because the batch's chunks are increasing in the loop, and each calculation reflects the updated batch state.
rollup/internal/controller/watcher/bundle_proposer_test.go (1)
Learnt from: colinlyguo
PR: scroll-tech/scroll#1530
File: rollup/internal/controller/watcher/batch_proposer.go:291-294
Timestamp: 2024-10-20T16:13:20.397Z
Learning: In `batch_proposer.go`, it's acceptable to call `utils.CalculateBatchMetrics` multiple times within the loop because the batch's chunks are increasing in the loop, and each calculation reflects the updated batch state.
rollup/internal/controller/watcher/batch_proposer_test.go (1)
Learnt from: colinlyguo
PR: scroll-tech/scroll#1530
File: rollup/internal/controller/watcher/batch_proposer.go:291-294
Timestamp: 2024-10-20T16:13:20.397Z
Learning: In `batch_proposer.go`, it's acceptable to call `utils.CalculateBatchMetrics` multiple times within the loop because the batch's chunks are increasing in the loop, and each calculation reflects the updated batch state.
rollup/internal/controller/relayer/l2_relayer.go (2)
Learnt from: colinlyguo
PR: scroll-tech/scroll#1693
File: rollup/abi/validium_abi.go:13-15
Timestamp: 2025-07-07T12:02:52.191Z
Learning: In the Scroll codebase, ABI initialization in files like bridge_abi.go and validium_abi.go follows a consistent pattern of ignoring errors from GetAbi() in init functions to maintain code style consistency across the project.
Learnt from: colinlyguo
PR: scroll-tech/scroll#1530
File: rollup/internal/controller/watcher/batch_proposer.go:291-294
Timestamp: 2024-10-20T16:13:20.397Z
Learning: In `batch_proposer.go`, it's acceptable to call `utils.CalculateBatchMetrics` multiple times within the loop because the batch's chunks are increasing in the loop, and each calculation reflects the updated batch state.
⏰ 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). (3)
- GitHub Check: tests
- GitHub Check: check
- GitHub Check: tests
🔇 Additional comments (10)
rollup/internal/controller/watcher/proposer_tool.go (1)
128-128
: LGTM: Constructor update is consistent with validium mode support.The addition of the
false /* rollup mode */
parameter aligns with the BatchProposer constructor signature update to support both rollup and validium modes.rollup/internal/controller/watcher/bundle_proposer_test.go (1)
106-106
: LGTM: Test constructor update is correct.The test correctly specifies rollup mode with the
false /* rollup mode */
parameter, which is appropriate for general batch proposer testing.rollup/tests/rollup_test.go (1)
131-131
: LGTM: Test constructor update maintains existing behavior.The explicit
false /* rollup mode */
parameter ensures the test continues to use rollup mode as expected.rollup/internal/controller/watcher/batch_proposer_test.go (1)
103-103
: LGTM: Consistent test constructor updates across all test functions.All test functions correctly add the
false /* rollup mode */
parameter to maintain existing rollup mode behavior in tests.Also applies to: 181-181, 249-249, 338-338
rollup/internal/controller/relayer/l2_relayer.go (6)
82-82
: LGTM: ValidiumABI field addition and initialization.The validiumABI field is properly added and initialized from the bridgeAbi package, following the same pattern as the existing l1RollupABI.
Also applies to: 176-176
279-296
: LGTM: Genesis batch commitment logic branches correctly for validium mode.The conditional logic properly handles both rollup and validium modes:
- Validium mode: Only passes batchHeader to importGenesisBatch
- Rollup mode: Passes both batchHeader and stateRoot
- Logging appropriately identifies the mode being used
Also applies to: 303-303, 328-328
484-496
: LGTM: Batch processing correctly branches based on validium mode.The ProcessPendingBatches function properly calls different payload construction methods based on the validium mode flag, with appropriate error handling for each path.
716-726
: LGTM: Bundle finalization correctly branches based on validium mode.The finalizeBundle function appropriately calls different payload construction methods for validium vs rollup modes with proper error handling.
1045-1045
: LGTM: Added logging for rollup mode finalization.The logging addition provides useful visibility into the rollup mode finalization process, mirroring the logging added for validium mode.
1061-1078
: Validium finalizeBundle always requires aggProofI compared both implementations and confirmed:
- In rollup mode (
constructFinalizeBundlePayloadCodecV7
), anil
aggProof falls back tofinalizeBundlePostEuclidV2NoProof
.- In validium mode (
constructFinalizeBundlePayloadValidium
), anil
aggProof returns an error (lines 1064–1066).- There are no test-bypass flags or special branches for validium mode.
This behavior is intentional: validium finalization cannot proceed without a proof. If you need proof-less finalization in test environments, add a
nil
-proof branch similar to the rollup version.
a398f64
to
7dfb8b5
Compare
Purpose or design rationale of this PR
Support Validium in rollup-relayer.
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:
Deployment tag versioning
Has
tag
incommon/version.go
been updated or have you addedbump-version
label to this PR?Breaking change label
Does this PR have the
breaking-change
label?Summary by CodeRabbit
New Features
Chores