diff --git a/libs/tendermint/consensus/consensus.go b/libs/tendermint/consensus/consensus.go index 06c1aa08f..80b780206 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/okx/okbchain/libs/system/trace" cfg "github.com/okx/okbchain/libs/tendermint/config" cstypes "github.com/okx/okbchain/libs/tendermint/consensus/types" @@ -16,8 +19,6 @@ import ( "github.com/okx/okbchain/libs/tendermint/p2p" sm "github.com/okx/okbchain/libs/tendermint/state" "github.com/okx/okbchain/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 6f4ca9a7b..0e49cb695 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/okx/okbchain/libs/iavl" iavlcfg "github.com/okx/okbchain/libs/iavl/config" "github.com/okx/okbchain/libs/system/trace" @@ -14,7 +16,6 @@ import ( sm "github.com/okx/okbchain/libs/tendermint/state" "github.com/okx/okbchain/libs/tendermint/types" tmtime "github.com/okx/okbchain/libs/tendermint/types/time" - "time" ) func (cs *State) dumpElapsed(trc *trace.Tracer, schema string) { @@ -256,6 +257,12 @@ 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 && height%iavlcfg.DynamicConfig.GetCommitGapHeight() == iavl.GetFinalCommitGapOffset() { @@ -401,6 +408,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 4bc59535c..06003289a 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/okx/okbchain/libs/tendermint/config" cstypes "github.com/okx/okbchain/libs/tendermint/consensus/types" "github.com/okx/okbchain/libs/tendermint/libs/fail" "github.com/okx/okbchain/libs/tendermint/types" tmtime "github.com/okx/okbchain/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 4ba90e73b..1b5c9b327 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) @@ -102,6 +104,7 @@ func (cs *State) enterPropose(height int64, round int) { newProposer = "-avc-" + cs.vcHeight[height][:6] } cs.stateMtx.RUnlock() + cs.trc.Pin("enterPropose-%d-%s-%s%s", round, isBlockProducer, bpAddr, newProposer) logger.Info(fmt.Sprintf("enterPropose(%v/%v). Current: %v/%v/%v", height, round, cs.Height, cs.Round, cs.Step)) @@ -179,6 +182,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/consensus/reactor.go b/libs/tendermint/consensus/reactor.go index 0015c2668..db2ea8f99 100644 --- a/libs/tendermint/consensus/reactor.go +++ b/libs/tendermint/consensus/reactor.go @@ -3,12 +3,13 @@ package consensus import ( "bytes" "fmt" - "github.com/okx/okbchain/libs/tendermint/crypto" - "github.com/okx/okbchain/libs/tendermint/libs/automation" "reflect" "sync" "time" + "github.com/okx/okbchain/libs/tendermint/crypto" + "github.com/okx/okbchain/libs/tendermint/libs/automation" + "github.com/pkg/errors" amino "github.com/tendermint/go-amino" diff --git a/libs/tendermint/mempool/clist_mempool.go b/libs/tendermint/mempool/clist_mempool.go index 61371674e..4082c1aae 100644 --- a/libs/tendermint/mempool/clist_mempool.go +++ b/libs/tendermint/mempool/clist_mempool.go @@ -1000,9 +1000,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) @@ -1246,6 +1243,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 f53b6ff24..e9aabbecb 100644 --- a/libs/tendermint/state/execution.go +++ b/libs/tendermint/state/execution.go @@ -457,6 +457,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 {