chainx-org / ChainX

Bitcoin's layer2 smart contract network has already supported WASM and EVM, and is supporting MoveVM
https://chainx.org
GNU General Public License v3.0
323 stars 121 forks source link

Debug: slash exception from upgrade ChainX v4.0.0 #616

Closed icodezjb closed 2 years ago

icodezjb commented 2 years ago

Issue:

Since ChainX has been upgraded to v4.0.0 (runtime 11 -> 12), many validators have been slashed for no reason

Analyze:

Before the end of each session, pallet-im-online will submit offline validators to xstaking, and they will all be slashed. There are two conditions for pallet-im-online to determine whether the validator is online:

We also notice that the node that should be slashed is not slashed

Root Cause:

we tracked this pr Force the validators in the waiting list to run an authority node

the XStaking::active_validator_set().collect() return validators which the order is not fixed.

and in pallet-im-online, mark whether to be online in the order of validator, And this is the root cause

let session_index = T::ValidatorSet::session_index();
let keys = Keys::<T>::get();
let current_validators = T::ValidatorSet::validators();

let offenders = current_validators
            .into_iter()
            .enumerate()
            .filter(|(index, id)| !Self::is_online_aux(*index as u32, id))
            .filter_map(|(_, id)| {
                <T::ValidatorSet as ValidatorSetWithIdentification<T::AccountId>>::IdentificationOf::convert(
                    id.clone()
                ).map(|full_id| (id, full_id))
            })
            .collect::<Vec<IdentificationTuple<T>>>();

Fix:

Fix slash exception

/// Returns all the validators and candidates by order
    #[inline]
    pub fn active_candidates() -> Vec<T::AccountId> {
        let mut candidates = Self::active_validator_set()
            .map(|v| (Self::total_votes_of(&v), v))
            .collect::<Vec<_>>();

        candidates.sort_by(|&(ref b1, _), &(ref b2, _)| b2.cmp(b1));

        candidates.into_iter().map(|(_, v)| v).collect()
    }

More rewards for validators

For the security of the ChainX mainnet and to encourage more community users to participate in the ChainX validators selection, we have decided to increase the proportion of system rewards to validators from 10% to 20% Rewards: 20% for validator and 80% for the reward pot.

ddozen commented 2 years ago

Im still getting slashed after upgrade to v4.1.1

icodezjb commented 2 years ago

Im still getting slashed after upgrade to v4.1.1

ChainX mainnet is OK now, and you can

ddozen commented 2 years ago

It is slashing and i;m loosing 1 pcx everytimne it happens. (1) i rechecked session keys and even set new ones (2)state-cache-size=0 is set

icodezjb commented 2 years ago

It is slashing and i;m loosing 1 pcx everytimne it happens. (1) i rechecked session keys and even set new ones (2)state-cache-size=0 is set

Are you DOZENODES? You were slashed during the candidate stage. If you do not set the correct session keys in the candidate stage, it means that the heartbeat transaction (using the im-online key) cannot be sent to the system, the system thinks you are offline, and then you are slashed

icodezjb commented 2 years ago

Im still getting slashed after upgrade to v4.1.1 @ddozen Try ChainX v4.2.0 now (runtime version 20). The candidate node would be slashed.