From da2aed8fda3ee77a0f9478095ce5e99b82af155b Mon Sep 17 00:00:00 2001 From: Raina Date: Mon, 5 Feb 2024 10:36:37 +0800 Subject: [PATCH] fix: bugs when mining (#9) * fix: bugs when mining --- miner/bidder.go | 7 +++++-- miner/miner.go | 3 +-- miner/worker.go | 2 -- miner/worker_builder.go | 9 +++++++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/miner/bidder.go b/miner/bidder.go index a67750738f..85a8cd460e 100644 --- a/miner/bidder.go +++ b/miner/bidder.go @@ -6,8 +6,11 @@ import ( "fmt" "net" "net/http" + "sync" "time" + "golang.org/x/exp/slices" + "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" @@ -18,8 +21,6 @@ import ( "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rpc" - "golang.org/x/exp/slices" - "sync" ) var ( @@ -226,6 +227,8 @@ func (b *Bidder) bid(work *environment) { } log.Debug("Bidder: bidding success") + + return } // signBid signs the bid with builder's account diff --git a/miner/miner.go b/miner/miner.go index 676bb78858..4baa6a4de0 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -278,7 +278,6 @@ func (miner *Miner) BuildPayload(args *BuildPayloadArgs) (*Payload, error) { func (miner *Miner) SimulateBundle(bundle *types.Bundle) (*big.Int, error) { parent := miner.eth.BlockChain().CurrentBlock() - num := parent.Number timestamp := time.Now().Unix() if parent.Time >= uint64(timestamp) { timestamp = int64(parent.Time + 1) @@ -286,7 +285,7 @@ func (miner *Miner) SimulateBundle(bundle *types.Bundle) (*big.Int, error) { header := &types.Header{ ParentHash: parent.Hash(), - Number: num.Add(num, common.Big1), + Number: new(big.Int).Add(parent.Number, common.Big1), GasLimit: core.CalcGasLimit(parent.GasLimit, miner.Worker.config.GasCeil), Extra: miner.Worker.extra, Time: uint64(timestamp), diff --git a/miner/worker.go b/miner/worker.go index 982d506664..3d1a720b24 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -425,7 +425,6 @@ func (w *worker) newWorkLoop(recommit time.Duration) { } for { - log.Info("worker newLoop running...") select { case <-w.startCh: clearPending(w.chain.CurrentBlock().Number.Uint64()) @@ -433,7 +432,6 @@ func (w *worker) newWorkLoop(recommit time.Duration) { commit(commitInterruptNewHead) case head := <-w.chainHeadCh: - log.Info("worker received new head", "number", head.Block.NumberU64(), "running", w.isRunning()) if !w.isRunning() { continue } diff --git a/miner/worker_builder.go b/miner/worker_builder.go index fd7d05d03e..3d92206f56 100644 --- a/miner/worker_builder.go +++ b/miner/worker_builder.go @@ -30,6 +30,9 @@ func (w *worker) commitWorkV2(interruptCh chan int32, timestamp int64) { // fillTransactions retrieves the pending bundles and transactions from the txpool and fills them // into the given sealing block. The selection and ordering strategy can be extended in the future. func (w *worker) fillTransactionsAndBundles(interruptCh chan int32, env *environment, stopTimer *time.Timer) error { + env.blockReward = new(big.Int) + env.profit = new(big.Int) + var ( pending map[common.Address][]*txpool.LazyTransaction localTxs map[common.Address][]*txpool.LazyTransaction @@ -303,8 +306,10 @@ func (w *worker) mergeBundles( includedTxs := types.Transactions{} mergedBundle := types.SimulatedBundle{ - BundleGasUsed: 0, - BundleGasPrice: new(big.Int), + BundleGasFees: new(big.Int), + BundleGasUsed: 0, + BundleGasPrice: new(big.Int), + EthSentToSystem: new(big.Int), } for _, bundle := range bundles {