Skip to content

Commit f0ef173

Browse files
authored
Merge pull request lightningdevkit#19 from TheBlueMatt/main
Update LDK to 0.0.112 and workaround Postgres being broken
2 parents 8401949 + 5921ed9 commit f0ef173

File tree

7 files changed

+27
-12
lines changed

7 files changed

+27
-12
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
cargo update -p tokio-postgres --precise "0.7.5" --verbose
3737
cargo update -p postgres-types --precise "0.2.3" --verbose
3838
cargo update -p tokio --precise "1.14.1" --verbose
39+
cargo update -p once_cell --precise "1.14.0" --verbose
3940
- name: Build on Rust ${{ matrix.toolchain }}
4041
run: |
4142
cargo build --verbose --color always

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ edition = "2018"
55

66
[dependencies]
77
bitcoin = "0.29"
8-
lightning = { version = "0.0.111" }
9-
lightning-block-sync = { version = "0.0.111", features=["rest-client"] }
10-
lightning-net-tokio = { version = "0.0.111" }
8+
lightning = { version = "0.0.112" }
9+
lightning-block-sync = { version = "0.0.112", features=["rest-client"] }
10+
lightning-net-tokio = { version = "0.0.112" }
1111
tokio = { version = "1.14.1", features = ["full"] }
1212
tokio-postgres = { version="0.7.5" }
1313
futures = "0.3"

src/config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ pub(crate) async fn upgrade_db(schema: i32, client: &mut tokio_postgres::Client)
200200
if schema <= 1 || schema > SCHEMA_VERSION {
201201
panic!("Unknown schema in db: {}, we support up to {}", schema, SCHEMA_VERSION);
202202
}
203+
// PostgreSQL (at least v13, but likely later versions as well) handles insert-only tables
204+
// *very* poorly. After some number of inserts, it refuses to rely on indexes, assuming them to
205+
// be possibly-stale, until a VACUUM happens. Thus, we set the vacuum factor really low here,
206+
// pushing PostgreSQL to vacuum often.
207+
// See https://www.cybertec-postgresql.com/en/postgresql-autovacuum-insert-only-tables/
208+
let _ = client.execute("ALTER TABLE channel_updates SET ( autovacuum_vacuum_insert_scale_factor = 0.005 );", &[]).await;
209+
let _ = client.execute("ALTER TABLE channel_announcements SET ( autovacuum_vacuum_insert_scale_factor = 0.005 );", &[]).await;
203210
}
204211

205212
/// EDIT ME

src/downloader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl RoutingMessageHandler for GossipRouter {
106106
self.native_router.get_next_node_announcement(starting_point)
107107
}
108108

109-
fn peer_connected(&self, their_node_id: &PublicKey, init: &Init) {
109+
fn peer_connected(&self, their_node_id: &PublicKey, init: &Init) -> Result<(), ()> {
110110
self.native_router.peer_connected(their_node_id, init)
111111
}
112112

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl RapidSyncProcessor {
6060
let mut buffered_reader = BufReader::new(file);
6161
let network_graph_result = NetworkGraph::read(&mut buffered_reader, logger);
6262
if let Ok(network_graph) = network_graph_result {
63-
network_graph.remove_stale_channels();
63+
network_graph.remove_stale_channels_and_tracking();
6464
println!("Initialized from cached network graph!");
6565
network_graph
6666
} else {
@@ -106,6 +106,8 @@ impl RapidSyncProcessor {
106106
async fn serialize_delta(network_graph: Arc<NetworkGraph<TestLogger>>, last_sync_timestamp: u32, consider_intermediate_updates: bool) -> SerializedResponse {
107107
let (client, connection) = lookup::connect_to_db().await;
108108

109+
network_graph.remove_stale_channels_and_tracking();
110+
109111
tokio::spawn(async move {
110112
if let Err(e) = connection.await {
111113
panic!("connection error: {}", e);

src/persistence.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl GossipPersister {
189189
.truncate(true)
190190
.open(&cache_path)
191191
.unwrap();
192-
self.network_graph.remove_stale_channels();
192+
self.network_graph.remove_stale_channels_and_tracking();
193193
let mut writer = BufWriter::new(file);
194194
self.network_graph.write(&mut writer).unwrap();
195195
writer.flush().unwrap();

src/verifier.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use bitcoin::blockdata::block::Block;
55
use bitcoin::hashes::Hash;
66
use lightning::chain;
77
use lightning::chain::AccessError;
8-
use lightning_block_sync::BlockSource;
8+
use lightning_block_sync::{BlockData, BlockSource};
99
use lightning_block_sync::http::BinaryResponse;
1010
use lightning_block_sync::rest::RestClient;
1111

@@ -36,11 +36,16 @@ impl ChainVerifier {
3636
let block_hash = BlockHash::from_slice(&block_hash).unwrap();
3737

3838
let block_result = self.rest_client.get_block(&block_hash).await;
39-
let block = block_result.map_err(|error| {
40-
eprintln!("Couldn't retrieve block {}: {:?} ({})", block_height, error, block_hash);
41-
AccessError::UnknownChain
42-
})?;
43-
Ok(block)
39+
match block_result {
40+
Ok(BlockData::FullBlock(block)) => {
41+
Ok(block)
42+
},
43+
Ok(_) => unreachable!(),
44+
Err(error) => {
45+
eprintln!("Couldn't retrieve block {}: {:?} ({})", block_height, error, block_hash);
46+
Err(AccessError::UnknownChain)
47+
}
48+
}
4449
}) })
4550
}
4651
}

0 commit comments

Comments
 (0)