Skip to content

Conversation

@bragaigor
Copy link
Contributor

@bragaigor bragaigor commented Dec 22, 2025

Today openInitializeChainDb has procedures related to both Execution and Consensus components. So we split them into target functions related specifically to either Execution and Consensus.

Now openInitializeChainDb can be thought of as:

openInitializeChainDb(...)
|
├─> executionDB := openExistingExecutionDB(...) (executionDB, wasmDB, chainConfig)
|
├─> If executionDB == nil
|   |
|   ├─> checkAndDownloadDB(...)
|   |
|   ├─> openDownloadedExecutionDB(...) (executionDB, wasmDB)
|   |
|   ├─> getConsensusParsedInitMsg(...)
|   |
|   ├─> getNewBlockchain(...)
|   |
|   └─> getAndValidateGenesisAssertion
|
├─> PruneExecutionDB(...)
|
├─> validateBlockChain(...)
|
└─> recreateMissingStates(...)
|
└─> rebuildLocalWasm(...) (executionDB, l2BlockChain)

closes NIT-4199
closes NIT-4268

@codecov
Copy link

codecov bot commented Dec 22, 2025

Codecov Report

❌ Patch coverage is 3.04878% with 477 lines in your changes missing coverage. Please review.
✅ Project coverage is 32.55%. Comparing base (893facb) to head (6738f16).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4169      +/-   ##
==========================================
- Coverage   32.69%   32.55%   -0.14%     
==========================================
  Files         476      483       +7     
  Lines       56785    57089     +304     
==========================================
+ Hits        18564    18586      +22     
- Misses      34986    35254     +268     
- Partials     3235     3249      +14     

@github-actions
Copy link
Contributor

github-actions bot commented Dec 22, 2025

✅ All tests successful. No failed tests were found.

📣 Thoughts on this report? Let Codecov know! | Powered by Codecov

@bragaigor bragaigor force-pushed the braga/refactor-openInitialzeChainDb branch from 4ac62dd to 1826ff4 Compare December 22, 2025 21:11
@pmikolajczyk41 pmikolajczyk41 self-requested a review December 23, 2025 17:13
@bragaigor bragaigor force-pushed the braga/refactor-openInitialzeChainDb branch from 0bab452 to 7b16439 Compare December 24, 2025 13:59
@bragaigor bragaigor marked this pull request as ready for review December 24, 2025 15:16
Copy link
Contributor

@diegoximenes diegoximenes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about checking if it is easy to extend a bold test so it can test getGenesisAssertionCreationInfo and validateGenesisAssertion?
If it is easy then the test can be implemented 🙂

Copy link
Member

@pmikolajczyk41 pmikolajczyk41 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throwing two secondary comments for now

@bragaigor bragaigor assigned diegoximenes and unassigned bragaigor Dec 29, 2025
@bragaigor bragaigor force-pushed the braga/refactor-openInitialzeChainDb branch from 416a75e to 67f56ab Compare December 31, 2025 14:48
Copy link
Contributor

@diegoximenes diegoximenes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Focused on only reviewing the commits added after my last review.

Code is way better than it was 🙂

Requesting changes mainly due to the lack of tests related to validate genesis assertion procedure.
We can discuss out of GitHub on how to test this in this PR, or if changes related to it can be reverted and introduced/tested in a new PR.
Also added some minor nitpicks, and some extra tests that can be added.

@bragaigor bragaigor force-pushed the braga/refactor-openInitialzeChainDb branch from d67dee7 to 9a6a20e Compare January 17, 2026 01:48
Copy link
Contributor

@diegoximenes diegoximenes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't review tests this time

Copy link
Contributor

@diegoximenes diegoximenes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: In case you find it will take more time to implement validate genesis assertion tests, you can revert changes related to validate genesis assertion, and open another PR to only implement those changes and the tests.
This PR already makes good improvements to the codebase, and we can merge it sooner.

The test for validate genesis assertion, if code related to it is changed, is a requirement.
Reviews of this part of the codebase already spotted some issues, which indicate that it is a good idea to have tests related to it.
Also, I am not completely sure how much coverage this validate genesis assertion procedure has is release qualification tests.

@bragaigor
Copy link
Contributor Author

Suggestion: In case you find it will take more time to implement validate genesis assertion tests, you can revert changes related to validate genesis assertion, and open another PR to only implement those changes and the tests.
This PR already makes good improvements to the codebase, and we can merge it sooner.

Chatted with @rauljordan and was able to jot down a concise test for genesis assertion. Such test can be found in system_tests/genesis_assertion_test.go and in there you'll find 2 tests:

  • One that uses createCompleteTestNodeOnL1 (used by BoLD tests)
  • And another that uses builder

I thought to keep both since each of them starts L1 chain with different configuration, but let me know if you prefer to keep just one of them.

}

