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 cryptonote::reward_money in db_sqlite #1802

Open
wants to merge 73 commits into
base: dev
Choose a base branch
from

Conversation

Doy-lee
Copy link
Collaborator

@Doy-lee Doy-lee commented Mar 5, 2025

This goes on top of/depends on #1800

Only the last commit is relevant to this change which is that I've propagated the usage of cryptonote::reward_money our strongly typed money unit for handling the atomic OXEN and DB units into the SQLite DB layer.

--

Passing now. Not sure what those deb failures are atm.

jagerman and others added 30 commits March 5, 2025 16:20
the bulk of the code for transitioning to HF21 is present, and much
testing code is present.  This code does not yet work, and the tests are
not yet complete.

add hf21 transition mechanism to sqlite db
After HF21, any nodes which did not transition to SENT stakes need to be
removed.  Doing them all at once would be chaotic with swarms, so they
will be removed by the existing decommission/deregister system.

That system now has a config-determined limit of deactivations per block
so that this transition (but also huge network outages) won't cause
swarms to disappear (or other possible chaos resulting from mass
removal).
Staked oxen addresses which are not registered for the SENT transition
will have their pending service node rewards paid out in full on the
final block before HF21.

Modified local devnet testing to leave a staked static-startup address
out of the registration for testing this (and adjusted expected numbers
accordingly).
nodes which did not transition to hf21 will be removed by the
decommission->deregister mechanism rather than by the
bls-key-not-in-the-contract mechanism
script needs parameters set as appropriate:
  - oxen -> eth address mapping
  - transition bonus mapping
  - staking requirement and scaling ratio

TODO: some mainnet nodes have a larger stake, scaling needs to be normalized for those
They cannot ever come back, so there's really no point of leaving them
for a week.

(We *don't* want to immediately dereg them because going into decomm
still allows SN comms between storage servers, allowing the leaving
nodes to still transfer their files out to the remaining nodes upon
swarm dissolution).
nodes which do not transition at hardfork 21 should not be
in the reward payment rotation
calling this method returns a before and after as if hf21 would
happen the very next block.  Because outstanding oxen rewards will
differ from the exact fork height (and from block to block), this
can only be approximate, but it should be fairly close to what the
actual result will be.
higher staking requirement to test hf21 transition correctly scaling stake
proportions in multi-contrib
one line of this commit was kept and moved, making actually reverting it
and demolishing this commit tedious, so it stays, but the important
aspect of it which was to be reverted was later reverted.
The block before HF21 all addresses with accrued rewards which are
not registered for the HF21 transition with an ETH address will have
their OXEN balance paid out at that height rather than converted.

This was not working correctly for multiple reasons, but is now.
also update devnet hf21 parameters
Doy-lee added 18 commits March 5, 2025 16:20
This lets the caller control the final values that the transition will run with.
For ordinary usecases this is not important, the transition parameters
are pulled from the compile time constants. For testing and mocking it
can be useful to modify these values at runtime to simulate different
transition conditions.
For mocknet and testing we now allow changing the staking requirement
at runtime (i.e. for testing different staking requirements and
conversion ratios) the staking ratio needs to be updated with the
appropriate values.

Allow a higher precision conversion ratio to allow for more fine grained
conversions. For the $OXEN to $SESH conversion we now defer to a 128 bit
multiply to avoid overflow for the conversion.
I was counting the number SESH calculated for each contributor as the
amount they contributed to the node. This was incorrect because that
number is not the amount they were able to stake, just the amount the
were required to have to be able to keep the node alive.

This mean that `tokens_allocated >= staking_requirement` was incorrectly
attributing a node as having made it past the transition when it
actually didn't.

Instead of trying to be clever and calculating the partial collaterised
nodes that will be zombified, only count tokens from a fully
collateralised node.
@Doy-lee Doy-lee changed the title Use cryptonote::reward_money in db_sqlite WIP: Use cryptonote::reward_money in db_sqlite Mar 5, 2025
@Doy-lee Doy-lee changed the title WIP: Use cryptonote::reward_money in db_sqlite DRAFT: Use cryptonote::reward_money in db_sqlite Mar 5, 2025
Doy-lee added 4 commits March 6, 2025 11:36
```diff
     std::bitset<sizeof(uint16_t) * 8> bitset_view16(uint16_t val) {
-        std::bitset<sizeof(uint16_t) * 8> result = val;
+        std::bitset<sizeof(uint16_t)* 8> result = val;
         return result;
     }
```

clang-format constantly tries to re-format this line, moving the '*'
back and forth all the time. Seems to be a bug that we can avoid
completely by just pulling out the expression into a constexpr value.
There's various conversions back and forth between atomic OXEN and
atomic DB units that is error prone. This can be mitigated by using
a strongly-typed money amount that makes it explicit where and when
which unit is being used.
@Doy-lee Doy-lee force-pushed the doyle-use-reward-money-in-db-sqlite branch from 5639782 to ea82e61 Compare March 6, 2025 00:46
@Doy-lee Doy-lee force-pushed the doyle-use-reward-money-in-db-sqlite branch from 5945dfa to 7b6dc7c Compare March 6, 2025 06:14
@Doy-lee Doy-lee changed the title DRAFT: Use cryptonote::reward_money in db_sqlite Use cryptonote::reward_money in db_sqlite Mar 6, 2025
And somewhere, it already defines WIN32_LEAN_AND_MEAN so we remove that.
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.

3 participants