aboutsummaryrefslogtreecommitdiffstats
path: root/core/evm.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-04-12 21:38:31 +0800
committerGitHub <noreply@github.com>2017-04-12 21:38:31 +0800
commita7b9e484d05ceb0afce4ba5dbc62b8f262c2e354 (patch)
tree35ab50c0e276beb15e6beac2eaa846f6b737f64c /core/evm.go
parent6b7ae4e751dbaee0f31032f045fd35b0c1079388 (diff)
downloaddexon-a7b9e484d05ceb0afce4ba5dbc62b8f262c2e354.tar.gz
dexon-a7b9e484d05ceb0afce4ba5dbc62b8f262c2e354.tar.zst
dexon-a7b9e484d05ceb0afce4ba5dbc62b8f262c2e354.zip
consensus, core, ethstats: use engine specific block beneficiary (#14318)
* consensus, core, ethstats: use engine specific block beneficiary * core, eth, les, miner: use explicit beneficiary during mining
Diffstat (limited to 'core/evm.go')
-rw-r--r--core/evm.go25
1 files changed, 18 insertions, 7 deletions
diff --git a/core/evm.go b/core/evm.go
index 6a5713075..49a786a86 100644
--- a/core/evm.go
+++ b/core/evm.go
@@ -20,25 +20,36 @@ import (
"math/big"
"github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
)
-// BlockFetcher retrieves headers by their hash
-type HeaderFetcher interface {
- // GetHeader returns the hash corresponding to their hash
+// ChainContext supports retrieving headers and consensus parameters from the
+// current blockchain to be used during transaction processing.
+type ChainContext interface {
+ // Engine retrieves the chain's consensus engine.
+ Engine() consensus.Engine
+
+ // GetHeader returns the hash corresponding to their hash.
GetHeader(common.Hash, uint64) *types.Header
}
// NewEVMContext creates a new context for use in the EVM.
-func NewEVMContext(msg Message, header *types.Header, chain HeaderFetcher) vm.Context {
+func NewEVMContext(msg Message, header *types.Header, chain ChainContext, author *common.Address) vm.Context {
+ // If we don't have an explicit author (i.e. not mining), extract from the header
+ var beneficiary common.Address
+ if author == nil {
+ beneficiary, _ = chain.Engine().Author(header) // Ignore error, we're past header validation
+ } else {
+ beneficiary = *author
+ }
return vm.Context{
CanTransfer: CanTransfer,
Transfer: Transfer,
GetHash: GetHashFn(header, chain),
-
Origin: msg.From(),
- Coinbase: header.Coinbase,
+ Coinbase: beneficiary,
BlockNumber: new(big.Int).Set(header.Number),
Time: new(big.Int).Set(header.Time),
Difficulty: new(big.Int).Set(header.Difficulty),
@@ -48,7 +59,7 @@ func NewEVMContext(msg Message, header *types.Header, chain HeaderFetcher) vm.Co
}
// GetHashFn returns a GetHashFunc which retrieves header hashes by number
-func GetHashFn(ref *types.Header, chain HeaderFetcher) func(n uint64) common.Hash {
+func GetHashFn(ref *types.Header, chain ChainContext) func(n uint64) common.Hash {
return func(n uint64) common.Hash {
for header := chain.GetHeader(ref.ParentHash, ref.Number.Uint64()-1); header != nil; header = chain.GetHeader(header.ParentHash, header.Number.Uint64()-1) {
if header.Number.Uint64() == n {