miner: use common.hash instead of *types.header

This commit is contained in:
Martin Holst Swende 2024-02-16 13:35:49 +01:00 committed by Marius van der Wijden
parent 72192b7ee7
commit 9b276dda61
3 changed files with 25 additions and 22 deletions

View file

@ -604,16 +604,20 @@ func testAtFunctions(t *testing.T, client *rpc.Client) {
// send a transaction for some interesting pending status
// and wait for the transaction to be included in the pending block
sendTransaction(ec)
time.Sleep(2000 * time.Millisecond)
// wait for the transaction to be included in the pending block
for {
// Check pending transaction count
pending, err := ec.PendingTransactionCount(context.Background())
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if pending != 1 {
t.Fatalf("unexpected pending, wanted 1 got: %v", pending)
if pending == 1 {
break
}
time.Sleep(100 * time.Millisecond)
}
// Query balance
balance, err := ec.BalanceAt(context.Background(), testAddr, nil)
if err != nil {
@ -738,7 +742,7 @@ func sendTransaction(ec *Client) error {
if err != nil {
return err
}
nonce, err := ec.PendingNonceAt(context.Background(), testAddr)
nonce, err := ec.NonceAt(context.Background(), testAddr, nil)
if err != nil {
return err
}

View file

@ -143,7 +143,7 @@ func (miner *Miner) getPending() *newPayloadResult {
miner.confMu.RUnlock()
header := miner.chain.CurrentHeader()
if cached := miner.pending.resolve(header, coinbase); cached != nil {
if cached := miner.pending.resolve(header.Hash(), coinbase); cached != nil {
return cached
}
var (
@ -166,6 +166,6 @@ func (miner *Miner) getPending() *newPayloadResult {
if ret.err != nil {
return nil
}
miner.pending.update(header, ret)
miner.pending.update(header.Hash(), ret)
return ret
}

View file

@ -21,7 +21,6 @@ import (
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)
// pendingTTL indicates the period of time a generated pending block should
@ -32,23 +31,23 @@ const pendingTTL = 2 * time.Second
// pending wraps a pending block with additional metadata.
type pending struct {
created time.Time
parent *types.Header
parentHash common.Hash
result *newPayloadResult
lock sync.Mutex
}
// resolve retrieves the cached pending result if it's available. Nothing will be
// returned if the parent/coinbase is not matched or the result is already too old.
// returned if the parentHash/coinbase is not matched or the result is already too old.
//
// Note, don't modify the returned payload result.
func (p *pending) resolve(parent *types.Header, coinbase common.Address) *newPayloadResult {
func (p *pending) resolve(parentHash common.Hash, coinbase common.Address) *newPayloadResult {
p.lock.Lock()
defer p.lock.Unlock()
if p.result == nil || p.parent == nil {
if p.result == nil {
return nil
}
if parent.Hash() != p.parent.Hash() {
if parentHash != p.parentHash {
return nil
}
if p.result.block.Coinbase() != coinbase {
@ -61,11 +60,11 @@ func (p *pending) resolve(parent *types.Header, coinbase common.Address) *newPay
}
// update refreshes the cached pending block with newly created one.
func (p *pending) update(parent *types.Header, result *newPayloadResult) {
func (p *pending) update(parent common.Hash, result *newPayloadResult) {
p.lock.Lock()
defer p.lock.Unlock()
p.parent = parent
p.parentHash = parent
p.result = result
p.created = time.Now()
}