Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify SimTx SimGasUsed log print and add isAVCProducer #3237

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions libs/tendermint/consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
}
Expand Down
9 changes: 8 additions & 1 deletion libs/tendermint/consensus/consensus_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Expand Down Expand Up @@ -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 &&
Expand Down Expand Up @@ -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()
Expand Down
9 changes: 6 additions & 3 deletions libs/tendermint/consensus/consensus_main_routine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

//-----------------------------------------
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion libs/tendermint/consensus/consensus_propose.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
23 changes: 19 additions & 4 deletions libs/tendermint/mempool/clist_mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down
12 changes: 11 additions & 1 deletion libs/tendermint/state/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -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 {
Expand Down