Skip to content

Commit 637b3a0

Browse files
committed
Use async fsstore
1 parent 3009e54 commit 637b3a0

10 files changed

Lines changed: 572 additions & 554 deletions

File tree

Cargo.toml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@ default = []
5252
#lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
5353
#lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
5454

55-
lightning = { git = "https://github.com/joostjager/rust-lightning", branch="owned-kvstore-args", features = ["std"] }
56-
lightning-types = { git = "https://github.com/joostjager/rust-lightning", branch="owned-kvstore-args" }
57-
lightning-invoice = { git = "https://github.com/joostjager/rust-lightning", branch="owned-kvstore-args", features = ["std"] }
58-
lightning-net-tokio = { git = "https://github.com/joostjager/rust-lightning", branch="owned-kvstore-args" }
59-
lightning-persister = { git = "https://github.com/joostjager/rust-lightning", branch="owned-kvstore-args" }
60-
lightning-background-processor = { git = "https://github.com/joostjager/rust-lightning", branch="owned-kvstore-args" }
61-
lightning-rapid-gossip-sync = { git = "https://github.com/joostjager/rust-lightning", branch="owned-kvstore-args" }
62-
lightning-block-sync = { git = "https://github.com/joostjager/rust-lightning", branch="owned-kvstore-args", features = ["rest-client", "rpc-client", "tokio"] }
63-
lightning-transaction-sync = { git = "https://github.com/joostjager/rust-lightning", branch="owned-kvstore-args", features = ["esplora-async-https", "electrum", "time"] }
64-
lightning-liquidity = { git = "https://github.com/joostjager/rust-lightning", branch="owned-kvstore-args" }
65-
lightning-macros = { git = "https://github.com/joostjager/rust-lightning", branch="owned-kvstore-args" }
55+
lightning = { git = "https://github.com/joostjager/rust-lightning", branch = "async-fsstore", features = ["std"] }
56+
lightning-types = { git = "https://github.com/joostjager/rust-lightning", branch = "async-fsstore" }
57+
lightning-invoice = { git = "https://github.com/joostjager/rust-lightning", branch = "async-fsstore", features = ["std"] }
58+
lightning-net-tokio = { git = "https://github.com/joostjager/rust-lightning", branch = "async-fsstore" }
59+
lightning-persister = { git = "https://github.com/joostjager/rust-lightning", branch = "async-fsstore", features = ["tokio"] }
60+
lightning-background-processor = { git = "https://github.com/joostjager/rust-lightning", branch = "async-fsstore" }
61+
lightning-rapid-gossip-sync = { git = "https://github.com/joostjager/rust-lightning", branch = "async-fsstore" }
62+
lightning-block-sync = { git = "https://github.com/joostjager/rust-lightning", branch = "async-fsstore", features = ["rest-client", "rpc-client", "tokio"] }
63+
lightning-transaction-sync = { git = "https://github.com/joostjager/rust-lightning", branch = "async-fsstore", features = ["esplora-async-https", "electrum", "time"] }
64+
lightning-liquidity = { git = "https://github.com/joostjager/rust-lightning", branch = "async-fsstore" }
65+
lightning-macros = { git = "https://github.com/joostjager/rust-lightning", branch = "async-fsstore" }
6666

6767
#lightning = { path = "../rust-lightning/lightning", features = ["std"] }
6868
#lightning-types = { path = "../rust-lightning/lightning-types" }
@@ -108,7 +108,7 @@ winapi = { version = "0.3", features = ["winbase"] }
108108
[dev-dependencies]
109109
#lightning = { version = "0.1.0", features = ["std", "_test_utils"] }
110110
#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["std", "_test_utils"] }
111-
lightning = { git = "https://github.com/joostjager/rust-lightning", branch="owned-kvstore-args", features = ["std", "_test_utils"] }
111+
lightning = { git = "https://github.com/joostjager/rust-lightning", branch = "async-fsstore", features = ["std", "_test_utils"] }
112112
#lightning = { path = "../rust-lightning/lightning", features = ["std", "_test_utils"] }
113113
proptest = "1.0.0"
114114
regex = "1.5.6"

