Browse Source

New genesis.json

pull/55/head
Jae Kwon 10 years ago
parent
commit
5bdd73f4a4
4 changed files with 56 additions and 11 deletions
  1. +31
    -1
      config/config.go
  2. +12
    -9
      consensus/state.go
  3. +2
    -0
      state/execution.go
  4. +11
    -1
      state/validator_set_test.go

+ 31
- 1
config/config.go View File

@ -68,10 +68,20 @@ var DefaultGenesis = `{
"Accounts": [ "Accounts": [
{ {
"Address": "29BF3A0A13001A0D23533386BE03E74923AF1179", "Address": "29BF3A0A13001A0D23533386BE03E74923AF1179",
"Amount": 2099900000000000
"Amount": 2099600000000000
} }
], ],
"Validators": [ "Validators": [
{
"PubKey": [1, "1ED8C1E665B5035E62DDB3D6B8E7B4D728E13B5F571E687BB9C4B161C23D7686"],
"Amount": 100000000000,
"UnbondTo": [
{
"Address": "32B472D2E90FD423ABB6942AB27434471F92D736",
"Amount": 100000000000
}
]
},
{ {
"PubKey": [1, "3A2C5C341FFC1D5F7AB518519FF8289D3BFAB82DFD6E167B926FAD72C1BF10F8"], "PubKey": [1, "3A2C5C341FFC1D5F7AB518519FF8289D3BFAB82DFD6E167B926FAD72C1BF10F8"],
"Amount": 100000000000, "Amount": 100000000000,
@ -81,6 +91,26 @@ var DefaultGenesis = `{
"Amount": 100000000000 "Amount": 100000000000
} }
] ]
},
{
"PubKey": [1, "E9664351DC7C15F431E1ADBA5E135F171F67C85DFF64B689FC3359D62E437EEF"],
"Amount": 100000000000,
"UnbondTo": [
{
"Address": "F1901AF1B2778DBB7939569A91CEB1FE72A7AB12",
"Amount": 100000000000
}
]
},
{
"PubKey": [1, "5D56001CB46D67045FC78A431E844AC94E5780CCEE235B3D8E8666349F1BC1C2"],
"Amount": 100000000000,
"UnbondTo": [
{
"Address": "E91C4F631EF6DAA25C3E658F72E152AD853EA221",
"Amount": 100000000000
}
]
} }
] ]
}` }`


+ 12
- 9
consensus/state.go View File

