-
Notifications
You must be signed in to change notification settings - Fork 536
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
Simplfied SummarizerNode:refreshLatestSummary logic #17106
Changes from all commits
5a7338e
682762e
df6dd0e
a34326f
fde2bbd
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 |
---|---|---|
|
@@ -35,10 +35,10 @@ import { | |
EscapedPath, | ||
ICreateChildDetails, | ||
IInitialSummary, | ||
IRefreshSummaryResult, | ||
ISummarizerNodeRootContract, | ||
parseSummaryForSubtrees, | ||
parseSummaryTreeForSubtrees, | ||
RefreshSummaryResult, | ||
SummaryNode, | ||
ValidateSummaryResult, | ||
} from "./summarizerNodeUtils"; | ||
|
@@ -365,27 +365,21 @@ export class SummarizerNode implements IRootSummarizerNode { | |
|
||
/** | ||
* Refreshes the latest summary tracked by this node. If we have a pending summary for the given proposal handle, | ||
* it becomes the latest summary. If the current summary is already ahead (e.g., loaded from a service summary), | ||
* we skip the update. If the current summary is behind, then we do not refresh. | ||
* it becomes the latest summary. If the current summary is already ahead, we skip the update. | ||
* If the current summary is behind, then we do not refresh. | ||
* | ||
* @returns A RefreshSummaryResult type which returns information based on the following three scenarios: | ||
* | ||
* 1. The latest summary was not updated. | ||
* | ||
* 2. The latest summary was updated and the summary corresponding to the params was being tracked. | ||
* | ||
* 3. The latest summary was updated but the summary corresponding to the params was not tracked. | ||
* @returns true if the summary is tracked by this node, false otherwise. | ||
*/ | ||
public async refreshLatestSummary( | ||
proposalHandle: string | undefined, | ||
proposalHandle: string, | ||
summaryRefSeq: number, | ||
): Promise<RefreshSummaryResult> { | ||
): Promise<IRefreshSummaryResult> { | ||
const eventProps: { | ||
proposalHandle: string | undefined; | ||
summaryRefSeq: number; | ||
referenceSequenceNumber: number; | ||
latestSummaryUpdated?: boolean; | ||
wasSummaryTracked?: boolean; | ||
isSummaryTracked?: boolean; | ||
pendingSummaryFound?: boolean; | ||
} = { | ||
proposalHandle, | ||
summaryRefSeq, | ||
|
@@ -406,48 +400,22 @@ export class SummarizerNode implements IRootSummarizerNode { | |
}); | ||
} | ||
|
||
if (proposalHandle !== undefined) { | ||
const maybeSummaryNode = this.pendingSummaries.get(proposalHandle); | ||
|
||
if (maybeSummaryNode !== undefined) { | ||
this.refreshLatestSummaryFromPending( | ||
proposalHandle, | ||
maybeSummaryNode.referenceSequenceNumber, | ||
); | ||
eventProps.wasSummaryTracked = true; | ||
eventProps.latestSummaryUpdated = true; | ||
event.end(eventProps); | ||
return { | ||
latestSummaryUpdated: true, | ||
wasSummaryTracked: true, | ||
summaryRefSeq, | ||
}; | ||
} | ||
let isSummaryTracked = false; | ||
let isSummaryNewer = false; | ||
|
||
const props = { | ||
summaryRefSeq, | ||
pendingSize: this.pendingSummaries.size ?? undefined, | ||
}; | ||
this.logger.sendTelemetryEvent({ | ||
eventName: "PendingSummaryNotFound", | ||
proposalHandle, | ||
referenceSequenceNumber: this.referenceSequenceNumber, | ||
details: JSON.stringify(props), | ||
markfields marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
if (summaryRefSeq > this.referenceSequenceNumber) { | ||
isSummaryNewer = true; | ||
} | ||
|
||
// If the summary for which refresh is called is older than the latest tracked summary, ignore it. | ||
if (this.referenceSequenceNumber >= summaryRefSeq) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Observation: This case is no longer addressed by this function. It's up to the caller. This is probably fine, but I'd want us to think really carefully about the global state here, since I think it's fine because it only changes if we are tracking the incoming summary, in which case before his code would be unreachable anyway. And if we're not tracking, then it doesn't change, so it's fine for the caller to check. Sound correct? Hopefully test coverage helps here too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Weird that this was There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check is still there:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm curious Why you brought it back? I thought it was fine after I thought out loud about it. It was just a little hard to trace through the diff. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was on the fence about keeping it vs removing it from the point of view of not making significant changes in one go. With you comment, it seemed like it added some confusion so I added it back. We can remove it later if needed. |
||
eventProps.latestSummaryUpdated = false; | ||
event.end(eventProps); | ||
return { latestSummaryUpdated: false }; | ||
const maybeSummaryNode = this.pendingSummaries.get(proposalHandle); | ||
if (maybeSummaryNode !== undefined) { | ||
this.refreshLatestSummaryFromPending( | ||
proposalHandle, | ||
maybeSummaryNode.referenceSequenceNumber, | ||
); | ||
isSummaryTracked = true; | ||
} | ||
|
||
// Note that we did not track this summary, but that the latest summary was updated. | ||
eventProps.latestSummaryUpdated = true; | ||
eventProps.wasSummaryTracked = false; | ||
event.end(eventProps); | ||
return { latestSummaryUpdated: true, wasSummaryTracked: false }; | ||
event.end({ ...eventProps, isSummaryNewer, pendingSummaryFound: isSummaryTracked }); | ||
return { isSummaryTracked, isSummaryNewer }; | ||
}, | ||
{ start: true, end: true, cancel: "error" }, | ||
); | ||
|
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.
What do you think of renaming this here and elsewhere to
handleSummaryAck
oronSummaryAck
or something?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.
Reason why - Besides the obvious (we don't do any "refreshing", just tracking), the return value is typically called
isSummaryTracked
, but without all the context we have this reads kind of strangely:const isSummaryTracked = refreshLatestSummary(...);
How about this:
const pendingSummaryFound = matchAckWithPendingSummary(...);
Or something similar?
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.
I would rather not do any such renames in this PR for 3 reasons:
updateLatestSummaryState
or something like that.