mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-25 10:41:41 +00:00
[state] expose ChainID and Params
``` jaekwon Yeah we should definitely expose ChainID. ConsensusParams is small enough, we can just write it. ``` https://github.com/tendermint/tendermint/pull/676#discussion_r144123203
This commit is contained in:
@ -175,7 +175,7 @@ func (bcR *BlockchainReactor) Receive(chID byte, src p2p.Peer, msgBytes []byte)
|
|||||||
// maxMsgSize returns the maximum allowable size of a
|
// maxMsgSize returns the maximum allowable size of a
|
||||||
// message on the blockchain reactor.
|
// message on the blockchain reactor.
|
||||||
func (bcR *BlockchainReactor) maxMsgSize() int {
|
func (bcR *BlockchainReactor) maxMsgSize() int {
|
||||||
return bcR.state.Params().BlockSizeParams.MaxBytes + 2
|
return bcR.state.Params.BlockSizeParams.MaxBytes + 2
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle messages from the poolReactor telling the reactor what to do.
|
// Handle messages from the poolReactor telling the reactor what to do.
|
||||||
@ -187,7 +187,7 @@ func (bcR *BlockchainReactor) poolRoutine() {
|
|||||||
statusUpdateTicker := time.NewTicker(statusUpdateIntervalSeconds * time.Second)
|
statusUpdateTicker := time.NewTicker(statusUpdateIntervalSeconds * time.Second)
|
||||||
switchToConsensusTicker := time.NewTicker(switchToConsensusIntervalSeconds * time.Second)
|
switchToConsensusTicker := time.NewTicker(switchToConsensusIntervalSeconds * time.Second)
|
||||||
|
|
||||||
chainID := bcR.state.ChainID()
|
chainID := bcR.state.ChainID
|
||||||
|
|
||||||
FOR_LOOP:
|
FOR_LOOP:
|
||||||
for {
|
for {
|
||||||
@ -238,7 +238,7 @@ FOR_LOOP:
|
|||||||
// We need both to sync the first block.
|
// We need both to sync the first block.
|
||||||
break SYNC_LOOP
|
break SYNC_LOOP
|
||||||
}
|
}
|
||||||
firstParts := first.MakePartSet(bcR.state.Params().BlockPartSizeBytes)
|
firstParts := first.MakePartSet(bcR.state.Params.BlockPartSizeBytes)
|
||||||
firstPartsHeader := firstParts.Header()
|
firstPartsHeader := firstParts.Header()
|
||||||
// Finally, verify the first block using the second's commit
|
// Finally, verify the first block using the second's commit
|
||||||
// NOTE: we can probably make this more efficient, but note that calling
|
// NOTE: we can probably make this more efficient, but note that calling
|
||||||
|
@ -42,7 +42,7 @@ func newBlockchainReactor(logger log.Logger, maxBlockHeight int) *BlockchainReac
|
|||||||
for blockHeight := 1; blockHeight <= maxBlockHeight; blockHeight++ {
|
for blockHeight := 1; blockHeight <= maxBlockHeight; blockHeight++ {
|
||||||
firstBlock := makeBlock(blockHeight, state)
|
firstBlock := makeBlock(blockHeight, state)
|
||||||
secondBlock := makeBlock(blockHeight+1, state)
|
secondBlock := makeBlock(blockHeight+1, state)
|
||||||
firstParts := firstBlock.MakePartSet(state.Params().BlockGossipParams.BlockPartSizeBytes)
|
firstParts := firstBlock.MakePartSet(state.Params.BlockGossipParams.BlockPartSizeBytes)
|
||||||
blockStore.SaveBlock(firstBlock, firstParts, secondBlock.LastCommit)
|
blockStore.SaveBlock(firstBlock, firstParts, secondBlock.LastCommit)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ func makeBlock(blockNumber int, state *sm.State) *types.Block {
|
|||||||
valHash := state.Validators.Hash()
|
valHash := state.Validators.Hash()
|
||||||
prevBlockID := types.BlockID{prevHash, prevParts}
|
prevBlockID := types.BlockID{prevHash, prevParts}
|
||||||
block, _ := types.MakeBlock(blockNumber, "test_chain", makeTxs(blockNumber),
|
block, _ := types.MakeBlock(blockNumber, "test_chain", makeTxs(blockNumber),
|
||||||
new(types.Commit), prevBlockID, valHash, state.AppHash, state.Params().BlockGossipParams.BlockPartSizeBytes)
|
new(types.Commit), prevBlockID, valHash, state.AppHash, state.Params.BlockGossipParams.BlockPartSizeBytes)
|
||||||
return block
|
return block
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,13 +167,13 @@ func byzantineDecideProposalFunc(t *testing.T, height, round int, cs *ConsensusS
|
|||||||
block1, blockParts1 := cs.createProposalBlock()
|
block1, blockParts1 := cs.createProposalBlock()
|
||||||
polRound, polBlockID := cs.Votes.POLInfo()
|
polRound, polBlockID := cs.Votes.POLInfo()
|
||||||
proposal1 := types.NewProposal(height, round, blockParts1.Header(), polRound, polBlockID)
|
proposal1 := types.NewProposal(height, round, blockParts1.Header(), polRound, polBlockID)
|
||||||
cs.privValidator.SignProposal(cs.state.ChainID(), proposal1) // byzantine doesnt err
|
cs.privValidator.SignProposal(cs.state.ChainID, proposal1) // byzantine doesnt err
|
||||||
|
|
||||||
// Create a new proposal block from state/txs from the mempool.
|
// Create a new proposal block from state/txs from the mempool.
|
||||||
block2, blockParts2 := cs.createProposalBlock()
|
block2, blockParts2 := cs.createProposalBlock()
|
||||||
polRound, polBlockID = cs.Votes.POLInfo()
|
polRound, polBlockID = cs.Votes.POLInfo()
|
||||||
proposal2 := types.NewProposal(height, round, blockParts2.Header(), polRound, polBlockID)
|
proposal2 := types.NewProposal(height, round, blockParts2.Header(), polRound, polBlockID)
|
||||||
cs.privValidator.SignProposal(cs.state.ChainID(), proposal2) // byzantine doesnt err
|
cs.privValidator.SignProposal(cs.state.ChainID, proposal2) // byzantine doesnt err
|
||||||
|
|
||||||
block1Hash := block1.Hash()
|
block1Hash := block1.Hash()
|
||||||
block2Hash := block2.Hash()
|
block2Hash := block2.Hash()
|
||||||
|
@ -231,7 +231,7 @@ func TestWALCrashBeforeWritePropose(t *testing.T) {
|
|||||||
msg := readTimedWALMessage(t, proposalMsg)
|
msg := readTimedWALMessage(t, proposalMsg)
|
||||||
proposal := msg.Msg.(msgInfo).Msg.(*ProposalMessage)
|
proposal := msg.Msg.(msgInfo).Msg.(*ProposalMessage)
|
||||||
// Set LastSig
|
// Set LastSig
|
||||||
toPV(cs.privValidator).LastSignBytes = types.SignBytes(cs.state.ChainID(), proposal.Proposal)
|
toPV(cs.privValidator).LastSignBytes = types.SignBytes(cs.state.ChainID, proposal.Proposal)
|
||||||
toPV(cs.privValidator).LastSignature = proposal.Proposal.Signature
|
toPV(cs.privValidator).LastSignature = proposal.Proposal.Signature
|
||||||
runReplayTest(t, cs, walFile, newBlockCh, thisCase, lineNum)
|
runReplayTest(t, cs, walFile, newBlockCh, thisCase, lineNum)
|
||||||
}
|
}
|
||||||
@ -256,7 +256,7 @@ func testReplayCrashBeforeWriteVote(t *testing.T, thisCase *testCase, lineNum in
|
|||||||
msg := readTimedWALMessage(t, voteMsg)
|
msg := readTimedWALMessage(t, voteMsg)
|
||||||
vote := msg.Msg.(msgInfo).Msg.(*VoteMessage)
|
vote := msg.Msg.(msgInfo).Msg.(*VoteMessage)
|
||||||
// Set LastSig
|
// Set LastSig
|
||||||
toPV(cs.privValidator).LastSignBytes = types.SignBytes(cs.state.ChainID(), vote.Vote)
|
toPV(cs.privValidator).LastSignBytes = types.SignBytes(cs.state.ChainID, vote.Vote)
|
||||||
toPV(cs.privValidator).LastSignature = vote.Vote.Signature
|
toPV(cs.privValidator).LastSignature = vote.Vote.Signature
|
||||||
})
|
})
|
||||||
runReplayTest(t, cs, walFile, newBlockCh, thisCase, lineNum)
|
runReplayTest(t, cs, walFile, newBlockCh, thisCase, lineNum)
|
||||||
@ -382,7 +382,7 @@ func testHandshakeReplay(t *testing.T, nBlocks int, mode uint) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func applyBlock(st *sm.State, blk *types.Block, proxyApp proxy.AppConns) {
|
func applyBlock(st *sm.State, blk *types.Block, proxyApp proxy.AppConns) {
|
||||||
testPartSize := st.Params().BlockPartSizeBytes
|
testPartSize := st.Params.BlockPartSizeBytes
|
||||||
err := st.ApplyBlock(nil, proxyApp.Consensus(), blk, blk.MakePartSet(testPartSize).Header(), mempool)
|
err := st.ApplyBlock(nil, proxyApp.Consensus(), blk, blk.MakePartSet(testPartSize).Header(), mempool)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -562,7 +562,7 @@ func stateAndStore(config *cfg.Config, pubKey crypto.PubKey) (*sm.State, *mockBl
|
|||||||
state, _ := sm.MakeGenesisStateFromFile(stateDB, config.GenesisFile())
|
state, _ := sm.MakeGenesisStateFromFile(stateDB, config.GenesisFile())
|
||||||
state.SetLogger(log.TestingLogger().With("module", "state"))
|
state.SetLogger(log.TestingLogger().With("module", "state"))
|
||||||
|
|
||||||
store := NewMockBlockStore(config, state.Params())
|
store := NewMockBlockStore(config, *state.Params)
|
||||||
return state, store
|
return state, store
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,7 +390,7 @@ func (cs *ConsensusState) reconstructLastCommit(state *sm.State) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
seenCommit := cs.blockStore.LoadSeenCommit(state.LastBlockHeight)
|
seenCommit := cs.blockStore.LoadSeenCommit(state.LastBlockHeight)
|
||||||
lastPrecommits := types.NewVoteSet(state.ChainID(), state.LastBlockHeight, seenCommit.Round(), types.VoteTypePrecommit, state.LastValidators)
|
lastPrecommits := types.NewVoteSet(state.ChainID, state.LastBlockHeight, seenCommit.Round(), types.VoteTypePrecommit, state.LastValidators)
|
||||||
for _, precommit := range seenCommit.Precommits {
|
for _, precommit := range seenCommit.Precommits {
|
||||||
if precommit == nil {
|
if precommit == nil {
|
||||||
continue
|
continue
|
||||||
@ -707,7 +707,7 @@ func (cs *ConsensusState) proposalHeartbeat(height, round int) {
|
|||||||
// not a validator
|
// not a validator
|
||||||
valIndex = -1
|
valIndex = -1
|
||||||
}
|
}
|
||||||
chainID := cs.state.ChainID()
|
chainID := cs.state.ChainID
|
||||||
for {
|
for {
|
||||||
rs := cs.GetRoundState()
|
rs := cs.GetRoundState()
|
||||||
// if we've already moved on, no need to send more heartbeats
|
// if we've already moved on, no need to send more heartbeats
|
||||||
@ -798,7 +798,7 @@ func (cs *ConsensusState) defaultDecideProposal(height, round int) {
|
|||||||
// Make proposal
|
// Make proposal
|
||||||
polRound, polBlockID := cs.Votes.POLInfo()
|
polRound, polBlockID := cs.Votes.POLInfo()
|
||||||
proposal := types.NewProposal(height, round, blockParts.Header(), polRound, polBlockID)
|
proposal := types.NewProposal(height, round, blockParts.Header(), polRound, polBlockID)
|
||||||
if err := cs.privValidator.SignProposal(cs.state.ChainID(), proposal); err == nil {
|
if err := cs.privValidator.SignProposal(cs.state.ChainID, proposal); err == nil {
|
||||||
// Set fields
|
// Set fields
|
||||||
/* fields set by setProposal and addBlockPart
|
/* fields set by setProposal and addBlockPart
|
||||||
cs.Proposal = proposal
|
cs.Proposal = proposal
|
||||||
@ -857,9 +857,9 @@ func (cs *ConsensusState) createProposalBlock() (block *types.Block, blockParts
|
|||||||
|
|
||||||
// Mempool validated transactions
|
// Mempool validated transactions
|
||||||
txs := cs.mempool.Reap(cs.config.MaxBlockSizeTxs)
|
txs := cs.mempool.Reap(cs.config.MaxBlockSizeTxs)
|
||||||
return types.MakeBlock(cs.Height, cs.state.ChainID(), txs, commit,
|
return types.MakeBlock(cs.Height, cs.state.ChainID, txs, commit,
|
||||||
cs.state.LastBlockID, cs.state.Validators.Hash(),
|
cs.state.LastBlockID, cs.state.Validators.Hash(),
|
||||||
cs.state.AppHash, cs.state.Params().BlockPartSizeBytes)
|
cs.state.AppHash, cs.state.Params.BlockPartSizeBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enter: `timeoutPropose` after entering Propose.
|
// Enter: `timeoutPropose` after entering Propose.
|
||||||
@ -1263,7 +1263,7 @@ func (cs *ConsensusState) defaultSetProposal(proposal *types.Proposal) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Verify signature
|
// Verify signature
|
||||||
if !cs.Validators.GetProposer().PubKey.VerifyBytes(types.SignBytes(cs.state.ChainID(), proposal), proposal.Signature) {
|
if !cs.Validators.GetProposer().PubKey.VerifyBytes(types.SignBytes(cs.state.ChainID, proposal), proposal.Signature) {
|
||||||
return ErrInvalidProposalSignature
|
return ErrInvalidProposalSignature
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1294,7 +1294,7 @@ func (cs *ConsensusState) addProposalBlockPart(height int, part *types.Part, ver
|
|||||||
var n int
|
var n int
|
||||||
var err error
|
var err error
|
||||||
cs.ProposalBlock = wire.ReadBinary(&types.Block{}, cs.ProposalBlockParts.GetReader(),
|
cs.ProposalBlock = wire.ReadBinary(&types.Block{}, cs.ProposalBlockParts.GetReader(),
|
||||||
cs.state.Params().BlockSizeParams.MaxBytes, &n, &err).(*types.Block)
|
cs.state.Params.BlockSizeParams.MaxBytes, &n, &err).(*types.Block)
|
||||||
// NOTE: it's possible to receive complete proposal blocks for future rounds without having the proposal
|
// NOTE: it's possible to receive complete proposal blocks for future rounds without having the proposal
|
||||||
cs.Logger.Info("Received complete proposal block", "height", cs.ProposalBlock.Height, "hash", cs.ProposalBlock.Hash())
|
cs.Logger.Info("Received complete proposal block", "height", cs.ProposalBlock.Height, "hash", cs.ProposalBlock.Hash())
|
||||||
if cs.Step == cstypes.RoundStepPropose && cs.isProposalComplete() {
|
if cs.Step == cstypes.RoundStepPropose && cs.isProposalComplete() {
|
||||||
@ -1458,7 +1458,7 @@ func (cs *ConsensusState) signVote(type_ byte, hash []byte, header types.PartSet
|
|||||||
Type: type_,
|
Type: type_,
|
||||||
BlockID: types.BlockID{hash, header},
|
BlockID: types.BlockID{hash, header},
|
||||||
}
|
}
|
||||||
err := cs.privValidator.SignVote(cs.state.ChainID(), vote)
|
err := cs.privValidator.SignVote(cs.state.ChainID, vote)
|
||||||
return vote, err
|
return vote, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,7 +181,7 @@ func TestBadProposal(t *testing.T) {
|
|||||||
height, round := cs1.Height, cs1.Round
|
height, round := cs1.Height, cs1.Round
|
||||||
vs2 := vss[1]
|
vs2 := vss[1]
|
||||||
|
|
||||||
partSize := cs1.state.Params().BlockPartSizeBytes
|
partSize := cs1.state.Params.BlockPartSizeBytes
|
||||||
|
|
||||||
proposalCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringCompleteProposal(), 1)
|
proposalCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringCompleteProposal(), 1)
|
||||||
voteCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringVote(), 1)
|
voteCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringVote(), 1)
|
||||||
@ -328,7 +328,7 @@ func TestLockNoPOL(t *testing.T) {
|
|||||||
vs2 := vss[1]
|
vs2 := vss[1]
|
||||||
height := cs1.Height
|
height := cs1.Height
|
||||||
|
|
||||||
partSize := cs1.state.Params().BlockPartSizeBytes
|
partSize := cs1.state.Params.BlockPartSizeBytes
|
||||||
|
|
||||||
timeoutProposeCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringTimeoutPropose(), 1)
|
timeoutProposeCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringTimeoutPropose(), 1)
|
||||||
timeoutWaitCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringTimeoutWait(), 1)
|
timeoutWaitCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringTimeoutWait(), 1)
|
||||||
@ -494,7 +494,7 @@ func TestLockPOLRelock(t *testing.T) {
|
|||||||
cs1, vss := randConsensusState(4)
|
cs1, vss := randConsensusState(4)
|
||||||
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
|
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
|
||||||
|
|
||||||
partSize := cs1.state.Params().BlockPartSizeBytes
|
partSize := cs1.state.Params.BlockPartSizeBytes
|
||||||
|
|
||||||
timeoutProposeCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringTimeoutPropose(), 1)
|
timeoutProposeCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringTimeoutPropose(), 1)
|
||||||
timeoutWaitCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringTimeoutWait(), 1)
|
timeoutWaitCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringTimeoutWait(), 1)
|
||||||
@ -607,7 +607,7 @@ func TestLockPOLUnlock(t *testing.T) {
|
|||||||
cs1, vss := randConsensusState(4)
|
cs1, vss := randConsensusState(4)
|
||||||
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
|
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
|
||||||
|
|
||||||
partSize := cs1.state.Params().BlockPartSizeBytes
|
partSize := cs1.state.Params.BlockPartSizeBytes
|
||||||
|
|
||||||
proposalCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringCompleteProposal(), 1)
|
proposalCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringCompleteProposal(), 1)
|
||||||
timeoutProposeCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringTimeoutPropose(), 1)
|
timeoutProposeCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringTimeoutPropose(), 1)
|
||||||
@ -702,7 +702,7 @@ func TestLockPOLSafety1(t *testing.T) {
|
|||||||
cs1, vss := randConsensusState(4)
|
cs1, vss := randConsensusState(4)
|
||||||
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
|
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
|
||||||
|
|
||||||
partSize := cs1.state.Params().BlockPartSizeBytes
|
partSize := cs1.state.Params.BlockPartSizeBytes
|
||||||
|
|
||||||
proposalCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringCompleteProposal(), 1)
|
proposalCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringCompleteProposal(), 1)
|
||||||
timeoutProposeCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringTimeoutPropose(), 1)
|
timeoutProposeCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringTimeoutPropose(), 1)
|
||||||
@ -823,7 +823,7 @@ func TestLockPOLSafety2(t *testing.T) {
|
|||||||
cs1, vss := randConsensusState(4)
|
cs1, vss := randConsensusState(4)
|
||||||
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
|
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
|
||||||
|
|
||||||
partSize := cs1.state.Params().BlockPartSizeBytes
|
partSize := cs1.state.Params.BlockPartSizeBytes
|
||||||
|
|
||||||
proposalCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringCompleteProposal(), 1)
|
proposalCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringCompleteProposal(), 1)
|
||||||
timeoutProposeCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringTimeoutPropose(), 1)
|
timeoutProposeCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringTimeoutPropose(), 1)
|
||||||
@ -998,7 +998,7 @@ func TestHalt1(t *testing.T) {
|
|||||||
cs1, vss := randConsensusState(4)
|
cs1, vss := randConsensusState(4)
|
||||||
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
|
vs2, vs3, vs4 := vss[1], vss[2], vss[3]
|
||||||
|
|
||||||
partSize := cs1.state.Params().BlockPartSizeBytes
|
partSize := cs1.state.Params.BlockPartSizeBytes
|
||||||
|
|
||||||
proposalCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringCompleteProposal(), 1)
|
proposalCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringCompleteProposal(), 1)
|
||||||
timeoutWaitCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringTimeoutWait(), 1)
|
timeoutWaitCh := subscribeToEvent(cs1.evsw, "tester", types.EventStringTimeoutWait(), 1)
|
||||||
|
@ -145,9 +145,6 @@ func NewNode(config *cfg.Config,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
state.Save()
|
state.Save()
|
||||||
} else {
|
|
||||||
state.SetChainID(genDoc.ChainID)
|
|
||||||
state.SetParams(genDoc.ConsensusParams)
|
|
||||||
}
|
}
|
||||||
state.SetLogger(stateLogger)
|
state.SetLogger(stateLogger)
|
||||||
|
|
||||||
@ -163,8 +160,6 @@ func NewNode(config *cfg.Config,
|
|||||||
|
|
||||||
// reload the state (it may have been updated by the handshake)
|
// reload the state (it may have been updated by the handshake)
|
||||||
state = sm.LoadState(stateDB)
|
state = sm.LoadState(stateDB)
|
||||||
state.SetChainID(genDoc.ChainID)
|
|
||||||
state.SetParams(genDoc.ConsensusParams)
|
|
||||||
state.SetLogger(stateLogger)
|
state.SetLogger(stateLogger)
|
||||||
|
|
||||||
// Transaction indexing
|
// Transaction indexing
|
||||||
|
@ -179,9 +179,8 @@ func (s *State) ValidateBlock(block *types.Block) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *State) validateBlock(block *types.Block) error {
|
func (s *State) validateBlock(block *types.Block) error {
|
||||||
chainID := s.ChainID()
|
|
||||||
// Basic block validation.
|
// Basic block validation.
|
||||||
err := block.ValidateBasic(chainID, s.LastBlockHeight, s.LastBlockID, s.LastBlockTime, s.AppHash)
|
err := block.ValidateBasic(s.ChainID, s.LastBlockHeight, s.LastBlockID, s.LastBlockTime, s.AppHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -197,7 +196,7 @@ func (s *State) validateBlock(block *types.Block) error {
|
|||||||
s.LastValidators.Size(), len(block.LastCommit.Precommits)))
|
s.LastValidators.Size(), len(block.LastCommit.Precommits)))
|
||||||
}
|
}
|
||||||
err := s.LastValidators.VerifyCommit(
|
err := s.LastValidators.VerifyCommit(
|
||||||
chainID, s.LastBlockID, block.Height-1, block.LastCommit)
|
s.ChainID, s.LastBlockID, block.Height-1, block.LastCommit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -39,9 +39,10 @@ type State struct {
|
|||||||
db dbm.DB
|
db dbm.DB
|
||||||
|
|
||||||
// See https://github.com/tendermint/tendermint/issues/671.
|
// See https://github.com/tendermint/tendermint/issues/671.
|
||||||
chainID string
|
ChainID string
|
||||||
|
// consensus parameters used for validating blocks
|
||||||
params *types.ConsensusParams
|
// must not be nil
|
||||||
|
Params *types.ConsensusParams
|
||||||
|
|
||||||
// These fields are updated by SetBlockAndValidators.
|
// These fields are updated by SetBlockAndValidators.
|
||||||
// LastBlockHeight=0 at genesis (ie. block(H=0) does not exist)
|
// LastBlockHeight=0 at genesis (ie. block(H=0) does not exist)
|
||||||
@ -70,21 +71,14 @@ type State struct {
|
|||||||
// or creates a new one from the given genesisFile and persists the result
|
// or creates a new one from the given genesisFile and persists the result
|
||||||
// to the database.
|
// to the database.
|
||||||
func GetState(stateDB dbm.DB, genesisFile string) (*State, error) {
|
func GetState(stateDB dbm.DB, genesisFile string) (*State, error) {
|
||||||
var err error
|
|
||||||
genDoc, err := MakeGenesisDocFromFile(genesisFile)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
state := LoadState(stateDB)
|
state := LoadState(stateDB)
|
||||||
if state == nil {
|
if state == nil {
|
||||||
state, err = MakeGenesisState(stateDB, genDoc)
|
var err error
|
||||||
|
state, err = MakeGenesisStateFromFile(stateDB, genesisFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
state.Save()
|
state.Save()
|
||||||
} else {
|
|
||||||
state.SetChainID(genDoc.ChainID)
|
|
||||||
state.SetParams(genDoc.ConsensusParams)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return state, nil
|
return state, nil
|
||||||
@ -119,7 +113,7 @@ func (s *State) SetLogger(l log.Logger) {
|
|||||||
|
|
||||||
// Copy makes a copy of the State for mutating.
|
// Copy makes a copy of the State for mutating.
|
||||||
func (s *State) Copy() *State {
|
func (s *State) Copy() *State {
|
||||||
paramsCopy := *s.params
|
paramsCopy := *s.Params
|
||||||
return &State{
|
return &State{
|
||||||
db: s.db,
|
db: s.db,
|
||||||
LastBlockHeight: s.LastBlockHeight,
|
LastBlockHeight: s.LastBlockHeight,
|
||||||
@ -131,17 +125,17 @@ func (s *State) Copy() *State {
|
|||||||
TxIndexer: s.TxIndexer, // pointer here, not value
|
TxIndexer: s.TxIndexer, // pointer here, not value
|
||||||
LastHeightValidatorsChanged: s.LastHeightValidatorsChanged,
|
LastHeightValidatorsChanged: s.LastHeightValidatorsChanged,
|
||||||
logger: s.logger,
|
logger: s.logger,
|
||||||
chainID: s.chainID,
|
ChainID: s.ChainID,
|
||||||
params: ¶msCopy,
|
Params: ¶msCopy,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save persists the State to the database.
|
// Save persists the State to the database.
|
||||||
func (s *State) Save() {
|
func (s *State) Save() {
|
||||||
s.mtx.Lock()
|
s.mtx.Lock()
|
||||||
|
defer s.mtx.Unlock()
|
||||||
s.saveValidatorsInfo()
|
s.saveValidatorsInfo()
|
||||||
s.db.SetSync(stateKey, s.Bytes())
|
s.db.SetSync(stateKey, s.Bytes())
|
||||||
s.mtx.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SaveABCIResponses persists the ABCIResponses to the database.
|
// SaveABCIResponses persists the ABCIResponses to the database.
|
||||||
@ -273,28 +267,6 @@ func (s *State) GetValidators() (*types.ValidatorSet, *types.ValidatorSet) {
|
|||||||
return s.LastValidators, s.Validators
|
return s.LastValidators, s.Validators
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChainID returns the chain ID.
|
|
||||||
func (s *State) ChainID() string {
|
|
||||||
return s.chainID
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetChainID sets the chain ID.
|
|
||||||
func (s *State) SetChainID(chainID string) {
|
|
||||||
s.chainID = chainID
|
|
||||||
}
|
|
||||||
|
|
||||||
// Params returns the consensus parameters used for
|
|
||||||
// validating blocks.
|
|
||||||
func (s *State) Params() types.ConsensusParams {
|
|
||||||
return *s.params
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetParams sets the consensus parameters used for
|
|
||||||
// validating blocks.
|
|
||||||
func (s *State) SetParams(params *types.ConsensusParams) {
|
|
||||||
s.params = params
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
|
|
||||||
// ABCIResponses retains the responses of the various ABCI calls during block processing.
|
// ABCIResponses retains the responses of the various ABCI calls during block processing.
|
||||||
@ -364,8 +336,6 @@ func MakeGenesisDocFromFile(genDocFile string) (*types.GenesisDoc, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MakeGenesisState creates state from types.GenesisDoc.
|
// MakeGenesisState creates state from types.GenesisDoc.
|
||||||
//
|
|
||||||
// Used in tests.
|
|
||||||
func MakeGenesisState(db dbm.DB, genDoc *types.GenesisDoc) (*State, error) {
|
func MakeGenesisState(db dbm.DB, genDoc *types.GenesisDoc) (*State, error) {
|
||||||
err := genDoc.ValidateAndComplete()
|
err := genDoc.ValidateAndComplete()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -389,8 +359,8 @@ func MakeGenesisState(db dbm.DB, genDoc *types.GenesisDoc) (*State, error) {
|
|||||||
return &State{
|
return &State{
|
||||||
db: db,
|
db: db,
|
||||||
|
|
||||||
chainID: genDoc.ChainID,
|
ChainID: genDoc.ChainID,
|
||||||
params: genDoc.ConsensusParams,
|
Params: genDoc.ConsensusParams,
|
||||||
|
|
||||||
LastBlockHeight: 0,
|
LastBlockHeight: 0,
|
||||||
LastBlockID: types.BlockID{},
|
LastBlockID: types.BlockID{},
|
||||||
|
@ -116,22 +116,6 @@ func TestValidatorSimpleSaveLoad(t *testing.T) {
|
|||||||
assert.IsType(ErrNoValSetForHeight{}, err, "expected err at unknown height")
|
assert.IsType(ErrNoValSetForHeight{}, err, "expected err at unknown height")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChainID(t *testing.T) {
|
|
||||||
tearDown, _, state := setupTestCase(t)
|
|
||||||
defer tearDown(t)
|
|
||||||
|
|
||||||
state.SetChainID("test")
|
|
||||||
assert.Equal(t, "test", state.ChainID())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestParams(t *testing.T) {
|
|
||||||
tearDown, _, state := setupTestCase(t)
|
|
||||||
defer tearDown(t)
|
|
||||||
|
|
||||||
state.SetParams(&types.ConsensusParams{})
|
|
||||||
assert.Equal(t, types.ConsensusParams{}, state.Params())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestValidatorChangesSaveLoad(t *testing.T) {
|
func TestValidatorChangesSaveLoad(t *testing.T) {
|
||||||
tearDown, _, state := setupTestCase(t)
|
tearDown, _, state := setupTestCase(t)
|
||||||
defer tearDown(t)
|
defer tearDown(t)
|
||||||
|
Reference in New Issue
Block a user