Skip to content

Commit

Permalink
Emit scoring details and instant unstake details in V2 events (#81)
Browse files Browse the repository at this point in the history
Updates scoring and instant unstake functions with several improvements:
* Events now contain a "details" field which, for each given component
that fails or is triggered, will now track the specific epoch and value
that contained the violation, and will be emitted.
* Will be shown in UI to improve validators' ability to diagnose scoring
failures
* Both response structs are now updated to a V2 since adding new fields
without changing the name would break the ability to backfill the event
from genesis, as the event discriminator is based on the name, and
fields changing mid-history is a very annoying thing to code in. Old
structs are stored and noted
* Each individual component and the associated values are now calculated
in their own helper methods which greatly improves readability.
* In a future PR we can add tests for these helper functions, which will
allow us to really simplify the unit tests for these functions
in`test_algorithms.rs`
* All score functionality remains the same as confirmed by tests
  • Loading branch information
ebatsell authored Sep 12, 2024
1 parent 4ec761c commit 57f2656
Show file tree
Hide file tree
Showing 6 changed files with 1,021 additions and 249 deletions.
271 changes: 271 additions & 0 deletions programs/steward/idl/steward.json
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,19 @@
77
]
},
{
"name": "InstantUnstakeComponentsV2",
"discriminator": [
138,
62,
181,
14,
9,
48,
109,
47
]
},
{
"name": "RebalanceEvent",
"discriminator": [
Expand All @@ -1650,6 +1663,19 @@
251
]
},
{
"name": "ScoreComponentsV2",
"discriminator": [
140,
182,
108,
49,
246,
38,
247,
181
]
},
{
"name": "StateTransition",
"discriminator": [
Expand Down Expand Up @@ -2319,6 +2345,47 @@
},
{
"name": "InstantUnstakeComponents",
"docs": [
"Deprecated: This struct is no longer emitted but is kept to allow parsing of old events.",
"Because the event discriminator is based on struct name, it's important to rename the struct if",
"fields are changed."
],
"type": {
"kind": "struct",
"fields": [
{
"name": "instant_unstake",
"type": "bool"
},
{
"name": "delinquency_check",
"type": "bool"
},
{
"name": "commission_check",
"type": "bool"
},
{
"name": "mev_commission_check",
"type": "bool"
},
{
"name": "is_blacklisted",
"type": "bool"
},
{
"name": "vote_account",
"type": "pubkey"
},
{
"name": "epoch",
"type": "u16"
}
]
}
},
{
"name": "InstantUnstakeComponentsV2",
"type": {
"kind": "struct",
"fields": [
Expand Down Expand Up @@ -2364,6 +2431,67 @@
{
"name": "epoch",
"type": "u16"
},
{
"name": "details",
"docs": [
"Details about why a given check was calculated"
],
"type": {
"defined": {
"name": "InstantUnstakeDetails"
}
}
}
]
}
},
{
"name": "InstantUnstakeDetails",
"type": {
"kind": "struct",
"fields": [
{
"name": "epoch_credits_latest",
"docs": [
"Latest epoch credits"
],
"type": "u64"
},
{
"name": "vote_account_last_update_slot",
"docs": [
"Latest vote account update slot"
],
"type": "u64"
},
{
"name": "total_blocks_latest",
"docs": [
"Latest total blocks"
],
"type": "u32"
},
{
"name": "cluster_history_slot_index",
"docs": [
"Cluster history slot index"
],
"type": "u64"
},
{
"name": "commission",
"docs": [
"Commission value"
],
"type": "u8"
},
{
"name": "mev_commission",
"docs": [
"MEV commission value"
],
"type": "u16"
}
]
}
Expand Down Expand Up @@ -2621,6 +2749,67 @@
},
{
"name": "ScoreComponents",
"docs": [
"Deprecated: This struct is no longer emitted but is kept to allow parsing of old events.",
"Because the event discriminator is based on struct name, it's important to rename the struct if",
"fields are changed."
],
"type": {
"kind": "struct",
"fields": [
{
"name": "score",
"type": "f64"
},
{
"name": "yield_score",
"type": "f64"
},
{
"name": "mev_commission_score",
"type": "f64"
},
{
"name": "blacklisted_score",
"type": "f64"
},
{
"name": "superminority_score",
"type": "f64"
},
{
"name": "delinquency_score",
"type": "f64"
},
{
"name": "running_jito_score",
"type": "f64"
},
{
"name": "commission_score",
"type": "f64"
},
{
"name": "historical_commission_score",
"type": "f64"
},
{
"name": "vote_credits_ratio",
"type": "f64"
},
{
"name": "vote_account",
"type": "pubkey"
},
{
"name": "epoch",
"type": "u16"
}
]
}
},
{
"name": "ScoreComponentsV2",
"type": {
"kind": "struct",
"fields": [
Expand Down Expand Up @@ -2702,6 +2891,88 @@
{
"name": "epoch",
"type": "u16"
},
{
"name": "details",
"docs": [
"Details about why a given score was calculated"
],
"type": {
"defined": {
"name": "ScoreDetails"
}
}
}
]
}
},
{
"name": "ScoreDetails",
"type": {
"kind": "struct",
"fields": [
{
"name": "max_mev_commission",
"docs": [
"Max MEV commission observed"
],
"type": "u16"
},
{
"name": "max_mev_commission_epoch",
"docs": [
"Epoch of max MEV commission"
],
"type": "u16"
},
{
"name": "superminority_epoch",
"docs": [
"Epoch when superminority was detected"
],
"type": "u16"
},
{
"name": "delinquency_ratio",
"docs": [
"Ratio that failed delinquency check"
],
"type": "f64"
},
{
"name": "delinquency_epoch",
"docs": [
"Epoch when delinquency was detected"
],
"type": "u16"
},
{
"name": "max_commission",
"docs": [
"Max commission observed"
],
"type": "u8"
},
{
"name": "max_commission_epoch",
"docs": [
"Epoch of max commission"
],
"type": "u16"
},
{
"name": "max_historical_commission",
"docs": [
"Max historical commission observed"
],
"type": "u8"
},
{
"name": "max_historical_commission_epoch",
"docs": [
"Epoch of max historical commission"
],
"type": "u16"
}
]
}
Expand Down
1 change: 1 addition & 0 deletions programs/steward/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub const BASIS_POINTS_MAX: u16 = 10_000;
pub const COMMISSION_MAX: u8 = 100;
pub const SORTED_INDEX_DEFAULT: u16 = u16::MAX;
pub const LAMPORT_BALANCE_DEFAULT: u64 = u64::MAX;
pub const EPOCH_DEFAULT: u16 = u16::MAX;
// Need at least 1% of slots remaining (4320 slots) to execute steps in state machine
pub const EPOCH_PROGRESS_MAX: f64 = 0.99;
// Cannot go more than 100 epochs without scoring
Expand Down
35 changes: 35 additions & 0 deletions programs/steward/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,38 @@ impl IdlBuild for RebalanceTypeTag {
})
}
}

/// Deprecated: This struct is no longer emitted but is kept to allow parsing of old events.
/// Because the event discriminator is based on struct name, it's important to rename the struct if
/// fields are changed.
#[event]
#[derive(Debug, PartialEq)]
pub struct ScoreComponents {
pub score: f64,
pub yield_score: f64,
pub mev_commission_score: f64,
pub blacklisted_score: f64,
pub superminority_score: f64,
pub delinquency_score: f64,
pub running_jito_score: f64,
pub commission_score: f64,
pub historical_commission_score: f64,
pub vote_credits_ratio: f64,
pub vote_account: Pubkey,
pub epoch: u16,
}

/// Deprecated: This struct is no longer emitted but is kept to allow parsing of old events.
/// Because the event discriminator is based on struct name, it's important to rename the struct if
/// fields are changed.
#[event]
#[derive(Debug, PartialEq, Eq)]
pub struct InstantUnstakeComponents {
pub instant_unstake: bool,
pub delinquency_check: bool,
pub commission_check: bool,
pub mev_commission_check: bool,
pub is_blacklisted: bool,
pub vote_account: Pubkey,
pub epoch: u16,
}
Loading

0 comments on commit 57f2656

Please sign in to comment.