Skip to content

Commit

Permalink
add hash_rewards_into_partitions (solana-labs#31795)
Browse files Browse the repository at this point in the history
* add sort_and_shuffle_partitioned_rewards

* break stake accounts into partitions by hashing

* fmt

* Update runtime/src/epoch_rewards_hasher.rs

Co-authored-by: Trent Nelson <[email protected]>

* Update runtime/src/bank/tests.rs

Co-authored-by: Trent Nelson <[email protected]>

* Update runtime/src/bank/tests.rs

Co-authored-by: Trent Nelson <[email protected]>

* Update runtime/src/bank.rs

Co-authored-by: Trent Nelson <[email protected]>

* fix build

* more build fixes

* use spihasher13 for reward partition

* update comments

* revert calc reward struct change to avoid abi changes for now

* cippy

* sort deps

* saturating math

* use copy traits on hasher
use parent block hash to seed rewards partition

* fmt

* use concurrent map to speed up reward partition

* clippy

* Update runtime/src/epoch_rewards_hasher.rs

Co-authored-by: Trent Nelson <[email protected]>

* Update runtime/Cargo.toml

Co-authored-by: Trent Nelson <[email protected]>

* Update runtime/src/bank.rs

Co-authored-by: Trent Nelson <[email protected]>

* rename

* address review comments

* cargo.lock

* Update runtime/src/bank.rs

Co-authored-by: Trent Nelson <[email protected]>

* update test

* clippy

* comments

* move hash_address_to_partition to epoch_rewards_hasher.rs

* tests to nail down width of partitions

* rename parameter to match with comments

* hash_address takes &self

* clippy

* EpochRewardHasher -> EpochRewardsHasher

* revert "hash_address takes &self" and refactor

* stake_rewards takes by value

---------

Co-authored-by: HaoranYi <[email protected]>
Co-authored-by: Trent Nelson <[email protected]>
Co-authored-by: HaoranYi <[email protected]>
  • Loading branch information
4 people authored Jun 9, 2023
1 parent 14e90cb commit 4ebec90
Show file tree
Hide file tree
Showing 8 changed files with 341 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ serde_with = { version = "2.3.3", default-features = false }
sha2 = "0.10.6"
sha3 = "0.10.4"
signal-hook = "0.3.15"
siphasher = "0.3.10"
smpl_jwt = "0.7.1"
socket2 = "0.4.9"
soketto = "0.7"
Expand Down
7 changes: 7 additions & 0 deletions programs/sbf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ rayon = { workspace = true }
regex = { workspace = true }
serde = { workspace = true, features = ["rc"] }
serde_derive = { workspace = true }
siphasher = { workspace = true }
solana-address-lookup-table-program = { workspace = true }
solana-bpf-loader-program = { workspace = true }
solana-bucket-map = { workspace = true }
Expand Down
6 changes: 6 additions & 0 deletions runtime/src/bank/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub(crate) struct RewardsMetrics {
pub(crate) invalid_cached_stake_accounts: usize,
pub(crate) invalid_cached_stake_accounts_rent_epoch: usize,
pub(crate) vote_accounts_cache_miss_count: usize,
pub(crate) hash_partition_rewards_us: u64,
}

pub(crate) struct NewBankTimings {
Expand Down Expand Up @@ -115,6 +116,11 @@ pub(crate) fn report_new_epoch_metrics(
metrics.vote_accounts_cache_miss_count,
i64
),
(
"hash_partition_rewards_us",
metrics.hash_partition_rewards_us,
i64
),
);
}

Expand Down
40 changes: 40 additions & 0 deletions runtime/src/bank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,46 @@ use {
test_case::test_case,
};

impl StakeReward {
pub fn new_random() -> Self {
let mut rng = rand::thread_rng();

let rent = Rent::free();

let validator_pubkey = solana_sdk::pubkey::new_rand();
let validator_stake_lamports = 20;
let validator_staking_keypair = Keypair::new();
let validator_voting_keypair = Keypair::new();

let validator_vote_account = vote_state::create_account(
&validator_voting_keypair.pubkey(),
&validator_pubkey,
10,
validator_stake_lamports,
);

let validator_stake_account = stake_state::create_account(
&validator_staking_keypair.pubkey(),
&validator_voting_keypair.pubkey(),
&validator_vote_account,
&rent,
validator_stake_lamports,
);

Self {
stake_pubkey: Pubkey::new_unique(),
stake_reward_info: RewardInfo {
reward_type: RewardType::Staking,
lamports: rng.gen_range(1, 200),
post_balance: 0, /* unused atm */
commission: None, /* unused atm */
},

stake_account: validator_stake_account,
}
}
}

#[test]
fn test_race_register_tick_freeze() {
solana_logger::setup();
Expand Down
Loading

0 comments on commit 4ebec90

Please sign in to comment.