mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +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")
|
addr := common.HexToAddress("12345")
|
||||||
genesis := core.DeveloperGenesisBlock(11_500_000, &addr)
|
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 {
|
if err != nil {
|
||||||
t.Fatalf("can't create new chain config: %v", err)
|
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) {
|
func (miner *Miner) SetPrioAddresses(prio []common.Address) {
|
||||||
miner.confMu.Lock()
|
miner.confMu.Lock()
|
||||||
miner.prio = prio
|
miner.prio = prio
|
||||||
|
miner.worker.prio = miner.prio
|
||||||
miner.confMu.Unlock()
|
miner.confMu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -207,6 +207,8 @@ type worker struct {
|
||||||
eth Backend
|
eth Backend
|
||||||
chain *core.BlockChain
|
chain *core.BlockChain
|
||||||
|
|
||||||
|
prio []common.Address // A list of senders to prioritize
|
||||||
|
|
||||||
// Feeds
|
// Feeds
|
||||||
pendingLogsFeed event.Feed
|
pendingLogsFeed event.Feed
|
||||||
|
|
||||||
|
|
@ -860,7 +862,7 @@ func (w *worker) makeEnv(parent *types.Header, header *types.Header, coinbase co
|
||||||
coinbase: coinbase,
|
coinbase: coinbase,
|
||||||
header: header,
|
header: header,
|
||||||
witness: state.Witness(),
|
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
|
// Keep track of transactions which return errors so they can be removed
|
||||||
env.tcount = 0
|
env.tcount = 0
|
||||||
|
|
@ -980,7 +982,7 @@ mainloop:
|
||||||
}
|
}
|
||||||
// If we don't have enough blob space for any further blob transactions,
|
// If we don't have enough blob space for any further blob transactions,
|
||||||
// skip that list altogether
|
// 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")
|
log.Trace("Not enough blob space for further blob transactions")
|
||||||
blobTxs.Clear()
|
blobTxs.Clear()
|
||||||
// Fall though to pick up any plain txs
|
// 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
|
// 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
|
// 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.
|
// a defined schedule, so we need to verify it's safe to call.
|
||||||
if miner.chainConfig.IsCancun(env.header.Number, env.header.Time) {
|
if w.chainConfig.IsCancun(env.header.Number) {
|
||||||
left := eip4844.MaxBlobsPerBlock(miner.chainConfig, env.header.Time) - env.blobs
|
left := eip4844.MaxBlobsPerBlock(w.chainConfig, env.header.Time) - env.blobs
|
||||||
if left < int(ltx.BlobGas/params.BlobTxBlobGasPerBlob) {
|
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)
|
log.Trace("Not enough blob space left for transaction", "hash", ltx.Hash, "left", left, "needed", ltx.BlobGas/params.BlobTxBlobGasPerBlob)
|
||||||
txs.Pop()
|
txs.Pop()
|
||||||
|
|
@ -1307,12 +1309,12 @@ func (w *worker) prepareWork(genParams *generateParams, witness bool) (*environm
|
||||||
if header.ParentBeaconRoot != nil {
|
if header.ParentBeaconRoot != nil {
|
||||||
context := core.NewEVMBlockContext(header, w.chain, nil)
|
context := core.NewEVMBlockContext(header, w.chain, nil)
|
||||||
vmenv := vm.NewEVM(context, env.state, w.chainConfig, vm.Config{})
|
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) {
|
if w.chainConfig.IsPrague(header.Number) {
|
||||||
context := core.NewEVMBlockContext(header, w.chain, nil)
|
context := core.NewEVMBlockContext(header, w.chain, nil)
|
||||||
vmenv := vm.NewEVM(context, env.state, w.chainConfig, vm.Config{})
|
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
|
return env, nil
|
||||||
}
|
}
|
||||||
|
|
@ -1324,14 +1326,10 @@ func (w *worker) prepareWork(genParams *generateParams, witness bool) (*environm
|
||||||
//
|
//
|
||||||
//nolint:gocognit
|
//nolint:gocognit
|
||||||
func (w *worker) fillTransactions(interrupt *atomic.Int32, env *environment) error {
|
func (w *worker) fillTransactions(interrupt *atomic.Int32, env *environment) error {
|
||||||
// TODO(@pratikspatil024) - review these locks and tip/prio
|
|
||||||
miner.confMu.RLock()
|
|
||||||
w.mu.RLock()
|
w.mu.RLock()
|
||||||
tip := w.tip
|
tip := w.tip
|
||||||
tip := miner.config.GasPrice
|
prio := w.prio
|
||||||
prio := miner.prio
|
|
||||||
w.mu.RUnlock()
|
w.mu.RUnlock()
|
||||||
miner.confMu.RUnlock()
|
|
||||||
|
|
||||||
// Retrieve the pending transactions pre-filtered by the 1559/4844 dynamic fees
|
// Retrieve the pending transactions pre-filtered by the 1559/4844 dynamic fees
|
||||||
filter := txpool.PendingFilter{
|
filter := txpool.PendingFilter{
|
||||||
|
|
@ -1343,7 +1341,7 @@ func (w *worker) fillTransactions(interrupt *atomic.Int32, env *environment) err
|
||||||
}
|
}
|
||||||
|
|
||||||
if env.header.ExcessBlobGas != nil {
|
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 (
|
var (
|
||||||
|
|
@ -1430,20 +1428,17 @@ func (w *worker) generateWork(params *generateParams, witness bool) *newPayloadR
|
||||||
var requests [][]byte
|
var requests [][]byte
|
||||||
if w.chainConfig.IsPrague(work.header.Number) && w.chainConfig.Bor == nil {
|
if w.chainConfig.IsPrague(work.header.Number) && w.chainConfig.Bor == nil {
|
||||||
// EIP-6110 deposits
|
// EIP-6110 deposits
|
||||||
depositRequests, err := core.ParseDepositLogs(allLogs, w.chainConfig)
|
err := core.ParseDepositLogs(&requests, allLogs, w.chainConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &newPayloadResult{err: err}
|
return &newPayloadResult{err: err}
|
||||||
}
|
}
|
||||||
requests = append(requests, depositRequests)
|
|
||||||
// create EVM for system calls
|
// create EVM for system calls
|
||||||
blockContext := core.NewEVMBlockContext(work.header, w.chain, &work.header.Coinbase)
|
blockContext := core.NewEVMBlockContext(work.header, w.chain, &work.header.Coinbase)
|
||||||
vmenv := vm.NewEVM(blockContext, work.state, w.chainConfig, vm.Config{})
|
vmenv := vm.NewEVM(blockContext, work.state, w.chainConfig, vm.Config{})
|
||||||
// EIP-7002 withdrawals
|
// EIP-7002 withdrawals
|
||||||
withdrawalRequests := core.ProcessWithdrawalQueue(vmenv, work.state)
|
core.ProcessWithdrawalQueue(&requests, vmenv)
|
||||||
requests = append(requests, withdrawalRequests)
|
|
||||||
// EIP-7251 consolidations
|
// EIP-7251 consolidations
|
||||||
consolidationRequests := core.ProcessConsolidationQueue(vmenv, work.state)
|
core.ProcessConsolidationQueue(&requests, vmenv)
|
||||||
requests = append(requests, consolidationRequests)
|
|
||||||
}
|
}
|
||||||
if requests != nil {
|
if requests != nil {
|
||||||
reqHash := types.CalcRequestsHash(requests)
|
reqHash := types.CalcRequestsHash(requests)
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ func testGenerateBlockAndImport(t *testing.T, isClique bool, isBor bool) {
|
||||||
// []*types.Transaction{tx}
|
// []*types.Transaction{tx}
|
||||||
var i uint64
|
var i uint64
|
||||||
for i = 0; i < 5; i++ {
|
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 {
|
if err != nil {
|
||||||
t.Fatal("while adding a local transaction", err)
|
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++ {
|
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 {
|
if err != nil {
|
||||||
t.Fatal("while adding a remote transaction", err)
|
t.Fatal("while adding a remote transaction", err)
|
||||||
}
|
}
|
||||||
|
|
@ -239,9 +239,7 @@ func newTestWorkerBackend(t TensingObject, chainConfig *params.ChainConfig, engi
|
||||||
case *clique.Clique:
|
case *clique.Clique:
|
||||||
gspec.ExtraData = make([]byte, 32+common.AddressLength+crypto.SignatureLength)
|
gspec.ExtraData = make([]byte, 32+common.AddressLength+crypto.SignatureLength)
|
||||||
copy(gspec.ExtraData[32:32+common.AddressLength], testBankAddress.Bytes())
|
copy(gspec.ExtraData[32:32+common.AddressLength], testBankAddress.Bytes())
|
||||||
e.Authorize(testBankAddress, func(account accounts.Account, s string, data []byte) ([]byte, error) {
|
e.Authorize(testBankAddress)
|
||||||
return crypto.Sign(crypto.Keccak256(data), testBankKey)
|
|
||||||
})
|
|
||||||
case *ethash.Ethash:
|
case *ethash.Ethash:
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unexpected consensus engine type: %T", engine)
|
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()) {
|
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 := 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)
|
w := newWorker(testConfig, chainConfig, engine, backend, new(event.TypeMux), nil, false)
|
||||||
if delay != 0 || opcodeDelay != 0 {
|
if delay != 0 || opcodeDelay != 0 {
|
||||||
w.setInterruptCtx(vm.InterruptCtxDelayKey, delay)
|
w.setInterruptCtx(vm.InterruptCtxDelayKey, delay)
|
||||||
|
|
@ -360,8 +358,8 @@ func TestGenerateAndImportBlock(t *testing.T) {
|
||||||
w.start()
|
w.start()
|
||||||
|
|
||||||
for i := 0; i < 5; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
b.txPool.Add([]*types.Transaction{b.newRandomTx(true)}, true, false)
|
b.txPool.Add([]*types.Transaction{b.newRandomTx(true)}, false)
|
||||||
b.txPool.Add([]*types.Transaction{b.newRandomTx(false)}, true, false)
|
b.txPool.Add([]*types.Transaction{b.newRandomTx(false)}, false)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case ev := <-sub.Chan():
|
case ev := <-sub.Chan():
|
||||||
|
|
@ -754,7 +752,7 @@ func testCommitInterruptExperimentBorContract(t *testing.T, delay uint, txCount
|
||||||
|
|
||||||
// nonce 0 tx
|
// nonce 0 tx
|
||||||
tx, addr := b.newStorageCreateContractTx()
|
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)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -771,7 +769,7 @@ func testCommitInterruptExperimentBorContract(t *testing.T, delay uint, txCount
|
||||||
wrapped := make([]*types.Transaction, len(txs))
|
wrapped := make([]*types.Transaction, len(txs))
|
||||||
copy(wrapped, txs)
|
copy(wrapped, txs)
|
||||||
|
|
||||||
b.TxPool().Add(wrapped, false, false)
|
b.TxPool().Add(wrapped, false)
|
||||||
|
|
||||||
// Start mining!
|
// Start mining!
|
||||||
w.start()
|
w.start()
|
||||||
|
|
@ -823,7 +821,7 @@ func testCommitInterruptExperimentBor(t *testing.T, delay uint, txCount int, opc
|
||||||
wrapped[i] = tx
|
wrapped[i] = tx
|
||||||
}
|
}
|
||||||
|
|
||||||
b.TxPool().Add(wrapped, false, false)
|
b.TxPool().Add(wrapped, false)
|
||||||
|
|
||||||
// Start mining!
|
// Start mining!
|
||||||
w.start()
|
w.start()
|
||||||
|
|
@ -883,7 +881,7 @@ func TestCommitInterruptExperimentBor_NewTxFlow(t *testing.T) {
|
||||||
w.stop()
|
w.stop()
|
||||||
|
|
||||||
// Add the first transaction to be mined normally via `txsCh`
|
// 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
|
// Set it to syncing mode so that it doesn't mine via the `commitWork` flow
|
||||||
w.syncing.Store(true)
|
w.syncing.Store(true)
|
||||||
|
|
@ -901,7 +899,7 @@ func TestCommitInterruptExperimentBor_NewTxFlow(t *testing.T) {
|
||||||
w.setInterruptCtx(vm.InterruptCtxOpcodeDelayKey, uint(500))
|
w.setInterruptCtx(vm.InterruptCtxOpcodeDelayKey, uint(500))
|
||||||
|
|
||||||
// Send the second transaction
|
// 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.
|
// 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))
|
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))
|
w.setInterruptCtx(vm.InterruptCtxOpcodeDelayKey, uint(0))
|
||||||
|
|
||||||
// Send the third transaction
|
// 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
|
// a bit risky
|
||||||
for i := 0; i < 2*totalBlocks*txInBlock; i++ {
|
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 {
|
if err != nil {
|
||||||
b.Fatal("while adding a local transaction", err)
|
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 {
|
if err != nil {
|
||||||
b.Fatal("while adding a remote transaction", err)
|
b.Fatal("while adding a remote transaction", err)
|
||||||
}
|
}
|
||||||
|
|
@ -1083,12 +1081,12 @@ func BenchmarkBorMiningBlockSTMMetadata(b *testing.B) {
|
||||||
|
|
||||||
// a bit risky
|
// a bit risky
|
||||||
for i := 0; i < 2*totalBlocks*txInBlock; i++ {
|
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 {
|
if err != nil {
|
||||||
b.Fatal("while adding a local transaction", err)
|
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 {
|
if err != nil {
|
||||||
b.Fatal("while adding a remote transaction", err)
|
b.Fatal("while adding a remote transaction", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue