Skip to content

Approximates code from algorithmic description#1235

Closed
lasarojc wants to merge 13 commits intomainfrom
lasarojc/approximate-code-algo
Closed

Approximates code from algorithmic description#1235
lasarojc wants to merge 13 commits intomainfrom
lasarojc/approximate-code-algo

Conversation

@lasarojc
Copy link
Contributor

@lasarojc lasarojc commented Aug 10, 2023

lines 36 to 43 of the algorithm are broken into two separate conditions to detect if a value is being relocked.
Relocking is a subclass of locking and restructuring the case as such brings the code closer to the algorithm, while keeping the distinction in the logging.


PR checklist

  • Tests written/updated
  • Changelog entry added in .changelog (we use unclog to manage our changelog)
  • Updated relevant documentation (docs/ or spec/) and code comments

@lasarojc lasarojc requested a review from a team as a code owner August 10, 2023 17:50
@lasarojc lasarojc requested a review from a team August 10, 2023 17:50
@lasarojc lasarojc changed the base branch from main to hvanz/request-process-proprosal-once August 10, 2023 17:51
Co-authored-by: Sergio Mena <sergio@informal.systems>
Base automatically changed from hvanz/request-process-proprosal-once to main August 11, 2023 12:25
Copy link
Collaborator

@sergio-mena sergio-mena left a comment

Choose a reason for hiding this comment

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

Thanks for this @lasarojc, looking great!

Copy link

@cason cason left a comment

Choose a reason for hiding this comment

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

I think the changes are legit, but I have two main comments:

  1. We are changing how the protocol works. In the case we locked on a block (so we have that block) in a previous round, and receive a Proposal from the current round for the locked block ID, plus the associated 2/3+ Prevotes, we are not issuing a Precommit for that (locked) block if we didn't receive the full proposed block again (the same block, but with updated round).
  2. I wonder why the above mentioned situation is not covered by a test unit. The test unit would also serve as a way to document the protocol operation change we are introducing here. I still think that the ideal procedure should be to first create a test that fails, then update the code so that the test succeeds.

I am aware that creating and updating test units for consensus is a nightmare. But I think that, if we don't have that test, we should at least clearly describe in the PR the change in the scenario mentioned above (and others, if it is the case).

logger.Error("failed publishing event lock", "err", err)
}
} else {
if err := cs.eventBus.PublishEventRelock(cs.RoundStateEvent()); err != nil {
Copy link

Choose a reason for hiding this comment

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

We are not re-locking in this case, right? We are unlocking and then locking a different value. I wonder whether the event we are producing should be the same. Actually, changing a lock is something unusual, I kind of information that should probably be highlighted on the logs and parsed in a different way.

Copy link
Contributor Author

@lasarojc lasarojc Aug 18, 2023

Choose a reason for hiding this comment

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

Indeed we are changing the locked value, which I considered to be a relocking.
We can add another event type to handle this case or send two events in sequence, unlock and lock.

@cason
Copy link

cason commented Aug 17, 2023

There is a test which is failining: TestStateLockPOLUpdateLock. And it is actually associated with relocking.

@cason
Copy link

cason commented Aug 17, 2023

As a suggestion for test units to be considered/updated: TestStateLockMissingProposalWhenPOLSeenDoesNotUpdateLock and TestStateLockMissingProposalWhenPOLSeenDoesNotUnlock. They both refer to a lock change, so in both cases the node is expected to Precommit for nil. I wonder whether adapting one of them to cover this situation in which we don't change the lock, as the proposal matches the locked value, but nonetheless we should, with the new code, Precommit for nil.

@cason
Copy link

cason commented Aug 17, 2023

The scenario that I mentioned in previous comments is tested in PR #1257.

@lasarojc lasarojc self-assigned this Aug 18, 2023
@lasarojc lasarojc added the wip Work in progress label Aug 18, 2023
@lasarojc
Copy link
Contributor Author

We are closing this PR without merging, as it would revert an optimization that is in place, even though the optimization is for the non-happy path and, as stated in the PR, causes the code to slightly diverge from the pseudo-code.

@lasarojc lasarojc closed this Aug 28, 2023
@zrbecker zrbecker deleted the lasarojc/approximate-code-algo branch February 7, 2025 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wip Work in progress

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants