Skip to content

Commit

Permalink
setup path correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
1xstj committed Oct 24, 2023
1 parent 107dbdd commit e69487d
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 19 deletions.
Binary file added alice
Binary file not shown.
1 change: 1 addition & 0 deletions dkg-gadget/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod sql_storage;
use crate::async_protocols::types::LocalKeyType;
pub use mem::DKGInMemoryDb;
pub use offchain_storage::DKGOffchainStorageDb;
pub use sql_storage::{BackendConfig, SqlBackend, SqliteBackendConfig};

/// A Database backend, specifically for the DKG to store and load important state
///
Expand Down
25 changes: 24 additions & 1 deletion dkg-gadget/src/db/sql_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,17 @@ pub struct SqlBackend {
}

impl SqlBackend {
pub fn new(
config: BackendConfig<'_>,
pool_size: u32,
num_ops_timeout: Option<NonZeroU32>,
) -> Result<Self, Error> {
futures::executor::block_on(async {
Self::new_inner(config, pool_size, num_ops_timeout).await
})
}
/// Creates a new instance of the SQL backend.
pub async fn new(
pub async fn new_inner(
config: BackendConfig<'_>,
pool_size: u32,
num_ops_timeout: Option<NonZeroU32>,
Expand Down Expand Up @@ -179,3 +188,17 @@ impl SqlBackend {
tx.commit().await.map_err(|_| DKGError::StoringLocalKeyFailed)
}
}

impl super::DKGDbBackend for SqlBackend {
fn get_local_key(&self, session_id: SessionId) -> Result<Option<LocalKeyType>, DKGError> {
futures::executor::block_on(async { self.get_local_key(session_id).await })
}

fn store_local_key(
&self,
session_id: SessionId,
local_key: LocalKeyType,
) -> Result<(), DKGError> {
futures::executor::block_on(async { self.store_local_key(session_id, local_key).await })
}
}
40 changes: 30 additions & 10 deletions dkg-gadget/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use std::{marker::PhantomData, sync::Arc};

use debug_logger::DebugLogger;
use dkg_runtime_primitives::{crypto::AuthorityId, DKGApi, MaxAuthorities, MaxProposalLength};
use parking_lot::RwLock;
Expand All @@ -26,6 +23,11 @@ use sp_api::{NumberFor, ProvideRuntimeApi};
use sp_blockchain::HeaderBackend;
use sp_keystore::KeystorePtr;
use sp_runtime::traits::Block;
use std::{
marker::PhantomData,
path::{Path, PathBuf},
sync::Arc,
};

mod error;
/// Stores keypairs for DKG
Expand Down Expand Up @@ -107,6 +109,8 @@ where
pub prometheus_registry: Option<Registry>,
/// For logging
pub debug_logger: DebugLogger,
/// database path
pub db_path: PathBuf,
/// Phantom block type
pub _block: PhantomData<B>,
}
Expand Down Expand Up @@ -134,6 +138,7 @@ where
local_keystore,
_block,
debug_logger,
db_path,
} = dkg_params;

let dkg_keystore: DKGKeystore = DKGKeystore::new(key_store, debug_logger.clone());
Expand Down Expand Up @@ -180,13 +185,28 @@ where

// In memory backend, not used for now
// let db_backend = Arc::new(db::DKGInMemoryDb::new());
let offchain_db_backend = db::DKGOffchainStorageDb::new(
backend.clone(),
dkg_keystore.clone(),
local_keystore.clone(),
debug_logger.clone(),
);
let db_backend = Arc::new(offchain_db_backend);
// let offchain_db_backend = db::DKGOffchainStorageDb::new(
// backend.clone(),
// dkg_keystore.clone(),
// local_keystore.clone(),
// debug_logger.clone(),
// );

let path = Path::new("sqlite:///").join(db_path).join("frontier.db3");

let sql_backend = db::SqlBackend::new(
db::BackendConfig::Sqlite(db::SqliteBackendConfig {
path: path.to_str().unwrap(),
create_if_missing: true,
cache_size: 20480,
thread_count: 4,
}),
1,
None,
)
.unwrap();

