Skip to content

Commit

Permalink
Merge pull request #5863 from oasisprotocol/peternose/internal/fetch-…
Browse files Browse the repository at this point in the history
…key-shares-concurrently

keymanager/src/client: Fetch churp key shares concurrently
  • Loading branch information
peternose authored Sep 24, 2024
2 parents fef9a7d + fb28b63 commit 6c5af61
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 115 deletions.
1 change: 1 addition & 0 deletions .changelog/5863.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
keymanager/src/client: Fetch churp key shares concurrently
14 changes: 8 additions & 6 deletions keymanager/src/churp/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,11 +620,13 @@ impl<S: Suite> Instance<S> {
}

// Fetch from the remote node.
client.set_nodes(vec![node_id]);

if handoff.needs_verification_matrix()? {
// The remote verification matrix needs to be verified.
let vm = block_on(client.churp_verification_matrix(self.churp_id, status.handoff))?;
let vm = block_on(client.churp_verification_matrix(
self.churp_id,
status.handoff,
vec![node_id],
))?;
let checksum = self.checksum_verification_matrix_bytes(&vm, status.handoff);
let status_checksum = status.checksum.ok_or(Error::InvalidHandoff)?; // Should never happen.
if checksum != status_checksum {
Expand All @@ -640,6 +642,7 @@ impl<S: Suite> Instance<S> {
self.churp_id,
status.next_handoff,
self.node_id,
vec![node_id],
))?;
let point = scalar_from_bytes(&point).ok_or(Error::PointDecodingFailed)?;

Expand Down Expand Up @@ -669,11 +672,11 @@ impl<S: Suite> Instance<S> {
}

// Fetch from the remote node.
client.set_nodes(vec![node_id]);
let point = block_on(client.churp_share_distribution_point(
self.churp_id,
status.next_handoff,
self.node_id,
vec![node_id],
))?;
let point = scalar_from_bytes(&point).ok_or(Error::PointDecodingFailed)?;

Expand Down Expand Up @@ -706,11 +709,11 @@ impl<S: Suite> Instance<S> {
}

// Fetch from the remote node.
client.set_nodes(vec![node_id]);
let share = block_on(client.churp_bivariate_share(
self.churp_id,
status.next_handoff,
self.node_id,
vec![node_id],
))?;

// The remote verification matrix needs to be verified.
Expand Down Expand Up @@ -1131,7 +1134,6 @@ impl<S: Suite> Instance<S> {
self.consensus_verifier.clone(),
self.identity.clone(),
1, // Not used, doesn't matter.
vec![],
);

Ok(client)
Expand Down
32 changes: 24 additions & 8 deletions keymanager/src/client/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,22 @@ pub trait KeyManagerClient: Send + Sync {
async fn replicate_master_secret(
&self,
generation: u64,
nodes: Vec<PublicKey>,
) -> Result<VerifiableSecret, KeyManagerError>;

/// Get a copy of the ephemeral secret for replication.
async fn replicate_ephemeral_secret(&self, epoch: EpochTime)
-> Result<Secret, KeyManagerError>;
async fn replicate_ephemeral_secret(
&self,
epoch: EpochTime,
nodes: Vec<PublicKey>,
) -> Result<Secret, KeyManagerError>;

/// Returns the verification matrix for the given handoff.
async fn churp_verification_matrix(
&self,
churp_id: u8,
epoch: EpochTime,
nodes: Vec<PublicKey>,
) -> Result<Vec<u8>, KeyManagerError>;

/// Returns a switch point for the share reduction phase
Expand All @@ -89,6 +94,7 @@ pub trait KeyManagerClient: Send + Sync {
churp_id: u8,
epoch: EpochTime,
node_id: PublicKey,
nodes: Vec<PublicKey>,
) -> Result<Vec<u8>, KeyManagerError>;

/// Returns a switch point for the share distribution phase
Expand All @@ -98,6 +104,7 @@ pub trait KeyManagerClient: Send + Sync {
churp_id: u8,
epoch: EpochTime,
node_id: PublicKey,
nodes: Vec<PublicKey>,
) -> Result<Vec<u8>, KeyManagerError>;

/// Returns a bivariate share for the given handoff.
Expand All @@ -106,6 +113,7 @@ pub trait KeyManagerClient: Send + Sync {
churp_id: u8,
epoch: EpochTime,
node_id: PublicKey,
nodes: Vec<PublicKey>,
) -> Result<EncodedVerifiableSecretShare, KeyManagerError>;

/// Returns state key.
Expand Down Expand Up @@ -165,50 +173,58 @@ impl<T: ?Sized + KeyManagerClient> KeyManagerClient for Arc<T> {
async fn replicate_master_secret(
&self,
generation: u64,
nodes: Vec<PublicKey>,
) -> Result<VerifiableSecret, KeyManagerError> {
KeyManagerClient::replicate_master_secret(&**self, generation).await
KeyManagerClient::replicate_master_secret(&**self, generation, nodes).await
}

async fn replicate_ephemeral_secret(
&self,
epoch: EpochTime,
nodes: Vec<PublicKey>,
) -> Result<Secret, KeyManagerError> {
KeyManagerClient::replicate_ephemeral_secret(&**self, epoch).await
KeyManagerClient::replicate_ephemeral_secret(&**self, epoch, nodes).await
}

async fn churp_verification_matrix(
&self,
churp_id: u8,
epoch: EpochTime,
nodes: Vec<PublicKey>,
) -> Result<Vec<u8>, KeyManagerError> {
KeyManagerClient::churp_verification_matrix(&**self, churp_id, epoch).await
KeyManagerClient::churp_verification_matrix(&**self, churp_id, epoch, nodes).await
}

async fn churp_share_reduction_point(
&self,
churp_id: u8,
epoch: EpochTime,
node_id: PublicKey,
nodes: Vec<PublicKey>,
) -> Result<Vec<u8>, KeyManagerError> {
KeyManagerClient::churp_share_reduction_point(&**self, churp_id, epoch, node_id).await
KeyManagerClient::churp_share_reduction_point(&**self, churp_id, epoch, node_id, nodes)
.await
}

async fn churp_share_distribution_point(
&self,
churp_id: u8,
epoch: EpochTime,
node_id: PublicKey,
nodes: Vec<PublicKey>,
) -> Result<Vec<u8>, KeyManagerError> {
KeyManagerClient::churp_share_distribution_point(&**self, churp_id, epoch, node_id).await
KeyManagerClient::churp_share_distribution_point(&**self, churp_id, epoch, node_id, nodes)
.await
}

async fn churp_bivariate_share(
&self,
churp_id: u8,
epoch: EpochTime,
node_id: PublicKey,
nodes: Vec<PublicKey>,
) -> Result<EncodedVerifiableSecretShare, KeyManagerError> {
KeyManagerClient::churp_bivariate_share(&**self, churp_id, epoch, node_id).await
KeyManagerClient::churp_bivariate_share(&**self, churp_id, epoch, node_id, nodes).await
}

async fn churp_state_key(
Expand Down
6 changes: 6 additions & 0 deletions keymanager/src/client/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,15 @@ impl KeyManagerClient for MockClient {
async fn replicate_master_secret(
&self,
_generation: u64,
_nodes: Vec<PublicKey>,
) -> Result<VerifiableSecret, KeyManagerError> {
unimplemented!();
}

async fn replicate_ephemeral_secret(
&self,
_epoch: EpochTime,
_nodes: Vec<PublicKey>,
) -> Result<Secret, KeyManagerError> {
unimplemented!();
}
Expand All @@ -124,6 +126,7 @@ impl KeyManagerClient for MockClient {
&self,
_churp_id: u8,
_epoch: EpochTime,
_nodes: Vec<PublicKey>,
) -> Result<Vec<u8>, KeyManagerError> {
unimplemented!();
}
Expand All @@ -133,6 +136,7 @@ impl KeyManagerClient for MockClient {
_churp_id: u8,
_epoch: EpochTime,
_node_id: PublicKey,
_nodes: Vec<PublicKey>,
) -> Result<Vec<u8>, KeyManagerError> {
unimplemented!();
}
Expand All @@ -142,6 +146,7 @@ impl KeyManagerClient for MockClient {
_churp_id: u8,
_epoch: EpochTime,
_node_id: PublicKey,
_nodes: Vec<PublicKey>,
) -> Result<Vec<u8>, KeyManagerError> {
unimplemented!();
}
Expand All @@ -151,6 +156,7 @@ impl KeyManagerClient for MockClient {
_churp_id: u8,
_epoch: EpochTime,
_node_id: PublicKey,
_nodes: Vec<PublicKey>,
) -> Result<EncodedVerifiableSecretShare, KeyManagerError> {
unimplemented!();
}
Expand Down
Loading

0 comments on commit 6c5af61

Please sign in to comment.