From d14fa2e04debe45614fdfd84db85e58a0d2ce88c Mon Sep 17 00:00:00 2001 From: Alfonso de la Rocha Date: Wed, 3 May 2023 18:32:04 +0200 Subject: [PATCH 1/3] add pre-fund when there are less than three validators --- gateway/src/lib.rs | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/gateway/src/lib.rs b/gateway/src/lib.rs index 8c1d840..a4f37ed 100644 --- a/gateway/src/lib.rs +++ b/gateway/src/lib.rs @@ -685,9 +685,17 @@ impl Actor { validator_set: ValidatorSet, ) -> Result { rt.validate_immediate_caller_is([&SYSTEM_ACTOR_ADDR as &Address])?; - let network_name = rt.transaction(|st: &mut State, _| { + let (network_name, pre_fund) = rt.transaction(|st: &mut State, _| { st.set_membership(validator_set.clone()); - Ok(st.network_name.clone()) + // Get validators that are different from the existing validator set + let mut pre_fund = vec![]; + for v in validator_set.validators().iter() { + if !st.validators.validators.validators().iter().any(|x| x.addr == v.addr) { + pre_fund.push(v.addr.clone()); + } + } + + Ok((st.network_name.clone(), pre_fund)) })?; // initial validators need to be conveniently funded with at least @@ -699,12 +707,25 @@ impl Actor { // to be committed. This doesn't apply to the root. // TODO: Once account abstraction is conveniently supported, there will be // no need for this initial funding of validators. - - if rt.curr_epoch() == 1 && network_name != *ROOTNET_ID { + if network_name != *ROOTNET_ID { + if rt.curr_epoch() == 1 { for v in validator_set.validators().iter() { rt.send(&v.addr, METHOD_SEND, None, INITIAL_VALIDATOR_FUNDS.clone())?; } } + + // to prevent top-down checkpoint submissions from being stuck when the number of validators + // is too small (< 3), where if a new validator join and it doesn't have funds + // no new top-down checkpoints can be submitted, we add some balance also for + // non-initial validators. + if rt.curr_epoch() > 1 && validator_set.validators().len() < 4 { + for v in pre_fund.iter() { + rt.send(&v, METHOD_SEND, None, INITIAL_VALIDATOR_FUNDS.clone())?; + } + } + } + + Ok(RawBytes::default()) } From 0e1146a20bb557ee90497663bee79f42ad7d625f Mon Sep 17 00:00:00 2001 From: Alfonso de la Rocha Date: Wed, 3 May 2023 19:12:29 +0200 Subject: [PATCH 2/3] cargo fmt --- gateway/src/lib.rs | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/gateway/src/lib.rs b/gateway/src/lib.rs index a4f37ed..5dd4ae8 100644 --- a/gateway/src/lib.rs +++ b/gateway/src/lib.rs @@ -690,11 +690,17 @@ impl Actor { // Get validators that are different from the existing validator set let mut pre_fund = vec![]; for v in validator_set.validators().iter() { - if !st.validators.validators.validators().iter().any(|x| x.addr == v.addr) { + if !st + .validators + .validators + .validators() + .iter() + .any(|x| x.addr == v.addr) + { pre_fund.push(v.addr.clone()); } } - + Ok((st.network_name.clone(), pre_fund)) })?; @@ -707,24 +713,23 @@ impl Actor { // to be committed. This doesn't apply to the root. // TODO: Once account abstraction is conveniently supported, there will be // no need for this initial funding of validators. - if network_name != *ROOTNET_ID { + if network_name != *ROOTNET_ID { if rt.curr_epoch() == 1 { - for v in validator_set.validators().iter() { - rt.send(&v.addr, METHOD_SEND, None, INITIAL_VALIDATOR_FUNDS.clone())?; + for v in validator_set.validators().iter() { + rt.send(&v.addr, METHOD_SEND, None, INITIAL_VALIDATOR_FUNDS.clone())?; + } } - } - // to prevent top-down checkpoint submissions from being stuck when the number of validators - // is too small (< 3), where if a new validator join and it doesn't have funds - // no new top-down checkpoints can be submitted, we add some balance also for - // non-initial validators. - if rt.curr_epoch() > 1 && validator_set.validators().len() < 4 { - for v in pre_fund.iter() { - rt.send(&v, METHOD_SEND, None, INITIAL_VALIDATOR_FUNDS.clone())?; + // to prevent top-down checkpoint submissions from being stuck when the number of validators + // is too small (< 3), where if a new validator join and it doesn't have funds + // no new top-down checkpoints can be submitted, we add some balance also for + // non-initial validators. + if rt.curr_epoch() > 1 && validator_set.validators().len() < 4 { + for v in pre_fund.iter() { + rt.send(&v, METHOD_SEND, None, INITIAL_VALIDATOR_FUNDS.clone())?; + } } } - } - Ok(RawBytes::default()) } From d2ec7d7992bd63c7009bb8b6c78d80b3b516ed6e Mon Sep 17 00:00:00 2001 From: Alfonso de la Rocha Date: Wed, 3 May 2023 20:38:02 +0200 Subject: [PATCH 3/3] fix clippy --- gateway/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gateway/src/lib.rs b/gateway/src/lib.rs index 5dd4ae8..20966b5 100644 --- a/gateway/src/lib.rs +++ b/gateway/src/lib.rs @@ -697,7 +697,7 @@ impl Actor { .iter() .any(|x| x.addr == v.addr) { - pre_fund.push(v.addr.clone()); + pre_fund.push(v.addr); } } @@ -726,7 +726,7 @@ impl Actor { // non-initial validators. if rt.curr_epoch() > 1 && validator_set.validators().len() < 4 { for v in pre_fund.iter() { - rt.send(&v, METHOD_SEND, None, INITIAL_VALIDATOR_FUNDS.clone())?; + rt.send(v, METHOD_SEND, None, INITIAL_VALIDATOR_FUNDS.clone())?; } } }