Skip to content

Commit 2918cb0

Browse files
committed
RPC fixes
1 parent fa305ae commit 2918cb0

File tree

9 files changed

+89
-55
lines changed

9 files changed

+89
-55
lines changed

eth2near/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eth2near/eth2near-block-relay-rs/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ ethereum_hashing = { workspace = true }
1212
ethereum_ssz = { workspace = true }
1313
eth-types = { path = "../../contracts/near/eth-types/" }
1414
eth2-utility = { path = "../../contracts/near/eth2-utility" }
15+
near-workspaces = "0.18"
1516

1617
contract_wrapper = { path = "../contract_wrapper" }
1718
finality-update-verify = { path = "../finality-update-verify" }

eth2near/eth2near-block-relay-rs/config_for_tests.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
beacon_endpoint = "https://lodestar-goerli.chainsafe.io"
2-
eth1_endpoint = "https://goerli.infura.io/v3/ETH1_INFURA_API_KEY"
1+
beacon_endpoint = "http://unstable.sepolia.beacon-api.nimbus.team/"
2+
eth1_endpoint = "https://sepolia.infura.io/v3/ETH1_INFURA_API_KEY"
33
path_to_current_sync_committee = "./data/goerli_testdata/next_sync_committee_goerli_period_473.json"
44
path_to_next_sync_committee = "./data/goerli_testdata/next_sync_committee_goerli_period_474.json"
55
path_to_execution_blocks_headers = "./data/goerli_testdata/execution_block_headers_goerli_slots_3885697_3886176.json"

eth2near/eth2near-block-relay-rs/src/contract_type.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::str::FromStr;
77
#[derive(Debug, Clone, Deserialize)]
88
pub enum ContractType {
99
Near,
10-
Dao,
1110
File,
1211
}
1312

