X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Flookup.rs;h=8def6f13750fa5cf556ac6c1a1106b6d4b70635a;hb=cbf7897549f540ca3017dced125d9b1202b61dad;hp=696b4d041ab508b53c7074884a63b89047d4957a;hpb=858c7f23cee5fd36b5fa77232412d0cc106b1f76;p=rapid-gossip-sync-server diff --git a/src/lookup.rs b/src/lookup.rs index 696b4d0..8def6f1 100644 --- a/src/lookup.rs +++ b/src/lookup.rs @@ -10,7 +10,7 @@ use lightning::util::ser::Readable; use tokio_postgres::Client; use futures::StreamExt; -use lightning::log_info; +use lightning::{log_gossip, log_info}; use lightning::util::logger::Logger; use crate::config; @@ -31,7 +31,7 @@ pub(super) struct UpdateDelta { } pub(super) struct DirectedUpdateDelta { - pub(super) last_update_before_seen: Option, + pub(super) last_update_before_seen: Option, pub(super) mutated_properties: MutatedProperties, pub(super) latest_update_after_seen: Option, pub(super) serialization_update_flags: Option, @@ -229,7 +229,7 @@ pub(super) async fn fetch_channel_updates(delta_set: &mut DeltaSet, cl // there was an update in either direction that happened after the last sync (to avoid // collecting too many reference updates) let reference_rows = client.query_raw(" - SELECT id, direction, blob_signed FROM channel_updates + SELECT id, direction, CAST(EXTRACT('epoch' from seen) AS BIGINT) AS seen, blob_signed FROM channel_updates WHERE id IN ( SELECT DISTINCT ON (short_channel_id, direction) id FROM channel_updates @@ -256,6 +256,7 @@ pub(super) async fn fetch_channel_updates(delta_set: &mut DeltaSet, cl non_intermediate_ids.insert(update_id); let direction: bool = current_reference.get("direction"); + let seen = current_reference.get::<_, i64>("seen") as u32; let blob: Vec = current_reference.get("blob_signed"); let mut readable = Cursor::new(blob); let unsigned_channel_update = ChannelUpdate::read(&mut readable).unwrap().contents; @@ -267,7 +268,12 @@ pub(super) async fn fetch_channel_updates(delta_set: &mut DeltaSet, cl } else { (*current_channel_delta).updates.1.get_or_insert(DirectedUpdateDelta::default()) }; - update_delta.last_update_before_seen = Some(unsigned_channel_update); + log_gossip!(logger, "Channel {} last update before seen: {}/{}/{}", scid, update_id, direction, unsigned_channel_update.timestamp); + update_delta.last_update_before_seen = Some(UpdateDelta { + seen, + update: unsigned_channel_update, + }); + reference_row_count += 1; } @@ -339,22 +345,22 @@ pub(super) async fn fetch_channel_updates(delta_set: &mut DeltaSet, cl // determine mutations if let Some(last_seen_update) = update_delta.last_update_before_seen.as_ref() { - if unsigned_channel_update.flags != last_seen_update.flags { + if unsigned_channel_update.flags != last_seen_update.update.flags { update_delta.mutated_properties.flags = true; } - if unsigned_channel_update.cltv_expiry_delta != last_seen_update.cltv_expiry_delta { + if unsigned_channel_update.cltv_expiry_delta != last_seen_update.update.cltv_expiry_delta { update_delta.mutated_properties.cltv_expiry_delta = true; } - if unsigned_channel_update.htlc_minimum_msat != last_seen_update.htlc_minimum_msat { + if unsigned_channel_update.htlc_minimum_msat != last_seen_update.update.htlc_minimum_msat { update_delta.mutated_properties.htlc_minimum_msat = true; } - if unsigned_channel_update.fee_base_msat != last_seen_update.fee_base_msat { + if unsigned_channel_update.fee_base_msat != last_seen_update.update.fee_base_msat { update_delta.mutated_properties.fee_base_msat = true; } - if unsigned_channel_update.fee_proportional_millionths != last_seen_update.fee_proportional_millionths { + if unsigned_channel_update.fee_proportional_millionths != last_seen_update.update.fee_proportional_millionths { update_delta.mutated_properties.fee_proportional_millionths = true; } - if unsigned_channel_update.htlc_maximum_msat != last_seen_update.htlc_maximum_msat { + if unsigned_channel_update.htlc_maximum_msat != last_seen_update.update.htlc_maximum_msat { update_delta.mutated_properties.htlc_maximum_msat = true; } }