abci/example/kvstore: decrease val power by 1 upon equivocation (#5056)

in `persistent_kvstore`
This commit is contained in:
Anton Kaliaev
2020-06-26 15:58:27 +04:00
committed by GitHub
parent dab488b118
commit 0c7fd316eb
2 changed files with 14 additions and 9 deletions

View File

@@ -125,16 +125,21 @@ func (app *PersistentKVStoreApplication) BeginBlock(req types.RequestBeginBlock)
// reset valset changes
app.ValUpdates = make([]types.ValidatorUpdate, 0)
// Punish validators who committed equivocation.
for _, ev := range req.ByzantineValidators {
if ev.Type == tmtypes.ABCIEvidenceTypeDuplicateVote {
// decrease voting power by 1
if ev.TotalVotingPower == 0 {
continue
addr := string(ev.Validator.Address)
if pubKey, ok := app.valAddrToPubKeyMap[addr]; ok {
app.updateValidator(types.ValidatorUpdate{
PubKey: pubKey,
Power: ev.Validator.Power - 1,
})
app.logger.Info("Decreased val power by 1 because of the equivocation",
"val", addr)
} else {
app.logger.Error("Wanted to punish val, but can't find it",
"val", addr)
}
app.updateValidator(types.ValidatorUpdate{
PubKey: app.valAddrToPubKeyMap[string(ev.Validator.Address)],
Power: ev.TotalVotingPower - 1,
})
}
}

View File

@@ -10,8 +10,8 @@ sudo apt-get upgrade -y
sudo apt-get install -y jq unzip python-pip software-properties-common make
# get and unpack golang
curl -O https://storage.googleapis.com/golang/go1.13.linux-amd64.tar.gz
tar -xvf go1.13.linux-amd64.tar.gz
curl -O https://dl.google.com/go/go1.14.4.linux-amd64.tar.gz
tar -xvf go1.14.4.linux-amd64.tar.gz
## move binary and add to path
mv go /usr/local