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 1a88e43
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions protocol/communities/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3448,9 +3448,11 @@ func (m *Manager) dbRecordBundleToCommunity(r *CommunityRecordBundle) (*Communit

if community.config.EventsData != nil {
eventsDescription, err := validateAndGetEventsMessageCommunityDescription(community.config.EventsData.EventsBaseCommunityDescription, community.ControlNode())

if err != nil {
m.logger.Error("invalid EventsBaseCommunityDescription", zap.Error(err))
}

if eventsDescription != nil && eventsDescription.Clock == community.Clock() {
community.applyEvents()
}
Expand Down Expand Up @@ -5147,6 +5149,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 +5201,17 @@ func (m *Manager) promoteSelfToControlNode(community *Community, clock uint64) (
return false, err
}

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

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 1a88e43

Please sign in to comment.