Browse Source

Amount -> Power. Closes #166

pull/650/head
Ethan Buchman 7 years ago
parent
commit
3089bbf2b8
15 changed files with 42 additions and 36 deletions
  1. +1
    -1
      cmd/tendermint/commands/init.go
  2. +2
    -2
      cmd/tendermint/commands/testnet.go
  3. +1
    -1
      config/toml.go
  4. +1
    -1
      consensus/common_test.go
  5. +5
    -5
      docs/specification/genesis.rst
  6. +3
    -3
      docs/using-tendermint.rst
  7. +1
    -1
      rpc/client/rpc_test.go
  8. +1
    -1
      rpc/core/net.go
  9. +1
    -1
      state/state.go
  10. +4
    -4
      test/p2p/data/mach1/core/genesis.json
  11. +4
    -4
      test/p2p/data/mach2/core/genesis.json
  12. +4
    -4
      test/p2p/data/mach3/core/genesis.json
  13. +4
    -4
      test/p2p/data/mach4/core/genesis.json
  14. +8
    -2
      types/genesis.go
  15. +2
    -2
      types/genesis_test.go

+ 1
- 1
cmd/tendermint/commands/init.go View File

@ -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)


+ 2
- 2
cmd/tendermint/commands/testnet.go View File

@ -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,
}
}


+ 1
- 1
config/toml.go View File

@ -119,7 +119,7 @@ var testGenesis = `{
"type": "ed25519",
"data":"3B3069C422E19688B45CBFAE7BB009FC0FA1B1EA86593519318B7214853803C8"
},
"amount": 10,
"power": 10,
"name": ""
}
],


+ 1
- 1
consensus/common_test.go View File

@ -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
}


+ 5
- 5
docs/specification/genesis.rst View File

@ -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"
}
],


+ 3
- 3
docs/using-tendermint.rst View File

@ -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,


+ 1
- 1
rpc/client/rpc_test.go View File

@ -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)
}
}


+ 1
- 1
rpc/core/net.go View File

@ -90,7 +90,7 @@ func UnsafeDialSeeds(seeds []string) (*ctypes.ResultDialSeeds, error) {
// "validators": [
// {
// "name": "",
// "amount": 10,
// "power": 10,
// "pub_key": {
// "data": "68DFDA7E50F82946E7E8546BED37944A422CD1B831E70DF66BA3B8430593944D",
// "type": "ed25519"


+ 1
- 1
state/state.go View File

@ -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,
}
}


+ 4
- 4
test/p2p/data/mach1/core/genesis.json View File

@ -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",


+ 4
- 4
test/p2p/data/mach2/core/genesis.json View File

@ -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",


+ 4
- 4
test/p2p/data/mach3/core/genesis.json View File

@ -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",


+ 4
- 4
test/p2p/data/mach4/core/genesis.json View File

@ -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",


+ 8
- 2
types/genesis.go View File

@ -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()
}


+ 2
- 2
types/genesis_test.go View File

@ -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")


Loading…
Cancel
Save