-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add patch for moonbase block 2285348
- Loading branch information
Showing
7 changed files
with
186 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2024 Moonbeam foundation | ||
// This file is part of Moonbeam. | ||
|
||
// Moonbeam is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Moonbeam is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Moonbeam. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
pub mod storage; | ||
mod block_patches; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2024 Moonbeam foundation | ||
// This file is part of Moonbeam. | ||
|
||
// Moonbeam is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Moonbeam is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Moonbeam. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
//! This file aggregates ethereum specific block patches. | ||
//! | ||
//! Patches: | ||
//! | ||
//! [Moonbase] | ||
//! | ||
//! Block: 0xdadbbbfd8a7f177c466117a6f5635eff51d698d12cec9f5e2b360909621beb43 | ||
//! Description: | ||
//! Block 2285348 includes transactions from the previous block. | ||
//! | ||
//! The problem was caused by this change in frontier, which moved `Pending::<T>::kill()` | ||
//! from `on_initialize` to `on_finalize`: https://github.com/polkadot-evm/frontier/pull/638 | ||
//! | ||
//! The bug was included with runtime 1603 in block 2285347. | ||
//! | ||
//! Github issue: https://github.com/moonbeam-foundation/moonbeam/issues/3026 | ||
//! | ||
use sp_core::H256; | ||
|
||
struct BlockPatch { | ||
pub hash: H256, | ||
pub invalid_transaction: Vec<H256>, | ||
} | ||
|
||
pub const MOONBASE_BLOCK_PATCHES: Vec<BlockPatch> = vec![ | ||
BlockPatch { | ||
hash: hex_literal::hex!("dadbbbfd8a7f177c466117a6f5635eff51d698d12cec9f5e2b360909621beb43").into(), | ||
invalid_transaction: vec![ | ||
hex_literal::hex!("006a6843eb35ad35a9ea9a99affa8d81f1ed500253c98cc9c080d84171a0afb3").into(), | ||
hex_literal::hex!("64c102f664eb435206ad4fcb49b526722176bcf74801c79473c3b5b2c281a243").into(), | ||
hex_literal::hex!("f546335453b6e35ce7e236ee873c96ba3a22602b3acc4f45f5d68b33a76d79ca").into(), | ||
hex_literal::hex!("4ed713ccd474fc33d2022a802f064cc012e3e37cd22891d4a89c7ba3d776f2db").into(), | ||
hex_literal::hex!("a5355f86844bb23fe666b10b509543fa377a9e324513eb221e0a2c926a64cae4").into(), | ||
hex_literal::hex!("c14791a3a392018fc3438f39cac1d572e8baadd4ed350e0355d1ca874a169e6a").into() | ||
] | ||
} | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Copyright 2024 Moonbeam foundation | ||
// This file is part of Moonbeam. | ||
|
||
// Moonbeam is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Moonbeam is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Moonbeam. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
use block_patches::MOONBASE_BLOCK_PATCHES; | ||
|
||
use std::sync::Arc; | ||
use fc_rpc::{StorageOverride, StorageOverrideHandler}; | ||
|
||
use ethereum::{BlockV2, ReceiptV3}; | ||
use ethereum_types::{Address, H256, U256}; | ||
// Substrate | ||
use sc_client_api::{backend::Backend, StorageProvider}; | ||
use sp_api::ProvideRuntimeApi; | ||
use sp_runtime::{traits::Block as BlockT, Permill}; | ||
// Frontier | ||
use fp_rpc::{EthereumRuntimeRPCApi, TransactionStatus}; | ||
use crate::frontier::block_patches; | ||
|
||
/// A storage override for runtimes that use different ethereum schema. | ||
/// | ||
/// It fetches data from the state backend, with some assumptions about pallet-ethereum's storage | ||
/// schema, as a preference. However, if there is no ethereum schema in the state, it'll use the | ||
/// runtime API as fallback implementation. | ||
/// | ||
/// It is used to avoid spawning the runtime and the overhead associated with it. | ||
#[derive(Clone)] | ||
pub struct FrontierStorageOverrideHandler<B, C, BE> { | ||
handler: StorageOverrideHandler<B, C, BE>, | ||
} | ||
|
||
impl<B, C, BE> FrontierStorageOverrideHandler<B, C, BE> { | ||
pub fn new(client: Arc<C>) -> Self { | ||
Self { | ||
handler: StorageOverrideHandler::<B, C, BE>::new(client.clone()) | ||
} | ||
} | ||
} | ||
|
||
impl<B, C, BE> StorageOverride<B> for FrontierStorageOverrideHandler<B, C, BE> | ||
where | ||
B: BlockT, | ||
C: ProvideRuntimeApi<B>, | ||
C::Api: EthereumRuntimeRPCApi<B>, | ||
C: StorageProvider<B, BE> + Send + Sync + 'static, | ||
BE: Backend<B> + 'static, | ||
{ | ||
fn account_code_at(&self, at: B::Hash, address: Address) -> Option<Vec<u8>> { | ||
self.handler.account_code_at(at, address) | ||
} | ||
|
||
fn account_storage_at(&self, at: B::Hash, address: Address, index: U256) -> Option<H256> { | ||
self.handler.account_storage_at(at, address, index) | ||
} | ||
|
||
fn current_block(&self, at: B::Hash) -> Option<BlockV2> { | ||
let block = self.handler.current_block(at); | ||
block.map(|mut block| { | ||
for patch in MOONBASE_BLOCK_PATCHES { | ||
if block.header.hash() == patch.hash { | ||
block.transactions = block.transactions.iter().filter_map(|tx| { | ||
if patch.invalid_transaction.contains(&tx.hash()) { | ||
None | ||
} else { | ||
Some(tx.clone()) | ||
} | ||
}).collect(); | ||
} | ||
} | ||
block | ||
}) | ||
} | ||
|
||
fn current_receipts(&self, at: B::Hash) -> Option<Vec<ReceiptV3>> { | ||
self.handler.current_receipts(at) | ||
} | ||
|
||
fn current_transaction_statuses(&self, at: B::Hash) -> Option<Vec<TransactionStatus>> { | ||
self.handler.current_transaction_statuses(at) | ||
} | ||
|
||
fn elasticity(&self, at: B::Hash) -> Option<Permill> { | ||
self.handler.elasticity(at) | ||
} | ||
|
||
fn is_eip1559(&self, at: B::Hash) -> bool { | ||
self.handler.is_eip1559(at) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters