block_hash => blockhash

This commit is contained in:
Michael Vines
2019-03-02 10:25:16 -08:00
committed by Greg Fitzgerald
parent 0f1582c196
commit a94880574b
55 changed files with 591 additions and 597 deletions

View File

@ -20,7 +20,7 @@ impl BudgetTransaction {
from_keypair: &Keypair,
to: Pubkey,
tokens: u64,
recent_block_hash: Hash,
recent_blockhash: Hash,
fee: u64,
) -> Transaction {
let contract = Keypair::new().pubkey();
@ -29,7 +29,7 @@ impl BudgetTransaction {
TransactionBuilder::new(fee)
.push(SystemInstruction::new_move(from, contract, tokens))
.push(Instruction::new_budget(contract, payment))
.sign(&[from_keypair], recent_block_hash)
.sign(&[from_keypair], recent_blockhash)
}
/// Create and sign a new Transaction. Used for unit-testing.
@ -38,9 +38,9 @@ impl BudgetTransaction {
from_keypair: &Keypair,
to: Pubkey,
tokens: u64,
recent_block_hash: Hash,
recent_blockhash: Hash,
) -> Transaction {
Self::new_payment(from_keypair, to, tokens, recent_block_hash, 0)
Self::new_payment(from_keypair, to, tokens, recent_blockhash, 0)
}
/// Create and sign a new Witness Timestamp. Used for unit-testing.
@ -49,7 +49,7 @@ impl BudgetTransaction {
contract: Pubkey,
to: Pubkey,
dt: DateTime<Utc>,
recent_block_hash: Hash,
recent_blockhash: Hash,
) -> Transaction {
let instruction = Instruction::ApplyTimestamp(dt);
Transaction::new(
@ -57,7 +57,7 @@ impl BudgetTransaction {
&[contract, to],
budget_program::id(),
&instruction,
recent_block_hash,
recent_blockhash,
0,
)
}
@ -67,7 +67,7 @@ impl BudgetTransaction {
from_keypair: &Keypair,
contract: Pubkey,
to: Pubkey,
recent_block_hash: Hash,
recent_blockhash: Hash,
) -> Transaction {
let instruction = Instruction::ApplySignature;
let mut keys = vec![contract];
@ -79,7 +79,7 @@ impl BudgetTransaction {
&keys,
budget_program::id(),
&instruction,
recent_block_hash,
recent_blockhash,
0,
)
}
@ -93,7 +93,7 @@ impl BudgetTransaction {
dt_pubkey: Pubkey,
cancelable: Option<Pubkey>,
tokens: u64,
recent_block_hash: Hash,
recent_blockhash: Hash,
) -> Transaction {
let expr = if let Some(from) = cancelable {
BudgetExpr::Or(
@ -118,7 +118,7 @@ impl BudgetTransaction {
&[contract],
budget_program::id(),
&instruction,
recent_block_hash,
recent_blockhash,
0,
)
}
@ -130,7 +130,7 @@ impl BudgetTransaction {
witness: Pubkey,
cancelable: Option<Pubkey>,
tokens: u64,
recent_block_hash: Hash,
recent_blockhash: Hash,
) -> Transaction {
let expr = if let Some(from) = cancelable {
BudgetExpr::Or(
@ -155,7 +155,7 @@ impl BudgetTransaction {
&[contract],
budget_program::id(),
&instruction,
recent_block_hash,
recent_blockhash,
0,
)
}

View File

@ -14,7 +14,7 @@ impl LoaderTransaction {
loader: Pubkey,
offset: u32,
bytes: Vec<u8>,
recent_block_hash: Hash,
recent_blockhash: Hash,
fee: u64,
) -> Transaction {
let instruction = LoaderInstruction::Write { offset, bytes };
@ -23,7 +23,7 @@ impl LoaderTransaction {
&[],
loader,
&instruction,
recent_block_hash,
recent_blockhash,
fee,
)
}
@ -31,7 +31,7 @@ impl LoaderTransaction {
pub fn new_finalize(
from_keypair: &Keypair,
loader: Pubkey,
recent_block_hash: Hash,
recent_blockhash: Hash,
fee: u64,
) -> Transaction {
let instruction = LoaderInstruction::Finalize;
@ -40,7 +40,7 @@ impl LoaderTransaction {
&[],
loader,
&instruction,
recent_block_hash,
recent_blockhash,
fee,
)
}

View File

@ -48,7 +48,7 @@ pub enum StorageProgram {
entry_height: u64,
signature: Signature,
},
AdvertiseStorageRecentBlockHash {
AdvertiseStorageRecentBlockhash {
hash: Hash,
entry_height: u64,
},
@ -80,7 +80,7 @@ impl StorageTransaction {
pub fn new_mining_proof(
from_keypair: &Keypair,
sha_state: Hash,
recent_block_hash: Hash,
recent_blockhash: Hash,
entry_height: u64,
signature: Signature,
) -> Transaction {
@ -89,25 +89,25 @@ impl StorageTransaction {
entry_height,
signature,
};
Transaction::new(from_keypair, &[], id(), &program, recent_block_hash, 0)
Transaction::new(from_keypair, &[], id(), &program, recent_blockhash, 0)
}
pub fn new_advertise_recent_block_hash(
pub fn new_advertise_recent_blockhash(
from_keypair: &Keypair,
storage_hash: Hash,
recent_block_hash: Hash,
recent_blockhash: Hash,
entry_height: u64,
) -> Transaction {
let program = StorageProgram::AdvertiseStorageRecentBlockHash {
let program = StorageProgram::AdvertiseStorageRecentBlockhash {
hash: storage_hash,
entry_height,
};
Transaction::new(from_keypair, &[], id(), &program, recent_block_hash, 0)
Transaction::new(from_keypair, &[], id(), &program, recent_blockhash, 0)
}
pub fn new_proof_validation(
from_keypair: &Keypair,
recent_block_hash: Hash,
recent_blockhash: Hash,
entry_height: u64,
proof_mask: Vec<ProofStatus>,
) -> Transaction {
@ -115,15 +115,15 @@ impl StorageTransaction {
entry_height,
proof_mask,
};
Transaction::new(from_keypair, &[], id(), &program, recent_block_hash, 0)
Transaction::new(from_keypair, &[], id(), &program, recent_blockhash, 0)
}
pub fn new_reward_claim(
from_keypair: &Keypair,
recent_block_hash: Hash,
recent_blockhash: Hash,
entry_height: u64,
) -> Transaction {
let program = StorageProgram::ClaimStorageReward { entry_height };
Transaction::new(from_keypair, &[], id(), &program, recent_block_hash, 0)
Transaction::new(from_keypair, &[], id(), &program, recent_blockhash, 0)
}
}

View File

@ -14,7 +14,7 @@ impl SystemTransaction {
pub fn new_program_account(
from_keypair: &Keypair,
to: Pubkey,
recent_block_hash: Hash,
recent_blockhash: Hash,
tokens: u64,
space: u64,
program_id: Pubkey,
@ -30,7 +30,7 @@ impl SystemTransaction {
&[to],
system_program::id(),
&create,
recent_block_hash,
recent_blockhash,
fee,
)
}
@ -40,14 +40,14 @@ impl SystemTransaction {
from_keypair: &Keypair,
to: Pubkey,
tokens: u64,
recent_block_hash: Hash,
recent_blockhash: Hash,
fee: u64,
) -> Transaction {
let program_id = system_program::id();
Self::new_program_account(
from_keypair,
to,
recent_block_hash,
recent_blockhash,
tokens,
0,
program_id,
@ -57,7 +57,7 @@ impl SystemTransaction {
/// Create and sign new SystemInstruction::Assign transaction
pub fn new_assign(
from_keypair: &Keypair,
recent_block_hash: Hash,
recent_blockhash: Hash,
program_id: Pubkey,
fee: u64,
) -> Transaction {
@ -67,7 +67,7 @@ impl SystemTransaction {
&[],
system_program::id(),
&assign,
recent_block_hash,
recent_blockhash,
fee,
)
}
@ -76,7 +76,7 @@ impl SystemTransaction {
from_keypair: &Keypair,
to: Pubkey,
tokens: u64,
recent_block_hash: Hash,
recent_blockhash: Hash,
fee: u64,
) -> Transaction {
let move_tokens = SystemInstruction::Move { tokens };
@ -85,7 +85,7 @@ impl SystemTransaction {
&[to],
system_program::id(),
&move_tokens,
recent_block_hash,
recent_blockhash,
fee,
)
}
@ -93,7 +93,7 @@ impl SystemTransaction {
pub fn new_move_many(
from: &Keypair,
moves: &[(Pubkey, u64)],
recent_block_hash: Hash,
recent_blockhash: Hash,
fee: u64,
) -> Transaction {
let instructions: Vec<_> = moves
@ -109,7 +109,7 @@ impl SystemTransaction {
Transaction::new_with_instructions(
&[from],
&to_keys,
recent_block_hash,
recent_blockhash,
fee,
vec![system_program::id()],
instructions,

View File

@ -11,14 +11,14 @@ pub const DEFAULT_SLOTS_PER_EPOCH: u64 = 64;
/// The time window of recent block hash values that the bank will track the signatures
/// of over. Once the bank discards a block hash, it will reject any transactions that use
/// that `recent_block_hash` in a transaction. Lowering this value reduces memory consumption,
/// but requires clients to update its `recent_block_hash` more frequently. Raising the value
/// that `recent_blockhash` in a transaction. Lowering this value reduces memory consumption,
/// but requires clients to update its `recent_blockhash` more frequently. Raising the value
/// lengthens the time a client must wait to be certain a missing transaction will
/// not be processed by the network.
pub const MAX_HASH_AGE_IN_SECONDS: usize = 120;
pub const MAX_RECENT_TICK_HASHES: usize = NUM_TICKS_PER_SECOND as usize * MAX_HASH_AGE_IN_SECONDS;
pub const MAX_RECENT_BLOCK_HASHES: usize =
pub const MAX_RECENT_BLOCKHASHES: usize =
MAX_RECENT_TICK_HASHES / (DEFAULT_TICKS_PER_SLOT as usize);
pub fn duration_as_us(d: &Duration) -> u64 {

View File

@ -79,13 +79,13 @@ impl Instruction<u8, u8> {
/// An atomic transaction
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct Transaction {
/// A set of digital signatures of `account_keys`, `program_ids`, `recent_block_hash`, `fee` and `instructions`, signed by the first
/// A set of digital signatures of `account_keys`, `program_ids`, `recent_blockhash`, `fee` and `instructions`, signed by the first
/// signatures.len() keys of account_keys
pub signatures: Vec<Signature>,
/// All the account keys used by this transaction
pub account_keys: Vec<Pubkey>,
/// The id of a recent ledger entry.
pub recent_block_hash: Hash,
pub recent_blockhash: Hash,
/// The number of tokens paid for processing and storing of this transaction.
pub fee: u64,
/// All the program id keys used to execute this transaction's instructions
@ -101,7 +101,7 @@ impl Transaction {
transaction_keys: &[Pubkey],
program_id: Pubkey,
userdata: &S,
recent_block_hash: Hash,
recent_blockhash: Hash,
fee: u64,
) -> Self {
let program_ids = vec![program_id];
@ -110,7 +110,7 @@ impl Transaction {
Self::new_with_instructions(
&[from_keypair],
transaction_keys,
recent_block_hash,
recent_blockhash,
fee,
program_ids,
instructions,
@ -121,7 +121,7 @@ impl Transaction {
transaction_keys: &[Pubkey],
program_id: Pubkey,
userdata: &T,
recent_block_hash: Hash,
recent_blockhash: Hash,
fee: u64,
) -> Self {
let program_ids = vec![program_id];
@ -132,7 +132,7 @@ impl Transaction {
Self::new_with_instructions::<Keypair>(
&[],
&keys[..],
recent_block_hash,
recent_blockhash,
fee,
program_ids,
instructions,
@ -142,14 +142,14 @@ impl Transaction {
/// * `from_keypair` - The key used to sign the transaction. This key is stored as keys[0]
/// * `account_keys` - The keys for the transaction. These are the program state
/// instances or token recipient keys.
/// * `recent_block_hash` - The PoH hash.
/// * `recent_blockhash` - The PoH hash.
/// * `fee` - The transaction fee.
/// * `program_ids` - The keys that identify programs used in the `instruction` vector.
/// * `instructions` - The programs and their arguments that the transaction will execute atomically
pub fn new_with_instructions<T: KeypairUtil>(
from_keypairs: &[&T],
keys: &[Pubkey],
recent_block_hash: Hash,
recent_blockhash: Hash,
fee: u64,
program_ids: Vec<Pubkey>,
instructions: Vec<Instruction<u8, u8>>,
@ -162,12 +162,12 @@ impl Transaction {
let mut tx = Transaction {
signatures: vec![],
account_keys,
recent_block_hash: Hash::default(),
recent_blockhash: Hash::default(),
fee,
program_ids,
instructions,
};
tx.sign(from_keypairs, recent_block_hash);
tx.sign(from_keypairs, recent_blockhash);
tx
}
pub fn userdata(&self, instruction_index: usize) -> &[u8] {
@ -205,8 +205,8 @@ impl Transaction {
let mut wr = Cursor::new(&mut buf[..]);
serialize_vec_with(&mut wr, &self.account_keys, Transaction::serialize_pubkey)
.expect("serialize account_keys");
wr.write_all(self.recent_block_hash.as_ref())
.expect("serialize recent_block_hash");
wr.write_all(self.recent_blockhash.as_ref())
.expect("serialize recent_blockhash");
wr.write_u64::<LittleEndian>(self.fee)
.expect("serialize fee");
serialize_vec_with(&mut wr, &self.program_ids, Transaction::serialize_pubkey)
@ -218,8 +218,8 @@ impl Transaction {
}
/// Sign this transaction.
pub fn sign<T: KeypairUtil>(&mut self, keypairs: &[&T], recent_block_hash: Hash) {
self.recent_block_hash = recent_block_hash;
pub fn sign<T: KeypairUtil>(&mut self, keypairs: &[&T], recent_blockhash: Hash) {
self.recent_blockhash = recent_blockhash;
let message = self.message();
self.signatures = keypairs
.iter()
@ -332,7 +332,7 @@ impl Serialize for Transaction {
.map_err(Error::custom)?;
serialize_vec_with(&mut wr, &self.account_keys, Transaction::serialize_pubkey)
.map_err(Error::custom)?;
wr.write_all(self.recent_block_hash.as_ref())
wr.write_all(self.recent_blockhash.as_ref())
.map_err(Error::custom)?;
wr.write_u64::<LittleEndian>(self.fee)
.map_err(Error::custom)?;
@ -366,7 +366,7 @@ impl<'a> serde::de::Visitor<'a> for TransactionVisitor {
.map_err(Error::custom)?;
let mut buf = [0; size_of::<Hash>()];
rd.read_exact(&mut buf).map_err(Error::custom)?;
let recent_block_hash: Hash = Hash::new(&buf);
let recent_blockhash: Hash = Hash::new(&buf);
let fee = rd.read_u64::<LittleEndian>().map_err(Error::custom)?;
let program_ids: Vec<Pubkey> =
deserialize_vec_with(&mut rd, Transaction::deserialize_pubkey)
@ -376,7 +376,7 @@ impl<'a> serde::de::Visitor<'a> for TransactionVisitor {
Ok(Transaction {
signatures,
account_keys,
recent_block_hash,
recent_blockhash,
fee,
program_ids,
instructions,

View File

@ -91,7 +91,7 @@ impl TransactionBuilder {
}
/// Return a signed transaction.
pub fn sign<T: KeypairUtil>(&self, keypairs: &[&T], recent_block_hash: Hash) -> Transaction {
pub fn sign<T: KeypairUtil>(&self, keypairs: &[&T], recent_blockhash: Hash) -> Transaction {
let program_ids = self.program_ids();
let (mut signed_keys, unsigned_keys) = self.keys();
for (i, keypair) in keypairs.iter().enumerate() {
@ -104,7 +104,7 @@ impl TransactionBuilder {
Transaction::new_with_instructions(
keypairs,
&unsigned_keys,
recent_block_hash,
recent_blockhash,
self.fee,
program_ids,
instructions,

View File

@ -16,20 +16,20 @@ impl VoteTransaction {
pub fn new_vote<T: KeypairUtil>(
voting_keypair: &T,
slot_height: u64,
recent_block_hash: Hash,
recent_blockhash: Hash,
fee: u64,
) -> Transaction {
let vote = Vote { slot_height };
TransactionBuilder::new(fee)
.push(VoteInstruction::new_vote(voting_keypair.pubkey(), vote))
.sign(&[voting_keypair], recent_block_hash)
.sign(&[voting_keypair], recent_blockhash)
}
/// Fund or create the staking account with tokens
pub fn fund_staking_account(
from_keypair: &Keypair,
vote_account_id: Pubkey,
recent_block_hash: Hash,
recent_blockhash: Hash,
num_tokens: u64,
fee: u64,
) -> Transaction {
@ -41,7 +41,7 @@ impl VoteTransaction {
Transaction::new_with_instructions(
&[from_keypair],
&[vote_account_id],
recent_block_hash,
recent_blockhash,
fee,
vec![system_program::id(), vote_program::id()],
vec![
@ -54,7 +54,7 @@ impl VoteTransaction {
/// Choose a node id to `delegate` or `assign` this vote account to
pub fn delegate_vote_account<T: KeypairUtil>(
vote_keypair: &T,
recent_block_hash: Hash,
recent_blockhash: Hash,
node_id: Pubkey,
fee: u64,
) -> Transaction {
@ -63,7 +63,7 @@ impl VoteTransaction {
vote_keypair.pubkey(),
node_id,
))
.sign(&[vote_keypair], recent_block_hash)
.sign(&[vote_keypair], recent_blockhash)
}
fn get_vote(tx: &Transaction, ix_index: usize) -> Option<(Pubkey, Vote, Hash)> {
@ -72,7 +72,7 @@ impl VoteTransaction {
}
let instruction = deserialize(&tx.userdata(ix_index)).unwrap();
if let VoteInstruction::Vote(vote) = instruction {
Some((tx.account_keys[0], vote, tx.recent_block_hash))
Some((tx.account_keys[0], vote, tx.recent_blockhash))
} else {
None
}
@ -93,11 +93,11 @@ mod tests {
fn test_get_votes() {
let keypair = Keypair::new();
let slot_height = 1;
let recent_block_hash = Hash::default();
let transaction = VoteTransaction::new_vote(&keypair, slot_height, recent_block_hash, 0);
let recent_blockhash = Hash::default();
let transaction = VoteTransaction::new_vote(&keypair, slot_height, recent_blockhash, 0);
assert_eq!(
VoteTransaction::get_votes(&transaction),
vec![(keypair.pubkey(), Vote::new(slot_height), recent_block_hash)]
vec![(keypair.pubkey(), Vote::new(slot_height), recent_blockhash)]
);
}
}