diff --git a/eth/peer.go b/eth/peer.go index b5f4508559..be57542577 100644 --- a/eth/peer.go +++ b/eth/peer.go @@ -327,6 +327,25 @@ func (p *peer) RequestReceipts(hashes []common.Hash) error { 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, // network IDs, difficulties, head and genesis blocks. func (p *peer) Handshake(network uint64, td *big.Int, head common.Hash, genesis common.Hash) error { diff --git a/eth/protocol.go b/eth/protocol.go index 0e90e6a2ef..0aca594a61 100644 --- a/eth/protocol.go +++ b/eth/protocol.go @@ -41,7 +41,7 @@ var ProtocolName = "eth" var ProtocolVersions = []uint{eth63, eth62} // 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 @@ -62,6 +62,9 @@ const ( NodeDataMsg = 0x0e GetReceiptsMsg = 0x0f ReceiptsMsg = 0x10 + GetGrapheneMsg = 0x08 + GrapheneMsg = 0x09 + GetTxMsg = 0x0a ) type errCode int @@ -181,3 +184,22 @@ type blockBody struct { // blockBodiesData is the network packet for block content distribution. 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 +}