Skip to content
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

Simplify simulation messaging with priority queue and parameterise GST #209

Merged
merged 1 commit into from May 14, 2024

Conversation

masih
Copy link
Member

@masih masih commented May 10, 2024

Use heap.Interface to simplify the implementation of message passing during simulation by implementing a priority queue. The messages in-flight are priorities in ascending order of their deliverAt time, i.e. messages with earlier delivery time have higher priority.

Additionally, explicitly introduce an option to set Global Stabilization Time (GST). GST duration is one of the fundamental assumptions made by gPBFT, beyond which message delivery is assumed to be guaranteed. Enhance Withold adversary tests with varying GST time.

Relates to #196

@masih masih marked this pull request as ready for review May 10, 2024 12:26
@masih masih requested a review from anorth May 10, 2024 12:26
@masih masih force-pushed the masih/sim-msg-priority-queue branch 2 times, most recently from 1bf3314 to a0d96e5 Compare May 13, 2024 08:40
@masih masih force-pushed the masih/sim-msg-priority-queue branch from a0d96e5 to b4ef5a0 Compare May 13, 2024 19:07
@masih masih enabled auto-merge May 13, 2024 19:08
Use `heap.Interface` to simplify the implementation of message passing
during simulation by implementing a priority queue. The messages
in-flight are priorities in ascending order of their `deliverAt` time,
i.e. messages with earlier delivery time have higher priority.

Additionally, explicitly introduce an option to set Global Stabilization
Time (GST). GST duration is one of the fundamental assumptions made by
gPBFT, beyond which message delivery is assumed to be guaranteed.
Enhance Withold adversary tests with varying GST time.

Relates to #196
@masih masih force-pushed the masih/sim-msg-priority-queue branch from b4ef5a0 to ee3c5e2 Compare May 14, 2024 07:38
@masih masih added this pull request to the merge queue May 14, 2024
Merged via the queue into main with commit 6634d0b May 14, 2024
3 checks passed
@masih masih deleted the masih/sim-msg-priority-queue branch May 14, 2024 07:48
func (pq *messageQueue) Pop() any {
old := pq.mailbox
n := len(old)
item := old[n-1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it's removing the lowest priority (highest deliverAt) item, if they are in ascending order. Which I don't think is what we want here.

This message queue is lacking tests (my fault).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation of Pop is correct, i.e. adheres to what heap.Interface demands. It's my documentation that's misleading; apologies.

Unit tests are added here along with documentation correction.

Comment on lines +144 to +145
if adv != nil && !n.globalStabilisationElapsed {
if n.hasGlobalStabilizationTimeElapsed() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit confusing to read. We should just remove the boolean field if this can be calculated instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need the boolean filed to cache that GST has elapsed. Because, otherwise the simulation logs "GST elapsed" on every tick after GST has elapsed.

If you are happy for the log line to be removed then we can totally get rid of the boolean flag.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok makes sense, thanks.

masih added a commit that referenced this pull request May 15, 2024
Assert that simulation priority queue used to order message delivery is
behaving as expected:

* queued messages are sorted in ascending order of their `deliverAt`.
* removal of a message returns the one with earliest `deliverAt`.
* conditional upsert is respected.
* duplicate messages are allowed and ordered as expected.
* queue is fully drained upon removing all messages.

Update misleading godoc for `Pop` receiver.

Addresses #209 (comment)
masih added a commit that referenced this pull request May 15, 2024
Assert that simulation priority queue used to order message delivery is
behaving as expected:

* queued messages are sorted in ascending order of their `deliverAt`.
* removal of a message returns the one with earliest `deliverAt`.
* conditional upsert is respected.
* duplicate messages are allowed and ordered as expected.
* queue is fully drained upon removing all messages.

Update misleading godoc for `Pop` receiver.

Addresses #209 (comment)
masih added a commit that referenced this pull request May 15, 2024
Assert that simulation priority queue used to order message delivery is
behaving as expected:

* queued messages are sorted in ascending order of their `deliverAt`.
* removal of a message returns the one with earliest `deliverAt`.
* conditional upsert is respected.
* duplicate messages are allowed and ordered as expected.
* queue is fully drained upon removing all messages.

Update misleading godoc for `Pop` receiver.

Addresses #209 (comment)
github-merge-queue bot pushed a commit that referenced this pull request May 15, 2024
Assert that simulation priority queue used to order message delivery is
behaving as expected:

* queued messages are sorted in ascending order of their `deliverAt`.
* removal of a message returns the one with earliest `deliverAt`.
* conditional upsert is respected.
* duplicate messages are allowed and ordered as expected.
* queue is fully drained upon removing all messages.

Update misleading godoc for `Pop` receiver.

Addresses #209 (comment)
@masih masih self-assigned this May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants