diff --git a/libs/tendermint/consensus/consensus.go b/libs/tendermint/consensus/consensus.go index 7cd25c300b..a69bf06129 100644 --- a/libs/tendermint/consensus/consensus.go +++ b/libs/tendermint/consensus/consensus.go @@ -6,6 +6,9 @@ import ( "sync" "time" + "github.com/pkg/errors" + "github.com/spf13/viper" + "github.com/okex/exchain/libs/system/trace" cfg "github.com/okex/exchain/libs/tendermint/config" cstypes "github.com/okex/exchain/libs/tendermint/consensus/types" @@ -16,8 +19,6 @@ import ( "github.com/okex/exchain/libs/tendermint/p2p" sm "github.com/okex/exchain/libs/tendermint/state" "github.com/okex/exchain/libs/tendermint/types" - "github.com/pkg/errors" - "github.com/spf13/viper" ) //----------------------------------------------------------------------------- @@ -162,6 +163,8 @@ type State struct { vcMsg *ViewChangeMessage vcHeight map[int64]string + //actual proposer when avc + needLogPgu bool preBlockTaskChan chan *preBlockTask taskResultChan chan *preBlockTaskRes @@ -206,6 +209,7 @@ func NewState( bt: &BlockTransport{}, blockTimeTrc: trace.NewTracer(trace.LastBlockTime), vcHeight: make(map[int64]string), + needLogPgu: false, taskResultChan: make(chan *preBlockTaskRes, 1), preBlockTaskChan: make(chan *preBlockTask, 1), } diff --git a/libs/tendermint/consensus/consensus_commit.go b/libs/tendermint/consensus/consensus_commit.go index 54dd34c88c..e6d4f5883f 100644 --- a/libs/tendermint/consensus/consensus_commit.go +++ b/libs/tendermint/consensus/consensus_commit.go @@ -4,6 +4,8 @@ import ( "bytes" "encoding/hex" "fmt" + "time" + "github.com/okex/exchain/libs/iavl" iavlcfg "github.com/okex/exchain/libs/iavl/config" "github.com/okex/exchain/libs/system/trace" @@ -14,7 +16,6 @@ import ( sm "github.com/okex/exchain/libs/tendermint/state" "github.com/okex/exchain/libs/tendermint/types" tmtime "github.com/okex/exchain/libs/tendermint/types/time" - "time" ) func (cs *State) dumpElapsed(trc *trace.Tracer, schema string) { @@ -255,6 +256,11 @@ func (cs *State) finalizeCommit(height int64) { } return } + //Add trace.SimTx After ApplyBlock using needLogPgu + err = cs.blockExec.MempoolLogPgu(cs.needLogPgu) + if err != nil { + cs.Logger.Error("Failed to print PGU log from mempool", "Height", height, "err", err) + } //reset offset after commitGap if iavl.EnableAsyncCommit && @@ -401,6 +407,7 @@ func (cs *State) updateToState(state sm.State) { cs.LastValidators = state.LastValidators cs.TriggeredTimeoutPrecommit = false cs.state = state + cs.needLogPgu = false // Finally, broadcast RoundState cs.newStep() diff --git a/libs/tendermint/consensus/consensus_main_routine.go b/libs/tendermint/consensus/consensus_main_routine.go index c226d77588..07c7bed90f 100644 --- a/libs/tendermint/consensus/consensus_main_routine.go +++ b/libs/tendermint/consensus/consensus_main_routine.go @@ -3,14 +3,15 @@ package consensus import ( "bytes" "fmt" + "reflect" + "runtime/debug" + "time" + cfg "github.com/okex/exchain/libs/tendermint/config" cstypes "github.com/okex/exchain/libs/tendermint/consensus/types" "github.com/okex/exchain/libs/tendermint/libs/fail" "github.com/okex/exchain/libs/tendermint/types" tmtime "github.com/okex/exchain/libs/tendermint/types/time" - "reflect" - "runtime/debug" - "time" ) //----------------------------------------- @@ -117,6 +118,8 @@ func (cs *State) handleAVCProposal(proposal *types.Proposal) { part := res.blockParts.GetPart(i) cs.sendInternalMessage(msgInfo{&BlockPartMessage{cs.Height, cs.Round, part}, ""}) } + cs.needLogPgu = true + cs.trc.Pin("isAVCProposer") } // state transitions on complete-proposal, 2/3-any, 2/3-one diff --git a/libs/tendermint/consensus/consensus_propose.go b/libs/tendermint/consensus/consensus_propose.go index 685c850ec4..8e452e0cb3 100644 --- a/libs/tendermint/consensus/consensus_propose.go +++ b/libs/tendermint/consensus/consensus_propose.go @@ -77,7 +77,9 @@ func (cs *State) isBlockProducer() (string, string) { // Enter (CreateEmptyBlocks): from enterNewRound(height,round) // Enter (CreateEmptyBlocks, CreateEmptyBlocksInterval > 0 ): -// after enterNewRound(height,round), after timeout of CreateEmptyBlocksInterval +// +// after enterNewRound(height,round), after timeout of CreateEmptyBlocksInterval +// // Enter (!CreateEmptyBlocks) : after enterNewRound(height,round), once txs are in the mempool func (cs *State) enterPropose(height int64, round int) { logger := cs.Logger.With("height", height, "round", round) @@ -179,6 +181,7 @@ func (cs *State) defaultDecideProposal(height int64, round int) { part := blockParts.GetPart(i) cs.sendInternalMessage(msgInfo{&BlockPartMessage{cs.Height, cs.Round, part}, ""}) } + cs.needLogPgu = true cs.Logger.Info("Signed proposal", "height", height, "round", round, "proposal", proposal) cs.Logger.Debug(fmt.Sprintf("Signed proposal block: %v", block)) } else if !cs.replayMode { diff --git a/libs/tendermint/mempool/clist_mempool.go b/libs/tendermint/mempool/clist_mempool.go index 291928ef75..8c7ea05f61 100644 --- a/libs/tendermint/mempool/clist_mempool.go +++ b/libs/tendermint/mempool/clist_mempool.go @@ -12,6 +12,8 @@ import ( "time" "github.com/VictoriaMetrics/fastcache" + "github.com/tendermint/go-amino" + "github.com/okex/exchain/libs/system/trace" abci "github.com/okex/exchain/libs/tendermint/abci/types" cfg "github.com/okex/exchain/libs/tendermint/config" @@ -21,7 +23,6 @@ import ( tmmath "github.com/okex/exchain/libs/tendermint/libs/math" "github.com/okex/exchain/libs/tendermint/proxy" "github.com/okex/exchain/libs/tendermint/types" - "github.com/tendermint/go-amino" ) type TxInfoParser interface { @@ -997,9 +998,6 @@ func (mem *CListMempool) Update( if mem.config.Sealed { return mem.updateSealed(height, txs, deliverTxResponses) } - trace.GetElapsedInfo().AddInfo(trace.SimTx, fmt.Sprintf("%d", mem.info.txCount)) - trace.GetElapsedInfo().AddInfo(trace.SimGasUsed, fmt.Sprintf("%d", mem.info.gasUsed)) - mem.info.reset() // Set height atomic.StoreInt64(&mem.height, height) @@ -1241,6 +1239,23 @@ func (mem *CListMempool) GetConfig() *cfg.MempoolConfig { return mem.config } +func (mem *CListMempool) LogPgu(isBlockProducer bool) { + // no need to print pguInfo + if mem.config.Sealed { + return + } + + if isBlockProducer { + trace.GetElapsedInfo().AddInfo(trace.SimTx, fmt.Sprintf("%d", mem.info.txCount)) + trace.GetElapsedInfo().AddInfo(trace.SimGasUsed, fmt.Sprintf("%d", mem.info.gasUsed)) + } else { + trace.GetElapsedInfo().AddInfo(trace.SimTx, fmt.Sprintf("%d", 0)) + trace.GetElapsedInfo().AddInfo(trace.SimGasUsed, fmt.Sprintf("%d", 0)) + } + + mem.info.reset() +} + func MultiPriceBump(rawPrice *big.Int, priceBump int64) *big.Int { tmpPrice := new(big.Int).Div(rawPrice, big.NewInt(100)) inc := new(big.Int).Mul(tmpPrice, big.NewInt(priceBump)) diff --git a/libs/tendermint/state/execution.go b/libs/tendermint/state/execution.go index 808601bf58..1d70fe47c1 100644 --- a/libs/tendermint/state/execution.go +++ b/libs/tendermint/state/execution.go @@ -5,6 +5,8 @@ import ( "strconv" "time" + "github.com/tendermint/go-amino" + "github.com/okex/exchain/libs/system/trace" abci "github.com/okex/exchain/libs/tendermint/abci/types" cfg "github.com/okex/exchain/libs/tendermint/config" @@ -17,7 +19,6 @@ import ( "github.com/okex/exchain/libs/tendermint/types" tmtime "github.com/okex/exchain/libs/tendermint/types/time" dbm "github.com/okex/exchain/libs/tm-db" - "github.com/tendermint/go-amino" ) // ----------------------------------------------------------------------------- @@ -461,6 +462,15 @@ func (blockExec *BlockExecutor) commit( return res, res.RetainHeight, err } +func (blockExec *BlockExecutor) MempoolLogPgu(isBlockProducer bool) error { + clistmempool, ok := blockExec.mempool.(*mempl.CListMempool) + if !ok { + return fmt.Errorf("error on Printing PGU Log SimTx and SimGasUsed in mempool") + } + clistmempool.LogPgu(isBlockProducer) + return nil +} + func transTxsToBytes(txs types.Txs) [][]byte { ret := make([][]byte, 0) for _, v := range txs {