More TM 0.24 updates

This commit is contained in:
Christopher Goes 2018-09-03 18:04:28 +02:00
parent 73292e08b4
commit 14d5e686d9
11 changed files with 40 additions and 24 deletions

View File

@ -420,7 +420,7 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg
// set the signed validators for addition to context in deliverTx
// TODO: communicate this result to the address to pubkey map in slashing
app.signedValidators = req.LastCommitInfo.GetValidators()
app.voteInfos = req.LastCommitInfo.GetVotes()
return
}

View File

@ -10,6 +10,7 @@ import (
tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/node"
"github.com/tendermint/tendermint/p2p"
pvm "github.com/tendermint/tendermint/privval"
"github.com/tendermint/tendermint/proxy"
)
@ -94,10 +95,16 @@ func startInProcess(ctx *Context, appCreator AppCreator) (*node.Node, error) {
return nil, err
}
nodeKey, err := p2p.LoadOrGenNodeKey(cfg.NodeKeyFile())
if err != nil {
return nil, err
}
// create & start tendermint node
tmNode, err := node.NewNode(
cfg,
pvm.LoadOrGenFilePV(cfg.PrivValidatorFile()),
nodeKey,
proxy.NewLocalClientCreator(app),
node.DefaultGenesisDocProviderFunc(cfg),
node.DefaultDBProvider,

View File

@ -14,7 +14,7 @@ func First(st KVStore, start, end []byte) (kv cmn.KVPair, ok bool) {
}
defer iter.Close()
return cmn.KVPair{iter.Key(), iter.Value()}, true
return cmn.KVPair{Key: iter.Key(), Value: iter.Value()}, true
}
// Gets the last item. `end` is exclusive.
@ -22,7 +22,7 @@ func Last(st KVStore, start, end []byte) (kv cmn.KVPair, ok bool) {
iter := st.ReverseIterator(end, start)
if !iter.Valid() {
if v := st.Get(start); v != nil {
return cmn.KVPair{cp(start), cp(v)}, true
return cmn.KVPair{Key: cp(start), Value: cp(v)}, true
}
return kv, false
}
@ -36,5 +36,5 @@ func Last(st KVStore, start, end []byte) (kv cmn.KVPair, ok bool) {
}
}
return cmn.KVPair{iter.Key(), iter.Value()}, true
return cmn.KVPair{Key: iter.Key(), Value: iter.Value()}, true
}

View File

