Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
update fork version and config (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
salman01zp authored Sep 5, 2023
1 parent be844d5 commit f35213a
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 53 deletions.
24 changes: 1 addition & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ git lfs install
#### 2. Configure light client
```bash
# Edit configuration as required
eth2substrate-block-relay-rs/config_for_tests.toml
cp eth2substrate-block-relay-rs/config_for_tests.toml /tmp/empty/
eth2substrate-block-relay-rs/config.toml
```
#### 3. Set Infura API Key
```bash
Expand All @@ -104,34 +103,13 @@ cargo build --release -p node-template

#### 5. Run light client
```bash
#terminal 1
./target/release/node-template --tmp --chain local --alice \
--rpc-cors all --rpc-external --rpc-methods=unsafe \
--port 30433 \
--relayer-config-dir=./gadget/config \
--light-client-init-pallet-config-path=./crates/eth2-pallet-init/config.toml \
--light-client-relay-config-path=./eth2substrate-block-relay-rs/config.toml
--rpc-port 9444

#terminal 2
./target/release/node-template --tmp --chain local --bob \
--rpc-cors all --rpc-external --rpc-methods=unsafe \
--port 30405 \
--relayer-config-dir=./gadget/config \
--light-client-init-pallet-config-path=./crates/eth2-pallet-init/config.toml \
--light-client-relay-config-path=./eth2substrate-block-relay-rs/config.toml
--rpc-port 9445 --bootnodes /ip4/127.0.0.1/tcp/30433/p2p/12D3KooWCzqQx1oEPJ94uDPXPa2VdHqDD5ftpCFmSd5KPHgxMivK

#terminal 3
./target/release/node-template --tmp --chain local --charlie \
--rpc-cors all --rpc-external \
--rpc-port 9448 \
--port 30408 \
--relayer-config-dir=./gadget/config \
--light-client-init-pallet-config-path=./crates/eth2-pallet-init/config.toml \
--light-client-relay-config-path=./eth2substrate-block-relay-rs/config.toml
--bootnodes /ip4/127.0.0.1/tcp/30433/p2p/12D3KooWCzqQx1oEPJ94uDPXPa2VdHqDD5ftpCFmSd5KPHgxMivK \
--unsafe-rpc-external --rpc-methods=unsafe
```

---
Expand Down
3 changes: 2 additions & 1 deletion crates/bls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ tree-hash = { package = "webb-tree-hash", path = "../tree-hash", default-feature
eth2-hashing = { package = "webb-eth2-hashing", path = "../eth2-hashing", default-features = false, features = ["zero_hash_cache"] }
eth2-serde-utils = { package = "webb-eth2-serde-utils", path = "../serde-utils", default-features = false, optional = true }

milagro_bls = { git = "https://github.com/Snowfork/milagro_bls", default-features = false }
log = { version = "0.4.14", default-features = false }
milagro_bls = { git = "https://github.com/Snowfork/milagro_bls", default-features = false, rev="a6d66e4eb89015e352fb1c9f7b661ecdbb5b2176" }
rand = { version = "0.7.3", default-features = false }
rand_chacha = { version = "0.3.1", default-features = false }
serde = { version = "1.0.152", features = ["derive"], default-features = false}
Expand Down
8 changes: 4 additions & 4 deletions crates/finality-update-verify/config_for_tests.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
path_to_current_sync_committee = "./../beacon-chain-relay/data/goerli_testdata/next_sync_committee_goerli_period_473.json"
path_to_next_sync_committee = "./../beacon-chain-relay/data/goerli_testdata/next_sync_committee_goerli_period_474.json"
path_to_light_client_updates = "./../beacon-chain-relay/data/goerli_testdata/light_client_updates_goerli_slots_3885697_3886176.json"
network_name = "goerli"
path_to_current_sync_committee = "./eth2substrate-block-relay-rs/data/goerli_testdata/next_sync_committee_goerli_period_473.json"
path_to_next_sync_committee = "./eth2substrate-block-relay-rs/data/goerli_testdata/next_sync_committee_goerli_period_474.json"
path_to_light_client_updates = "./eth2substrate-block-relay-rs/data/goerli_testdata/light_client_updates_goerli_slots_3885697_3886176.json"
network_name = "Goerli"
25 changes: 11 additions & 14 deletions crates/finality-update-verify/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ fn to_lighthouse_beacon_block_header(
}

pub fn is_correct_finality_update(
bellatrix_fork_epoch: Epoch,
bellatrix_fork_version: ForkVersion,
fork_epoch: Epoch,
fork_version: ForkVersion,
genesis_validators_root: [u8; 32],
light_client_update: &LightClientUpdate,
sync_committee: SyncCommittee,
Expand All @@ -53,12 +53,9 @@ pub fn is_correct_finality_update(

let participant_pubkeys =
get_participant_pubkeys(&sync_committee.pubkeys.0, &sync_committee_bits);
let fork_version = compute_fork_version_by_slot(
light_client_update.signature_slot,
bellatrix_fork_epoch,
bellatrix_fork_version,
)
.expect("Unsupported fork");
let fork_version =
compute_fork_version_by_slot(light_client_update.signature_slot, fork_epoch, fork_version)
.expect("Unsupported fork");
let domain =
compute_domain(DOMAIN_SYNC_COMMITTEE, fork_version, genesis_validators_root.into());

Expand Down Expand Up @@ -117,22 +114,22 @@ mod tests {

let network: NetworkConfig =
NetworkConfig::new(&Network::from_str(&config.network_name).unwrap());
let bellatrix_fork_epoch = network.bellatrix_fork_epoch;
let bellatrix_fork_version = network.bellatrix_fork_version;
let fork_epoch = network.bellatrix_fork_epoch;
let fork_version = network.bellatrix_fork_version;
let genesis_validators_root = network.genesis_validators_root;

assert!(is_correct_finality_update(
bellatrix_fork_epoch,
bellatrix_fork_version,
fork_epoch,
fork_version,
genesis_validators_root,
&light_client_updates[0],
current_sync_committee
)
.unwrap());

assert!(!is_correct_finality_update(
bellatrix_fork_epoch,
bellatrix_fork_version,
fork_epoch,
fork_version,
genesis_validators_root,
&light_client_updates[0],
next_sync_committee
Expand Down
17 changes: 8 additions & 9 deletions eth2substrate-block-relay-rs/src/eth2substrate_relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ use eth_types::{
BlockHeader,
};
use log::{debug, info, trace, warn};
use min_max::*;
use std::{cmp, str::FromStr, thread, time::Duration, vec::Vec};
use tokio::time::sleep;
use min_max::*;

const ONE_EPOCH_IN_SLOTS: u64 = 32;

Expand Down Expand Up @@ -88,8 +88,8 @@ pub struct Eth2SubstrateRelay {
eth1_rpc_client: Eth1RPCClient,
eth_client_pallet: Box<dyn EthClientPalletTrait>,
headers_batch_size: u64,
bellatrix_fork_epoch: Epoch,
bellatrix_fork_version: ForkVersion,
fork_epoch: Epoch,
fork_version: ForkVersion,
genesis_validators_root: [u8; 32],
interval_between_light_client_updates_submission_in_epochs: u64,
max_blocks_for_finalization: u64,
Expand Down Expand Up @@ -134,8 +134,8 @@ impl Eth2SubstrateRelay {
sleep_time_on_sync_secs: config.sleep_time_on_sync_secs,
sleep_time_after_submission_secs: config.sleep_time_after_submission_secs,
eth_client_pallet: eth_pallet,
bellatrix_fork_epoch: eth2_network.bellatrix_fork_epoch,
bellatrix_fork_version: eth2_network.bellatrix_fork_version,
fork_epoch: eth2_network.capella_fork_epoch,
fork_version: eth2_network.capella_fork_version,
genesis_validators_root: eth2_network.genesis_validators_root,
get_light_client_update_by_epoch: config
.get_light_client_update_by_epoch
Expand Down Expand Up @@ -269,8 +269,7 @@ impl Eth2SubstrateRelay {

let min_max = min_max!(min_block_number_in_batch, current_block_number);
let mut headers = skip_fail!(
self.get_execution_blocks_between(min_max.0, min_max.1)
.await,
self.get_execution_blocks_between(min_max.0, min_max.1).await,
"Network problems during fetching execution blocks",
self.sleep_time_on_sync_secs
);
Expand Down Expand Up @@ -396,8 +395,8 @@ impl Eth2SubstrateRelay {
};

finality_update_verify::is_correct_finality_update(
self.bellatrix_fork_epoch,
self.bellatrix_fork_version,
self.fork_epoch,
self.fork_version,
self.genesis_validators_root,
light_client_update,
sync_committee,
Expand Down
8 changes: 6 additions & 2 deletions gadget/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,15 @@ pub async fn start_gadget(relayer_params: Eth2LightClientParams) {

tracing::info!(target: "relay", "=== Initializing relay ===");

if let Ok(is_initialized) = eth_pallet.is_initialized(init_pallet::get_typed_chain_id(&lc_init_config)).await {
if let Ok(is_initialized) = eth_pallet
.is_initialized(init_pallet::get_typed_chain_id(&lc_init_config))
.await
{
if !is_initialized {
match init_pallet::init_pallet(&lc_init_config, &mut eth_pallet).await {
Ok(_) => tracing::info!(target: "relay", "=== Pallet initialized ==="),
Err(e) => tracing::error!(target: "relay", "=== Failed to initialize pallet: {:?} ===", e),
Err(e) =>
tracing::error!(target: "relay", "=== Failed to initialize pallet: {:?} ===", e),
};
}
}
Expand Down
1 change: 1 addition & 0 deletions pallets/eth2-light-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
log = { version = "0.4.14", default-features = false }
serde = { version = "1.0.101", default-features = false, features = ["derive"], optional = true }
codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "max-encoded-len"] }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
Expand Down

0 comments on commit f35213a

Please sign in to comment.