generate deterministic seeds for shreds (#17950)
* generate shred seed from leader pubkey * clippy * clippy * review * review 2 * fmt * review * check * review * cleanup * fmt
This commit is contained in:
@ -65,15 +65,17 @@ use serde::{Deserialize, Serialize};
|
||||
use solana_measure::measure::Measure;
|
||||
use solana_perf::packet::{limited_deserialize, Packet};
|
||||
use solana_rayon_threadlimit::get_thread_count;
|
||||
use solana_runtime::bank::Bank;
|
||||
use solana_sdk::{
|
||||
clock::Slot,
|
||||
feature_set,
|
||||
hash::hashv,
|
||||
hash::Hash,
|
||||
packet::PACKET_DATA_SIZE,
|
||||
pubkey::Pubkey,
|
||||
signature::{Keypair, Signature, Signer},
|
||||
};
|
||||
use std::mem::size_of;
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
@ -467,7 +469,18 @@ impl Shred {
|
||||
self.common_header.signature
|
||||
}
|
||||
|
||||
pub fn seed(&self) -> [u8; 32] {
|
||||
pub fn seed(&self, leader_pubkey: Option<Pubkey>, root_bank: &Bank) -> [u8; 32] {
|
||||
if let Some(leader_pubkey) = leader_pubkey {
|
||||
if enable_deterministic_seed(self.slot(), root_bank) {
|
||||
let h = hashv(&[
|
||||
&self.slot().to_le_bytes(),
|
||||
&self.index().to_le_bytes(),
|
||||
&leader_pubkey.to_bytes(),
|
||||
]);
|
||||
return h.to_bytes();
|
||||
}
|
||||
}
|
||||
|
||||
let mut seed = [0; 32];
|
||||
let seed_len = seed.len();
|
||||
let sig = self.common_header.signature.as_ref();
|
||||
@ -557,6 +570,21 @@ impl Shred {
|
||||
}
|
||||
}
|
||||
|
||||
fn enable_deterministic_seed(shred_slot: Slot, bank: &Bank) -> bool {
|
||||
let feature_slot = bank
|
||||
.feature_set
|
||||
.activated_slot(&feature_set::deterministic_shred_seed_enabled::id());
|
||||
match feature_slot {
|
||||
None => false,
|
||||
Some(feature_slot) => {
|
||||
let epoch_schedule = bank.epoch_schedule();
|
||||
let feature_epoch = epoch_schedule.get_epoch(feature_slot);
|
||||
let shred_epoch = epoch_schedule.get_epoch(shred_slot);
|
||||
feature_epoch < shred_epoch
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Shredder {
|
||||
pub slot: Slot,
|
||||
|
Reference in New Issue
Block a user