mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
miner: fixed miner
This commit is contained in:
parent
1684eaec99
commit
cb7c81ffdf
4 changed files with 31 additions and 37 deletions
|
|
@ -132,7 +132,7 @@ func NewDBForFakes(t TensingObject) (ethdb.Database, *core.Genesis, *params.Chai
|
|||
addr := common.HexToAddress("12345")
|
||||
genesis := core.DeveloperGenesisBlock(11_500_000, &addr)
|
||||
|
||||
chainConfig, _, err := core.SetupGenesisBlock(chainDB, triedb.NewDatabase(chainDB, triedb.HashDefaults), genesis)
|
||||
chainConfig, _, err, _ := core.SetupGenesisBlock(chainDB, triedb.NewDatabase(chainDB, triedb.HashDefaults), genesis)
|
||||
if err != nil {
|
||||
t.Fatalf("can't create new chain config: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -254,6 +254,7 @@ func (miner *Miner) SetEtherbase(addr common.Address) {
|
|||
func (miner *Miner) SetPrioAddresses(prio []common.Address) {
|
||||
miner.confMu.Lock()
|
||||
miner.prio = prio
|
||||
miner.worker.prio = miner.prio
|
||||
miner.confMu.Unlock()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -207,6 +207,8 @@ type worker struct {
|
|||
eth Backend
|
||||
chain *core.BlockChain
|
||||
|
||||
prio []common.Address // A list of senders to prioritize
|
||||
|
||||
// Feeds
|
||||
pendingLogsFeed event.Feed
|
||||
|
||||
|
|
@ -860,7 +862,7 @@ func (w *worker) makeEnv(parent *types.Header, header *types.Header, coinbase co
|
|||
coinbase: coinbase,
|
||||
header: header,
|
||||
witness: state.Witness(),
|
||||
evm: vm.NewEVM(core.NewEVMBlockContext(header, miner.chain, &coinbase), state, miner.chainConfig, vm.Config{}),
|
||||
evm: vm.NewEVM(core.NewEVMBlockContext(header, w.chain, &coinbase), state, w.chainConfig, vm.Config{}),
|
||||
}
|
||||
// Keep track of transactions which return errors so they can be removed
|
||||
env.tcount = 0
|
||||
|
|
@ -980,7 +982,7 @@ mainloop:
|
|||
}
|
||||
// If we don't have enough blob space for any further blob transactions,
|
||||
// skip that list altogether
|
||||
if !blobTxs.Empty() && env.blobs >= eip4844.MaxBlobsPerBlock(miner.chainConfig, env.header.Time) {
|
||||
if !blobTxs.Empty() && env.blobs >= eip4844.MaxBlobsPerBlock(w.chainConfig, env.header.Time) {
|
||||
log.Trace("Not enough blob space for further blob transactions")
|
||||
blobTxs.Clear()
|
||||
// Fall though to pick up any plain txs
|
||||
|
|
@ -1020,8 +1022,8 @@ mainloop:
|
|||
// Most of the blob gas logic here is agnostic as to if the chain supports
|
||||
// blobs or not, however the max check panics when called on a chain without
|
||||
// a defined schedule, so we need to verify it's safe to call.
|
||||
if miner.chainConfig.IsCancun(env.header.Number, env.header.Time) {
|
||||
left := eip4844.MaxBlobsPerBlock(miner.chainConfig, env.header.Time) - env.blobs
|
||||
if w.chainConfig.IsCancun(env.header.Number) {
|
||||
left := eip4844.MaxBlobsPerBlock(w.chainConfig, env.header.Time) - env.blobs
|
||||
if left < int(ltx.BlobGas/params.BlobTxBlobGasPerBlob) {
|
||||
log.Trace("Not enough blob space left for transaction", "hash", ltx.Hash, "left", left, "needed", ltx.BlobGas/params.BlobTxBlobGasPerBlob)
|
||||
txs.Pop()
|
||||
|
|
@ -1307,12 +1309,12 @@ func (w *worker) prepareWork(genParams *generateParams, witness bool) (*environm
|
|||
if header.ParentBeaconRoot != nil {
|
||||
context := core.NewEVMBlockContext(header, w.chain, nil)
|
||||
vmenv := vm.NewEVM(context, env.state, w.chainConfig, vm.Config{})
|
||||
core.ProcessBeaconBlockRoot(*header.ParentBeaconRoot, vmenv, env.state)
|
||||
core.ProcessBeaconBlockRoot(*header.ParentBeaconRoot, vmenv)
|
||||
}
|
||||
if w.chainConfig.IsPrague(header.Number) {
|
||||
context := core.NewEVMBlockContext(header, w.chain, nil)
|
||||
vmenv := vm.NewEVM(context, env.state, w.chainConfig, vm.Config{})
|
||||
core.ProcessParentBlockHash(header.ParentHash, vmenv, env.state)
|
||||
core.ProcessParentBlockHash(header.ParentHash, vmenv)
|
||||
}
|
||||
return env, nil
|
||||
}
|
||||
|
|
@ -1324,14 +1326,10 @@ func (w *worker) prepareWork(genParams *generateParams, witness bool) (*environm
|
|||
//
|
||||
//nolint:gocognit
|
||||
func (w *worker) fillTransactions(interrupt *atomic.Int32, env *environment) error {
|
||||
// TODO(@pratikspatil024) - review these locks and tip/prio
|
||||
miner.confMu.RLock()
|
||||
w.mu.RLock()
|
||||
tip := w.tip
|
||||
tip := miner.config.GasPrice
|
||||
prio := miner.prio
|
||||
prio := w.prio
|
||||
w.mu.RUnlock()
|
||||
miner.confMu.RUnlock()
|
||||
|
||||
// Retrieve the pending transactions pre-filtered by the 1559/4844 dynamic fees
|
||||
filter := txpool.PendingFilter{
|
||||
|
|
@ -1343,7 +1341,7 @@ func (w *worker) fillTransactions(interrupt *atomic.Int32, env *environment) err
|
|||
}
|
||||
|
||||
if env.header.ExcessBlobGas != nil {
|
||||
filter.BlobFee = uint256.MustFromBig(eip4844.CalcBlobFee(miner.chainConfig, env.header))
|
||||
filter.BlobFee = uint256.MustFromBig(eip4844.CalcBlobFee(w.chainConfig, env.header))
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
@ -1430,20 +1428,17 @@ func (w *worker) generateWork(params *generateParams, witness bool) *newPayloadR
|
|||
var requests [][]byte
|
||||
if w.chainConfig.IsPrague(work.header.Number) && w.chainConfig.Bor == nil {
|
||||
// EIP-6110 deposits
|
||||
depositRequests, err := core.ParseDepositLogs(allLogs, w.chainConfig)
|
||||
err := core.ParseDepositLogs(&requests, allLogs, w.chainConfig)
|
||||
if err != nil {
|
||||
return &newPayloadResult{err: err}
|
||||
}
|
||||
requests = append(requests, depositRequests)
|
||||
// create EVM for system calls
|
||||
blockContext := core.NewEVMBlockContext(work.header, w.chain, &work.header.Coinbase)
|
||||
vmenv := vm.NewEVM(blockContext, work.state, w.chainConfig, vm.Config{})
|
||||
// EIP-7002 withdrawals
|
||||
withdrawalRequests := core.ProcessWithdrawalQueue(vmenv, work.state)
|
||||
requests = append(requests, withdrawalRequests)
|
||||
core.ProcessWithdrawalQueue(&requests, vmenv)
|
||||
// EIP-7251 consolidations
|
||||
consolidationRequests := core.ProcessConsolidationQueue(vmenv, work.state)
|
||||
requests = append(requests, consolidationRequests)
|
||||
core.ProcessConsolidationQueue(&requests, vmenv)
|
||||
}
|
||||
if requests != nil {
|
||||
reqHash := types.CalcRequestsHash(requests)
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ func testGenerateBlockAndImport(t *testing.T, isClique bool, isBor bool) {
|
|||
// []*types.Transaction{tx}
|
||||
var i uint64
|
||||
for i = 0; i < 5; i++ {
|
||||
err = b.txPool.Add([]*types.Transaction{b.newRandomTxWithNonce(true, i)}, true, false)[0]
|
||||
err = b.txPool.Add([]*types.Transaction{b.newRandomTxWithNonce(true, i)}, false)[0]
|
||||
if err != nil {
|
||||
t.Fatal("while adding a local transaction", err)
|
||||
}
|
||||
|
|
@ -128,7 +128,7 @@ func testGenerateBlockAndImport(t *testing.T, isClique bool, isBor bool) {
|
|||
}
|
||||
|
||||
for i = 5; i < 10; i++ {
|
||||
err = b.txPool.Add([]*types.Transaction{b.newRandomTxWithNonce(false, i)}, true, false)[0]
|
||||
err = b.txPool.Add([]*types.Transaction{b.newRandomTxWithNonce(false, i)}, false)[0]
|
||||
if err != nil {
|
||||
t.Fatal("while adding a remote transaction", err)
|
||||
}
|
||||
|
|
@ -239,9 +239,7 @@ func newTestWorkerBackend(t TensingObject, chainConfig *params.ChainConfig, engi
|
|||
case *clique.Clique:
|
||||
gspec.ExtraData = make([]byte, 32+common.AddressLength+crypto.SignatureLength)
|
||||
copy(gspec.ExtraData[32:32+common.AddressLength], testBankAddress.Bytes())
|
||||
e.Authorize(testBankAddress, func(account accounts.Account, s string, data []byte) ([]byte, error) {
|
||||
return crypto.Sign(crypto.Keccak256(data), testBankKey)
|
||||
})
|
||||
e.Authorize(testBankAddress)
|
||||
case *ethash.Ethash:
|
||||
default:
|
||||
t.Fatalf("unexpected consensus engine type: %T", engine)
|
||||
|
|
@ -319,7 +317,7 @@ func (b *testWorkerBackend) newStorageContractCallTx(to common.Address, nonce ui
|
|||
|
||||
func newTestWorker(t TensingObject, chainConfig *params.ChainConfig, engine consensus.Engine, db ethdb.Database, noempty bool, delay uint, opcodeDelay uint) (*worker, *testWorkerBackend, func()) {
|
||||
backend := newTestWorkerBackend(t, chainConfig, engine, db)
|
||||
backend.txPool.Add(pendingTxs, true, false)
|
||||
backend.txPool.Add(pendingTxs, false)
|
||||
w := newWorker(testConfig, chainConfig, engine, backend, new(event.TypeMux), nil, false)
|
||||
if delay != 0 || opcodeDelay != 0 {
|
||||
w.setInterruptCtx(vm.InterruptCtxDelayKey, delay)
|
||||
|
|
@ -360,8 +358,8 @@ func TestGenerateAndImportBlock(t *testing.T) {
|
|||
w.start()
|
||||
|
||||
for i := 0; i < 5; i++ {
|
||||
b.txPool.Add([]*types.Transaction{b.newRandomTx(true)}, true, false)
|
||||
b.txPool.Add([]*types.Transaction{b.newRandomTx(false)}, true, false)
|
||||
b.txPool.Add([]*types.Transaction{b.newRandomTx(true)}, false)
|
||||
b.txPool.Add([]*types.Transaction{b.newRandomTx(false)}, false)
|
||||
|
||||
select {
|
||||
case ev := <-sub.Chan():
|
||||
|
|
@ -754,7 +752,7 @@ func testCommitInterruptExperimentBorContract(t *testing.T, delay uint, txCount
|
|||
|
||||
// nonce 0 tx
|
||||
tx, addr := b.newStorageCreateContractTx()
|
||||
if err := b.txPool.Add([]*types.Transaction{tx}, false, false)[0]; err != nil {
|
||||
if err := b.txPool.Add([]*types.Transaction{tx}, false)[0]; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
|
@ -771,7 +769,7 @@ func testCommitInterruptExperimentBorContract(t *testing.T, delay uint, txCount
|
|||
wrapped := make([]*types.Transaction, len(txs))
|
||||
copy(wrapped, txs)
|
||||
|
||||
b.TxPool().Add(wrapped, false, false)
|
||||
b.TxPool().Add(wrapped, false)
|
||||
|
||||
// Start mining!
|
||||
w.start()
|
||||
|
|
@ -823,7 +821,7 @@ func testCommitInterruptExperimentBor(t *testing.T, delay uint, txCount int, opc
|
|||
wrapped[i] = tx
|
||||
}
|
||||
|
||||
b.TxPool().Add(wrapped, false, false)
|
||||
b.TxPool().Add(wrapped, false)
|
||||
|
||||
// Start mining!
|
||||
w.start()
|
||||
|
|
@ -883,7 +881,7 @@ func TestCommitInterruptExperimentBor_NewTxFlow(t *testing.T) {
|
|||
w.stop()
|
||||
|
||||
// Add the first transaction to be mined normally via `txsCh`
|
||||
b.TxPool().Add([]*types.Transaction{tx1}, false, false)
|
||||
b.TxPool().Add([]*types.Transaction{tx1}, false)
|
||||
|
||||
// Set it to syncing mode so that it doesn't mine via the `commitWork` flow
|
||||
w.syncing.Store(true)
|
||||
|
|
@ -901,7 +899,7 @@ func TestCommitInterruptExperimentBor_NewTxFlow(t *testing.T) {
|
|||
w.setInterruptCtx(vm.InterruptCtxOpcodeDelayKey, uint(500))
|
||||
|
||||
// Send the second transaction
|
||||
b.TxPool().Add([]*types.Transaction{tx2}, false, false)
|
||||
b.TxPool().Add([]*types.Transaction{tx2}, false)
|
||||
|
||||
// Reset the delay again. By this time, we're sure that it has timed out.
|
||||
delay = time.Until(time.Unix(int64(w.current.header.Time), 0))
|
||||
|
|
@ -914,7 +912,7 @@ func TestCommitInterruptExperimentBor_NewTxFlow(t *testing.T) {
|
|||
w.setInterruptCtx(vm.InterruptCtxOpcodeDelayKey, uint(0))
|
||||
|
||||
// Send the third transaction
|
||||
b.TxPool().Add([]*types.Transaction{tx3}, false, false)
|
||||
b.TxPool().Add([]*types.Transaction{tx3}, false)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
|
@ -977,12 +975,12 @@ func BenchmarkBorMining(b *testing.B) {
|
|||
|
||||
// a bit risky
|
||||
for i := 0; i < 2*totalBlocks*txInBlock; i++ {
|
||||
err = back.txPool.Add([]*types.Transaction{back.newRandomTx(true)}, true, false)[0]
|
||||
err = back.txPool.Add([]*types.Transaction{back.newRandomTx(true)}, false)[0]
|
||||
if err != nil {
|
||||
b.Fatal("while adding a local transaction", err)
|
||||
}
|
||||
|
||||
err = back.txPool.Add([]*types.Transaction{back.newRandomTx(false)}, false, false)[0]
|
||||
err = back.txPool.Add([]*types.Transaction{back.newRandomTx(false)}, false)[0]
|
||||
if err != nil {
|
||||
b.Fatal("while adding a remote transaction", err)
|
||||
}
|
||||
|
|
@ -1083,12 +1081,12 @@ func BenchmarkBorMiningBlockSTMMetadata(b *testing.B) {
|
|||
|
||||
// a bit risky
|
||||
for i := 0; i < 2*totalBlocks*txInBlock; i++ {
|
||||
err = back.txPool.Add([]*types.Transaction{back.newRandomTx(true)}, true, false)[0]
|
||||
err = back.txPool.Add([]*types.Transaction{back.newRandomTx(true)}, false)[0]
|
||||
if err != nil {
|
||||
b.Fatal("while adding a local transaction", err)
|
||||
}
|
||||
|
||||
err = back.txPool.Add([]*types.Transaction{back.newRandomTx(false)}, false, false)[0]
|
||||
err = back.txPool.Add([]*types.Transaction{back.newRandomTx(false)}, false)[0]
|
||||
if err != nil {
|
||||
b.Fatal("while adding a remote transaction", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue