Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace solana_sdk::pubkey with solana_pubkey in ledger #4235

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 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 ledger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ solana-measure = { workspace = true }
solana-metrics = { workspace = true }
solana-perf = { workspace = true }
solana-program-runtime = { workspace = true, features = ["metrics"] }
solana-pubkey = { workspace = true }
solana-rayon-threadlimit = { workspace = true }
solana-runtime = { workspace = true }
solana-runtime-transaction = { workspace = true }
Expand Down
3 changes: 1 addition & 2 deletions ledger/benches/protobuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ use {
bincode::{deserialize, serialize},
prost::Message,
solana_runtime::bank::RewardType,
solana_sdk::pubkey,
solana_transaction_status::{Reward, Rewards},
test::Bencher,
};

fn create_rewards() -> Rewards {
(0..100)
.map(|i| Reward {
pubkey: pubkey::new_rand().to_string(),
pubkey: solana_pubkey::new_rand().to_string(),
lamports: 42 + i,
post_balance: u64::MAX,
reward_type: Some(RewardType::Fee),
Expand Down
30 changes: 15 additions & 15 deletions ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5488,9 +5488,9 @@ pub mod tests {
for x in 0..num_entries {
let transaction = Transaction::new_with_compiled_instructions(
&[&Keypair::new()],
&[solana_sdk::pubkey::new_rand()],
&[solana_pubkey::new_rand()],
Hash::default(),
vec![solana_sdk::pubkey::new_rand()],
vec![solana_pubkey::new_rand()],
vec![CompiledInstruction::new(1, &(), vec![0])],
);
entries.push(next_entry_mut(&mut Hash::default(), 0, vec![transaction]));
Expand Down Expand Up @@ -9112,8 +9112,8 @@ pub mod tests {
.put_protobuf((signature2, lowest_available_slot), &status)
.unwrap();

let address0 = solana_sdk::pubkey::new_rand();
let address1 = solana_sdk::pubkey::new_rand();
let address0 = solana_pubkey::new_rand();
let address1 = solana_pubkey::new_rand();
blockstore
.write_transaction_status(
lowest_cleanup_slot,
Expand Down Expand Up @@ -9485,8 +9485,8 @@ pub mod tests {
let ledger_path = get_tmp_ledger_path_auto_delete!();
let blockstore = Blockstore::open(ledger_path.path()).unwrap();

let address0 = solana_sdk::pubkey::new_rand();
let address1 = solana_sdk::pubkey::new_rand();
let address0 = solana_pubkey::new_rand();
let address1 = solana_pubkey::new_rand();

let slot1 = 1;
for x in 1..5 {
Expand Down Expand Up @@ -9581,7 +9581,7 @@ pub mod tests {
&[&Keypair::new()],
&[*address],
Hash::default(),
vec![solana_sdk::pubkey::new_rand()],
vec![solana_pubkey::new_rand()],
vec![CompiledInstruction::new(1, &(), vec![0])],
);
entries.push(next_entry_mut(&mut Hash::default(), 0, vec![transaction]));
Expand All @@ -9591,8 +9591,8 @@ pub mod tests {
entries
}

let address0 = solana_sdk::pubkey::new_rand();
let address1 = solana_sdk::pubkey::new_rand();
let address0 = solana_pubkey::new_rand();
let address1 = solana_pubkey::new_rand();

for slot in 2..=8 {
let entries = make_slot_entries_with_transaction_addresses(&[
Expand Down Expand Up @@ -10051,9 +10051,9 @@ pub mod tests {
for x in 0..4 {
let transaction = Transaction::new_with_compiled_instructions(
&[&Keypair::new()],
&[solana_sdk::pubkey::new_rand()],
&[solana_pubkey::new_rand()],
Hash::default(),
vec![solana_sdk::pubkey::new_rand()],
vec![solana_pubkey::new_rand()],
vec![CompiledInstruction::new(1, &(), vec![0])],
);
let status = TransactionStatusMeta {
Expand Down Expand Up @@ -10092,9 +10092,9 @@ pub mod tests {
transactions.push(
Transaction::new_with_compiled_instructions(
&[&Keypair::new()],
&[solana_sdk::pubkey::new_rand()],
&[solana_pubkey::new_rand()],
Hash::default(),
vec![solana_sdk::pubkey::new_rand()],
vec![solana_pubkey::new_rand()],
vec![CompiledInstruction::new(1, &(), vec![0])],
)
.into(),
Expand Down Expand Up @@ -10779,7 +10779,7 @@ pub mod tests {

let rewards: Rewards = (0..100)
.map(|i| Reward {
pubkey: solana_sdk::pubkey::new_rand().to_string(),
pubkey: solana_pubkey::new_rand().to_string(),
lamports: 42 + i,
post_balance: u64::MAX,
reward_type: Some(RewardType::Fee),
Expand Down Expand Up @@ -10900,7 +10900,7 @@ pub mod tests {
let txs: Vec<_> = (0..num_txs)
.map(|_| {
let keypair0 = Keypair::new();
let to = solana_sdk::pubkey::new_rand();
let to = solana_pubkey::new_rand();
solana_sdk::system_transaction::transfer(&keypair0, &to, 1, Hash::default())
})
.collect();
Expand Down
28 changes: 14 additions & 14 deletions ledger/src/blockstore_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3106,7 +3106,7 @@ pub mod tests {
#[test]
fn test_process_ledger_simple() {
solana_logger::setup();
let leader_pubkey = solana_sdk::pubkey::new_rand();
let leader_pubkey = solana_pubkey::new_rand();
let mint = 100;
let hashes_per_tick = 10;
let GenesisConfigInfo {
Expand Down Expand Up @@ -3783,7 +3783,7 @@ pub mod tests {
bank.last_blockhash(),
1,
0,
&solana_sdk::pubkey::new_rand(),
&solana_pubkey::new_rand(),
));

next_entry_mut(&mut hash, 0, transactions)
Expand Down Expand Up @@ -3942,7 +3942,7 @@ pub mod tests {
let (bank, _bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config);

// Make sure instruction errors still update the signature cache
let pubkey = solana_sdk::pubkey::new_rand();
let pubkey = solana_pubkey::new_rand();
bank.transfer(1_000, &mint_keypair, &pubkey).unwrap();
assert_eq!(bank.transaction_count(), 1);
assert_eq!(bank.get_balance(&pubkey), 1_000);
Expand Down Expand Up @@ -4244,7 +4244,7 @@ pub mod tests {
bank.last_blockhash(),
100,
100,
&solana_sdk::pubkey::new_rand(),
&solana_pubkey::new_rand(),
));
transactions
})
Expand Down Expand Up @@ -4371,14 +4371,14 @@ pub mod tests {
// Create array of two transactions which throw different errors
let account_not_found_tx = system_transaction::transfer(
&keypair,
&solana_sdk::pubkey::new_rand(),
&solana_pubkey::new_rand(),
42,
bank.last_blockhash(),
);
let account_not_found_sig = account_not_found_tx.signatures[0];
let invalid_blockhash_tx = system_transaction::transfer(
&mint_keypair,
&solana_sdk::pubkey::new_rand(),
&solana_pubkey::new_rand(),
42,
Hash::default(),
);
Expand Down Expand Up @@ -4418,7 +4418,7 @@ pub mod tests {
.unwrap()
.insert(Bank::new_from_parent(
bank0.clone(),
&solana_sdk::pubkey::new_rand(),
&solana_pubkey::new_rand(),
1,
))
.clone_without_scheduler();
Expand Down Expand Up @@ -4719,7 +4719,7 @@ pub mod tests {
let versioned = VoteStateVersions::new_current(vote_state);
VoteState::serialize(&versioned, vote_account.data_as_mut_slice()).unwrap();
(
solana_sdk::pubkey::new_rand(),
solana_pubkey::new_rand(),
(stake, VoteAccount::try_from(vote_account).unwrap()),
)
})
Expand Down Expand Up @@ -4780,11 +4780,11 @@ pub mod tests {
mint_keypair: &Keypair,
genesis_hash: &Hash,
) -> Vec<RuntimeTransaction<SanitizedTransaction>> {
let pubkey = solana_sdk::pubkey::new_rand();
let pubkey = solana_pubkey::new_rand();
let keypair2 = Keypair::new();
let pubkey2 = solana_sdk::pubkey::new_rand();
let pubkey2 = solana_pubkey::new_rand();
let keypair3 = Keypair::new();
let pubkey3 = solana_sdk::pubkey::new_rand();
let pubkey3 = solana_pubkey::new_rand();

vec![
RuntimeTransaction::from_transaction_for_tests(system_transaction::transfer(
Expand Down Expand Up @@ -4926,7 +4926,7 @@ pub mod tests {

#[test]
fn test_rebatch_transactions() {
let dummy_leader_pubkey = solana_sdk::pubkey::new_rand();
let dummy_leader_pubkey = solana_pubkey::new_rand();
let GenesisConfigInfo {
genesis_config,
mint_keypair,
Expand All @@ -4950,7 +4950,7 @@ pub mod tests {

fn do_test_schedule_batches_for_execution(should_succeed: bool) {
solana_logger::setup();
let dummy_leader_pubkey = solana_sdk::pubkey::new_rand();
let dummy_leader_pubkey = solana_pubkey::new_rand();
let GenesisConfigInfo {
genesis_config,
mint_keypair,
Expand Down Expand Up @@ -5165,7 +5165,7 @@ pub mod tests {

#[test]
fn test_check_block_cost_limit() {
let dummy_leader_pubkey = solana_sdk::pubkey::new_rand();
let dummy_leader_pubkey = solana_pubkey::new_rand();
let GenesisConfigInfo {
genesis_config,
mint_keypair,
Expand Down
18 changes: 9 additions & 9 deletions ledger/src/leader_schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use {
itertools::Itertools,
rand::distributions::{Distribution, WeightedIndex},
rand_chacha::{rand_core::SeedableRng, ChaChaRng},
solana_sdk::pubkey::Pubkey,
solana_pubkey::Pubkey,
Copy link

@steviez steviez Jan 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can make this substitution on a bunch more files in solana_ledger. Looks like:

  • benches/blockstore.rs
  • src/blockstore.rs
    • This file looks to have a redundant import in the test module as well
  • src/blockstore_db.rs
  • src/blockstore_processor.rs
    • Redundant import in test module as well
  • src/genesis_utils.rs
  • src/leader_schedule.rs
    • Already done per the highlighted line in the diff
  • src/leader_schedule_cache.rs
  • src/leader_schedule_utils.rs
  • src/shred.rs
  • src/shredder.rs
  • src/sigverify_shreds.rs
  • src/staking_utils.rs
  • src/token_balances.rs
  • src/transaction_address_lookup_table_scanner.rs
  • src/shred/merkle.rs

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's do this in a separate PR?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm somewhat inclined to include it in this same PR. The PR title states "replace solana_sdk::pubkey with solana_pubkey in ledger", and without these changes, that is not fully accomplished. The diff should still be pretty small with these changes. Finally, if we were to do those changes in a separate PR, then I'd argue we should revert this line in src/leader_schedule.rs for the sake of consistency across the crate.

That being said, I don't want to punish a good deed. So, if you're opposed to tagging the change onto this PR, I'd probably still be fine pushing the PR.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah by that PR title I meant sed -i 's/solana_sdk::pubkey/solana_pubkey/g'

std::{collections::HashMap, convert::identity, ops::Index, sync::Arc},
};

Expand Down Expand Up @@ -103,8 +103,8 @@ mod tests {

#[test]
fn test_leader_schedule_index() {
let pubkey0 = solana_sdk::pubkey::new_rand();
let pubkey1 = solana_sdk::pubkey::new_rand();
let pubkey0 = solana_pubkey::new_rand();
let pubkey1 = solana_pubkey::new_rand();
let leader_schedule = LeaderSchedule::new_from_schedule(vec![pubkey0, pubkey1]);
assert_eq!(leader_schedule[0], pubkey0);
assert_eq!(leader_schedule[1], pubkey1);
Expand All @@ -115,10 +115,10 @@ mod tests {
fn test_leader_schedule_basic() {
let num_keys = 10;
let stakes: Vec<_> = (0..num_keys)
.map(|i| (solana_sdk::pubkey::new_rand(), i))
.map(|i| (solana_pubkey::new_rand(), i))
.collect();

let seed = solana_sdk::pubkey::new_rand();
let seed = solana_pubkey::new_rand();
let mut seed_bytes = [0u8; 32];
seed_bytes.copy_from_slice(seed.as_ref());
let len = num_keys * 10;
Expand All @@ -133,10 +133,10 @@ mod tests {
fn test_repeated_leader_schedule() {
let num_keys = 10;
let stakes: Vec<_> = (0..num_keys)
.map(|i| (solana_sdk::pubkey::new_rand(), i))
.map(|i| (solana_pubkey::new_rand(), i))
.collect();

let seed = solana_sdk::pubkey::new_rand();
let seed = solana_pubkey::new_rand();
let mut seed_bytes = [0u8; 32];
seed_bytes.copy_from_slice(seed.as_ref());
let len = num_keys * 10;
Expand All @@ -155,8 +155,8 @@ mod tests {

#[test]
fn test_repeated_leader_schedule_specific() {
let alice_pubkey = solana_sdk::pubkey::new_rand();
let bob_pubkey = solana_sdk::pubkey::new_rand();
let alice_pubkey = solana_pubkey::new_rand();
let bob_pubkey = solana_pubkey::new_rand();
let stakes = vec![(alice_pubkey, 2), (bob_pubkey, 1)];

let seed = Pubkey::default();
Expand Down
10 changes: 5 additions & 5 deletions ledger/src/leader_schedule_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ mod tests {

#[test]
fn test_next_leader_slot() {
let pubkey = solana_sdk::pubkey::new_rand();
let pubkey = solana_pubkey::new_rand();
let mut genesis_config =
create_genesis_config_with_leader(42, &pubkey, bootstrap_validator_stake_lamports())
.genesis_config;
Expand Down Expand Up @@ -409,7 +409,7 @@ mod tests {

assert_eq!(
cache.next_leader_slot(
&solana_sdk::pubkey::new_rand(), // not in leader_schedule
&solana_pubkey::new_rand(), // not in leader_schedule
0,
&bank,
None,
Expand All @@ -421,7 +421,7 @@ mod tests {

#[test]
fn test_next_leader_slot_blockstore() {
let pubkey = solana_sdk::pubkey::new_rand();
let pubkey = solana_pubkey::new_rand();
let mut genesis_config =
create_genesis_config_with_leader(42, &pubkey, bootstrap_validator_stake_lamports())
.genesis_config;
Expand Down Expand Up @@ -486,7 +486,7 @@ mod tests {

assert_eq!(
cache.next_leader_slot(
&solana_sdk::pubkey::new_rand(), // not in leader_schedule
&solana_pubkey::new_rand(), // not in leader_schedule
0,
&bank,
Some(&blockstore),
Expand Down Expand Up @@ -593,7 +593,7 @@ mod tests {
assert_eq!(bank.get_epoch_and_slot_index(96).0, 2);
assert!(cache.slot_leader_at(96, Some(&bank)).is_none());

let bank2 = Bank::new_from_parent(bank, &solana_sdk::pubkey::new_rand(), 95);
let bank2 = Bank::new_from_parent(bank, &solana_pubkey::new_rand(), 95);
assert!(bank2.epoch_vote_accounts(2).is_some());

// Set root for a slot in epoch 1, so that epoch 2 is now confirmed
Expand Down
14 changes: 7 additions & 7 deletions ledger/src/leader_schedule_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ mod tests {

#[test]
fn test_leader_schedule_via_bank() {
let pubkey = solana_sdk::pubkey::new_rand();
let pubkey = solana_pubkey::new_rand();
let genesis_config =
create_genesis_config_with_leader(0, &pubkey, bootstrap_validator_stake_lamports())
.genesis_config;
Expand All @@ -118,7 +118,7 @@ mod tests {

#[test]
fn test_leader_scheduler1_basic() {
let pubkey = solana_sdk::pubkey::new_rand();
let pubkey = solana_pubkey::new_rand();
let genesis_config =
create_genesis_config_with_leader(42, &pubkey, bootstrap_validator_stake_lamports())
.genesis_config;
Expand All @@ -128,17 +128,17 @@ mod tests {

#[test]
fn test_sort_stakes_basic() {
let pubkey0 = solana_sdk::pubkey::new_rand();
let pubkey1 = solana_sdk::pubkey::new_rand();
let pubkey0 = solana_pubkey::new_rand();
let pubkey1 = solana_pubkey::new_rand();
let mut stakes = vec![(pubkey0, 1), (pubkey1, 2)];
sort_stakes(&mut stakes);
assert_eq!(stakes, vec![(pubkey1, 2), (pubkey0, 1)]);
}

#[test]
fn test_sort_stakes_with_dup() {
let pubkey0 = solana_sdk::pubkey::new_rand();
let pubkey1 = solana_sdk::pubkey::new_rand();
let pubkey0 = solana_pubkey::new_rand();
let pubkey1 = solana_pubkey::new_rand();
let mut stakes = vec![(pubkey0, 1), (pubkey1, 2), (pubkey0, 1)];
sort_stakes(&mut stakes);
assert_eq!(stakes, vec![(pubkey1, 2), (pubkey0, 1)]);
Expand All @@ -147,7 +147,7 @@ mod tests {
#[test]
fn test_sort_stakes_with_equal_stakes() {
let pubkey0 = Pubkey::default();
let pubkey1 = solana_sdk::pubkey::new_rand();
let pubkey1 = solana_pubkey::new_rand();
let mut stakes = vec![(pubkey0, 1), (pubkey1, 1)];
sort_stakes(&mut stakes);
assert_eq!(stakes, vec![(pubkey1, 1), (pubkey0, 1)]);
Expand Down
Loading
Loading