Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

SecretStore: use in-memory transport in cluster tests #9850

Merged
merged 8 commits into from
Feb 18, 2019
Merged

Conversation

svyatonik
Copy link
Collaborator

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 the cluster.rs;
    cluster_message_processor.rs - entity that connects cluster connections with cluster sessions.

Test-related notes:

  1. all tests from in cluster.rs are now using in-memory connections implementation => no timeouts;
  2. there's still single place where timeouts are used - 1000ms when network connections are established in 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;
  3. most of changes in tests from cluster.rs and various *_session.rs are about switching to the new MessagesLoop from cluster.rs (this removes a lot of duplicate && boilerplate code). It isn't finished yet (there are more *_session.rs), but enough for first PR.

@svyatonik svyatonik added A0-pleasereview 🤓 Pull request needs code review. M4-core ⛓ Core client code / Rust. labels Nov 1, 2018
@niklasad1 niklasad1 self-requested a review November 24, 2018 16:46
@5chdn 5chdn added this to the 2.3 milestone Nov 25, 2018
let config = NetClusterConfiguration {
threads: config.threads,
let threads = config.threads;
let cconfig = NetClusterConfiguration {
Copy link
Collaborator

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

@@ -460,7 +463,7 @@ pub mod tests {
#[test]
fn decryption_session_is_delegated_when_node_does_not_have_key_share() {
//::logger::init_log();
Copy link
Collaborator

@niklasad1 niklasad1 Nov 28, 2018

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,
Copy link
Collaborator

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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clone on Copy type

Suggested change
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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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()))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.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()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NodeID is Copy

Suggested change
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)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.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());
Copy link
Collaborator

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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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<_>>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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<_>>()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.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<_>>()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.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<_>>()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.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() {
Copy link
Collaborator

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());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.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())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.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))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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()),
Copy link
Collaborator

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(),
Copy link
Collaborator

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};
Copy link
Collaborator

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

Suggested change
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())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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};
Copy link
Collaborator

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};
Copy link
Collaborator

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()),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
migration_id: Some(migration.id.clone()),
migration_id: Some(migration.id),

Copy link
Collaborator

@niklasad1 niklasad1 left a 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!

@niklasad1 niklasad1 added A6-mustntgrumble 💦 Pull request has areas for improvement. The author need not address them before merging. and removed A0-pleasereview 🤓 Pull request needs code review. labels Nov 29, 2018
@svyatonik svyatonik added A0-pleasereview 🤓 Pull request needs code review. and removed A6-mustntgrumble 💦 Pull request has areas for improvement. The author need not address them before merging. labels Nov 29, 2018
@niklasad1 niklasad1 added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Nov 29, 2018
@5chdn
Copy link
Contributor

5chdn commented Dec 5, 2018

👍 needs a 2nd review

@5chdn
Copy link
Contributor

5chdn commented Dec 28, 2018

could you rebase this @svyatonik?

who wants to do a 2nd review @grbIzl @seunlanlege?

@5chdn 5chdn modified the milestones: 2.3, 2.4 Jan 10, 2019
@5chdn
Copy link
Contributor

5chdn commented Jan 28, 2019

Needs a 2nd review 🙄 😆

Copy link
Contributor

@ascjones ascjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@5chdn 5chdn merged commit ef0eda0 into master Feb 18, 2019
@5chdn 5chdn deleted the fix_ss_tests branch February 18, 2019 12:38
ordian added a commit that referenced this pull request Apr 5, 2019
* 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)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. M4-core ⛓ Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

key_server_cluster randomly failing
4 participants