You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
6.4 KiB

  1. ==================================
  2. RFC 010: Peer to Peer Light Client
  3. ==================================
  4. Changelog
  5. ---------
  6. - 2022-01-21: Initial draft (@tychoish)
  7. Abstract
  8. --------
  9. The dependency on access to the RPC system makes running or using the light
  10. client more complicated than it should be, because in practice node operators
  11. choose to restrict access to these end points (often correctly.) There is no
  12. deep dependency for the light client on the RPC system, and there is a
  13. persistent notion that "make a p2p light client" is a solution to this
  14. operational limitation. This document explores the implications and
  15. requirements of implementing a p2p-based light client, as well as the
  16. possibilities afforded by this implementation.
  17. Background
  18. ----------
  19. High Level Design
  20. ~~~~~~~~~~~~~~~~~
  21. From a high level, the light client P2P implementation, is relatively straight
  22. forward, but is orthogonal to the P2P-backed statesync implementation that
  23. took place during the 0.35 cycle. The light client only really needs to be
  24. able to request (and receive) a `LightBlock` at a given height. To support
  25. this, a new Reactor would run on every full node and validator which would be
  26. able to service these requests. The workload would be entirely
  27. request-response, and the implementation of the reactor would likely be very
  28. straight forward, and the implementation of the provider is similarly
  29. relatively simple.
  30. The complexity of the project focuses around peer discovery, handling when
  31. peers disconnect from the light clients, and how to change the current P2P
  32. code to appropriately handle specialized nodes.
  33. I believe it's safe to assume that much of the current functionality of the
  34. current ``light`` mode would *not* need to be maintained: there is no need to
  35. proxy the RPC endpoints over the P2P layer and there may be no need to run a
  36. node/process for the p2p light client (e.g. all use of this will be as a
  37. client.)
  38. The ability to run light clients using the RPC system will continue to be
  39. maintained.
  40. LibP2P
  41. ~~~~~~
  42. While some aspects of the P2P light client implementation are orthogonal to
  43. LibP2P project, it's useful to think about the ways that these efforts may
  44. combine or interact.
  45. We expect to be able to leverage libp2p tools to provide some kind of service
  46. discovery for tendermint-based networks. This means that it will be possible
  47. for the p2p stack to easily identify specialized nodes, (e.g. light clients)
  48. thus obviating many of the design challenges with providing this feature in
  49. the context of the current stack.
  50. Similarly, libp2p makes it possible for a project to be able back their non-Go
  51. light clients, without the major task of first implementing Tendermint's p2p
  52. connection handling. We should identify if there exist users (e.g. the go IBC
  53. relayer, it's maintainers, and operators) who would be able to take advantage
  54. of p2p light client, before switching to libp2p. To our knowledge there are
  55. limited implementations of this p2p protocol (a simple implementation without
  56. secret connection support exists in rust but it has not been used in
  57. production), and it seems unlikely that a team would implement this directly
  58. ahead of its impending removal.
  59. User Cases
  60. ~~~~~~~~~~
  61. This RFC makes a few assumptions about the use cases and users of light
  62. clients in tendermint.
  63. The most active and delicate use cases for light clients is in the
  64. implementation of the IBC relayer. Thus, we expect that providing P2P light
  65. clients might increase the reliability of relayers and reduce the cost of
  66. running a relayer, because relayer operators won't have to decide between rely
  67. on public RPC endpoints (unreliable) or running their own full nodes
  68. (expensive.) This also assumes that there are *no* other uses of the RPC in
  69. the relayer, and unless the relayers have the option of dropping all RPC use,
  70. it's unclear if a P2P light client will actually be able to successfully
  71. remove the dependency on the RPC system.
  72. Given that the primary relayer implementation is Hermes (rust,) it might be
  73. safe to deliver a version of Tendermint that adds a light client rector in
  74. the full nodes, but that does not provide an implementation of a Go light
  75. client. This either means that the rust implementation would need support for
  76. the legacy P2P connection protocol or wait for the libp2p implementation.
  77. Client side light client (e.g. wallets, etc.) users may always want to use (a
  78. subset) of the RPC rather than connect to the P2P network for an ephemeral
  79. use.
  80. Discussion
  81. ----------
  82. Implementation Questions
  83. ~~~~~~~~~~~~~~~~~~~~~~~~
  84. Most of the complication in the is how to have a long lived light client node
  85. that *only* runs the light client reactor, as this raises a few questions:
  86. - would users specify a single P2P node to connect to when creating a light
  87. client or would they also need/want to discover peers?
  88. - **answer**: most light client use cases won't care much about selecting
  89. peers (and those that do can either disable PEX and specify persistent
  90. peers, *or* use the RPC light client.)
  91. - how do we prevent full nodes and validators from allowing their peer slots,
  92. which are typically limited, from filling with light clients? If
  93. light-clients aren't limited, how do we prevent light clients from consuming
  94. resources on consensus nodes?
  95. - **answer**: I think we can institute an internal cap on number of light
  96. client connections to accept and also elide light client nodes from PEX
  97. (pre-libp2p, if we implement this.) I believe that libp2p should provide
  98. us with the kind of service discovery semantics for network connectivity
  99. that would obviate this issue.
  100. - when a light client disconnects from its peers will it need to reset its
  101. internal state (cache)? does this change if it connects to the same peers?
  102. - **answer**: no, the internal state only needs to be reset if the light
  103. client detects an invalid block or other divergence, and changing
  104. witnesses--which will be more common with a p2p light client--need not
  105. invalidate the cache.
  106. These issues are primarily present given that the current peer management later
  107. does not have a particularly good service discovery mechanism nor does it have
  108. a very sophisticated way of identifying nodes of different types or modes.
  109. Report Evidence
  110. ~~~~~~~~~~~~~~~
  111. The current light client implementation currently has the ability to report
  112. observed evidence. Either the notional light client reactor needs to be able
  113. to handle these kinds of requests *or* all light client nodes need to also run
  114. the evidence reactor. This could be configured at runtime.