Skip to content

Commit

Permalink
fix: bugs when mining (#9)
Browse files Browse the repository at this point in the history
* fix: bugs when mining
  • Loading branch information
Raina authored Feb 5, 2024
1 parent 991826c commit da2aed8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
7 changes: 5 additions & 2 deletions miner/bidder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 (
Expand Down Expand Up @@ -226,6 +227,8 @@ func (b *Bidder) bid(work *environment) {
}

log.Debug("Bidder: bidding success")

return
}

// signBid signs the bid with builder's account
Expand Down
3 changes: 1 addition & 2 deletions miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,14 @@ 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)
}

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),
Expand Down
2 changes: 0 additions & 2 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,15 +425,13 @@ func (w *worker) newWorkLoop(recommit time.Duration) {
}

for {
log.Info("worker newLoop running...")
select {
case <-w.startCh:
clearPending(w.chain.CurrentBlock().Number.Uint64())
timestamp = time.Now().Unix()
commit(commitInterruptNewHead)

case head := <-w.chainHeadCh:
log.Info("worker received new head", "number", head.Block.NumberU64(), "running", w.isRunning())
if !w.isRunning() {
continue
}
Expand Down
9 changes: 7 additions & 2 deletions miner/worker_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit da2aed8

Please sign in to comment.