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

Eth2Near-relay: split relay on a few crates, many improvements #825

Merged
merged 86 commits into from
Oct 23, 2022
Merged
Show file tree
Hide file tree
Changes from 77 commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
4def692
fix API for goerli
olga24912 Aug 30, 2022
ba1624d
fix sync committee for submitting light client update between period
olga24912 Aug 31, 2022
11e3e37
checks for empty headers submittion
olga24912 Aug 31, 2022
48c4ade
timeout on client call
olga24912 Aug 31, 2022
747738e
search for valid signature_slot
olga24912 Sep 3, 2022
2198169
arg for submit only finalized blocks
olga24912 Sep 6, 2022
381464e
:sleep 20 secs if on time
olga24912 Sep 6, 2022
f695535
skip signature slot with empty attestations
olga24912 Sep 12, 2022
fb090b4
fix don't decrement unsigned int
olga24912 Sep 12, 2022
6d9c168
sleep before new iteration
olga24912 Sep 12, 2022
fc62e3a
is_sync for beacon client
olga24912 Sep 12, 2022
0ea9087
fix after rebase
olga24912 Sep 13, 2022
ba2a295
check syncing for Eth1
olga24912 Sep 13, 2022
9679949
wait for sync
olga24912 Sep 13, 2022
c212c3e
separate timeout to config
olga24912 Sep 13, 2022
3175b40
check account id
olga24912 Sep 13, 2022
5499973
check near is sync
olga24912 Sep 13, 2022
f5a41f4
parse URL on init
olga24912 Sep 13, 2022
c9129c0
config for tests
olga24912 Sep 14, 2022
bdc1ecf
fix tests
olga24912 Sep 14, 2022
f487253
fix eth2near_relay tests
olga24912 Sep 15, 2022
fdfeebc
fix hand made finality light client updates
olga24912 Sep 16, 2022
2faaf20
execution_block_proof
olga24912 Sep 16, 2022
1afefcb
fix tests for eth1_rpc_client
olga24912 Sep 16, 2022
ea10ca6
fix beacon_rpc_client tests
olga24912 Sep 16, 2022
c1df6cf
fix: init contract by owner
olga24912 Sep 19, 2022
d22f4ab
fix tests for contract wrapper
olga24912 Sep 19, 2022
a54752b
fix tests for finality-update-verify
olga24912 Sep 19, 2022
c87c71a
rename test files
olga24912 Sep 19, 2022
feb9b28
goerli test data
olga24912 Sep 19, 2022
c9da1a3
Merge branch 'master' into eth2near-relay-configurable-tests
olga24912 Sep 19, 2022
eec2fd4
fix after merge
olga24912 Sep 19, 2022
d587352
Merge remote-tracking branch 'origin/master' into eth2near-relay-conf…
olga24912 Sep 20, 2022
6fc60eb
init contract with trust mode
olga24912 Sep 20, 2022
05ef7a0
:fix separate checks for light client update
olga24912 Sep 20, 2022
e0fd4b7
save to lfs only state files
olga24912 Sep 20, 2022
11cf954
fetch lfs objects
olga24912 Sep 20, 2022
69f677f
store test files to regular git
olga24912 Sep 20, 2022
d66b9db
ignore tests which use state files
olga24912 Sep 20, 2022
acbb3c4
isolate eth2-contract-init
olga24912 Sep 20, 2022
5a6c935
add to config initialization parametrs
olga24912 Sep 20, 2022
5c166bd
extra check on contract init
olga24912 Sep 20, 2022
9bec530
contract_type enum
olga24912 Sep 20, 2022
e5c6d4e
Update eth2near/eth2near-block-relay-rs/config_for_tests.toml
sept-en Sep 21, 2022
c4e5491
use enum for all configs
olga24912 Sep 21, 2022
becd809
move near rpc client to contract wrapper
olga24912 Sep 21, 2022
2380fe1
separate eth_rpc_client
olga24912 Sep 21, 2022
58b3cad
separate logger
olga24912 Sep 21, 2022
dc111e8
rename git_config -> git_test_config
olga24912 Sep 21, 2022
4e20075
change ro relay_account for signed transaction
olga24912 Sep 21, 2022
c868e9b
print finalized execution block number in slot
olga24912 Sep 21, 2022
fa247a0
secret key
olga24912 Sep 21, 2022
3e8a826
change logs order
olga24912 Sep 22, 2022
fa192e2
print info about finalized slot and number on ETH contract
olga24912 Sep 22, 2022
a17adf9
read API_KEY file in test
olga24912 Sep 22, 2022
ce4ea8d
unwrap secret key in test
olga24912 Sep 22, 2022
b859cab
Merge branch 'master' into eth2near-relay-configurable-tests
olga24912 Sep 22, 2022
bdcc0bb
tests for contract-init
olga24912 Sep 22, 2022
ee42b47
use env for secrets
olga24912 Sep 22, 2022
cddcf73
use secret in Action
olga24912 Sep 22, 2022
d796642
Merge branch 'master' into eth2near-relay-configurable-tests
olga24912 Sep 22, 2022
8208b80
env API_KEY
olga24912 Sep 22, 2022
cb55091
API_KEY in tests
olga24912 Sep 22, 2022
1601b32
run tests in Action
olga24912 Sep 22, 2022
85a9564
eth2-contract-init unwrap->expect
olga24912 Sep 22, 2022
36dbf09
remove unwrap in eth_rpc_client
olga24912 Sep 23, 2022
2ad6184
remove unwrap in contract_wrapper
olga24912 Sep 23, 2022
981da6c
unwrap->expect in eth2near-block-relay-rs
olga24912 Sep 23, 2022
a094c75
remove unwrap from logger
olga24912 Sep 23, 2022
b0da0b7
fix tests
olga24912 Sep 23, 2022
ce662b9
Merge branch 'eth2near-relay-configurable-tests' into eth2near-relay-…
olga24912 Sep 24, 2022
2ae7242
Merge branch 'master' into eth2near-relay-separate-init
olga24912 Oct 3, 2022
e6c7827
Remove redundant brackets
olga24912 Oct 6, 2022
a2dc229
fix init_contract
olga24912 Oct 6, 2022
e191f98
Merge branch 'master' into eth2near-relay-separate-init
olga24912 Oct 12, 2022
adeeb5b
Merge branch 'master' into eth2near-relay-separate-init
olga24912 Oct 13, 2022
30ce790
eth2near-relay: option for some arg for contract init
olga24912 Oct 17, 2022
6799ed3
Apply suggestions from code review: fix messages
sept-en Oct 21, 2022
a7f0046
Apply suggestions from code review: fix messages
sept-en Oct 21, 2022
d817c36
eth_network_enum -> eth_network
olga24912 Oct 21, 2022
4683dcd
logger -> eth2near-logger
olga24912 Oct 21, 2022
e4e2d11
as_str in fmt
olga24912 Oct 21, 2022
22da4aa
simplify from str to enum
olga24912 Oct 21, 2022
17bcda0
fix contract_type
olga24912 Oct 21, 2022
c924a32
trusted_signature -> trusted_signer_account_id
olga24912 Oct 21, 2022
48d20fa
fix tests for eth2near-block-relay-rs
olga24912 Oct 21, 2022
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
12 changes: 12 additions & 0 deletions .github/workflows/contracts-near.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ jobs:
./test.sh
timeout-minutes: 20

