clboss/Ln/FeatureBit.cpp
Ken Sedgwick f1b37c5da5
ChannelCreator: prefer spliceable peers within the no-record tier
The track-record pass orders open proposals keepers, no-record,
underperformers.  The no-record tier carries no earnings evidence,
so order it by a capability prior: nodes whose node_announcement
advertises splicing (BOLT 9 option_splice, bits 62/63) come first,
since their channels can later be resized without a close and
reopen.  Keepers and underperformers keep their earnings-based
order, and nothing moves across a tier boundary.

New Ln::feature_bit tests a bit in a BOLT 9 hex bitfield (bit 0 is
the least-significant bit of the last byte), with a unit test.
Spliceability is looked up per candidate via listnodes; an RPC
failure or absent features field counts as not spliceable, so the
lookup cannot block channel creation.  The Track records report
marks spliceable no-record nodes with an (S) suffix.
2026-08-04 11:02:22 -07:00

22 lines
522 B
C++

#include"Ln/FeatureBit.hpp"
#include"Util/Str.hpp"
#include<cstdint>
#include<vector>
namespace Ln {
bool feature_bit(std::string const& features_hex, unsigned int bit) {
auto bytes = std::vector<std::uint8_t>();
try {
bytes = Util::Str::hexread(features_hex);
} catch (Util::Str::HexParseFailure const&) {
return false;
}
auto byte_from_end = std::size_t(bit / 8);
if (byte_from_end >= bytes.size())
return false;
auto b = bytes[bytes.size() - 1 - byte_from_end];
return ((b >> (bit % 8)) & 1) != 0;
}
}