Skip to content

Commit

Permalink
chore: add debug log
Browse files Browse the repository at this point in the history
  • Loading branch information
irrun committed Apr 11, 2024
1 parent a796b44 commit 0a92d9f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
15 changes: 10 additions & 5 deletions miner/bid_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,16 @@ 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 {
simDuration = lastBid.duration
}

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
}

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

Expand Down Expand Up @@ -378,6 +382,7 @@ func (b *bidSimulator) newBidLoop() {
continue
}

log.Debug("BidSimulator: lower reward, ignore", "bidHash", newBid.Hash().Hex())
continue
}

Expand All @@ -389,6 +394,7 @@ func (b *bidSimulator) newBidLoop() {
continue
}

log.Debug("BidSimulator: lower reward, ignore", "bidHash", newBid.Hash().Hex())
case <-b.exitCh:
return
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
}
Expand Down

0 comments on commit 0a92d9f

Please sign in to comment.