Fix harmony node vs staking node SelfAddress

pull/1996/head
Rongjian Lan 5 years ago
parent 937b99828c
commit 9abd1f8c06
  1. 7
      cmd/harmony/main.go
  2. 29
      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)

@ -1,6 +1,7 @@
package node
import (
"bytes"
"sort"
"strings"
"time"
@ -83,21 +84,27 @@ 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
)
// 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
}
node.Worker.GetCurrentHeader().SetCoinbase(coinbase)
beneficiary, err := node.Blockchain().GetECDSAFromCoinbase(node.Worker.GetCurrentHeader())
if err != nil {
return nil, err
if bytes.Compare(coinbase[:], addr[:]) == 0 { // empty SelfAddress means it's a staking validator
blsPubKeyBytes := node.Consensus.PubKey.GetAddress()
addr.SetBytes(blsPubKeyBytes[:])
coinbase = addr // coinbase will be the bls address
// validator's ecdsa 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

Loading…
Cancel
Save