Skip to content

Commit

Permalink
Eth2-to-Near-relay: improve client initialization (#819)
Browse files Browse the repository at this point in the history
* Improve init of the Eth2Client contract
* Move the default init to the client wrapper method
* Fix tests
* Print init eth2 client input

Co-authored-by: Kirill <[email protected]>
  • Loading branch information
karim-en and sept-en authored Sep 22, 2022
1 parent 9f66471 commit c55f79a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
3 changes: 3 additions & 0 deletions eth2near/contract_wrapper/src/dao_eth_client_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ mod tests {
finalized_beacon_header,
current_sync_committee,
next_sync_committee,
None,
None,
Some(eth_client.contract_wrapper.get_signer_account_id()),
);

let dao_contract_wrapper =
Expand Down
23 changes: 17 additions & 6 deletions eth2near/contract_wrapper/src/eth_client_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ use std::error::Error;
use std::option::Option;
use std::string::String;
use std::vec::Vec;

use serde::Serialize;
pub struct EthClientContract {
last_slot: u64,
contract_wrapper: Box<dyn ContractWrapper>,
pub contract_wrapper: Box<dyn ContractWrapper>,
}

impl EthClientContract {
Expand All @@ -35,8 +35,11 @@ impl EthClientContract {
finalized_beacon_header: ExtendedBeaconBlockHeader,
current_sync_committee: SyncCommittee,
next_sync_committee: SyncCommittee,
hashes_gc_threshold: Option<u64>,
max_submitted_blocks_by_account: Option<u32>,
trusted_signer: Option<AccountId>,
) {
#[derive(BorshSerialize)]
#[derive(BorshSerialize, Serialize)]
pub struct InitInput {
pub network: String,
pub finalized_execution_header: eth_types::BlockHeader,
Expand All @@ -58,11 +61,16 @@ impl EthClientContract {
next_sync_committee,
validate_updates: true,
verify_bls_signatures: false,
hashes_gc_threshold: 51000,
max_submitted_blocks_by_account: 8000,
trusted_signer: Option::<AccountId>::None,
hashes_gc_threshold: hashes_gc_threshold.unwrap_or(51_000),
max_submitted_blocks_by_account: max_submitted_blocks_by_account.unwrap_or(8000),
trusted_signer,
};

println!(
"Init eth2 client input: \n {}",
serde_json::to_string_pretty(&init_input).unwrap()
);

self.contract_wrapper
.call_change_method(
"init".to_string(),
Expand Down Expand Up @@ -319,6 +327,9 @@ mod tests {
finalized_beacon_header,
current_sync_committee,
next_sync_committee,
None,
None,
None,
);
eth_state.current_light_client_update = 1;
}
Expand Down
9 changes: 9 additions & 0 deletions eth2near/eth2near-block-relay-rs/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ pub struct Config {

// Sleep time in seconds after blocks/light_client_update submission to client
pub sleep_time_after_submission_secs: u64,

/// Max number of stored blocks in the storage of the eth2 client contract.
/// Events that happen past this threshold cannot be verified by the client.
/// It is used on initialization of the Eth2 client.
pub hashes_gc_threshold: Option<u64>,

/// Max number of unfinalized blocks allowed to be stored by one submitter account.
/// It is used on initialization of the Eth2 client.
pub max_submitted_blocks_by_account: Option<u32>,
}

impl Config {
Expand Down
10 changes: 10 additions & 0 deletions eth2near/eth2near-block-relay-rs/src/init_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ pub fn init_contract(
finalized_header,
current_sync_committee,
next_sync_committee,
config.hashes_gc_threshold,
config.max_submitted_blocks_by_account,
Some(
config
.dao_contract_account_id
.as_ref()
.unwrap_or(&config.signer_account_id)
.parse()
.unwrap(),
),
);

thread::sleep(time::Duration::from_secs(30));
Expand Down
8 changes: 8 additions & 0 deletions eth2near/eth2near-block-relay-rs/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ pub fn init_contract_from_files(eth_client_contract: &mut EthClientContract) {
finalized_beacon_header,
current_sync_committee,
next_sync_committee,
None,
None,
Some(eth_client_contract.contract_wrapper.get_signer_account_id()),
);
thread::sleep(time::Duration::from_secs(30));
}
Expand Down Expand Up @@ -154,6 +157,9 @@ pub fn init_contract_from_specific_slot(
finalized_beacon_header,
current_sync_committee,
next_sync_committee,
None,
None,
Some(eth_client_contract.contract_wrapper.get_signer_account_id()),
);

thread::sleep(time::Duration::from_secs(30));
Expand Down Expand Up @@ -207,6 +213,8 @@ fn get_config() -> Config {
state_requests_timeout_seconds: 1000,
sleep_time_after_submission_secs: 5,
sleep_time_on_sync_secs: 30,
hashes_gc_threshold: None,
max_submitted_blocks_by_account: None,
}
}

Expand Down

0 comments on commit c55f79a

Please sign in to comment.