- job-name: test eth2near/eth2-contract-init
cmd: |
cd eth2near/eth2-contract-init
./test.sh
timeout-minutes: 20

- job-name: test eth2near/eth_rpc_client
cmd: |
cd eth2near/eth_rpc_client
./test.sh
timeout-minutes: 20

name: ${{ matrix.job-name }}
steps:
- name: Clone the repository
Expand Down
10 changes: 4 additions & 6 deletions eth2near/contract_wrapper/src/dao_eth_client_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ impl EthClientContractTrait for DaoEthClientContract {
mod tests {
use crate::eth_client_contract_trait::EthClientContractTrait;
use crate::near_contract_wrapper::NearContractWrapper;
use crate::{
dao_contract, dao_eth_client_contract, eth_client_contract, near_contract_wrapper, utils,
};
use crate::{dao_contract, dao_eth_client_contract, eth_client_contract, eth_network_enum, near_contract_wrapper, utils};
use eth_types::eth2::{ExtendedBeaconBlockHeader, LightClientUpdate, SyncCommittee};
use eth_types::BlockHeader;
use std::path::PathBuf;
Expand Down Expand Up @@ -180,8 +178,6 @@ mod tests {
const CONTRACT_ACCOUNT_ID: &str = "dev-1660212590113-35162107482173";
const DAO_CONTRACT_ACCOUNT_ID: &str = "eth2-test.sputnikv2.testnet";

const ETH_NETWORK: &str = "kiln";

let near_contract_wrapper = Box::new(NearContractWrapper::new_with_raw_secret_key(
NEAR_ENDPOINT,
&signer_account_id,
Expand Down Expand Up @@ -232,11 +228,13 @@ mod tests {
}

eth_client.init_contract(
ETH_NETWORK.to_string(),
eth_network_enum::EthNetwork::Kiln,
finalized_execution_header.unwrap(),
finalized_beacon_header,
current_sync_committee,
next_sync_committee,
Some(true),
Some(false),
None,
None,
Some(eth_client.contract_wrapper.get_signer_account_id()),
Expand Down
20 changes: 13 additions & 7 deletions eth2near/contract_wrapper/src/eth_client_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use serde_json::json;
use std::error::Error;
use std::option::Option;
use std::string::String;
use crate::eth_network_enum::EthNetwork;
use serde::Serialize;

/// Implementation for interaction with Ethereum Light Client Contract on NEAR.
Expand Down Expand Up @@ -46,11 +47,13 @@ impl EthClientContract {
/// * `trusted_signer` - the account address of the trusted signer which is allowed to submit light client updates.
pub fn init_contract(
&self,
ethereum_network: String,
ethereum_network: EthNetwork,
finalized_execution_header: BlockHeader,
finalized_beacon_header: ExtendedBeaconBlockHeader,
current_sync_committee: SyncCommittee,
next_sync_committee: SyncCommittee,
validate_updates: Option<bool>,
verify_bls_signatures: Option<bool>,
hashes_gc_threshold: Option<u64>,
max_submitted_blocks_by_account: Option<u32>,
trusted_signer: Option<AccountId>,
Expand All @@ -70,13 +73,13 @@ impl EthClientContract {
}

let init_input = InitInput {
network: ethereum_network,
network: ethereum_network.to_string(),
finalized_execution_header,
finalized_beacon_header,
current_sync_committee,
next_sync_committee,
validate_updates: true,
verify_bls_signatures: false,
validate_updates: validate_updates.unwrap_or(true),
verify_bls_signatures: verify_bls_signatures.unwrap_or(false),
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,
Expand All @@ -102,7 +105,9 @@ impl EthClientContract {
self.contract_wrapper.get_account_id()
}

pub fn get_signature_account_id(&self) -> AccountId { self.contract_wrapper.get_signer_account_id() }
pub fn get_signer_account_id(&self) -> AccountId {
self.contract_wrapper.get_signer_account_id()
}
}

impl EthClientContractTrait for EthClientContract {
Expand Down Expand Up @@ -328,7 +333,6 @@ mod tests {
const PATH_TO_CURRENT_SYNC_COMMITTEE: &str =
"./data/next_sync_committee_kiln_period_133.json";
const PATH_TO_NEXT_SYNC_COMMITTEE: &str = "./data/next_sync_committee_kiln_period_134.json";
const ETH_NETWORK: &str = "kiln";

let current_sync_committee: SyncCommittee = serde_json::from_str(
&std::fs::read_to_string(PATH_TO_CURRENT_SYNC_COMMITTEE).expect("Unable to read file"),
Expand Down Expand Up @@ -361,11 +365,13 @@ mod tests {
}

eth_client_contract.init_contract(
ETH_NETWORK.to_string(),
eth_client_contract::EthNetwork::Kiln,
finalized_execution_header.unwrap(),
finalized_beacon_header,
current_sync_committee,
next_sync_committee,
Some(true),
Some(false),
None,
None,
Option::<AccountId>::Some(trusted_signer.parse().unwrap()),
Expand Down
63 changes: 63 additions & 0 deletions eth2near/contract_wrapper/src/eth_network_enum.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
use std::error::Error;
use std::fmt;
use std::fmt::{Display, Formatter};
use std::str::FromStr;
use serde::Deserialize;

#[derive(Debug, Clone, Deserialize)]
pub enum EthNetwork {
Mainnet,
Kiln,
Ropsten,
Goerli,
}

#[derive(Debug, Clone, Deserialize)]
pub struct IncorrectEthNetwork;

impl Display for IncorrectEthNetwork {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"Unknown Eth network. Possible Eth network: 'Mainnet', 'Kiln', 'Goerli', 'Ropsten'"
sept-en marked this conversation as resolved.
Show resolved Hide resolved
)
}
}

impl Error for IncorrectEthNetwork {}

impl Display for EthNetwork {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
EthNetwork::Mainnet => write!(f, "mainnet"),
EthNetwork::Kiln => write!(f, "kiln"),
EthNetwork::Goerli => write!(f, "goerli"),
EthNetwork::Ropsten => write!(f, "ropsten")
}
sept-en marked this conversation as resolved.
Show resolved Hide resolved
}
}

impl EthNetwork {
pub fn as_str(&self) -> &str {
match self {
EthNetwork::Mainnet => "mainnet",
EthNetwork::Kiln => "kiln",
EthNetwork::Goerli => "goerli",
EthNetwork::Ropsten => "ropsten"
}
}
}

impl FromStr for EthNetwork {
type Err = IncorrectEthNetwork;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"Mainnet" | "mainnet" => Ok(EthNetwork::Mainnet),
"Kiln" | "kiln" => Ok(EthNetwork::Kiln),
"Goerli" | "goerli" => Ok(EthNetwork::Goerli),
"Ropsten" | "ropsten" => Ok(EthNetwork::Ropsten),
_ => Err(IncorrectEthNetwork),
}
sept-en marked this conversation as resolved.
Show resolved Hide resolved
}
}
5 changes: 4 additions & 1 deletion eth2near/contract_wrapper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ pub mod eth_client_contract_trait;
pub mod file_eth_client_contract;
pub mod near_contract_wrapper;
pub mod sandbox_contract_wrapper;
pub mod utils;
pub mod utils;
pub mod eth_network_enum;
pub mod near_network_enum;
sept-en marked this conversation as resolved.
Show resolved Hide resolved
pub mod near_rpc_client;
55 changes: 55 additions & 0 deletions eth2near/contract_wrapper/src/near_network_enum.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use std::error::Error;
use std::fmt;
use std::fmt::{Display, Formatter};
use std::str::FromStr;
use serde::Deserialize;

#[derive(Debug, Clone, Deserialize)]
pub enum NearNetwork {
Mainnet,
Testnet,
}

#[derive(Debug, Clone, Deserialize)]
pub struct IncorrectNearNetwork;

impl Display for IncorrectNearNetwork {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"Unknown near network id. Possible near networks: 'Mainnet', 'Testnet'"
sept-en marked this conversation as resolved.
Show resolved Hide resolved
)
}
}

impl Error for IncorrectNearNetwork {}

impl Display for NearNetwork {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
NearNetwork::Mainnet => write!(f, "mainnet"),
NearNetwork::Testnet => write!(f, "testnet"),
}
sept-en marked this conversation as resolved.
Show resolved Hide resolved
}
}

impl NearNetwork {
pub fn as_str(&self) -> &str {
match self {
NearNetwork::Mainnet => "mainnet",
NearNetwork::Testnet => "testnet",
}
}
}

impl FromStr for NearNetwork {
type Err = IncorrectNearNetwork;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"Mainnet" | "mainnet" => Ok(NearNetwork::Mainnet),
"Testnet" | "testnet" => Ok(NearNetwork::Testnet),
_ => Err(IncorrectNearNetwork),
}
sept-en marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading