-
Notifications
You must be signed in to change notification settings - Fork 19
fix: prevent add prev_event or auth_events if the initial events are already informed #248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -50,6 +50,9 @@ export abstract class PersistentEventBase< | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| protected rawEvent: PduWithHashesAndSignaturesOptional; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private authEventsIds: Set<EventID> = new Set(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private prevEventsIds: Set<EventID> = new Set(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| constructor( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| event: PduWithHashesAndSignaturesOptional, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public readonly version: Version, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -58,6 +61,16 @@ export abstract class PersistentEventBase< | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (this.rawEvent.signatures) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.signatures = this.rawEvent.signatures; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (this.rawEvent.auth_events) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const id of this.rawEvent.auth_events) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.authEventsIds.add(id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (this.rawEvent.prev_events) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const id of this.rawEvent.prev_events) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.prevEventsIds.add(id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+67
to
75
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | |
| } | |
| if (this.rawEvent.prev_events) { | |
| for (const id of this.rawEvent.prev_events) { | |
| this.prevEventsIds.add(id); | |
| } | |
| } | |
| } | |
| } | |
| delete this.rawEvent.auth_events; | |
| } | |
| if (this.rawEvent.prev_events) { | |
| for (const id of this.rawEvent.prev_events) { | |
| this.prevEventsIds.add(id); | |
| } | |
| delete this.rawEvent.prev_events; | |
| } | |
| } | |
| /** | |
| * Returns the current list of auth event IDs as an array. | |
| */ | |
| getAuthEventsArray(): EventID[] { | |
| return Array.from(this.authEventsIds); | |
| } | |
| /** | |
| * Returns the current list of prev event IDs as an array. | |
| */ | |
| getPrevEventsArray(): EventID[] { | |
| return Array.from(this.prevEventsIds); | |
| } |
Copilot
AI
Oct 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addPrevEvents and authedBy now update only the Sets and no longer mutate rawEvent.prev_events or rawEvent.auth_events, which can leave rawEvent.* arrays stale if any other code paths still access them directly. To avoid divergence, either also update rawEvent.* arrays here, or refactor remaining internal/external usages to always go through the Set-backed accessors and document rawEvent.* as legacy.
Copilot
AI
Oct 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addPrevEvents and authedBy now update only the Sets and no longer mutate rawEvent.prev_events or rawEvent.auth_events, which can leave rawEvent.* arrays stale if any other code paths still access them directly. To avoid divergence, either also update rawEvent.* arrays here, or refactor remaining internal/external usages to always go through the Set-backed accessors and document rawEvent.* as legacy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using logical && inside Promise.all results in boolean false entries when conditions fail, which is unconventional and can obscure intent. Recommend building the promise list explicitly: const tasks = []; if (instance.event.auth_events.length === 0) tasks.push(this.addAuthEvents(instance)); if (instance.event.prev_events.length === 0) tasks.push(this.addPrevEvents(instance)); await Promise.all(tasks);