mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 06:42:16 +00:00
parent
4fe9906361
commit
38bced2440
@ -20,5 +20,6 @@ FEATURES:
|
|||||||
* \#2310 Mempool is now aware of the MaxGas requirement
|
* \#2310 Mempool is now aware of the MaxGas requirement
|
||||||
|
|
||||||
IMPROVEMENTS:
|
IMPROVEMENTS:
|
||||||
|
- [types] add Address to GenesisValidator [\#1714](https://github.com/tendermint/tendermint/issues/1714)
|
||||||
|
|
||||||
BUG FIXES:
|
BUG FIXES:
|
||||||
|
@ -58,6 +58,7 @@ func initFilesWithConfig(config *cfg.Config) error {
|
|||||||
ConsensusParams: types.DefaultConsensusParams(),
|
ConsensusParams: types.DefaultConsensusParams(),
|
||||||
}
|
}
|
||||||
genDoc.Validators = []types.GenesisValidator{{
|
genDoc.Validators = []types.GenesisValidator{{
|
||||||
|
Address: pv.GetPubKey().Address(),
|
||||||
PubKey: pv.GetPubKey(),
|
PubKey: pv.GetPubKey(),
|
||||||
Power: 10,
|
Power: 10,
|
||||||
}}
|
}}
|
||||||
|
@ -91,6 +91,7 @@ func testnetFiles(cmd *cobra.Command, args []string) error {
|
|||||||
pvFile := filepath.Join(nodeDir, config.BaseConfig.PrivValidator)
|
pvFile := filepath.Join(nodeDir, config.BaseConfig.PrivValidator)
|
||||||
pv := privval.LoadFilePV(pvFile)
|
pv := privval.LoadFilePV(pvFile)
|
||||||
genVals[i] = types.GenesisValidator{
|
genVals[i] = types.GenesisValidator{
|
||||||
|
Address: pv.GetPubKey().Address(),
|
||||||
PubKey: pv.GetPubKey(),
|
PubKey: pv.GetPubKey(),
|
||||||
Power: 1,
|
Power: 1,
|
||||||
Name: nodeDirName,
|
Name: nodeDirName,
|
||||||
|
@ -307,7 +307,10 @@ func state(nVals, height int) (State, dbm.DB) {
|
|||||||
secret := []byte(fmt.Sprintf("test%d", i))
|
secret := []byte(fmt.Sprintf("test%d", i))
|
||||||
pk := ed25519.GenPrivKeyFromSecret(secret)
|
pk := ed25519.GenPrivKeyFromSecret(secret)
|
||||||
vals[i] = types.GenesisValidator{
|
vals[i] = types.GenesisValidator{
|
||||||
pk.PubKey(), 1000, fmt.Sprintf("test%d", i),
|
pk.PubKey().Address(),
|
||||||
|
pk.PubKey(),
|
||||||
|
1000,
|
||||||
|
fmt.Sprintf("test%d", i),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s, _ := MakeGenesisState(&types.GenesisDoc{
|
s, _ := MakeGenesisState(&types.GenesisDoc{
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -21,6 +22,7 @@ const (
|
|||||||
|
|
||||||
// GenesisValidator is an initial validator.
|
// GenesisValidator is an initial validator.
|
||||||
type GenesisValidator struct {
|
type GenesisValidator struct {
|
||||||
|
Address Address `json:"address"`
|
||||||
PubKey crypto.PubKey `json:"pub_key"`
|
PubKey crypto.PubKey `json:"pub_key"`
|
||||||
Power int64 `json:"power"`
|
Power int64 `json:"power"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
@ -62,7 +64,7 @@ func (genDoc *GenesisDoc) ValidateAndComplete() error {
|
|||||||
return cmn.NewError("Genesis doc must include non-empty chain_id")
|
return cmn.NewError("Genesis doc must include non-empty chain_id")
|
||||||
}
|
}
|
||||||
if len(genDoc.ChainID) > MaxChainIDLen {
|
if len(genDoc.ChainID) > MaxChainIDLen {
|
||||||
return cmn.NewError(fmt.Sprintf("chain_id in genesis doc is too long (max: %d)", MaxChainIDLen))
|
return cmn.NewError("chain_id in genesis doc is too long (max: %d)", MaxChainIDLen)
|
||||||
}
|
}
|
||||||
|
|
||||||
if genDoc.ConsensusParams == nil {
|
if genDoc.ConsensusParams == nil {
|
||||||
@ -73,10 +75,16 @@ func (genDoc *GenesisDoc) ValidateAndComplete() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range genDoc.Validators {
|
for i, v := range genDoc.Validators {
|
||||||
if v.Power == 0 {
|
if v.Power == 0 {
|
||||||
return cmn.NewError("The genesis file cannot contain validators with no voting power: %v", v)
|
return cmn.NewError("The genesis file cannot contain validators with no voting power: %v", v)
|
||||||
}
|
}
|
||||||
|
if len(v.Address) > 0 && !bytes.Equal(v.PubKey.Address(), v.Address) {
|
||||||
|
return cmn.NewError("Incorrect address for validator %v in the genesis file, should be %v", v, v.PubKey.Address())
|
||||||
|
}
|
||||||
|
if len(v.Address) == 0 {
|
||||||
|
genDoc.Validators[i].Address = v.PubKey.Address()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if genDoc.GenesisTime.IsZero() {
|
if genDoc.GenesisTime.IsZero() {
|
||||||
|
@ -22,6 +22,10 @@ func TestGenesisBad(t *testing.T) {
|
|||||||
[]byte(`{"validators":[{"pub_key":{"value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="},"power":"10","name":""}]}`),
|
[]byte(`{"validators":[{"pub_key":{"value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="},"power":"10","name":""}]}`),
|
||||||
// missing chain_id
|
// missing chain_id
|
||||||
[]byte(`{"validators":[{"pub_key":{"type":"tendermint/PubKeyEd25519","value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="},"power":"10","name":""}]}`),
|
[]byte(`{"validators":[{"pub_key":{"type":"tendermint/PubKeyEd25519","value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="},"power":"10","name":""}]}`),
|
||||||
|
// too big chain_id
|
||||||
|
[]byte(`{"chain_id": "Lorem ipsum dolor sit amet, consectetuer adipiscing", "validators": [{"pub_key":{"type":"tendermint/PubKeyEd25519","value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="},"power":"10","name":""}]}`),
|
||||||
|
// wrong address
|
||||||
|
[]byte(`{"chain_id":"mychain", "validators":[{"address": "A", "pub_key":{"type":"tendermint/PubKeyEd25519","value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="},"power":"10","name":""}]}`),
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
@ -36,10 +40,11 @@ func TestGenesisGood(t *testing.T) {
|
|||||||
_, err := GenesisDocFromJSON(genDocBytes)
|
_, err := GenesisDocFromJSON(genDocBytes)
|
||||||
assert.NoError(t, err, "expected no error for good genDoc json")
|
assert.NoError(t, err, "expected no error for good genDoc json")
|
||||||
|
|
||||||
|
pubkey := ed25519.GenPrivKey().PubKey()
|
||||||
// create a base gendoc from struct
|
// create a base gendoc from struct
|
||||||
baseGenDoc := &GenesisDoc{
|
baseGenDoc := &GenesisDoc{
|
||||||
ChainID: "abc",
|
ChainID: "abc",
|
||||||
Validators: []GenesisValidator{{ed25519.GenPrivKey().PubKey(), 10, "myval"}},
|
Validators: []GenesisValidator{{pubkey.Address(), pubkey, 10, "myval"}},
|
||||||
}
|
}
|
||||||
genDocBytes, err = cdc.MarshalJSON(baseGenDoc)
|
genDocBytes, err = cdc.MarshalJSON(baseGenDoc)
|
||||||
assert.NoError(t, err, "error marshalling genDoc")
|
assert.NoError(t, err, "error marshalling genDoc")
|
||||||
@ -49,6 +54,9 @@ func TestGenesisGood(t *testing.T) {
|
|||||||
assert.NoError(t, err, "expected no error for valid genDoc json")
|
assert.NoError(t, err, "expected no error for valid genDoc json")
|
||||||
assert.NotNil(t, genDoc.ConsensusParams, "expected consensus params to be filled in")
|
assert.NotNil(t, genDoc.ConsensusParams, "expected consensus params to be filled in")
|
||||||
|
|
||||||
|
// check validator's address is filled
|
||||||
|
assert.NotNil(t, genDoc.Validators[0].Address, "expected validator's address to be filled in")
|
||||||
|
|
||||||
// create json with consensus params filled
|
// create json with consensus params filled
|
||||||
genDocBytes, err = cdc.MarshalJSON(genDoc)
|
genDocBytes, err = cdc.MarshalJSON(genDoc)
|
||||||
assert.NoError(t, err, "error marshalling genDoc")
|
assert.NoError(t, err, "error marshalling genDoc")
|
||||||
@ -109,10 +117,11 @@ func TestGenesisValidatorHash(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func randomGenesisDoc() *GenesisDoc {
|
func randomGenesisDoc() *GenesisDoc {
|
||||||
|
pubkey := ed25519.GenPrivKey().PubKey()
|
||||||
return &GenesisDoc{
|
return &GenesisDoc{
|
||||||
GenesisTime: tmtime.Now(),
|
GenesisTime: tmtime.Now(),
|
||||||
ChainID: "abc",
|
ChainID: "abc",
|
||||||
Validators: []GenesisValidator{{ed25519.GenPrivKey().PubKey(), 10, "myval"}},
|
Validators: []GenesisValidator{{pubkey.Address(), pubkey, 10, "myval"}},
|
||||||
ConsensusParams: DefaultConsensusParams(),
|
ConsensusParams: DefaultConsensusParams(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user