forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ethereum#46 from rjl493456442/miner-stuff
miner, eth: various fixes
- Loading branch information
Showing
8 changed files
with
372 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright 2024 The go-ethereum Authors | ||
// This file is part of the go-ethereum library. | ||
// | ||
// The go-ethereum library is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Lesser General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// The go-ethereum library is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
package miner | ||
|
||
import ( | ||
"sync" | ||
"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 | ||
// exist to serve RPC requests before being discarded if the parent block | ||
// has not changed yet. The value is chosen to align with the recommit interval. | ||
const pendingTTL = 2 * time.Second | ||
|
||
// pending wraps a pending block with additional metadata. | ||
type pending struct { | ||
created time.Time | ||
parent *types.Header | ||
coinbase common.Address | ||
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. | ||
// | ||
// Note, don't modify the returned payload result. | ||
func (p *pending) resolve(parent *types.Header, coinbase common.Address) *newPayloadResult { | ||
p.lock.Lock() | ||
defer p.lock.Unlock() | ||
|
||
if p.result == nil || p.parent == nil { | ||
return nil | ||
} | ||
if parent.Hash() != p.parent.Hash() || p.coinbase != coinbase { | ||
return nil | ||
} | ||
if time.Since(p.created) > pendingTTL { | ||
return nil | ||
} | ||
return p.result | ||
} | ||
|
||
// update refreshes the cached pending block with newly created one. | ||
func (p *pending) update(parent *types.Header, coinbase common.Address, result *newPayloadResult) { | ||
p.lock.Lock() | ||
defer p.lock.Unlock() | ||
|
||
p.parent = parent | ||
p.coinbase = coinbase | ||
p.result = result | ||
p.created = time.Now() | ||
} |
Oops, something went wrong.