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

Enclave avoid duplicated Leaders #1760

Conversation

danielSanchezQ
Copy link
Contributor

Should fix #1498

@danielSanchezQ
Copy link
Contributor Author

danielSanchezQ commented Feb 10, 2020

It is not tested still. I wanted to add some considerations here first.

use std::sync::Arc;
use tokio02::sync::RwLock;

#[derive(Clone)]
pub struct Enclave {
leaders: Arc<RwLock<BTreeMap<LeaderId, Leader>>>,
added_cache: Arc<RwLock<HashMap<String, LeaderId>>>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used String but maybe we could use PublicKey instead, I wanted to go ahead and used the easy way first but if PublicKey is hashable should be fine also.

@danielSanchezQ danielSanchezQ marked this pull request as ready for review February 11, 2020 11:57
@danielSanchezQ
Copy link
Contributor Author

I added some tests to check that the method behaves as expected.

@danielSanchezQ
Copy link
Contributor Author

I need to update the tests for the last commit

@NicolasDP NicolasDP added bug Something isn't working A-jormungandr Area: Issues affecting jörmungandr Priority - Medium subsys-crypto labels Feb 13, 2020
@NicolasDP NicolasDP added this to the Net improvement 4 milestone Feb 13, 2020
Copy link
Contributor

@NicolasDP NicolasDP left a comment

Choose a reason for hiding this comment

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

Only one lock max for this, the double locking will clearly rick having a deadlock on the operations here

jormungandr/src/secure/enclave.rs Outdated Show resolved Hide resolved
@vincenthz vincenthz removed this from the Net improvement 4 milestone Feb 17, 2020
Copy link
Contributor

@NicolasDP NicolasDP left a comment

Choose a reason for hiding this comment

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

looking better, no risk of deadlock now

just a few sanity changes and it is good to go

@@ -41,6 +41,7 @@ network-core = { path = "../chain-deps/network-core" }
network-grpc = { path = "../chain-deps/network-grpc" }
poldercast = "0.11.2"
rand = "0.7"
rand_core = "0.5"
Copy link
Contributor

Choose a reason for hiding this comment

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

this is only used for the test, move this to the dev-dependency

[build-dependencies]
versionisator = "1.0.2"


Copy link
Contributor

Choose a reason for hiding this comment

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

non necessary trailing line

Comment on lines 19 to 20
// leaders: Arc<RwLock<BTreeMap<LeaderId, Leader>>>,
// added_leaders_cache: Arc<RwLock<HashMap<String, LeaderId>>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

remove deadcode

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, sorry for this.

@danielSanchezQ danielSanchezQ force-pushed the jcli_leader_registration_fix_#1498 branch from 655c001 to ec504fa Compare February 21, 2020 15:38
@danielSanchezQ
Copy link
Contributor Author

This should be ready now @NicolasDP , thanks!

@NicolasDP NicolasDP merged commit da93bbb into input-output-hk:master Feb 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-jormungandr Area: Issues affecting jörmungandr bug Something isn't working Priority - Medium subsys-crypto
Projects
None yet
Development

Successfully merging this pull request may close these issues.

REST API - leaders registration - Registering twice the same leader is allowed
3 participants