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 2188487
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions protocol/communities/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3447,13 +3447,11 @@ func (m *Manager) dbRecordBundleToCommunity(r *CommunityRecordBundle) (*Communit
community.config.CommunityDescription = description

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

if err != nil {
m.logger.Error("invalid EventsBaseCommunityDescription", zap.Error(err))
}
if eventsDescription != nil && eventsDescription.Clock == community.Clock() {
community.applyEvents()
}
}

if m.transport != nil && m.transport.WakuVersion() == 2 {
Expand Down Expand Up @@ -5147,6 +5145,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 +5197,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 2188487

Please sign in to comment.