Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions .github/workflows/ldk-node-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,28 @@ jobs:
uses: actions/checkout@v3
with:
path: rust-lightning
- name: Determine LDK Node repo and branch
id: ldk-node-ref
if: github.event_name == 'pull_request'
env:
PR_BODY: ${{ github.event.pull_request.body }}
run: |
LDK_NODE_REF=$(echo "$PR_BODY" | sed -n 's/^[[:space:]]*ldk-node:[[:space:]]*//p' | tr -d '[:space:]')
if [ -n "$LDK_NODE_REF" ]; then
echo "repo=$(echo "$LDK_NODE_REF" | cut -d'#' -f1)" >> "$GITHUB_OUTPUT"
echo "ref=$(echo "$LDK_NODE_REF" | cut -d'#' -s -f2)" >> "$GITHUB_OUTPUT"
fi
- name: Checkout LDK Node
uses: actions/checkout@v3
with:
repository: lightningdevkit/ldk-node
repository: ${{ steps.ldk-node-ref.outputs.repo || 'lightningdevkit/ldk-node' }}
ref: ${{ steps.ldk-node-ref.outputs.ref || '' }}
path: ldk-node
- name: Install Rust stable toolchain
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain stable
- name: Run LDK Node Integration Tests
- name: Patch LDK Node Cargo.toml
if: steps.ldk-node-ref.outputs.repo == ''
run: |
cd ldk-node
cat <<EOF >> Cargo.toml
Expand Down Expand Up @@ -53,5 +66,8 @@ jobs:
lightning-liquidity = { path = "../rust-lightning/lightning-liquidity" }
lightning-macros = { path = "../rust-lightning/lightning-macros" }
EOF
- name: Run LDK Node Integration Tests
run: |
cd ldk-node
cargo check
cargo check --features uniffi
28 changes: 14 additions & 14 deletions lightning/src/routing/scoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,16 +483,16 @@ pub struct ProbabilisticScorer<G: Deref<Target = NetworkGraph<L>>, L: Logger> {
decay_params: ProbabilisticScoringDecayParameters,
network_graph: G,
logger: L,
channel_liquidities: ChannelLiquidities,
channel_liquidities: ChannelLiquiditiesX,
/// The last time we were given via a [`ScoreUpdate`] method. This does not imply that we've
/// decayed every liquidity bound up to that time.
last_update_time: Duration,
}
/// Container for live and historical liquidity bounds for each channel.
#[derive(Clone)]
pub struct ChannelLiquidities(HashMap<u64, ChannelLiquidity>);
pub struct ChannelLiquiditiesX(HashMap<u64, ChannelLiquidity>);

impl ChannelLiquidities {
impl ChannelLiquiditiesX {
fn new() -> Self {
Self(new_hash_map())
}
Expand Down Expand Up @@ -551,18 +551,18 @@ impl ChannelLiquidities {
}
}

impl Readable for ChannelLiquidities {
impl Readable for ChannelLiquiditiesX {
#[inline]
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
let mut channel_liquidities = new_hash_map();
read_tlv_fields!(r, {
(0, channel_liquidities, required),
});
Ok(ChannelLiquidities(channel_liquidities))
Ok(ChannelLiquiditiesX(channel_liquidities))
}
}

impl Writeable for ChannelLiquidities {
impl Writeable for ChannelLiquiditiesX {
#[inline]
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
write_tlv_fields!(w, {
Expand Down Expand Up @@ -971,7 +971,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Logger> ProbabilisticScorer<G, L> {
decay_params,
network_graph,
logger,
channel_liquidities: ChannelLiquidities::new(),
channel_liquidities: ChannelLiquiditiesX::new(),
last_update_time: Duration::from_secs(0),
}
}
Expand Down Expand Up @@ -1193,12 +1193,12 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Logger> ProbabilisticScorer<G, L> {
}

/// Overwrite the scorer state with the given external scores.
pub fn set_scores(&mut self, external_scores: ChannelLiquidities) {
pub fn set_scores(&mut self, external_scores: ChannelLiquiditiesX) {
_ = mem::replace(&mut self.channel_liquidities, external_scores);
}

/// Returns the current scores.
pub fn scores(&self) -> &ChannelLiquidities {
pub fn scores(&self) -> &ChannelLiquiditiesX {
&self.channel_liquidities
}
}
Expand Down Expand Up @@ -1848,7 +1848,7 @@ impl<G: Deref<Target = NetworkGraph<L>> + Clone, L: Logger + Clone> CombinedScor

/// Merge external channel liquidity information into the scorer.
pub fn merge(
&mut self, mut external_scores: ChannelLiquidities, duration_since_epoch: Duration,
&mut self, mut external_scores: ChannelLiquiditiesX, duration_since_epoch: Duration,
) {
// Decay both sets of scores to make them comparable and mergeable.
self.local_only_scorer.time_passed(duration_since_epoch);
Expand All @@ -1866,7 +1866,7 @@ impl<G: Deref<Target = NetworkGraph<L>> + Clone, L: Logger + Clone> CombinedScor
}

/// Overwrite the scorer state with the given external scores.
pub fn set_scores(&mut self, external_scores: ChannelLiquidities) {
pub fn set_scores(&mut self, external_scores: ChannelLiquiditiesX) {
self.scorer.set_scores(external_scores);
}
}
Expand Down Expand Up @@ -2506,7 +2506,7 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Logger>
r: &mut R, args: (ProbabilisticScoringDecayParameters, G, L)
) -> Result<Self, DecodeError> {
let (decay_params, network_graph, logger) = args;
let channel_liquidities = ChannelLiquidities::read(r)?;
let channel_liquidities = ChannelLiquiditiesX::read(r)?;
let mut last_update_time = Duration::from_secs(0);
for (_, liq) in channel_liquidities.0.iter() {
last_update_time = cmp::max(last_update_time, liq.last_updated);
Expand Down Expand Up @@ -2609,7 +2609,7 @@ mod tests {
BlindedTail, CandidateRouteHop, Path, PublicHopCandidate, RouteHop,
};
use crate::routing::scoring::{
ChannelLiquidities, ChannelUsage, CombinedScorer, ScoreLookUp, ScoreUpdate,
ChannelLiquiditiesX, ChannelUsage, CombinedScorer, ScoreLookUp, ScoreUpdate,
};
use crate::util::ser::{ReadableArgs, Writeable};
use crate::util::test_utils::{self, TestLogger};
Expand Down Expand Up @@ -4214,7 +4214,7 @@ mod tests {
logger_rc.as_ref(),
);

let mut external_scores = ChannelLiquidities::new();
let mut external_scores = ChannelLiquiditiesX::new();
external_scores.insert(42, external_liquidity);

{
Expand Down