Skip to content

Commit

Permalink
Fixes for a bug in validatorSet query
Browse files Browse the repository at this point in the history
  • Loading branch information
jieyilong committed Mar 15, 2023
1 parent a198d94 commit f13b63b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions core/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func (v Validator) ID() common.Address {

// Equals checks whether the validator is the same as another validator
func (v Validator) Equals(x Validator) bool {
logger.Debugf("v.Equals(x) check, v.Addr: %v, x.Addr: %v, v.Stake: %v, x.Stake: %v\n", v.Address.Hex(), x.Address.Hex(), v.Stake, x.Stake)
if v.Address != x.Address {
return false
}
Expand Down
9 changes: 6 additions & 3 deletions interchain/witness/metachain_witness.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,10 @@ func (mw *MetachainWitness) updateValidatorSetCache(dynasty *big.Int) (*score.Va
mw.cacheMutex.Lock()
defer mw.cacheMutex.Unlock()

queryBlockHeight := big.NewInt(1).Mul(dynasty, big.NewInt(1).SetInt64(scom.NumMainchainBlocksPerDynasty))
queryBlockHeight = big.NewInt(0).Add(queryBlockHeight, big.NewInt(1)) // increment by one to make sure the query block height falls into the dynasty
vs, err := mw.chainRegistrarOnMainchain.GetValidatorSet(nil, mw.subchainID, queryBlockHeight)
// queryBlockHeight := big.NewInt(1).Mul(dynasty, big.NewInt(1).SetInt64(scom.NumMainchainBlocksPerDynasty))
// queryBlockHeight = big.NewInt(0).Add(queryBlockHeight, big.NewInt(1)) // increment by one to make sure the query block height falls into the dynasty
// vs, err := mw.chainRegistrarOnMainchain.GetValidatorSet(nil, mw.subchainID, queryBlockHeight)
vs, err := mw.chainRegistrarOnMainchain.GetValidatorSet(nil, mw.subchainID, dynasty)
validatorAddrs := vs.Validators
validatorStakes := vs.ShareAmounts

Expand All @@ -592,6 +593,8 @@ func (mw *MetachainWitness) updateValidatorSetCache(dynasty *big.Int) (*score.Va

mw.validatorSetCache[dynasty.String()] = validatorSet

logger.Debugf("updateValidatorSetCache, dynasty = %v, validatorSet = %v", dynasty.String(), validatorSet.String())

return validatorSet, nil
}

Expand Down
4 changes: 4 additions & 0 deletions ledger/execution/tx_validator_set_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ func (exec *SubchainValidatorSetUpdateTxExecutor) process(chainID string, view *
return common.Hash{}, result.UndecidedWith(result.Info{"newDynasty": newDynasty, "err": err})
}

logger.Debugf("newDynasty: %v", newDynasty)
logger.Debugf("newValidatorSet : %v", newValidatorSet.String())
logger.Debugf("witnessedValidatorSet: %v", witnessedValidatorSet.String())

if !newValidatorSet.Equals(witnessedValidatorSet) {
return common.Hash{}, result.Error("validator set mismatch: %v vs %v", *newValidatorSet, *witnessedValidatorSet)
}
Expand Down

0 comments on commit f13b63b

Please sign in to comment.