Skip to content

Commit f5b40c5

Browse files
Update channel scores on payment route
1 parent b5723c7 commit f5b40c5

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
@@ -201,6 +201,36 @@ impl RoutingMessageHandler for NetGraphMsgHandler {
201201
}
202202
}
203203

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

226259
impl std::fmt::Display for DirectionalChannelInfo {
@@ -236,7 +269,8 @@ impl_writeable!(DirectionalChannelInfo, 0, {
236269
cltv_expiry_delta,
237270
htlc_minimum_msat,
238271
fees,
239-
last_update_message
272+
last_update_message,
273+
channel_score
240274
});
241275

242276
#[derive(PartialEq)]
@@ -676,7 +710,11 @@ impl NetworkGraph {
676710
base_msat: msg.contents.fee_base_msat,
677711
proportional_millionths: msg.contents.fee_proportional_millionths,
678712
},
679-
last_update_message
713+
last_update_message,
714+
channel_score: ChannelScore {
715+
successes: 0,
716+
failures: 0,
717+
}
680718
};
681719
$target = Some(updated_channel_dir_info);
682720
}

0 commit comments

Comments
 (0)