src/builder.rs

Lines changed: 114 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ use crate::message_handler::NodeCustomMessageHandler;
3030
use crate::peer_store::PeerStore;
3131
use crate::tx_broadcaster::TransactionBroadcaster;
3232
use crate::types::{
33-
ChainMonitor, ChannelManager, DynStore, GossipSync, Graph, KeysManager, MessageRouter,
34-
OnionMessenger, PaymentStore, PeerManager,
33+
ChainMonitor, ChannelManager, DynStore, DynStoreAsync, GossipSync, Graph, KeysManager,
34+
MessageRouter, OnionMessenger, PaymentStore, PeerManager,
3535
};
3636
use crate::wallet::persist::KVStoreWalletPersister;
3737
use crate::wallet::Wallet;
@@ -50,7 +50,7 @@ use lightning::routing::scoring::{
5050
use lightning::sign::{EntropySource, NodeSigner};
5151

5252
use lightning::util::persist::{
53-
read_channel_monitors, CHANNEL_MANAGER_PERSISTENCE_KEY,
53+
read_channel_monitors, KVStore, CHANNEL_MANAGER_PERSISTENCE_KEY,
5454
CHANNEL_MANAGER_PERSISTENCE_PRIMARY_NAMESPACE, CHANNEL_MANAGER_PERSISTENCE_SECONDARY_NAMESPACE,
5555
};
5656
use lightning::util::ser::ReadableArgs;
@@ -529,20 +529,20 @@ impl NodeBuilder {
529529

530530
/// Builds a [`Node`] instance with a [`SqliteStore`] backend and according to the options
531531
/// previously configured.
532-
pub fn build(&self) -> Result<Node, BuildError> {
533-
let storage_dir_path = self.config.storage_dir_path.clone();
534-
fs::create_dir_all(storage_dir_path.clone())
535-
.map_err(|_| BuildError::StoragePathAccessFailed)?;
536-
let kv_store = Arc::new(
537-
SqliteStore::new(
538-
storage_dir_path.into(),
539-
Some(io::sqlite_store::SQLITE_DB_FILE_NAME.to_string()),
540-
Some(io::sqlite_store::KV_TABLE_NAME.to_string()),
541-
)
542-
.map_err(|_| BuildError::KVStoreSetupFailed)?,
543-
);
544-
self.build_with_store(kv_store)
545-
}
532+
// pub async fn build(&self) -> Result<Node, BuildError> {
533+
// let storage_dir_path = self.config.storage_dir_path.clone();
534+
// fs::create_dir_all(storage_dir_path.clone())
535+
// .map_err(|_| BuildError::StoragePathAccessFailed)?;
536+
// let kv_store = Arc::new(
537+
// SqliteStore::new(
538+
// storage_dir_path.into(),
539+
// Some(io::sqlite_store::SQLITE_DB_FILE_NAME.to_string()),
540+
// Some(io::sqlite_store::KV_TABLE_NAME.to_string()),
541+
// )
542+
// .map_err(|_| BuildError::KVStoreSetupFailed)?,
543+
// );
544+
// self.build_with_store(kv_store)
545+
// }
546546

547547
/// Builds a [`Node`] instance with a [`FilesystemStore`] backend and according to the options
548548
/// previously configured.
@@ -553,7 +553,10 @@ impl NodeBuilder {
553553
fs::create_dir_all(storage_dir_path.clone())
554554
.map_err(|_| BuildError::StoragePathAccessFailed)?;
555555
let kv_store = Arc::new(FilesystemStore::new(storage_dir_path));
556-
self.build_with_store(kv_store)
556+
557+
let kv_store_async: Arc<DynStoreAsync> = kv_store.clone();
558+
559+
self.build_with_store(kv_store, kv_store_async)
557560
}
558561

559562
/// Builds a [`Node`] instance with a [VSS] backend and according to the options
@@ -573,46 +576,46 @@ impl NodeBuilder {
573576
///
574577
/// [VSS]: https://github.com/lightningdevkit/vss-server/blob/main/README.md
575578
/// [LNURL-auth]: https://github.com/lnurl/luds/blob/luds/04.md
576-
pub fn build_with_vss_store(
577-
&self, vss_url: String, store_id: String, lnurl_auth_server_url: String,
578-
fixed_headers: HashMap<String, String>,
579-
) -> Result<Node, BuildError> {
580-
use bitcoin::key::Secp256k1;
581-
582-
let logger = setup_logger(&self.log_writer_config, &self.config)?;
583-
584-
let seed_bytes = seed_bytes_from_config(
585-
&self.config,
586-
self.entropy_source_config.as_ref(),
587-
Arc::clone(&logger),
588-
)?;
589-
590-
let config = Arc::new(self.config.clone());
591-
592-
let vss_xprv =
593-
derive_xprv(config, &seed_bytes, VSS_HARDENED_CHILD_INDEX, Arc::clone(&logger))?;
594-
595-
let lnurl_auth_xprv = vss_xprv
596-
.derive_priv(
597-
&Secp256k1::new(),
598-
&[ChildNumber::Hardened { index: VSS_LNURL_AUTH_HARDENED_CHILD_INDEX }],
599-
)
600-
.map_err(|e| {
601-
log_error!(logger, "Failed to derive VSS secret: {}", e);
602-
BuildError::KVStoreSetupFailed
603-
})?;
604-
605-
let lnurl_auth_jwt_provider =
606-
LnurlAuthToJwtProvider::new(lnurl_auth_xprv, lnurl_auth_server_url, fixed_headers)
607-
.map_err(|e| {
608-
log_error!(logger, "Failed to create LnurlAuthToJwtProvider: {}", e);
609-
BuildError::KVStoreSetupFailed
610-
})?;
611-
612-
let header_provider = Arc::new(lnurl_auth_jwt_provider);
613-
614-
self.build_with_vss_store_and_header_provider(vss_url, store_id, header_provider)
615-
}
579+
// pub fn build_with_vss_store(
580+
// &self, vss_url: String, store_id: String, lnurl_auth_server_url: String,
581+
// fixed_headers: HashMap<String, String>,
582+
// ) -> Result<Node, BuildError> {
583+
// use bitcoin::key::Secp256k1;
584+
585+
// let logger = setup_logger(&self.log_writer_config, &self.config)?;
586+
587+
// let seed_bytes = seed_bytes_from_config(
588+
// &self.config,
589+
// self.entropy_source_config.as_ref(),
590+
// Arc::clone(&logger),
591+
// )?;
592+
593+
// let config = Arc::new(self.config.clone());
594+
595+
// let vss_xprv =
596+
// derive_xprv(config, &seed_bytes, VSS_HARDENED_CHILD_INDEX, Arc::clone(&logger))?;
597+
598+
// let lnurl_auth_xprv = vss_xprv
599+
// .derive_priv(
600+
// &Secp256k1::new(),
601+
// &[ChildNumber::Hardened { index: VSS_LNURL_AUTH_HARDENED_CHILD_INDEX }],
602+
// )
603+
// .map_err(|e| {
604+
// log_error!(logger, "Failed to derive VSS secret: {}", e);
605+
// BuildError::KVStoreSetupFailed
606+
// })?;
607+
608+
// let lnurl_auth_jwt_provider =
609+
// LnurlAuthToJwtProvider::new(lnurl_auth_xprv, lnurl_auth_server_url, fixed_headers)
610+
// .map_err(|e| {
611+
// log_error!(logger, "Failed to create LnurlAuthToJwtProvider: {}", e);
612+
// BuildError::KVStoreSetupFailed
613+
// })?;
614+
615+
// let header_provider = Arc::new(lnurl_auth_jwt_provider);
616+
617+
// self.build_with_vss_store_and_header_provider(vss_url, store_id, header_provider)
618+
// }
616619

617620
/// Builds a [`Node`] instance with a [VSS] backend and according to the options
618621
/// previously configured.
@@ -626,13 +629,13 @@ impl NodeBuilder {
626629
/// unrecoverable, i.e., if they remain unresolved after internal retries are exhausted.
627630
///
628631
/// [VSS]: https://github.com/lightningdevkit/vss-server/blob/main/README.md
629-
pub fn build_with_vss_store_and_fixed_headers(
630-
&self, vss_url: String, store_id: String, fixed_headers: HashMap<String, String>,
631-
) -> Result<Node, BuildError> {
632-
let header_provider = Arc::new(FixedHeaders::new(fixed_headers));
632+
// pub fn build_with_vss_store_and_fixed_headers(
633+
// &self, vss_url: String, store_id: String, fixed_headers: HashMap<String, String>,
634+
// ) -> Result<Node, BuildError> {
635+
// let header_provider = Arc::new(FixedHeaders::new(fixed_headers));
633636

634-
self.build_with_vss_store_and_header_provider(vss_url, store_id, header_provider)
635-
}
637+
// self.build_with_vss_store_and_header_provider(vss_url, store_id, header_provider)
638+
// }
636639

637640
/// Builds a [`Node`] instance with a [VSS] backend and according to the options
638641
/// previously configured.
@@ -645,46 +648,49 @@ impl NodeBuilder {
645648
/// unrecoverable, i.e., if they remain unresolved after internal retries are exhausted.
646649
///
647650
/// [VSS]: https://github.com/lightningdevkit/vss-server/blob/main/README.md
648-
pub fn build_with_vss_store_and_header_provider(
649-
&self, vss_url: String, store_id: String, header_provider: Arc<dyn VssHeaderProvider>,
650-
) -> Result<Node, BuildError> {
651-
let logger = setup_logger(&self.log_writer_config, &self.config)?;
652-
653-
let seed_bytes = seed_bytes_from_config(
654-
&self.config,
655-
self.entropy_source_config.as_ref(),
656-
Arc::clone(&logger),
657-
)?;
658-
659-
let config = Arc::new(self.config.clone());
660-
661-
let vss_xprv = derive_xprv(
662-
config.clone(),
663-
&seed_bytes,
664-
VSS_HARDENED_CHILD_INDEX,
665-
Arc::clone(&logger),
666-
)?;
667-
668-
let vss_seed_bytes: [u8; 32] = vss_xprv.private_key.secret_bytes();
669-
670-
let vss_store =
671-
VssStore::new(vss_url, store_id, vss_seed_bytes, header_provider).map_err(|e| {
672-
log_error!(logger, "Failed to setup VssStore: {}", e);
673-
BuildError::KVStoreSetupFailed
674-
})?;
675-
build_with_store_internal(
676-
config,
677-
self.chain_data_source_config.as_ref(),
678-
self.gossip_source_config.as_ref(),
679-
self.liquidity_source_config.as_ref(),
680-
seed_bytes,
681-
logger,
682-
Arc::new(vss_store),
683-
)
684-
}
651+
// pub async fn build_with_vss_store_and_header_provider(
652+
// &self, vss_url: String, store_id: String, header_provider: Arc<dyn VssHeaderProvider>,
653+
// ) -> Result<Node, BuildError> {
654+
// let logger = setup_logger(&self.log_writer_config, &self.config)?;
655+
656+
// let seed_bytes = seed_bytes_from_config(
657+
// &self.config,
658+
// self.entropy_source_config.as_ref(),
659+
// Arc::clone(&logger),
660+
// )?;
661+
662+
// let config = Arc::new(self.config.clone());
663+
664+
// let vss_xprv = derive_xprv(
665+
// config.clone(),
666+
// &seed_bytes,
667+
// VSS_HARDENED_CHILD_INDEX,
668+
// Arc::clone(&logger),
669+
// )?;
670+
671+
// let vss_seed_bytes: [u8; 32] = vss_xprv.private_key.secret_bytes();
672+
673+
// let vss_store =
674+
// VssStore::new(vss_url, store_id, vss_seed_bytes, header_provider).map_err(|e| {
675+
// log_error!(logger, "Failed to setup VssStore: {}", e);
676+
// BuildError::KVStoreSetupFailed
677+
// })?;
678+
// build_with_store_internal(
679+
// config,
680+
// self.chain_data_source_config.as_ref(),
681+
// self.gossip_source_config.as_ref(),
682+
// self.liquidity_source_config.as_ref(),
683+
// seed_bytes,
684+
// logger,
685+
// Arc::new(vss_store),
686+
// )
687+
// .await
688+
// }
685689

686690
/// Builds a [`Node`] instance according to the options previously configured.
687-
pub fn build_with_store(&self, kv_store: Arc<DynStore>) -> Result<Node, BuildError> {
691+
pub fn build_with_store(
692+
&self, kv_store: Arc<DynStore>, kv_store_async: Arc<DynStoreAsync>,
693+
) -> Result<Node, BuildError> {
688694
let logger = setup_logger(&self.log_writer_config, &self.config)?;
689695

690696
let seed_bytes = seed_bytes_from_config(
@@ -702,6 +708,7 @@ impl NodeBuilder {
702708
seed_bytes,
703709
logger,
704710
kv_store,
711+
kv_store_async,
705712
)
706713
}
707714
}
@@ -1049,7 +1056,7 @@ fn build_with_store_internal(
10491056
config: Arc<Config>, chain_data_source_config: Option<&ChainDataSourceConfig>,
10501057
gossip_source_config: Option<&GossipSourceConfig>,
10511058
liquidity_source_config: Option<&LiquiditySourceConfig>, seed_bytes: [u8; 64],
1052-
logger: Arc<Logger>, kv_store: Arc<DynStore>,
1059+
logger: Arc<Logger>, kv_store: Arc<DynStore>, kv_store_async: Arc<DynStoreAsync>,
10531060
) -> Result<Node, BuildError> {
10541061
if let Err(err) = may_announce_channel(&config) {
10551062
if config.announcement_addresses.is_some() {
@@ -1567,19 +1574,20 @@ fn build_with_store_internal(
15671574
Arc::clone(&chain_source),
15681575
Arc::clone(&keys_manager),
15691576
Arc::clone(&kv_store),
1577+
Arc::clone(&kv_store_async),
15701578
Arc::clone(&logger),
15711579
) {
15721580
Ok(output_sweeper) => Arc::new(output_sweeper),
15731581
Err(e) => {
15741582
if e.kind() == std::io::ErrorKind::NotFound {
1575-
Arc::new(OutputSweeper::new_with_kv_store_sync(
1583+
Arc::new(OutputSweeper::new(
15761584
channel_manager.current_best_block(),
15771585
Arc::clone(&tx_broadcaster),
15781586
Arc::clone(&fee_estimator),
15791587
Some(Arc::clone(&chain_source)),
15801588
Arc::clone(&keys_manager),
15811589
Arc::clone(&keys_manager),
1582-
Arc::clone(&kv_store),
1590+
Arc::clone(&kv_store_async),
15831591
Arc::clone(&logger),
15841592
))
15851593
} else {
@@ -1634,6 +1642,7 @@ fn build_with_store_internal(
16341642
gossip_source,
16351643
liquidity_source,
16361644
kv_store,
1645+
kv_store_async,
16371646
logger,
16381647
_router: router,
16391648
scorer,

0 commit comments

Comments
 (0)