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

Improve private chains tracking #348

Merged
merged 7 commits into from Mar 22, 2021
Merged

Conversation

abi87
Copy link
Contributor

@abi87 abi87 commented Nov 10, 2020

Along @cronicc indications we are going to extend getchaintips with a --with-penalties=true/false paramenter to include, for each branch:

  1. penalty-at-start of branch. A non-zero value indicates branch starts of penalized
  2. penalty-at-tip of branch
  3. blocks-to-mainchain, i.e. how many blocks on selected branch must be mined in order for it to become the mainchain

@abi87 abi87 requested review from cronicc and alsala November 10, 2020 08:14
{
// blocks on tip get penalty reduced by 1;
// others get penalty increased proportionally to distance from tip
return std::max<int>((activeChainHeight - newBlock.nHeight),-1);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is more compact than before but we have not the trace anymore; should we keep it?

{
// blocks on tip get penalty reduced by 1;
// other blocks get penalty increased proportionally to distance from tip
int64_t blockDelay = std::max<int64_t>((activeChainHeight - newBlock.nHeight),int64_t(-1));
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this code behaving the same way if for example activeChainHeight is MIN_INT64 and newBlock.height is MIN_INT64 +1?
Why this PR needed this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Change is purely to improve readability, I can roll it back should there not be agreement on such improvement.
Moreover this function is called uniquely by AddToBlockIndex, with activeChainHeight set to chainActive.Height(). chainActive.Height() is either positive, or -1 (at start, when no block has been added yet). In both cases, the value far away for int64_t boundaries, which would cause the refactored code to diverge from the original

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted change as agree offline

@cronicc
Copy link
Member

cronicc commented Feb 10, 2021

To be rebased on top of current development to make a new CI run pass, ready to be merged once CI passes.

@cronicc
Copy link
Member

cronicc commented Feb 15, 2021

Not merging until I had a chance to look at #366

In cases where 2 branches have the same length, the 'active' branch
is not guaranteed to be at list index 0 in the getchaintips response.
Fixed by sorting the list on 'status' k:v.
@cronicc cronicc merged commit 7bd5967 into development Mar 22, 2021
@lander86 lander86 deleted the improve_private_chains_tracking branch April 5, 2022 09:39
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

4 participants