From a5b963c54a4eef59a0b2235e271e9481169db669 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sun, 11 Sep 2022 21:07:57 +0000 Subject: [PATCH] Drop the chain_hash column --- src/config.rs | 16 ++++++++++------ src/persistence.rs | 13 ++----------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/config.rs b/src/config.rs index e7ba89c..81db4cf 100644 --- a/src/config.rs +++ b/src/config.rs @@ -5,7 +5,7 @@ use lightning_block_sync::http::HttpEndpoint; use tokio_postgres::Config; use crate::hex_utils; -pub(crate) const SCHEMA_VERSION: i32 = 1; +pub(crate) const SCHEMA_VERSION: i32 = 2; pub(crate) const SNAPSHOT_CALCULATION_INTERVAL: u32 = 3600 * 24; // every 24 hours, in seconds pub(crate) const DOWNLOAD_NEW_GOSSIP: bool = true; @@ -49,7 +49,6 @@ pub(crate) fn db_announcement_table_creation_query() -> &'static str { id SERIAL PRIMARY KEY, short_channel_id character varying(255) NOT NULL UNIQUE, block_height integer, - chain_hash character varying(255), announcement_signed BYTEA, seen timestamp NOT NULL DEFAULT NOW() )" @@ -59,7 +58,6 @@ pub(crate) fn db_channel_update_table_creation_query() -> &'static str { "CREATE TABLE IF NOT EXISTS channel_updates ( id SERIAL PRIMARY KEY, composite_index character varying(255) UNIQUE, - chain_hash character varying(255), short_channel_id character varying(255), timestamp bigint, channel_flags integer, @@ -85,9 +83,15 @@ pub(crate) fn db_index_creation_query() -> &'static str { } pub(crate) async fn upgrade_db(schema: i32, client: &mut tokio_postgres::Client) { - match schema { - SCHEMA_VERSION => {}, - _ => panic!("Unknown schema in db: {}, we support up to {}", schema, SCHEMA_VERSION), + if schema == 1 { + let tx = client.transaction().await.unwrap(); + tx.execute("ALTER TABLE channel_updates DROP COLUMN chain_hash", &[]).await.unwrap(); + tx.execute("ALTER TABLE channel_announcements DROP COLUMN chain_hash", &[]).await.unwrap(); + tx.execute("UPDATE config SET db_schema = 2 WHERE id = 1", &[]).await.unwrap(); + tx.commit().await.unwrap(); + } + if schema <= 1 || schema > SCHEMA_VERSION { + panic!("Unknown schema in db: {}, we support up to {}", schema, SCHEMA_VERSION); } } diff --git a/src/persistence.rs b/src/persistence.rs index d961b30..8fbf166 100644 --- a/src/persistence.rs +++ b/src/persistence.rs @@ -115,8 +115,6 @@ impl GossipPersister { // block height is the first three bytes // to obtain block height, shift scid right by 5 bytes (40 bits) let block_height = (scid >> 5 * 8) as i32; - let chain_hash = announcement.contents.chain_hash.as_ref(); - let chain_hash_hex = hex_utils::hex_str(chain_hash); // start with the type prefix, which is already known a priori let mut announcement_signed = Vec::new(); @@ -126,12 +124,10 @@ impl GossipPersister { .execute("INSERT INTO channel_announcements (\ short_channel_id, \ block_height, \ - chain_hash, \ announcement_signed \ - ) VALUES ($1, $2, $3, $4) ON CONFLICT (short_channel_id) DO NOTHING", &[ + ) VALUES ($1, $2, $3) ON CONFLICT (short_channel_id) DO NOTHING", &[ &scid_hex, &block_height, - &chain_hash_hex, &announcement_signed ]).await; if result.is_err() { @@ -142,9 +138,6 @@ impl GossipPersister { let scid = update.contents.short_channel_id; let scid_hex = hex_utils::hex_str(&scid.to_be_bytes()); - let chain_hash = update.contents.chain_hash.as_ref(); - let chain_hash_hex = hex_utils::hex_str(chain_hash); - let timestamp = update.contents.timestamp as i64; let channel_flags = update.contents.flags as i32; @@ -167,7 +160,6 @@ impl GossipPersister { let result = client .execute("INSERT INTO channel_updates (\ composite_index, \ - chain_hash, \ short_channel_id, \ timestamp, \ channel_flags, \ @@ -179,9 +171,8 @@ impl GossipPersister { fee_proportional_millionths, \ htlc_maximum_msat, \ blob_signed \ - ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) ON CONFLICT (composite_index) DO NOTHING", &[ + ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) ON CONFLICT (composite_index) DO NOTHING", &[ &composite_index, - &chain_hash_hex, &scid_hex, ×tamp, &channel_flags, -- 2.30.2