Skip to content

Commit 1666d56

Browse files
GTC6244Copilot
andauthored
Set a default realm to request_to_join, if a realm id isn't found. (#103)
* Set a default realm to request_to_join, if a realm id isn't found. * cargo fmt ! * remove trace & add call. * Update rust/lit-node/lit-node/tests/toxiproxy/chain_faults.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Spelling. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 72be7da commit 1666d56

File tree

3 files changed

+69
-15
lines changed

3 files changed

+69
-15
lines changed

rust/lit-node/lit-node/src/peers/peer_state/chain_update.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,43 @@ impl PeerState {
192192

193193
#[instrument(level = "debug", skip_all)]
194194
pub async fn request_to_join(&self) -> Result<()> {
195-
let Some(realm_id) = self.chain_data_config_manager.get_realm_id() else {
196-
return Err(unexpected_err("No realm id set", None));
195+
let realm_id = match self.chain_data_config_manager.get_realm_id() {
196+
Some(realm_id) => realm_id,
197+
None => {
198+
trace!(
199+
"Failed to get realm id, but will try to join realm # 1, if staking amount is sufficient."
200+
);
201+
202+
let check_staking_amounts = self
203+
.staking_contract
204+
.check_staking_amounts(self.staker_address)
205+
.call()
206+
.await;
207+
match check_staking_amounts {
208+
Ok(true) => {
209+
trace!(
210+
"Staking amount is valid for a node to join a network. Selecting realm # 1."
211+
);
212+
}
213+
Ok(false) => {
214+
return Err(unexpected_err(
215+
"Staking amount is not valid for this node to request to join."
216+
.to_string(),
217+
None,
218+
));
219+
}
220+
Err(e) => {
221+
return Err(blockchain_err(
222+
e,
223+
Some(
224+
"Failed to check staking amount for this request to join."
225+
.to_string(),
226+
),
227+
));
228+
}
229+
}
230+
U256::from(1)
231+
}
197232
};
198233

199234
let func = self

rust/lit-node/lit-node/tests/common/faults.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ pub fn enable_fault_channel_direct(source_url: Url, target_url: Url, target_is_c
566566
assert!(get_proxy_result.is_ok());
567567
let r = get_proxy_result.as_ref().unwrap().enable();
568568
assert!(r.is_ok());
569-
info!("Enabled fault for {:?}", proxy_name);
569+
info!("Enabled fault channel for {:?}", proxy_name);
570570
})
571571
.join()
572572
.expect("Failed to enable fault");

rust/lit-node/lit-node/tests/toxiproxy/chain_faults.rs

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::common::setup_logging;
66
use ethers::types::U256;
77
use lit_node_common::proxy_mapping::ClientProxyMapping;
88
use lit_node_testnet::TestSetupBuilder;
9+
use lit_node_testnet::testnet::actions::Actions;
910
use once_cell::sync::Lazy;
1011
use tracing::info;
1112

@@ -82,7 +83,6 @@ async fn auto_rejoin_faulty_node() {
8283

8384
info!("TEST: auto_rejoin_faulty_node");
8485
let realm_id = U256::from(1);
85-
let seconds_to_increase = 300;
8686

8787
// Start a new node collection
8888
let (testnet, _validator_collection, _end_user) = TestSetupBuilder::default()
@@ -93,9 +93,12 @@ async fn auto_rejoin_faulty_node() {
9393

9494
let actions = testnet.actions().clone();
9595

96-
// wait for a few seconds to led the nodes chat with each other.
96+
// wait for a few seconds to let the nodes chat with each other.
9797
actions.sleep_millis(1000).await;
9898

99+
// Advance and check the current and next validators.
100+
advance_and_check_current_and_next_validators(&actions, realm_id).await;
101+
99102
let faulty_node_port =
100103
disable_chain_for_random_faulty_node(STARTING_PORT, FAULT_TEST_NUM_NODES);
101104
info!("Faulty node port: {}", faulty_node_port);
@@ -108,23 +111,31 @@ async fn auto_rejoin_faulty_node() {
108111
);
109112

110113
// Update the epoch, forcing a kick due to DKG non-participation.
111-
let epoch = actions.get_current_epoch(realm_id).await;
112-
info!("Current epoch: {}", epoch);
113-
actions
114-
.increase_blockchain_timestamp(seconds_to_increase)
115-
.await;
114+
advance_and_check_current_and_next_validators(&actions, realm_id).await;
116115

117-
let next_epoch = epoch + U256::from(1);
118-
info!("Next epoch: {}", next_epoch);
119-
actions.wait_for_epoch(realm_id, next_epoch).await;
120-
info!("Advanced to next epoch: {}", next_epoch);
116+
// advance again
117+
advance_and_check_current_and_next_validators(&actions, realm_id).await;
121118

122119
// Test to see if our validator was kicked.
123120

124-
// wait for the kicked node to try to call rejion.
121+
// wait for the kicked node to try to call request_to_join.
125122
enable_chain_for_node(faulty_node_port);
126123
actions.sleep_millis(3000).await;
127124

125+
advance_and_check_current_and_next_validators(&actions, realm_id).await;
126+
}
127+
128+
async fn advance_and_check_current_and_next_validators(actions: &Actions, realm_id: U256) {
129+
let seconds_to_increase = 300;
130+
131+
let validator_structs = actions.get_current_validator_structs(realm_id).await;
132+
let next_validator_structs = actions.get_next_validator_structs(realm_id).await;
133+
info!(
134+
"Current/next validator count before advance: {} / {}",
135+
validator_structs.len(),
136+
next_validator_structs.len()
137+
);
138+
128139
let epoch = actions.get_current_epoch(realm_id).await;
129140
info!("Current epoch: {}", epoch);
130141
actions
@@ -135,4 +146,12 @@ async fn auto_rejoin_faulty_node() {
135146
info!("Next epoch: {}", next_epoch);
136147
actions.wait_for_epoch(realm_id, next_epoch).await;
137148
info!("Advanced to next epoch: {}", next_epoch);
149+
150+
let validator_structs = actions.get_current_validator_structs(realm_id).await;
151+
let next_validator_structs = actions.get_next_validator_structs(realm_id).await;
152+
info!(
153+
"Current/next validator count after advance: {} / {}",
154+
validator_structs.len(),
155+
next_validator_structs.len()
156+
);
138157
}

0 commit comments

Comments
 (0)