Browse Source

Set protocol versions in NodeInfo from state (#2686)

* use types.NewValidator

* node: set p2p.ProtocolVersion from state, not globals
pull/2694/head
Ethan Buchman 6 years ago
committed by GitHub
parent
commit
fe1d59ab7b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 24 additions and 37 deletions
  1. +1
    -1
      benchmarks/codec_test.go
  2. +5
    -1
      node/node.go
  3. +12
    -8
      p2p/node_info.go
  4. +1
    -1
      p2p/peer_test.go
  5. +1
    -1
      p2p/test_util.go
  6. +1
    -10
      state/state.go
  7. +3
    -15
      types/protobuf_test.go

+ 1
- 1
benchmarks/codec_test.go View File

@ -14,7 +14,7 @@ import (
func testNodeInfo(id p2p.ID) p2p.DefaultNodeInfo {
return p2p.DefaultNodeInfo{
ProtocolVersion: p2p.InitProtocolVersion,
ProtocolVersion: p2p.ProtocolVersion{1, 2, 3},
ID_: id,
Moniker: "SOMENAME",
Network: "SOMENAME",


+ 5
- 1
node/node.go View File

@ -367,7 +367,11 @@ func NewNode(config *cfg.Config,
nodeKey.ID(),
txIndexer,
genDoc.ChainID,
p2p.ProtocolVersionWithApp(state.Version.Consensus.App),
p2p.NewProtocolVersion(
version.P2PProtocol, // global
state.Version.Consensus.Block,
state.Version.Consensus.App,
),
)
)


+ 12
- 8
p2p/node_info.go View File

@ -49,16 +49,20 @@ type ProtocolVersion struct {
App version.Protocol `json:"app"`
}
// InitProtocolVersion populates the Block and P2P versions, but not the App.
var InitProtocolVersion = ProtocolVersionWithApp(0)
// defaultProtocolVersion populates the Block and P2P versions using
// the global values, but not the App.
var defaultProtocolVersion = NewProtocolVersion(
version.P2PProtocol,
version.BlockProtocol,
0,
)
// ProtocolVersionWithApp returns a fully populated ProtocolVersion
// using the provided App version and the Block and P2P versions defined in the `version` package.
func ProtocolVersionWithApp(appVersion version.Protocol) ProtocolVersion {
// NewProtocolVersion returns a fully populated ProtocolVersion.
func NewProtocolVersion(p2p, block, app version.Protocol) ProtocolVersion {
return ProtocolVersion{
P2P: version.P2PProtocol,
Block: version.BlockProtocol,
App: appVersion,
P2P: p2p,
Block: block,
App: app,
}
}


+ 1
- 1
p2p/peer_test.go View File

@ -207,7 +207,7 @@ func (rp *remotePeer) accept(l net.Listener) {
func (rp *remotePeer) nodeInfo(l net.Listener) NodeInfo {
return DefaultNodeInfo{
ProtocolVersion: InitProtocolVersion,
ProtocolVersion: defaultProtocolVersion,
ID_: rp.Addr().ID,
ListenAddr: l.Addr().String(),
Network: "testing",


+ 1
- 1
p2p/test_util.go View File

@ -249,7 +249,7 @@ func testNodeInfo(id ID, name string) NodeInfo {
func testNodeInfoWithNetwork(id ID, name, network string) NodeInfo {
return DefaultNodeInfo{
ProtocolVersion: InitProtocolVersion,
ProtocolVersion: defaultProtocolVersion,
ID_: id,
ListenAddr: fmt.Sprintf("127.0.0.1:%d", cmn.RandIntn(64512)+1023),
Network: network,


+ 1
- 10
state/state.go View File

@ -222,7 +222,6 @@ func MakeGenesisState(genDoc *types.GenesisDoc) (State, error) {
return State{}, fmt.Errorf("Error in genesis file: %v", err)
}
// Make validators slice
var validatorSet, nextValidatorSet *types.ValidatorSet
if genDoc.Validators == nil {
validatorSet = types.NewValidatorSet(nil)
@ -230,15 +229,7 @@ func MakeGenesisState(genDoc *types.GenesisDoc) (State, error) {
} else {
validators := make([]*types.Validator, len(genDoc.Validators))
for i, val := range genDoc.Validators {
pubKey := val.PubKey
address := pubKey.Address()
// Make validator
validators[i] = &types.Validator{
Address: address,
PubKey: pubKey,
VotingPower: val.Power,
}
validators[i] = types.NewValidator(val.PubKey, val.Power)
}
validatorSet = types.NewValidatorSet(validators)
nextValidatorSet = types.NewValidatorSet(validators).CopyIncrementAccum(1)


+ 3
- 15
types/protobuf_test.go View File

@ -30,17 +30,9 @@ func TestABCIValidators(t *testing.T) {
pkEd := ed25519.GenPrivKey().PubKey()
// correct validator
tmValExpected := &Validator{
Address: pkEd.Address(),
PubKey: pkEd,
VotingPower: 10,
}
tmValExpected := NewValidator(pkEd, 10)
tmVal := &Validator{
Address: pkEd.Address(),
PubKey: pkEd,
VotingPower: 10,
}
tmVal := NewValidator(pkEd, 10)
abciVal := TM2PB.ValidatorUpdate(tmVal)
tmVals, err := PB2TM.ValidatorUpdates([]abci.ValidatorUpdate{abciVal})
@ -127,11 +119,7 @@ func TestABCIValidatorFromPubKeyAndPower(t *testing.T) {
func TestABCIValidatorWithoutPubKey(t *testing.T) {
pkEd := ed25519.GenPrivKey().PubKey()
abciVal := TM2PB.Validator(&Validator{
Address: pkEd.Address(),
PubKey: pkEd,
VotingPower: 10,
})
abciVal := TM2PB.Validator(NewValidator(pkEd, 10))
// pubkey must be nil
tmValExpected := abci.Validator{


Loading…
Cancel
Save