final updates for state

This commit is contained in:
Ethan Buchman
2017-12-28 23:15:54 -05:00
parent bac60f2067
commit 0acca7fe69
17 changed files with 192 additions and 165 deletions
+2 -4
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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{