Skip to content

Commit 20e3d70

Browse files
Update channel scores on payment route
1 parent d4ad57b commit 20e3d70

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

lightning/src/routing/network_graph.rs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,36 @@ impl<C: Deref + Sync + Send, L: Deref + Sync + Send> RoutingMessageHandler for N
202202
}
203203
}
204204

205+
#[derive(PartialEq, Debug)]
206+
/// Details about the quality of a channel stored in a field within a DirectionalChannelInfo
207+
/// object. Updates on PaymentSent/Failed events.
208+
pub struct ChannelScore {
209+
/// Increments on detection of a PaymentSent event occuring
210+
pub successes: u64,
211+
/// Increments on detection of a PaymentFailed event occurring
212+
pub failures: u64,
213+
// Many more to come...
214+
}
215+
216+
impl Readable for ChannelScore {
217+
fn read<R: ::std::io::Read>(reader: &mut R) -> Result<ChannelScore, DecodeError> {
218+
let successes: u64 = Readable::read(reader)?;
219+
let failures: u64 = Readable::read(reader)?;
220+
Ok(ChannelScore {
221+
successes,
222+
failures,
223+
})
224+
}
225+
}
226+
227+
impl Writeable for ChannelScore {
228+
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
229+
self.successes.write(writer)?;
230+
self.failures.write(writer)?;
231+
Ok(())
232+
}
233+
}
234+
205235
#[derive(PartialEq, Debug)]
206236
/// Details about one direction of a channel. Received
207237
/// within a channel update.
@@ -222,6 +252,9 @@ pub struct DirectionalChannelInfo {
222252
/// Everything else is useful only for sending out for initial routing sync.
223253
/// Not stored if contains excess data to prevent DoS.
224254
pub last_update_message: Option<msgs::ChannelUpdate>,
255+
/// Tracks a channel's performance over time. Gets updated on the detection of a
256+
/// PaymentSent or PaymentFailed event
257+
pub channel_score: ChannelScore,
225258
}
226259

227260
impl std::fmt::Display for DirectionalChannelInfo {
@@ -237,7 +270,8 @@ impl_writeable!(DirectionalChannelInfo, 0, {
237270
cltv_expiry_delta,
238271
htlc_minimum_msat,
239272
fees,
240-
last_update_message
273+
last_update_message,
274+
channel_score
241275
});
242276

243277
#[derive(PartialEq)]
@@ -677,7 +711,11 @@ impl NetworkGraph {
677711
base_msat: msg.contents.fee_base_msat,
678712
proportional_millionths: msg.contents.fee_proportional_millionths,
679713
},
680-
last_update_message
714+
last_update_message,
715+
channel_score: ChannelScore {
716+
successes: 0,
717+
failures: 0,
718+
}
681719
};
682720
$target = Some(updated_channel_dir_info);
683721
}

0 commit comments

Comments
 (0)