clboss/tests/ln/test_featurebit.cpp
Ken Sedgwick c7d35b1ebd
Some checks are pending
Code Base Sanity Check / tests (push) Waiting to run
Code Base Sanity Check / coverage (push) Waiting to run
Code Base Sanity Check / build-clang (push) Waiting to run
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-07-30 14:49:01 -07:00

39 lines
1.1 KiB
C++

#undef NDEBUG
#include"Ln/FeatureBit.hpp"
#include<assert.h>
int main() {
using Ln::feature_bit;
/* Bit 0 is the least-significant bit of the last byte. */
assert( feature_bit("01", 0));
assert(!feature_bit("01", 1));
assert( feature_bit("02", 1));
assert(!feature_bit("02", 0));
/* Bits beyond the field are unset. */
assert(!feature_bit("01", 8));
assert(!feature_bit("", 0));
/* Multi-byte: bit 8 is the least-significant bit of the
* second-to-last byte. */
assert( feature_bit("0100", 8));
assert(!feature_bit("0100", 0));
/* option_splice bits 62/63 need an 8-byte field; bit 62 is
* 0x40 of the leading byte, bit 63 is 0x80. */
assert( feature_bit("4000000000000000", 62));
assert(!feature_bit("4000000000000000", 63));
assert( feature_bit("8000000000000000", 63));
assert(!feature_bit("8000000000000000", 62));
/* Longer fields keep bit positions anchored at the tail. */
assert( feature_bit("00004000000000000000", 62));
assert( feature_bit("888a4000000000000000", 62));
/* Malformed hex is just "no features". */
assert(!feature_bit("xyz", 0));
assert(!feature_bit("0", 0));
return 0;
}