mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-21 07:24:36 +00:00
final updates for state
This commit is contained in:
+2
-4
@@ -36,7 +36,7 @@ func GetState(stateDB dbm.DB, genesisFile string) (State, error) {
|
||||
if err != nil {
|
||||
return state, err
|
||||
}
|
||||
SaveState(stateDB, state, state.AppHash)
|
||||
SaveState(stateDB, state)
|
||||
}
|
||||
|
||||
return state, nil
|
||||
@@ -66,9 +66,7 @@ func loadState(db dbm.DB, key []byte) (state State) {
|
||||
}
|
||||
|
||||
// SaveState persists the State, the ValidatorsInfo, and the ConsensusParamsInfo to the database.
|
||||
// It sets the given appHash on the state before persisting.
|
||||
func SaveState(db dbm.DB, s State, appHash []byte) {
|
||||
s.AppHash = appHash
|
||||
func SaveState(db dbm.DB, s State) {
|
||||
nextHeight := s.LastBlockHeight + 1
|
||||
saveValidatorsInfo(db, nextHeight, s.LastHeightValidatorsChanged, s.Validators)
|
||||
saveConsensusParamsInfo(db, nextHeight, s.LastHeightConsensusParamsChanged, s.ConsensusParams)
|
||||
|
||||
+12
-9
@@ -30,6 +30,10 @@ type BlockExecutor struct {
|
||||
evpool types.EvidencePool
|
||||
}
|
||||
|
||||
func (blockExec *BlockExecutor) SetTxEventPublisher(txEventPublisher types.TxEventPublisher) {
|
||||
blockExec.txEventPublisher = txEventPublisher
|
||||
}
|
||||
|
||||
// NewBlockExecutor returns a new BlockExecutor.
|
||||
func NewBlockExecutor(db dbm.DB, logger log.Logger,
|
||||
txEventer types.TxEventPublisher, proxyApp proxy.AppConnConsensus,
|
||||
@@ -82,8 +86,9 @@ func (blockExec *BlockExecutor) ApplyBlock(s State, blockID types.BlockID, block
|
||||
|
||||
fail.Fail() // XXX
|
||||
|
||||
// save the state and the validators
|
||||
SaveState(blockExec.db, s, appHash)
|
||||
// update the app hash and save the state
|
||||
s.AppHash = appHash
|
||||
SaveState(blockExec.db, s)
|
||||
|
||||
return s, nil
|
||||
}
|
||||
@@ -110,7 +115,7 @@ func (blockExec *BlockExecutor) Commit(block *types.Block) ([]byte, error) {
|
||||
blockExec.logger.Debug("Commit.Log: " + res.Log)
|
||||
}
|
||||
|
||||
blockExec.logger.Info("Committed state", "height", block.Height, "txs", block.NumTxs, "hash", res.Data)
|
||||
blockExec.logger.Info("Committed state", "height", block.Height, "txs", block.NumTxs, "appHash", res.Data)
|
||||
|
||||
// Update evpool
|
||||
blockExec.evpool.MarkEvidenceAsCommitted(block.Evidence.Evidence)
|
||||
@@ -343,16 +348,14 @@ func updateState(s State, blockID types.BlockID, header *types.Header,
|
||||
}
|
||||
|
||||
func fireEvents(txEventPublisher types.TxEventPublisher, block *types.Block, abciResponses *ABCIResponses) {
|
||||
// TODO: Fire events
|
||||
/*
|
||||
tx := types.Tx(req.GetDeliverTx().Tx)
|
||||
for i, tx := range block.Data.Txs {
|
||||
txEventPublisher.PublishEventTx(types.EventDataTx{types.TxResult{
|
||||
Height: block.Height,
|
||||
Index: uint32(txIndex),
|
||||
Index: uint32(i),
|
||||
Tx: tx,
|
||||
Result: *txRes,
|
||||
Result: *(abciResponses.DeliverTx[i]),
|
||||
}})
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
|
||||
+1
-1
@@ -91,7 +91,7 @@ func (s State) Bytes() []byte {
|
||||
|
||||
// IsEmpty returns true if the State is equal to the empty State.
|
||||
func (s State) IsEmpty() bool {
|
||||
return s.LastBlockHeight == 0 // XXX can't compare to Empty
|
||||
return s.Validators == nil // XXX can't compare to Empty
|
||||
}
|
||||
|
||||
// GetValidators returns the last and current validator sets.
|
||||
|
||||
+3
-3
@@ -57,7 +57,7 @@ func TestStateSaveLoad(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
state.LastBlockHeight++
|
||||
SaveState(stateDB, state, state.AppHash)
|
||||
SaveState(stateDB, state)
|
||||
|
||||
loadedState := LoadState(stateDB)
|
||||
assert.True(state.Equals(loadedState),
|
||||
@@ -261,7 +261,7 @@ func TestManyValidatorChangesSaveLoad(t *testing.T) {
|
||||
const valSetSize = 7
|
||||
tearDown, stateDB, state := setupTestCase(t)
|
||||
state.Validators = genValSet(valSetSize)
|
||||
SaveState(stateDB, state, state.AppHash)
|
||||
SaveState(stateDB, state)
|
||||
defer tearDown(t)
|
||||
|
||||
const height = 1
|
||||
@@ -425,7 +425,7 @@ func TestLessThanOneThirdOfVotingPowerPerBlockEnforced(t *testing.T) {
|
||||
for i, tc := range testCases {
|
||||
tearDown, stateDB, state := setupTestCase(t)
|
||||
state.Validators = genValSet(tc.initialValSetSize)
|
||||
SaveState(stateDB, state, state.AppHash)
|
||||
SaveState(stateDB, state)
|
||||
height := state.LastBlockHeight + 1
|
||||
block := makeBlock(state, height)
|
||||
abciResponses := &ABCIResponses{
|
||||
|
||||
Reference in New Issue
Block a user