Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/js/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -2396,7 +2396,12 @@ class ChannelManager {
// Persist the PRUNED cover even when nothing is pending — a member
// who regained access must leave the cover now, or the record of
// the regain is lost and their next loss never rotates.
channel.rotatedForNoAccess = [...covered, ...pending];
const cover = new Set([...covered, ...pending]);
const same = (a, b) => a.size === b.size && [...a].every(x => b.has(x));
// Runs on every admin open, and each save schedules a full sync push.
if (same(cover, new Set((channel.rotatedForNoAccess || []).map(lower)))
&& same(withAccess, previously)) return;
channel.rotatedForNoAccess = [...cover];
channel.accessSnapshot = [...withAccess];
await this.saveChannels();
} catch (e) {
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/channels.extended.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,27 @@ describe('ChannelManager Extended', () => {
expect(channelManager.isRotationOwed(streamId)).toBe(true);
});

it("the owner's sweep saves only when the gate changed what it records", async () => {
const flags = vi.spyOn(channelManager, 'getGateMemberFlags').mockResolvedValue([
{ address: '0xMyAddress', access: true, isOwner: true },
{ address: '0xmember1', access: true }
]);

await channelManager._rotateForLostAccess(channel);
await channelManager._rotateForLostAccess(channel);
expect(channelManager.saveChannels).toHaveBeenCalledTimes(1);

flags.mockResolvedValue([
{ address: '0xmyaddress', access: true, isOwner: true },
{ address: '0xmember1', access: true },
{ address: '0xmember2', access: true }
]);
await channelManager._rotateForLostAccess(channel);
await channelManager._rotateForLostAccess(channel);
expect(channelManager.saveChannels).toHaveBeenCalledTimes(2);
flags.mockRestore();
});

it('a ban whose rotation goes out owes nothing', async () => {
epochKeyManager.rotateEpoch.mockResolvedValue(undefined);

Expand Down
Loading