diff --git a/src/did/src/lib.rs b/src/did/src/lib.rs index 1dd0f9ec..83cc7706 100644 --- a/src/did/src/lib.rs +++ b/src/did/src/lib.rs @@ -28,6 +28,7 @@ pub mod permission; pub mod revert_blocks; pub mod state; pub mod transaction; +pub mod unsafe_blocks; pub mod fees; #[cfg(test)] diff --git a/src/did/src/permission.rs b/src/did/src/permission.rs index 636f7a28..8c7db274 100644 --- a/src/did/src/permission.rs +++ b/src/did/src/permission.rs @@ -14,10 +14,12 @@ pub enum Permission { Admin, /// Allows calling the endpoints to read the logs and get runtime statistics ReadLogs, - /// Allows calling the endpoints to set the logs configuration - UpdateLogsConfiguration, /// Allows caller to reset the EVM state ResetEvmState, + /// Allows calling the endpoints to set the logs configuration + UpdateLogsConfiguration, + /// Allows calling the endpoints to set validate unsafe blocks + ValidateUnsafeBlocks, } #[derive(Debug, Clone, Default, CandidType, Deserialize, PartialEq, Eq, serde::Serialize)] diff --git a/src/did/src/unsafe_blocks.rs b/src/did/src/unsafe_blocks.rs new file mode 100644 index 00000000..e9014a5c --- /dev/null +++ b/src/did/src/unsafe_blocks.rs @@ -0,0 +1,14 @@ +use candid::{CandidType, Deserialize}; +use serde::Serialize; + +use crate::H256; + +#[derive(CandidType, Serialize, Deserialize, Debug)] +/// Arguments to `validate_unsafe_blocks` function. +pub struct ValidateUnsafeBlockArgs { + pub block_number: u64, + pub block_hash: H256, + pub state_root: H256, + pub transactions_root: H256, + pub receipts_root: H256, +} diff --git a/src/evm-canister-client/src/client.rs b/src/evm-canister-client/src/client.rs index 257ce3b0..e8cda544 100644 --- a/src/evm-canister-client/src/client.rs +++ b/src/evm-canister-client/src/client.rs @@ -7,6 +7,7 @@ use did::permission::{Permission, PermissionList}; use did::revert_blocks::RevertToBlockArgs; use did::state::BasicAccount; use did::transaction::StorableExecutionResult; +use did::unsafe_blocks::ValidateUnsafeBlockArgs; use did::{ Block, BlockNumber, BlockchainStorageLimits, Bytes, EstimateGasRequest, EvmStats, Transaction, TransactionReceipt, H160, H256, U256, U64, @@ -534,6 +535,31 @@ impl EvmCanisterClient { .await } + /// Enable or disable unsafe blocks. This function requires admin permissions. + pub async fn admin_enable_unsafe_blocks( + &self, + enabled: bool, + ) -> CanisterClientResult> { + self.client + .update("admin_enable_unsafe_blocks", (enabled,)) + .await + } + + /// Returns whether unsafe blocks are enabled + pub async fn is_unsafe_blocks_enabled(&self) -> CanisterClientResult { + self.client.query("is_unsafe_blocks_enabled", ()).await + } + + /// Validate unsafe block on the EVM. + /// + /// Only those with [`did::permission::Permission::ValidateUnsafeBlocks`] can call this method. + pub async fn validate_unsafe_block( + &self, + args: ValidateUnsafeBlockArgs, + ) -> CanisterClientResult> { + self.client.update("validate_unsafe_block", (args,)).await + } + /// Returns the chain ID used for signing replay-protected transactions. /// See [eth_chainid] (https://eth.wiki/json-rpc/API#eth_chainid) ///