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

deprecates Signature::new in favor of Signature::{try_,}from #32481

Merged
merged 1 commit into from
Jul 14, 2023
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
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>());
t-nelson marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -338,7 +338,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 @@ -358,7 +358,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 @@ -380,7 +380,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 @@ -403,7 +403,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 @@ -442,7 +442,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 @@ -628,7 +628,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 @@ -651,7 +651,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 @@ -671,7 +671,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 @@ -702,7 +702,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 @@ -803,7 +803,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 @@ -838,7 +838,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 @@ -866,7 +866,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 @@ -895,7 +895,7 @@ mod tests {
vote_account_key,
vote,
packet_batch: PacketBatch::default(),
signature: Signature::new(&[1u8; 64]),
signature: Signature::from([1u8; 64]),
}])
.unwrap();

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

Expand All @@ -939,7 +939,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