helium / blockchain-core

Apache License 2.0
214 stars 85 forks source link

Add validation for stale heartbeats #1393

Closed PaulVMo closed 2 years ago

PaulVMo commented 2 years ago

This change proposes adding a new validation to validator heartbeat transactions to ensure they are not older than the heartbeat interval + grace period. This change will help ensure that 1) validators who are significantly behind the blockchain (i.e. still syncing) do not submit PoC proposals or gateway reactivations and 2) PoC public keys stored in the ledger do not outlive the private keys stored locally by the validator (and thus causing invalid PoCs).

Currently, heartbeats are validated 1) to make sure they are not ahead of the consensus group validating the transaction and 2) to make sure they are not too soon after the previous heartbeat for that validator. The proposed change in this PR adds another check to make sure that the transaction height is not too old, using the heartbeat interval + grace period as the maximum age. While the miner includes a check to not submit a heartbeat if still synching, this is not currently enforced on chain.

This is likely an edge case, as most validator heartbeats are added to the chain within 2-3 blocks (see below for stats). However, during times of heavily load or in the case of an improperly functioning validator, the difference between the heartbeat transaction height and the height at which it is absorbed, may be significant. The table below shows the count of heartbeat transactions grouped by the difference between the chain height and the heartbeat transaction height in blocks for the last 100000 heartbeats.

Diff.   Count
2       45541
3       33080
4       11860
5        4341
6        1749
7         854
8         433
9         321
10        229
11-150    117
151+       94
PaulVMo commented 2 years ago

thanks evan. let me know if this tests are what you had in mind.

PaulVMo commented 2 years ago

Resolved merge conflict and squashed including re-running ct suite for validator heartbeats.