mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-04 07:07:13 +00:00
abci: VoteInfo, ValidatorUpdate. See ADR-018
This commit is contained in:
+19
-15
@@ -184,15 +184,14 @@ func execBlockOnProxyApp(logger log.Logger, proxyAppConn proxy.AppConnConsensus,
|
||||
}
|
||||
proxyAppConn.SetResponseCallback(proxyCb)
|
||||
|
||||
signVals, byzVals := getBeginBlockValidatorInfo(block, lastValSet, stateDB)
|
||||
voteInfos, byzVals := getBeginBlockValidatorInfo(block, lastValSet, stateDB)
|
||||
|
||||
// Begin block.
|
||||
_, err := proxyAppConn.BeginBlockSync(abci.RequestBeginBlock{
|
||||
Hash: block.Hash(),
|
||||
Header: types.TM2PB.Header(&block.Header),
|
||||
LastCommitInfo: abci.LastCommitInfo{
|
||||
CommitRound: int32(block.LastCommit.Round()),
|
||||
Validators: signVals,
|
||||
CommitVotes: voteInfos,
|
||||
},
|
||||
ByzantineValidators: byzVals,
|
||||
})
|
||||
@@ -218,15 +217,15 @@ func execBlockOnProxyApp(logger log.Logger, proxyAppConn proxy.AppConnConsensus,
|
||||
|
||||
logger.Info("Executed block", "height", block.Height, "validTxs", validTxs, "invalidTxs", invalidTxs)
|
||||
|
||||
valUpdates := abciResponses.EndBlock.ValidatorUpdates
|
||||
if len(valUpdates) > 0 {
|
||||
logger.Info("Updates to validators", "updates", abci.ValidatorsString(valUpdates))
|
||||
if len(abciResponses.EndBlock.ValidatorUpdates) > 0 {
|
||||
// TODO: cleanup the formatting
|
||||
logger.Info("Updates to validators", "updates", abciResponses.EndBlock.ValidatorUpdates)
|
||||
}
|
||||
|
||||
return abciResponses, nil
|
||||
}
|
||||
|
||||
func getBeginBlockValidatorInfo(block *types.Block, lastValSet *types.ValidatorSet, stateDB dbm.DB) ([]abci.SigningValidator, []abci.Evidence) {
|
||||
func getBeginBlockValidatorInfo(block *types.Block, lastValSet *types.ValidatorSet, stateDB dbm.DB) ([]abci.VoteInfo, []abci.Evidence) {
|
||||
|
||||
// Sanity check that commit length matches validator set size -
|
||||
// only applies after first block
|
||||
@@ -241,17 +240,22 @@ func getBeginBlockValidatorInfo(block *types.Block, lastValSet *types.ValidatorS
|
||||
}
|
||||
|
||||
// determine which validators did not sign last block.
|
||||
signVals := make([]abci.SigningValidator, len(lastValSet.Validators))
|
||||
voteInfos := make([]abci.VoteInfo, len(lastValSet.Validators))
|
||||
for i, val := range lastValSet.Validators {
|
||||
var vote *types.Vote
|
||||
var commitRound = -1
|
||||
if i < len(block.LastCommit.Precommits) {
|
||||
vote = block.LastCommit.Precommits[i]
|
||||
if vote != nil {
|
||||
commitRound = vote.Round
|
||||
}
|
||||
}
|
||||
val := abci.SigningValidator{
|
||||
Validator: types.TM2PB.ValidatorWithoutPubKey(val),
|
||||
SignedLastBlock: vote != nil,
|
||||
voteInfo := abci.VoteInfo{
|
||||
Validator: types.TM2PB.Validator(val),
|
||||
SignedLastBlock: vote != nil, // XXX: should we replace with commitRound == -1 ?
|
||||
CommitRound: int64(commitRound), //XXX: why is round an int?
|
||||
}
|
||||
signVals[i] = val
|
||||
voteInfos[i] = voteInfo
|
||||
}
|
||||
|
||||
byzVals := make([]abci.Evidence, len(block.Evidence.Evidence))
|
||||
@@ -266,15 +270,15 @@ func getBeginBlockValidatorInfo(block *types.Block, lastValSet *types.ValidatorS
|
||||
byzVals[i] = types.TM2PB.Evidence(ev, valset, block.Time)
|
||||
}
|
||||
|
||||
return signVals, byzVals
|
||||
return voteInfos, byzVals
|
||||
|
||||
}
|
||||
|
||||
// If more or equal than 1/3 of total voting power changed in one block, then
|
||||
// a light client could never prove the transition externally. See
|
||||
// ./lite/doc.go for details on how a light client tracks validators.
|
||||
func updateValidators(currentSet *types.ValidatorSet, abciUpdates []abci.Validator) error {
|
||||
updates, err := types.PB2TM.Validators(abciUpdates)
|
||||
func updateValidators(currentSet *types.ValidatorSet, abciUpdates []abci.ValidatorUpdate) error {
|
||||
updates, err := types.PB2TM.ValidatorUpdates(abciUpdates)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ func TestBeginBlockValidators(t *testing.T) {
|
||||
|
||||
// -> app receives a list of validators with a bool indicating if they signed
|
||||
ctr := 0
|
||||
for i, v := range app.Validators {
|
||||
for i, v := range app.CommitVotes {
|
||||
if ctr < len(tc.expectedAbsentValidators) &&
|
||||
tc.expectedAbsentValidators[ctr] == i {
|
||||
|
||||
@@ -160,7 +160,7 @@ func TestUpdateValidators(t *testing.T) {
|
||||
name string
|
||||
|
||||
currentSet *types.ValidatorSet
|
||||
abciUpdates []abci.Validator
|
||||
abciUpdates []abci.ValidatorUpdate
|
||||
|
||||
resultingSet *types.ValidatorSet
|
||||
shouldErr bool
|
||||
@@ -169,7 +169,7 @@ func TestUpdateValidators(t *testing.T) {
|
||||
"adding a validator is OK",
|
||||
|
||||
types.NewValidatorSet([]*types.Validator{val1}),
|
||||
[]abci.Validator{{Address: []byte{}, PubKey: types.TM2PB.PubKey(pubkey2), Power: 20}},
|
||||
[]abci.ValidatorUpdate{{PubKey: types.TM2PB.PubKey(pubkey2), Power: 20}},
|
||||
|
||||
types.NewValidatorSet([]*types.Validator{val1, val2}),
|
||||
false,
|
||||
@@ -178,7 +178,7 @@ func TestUpdateValidators(t *testing.T) {
|
||||
"updating a validator is OK",
|
||||
|
||||
types.NewValidatorSet([]*types.Validator{val1}),
|
||||
[]abci.Validator{{Address: []byte{}, PubKey: types.TM2PB.PubKey(pubkey1), Power: 20}},
|
||||
[]abci.ValidatorUpdate{{PubKey: types.TM2PB.PubKey(pubkey1), Power: 20}},
|
||||
|
||||
types.NewValidatorSet([]*types.Validator{types.NewValidator(pubkey1, 20)}),
|
||||
false,
|
||||
@@ -187,7 +187,7 @@ func TestUpdateValidators(t *testing.T) {
|
||||
"removing a validator is OK",
|
||||
|
||||
types.NewValidatorSet([]*types.Validator{val1, val2}),
|
||||
[]abci.Validator{{Address: []byte{}, PubKey: types.TM2PB.PubKey(pubkey2), Power: 0}},
|
||||
[]abci.ValidatorUpdate{{PubKey: types.TM2PB.PubKey(pubkey2), Power: 0}},
|
||||
|
||||
types.NewValidatorSet([]*types.Validator{val1}),
|
||||
false,
|
||||
@@ -197,7 +197,7 @@ func TestUpdateValidators(t *testing.T) {
|
||||
"removing a non-existing validator results in error",
|
||||
|
||||
types.NewValidatorSet([]*types.Validator{val1}),
|
||||
[]abci.Validator{{Address: []byte{}, PubKey: types.TM2PB.PubKey(pubkey2), Power: 0}},
|
||||
[]abci.ValidatorUpdate{{PubKey: types.TM2PB.PubKey(pubkey2), Power: 0}},
|
||||
|
||||
types.NewValidatorSet([]*types.Validator{val1}),
|
||||
true,
|
||||
@@ -207,7 +207,7 @@ func TestUpdateValidators(t *testing.T) {
|
||||
"adding a validator with negative power results in error",
|
||||
|
||||
types.NewValidatorSet([]*types.Validator{val1}),
|
||||
[]abci.Validator{{Address: []byte{}, PubKey: types.TM2PB.PubKey(pubkey2), Power: -100}},
|
||||
[]abci.ValidatorUpdate{{PubKey: types.TM2PB.PubKey(pubkey2), Power: -100}},
|
||||
|
||||
types.NewValidatorSet([]*types.Validator{val1}),
|
||||
true,
|
||||
@@ -335,7 +335,7 @@ func makeBlock(state State, height int64) *types.Block {
|
||||
type testApp struct {
|
||||
abci.BaseApplication
|
||||
|
||||
Validators []abci.SigningValidator
|
||||
CommitVotes []abci.VoteInfo
|
||||
ByzantineValidators []abci.Evidence
|
||||
ValidatorUpdates []abci.Validator
|
||||
}
|
||||
@@ -347,7 +347,7 @@ func (app *testApp) Info(req abci.RequestInfo) (resInfo abci.ResponseInfo) {
|
||||
}
|
||||
|
||||
func (app *testApp) BeginBlock(req abci.RequestBeginBlock) abci.ResponseBeginBlock {
|
||||
app.Validators = req.LastCommitInfo.Validators
|
||||
app.CommitVotes = req.LastCommitInfo.CommitVotes
|
||||
app.ByzantineValidators = req.ByzantineValidators
|
||||
return abci.ResponseBeginBlock{}
|
||||
}
|
||||
|
||||
+7
-7
@@ -78,8 +78,8 @@ func TestABCIResponsesSaveLoad1(t *testing.T) {
|
||||
abciResponses := NewABCIResponses(block)
|
||||
abciResponses.DeliverTx[0] = &abci.ResponseDeliverTx{Data: []byte("foo"), Tags: nil}
|
||||
abciResponses.DeliverTx[1] = &abci.ResponseDeliverTx{Data: []byte("bar"), Log: "ok", Tags: nil}
|
||||
abciResponses.EndBlock = &abci.ResponseEndBlock{ValidatorUpdates: []abci.Validator{
|
||||
types.TM2PB.ValidatorFromPubKeyAndPower(ed25519.GenPrivKey().PubKey(), 10),
|
||||
abciResponses.EndBlock = &abci.ResponseEndBlock{ValidatorUpdates: []abci.ValidatorUpdate{
|
||||
types.TM2PB.NewValidatorUpdate(ed25519.GenPrivKey().PubKey(), 10),
|
||||
}}
|
||||
|
||||
saveABCIResponses(stateDB, block.Height, abciResponses)
|
||||
@@ -454,9 +454,9 @@ func makeHeaderPartsResponsesValPubKeyChange(state State, height int64,
|
||||
_, val := state.NextValidators.GetByIndex(0)
|
||||
if !bytes.Equal(pubkey.Bytes(), val.PubKey.Bytes()) {
|
||||
abciResponses.EndBlock = &abci.ResponseEndBlock{
|
||||
ValidatorUpdates: []abci.Validator{
|
||||
types.TM2PB.ValidatorFromPubKeyAndPower(val.PubKey, 0),
|
||||
types.TM2PB.ValidatorFromPubKeyAndPower(pubkey, 10),
|
||||
ValidatorUpdates: []abci.ValidatorUpdate{
|
||||
types.TM2PB.NewValidatorUpdate(val.PubKey, 0),
|
||||
types.TM2PB.NewValidatorUpdate(pubkey, 10),
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -476,8 +476,8 @@ func makeHeaderPartsResponsesValPowerChange(state State, height int64,
|
||||
_, val := state.NextValidators.GetByIndex(0)
|
||||
if val.VotingPower != power {
|
||||
abciResponses.EndBlock = &abci.ResponseEndBlock{
|
||||
ValidatorUpdates: []abci.Validator{
|
||||
types.TM2PB.ValidatorFromPubKeyAndPower(val.PubKey, power),
|
||||
ValidatorUpdates: []abci.ValidatorUpdate{
|
||||
types.TM2PB.NewValidatorUpdate(val.PubKey, power),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user