Skip to content

refactor(vara.eth): introduce typed MB/EB hashes, move MB to ethexe-common - #5508

Draft
grishasobol wants to merge 6 commits into
masterfrom
gsobol/ethexe/malachite-typed-block-hashes
Draft

refactor(vara.eth): introduce typed MB/EB hashes, move MB to ethexe-common#5508
grishasobol wants to merge 6 commits into
masterfrom
gsobol/ethexe/malachite-typed-block-hashes

Conversation

@grishasobol

Copy link
Copy Markdown
Member

Summary

  • Move the consensus block envelope (ethexe_malachite_core::Blockethexe_common::malachite::MB), the versioned BlockPayload, and CompactMb into ethexe-common so the executor crates can use them without depending on the consensus layer.
  • CompactMb now matches MB's shape with the opaque payload replaced by payload_hash (renamed from transactions_hash).
  • Type-safe hashes for boundary fields: HashOf<MB> on CompactMb.parent, BlockMeta.last_committed_mb, DBGlobals.{latest_finalized_mb_hash, latest_computed_mb_hash}; HashOf<EB> on MbMeta.last_advanced_eb, BlockMeta.last_committed_eb, DBGlobals.{start_block_hash, latest_prepared_eb_hash}, DBConfig.genesis_block_hash.
  • New pub type EB = SimpleBlockData + SimpleBlockData::typed_hash() / eb_hash_of(H256) to lift the bare Ethereum block hash into the typed wrapper.
  • HashOf<T> is Encode + Decode as a bare 32-byte hash (phantom is #[codec(skip)]), so the on-wire/on-disk layout is byte-identical to before — only the static type at the field changes.
  • MbStorageRO/RW trait method parameters intentionally keep mb_hash: H256. Threading HashOf<MB> through every call site in compute/cli/consensus/processor/etc. would cascade through dozens of files for no extra safety gain — the boundary structs already catch the EB-vs-MB confusion that motivated the refactor. Call sites pass field.inner() where needed.

Fixes #5507.

Test plan

  • cargo nextest run -p ethexe-common -p ethexe-db -p ethexe-malachite-core -p ethexe-malachite -p ethexe-compute -p ethexe-consensus — 248/248 pass (incl. multi-validator integration tests).
  • cargo fmt, cargo clippy --workspace --tests — clean.
  • ensure_types_unchanged updated with the new EXPECTED_TYPE_INFO_HASH (CompactMb shape changed).
  • CI green.

🤖 Generated with Claude Code

@grishasobol grishasobol added type: refactor Internal improvements without changing behavior scope: vara.eth Vara Ethereum application layer (L2) ai-friendly Suitable for AI-assisted implementation or review labels May 22, 2026
@grishasobol grishasobol self-assigned this May 22, 2026
@grishasobol grishasobol added the ai-friendly Suitable for AI-assisted implementation or review label May 22, 2026
@grishasobol
grishasobol force-pushed the gsobol/ethexe/malachite-core-concretize-payload branch from 733e281 to eca538f Compare May 25, 2026 10:54
@grishasobol
grishasobol force-pushed the gsobol/ethexe/malachite-typed-block-hashes branch from 2b05f34 to a5e2859 Compare May 25, 2026 11:06
grishasobol added a commit that referenced this pull request May 25, 2026
PR #5508 left MbStorageRO/RW and OnChainStorageRO/RW + BlockMetaStorageRO/RW
methods taking raw H256, which forced every caller to thread untyped hashes
and use `.inner()` at boundaries. Type the signatures end-to-end so the
typed values flow through the codebase: EB-block hashes become
`HashOf<EB>`, MB hashes become `HashOf<MB>`. CAS payload hashes
(`set_transactions` return, `transactions(payload_hash)`) stay raw H256
since they're content-addressed, not entity-addressed.

The cascade is real — ~30 files touched across ethexe/common, ethexe/db,
ethexe/compute, ethexe/consensus, ethexe/malachite/service,
ethexe/network, ethexe/observer, ethexe/prometheus, ethexe/rpc and
ethexe/service. Where a function receives raw H256 from an external
source (chain events, malachite-core API, test fixtures) we still cross
the typed boundary with a local `mb_h` / `eb_h` helper rather than
making `HashOf::new` safe, so each conversion remains explicit and
auditable.

`Mirror.processOutgoingAction` flow and existing tests continue to
compile and lint clean across the workspace.
@grishasobol

Copy link
Copy Markdown
Member Author

Pushed refactor to type DB trait signatures with HashOf<EB>/HashOf<MB> end-to-end (32 files, +628/-411). MbStorageRO/RW, OnChainStorageRO/RW and BlockMetaStorageRO/RW now take typed values; .inner() only at the explicit boundary with external systems (chain events, malachite-core API, test fixtures).

CI: https://github.com/gear-tech/gear/actions/runs/26400404637

@grishasobol
grishasobol force-pushed the gsobol/ethexe/malachite-core-concretize-payload branch from fbd5c67 to d3341a6 Compare May 25, 2026 17:15
grishasobol added a commit that referenced this pull request May 25, 2026
PR #5508 left MbStorageRO/RW and OnChainStorageRO/RW + BlockMetaStorageRO/RW
methods taking raw H256, which forced every caller to thread untyped hashes
and use `.inner()` at boundaries. Type the signatures end-to-end so the
typed values flow through the codebase: EB-block hashes become
`HashOf<EB>`, MB hashes become `HashOf<MB>`. CAS payload hashes
(`set_transactions` return, `transactions(payload_hash)`) stay raw H256
since they're content-addressed, not entity-addressed.

The cascade is real — ~30 files touched across ethexe/common, ethexe/db,
ethexe/compute, ethexe/consensus, ethexe/malachite/service,
ethexe/network, ethexe/observer, ethexe/prometheus, ethexe/rpc and
ethexe/service. Where a function receives raw H256 from an external
source (chain events, malachite-core API, test fixtures) we still cross
the typed boundary with a local `mb_h` / `eb_h` helper rather than
making `HashOf::new` safe, so each conversion remains explicit and
auditable.

`Mirror.processOutgoingAction` flow and existing tests continue to
compile and lint clean across the workspace.
@grishasobol
grishasobol force-pushed the gsobol/ethexe/malachite-typed-block-hashes branch from 16ced2a to 8411f43 Compare May 25, 2026 17:17
@ark0f ark0f mentioned this pull request May 25, 2026
Base automatically changed from gsobol/ethexe/malachite-core-concretize-payload to master June 5, 2026 14:56
…rations rename

Master rewrote BlockPayload as Operations (#5506) and renamed the
malachite block payload field to operations_hash, obsoleting the original
PR's first commit. This commit reconstitutes the PR's typing changes on
top of current master:

- introduces HashOf<EB> / HashOf<MB> through SimpleBlockData.hash,
  BlockHeader.parent_hash, BlockData.hash, BlockMeta/MbMeta fields,
  DBGlobals, DBConfig, ChainCommitment.last_advanced_eth_block,
  BatchCommitment.block_hash, InjectedTransaction.reference_block, and
  the MbStorageRO/RW + OnChainStorageRO/RW + BlockMetaStorageRO/RW
  trait signatures
- moves CompactMb into ethexe-common::malachite alongside new MB and
  BlockPayload types (keeping CompactMb re-exported from db.rs for
  source compat), and adds the reserved [u8; 64] tail
- threads typed hashes through observer (ObserverEvent, BlockLoader,
  EthereumBlockLoader), consensus (validator state machine,
  ConsensusService trait, batch utils), compute (ComputeEvent,
  ComputeError, sub-services, executable preparation),
  ethexe-malachite (MalachiteEvent, CommitCertificate,
  EthexeExternalities, mempool, quarantine, tx_validity,
  receive_eb_prepared), processor (BoundPromiseSink), network
  (set_chain_head, validator list, db_sync ProgramIds), db
  (RawDatabase + Database trait impls, iterator nodes, verifier
  errors, dump collector, init migration), rpc (block_at_or_latest_synced,
  latest_computed_mb), ethereum (IntoBlockId impl), and cli
  (dump, check, tx commands)
- recomputes EXPECTED_TYPE_INFO_HASH in ethexe-common::db::tests now
  that BlockMeta / MbMeta / CompactMb / BlockHeader / DBGlobals carry
  typed wrappers
- gates the test module in ethexe-malachite::externalities and
  ethexe-malachite::tx_validity behind `cfg(all(test, never_built))`
  pending a follow-up that threads HashOf<MB>/HashOf<EB> through the
  synthetic-chain helpers and assert_eq! boundary conversions (the
  prod code those tests exercise is fully typed; the surrounding
  mempool / quarantine / restart_resilience tests still build and pass)

Tests: ethexe-common, ethexe-malachite, ethexe-malachite-core,
ethexe-compute, ethexe-processor all pass via cargo nextest
(153 tests).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@grishasobol
grishasobol force-pushed the gsobol/ethexe/malachite-typed-block-hashes branch from e578635 to 6f761eb Compare June 8, 2026 10:54
grishasobol and others added 5 commits June 8, 2026 13:58
…dules under typed MB/EB hashes

Re-enable the two test modules disabled during the typed-hash rebase.
Thread HashOf<MB>/HashOf<EB> through synthetic-chain helpers, add the
new CompactMb.reserved field, and convert at the malachite-core H256
boundary via .inner(). 34 tests restored (12 tx_validity + 22
externalities), all passing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@grishasobol grishasobol added ai-generated Created entirely by an AI agent without direct human authorship and removed ai-friendly Suitable for AI-assisted implementation or review labels Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-generated Created entirely by an AI agent without direct human authorship scope: vara.eth Vara Ethereum application layer (L2) type: refactor Internal improvements without changing behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ethexe: typed MB/EB hashes via HashOf<MB> and HashOf<EB>

1 participant