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

[Consensus][Refactoring] Blocks v10: TierTwo payments in the coinbase transaction #2274

Merged
merged 16 commits into from
May 5, 2021

Conversation

random-zebra
Copy link

@random-zebra random-zebra commented Mar 26, 2021

Extracted from #2267.
This PR introduces an important consensus change. As per title, mn/budget payments are now outputs of the coinbase transaction, rather than the coinstake (which, now, contains only outputs belonging to the staker).
The block version is bumped to 10.
Also refactor the budget-payment functions, in preparation for the compatibility code and the new payment logic.

Built on top of:

@furszy
Copy link

furszy commented Apr 27, 2021

Can be rebased now.

@random-zebra
Copy link
Author

Rebased.

Copy link

@furszy furszy left a comment

Choose a reason for hiding this comment

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

Initial code review completed. There are some really nice cleanups and refactorings 👌

Left some comments. Probably the most important one for me, code structure wise, is inside 89416a1. The rest looks great

src/blockassembler.cpp Outdated Show resolved Hide resolved
src/validation.cpp Outdated Show resolved Hide resolved
src/masternodeman.cpp Outdated Show resolved Hide resolved
src/masternodeman.cpp Show resolved Hide resolved
@random-zebra
Copy link
Author

Thanks for the feedback @furszy!
I think I have addressed everything.
Feel free to take it for another round when you want 🥃

Copy link

@furszy furszy left a comment

Choose a reason for hiding this comment

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

Nice cool 👌, thanks for jumping over the feedback so quickly. Left some more comments after doing another full round.

The only comment that you missed to tackle from the previous round was the addMnToScores refactor that has the same rationale as the CanScheduleMN refactor, from this comment #2274 (comment)

Other than that and as a final line, awesome unit tests inclusion + further changes into the budget one, loved them 🥃 .

src/spork.cpp Show resolved Hide resolved
src/test/budget_tests.cpp Outdated Show resolved Hide resolved
src/test/budget_tests.cpp Outdated Show resolved Hide resolved
src/test/budget_tests.cpp Outdated Show resolved Hide resolved
src/masternodeman.cpp Outdated Show resolved Hide resolved
src/masternodeman.cpp Outdated Show resolved Hide resolved
@random-zebra
Copy link
Author

Updated as per review and rebased on master.

furszy
furszy previously approved these changes Apr 30, 2021
Copy link

@furszy furszy left a comment

Choose a reason for hiding this comment

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

Code review ACK 2410ee6, great work 👌 ☕ .

A good future PR work can be to create a functional test for the coinbase and coinstake changes pre and post v6 enforcement, overminting, sending to a different payee etc.
Crafting invalid blocks similar to how it is done in #2346. So we can validate the entire block processing flow as well.

@random-zebra
Copy link
Author

Squashed 328f12a into 511631c (now ddb1f26)

furszy
furszy previously approved these changes Apr 30, 2021
Copy link

@furszy furszy left a comment

Choose a reason for hiding this comment

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

No code changes after squashing, re-ACK 42005be

@furszy
Copy link

furszy commented May 3, 2021

Sadly, this PR requires a rebase. Will re-re-review the changes after it.

this will be needed in the following commits
Masternode and budgets are paid as outputs of the coinbase transaction
rather than the coinstake.
There is no change in the behavior here.
We just prepare the functions for a simpler integration with the new
payment logic by:
- passing the pindexPrev (instead of just the height), so we don't
introduce additional cs_main locks, to look into the active chain,
before accessing the deterministic list.
- using a *vector* of outputs (instead of a single one) since DMNs could
require a payment for the mn operator.
- use MasternodeRef for const mn pointers
- Initialize CMasternodePaymentWinner with the height
- CMasternodeMan:
  - CompareLastPaid/CompareScoreTxIn/CompareScoreMN (same)
  - Save MasternodeRefs in vecMasternodeLastPaid (instead of ins)
  - Refactor/Simplify GetMasternodeRank and GetCurrentMasterNode
@random-zebra
Copy link
Author

Rebased again. Please let's get this reviewed and merged, so we can keep moving forward with the priority list (which, atm includes this one, plus #2258, and #2296) and meet our deadlines.

Copy link

@furszy furszy left a comment

Choose a reason for hiding this comment

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

No code changes after rebase, ACK c2060ef

Copy link
Collaborator

@Fuzzbawls Fuzzbawls left a comment

Choose a reason for hiding this comment

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

Code ACK c2060ef

@furszy furszy merged commit 4e2e094 into PIVX-Project:master May 5, 2021
random-zebra added a commit that referenced this pull request May 11, 2021
…get_tests

42be32c [Trivial] Rename AddSporkMessage --> AddOrUpdateSporkMessage (random-zebra)
76fbe44 [Refactoring] Use AddSporkMessage globally for maps update (random-zebra)
7c68750 [Cleanup][Trivial] Remove un-implemented function ExecuteSpork (random-zebra)
eb271ef [Refactoring] Remove mocked BudgetManagerTest::IsBlockValueValid (random-zebra)

Pull request description:

  Extracted from:

  - [x] #2274

  and based on top of it.

  Forcing the update of the spork message and finalized budget, we can test the actual `IsBlockValueValid` function.

  This also refactors the spork code to update the maps in a single place, as suggested by @furszy here #2274 (comment).

ACKs for top commit:
  furszy:
    ACK 42be32c 👍 .
  Fuzzbawls:
    ACK 42be32c

Tree-SHA512: e1ef9aed9a4ff37f1dac4505d6213a93d75eba28d4592168f267c3089b60ff4e81c0d292bd1c8a34746124c3efbf479f2f42862fea414f4f31ed07e701ac8a57
furszy added a commit that referenced this pull request May 11, 2021
4a5baf3 [Doc] Add cold-staking changes to release notes (random-zebra)
c19416f [GUI] Use new opcode for P2CS after v6 enforcement (random-zebra)
45ebfee [RPC] Use new opcode for P2CS after v6 enforcement (random-zebra)
8eefab5 [Tests] Add script test for new opcode (random-zebra)
df11631 [Script] Introduce new OP_CHECKCOLDSTAKEVERIFY opcode (random-zebra)
b194386 [Refactor] Rename CCSV opcode to OP_CHECKCOLDSTAKEVERIFY_LOF (random-zebra)

Pull request description:

  Extracted from #2267, and rebased on top of #2258.
  Given the consensus change, introduced in #2274, we can define a more secure `OP_CHECKCOLDSTAKEVERIFY` opcode, which doesn't leave the last output of the coinstake "free" (as we no longer pay masternode/budgets in the coinstake tx).

  Built on top of:
  - [x] #2258
  - [x] #2274

ACKs for top commit:
  Fuzzbawls:
    re-Code ACK 4a5baf3 after rebase, no code changes.
  furszy:
    ACK 4a5baf3.

Tree-SHA512: ee78b76137e40df05b854f8959755f1b99e7c7328fb13708ba7e3e6dae6357450210ce19ed7a99dc54aa0d6051d0dbd745af70f4b6e9927de5d3cbb2e04fffb6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants