Skip to content

Commit cea9036

Browse files
committed
fix: more errors
1 parent 8870dff commit cea9036

8 files changed

Lines changed: 144 additions & 118 deletions

File tree

src/balance.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// accordance with one or both of these licenses.
77

88
use bitcoin::secp256k1::PublicKey;
9-
use bitcoin::{Amount, BlockHash, Txid};
9+
use bitcoin::{Amount, BlockHash, OutPoint, Txid};
1010
use lightning::chain::channelmonitor::{Balance as LdkBalance, BalanceSource};
1111
use lightning::ln::types::ChannelId;
1212
use lightning::sign::SpendableOutputDescriptor;
@@ -80,7 +80,7 @@ pub enum LightningBalance {
8080
/// Alby: funding transaction ID.
8181
funding_tx_id: Txid,
8282
/// Alby: funding transaction output index.
83-
funding_tx_index: u16,
83+
funding_tx_index: u32,
8484
/// The amount available to claim, in satoshis, excluding the on-chain fees which will be
8585
/// required to do so.
8686
amount_satoshis: u64,
@@ -138,7 +138,7 @@ pub enum LightningBalance {
138138
/// Alby: funding transaction ID.
139139
funding_tx_id: Txid,
140140
/// Alby: funding transaction output index.
141-
funding_tx_index: u16,
141+
funding_tx_index: u32,
142142
/// The amount available to claim, in satoshis, possibly excluding the on-chain fees which
143143
/// were spent in broadcasting the transaction.
144144
amount_satoshis: u64,
@@ -165,7 +165,7 @@ pub enum LightningBalance {
165165
/// Alby: funding transaction ID.
166166
funding_tx_id: Txid,
167167
/// Alby: funding transaction output index.
168-
funding_tx_index: u16,
168+
funding_tx_index: u32,
169169
/// The amount available to claim, in satoshis, excluding the on-chain fees which will be
170170
/// required to do so.
171171
amount_satoshis: u64,
@@ -188,7 +188,7 @@ pub enum LightningBalance {
188188
/// Alby: funding transaction ID.
189189
funding_tx_id: Txid,
190190
/// Alby: funding transaction output index.
191-
funding_tx_index: u16,
191+
funding_tx_index: u32,
192192
/// The amount potentially available to claim, in satoshis, excluding the on-chain fees
193193
/// which will be required to do so.
194194
amount_satoshis: u64,
@@ -211,7 +211,7 @@ pub enum LightningBalance {
211211
/// Alby: funding transaction ID.
212212
funding_tx_id: Txid,
213213
/// Alby: funding transaction output index.
214-
funding_tx_index: u16,
214+
funding_tx_index: u32,
215215
/// The amount potentially available to claim, in satoshis, excluding the on-chain fees
216216
/// which will be required to do so.
217217
amount_satoshis: u64,
@@ -234,7 +234,7 @@ pub enum LightningBalance {
234234
/// Alby: funding transaction ID.
235235
funding_tx_id: Txid,
236236
/// Alby: funding transaction output index.
237-
funding_tx_index: u16,
237+
funding_tx_index: u32,
238238
/// The amount, in satoshis, of the output which we can claim.
239239
amount_satoshis: u64,
240240
},
@@ -245,7 +245,7 @@ impl LightningBalance {
245245
channel_id: ChannelId, counterparty_node_id: PublicKey, funding_txo: OutPoint,
246246
balance: LdkBalance,
247247
) -> Self {
248-
let OutPoint { txid: funding_tx_id, index: funding_tx_index } = funding_txo;
248+
let OutPoint { txid: funding_tx_id, vout: funding_tx_index } = funding_txo;
249249
match balance {
250250
LdkBalance::ClaimableOnChannelClose {
251251
balance_candidates,
@@ -355,7 +355,7 @@ pub enum PendingSweepBalance {
355355
/// Alby: funding transaction ID.
356356
funding_tx_id: Option<Txid>,
357357
/// Alby: funding transaction output index.
358-
funding_tx_index: Option<u16>,
358+
funding_tx_index: Option<u32>,
359359
},
360360
/// A spending transaction has been generated and broadcast and is awaiting confirmation
361361
/// on-chain.
@@ -373,7 +373,7 @@ pub enum PendingSweepBalance {
373373
/// Alby: funding transaction ID.
374374
funding_tx_id: Option<Txid>,
375375
/// Alby: funding transaction output index.
376-
funding_tx_index: Option<u16>,
376+
funding_tx_index: Option<u32>,
377377
},
378378
/// A spending transaction has been confirmed on-chain and is awaiting threshold confirmations.
379379
///
@@ -396,7 +396,7 @@ pub enum PendingSweepBalance {
396396
/// Alby: funding transaction ID.
397397
funding_tx_id: Option<Txid>,
398398
/// Alby: funding transaction output index.
399-
funding_tx_index: Option<u16>,
399+
funding_tx_index: Option<u32>,
400400
},
401401
}
402402

@@ -414,7 +414,7 @@ impl PendingSweepBalance {
414414
amount_satoshis,
415415
counterparty_node_id,
416416
funding_tx_id: funding_txo.map(|funding_txo| funding_txo.txid),
417-
funding_tx_index: funding_txo.map(|funding_txo| funding_txo.index),
417+
funding_tx_index: funding_txo.map(|funding_txo| funding_txo.vout),
418418
}
419419
},
420420
OutputSpendStatus::PendingFirstConfirmation {
@@ -432,7 +432,7 @@ impl PendingSweepBalance {
432432
amount_satoshis,
433433
counterparty_node_id,
434434
funding_tx_id: funding_txo.map(|funding_txo| funding_txo.txid),
435-
funding_tx_index: funding_txo.map(|funding_txo| funding_txo.index),
435+
funding_tx_index: funding_txo.map(|funding_txo| funding_txo.vout),
436436
}
437437
},
438438
OutputSpendStatus::PendingThresholdConfirmations {
@@ -452,7 +452,7 @@ impl PendingSweepBalance {
452452
amount_satoshis,
453453
counterparty_node_id,
454454
funding_tx_id: funding_txo.map(|funding_txo| funding_txo.txid),
455-
funding_tx_index: funding_txo.map(|funding_txo| funding_txo.index),
455+
funding_tx_index: funding_txo.map(|funding_txo| funding_txo.vout),
456456
}
457457
},
458458
}

src/builder.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use std::collections::HashMap;
99
use std::convert::TryInto;
1010
use std::default::Default;
11-
use std::path::PathBuf;
11+
use std::path::{Path, PathBuf};
1212
use std::sync::{Arc, Mutex, Once, RwLock};
1313
use std::time::SystemTime;
1414
use std::{fmt, fs};
@@ -34,8 +34,13 @@ use lightning::routing::scoring::{
3434
use lightning::sign::{EntropySource, NodeSigner};
3535
use lightning::util::persist::{
3636
KVStoreSync, CHANNEL_MANAGER_PERSISTENCE_KEY, CHANNEL_MANAGER_PERSISTENCE_PRIMARY_NAMESPACE,
37-
CHANNEL_MANAGER_PERSISTENCE_SECONDARY_NAMESPACE,
37+
CHANNEL_MANAGER_PERSISTENCE_SECONDARY_NAMESPACE, CHANNEL_MONITOR_PERSISTENCE_PRIMARY_NAMESPACE,
38+
CHANNEL_MONITOR_PERSISTENCE_SECONDARY_NAMESPACE, NETWORK_GRAPH_PERSISTENCE_KEY,
39+
NETWORK_GRAPH_PERSISTENCE_PRIMARY_NAMESPACE, NETWORK_GRAPH_PERSISTENCE_SECONDARY_NAMESPACE,
40+
SCORER_PERSISTENCE_KEY, SCORER_PERSISTENCE_PRIMARY_NAMESPACE,
41+
SCORER_PERSISTENCE_SECONDARY_NAMESPACE,
3842
};
43+
3944
use lightning::util::ser::ReadableArgs;
4045
use lightning::util::sweep::OutputSweeper;
4146
use lightning_persister::fs_store::FilesystemStore;
@@ -65,19 +70,21 @@ use crate::io::{
6570
use crate::liquidity::{
6671
LSPS1ClientConfig, LSPS2ClientConfig, LSPS2ServiceConfig, LiquiditySourceBuilder,
6772
};
68-
use crate::logger::{log_error, LdkLogger, LogLevel, LogWriter, Logger};
73+
use crate::logger::{log_error, log_info, LdkLogger, LogLevel, LogWriter, Logger};
6974
use crate::message_handler::NodeCustomMessageHandler;
7075
use crate::payment::asynchronous::om_mailbox::OnionMessageMailbox;
7176
use crate::peer_store::PeerStore;
7277
use crate::runtime::Runtime;
7378
use crate::tx_broadcaster::TransactionBroadcaster;
7479
use crate::types::{
75-
ChainMonitor, ChannelManager, DynStore, GossipSync, Graph, KeysManager, MessageRouter,
76-
OnionMessenger, PaymentStore, PeerManager, Persister,
80+
ChainMonitor, ChannelManager, DynStore, GossipSync, Graph, KeyValue, KeysManager,
81+
MessageRouter, MigrateStorage, OnionMessenger, PaymentStore, PeerManager, Persister,
82+
ResetState,
7783
};
7884
use crate::wallet::persist::KVStoreWalletPersister;
7985
use crate::wallet::Wallet;
8086
use crate::{Node, NodeMetrics};
87+
use chrono::Local;
8188

8289
const VSS_HARDENED_CHILD_INDEX: u32 = 877;
8390
const VSS_LNURL_AUTH_HARDENED_CHILD_INDEX: u32 = 138;
@@ -252,7 +259,7 @@ pub struct NodeBuilder {
252259
chain_data_source_config: Option<ChainDataSourceConfig>,
253260
gossip_source_config: Option<GossipSourceConfig>,
254261
liquidity_source_config: Option<LiquiditySourceConfig>,
255-
monitors_to_restore: Option<Vec<KeyValue>>,
262+
monitors_to_restore: Option<Vec<KeyValue>>, // Alby: for hub recovery with SCB backup file
256263
reset_state: Option<ResetState>,
257264
migrate_storage: Option<MigrateStorage>,
258265
log_writer_config: Option<LogWriterConfig>,
@@ -618,8 +625,9 @@ impl NodeBuilder {
618625
let storage_dir_path = self.config.storage_dir_path.clone();
619626
fs::create_dir_all(storage_dir_path.clone())
620627
.map_err(|_| BuildError::StoragePathAccessFailed)?;
621-
let sql_store_config =
622-
SqliteStoreConfig { transient_graph: self.config.transient_network_graph };
628+
let sql_store_config = io::sqlite_store::SqliteStoreConfig {
629+
transient_graph: self.config.transient_network_graph,
630+
};
623631
let kv_store = Arc::new(
624632
SqliteStore::with_config(
625633
storage_dir_path.into(),
@@ -805,13 +813,14 @@ impl NodeBuilder {
805813
Some(io::sqlite_store::KV_TABLE_NAME.to_string()),
806814
)
807815
.map_err(|_| BuildError::KVStoreSetupFailed)?,
808-
) as Arc<DynStore>);
816+
) as Arc<SqliteStore>);
809817
}
810818

811819
// Alby: use a secondary KV store for non-essential data (not needed by VSS)
812820
let storage_dir_path = config.storage_dir_path.clone();
813-
let sql_store_config =
814-
SqliteStoreConfig { transient_graph: self.config.transient_network_graph };
821+
let sql_store_config = io::sqlite_store::SqliteStoreConfig {
822+
transient_graph: self.config.transient_network_graph,
823+
};
815824
let secondary_kv_store = Arc::new(
816825
SqliteStore::with_config(
817826
storage_dir_path.into(),
@@ -851,7 +860,7 @@ impl NodeBuilder {
851860
BuildError::KVStoreSetupFailed
852861
})?;
853862
// write value to new store
854-
vss_store.write(primary_namespace, secondary_namespace, key, &value).map_err(
863+
vss_store.write(primary_namespace, secondary_namespace, key, value).map_err(
855864
|e| {
856865
log_error!(logger, "Failed to migrate value: {}", e);
857866
BuildError::KVStoreSetupFailed
@@ -934,7 +943,7 @@ impl NodeBuilder {
934943
if self.monitors_to_restore.is_some() {
935944
let monitors = self.monitors_to_restore.clone().unwrap();
936945
for monitor in monitors {
937-
let result = kv_store.write("monitors", "", &monitor.key, &monitor.value);
946+
let result = &*kv_store.write("monitors", "", &monitor.key, &monitor.value);
938947
if result.is_err() {
939948
log_error!(logger, "Failed to restore monitor: {}", result.unwrap_err());
940949
}

src/event.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ use crate::payment::store::{
8181
PaymentDetails, PaymentDetailsUpdate, PaymentDirection, PaymentKind, PaymentStatus,
8282
};
8383
use crate::runtime::Runtime;
84-
use crate::types::{CustomTlvRecord, DynStore, OnionMessenger, PaymentStore, Sweeper, Wallet};
84+
use crate::types::{
85+
CustomTlvRecord, DynStore, OnionMessenger, PaymentStore, Sweeper, TlvEntry, Wallet,
86+
};
8587
use crate::{
8688
hex_utils, BumpTransactionEventHandler, ChannelManager, Error, Graph, PeerInfo, PeerStore,
8789
UserChannelId,

src/io/sqlite_store/mod.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ use std::sync::atomic::{AtomicU64, Ordering};
1616
use std::sync::{Arc, Mutex};
1717

1818
use lightning::io;
19-
/*use lightning::util::persist::{
20-
KVStore, NETWORK_GRAPH_PERSISTENCE_KEY, NETWORK_GRAPH_PERSISTENCE_PRIMARY_NAMESPACE,
21-
NETWORK_GRAPH_PERSISTENCE_SECONDARY_NAMESPACE,
22-
};
23-
use lightning::util::string::PrintableString;*/
2419

25-
use lightning::util::persist::{KVStore, KVStoreSync};
20+
use lightning::util::persist::{
21+
KVStore, KVStoreSync, NETWORK_GRAPH_PERSISTENCE_KEY,
22+
NETWORK_GRAPH_PERSISTENCE_PRIMARY_NAMESPACE, NETWORK_GRAPH_PERSISTENCE_SECONDARY_NAMESPACE,
23+
};
2624
use lightning_types::string::PrintableString;
2725
use rusqlite::{named_params, Connection};
2826

@@ -60,8 +58,6 @@ impl Default for SqliteStoreConfig {
6058
///
6159
/// [SQLite]: https://sqlite.org
6260
pub struct SqliteStore {
63-
config: SqliteStoreConfig,
64-
6561
inner: Arc<SqliteStoreInner>,
6662

6763
// Version counter to ensure that writes are applied in the correct order. It is assumed that read and list
@@ -117,15 +113,15 @@ impl SqliteStore {
117113

118114
if config.transient_graph {
119115
// Drop existing network graph if it has been persisted before.
120-
ret.remove(
116+
ret.inner.remove_internal(
121117
NETWORK_GRAPH_PERSISTENCE_PRIMARY_NAMESPACE,
122118
NETWORK_GRAPH_PERSISTENCE_SECONDARY_NAMESPACE,
123119
NETWORK_GRAPH_PERSISTENCE_KEY,
124120
false,
125121
)?;
126122
}
127123

128-
ret.config = config;
124+
ret.inner.config = config;
129125
Ok(ret)
130126
}
131127
}
@@ -270,6 +266,7 @@ struct SqliteStoreInner {
270266
data_dir: PathBuf,
271267
kv_table_name: String,
272268
write_version_locks: Mutex<HashMap<String, Arc<Mutex<u64>>>>,
269+
config: SqliteStoreConfig,
273270
}
274271

275272
impl SqliteStoreInner {
@@ -344,7 +341,13 @@ impl SqliteStoreInner {
344341

345342
let connection = Arc::new(Mutex::new(connection));
346343
let write_version_locks = Mutex::new(HashMap::new());
347-
Ok(Self { connection, data_dir, kv_table_name, write_version_locks })
344+
Ok(Self {
345+
connection,
346+
data_dir,
347+
kv_table_name,
348+
write_version_locks,
349+
config: SqliteStoreConfig::default(),
350+
})
348351
}
349352

350353
fn get_inner_lock_ref(&self, locking_key: String) -> Arc<Mutex<u64>> {

0 commit comments

Comments
 (0)