@ -239,7 +239,7 @@ func (st *iavlStore) Query(req abci.RequestQuery) (res abci.ResponseQuery) {
var KVs []KVPair
iterator := sdk.KVStorePrefixIterator(st, subspace)
for ; iterator.Valid(); iterator.Next() {
KVs = append(KVs, KVPair{iterator.Key(), iterator.Value()})
KVs = append(KVs, KVPair{Key: iterator.Key(), Value: iterator.Value()})
}
iterator.Close()
res.Value = cdc.MustMarshalBinary(KVs)
@ -309,7 +309,7 @@ func (iter *iavlIterator) iterateRoutine() {
select {
case <-iter.quitCh:
return true // done with iteration.
case iter.iterCh <- cmn.KVPair{key, value}:
case iter.iterCh <- cmn.KVPair{Key: key, Value: value}:
return false // yay.
}
},

View File

@ -3,6 +3,7 @@ package types
import (
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto"
tmtypes "github.com/tendermint/tendermint/types"
)
// status of a validator
@ -55,6 +56,14 @@ func ABCIValidator(v Validator) abci.Validator {
}
}
// validator which fulfills abci validator update interface for use in Tendermint
func ABCIValidatorUpdate(v Validator) abci.ValidatorUpdate {
return abci.ValidatorUpdate{
PubKey: tmtypes.TM2PB.PubKey(v.GetPubKey()),
Power: v.GetPower().RoundInt64(),
}
}
// properties for the set of all validators
type ValidatorSet interface {
// iterate through validator by owner-AccAddress, execute func for each validator

View File

@ -138,7 +138,7 @@ func (k Keeper) handleValidatorSignature(ctx sdk.Context, addr crypto.Address, p
}
// AddValidators adds the validators to the keepers validator addr to pubkey mapping.
func (k Keeper) AddValidators(ctx sdk.Context, vals []abci.Validator) {
func (k Keeper) AddValidators(ctx sdk.Context, vals []abci.ValidatorUpdate) {
for i := 0; i < len(vals); i++ {
val := vals[i]
pubkey, err := tmtypes.PB2TM.PubKey(val.PubKey)

View File

@ -20,7 +20,7 @@ func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, sk Keeper) (tags
// Iterate over all the validators which *should* have signed this block
// Store whether or not they have actually signed it and slash/unbond any
// which have missed too many blocks in a row (downtime slashing)
for _, voteInfo := range req.LastCommitInfo.GetVoteInfos() {
for _, voteInfo := range req.LastCommitInfo.GetVotes() {
sk.handleValidatorSignature(ctx, voteInfo.Validator.Address, voteInfo.Validator.Power, voteInfo.SignedLastBlock)
}

View File

@ -15,7 +15,7 @@ import (
// addition, it also sets any delegations found in data. Finally, it updates
// the bonded validators.
// Returns final validator set after applying all declaration and delegations
func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState) (res []abci.Validator, err error) {
func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState) (res []abci.ValidatorUpdate, err error) {
keeper.SetPool(ctx, data.Pool)
keeper.SetNewParams(ctx, data.Params)
keeper.InitIntraTxCounter(ctx)
@ -47,9 +47,9 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState) (res [
keeper.UpdateBondedValidatorsFull(ctx)
vals := keeper.GetValidatorsBonded(ctx)
res = make([]abci.Validator, len(vals))
res = make([]abci.ValidatorUpdate, len(vals))
for i, val := range vals {
res[i] = sdk.ABCIValidator(val)
res[i] = sdk.ABCIValidatorUpdate(val)
}
return
}

View File

@ -36,7 +36,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
}
// Called every block, process inflation, update validator set
func EndBlocker(ctx sdk.Context, k keeper.Keeper) (ValidatorUpdates []abci.Validator) {
func EndBlocker(ctx sdk.Context, k keeper.Keeper) (ValidatorUpdates []abci.ValidatorUpdate) {
pool := k.GetPool(ctx)
// Process provision inflation

View File

@ -201,13 +201,13 @@ func (k Keeper) GetValidatorsByPower(ctx sdk.Context) []types.Validator {
// Accumulated updates to the active/bonded validator set for tendermint
// get the most recently updated validators
func (k Keeper) GetTendermintUpdates(ctx sdk.Context) (updates []abci.Validator) {
func (k Keeper) GetTendermintUpdates(ctx sdk.Context) (updates []abci.ValidatorUpdate) {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, TendermintUpdatesKey) //smallest to largest
for ; iterator.Valid(); iterator.Next() {
valBytes := iterator.Value()
var val abci.Validator
var val abci.ValidatorUpdate
k.cdc.MustUnmarshalBinary(valBytes, &val)
updates = append(updates, val)
}
@ -256,7 +256,7 @@ func (k Keeper) UpdateValidator(ctx sdk.Context, validator types.Validator) type
case powerIncreasing && !validator.Jailed &&
(oldFound && oldValidator.Status == sdk.Bonded):
bz := k.cdc.MustMarshalBinary(validator.ABCIValidator())
bz := k.cdc.MustMarshalBinary(sdk.ABCIValidatorUpdate(validator))
store.Set(GetTendermintUpdatesKey(validator.Operator), bz)
if cliffPower != nil {
@ -292,7 +292,7 @@ func (k Keeper) UpdateValidator(ctx sdk.Context, validator types.Validator) type
// if decreased in power but still bonded, update Tendermint validator
if oldFound && oldValidator.BondedTokens().GT(validator.BondedTokens()) {
bz := k.cdc.MustMarshalBinary(validator.ABCIValidator())
bz := k.cdc.MustMarshalBinary(sdk.ABCIValidatorUpdate(validator))
store.Set(GetTendermintUpdatesKey(validator.Operator), bz)
}
}
@ -634,7 +634,7 @@ func (k Keeper) beginUnbondingValidator(ctx sdk.Context, validator types.Validat
k.SetValidator(ctx, validator)
// add to accumulated changes for tendermint
bzABCI := k.cdc.MustMarshalBinary(validator.ABCIValidatorZero())
bzABCI := k.cdc.MustMarshalBinary(validator.ABCIValidatorUpdateZero())
store.Set(GetTendermintUpdatesKey(validator.Operator), bzABCI)
// also remove from the Bonded types.Validators Store
@ -669,7 +669,7 @@ func (k Keeper) bondValidator(ctx sdk.Context, validator types.Validator) types.
store.Set(GetValidatorsBondedIndexKey(validator.Operator), []byte{})
// add to accumulated changes for tendermint
bzABCI := k.cdc.MustMarshalBinary(validator.ABCIValidator())
bzABCI := k.cdc.MustMarshalBinary(sdk.ABCIValidatorUpdate(validator))
store.Set(GetTendermintUpdatesKey(validator.Operator), bzABCI)
// call the bond hook if present
@ -704,7 +704,7 @@ func (k Keeper) RemoveValidator(ctx sdk.Context, address sdk.ValAddress) {
}
store.Delete(GetValidatorsBondedIndexKey(validator.Operator))
bz := k.cdc.MustMarshalBinary(validator.ABCIValidatorZero())
bz := k.cdc.MustMarshalBinary(validator.ABCIValidatorUpdateZero())
store.Set(GetTendermintUpdatesKey(address), bz)
}

View File

@ -317,12 +317,12 @@ func (v Validator) ABCIValidator() abci.Validator {
}
}
// ABCIValidatorZero returns an abci.Validator from a staked validator type
// ABCIValidatorUpdateZero returns an abci.ValidatorUpdate from a staked validator type
// with with zero power used for validator updates.
func (v Validator) ABCIValidatorZero() abci.Validator {
return abci.Validator{
Address: v.PubKey.Address(),
Power: 0,
func (v Validator) ABCIValidatorUpdateZero() abci.ValidatorUpdate {
return abci.ValidatorUpdate{
PubKey: tmtypes.TM2PB.PubKey(v.PubKey),
Power: 0,
}
}