Skip to content

Commit

Permalink
deprecates Signature::new in favor of Signature::{try_,}from (#32481)
Browse files Browse the repository at this point in the history
  • Loading branch information
behzadnouri authored Jul 14, 2023
1 parent 7823005 commit cfb0288
Show file tree
Hide file tree
Showing 19 changed files with 137 additions and 100 deletions.
12 changes: 6 additions & 6 deletions banking-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fn make_accounts_txs(
hash,
compute_unit_price,
);
let sig: Vec<u8> = (0..64).map(|_| thread_rng().gen::<u8>()).collect();
let sig: [u8; 64] = std::array::from_fn(|_| thread_rng().gen::<u8>());
new.message.account_keys[0] = pubkey::new_rand();
new.message.account_keys[1] = match contention {
WriteLockContention::None => pubkey::new_rand(),
Expand All @@ -148,7 +148,7 @@ fn make_accounts_txs(
}
WriteLockContention::Full => to_pubkey,
};
new.signatures = vec![Signature::new(&sig[0..64])];
new.signatures = vec![Signature::from(sig)];
new
})
.collect()
Expand Down Expand Up @@ -220,8 +220,8 @@ impl PacketsPerIteration {
fn refresh_blockhash(&mut self, new_blockhash: Hash) {
for tx in self.transactions.iter_mut() {
tx.message.recent_blockhash = new_blockhash;
let sig: Vec<u8> = (0..64).map(|_| thread_rng().gen::<u8>()).collect();
tx.signatures[0] = Signature::new(&sig[0..64]);
let sig: [u8; 64] = std::array::from_fn(|_| thread_rng().gen::<u8>());
tx.signatures[0] = Signature::from(sig);
}
self.packet_batches = to_packet_batches(&self.transactions, self.packets_per_batch);
}
Expand Down Expand Up @@ -377,8 +377,8 @@ fn main() {
genesis_config.hash(),
);
// Ignore any pesky duplicate signature errors in the case we are using single-payer
let sig: Vec<u8> = (0..64).map(|_| thread_rng().gen::<u8>()).collect();
fund.signatures = vec![Signature::new(&sig[0..64])];
let sig: [u8; 64] = std::array::from_fn(|_| thread_rng().gen::<u8>());
fund.signatures = vec![Signature::from(sig)];
bank.process_transaction(&fund).unwrap();
});
});
Expand Down
4 changes: 2 additions & 2 deletions bloom/benches/bloom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn bench_sigs_bloom(bencher: &mut Bencher) {
id = hash(id.as_ref());
sigbytes.extend(id.as_ref());

let sig = Signature::new(&sigbytes);
let sig = Signature::try_from(sigbytes).unwrap();
if sigs.contains(&sig) {
falses += 1;
}
Expand Down Expand Up @@ -89,7 +89,7 @@ fn bench_sigs_hashmap(bencher: &mut Bencher) {
id = hash(id.as_ref());
sigbytes.extend(id.as_ref());

let sig = Signature::new(&sigbytes);
let sig = Signature::try_from(sigbytes).unwrap();
if sigs.contains(&sig) {
falses += 1;
}
Expand Down
2 changes: 1 addition & 1 deletion cli-output/src/cli_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3052,7 +3052,7 @@ mod tests {
}

fn try_sign_message(&self, _message: &[u8]) -> Result<Signature, SignerError> {
Ok(Signature::new(&[1u8; 64]))
Ok(Signature::from([1u8; 64]))
}

fn is_interactive(&self) -> bool {
Expand Down
20 changes: 16 additions & 4 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1898,7 +1898,7 @@ mod tests {
);

// Test Confirm Subcommand
let signature = Signature::new(&[1; 64]);
let signature = Signature::from([1; 64]);
let signature_string = format!("{signature:?}");
let test_confirm =
test_commands
Expand Down Expand Up @@ -2053,7 +2053,11 @@ mod tests {
};
assert_eq!(process_command(&config).unwrap(), "0.00000005 SOL");

let good_signature = Signature::new(&bs58::decode(SIGNATURE).into_vec().unwrap());
let good_signature = bs58::decode(SIGNATURE)
.into_vec()
.map(Signature::try_from)
.unwrap()
.unwrap();
config.command = CliCommand::Confirm(good_signature);
assert_eq!(
process_command(&config).unwrap(),
Expand Down Expand Up @@ -2283,13 +2287,21 @@ mod tests {

// sig_not_found case
config.rpc_client = Some(Arc::new(RpcClient::new_mock("sig_not_found".to_string())));
let missing_signature = Signature::new(&bs58::decode("5VERv8NMvzbJMEkV8xnrLkEaWRtSz9CosKDYjCJjBRnbJLgp8uirBgmQpjKhoR4tjF3ZpRzrFmBV6UjKdiSZkQUW").into_vec().unwrap());
let missing_signature = bs58::decode("5VERv8NMvzbJMEkV8xnrLkEaWRtSz9CosKDYjCJjBRnbJLgp8uirBgmQpjKhoR4tjF3ZpRzrFmBV6UjKdiSZkQUW")
.into_vec()
.map(Signature::try_from)
.unwrap()
.unwrap();
config.command = CliCommand::Confirm(missing_signature);
assert_eq!(process_command(&config).unwrap(), "Not found");

// Tx error case
config.rpc_client = Some(Arc::new(RpcClient::new_mock("account_in_use".to_string())));
let any_signature = Signature::new(&bs58::decode(SIGNATURE).into_vec().unwrap());
let any_signature = bs58::decode(SIGNATURE)
.into_vec()
.map(Signature::try_from)
.unwrap()
.unwrap();
config.command = CliCommand::Confirm(any_signature);
assert_eq!(
process_command(&config).unwrap(),
Expand Down
4 changes: 2 additions & 2 deletions core/benches/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ fn make_accounts_txs(txes: usize, mint_keypair: &Keypair, hash: Hash) -> Vec<Tra
.into_par_iter()
.map(|_| {
let mut new = dummy.clone();
let sig: Vec<_> = (0..64).map(|_| thread_rng().gen::<u8>()).collect();
let sig: [u8; 64] = std::array::from_fn(|_| thread_rng().gen::<u8>());
new.message.account_keys[0] = pubkey::new_rand();
new.message.account_keys[1] = pubkey::new_rand();
new.signatures = vec![Signature::new(&sig[0..64])];
new.signatures = vec![Signature::from(sig)];
new
})
.collect()
Expand Down
30 changes: 15 additions & 15 deletions core/src/verified_vote_packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ mod tests {
vote_account_key,
vote: VoteTransaction::from(vote.clone()),
packet_batch: PacketBatch::default(),
signature: Signature::new(&[1u8; 64]),
signature: Signature::from([1u8; 64]),
}])
.unwrap();
verified_vote_packets
Expand All @@ -357,7 +357,7 @@ mod tests {
vote_account_key,
vote: VoteTransaction::from(vote),
packet_batch: PacketBatch::default(),
signature: Signature::new(&[1u8; 64]),
signature: Signature::from([1u8; 64]),
}])
.unwrap();
verified_vote_packets
Expand All @@ -379,7 +379,7 @@ mod tests {
vote_account_key,
vote: VoteTransaction::from(vote),
packet_batch: PacketBatch::default(),
signature: Signature::new(&[1u8; 64]),
signature: Signature::from([1u8; 64]),
}])
.unwrap();
verified_vote_packets
Expand All @@ -402,7 +402,7 @@ mod tests {
vote_account_key,
vote: VoteTransaction::from(vote),
packet_batch: PacketBatch::default(),
signature: Signature::new(&[2u8; 64]),
signature: Signature::from([2u8; 64]),
}])
.unwrap();
verified_vote_packets
Expand Down Expand Up @@ -441,7 +441,7 @@ mod tests {
vote_account_key,
vote: VoteTransaction::from(vote),
packet_batch: PacketBatch::default(),
signature: Signature::new(&[1u8; 64]),
signature: Signature::from([1u8; 64]),
}])
.unwrap();
}
Expand Down Expand Up @@ -627,7 +627,7 @@ mod tests {
vote_account_key,
vote: VoteTransaction::from(vote),
packet_batch: PacketBatch::default(),
signature: Signature::new(&[1u8; 64]),
signature: Signature::from([1u8; 64]),
}])
.unwrap();
}
Expand All @@ -650,7 +650,7 @@ mod tests {
vote_account_key,
vote: VoteTransaction::from(third_vote.clone()),
packet_batch: PacketBatch::default(),
signature: Signature::new(&[1u8; 64]),
signature: Signature::from([1u8; 64]),
}])
.unwrap();

