Skip to content

blockchain: Cleanup proof of stake checks.#3688

Open
davecgh wants to merge 10 commits intodecred:masterfrom
davecgh:blockchain_housekeeping
Open

blockchain: Cleanup proof of stake checks.#3688
davecgh wants to merge 10 commits intodecred:masterfrom
davecgh:blockchain_housekeeping

Conversation

@davecgh
Copy link
Copy Markdown
Member

@davecgh davecgh commented May 6, 2026

This is rebased on #3680.

This performs some light cleanup of the checkProofOfStake function to make it more consistent with the rest of the code make the error messages more accurate and useful.

@davecgh davecgh added this to the 2.2.0 milestone May 6, 2026
@davecgh davecgh force-pushed the blockchain_housekeeping branch from 4c38fa3 to 4218c2c Compare May 6, 2026 13:32
davecgh added 10 commits May 6, 2026 17:44
This reworks the tests in TestTreasuryIsFunctions for the treasury add,
treasurybase, and treasury spend identification funcs to make them more
comprehensive, correct some that weren't actually testing what they
claimed, and make them much more consistent with the other tests
throughout the code base.  Not only does it perform more comprehensive
testing, it reduces the test code by about 42%.

In particular:

- Use hex to bytes for hard-coded byte slices for some of the globals
  instead of the much more verbose raw byte slices
- Introduce helper functions to create the various components of the
  transactions
- Start with well-formed transactions and modify them for each test
  instead of building them from scratch every time
- Run all identification funcs against all of the transaction types to
  help ensure none of them are incorrectly detected as any other
- Significantly improves readability and adds descriptions to make it
  clear for people not familiar with the code
- Modernize the test formatting
- Effectively add more tests overall due to cross testing
- Correct test intending to pass stakebase but not treasury add and
  assert it actually passes the stakebase checks

This is part of a larger overall effort to bring the treasury code up to
the standards used throughout the rest of the blockchain consensus code.
Now that the updated treasury spend tests cover the fully valid case,
there is no benefit to repeating it in another test.

This is part of a larger overall effort to bring the treasury code up to
the standards used throughout the rest of the blockchain consensus code.
This reworks the treasury spend error tests to use the newly introduced
functions that start with a valid treasury spend and then mutates a copy
to induce the specific error to test.  In the process, it also corrects
some tests that weren't actually tsting what they claimed.

The result is significantly more readable, provides more comprehensive
test coverage, is more consistent with the other tests throughout the
code base, and reduces the test code for the relevant tests by about
69%.

This is part of a larger overall effort to bring the treasury code up to
the standards used throughout the rest of the blockchain consensus code.
This reworks the treasury add error tests to use the newly introduced
functions that start with a valid treasury add transaction and then
mutates a copy to induce the specific error to test.  In the process, it
also corrects some tests that weren't actually tsting what they claimed.

The result is significantly more readable, provides more comprehensive
test coverage, is more consistent with the other tests throughout the
code base, and reduces the test code for the relevant tests by about
56%.

This is part of a larger overall effort to bring the treasury code up to
the standards used throughout the rest of the blockchain consensus code.
This reworks the treasurybase error tests to use the newly introduced
functions that start with a valid treasurybase and then mutates a copy
to induce the specific error to test.  In the process, it also corrects
some tests that weren't actually tsting what they claimed.

The result is significantly more readable, provides more comprehensive
test coverage, is more consistent with the other tests throughout the
code base, and reduces the test code for the relevant tests by about
63%.

This is part of a larger overall effort to bring the treasury code up to
the standards used throughout the rest of the blockchain consensus code.
This cleans up the CheckTAdd method to make it much more consistent with
the other code used in consensus throughout the rest of the code base.

While there are no known exploitable issues with the func and it has
worked well for a while now, it is highly inconsistent with the rest of
the consensus code in style and polish and has various other issues.

For example:

- several of the reported error message are incorrect
- most of the error message don't provide very helpful messages and
  reference internal names that are not visible to users
- inconsistent variable names
- uses less efficient inverted logic tests
- various misleading and inaccurate comments
- exported func comment refers to internal func that is not visible in
  generated documention

This is part of a larger overall effort to bring the treasury code up to
the standards used throughout the rest of the blockchain consensus code.
This cleans up the CheckTSpend method to make it much more consistent
with the other code used in consensus throughout the rest of the code
base.

While there are no known exploitable issues with the func and it has
worked well for a while now, it is highly inconsistent with the rest of
the consensus code in style and polish and has various other issues.

For example:

- several of the reported error message are incorrect
- most of the error message don't provide very helpful messages and
  reference internal names that are not visible to users
- inconsistent errors
- inconsistent variable names
- uses less efficient and harder to read inverted logic tests
- various misleading and inaccurate comments

This is part of a larger overall effort to bring the treasury code up to
the standards used throughout the rest of the blockchain consensus code.
This cleans up the CheckTreasuryBase method to make it much more
consistent with the other code used in consensus throughout the rest of
the code base.

While there are no known exploitable issues with the func and it has
worked well for a while now, it is highly inconsistent with the rest of
the consensus code in style and polish and has various other issues.

For example:

- several of the reported error message are incorrect
- most of the error message don't provide very helpful messages and
  reference internal names that are not visible to users
- inconsistent variable names
- some checks are not in the most logical order
- various misleading and inaccurate comments
- some checks are not making use of existing funcs

This is part of a larger overall effort to bring the treasury code up to
the standards used throughout the rest of the blockchain consensus code.
This performs some light cleanup of the checkProofOfStake function to
make it more consistent with the rest of the code make the error
messages more accurate and useful.
@davecgh davecgh force-pushed the blockchain_housekeeping branch from 4218c2c to 8a1f132 Compare May 6, 2026 22:45
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.

1 participant