Skip to content

Commit

Permalink
Insert missing entries in CopyVoteAccount (#37)
Browse files Browse the repository at this point in the history
Problem: 
Due to unreliability in landing transactions in epoch 598 (when chain
was super congested), about half of active validators did not get a
single ValidatorHistoryEntry created, so their epoch credits were never
copied over in future epochs. This is bad for Stakenet scoring, and this
issue could happen in the future if congestion gets bad again.

Solution:
In the CopyVoteAccount instruction, when epochs are detected in the vote
account that don't exist in the CircBuf, insert those new entries and
shift all entries with greater epochs forward by one. This will evict
the oldest entries if we are wrapping around. After that, epoch credits
are copied to the old entries. We will then be able to retroactively
call:
`CopyTipDistributionAccount` and `UpdateStakeHistory` on those
validators.

Notes:
* We are still within the 64 epoch vote credit range, so epoch credits
from 598 and any other randomly skipped entries will get added
* In the most extreme case possible of 64 entries inserted (max epochs
in vote account), this instruction uses ~270k CUs. Most of the time none
will be added, and when this first runs, a handful will be added for
some validators. Normal CU usage is <30k.
  • Loading branch information
ebatsell authored May 27, 2024
1 parent a77dd50 commit d85e607
Show file tree
Hide file tree
Showing 6 changed files with 737 additions and 28 deletions.
9 changes: 7 additions & 2 deletions programs/validator-history/idl/validator_history.json
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@
{
"code": 6001,
"name": "InvalidEpochCredits",
"msg": "Invalid epoch credits, credits must be greater than previous credits"
"msg": "Invalid epoch credits, credits must exist and each value must be greater than previous credits"
},
{
"code": 6002,
Expand All @@ -928,7 +928,7 @@
{
"code": 6006,
"name": "NotEnoughVotingHistory",
"msg": "Not enough voting history to create account. Minimum 10 epochs required"
"msg": "Not enough voting history to create account. Minimum 5 epochs required"
},
{
"code": 6007,
Expand All @@ -954,6 +954,11 @@
"code": 6011,
"name": "EpochTooLarge",
"msg": "Epoch larger than 65535, cannot be stored"
},
{
"code": 6012,
"name": "DuplicateEpoch",
"msg": "Inserting duplicate epoch"
}
]
}
8 changes: 6 additions & 2 deletions programs/validator-history/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use anchor_lang::prelude::*;
pub enum ValidatorHistoryError {
#[msg("Account already reached proper size, no more allocations allowed")]
AccountFullySized,
#[msg("Invalid epoch credits, credits must be greater than previous credits")]
#[msg(
"Invalid epoch credits, credits must exist and each value must be greater than previous credits"
)]
InvalidEpochCredits,
#[msg("Epoch is out of range of history")]
EpochOutOfRange,
Expand All @@ -14,7 +16,7 @@ pub enum ValidatorHistoryError {
GossipDataInvalid,
#[msg("Unsupported IP Format, only IpAddr::V4 is supported")]
UnsupportedIpFormat,
#[msg("Not enough voting history to create account. Minimum 10 epochs required")]
#[msg("Not enough voting history to create account. Minimum 5 epochs required")]
NotEnoughVotingHistory,
#[msg(
"Gossip data too old. Data cannot be older than the last recorded timestamp for a field"
Expand All @@ -28,4 +30,6 @@ pub enum ValidatorHistoryError {
SlotHistoryOutOfDate,
#[msg("Epoch larger than 65535, cannot be stored")]
EpochTooLarge,
#[msg("Inserting duplicate epoch")]
DuplicateEpoch,
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub fn handle_copy_vote_account(ctx: Context<CopyVoteAccount>) -> Result<()> {
validator_history_account.set_commission_and_slot(epoch, commission, clock.slot)?;

let epoch_credits = VoteStateVersions::deserialize_epoch_credits(&ctx.accounts.vote_account)?;
validator_history_account.insert_missing_entries(&epoch_credits)?;
validator_history_account.set_epoch_credits(&epoch_credits)?;

Ok(())
Expand Down
Loading

0 comments on commit d85e607

Please sign in to comment.