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

add pre-fund when there are less than three validators #102

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions gateway/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,9 +685,23 @@ impl Actor {
validator_set: ValidatorSet,
) -> Result<RawBytes, ActorError> {
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);
}
}

Ok((st.network_name.clone(), pre_fund))
})?;

// initial validators need to be conveniently funded with at least
Expand All @@ -699,12 +713,24 @@ 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 rt.curr_epoch() == 1 {
for v in validator_set.validators().iter() {
rt.send(&v.addr, METHOD_SEND, None, INITIAL_VALIDATOR_FUNDS.clone())?;
}
}

if rt.curr_epoch() == 1 && network_name != *ROOTNET_ID {
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 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cryptoAtwill, just to double-check with you. I don't think we should merge this one, as there is a really simple attack where before there are more than four validators, any validator could continuously join and leave to drain 1 FIL of the gateway at a time. I think for now let's track the bug here and figure out a better way to solve it. Tracking the issue here: #103

for v in pre_fund.iter() {
rt.send(v, METHOD_SEND, None, INITIAL_VALIDATOR_FUNDS.clone())?;
}
}
}

Ok(RawBytes::default())
}

Expand Down