4

Typing the following command (with a running lightningd):

 lightning-cli listpeers

I get peers which all have a features flag, for example 0252a1. In the manpage lightning-listpeers(7) it says, that it corresponds to the features mentioned in BOLT #9.

How do I get from 0252a1 to the features listed in the table seen in the BOLT #9 document?

3

A bit is a binary digit with the two possible expressions 0 and 1. Binary data is often represented as hexadecimal in writing as that is more compact and human-readable. Hexadecimal (base 16) encodes the (decimal) numbers 0 through 15 with the symbols 0-9 and A-F (where A-F represent 10-15).

A few examples (subscript indicates base):
110 = 116 = 00012
510 = 516 = 01012
1010 = A16 = 10102
1310 = D16 = 11012

The flag array that you quote, 0252a1 would translate to the binary array 100101001010100001

To use it as a flag array, we do not interpret it as a number but interpret a 1 as a feature being set and a 0 as a feature being unset. We refer to each bit by its position counting from the rightmost. The rightmost is the zeroth bit and even.

The Feature Flags (BOLT #9) in Lightning are always assigned in pairs. Even bits refer to features that our node will consider mandatory, odd bits refer to optional features our node supports. Other nodes will ignore odd bits that they don't understand ("It's okay to be odd."), but will disconnect if there are even bits set they don't support.

1001010010101000_01_
Bits 0/1 refer to the feature option_data_loss_protect. The flag is on the even bit (the 0th), thus the feature is mandatory.

10010100101010_00_01
Bits 2/3 refer to initial_routing_sync. Since neither bit is set, our node does not support that feature.

100101001010_10_0001
Bits 4/5 signal option_upfront_shutdown_script. The flag is on bit 5, and thus it's an optional feature.

1001010010_10_100001
Bits 6/7 signal gossip_queries. The flag is on bit 7, also optional.

10010100_10_10100001
Bits 8/9 signal var_onion_optin. As the flag is on the odd bit, it's an optional feature.

100101_00_1010100001
Bits 10/11 is for gossip_queries_ex. Our node does not support this feature.

1001_01_001010100001
Bits 12/13 indicate that option_static_remotekey is mandatory for this node's peers, as it is set on bit 12, the even bit.

10_01_01001010100001
Bits 14/15 refer to payment_secret which is also mandatory.

_10_0101001010100001
The flag on bit 17 indicates that basic_mpp is optional.

The absence of the feature flags on bits 18-27 indicates that the node does not recognize any of the corresponding features.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy