-
Notifications
You must be signed in to change notification settings - Fork 1.7k
SecretStore: use in-memory transport in cluster tests #9850
Conversation
secret_store/src/key_server.rs
Outdated
let config = NetClusterConfiguration { | ||
threads: config.threads, | ||
let threads = config.threads; | ||
let cconfig = NetClusterConfiguration { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider renaming this to cluster_config
secret_store/src/key_server.rs
Outdated
@@ -460,7 +463,7 @@ pub mod tests { | |||
#[test] | |||
fn decryption_session_is_delegated_when_node_does_not_have_key_share() { | |||
//::logger::init_log(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to this PR, however this logger/comment should be enabled or removed IMHO
} | ||
|
||
struct MessageLoop { | ||
pub struct MessageLoop<S> { | ||
pub ml: MessagesLoop, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hrm, am I reading this correctly: is every MessageLoop instance containing another MessageLoop?
ml: &MessagesLoop, | ||
idx: usize | ||
) -> SessionImpl { | ||
meta.self_node_id = ml.node_key_pair(idx).public().clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clone on Copy type
meta.self_node_id = ml.node_key_pair(idx).public().clone(); | |
meta.self_node_id = *ml.node_key_pair(idx).public(); |
// all active nodes set | ||
let mut all_nodes_set: BTreeSet<_> = gml.nodes.keys() | ||
let mut all_nodes_set: BTreeSet<_> = ml.nodes().iter() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let mut all_nodes_set: BTreeSet<_> = ml.nodes().iter() | |
let mut all_nodes_set: BTreeSet<_> = ml.nodes().into_iter() | |
.filter(|n| !isolated_nodes_ids.contains(n)) | |
.collect(); | |
.filter(|n| !isolated_nodes_ids.contains(n)) | ||
.cloned() | ||
.collect(); | ||
// new nodes set includes all old nodes, except nodes being removed + all nodes being added | ||
let new_nodes_set: BTreeSet<NodeId> = all_nodes_set.iter().cloned() | ||
.chain(new_nodes_ids.iter().cloned()) | ||
.chain(add.iter().map(|kp| kp.public().clone())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.chain(add.iter().map(|kp| kp.public().clone())) | |
.chain(add.iter().map(|kp| *kp.public())) |
.filter(|n| !removed_nodes_ids.contains(n)) | ||
.collect(); | ||
all_nodes_set.extend(new_nodes_ids.iter().cloned()); | ||
let mut old_set_to_sign = all_nodes_set.clone(); | ||
all_nodes_set.extend(add.iter().map(|kp| kp.public().clone())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all_nodes_set.extend(add.iter().map(|kp| kp.public().clone())); | |
all_nodes_set.extend(add.iter().map(|kp| *kp.public())); |
let mut old_set_to_sign = all_nodes_set.clone(); | ||
all_nodes_set.extend(add.iter().map(|kp| kp.public().clone())); | ||
if C::SIGN_NEW_NODES { | ||
old_set_to_sign.extend(add.iter().map(|kp| kp.public().clone())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
old_set_to_sign.extend(add.iter().map(|kp| kp.public().clone())); | |
old_set_to_sign.extend(add.iter().map(|kp| *kp.public())); |
for isolated_node_id in &isolated_nodes_ids { | ||
all_nodes_set.remove(isolated_node_id); | ||
} | ||
|
||
let meta = ShareChangeSessionMeta { | ||
self_node_id: master_node_id.clone(), | ||
master_node_id: master_node_id.clone(), | ||
self_node_id: master.clone(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NodeID is Copy
self_node_id: master.clone(), | |
self_node_id: master, |
|
||
// prepare set of nodes | ||
let sessions: BTreeMap<_, _> = (0..ml.nodes().len()) | ||
.map(|idx| (ml.node(idx), C::create(meta.clone(), admin_public.clone(), all_nodes_set.clone(), &ml, idx))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.map(|idx| (ml.node(idx), C::create(meta.clone(), admin_public.clone(), all_nodes_set.clone(), &ml, idx))) | |
.map(|idx| (ml.node(idx), C::create(meta.clone(), admin_public, all_nodes_set.clone(), &ml, idx))) |
idx: usize | ||
) -> SessionImpl<IsolatedSessionTransport> { | ||
let key_storage = ml.key_storage(idx).clone(); | ||
let key_version = key_storage.get(&meta.id).unwrap().map(|ks| ks.last_version().unwrap().hash.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clone()
on Copy-type
let key_storage = ml.key_storage(idx).clone(); | ||
let key_version = key_storage.get(&meta.id).unwrap().map(|ks| ks.last_version().unwrap().hash.clone()); | ||
|
||
meta.self_node_id = ml.node_key_pair(idx).public().clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
meta.self_node_id = ml.node_key_pair(idx).public().clone(); | |
meta.self_node_id = *ml.node_key_pair(idx).public(); |
SessionImpl::new(SessionParams { | ||
meta: meta.clone(), | ||
transport: IsolatedSessionTransport::new(meta.id, key_version, 1, ml.cluster(idx).view().unwrap()), | ||
key_storage: key_storage, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
key_storage: key_storage, | |
key_storage, |
|
||
// try to add 1 node using this node as a master node | ||
let add = vec![Random.generate().unwrap()]; | ||
let master = add[0].public().clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let master = add[0].public().clone(); | |
let master = *add[0].public(); |
let mut oldest_nodes_set = gml.0.nodes(); | ||
oldest_nodes_set.remove(&node_to_isolate); | ||
let add = (0..add).map(|_| Random.generate().unwrap()).collect::<Vec<_>>(); | ||
let newest_nodes_set = add.iter().map(|kp| kp.public().clone()).collect::<Vec<_>>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let newest_nodes_set = add.iter().map(|kp| kp.public().clone()).collect::<Vec<_>>(); | |
let newest_nodes_set = add.iter().map(|kp| *kp.public()).collect::<Vec<_>>(); |
debug_assert!(::std::iter::once(&isolated_node_id).all(|n| vec![version_a.clone(), version_c.clone()] == | ||
ml.nodes[n].key_storage.get(&Default::default()).unwrap().unwrap().versions.iter().map(|v| v.hash.clone()).collect::<Vec<_>>())); | ||
ml.ml.key_storage_of(n).get(&Default::default()).unwrap().unwrap() | ||
.versions.iter().map(|v| v.hash.clone()).collect::<Vec<_>>())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.versions.iter().map(|v| v.hash.clone()).collect::<Vec<_>>())); | |
.versions.iter().map(|v| v.hash).collect::<Vec<_>>())); |
.versions.iter().map(|v| v.hash.clone()).collect::<Vec<_>>())); | ||
debug_assert!(::std::iter::once(&node_to_isolate).all(|n| vec![version_a.clone(), version_c.clone()] == | ||
ml.ml.key_storage_of(n).get(&Default::default()).unwrap().unwrap() | ||
.versions.iter().map(|v| v.hash.clone()).collect::<Vec<_>>())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.versions.iter().map(|v| v.hash.clone()).collect::<Vec<_>>())); | |
.versions.iter().map(|v| v.hash).collect::<Vec<_>>())); |
debug_assert!(newest_nodes_set.iter().all(|n| vec![version_b.clone(), version_c.clone()] == | ||
ml.nodes[n].key_storage.get(&Default::default()).unwrap().unwrap().versions.iter().map(|v| v.hash.clone()).collect::<Vec<_>>())); | ||
ml.ml.key_storage_of(n).get(&Default::default()).unwrap().unwrap() | ||
.versions.iter().map(|v| v.hash.clone()).collect::<Vec<_>>())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.versions.iter().map(|v| v.hash.clone()).collect::<Vec<_>>())); | |
.versions.iter().map(|v| v.hash).collect::<Vec<_>>())); |
pub fn second_slave(&self) -> &SessionImpl { | ||
&self.nodes.values().nth(2).unwrap().session | ||
pub fn take_message_confirm_initialization(&self) -> (NodeId, NodeId, ConfirmInitialization) { | ||
match self.0.take_message() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional
, but I prefer if/else instead of pattern match
with only two variants
assert_eq!(l.process_message(message.clone()).unwrap_err(), Error::InvalidStateForRequest); | ||
let ml = MessageLoop::new(2).init(0).unwrap(); | ||
let (from, to, msg) = ml.0.take_message().unwrap(); | ||
ml.0.process_message(from.clone(), to.clone(), msg.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ml.0.process_message(from.clone(), to.clone(), msg.clone()); | |
ml.0.process_message(from, to, msg.clone()); |
let signature = ethkey::sign(requester.secret(), &SessionId::default()).unwrap(); | ||
self.0.cluster(0).client() | ||
.new_ecdsa_signing_session(Default::default(), signature.into(), key_version, message_hash.clone()) | ||
.map(|_| (self, requester.public().clone(), message_hash)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.map(|_| (self, requester.public().clone(), message_hash)) | |
.map(|_| (self, *requester.public(), message_hash)) |
let requester = Random.generate().unwrap(); | ||
let signature = ethkey::sign(requester.secret(), &SessionId::default()).unwrap(); | ||
self.0.cluster(0).client() | ||
.new_ecdsa_signing_session(Default::default(), signature.into(), key_version, message_hash.clone()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.new_ecdsa_signing_session(Default::default(), signature.into(), key_version, message_hash.clone()) | |
.new_ecdsa_signing_session(Default::default(), signature.into(), key_version, message_hash) |
Default::default(), | ||
signature.into(), | ||
key_version, | ||
message_hash.clone()).map(|_| (self, requester.public().clone(), message_hash)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
message_hash.clone()).map(|_| (self, requester.public().clone(), message_hash)) | |
message_hash).map(|_| (self, *requester.public(), message_hash)) |
assert_eq!(sl.master().initialize(sl.version.clone(), 777.into()), Ok(())); | ||
assert_eq!(sl.master().initialize(sl.version.clone(), 777.into()), Err(Error::InvalidStateForRequest)); | ||
let (ml, _, _) = MessageLoop::new(1, 0).unwrap().init().unwrap(); | ||
assert_eq!(ml.session_at(0).initialize(ml.key_version(), 777.into()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this fits on a single line (< 120 chars)
match message { | ||
Message::Generation(message) => self | ||
.process_message(&self.sessions.generation_sessions, connection, Message::Generation(message)) | ||
.map(|_| ()).unwrap_or_default(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be map_or
use key_server_cluster::cluster_sessions::AdminSession; | ||
use key_server_cluster::cluster_connections::{Connection}; | ||
use key_server_cluster::cluster_connections_net::{NetConnectionsContainer}; | ||
use types::{Error, NodeId}; | ||
use {NodeKeyPair}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary blocks for single import
use {NodeKeyPair}; | |
use NodeKeyPair; |
@@ -95,6 +97,11 @@ pub struct TriggerConnections { | |||
} | |||
|
|||
impl SimpleConnectionTrigger { | |||
/// Create new simple from cluster configuration. | |||
pub fn with_config(config: &ClusterConfiguration) -> Self { | |||
Self::new(config.key_server_set.clone(), config.self_key_pair.clone(), config.admin_public.clone()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Self::new(config.key_server_set.clone(), config.self_key_pair.clone(), config.admin_public.clone()) | |
Self::new(config.key_server_set.clone(), config.self_key_pair.clone(), config.admin_public) |
use key_server_cluster::{MapKeyServerSet, PlainNodeKeyPair, KeyServerSetSnapshot, KeyServerSetMigration}; | ||
use key_server_cluster::cluster_connections_net::{NetConnectionsContainer}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary blocks for single import
@@ -21,7 +21,8 @@ use ethereum_types::H256; | |||
use ethkey::Public; | |||
use parking_lot::Mutex; | |||
use key_server_cluster::{KeyServerSet, KeyServerSetSnapshot, KeyServerSetMigration, is_migration_required}; | |||
use key_server_cluster::cluster::{ClusterClient, ClusterConnectionsData}; | |||
use key_server_cluster::cluster::{ClusterConfiguration, ServersSetChangeParams}; | |||
use key_server_cluster::cluster_connections_net::{NetConnectionsContainer}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary blocks for single import
match signatures { | ||
Ok((old_set_signature, new_set_signature)) => Some(ServersSetChangeParams { | ||
session_id: None, | ||
migration_id: Some(migration.id.clone()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
migration_id: Some(migration.id.clone()), | |
migration_id: Some(migration.id), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good with some style and clone() on Copy
things to clean up!
👍 needs a 2nd review |
could you rebase this @svyatonik? who wants to do a 2nd review @grbIzl @seunlanlege? |
Needs a 2nd review 🙄 😆 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
* master: Add message to IO errors (#10324) chore(bump parity-daemonize): require rust >= 1.31 (#10359) SecretStore: use in-memory transport in cluster tests (#9850) Add fields to `memzero`'s Cargo.toml (#10362) snap: release untagged versions from branches to the candidate snap channel (#10357) fix(compilation warns): `no-default-features` (#10346)
closes #9635 (at least if my assumption that it has been caused by timeout is true)
This PR doesn't introduces any new functionality, though it has some (non-negligible) non-test code modifications. These are mostly about splitting huge
cluster.rs
into several files:cluster_connections.rs
- contains trait for connections used by cluster + test implementation of these traits;cluster_connections_net.rs
- network implementation of connection traits. This isn't a new code - it is moved from thecluster.rs
;cluster_message_processor.rs
- entity that connects cluster connections with cluster sessions.Test-related notes:
cluster.rs
are now using in-memory connections implementation => no timeouts;key_server.rs
tests. I thought about switching to in-memory connections there too, but decided to leave as-is at least for now (until writing proper tests for net-connections). So treat these like integration tests for now. Also - iirc this timeout has never failed - 1s is enough for establishing network connections;cluster.rs
and various*_session.rs
are about switching to the newMessagesLoop
fromcluster.rs
(this removes a lot of duplicate && boilerplate code). It isn't finished yet (there are more*_session.rs
), but enough for first PR.