mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-19 22:44:24 +00:00
new logging
This commit is contained in:
+16
-15
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/tendermint/tendermint/state/txindex"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
cmn "github.com/tendermint/tmlibs/common"
|
||||
"github.com/tendermint/tmlibs/log"
|
||||
)
|
||||
|
||||
//--------------------------------------------------
|
||||
@@ -26,7 +27,7 @@ func (s *State) ValExecBlock(eventCache types.Fireable, proxyAppConn proxy.AppCo
|
||||
}
|
||||
|
||||
// Execute the block txs
|
||||
abciResponses, err := execBlockOnProxyApp(eventCache, proxyAppConn, block)
|
||||
abciResponses, err := execBlockOnProxyApp(eventCache, proxyAppConn, block, s.logger)
|
||||
if err != nil {
|
||||
// There was some error in proxyApp
|
||||
// TODO Report error and wait for proxyApp to be available.
|
||||
@@ -39,7 +40,7 @@ func (s *State) ValExecBlock(eventCache types.Fireable, proxyAppConn proxy.AppCo
|
||||
// Executes block's transactions on proxyAppConn.
|
||||
// Returns a list of transaction results and updates to the validator set
|
||||
// TODO: Generate a bitmap or otherwise store tx validity in state.
|
||||
func execBlockOnProxyApp(eventCache types.Fireable, proxyAppConn proxy.AppConnConsensus, block *types.Block) (*ABCIResponses, error) {
|
||||
func execBlockOnProxyApp(eventCache types.Fireable, proxyAppConn proxy.AppConnConsensus, block *types.Block, logger log.Logger) (*ABCIResponses, error) {
|
||||
var validTxs, invalidTxs = 0, 0
|
||||
|
||||
txIndex := 0
|
||||
@@ -58,7 +59,7 @@ func execBlockOnProxyApp(eventCache types.Fireable, proxyAppConn proxy.AppConnCo
|
||||
if txResult.Code == abci.CodeType_OK {
|
||||
validTxs++
|
||||
} else {
|
||||
log.Debug("Invalid tx", "code", txResult.Code, "log", txResult.Log)
|
||||
logger.Debug("Invalid tx", "code", txResult.Code, "log", txResult.Log)
|
||||
invalidTxs++
|
||||
txError = txResult.Code.String()
|
||||
}
|
||||
@@ -84,7 +85,7 @@ func execBlockOnProxyApp(eventCache types.Fireable, proxyAppConn proxy.AppConnCo
|
||||
// Begin block
|
||||
err := proxyAppConn.BeginBlockSync(block.Hash(), types.TM2PB.Header(block.Header))
|
||||
if err != nil {
|
||||
log.Warn("Error in proxyAppConn.BeginBlock", "error", err)
|
||||
logger.Error("Error in proxyAppConn.BeginBlock", "error", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -99,15 +100,15 @@ func execBlockOnProxyApp(eventCache types.Fireable, proxyAppConn proxy.AppConnCo
|
||||
// End block
|
||||
abciResponses.EndBlock, err = proxyAppConn.EndBlockSync(uint64(block.Height))
|
||||
if err != nil {
|
||||
log.Warn("Error in proxyAppConn.EndBlock", "error", err)
|
||||
logger.Error("Error in proxyAppConn.EndBlock", "error", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
valDiff := abciResponses.EndBlock.Diffs
|
||||
|
||||
log.Info("Executed block", "height", block.Height, "valid txs", validTxs, "invalid txs", invalidTxs)
|
||||
logger.Info("Executed block", "height", block.Height, "valid txs", validTxs, "invalid txs", invalidTxs)
|
||||
if len(valDiff) > 0 {
|
||||
log.Info("Update to validator set", "updates", abci.ValidatorsString(valDiff))
|
||||
logger.Info("Update to validator set", "updates", abci.ValidatorsString(valDiff))
|
||||
}
|
||||
|
||||
return abciResponses, nil
|
||||
@@ -251,14 +252,14 @@ func (s *State) CommitStateUpdateMempool(proxyAppConn proxy.AppConnConsensus, bl
|
||||
// Commit block, get hash back
|
||||
res := proxyAppConn.CommitSync()
|
||||
if res.IsErr() {
|
||||
log.Warn("Error in proxyAppConn.CommitSync", "error", res)
|
||||
s.logger.Error("Error in proxyAppConn.CommitSync", "error", res)
|
||||
return res
|
||||
}
|
||||
if res.Log != "" {
|
||||
log.Debug("Commit.Log: " + res.Log)
|
||||
s.logger.Debug("Commit.Log: " + res.Log)
|
||||
}
|
||||
|
||||
log.Info("Committed state", "hash", res.Data)
|
||||
s.logger.Info("Committed state", "hash", fmt.Sprintf("%X", res.Data))
|
||||
// Set the state's new AppHash
|
||||
s.AppHash = res.Data
|
||||
|
||||
@@ -286,21 +287,21 @@ func (s *State) indexTxs(abciResponses *ABCIResponses) {
|
||||
|
||||
// Exec and commit a block on the proxyApp without validating or mutating the state
|
||||
// Returns the application root hash (result of abci.Commit)
|
||||
func ExecCommitBlock(appConnConsensus proxy.AppConnConsensus, block *types.Block) ([]byte, error) {
|
||||
func ExecCommitBlock(appConnConsensus proxy.AppConnConsensus, block *types.Block, logger log.Logger) ([]byte, error) {
|
||||
var eventCache types.Fireable // nil
|
||||
_, err := execBlockOnProxyApp(eventCache, appConnConsensus, block)
|
||||
_, err := execBlockOnProxyApp(eventCache, appConnConsensus, block, logger)
|
||||
if err != nil {
|
||||
log.Warn("Error executing block on proxy app", "height", block.Height, "err", err)
|
||||
logger.Error("Error executing block on proxy app", "height", block.Height, "err", err)
|
||||
return nil, err
|
||||
}
|
||||
// Commit block, get hash back
|
||||
res := appConnConsensus.CommitSync()
|
||||
if res.IsErr() {
|
||||
log.Warn("Error in proxyAppConn.CommitSync", "error", res)
|
||||
logger.Error("Error in proxyAppConn.CommitSync", "error", res)
|
||||
return nil, res
|
||||
}
|
||||
if res.Log != "" {
|
||||
log.Info("Commit.Log: " + res.Log)
|
||||
logger.Info("Commit.Log: " + res.Log)
|
||||
}
|
||||
return res.Data, nil
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/tendermint/tendermint/state/txindex"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
dbm "github.com/tendermint/tmlibs/db"
|
||||
"github.com/tendermint/tmlibs/log"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -28,6 +29,7 @@ func TestApplyBlock(t *testing.T) {
|
||||
defer proxyApp.Stop()
|
||||
|
||||
state := state()
|
||||
state.SetLogger(log.TestingLogger())
|
||||
indexer := &dummyIndexer{0}
|
||||
state.TxIndexer = indexer
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package state
|
||||
|
||||
import (
|
||||
"github.com/tendermint/tmlibs/logger"
|
||||
)
|
||||
|
||||
var log = logger.New("module", "state")
|
||||
+14
-2
@@ -9,8 +9,9 @@ import (
|
||||
abci "github.com/tendermint/abci/types"
|
||||
cmn "github.com/tendermint/tmlibs/common"
|
||||
dbm "github.com/tendermint/tmlibs/db"
|
||||
"github.com/tendermint/tmlibs/log"
|
||||
|
||||
"github.com/tendermint/go-wire"
|
||||
wire "github.com/tendermint/go-wire"
|
||||
"github.com/tendermint/tendermint/state/txindex"
|
||||
"github.com/tendermint/tendermint/state/txindex/null"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
@@ -48,6 +49,8 @@ type State struct {
|
||||
// Intermediate results from processing
|
||||
// Persisted separately from the state
|
||||
abciResponses *ABCIResponses
|
||||
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
func LoadState(db dbm.DB) *State {
|
||||
@@ -71,6 +74,14 @@ func loadState(db dbm.DB, key []byte) *State {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *State) SetLogger(l log.Logger) {
|
||||
s.logger = l
|
||||
}
|
||||
|
||||
func (s *State) GetLogger() log.Logger {
|
||||
return s.logger
|
||||
}
|
||||
|
||||
func (s *State) Copy() *State {
|
||||
return &State{
|
||||
db: s.db,
|
||||
@@ -83,6 +94,7 @@ func (s *State) Copy() *State {
|
||||
LastValidators: s.LastValidators.Copy(),
|
||||
AppHash: s.AppHash,
|
||||
TxIndexer: s.TxIndexer, // pointer here, not value
|
||||
logger: s.logger,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +152,7 @@ func (s *State) SetBlockAndValidators(header *types.Header, blockPartsHeader typ
|
||||
// update the validator set with the latest abciResponses
|
||||
err := updateValidators(nextValSet, abciResponses.EndBlock.Diffs)
|
||||
if err != nil {
|
||||
log.Warn("Error changing validator set", "error", err)
|
||||
s.logger.Error("Error changing validator set", "error", err)
|
||||
// TODO: err or carry on?
|
||||
}
|
||||
// Update validator accums and set state variables
|
||||
|
||||
+5
-1
@@ -6,9 +6,10 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
abci "github.com/tendermint/abci/types"
|
||||
"github.com/tendermint/go-crypto"
|
||||
crypto "github.com/tendermint/go-crypto"
|
||||
cfg "github.com/tendermint/tendermint/config"
|
||||
dbm "github.com/tendermint/tmlibs/db"
|
||||
"github.com/tendermint/tmlibs/log"
|
||||
)
|
||||
|
||||
func TestStateCopyEquals(t *testing.T) {
|
||||
@@ -17,6 +18,7 @@ func TestStateCopyEquals(t *testing.T) {
|
||||
// Get State db
|
||||
stateDB := dbm.NewDB("state", config.DBBackend, config.DBDir())
|
||||
state := GetState(stateDB, config.GenesisFile())
|
||||
state.SetLogger(log.TestingLogger())
|
||||
|
||||
stateCopy := state.Copy()
|
||||
|
||||
@@ -36,6 +38,7 @@ func TestStateSaveLoad(t *testing.T) {
|
||||
// Get State db
|
||||
stateDB := dbm.NewDB("state", config.DBBackend, config.DBDir())
|
||||
state := GetState(stateDB, config.GenesisFile())
|
||||
state.SetLogger(log.TestingLogger())
|
||||
|
||||
state.LastBlockHeight += 1
|
||||
state.Save()
|
||||
@@ -52,6 +55,7 @@ func TestABCIResponsesSaveLoad(t *testing.T) {
|
||||
config := cfg.ResetTestRoot("state_")
|
||||
stateDB := dbm.NewDB("state", config.DBBackend, config.DBDir())
|
||||
state := GetState(stateDB, config.GenesisFile())
|
||||
state.SetLogger(log.TestingLogger())
|
||||
|
||||
state.LastBlockHeight += 1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user