add message type and message handler placeholder for cross shard transactions

pull/1357/head
chao 5 years ago
parent 5c512bef0e
commit 47bab85894
  1. 4
      api/proto/node/node.go
  2. 31
      node/node_cross_shard.go
  3. 17
      node/node_handler.go

@ -27,7 +27,6 @@ const (
PING // node send ip/pki to register with leader
PONG // node broadcast pubK
ShardState
// TODO: add more types
)
// BlockchainSyncMessage is a struct for blockchain sync message.
@ -96,6 +95,9 @@ type BlockMessageType int
// Block sync message subtype
const (
Sync BlockMessageType = iota
Header // used for crosslink from beacon chain to shard chain
Receipt // cross-shard transaction receipts
)
// SerializeBlockchainSyncMessage serializes BlockchainSyncMessage.

@ -0,0 +1,31 @@
package node
import (
"github.com/ethereum/go-ethereum/rlp"
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/internal/utils"
)
// ProcessHeaderMessage verify and process Node/Header message into crosslink when it's valid
func (node *Node) ProcessHeaderMessage(msgPayload []byte) {
var headers []*types.Header
err := rlp.DecodeBytes(msgPayload, &headers)
if err != nil {
utils.Logger().Error().
Err(err).
Msg("Crosslink Headers Broadcast Unable to Decode")
return
}
// TODO: add actual logic
}
// ProcessReceiptMessage store the receipts and merkle proof in local data store
func (node *Node) ProcessReceiptMessage(msgPayload []byte) {
// TODO: add logic
}
// ProcessCrossShardTx verify and process cross shard transaction on destination shard
func (node *Node) ProcessCrossShardTx(blocks []*types.Block) {
// TODO: add logic
}

@ -171,11 +171,13 @@ func (node *Node) messageHandler(content []byte, sender libp2p_peer.ID) {
} else {
// for non-beaconchain node, subscribe to beacon block broadcast
role := node.NodeConfig.Role()
if proto_node.BlockMessageType(msgPayload[0]) == proto_node.Sync && role == nodeconfig.Validator {
if role == nodeconfig.Validator {
utils.Logger().Info().
Uint64("block", blocks[0].NumberU64()).
Msg("Block being handled by block channel")
go node.ProcessCrossShardTx(blocks)
for _, block := range blocks {
node.BeaconBlockChannel <- block
}
@ -185,6 +187,19 @@ func (node *Node) messageHandler(content []byte, sender libp2p_peer.ID) {
node.Client.UpdateBlocks(blocks)
}
}
case proto_node.Header:
// only beacon chain will accept the header from other shards
if node.Consensus.ShardID != 0 {
return
}
utils.Logger().Debug().Msg("NET: received message: Node/Header")
node.ProcessHeaderMessage(msgPayload[1:]) // skip first byte which is blockMsgType
case proto_node.Receipt:
utils.Logger().Debug().Msg("NET: received message: Node/Receipt")
node.ProcessReceiptMessage(msgPayload[1:]) // skip first byte which is blockMsgType
}
case proto_node.PING:
node.pingMessageHandler(msgPayload, sender)

Loading…
Cancel
Save