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

tBTC rewards miscalculation on corner case #160

Open
manumonti opened this issue Nov 27, 2024 · 0 comments
Open

tBTC rewards miscalculation on corner case #160

manumonti opened this issue Nov 27, 2024 · 0 comments

Comments

@manumonti
Copy link
Member

A bug in the calculation of tBTC rewards has been discovered during regular checks of the last rewards distribution: a node may be able to skip penalties for insufficient uptime (96%) under certain circumstances.

The issue

If a node running the tBTC client stops running just before the end of a rewards period (i.e. the last days of the month) and starts up again during the next rewards period, the calculation script will erroneously consider that this is a new node during when calculating the rewards for the latter rewards period.

So a node can stop the client for a long time without being penalized for not meeting the 96% uptime requirement.

Example

I run my node during all through January, but I stop it on January 31st. Then, I wait until Feb 14th to start it again, and I keep it running during the rest of February.

Theoretically, I didn't run my node during 50% of February, so I shouldn't receive any rewards for the February period.

But in practice, the script will consider this to be a new node that starts for the first time on Feb 14th. As a new node, the uptime counter starts at Feb 14th, so the script will consider the uptime is 100% so this node will receive the rewards for the Feb 14th - Feb 28th period instead of being penalized with no rewards.

Why is this happening?

When calculating the tBTC rewards, the uptime of the clients is checked through a Prometheus server: the script queries the Prometheus server for the heartbeats sent by each tBTC client. So, if the client doesn't send heartbeats during more than 4% of the period time (the requirement is 96% of uptime), this node doesn't qualify for rewards.

The problem is that the tBTC calculation script queries the Prometheus server for the dates of the current period.

https://github.com/threshold-network/merkle-distribution/blob/main/src/scripts/tbtcv2-rewards/rewards.ts#L636

In the previous example, if we are calculating the February rewards, the script will query the heartbeats from Feb 1st to Feb 28th. Since the node stopped on Dec 31st and started again at Feb 14th, the query will not return any heartbeat from Feb 1st to Feb 14th. So the first heartbeat on Feb 14th will be considered as the first heartbeat ever and this node will be considered as new.

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

No branches or pull requests

1 participant