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

Use quorums N-MAX_REORG_BLOCKS_POST_HF12 for checkpointing #721

Merged
merged 5 commits into from
Jul 11, 2019

Conversation

Doy-lee
Copy link
Collaborator

@Doy-lee Doy-lee commented Jul 8, 2019

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

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);
Copy link
Member

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.

Copy link
Collaborator Author

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++)
Copy link
Member

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).

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

@Doy-lee Doy-lee left a 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);
Copy link
Collaborator Author

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++)
Copy link
Collaborator Author

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.

@Doy-lee Doy-lee force-pushed the CheckpointFromTailMinusNBlocks branch from f18d765 to 6205a88 Compare July 10, 2019 08:37
@Doy-lee Doy-lee merged commit 7ee4b10 into oxen-io:dev Jul 11, 2019
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

2 participants