mirror of
https://github.com/tendermint/tendermint.git
synced 2026-02-03 10:32:05 +00:00
new logging
This commit is contained in:
@@ -3,6 +3,7 @@ package dummy
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
@@ -10,9 +11,10 @@ import (
|
||||
abcicli "github.com/tendermint/abci/client"
|
||||
"github.com/tendermint/abci/server"
|
||||
"github.com/tendermint/abci/types"
|
||||
"github.com/tendermint/go-crypto"
|
||||
crypto "github.com/tendermint/go-crypto"
|
||||
"github.com/tendermint/merkleeyes/iavl"
|
||||
cmn "github.com/tendermint/tmlibs/common"
|
||||
"github.com/tendermint/tmlibs/log"
|
||||
)
|
||||
|
||||
func testDummy(t *testing.T, app types.Application, tx []byte, key, value string) {
|
||||
@@ -211,10 +213,13 @@ func valsEqual(t *testing.T, vals1, vals2 []*types.Validator) {
|
||||
func makeSocketClientServer(app types.Application, name string) (abcicli.Client, cmn.Service, error) {
|
||||
// Start the listener
|
||||
socket := cmn.Fmt("unix://%s.sock", name)
|
||||
logger := log.NewTmLogger(os.Stdout)
|
||||
|
||||
server, err := server.NewSocketServer(socket, app)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
server.SetLogger(log.With(logger, "module", "abci-server"))
|
||||
|
||||
// Connect to the socket
|
||||
client, err := abcicli.NewSocketClient(socket, false)
|
||||
@@ -222,6 +227,7 @@ func makeSocketClientServer(app types.Application, name string) (abcicli.Client,
|
||||
server.Stop()
|
||||
return nil, nil, err
|
||||
}
|
||||
client.SetLogger(log.With(logger, "module", "abci-client"))
|
||||
client.Start()
|
||||
|
||||
return client, server, err
|
||||
@@ -230,18 +236,21 @@ func makeSocketClientServer(app types.Application, name string) (abcicli.Client,
|
||||
func makeGRPCClientServer(app types.Application, name string) (abcicli.Client, cmn.Service, error) {
|
||||
// Start the listener
|
||||
socket := cmn.Fmt("unix://%s.sock", name)
|
||||
logger := log.NewTmLogger(os.Stdout)
|
||||
|
||||
gapp := types.NewGRPCApplication(app)
|
||||
server, err := server.NewGRPCServer(socket, gapp)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
server.SetLogger(log.With(logger, "module", "abci-server"))
|
||||
|
||||
client, err := abcicli.NewGRPCClient(socket, true)
|
||||
if err != nil {
|
||||
server.Stop()
|
||||
return nil, nil, err
|
||||
}
|
||||
client.SetLogger(log.With(logger, "module", "abci-client"))
|
||||
return client, server, err
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package dummy
|
||||
|
||||
import (
|
||||
"github.com/tendermint/tmlibs/logger"
|
||||
)
|
||||
|
||||
var log = logger.New("module", "dummy")
|
||||
@@ -6,11 +6,13 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/tendermint/abci/types"
|
||||
"github.com/tendermint/go-wire"
|
||||
wire "github.com/tendermint/go-wire"
|
||||
"github.com/tendermint/merkleeyes/iavl"
|
||||
cmn "github.com/tendermint/tmlibs/common"
|
||||
dbm "github.com/tendermint/tmlibs/db"
|
||||
"github.com/tendermint/tmlibs/log"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -29,6 +31,8 @@ type PersistentDummyApplication struct {
|
||||
|
||||
// validator set
|
||||
changes []*types.Validator
|
||||
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
func NewPersistentDummyApplication(dbDir string) *PersistentDummyApplication {
|
||||
@@ -38,14 +42,19 @@ func NewPersistentDummyApplication(dbDir string) *PersistentDummyApplication {
|
||||
stateTree := iavl.NewIAVLTree(0, db)
|
||||
stateTree.Load(lastBlock.AppHash)
|
||||
|
||||
log.Notice("Loaded state", "block", lastBlock.Height, "root", stateTree.Hash())
|
||||
// log.Notice("Loaded state", "block", lastBlock.Height, "root", stateTree.Hash())
|
||||
|
||||
return &PersistentDummyApplication{
|
||||
app: &DummyApplication{state: stateTree},
|
||||
db: db,
|
||||
app: &DummyApplication{state: stateTree},
|
||||
db: db,
|
||||
logger: log.NewNopLogger(),
|
||||
}
|
||||
}
|
||||
|
||||
func (app *PersistentDummyApplication) SetLogger(l log.Logger) {
|
||||
app.logger = l
|
||||
}
|
||||
|
||||
func (app *PersistentDummyApplication) Info() (resInfo types.ResponseInfo) {
|
||||
resInfo = app.app.Info()
|
||||
lastBlock := LoadLastBlock(app.db)
|
||||
@@ -79,13 +88,16 @@ func (app *PersistentDummyApplication) CheckTx(tx []byte) types.Result {
|
||||
func (app *PersistentDummyApplication) Commit() types.Result {
|
||||
// Save
|
||||
appHash := app.app.state.Save()
|
||||
log.Info("Saved state", "root", appHash)
|
||||
app.logger.Info("Saved state", "root", appHash)
|
||||
|
||||
lastBlock := LastBlockInfo{
|
||||
Height: app.blockHeader.Height,
|
||||
AppHash: appHash, // this hash will be in the next block header
|
||||
}
|
||||
|
||||
app.logger.Info("Saving block", "height", lastBlock.Height, "root", lastBlock.AppHash)
|
||||
SaveLastBlock(app.db, lastBlock)
|
||||
|
||||
return types.NewResultOK(appHash, "")
|
||||
}
|
||||
|
||||
@@ -98,7 +110,7 @@ func (app *PersistentDummyApplication) InitChain(validators []*types.Validator)
|
||||
for _, v := range validators {
|
||||
r := app.updateValidator(v)
|
||||
if r.IsErr() {
|
||||
log.Error("Error updating validators", "r", r)
|
||||
app.logger.Error("Error updating validators", "r", r)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -134,8 +146,7 @@ func LoadLastBlock(db dbm.DB) (lastBlock LastBlockInfo) {
|
||||
r, n, err := bytes.NewReader(buf), new(int), new(error)
|
||||
wire.ReadBinaryPtr(&lastBlock, r, 0, n, err)
|
||||
if *err != nil {
|
||||
// DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED
|
||||
log.Crit(cmn.Fmt("Data has been corrupted or its spec has changed: %v\n", *err))
|
||||
cmn.PanicCrisis(errors.Wrap(*err, "cannot load last block (data has been corrupted or its spec has changed)"))
|
||||
}
|
||||
// TODO: ensure that buf is completely read.
|
||||
}
|
||||
@@ -144,12 +155,11 @@ func LoadLastBlock(db dbm.DB) (lastBlock LastBlockInfo) {
|
||||
}
|
||||
|
||||
func SaveLastBlock(db dbm.DB, lastBlock LastBlockInfo) {
|
||||
log.Notice("Saving block", "height", lastBlock.Height, "root", lastBlock.AppHash)
|
||||
buf, n, err := new(bytes.Buffer), new(int), new(error)
|
||||
wire.WriteBinary(lastBlock, buf, n, err)
|
||||
if *err != nil {
|
||||
// TODO
|
||||
cmn.PanicCrisis(*err)
|
||||
cmn.PanicCrisis(errors.Wrap(*err, "cannot save last block"))
|
||||
}
|
||||
db.Set(lastBlockKey, buf.Bytes())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user