[stream] node.IsRunningBeaconChain is refactored to a new method

pull/3595/head
Jacky Wang 4 years ago
parent e1358ee1fc
commit b2fe9fe348
No known key found for this signature in database
GPG Key ID: 1085CE5F4FF5842C
  1. 4
      cmd/harmony/main.go
  2. 3
      node/double_signing.go
  3. 15
      node/node.go
  4. 2
      node/node_cross_link.go
  5. 8
      node/node_handler.go

@ -712,7 +712,7 @@ func setupPrometheusService(node *node.Node, hc harmonyConfig, sid uint32) {
func setupSyncService(node *node.Node, host p2p.Host, hc harmonyConfig) {
blockchains := []*core.BlockChain{node.Blockchain()}
if node.NodeConfig.ShardID != 0 {
if !node.IsRunningBeaconChain() {
blockchains = append(blockchains, node.Beaconchain())
}
@ -729,7 +729,7 @@ func setupSyncService(node *node.Node, host p2p.Host, hc harmonyConfig) {
}
// If we are running side chain, we will need to do some extra works for beacon
// sync
if node.NodeConfig.ShardID != 0 {
if !node.IsRunningBeaconChain() {
dConfig.BHConfig = &downloader.BeaconHelperConfig{
BlockC: node.BeaconBlockChannel,
InsertHook: node.BeaconSyncHook,

@ -3,13 +3,12 @@ package node
import (
"github.com/ethereum/go-ethereum/rlp"
"github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/shard"
"github.com/harmony-one/harmony/staking/slash"
)
// ProcessSlashCandidateMessage ..
func (node *Node) processSlashCandidateMessage(msgPayload []byte) {
if node.NodeConfig.ShardID != shard.BeaconChainShardID {
if !node.IsRunningBeaconChain() {
return
}
candidates := slash.Records{}

@ -217,7 +217,7 @@ func (node *Node) addPendingTransactions(newTxs types.Transactions) []error {
// Add new staking transactions to the pending staking transaction list.
func (node *Node) addPendingStakingTransactions(newStakingTxs staking.StakingTransactions) []error {
if node.NodeConfig.ShardID == shard.BeaconChainShardID {
if node.IsRunningBeaconChain() {
if node.Blockchain().Config().IsPreStaking(node.Blockchain().CurrentHeader().Epoch()) {
poolTxs := types.PoolTransactions{}
for _, tx := range newStakingTxs {
@ -245,7 +245,7 @@ func (node *Node) addPendingStakingTransactions(newStakingTxs staking.StakingTra
func (node *Node) AddPendingStakingTransaction(
newStakingTx *staking.StakingTransaction,
) error {
if node.NodeConfig.ShardID == shard.BeaconChainShardID {
if node.IsRunningBeaconChain() {
errs := node.addPendingStakingTransactions(staking.StakingTransactions{newStakingTx})
var err error
for i := range errs {
@ -404,7 +404,7 @@ func (node *Node) validateNodeMessage(ctx context.Context, payload []byte) (
case proto_node.SlashCandidate:
nodeNodeMessageCounterVec.With(prometheus.Labels{"type": "slash"}).Inc()
// only beacon chain node process slash candidate messages
if node.NodeConfig.ShardID != shard.BeaconChainShardID {
if !node.IsRunningBeaconChain() {
return nil, 0, errIgnoreBeaconMsg
}
case proto_node.Receipt:
@ -412,7 +412,7 @@ func (node *Node) validateNodeMessage(ctx context.Context, payload []byte) (
case proto_node.CrossLink:
nodeNodeMessageCounterVec.With(prometheus.Labels{"type": "crosslink"}).Inc()
// only beacon chain node process crosslink messages
if node.NodeConfig.ShardID != shard.BeaconChainShardID ||
if !node.IsRunningBeaconChain() ||
node.NodeConfig.Role() == nodeconfig.ExplorerNode {
return nil, 0, errIgnoreBeaconMsg
}
@ -1016,7 +1016,7 @@ func New(
go func() { webhooks.DoPost(url, &doubleSign) }()
}
}
if node.NodeConfig.ShardID != shard.BeaconChainShardID {
if !node.IsRunningBeaconChain() {
go node.BroadcastSlash(&doubleSign)
} else {
records := slash.Records{doubleSign}
@ -1282,3 +1282,8 @@ func (node *Node) GetAddresses(epoch *big.Int) map[string]common.Address {
// self addresses map can never be nil
return node.KeysToAddrs
}
// IsRunningBeaconChain returns whether the node is running on beacon chain.
func (node *Node) IsRunningBeaconChain() bool {
return node.NodeConfig.ShardID == shard.BeaconChainShardID
}

@ -61,7 +61,7 @@ func (node *Node) VerifyBlockCrossLinks(block *types.Block) error {
// ProcessCrossLinkMessage verify and process Node/CrossLink message into crosslink when it's valid
func (node *Node) ProcessCrossLinkMessage(msgPayload []byte) {
if node.NodeConfig.ShardID == shard.BeaconChainShardID {
if node.IsRunningBeaconChain() {
pendingCLs, err := node.Blockchain().ReadPendingCrossLinks()
if err == nil && len(pendingCLs) >= maxPendingCrossLinkSize {
utils.Logger().Debug().

@ -171,7 +171,7 @@ func (node *Node) BroadcastCrossLink() {
return
}
if node.NodeConfig.ShardID == shard.BeaconChainShardID ||
if node.IsRunningBeaconChain() ||
!node.Blockchain().Config().IsCrossLink(curBlock.Epoch()) {
// no need to broadcast crosslink if it's beacon chain or it's not crosslink epoch
return
@ -308,7 +308,7 @@ func (node *Node) VerifyNewBlock(newBlock *types.Block) error {
// Verify cross links
// TODO: move into ValidateNewBlock
if node.NodeConfig.ShardID == shard.BeaconChainShardID {
if node.IsRunningBeaconChain() {
err := node.VerifyBlockCrossLinks(newBlock)
if err != nil {
utils.Logger().Debug().Err(err).Msg("ops2 VerifyBlockCrossLinks Failed")
@ -336,7 +336,7 @@ func (node *Node) VerifyNewBlock(newBlock *types.Block) error {
// 3. [leader] send cross shard tx receipts to destination shard
func (node *Node) PostConsensusProcessing(newBlock *types.Block) error {
if node.Consensus.IsLeader() {
if node.NodeConfig.ShardID == shard.BeaconChainShardID {
if node.IsRunningBeaconChain() {
node.BroadcastNewBlock(newBlock)
}
node.BroadcastCXReceipts(newBlock)
@ -360,7 +360,7 @@ func (node *Node) PostConsensusProcessing(newBlock *types.Block) error {
rnd := rand.Intn(100)
if rnd < 1 {
// Beacon validators also broadcast new blocks to make sure beacon sync is strong.
if node.NodeConfig.ShardID == shard.BeaconChainShardID {
if node.IsRunningBeaconChain() {
node.BroadcastNewBlock(newBlock)
}
node.BroadcastCXReceipts(newBlock)

Loading…
Cancel
Save