protocol.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Quorum
  2. package consensus
  3. import (
  4. "github.com/ethereum/go-ethereum/common"
  5. "github.com/ethereum/go-ethereum/core/types"
  6. )
  7. // Constants to match up protocol versions and messages
  8. // istanbul/99 was added to accommodate new eth/64 handshake status data with fork id
  9. // this is for backward compatibility which allows a mixed old/new istanbul node network
  10. // istanbul/64 will continue using old status data as eth/63
  11. const (
  12. eth63 = 63
  13. eth64 = 64
  14. eth65 = 65
  15. eth66 = 66
  16. Istanbul64 = 64
  17. Istanbul99 = 99
  18. // this istanbul subprotocol will be registered in addition to "eth"
  19. Istanbul100 = 100
  20. )
  21. var (
  22. IstanbulProtocol = Protocol{
  23. Name: "istanbul",
  24. Versions: []uint{Istanbul100, Istanbul99, Istanbul64},
  25. // istanbul/100 has to have 22 message to be backwards compatible although at the p2p layer it only has
  26. // 1 message with msg.Code 17
  27. Lengths: map[uint]uint64{Istanbul100: 22, Istanbul99: 18, Istanbul64: 18},
  28. }
  29. CliqueProtocol = Protocol{
  30. Name: "eth",
  31. Versions: []uint{eth66, eth65, eth64, eth63},
  32. Lengths: map[uint]uint64{eth65: 17, eth64: 17, eth63: 17},
  33. }
  34. // Default: Keep up-to-date with eth/protocol.go
  35. EthProtocol = Protocol{
  36. Name: "eth",
  37. Versions: []uint{eth66, eth65, eth64, eth63},
  38. Lengths: map[uint]uint64{eth65: 17, eth64: 17, eth63: 17},
  39. }
  40. NorewardsProtocol = Protocol{
  41. Name: "Norewards",
  42. Versions: []uint{0},
  43. Lengths: map[uint]uint64{0: 0},
  44. }
  45. )
  46. // Protocol defines the protocol of the consensus
  47. type Protocol struct {
  48. // Official short name of the protocol used during capability negotiation.
  49. Name string
  50. // Supported versions of the eth protocol (first is primary).
  51. Versions []uint
  52. // Number of implemented message corresponding to different protocol versions.
  53. Lengths map[uint]uint64
  54. }
  55. // Broadcaster defines the interface to enqueue blocks to fetcher and find peer
  56. type Broadcaster interface {
  57. // Enqueue add a block into fetcher queue
  58. Enqueue(id string, block *types.Block)
  59. // FindPeers retrives peers by addresses
  60. FindPeers(map[common.Address]bool) map[common.Address]Peer
  61. }
  62. // Peer defines the interface to communicate with peer
  63. type Peer interface {
  64. // Send sends the message to this peer
  65. Send(msgcode uint64, data interface{}) error
  66. // SendConsensus sends the message to this p2p peer using the consensus specific devp2p subprotocol
  67. SendConsensus(msgcode uint64, data interface{}) error
  68. // SendQBFTConsensus is used to send consensus subprotocol messages from an "eth" peer without encoding the payload
  69. SendQBFTConsensus(msgcode uint64, payload []byte) error
  70. }