func getGenesisAssertionCreationInfo(ctx context.Context, rollupAddress common.Address, l1Client *ethclient.Client, genesisMsgResult *execution.MessageResult) (*protocol.AssertionCreatedInfo, [32]byte, error) {
func getGenesisAssertionCreationInfo(ctx context.Context, rollupAddress common.Address, l1Client *ethclient.Client, genesisHash common.Hash, sendRoot common.Hash) (*protocol.AssertionCreatedInfo, [32]byte, error) {
Copy link
Contributor

@diegoximenes diegoximenes Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is not a bold chain then getGenesisAssertionCreationInfo is returning a nil err, with an empty assertion hash.
However, in this case, GetAndValidateGenesisAssertion shouldn't continue and call validateGenesisAssertion.
getGenesisAssertionCreationInfo returning a bool, indicating if it is a bold chain, can help with that.

If possible, a test related to that should be added.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added but will still try to add a test for it as it didn't seem that straightforward to force getGenesisAssertionCreationInfo into returning a not bold error, which would require for the call to ChallengeGracePeriodBlocks return an error.

t.Fatalf("Expected chainConfig to be non nil")
}

expectedChainConfig := chaininfo.ArbitrumOneChainConfig()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some tests here are not able to detect if chain config returned by GetInit comes from gethexec.TryReadStoredChainConfig or chaininfo.GetChainConfig.

Using TestGetInitSkipInitDataReader as an example, you can OpenInitializeExecutionDB providing a node config with chain ID different than 42161, and then call GetInit providing another chain ID.

WDYT?

Copy link
Contributor Author

@bragaigor bragaigor Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, and I don't think we're testing the case that chain config returned by GetInit comes from gethexec.TryReadStoredChainConfig so I added a test for that at the bottom.

Comment on lines 88 to 90
// Make sure we shut down test functionality before the rest of the node
ctx, cancelCtx = context.WithCancel(ctx)
defer cancelCtx()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw that this exists in other bold tests, but I don't get why new values need to be assigned to ctx, cancelCtx here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true, we already defer ctx cancel at the very beginning. This feels redundant for this test at least. Maybe ctx changes for BoLD test but not here.

Comment on lines +100 to +101
// sure that nil assertions have no leftover accounts; however, that does not apply to a test
// environment, which is why it is safe to remove such account (genesis account) from ArbInitData
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have no leftover accounts

Not sure what you mean by leftover accounts here.

however, that does not apply to a test environment, which is why it is safe to remove any account from ArbInitData

This is not clear to me why 🤔, maybe I am missing some context about this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's probably my poor explanation. So when we call GetAndValidateGenesisAssertion, one of the parameters passed to validateGenesisAssertion is initDataReaderHasAccounts, which is coming from accountsReader.More() here.

accountsReader.More() calls into:

func (f *FieldReader) More() bool {
return f.count < f.length
}

if we backtrack a bit inside GetAndValidateGenesisAssertion we convert initDataReader into accountsReader with:

accountsReader, err := initDataReader.GetAccountDataReader()

and that's where we set length to the length of accounts:

func (r *MemoryInitDataReader) GetAccountDataReader() (AccountDataReader, error) {
return &MemoryAccountDataReader{
FieldReader: FieldReader{
m: r,
length: len(r.d.Accounts),
},

so as long as there's one or more accounts in builder.L2Info.ArbInitData, then GetAndValidateGenesisAssertion will always fail with genesis assertion is null but there are accounts in the init data. And that's what I call leftover accounts because it's a test environment, meaning, if we were dealing with a real chain and we set ValidateGenesisAssertion to true then initDataReaderHasAccounts would have been false. It's still unclear to me why in the case of new chains that's a problem but according to @rauljordan it seems to be a legacy configuration. We could remove that flag but not sure if that would result in introducing some unforseen bug that's not that clear right now.

Does that make sense?

// assertion is nil or not. When a chain is deployed, a genesis assertion is created. Such new chain
// deployment can happen from scratch or as part of a chain upgrade. In the first case, genesis
// chain assertion BeforeState and AfterState will be both zero since there's nothing before genesis.
// On the other hand, for the latter case, AfterState will be non zero since the rollup has been
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "rollup" an appropriate name here?

This latter case that you mention is: an Arbitrum chain is running without the bold protocol, and then there is an upgrade to use the bold protocol, right?
If that is true, then we are already testing GetAndValidateGenesisAssertion for the first case, through release qualification tests against Sepolia/Arb1, right?

Copy link
Contributor Author

@bragaigor bragaigor Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "rollup" an appropriate name here?

Renaming to chain

This latter case that you mention is: an Arbitrum chain is running without the bold protocol, and then there is an upgrade to use the bold protocol, right?

that is correct

If that is true, then we are already testing GetAndValidateGenesisAssertion for the first case, through release qualification tests against Sepolia/Arb1, right?

if ValidateGenesisAssertion is set to true then yes. But the only place I saw that being set to true was in InitConfigDefault here, unless that's coming from somewhere else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants