Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eth2 client: add trusted execution blocks submitter #916

Merged
merged 3 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading