Skip to content

Commit

Permalink
Eth2 client: add trusted execution blocks submitter (#916)
Browse files Browse the repository at this point in the history
* Eth2 client: add trusted execution blocks submitter (#38)

Co-authored-by: Kirill <[email protected]>

* Update contract build

---------

Co-authored-by: Kirill <[email protected]>
  • Loading branch information
karim-en and sept-en authored Oct 24, 2023
1 parent 3420dc7 commit 6390ff6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions contracts/near/eth2-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub struct Eth2Client {
client_mode: ClientMode,
unfinalized_head_execution_header: Option<ExecutionHeaderInfo>,
unfinalized_tail_execution_header: Option<ExecutionHeaderInfo>,
trusted_blocks_submitter: Option<AccountId>,
}

#[near_bindgen]
Expand Down Expand Up @@ -122,6 +123,7 @@ impl Eth2Client {
client_mode: ClientMode::SubmitLightClientUpdate,
unfinalized_head_execution_header: None,
unfinalized_tail_execution_header: None,
trusted_blocks_submitter: None,
};

contract.finalized_execution_blocks.insert(
Expand Down Expand Up @@ -214,6 +216,13 @@ impl Eth2Client {

#[result_serializer(borsh)]
pub fn submit_execution_header(&mut self, #[serializer(borsh)] block_header: BlockHeader) {
if let Some(trusted_blocks_submitter) = &self.trusted_blocks_submitter {
require!(
&env::predecessor_account_id() == trusted_blocks_submitter,
"Eth-client is deployed as trust mode, only trusted_blocks_submitter can submit blocks"
);
}

require!(self.client_mode == ClientMode::SubmitHeader);

let block_hash = block_header.calculate_hash();
Expand Down Expand Up @@ -319,6 +328,15 @@ impl Eth2Client {
self.trusted_signer.clone()
}

#[private]
pub fn update_trusted_blocks_submitter(&mut self, trusted_blocks_submitter: Option<AccountId>) {
self.trusted_blocks_submitter = trusted_blocks_submitter;
}

pub fn get_trusted_blocks_submitter(&self) -> Option<AccountId> {
self.trusted_blocks_submitter.clone()
}

#[private]
pub fn update_hashes_gc_threshold(&mut self, hashes_gc_threshold: u64) {
self.hashes_gc_threshold = hashes_gc_threshold;
Expand Down
1 change: 1 addition & 0 deletions contracts/near/eth2-client/src/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ impl Eth2Client {
client_mode: ClientMode::SubmitLightClientUpdate,
unfinalized_head_execution_header: None,
unfinalized_tail_execution_header: None,
trusted_blocks_submitter: None,
}
}
}
Binary file modified contracts/near/res/eth2_client.wasm
Binary file not shown.

0 comments on commit 6390ff6

Please sign in to comment.