From 3089bbf2b8c011d04e2c5a53d3444d3fbc46e6f2 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Thu, 21 Sep 2017 14:37:34 -0400 Subject: [PATCH] Amount -> Power. Closes #166 --- cmd/tendermint/commands/init.go | 2 +- cmd/tendermint/commands/testnet.go | 4 ++-- config/toml.go | 2 +- consensus/common_test.go | 2 +- docs/specification/genesis.rst | 10 +++++----- docs/using-tendermint.rst | 6 +++--- rpc/client/rpc_test.go | 2 +- rpc/core/net.go | 2 +- state/state.go | 2 +- test/p2p/data/mach1/core/genesis.json | 8 ++++---- test/p2p/data/mach2/core/genesis.json | 8 ++++---- test/p2p/data/mach3/core/genesis.json | 8 ++++---- test/p2p/data/mach4/core/genesis.json | 8 ++++---- types/genesis.go | 10 ++++++++-- types/genesis_test.go | 4 ++-- 15 files changed, 42 insertions(+), 36 deletions(-) diff --git a/cmd/tendermint/commands/init.go b/cmd/tendermint/commands/init.go index cd16707cc..ce900defa 100644 --- a/cmd/tendermint/commands/init.go +++ b/cmd/tendermint/commands/init.go @@ -34,7 +34,7 @@ func initFiles(cmd *cobra.Command, args []string) { } genDoc.Validators = []types.GenesisValidator{types.GenesisValidator{ PubKey: privValidator.PubKey, - Amount: 10, + Power: 10, }} genDoc.SaveAs(genFile) diff --git a/cmd/tendermint/commands/testnet.go b/cmd/tendermint/commands/testnet.go index 58767eb05..315f3b498 100644 --- a/cmd/tendermint/commands/testnet.go +++ b/cmd/tendermint/commands/testnet.go @@ -7,8 +7,8 @@ import ( "github.com/spf13/cobra" - cmn "github.com/tendermint/tmlibs/common" "github.com/tendermint/tendermint/types" + cmn "github.com/tendermint/tmlibs/common" ) var testnetFilesCmd = &cobra.Command{ @@ -48,7 +48,7 @@ func testnetFiles(cmd *cobra.Command, args []string) { privVal := types.LoadPrivValidator(privValFile) genVals[i] = types.GenesisValidator{ PubKey: privVal.PubKey, - Amount: 1, + Power: 1, Name: mach, } } diff --git a/config/toml.go b/config/toml.go index 999a05946..5dcbe5332 100644 --- a/config/toml.go +++ b/config/toml.go @@ -119,7 +119,7 @@ var testGenesis = `{ "type": "ed25519", "data":"3B3069C422E19688B45CBFAE7BB009FC0FA1B1EA86593519318B7214853803C8" }, - "amount": 10, + "power": 10, "name": "" } ], diff --git a/consensus/common_test.go b/consensus/common_test.go index 84f47d021..6a05b74e3 100644 --- a/consensus/common_test.go +++ b/consensus/common_test.go @@ -400,7 +400,7 @@ func randGenesisDoc(numValidators int, randPower bool, minPower int64) (*types.G val, privVal := types.RandValidator(randPower, minPower) validators[i] = types.GenesisValidator{ PubKey: val.PubKey, - Amount: val.VotingPower, + Power: val.VotingPower, } privValidators[i] = privVal } diff --git a/docs/specification/genesis.rst b/docs/specification/genesis.rst index 32dd19632..2187eb572 100644 --- a/docs/specification/genesis.rst +++ b/docs/specification/genesis.rst @@ -21,7 +21,7 @@ Fields - ``validators``: - ``pub_key``: The first element specifies the pub\_key type. 1 == Ed25519. The second element are the pubkey bytes. -- ``amount``: The validator's voting power. +- ``power``: The validator's voting power. - ``name``: Name of the validator (optional). - ``app_hash``: The expected application hash (as returned by the ``Commit`` ABCI message) upon genesis. If the app's hash does not @@ -41,7 +41,7 @@ Sample genesis.json 1, "9BC5112CB9614D91CE423FA8744885126CD9D08D9FC9D1F42E552D662BAA411E" ], - "amount": 1, + "power": 1, "name": "mach1" }, { @@ -49,7 +49,7 @@ Sample genesis.json 1, "F46A5543D51F31660D9F59653B4F96061A740FF7433E0DC1ECBC30BE8494DE06" ], - "amount": 1, + "power": 1, "name": "mach2" }, { @@ -57,7 +57,7 @@ Sample genesis.json 1, "0E7B423C1635FD07C0FC3603B736D5D27953C1C6CA865BB9392CD79DE1A682BB" ], - "amount": 1, + "power": 1, "name": "mach3" }, { @@ -65,7 +65,7 @@ Sample genesis.json 1, "4F49237B9A32EB50682EDD83C48CE9CDB1D02A7CFDADCFF6EC8C1FAADB358879" ], - "amount": 1, + "power": 1, "name": "mach4" } ], diff --git a/docs/using-tendermint.rst b/docs/using-tendermint.rst index fb9882f6b..1cb3ad86e 100644 --- a/docs/using-tendermint.rst +++ b/docs/using-tendermint.rst @@ -177,7 +177,7 @@ When ``tendermint init`` is run, both a ``genesis.json`` and "genesis_time": "0001-01-01T00:00:00.000Z", "validators": [ { - "amount": 10, + "power": 10, "name": "", "pub_key": [ 1, @@ -310,7 +310,7 @@ then the new ``genesis.json`` will be: "genesis_time": "0001-01-01T00:00:00.000Z", "validators": [ { - "amount": 10, + "power": 10, "name": "", "pub_key": [ 1, @@ -318,7 +318,7 @@ then the new ``genesis.json`` will be: ] }, { - "amount": 10, + "power": 10, "name": "", "pub_key": [ 1, diff --git a/rpc/client/rpc_test.go b/rpc/client/rpc_test.go index fee92b4a9..33cd4b432 100644 --- a/rpc/client/rpc_test.go +++ b/rpc/client/rpc_test.go @@ -93,7 +93,7 @@ func TestGenesisAndValidators(t *testing.T) { val := vals.Validators[0] // make sure the current set is also the genesis set - assert.Equal(t, gval.Amount, val.VotingPower) + assert.Equal(t, gval.Power, val.VotingPower) assert.Equal(t, gval.PubKey, val.PubKey) } } diff --git a/rpc/core/net.go b/rpc/core/net.go index c6749941c..b3f1c7ce5 100644 --- a/rpc/core/net.go +++ b/rpc/core/net.go @@ -90,7 +90,7 @@ func UnsafeDialSeeds(seeds []string) (*ctypes.ResultDialSeeds, error) { // "validators": [ // { // "name": "", -// "amount": 10, +// "power": 10, // "pub_key": { // "data": "68DFDA7E50F82946E7E8546BED37944A422CD1B831E70DF66BA3B8430593944D", // "type": "ed25519" diff --git a/state/state.go b/state/state.go index 1374fcf46..3a8b98d08 100644 --- a/state/state.go +++ b/state/state.go @@ -347,7 +347,7 @@ func MakeGenesisState(db dbm.DB, genDoc *types.GenesisDoc) *State { validators[i] = &types.Validator{ Address: address, PubKey: pubKey, - VotingPower: val.Amount, + VotingPower: val.Power, } } diff --git a/test/p2p/data/mach1/core/genesis.json b/test/p2p/data/mach1/core/genesis.json index 522f9831a..8d5c6c7b9 100644 --- a/test/p2p/data/mach1/core/genesis.json +++ b/test/p2p/data/mach1/core/genesis.json @@ -4,7 +4,7 @@ "genesis_time": "2016-06-24T20:01:19.322Z", "validators": [ { - "amount": 1, + "power": 1, "name": "mach1", "pub_key": { "type": "ed25519", @@ -12,7 +12,7 @@ } }, { - "amount": 1, + "power": 1, "name": "mach2", "pub_key": { "type": "ed25519", @@ -20,7 +20,7 @@ } }, { - "amount": 1, + "power": 1, "name": "mach3", "pub_key": { "type": "ed25519", @@ -28,7 +28,7 @@ } }, { - "amount": 1, + "power": 1, "name": "mach4", "pub_key": { "type": "ed25519", diff --git a/test/p2p/data/mach2/core/genesis.json b/test/p2p/data/mach2/core/genesis.json index 522f9831a..8d5c6c7b9 100644 --- a/test/p2p/data/mach2/core/genesis.json +++ b/test/p2p/data/mach2/core/genesis.json @@ -4,7 +4,7 @@ "genesis_time": "2016-06-24T20:01:19.322Z", "validators": [ { - "amount": 1, + "power": 1, "name": "mach1", "pub_key": { "type": "ed25519", @@ -12,7 +12,7 @@ } }, { - "amount": 1, + "power": 1, "name": "mach2", "pub_key": { "type": "ed25519", @@ -20,7 +20,7 @@ } }, { - "amount": 1, + "power": 1, "name": "mach3", "pub_key": { "type": "ed25519", @@ -28,7 +28,7 @@ } }, { - "amount": 1, + "power": 1, "name": "mach4", "pub_key": { "type": "ed25519", diff --git a/test/p2p/data/mach3/core/genesis.json b/test/p2p/data/mach3/core/genesis.json index 522f9831a..8d5c6c7b9 100644 --- a/test/p2p/data/mach3/core/genesis.json +++ b/test/p2p/data/mach3/core/genesis.json @@ -4,7 +4,7 @@ "genesis_time": "2016-06-24T20:01:19.322Z", "validators": [ { - "amount": 1, + "power": 1, "name": "mach1", "pub_key": { "type": "ed25519", @@ -12,7 +12,7 @@ } }, { - "amount": 1, + "power": 1, "name": "mach2", "pub_key": { "type": "ed25519", @@ -20,7 +20,7 @@ } }, { - "amount": 1, + "power": 1, "name": "mach3", "pub_key": { "type": "ed25519", @@ -28,7 +28,7 @@ } }, { - "amount": 1, + "power": 1, "name": "mach4", "pub_key": { "type": "ed25519", diff --git a/test/p2p/data/mach4/core/genesis.json b/test/p2p/data/mach4/core/genesis.json index 522f9831a..8d5c6c7b9 100644 --- a/test/p2p/data/mach4/core/genesis.json +++ b/test/p2p/data/mach4/core/genesis.json @@ -4,7 +4,7 @@ "genesis_time": "2016-06-24T20:01:19.322Z", "validators": [ { - "amount": 1, + "power": 1, "name": "mach1", "pub_key": { "type": "ed25519", @@ -12,7 +12,7 @@ } }, { - "amount": 1, + "power": 1, "name": "mach2", "pub_key": { "type": "ed25519", @@ -20,7 +20,7 @@ } }, { - "amount": 1, + "power": 1, "name": "mach3", "pub_key": { "type": "ed25519", @@ -28,7 +28,7 @@ } }, { - "amount": 1, + "power": 1, "name": "mach4", "pub_key": { "type": "ed25519", diff --git a/types/genesis.go b/types/genesis.go index 06b3d124c..e57787c42 100644 --- a/types/genesis.go +++ b/types/genesis.go @@ -18,7 +18,7 @@ import ( // GenesisValidator is an initial validator. type GenesisValidator struct { PubKey crypto.PubKey `json:"pub_key"` - Amount int64 `json:"amount"` + Power int64 `json:"power"` Name string `json:"name"` } @@ -44,7 +44,7 @@ func (genDoc *GenesisDoc) SaveAs(file string) error { func (genDoc *GenesisDoc) ValidatorHash() []byte { vals := make([]*Validator, len(genDoc.Validators)) for i, v := range genDoc.Validators { - vals[i] = NewValidator(v.PubKey, v.Amount) + vals[i] = NewValidator(v.PubKey, v.Power) } vset := NewValidatorSet(vals) return vset.Hash() @@ -71,6 +71,12 @@ func (genDoc *GenesisDoc) ValidateAndComplete() error { return errors.Errorf("The genesis file must have at least one validator") } + for _, v := range genDoc.Validators { + if v.Power == 0 { + return errors.Errorf("The genesis file cannot contain validators with no voting power: %v", v) + } + } + if genDoc.GenesisTime.IsZero() { genDoc.GenesisTime = time.Now() } diff --git a/types/genesis_test.go b/types/genesis_test.go index d06a70dab..fe997b690 100644 --- a/types/genesis_test.go +++ b/types/genesis_test.go @@ -20,7 +20,7 @@ func TestGenesis(t *testing.T) { []byte(`{"chain_id": "mychain", "validators": [{}]`), // missing validators []byte(`{"validators":[{"pub_key": {"type":"ed25519","data":"961EAB8752E51A03618502F55C2B6E09C38C65635C64CCF3173ED452CF86C957"}, - "amount":10,"name":""}]}`), // missing chain_id + "power":10,"name":""}]}`), // missing chain_id } for _, testCase := range testCases { @@ -29,7 +29,7 @@ func TestGenesis(t *testing.T) { } // test a good one by raw json - genDocBytes := []byte(`{"genesis_time":"0001-01-01T00:00:00Z","chain_id":"test-chain-QDKdJr","consensus_params":null,"validators":[{"pub_key":{"type":"ed25519","data":"961EAB8752E51A03618502F55C2B6E09C38C65635C64CCF3173ED452CF86C957"},"amount":10,"name":""}],"app_hash":""}`) + genDocBytes := []byte(`{"genesis_time":"0001-01-01T00:00:00Z","chain_id":"test-chain-QDKdJr","consensus_params":null,"validators":[{"pub_key":{"type":"ed25519","data":"961EAB8752E51A03618502F55C2B6E09C38C65635C64CCF3173ED452CF86C957"},"power":10,"name":""}],"app_hash":""}`) _, err := GenesisDocFromJSON(genDocBytes) assert.NoError(t, err, "expected no error for good genDoc json")