Chapter 13. Wire Protocol: Framing and Extensibility

In this chapter, we dive into the wire protocol of the Lightning Network and also cover all the various extensibility levers that have been built into the protocol. By the end of this chapter, an ambitious reader should be able to write their very own wire protocol parser for the Lightning Network. In addition to being able to write a custom wire protocol parser, a reader of this chapter will gain a deep understanding of the various upgrade mechanisms that have been built into the protocol.

Messaging Layer in the Lightning Protocol Suite

The messaging layer, which is detailed in this chapter, consists of “Framing and message format,” “Type-Length-Value” encoding, and “Feature bits.” These components are highlighted by an outline in the protocol suite, shown in Figure 13-1.

Messaging layer in the Lightning protocol suite
Figure 13-1. Messaging layer in the Lightning protocol suite

Wire Framing

We begin by describing the high-level structure of the wire framing within the protocol. When we say framing, we mean the way that the bytes are packed on the wire to encode a particular protocol message. Without knowledge of the framing system used in the protocol, a string of bytes on the wire would resemble a series of random bytes because no structure has been imposed. By applying proper framing to decode these bytes on the wire, we’ll be able to extract structure and finally ...

Get Mastering the Lightning Network now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.