Skip to content

Commit 2db5319

Browse files
committed
Refresh pending proposals
1 parent f60b08b commit 2db5319

File tree

3 files changed

+42
-12
lines changed

3 files changed

+42
-12
lines changed

services/galley/src/Galley/API/MLS/Message.hs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -710,15 +710,17 @@ processCommitWithAction qusr senderClient con lconv cm epoch groupId action send
710710
(_, Nothing) -> pure $ pure () -- ignore commits without update path
711711
_ -> throw (mlsProtocolError "Unexpected sender")
712712

713-
-- check all pending proposals are referenced in the commit
714-
allPendingProposals <- getAllPendingProposals groupId epoch
715-
let referencedProposals = Set.fromList $ mapMaybe (\x -> preview Proposal._Ref x) (cProposals commit)
716-
unless (all (`Set.member` referencedProposals) allPendingProposals) $
717-
throwS @'MLSCommitMissingReferences
718-
719-
-- check if an external commit
720-
when (sender == NewMemberSender) $
721-
validateExternalCommit qusr action
713+
if sender == NewMemberSender
714+
then -- check if an external commit
715+
validateExternalCommit qusr action
716+
else do
717+
-- check all pending proposals are referenced in the commit
718+
allPendingProposals <- getAllPendingProposals groupId epoch
719+
let referencedProposals =
720+
Set.fromList $
721+
mapMaybe (\x -> preview Proposal._Ref x) (cProposals commit)
722+
unless (all (`Set.member` referencedProposals) allPendingProposals) $
723+
throwS @'MLSCommitMissingReferences
722724

723725
-- process and execute proposals
724726
updates <- executeProposalAction qusr con lconv cm action
@@ -733,6 +735,9 @@ processCommitWithAction qusr senderClient con lconv cm epoch groupId action send
733735
. toOpaquePublicGroupState
734736
. gipGroupState
735737

738+
when (sender == NewMemberSender) $
739+
refreshPendingProposals groupId epoch
740+
736741
pure updates
737742

738743
validateExternalCommit ::

services/galley/src/Galley/Cassandra/Proposal.hs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ interpretProposalStoreToCassandra =
4747
GetProposal groupId epoch ref ->
4848
runIdentity <$$> retry x1 (query1 getQuery (params LocalQuorum (groupId, epoch, ref)))
4949
GetAllPendingProposals groupId epoch ->
50-
runIdentity <$$> retry x1 (query getAllPending (params LocalQuorum (groupId, epoch)))
50+
fst <$$> retry x1 (query getAllPending (params LocalQuorum (groupId, epoch)))
51+
RefreshPendingProposals groupId epoch -> refreshProposals groupId epoch
5152

5253
storeQuery :: Timeout -> PrepQuery W (GroupId, Epoch, ProposalRef, RawMLS Proposal) ()
5354
storeQuery ttl =
@@ -59,5 +60,22 @@ storeQuery ttl =
5960
getQuery :: PrepQuery R (GroupId, Epoch, ProposalRef) (Identity (RawMLS Proposal))
6061
getQuery = "select proposal from mls_proposal_refs where group_id = ? and epoch = ? and ref = ?"
6162

62-
getAllPending :: PrepQuery R (GroupId, Epoch) (Identity ProposalRef)
63-
getAllPending = "select ref from mls_proposal_refs where group_id = ? and epoch = ?"
63+
getAllPending :: PrepQuery R (GroupId, Epoch) (ProposalRef, RawMLS Proposal)
64+
getAllPending = "select ref, proposal from mls_proposal_refs where group_id = ? and epoch = ?"
65+
66+
refreshProposals :: GroupId -> Epoch -> Client ()
67+
refreshProposals groupId epoch = do
68+
props <- retry x1 (query getAllPending (params LocalQuorum (groupId, epoch)))
69+
retry x5 . batch $ do
70+
setType BatchLogged
71+
setConsistency LocalQuorum
72+
-- insert each proposal with a bumped epoch
73+
for_ props $ \p ->
74+
addPrepQuery
75+
(storeQuery defaultTTL)
76+
(groupId, succ epoch, fst p, snd p)
77+
-- remove old proposals
78+
addPrepQuery removeOld (groupId, epoch)
79+
where
80+
removeOld :: PrepQuery W (GroupId, Epoch) ()
81+
removeOld = "delete from mls_proposal_refs where group_id = ? and epoch = ?"

services/galley/src/Galley/Effects/ProposalStore.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,12 @@ data ProposalStore m a where
4242
GroupId ->
4343
Epoch ->
4444
ProposalStore m [ProposalRef]
45+
-- | Update pending proposals by increasing the epoch number by one. This is
46+
-- used for external commits because an external committer has no up-to-date
47+
-- view of pending proposals.
48+
RefreshPendingProposals ::
49+
GroupId ->
50+
Epoch ->
51+
ProposalStore m ()
4552

4653
makeSem ''ProposalStore

0 commit comments

Comments
 (0)