Use signer for signing transactions, not constructing them
This commit is contained in:
parent
c741a960b9
commit
85e7046caf
|
@ -370,7 +370,7 @@ pub fn fund_keys(client: &mut ThinClient, source: &Keypair, dests: &[Keypair], t
|
|||
|
||||
// re-sign retained to_fund_txes with updated last_id
|
||||
to_fund_txs.par_iter_mut().for_each(|(k, tx)| {
|
||||
tx.sign(&[k], last_id);
|
||||
tx.sign(&[*k], last_id);
|
||||
});
|
||||
|
||||
to_fund_txs.iter().for_each(|(_, tx)| {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use crate::hash::Hash;
|
||||
use crate::pubkey::Pubkey;
|
||||
use crate::signature::Keypair;
|
||||
use crate::signature::{Keypair, KeypairUtil};
|
||||
use crate::system_instruction::SystemInstruction;
|
||||
use crate::system_program;
|
||||
use crate::transaction::{Instruction, Transaction};
|
||||
|
@ -10,7 +10,12 @@ use crate::vote_program::{self, Vote, VoteInstruction};
|
|||
use bincode::deserialize;
|
||||
|
||||
pub trait VoteTransaction {
|
||||
fn vote_new(vote_account: &Pubkey, tick_height: u64, last_id: Hash, fee: u64) -> Self;
|
||||
fn vote_new<T: KeypairUtil>(
|
||||
vote_account: &T,
|
||||
tick_height: u64,
|
||||
last_id: Hash,
|
||||
fee: u64,
|
||||
) -> Self;
|
||||
fn vote_account_new(
|
||||
validator_id: &Keypair,
|
||||
vote_account_id: Pubkey,
|
||||
|
@ -23,10 +28,15 @@ pub trait VoteTransaction {
|
|||
}
|
||||
|
||||
impl VoteTransaction for Transaction {
|
||||
fn vote_new(vote_account: &Pubkey, tick_height: u64, last_id: Hash, fee: u64) -> Self {
|
||||
fn vote_new<T: KeypairUtil>(
|
||||
vote_account: &T,
|
||||
tick_height: u64,
|
||||
last_id: Hash,
|
||||
fee: u64,
|
||||
) -> Self {
|
||||
let vote = Vote { tick_height };
|
||||
let instruction = VoteInstruction::NewVote(vote);
|
||||
Transaction::new_unsigned(
|
||||
Transaction::new(
|
||||
vote_account,
|
||||
&[],
|
||||
vote_program::id(),
|
||||
|
|
|
@ -165,6 +165,8 @@ pub mod tests {
|
|||
use bincode::serialize;
|
||||
use solana_sdk::hash::hash;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_sdk::transaction::Transaction;
|
||||
use solana_sdk::vote_transaction::VoteTransaction;
|
||||
use std::sync::Arc;
|
||||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
|
@ -204,7 +206,7 @@ pub mod tests {
|
|||
.expect("Expected successful creation of account");
|
||||
|
||||
if i < 6 {
|
||||
let vote_tx = vote_signer.new_signed_vote_transaction(&last_id, (i + 1) as u64);
|
||||
let vote_tx = Transaction::vote_new(&vote_signer, (i + 1) as u64, last_id, 0);
|
||||
bank.process_transaction(&vote_tx).unwrap();
|
||||
}
|
||||
(vote_signer, validator_keypair)
|
||||
|
@ -222,7 +224,7 @@ pub mod tests {
|
|||
|
||||
// Get another validator to vote, so we now have 2/3 consensus
|
||||
let vote_signer = &vote_accounts[7].0;
|
||||
let vote_tx = vote_signer.new_signed_vote_transaction(&ids[6], 7);
|
||||
let vote_tx = Transaction::vote_new(vote_signer, 7, ids[6], 0);
|
||||
bank.process_transaction(&vote_tx).unwrap();
|
||||
|
||||
ComputeLeaderConfirmationService::compute_confirmation(
|
||||
|
|
22
src/entry.rs
22
src/entry.rs
|
@ -607,16 +607,7 @@ mod tests {
|
|||
let one = hash(&zero.as_ref());
|
||||
let keypair = Keypair::new();
|
||||
let vote_account = Keypair::new();
|
||||
let tx = Transaction::vote_new(&vote_account.pubkey(), 1, one, 1);
|
||||
let sig = vote_account.sign_message(&tx.message());
|
||||
let tx0 = Transaction {
|
||||
signatures: vec![sig],
|
||||
account_keys: tx.account_keys,
|
||||
last_id: tx.last_id,
|
||||
fee: tx.fee,
|
||||
program_ids: tx.program_ids,
|
||||
instructions: tx.instructions,
|
||||
};
|
||||
let tx0 = Transaction::vote_new(&vote_account, 1, one, 1);
|
||||
let tx1 = Transaction::budget_new_timestamp(
|
||||
&keypair,
|
||||
keypair.pubkey(),
|
||||
|
@ -664,16 +655,7 @@ mod tests {
|
|||
let next_id = hash(&id.as_ref());
|
||||
let keypair = Keypair::new();
|
||||
let vote_account = Keypair::new();
|
||||
let tx = Transaction::vote_new(&vote_account.pubkey(), 1, next_id, 2);
|
||||
let sig = vote_account.sign_message(&tx.message());
|
||||
let tx_small = Transaction {
|
||||
signatures: vec![sig],
|
||||
account_keys: tx.account_keys,
|
||||
last_id: tx.last_id,
|
||||
fee: tx.fee,
|
||||
program_ids: tx.program_ids,
|
||||
instructions: tx.instructions,
|
||||
};
|
||||
let tx_small = Transaction::vote_new(&vote_account, 1, next_id, 2);
|
||||
let tx_large = Transaction::budget_new(&keypair, keypair.pubkey(), 1, next_id);
|
||||
|
||||
let tx_small_size = tx_small.serialized_size().unwrap() as usize;
|
||||
|
|
|
@ -499,16 +499,7 @@ pub fn make_active_set_entries(
|
|||
last_entry_id = new_vote_account_entry.id;
|
||||
|
||||
// 3) Create vote entry
|
||||
let tx = Transaction::vote_new(&vote_account_id, 1, *last_tick_id, 0);
|
||||
let sig = active_keypair.sign_message(&tx.message());
|
||||
let vote_tx = Transaction {
|
||||
signatures: vec![sig],
|
||||
account_keys: tx.account_keys,
|
||||
last_id: tx.last_id,
|
||||
fee: tx.fee,
|
||||
program_ids: tx.program_ids,
|
||||
instructions: tx.instructions,
|
||||
};
|
||||
let vote_tx = Transaction::vote_new(&vote_signer, 1, *last_tick_id, 0);
|
||||
let vote_entry = Entry::new(&last_entry_id, 0, 1, vec![vote_tx]);
|
||||
last_entry_id = vote_entry.id;
|
||||
|
||||
|
@ -521,6 +512,7 @@ pub fn make_active_set_entries(
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::bank::Bank;
|
||||
use crate::genesis_block::GenesisBlock;
|
||||
use crate::leader_scheduler::{
|
||||
|
@ -544,8 +536,7 @@ mod tests {
|
|||
}
|
||||
|
||||
fn push_vote(vote_signer: &VoteSignerProxy, bank: &Bank, height: u64, last_id: Hash) {
|
||||
let new_vote_tx = vote_signer.new_signed_vote_transaction(&last_id, height);
|
||||
|
||||
let new_vote_tx = Transaction::vote_new(vote_signer, height, last_id, 0);
|
||||
bank.process_transaction(&new_vote_tx).unwrap();
|
||||
}
|
||||
|
||||
|
|
|
@ -604,16 +604,7 @@ mod tests {
|
|||
}
|
||||
let mut vote_txs: Vec<Transaction> = Vec::new();
|
||||
let keypair = Keypair::new();
|
||||
let tx = Transaction::vote_new(&keypair.pubkey(), 123456, Hash::default(), 1);
|
||||
let sig = keypair.sign_message(&tx.message());
|
||||
let vote_tx = Transaction {
|
||||
signatures: vec![sig],
|
||||
account_keys: tx.account_keys,
|
||||
last_id: tx.last_id,
|
||||
fee: tx.fee,
|
||||
program_ids: tx.program_ids,
|
||||
instructions: tx.instructions,
|
||||
};
|
||||
let vote_tx = Transaction::vote_new(&keypair, 123456, Hash::default(), 1);
|
||||
vote_txs.push(vote_tx);
|
||||
let vote_entries = vec![Entry::new(&Hash::default(), 0, 1, vote_txs)];
|
||||
storage_entry_sender.send(vote_entries).unwrap();
|
||||
|
|
|
@ -148,7 +148,7 @@ impl VoteSignerProxy {
|
|||
);
|
||||
}
|
||||
|
||||
let tx = self.new_signed_vote_transaction(&bank.last_id(), bank.tick_height());
|
||||
let tx = Transaction::vote_new(self, bank.tick_height(), bank.last_id(), 0);
|
||||
|
||||
match VoteSignerProxy::get_leader_tpu(&bank, cluster_info) {
|
||||
Ok(tpu) => {
|
||||
|
@ -174,14 +174,6 @@ impl VoteSignerProxy {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn new_signed_vote_transaction(&self, last_id: &Hash, tick_height: u64) -> Transaction {
|
||||
let mut tx = Transaction::vote_new(&self.vote_account, tick_height, *last_id, 0);
|
||||
assert!(tx.signatures.is_empty());
|
||||
let sig = self.sign_message(&tx.message());
|
||||
tx.signatures.push(sig);
|
||||
tx
|
||||
}
|
||||
|
||||
fn new_signed_vote_blob(&self, tx: &Transaction, leader_tpu: SocketAddr) -> Result<SharedBlob> {
|
||||
let shared_blob = SharedBlob::default();
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue