Skip to content

Commit

Permalink
get rid of CoreGroup::merge_staged_commit
Browse files Browse the repository at this point in the history
  • Loading branch information
keks committed Aug 19, 2024
1 parent ebb5b7c commit 19d7a90
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 27 deletions.
23 changes: 0 additions & 23 deletions openmls/src/group/core_group/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,27 +284,4 @@ impl CoreGroup {

Ok((old_epoch_keypairs, leaf_node_keypairs))
}

/// Merge a [StagedCommit] into the group after inspection
pub(crate) fn merge_staged_commit<Provider: OpenMlsProvider>(
&mut self,
provider: &Provider,
staged_commit: StagedCommit,
) -> Result<(), MergeCommitError<Provider::StorageError>> {
// Save the past epoch
let past_epoch = self.context().epoch();
// Get all the full leaves
let leaves = self.public_group().members().collect();
// Merge the staged commit into the group state and store the secret tree from the
// previous epoch in the message secrets store.
if let Some(message_secrets) = self.merge_commit(provider, staged_commit)? {
self.message_secrets_store
.add(past_epoch, message_secrets, leaves);
}
provider
.storage()
.write_message_secrets(self.group_id(), &self.message_secrets_store)
.map_err(MergeCommitError::StorageError)?;
Ok(())
}
}
14 changes: 11 additions & 3 deletions openmls/src/group/core_group/staged_commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ impl CoreGroup {
&mut self,
provider: &Provider,
staged_commit: StagedCommit,
) -> Result<Option<MessageSecrets>, MergeCommitError<Provider::StorageError>> {
) -> Result<(), MergeCommitError<Provider::StorageError>> {
// Get all keypairs from the old epoch, so we can later store the ones
// that are still relevant in the new epoch.
let old_epoch_keypairs = self.read_epoch_keypairs(provider.storage());
Expand All @@ -329,9 +329,15 @@ impl CoreGroup {
.merge_diff(staged_state.into_staged_diff());
self.store(provider.storage())
.map_err(MergeCommitError::StorageError)?;
Ok(None)
Ok(())
}
StagedCommitState::GroupMember(state) => {
// Save the past epoch
let past_epoch = self.context().epoch();
// Get all the full leaves
let leaves = self.public_group().members().collect();
// Merge the staged commit into the group state and store the secret tree from the
// previous epoch in the message secrets store.
self.group_epoch_secrets = state.group_epoch_secrets;

// Replace the previous message secrets with the new ones and return the previous message secrets
Expand All @@ -340,6 +346,8 @@ impl CoreGroup {
&mut message_secrets,
self.message_secrets_store.message_secrets_mut(),
);
self.message_secrets_store
.add(past_epoch, message_secrets, leaves);

self.public_group.merge_diff(state.staged_diff);

Expand Down Expand Up @@ -407,7 +415,7 @@ impl CoreGroup {
.map_err(MergeCommitError::StorageError)?;
self.proposal_store_mut().empty();

Ok(Some(message_secrets))
Ok(())
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion openmls/src/group/mls_group/processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl MlsGroup {
.map_err(MergeCommitError::StorageError)?;

// Merge staged commit
self.group.merge_staged_commit(provider, staged_commit)?;
self.group.merge_commit(provider, staged_commit)?;

// Extract and store the resumption psk for the current epoch
let resumption_psk = self.group.group_epoch_secrets().resumption_psk();
Expand Down

0 comments on commit 19d7a90

Please sign in to comment.