From 0a92d9fa04c6d5f743302f29bcb081cf1cd1b1ca Mon Sep 17 00:00:00 2001 From: irrun Date: Wed, 10 Apr 2024 11:06:39 +0800 Subject: [PATCH] chore: add debug log --- miner/bid_simulator.go | 15 ++++++++++----- miner/worker.go | 12 ++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/miner/bid_simulator.go b/miner/bid_simulator.go index 4aa8458f7e..0831922501 100644 --- a/miner/bid_simulator.go +++ b/miner/bid_simulator.go @@ -311,6 +311,8 @@ func (b *bidSimulator) newBidLoop() { // commit aborts in-flight bid execution with given signal and resubmits a new one. commit := func(reason int32, bidRuntime *BidRuntime) { + log.Debug("BidSimulator: start", "bidHash", bidRuntime.bid.Hash().Hex()) + // if the left time is not enough to do simulation, return var simDuration time.Duration if lastBid := b.GetBestBid(bidRuntime.bid.ParentHash); lastBid != nil && lastBid.duration != 0 { @@ -318,6 +320,7 @@ func (b *bidSimulator) newBidLoop() { } if time.Until(b.bidMustBefore(bidRuntime.bid.ParentHash)) <= simDuration*leftOverTimeRate/leftOverTimeScale { + log.Debug("BidSimulator: abort commit, not enough time to simulate", "bidHash", bidRuntime.bid.Hash().Hex()) return } @@ -349,6 +352,7 @@ func (b *bidSimulator) newBidLoop() { if expectedValidatorReward.Cmp(big.NewInt(0)) < 0 { // damage self profit, ignore + log.Debug("BidSimulator: invalid bid, validator reward is less than 0, ignore", "bidHash", newBid.Hash().Hex()) continue } @@ -378,6 +382,7 @@ func (b *bidSimulator) newBidLoop() { continue } + log.Debug("BidSimulator: lower reward, ignore", "bidHash", newBid.Hash().Hex()) continue } @@ -389,6 +394,7 @@ func (b *bidSimulator) newBidLoop() { continue } + log.Debug("BidSimulator: lower reward, ignore", "bidHash", newBid.Hash().Hex()) case <-b.exitCh: return } @@ -535,7 +541,7 @@ func (b *bidSimulator) simBid(interruptCh chan int32, bidRuntime *BidRuntime) { if err != nil { logCtx = append(logCtx, "err", err) - log.Debug("bid simulation failed", logCtx...) + log.Info("BidSimulator: simulation failed", logCtx...) go b.reportIssue(bidRuntime, err) } @@ -606,7 +612,7 @@ func (b *bidSimulator) simBid(interruptCh chan int32, bidRuntime *BidRuntime) { if b.config.GreedyMergeTx { delay := b.engine.Delay(b.chain, bidRuntime.env.header, &b.delayLeftOver) if delay != nil && *delay > 0 { - log.Debug("BidSimulator: GreedyMergeTx stopTimer", "block", bidRuntime.env.header.Number, + log.Debug("BidSimulator: greedy merge tx stopTimer", "block", bidRuntime.env.header.Number, "header time", time.Until(time.Unix(int64(bidRuntime.env.header.Time), 0)), "commit delay", *delay, "DelayLeftOver", b.delayLeftOver) @@ -618,9 +624,8 @@ func (b *bidSimulator) simBid(interruptCh chan int32, bidRuntime *BidRuntime) { } fillErr := b.bidWorker.fillTransactions(interruptCh, bidRuntime.env, stopTimer, bidTxsSet) - if fillErr != nil { - log.Debug("BidSimulator: GreedyMergeTx fillTransactions", "block", bidRuntime.env.header.Number, "err", fillErr) - } + log.Info("BidSimulator: greedy merge tx fill transactions", "block", bidRuntime.env.header.Number, + "tx count", bidRuntime.env.tcount-bidTxLen+1, "err", fillErr) // recalculate the packed reward bidRuntime.packReward(b.config.ValidatorCommission) diff --git a/miner/worker.go b/miner/worker.go index 5105548cb7..44352c42d6 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -1331,15 +1331,27 @@ LOOP: if w.bidFetcher != nil && bestWork.header.Difficulty.Cmp(diffInTurn) == 0 { bestBid := w.bidFetcher.GetBestBid(bestWork.header.ParentHash) + if bestBid != nil { + log.Debug("BidSimulator: final compare", "block", bestWork.header.Number.Uint64(), + "localBlockReward", bestReward.String(), + "bidBlockReward", bestBid.packedBlockReward.String()) + } + if bestBid != nil && bestReward.CmpBig(bestBid.packedBlockReward) < 0 { // localValidatorReward is the reward for the validator self by the local block. localValidatorReward := new(uint256.Int).Mul(bestReward, uint256.NewInt(w.config.Mev.ValidatorCommission)) localValidatorReward.Div(localValidatorReward, uint256.NewInt(10000)) + log.Debug("BidSimulator: final compare", "block", bestWork.header.Number.Uint64(), + "localValidatorReward", localValidatorReward.String(), + "bidValidatorReward", bestBid.packedValidatorReward.String()) + // blockReward(benefits delegators) and validatorReward(benefits the validator) are both optimal if localValidatorReward.CmpBig(bestBid.packedValidatorReward) < 0 { bestWork = bestBid.env from = bestBid.bid.Builder + + log.Debug("BidSimulator: bid win", "block", bestWork.header.Number.Uint64(), "bid", bestBid.bid.Hash()) } } }