Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved multisig to its own crate #3147

Merged
merged 14 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions engine/generate-genesis-keys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@ section = "rust"

[dependencies]
anyhow = "1.0"
chainflip-engine = {path = "../../engine/"}
hex = "0.4.3"
bincode = "1.3.3"
csv = "1.1.6"
serde_json = "1.0"
serde = {version = "1.0", features = ["derive"]}
state-chain-runtime = {path = "../../state-chain/runtime"}
cf-primitives = {path = "../../state-chain/primitives"}
chainflip-node = {path = "../../state-chain/node"}
# have to use the older version until secp256k1 updates its dependency (https://github.com/rust-bitcoin/rust-secp256k1/issues/328)
rand_legacy = { package = "rand", version = "0.6" }

# Local deps
chainflip-engine = {path = "../../engine"}
chainflip-node = {path = "../../state-chain/node"}
multisig = {path = "../../engine/multisig"}

[dependencies.rocksdb]
version = "0.19.0"
# Disabling of default features, and using lz4 compression is primarily to avoid linker issues
Expand Down
14 changes: 6 additions & 8 deletions engine/generate-genesis-keys/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use cf_primitives::{KeyId, GENESIS_EPOCH};

use chainflip_engine::{
db::PersistentKeyDB,
multisig::{
client::keygen::generate_key_data, eth::EthSigning, polkadot::PolkadotSigning,
CryptoScheme, Rng,
},
};
use chainflip_engine::db::PersistentKeyDB;
use chainflip_node::chain_spec::use_chainflip_account_id_encoding;
use multisig::{
client::keygen::generate_key_data, eth::EthSigning, polkadot::PolkadotSigning, CryptoScheme,
Rng,
};
use rand_legacy::FromEntropy;
use state_chain_runtime::AccountId;
use std::{
Expand Down Expand Up @@ -117,7 +115,7 @@ fn generate_and_save_keys<Crypto: CryptoScheme>(
#[cfg(test)]
#[test]
fn should_generate_and_save_all_keys() {
use chainflip_engine::multisig::bitcoin::BtcSigning;
use multisig::bitcoin::BtcSigning;

let tempdir = tempfile::TempDir::new().unwrap();
let db_path = tempdir.path().to_owned().join("test");
Expand Down
4 changes: 2 additions & 2 deletions engine/multisig/src/client/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct KeygenResult<C: CryptoScheme> {
}

/// This computes a scalar, multiplying by which the public key will become compatible
/// according to [`crate::multisig::CryptoScheme::is_pubkey_compatible`].
/// according to [`multisig::CryptoScheme::is_pubkey_compatible`].
fn compute_compatibility_factor<C: CryptoScheme>(
pubkey: &C::Point,
) -> <C::Point as ECPoint>::Scalar {
Expand All @@ -59,7 +59,7 @@ fn compute_compatibility_factor<C: CryptoScheme>(

impl<C: CryptoScheme> KeygenResult<C> {
/// Create keygen result, ensuring that the public key is "contract compatible" (mostly relevant
/// for Ethereum keys/contracts, see [`crate::multisig::CryptoScheme::is_pubkey_compatible`]).
/// for Ethereum keys/contracts, see [`multisig::CryptoScheme::is_pubkey_compatible`]).
/// Note that the keys might be modified as part of this procedure. However, the result is
/// guaranteed to produce a valid multisig share as long as all ceremony participants use the
/// same procedure.
Expand Down
16 changes: 7 additions & 9 deletions engine/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{collections::HashMap, sync::Arc};
use cf_primitives::KeyId;
pub use persistent::PersistentKeyDB;

use crate::multisig::{
use multisig::{
client::{key_store_api::KeyStoreAPI, KeygenResultInfo},
CryptoScheme,
};
Expand Down Expand Up @@ -50,15 +50,13 @@ impl<C: CryptoScheme> KeyStoreAPI<C> for KeyStore<C> {
#[cfg(test)]
mod tests {
use super::*;
use crate::{
db::PersistentKeyDB,
multisig::{
client::{keygen, keygen::generate_key_data},
eth::EthSigning,
Rng,
},
};
use crate::db::PersistentKeyDB;
use cf_primitives::AccountId;
use multisig::{
client::{keygen, keygen::generate_key_data},
eth::EthSigning,
Rng,
};
use rand_legacy::FromEntropy;
use std::collections::BTreeSet;

Expand Down
10 changes: 4 additions & 6 deletions engine/src/db/persistent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ use rocksdb::{ColumnFamily, ColumnFamilyDescriptor, Options, WriteBatch, DB};
use serde::{de::DeserializeOwned, Serialize};
use tracing::{debug, info, info_span};

use crate::{
multisig::{
client::KeygenResultInfo, eth::EthSigning, polkadot::PolkadotSigning, ChainTag,
CryptoScheme, CHAIN_TAG_SIZE,
},
witnesser::checkpointing::WitnessedUntil,
use crate::witnesser::checkpointing::WitnessedUntil;
use multisig::{
client::KeygenResultInfo, eth::EthSigning, polkadot::PolkadotSigning, ChainTag, CryptoScheme,
CHAIN_TAG_SIZE,
};

use anyhow::{anyhow, bail, Context, Result};
Expand Down
8 changes: 3 additions & 5 deletions engine/src/db/persistent/persistent_key_db_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ use std::{
};

use super::*;
use crate::{
db::PersistentKeyDB,
multisig::{client::get_key_data_for_test, eth::EthSigning, polkadot::PolkadotSigning},
};
use crate::db::PersistentKeyDB;
use cf_primitives::{KeyId, GENESIS_EPOCH};
use multisig::{client::get_key_data_for_test, eth::EthSigning, polkadot::PolkadotSigning};
use rocksdb::{Options, DB};
use sp_runtime::AccountId32;
use tempfile::TempDir;
Expand Down Expand Up @@ -353,8 +351,8 @@ fn test_migration_to_latest_from_0() {

#[test]
fn test_migration_to_v1() {
use crate::multisig::{client::keygen, Rng};
use cf_primitives::AccountId;
use multisig::{client::keygen, Rng};
use rand_legacy::FromEntropy;
use std::collections::BTreeSet;

Expand Down
11 changes: 5 additions & 6 deletions engine/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ use chainflip_engine::{
dot::{self, rpc::DotRpcClient, witnesser as dot_witnesser, DotBroadcaster},
eth::{self, build_broadcast_channel, rpc::EthDualRpcClient, EthBroadcaster},
health::HealthChecker,
logging,
multisig::{self, bitcoin::BtcSigning, eth::EthSigning, polkadot::PolkadotSigning},
p2p,
logging, p2p,
settings::{CommandLineOptions, Settings},
state_chain_observer::{
self,
client::{extrinsic_api::ExtrinsicApi, storage_api::StorageApi},
},
witnesser::AddressMonitor,
};
use multisig::{self, bitcoin::BtcSigning, eth::EthSigning, polkadot::PolkadotSigning};
use utilities::task_scope::task_scope;

use chainflip_node::chain_spec::use_chainflip_account_id_encoding;
Expand Down Expand Up @@ -130,7 +129,7 @@ async fn main() -> anyhow::Result<()> {
scope.spawn(p2p_fut);

let (eth_multisig_client, eth_multisig_client_backend_future) =
multisig::start_client::<EthSigning>(
chainflip_engine::multisig::start_client::<EthSigning>(
state_chain_client.account_id(),
KeyStore::new(db.clone()),
eth_incoming_receiver,
Expand All @@ -141,7 +140,7 @@ async fn main() -> anyhow::Result<()> {
scope.spawn(eth_multisig_client_backend_future);

let (dot_multisig_client, dot_multisig_client_backend_future) =
multisig::start_client::<PolkadotSigning>(
chainflip_engine::multisig::start_client::<PolkadotSigning>(
state_chain_client.account_id(),
KeyStore::new(db.clone()),
dot_incoming_receiver,
Expand All @@ -152,7 +151,7 @@ async fn main() -> anyhow::Result<()> {
scope.spawn(dot_multisig_client_backend_future);

let (btc_multisig_client, btc_multisig_client_backend_future) =
multisig::start_client::<BtcSigning>(
chainflip_engine::multisig::start_client::<BtcSigning>(
state_chain_client.account_id(),
KeyStore::new(db.clone()),
btc_incoming_receiver,
Expand Down
7 changes: 1 addition & 6 deletions engine/src/multisig.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Result;
use cf_primitives::CeremonyId;

use multisig::MultisigClient;
use multisig::{CryptoScheme, MultisigClient};
use tracing::{info, info_span, Instrument};

use crate::{
Expand All @@ -10,11 +10,6 @@ use crate::{
};
use state_chain_runtime::AccountId;

pub use multisig::{
bitcoin, client, eth, polkadot, ChainTag, CryptoScheme, Rng, SignatureToThresholdSignature,
CHAIN_TAG_SIZE,
};

/// Start the multisig client, which listens for p2p messages and requests from the SC
pub fn start_client<C: CryptoScheme>(
my_account_id: AccountId,
Expand Down
6 changes: 2 additions & 4 deletions engine/src/p2p/muxer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ use state_chain_runtime::AccountId;
use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender};
use tracing::{info_span, trace, warn, Instrument};

use crate::{
multisig::ChainTag,
p2p::{MultisigMessageReceiver, MultisigMessageSender, OutgoingMultisigStageMessages},
};
use crate::p2p::{MultisigMessageReceiver, MultisigMessageSender, OutgoingMultisigStageMessages};
use multisig::ChainTag;

pub use multisig::p2p::{ProtocolVersion, VersionedCeremonyMessage, CURRENT_PROTOCOL_VERSION};

Expand Down
14 changes: 7 additions & 7 deletions engine/src/state_chain_observer/sc_observer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ use crate::{
btc::{rpc::BtcRpcApi, BtcBroadcaster},
dot::{rpc::DotRpcApi, DotBroadcaster},
eth::{rpc::EthRpcApi, EthBroadcaster},
multisig::{
bitcoin::BtcSigning, client::MultisigClientApi, eth::EthSigning, polkadot::PolkadotSigning,
CryptoScheme, SignatureToThresholdSignature,
},
p2p::{PeerInfo, PeerUpdate},
state_chain_observer::client::{extrinsic_api::ExtrinsicApi, storage_api::StorageApi},
witnesser::{AddressMonitorCommand, EpochStart},
};
use multisig::{
bitcoin::BtcSigning, client::MultisigClientApi, eth::EthSigning, polkadot::PolkadotSigning,
CryptoScheme, SignatureToThresholdSignature,
};
use utilities::task_scope::{task_scope, Scope};

pub type EthAddressSender = UnboundedSender<AddressMonitorCommand<H160>>;
Expand Down Expand Up @@ -468,7 +468,7 @@ where
ceremony_id,
key_id,
signatories,
vec![crate::multisig::eth::SigningPayload(payload.0)],
vec![multisig::eth::SigningPayload(payload.0)],
).await;
}

Expand All @@ -492,7 +492,7 @@ where
ceremony_id,
key_id,
signatories,
vec![crate::multisig::polkadot::SigningPayload::new(payload.0)
vec![multisig::polkadot::SigningPayload::new(payload.0)
.expect("Payload should be correct size")],
).await;
}
Expand All @@ -516,7 +516,7 @@ where
ceremony_id,
key_id,
signatories,
payloads.into_iter().map(crate::multisig::bitcoin::SigningPayload).collect(),
payloads.into_iter().map(multisig::bitcoin::SigningPayload).collect(),
).await;
}
state_chain_runtime::RuntimeEvent::EthereumBroadcaster(
Expand Down
17 changes: 9 additions & 8 deletions engine/src/state_chain_observer/sc_observer/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{collections::BTreeSet, sync::Arc};

use crate::{btc::rpc::MockBtcRpcApi, multisig::SignatureToThresholdSignature};
use crate::btc::rpc::MockBtcRpcApi;
use cf_chains::{
eth::{Ethereum, Transaction},
ChainCrypto,
Expand All @@ -9,6 +9,7 @@ use cf_primitives::{AccountRole, KeyId, PolkadotAccountId, GENESIS_EPOCH};
use frame_system::Phase;
use futures::{FutureExt, StreamExt};
use mockall::predicate::{self, eq};
use multisig::SignatureToThresholdSignature;
use pallet_cf_broadcast::BroadcastAttemptId;
use pallet_cf_vaults::Vault;

Expand All @@ -25,15 +26,15 @@ use crate::{
rpc::{EthWsRpcClient, MockEthRpcApi},
EthBroadcaster,
},
multisig::{
client::{KeygenFailureReason, MockMultisigClientApi, SigningFailureReason},
eth::EthSigning,
CryptoScheme,
},
settings::Settings,
state_chain_observer::{client::mocks::MockStateChainClient, sc_observer},
witnesser::EpochStart,
};
use multisig::{
client::{KeygenFailureReason, MockMultisigClientApi, SigningFailureReason},
eth::EthSigning,
CryptoScheme,
};
use utilities::task_scope::task_scope;

use super::EthAddressToMonitorSender;
Expand Down Expand Up @@ -1487,7 +1488,7 @@ async fn should_handle_signing_request_eth() {

mod dot_signing {

use crate::multisig::polkadot::PolkadotSigning;
use multisig::polkadot::PolkadotSigning;

use super::*;
use state_chain_runtime::PolkadotInstance;
Expand Down Expand Up @@ -1582,7 +1583,7 @@ async fn should_handle_keygen_request_eth() {
}

mod dot_keygen {
use crate::multisig::polkadot::PolkadotSigning;
use multisig::polkadot::PolkadotSigning;

use super::*;
use state_chain_runtime::PolkadotInstance;
Expand Down
4 changes: 2 additions & 2 deletions engine/src/witnesser/checkpointing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use cf_primitives::EpochIndex;
use serde::{Deserialize, Serialize};
use tracing::info;

use crate::{db::PersistentKeyDB, multisig::ChainTag};

use super::HasChainTag;
use crate::db::PersistentKeyDB;
use multisig::ChainTag;

mod migrations;

Expand Down
3 changes: 2 additions & 1 deletion engine/src/witnesser/checkpointing/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use anyhow::Result;
use itertools::Itertools;
use tracing::{error, info};

use crate::{db::PersistentKeyDB, multisig::ChainTag};
use crate::db::PersistentKeyDB;
use multisig::ChainTag;
use utilities::task_scope;

use super::WitnessedUntil;
Expand Down
2 changes: 1 addition & 1 deletion engine/src/witnesser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub mod http_safe_stream;

use anyhow::Result;

use crate::multisig::ChainTag;
use multisig::ChainTag;

pub type ChainBlockNumber<Chain> = <Chain as cf_chains::Chain>::ChainBlockNumber;

Expand Down