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

SCP align implementation with spec #745

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

UkoeHB
Copy link
Contributor

@UkoeHB UkoeHB commented Mar 8, 2021

Soundtrack of this PR: link to song that really fits the mood of this PR

Motivation

Align ballot value in ballot to vote to prepare with spec

The current implementation of SCP in MobileCoin is very close to the protocol description in the IETF draft and whitepaper. However one nuance was overlooked.

When setting the ballot value B, which corresponds to the ballot the node will vote to prepare, get_next_ballot_values() uses this priority list:

  • value of highest ballot confirmed prepared {with available messages from the network}
  • composite value from nomination
  • value of highest ballot accepted prepared {with available messages from the network}
  • previous value of B
  • None

However the available documentation on SCP does not indicate the {with available messages from the network} should be used. Instead they say

[IETF pg. 15] Each time the ballot counter is changed, the value is also recomputed as follows:

  • If any ballot has been confirmed prepared, then "ballot.value" is taken to to be "h.value" for the highest confirmed prepared ballot "h".
    Otherwise, if no ballot is confirmed prepared and no value is confirmed nominated, but the node has accepted a ballot prepared (because "prepare(b)" meets blocking threshold for some ballot "b"), then "ballot.value" is taken as the value of the highest such accepted prepared ballot.

[whitepaper pg. 24] If phase = PREPARE and m lets v confirm new higher ballots prepared, then raise h to the highest such ballot and set z = h:x.
[whitepaper pg. 23] z: Value to use in next ballot. If h=0, then z is the composite value ... otherwise, z=h:x.

Since nodes only store very limited historical information in their state (only B, P, PP, C:H), it is possible for future messages from a node to 'forget' about old information that a different node once used to set their H or P. This means after H is set, the other node could see a future state of the network that would not permit it to confirm H is prepared, and get_next_ballot_values() will fail to return the highest ballot confirmed prepared previously.

Add missing maybe_set_ballot_timer()

In do_prepare_phase() step 9 there is a maybe_set_ballot_timer() after updating the counter, however it is missing from step 9 in do_commit_phase() without explanation.

In this PR

  • SCP: aligns setting of ballot value for vote to prepare a ballot with specification
  • SCP: add missing maybe_set_ballot_timer()

Future Work

  • none

Comment on lines 1198 to +1209
if let Some(h) = self.ballots_confirmed_prepared().into_iter().max() {
if let Some(h_old) = &self.H {
if h_old > h {
return Some(h_old.X);
}
}
return Some(h.X);
}
else if let Some(h_old) = &self.H {
return Some(h_old.X);
}
Copy link
Contributor Author

@UkoeHB UkoeHB Mar 8, 2021

Choose a reason for hiding this comment

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

A simpler alternative would be returning H if it exists. Calling ballots_confirmed_prepared() is fairly expensive (or looks expensive).

Comment on lines +1225 to +1235
if let Some(p_old) = &self.P {
if p_old > p {
return Some(p_old.X);
}
}
return Some(p.X);
}
else if let Some(p_old) = &self.P {
return Some(p_old.X);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Similarly, simpler to return P if it exists.

Comment on lines 1236 to 1238
// Otherwise, values are unchanged.
if !self.B.is_zero() {
Copy link
Contributor Author

@UkoeHB UkoeHB Mar 8, 2021

Choose a reason for hiding this comment

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

I do not believe this conditional will ever be true. B can only be non-zero if: Z is set, H is set, or P is set. Whichever way it gets set, the earlier conditionals in this function will trigger before we get this far (assuming commit changes are added).

@UkoeHB UkoeHB changed the title SCP align vote to prepare ballot values with spec SCP align implementation with spec Mar 8, 2021
@UkoeHB UkoeHB marked this pull request as ready for review March 9, 2021 21:39
@jcape jcape added the help wanted Extra attention is needed label Apr 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
Status: Needs Triage
Development

Successfully merging this pull request may close these issues.

None yet

2 participants