witnet / witnet-rust

Open source Rust implementation of the Witnet decentralized oracle protocol, including full node and wallet backend 👁️🦀
https://docs.witnet.io
GNU General Public License v3.0
180 stars 56 forks source link

Validator with withdrawer address different from the validator address is never eligible to mine #2466

Closed drcpu-github closed 4 weeks ago

drcpu-github commented 3 months ago

A validator which has a stake for which the withdrawer address is not the validator address can never mine a block. This is due to the way his power is calculated. In mining.rs, a StakeKey is contructed where own_pkh is the pkh of the validator:

let key = StakeKey::from((own_pkh, own_pkh));

This StakeKey is later on used to query the power of the validator (which will determine its mining eligibility) using the self.by_key staking tracker. However, since that structure is indexed by a StakeKey<validator, withdrawer> no StakeEntry is found and this his power and eligibility is zero.

Either the query_power should use the by_validator structure (not sure if this has other implications) or the validator should construct its StakeKey using the correct withdrawer as second argument (and I don't know how it can currently know the withdrawer address)?