Skip to content

VIEW ONLY: vara-eth testnet re-genesis#5341

Closed
grishasobol wants to merge 2 commits intovara-eth-testnet-5e1092edcfrom
gsobol/ethexe/vara-eth-testnet-re-genesis
Closed

VIEW ONLY: vara-eth testnet re-genesis#5341
grishasobol wants to merge 2 commits intovara-eth-testnet-5e1092edcfrom
gsobol/ethexe/vara-eth-testnet-re-genesis

Conversation

@grishasobol
Copy link
Copy Markdown
Member

No description provided.

@semanticdiff-com
Copy link
Copy Markdown

semanticdiff-com bot commented Apr 13, 2026

Review changes with  SemanticDiff

Changed Files
File Status
  ethexe/ethereum/abi/POAMiddleware.json  100% smaller
  ethexe/ethereum/abi/Middleware.json  100% smaller
  ethexe/ethereum/abi/Mirror.json  100% smaller
  ethexe/ethereum/abi/WrappedVara.json  100% smaller
  ethexe/db/init/src/lib.rs  9% smaller
  ethexe/db/init/src/version1.rs  5% smaller
  ethexe/service/src/tests/mod.rs  1% smaller
  ethexe/db/src/database.rs  1% smaller
  Cargo.lock Unsupported file format
  Cargo.toml Unsupported file format
  ethexe/cli/src/commands/dump.rs  0% smaller
  ethexe/cli/src/commands/mod.rs  0% smaller
  ethexe/cli/src/params/node.rs  0% smaller
  ethexe/contracts/src/Router.sol Unsupported file format
  ethexe/db/Cargo.toml Unsupported file format
  ethexe/db/init/Cargo.toml Unsupported file format
  ethexe/db/src/dump/collect.rs  0% smaller
  ethexe/db/src/dump/mod.rs  0% smaller
  ethexe/db/src/lib.rs  0% smaller
  ethexe/ethereum/abi/Router.json Unsupported file format
  ethexe/ethereum/src/router/mod.rs  0% smaller
  ethexe/observer/src/tests.rs Unsupported file format
  ethexe/service/src/config.rs  0% smaller
  ethexe/service/src/lib.rs Unsupported file format
  ethexe/service/src/tests/utils/env.rs  0% smaller
  ethexe/service/src/tests/utils/mod.rs  0% smaller

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request implements a re-genesis mechanism for the vara-eth testnet. It provides the necessary tools to capture a snapshot of the current chain state—including programs, codes, and storage blobs—and subsequently initialize a new database instance from this snapshot. This functionality is critical for resetting the network state while preserving existing programs and their data.

Highlights

  • State Dump Mechanism: Introduced a new StateDump structure and associated logic to collect and serialize the chain state, enabling re-genesis from a snapshot.
  • CLI Command: Added a new dump CLI command to create state dumps from the database and inspect them as JSON.
  • Genesis Initialization: Implemented a GenesisInitializer trait and updated the database initialization flow to support bootstrapping from a StateDump.
  • Router Contract Update: Added a reGenesis function to the Router contract to allow resetting the genesis block and committed batch info.
Ignored Files
  • Ignored by pattern: ethexe/ethereum/abi/*.json (1)
    • ethexe/ethereum/abi/Router.json
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces re-genesis functionality for the ethexe layer, enabling the chain to be bootstrapped from a state dump. Key additions include a new dump CLI command for creating and inspecting state snapshots, a reGenesis function in the Router Solidity contract, and logic to restore programs, codes, and scheduled tasks from these dumps during database initialization. My review identified several areas for improvement: the dump command may fail due to database locking if run on a live node, the reGenesis contract function lacks a critical event for off-chain tracking, the unsafe keyword is inappropriately used for the memory() database constructor, and the JSON serialization of state blobs is highly memory-inefficient and poses an OOM risk for large dumps.

Comment on lines +80 to +86
let rocks_db = RocksDatabase::open(
self.db
.clone()
.or_else(|| self.params.node.as_ref().map(|node| node.db_dir()))
.context("missing database path")?,
)
.context("failed to open database")?;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

RocksDatabase::open typically acquires an exclusive lock on the database directory. If this command is executed while the node is running, it will fail with a locking error. To support creating state dumps from a live node, consider opening the database in read-only mode (e.g., using RocksDatabase::open_read_only if the wrapper supports it).

Comment thread ethexe/contracts/src/Router.sol Outdated
Comment on lines +129 to +133
function reGenesis(Gear.GenesisBlockInfo memory newGenesis) public onlyOwner {
Storage storage router = _router();
router.genesisBlock = newGenesis;
router.latestCommittedBatch = Gear.CommittedBatchInfo({hash: bytes32(0), timestamp: 0});
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The reGenesis function performs a critical state transition by resetting the genesis block and the latest committed batch. It is highly recommended to emit an event (e.g., event ReGenesis(Gear.GenesisBlockInfo newGenesis)) to allow off-chain components like observers and indexers to detect and handle this transition correctly without relying on polling storage.

Comment thread ethexe/db/src/database.rs
Comment on lines +730 to +733
#[cfg(not(feature = "mock"))]
pub unsafe fn memory() -> Self {
Self::memory_inner()
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The memory() function is marked as unsafe when the mock feature is disabled, but it does not appear to perform any memory-unsafe operations. In Rust, unsafe should be reserved for memory safety. If the intention is to warn users against using this in production, consider using a more descriptive name like unstable_memory(), adding #[doc(hidden)], or using a specific feature gate instead of overloading the unsafe keyword.

Comment thread ethexe/db/src/dump/mod.rs
Comment on lines +59 to +69
fn serialize_blobs<S: Serializer>(blobs: &Vec<Vec<u8>>, serializer: S) -> Result<S::Ok, S::Error> {
let encoded = blobs.encode();

let mut compressed = Vec::new();
let mut encoder = DeflateEncoder::new(&mut compressed, Compression::default());
io::Write::write_all(&mut encoder, &encoded).map_err(serde::ser::Error::custom)?;
encoder.finish().map_err(serde::ser::Error::custom)?;

let hex = format!("0x{}", hex::encode(&compressed));
serializer.serialize_str(&hex)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The custom JSON serialization for blobs is very memory-intensive. It SCALE-encodes the entire vector, compresses it, and then hex-encodes it into a single string using format!. For large state dumps, this can lead to massive memory allocations (potentially several times the size of the actual data) and OOM issues. Since StateDump already implements Encode/Decode for binary format, consider if such an inefficient JSON representation is necessary, or use a more memory-efficient hex encoding approach.

function reGenesis(Gear.GenesisBlockInfo memory newGenesis) public onlyOwner {
Storage storage router = _router();
router.genesisBlock = newGenesis;
router.latestCommittedBatch = Gear.CommittedBatchInfo({hash: bytes32(0), timestamp: 0});
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd prefer different approach: reset router.genesisBlock and router.latestCommittedBatch and set the current block height as we do in the constructor. Then, anyone should call lookupGenesisHash in next block. This prevents the admin from setting any block hash they want.

@grishasobol
Copy link
Copy Markdown
Member Author

No more needed - test-net was updated

@grishasobol grishasobol deleted the gsobol/ethexe/vara-eth-testnet-re-genesis branch April 17, 2026 14:22
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.

2 participants