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 2.97619% with 489 lines in your changes missing coverage. Please review.
✅ Project coverage is 33.11%. Comparing base (02566fc) to head (edec88f).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4169      +/-   ##
==========================================
- Coverage   33.41%   33.11%   -0.31%     
==========================================
  Files         461      462       +1     
  Lines       55901    55976      +75     
==========================================
- Hits        18681    18534     -147     
- Misses      33921    34179     +258     
+ Partials     3299     3263      -36     

@github-actions
Copy link

github-actions bot commented Dec 22, 2025

❌ 9 Tests Failed:

Tests completed Failed Passed Skipped
4478 9 4469 0
View the top 3 failed tests by shortest run time
TestDataStreaming_PositiveScenario/Many_senders,_long_messages
Stack Traces | 0.110s run time
... [CONTENT TRUNCATED: Keeping last 20 lines]
        github.com/offchainlabs/nitro/daprovider/data_streaming.testBasic.func1()
        	/home/runner/work/nitro/nitro/daprovider/data_streaming/protocol_test.go:230 +0x19b
        created by github.com/offchainlabs/nitro/daprovider/data_streaming.testBasic in goroutine 152
        	/home/runner/work/nitro/nitro/daprovider/data_streaming/protocol_test.go:223 +0x85
        
    protocol_test.go:230: �[31;1m [] too much time has elapsed since request was signed �[0;0m
WARN [12-31|15:17:17.049] Served datastreaming_start               conn=127.0.0.1:44758 reqid=10 duration=31.566213ms err="too much time has elapsed since request was signed"
INFO [12-31|15:17:17.067] rpc response                             method=datastreaming_start logId=10 err="too much time has elapsed since request was signed" result={} attempt=0 args="[\"0x69553e7c\", \"0x24\", \"0xd9\", \"0x1df1\", \"0xa\", \"0x4afc09dfaae015dbd6607591ebe3c9a8cd6d2ab364756ce88a03ecb660a338002f251d6d33a4cc134c508e894e3cd4d2e875bfbb03eced89158b0a33c423511601\"]" errorData=null
    protocol_test.go:230: goroutine 308 [running]:
        runtime/debug.Stack()
        	/opt/hostedtoolcache/go/1.25.5/x64/src/runtime/debug/stack.go:26 +0x5e
        github.com/offchainlabs/nitro/util/testhelpers.RequireImpl({0x161f1b0, 0xc000572540}, {0x1605a00, 0xc000d817d0}, {0x0, 0x0, 0x0})
        	/home/runner/work/nitro/nitro/util/testhelpers/testhelpers.go:29 +0x9f
        github.com/offchainlabs/nitro/daprovider/data_streaming.testBasic.func1()
        	/home/runner/work/nitro/nitro/daprovider/data_streaming/protocol_test.go:230 +0x19b
        created by github.com/offchainlabs/nitro/daprovider/data_streaming.testBasic in goroutine 152
        	/home/runner/work/nitro/nitro/daprovider/data_streaming/protocol_test.go:223 +0x85
        
    protocol_test.go:230: �[31;1m [] too much time has elapsed since request was signed �[0;0m
--- FAIL: TestDataStreaming_PositiveScenario/Many_senders,_long_messages (0.11s)
TestDataStreaming_PositiveScenario
Stack Traces | 0.130s run time
=== RUN   TestDataStreaming_PositiveScenario
--- FAIL: TestDataStreaming_PositiveScenario (0.13s)
TestVersion40
Stack Traces | 5.740s run time
... [CONTENT TRUNCATED: Keeping last 20 lines]
=== CONT  TestVersion40
�[38;5;48;1myay!! we validated block 2 in 171.49ms�[0;0m
    precompile_inclusion_test.go:94: goroutine 610561 [running]:
        runtime/debug.Stack()
        	/opt/hostedtoolcache/go/1.25.5/x64/src/runtime/debug/stack.go:26 +0x5e
        github.com/offchainlabs/nitro/util/testhelpers.RequireImpl({0x4111810, 0xc01dafcc40}, {0x40ce7c0, 0xc0f6ba4690}, {0x0, 0x0, 0x0})
        	/home/runner/work/nitro/nitro/util/testhelpers/testhelpers.go:29 +0x55
        github.com/offchainlabs/nitro/system_tests.Require(0xc01dafcc40, {0x40ce7c0, 0xc0f6ba4690}, {0x0, 0x0, 0x0})
        	/home/runner/work/nitro/nitro/system_tests/common_test.go:2031 +0x5d
        github.com/offchainlabs/nitro/system_tests.testPrecompiles(0xc01dafcc40, 0x28, {0xc128747df8, 0x5, 0x39?})
        	/home/runner/work/nitro/nitro/system_tests/precompile_inclusion_test.go:94 +0x371
        github.com/offchainlabs/nitro/system_tests.TestVersion40(0xc01dafcc40?)
        	/home/runner/work/nitro/nitro/system_tests/precompile_inclusion_test.go:71 +0x64b
        testing.tRunner(0xc01dafcc40, 0x3d4eba8)
        	/opt/hostedtoolcache/go/1.25.5/x64/src/testing/testing.go:1934 +0xea
        created by testing.(*T).Run in goroutine 1
        	/opt/hostedtoolcache/go/1.25.5/x64/src/testing/testing.go:1997 +0x465
        
    precompile_inclusion_test.go:94: �[31;1m [] execution aborted (timeout = 5s) �[0;0m
--- FAIL: TestVersion40 (5.74s)

📣 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
Comment on lines 634 to 641
if chainConfig == nil {
chainConfig, err = getChainConfig(config, initDataReader, executionDB)
if err != nil {
return nil, nil, err
}
}

parsedInitMessage, err := getConsensusParsedInitMsg(ctx, config, chainId, l1Client, rollupAddrs, chainConfig)
Copy link
Contributor Author

@bragaigor bragaigor Dec 24, 2025

Choose a reason for hiding this comment

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

This part in particular, might different a bit in logic from the current chainConfig lifecycle which is as follows:

readOnlyDB, err := stack.OpenDatabaseWithOptions
if err == nil {
   chainConfig := gethexec.TryReadStoredChainConfig(readOnlyDB)
   if chainConfig != nil {
      validateBlockChain(l2BlockChain, chainConfig)
      return rebuildLocalWasm(... l2BlockChain, executionDB, ...)
   }
}

var chainConfig *params.ChainConfig
if config.Init.GenesisJsonFile != "" {
   chainConfig = gen.Config
}
if initDataReader == nil {
   chainConfig = gethexec.TryReadStoredChainConfig(executionDB)
   if chainConfig == nil { return error }
else {
   if chainConfig == nil {
      chainConfig, err = chaininfo.GetChainConfig(...)
      if err != nil {return err}
   }
}
validateBlockChain(l2BlockChain, chainConfig)
return rebuildLocalWasm(... l2BlockChain, executionDB, ...)

And now is:

..., chainConfig, err := openExistingExecutionDB
// if evaluated to true then chainConfig is also nil
if executionDB == nil {
   ..., chainConfig, ..., err = getInit(config)
   if chainConfig == nil {
      chainConfig, err = getChainConfig(config, initDataReader, executionDB)
   }
}
if chainConfig == nil { return error }
validateBlockChain(l2BlockChain, chainConfig)
return rebuildLocalWasm(... l2BlockChain, executionDB, ...)

@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 🙂

Require(t, err)
}

func TestOpenDownloadedExecutionDB(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can also create a test for openExistingExecutionDB.
You can move openExistingExecutionDB out of the main package, so it is able to be imported by system test.
You can create a system test that starts a L2 chain, create some blocks, stop the chain, and then calls openExistingExecutionDB.
Something similar to TestDatabaseConversion.
Then you can check if it is properly able to read executionDB, reading a block hash with rawdb.ReadCanonicalHash for example.

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 would be nice so I created ticket NIT-4268 to do on another PR as I thought it would make things look more organized if done separately. But please let me know if you prefer this to be done in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implemented them in 67f56ab

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

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.

Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
Add checkDBDir tests

Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
- Create new config package to expose and organize
init and config nitro functionality.
- Add new system_tests for openExistingExecutionDB
and getConsensusParsedInitMsg

Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
@bragaigor bragaigor force-pushed the braga/refactor-openInitialzeChainDb branch from 416a75e to 67f56ab Compare December 31, 2025 14:48
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@diegoximenes these are the system_tests I included for openExistingExecutionDB and getConsensusParsedInitMsg. As a result of exposing those functions I created config package under cmd/nitro; not sure if config is too generic of a name. Still looking at how to test getGenesisAssertionCreationInfo without introducing too much code, will update after trying some more.

@bragaigor bragaigor removed their assignment Dec 31, 2025
Signed-off-by: Igor Braga <5835477+bragaigor@users.noreply.github.com>
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