Skip to content

Commit

Permalink
fix_: mitigate permission stuck in pending state
Browse files Browse the repository at this point in the history
This PR mitigates permission stuck in pending state upon making device a
control node. It fixes
[#14023](status-im/status-desktop#14023)
  • Loading branch information
kounkou committed Apr 18, 2024
1 parent 9e5462e commit 44f4212
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions protocol/communities/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -5147,6 +5147,17 @@ func (m *Manager) PromoteSelfToControlNode(community *Community, clock uint64) (
return community.emptyCommunityChanges(), m.saveAndPublish(community)
}

func (m *Manager) applyCommunityEvents(community *Community) map[string]uint64 {
appliedEvents := map[string]uint64{}
if community.config.EventsData != nil {
for _, event := range community.config.EventsData.Events {
appliedEvents[event.EventTypeID()] = event.CommunityEventClock
}
}

return appliedEvents
}

func (m *Manager) promoteSelfToControlNode(community *Community, clock uint64) (bool, error) {
ownerChanged := false
community.setPrivateKey(m.identity)
Expand Down Expand Up @@ -5188,6 +5199,32 @@ func (m *Manager) promoteSelfToControlNode(community *Community, clock uint64) (
return false, err
}

if community.config.EventsData != nil {
appliedEvents := m.applyCommunityEvents(community)

community.config.EventsData = nil // clear events, they are already applied

// TODO : retrieve message from non-control-node clients
/*
err = community.processEvents(, appliedEvents)
if err != nil {
return false, err
}
*/

err = m.persistence.SaveCommunity(community)
if err != nil {
return false, err
}

err = m.persistence.UpsertAppliedCommunityEvents(community.ID(), appliedEvents)
if err != nil {
return false, err
}

m.publish(&Subscription{Community: community})
}

community.increaseClock()

return ownerChanged, nil
Expand Down

0 comments on commit 44f4212

Please sign in to comment.