MCPcopy Create free account
hub / github.com/DNAProject/DNA / BlockHandle

Function BlockHandle

p2pserver/message/utils/msg_handler.go:178–202  ·  view source on GitHub ↗

BlockHandle handles the block message from peer

(data *msgTypes.MsgPayload, p2p p2p.P2P, pid *evtActor.PID, args ...interface{})

Source from the content-addressed store, hash-verified

176
177// BlockHandle handles the block message from peer
178func BlockHandle(data *msgTypes.MsgPayload, p2p p2p.P2P, pid *evtActor.PID, args ...interface{}) {
179 log.Trace("[p2p]receive block message from ", data.Addr, data.Id)
180
181 if pid != nil {
182 var block = data.Payload.(*msgTypes.Block)
183 stateHashHeight := config.GetStateHashCheckHeight(config.DefConfig.P2PNode.NetworkId)
184 if block.Blk.Header.Height >= stateHashHeight && block.MerkleRoot == common.UINT256_EMPTY {
185 log.Info("received block msg with empty merkle root")
186 remotePeer := p2p.GetPeer(data.Id)
187 if remotePeer != nil {
188 remotePeer.Close()
189 }
190
191 return
192 }
193
194 input := &msgCommon.AppendBlock{
195 FromID: data.Id,
196 BlockSize: data.PayloadSize,
197 Block: block.Blk,
198 MerkleRoot: block.MerkleRoot,
199 }
200 pid.Tell(input)
201 }
202}
203
204// ConsensusHandle handles the consensus message from peer
205func ConsensusHandle(data *msgTypes.MsgPayload, p2p p2p.P2P, pid *evtActor.PID, args ...interface{}) {

Callers 1

TestBlockHandleFunction · 0.85

Calls 5

TraceFunction · 0.92
GetStateHashCheckHeightFunction · 0.92
InfoFunction · 0.92
GetPeerMethod · 0.65
CloseMethod · 0.65

Tested by 1

TestBlockHandleFunction · 0.68