@ -317,11 +317,10 @@ func (cs *ConsensusState) stepTransitionRoutine() {
// For clarity, all state transitions that happen after some timeout are here. // For clarity, all state transitions that happen after some timeout are here.
// Schedule the next action by pushing a RoundAction{} to cs.runActionCh. // Schedule the next action by pushing a RoundAction{} to cs.runActionCh.
scheduleNextAction := func() {
scheduleNextAction := func(rs *RoundState) {
go func() { go func() {
// NOTE: We can push directly to runActionCh because // NOTE: We can push directly to runActionCh because
// we're running in a separate goroutine, which avoids deadlocks. // we're running in a separate goroutine, which avoids deadlocks.
rs := cs.getRoundState()
round, roundStartTime, RoundDuration, _, elapsedRatio := calcRoundInfo(rs.StartTime) round, roundStartTime, RoundDuration, _, elapsedRatio := calcRoundInfo(rs.StartTime)
log.Debug("Scheduling next action", "height", rs.Height, "round", round, "step", rs.Step, "roundStartTime", roundStartTime, "elapsedRatio", elapsedRatio) log.Debug("Scheduling next action", "height", rs.Height, "round", round, "step", rs.Step, "roundStartTime", roundStartTime, "elapsedRatio", elapsedRatio)
switch rs.Step { switch rs.Step {
@ -351,14 +350,14 @@ func (cs *ConsensusState) stepTransitionRoutine() {
// There's nothing to scheudle, we're waiting for // There's nothing to scheudle, we're waiting for
// ProposalBlockParts.IsComplete() && // ProposalBlockParts.IsComplete() &&
// Commits.HasTwoThirdsMajority() // Commits.HasTwoThirdsMajority()
panic("The next action from RoundStepCommit is not scheduled by time")
//panic("The next action from RoundStepCommit is not scheduled by time")
default: default:
panic("Should not happen") panic("Should not happen")
} }
}() }()
} }
scheduleNextAction()
scheduleNextAction(cs.getRoundState())
// NOTE: All ConsensusState.RunAction*() calls come from here. // NOTE: All ConsensusState.RunAction*() calls come from here.
// Since only one routine calls them, it is safe to assume that // Since only one routine calls them, it is safe to assume that
@ -397,7 +396,7 @@ ACTION_LOOP:
continue ACTION_LOOP continue ACTION_LOOP
} }
cs.RunActionPropose(rs.Height, rs.Round) cs.RunActionPropose(rs.Height, rs.Round)
scheduleNextAction()
scheduleNextAction(rs)
continue ACTION_LOOP continue ACTION_LOOP
case RoundActionPrevote: case RoundActionPrevote:
@ -405,7 +404,7 @@ ACTION_LOOP:
continue ACTION_LOOP continue ACTION_LOOP
} }
cs.RunActionPrevote(rs.Height, rs.Round) cs.RunActionPrevote(rs.Height, rs.Round)
scheduleNextAction()
scheduleNextAction(rs)
continue ACTION_LOOP continue ACTION_LOOP
case RoundActionPrecommit: case RoundActionPrecommit:
@ -413,7 +412,7 @@ ACTION_LOOP:
continue ACTION_LOOP continue ACTION_LOOP
} }
cs.RunActionPrecommit(rs.Height, rs.Round) cs.RunActionPrecommit(rs.Height, rs.Round)
scheduleNextAction()
scheduleNextAction(rs)
continue ACTION_LOOP continue ACTION_LOOP
case RoundActionTryCommit: case RoundActionTryCommit:
@ -428,7 +427,7 @@ ACTION_LOOP:
// Could not commit, move onto next round. // Could not commit, move onto next round.
cs.SetupNewRound(rs.Height, rs.Round+1) cs.SetupNewRound(rs.Height, rs.Round+1)
// cs.Step is now at RoundStepNewRound // cs.Step is now at RoundStepNewRound
scheduleNextAction()
scheduleNextAction(rs)
continue ACTION_LOOP continue ACTION_LOOP
} }
@ -450,7 +449,7 @@ ACTION_LOOP:
cs.evsw.FireEvent(types.EventStringNewBlock(), newBlock) cs.evsw.FireEvent(types.EventStringNewBlock(), newBlock)
cs.evc.Flush() cs.evc.Flush()
}() }()
scheduleNextAction()
scheduleNextAction(rs)
continue ACTION_LOOP continue ACTION_LOOP
} else { } else {
// do not schedule next action. // do not schedule next action.
@ -533,14 +532,18 @@ func (cs *ConsensusState) updateToState(state *sm.State, contiguous bool) {
// After the call cs.Step becomes RoundStepNewRound. // After the call cs.Step becomes RoundStepNewRound.
func (cs *ConsensusState) setupNewRound(round uint) { func (cs *ConsensusState) setupNewRound(round uint) {
// XXX Looks like this is just not called.
// Sanity check // Sanity check
if round == 0 { if round == 0 {
panic("setupNewRound() should never be called for round 0") panic("setupNewRound() should never be called for round 0")
} }
// Increment all the way to round. // Increment all the way to round.
log.Debug(Fmt("Validators prior to IncrementAccum: %v, %v-%v", cs.Validators.String(),
round, cs.Round))
validators := cs.Validators.Copy() validators := cs.Validators.Copy()
validators.IncrementAccum(round - cs.Round) validators.IncrementAccum(round - cs.Round)
log.Debug(Fmt("Validators after IncrementAccum: %v", validators.String()))
cs.Round = round cs.Round = round
cs.Step = RoundStepNewRound cs.Step = RoundStepNewRound


+ 2
- 0
state/execution.go View File

@ -151,7 +151,9 @@ func execBlock(s *State, block *types.Block, blockPartsHeader types.PartSetHeade
} }
// Increment validator AccumPowers // Increment validator AccumPowers
log.Debug(Fmt("Bonded Validators prior to IncrementAccum: %v", s.BondedValidators.String()))
s.BondedValidators.IncrementAccum(1) s.BondedValidators.IncrementAccum(1)
log.Debug(Fmt("Bonded Validators after IncrementAccum: %v", s.BondedValidators.String()))
s.LastBlockHeight = block.Height s.LastBlockHeight = block.Height
s.LastBlockHash = block.Hash() s.LastBlockHash = block.Hash()


+ 11
- 1
state/validator_set_test.go View File

@ -5,6 +5,7 @@ import (
. "github.com/tendermint/tendermint/common" . "github.com/tendermint/tendermint/common"
"bytes" "bytes"
"fmt"
"testing" "testing"
) )
@ -41,6 +42,15 @@ func TestCopy(t *testing.T) {
} }
} }
func TestProposerSelection(t *testing.T) {
vset := randValidatorSet(10)
for i := 0; i < 100; i++ {
val := vset.Proposer()
fmt.Printf("Proposer: %v\n", val)
vset.IncrementAccum(1)
}
}
func BenchmarkValidatorSetCopy(b *testing.B) { func BenchmarkValidatorSetCopy(b *testing.B) {
b.StopTimer() b.StopTimer()
vset := NewValidatorSet([]*Validator{}) vset := NewValidatorSet([]*Validator{})
@ -51,7 +61,7 @@ func BenchmarkValidatorSetCopy(b *testing.B) {
PubKey: privAccount.PubKey.(account.PubKeyEd25519), PubKey: privAccount.PubKey.(account.PubKeyEd25519),
} }
if !vset.Add(val) { if !vset.Add(val) {
panic("Failde to add validator")
panic("Failed to add validator")
} }
} }
b.StartTimer() b.StartTimer()


Loading…
Cancel
Save