let db_backend = Arc::new(sql_backend);
let worker_params = worker::WorkerParams {
latest_header,
client,
Expand Down
4 changes: 2 additions & 2 deletions dkg-primitives/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ pub enum DKGError {
InputOutOfBounds,
CannotSign,
LocalKeyNotFound,
StoringLocalKeyFailed
StoringLocalKeyFailed,
}

impl fmt::Display for DKGError {
Expand Down Expand Up @@ -245,7 +245,7 @@ impl fmt::Display for DKGError {
InputOutOfBounds => "Input value out of bounds set by runtime".to_string(),
CannotSign => "Could not sign public key".to_string(),
LocalKeyNotFound => "Local key not found!".to_string(),
StoringLocalKeyFailed => "Local key not be saved!".to_string(),
StoringLocalKeyFailed => "Local key not be saved!".to_string(),
};
write!(f, "DKGError of type {label}")
}
Expand Down
10 changes: 5 additions & 5 deletions scripts/run-local-testnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,28 @@ echo "*** Start Webb DKG Node ***"
# Alice
./target/release/dkg-standalone-node --tmp --chain local --validator -lerror --alice --output-path=./tmp/alice/output.log \
--rpc-cors all --rpc-external --rpc-methods=unsafe \
--port 30333 \
--port 30333 --db-path=./tmp/alice/db \
--rpc-port 9944 --node-key 0000000000000000000000000000000000000000000000000000000000000001 &
# Bob
./target/release/dkg-standalone-node --tmp --chain local --validator -lerror --bob --output-path=./tmp/bob/output.log \
--rpc-cors all --rpc-external --rpc-methods=unsafe \
--port 30305 \
--port 30305 --db-path=./tmp/bob/db \
--rpc-port 9945 --bootnodes /ip4/127.0.0.1/tcp/30333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp &
# Charlie
./target/release/dkg-standalone-node --tmp --chain local --validator -lerror --charlie --output-path=./tmp/charlie/output.log \
--rpc-cors all --rpc-external --rpc-methods=unsafe \
--port 30308 \
--port 30308 --db-path=./tmp/charlie/db \
--rpc-port 9946 --bootnodes /ip4/127.0.0.1/tcp/30333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp &
# Dave
./target/release/dkg-standalone-node --tmp --chain local --validator -lerror --dave --output-path=./tmp/dave/output.log \
--rpc-cors all --rpc-external --rpc-methods=unsafe \
--port 30309 \
--port 30309 --db-path=./tmp/dave/db \
--rpc-port 9947 --bootnodes /ip4/127.0.0.1/tcp/30333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp &
# Eve
./target/release/dkg-standalone-node --tmp --chain local --validator -linfo --eve --output-path=./tmp/eve/output.log \
--rpc-cors all --rpc-external \
--rpc-port 9948 \
--port 30310 \
--port 30310 --db-path=./tmp/eve/db \
-ldkg=debug \
-ldkg_gadget::worker=debug \
-lruntime::dkg_metadata=debug \
Expand Down
2 changes: 2 additions & 0 deletions standalone/node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub struct Cli {
pub subcommand: Option<Subcommand>,
#[clap(flatten)]
pub run: RunCmd,
#[arg(long, short = 'd')]
pub db_path: std::path::PathBuf,
#[arg(long, short = 'o')]
pub output_path: Option<std::path::PathBuf>,
#[clap(flatten)]
Expand Down
1 change: 1 addition & 0 deletions standalone/node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ pub fn run() -> sc_cli::Result<()> {
runner.run_node_until_exit(|config| async move {
service::new_full(service::RunFullParams {
config,
db_path: cli.db_path,
debug_output: cli.output_path,
relayer_cmd: cli.relayer_cmd,
})
Expand Down
4 changes: 3 additions & 1 deletion standalone/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,13 @@ pub fn new_partial(
pub struct RunFullParams {
pub config: Configuration,
pub debug_output: Option<std::path::PathBuf>,
pub db_path: std::path::PathBuf,
pub relayer_cmd: webb_relayer_gadget_cli::WebbRelayerCmd,
}

/// Builds a new service for a full client.
pub fn new_full(
RunFullParams { config, debug_output, relayer_cmd }: RunFullParams,
RunFullParams { config, debug_output, db_path, relayer_cmd }: RunFullParams,
) -> Result<TaskManager, ServiceError> {
let sc_service::PartialComponents {
client,
Expand Down Expand Up @@ -269,6 +270,7 @@ pub fn new_full(
sync_service: sync_service.clone(),
prometheus_registry: prometheus_registry.clone(),
local_keystore: Some(keystore_container.local_keystore()),
db_path,
_block: std::marker::PhantomData::<Block>,
debug_logger,
};
Expand Down

0 comments on commit e69487d

Please sign in to comment.