mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
miner: use common.hash instead of *types.header
This commit is contained in:
parent
72192b7ee7
commit
9b276dda61
3 changed files with 25 additions and 22 deletions
|
|
@ -604,16 +604,20 @@ func testAtFunctions(t *testing.T, client *rpc.Client) {
|
||||||
// send a transaction for some interesting pending status
|
// send a transaction for some interesting pending status
|
||||||
// and wait for the transaction to be included in the pending block
|
// and wait for the transaction to be included in the pending block
|
||||||
sendTransaction(ec)
|
sendTransaction(ec)
|
||||||
time.Sleep(2000 * time.Millisecond)
|
|
||||||
|
|
||||||
|
// wait for the transaction to be included in the pending block
|
||||||
|
for {
|
||||||
// Check pending transaction count
|
// Check pending transaction count
|
||||||
pending, err := ec.PendingTransactionCount(context.Background())
|
pending, err := ec.PendingTransactionCount(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if pending != 1 {
|
if pending == 1 {
|
||||||
t.Fatalf("unexpected pending, wanted 1 got: %v", pending)
|
break
|
||||||
}
|
}
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
}
|
||||||
|
|
||||||
// Query balance
|
// Query balance
|
||||||
balance, err := ec.BalanceAt(context.Background(), testAddr, nil)
|
balance, err := ec.BalanceAt(context.Background(), testAddr, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -738,7 +742,7 @@ func sendTransaction(ec *Client) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
nonce, err := ec.PendingNonceAt(context.Background(), testAddr)
|
nonce, err := ec.NonceAt(context.Background(), testAddr, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -143,7 +143,7 @@ func (miner *Miner) getPending() *newPayloadResult {
|
||||||
miner.confMu.RUnlock()
|
miner.confMu.RUnlock()
|
||||||
|
|
||||||
header := miner.chain.CurrentHeader()
|
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
|
return cached
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
|
|
@ -166,6 +166,6 @@ func (miner *Miner) getPending() *newPayloadResult {
|
||||||
if ret.err != nil {
|
if ret.err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
miner.pending.update(header, ret)
|
miner.pending.update(header.Hash(), ret)
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// pendingTTL indicates the period of time a generated pending block should
|
// 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.
|
// pending wraps a pending block with additional metadata.
|
||||||
type pending struct {
|
type pending struct {
|
||||||
created time.Time
|
created time.Time
|
||||||
parent *types.Header
|
parentHash common.Hash
|
||||||
result *newPayloadResult
|
result *newPayloadResult
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// resolve retrieves the cached pending result if it's available. Nothing will be
|
// 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.
|
// 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()
|
p.lock.Lock()
|
||||||
defer p.lock.Unlock()
|
defer p.lock.Unlock()
|
||||||
|
|
||||||
if p.result == nil || p.parent == nil {
|
if p.result == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if parent.Hash() != p.parent.Hash() {
|
if parentHash != p.parentHash {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if p.result.block.Coinbase() != coinbase {
|
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.
|
// 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()
|
p.lock.Lock()
|
||||||
defer p.lock.Unlock()
|
defer p.lock.Unlock()
|
||||||
|
|
||||||
p.parent = parent
|
p.parentHash = parent
|
||||||
p.result = result
|
p.result = result
|
||||||
p.created = time.Now()
|
p.created = time.Now()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue