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

Implement mocknet and CSV output of HF21 transition #1800

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

Conversation

Doy-lee
Copy link
Collaborator

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

Goes ontop of https://github.com/oxen-io/oxen-core/pull/1790/files

I did have to modify the transition code a little bit to extract out information for producing the reports. The notable changes:

  • Mocknet is enabled by configuring the build with -D WITH_MOCKNET=ON. The intention is that in our release and packagable builds everything mocknet should be completely compiled out and there's no way of getting it to activated at all in public builds.

Most of the implementation is compartmentalised into src/network_config/mocknet.{h,cpp} and compiles to no-op macros when disabled.

  • Some cursory header cleanup, removing unused headers, moving things to implementation file if it can be, removing dead/unused macros e.t.c.

  • Updating the conversion_ratio to use 64 bits, the numbers we were playing were fractional and we have a mul128_div primitive in the codebase that seemed fine to use for this purpose.

  • Stack trace support is not a build flag enabled with -D WITH_STACKTRACE=ON

  • Fix 0 OXEN payout generating an output in the miner TX on transition of the amount of rewards owed is less than 1000 DB OXEN units.

Enabling mocknet can be done by specifying the flag --fork-to-mocknet <height> at which when the chain height reaches <height> (e.g. top_block.get_height() + 1 == <height>) then mock nodes will be injected into the SNL and all the quorums from that point will be hijacked by those nodes and it will periodically generate blocks to the chain.

When this happens, pulse timestamps are disabled and blocks are appended to the chain every 5s.

@Doy-lee Doy-lee requested a review from tewinget March 5, 2025 02:44
@Doy-lee Doy-lee force-pushed the doyle-mocknet-rebased branch 2 times, most recently from 860087b to da5f3e8 Compare March 5, 2025 05:58

for (auto& [addr, amt] : rewards) {
auto address_str = "0x{:x}"_format(addr);
auto amount = static_cast<int64_t>(amt * BATCH_REWARD_FACTOR);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be covered in #1802 but github won't let me comment here in that PR. I assume that this amt * BATCH_REWARD_FACTOR should be converted to the "db vs actual" coin functions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep. Just separated them because that change could be completely isolated out and that this PR focuses on just getting mocknet in.

Copy link
Collaborator

@tewinget tewinget left a comment

Choose a reason for hiding this comment

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

Couple tiny nitpicks but LGTM

tewinget and others added 23 commits March 7, 2025 14:33
Boost 1.87 removed many things which were previously only deprecated,
some of which we were still using.
changing from including boost asio io_service to io_context is roughly equivalent,
but the former has a typedef for compatibility.  I replicated the typedef,
but gated it on the boost version that removed the io_service include.
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.
Doy-lee added 29 commits March 12, 2025 13:29
- Windows.h is only needed if we don't have readline
- Use WIN32_LEAN_AND_MEAN to #define out a bunch of headers you don't need
- Address some issues with the network not correctly transitioning to
mocknet when a height is given that has already passed.
- Fix block leader not being set in the cache in certain scenarios
causing bad blocks to be generated
- Ensure that the Pulse quorum is hijacked at the leaf-most function for
generating a quorum to ensure all code paths requesting a Pulse quorum correctly
get hijacked with mock nodes
- Simplify the mocknet interface by dropping the post CN block add hook
and instead kill P2P comms when a mock pulse block is being constructed
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.
```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.
@Doy-lee Doy-lee force-pushed the doyle-mocknet-rebased branch from cfe33df to 118ae8f Compare March 12, 2025 03:23
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