@@ -18,7 +17,7 @@ impl Display for IncorrectContractType {
1817
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1918
write!(
2019
f,
21-
"Unknown contract type. Possible contract types: 'Near', 'Dao', 'File'"
20+
"Unknown contract type. Possible contract types: 'Near', 'File'"
2221
)
2322
}
2423
}
@@ -35,7 +34,6 @@ impl ContractType {
3534
pub fn as_str(&self) -> &str {
3635
match self {
3736
ContractType::Near => "Near",
38-
ContractType::Dao => "Dao",
3937
ContractType::File => "File",
4038
}
4139
}
@@ -47,7 +45,6 @@ impl FromStr for ContractType {
4745
fn from_str(s: &str) -> Result<Self, Self::Err> {
4846
match s.to_lowercase().as_str() {
4947
"near" => Ok(ContractType::Near),
50-
"dao" => Ok(ContractType::Dao),
5148
"file" => Ok(ContractType::File),
5249
_ => Err(IncorrectContractType),
5350
}

eth2near/eth2near-block-relay-rs/src/eth2near_relay.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use eth_rpc_client::hand_made_finality_light_client_update::HandMadeFinalityLigh
1616
use eth_types::eth2::LightClientUpdate;
1717
use eth_types::BlockHeader;
1818
use log::{debug, info, trace, warn};
19+
use types::Hash256;
20+
1921
use near_primitives::views::FinalExecutionStatus;
2022
use std::cmp::max;
2123
use std::error::Error;
@@ -707,6 +709,7 @@ mod tests {
707709
use eth_types::BlockHeader;
708710
use std::error::Error;
709711
use tree_hash::TreeHash;
712+
use types::Hash256;
710713

711714
fn get_test_config() -> ConfigForTests {
712715
ConfigForTests::load_from_toml("config_for_tests.toml".try_into().unwrap())
@@ -804,12 +807,13 @@ mod tests {
804807
.get_light_client_update(last_period)
805808
.unwrap();
806809

807-
let branch: Vec<ethereum_types::H256> = light_client_update
810+
let branch: Vec<Hash256> = light_client_update
808811
.finality_update
809812
.finality_branch
810813
.iter()
811-
.map(|h| h.0)
814+
.map(|h| Hash256::from_slice(h.0.as_bytes()))
812815
.collect();
816+
813817
assert!(
814818
merkle_proof::verify_merkle_proof(
815819
light_client_update
@@ -820,19 +824,26 @@ mod tests {
820824
branch.as_slice(),
821825
TREE_FINALITY_DEPTH,
822826
TREE_FINALITY_INDEX,
823-
light_client_update.attested_beacon_header.state_root.0
827+
Hash256::from_slice(
828+
light_client_update
829+
.attested_beacon_header
830+
.state_root
831+
.0
832+
.as_bytes()
833+
)
824834
),
825835
"Incorrect proof of inclusion the finality checkpoint to attested beacon state"
826836
);
827837

828-
let branch = light_client_update
838+
let branch: Vec<Hash256> = light_client_update
829839
.sync_committee_update
830840
.as_ref()
831841
.unwrap()
832842
.next_sync_committee_branch
833843
.iter()
834-
.map(|h| h.0)
835-
.collect::<Vec<ethereum_types::H256>>();
844+
.map(|h| Hash256::from_slice(h.0.as_bytes()))
845+
.collect();
846+
836847
assert!(
837848
merkle_proof::verify_merkle_proof(
838849
light_client_update
@@ -844,7 +855,13 @@ mod tests {
844855
branch.as_slice(),
845856
TREE_NEXT_SYNC_COMMITTEE_DEPTH,
846857
TREE_NEXT_SYNC_COMMITTEE_INDEX,
847-
light_client_update.attested_beacon_header.state_root.0
858+
Hash256::from_slice(
859+
light_client_update
860+
.attested_beacon_header
861+
.state_root
862+
.0
863+
.as_bytes()
864+
)
848865
),
849866
"Incorrect proof of inclusion the next sync committee to finality beacon state"
850867
);

eth2near/eth2near-block-relay-rs/src/main.rs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ use clap::Parser;
22
use contract_wrapper::contract_wrapper_trait::ContractWrapper;
33
use contract_wrapper::eth_client_contract_trait::EthClientContractTrait;
44
use contract_wrapper::near_contract_wrapper::NearContractWrapper;
5-
use contract_wrapper::{
6-
dao_contract, dao_eth_client_contract, eth_client_contract, file_eth_client_contract,
7-
};
5+
use contract_wrapper::{eth_client_contract, file_eth_client_contract};
86
use eth2_to_near_relay::config::Config;
97
use eth2_to_near_relay::contract_type::ContractType;
108
use eth2_to_near_relay::eth2near_relay::Eth2NearRelay;
@@ -36,30 +34,11 @@ fn get_eth_contract_wrapper(config: &Config) -> Box<dyn ContractWrapper> {
3634
))
3735
}
3836

39-
fn get_dao_contract_wrapper(config: &Config) -> Box<dyn ContractWrapper> {
40-
let dao_contract_account_id = config.dao_contract_account_id.clone();
41-
42-
Box::new(NearContractWrapper::new(
43-
&config.near_endpoint,
44-
&config.signer_account_id,
45-
&config.path_to_signer_secret_key,
46-
&dao_contract_account_id
47-
.expect("No DAO contract account ID provided for relay running in DAO mode"),
48-
Some(std::time::Duration::from_secs(
49-
config.near_requests_timeout_seconds,
50-
)),
51-
))
52-
}
53-
5437
fn get_eth_client_contract(config: &Config) -> Box<dyn EthClientContractTrait> {
5538
let eth_contract_wrapper = get_eth_contract_wrapper(config);
5639
let eth_client = eth_client_contract::EthClientContract::new(eth_contract_wrapper);
5740

5841
match config.contract_type {
59-
ContractType::Dao => Box::new(dao_eth_client_contract::DaoEthClientContract::new(
60-
eth_client,
61-
dao_contract::DAOContract::new(get_dao_contract_wrapper(config)),
62-
)),
6342
ContractType::File => Box::new(file_eth_client_contract::FileEthClientContract::new(
6443
eth_client,
6544
config

eth2near/eth2near-block-relay-rs/src/test_utils.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ use eth_rpc_client::beacon_rpc_client::{BeaconRPCClient, BeaconRPCVersion};
1212
use eth_rpc_client::eth1_rpc_client::Eth1RPCClient;
1313
use eth_types::eth2::{ExtendedBeaconBlockHeader, LightClientUpdate, SyncCommittee};
1414
use eth_types::BlockHeader;
15+
use near_workspaces::{Account, Contract};
1516
use std::{thread, time};
1617
use tokio::runtime::Runtime;
1718
use tree_hash::TreeHash;
1819
use types::{ExecutionPayload, MainnetEthSpec};
19-
use workspaces::{Account, Contract};
2020

2121
pub fn read_json_file_from_data_dir(file_name: &str) -> std::string::String {
2222
let mut json_file_path = std::env::current_exe().unwrap();
@@ -119,12 +119,12 @@ pub fn init_contract_from_specific_slot(
119119
.get_beacon_block_header_for_block_id(&format!("{}", finality_slot))
120120
.unwrap();
121121

122-
let finality_header = eth_types::eth2::BeaconBlockHeader {
122+
let finality_header: eth_types::eth2::BeaconBlockHeader = eth_types::eth2::BeaconBlockHeader {
123123
slot: finality_header.slot.as_u64(),
124124
proposer_index: finality_header.proposer_index,
125-
parent_root: finality_header.parent_root.into(),
126-
state_root: finality_header.state_root.into(),
127-
body_root: finality_header.body_root.into(),
125+
parent_root: finality_header.parent_root.0.into(),
126+
state_root: finality_header.state_root.0.into(),
127+
body_root: finality_header.body_root.0.into(),
128128
};
129129

130130
let finalized_body = beacon_rpc_client
@@ -135,8 +135,8 @@ pub fn init_contract_from_specific_slot(
135135
finalized_body.execution_payload().unwrap().into();
136136
let finalized_beacon_header = ExtendedBeaconBlockHeader {
137137
header: finality_header.clone(),
138-
beacon_block_root: eth_types::H256(finality_header.tree_hash_root()),
139-
execution_block_hash: execution_payload.block_hash().into_root().into(),
138+
beacon_block_root: eth_types::H256(finality_header.tree_hash_root().0.into()),
139+
execution_block_hash: execution_payload.block_hash().into_root().0.into(),
140140
};
141141

142142
let finalized_execution_header: BlockHeader = eth1_rpc_client
@@ -160,7 +160,9 @@ pub fn init_contract_from_specific_slot(
160160

161161
fn create_contract(config_for_test: &ConfigForTests) -> (Account, Contract) {
162162
let rt = Runtime::new().unwrap();
163-
let worker = rt.block_on(workspaces::sandbox()).unwrap();
163+
let worker = rt
164+
.block_on(async { near_workspaces::sandbox().await })
165+
.unwrap();
164166

165167
// create accounts
166168
let owner = worker.root_account().unwrap();

eth2near/eth_rpc_client/src/beacon_rpc_client.rs

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ impl BeaconRPCClient {
123123
"{}/{}/{}",
124124
self.endpoint_url, self.routes.get_block, block_id
125125
);
126+
let url = url.replace("//", "/");
127+
let url = url.replace("http:/", "http://");
128+
println!("URL: {}", url);
126129

127130
let json_str = &self.get_json_from_raw_request(&url)?;
128131

@@ -147,6 +150,10 @@ impl BeaconRPCClient {
147150
"{}/{}/{}",
148151
self.endpoint_url, self.routes.get_block_header, block_id
149152
);
153+
// Strip double slashes
154+
let url = url.replace("//", "/");
155+
let url = url.replace("https:/", "https://");
156+
println!("URL: {}", url);
150157

151158
let json_str = &self.get_json_from_raw_request(&url)?;
152159
self.check_block_found_for_slot(json_str)?;
@@ -168,6 +175,10 @@ impl BeaconRPCClient {
168175
"{}/{}?start_period={}&count=1",
169176
self.endpoint_url, self.routes.get_light_client_update, period
170177
);
178+
// Strip double slashes
179+
let url = url.replace("//", "/");
180+
let url = url.replace("http:/", "http://");
181+
println!("URL: {}", url);
171182
let light_client_update_json_str = self.get_json_from_raw_request(&url)?;
172183
self.light_client_update_from_json_str(light_client_update_json_str)
173184
}
@@ -203,6 +214,11 @@ impl BeaconRPCClient {
203214
"{}/{}?epoch={}",
204215
self.endpoint_url, self.routes.get_light_client_update_by_epoch, epoch
205216
);
217+
// Strip double slashes
218+
let url = url.replace("//", "/");
219+
let url = url.replace("https:/", "https://");
220+
println!("URL: {}", url);
221+
206222
let mut light_client_update_json_str = self.get_json_from_raw_request(&url)?;
207223
let v: Value = serde_json::from_str(light_client_update_json_str.as_str())?;
208224
let object = json!({
@@ -240,6 +256,10 @@ impl BeaconRPCClient {
240256
"{}/{}/{}",
241257
self.endpoint_url, self.routes.get_bootstrap, block_root
242258
);
259+
// Strip double slashes
260+
let url = url.replace("//", "/");
261+
let url = url.replace("http:/", "http://");
262+
println!("URL: {}", url);
243263

244264
let light_client_snapshot_json_str = self.get_json_from_raw_request(&url)?;
245265
let parsed_json: Value = serde_json::from_str(&light_client_snapshot_json_str)?;
@@ -266,6 +286,10 @@ impl BeaconRPCClient {
266286
"{}/eth/v1/beacon/states/finalized/finality_checkpoints",
267287
self.endpoint_url
268288
);
289+
// Strip double slashes
290+
let url = url.replace("//", "/");
291+
let url = url.replace("http:/", "http://");
292+
println!("URL: {}", url);
269293
let checkpoint_json_str = self.get_json_from_raw_request(&url)?;
270294
let parsed_json: Value = serde_json::from_str(&checkpoint_json_str)?;
271295

@@ -295,6 +319,10 @@ impl BeaconRPCClient {
295319
"{}/{}/{}",
296320
self.endpoint_url, self.routes.get_block, beacon_block_hash_str
297321
);
322+
// Strip double slashes
323+
let url = url.replace("//", "/");
324+
let url = url.replace("http:/", "http://");
325+
println!("URL: {}", url);
298326
let block_json_str = &self.get_json_from_raw_request(&url)?;
299327
let v: Value = serde_json::from_str(block_json_str)?;
300328
let slot = utils::trim_quotes(v["data"]["message"]["slot"].to_string()).parse::<u64>()?;
@@ -317,7 +345,10 @@ impl BeaconRPCClient {
317345
"{}/{}",
318346
self.endpoint_url, self.routes.get_light_client_finality_update,
319347
);
320-
348+
// Strip double slashes
349+
let url = url.replace("//", "/");
350+
let url = url.replace("http:/", "http://");
351+
println!("URL: {}", url);
321352
let light_client_update_json_str = self.get_json_from_raw_request(&url)?;
322353
let v: Value = serde_json::from_str(&light_client_update_json_str)?;
323354
let light_client_update_json_str = serde_json::to_string(&json!({"data": [v["data"]]}))?;
@@ -345,6 +376,10 @@ impl BeaconRPCClient {
345376
"{}/{}/{}",
346377
self.endpoint_url, self.routes.get_state, state_id
347378
);
379+
// Strip double slashes
380+
let url_request = url_request.replace("//", "/");
381+
let url_request = url_request.replace("http:/", "http://");
382+
println!("URL: {}", url_request);
348383
let json_str = Self::get_json_from_client(&self.client_state_request, &url_request)?;
349384

350385
let v: Value = serde_json::from_str(&json_str)?;
@@ -690,7 +725,11 @@ mod tests {
690725
let beacon_rpc_client =
691726
BeaconRPCClient::new(&url, TIMEOUT_SECONDS, TIMEOUT_STATE_SECONDS, None);
692727
let rpc_json_str = beacon_rpc_client.get_json_from_raw_request(&url);
693-
assert_eq!(rpc_json_str.unwrap(), file_json_str.trim());
728+
729+
let rpc_json_str = rpc_json_str.unwrap();
730+
let rpc_json: Value = serde_json::from_str(&rpc_json_str).unwrap();
731+
let file_json: Value = serde_json::from_str(&file_json_str).unwrap();
732+
assert_eq!(rpc_json, file_json);
694733
}
695734

696735
#[test]
@@ -733,27 +772,25 @@ mod tests {
733772

734773
assert_eq!(
735774
beacon_block_header.slot,
736-
trim_quotes(v["data"]["header"]["message"]["slot"].to_string())
737-
.parse::<u64>()
738-
.unwrap()
775+
trim_quotes(v["slot"].to_string()).parse::<u64>().unwrap()
739776
);
740777
assert_eq!(
741778
beacon_block_header.proposer_index,
742-
trim_quotes(v["data"]["header"]["message"]["proposer_index"].to_string())
779+
trim_quotes(v["proposer_index"].to_string())
743780
.parse::<u64>()
744781
.unwrap()
745782
);
746783
assert_eq!(
747784
format!("{:?}", beacon_block_header.body_root),
748-
trim_quotes(v["data"]["header"]["message"]["body_root"].to_string())
785+
trim_quotes(v["body_root"].to_string())
749786
);
750787
assert_eq!(
751788
format!("{:?}", beacon_block_header.parent_root),
752-
trim_quotes(v["data"]["header"]["message"]["parent_root"].to_string())
789+
trim_quotes(v["parent_root"].to_string())
753790
);
754791
assert_eq!(
755792
format!("{:?}", beacon_block_header.state_root),
756-
trim_quotes(v["data"]["header"]["message"]["state_root"].to_string())
793+
trim_quotes(v["state_root"].to_string())
757794
);
758795
}
759796

@@ -774,7 +811,7 @@ mod tests {
774811
std::fs::read_to_string(config.path_to_block).expect("Unable to read file");
775812
let v: Value = serde_json::from_str(&block_json_str).unwrap();
776813
assert_eq!(
777-
beacon_block_body.attestations_base().unwrap().len(),
814+
beacon_block_body.attestations_electra().unwrap().len(),
778815
v["data"]["message"]["body"]["attestations"]
779816
.as_array()
780817
.unwrap()
@@ -789,7 +826,7 @@ mod tests {
789826
#[test]
790827
fn test_is_sync() {
791828
assert!(!BeaconRPCClient::new(
792-
"https://lodestar-goerli.chainsafe.io",
829+
"https://lodestar-sepolia.chainsafe.io",
793830
TIMEOUT_SECONDS,
794831
TIMEOUT_STATE_SECONDS,
795832
None

0 commit comments

Comments
 (0)