Skip to content

Commit

Permalink
Only resend proposals once after external commit (#4103)
Browse files Browse the repository at this point in the history
* Only resend proposals once after external commit

* Add CHANGELOG entry

* Log when duplicate proposals are found

* Regenerate nix packages
  • Loading branch information
pcapriotti authored Jun 24, 2024
1 parent 87b8f96 commit d3f64ea
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Only resend proposals once after external commit
2 changes: 2 additions & 0 deletions services/galley/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
, galley-types
, gitignoreSource
, gundeck-types
, hex
, HsOpenSSL
, http-api-data
, http-client
Expand Down Expand Up @@ -164,6 +165,7 @@ mkDerivation {
extra
galley-types
gundeck-types
hex
HsOpenSSL
http-client
http-client-openssl
Expand Down
1 change: 1 addition & 0 deletions services/galley/galley.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ library
, extra >=1.3
, galley-types >=0.65.0
, gundeck-types >=1.35.2
, hex
, HsOpenSSL >=0.11
, http-client >=0.7
, http-client-openssl >=0.2
Expand Down
10 changes: 5 additions & 5 deletions services/galley/src/Galley/API/MLS/Commit/ExternalCommit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ processExternalCommit senderIdentity lConvOrSub ciphersuite epoch action updateP
lConvOrSub' <- for lConvOrSub incrementEpoch

-- fetch backend remove proposals of the previous epoch
indicesInRemoveProposals <-
-- skip remove proposals of already removed by the external commit
(\\ toList action.remove)
<$> getPendingBackendRemoveProposals groupId epoch
indices0 <- getPendingBackendRemoveProposals groupId epoch

-- skip proposals for clients already removed by the external commit
let indices = maybe id Set.delete action.remove indices0

-- requeue backend remove proposals for the current epoch
createAndSendRemoveProposals
lConvOrSub'
indicesInRemoveProposals
indices
(cidQualifiedUser senderIdentity)
(tUnqualified lConvOrSub').members

Expand Down
37 changes: 24 additions & 13 deletions services/galley/src/Galley/API/MLS/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
module Galley.API.MLS.Util where

import Control.Comonad
import Data.Hex
import Data.Id
import Data.Qualified
import Data.Set qualified as Set
import Data.Text qualified as T
import Galley.Data.Conversation.Types hiding (Conversation)
import Galley.Data.Conversation.Types qualified as Data
Expand Down Expand Up @@ -77,21 +79,30 @@ getPendingBackendRemoveProposals ::
) =>
GroupId ->
Epoch ->
Sem r [LeafIndex]
Sem r (Set LeafIndex)
getPendingBackendRemoveProposals gid epoch = do
proposals <- getAllPendingProposals gid epoch
catMaybes
<$> for
proposals
( \case
(Just ProposalOriginBackend, proposal) -> case value proposal of
RemoveProposal i -> pure (Just i)
_ -> pure Nothing
(Just ProposalOriginClient, _) -> pure Nothing
(Nothing, _) -> do
TinyLog.warn $ Log.msg ("found pending proposal without origin, ignoring" :: ByteString)
pure Nothing
)
indexList <-
catMaybes
<$> for
proposals
( \case
(Just ProposalOriginBackend, proposal) -> case proposal.value of
RemoveProposal i -> pure (Just i)
_ -> pure Nothing
(Just ProposalOriginClient, _) -> pure Nothing
(Nothing, _) -> do
TinyLog.warn $ Log.msg ("found pending proposal without origin, ignoring" :: ByteString)
pure Nothing
)

let indexSet = Set.fromList indexList
when (length indexList /= length indexSet) $ do
TinyLog.warn $
Log.msg ("found duplicate proposals" :: ByteString)
. Log.field "groupId" ("0x" <> hex (unGroupId gid))
. Log.field "epoch" (epochNumber epoch)
pure indexSet

withCommitLock ::
forall r a.
Expand Down

0 comments on commit d3f64ea

Please sign in to comment.