oxen-io / oxen-core

Oxen core repository, containing oxend and oxen cli wallets
https://oxen.io
Other
317 stars 120 forks source link

Fix incorrect returning of stakes and regen SNL & SQL DB metadata #1725

Closed Doy-lee closed 2 months ago

Doy-lee commented 2 months ago

Currently the network has the incorrect stake amounts to unlock to operators because the stake amount was not correctly multiplied by BATCH_REWARD_FACTOR when inserted into the SQL DB. The staking_requirement was also not serialized to disk (so once the node restarts that value gets set to 0) and when the exit is processed, the stake amount to return gets clamped to 0. Right now only 2 exits have been done on the network which are from my nodes.

This patch fixes that and increments the version of the SNL which will trigger everyone to recalculate the values in the DB and the metadata (and correctly store the staking_requirement).

If the network tries to claim now there'll be inconsistencies in the amount of rewards claimable by the operator (me) and the aggregation will fail. The more operators that upgrade the better as the BLS aggregation will have less non-signers and more nodes with this patch will agree on the correct amounts to return.

Additionally noticed another adjacent bug where if you had multiple exits in the one block, only the first stake would get queued for unlocking and the rest was dropped due to an insert conflict.

More specifically:

More broadly, at a higher level the primary key looks out of place since the table is not really relational but it did help catch this error and the end result of coalescing rows is more ideal than having individual rows for each payment.

jagerman commented 2 months ago

The staking_requirement was also not serialized to disk (so once the node restarts that value gets set to 0) and when the exit is processed, the stake amount to return gets clamped to 0.

I'm not seeing this happen on current dev: staking_requirement seems to get preserved across a restart.

Edit: Oh, wait, I see: this is only for recently removed nodes (and I was looking at currently registered nodes).

jagerman commented 2 months ago

Resyncing mainnet failed the payment validation check; pushed a fix.

Doy-lee commented 2 months ago

Added the fixes and bumped the version to 11.0.5