Skip to content

Extend EthereumBlockNotification with reorg info to allow compliance with Ethereum specs#1787

Merged
RomarQ merged 23 commits intopolkadot-evm:masterfrom
moonbeam-foundation:manuel/make-new-heads-comply-with-ethereum-spec
Jan 7, 2026
Merged

Extend EthereumBlockNotification with reorg info to allow compliance with Ethereum specs#1787
RomarQ merged 23 commits intopolkadot-evm:masterfrom
moonbeam-foundation:manuel/make-new-heads-comply-with-ethereum-spec

Conversation

@manuelmauro
Copy link
Copy Markdown
Contributor

Description

Modify the EthereumBlockNotification struct in fc-mapping-sync to include reorg information. The mapping sync layer already tracks the canonical chain and could provide this data.

Implementation:

// In fc_mapping_sync
pub struct EthereumBlockNotification<B: BlockT> {
    pub hash: B::Hash,
    pub is_new_best: bool,
    pub reorg_info: Option<ReorgInfo>, // NEW
}

pub struct ReorgInfo {
    pub retracted: Vec<B::Hash>,
    pub enacted: Vec<B::Hash>,
}

This allows us to comply with Ethereum specs.

@manuelmauro manuelmauro requested a review from sorpaas as a code owner December 17, 2025 09:19
@manuelmauro
Copy link
Copy Markdown
Contributor Author

This is (kind of) a follow-up PR to #1781

@manuelmauro
Copy link
Copy Markdown
Contributor Author

@RomarQ concerning the comments above, the fact that we populate the reorg info at Canonicalize-time should guarantee their soundness, right?

Specifically this:

let reorg_info = if let Some(ref tree_route) = notification.tree_route {
	log::debug!(
		target: "frontier-sql",
		"🔀  Re-org happened at new best {}, proceeding to canonicalize db",
		notification.hash
	);
	let retracted = tree_route
		.retracted()
		.iter()
		.map(|hash_and_number| hash_and_number.hash)
		.collect::<Vec<_>>();
	let enacted = tree_route
		.enacted()
		.iter()
		.map(|hash_and_number| hash_and_number.hash)
		.collect::<Vec<_>>();

	let common = tree_route.common_block().hash;
	tx.send(WorkerCommand::Canonicalize {
		common,
		enacted: enacted.clone(),
		retracted: retracted.clone(),
	}).await.ok();

	Some(ReorgInfo {
		common_ancestor: common,
		retracted,
		enacted,
	})
} else {
	None
};

Copy link
Copy Markdown
Collaborator

@RomarQ RomarQ left a comment

Choose a reason for hiding this comment

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

I am a bit concerned that the notification mechanism for key-value and sql backends are so different. Could we unify the notification mechanism in a single place? maybe reusing the WorkerCommand approach.

We also need to run the test for each storage backend sql and key-value.

@manuelmauro
Copy link
Copy Markdown
Contributor Author

manuelmauro commented Dec 19, 2025

I am a bit concerned that the notification mechanism for key-value and sql backends are so different. Could we unify the notification mechanism in a single place? maybe reusing the WorkerCommand approach.

We also need to run the test for each storage backend sql and key-value.

Possibly addressed the comment in dbd0537 and 4582a9a

(It might need more work.)

Copy link
Copy Markdown
Collaborator

@RomarQ RomarQ left a comment

Choose a reason for hiding this comment

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

Currently, the implementation of kv and sql backends seems to different. This makes the maintenance more difficult and can cause inconsistencies. I think we should try to align the mapping-sync implementation on both backends, by making it more generic.

I am fine to approve this once the remarks have been addressed, and do the alignment of the mapping-sync implementation in a follow-up PR.

@RomarQ RomarQ enabled auto-merge January 7, 2026 16:35
@RomarQ RomarQ added this pull request to the merge queue Jan 7, 2026
Merged via the queue into polkadot-evm:master with commit c0a943e Jan 7, 2026
4 checks passed
@RomarQ RomarQ deleted the manuel/make-new-heads-comply-with-ethereum-spec branch January 7, 2026 17:18
manuelmauro added a commit to moonbeam-foundation/frontier that referenced this pull request Jan 8, 2026
…e with Ethereum specs (polkadot-evm#1787)

* feat: ✨ extend EthereumBlockNotification with reorg info

* style: 🎨 fmt

* fix: 🐛 emit reorg information from Canonicalize

* test: ✅ add basic integration tests

* fix: 🐛 fix newHead missing enacted block

* test: ✅ test deeper forks

* style: 🎨 fmt

* fix: 🐛 sort enacted blocks

* fix: 🐛 guarantee async sends ordering

* style: 🎨 fmt

* Revert "style: 🎨 fmt"

This reverts commit 6d644a6.

* Revert "fix: 🐛 guarantee async sends ordering"

This reverts commit 2945dda.

* Revert "fix: 🐛 sort enacted blocks"

This reverts commit 44e7517.

* ci: 👷 test sql backend in CI

* refactor: ♻️ dedupliacte common logic between sql and kv backends

* style: 🎨 fmt

* refactor: ♻️ uniform notification process across backends

* docs: 📝 remove comments

* refactor: ♻️ add defensive check

* fix: 🐛 properly distinguish enacted blocks from new best

* refactor: ♻️ reduce code duplication
alstjd0921 added a commit to bifrost-platform/bifrost-frontier that referenced this pull request Feb 2, 2026
Merge upstream frontier master (polkadot-sdk stable2512 compatible).
This brings 43 commits including:
- Update to polkadot-sdk stable2512 (polkadot-evm#1796)
- Add support for EIP-7825, EIP-7823, EIP-7883, EIP-7939 (Osaka fork)
- Validate max block range eth_getLogs RPC (polkadot-evm#1794)
- Extend EthereumBlockNotification with reorg info (polkadot-evm#1787)

Bifrost customizations preserved:
- view_call: Read-only EVM calls without nonce modification
- call_as_internal_call: Internal EVM calls for fee payment operations
- FeelessCallFilter: Gas-free EVM call support
- ERC20 fee payment (NODE-194)
- Debug/trace RPC extensions (NODE-190, NODE-193)
- Custom web3_clientVersion format (NODE-84)
- logs_request_timeout parameter

Conflicts resolved:
- frame/evm/src/runner/mod.rs: Added both create_force_address and Bifrost methods
- frame/evm/src/runner/stack.rs: Added both create_force_address and Bifrost methods
- client/rpc/src/eth/filter.rs: Kept both logs_request_timeout and max_block_range

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.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.

2 participants