Protocol changes for graphene

This commit is contained in:
Sunny Katkuri 2018-09-20 14:35:06 +00:00
parent f55c26ae6d
commit ae322a9b61
2 changed files with 42 additions and 1 deletions

View file

@ -327,6 +327,25 @@ func (p *peer) RequestReceipts(hashes []common.Hash) error {
return p2p.Send(p.rw, GetReceiptsMsg, hashes) return p2p.Send(p.rw, GetReceiptsMsg, hashes)
} }
// RequestTransactions fetches a batch of transactions
func (p *peer) RequestTransactions(hashes []common.Hash) error {
p.Log().Debug("Requesting transactions", "hashes", hashes)
return p2p.Send(p.rw, GetTxMsg, hashes)
}
// RequestGraphene fetches a graphene message containing a Bloom filter and an IBLT
func (p *peer) RequestGraphene(hash common.Hash, nTxs int) error {
p.Log().Debug("Requesting graphene", "block", hash)
return p2p.Send(p.rw, GetGrapheneMsg, &getGrapheneData{NTxs: uint(nTxs), Hash: hash})
}
// SendGraphene sends the graphene message in response to a RequestGraphene
func (p *peer) SendGraphene(hash common.Hash, i []byte, b []byte, ni uint, fpr uint, nTxs uint, indexArray []byte, uncles []*types.Header) error {
p.Log().Debug("Sending graphene", "block", hash)
return p2p.Send(p.rw, GrapheneMsg, &grapheneData{Hash: hash, GrapheneIBLT: i, GrapheneBloom: b, NIBLT: ni, FPR: fpr, NTxs: nTxs, Indices: indexArray, Uncles: uncles})
}
// Handshake executes the eth protocol handshake, negotiating version number, // Handshake executes the eth protocol handshake, negotiating version number,
// network IDs, difficulties, head and genesis blocks. // network IDs, difficulties, head and genesis blocks.
func (p *peer) Handshake(network uint64, td *big.Int, head common.Hash, genesis common.Hash) error { func (p *peer) Handshake(network uint64, td *big.Int, head common.Hash, genesis common.Hash) error {

View file

@ -41,7 +41,7 @@ var ProtocolName = "eth"
var ProtocolVersions = []uint{eth63, eth62} var ProtocolVersions = []uint{eth63, eth62}
// ProtocolLengths are the number of implemented message corresponding to different protocol versions. // ProtocolLengths are the number of implemented message corresponding to different protocol versions.
var ProtocolLengths = []uint64{17, 8} var ProtocolLengths = []uint64{20, 8}
const ProtocolMaxMsgSize = 10 * 1024 * 1024 // Maximum cap on the size of a protocol message const ProtocolMaxMsgSize = 10 * 1024 * 1024 // Maximum cap on the size of a protocol message
@ -62,6 +62,9 @@ const (
NodeDataMsg = 0x0e NodeDataMsg = 0x0e
GetReceiptsMsg = 0x0f GetReceiptsMsg = 0x0f
ReceiptsMsg = 0x10 ReceiptsMsg = 0x10
GetGrapheneMsg = 0x08
GrapheneMsg = 0x09
GetTxMsg = 0x0a
) )
type errCode int type errCode int
@ -181,3 +184,22 @@ type blockBody struct {
// blockBodiesData is the network packet for block content distribution. // blockBodiesData is the network packet for block content distribution.
type blockBodiesData []*blockBody type blockBodiesData []*blockBody
// getGrapheneData represents a request for a graphene message for a block
type getGrapheneData struct {
NTxs uint
Hash common.Hash
}
// grapheneData represents the Bloom filter and IBLT that make up a graphene message
type grapheneData struct {
GrapheneIBLT []byte
GrapheneBloom []byte
FPR uint
NIBLT uint
NTxs uint
Hash common.Hash
Indices []byte
Uncles []*types.Header
}