-
Notifications
You must be signed in to change notification settings - Fork 116
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
Use quorums N-MAX_REORG_BLOCKS_POST_HF12 for checkpointing #721
Conversation
Nodes on an alternative chain will generate quorums reflecting those on the alternate chain. Since checkpointing prevents reorgs up to MAX_REORG_BLOCKS_POST_HF12, use quorums exactly that many blocks old to ensure that at any point, all nodes will be working in quorums that are consistent between each other.
@@ -311,15 +308,19 @@ namespace service_nodes | |||
case quorum_type::checkpointing: | |||
{ | |||
m_last_checkpointed_height = std::max(start_voting_from_height, m_last_checkpointed_height); | |||
|
|||
for (m_last_checkpointed_height += (m_last_checkpointed_height % CHECKPOINT_INTERVAL); |
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.
This initial mutating addition doesn't look right. If the last checkpoint height is something that isn't already a multiple of CHECKPOINT_INTERVAL (say 100003) then this is going to add 3 and give 100006 which still isn't a proper checkpoint height. And if it is a multiple of CHECKPOINT_INTERVAL already (say 100000) then it seems as though it is going to add 0 and end up processing a checkpoint that has already been handled?
I think this should instead be: m_last_checkpointed_height += (CHECKPOINT_INTERVAL - m_last_checkpointed_height % CHECKPOINT_INTERVAL)
, but perhaps I'm missing 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.
I've made this error with modulo so many times now, when will I learn.
@@ -197,7 +194,7 @@ namespace service_nodes | |||
break; | |||
|
|||
m_obligations_height = std::max(m_obligations_height, start_voting_from_height); | |||
for (; m_obligations_height < (height - REORG_SAFETY_BUFFER_IN_BLOCKS); m_obligations_height++) | |||
for (; m_obligations_height < (height - MAX_REORG_BLOCKS); m_obligations_height++) |
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 like the "safety buffer" name much better. The "max reorg" name implies that this is somehow a limit, but as far as I can see it isn't (and mustn't be!): it is merely the target maximum implied by a checkpointing mechanism working in normal times. It is still possible for checkpoints to be missed and for this maximum to be exceeded; it's a rare case that shouldn't normally happen, but it is something we need to handle (even if suboptimally).
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.
You're right, I forgot about missed checkpoints leading to > the usual number of blocks reorganisable.
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.
Ready for merge when you're ready.
@@ -311,15 +308,19 @@ namespace service_nodes | |||
case quorum_type::checkpointing: | |||
{ | |||
m_last_checkpointed_height = std::max(start_voting_from_height, m_last_checkpointed_height); | |||
|
|||
for (m_last_checkpointed_height += (m_last_checkpointed_height % CHECKPOINT_INTERVAL); |
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've made this error with modulo so many times now, when will I learn.
@@ -197,7 +194,7 @@ namespace service_nodes | |||
break; | |||
|
|||
m_obligations_height = std::max(m_obligations_height, start_voting_from_height); | |||
for (; m_obligations_height < (height - REORG_SAFETY_BUFFER_IN_BLOCKS); m_obligations_height++) | |||
for (; m_obligations_height < (height - MAX_REORG_BLOCKS); m_obligations_height++) |
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.
You're right, I forgot about missed checkpoints leading to > the usual number of blocks reorganisable.
f18d765
to
6205a88
Compare
Nodes on an alternative chain will generate quorums reflecting those on
the alternate chain. Since checkpointing prevents reorgs up to
MAX_REORG_BLOCKS_POST_HF12, use quorums exactly that many blocks old to
ensure that at any point, all nodes will be working in quorums that are
consistent between each other.
This will cause a fork most likely on testnet. @jagerman