Browse Source

update for abci v0.11.0 release. let InitChain update validators

pull/1701/head
Ethan Buchman 6 years ago
parent
commit
8e45348737
7 changed files with 105 additions and 12 deletions
  1. +14
    -2
      CHANGELOG.md
  2. +4
    -4
      Gopkg.lock
  3. +1
    -1
      Gopkg.toml
  4. +16
    -2
      consensus/replay.go
  5. +51
    -0
      consensus/replay_test.go
  6. +16
    -0
      types/protobuf.go
  7. +3
    -3
      version/version.go

+ 14
- 2
CHANGELOG.md View File

@ -1,8 +1,20 @@
# Changelog
## 0.19.10
## 0.20.0
*June 6th, 2018*
BREAKING CHANGES
- [abci] Upgrade to
[v0.11.0](https://github.com/tendermint/abci/blob/master/CHANGELOG.md#0110)
NOTE: this release does not break any blockchain data structures or
protocols other than the ABCI messages between Tendermint and the application.
Applications that upgrade for ABCI v0.11.0 should be able to continue running Tendermint
v0.20.0 on blockchains created with v0.19.X
*TBD*
## 0.19.9


+ 4
- 4
Gopkg.lock View File

@ -238,8 +238,8 @@
"server",
"types"
]
revision = "7cf66f570e2f47b286985e2d688b0a400c028e4c"
version = "v0.11.0-rc6"
revision = "ebee2fe114020aa49c70bbbae50b7079fc7e7b90"
version = "v0.11.0"
[[projects]]
branch = "master"
@ -313,7 +313,7 @@
branch = "master"
name = "golang.org/x/sys"
packages = ["unix"]
revision = "c11f84a56e43e20a78cee75a7c034031ecf57d1f"
revision = "9527bec2660bd847c050fda93a0f0c6dee0800bb"
[[projects]]
name = "golang.org/x/text"
@ -374,6 +374,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "132980da98fc92b6c0dd988df07316a340f5fc91ee77593cf984ade4e3e5fd62"
inputs-digest = "ae6792578b0664708339f4c05e020687d6b799ad6f8282394b919de69e403d1f"
solver-name = "gps-cdcl"
solver-version = 1

+ 1
- 1
Gopkg.toml View File

@ -71,7 +71,7 @@
[[constraint]]
name = "github.com/tendermint/abci"
version = "~0.11.0-rc6"
version = "~0.11.0"
[[constraint]]
name = "github.com/tendermint/go-crypto"


+ 16
- 2
consensus/replay.go View File

@ -267,17 +267,31 @@ func (h *Handshaker) ReplayBlocks(state sm.State, appHash []byte, appBlockHeight
// If appBlockHeight == 0 it means that we are at genesis and hence should send InitChain
if appBlockHeight == 0 {
validators := types.TM2PB.Validators(state.Validators)
csParams := types.TM2PB.ConsensusParams(h.genDoc.ConsensusParams)
req := abci.RequestInitChain{
Time: h.genDoc.GenesisTime.Unix(), // TODO
ChainId: h.genDoc.ChainID,
ConsensusParams: types.TM2PB.ConsensusParams(h.genDoc.ConsensusParams),
ConsensusParams: csParams,
Validators: validators,
AppStateBytes: h.genDoc.AppStateJSON,
}
_, err := proxyApp.Consensus().InitChainSync(req)
res, err := proxyApp.Consensus().InitChainSync(req)
if err != nil {
return nil, err
}
// update the state
if len(res.Validators) > 0 {
vals, err := types.PB2TM.Validators(res.Validators)
if err != nil {
return nil, err
}
state.Validators = types.NewValidatorSet(vals)
}
if res.ConsensusParams != nil {
// TODO
}
sm.SaveState(h.stateDB, state)
}
// First handle edge cases and constraints on the storeBlockHeight


+ 51
- 0
consensus/replay_test.go View File

@ -13,6 +13,7 @@ import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/abci/example/kvstore"
@ -634,3 +635,53 @@ func (bs *mockBlockStore) LoadBlockCommit(height int64) *types.Commit {
func (bs *mockBlockStore) LoadSeenCommit(height int64) *types.Commit {
return bs.commits[height-1]
}
//----------------------------------------
func TestInitChainUpdateValidators(t *testing.T) {
val, _ := types.RandValidator(true, 10)
vals := types.NewValidatorSet([]*types.Validator{val})
app := &initChainApp{vals: types.TM2PB.Validators(vals)}
clientCreator := proxy.NewLocalClientCreator(app)
config := ResetConfig("proxy_test_")
privVal := privval.LoadFilePV(config.PrivValidatorFile())
stateDB, state, store := stateAndStore(config, privVal.GetPubKey())
oldValAddr := state.Validators.Validators[0].Address
// now start the app using the handshake - it should sync
genDoc, _ := sm.MakeGenesisDocFromFile(config.GenesisFile())
handshaker := NewHandshaker(stateDB, state, store, genDoc)
proxyApp := proxy.NewAppConns(clientCreator, handshaker)
if err := proxyApp.Start(); err != nil {
t.Fatalf("Error starting proxy app connections: %v", err)
}
defer proxyApp.Stop()
// reload the state, check the validator set was updated
state = sm.LoadState(stateDB)
newValAddr := state.Validators.Validators[0].Address
expectValAddr := val.Address
assert.NotEqual(t, oldValAddr, newValAddr)
assert.Equal(t, newValAddr, expectValAddr)
}
func newInitChainApp(vals []abci.Validator) *initChainApp {
return &initChainApp{
vals: vals,
}
}
// returns the vals on InitChain
type initChainApp struct {
abci.BaseApplication
vals []abci.Validator
}
func (ica *initChainApp) InitChain(req abci.RequestInitChain) abci.ResponseInitChain {
return abci.ResponseInitChain{
Validators: ica.vals,
}
}

+ 16
- 0
types/protobuf.go View File

@ -167,3 +167,19 @@ func (pb2tm) PubKey(pubKey abci.PubKey) (crypto.PubKey, error) {
return nil, fmt.Errorf("Unknown pubkey type %v", pubKey.Type)
}
}
func (pb2tm) Validators(vals []abci.Validator) ([]*Validator, error) {
tmVals := make([]*Validator, len(vals))
for i, v := range vals {
pub, err := PB2TM.PubKey(v.PubKey)
if err != nil {
return nil, err
}
tmVals[i] = &Validator{
Address: v.Address,
PubKey: pub,
VotingPower: v.Power,
}
}
return tmVals, nil
}

+ 3
- 3
version/version.go View File

@ -3,14 +3,14 @@ package version
// Version components
const (
Maj = "0"
Min = "19"
Fix = "10"
Min = "20"
Fix = "0"
)
var (
// Version is the current version of Tendermint
// Must be a string because scripts like dist.sh read this file.
Version = "0.19.10-dev"
Version = "0.20.0-dev"
// GitCommit is the current HEAD set using ldflags.
GitCommit string


Loading…
Cancel
Save