Skip to content

Commit b186cd4

Browse files
authored
Eth2Near-relayer: fix sending update for the next period (#894)
* Fix handling the case when the gap between NEAR and Ethereum is more than one period. Send the update for the next period, not for the last one.
1 parent e071341 commit b186cd4

File tree

4 files changed

+14
-18
lines changed

4 files changed

+14
-18
lines changed

eth2near/contract_wrapper/src/dao_contract.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ mod tests {
139139
SyncAggregate, SyncCommitteeBits,
140140
};
141141
use near_crypto::{KeyType, PublicKey};
142-
use near_primitives::serialize::to_base64;
143142
use near_primitives::types::AccountId;
144143
use near_primitives::views::{
145144
ExecutionOutcomeView, ExecutionOutcomeWithIdView, ExecutionStatusView,
@@ -152,7 +151,7 @@ mod tests {
152151
use std::time::Duration;
153152

154153
fn get_default_result() -> FinalExecutionOutcomeView {
155-
let status_str = to_base64("215");
154+
let status_str = "215";
156155
FinalExecutionOutcomeView {
157156
status: FinalExecutionStatus::SuccessValue(status_str.into()),
158157
transaction: SignedTransactionView {

eth2near/eth2-contract-init/src/init_contract.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,13 @@ pub fn init_contract(
6464
);
6565
let eth1_rpc_client = Eth1RPCClient::new(&config.eth1_endpoint);
6666

67+
let last_period = BeaconRPCClient::get_period_for_slot(beacon_rpc_client
68+
.get_last_slot_number()
69+
.expect("Error on fetching last slot number")
70+
.as_u64());
71+
6772
let light_client_update_with_next_sync_committee = beacon_rpc_client
68-
.get_light_client_update_for_last_period()
73+
.get_light_client_update(last_period)
6974
.expect("Error on fetching finality light client update with sync committee update");
7075
let finality_light_client_update = beacon_rpc_client
7176
.get_finality_light_client_update()

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ impl Eth2NearRelay {
524524
debug!(target: "relay", "Finalized period on ETH and NEAR are different. Fetching sync commity update");
525525
return_on_fail!(
526526
self.beacon_rpc_client
527-
.get_light_client_update_for_last_period(),
527+
.get_light_client_update(last_eth2_period_on_near_chain + 1),
528528
"Error on getting light client update. Skipping sending light client update"
529529
)
530530
};
@@ -794,9 +794,14 @@ mod tests {
794794

795795
let relay = get_relay(true, &config_for_test);
796796

797+
let last_period = BeaconRPCClient::get_period_for_slot(relay.beacon_rpc_client
798+
.get_last_slot_number()
799+
.unwrap()
800+
.as_u64());
801+
797802
let light_client_update = relay
798803
.beacon_rpc_client
799-
.get_light_client_update_for_last_period()
804+
.get_light_client_update(last_period)
800805
.unwrap();
801806

802807
let branch: Vec<ethereum_types::H256> = light_client_update

eth2near/eth_rpc_client/src/beacon_rpc_client.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -337,19 +337,6 @@ impl BeaconRPCClient {
337337
})
338338
}
339339

340-
/// Returns the best light client update for the last period
341-
///
342-
/// Best is defined by (in order of priority):
343-
/// - Is finalized update
344-
/// - Has most bits
345-
/// - Oldest update
346-
pub fn get_light_client_update_for_last_period(
347-
&self,
348-
) -> Result<LightClientUpdate, Box<dyn Error>> {
349-
let last_period = Self::get_period_for_slot(self.get_last_slot_number()?.as_u64());
350-
self.get_light_client_update(last_period)
351-
}
352-
353340
pub fn get_beacon_state(
354341
&self,
355342
state_id: &str,

0 commit comments

Comments
 (0)