Skip to content

Commit

Permalink
Merge branch 'master' into add-near-plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
karim-en committed Oct 24, 2023
2 parents acb4481 + 6390ff6 commit e47da3b
Show file tree
Hide file tree
Showing 2 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 @@ -83,6 +83,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 @@ -145,6 +146,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 @@ -241,6 +243,13 @@ impl Eth2Client {
#[result_serializer(borsh)]
#[pause(except(roles(Role::UnrestrictedSubmitExecutionHeader, Role::DAO)))]
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 @@ -346,6 +355,15 @@ impl Eth2Client {
self.trusted_signer.clone()
}

#[access_control_any(roles(Role::DAO))]
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()
}

#[access_control_any(roles(Role::DAO))]
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 @@ -45,6 +45,7 @@ impl Eth2Client {
client_mode: ClientMode::SubmitLightClientUpdate,
unfinalized_head_execution_header: None,
unfinalized_tail_execution_header: None,
trusted_blocks_submitter: None,
}
}
}

0 comments on commit e47da3b

Please sign in to comment.