fix beneficiary issue

pull/1996/head
Rongjian Lan 5 years ago
parent 09ffce3960
commit 9343fdaaed
  1. 10
      core/evm.go
  2. 20
      core/state_processor.go
  3. 9
      node/node_newblock.go

@ -27,7 +27,6 @@ import (
consensus_engine "github.com/harmony-one/harmony/consensus/engine"
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/core/vm"
"github.com/harmony-one/harmony/internal/utils"
)
// ChainContext supports retrieving headers and consensus parameters from the
@ -44,21 +43,14 @@ type ChainContext interface {
// ReadValidatorSnapshot returns the snapshot of validator at the beginning of current epoch.
ReadValidatorSnapshot(common.Address) (*types2.ValidatorWrapper, error)
// GetECDSAFromCoinbase retrieves corresponding ECDSA address from the coinbase (BLS Address)
GetECDSAFromCoinbase(*block.Header) (common.Address, error)
}
// NewEVMContext creates a new context for use in the EVM.
func NewEVMContext(msg Message, header *block.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
var err error
if author == nil {
beneficiary, err = chain.GetECDSAFromCoinbase(header) // Ignore error, we're past header validation
if err != nil {
utils.Logger().Warn().Msg("oops! We cannot find any beneficiary from header")
}
beneficiary, _ = chain.Engine().Author(header) // Ignore error, we're past header validation
} else {
beneficiary = *author
}

@ -67,18 +67,22 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.DB, cfg vm.C
receipts types.Receipts
outcxs types.CXReceipts
incxs = block.IncomingReceipts()
usedGas = new(uint64)
header = block.Header()
coinbase = block.Header().Coinbase()
allLogs []*types.Log
gp = new(GasPool).AddGas(block.GasLimit())
incxs = block.IncomingReceipts()
usedGas = new(uint64)
header = block.Header()
allLogs []*types.Log
gp = new(GasPool).AddGas(block.GasLimit())
)
beneficiary, err := p.bc.GetECDSAFromCoinbase(header)
if err != nil {
return nil, nil, nil, 0, nil, err
}
// Iterate over and process the individual transactions
for i, tx := range block.Transactions() {
statedb.Prepare(tx.Hash(), block.Hash(), i)
receipt, cxReceipt, _, err := ApplyTransaction(p.config, p.bc, &coinbase, gp, statedb, header, tx, usedGas, cfg)
receipt, cxReceipt, _, err := ApplyTransaction(p.config, p.bc, &beneficiary, gp, statedb, header, tx, usedGas, cfg)
if err != nil {
return nil, nil, nil, 0, nil, err
}
@ -94,7 +98,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.DB, cfg vm.C
for i, tx := range block.StakingTransactions() {
statedb.Prepare(tx.Hash(), block.Hash(), i+L)
receipt, _, err :=
ApplyStakingTransaction(p.config, p.bc, &coinbase, gp, statedb, header, tx, usedGas, cfg)
ApplyStakingTransaction(p.config, p.bc, &beneficiary, gp, statedb, header, tx, usedGas, cfg)
if err != nil {
return nil, nil, nil, 0, nil, err

@ -93,6 +93,13 @@ func (node *Node) proposeNewBlock() (*types.Block, error) {
coinbase = addr
}
node.Worker.GetCurrentHeader().SetCoinbase(coinbase)
beneficiary, err := node.Blockchain().GetECDSAFromCoinbase(node.Worker.GetCurrentHeader())
if err != nil {
return nil, err
}
// Prepare transactions including staking transactions
pending, err := node.TxPool.Pending()
if err != nil {
@ -112,7 +119,7 @@ func (node *Node) proposeNewBlock() (*types.Block, error) {
node.pendingStakingTxMutex.Unlock()
}
if err := node.Worker.CommitTransactions(pending, pendingStakingTransactions, coinbase); err != nil {
if err := node.Worker.CommitTransactions(pending, pendingStakingTransactions, beneficiary); err != nil {
utils.Logger().Error().Err(err).Msg("[proposeNewBlock] cannot commit transactions")
return nil, err
}

Loading…
Cancel
Save