Merge pull request #1996 from rlan35/staking_pangaea

fix beneficiary issue
pull/1999/head
Rongjian Lan 5 years ago committed by GitHub
commit e9a03bec88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      cmd/harmony/main.go
  2. 13
      core/blockchain.go
  3. 10
      core/evm.go
  4. 20
      core/state_processor.go
  5. 18
      node/node_newblock.go

@ -217,8 +217,7 @@ func setupStakingNodeAccount() error {
initialAccount = &genesis.DeployAccount{}
initialAccount.ShardID = shardID
initialAccount.BlsPublicKey = pubKey.SerializeToHexStr()
blsAddressBytes := pubKey.GetAddress()
initialAccount.Address = hex.EncodeToString(blsAddressBytes[:])
initialAccount.Address = ""
return nil
}
@ -295,7 +294,9 @@ func setupConsensusAndNode(nodeConfig *nodeconfig.ConfigType) *node.Node {
return currentConsensus.PubKey, nil
})
currentConsensus.SelfAddress = common.ParseAddr(initialAccount.Address)
if initialAccount.Address != "" { // staking validator doesn't have to specify ECDSA address
currentConsensus.SelfAddress = common.ParseAddr(initialAccount.Address)
}
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "Error :%v \n", err)

@ -2938,16 +2938,17 @@ func (bc *BlockChain) DelegatorsInformation(addr common.Address) []*staking.Dele
// GetECDSAFromCoinbase retrieve corresponding ecdsa address from Coinbase Address
func (bc *BlockChain) GetECDSAFromCoinbase(header *block.Header) (common.Address, error) {
// backward compatibility: before isStaking epoch, coinbase address is the ecdsa address
coinbase := header.Coinbase()
isStaking := bc.Config().IsStaking(header.Epoch())
if !isStaking {
return header.Coinbase(), nil
return coinbase, nil
}
shardState, err := bc.ReadShardState(header.Epoch())
if err != nil {
return common.Address{}, ctxerror.New("cannot read shard state",
"epoch", header.Epoch(),
"coinbaseAddr", header.Coinbase(),
"coinbaseAddr", coinbase,
).WithCause(err)
}
@ -2956,12 +2957,16 @@ func (bc *BlockChain) GetECDSAFromCoinbase(header *block.Header) (common.Address
return common.Address{}, ctxerror.New("cannot find shard in the shard state",
"blockNum", header.Number(),
"shardID", header.ShardID(),
"coinbaseAddr", header.Coinbase(),
"coinbaseAddr", coinbase,
)
}
for _, member := range committee.Slots {
// After staking the coinbase address will be the address of bls public key
if utils.GetAddressFromBlsPubKeyBytes(member.BlsPublicKey[:]) == header.Coinbase() {
if bytes.Compare(member.EcdsaAddress[:], coinbase[:]) == 0 {
return member.EcdsaAddress, nil
}
if utils.GetAddressFromBlsPubKeyBytes(member.BlsPublicKey[:]) == coinbase {
return member.EcdsaAddress, nil
}
}

@ -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

@ -83,14 +83,26 @@ func (node *Node) proposeNewBlock() (*types.Block, error) {
node.Worker.UpdateCurrent()
// Update worker's current header and state data in preparation to propose/process new transactions
coinbase := node.Consensus.SelfAddress
var (
coinbase = node.Consensus.SelfAddress
beneficiary = coinbase
err error
)
node.Worker.GetCurrentHeader().SetCoinbase(coinbase)
// After staking, all coinbase will be the address of bls pub key
if node.Blockchain().Config().IsStaking(node.Worker.GetCurrentHeader().Epoch()) {
addr := common.Address{}
blsPubKeyBytes := node.Consensus.PubKey.GetAddress()
addr.SetBytes(blsPubKeyBytes[:])
coinbase = addr
coinbase = addr // coinbase will be the bls address
node.Worker.GetCurrentHeader().SetCoinbase(coinbase)
}
beneficiary, err = node.Blockchain().GetECDSAFromCoinbase(node.Worker.GetCurrentHeader())
if err != nil {
return nil, err
}
// Prepare transactions including staking transactions
@ -112,7 +124,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