Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into testnet-alpha-1
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-wright committed Oct 16, 2023
2 parents 2d6ce4b + 6c23d66 commit 0166dba
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ if [[ ! -d /root/.lightning/keystore ]]; then
lgtn keys generate
fi

lgtn -v run
lgtn -vv run
EOF

RUN chmod +x /root/init
Expand Down
69 changes: 69 additions & 0 deletions core/handshake/src/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,72 @@ impl<C: Collection> WithStartAndShutdown for Handshake<C> {
});
}
}

#[cfg(test)]
mod tests {
use std::time::Duration;

use affair::{Executor, TokioSpawn, Worker};
use anyhow::Result;
use infusion::Blank;
use lightning_blockstore::blockstore::Blockstore;
use lightning_interfaces::types::TransactionRequest;
use lightning_interfaces::{partial, BlockStoreInterface};
use lightning_service_executor::shim::{ServiceExecutor, ServiceExecutorConfig};
use lightning_signer::Signer;
use tokio::sync::Notify;

use super::*;

partial!(TestBinding {
HandshakeInterface = Handshake<Self>;
ServiceExecutorInterface = ServiceExecutor<Self>;
SignerInterface = Signer<Self>;
BlockStoreInterface = Blockstore<Self>;
});

struct DummyWorker;
impl Worker for DummyWorker {
type Request = TransactionRequest;
type Response = ();
fn handle(&mut self, _: Self::Request) -> Self::Response {
todo!()
}
}

#[tokio::test]
async fn restart() -> Result<()> {
let mut signer = Signer::init(lightning_signer::Config::test(), Blank::default())?;
let socket = TokioSpawn::spawn(DummyWorker);
signer.provide_mempool(socket);
signer.provide_new_block_notify(Notify::default().into());
let blockstore = Blockstore::init(lightning_blockstore::config::Config::default())?;
let service_executor =
ServiceExecutor::<TestBinding>::init(ServiceExecutorConfig::default(), &blockstore)?;
signer.start().await;
service_executor.start().await;

// Startup handshake
let handshake = Handshake::<TestBinding>::init(
HandshakeConfig::default(),
&signer,
service_executor.get_provider(),
)?;
handshake.start().await;
tokio::time::sleep(Duration::from_secs(1)).await;
// Shutdown and drop it
handshake.shutdown().await;
drop(handshake);

// Start handshake again
tokio::time::sleep(Duration::from_secs(1)).await;
let handshake = Handshake::<TestBinding>::init(
HandshakeConfig::default(),
&signer,
service_executor.get_provider(),
)?;
handshake.start().await;

Ok(())
}
}
4 changes: 2 additions & 2 deletions core/node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use lightning_interfaces::infu_collection::{Collection, Node};
use lightning_interfaces::ConfigConsumer;
use resolved_pathbuf::ResolvedPathBuf;
use toml::{Table, Value};
use tracing::info;
use tracing::debug;

/// The implementation of a configuration loader that uses the `toml` backend.
pub struct TomlConfigProvider<C: Collection> {
Expand Down Expand Up @@ -93,7 +93,7 @@ impl<C: Collection> TomlConfigProvider<C> {

impl<C: Collection> ConfigProviderInterface<C> for TomlConfigProvider<C> {
fn get<S: lightning_interfaces::config::ConfigConsumer>(&self) -> S::Config {
info!("Getting the config for {}", std::any::type_name::<S>());
debug!("Getting the config for {}", std::any::type_name::<S>());

let mut table = self.table.lock().expect("failed to acquire lock");

Expand Down
1 change: 1 addition & 0 deletions core/service-executor/src/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ impl<C: Collection> WithStartAndShutdown for ServiceExecutor<C> {
}

async fn shutdown(&self) {
fn_sdk::api::unregister();
self.is_running.store(false, Ordering::Relaxed)
}
}
Expand Down
8 changes: 8 additions & 0 deletions lib/sdk/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ pub fn setup(args: OnStartArgs) {
}
}

#[doc(hidden)]
pub fn unregister() {
unsafe {
SENDER = None;
BLOCKSTORE = None;
}
}

pub(crate) fn blockstore_root() -> &'static PathBuf {
unsafe { BLOCKSTORE.as_ref().expect("setup not completed") }
}
Expand Down

0 comments on commit 0166dba

Please sign in to comment.