Expand All @@ -670,7 +670,7 @@ mod tests {
vote_account_key,
vote: VoteTransaction::from(vote),
packet_batch: PacketBatch::default(),
signature: Signature::new(&[1u8; 64]),
signature: Signature::from([1u8; 64]),
}])
.unwrap();
}
Expand Down Expand Up @@ -701,7 +701,7 @@ mod tests {
vote_account_key,
vote: VoteTransaction::from(vote),
packet_batch: PacketBatch::default(),
signature: Signature::new(&[1u8; 64]),
signature: Signature::from([1u8; 64]),
}])
.unwrap();
verified_vote_packets
Expand Down Expand Up @@ -802,7 +802,7 @@ mod tests {
vote_account_key,
vote,
packet_batch: PacketBatch::default(),
signature: Signature::new(&[1u8; 64]),
signature: Signature::from([1u8; 64]),
}])
.unwrap();
}
Expand Down Expand Up @@ -837,7 +837,7 @@ mod tests {
vote_account_key,
vote,
packet_batch: PacketBatch::default(),
signature: Signature::new(&[1u8; 64]),
signature: Signature::from([1u8; 64]),
}])
.unwrap();
}
Expand Down Expand Up @@ -865,7 +865,7 @@ mod tests {
vote_account_key,
vote,
packet_batch: PacketBatch::default(),
signature: Signature::new(&[1u8; 64]),
signature: Signature::from([1u8; 64]),
}])
.unwrap();

Expand Down Expand Up @@ -894,7 +894,7 @@ mod tests {
vote_account_key,
vote,
packet_batch: PacketBatch::default(),
signature: Signature::new(&[1u8; 64]),
signature: Signature::from([1u8; 64]),
}])
.unwrap();

Expand All @@ -917,7 +917,7 @@ mod tests {
vote_account_key,
vote,
packet_batch: PacketBatch::default(),
signature: Signature::new(&[1u8; 64]),
signature: Signature::from([1u8; 64]),
}])
.unwrap();

Expand All @@ -938,7 +938,7 @@ mod tests {
vote_account_key,
vote,
packet_batch: PacketBatch::default(),
signature: Signature::new(&[1u8; 64]),
signature: Signature::from([1u8; 64]),
}])
.unwrap();

Expand Down
Loading

0 comments on commit cfb0288

Please sign in to comment.