Purge remaining last_id (now called block_hash)
This commit is contained in:
parent
2bfad87a5f
commit
258cf21416
|
@ -100,7 +100,7 @@ pub fn sample_tx_count(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send loopback payment of 0 tokens and confirm the network processed it
|
/// Send loopback payment of 0 tokens and confirm the network processed it
|
||||||
pub fn send_barrier_transaction(barrier_client: &mut ThinClient, last_id: &mut Hash, id: &Keypair) {
|
pub fn send_barrier_transaction(barrier_client: &mut ThinClient, block_hash: &mut Hash, id: &Keypair) {
|
||||||
let transfer_start = Instant::now();
|
let transfer_start = Instant::now();
|
||||||
|
|
||||||
let mut poll_count = 0;
|
let mut poll_count = 0;
|
||||||
|
@ -112,9 +112,9 @@ pub fn send_barrier_transaction(barrier_client: &mut ThinClient, last_id: &mut H
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
*last_id = barrier_client.get_recent_block_hash();
|
*block_hash = barrier_client.get_recent_block_hash();
|
||||||
let signature = barrier_client
|
let signature = barrier_client
|
||||||
.transfer(0, &id, id.pubkey(), last_id)
|
.transfer(0, &id, id.pubkey(), block_hash)
|
||||||
.expect("Unable to send barrier transaction");
|
.expect("Unable to send barrier transaction");
|
||||||
|
|
||||||
let confirmatiom = barrier_client.poll_for_signature(&signature);
|
let confirmatiom = barrier_client.poll_for_signature(&signature);
|
||||||
|
@ -154,13 +154,13 @@ pub fn send_barrier_transaction(barrier_client: &mut ThinClient, last_id: &mut H
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_last_id = barrier_client.get_recent_block_hash();
|
let new_block_hash = barrier_client.get_recent_block_hash();
|
||||||
if new_last_id == *last_id {
|
if new_block_hash == *block_hash {
|
||||||
if poll_count > 0 && poll_count % 8 == 0 {
|
if poll_count > 0 && poll_count % 8 == 0 {
|
||||||
println!("last_id is not advancing, still at {:?}", *last_id);
|
println!("block_hash is not advancing, still at {:?}", *block_hash);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
*last_id = new_last_id;
|
*block_hash = new_block_hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
poll_count += 1;
|
poll_count += 1;
|
||||||
|
@ -176,7 +176,7 @@ pub fn generate_txs(
|
||||||
leader: &NodeInfo,
|
leader: &NodeInfo,
|
||||||
) {
|
) {
|
||||||
let mut client = mk_client(leader);
|
let mut client = mk_client(leader);
|
||||||
let last_id = client.get_recent_block_hash();
|
let block_hash = client.get_recent_block_hash();
|
||||||
let tx_count = source.len();
|
let tx_count = source.len();
|
||||||
println!("Signing transactions... {} (reclaim={})", tx_count, reclaim);
|
println!("Signing transactions... {} (reclaim={})", tx_count, reclaim);
|
||||||
let signing_start = Instant::now();
|
let signing_start = Instant::now();
|
||||||
|
@ -190,7 +190,7 @@ pub fn generate_txs(
|
||||||
.par_iter()
|
.par_iter()
|
||||||
.map(|(id, keypair)| {
|
.map(|(id, keypair)| {
|
||||||
(
|
(
|
||||||
SystemTransaction::new_account(id, keypair.pubkey(), 1, last_id, 0),
|
SystemTransaction::new_account(id, keypair.pubkey(), 1, block_hash, 0),
|
||||||
timestamp(),
|
timestamp(),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -205,7 +205,7 @@ pub fn generate_txs(
|
||||||
bsps * 1_000_000_f64,
|
bsps * 1_000_000_f64,
|
||||||
nsps / 1_000_f64,
|
nsps / 1_000_f64,
|
||||||
duration_as_ms(&duration),
|
duration_as_ms(&duration),
|
||||||
last_id,
|
block_hash,
|
||||||
);
|
);
|
||||||
solana_metrics::submit(
|
solana_metrics::submit(
|
||||||
influxdb::Point::new("bench-tps")
|
influxdb::Point::new("bench-tps")
|
||||||
|
@ -328,7 +328,7 @@ pub fn fund_keys(client: &mut ThinClient, source: &Keypair, dests: &[Keypair], t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to transfer a "few" at a time with recent last_id
|
// try to transfer a "few" at a time with recent block_hash
|
||||||
// assume 4MB network buffers, and 512 byte packets
|
// assume 4MB network buffers, and 512 byte packets
|
||||||
const FUND_CHUNK_LEN: usize = 4 * 1024 * 1024 / 512;
|
const FUND_CHUNK_LEN: usize = 4 * 1024 * 1024 / 512;
|
||||||
|
|
||||||
|
@ -366,11 +366,11 @@ pub fn fund_keys(client: &mut ThinClient, source: &Keypair, dests: &[Keypair], t
|
||||||
to_fund_txs.len(),
|
to_fund_txs.len(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let last_id = client.get_recent_block_hash();
|
let block_hash = client.get_recent_block_hash();
|
||||||
|
|
||||||
// re-sign retained to_fund_txes with updated last_id
|
// re-sign retained to_fund_txes with updated block_hash
|
||||||
to_fund_txs.par_iter_mut().for_each(|(k, tx)| {
|
to_fund_txs.par_iter_mut().for_each(|(k, tx)| {
|
||||||
tx.sign(&[*k], last_id);
|
tx.sign(&[*k], block_hash);
|
||||||
});
|
});
|
||||||
|
|
||||||
to_fund_txs.iter().for_each(|(_, tx)| {
|
to_fund_txs.iter().for_each(|(_, tx)| {
|
||||||
|
@ -410,8 +410,8 @@ pub fn airdrop_tokens(
|
||||||
id.pubkey(),
|
id.pubkey(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let last_id = client.get_recent_block_hash();
|
let block_hash = client.get_recent_block_hash();
|
||||||
match request_airdrop_transaction(&drone_addr, &id.pubkey(), airdrop_amount, last_id) {
|
match request_airdrop_transaction(&drone_addr, &id.pubkey(), airdrop_amount, block_hash) {
|
||||||
Ok(transaction) => {
|
Ok(transaction) => {
|
||||||
let signature = client.transfer_signed(&transaction).unwrap();
|
let signature = client.transfer_signed(&transaction).unwrap();
|
||||||
client.poll_for_signature(&signature).unwrap();
|
client.poll_for_signature(&signature).unwrap();
|
||||||
|
|
|
@ -170,8 +170,8 @@ fn main() {
|
||||||
airdrop_tokens(&mut barrier_client, &drone_addr, &barrier_id, 1);
|
airdrop_tokens(&mut barrier_client, &drone_addr, &barrier_id, 1);
|
||||||
|
|
||||||
println!("Get last ID...");
|
println!("Get last ID...");
|
||||||
let mut last_id = client.get_recent_block_hash();
|
let mut block_hash = client.get_recent_block_hash();
|
||||||
println!("Got last ID {:?}", last_id);
|
println!("Got last ID {:?}", block_hash);
|
||||||
|
|
||||||
let first_tx_count = client.transaction_count();
|
let first_tx_count = client.transaction_count();
|
||||||
println!("Initial transaction count {}", first_tx_count);
|
println!("Initial transaction count {}", first_tx_count);
|
||||||
|
@ -254,7 +254,7 @@ fn main() {
|
||||||
// It's not feasible (would take too much time) to confirm each of the `tx_count / 2`
|
// It's not feasible (would take too much time) to confirm each of the `tx_count / 2`
|
||||||
// transactions sent by `generate_txs()` so instead send and confirm a single transaction
|
// transactions sent by `generate_txs()` so instead send and confirm a single transaction
|
||||||
// to validate the network is still functional.
|
// to validate the network is still functional.
|
||||||
send_barrier_transaction(&mut barrier_client, &mut last_id, &barrier_id);
|
send_barrier_transaction(&mut barrier_client, &mut block_hash, &barrier_id);
|
||||||
|
|
||||||
i += 1;
|
i += 1;
|
||||||
if should_switch_directions(num_tokens_per_account, i) {
|
if should_switch_directions(num_tokens_per_account, i) {
|
||||||
|
|
|
@ -66,7 +66,7 @@ impl BankingStage {
|
||||||
|
|
||||||
// Single thread to generate entries from many banks.
|
// Single thread to generate entries from many banks.
|
||||||
// This thread talks to poh_service and broadcasts the entries once they have been recorded.
|
// This thread talks to poh_service and broadcasts the entries once they have been recorded.
|
||||||
// Once an entry has been recorded, its last_id is registered with the bank.
|
// Once an entry has been recorded, its block_hash is registered with the bank.
|
||||||
let exit = Arc::new(AtomicBool::new(false));
|
let exit = Arc::new(AtomicBool::new(false));
|
||||||
|
|
||||||
// Single thread to compute confirmation
|
// Single thread to compute confirmation
|
||||||
|
@ -464,11 +464,11 @@ mod tests {
|
||||||
|
|
||||||
assert!(entries.len() >= 1);
|
assert!(entries.len() >= 1);
|
||||||
|
|
||||||
let mut last_id = start_hash;
|
let mut block_hash = start_hash;
|
||||||
entries.iter().for_each(|entries| {
|
entries.iter().for_each(|entries| {
|
||||||
assert_eq!(entries.len(), 1);
|
assert_eq!(entries.len(), 1);
|
||||||
assert!(entries.verify(&last_id));
|
assert!(entries.verify(&block_hash));
|
||||||
last_id = entries.last().unwrap().hash;
|
block_hash = entries.last().unwrap().hash;
|
||||||
});
|
});
|
||||||
drop(entry_receiver);
|
drop(entry_receiver);
|
||||||
banking_stage.join().unwrap();
|
banking_stage.join().unwrap();
|
||||||
|
|
|
@ -71,7 +71,7 @@ pub trait BlockstreamEvents {
|
||||||
slot: u64,
|
slot: u64,
|
||||||
tick_height: u64,
|
tick_height: u64,
|
||||||
leader_id: Pubkey,
|
leader_id: Pubkey,
|
||||||
last_id: Hash,
|
block_hash: Hash,
|
||||||
) -> Result<()>;
|
) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ where
|
||||||
slot: u64,
|
slot: u64,
|
||||||
tick_height: u64,
|
tick_height: u64,
|
||||||
leader_id: Pubkey,
|
leader_id: Pubkey,
|
||||||
last_id: Hash,
|
block_hash: Hash,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let payload = format!(
|
let payload = format!(
|
||||||
r#"{{"dt":"{}","t":"block","s":{},"h":{},"l":"{:?}","id":"{:?}"}}"#,
|
r#"{{"dt":"{}","t":"block","s":{},"h":{},"l":"{:?}","id":"{:?}"}}"#,
|
||||||
|
@ -117,7 +117,7 @@ where
|
||||||
slot,
|
slot,
|
||||||
tick_height,
|
tick_height,
|
||||||
leader_id,
|
leader_id,
|
||||||
last_id,
|
block_hash,
|
||||||
);
|
);
|
||||||
self.output.write(payload)?;
|
self.output.write(payload)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -163,7 +163,7 @@ mod test {
|
||||||
let blockstream = MockBlockstream::new("test_stream".to_string());
|
let blockstream = MockBlockstream::new("test_stream".to_string());
|
||||||
let ticks_per_slot = 5;
|
let ticks_per_slot = 5;
|
||||||
|
|
||||||
let mut last_id = Hash::default();
|
let mut block_hash = Hash::default();
|
||||||
let mut entries = Vec::new();
|
let mut entries = Vec::new();
|
||||||
let mut expected_entries = Vec::new();
|
let mut expected_entries = Vec::new();
|
||||||
|
|
||||||
|
@ -175,12 +175,12 @@ mod test {
|
||||||
for tick_height in tick_height_initial..=tick_height_final {
|
for tick_height in tick_height_initial..=tick_height_final {
|
||||||
if tick_height == 5 {
|
if tick_height == 5 {
|
||||||
blockstream
|
blockstream
|
||||||
.emit_block_event(curr_slot, tick_height - 1, leader_id, last_id)
|
.emit_block_event(curr_slot, tick_height - 1, leader_id, block_hash)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
curr_slot += 1;
|
curr_slot += 1;
|
||||||
}
|
}
|
||||||
let entry = Entry::new(&mut last_id, 1, vec![]); // just ticks
|
let entry = Entry::new(&mut block_hash, 1, vec![]); // just ticks
|
||||||
last_id = entry.hash;
|
block_hash = entry.hash;
|
||||||
blockstream
|
blockstream
|
||||||
.emit_entry_event(curr_slot, tick_height, leader_id, &entry)
|
.emit_entry_event(curr_slot, tick_height, leader_id, &entry)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -125,7 +125,7 @@ mod test {
|
||||||
let (mut genesis_block, _mint_keypair) = GenesisBlock::new(1000);
|
let (mut genesis_block, _mint_keypair) = GenesisBlock::new(1000);
|
||||||
genesis_block.ticks_per_slot = ticks_per_slot;
|
genesis_block.ticks_per_slot = ticks_per_slot;
|
||||||
|
|
||||||
let (ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
let (ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block);
|
||||||
let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap();
|
let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap();
|
||||||
|
|
||||||
// Set up blockstream
|
// Set up blockstream
|
||||||
|
@ -138,12 +138,12 @@ mod test {
|
||||||
let mut entries = create_ticks(4, Hash::default());
|
let mut entries = create_ticks(4, Hash::default());
|
||||||
|
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let mut last_id = entries[3].hash;
|
let mut block_hash = entries[3].hash;
|
||||||
let tx = SystemTransaction::new_account(&keypair, keypair.pubkey(), 1, Hash::default(), 0);
|
let tx = SystemTransaction::new_account(&keypair, keypair.pubkey(), 1, Hash::default(), 0);
|
||||||
let entry = Entry::new(&mut last_id, 1, vec![tx]);
|
let entry = Entry::new(&mut block_hash, 1, vec![tx]);
|
||||||
last_id = entry.hash;
|
block_hash = entry.hash;
|
||||||
entries.push(entry);
|
entries.push(entry);
|
||||||
let final_tick = create_ticks(1, last_id);
|
let final_tick = create_ticks(1, block_hash);
|
||||||
entries.extend_from_slice(&final_tick);
|
entries.extend_from_slice(&final_tick);
|
||||||
|
|
||||||
let expected_entries = entries.clone();
|
let expected_entries = entries.clone();
|
||||||
|
|
|
@ -689,7 +689,7 @@ impl Blocktree {
|
||||||
db_iterator.seek_to_first();
|
db_iterator.seek_to_first();
|
||||||
Ok(EntryIterator {
|
Ok(EntryIterator {
|
||||||
db_iterator,
|
db_iterator,
|
||||||
last_id: None,
|
block_hash: None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1250,7 +1250,7 @@ struct EntryIterator {
|
||||||
// TODO: remove me when replay_stage is iterating by block (Blocktree)
|
// TODO: remove me when replay_stage is iterating by block (Blocktree)
|
||||||
// this verification is duplicating that of replay_stage, which
|
// this verification is duplicating that of replay_stage, which
|
||||||
// can do this in parallel
|
// can do this in parallel
|
||||||
last_id: Option<Hash>,
|
block_hash: Option<Hash>,
|
||||||
// https://github.com/rust-rocksdb/rust-rocksdb/issues/234
|
// https://github.com/rust-rocksdb/rust-rocksdb/issues/234
|
||||||
// rocksdb issue: the _blocktree member must be lower in the struct to prevent a crash
|
// rocksdb issue: the _blocktree member must be lower in the struct to prevent a crash
|
||||||
// when the db_iterator member above is dropped.
|
// when the db_iterator member above is dropped.
|
||||||
|
@ -1267,13 +1267,13 @@ impl Iterator for EntryIterator {
|
||||||
if self.db_iterator.valid() {
|
if self.db_iterator.valid() {
|
||||||
if let Some(value) = self.db_iterator.value() {
|
if let Some(value) = self.db_iterator.value() {
|
||||||
if let Ok(entry) = deserialize::<Entry>(&value[BLOB_HEADER_SIZE..]) {
|
if let Ok(entry) = deserialize::<Entry>(&value[BLOB_HEADER_SIZE..]) {
|
||||||
if let Some(last_id) = self.last_id {
|
if let Some(block_hash) = self.block_hash {
|
||||||
if !entry.verify(&last_id) {
|
if !entry.verify(&block_hash) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.db_iterator.next();
|
self.db_iterator.next();
|
||||||
self.last_id = Some(entry.hash);
|
self.block_hash = Some(entry.hash);
|
||||||
return Some(entry);
|
return Some(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1284,7 +1284,7 @@ impl Iterator for EntryIterator {
|
||||||
|
|
||||||
// Creates a new ledger with slot 0 full of ticks (and only ticks).
|
// Creates a new ledger with slot 0 full of ticks (and only ticks).
|
||||||
//
|
//
|
||||||
// Returns the last_id that can be used to append entries with.
|
// Returns the block_hash that can be used to append entries with.
|
||||||
pub fn create_new_ledger(ledger_path: &str, genesis_block: &GenesisBlock) -> Result<Hash> {
|
pub fn create_new_ledger(ledger_path: &str, genesis_block: &GenesisBlock) -> Result<Hash> {
|
||||||
let ticks_per_slot = genesis_block.ticks_per_slot;
|
let ticks_per_slot = genesis_block.ticks_per_slot;
|
||||||
Blocktree::destroy(ledger_path)?;
|
Blocktree::destroy(ledger_path)?;
|
||||||
|
@ -1362,8 +1362,8 @@ macro_rules! create_new_tmp_ledger {
|
||||||
// ticks)
|
// ticks)
|
||||||
pub fn create_new_tmp_ledger(name: &str, genesis_block: &GenesisBlock) -> (String, Hash) {
|
pub fn create_new_tmp_ledger(name: &str, genesis_block: &GenesisBlock) -> (String, Hash) {
|
||||||
let ledger_path = get_tmp_ledger_path(name);
|
let ledger_path = get_tmp_ledger_path(name);
|
||||||
let last_id = create_new_ledger(&ledger_path, genesis_block).unwrap();
|
let block_hash = create_new_ledger(&ledger_path, genesis_block).unwrap();
|
||||||
(ledger_path, last_id)
|
(ledger_path, block_hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
|
|
@ -286,7 +286,7 @@ mod tests {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Create a new ledger with slot 0 full of ticks
|
// Create a new ledger with slot 0 full of ticks
|
||||||
let (ledger_path, mut last_id) = create_new_tmp_ledger!(&genesis_block);
|
let (ledger_path, mut block_hash) = create_new_tmp_ledger!(&genesis_block);
|
||||||
debug!("ledger_path: {:?}", ledger_path);
|
debug!("ledger_path: {:?}", ledger_path);
|
||||||
|
|
||||||
let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot)
|
let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot)
|
||||||
|
@ -297,8 +297,8 @@ mod tests {
|
||||||
{
|
{
|
||||||
let parent_slot = 0;
|
let parent_slot = 0;
|
||||||
let slot = 1;
|
let slot = 1;
|
||||||
let mut entries = create_ticks(ticks_per_slot, last_id);
|
let mut entries = create_ticks(ticks_per_slot, block_hash);
|
||||||
last_id = entries.last().unwrap().hash;
|
block_hash = entries.last().unwrap().hash;
|
||||||
|
|
||||||
entries.pop();
|
entries.pop();
|
||||||
|
|
||||||
|
@ -307,7 +307,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
// slot 2, points at slot 1
|
// slot 2, points at slot 1
|
||||||
fill_blocktree_slot_with_ticks(&blocktree, ticks_per_slot, 2, 1, last_id);
|
fill_blocktree_slot_with_ticks(&blocktree, ticks_per_slot, 2, 1, block_hash);
|
||||||
|
|
||||||
let (mut _bank_forks, bank_forks_info) =
|
let (mut _bank_forks, bank_forks_info) =
|
||||||
process_blocktree(&genesis_block, &blocktree, None).unwrap();
|
process_blocktree(&genesis_block, &blocktree, None).unwrap();
|
||||||
|
@ -330,9 +330,9 @@ mod tests {
|
||||||
let ticks_per_slot = genesis_block.ticks_per_slot;
|
let ticks_per_slot = genesis_block.ticks_per_slot;
|
||||||
|
|
||||||
// Create a new ledger with slot 0 full of ticks
|
// Create a new ledger with slot 0 full of ticks
|
||||||
let (ledger_path, last_id) = create_new_tmp_ledger!(&genesis_block);
|
let (ledger_path, block_hash) = create_new_tmp_ledger!(&genesis_block);
|
||||||
debug!("ledger_path: {:?}", ledger_path);
|
debug!("ledger_path: {:?}", ledger_path);
|
||||||
let mut last_entry_hash = last_id;
|
let mut last_entry_hash = block_hash;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Build a blocktree in the ledger with the following fork structure:
|
Build a blocktree in the ledger with the following fork structure:
|
||||||
|
@ -460,11 +460,11 @@ mod tests {
|
||||||
debug!("ledger_path: {:?}", ledger_path);
|
debug!("ledger_path: {:?}", ledger_path);
|
||||||
|
|
||||||
let mut entries = vec![];
|
let mut entries = vec![];
|
||||||
let last_id = genesis_block.hash();
|
let block_hash = genesis_block.hash();
|
||||||
for _ in 0..3 {
|
for _ in 0..3 {
|
||||||
// Transfer one token from the mint to a random account
|
// Transfer one token from the mint to a random account
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let tx = SystemTransaction::new_account(&mint_keypair, keypair.pubkey(), 1, last_id, 0);
|
let tx = SystemTransaction::new_account(&mint_keypair, keypair.pubkey(), 1, block_hash, 0);
|
||||||
let entry = Entry::new(&last_entry_hash, 1, vec![tx]);
|
let entry = Entry::new(&last_entry_hash, 1, vec![tx]);
|
||||||
last_entry_hash = entry.hash;
|
last_entry_hash = entry.hash;
|
||||||
entries.push(entry);
|
entries.push(entry);
|
||||||
|
@ -472,7 +472,7 @@ mod tests {
|
||||||
// Add a second Transaction that will produce a
|
// Add a second Transaction that will produce a
|
||||||
// ProgramError<0, ResultWithNegativeTokens> error when processed
|
// ProgramError<0, ResultWithNegativeTokens> error when processed
|
||||||
let keypair2 = Keypair::new();
|
let keypair2 = Keypair::new();
|
||||||
let tx = SystemTransaction::new_account(&keypair, keypair2.pubkey(), 42, last_id, 0);
|
let tx = SystemTransaction::new_account(&keypair, keypair2.pubkey(), 42, block_hash, 0);
|
||||||
let entry = Entry::new(&last_entry_hash, 1, vec![tx]);
|
let entry = Entry::new(&last_entry_hash, 1, vec![tx]);
|
||||||
last_entry_hash = entry.hash;
|
last_entry_hash = entry.hash;
|
||||||
entries.push(entry);
|
entries.push(entry);
|
||||||
|
@ -507,7 +507,7 @@ mod tests {
|
||||||
fn test_process_ledger_with_one_tick_per_slot() {
|
fn test_process_ledger_with_one_tick_per_slot() {
|
||||||
let (mut genesis_block, _mint_keypair) = GenesisBlock::new(123);
|
let (mut genesis_block, _mint_keypair) = GenesisBlock::new(123);
|
||||||
genesis_block.ticks_per_slot = 1;
|
genesis_block.ticks_per_slot = 1;
|
||||||
let (ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
let (ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block);
|
||||||
|
|
||||||
let blocktree = Blocktree::open(&ledger_path).unwrap();
|
let blocktree = Blocktree::open(&ledger_path).unwrap();
|
||||||
let (bank_forks, bank_forks_info) =
|
let (bank_forks, bank_forks_info) =
|
||||||
|
@ -544,19 +544,19 @@ mod tests {
|
||||||
let keypair1 = Keypair::new();
|
let keypair1 = Keypair::new();
|
||||||
let keypair2 = Keypair::new();
|
let keypair2 = Keypair::new();
|
||||||
|
|
||||||
let last_id = bank.last_block_hash();
|
let block_hash = bank.last_block_hash();
|
||||||
|
|
||||||
// ensure bank can process 2 entries that have a common account and no tick is registered
|
// ensure bank can process 2 entries that have a common account and no tick is registered
|
||||||
let tx =
|
let tx =
|
||||||
SystemTransaction::new_account(&mint_keypair, keypair1.pubkey(), 2, bank.last_block_hash(), 0);
|
SystemTransaction::new_account(&mint_keypair, keypair1.pubkey(), 2, bank.last_block_hash(), 0);
|
||||||
let entry_1 = next_entry(&last_id, 1, vec![tx]);
|
let entry_1 = next_entry(&block_hash, 1, vec![tx]);
|
||||||
let tx =
|
let tx =
|
||||||
SystemTransaction::new_account(&mint_keypair, keypair2.pubkey(), 2, bank.last_block_hash(), 0);
|
SystemTransaction::new_account(&mint_keypair, keypair2.pubkey(), 2, bank.last_block_hash(), 0);
|
||||||
let entry_2 = next_entry(&entry_1.hash, 1, vec![tx]);
|
let entry_2 = next_entry(&entry_1.hash, 1, vec![tx]);
|
||||||
assert_eq!(par_process_entries(&bank, &[entry_1, entry_2]), Ok(()));
|
assert_eq!(par_process_entries(&bank, &[entry_1, entry_2]), Ok(()));
|
||||||
assert_eq!(bank.get_balance(&keypair1.pubkey()), 2);
|
assert_eq!(bank.get_balance(&keypair1.pubkey()), 2);
|
||||||
assert_eq!(bank.get_balance(&keypair2.pubkey()), 2);
|
assert_eq!(bank.get_balance(&keypair2.pubkey()), 2);
|
||||||
assert_eq!(bank.last_block_hash(), last_id);
|
assert_eq!(bank.last_block_hash(), block_hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -633,15 +633,15 @@ mod tests {
|
||||||
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
||||||
|
|
||||||
// ensure bank can process 2 entries that do not have a common account and no tick is registered
|
// ensure bank can process 2 entries that do not have a common account and no tick is registered
|
||||||
let last_id = bank.last_block_hash();
|
let block_hash = bank.last_block_hash();
|
||||||
let tx = SystemTransaction::new_account(&keypair1, keypair3.pubkey(), 1, bank.last_block_hash(), 0);
|
let tx = SystemTransaction::new_account(&keypair1, keypair3.pubkey(), 1, bank.last_block_hash(), 0);
|
||||||
let entry_1 = next_entry(&last_id, 1, vec![tx]);
|
let entry_1 = next_entry(&block_hash, 1, vec![tx]);
|
||||||
let tx = SystemTransaction::new_account(&keypair2, keypair4.pubkey(), 1, bank.last_block_hash(), 0);
|
let tx = SystemTransaction::new_account(&keypair2, keypair4.pubkey(), 1, bank.last_block_hash(), 0);
|
||||||
let entry_2 = next_entry(&entry_1.hash, 1, vec![tx]);
|
let entry_2 = next_entry(&entry_1.hash, 1, vec![tx]);
|
||||||
assert_eq!(par_process_entries(&bank, &[entry_1, entry_2]), Ok(()));
|
assert_eq!(par_process_entries(&bank, &[entry_1, entry_2]), Ok(()));
|
||||||
assert_eq!(bank.get_balance(&keypair3.pubkey()), 1);
|
assert_eq!(bank.get_balance(&keypair3.pubkey()), 1);
|
||||||
assert_eq!(bank.get_balance(&keypair4.pubkey()), 1);
|
assert_eq!(bank.get_balance(&keypair4.pubkey()), 1);
|
||||||
assert_eq!(bank.last_block_hash(), last_id);
|
assert_eq!(bank.last_block_hash(), block_hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -661,14 +661,14 @@ mod tests {
|
||||||
SystemTransaction::new_account(&mint_keypair, keypair2.pubkey(), 1, bank.last_block_hash(), 0);
|
SystemTransaction::new_account(&mint_keypair, keypair2.pubkey(), 1, bank.last_block_hash(), 0);
|
||||||
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
||||||
|
|
||||||
let last_id = bank.last_block_hash();
|
let block_hash = bank.last_block_hash();
|
||||||
while last_id == bank.last_block_hash() {
|
while block_hash == bank.last_block_hash() {
|
||||||
bank.register_tick(&Hash::default());
|
bank.register_tick(&Hash::default());
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure bank can process 2 entries that do not have a common account and tick is registered
|
// ensure bank can process 2 entries that do not have a common account and tick is registered
|
||||||
let tx = SystemTransaction::new_account(&keypair2, keypair3.pubkey(), 1, last_id, 0);
|
let tx = SystemTransaction::new_account(&keypair2, keypair3.pubkey(), 1, block_hash, 0);
|
||||||
let entry_1 = next_entry(&last_id, 1, vec![tx]);
|
let entry_1 = next_entry(&block_hash, 1, vec![tx]);
|
||||||
let tick = next_entry(&entry_1.hash, 1, vec![]);
|
let tick = next_entry(&entry_1.hash, 1, vec![]);
|
||||||
let tx = SystemTransaction::new_account(&keypair1, keypair4.pubkey(), 1, bank.last_block_hash(), 0);
|
let tx = SystemTransaction::new_account(&keypair1, keypair4.pubkey(), 1, bank.last_block_hash(), 0);
|
||||||
let entry_2 = next_entry(&tick.hash, 1, vec![tx]);
|
let entry_2 = next_entry(&tick.hash, 1, vec![tx]);
|
||||||
|
|
|
@ -331,12 +331,12 @@ impl Fullnode {
|
||||||
//instead of here
|
//instead of here
|
||||||
info!(
|
info!(
|
||||||
"reset PoH... {} {}",
|
"reset PoH... {} {}",
|
||||||
rotation_info.tick_height, rotation_info.last_id
|
rotation_info.tick_height, rotation_info.block_hash
|
||||||
);
|
);
|
||||||
self.poh_recorder
|
self.poh_recorder
|
||||||
.lock()
|
.lock()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.reset(rotation_info.tick_height, rotation_info.last_id);
|
.reset(rotation_info.tick_height, rotation_info.block_hash);
|
||||||
let slot = rotation_info.slot;
|
let slot = rotation_info.slot;
|
||||||
self.rotate(rotation_info);
|
self.rotate(rotation_info);
|
||||||
debug!("role transition complete");
|
debug!("role transition complete");
|
||||||
|
@ -437,13 +437,13 @@ pub fn make_active_set_entries(
|
||||||
token_source: &Keypair,
|
token_source: &Keypair,
|
||||||
stake: u64,
|
stake: u64,
|
||||||
slot_height_to_vote_on: u64,
|
slot_height_to_vote_on: u64,
|
||||||
last_id: &Hash,
|
block_hash: &Hash,
|
||||||
num_ending_ticks: u64,
|
num_ending_ticks: u64,
|
||||||
) -> (Vec<Entry>, VotingKeypair) {
|
) -> (Vec<Entry>, VotingKeypair) {
|
||||||
// 1) Assume the active_keypair node has no tokens staked
|
// 1) Assume the active_keypair node has no tokens staked
|
||||||
let transfer_tx =
|
let transfer_tx =
|
||||||
SystemTransaction::new_account(&token_source, active_keypair.pubkey(), stake, *last_id, 0);
|
SystemTransaction::new_account(&token_source, active_keypair.pubkey(), stake, *block_hash, 0);
|
||||||
let mut last_entry_hash = *last_id;
|
let mut last_entry_hash = *block_hash;
|
||||||
let transfer_entry = next_entry_mut(&mut last_entry_hash, 1, vec![transfer_tx]);
|
let transfer_entry = next_entry_mut(&mut last_entry_hash, 1, vec![transfer_tx]);
|
||||||
|
|
||||||
// 2) Create and register a vote account for active_keypair
|
// 2) Create and register a vote account for active_keypair
|
||||||
|
@ -451,11 +451,11 @@ pub fn make_active_set_entries(
|
||||||
let vote_account_id = voting_keypair.pubkey();
|
let vote_account_id = voting_keypair.pubkey();
|
||||||
|
|
||||||
let new_vote_account_tx =
|
let new_vote_account_tx =
|
||||||
VoteTransaction::fund_staking_account(active_keypair, vote_account_id, *last_id, 1, 1);
|
VoteTransaction::fund_staking_account(active_keypair, vote_account_id, *block_hash, 1, 1);
|
||||||
let new_vote_account_entry = next_entry_mut(&mut last_entry_hash, 1, vec![new_vote_account_tx]);
|
let new_vote_account_entry = next_entry_mut(&mut last_entry_hash, 1, vec![new_vote_account_tx]);
|
||||||
|
|
||||||
// 3) Create vote entry
|
// 3) Create vote entry
|
||||||
let vote_tx = VoteTransaction::new_vote(&voting_keypair, slot_height_to_vote_on, *last_id, 0);
|
let vote_tx = VoteTransaction::new_vote(&voting_keypair, slot_height_to_vote_on, *block_hash, 0);
|
||||||
let vote_entry = next_entry_mut(&mut last_entry_hash, 1, vec![vote_tx]);
|
let vote_entry = next_entry_mut(&mut last_entry_hash, 1, vec![vote_tx]);
|
||||||
|
|
||||||
// 4) Create `num_ending_ticks` empty ticks
|
// 4) Create `num_ending_ticks` empty ticks
|
||||||
|
@ -486,7 +486,7 @@ mod tests {
|
||||||
let validator_node = Node::new_localhost_with_pubkey(validator_keypair.pubkey());
|
let validator_node = Node::new_localhost_with_pubkey(validator_keypair.pubkey());
|
||||||
let (genesis_block, _mint_keypair) =
|
let (genesis_block, _mint_keypair) =
|
||||||
GenesisBlock::new_with_leader(10_000, leader_keypair.pubkey(), 1000);
|
GenesisBlock::new_with_leader(10_000, leader_keypair.pubkey(), 1000);
|
||||||
let (validator_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
let (validator_ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block);
|
||||||
|
|
||||||
let validator = Fullnode::new(
|
let validator = Fullnode::new(
|
||||||
validator_node,
|
validator_node,
|
||||||
|
@ -512,7 +512,7 @@ mod tests {
|
||||||
let validator_node = Node::new_localhost_with_pubkey(validator_keypair.pubkey());
|
let validator_node = Node::new_localhost_with_pubkey(validator_keypair.pubkey());
|
||||||
let (genesis_block, _mint_keypair) =
|
let (genesis_block, _mint_keypair) =
|
||||||
GenesisBlock::new_with_leader(10_000, leader_keypair.pubkey(), 1000);
|
GenesisBlock::new_with_leader(10_000, leader_keypair.pubkey(), 1000);
|
||||||
let (validator_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
let (validator_ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block);
|
||||||
ledger_paths.push(validator_ledger_path.clone());
|
ledger_paths.push(validator_ledger_path.clone());
|
||||||
Fullnode::new(
|
Fullnode::new(
|
||||||
validator_node,
|
validator_node,
|
||||||
|
@ -560,7 +560,7 @@ mod tests {
|
||||||
genesis_block.ticks_per_slot = ticks_per_slot;
|
genesis_block.ticks_per_slot = ticks_per_slot;
|
||||||
genesis_block.slots_per_epoch = slots_per_epoch;
|
genesis_block.slots_per_epoch = slots_per_epoch;
|
||||||
|
|
||||||
let (bootstrap_leader_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
let (bootstrap_leader_ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block);
|
||||||
|
|
||||||
// Start the bootstrap leader
|
// Start the bootstrap leader
|
||||||
let bootstrap_leader = Fullnode::new(
|
let bootstrap_leader = Fullnode::new(
|
||||||
|
@ -657,7 +657,7 @@ mod tests {
|
||||||
let leader_keypair = Arc::new(Keypair::new());
|
let leader_keypair = Arc::new(Keypair::new());
|
||||||
let validator_keypair = Arc::new(Keypair::new());
|
let validator_keypair = Arc::new(Keypair::new());
|
||||||
let fullnode_config = FullnodeConfig::default();
|
let fullnode_config = FullnodeConfig::default();
|
||||||
let (leader_node, validator_node, validator_ledger_path, ledger_initial_len, last_id) =
|
let (leader_node, validator_node, validator_ledger_path, ledger_initial_len, block_hash) =
|
||||||
setup_leader_validator(&leader_keypair, &validator_keypair, ticks_per_slot, 0);
|
setup_leader_validator(&leader_keypair, &validator_keypair, ticks_per_slot, 0);
|
||||||
|
|
||||||
let leader_id = leader_keypair.pubkey();
|
let leader_id = leader_keypair.pubkey();
|
||||||
|
@ -697,7 +697,7 @@ mod tests {
|
||||||
&leader_id,
|
&leader_id,
|
||||||
blobs_to_send,
|
blobs_to_send,
|
||||||
ledger_initial_len,
|
ledger_initial_len,
|
||||||
last_id,
|
block_hash,
|
||||||
&tvu_address,
|
&tvu_address,
|
||||||
)
|
)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -747,7 +747,7 @@ mod tests {
|
||||||
GenesisBlock::new_with_leader(10_000, leader_node.info.id, 500);
|
GenesisBlock::new_with_leader(10_000, leader_node.info.id, 500);
|
||||||
genesis_block.ticks_per_slot = ticks_per_slot;
|
genesis_block.ticks_per_slot = ticks_per_slot;
|
||||||
|
|
||||||
let (ledger_path, last_id) = create_new_tmp_ledger!(&genesis_block);
|
let (ledger_path, block_hash) = create_new_tmp_ledger!(&genesis_block);
|
||||||
|
|
||||||
// Add entries so that the validator is in the active set, then finish up the slot with
|
// Add entries so that the validator is in the active set, then finish up the slot with
|
||||||
// ticks (and maybe add extra slots full of empty ticks)
|
// ticks (and maybe add extra slots full of empty ticks)
|
||||||
|
@ -756,12 +756,12 @@ mod tests {
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
10,
|
10,
|
||||||
0,
|
0,
|
||||||
&last_id,
|
&block_hash,
|
||||||
ticks_per_slot * (num_ending_slots + 1),
|
ticks_per_slot * (num_ending_slots + 1),
|
||||||
);
|
);
|
||||||
|
|
||||||
let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap();
|
let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap();
|
||||||
let last_id = entries.last().unwrap().hash;
|
let block_hash = entries.last().unwrap().hash;
|
||||||
let entry_height = ticks_per_slot + entries.len() as u64;
|
let entry_height = ticks_per_slot + entries.len() as u64;
|
||||||
blocktree.write_entries(1, 0, 0, entries).unwrap();
|
blocktree.write_entries(1, 0, 0, entries).unwrap();
|
||||||
|
|
||||||
|
@ -770,7 +770,7 @@ mod tests {
|
||||||
validator_node,
|
validator_node,
|
||||||
ledger_path,
|
ledger_path,
|
||||||
entry_height,
|
entry_height,
|
||||||
last_id,
|
block_hash,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,7 +154,7 @@ mod tests {
|
||||||
tick_hash = hash(&serialize(&tick_hash).unwrap());
|
tick_hash = hash(&serialize(&tick_hash).unwrap());
|
||||||
bank.register_tick(&tick_hash);
|
bank.register_tick(&tick_hash);
|
||||||
}
|
}
|
||||||
let last_id = bank.last_block_hash();
|
let block_hash = bank.last_block_hash();
|
||||||
|
|
||||||
// Create a total of 10 vote accounts, each will have a balance of 1 (after giving 1 to
|
// Create a total of 10 vote accounts, each will have a balance of 1 (after giving 1 to
|
||||||
// their vote account), for a total staking pool of 10 tokens.
|
// their vote account), for a total staking pool of 10 tokens.
|
||||||
|
@ -166,7 +166,7 @@ mod tests {
|
||||||
let voting_pubkey = voting_keypair.pubkey();
|
let voting_pubkey = voting_keypair.pubkey();
|
||||||
|
|
||||||
// Give the validator some tokens
|
// Give the validator some tokens
|
||||||
bank.transfer(2, &mint_keypair, validator_keypair.pubkey(), last_id)
|
bank.transfer(2, &mint_keypair, validator_keypair.pubkey(), block_hash)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
new_vote_account(&validator_keypair, &voting_pubkey, &bank, 1);
|
new_vote_account(&validator_keypair, &voting_pubkey, &bank, 1);
|
||||||
|
|
||||||
|
@ -188,7 +188,7 @@ mod tests {
|
||||||
|
|
||||||
// Get another validator to vote, so we now have 2/3 consensus
|
// Get another validator to vote, so we now have 2/3 consensus
|
||||||
let voting_keypair = &vote_accounts[7].0;
|
let voting_keypair = &vote_accounts[7].0;
|
||||||
let vote_tx = VoteTransaction::new_vote(voting_keypair, 7, last_id, 0);
|
let vote_tx = VoteTransaction::new_vote(voting_keypair, 7, block_hash, 0);
|
||||||
bank.process_transaction(&vote_tx).unwrap();
|
bank.process_transaction(&vote_tx).unwrap();
|
||||||
|
|
||||||
LeaderConfirmationService::compute_confirmation(
|
LeaderConfirmationService::compute_confirmation(
|
||||||
|
|
|
@ -34,7 +34,7 @@ impl LocalCluster {
|
||||||
let leader_node = Node::new_localhost_with_pubkey(leader_keypair.pubkey());
|
let leader_node = Node::new_localhost_with_pubkey(leader_keypair.pubkey());
|
||||||
let (genesis_block, mint_keypair) =
|
let (genesis_block, mint_keypair) =
|
||||||
GenesisBlock::new_with_leader(cluster_lamports, leader_pubkey, lamports_per_node);
|
GenesisBlock::new_with_leader(cluster_lamports, leader_pubkey, lamports_per_node);
|
||||||
let (genesis_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
let (genesis_ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block);
|
||||||
let leader_ledger_path = tmp_copy_blocktree!(&genesis_ledger_path);
|
let leader_ledger_path = tmp_copy_blocktree!(&genesis_ledger_path);
|
||||||
let mut ledger_paths = vec![];
|
let mut ledger_paths = vec![];
|
||||||
ledger_paths.push(genesis_ledger_path.clone());
|
ledger_paths.push(genesis_ledger_path.clone());
|
||||||
|
@ -121,10 +121,10 @@ impl LocalCluster {
|
||||||
dest_pubkey: &Pubkey,
|
dest_pubkey: &Pubkey,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) -> u64 {
|
) -> u64 {
|
||||||
trace!("getting leader last_id");
|
trace!("getting leader block_hash");
|
||||||
let last_id = client.get_recent_block_hash();
|
let block_hash = client.get_recent_block_hash();
|
||||||
let mut tx =
|
let mut tx =
|
||||||
SystemTransaction::new_account(&source_keypair, *dest_pubkey, lamports, last_id, 0);
|
SystemTransaction::new_account(&source_keypair, *dest_pubkey, lamports, block_hash, 0);
|
||||||
info!(
|
info!(
|
||||||
"executing transfer of {} from {} to {}",
|
"executing transfer of {} from {} to {}",
|
||||||
lamports,
|
lamports,
|
||||||
|
|
|
@ -52,14 +52,14 @@ impl PohRecorder {
|
||||||
}
|
}
|
||||||
|
|
||||||
// synchronize PoH with a bank
|
// synchronize PoH with a bank
|
||||||
pub fn reset(&mut self, tick_height: u64, last_id: Hash) {
|
pub fn reset(&mut self, tick_height: u64, block_hash: Hash) {
|
||||||
let mut cache = vec![];
|
let mut cache = vec![];
|
||||||
info!(
|
info!(
|
||||||
"reset poh from: {},{} to: {},{}",
|
"reset poh from: {},{} to: {},{}",
|
||||||
self.poh.hash, self.poh.tick_height, last_id, tick_height,
|
self.poh.hash, self.poh.tick_height, block_hash, tick_height,
|
||||||
);
|
);
|
||||||
std::mem::swap(&mut cache, &mut self.tick_cache);
|
std::mem::swap(&mut cache, &mut self.tick_cache);
|
||||||
self.poh = Poh::new(last_id, tick_height);
|
self.poh = Poh::new(block_hash, tick_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_working_bank(&mut self, working_bank: WorkingBank) {
|
pub fn set_working_bank(&mut self, working_bank: WorkingBank) {
|
||||||
|
|
|
@ -152,7 +152,7 @@ impl ReplayStage {
|
||||||
);
|
);
|
||||||
to_leader_sender.send(TvuRotationInfo {
|
to_leader_sender.send(TvuRotationInfo {
|
||||||
tick_height: parent.tick_height(),
|
tick_height: parent.tick_height(),
|
||||||
last_id: parent.last_block_hash(),
|
block_hash: parent.last_block_hash(),
|
||||||
slot: next_slot,
|
slot: next_slot,
|
||||||
leader_id: next_leader,
|
leader_id: next_leader,
|
||||||
})?;
|
})?;
|
||||||
|
@ -329,7 +329,7 @@ mod test {
|
||||||
|
|
||||||
let (genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(10_000, leader_id, 500);
|
let (genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(10_000, leader_id, 500);
|
||||||
|
|
||||||
let (my_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
let (my_ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block);
|
||||||
|
|
||||||
// Set up the cluster info
|
// Set up the cluster info
|
||||||
let cluster_info_me = Arc::new(RwLock::new(ClusterInfo::new(my_node.info.clone())));
|
let cluster_info_me = Arc::new(RwLock::new(ClusterInfo::new(my_node.info.clone())));
|
||||||
|
@ -383,10 +383,10 @@ mod test {
|
||||||
let (forward_entry_sender, forward_entry_receiver) = channel();
|
let (forward_entry_sender, forward_entry_receiver) = channel();
|
||||||
let genesis_block = GenesisBlock::new(10_000).0;
|
let genesis_block = GenesisBlock::new(10_000).0;
|
||||||
let bank = Arc::new(Bank::new(&genesis_block));
|
let bank = Arc::new(Bank::new(&genesis_block));
|
||||||
let mut last_id = bank.last_block_hash();
|
let mut block_hash = bank.last_block_hash();
|
||||||
let mut entries = Vec::new();
|
let mut entries = Vec::new();
|
||||||
for _ in 0..5 {
|
for _ in 0..5 {
|
||||||
let entry = next_entry_mut(&mut last_id, 1, vec![]); //just ticks
|
let entry = next_entry_mut(&mut block_hash, 1, vec![]); //just ticks
|
||||||
entries.push(entry);
|
entries.push(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ pub fn sample_file(in_path: &Path, sample_offsets: &[u64]) -> io::Result<Hash> {
|
||||||
Ok(hasher.result())
|
Ok(hasher.result())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_entry_heights_from_last_id(
|
fn get_entry_heights_from_block_hash(
|
||||||
signature: &ring::signature::Signature,
|
signature: &ring::signature::Signature,
|
||||||
storage_entry_height: u64,
|
storage_entry_height: u64,
|
||||||
) -> u64 {
|
) -> u64 {
|
||||||
|
@ -159,10 +159,10 @@ impl Replicator {
|
||||||
info!("Got leader: {:?}", leader);
|
info!("Got leader: {:?}", leader);
|
||||||
|
|
||||||
let (storage_block_hash, storage_entry_height) =
|
let (storage_block_hash, storage_entry_height) =
|
||||||
Self::poll_for_last_id_and_entry_height(&cluster_info)?;
|
Self::poll_for_block_hash_and_entry_height(&cluster_info)?;
|
||||||
|
|
||||||
let signature = keypair.sign(storage_block_hash.as_ref());
|
let signature = keypair.sign(storage_block_hash.as_ref());
|
||||||
let entry_height = get_entry_heights_from_last_id(&signature, storage_entry_height);
|
let entry_height = get_entry_heights_from_block_hash(&signature, storage_entry_height);
|
||||||
|
|
||||||
info!("replicating entry_height: {}", entry_height);
|
info!("replicating entry_height: {}", entry_height);
|
||||||
|
|
||||||
|
@ -254,12 +254,12 @@ impl Replicator {
|
||||||
|
|
||||||
match sample_file(&ledger_data_file_encrypted, &sampling_offsets) {
|
match sample_file(&ledger_data_file_encrypted, &sampling_offsets) {
|
||||||
Ok(hash) => {
|
Ok(hash) => {
|
||||||
let last_id = client.get_recent_block_hash();
|
let block_hash = client.get_recent_block_hash();
|
||||||
info!("sampled hash: {}", hash);
|
info!("sampled hash: {}", hash);
|
||||||
let mut tx = StorageTransaction::new_mining_proof(
|
let mut tx = StorageTransaction::new_mining_proof(
|
||||||
&keypair,
|
&keypair,
|
||||||
hash,
|
hash,
|
||||||
last_id,
|
block_hash,
|
||||||
entry_height,
|
entry_height,
|
||||||
Signature::new(signature.as_ref()),
|
Signature::new(signature.as_ref()),
|
||||||
);
|
);
|
||||||
|
@ -326,7 +326,7 @@ impl Replicator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn poll_for_last_id_and_entry_height(
|
fn poll_for_block_hash_and_entry_height(
|
||||||
cluster_info: &Arc<RwLock<ClusterInfo>>,
|
cluster_info: &Arc<RwLock<ClusterInfo>>,
|
||||||
) -> Result<(String, u64)> {
|
) -> Result<(String, u64)> {
|
||||||
for _ in 0..10 {
|
for _ in 0..10 {
|
||||||
|
@ -355,7 +355,7 @@ impl Replicator {
|
||||||
}
|
}
|
||||||
Err(Error::new(
|
Err(Error::new(
|
||||||
ErrorKind::Other,
|
ErrorKind::Other,
|
||||||
"Couldn't get last_id or entry_height",
|
"Couldn't get block_hash or entry_height",
|
||||||
))?
|
))?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,12 +366,12 @@ impl Replicator {
|
||||||
|
|
||||||
let airdrop_amount = 1;
|
let airdrop_amount = 1;
|
||||||
|
|
||||||
let last_id = client.get_recent_block_hash();
|
let block_hash = client.get_recent_block_hash();
|
||||||
match request_airdrop_transaction(
|
match request_airdrop_transaction(
|
||||||
&drone_addr,
|
&drone_addr,
|
||||||
&keypair.pubkey(),
|
&keypair.pubkey(),
|
||||||
airdrop_amount,
|
airdrop_amount,
|
||||||
last_id,
|
block_hash,
|
||||||
) {
|
) {
|
||||||
Ok(transaction) => {
|
Ok(transaction) => {
|
||||||
let signature = client.transfer_signed(&transaction).unwrap();
|
let signature = client.transfer_signed(&transaction).unwrap();
|
||||||
|
|
|
@ -255,8 +255,8 @@ impl RpcSol for RpcSolImpl {
|
||||||
trace!("request_airdrop id={} tokens={}", id, tokens);
|
trace!("request_airdrop id={} tokens={}", id, tokens);
|
||||||
let pubkey = verify_pubkey(id)?;
|
let pubkey = verify_pubkey(id)?;
|
||||||
|
|
||||||
let last_id = meta.request_processor.read().unwrap().bank()?.last_block_hash();
|
let block_hash = meta.request_processor.read().unwrap().bank()?.last_block_hash();
|
||||||
let transaction = request_airdrop_transaction(&meta.drone_addr, &pubkey, tokens, last_id)
|
let transaction = request_airdrop_transaction(&meta.drone_addr, &pubkey, tokens, block_hash)
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
info!("request_airdrop_transaction failed: {:?}", err);
|
info!("request_airdrop_transaction failed: {:?}", err);
|
||||||
Error::internal_error()
|
Error::internal_error()
|
||||||
|
@ -370,8 +370,8 @@ mod tests {
|
||||||
let (genesis_block, alice) = GenesisBlock::new(10_000);
|
let (genesis_block, alice) = GenesisBlock::new(10_000);
|
||||||
let bank = Arc::new(Bank::new(&genesis_block));
|
let bank = Arc::new(Bank::new(&genesis_block));
|
||||||
|
|
||||||
let last_id = bank.last_block_hash();
|
let block_hash = bank.last_block_hash();
|
||||||
let tx = SystemTransaction::new_move(&alice, pubkey, 20, last_id, 0);
|
let tx = SystemTransaction::new_move(&alice, pubkey, 20, block_hash, 0);
|
||||||
bank.process_transaction(&tx).expect("process transaction");
|
bank.process_transaction(&tx).expect("process transaction");
|
||||||
|
|
||||||
let request_processor = Arc::new(RwLock::new(JsonRpcRequestProcessor::new(
|
let request_processor = Arc::new(RwLock::new(JsonRpcRequestProcessor::new(
|
||||||
|
@ -395,7 +395,7 @@ mod tests {
|
||||||
drone_addr,
|
drone_addr,
|
||||||
rpc_addr,
|
rpc_addr,
|
||||||
};
|
};
|
||||||
(io, meta, last_id, alice)
|
(io, meta, block_hash, alice)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -406,8 +406,8 @@ mod tests {
|
||||||
let mut request_processor = JsonRpcRequestProcessor::new(StorageState::default());
|
let mut request_processor = JsonRpcRequestProcessor::new(StorageState::default());
|
||||||
request_processor.set_bank(&bank);
|
request_processor.set_bank(&bank);
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let last_id = bank.last_block_hash();
|
let block_hash = bank.last_block_hash();
|
||||||
let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, last_id, 0);
|
let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, block_hash, 0);
|
||||||
bank.process_transaction(&tx).expect("process transaction");
|
bank.process_transaction(&tx).expect("process transaction");
|
||||||
})
|
})
|
||||||
.join()
|
.join()
|
||||||
|
@ -418,7 +418,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rpc_get_balance() {
|
fn test_rpc_get_balance() {
|
||||||
let bob_pubkey = Keypair::new().pubkey();
|
let bob_pubkey = Keypair::new().pubkey();
|
||||||
let (io, meta, _last_id, _alice) = start_rpc_handler_with_tx(bob_pubkey);
|
let (io, meta, _block_hash, _alice) = start_rpc_handler_with_tx(bob_pubkey);
|
||||||
|
|
||||||
let req = format!(
|
let req = format!(
|
||||||
r#"{{"jsonrpc":"2.0","id":1,"method":"getBalance","params":["{}"]}}"#,
|
r#"{{"jsonrpc":"2.0","id":1,"method":"getBalance","params":["{}"]}}"#,
|
||||||
|
@ -436,7 +436,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rpc_get_tx_count() {
|
fn test_rpc_get_tx_count() {
|
||||||
let bob_pubkey = Keypair::new().pubkey();
|
let bob_pubkey = Keypair::new().pubkey();
|
||||||
let (io, meta, _last_id, _alice) = start_rpc_handler_with_tx(bob_pubkey);
|
let (io, meta, _block_hash, _alice) = start_rpc_handler_with_tx(bob_pubkey);
|
||||||
|
|
||||||
let req = format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getTransactionCount"}}"#);
|
let req = format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getTransactionCount"}}"#);
|
||||||
let res = io.handle_request_sync(&req, meta);
|
let res = io.handle_request_sync(&req, meta);
|
||||||
|
@ -451,7 +451,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rpc_get_account_info() {
|
fn test_rpc_get_account_info() {
|
||||||
let bob_pubkey = Keypair::new().pubkey();
|
let bob_pubkey = Keypair::new().pubkey();
|
||||||
let (io, meta, _last_id, _alice) = start_rpc_handler_with_tx(bob_pubkey);
|
let (io, meta, _block_hash, _alice) = start_rpc_handler_with_tx(bob_pubkey);
|
||||||
|
|
||||||
let req = format!(
|
let req = format!(
|
||||||
r#"{{"jsonrpc":"2.0","id":1,"method":"getAccountInfo","params":["{}"]}}"#,
|
r#"{{"jsonrpc":"2.0","id":1,"method":"getAccountInfo","params":["{}"]}}"#,
|
||||||
|
@ -478,8 +478,8 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rpc_confirm_tx() {
|
fn test_rpc_confirm_tx() {
|
||||||
let bob_pubkey = Keypair::new().pubkey();
|
let bob_pubkey = Keypair::new().pubkey();
|
||||||
let (io, meta, last_id, alice) = start_rpc_handler_with_tx(bob_pubkey);
|
let (io, meta, block_hash, alice) = start_rpc_handler_with_tx(bob_pubkey);
|
||||||
let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, last_id, 0);
|
let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, block_hash, 0);
|
||||||
|
|
||||||
let req = format!(
|
let req = format!(
|
||||||
r#"{{"jsonrpc":"2.0","id":1,"method":"confirmTransaction","params":["{}"]}}"#,
|
r#"{{"jsonrpc":"2.0","id":1,"method":"confirmTransaction","params":["{}"]}}"#,
|
||||||
|
@ -497,8 +497,8 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rpc_get_signature_status() {
|
fn test_rpc_get_signature_status() {
|
||||||
let bob_pubkey = Keypair::new().pubkey();
|
let bob_pubkey = Keypair::new().pubkey();
|
||||||
let (io, meta, last_id, alice) = start_rpc_handler_with_tx(bob_pubkey);
|
let (io, meta, block_hash, alice) = start_rpc_handler_with_tx(bob_pubkey);
|
||||||
let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, last_id, 0);
|
let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, block_hash, 0);
|
||||||
|
|
||||||
let req = format!(
|
let req = format!(
|
||||||
r#"{{"jsonrpc":"2.0","id":1,"method":"getSignatureStatus","params":["{}"]}}"#,
|
r#"{{"jsonrpc":"2.0","id":1,"method":"getSignatureStatus","params":["{}"]}}"#,
|
||||||
|
@ -513,7 +513,7 @@ mod tests {
|
||||||
assert_eq!(expected, result);
|
assert_eq!(expected, result);
|
||||||
|
|
||||||
// Test getSignatureStatus request on unprocessed tx
|
// Test getSignatureStatus request on unprocessed tx
|
||||||
let tx = SystemTransaction::new_move(&alice, bob_pubkey, 10, last_id, 0);
|
let tx = SystemTransaction::new_move(&alice, bob_pubkey, 10, block_hash, 0);
|
||||||
let req = format!(
|
let req = format!(
|
||||||
r#"{{"jsonrpc":"2.0","id":1,"method":"getSignatureStatus","params":["{}"]}}"#,
|
r#"{{"jsonrpc":"2.0","id":1,"method":"getSignatureStatus","params":["{}"]}}"#,
|
||||||
tx.signatures[0]
|
tx.signatures[0]
|
||||||
|
@ -530,11 +530,11 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rpc_get_recent_block_hash() {
|
fn test_rpc_get_recent_block_hash() {
|
||||||
let bob_pubkey = Keypair::new().pubkey();
|
let bob_pubkey = Keypair::new().pubkey();
|
||||||
let (io, meta, last_id, _alice) = start_rpc_handler_with_tx(bob_pubkey);
|
let (io, meta, block_hash, _alice) = start_rpc_handler_with_tx(bob_pubkey);
|
||||||
|
|
||||||
let req = format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getLastId"}}"#);
|
let req = format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getLastId"}}"#);
|
||||||
let res = io.handle_request_sync(&req, meta);
|
let res = io.handle_request_sync(&req, meta);
|
||||||
let expected = format!(r#"{{"jsonrpc":"2.0","result":"{}","id":1}}"#, last_id);
|
let expected = format!(r#"{{"jsonrpc":"2.0","result":"{}","id":1}}"#, block_hash);
|
||||||
let expected: Response =
|
let expected: Response =
|
||||||
serde_json::from_str(&expected).expect("expected response deserialization");
|
serde_json::from_str(&expected).expect("expected response deserialization");
|
||||||
let result: Response = serde_json::from_str(&res.expect("actual response"))
|
let result: Response = serde_json::from_str(&res.expect("actual response"))
|
||||||
|
@ -545,7 +545,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rpc_fail_request_airdrop() {
|
fn test_rpc_fail_request_airdrop() {
|
||||||
let bob_pubkey = Keypair::new().pubkey();
|
let bob_pubkey = Keypair::new().pubkey();
|
||||||
let (io, meta, _last_id, _alice) = start_rpc_handler_with_tx(bob_pubkey);
|
let (io, meta, _block_hash, _alice) = start_rpc_handler_with_tx(bob_pubkey);
|
||||||
|
|
||||||
// Expect internal error because no leader is running
|
// Expect internal error because no leader is running
|
||||||
let req = format!(
|
let req = format!(
|
||||||
|
|
|
@ -98,14 +98,14 @@ pub fn request_airdrop_transaction(
|
||||||
_drone_addr: &SocketAddr,
|
_drone_addr: &SocketAddr,
|
||||||
_id: &Pubkey,
|
_id: &Pubkey,
|
||||||
tokens: u64,
|
tokens: u64,
|
||||||
_last_id: Hash,
|
_block_hash: Hash,
|
||||||
) -> Result<Transaction, Error> {
|
) -> Result<Transaction, Error> {
|
||||||
if tokens == 0 {
|
if tokens == 0 {
|
||||||
Err(Error::new(ErrorKind::Other, "Airdrop failed"))?
|
Err(Error::new(ErrorKind::Other, "Airdrop failed"))?
|
||||||
}
|
}
|
||||||
let key = Keypair::new();
|
let key = Keypair::new();
|
||||||
let to = Keypair::new().pubkey();
|
let to = Keypair::new().pubkey();
|
||||||
let last_id = Hash::default();
|
let block_hash = Hash::default();
|
||||||
let tx = SystemTransaction::new_account(&key, to, 50, last_id, 0);
|
let tx = SystemTransaction::new_account(&key, to, 50, block_hash, 0);
|
||||||
Ok(tx)
|
Ok(tx)
|
||||||
}
|
}
|
||||||
|
|
|
@ -203,12 +203,12 @@ mod tests {
|
||||||
let bob_pubkey = bob.pubkey();
|
let bob_pubkey = bob.pubkey();
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
let arc_bank = Arc::new(bank);
|
let arc_bank = Arc::new(bank);
|
||||||
let last_id = arc_bank.last_block_hash();
|
let block_hash = arc_bank.last_block_hash();
|
||||||
|
|
||||||
let rpc = RpcSolPubSubImpl::default();
|
let rpc = RpcSolPubSubImpl::default();
|
||||||
|
|
||||||
// Test signature subscriptions
|
// Test signature subscriptions
|
||||||
let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, last_id, 0);
|
let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, block_hash, 0);
|
||||||
|
|
||||||
let session = create_session();
|
let session = create_session();
|
||||||
let (subscriber, _id_receiver, mut receiver) =
|
let (subscriber, _id_receiver, mut receiver) =
|
||||||
|
@ -232,7 +232,7 @@ mod tests {
|
||||||
let bob_pubkey = Keypair::new().pubkey();
|
let bob_pubkey = Keypair::new().pubkey();
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
let arc_bank = Arc::new(bank);
|
let arc_bank = Arc::new(bank);
|
||||||
let last_id = arc_bank.last_block_hash();
|
let block_hash = arc_bank.last_block_hash();
|
||||||
|
|
||||||
let session = create_session();
|
let session = create_session();
|
||||||
|
|
||||||
|
@ -240,7 +240,7 @@ mod tests {
|
||||||
let rpc = RpcSolPubSubImpl::default();
|
let rpc = RpcSolPubSubImpl::default();
|
||||||
io.extend_with(rpc.to_delegate());
|
io.extend_with(rpc.to_delegate());
|
||||||
|
|
||||||
let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, last_id, 0);
|
let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, block_hash, 0);
|
||||||
let req = format!(
|
let req = format!(
|
||||||
r#"{{"jsonrpc":"2.0","id":1,"method":"signatureSubscribe","params":["{}"]}}"#,
|
r#"{{"jsonrpc":"2.0","id":1,"method":"signatureSubscribe","params":["{}"]}}"#,
|
||||||
tx.signatures[0].to_string()
|
tx.signatures[0].to_string()
|
||||||
|
@ -279,7 +279,7 @@ mod tests {
|
||||||
let executable = false; // TODO
|
let executable = false; // TODO
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
let arc_bank = Arc::new(bank);
|
let arc_bank = Arc::new(bank);
|
||||||
let last_id = arc_bank.last_block_hash();
|
let block_hash = arc_bank.last_block_hash();
|
||||||
|
|
||||||
let rpc = RpcSolPubSubImpl::default();
|
let rpc = RpcSolPubSubImpl::default();
|
||||||
let session = create_session();
|
let session = create_session();
|
||||||
|
@ -289,7 +289,7 @@ mod tests {
|
||||||
let tx = SystemTransaction::new_program_account(
|
let tx = SystemTransaction::new_program_account(
|
||||||
&alice,
|
&alice,
|
||||||
contract_funds.pubkey(),
|
contract_funds.pubkey(),
|
||||||
last_id,
|
block_hash,
|
||||||
50,
|
50,
|
||||||
0,
|
0,
|
||||||
budget_program_id,
|
budget_program_id,
|
||||||
|
@ -300,7 +300,7 @@ mod tests {
|
||||||
let tx = SystemTransaction::new_program_account(
|
let tx = SystemTransaction::new_program_account(
|
||||||
&alice,
|
&alice,
|
||||||
contract_state.pubkey(),
|
contract_state.pubkey(),
|
||||||
last_id,
|
block_hash,
|
||||||
1,
|
1,
|
||||||
196,
|
196,
|
||||||
budget_program_id,
|
budget_program_id,
|
||||||
|
@ -342,7 +342,7 @@ mod tests {
|
||||||
witness.pubkey(),
|
witness.pubkey(),
|
||||||
None,
|
None,
|
||||||
50,
|
50,
|
||||||
last_id,
|
block_hash,
|
||||||
);
|
);
|
||||||
let arc_bank = process_transaction_and_notify(&arc_bank, &tx, &rpc.subscriptions).unwrap();
|
let arc_bank = process_transaction_and_notify(&arc_bank, &tx, &rpc.subscriptions).unwrap();
|
||||||
sleep(Duration::from_millis(200));
|
sleep(Duration::from_millis(200));
|
||||||
|
@ -371,14 +371,14 @@ mod tests {
|
||||||
assert_eq!(serde_json::to_string(&expected).unwrap(), response);
|
assert_eq!(serde_json::to_string(&expected).unwrap(), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
let tx = SystemTransaction::new_account(&alice, witness.pubkey(), 1, last_id, 0);
|
let tx = SystemTransaction::new_account(&alice, witness.pubkey(), 1, block_hash, 0);
|
||||||
let arc_bank = process_transaction_and_notify(&arc_bank, &tx, &rpc.subscriptions).unwrap();
|
let arc_bank = process_transaction_and_notify(&arc_bank, &tx, &rpc.subscriptions).unwrap();
|
||||||
sleep(Duration::from_millis(200));
|
sleep(Duration::from_millis(200));
|
||||||
let tx = BudgetTransaction::new_signature(
|
let tx = BudgetTransaction::new_signature(
|
||||||
&witness,
|
&witness,
|
||||||
contract_state.pubkey(),
|
contract_state.pubkey(),
|
||||||
bob_pubkey,
|
bob_pubkey,
|
||||||
last_id,
|
block_hash,
|
||||||
);
|
);
|
||||||
let arc_bank = process_transaction_and_notify(&arc_bank, &tx, &rpc.subscriptions).unwrap();
|
let arc_bank = process_transaction_and_notify(&arc_bank, &tx, &rpc.subscriptions).unwrap();
|
||||||
sleep(Duration::from_millis(200));
|
sleep(Duration::from_millis(200));
|
||||||
|
|
|
@ -275,16 +275,16 @@ mod tests {
|
||||||
);
|
);
|
||||||
assert_eq!(balance.unwrap().as_u64().unwrap(), 50);
|
assert_eq!(balance.unwrap().as_u64().unwrap(), 50);
|
||||||
|
|
||||||
let last_id = rpc_client.make_rpc_request(2, RpcRequest::GetLastId, None);
|
let block_hash = rpc_client.make_rpc_request(2, RpcRequest::GetLastId, None);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
last_id.unwrap().as_str().unwrap(),
|
block_hash.unwrap().as_str().unwrap(),
|
||||||
"deadbeefXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNHhx"
|
"deadbeefXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNHhx"
|
||||||
);
|
);
|
||||||
|
|
||||||
// Send erroneous parameter
|
// Send erroneous parameter
|
||||||
let last_id =
|
let block_hash =
|
||||||
rpc_client.make_rpc_request(3, RpcRequest::GetLastId, Some(json!("paramter")));
|
rpc_client.make_rpc_request(3, RpcRequest::GetLastId, Some(json!("paramter")));
|
||||||
assert_eq!(last_id.is_err(), true);
|
assert_eq!(block_hash.is_err(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -156,11 +156,11 @@ mod tests {
|
||||||
let (genesis_block, mint_keypair) = GenesisBlock::new(100);
|
let (genesis_block, mint_keypair) = GenesisBlock::new(100);
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
let alice = Keypair::new();
|
let alice = Keypair::new();
|
||||||
let last_id = bank.last_block_hash();
|
let block_hash = bank.last_block_hash();
|
||||||
let tx = SystemTransaction::new_program_account(
|
let tx = SystemTransaction::new_program_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
alice.pubkey(),
|
alice.pubkey(),
|
||||||
last_id,
|
block_hash,
|
||||||
1,
|
1,
|
||||||
16,
|
16,
|
||||||
budget_program::id(),
|
budget_program::id(),
|
||||||
|
@ -201,8 +201,8 @@ mod tests {
|
||||||
let (genesis_block, mint_keypair) = GenesisBlock::new(100);
|
let (genesis_block, mint_keypair) = GenesisBlock::new(100);
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
let alice = Keypair::new();
|
let alice = Keypair::new();
|
||||||
let last_id = bank.last_block_hash();
|
let block_hash = bank.last_block_hash();
|
||||||
let tx = SystemTransaction::new_move(&mint_keypair, alice.pubkey(), 20, last_id, 0);
|
let tx = SystemTransaction::new_move(&mint_keypair, alice.pubkey(), 20, block_hash, 0);
|
||||||
let signature = tx.signatures[0];
|
let signature = tx.signatures[0];
|
||||||
bank.process_transaction(&tx).unwrap();
|
bank.process_transaction(&tx).unwrap();
|
||||||
|
|
||||||
|
|
|
@ -495,7 +495,7 @@ mod tests {
|
||||||
let keypairs = vec![&keypair0, &keypair1];
|
let keypairs = vec![&keypair0, &keypair1];
|
||||||
let tokens = 5;
|
let tokens = 5;
|
||||||
let fee = 2;
|
let fee = 2;
|
||||||
let last_id = Hash::default();
|
let block_hash = Hash::default();
|
||||||
|
|
||||||
let keys = vec![keypair0.pubkey(), keypair1.pubkey()];
|
let keys = vec![keypair0.pubkey(), keypair1.pubkey()];
|
||||||
|
|
||||||
|
@ -508,7 +508,7 @@ mod tests {
|
||||||
let tx = Transaction::new_with_instructions(
|
let tx = Transaction::new_with_instructions(
|
||||||
&keypairs,
|
&keypairs,
|
||||||
&keys,
|
&keys,
|
||||||
last_id,
|
block_hash,
|
||||||
fee,
|
fee,
|
||||||
program_ids,
|
program_ids,
|
||||||
instructions,
|
instructions,
|
||||||
|
|
|
@ -235,10 +235,10 @@ impl StorageStage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut last_id = None;
|
let mut block_hash = None;
|
||||||
for _ in 0..10 {
|
for _ in 0..10 {
|
||||||
if let Some(new_last_id) = client.try_get_recent_block_hash(1) {
|
if let Some(new_block_hash) = client.try_get_recent_block_hash(1) {
|
||||||
last_id = Some(new_last_id);
|
block_hash = Some(new_block_hash);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,8 +247,8 @@ impl StorageStage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(last_id) = last_id {
|
if let Some(block_hash) = block_hash {
|
||||||
tx.sign(&[keypair.as_ref()], last_id);
|
tx.sign(&[keypair.as_ref()], block_hash);
|
||||||
|
|
||||||
if exit.load(Ordering::Relaxed) {
|
if exit.load(Ordering::Relaxed) {
|
||||||
Err(io::Error::new(io::ErrorKind::Other, "exit signaled"))?;
|
Err(io::Error::new(io::ErrorKind::Other, "exit signaled"))?;
|
||||||
|
@ -505,7 +505,7 @@ mod tests {
|
||||||
|
|
||||||
let (genesis_block, _mint_keypair) = GenesisBlock::new(1000);
|
let (genesis_block, _mint_keypair) = GenesisBlock::new(1000);
|
||||||
let ticks_per_slot = genesis_block.ticks_per_slot;
|
let ticks_per_slot = genesis_block.ticks_per_slot;
|
||||||
let (ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
let (ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block);
|
||||||
|
|
||||||
let entries = make_tiny_test_entries(64);
|
let entries = make_tiny_test_entries(64);
|
||||||
let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap();
|
let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap();
|
||||||
|
@ -567,7 +567,7 @@ mod tests {
|
||||||
|
|
||||||
let (genesis_block, _mint_keypair) = GenesisBlock::new(1000);
|
let (genesis_block, _mint_keypair) = GenesisBlock::new(1000);
|
||||||
let ticks_per_slot = genesis_block.ticks_per_slot;;
|
let ticks_per_slot = genesis_block.ticks_per_slot;;
|
||||||
let (ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
let (ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block);
|
||||||
|
|
||||||
let entries = make_tiny_test_entries(128);
|
let entries = make_tiny_test_entries(128);
|
||||||
let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap();
|
let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap();
|
||||||
|
|
|
@ -123,17 +123,17 @@ impl ThinClient {
|
||||||
tokens: u64,
|
tokens: u64,
|
||||||
keypair: &Keypair,
|
keypair: &Keypair,
|
||||||
to: Pubkey,
|
to: Pubkey,
|
||||||
last_id: &Hash,
|
block_hash: &Hash,
|
||||||
) -> io::Result<Signature> {
|
) -> io::Result<Signature> {
|
||||||
debug!(
|
debug!(
|
||||||
"transfer: tokens={} from={:?} to={:?} last_id={:?}",
|
"transfer: tokens={} from={:?} to={:?} block_hash={:?}",
|
||||||
tokens,
|
tokens,
|
||||||
keypair.pubkey(),
|
keypair.pubkey(),
|
||||||
to,
|
to,
|
||||||
last_id
|
block_hash
|
||||||
);
|
);
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
let transaction = SystemTransaction::new_account(keypair, to, tokens, *last_id, 0);
|
let transaction = SystemTransaction::new_account(keypair, to, tokens, *block_hash, 0);
|
||||||
let result = self.transfer_signed(&transaction);
|
let result = self.transfer_signed(&transaction);
|
||||||
solana_metrics::submit(
|
solana_metrics::submit(
|
||||||
influxdb::Point::new("thinclient")
|
influxdb::Point::new("thinclient")
|
||||||
|
@ -216,7 +216,7 @@ impl ThinClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Request the last Entry ID from the server without blocking.
|
/// Request the last Entry ID from the server without blocking.
|
||||||
/// Returns the last_id Hash or None if there was no response from the server.
|
/// Returns the block_hash Hash or None if there was no response from the server.
|
||||||
pub fn try_get_recent_block_hash(&mut self, mut num_retries: u64) -> Option<Hash> {
|
pub fn try_get_recent_block_hash(&mut self, mut num_retries: u64) -> Option<Hash> {
|
||||||
loop {
|
loop {
|
||||||
trace!("try_get_recent_block_hash send_to {}", &self.rpc_addr);
|
trace!("try_get_recent_block_hash send_to {}", &self.rpc_addr);
|
||||||
|
@ -226,9 +226,9 @@ impl ThinClient {
|
||||||
|
|
||||||
match response {
|
match response {
|
||||||
Ok(value) => {
|
Ok(value) => {
|
||||||
let last_id_str = value.as_str().unwrap();
|
let block_hash_str = value.as_str().unwrap();
|
||||||
let last_id_vec = bs58::decode(last_id_str).into_vec().unwrap();
|
let block_hash_vec = bs58::decode(block_hash_str).into_vec().unwrap();
|
||||||
return Some(Hash::new(&last_id_vec));
|
return Some(Hash::new(&block_hash_vec));
|
||||||
}
|
}
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
debug!("thin_client get_recent_block_hash error: {:?}", error);
|
debug!("thin_client get_recent_block_hash error: {:?}", error);
|
||||||
|
@ -254,18 +254,18 @@ impl ThinClient {
|
||||||
|
|
||||||
/// Request a new last Entry ID from the server. This method blocks
|
/// Request a new last Entry ID from the server. This method blocks
|
||||||
/// until the server sends a response.
|
/// until the server sends a response.
|
||||||
pub fn get_next_last_id(&mut self, previous_last_id: &Hash) -> Hash {
|
pub fn get_next_block_hash(&mut self, previous_block_hash: &Hash) -> Hash {
|
||||||
self.get_next_last_id_ext(previous_last_id, &|| {
|
self.get_next_block_hash_ext(previous_block_hash, &|| {
|
||||||
sleep(Duration::from_millis(100));
|
sleep(Duration::from_millis(100));
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
pub fn get_next_last_id_ext(&mut self, previous_last_id: &Hash, func: &Fn()) -> Hash {
|
pub fn get_next_block_hash_ext(&mut self, previous_block_hash: &Hash, func: &Fn()) -> Hash {
|
||||||
loop {
|
loop {
|
||||||
let last_id = self.get_recent_block_hash();
|
let block_hash = self.get_recent_block_hash();
|
||||||
if last_id != *previous_last_id {
|
if block_hash != *previous_block_hash {
|
||||||
break last_id;
|
break block_hash;
|
||||||
}
|
}
|
||||||
debug!("Got same last_id ({:?}), will retry...", last_id);
|
debug!("Got same block_hash ({:?}), will retry...", block_hash);
|
||||||
func()
|
func()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -468,7 +468,7 @@ pub fn new_fullnode() -> (Fullnode, NodeInfo, Keypair, String) {
|
||||||
let node_info = node.info.clone();
|
let node_info = node.info.clone();
|
||||||
|
|
||||||
let (genesis_block, mint_keypair) = GenesisBlock::new_with_leader(10_000, node_info.id, 42);
|
let (genesis_block, mint_keypair) = GenesisBlock::new_with_leader(10_000, node_info.id, 42);
|
||||||
let (ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
let (ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block);
|
||||||
|
|
||||||
let vote_account_keypair = Arc::new(Keypair::new());
|
let vote_account_keypair = Arc::new(Keypair::new());
|
||||||
let voting_keypair = VotingKeypair::new_local(&vote_account_keypair);
|
let voting_keypair = VotingKeypair::new_local(&vote_account_keypair);
|
||||||
|
@ -511,10 +511,10 @@ mod tests {
|
||||||
let transaction_count = client.transaction_count();
|
let transaction_count = client.transaction_count();
|
||||||
assert_eq!(transaction_count, 0);
|
assert_eq!(transaction_count, 0);
|
||||||
|
|
||||||
let last_id = client.get_recent_block_hash();
|
let block_hash = client.get_recent_block_hash();
|
||||||
info!("test_thin_client last_id: {:?}", last_id);
|
info!("test_thin_client block_hash: {:?}", block_hash);
|
||||||
|
|
||||||
let signature = client.transfer(500, &alice, bob_pubkey, &last_id).unwrap();
|
let signature = client.transfer(500, &alice, bob_pubkey, &block_hash).unwrap();
|
||||||
info!("test_thin_client signature: {:?}", signature);
|
info!("test_thin_client signature: {:?}", signature);
|
||||||
client.poll_for_signature(&signature).unwrap();
|
client.poll_for_signature(&signature).unwrap();
|
||||||
|
|
||||||
|
@ -541,15 +541,15 @@ mod tests {
|
||||||
|
|
||||||
let mut client = mk_client(&leader_data);
|
let mut client = mk_client(&leader_data);
|
||||||
|
|
||||||
let last_id = client.get_recent_block_hash();
|
let block_hash = client.get_recent_block_hash();
|
||||||
|
|
||||||
let tx = SystemTransaction::new_account(&alice, bob_pubkey, 500, last_id, 0);
|
let tx = SystemTransaction::new_account(&alice, bob_pubkey, 500, block_hash, 0);
|
||||||
|
|
||||||
let _sig = client.transfer_signed(&tx).unwrap();
|
let _sig = client.transfer_signed(&tx).unwrap();
|
||||||
|
|
||||||
let last_id = client.get_recent_block_hash();
|
let block_hash = client.get_recent_block_hash();
|
||||||
|
|
||||||
let mut tr2 = SystemTransaction::new_account(&alice, bob_pubkey, 501, last_id, 0);
|
let mut tr2 = SystemTransaction::new_account(&alice, bob_pubkey, 501, block_hash, 0);
|
||||||
let mut instruction2 = deserialize(tr2.userdata(0)).unwrap();
|
let mut instruction2 = deserialize(tr2.userdata(0)).unwrap();
|
||||||
if let SystemInstruction::Move { ref mut tokens } = instruction2 {
|
if let SystemInstruction::Move { ref mut tokens } = instruction2 {
|
||||||
*tokens = 502;
|
*tokens = 502;
|
||||||
|
@ -578,9 +578,9 @@ mod tests {
|
||||||
|
|
||||||
// Create the validator account, transfer some tokens to that account
|
// Create the validator account, transfer some tokens to that account
|
||||||
let validator_keypair = Keypair::new();
|
let validator_keypair = Keypair::new();
|
||||||
let last_id = client.get_recent_block_hash();
|
let block_hash = client.get_recent_block_hash();
|
||||||
let signature = client
|
let signature = client
|
||||||
.transfer(500, &alice, validator_keypair.pubkey(), &last_id)
|
.transfer(500, &alice, validator_keypair.pubkey(), &block_hash)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
client.poll_for_signature(&signature).unwrap();
|
client.poll_for_signature(&signature).unwrap();
|
||||||
|
@ -588,12 +588,12 @@ mod tests {
|
||||||
// Create and register the vote account
|
// Create and register the vote account
|
||||||
let validator_vote_account_keypair = Keypair::new();
|
let validator_vote_account_keypair = Keypair::new();
|
||||||
let vote_account_id = validator_vote_account_keypair.pubkey();
|
let vote_account_id = validator_vote_account_keypair.pubkey();
|
||||||
let last_id = client.get_recent_block_hash();
|
let block_hash = client.get_recent_block_hash();
|
||||||
|
|
||||||
let transaction = VoteTransaction::fund_staking_account(
|
let transaction = VoteTransaction::fund_staking_account(
|
||||||
&validator_keypair,
|
&validator_keypair,
|
||||||
vote_account_id,
|
vote_account_id,
|
||||||
last_id,
|
block_hash,
|
||||||
1,
|
1,
|
||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
|
@ -652,15 +652,15 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut client = mk_client(&leader_data);
|
let mut client = mk_client(&leader_data);
|
||||||
let last_id = client.get_recent_block_hash();
|
let block_hash = client.get_recent_block_hash();
|
||||||
info!("test_thin_client last_id: {:?}", last_id);
|
info!("test_thin_client block_hash: {:?}", block_hash);
|
||||||
|
|
||||||
let starting_alice_balance = client.poll_get_balance(&alice.pubkey()).unwrap();
|
let starting_alice_balance = client.poll_get_balance(&alice.pubkey()).unwrap();
|
||||||
info!("Alice has {} tokens", starting_alice_balance);
|
info!("Alice has {} tokens", starting_alice_balance);
|
||||||
|
|
||||||
info!("Give Bob 500 tokens");
|
info!("Give Bob 500 tokens");
|
||||||
let signature = client
|
let signature = client
|
||||||
.transfer(500, &alice, bob_keypair.pubkey(), &last_id)
|
.transfer(500, &alice, bob_keypair.pubkey(), &block_hash)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
client.poll_for_signature(&signature).unwrap();
|
client.poll_for_signature(&signature).unwrap();
|
||||||
|
|
||||||
|
@ -669,7 +669,7 @@ mod tests {
|
||||||
|
|
||||||
info!("Take Bob's 500 tokens away");
|
info!("Take Bob's 500 tokens away");
|
||||||
let signature = client
|
let signature = client
|
||||||
.transfer(500, &bob_keypair, alice.pubkey(), &last_id)
|
.transfer(500, &bob_keypair, alice.pubkey(), &block_hash)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
client.poll_for_signature(&signature).unwrap();
|
client.poll_for_signature(&signature).unwrap();
|
||||||
let alice_balance = client.poll_get_balance(&alice.pubkey()).unwrap();
|
let alice_balance = client.poll_get_balance(&alice.pubkey()).unwrap();
|
||||||
|
|
|
@ -34,7 +34,7 @@ use std::thread;
|
||||||
|
|
||||||
pub struct TvuRotationInfo {
|
pub struct TvuRotationInfo {
|
||||||
pub tick_height: u64, // tick height, bank might not exist yet
|
pub tick_height: u64, // tick height, bank might not exist yet
|
||||||
pub last_id: Hash, // last_id that was voted on
|
pub block_hash: Hash, // block_hash that was voted on
|
||||||
pub slot: u64, // slot height to initiate a rotation
|
pub slot: u64, // slot height to initiate a rotation
|
||||||
pub leader_id: Pubkey, // leader upon rotation
|
pub leader_id: Pubkey, // leader upon rotation
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//! The `vote_signer_proxy` votes on the `last_id` of the bank at a regular cadence
|
//! The `vote_signer_proxy` votes on the `block_hash` of the bank at a regular cadence
|
||||||
|
|
||||||
use crate::rpc_request::{RpcClient, RpcRequest};
|
use crate::rpc_request::{RpcClient, RpcRequest};
|
||||||
use jsonrpc_core;
|
use jsonrpc_core;
|
||||||
|
@ -109,11 +109,11 @@ pub mod tests {
|
||||||
bank: &Bank,
|
bank: &Bank,
|
||||||
num_tokens: u64,
|
num_tokens: u64,
|
||||||
) {
|
) {
|
||||||
let last_id = bank.last_block_hash();
|
let block_hash = bank.last_block_hash();
|
||||||
let tx = VoteTransaction::fund_staking_account(
|
let tx = VoteTransaction::fund_staking_account(
|
||||||
from_keypair,
|
from_keypair,
|
||||||
*voting_pubkey,
|
*voting_pubkey,
|
||||||
last_id,
|
block_hash,
|
||||||
num_tokens,
|
num_tokens,
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
|
@ -121,8 +121,8 @@ pub mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn push_vote<T: KeypairUtil>(voting_keypair: &T, bank: &Bank, slot_height: u64) {
|
pub fn push_vote<T: KeypairUtil>(voting_keypair: &T, bank: &Bank, slot_height: u64) {
|
||||||
let last_id = bank.last_block_hash();
|
let block_hash = bank.last_block_hash();
|
||||||
let tx = VoteTransaction::new_vote(voting_keypair, slot_height, last_id, 0);
|
let tx = VoteTransaction::new_vote(voting_keypair, slot_height, block_hash, 0);
|
||||||
bank.process_transaction(&tx).unwrap();
|
bank.process_transaction(&tx).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ pub enum DroneRequest {
|
||||||
GetAirdrop {
|
GetAirdrop {
|
||||||
tokens: u64,
|
tokens: u64,
|
||||||
to: Pubkey,
|
to: Pubkey,
|
||||||
last_id: Hash,
|
block_hash: Hash,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ impl Drone {
|
||||||
DroneRequest::GetAirdrop {
|
DroneRequest::GetAirdrop {
|
||||||
tokens,
|
tokens,
|
||||||
to,
|
to,
|
||||||
last_id,
|
block_hash,
|
||||||
} => {
|
} => {
|
||||||
if self.check_request_limit(tokens) {
|
if self.check_request_limit(tokens) {
|
||||||
self.request_current += tokens;
|
self.request_current += tokens;
|
||||||
|
@ -137,11 +137,11 @@ impl Drone {
|
||||||
&[to],
|
&[to],
|
||||||
system_program::id(),
|
system_program::id(),
|
||||||
&create_instruction,
|
&create_instruction,
|
||||||
last_id,
|
block_hash,
|
||||||
0, /*fee*/
|
0, /*fee*/
|
||||||
);
|
);
|
||||||
|
|
||||||
transaction.sign(&[&self.mint_keypair], last_id);
|
transaction.sign(&[&self.mint_keypair], block_hash);
|
||||||
Ok(transaction)
|
Ok(transaction)
|
||||||
} else {
|
} else {
|
||||||
Err(Error::new(ErrorKind::Other, "token limit reached"))
|
Err(Error::new(ErrorKind::Other, "token limit reached"))
|
||||||
|
@ -194,18 +194,18 @@ pub fn request_airdrop_transaction(
|
||||||
drone_addr: &SocketAddr,
|
drone_addr: &SocketAddr,
|
||||||
id: &Pubkey,
|
id: &Pubkey,
|
||||||
tokens: u64,
|
tokens: u64,
|
||||||
last_id: Hash,
|
block_hash: Hash,
|
||||||
) -> Result<Transaction, Error> {
|
) -> Result<Transaction, Error> {
|
||||||
info!(
|
info!(
|
||||||
"request_airdrop_transaction: drone_addr={} id={} tokens={} last_id={}",
|
"request_airdrop_transaction: drone_addr={} id={} tokens={} block_hash={}",
|
||||||
drone_addr, id, tokens, last_id
|
drone_addr, id, tokens, block_hash
|
||||||
);
|
);
|
||||||
// TODO: make this async tokio client
|
// TODO: make this async tokio client
|
||||||
let mut stream = TcpStream::connect_timeout(drone_addr, Duration::new(3, 0))?;
|
let mut stream = TcpStream::connect_timeout(drone_addr, Duration::new(3, 0))?;
|
||||||
stream.set_read_timeout(Some(Duration::new(10, 0)))?;
|
stream.set_read_timeout(Some(Duration::new(10, 0)))?;
|
||||||
let req = DroneRequest::GetAirdrop {
|
let req = DroneRequest::GetAirdrop {
|
||||||
tokens,
|
tokens,
|
||||||
last_id,
|
block_hash,
|
||||||
to: *id,
|
to: *id,
|
||||||
};
|
};
|
||||||
let req = serialize(&req).expect("serialize drone request");
|
let req = serialize(&req).expect("serialize drone request");
|
||||||
|
@ -353,11 +353,11 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_drone_build_airdrop_transaction() {
|
fn test_drone_build_airdrop_transaction() {
|
||||||
let to = Keypair::new().pubkey();
|
let to = Keypair::new().pubkey();
|
||||||
let last_id = Hash::default();
|
let block_hash = Hash::default();
|
||||||
let request = DroneRequest::GetAirdrop {
|
let request = DroneRequest::GetAirdrop {
|
||||||
tokens: 2,
|
tokens: 2,
|
||||||
to,
|
to,
|
||||||
last_id,
|
block_hash,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mint = Keypair::new();
|
let mint = Keypair::new();
|
||||||
|
@ -368,7 +368,7 @@ mod tests {
|
||||||
|
|
||||||
assert_eq!(tx.signatures.len(), 1);
|
assert_eq!(tx.signatures.len(), 1);
|
||||||
assert_eq!(tx.account_keys, vec![mint_pubkey, to]);
|
assert_eq!(tx.account_keys, vec![mint_pubkey, to]);
|
||||||
assert_eq!(tx.recent_block_hash, last_id);
|
assert_eq!(tx.recent_block_hash, block_hash);
|
||||||
assert_eq!(tx.program_ids, vec![system_program::id()]);
|
assert_eq!(tx.program_ids, vec![system_program::id()]);
|
||||||
|
|
||||||
assert_eq!(tx.instructions.len(), 1);
|
assert_eq!(tx.instructions.len(), 1);
|
||||||
|
@ -391,11 +391,11 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_process_drone_request() {
|
fn test_process_drone_request() {
|
||||||
let to = Keypair::new().pubkey();
|
let to = Keypair::new().pubkey();
|
||||||
let last_id = Hash::new(&to.as_ref());
|
let block_hash = Hash::new(&to.as_ref());
|
||||||
let tokens = 50;
|
let tokens = 50;
|
||||||
let req = DroneRequest::GetAirdrop {
|
let req = DroneRequest::GetAirdrop {
|
||||||
tokens,
|
tokens,
|
||||||
last_id,
|
block_hash,
|
||||||
to,
|
to,
|
||||||
};
|
};
|
||||||
let req = serialize(&req).unwrap();
|
let req = serialize(&req).unwrap();
|
||||||
|
@ -413,10 +413,10 @@ mod tests {
|
||||||
&[to],
|
&[to],
|
||||||
system_program::id(),
|
system_program::id(),
|
||||||
&expected_instruction,
|
&expected_instruction,
|
||||||
last_id,
|
block_hash,
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
expected_tx.sign(&[&keypair], last_id);
|
expected_tx.sign(&[&keypair], block_hash);
|
||||||
let expected_bytes = serialize(&expected_tx).unwrap();
|
let expected_bytes = serialize(&expected_tx).unwrap();
|
||||||
let mut expected_vec_with_length = vec![0; 2];
|
let mut expected_vec_with_length = vec![0; 2];
|
||||||
LittleEndian::write_u16(&mut expected_vec_with_length, expected_bytes.len() as u16);
|
LittleEndian::write_u16(&mut expected_vec_with_length, expected_bytes.len() as u16);
|
||||||
|
|
|
@ -11,7 +11,7 @@ fn test_local_drone() {
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let to = Keypair::new().pubkey();
|
let to = Keypair::new().pubkey();
|
||||||
let tokens = 50;
|
let tokens = 50;
|
||||||
let last_id = Hash::new(&to.as_ref());
|
let block_hash = Hash::new(&to.as_ref());
|
||||||
let expected_instruction = SystemInstruction::CreateAccount {
|
let expected_instruction = SystemInstruction::CreateAccount {
|
||||||
tokens,
|
tokens,
|
||||||
space: 0,
|
space: 0,
|
||||||
|
@ -22,15 +22,15 @@ fn test_local_drone() {
|
||||||
&[to],
|
&[to],
|
||||||
system_program::id(),
|
system_program::id(),
|
||||||
&expected_instruction,
|
&expected_instruction,
|
||||||
last_id,
|
block_hash,
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
expected_tx.sign(&[&keypair], last_id);
|
expected_tx.sign(&[&keypair], block_hash);
|
||||||
|
|
||||||
let (sender, receiver) = channel();
|
let (sender, receiver) = channel();
|
||||||
run_local_drone(keypair, sender);
|
run_local_drone(keypair, sender);
|
||||||
let drone_addr = receiver.recv().unwrap();
|
let drone_addr = receiver.recv().unwrap();
|
||||||
|
|
||||||
let result = request_airdrop_transaction(&drone_addr, &to, tokens, last_id);
|
let result = request_airdrop_transaction(&drone_addr, &to, tokens, block_hash);
|
||||||
assert_eq!(expected_tx, result.unwrap());
|
assert_eq!(expected_tx, result.unwrap());
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,10 +74,10 @@ fn create_and_fund_vote_account(
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
loop {
|
loop {
|
||||||
let last_id = client.get_recent_block_hash();
|
let block_hash = client.get_recent_block_hash();
|
||||||
info!("create_and_fund_vote_account last_id={:?}", last_id);
|
info!("create_and_fund_vote_account block_hash={:?}", block_hash);
|
||||||
let transaction =
|
let transaction =
|
||||||
VoteTransaction::fund_staking_account(node_keypair, vote_account, last_id, 1, 1);
|
VoteTransaction::fund_staking_account(node_keypair, vote_account, block_hash, 1, 1);
|
||||||
|
|
||||||
match client.transfer_signed(&transaction) {
|
match client.transfer_signed(&transaction) {
|
||||||
Ok(signature) => {
|
Ok(signature) => {
|
||||||
|
|
|
@ -38,7 +38,7 @@ fn nominal() {
|
||||||
let (genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(100, keypair.pubkey(), 50);
|
let (genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(100, keypair.pubkey(), 50);
|
||||||
let ticks_per_slot = genesis_block.ticks_per_slot;
|
let ticks_per_slot = genesis_block.ticks_per_slot;
|
||||||
|
|
||||||
let (ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
let (ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block);
|
||||||
let ticks = ticks_per_slot as usize;
|
let ticks = ticks_per_slot as usize;
|
||||||
|
|
||||||
// Basic validation
|
// Basic validation
|
||||||
|
|
|
@ -24,8 +24,8 @@ impl<'a> RewardsBank<'a> {
|
||||||
rewards_id: Pubkey,
|
rewards_id: Pubkey,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let last_id = self.bank.last_block_hash();
|
let block_hash = self.bank.last_block_hash();
|
||||||
let tx = RewardsTransaction::new_account(from_keypair, rewards_id, last_id, lamports, 0);
|
let tx = RewardsTransaction::new_account(from_keypair, rewards_id, block_hash, lamports, 0);
|
||||||
self.bank.process_transaction(&tx)
|
self.bank.process_transaction(&tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,24 +35,24 @@ impl<'a> RewardsBank<'a> {
|
||||||
vote_id: Pubkey,
|
vote_id: Pubkey,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let last_id = self.bank.last_block_hash();
|
let block_hash = self.bank.last_block_hash();
|
||||||
let tx = VoteTransaction::fund_staking_account(from_keypair, vote_id, last_id, lamports, 0);
|
let tx = VoteTransaction::fund_staking_account(from_keypair, vote_id, block_hash, lamports, 0);
|
||||||
self.bank.process_transaction(&tx)
|
self.bank.process_transaction(&tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn submit_vote(&self, vote_keypair: &Keypair, tick_height: u64) -> Result<VoteState> {
|
fn submit_vote(&self, vote_keypair: &Keypair, tick_height: u64) -> Result<VoteState> {
|
||||||
let last_id = self.bank.last_block_hash();
|
let block_hash = self.bank.last_block_hash();
|
||||||
let tx = VoteTransaction::new_vote(vote_keypair, tick_height, last_id, 0);
|
let tx = VoteTransaction::new_vote(vote_keypair, tick_height, block_hash, 0);
|
||||||
self.bank.process_transaction(&tx)?;
|
self.bank.process_transaction(&tx)?;
|
||||||
self.bank.register_tick(&hash(last_id.as_ref()));
|
self.bank.register_tick(&hash(block_hash.as_ref()));
|
||||||
|
|
||||||
let vote_account = self.bank.get_account(&vote_keypair.pubkey()).unwrap();
|
let vote_account = self.bank.get_account(&vote_keypair.pubkey()).unwrap();
|
||||||
Ok(VoteState::deserialize(&vote_account.userdata).unwrap())
|
Ok(VoteState::deserialize(&vote_account.userdata).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn redeem_credits(&self, rewards_id: Pubkey, vote_keypair: &Keypair) -> Result<VoteState> {
|
fn redeem_credits(&self, rewards_id: Pubkey, vote_keypair: &Keypair) -> Result<VoteState> {
|
||||||
let last_id = self.bank.last_block_hash();
|
let block_hash = self.bank.last_block_hash();
|
||||||
let tx = RewardsTransaction::new_redeem_credits(&vote_keypair, rewards_id, last_id, 0);
|
let tx = RewardsTransaction::new_redeem_credits(&vote_keypair, rewards_id, block_hash, 0);
|
||||||
self.bank.process_transaction(&tx)?;
|
self.bank.process_transaction(&tx)?;
|
||||||
let vote_account = self.bank.get_account(&vote_keypair.pubkey()).unwrap();
|
let vote_account = self.bank.get_account(&vote_keypair.pubkey()).unwrap();
|
||||||
Ok(VoteState::deserialize(&vote_account.userdata).unwrap())
|
Ok(VoteState::deserialize(&vote_account.userdata).unwrap())
|
||||||
|
|
|
@ -18,14 +18,14 @@ impl RewardsTransaction {
|
||||||
pub fn new_account(
|
pub fn new_account(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
rewards_id: Pubkey,
|
rewards_id: Pubkey,
|
||||||
last_id: Hash,
|
block_hash: Hash,
|
||||||
num_tokens: u64,
|
num_tokens: u64,
|
||||||
fee: u64,
|
fee: u64,
|
||||||
) -> Transaction {
|
) -> Transaction {
|
||||||
SystemTransaction::new_program_account(
|
SystemTransaction::new_program_account(
|
||||||
from_keypair,
|
from_keypair,
|
||||||
rewards_id,
|
rewards_id,
|
||||||
last_id,
|
block_hash,
|
||||||
num_tokens,
|
num_tokens,
|
||||||
RewardsState::max_size() as u64,
|
RewardsState::max_size() as u64,
|
||||||
id(),
|
id(),
|
||||||
|
@ -36,7 +36,7 @@ impl RewardsTransaction {
|
||||||
pub fn new_redeem_credits(
|
pub fn new_redeem_credits(
|
||||||
vote_keypair: &Keypair,
|
vote_keypair: &Keypair,
|
||||||
rewards_id: Pubkey,
|
rewards_id: Pubkey,
|
||||||
last_id: Hash,
|
block_hash: Hash,
|
||||||
fee: u64,
|
fee: u64,
|
||||||
) -> Transaction {
|
) -> Transaction {
|
||||||
let vote_id = vote_keypair.pubkey();
|
let vote_id = vote_keypair.pubkey();
|
||||||
|
@ -45,6 +45,6 @@ impl RewardsTransaction {
|
||||||
vote_id, rewards_id,
|
vote_id, rewards_id,
|
||||||
))
|
))
|
||||||
.push(VoteInstruction::new_clear_credits(vote_id))
|
.push(VoteInstruction::new_clear_credits(vote_id))
|
||||||
.sign(&[vote_keypair], last_id)
|
.sign(&[vote_keypair], block_hash)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,21 +46,21 @@ fn test_bank_storage() {
|
||||||
let jill = Keypair::new();
|
let jill = Keypair::new();
|
||||||
|
|
||||||
let x = 42;
|
let x = 42;
|
||||||
let last_id = genesis_block.hash();
|
let block_hash = genesis_block.hash();
|
||||||
let x2 = x * 2;
|
let x2 = x * 2;
|
||||||
let storage_block_hash = hash(&[x2]);
|
let storage_block_hash = hash(&[x2]);
|
||||||
|
|
||||||
bank.register_tick(&last_id);
|
bank.register_tick(&block_hash);
|
||||||
|
|
||||||
bank.transfer(10, &alice, jill.pubkey(), last_id).unwrap();
|
bank.transfer(10, &alice, jill.pubkey(), block_hash).unwrap();
|
||||||
|
|
||||||
bank.transfer(10, &alice, bob.pubkey(), last_id).unwrap();
|
bank.transfer(10, &alice, bob.pubkey(), block_hash).unwrap();
|
||||||
bank.transfer(10, &alice, jack.pubkey(), last_id).unwrap();
|
bank.transfer(10, &alice, jack.pubkey(), block_hash).unwrap();
|
||||||
|
|
||||||
let tx = SystemTransaction::new_program_account(
|
let tx = SystemTransaction::new_program_account(
|
||||||
&alice,
|
&alice,
|
||||||
bob.pubkey(),
|
bob.pubkey(),
|
||||||
last_id,
|
block_hash,
|
||||||
1,
|
1,
|
||||||
4 * 1024,
|
4 * 1024,
|
||||||
storage_program::id(),
|
storage_program::id(),
|
||||||
|
@ -72,7 +72,7 @@ fn test_bank_storage() {
|
||||||
let tx = StorageTransaction::new_advertise_recent_block_hash(
|
let tx = StorageTransaction::new_advertise_recent_block_hash(
|
||||||
&bob,
|
&bob,
|
||||||
storage_block_hash,
|
storage_block_hash,
|
||||||
last_id,
|
block_hash,
|
||||||
ENTRIES_PER_SEGMENT,
|
ENTRIES_PER_SEGMENT,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ fn test_bank_storage() {
|
||||||
//let tx = StorageTransaction::new_mining_proof(
|
//let tx = StorageTransaction::new_mining_proof(
|
||||||
// &jack,
|
// &jack,
|
||||||
// Hash::default(),
|
// Hash::default(),
|
||||||
// last_id,
|
// block_hash,
|
||||||
// entry_height,
|
// entry_height,
|
||||||
// Signature::default(),
|
// Signature::default(),
|
||||||
//);
|
//);
|
||||||
|
|
|
@ -26,16 +26,16 @@ impl<'a> VoteBank<'a> {
|
||||||
vote_id: Pubkey,
|
vote_id: Pubkey,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let last_id = self.bank.last_block_hash();
|
let block_hash = self.bank.last_block_hash();
|
||||||
let tx = VoteTransaction::fund_staking_account(from_keypair, vote_id, last_id, lamports, 0);
|
let tx = VoteTransaction::fund_staking_account(from_keypair, vote_id, block_hash, lamports, 0);
|
||||||
self.bank.process_transaction(&tx)
|
self.bank.process_transaction(&tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn submit_vote(&self, vote_keypair: &Keypair, tick_height: u64) -> Result<VoteState> {
|
fn submit_vote(&self, vote_keypair: &Keypair, tick_height: u64) -> Result<VoteState> {
|
||||||
let last_id = self.bank.last_block_hash();
|
let block_hash = self.bank.last_block_hash();
|
||||||
let tx = VoteTransaction::new_vote(vote_keypair, tick_height, last_id, 0);
|
let tx = VoteTransaction::new_vote(vote_keypair, tick_height, block_hash, 0);
|
||||||
self.bank.process_transaction(&tx)?;
|
self.bank.process_transaction(&tx)?;
|
||||||
self.bank.register_tick(&hash(last_id.as_ref()));
|
self.bank.register_tick(&hash(block_hash.as_ref()));
|
||||||
|
|
||||||
let vote_account = self.bank.get_account(&vote_keypair.pubkey()).unwrap();
|
let vote_account = self.bank.get_account(&vote_keypair.pubkey()).unwrap();
|
||||||
Ok(VoteState::deserialize(&vote_account.userdata).unwrap())
|
Ok(VoteState::deserialize(&vote_account.userdata).unwrap())
|
||||||
|
@ -71,7 +71,7 @@ fn test_vote_via_bank_with_no_signature() {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mallory_id = mallory_keypair.pubkey();
|
let mallory_id = mallory_keypair.pubkey();
|
||||||
let last_id = bank.last_block_hash();
|
let block_hash = bank.last_block_hash();
|
||||||
let vote_ix = BuilderInstruction::new(
|
let vote_ix = BuilderInstruction::new(
|
||||||
vote_program::id(),
|
vote_program::id(),
|
||||||
&VoteInstruction::Vote(Vote::new(0)),
|
&VoteInstruction::Vote(Vote::new(0)),
|
||||||
|
@ -84,7 +84,7 @@ fn test_vote_via_bank_with_no_signature() {
|
||||||
let tx = TransactionBuilder::default()
|
let tx = TransactionBuilder::default()
|
||||||
.push(SystemInstruction::new_move(mallory_id, vote_id, 1))
|
.push(SystemInstruction::new_move(mallory_id, vote_id, 1))
|
||||||
.push(vote_ix)
|
.push(vote_ix)
|
||||||
.sign(&[&mallory_keypair], last_id);
|
.sign(&[&mallory_keypair], block_hash);
|
||||||
|
|
||||||
let result = bank.process_transaction(&tx);
|
let result = bank.process_transaction(&tx);
|
||||||
|
|
||||||
|
|
|
@ -44,15 +44,15 @@ fn bench_sigs_bloom(bencher: &mut Bencher) {
|
||||||
// 1M TPS * 1s (length of block in sigs) == 1M items in filter
|
// 1M TPS * 1s (length of block in sigs) == 1M items in filter
|
||||||
// 1.0E-8 false positive rate
|
// 1.0E-8 false positive rate
|
||||||
// https://hur.st/bloomfilter/?n=1000000&p=1.0E-8&m=&k=
|
// https://hur.st/bloomfilter/?n=1000000&p=1.0E-8&m=&k=
|
||||||
let last_id = hash(Hash::default().as_ref());
|
let block_hash = hash(Hash::default().as_ref());
|
||||||
// eprintln!("last_id = {:?}", last_id);
|
// eprintln!("block_hash = {:?}", block_hash);
|
||||||
let keys = (0..27)
|
let keys = (0..27)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|i| last_id.hash_at_index(i))
|
.map(|i| block_hash.hash_at_index(i))
|
||||||
.collect();
|
.collect();
|
||||||
let mut sigs: Bloom<Signature> = Bloom::new(38_340_234, keys);
|
let mut sigs: Bloom<Signature> = Bloom::new(38_340_234, keys);
|
||||||
|
|
||||||
let mut id = last_id;
|
let mut id = block_hash;
|
||||||
let mut falses = 0;
|
let mut falses = 0;
|
||||||
let mut iterations = 0;
|
let mut iterations = 0;
|
||||||
bencher.iter(|| {
|
bencher.iter(|| {
|
||||||
|
@ -76,11 +76,11 @@ fn bench_sigs_bloom(bencher: &mut Bencher) {
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn bench_sigs_hashmap(bencher: &mut Bencher) {
|
fn bench_sigs_hashmap(bencher: &mut Bencher) {
|
||||||
// same structure as above, new
|
// same structure as above, new
|
||||||
let last_id = hash(Hash::default().as_ref());
|
let block_hash = hash(Hash::default().as_ref());
|
||||||
// eprintln!("last_id = {:?}", last_id);
|
// eprintln!("block_hash = {:?}", block_hash);
|
||||||
let mut sigs: HashSet<Signature> = HashSet::new();
|
let mut sigs: HashSet<Signature> = HashSet::new();
|
||||||
|
|
||||||
let mut id = last_id;
|
let mut id = block_hash;
|
||||||
let mut falses = 0;
|
let mut falses = 0;
|
||||||
let mut iterations = 0;
|
let mut iterations = 0;
|
||||||
bencher.iter(|| {
|
bencher.iter(|| {
|
||||||
|
|
|
@ -27,9 +27,9 @@ pub struct ErrorCounters {
|
||||||
pub account_not_found: usize,
|
pub account_not_found: usize,
|
||||||
pub account_in_use: usize,
|
pub account_in_use: usize,
|
||||||
pub account_loaded_twice: usize,
|
pub account_loaded_twice: usize,
|
||||||
pub last_id_not_found: usize,
|
pub block_hash_not_found: usize,
|
||||||
pub last_id_too_old: usize,
|
pub block_hash_too_old: usize,
|
||||||
pub reserve_last_id: usize,
|
pub reserve_block_hash: usize,
|
||||||
pub insufficient_funds: usize,
|
pub insufficient_funds: usize,
|
||||||
pub duplicate_signature: usize,
|
pub duplicate_signature: usize,
|
||||||
pub call_chain_too_deep: usize,
|
pub call_chain_too_deep: usize,
|
||||||
|
|
|
@ -426,7 +426,7 @@ impl Bank {
|
||||||
.zip(lock_results.into_iter())
|
.zip(lock_results.into_iter())
|
||||||
.map(|(tx, lock_res)| {
|
.map(|(tx, lock_res)| {
|
||||||
if lock_res.is_ok() && !hash_queue.check_entry_age(tx.recent_block_hash, max_age) {
|
if lock_res.is_ok() && !hash_queue.check_entry_age(tx.recent_block_hash, max_age) {
|
||||||
error_counters.reserve_last_id += 1;
|
error_counters.reserve_block_hash += 1;
|
||||||
Err(BankError::BlockHashNotFound)
|
Err(BankError::BlockHashNotFound)
|
||||||
} else {
|
} else {
|
||||||
lock_res
|
lock_res
|
||||||
|
@ -523,16 +523,16 @@ impl Bank {
|
||||||
.increment_transaction_count(self.accounts_id, tx_count);
|
.increment_transaction_count(self.accounts_id, tx_count);
|
||||||
|
|
||||||
inc_new_counter_info!("bank-process_transactions-txs", tx_count);
|
inc_new_counter_info!("bank-process_transactions-txs", tx_count);
|
||||||
if 0 != error_counters.last_id_not_found {
|
if 0 != error_counters.block_hash_not_found {
|
||||||
inc_new_counter_info!(
|
inc_new_counter_info!(
|
||||||
"bank-process_transactions-error-last_id_not_found",
|
"bank-process_transactions-error-block_hash_not_found",
|
||||||
error_counters.last_id_not_found
|
error_counters.block_hash_not_found
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if 0 != error_counters.reserve_last_id {
|
if 0 != error_counters.reserve_block_hash {
|
||||||
inc_new_counter_info!(
|
inc_new_counter_info!(
|
||||||
"bank-process_transactions-error-reserve_last_id",
|
"bank-process_transactions-error-reserve_block_hash",
|
||||||
error_counters.reserve_last_id
|
error_counters.reserve_block_hash
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if 0 != error_counters.duplicate_signature {
|
if 0 != error_counters.duplicate_signature {
|
||||||
|
@ -633,15 +633,15 @@ impl Bank {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create, sign, and process a Transaction from `keypair` to `to` of
|
/// Create, sign, and process a Transaction from `keypair` to `to` of
|
||||||
/// `n` tokens where `last_id` is the last Entry ID observed by the client.
|
/// `n` tokens where `block_hash` is the last Entry ID observed by the client.
|
||||||
pub fn transfer(
|
pub fn transfer(
|
||||||
&self,
|
&self,
|
||||||
n: u64,
|
n: u64,
|
||||||
keypair: &Keypair,
|
keypair: &Keypair,
|
||||||
to: Pubkey,
|
to: Pubkey,
|
||||||
last_id: Hash,
|
block_hash: Hash,
|
||||||
) -> Result<Signature> {
|
) -> Result<Signature> {
|
||||||
let tx = SystemTransaction::new_account(keypair, to, n, last_id, 0);
|
let tx = SystemTransaction::new_account(keypair, to, n, block_hash, 0);
|
||||||
let signature = tx.signatures[0];
|
let signature = tx.signatures[0];
|
||||||
self.process_transaction(&tx).map(|_| signature)
|
self.process_transaction(&tx).map(|_| signature)
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,8 +31,8 @@ impl<T: Clone> Default for StatusCache<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Clone> StatusCache<T> {
|
impl<T: Clone> StatusCache<T> {
|
||||||
pub fn new(last_id: &Hash) -> Self {
|
pub fn new(block_hash: &Hash) -> Self {
|
||||||
let keys = (0..27).map(|i| last_id.hash_at_index(i)).collect();
|
let keys = (0..27).map(|i| block_hash.hash_at_index(i)).collect();
|
||||||
Self {
|
Self {
|
||||||
signatures: Bloom::new(38_340_234, keys),
|
signatures: Bloom::new(38_340_234, keys),
|
||||||
failures: HashMap::new(),
|
failures: HashMap::new(),
|
||||||
|
@ -118,8 +118,8 @@ impl<T: Clone> StatusCache<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Crate a new cache, pushing the old cache into the merged queue
|
/// Crate a new cache, pushing the old cache into the merged queue
|
||||||
pub fn new_cache(&mut self, last_id: &Hash) {
|
pub fn new_cache(&mut self, block_hash: &Hash) {
|
||||||
let mut old = Self::new(last_id);
|
let mut old = Self::new(block_hash);
|
||||||
std::mem::swap(&mut old.signatures, &mut self.signatures);
|
std::mem::swap(&mut old.signatures, &mut self.signatures);
|
||||||
std::mem::swap(&mut old.failures, &mut self.failures);
|
std::mem::swap(&mut old.failures, &mut self.failures);
|
||||||
assert!(old.merges.is_empty());
|
assert!(old.merges.is_empty());
|
||||||
|
@ -175,8 +175,8 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_has_signature() {
|
fn test_has_signature() {
|
||||||
let sig = Signature::default();
|
let sig = Signature::default();
|
||||||
let last_id = hash(Hash::default().as_ref());
|
let block_hash = hash(Hash::default().as_ref());
|
||||||
let mut status_cache = BankStatusCache::new(&last_id);
|
let mut status_cache = BankStatusCache::new(&block_hash);
|
||||||
assert_eq!(status_cache.has_signature(&sig), false);
|
assert_eq!(status_cache.has_signature(&sig), false);
|
||||||
assert_eq!(status_cache.get_signature_status(&sig), None);
|
assert_eq!(status_cache.get_signature_status(&sig), None);
|
||||||
status_cache.add(&sig);
|
status_cache.add(&sig);
|
||||||
|
@ -187,12 +187,12 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_has_signature_checkpoint() {
|
fn test_has_signature_checkpoint() {
|
||||||
let sig = Signature::default();
|
let sig = Signature::default();
|
||||||
let last_id = hash(Hash::default().as_ref());
|
let block_hash = hash(Hash::default().as_ref());
|
||||||
let mut first = BankStatusCache::new(&last_id);
|
let mut first = BankStatusCache::new(&block_hash);
|
||||||
first.add(&sig);
|
first.add(&sig);
|
||||||
assert_eq!(first.get_signature_status(&sig), Some(Ok(())));
|
assert_eq!(first.get_signature_status(&sig), Some(Ok(())));
|
||||||
let last_id = hash(last_id.as_ref());
|
let block_hash = hash(block_hash.as_ref());
|
||||||
let second = StatusCache::new(&last_id);
|
let second = StatusCache::new(&block_hash);
|
||||||
let checkpoints = [&second, &first];
|
let checkpoints = [&second, &first];
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
BankStatusCache::get_signature_status_all(&checkpoints, &sig),
|
BankStatusCache::get_signature_status_all(&checkpoints, &sig),
|
||||||
|
@ -204,12 +204,12 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_new_cache() {
|
fn test_new_cache() {
|
||||||
let sig = Signature::default();
|
let sig = Signature::default();
|
||||||
let last_id = hash(Hash::default().as_ref());
|
let block_hash = hash(Hash::default().as_ref());
|
||||||
let mut first = BankStatusCache::new(&last_id);
|
let mut first = BankStatusCache::new(&block_hash);
|
||||||
first.add(&sig);
|
first.add(&sig);
|
||||||
assert_eq!(first.get_signature_status(&sig), Some(Ok(())));
|
assert_eq!(first.get_signature_status(&sig), Some(Ok(())));
|
||||||
let last_id = hash(last_id.as_ref());
|
let block_hash = hash(block_hash.as_ref());
|
||||||
first.new_cache(&last_id);
|
first.new_cache(&block_hash);
|
||||||
assert_eq!(first.get_signature_status(&sig), Some(Ok(())));
|
assert_eq!(first.get_signature_status(&sig), Some(Ok(())));
|
||||||
assert!(first.has_signature(&sig));
|
assert!(first.has_signature(&sig));
|
||||||
first.clear();
|
first.clear();
|
||||||
|
@ -220,13 +220,13 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_new_cache_full() {
|
fn test_new_cache_full() {
|
||||||
let sig = Signature::default();
|
let sig = Signature::default();
|
||||||
let last_id = hash(Hash::default().as_ref());
|
let block_hash = hash(Hash::default().as_ref());
|
||||||
let mut first = BankStatusCache::new(&last_id);
|
let mut first = BankStatusCache::new(&block_hash);
|
||||||
first.add(&sig);
|
first.add(&sig);
|
||||||
assert_eq!(first.get_signature_status(&sig), Some(Ok(())));
|
assert_eq!(first.get_signature_status(&sig), Some(Ok(())));
|
||||||
for _ in 0..(MAX_CACHE_ENTRIES + 1) {
|
for _ in 0..(MAX_CACHE_ENTRIES + 1) {
|
||||||
let last_id = hash(last_id.as_ref());
|
let block_hash = hash(block_hash.as_ref());
|
||||||
first.new_cache(&last_id);
|
first.new_cache(&block_hash);
|
||||||
}
|
}
|
||||||
assert_eq!(first.get_signature_status(&sig), None);
|
assert_eq!(first.get_signature_status(&sig), None);
|
||||||
assert!(!first.has_signature(&sig));
|
assert!(!first.has_signature(&sig));
|
||||||
|
@ -235,17 +235,17 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_status_cache_squash_has_signature() {
|
fn test_status_cache_squash_has_signature() {
|
||||||
let sig = Signature::default();
|
let sig = Signature::default();
|
||||||
let last_id = hash(Hash::default().as_ref());
|
let block_hash = hash(Hash::default().as_ref());
|
||||||
let mut first = BankStatusCache::new(&last_id);
|
let mut first = BankStatusCache::new(&block_hash);
|
||||||
first.add(&sig);
|
first.add(&sig);
|
||||||
assert_eq!(first.get_signature_status(&sig), Some(Ok(())));
|
assert_eq!(first.get_signature_status(&sig), Some(Ok(())));
|
||||||
|
|
||||||
// give first a merge
|
// give first a merge
|
||||||
let last_id = hash(last_id.as_ref());
|
let block_hash = hash(block_hash.as_ref());
|
||||||
first.new_cache(&last_id);
|
first.new_cache(&block_hash);
|
||||||
|
|
||||||
let last_id = hash(last_id.as_ref());
|
let block_hash = hash(block_hash.as_ref());
|
||||||
let mut second = BankStatusCache::new(&last_id);
|
let mut second = BankStatusCache::new(&block_hash);
|
||||||
|
|
||||||
second.squash(&[&first]);
|
second.squash(&[&first]);
|
||||||
|
|
||||||
|
@ -256,21 +256,21 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
#[ignore] // takes a lot of time or RAM or both..
|
#[ignore] // takes a lot of time or RAM or both..
|
||||||
fn test_status_cache_squash_overflow() {
|
fn test_status_cache_squash_overflow() {
|
||||||
let mut last_id = hash(Hash::default().as_ref());
|
let mut block_hash = hash(Hash::default().as_ref());
|
||||||
let mut cache = BankStatusCache::new(&last_id);
|
let mut cache = BankStatusCache::new(&block_hash);
|
||||||
|
|
||||||
let parents: Vec<_> = (0..MAX_CACHE_ENTRIES)
|
let parents: Vec<_> = (0..MAX_CACHE_ENTRIES)
|
||||||
.map(|_| {
|
.map(|_| {
|
||||||
last_id = hash(last_id.as_ref());
|
block_hash = hash(block_hash.as_ref());
|
||||||
|
|
||||||
BankStatusCache::new(&last_id)
|
BankStatusCache::new(&block_hash)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut parents_refs: Vec<_> = parents.iter().collect();
|
let mut parents_refs: Vec<_> = parents.iter().collect();
|
||||||
|
|
||||||
last_id = hash(Hash::default().as_ref());
|
block_hash = hash(Hash::default().as_ref());
|
||||||
let mut root = BankStatusCache::new(&last_id);
|
let mut root = BankStatusCache::new(&block_hash);
|
||||||
|
|
||||||
let sig = Signature::default();
|
let sig = Signature::default();
|
||||||
root.add(&sig);
|
root.add(&sig);
|
||||||
|
@ -290,8 +290,8 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_failure_status() {
|
fn test_failure_status() {
|
||||||
let sig = Signature::default();
|
let sig = Signature::default();
|
||||||
let last_id = hash(Hash::default().as_ref());
|
let block_hash = hash(Hash::default().as_ref());
|
||||||
let mut first = StatusCache::new(&last_id);
|
let mut first = StatusCache::new(&block_hash);
|
||||||
first.add(&sig);
|
first.add(&sig);
|
||||||
first.save_failure_status(&sig, BankError::DuplicateSignature);
|
first.save_failure_status(&sig, BankError::DuplicateSignature);
|
||||||
assert_eq!(first.has_signature(&sig), true);
|
assert_eq!(first.has_signature(&sig), true);
|
||||||
|
@ -304,8 +304,8 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_clear_signatures() {
|
fn test_clear_signatures() {
|
||||||
let sig = Signature::default();
|
let sig = Signature::default();
|
||||||
let last_id = hash(Hash::default().as_ref());
|
let block_hash = hash(Hash::default().as_ref());
|
||||||
let mut first = StatusCache::new(&last_id);
|
let mut first = StatusCache::new(&block_hash);
|
||||||
first.add(&sig);
|
first.add(&sig);
|
||||||
assert_eq!(first.has_signature(&sig), true);
|
assert_eq!(first.has_signature(&sig), true);
|
||||||
first.save_failure_status(&sig, BankError::DuplicateSignature);
|
first.save_failure_status(&sig, BankError::DuplicateSignature);
|
||||||
|
@ -320,11 +320,11 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_clear_signatures_all() {
|
fn test_clear_signatures_all() {
|
||||||
let sig = Signature::default();
|
let sig = Signature::default();
|
||||||
let last_id = hash(Hash::default().as_ref());
|
let block_hash = hash(Hash::default().as_ref());
|
||||||
let mut first = StatusCache::new(&last_id);
|
let mut first = StatusCache::new(&block_hash);
|
||||||
first.add(&sig);
|
first.add(&sig);
|
||||||
assert_eq!(first.has_signature(&sig), true);
|
assert_eq!(first.has_signature(&sig), true);
|
||||||
let mut second = StatusCache::new(&last_id);
|
let mut second = StatusCache::new(&block_hash);
|
||||||
let mut checkpoints = [&mut second, &mut first];
|
let mut checkpoints = [&mut second, &mut first];
|
||||||
BankStatusCache::clear_all(&mut checkpoints);
|
BankStatusCache::clear_all(&mut checkpoints);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
|
@ -44,7 +44,7 @@ fn test_replicator_startup_basic() {
|
||||||
|
|
||||||
let (genesis_block, mint_keypair) =
|
let (genesis_block, mint_keypair) =
|
||||||
GenesisBlock::new_with_leader(1_000_000_000, leader_info.id, 42);
|
GenesisBlock::new_with_leader(1_000_000_000, leader_info.id, 42);
|
||||||
let (leader_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
let (leader_ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block);
|
||||||
|
|
||||||
let validator_ledger_path = tmp_copy_blocktree!(&leader_ledger_path);
|
let validator_ledger_path = tmp_copy_blocktree!(&leader_ledger_path);
|
||||||
|
|
||||||
|
@ -72,11 +72,11 @@ fn test_replicator_startup_basic() {
|
||||||
let voting_keypair = VotingKeypair::new_local(&validator_keypair);
|
let voting_keypair = VotingKeypair::new_local(&validator_keypair);
|
||||||
|
|
||||||
let mut leader_client = mk_client(&leader_info);
|
let mut leader_client = mk_client(&leader_info);
|
||||||
let last_id = leader_client.get_recent_block_hash();
|
let block_hash = leader_client.get_recent_block_hash();
|
||||||
debug!("last_id: {:?}", last_id);
|
debug!("block_hash: {:?}", block_hash);
|
||||||
|
|
||||||
leader_client
|
leader_client
|
||||||
.transfer(10, &mint_keypair, validator_keypair.pubkey(), &last_id)
|
.transfer(10, &mint_keypair, validator_keypair.pubkey(), &block_hash)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let validator_node = Node::new_localhost_with_pubkey(validator_keypair.pubkey());
|
let validator_node = Node::new_localhost_with_pubkey(validator_keypair.pubkey());
|
||||||
|
@ -98,9 +98,9 @@ fn test_replicator_startup_basic() {
|
||||||
info!("starting transfers..");
|
info!("starting transfers..");
|
||||||
for i in 0..64 {
|
for i in 0..64 {
|
||||||
debug!("transfer {}", i);
|
debug!("transfer {}", i);
|
||||||
let last_id = leader_client.get_recent_block_hash();
|
let block_hash = leader_client.get_recent_block_hash();
|
||||||
let mut transaction =
|
let mut transaction =
|
||||||
SystemTransaction::new_account(&mint_keypair, bob.pubkey(), 1, last_id, 0);
|
SystemTransaction::new_account(&mint_keypair, bob.pubkey(), 1, block_hash, 0);
|
||||||
leader_client
|
leader_client
|
||||||
.retry_transfer(&mint_keypair, &mut transaction, 5)
|
.retry_transfer(&mint_keypair, &mut transaction, 5)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -116,13 +116,13 @@ fn test_replicator_startup_basic() {
|
||||||
|
|
||||||
info!("giving replicator tokens..");
|
info!("giving replicator tokens..");
|
||||||
|
|
||||||
let last_id = leader_client.get_recent_block_hash();
|
let block_hash = leader_client.get_recent_block_hash();
|
||||||
// Give the replicator some tokens
|
// Give the replicator some tokens
|
||||||
let mut tx = SystemTransaction::new_account(
|
let mut tx = SystemTransaction::new_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
replicator_keypair.pubkey(),
|
replicator_keypair.pubkey(),
|
||||||
1,
|
1,
|
||||||
last_id,
|
block_hash,
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
leader_client
|
leader_client
|
||||||
|
@ -238,7 +238,7 @@ fn test_replicator_startup_leader_hang() {
|
||||||
|
|
||||||
let leader_ledger_path = "replicator_test_leader_ledger";
|
let leader_ledger_path = "replicator_test_leader_ledger";
|
||||||
let (genesis_block, _mint_keypair) = GenesisBlock::new(10_000);
|
let (genesis_block, _mint_keypair) = GenesisBlock::new(10_000);
|
||||||
let (replicator_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
let (replicator_ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block);
|
||||||
|
|
||||||
{
|
{
|
||||||
let replicator_keypair = Keypair::new();
|
let replicator_keypair = Keypair::new();
|
||||||
|
@ -275,13 +275,13 @@ fn test_replicator_startup_ledger_hang() {
|
||||||
|
|
||||||
let (genesis_block, _mint_keypair) =
|
let (genesis_block, _mint_keypair) =
|
||||||
GenesisBlock::new_with_leader(100, leader_keypair.pubkey(), 42);
|
GenesisBlock::new_with_leader(100, leader_keypair.pubkey(), 42);
|
||||||
let (replicator_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
let (replicator_ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block);
|
||||||
|
|
||||||
info!("starting leader node");
|
info!("starting leader node");
|
||||||
let leader_node = Node::new_localhost_with_pubkey(leader_keypair.pubkey());
|
let leader_node = Node::new_localhost_with_pubkey(leader_keypair.pubkey());
|
||||||
let leader_info = leader_node.info.clone();
|
let leader_info = leader_node.info.clone();
|
||||||
|
|
||||||
let (leader_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
let (leader_ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block);
|
||||||
let validator_ledger_path = tmp_copy_blocktree!(&leader_ledger_path);
|
let validator_ledger_path = tmp_copy_blocktree!(&leader_ledger_path);
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -36,13 +36,13 @@ fn test_rpc_send_tx() {
|
||||||
.send()
|
.send()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let json: Value = serde_json::from_str(&response.text().unwrap()).unwrap();
|
let json: Value = serde_json::from_str(&response.text().unwrap()).unwrap();
|
||||||
let last_id_vec = bs58::decode(json["result"].as_str().unwrap())
|
let block_hash_vec = bs58::decode(json["result"].as_str().unwrap())
|
||||||
.into_vec()
|
.into_vec()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let last_id = Hash::new(&last_id_vec);
|
let block_hash = Hash::new(&block_hash_vec);
|
||||||
|
|
||||||
info!("last_id: {:?}", last_id);
|
info!("block_hash: {:?}", block_hash);
|
||||||
let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, last_id, 0);
|
let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, block_hash, 0);
|
||||||
let serial_tx = serialize(&tx).unwrap();
|
let serial_tx = serialize(&tx).unwrap();
|
||||||
|
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
|
|
|
@ -86,7 +86,7 @@ fn test_replay() {
|
||||||
let tvu_addr = target1.info.tvu;
|
let tvu_addr = target1.info.tvu;
|
||||||
|
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
let last_id = bank.last_block_hash();
|
let block_hash = bank.last_block_hash();
|
||||||
let bank_forks = BankForks::new(0, bank);
|
let bank_forks = BankForks::new(0, bank);
|
||||||
let bank_forks_info = vec![BankForksInfo {
|
let bank_forks_info = vec![BankForksInfo {
|
||||||
bank_id: 0,
|
bank_id: 0,
|
||||||
|
@ -138,7 +138,7 @@ fn test_replay() {
|
||||||
let num_transfers = 10;
|
let num_transfers = 10;
|
||||||
let mut transfer_amount = 501;
|
let mut transfer_amount = 501;
|
||||||
let bob_keypair = Keypair::new();
|
let bob_keypair = Keypair::new();
|
||||||
let mut cur_hash = last_id;
|
let mut cur_hash = block_hash;
|
||||||
for i in 0..num_transfers {
|
for i in 0..num_transfers {
|
||||||
let entry0 = next_entry_mut(&mut cur_hash, i, vec![]);
|
let entry0 = next_entry_mut(&mut cur_hash, i, vec![]);
|
||||||
let entry_tick0 = next_entry_mut(&mut cur_hash, i + 1, vec![]);
|
let entry_tick0 = next_entry_mut(&mut cur_hash, i + 1, vec![]);
|
||||||
|
@ -147,7 +147,7 @@ fn test_replay() {
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
bob_keypair.pubkey(),
|
bob_keypair.pubkey(),
|
||||||
transfer_amount,
|
transfer_amount,
|
||||||
last_id,
|
block_hash,
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
let entry_tick1 = next_entry_mut(&mut cur_hash, i + 1, vec![]);
|
let entry_tick1 = next_entry_mut(&mut cur_hash, i + 1, vec![]);
|
||||||
|
|
|
@ -401,7 +401,7 @@ fn process_deploy(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let last_id = get_recent_block_hash(&rpc_client)?;
|
let block_hash = get_recent_block_hash(&rpc_client)?;
|
||||||
let program_id = Keypair::new();
|
let program_id = Keypair::new();
|
||||||
let mut file = File::open(program_location).map_err(|err| {
|
let mut file = File::open(program_location).map_err(|err| {
|
||||||
WalletError::DynamicProgramError(
|
WalletError::DynamicProgramError(
|
||||||
|
@ -418,7 +418,7 @@ fn process_deploy(
|
||||||
let mut tx = SystemTransaction::new_program_account(
|
let mut tx = SystemTransaction::new_program_account(
|
||||||
&config.id,
|
&config.id,
|
||||||
program_id.pubkey(),
|
program_id.pubkey(),
|
||||||
last_id,
|
block_hash,
|
||||||
1,
|
1,
|
||||||
program_userdata.len() as u64,
|
program_userdata.len() as u64,
|
||||||
bpf_loader::id(),
|
bpf_loader::id(),
|
||||||
|
@ -439,7 +439,7 @@ fn process_deploy(
|
||||||
bpf_loader::id(),
|
bpf_loader::id(),
|
||||||
(i * USERDATA_CHUNK_SIZE) as u32,
|
(i * USERDATA_CHUNK_SIZE) as u32,
|
||||||
chunk.to_vec(),
|
chunk.to_vec(),
|
||||||
last_id,
|
block_hash,
|
||||||
0,
|
0,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -447,7 +447,7 @@ fn process_deploy(
|
||||||
send_and_confirm_transactions(&rpc_client, write_transactions, &program_id)?;
|
send_and_confirm_transactions(&rpc_client, write_transactions, &program_id)?;
|
||||||
|
|
||||||
trace!("Finalizing program account");
|
trace!("Finalizing program account");
|
||||||
let mut tx = LoaderTransaction::new_finalize(&program_id, bpf_loader::id(), last_id, 0);
|
let mut tx = LoaderTransaction::new_finalize(&program_id, bpf_loader::id(), block_hash, 0);
|
||||||
send_and_confirm_transaction(&rpc_client, &mut tx, &program_id).map_err(|_| {
|
send_and_confirm_transaction(&rpc_client, &mut tx, &program_id).map_err(|_| {
|
||||||
WalletError::DynamicProgramError("Program finalize transaction failed".to_string())
|
WalletError::DynamicProgramError("Program finalize transaction failed".to_string())
|
||||||
})?;
|
})?;
|
||||||
|
@ -468,10 +468,10 @@ fn process_pay(
|
||||||
witnesses: &Option<Vec<Pubkey>>,
|
witnesses: &Option<Vec<Pubkey>>,
|
||||||
cancelable: Option<Pubkey>,
|
cancelable: Option<Pubkey>,
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
let last_id = get_recent_block_hash(&rpc_client)?;
|
let block_hash = get_recent_block_hash(&rpc_client)?;
|
||||||
|
|
||||||
if timestamp == None && *witnesses == None {
|
if timestamp == None && *witnesses == None {
|
||||||
let mut tx = SystemTransaction::new_account(&config.id, to, tokens, last_id, 0);
|
let mut tx = SystemTransaction::new_account(&config.id, to, tokens, block_hash, 0);
|
||||||
let signature_str = send_and_confirm_transaction(&rpc_client, &mut tx, &config.id)?;
|
let signature_str = send_and_confirm_transaction(&rpc_client, &mut tx, &config.id)?;
|
||||||
Ok(signature_str.to_string())
|
Ok(signature_str.to_string())
|
||||||
} else if *witnesses == None {
|
} else if *witnesses == None {
|
||||||
|
@ -489,7 +489,7 @@ fn process_pay(
|
||||||
let mut tx = SystemTransaction::new_program_account(
|
let mut tx = SystemTransaction::new_program_account(
|
||||||
&config.id,
|
&config.id,
|
||||||
contract_funds.pubkey(),
|
contract_funds.pubkey(),
|
||||||
last_id,
|
block_hash,
|
||||||
tokens,
|
tokens,
|
||||||
0,
|
0,
|
||||||
budget_program_id,
|
budget_program_id,
|
||||||
|
@ -501,7 +501,7 @@ fn process_pay(
|
||||||
let mut tx = SystemTransaction::new_program_account(
|
let mut tx = SystemTransaction::new_program_account(
|
||||||
&config.id,
|
&config.id,
|
||||||
contract_state.pubkey(),
|
contract_state.pubkey(),
|
||||||
last_id,
|
block_hash,
|
||||||
1,
|
1,
|
||||||
196,
|
196,
|
||||||
budget_program_id,
|
budget_program_id,
|
||||||
|
@ -518,7 +518,7 @@ fn process_pay(
|
||||||
dt_pubkey,
|
dt_pubkey,
|
||||||
cancelable,
|
cancelable,
|
||||||
tokens,
|
tokens,
|
||||||
last_id,
|
block_hash,
|
||||||
);
|
);
|
||||||
let signature_str = send_and_confirm_transaction(&rpc_client, &mut tx, &config.id)?;
|
let signature_str = send_and_confirm_transaction(&rpc_client, &mut tx, &config.id)?;
|
||||||
|
|
||||||
|
@ -528,7 +528,7 @@ fn process_pay(
|
||||||
})
|
})
|
||||||
.to_string())
|
.to_string())
|
||||||
} else if timestamp == None {
|
} else if timestamp == None {
|
||||||
let last_id = get_recent_block_hash(&rpc_client)?;
|
let block_hash = get_recent_block_hash(&rpc_client)?;
|
||||||
|
|
||||||
let witness = if let Some(ref witness_vec) = *witnesses {
|
let witness = if let Some(ref witness_vec) = *witnesses {
|
||||||
witness_vec[0]
|
witness_vec[0]
|
||||||
|
@ -546,7 +546,7 @@ fn process_pay(
|
||||||
let mut tx = SystemTransaction::new_program_account(
|
let mut tx = SystemTransaction::new_program_account(
|
||||||
&config.id,
|
&config.id,
|
||||||
contract_funds.pubkey(),
|
contract_funds.pubkey(),
|
||||||
last_id,
|
block_hash,
|
||||||
tokens,
|
tokens,
|
||||||
0,
|
0,
|
||||||
budget_program_id,
|
budget_program_id,
|
||||||
|
@ -558,7 +558,7 @@ fn process_pay(
|
||||||
let mut tx = SystemTransaction::new_program_account(
|
let mut tx = SystemTransaction::new_program_account(
|
||||||
&config.id,
|
&config.id,
|
||||||
contract_state.pubkey(),
|
contract_state.pubkey(),
|
||||||
last_id,
|
block_hash,
|
||||||
1,
|
1,
|
||||||
196,
|
196,
|
||||||
budget_program_id,
|
budget_program_id,
|
||||||
|
@ -574,7 +574,7 @@ fn process_pay(
|
||||||
witness,
|
witness,
|
||||||
cancelable,
|
cancelable,
|
||||||
tokens,
|
tokens,
|
||||||
last_id,
|
block_hash,
|
||||||
);
|
);
|
||||||
let signature_str = send_and_confirm_transaction(&rpc_client, &mut tx, &config.id)?;
|
let signature_str = send_and_confirm_transaction(&rpc_client, &mut tx, &config.id)?;
|
||||||
|
|
||||||
|
@ -589,8 +589,8 @@ fn process_pay(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_cancel(rpc_client: &RpcClient, config: &WalletConfig, pubkey: Pubkey) -> ProcessResult {
|
fn process_cancel(rpc_client: &RpcClient, config: &WalletConfig, pubkey: Pubkey) -> ProcessResult {
|
||||||
let last_id = get_recent_block_hash(&rpc_client)?;
|
let block_hash = get_recent_block_hash(&rpc_client)?;
|
||||||
let mut tx = BudgetTransaction::new_signature(&config.id, pubkey, config.id.pubkey(), last_id);
|
let mut tx = BudgetTransaction::new_signature(&config.id, pubkey, config.id.pubkey(), block_hash);
|
||||||
let signature_str = send_and_confirm_transaction(&rpc_client, &mut tx, &config.id)?;
|
let signature_str = send_and_confirm_transaction(&rpc_client, &mut tx, &config.id)?;
|
||||||
Ok(signature_str.to_string())
|
Ok(signature_str.to_string())
|
||||||
}
|
}
|
||||||
|
@ -621,9 +621,9 @@ fn process_time_elapsed(
|
||||||
request_and_confirm_airdrop(&rpc_client, &drone_addr, &config.id, 1)?;
|
request_and_confirm_airdrop(&rpc_client, &drone_addr, &config.id, 1)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let last_id = get_recent_block_hash(&rpc_client)?;
|
let block_hash = get_recent_block_hash(&rpc_client)?;
|
||||||
|
|
||||||
let mut tx = BudgetTransaction::new_timestamp(&config.id, pubkey, to, dt, last_id);
|
let mut tx = BudgetTransaction::new_timestamp(&config.id, pubkey, to, dt, block_hash);
|
||||||
let signature_str = send_and_confirm_transaction(&rpc_client, &mut tx, &config.id)?;
|
let signature_str = send_and_confirm_transaction(&rpc_client, &mut tx, &config.id)?;
|
||||||
|
|
||||||
Ok(signature_str.to_string())
|
Ok(signature_str.to_string())
|
||||||
|
@ -642,8 +642,8 @@ fn process_witness(
|
||||||
request_and_confirm_airdrop(&rpc_client, &drone_addr, &config.id, 1)?;
|
request_and_confirm_airdrop(&rpc_client, &drone_addr, &config.id, 1)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let last_id = get_recent_block_hash(&rpc_client)?;
|
let block_hash = get_recent_block_hash(&rpc_client)?;
|
||||||
let mut tx = BudgetTransaction::new_signature(&config.id, pubkey, to, last_id);
|
let mut tx = BudgetTransaction::new_signature(&config.id, pubkey, to, block_hash);
|
||||||
let signature_str = send_and_confirm_transaction(&rpc_client, &mut tx, &config.id)?;
|
let signature_str = send_and_confirm_transaction(&rpc_client, &mut tx, &config.id)?;
|
||||||
|
|
||||||
Ok(signature_str.to_string())
|
Ok(signature_str.to_string())
|
||||||
|
@ -717,41 +717,41 @@ fn get_recent_block_hash(rpc_client: &RpcClient) -> Result<Hash, Box<dyn error::
|
||||||
let result = rpc_client.retry_make_rpc_request(1, &RpcRequest::GetLastId, None, 5)?;
|
let result = rpc_client.retry_make_rpc_request(1, &RpcRequest::GetLastId, None, 5)?;
|
||||||
if result.as_str().is_none() {
|
if result.as_str().is_none() {
|
||||||
Err(WalletError::RpcRequestError(
|
Err(WalletError::RpcRequestError(
|
||||||
"Received bad last_id".to_string(),
|
"Received bad block_hash".to_string(),
|
||||||
))?
|
))?
|
||||||
}
|
}
|
||||||
let last_id_str = result.as_str().unwrap();
|
let block_hash_str = result.as_str().unwrap();
|
||||||
let last_id_vec = bs58::decode(last_id_str)
|
let block_hash_vec = bs58::decode(block_hash_str)
|
||||||
.into_vec()
|
.into_vec()
|
||||||
.map_err(|_| WalletError::RpcRequestError("Received bad last_id".to_string()))?;
|
.map_err(|_| WalletError::RpcRequestError("Received bad block_hash".to_string()))?;
|
||||||
Ok(Hash::new(&last_id_vec))
|
Ok(Hash::new(&block_hash_vec))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_next_last_id(
|
fn get_next_block_hash(
|
||||||
rpc_client: &RpcClient,
|
rpc_client: &RpcClient,
|
||||||
previous_last_id: &Hash,
|
previous_block_hash: &Hash,
|
||||||
) -> Result<Hash, Box<dyn error::Error>> {
|
) -> Result<Hash, Box<dyn error::Error>> {
|
||||||
let mut next_last_id_retries = 3;
|
let mut next_block_hash_retries = 3;
|
||||||
loop {
|
loop {
|
||||||
let next_last_id = get_recent_block_hash(rpc_client)?;
|
let next_block_hash = get_recent_block_hash(rpc_client)?;
|
||||||
if cfg!(not(test)) {
|
if cfg!(not(test)) {
|
||||||
if next_last_id != *previous_last_id {
|
if next_block_hash != *previous_block_hash {
|
||||||
return Ok(next_last_id);
|
return Ok(next_block_hash);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// When using MockRpcClient, get_recent_block_hash() returns a constant value
|
// When using MockRpcClient, get_recent_block_hash() returns a constant value
|
||||||
return Ok(next_last_id);
|
return Ok(next_block_hash);
|
||||||
}
|
}
|
||||||
if next_last_id_retries == 0 {
|
if next_block_hash_retries == 0 {
|
||||||
Err(WalletError::RpcRequestError(
|
Err(WalletError::RpcRequestError(
|
||||||
format!(
|
format!(
|
||||||
"Unable to fetch new last_id, last_id stuck at {:?}",
|
"Unable to fetch new block_hash, block_hash stuck at {:?}",
|
||||||
next_last_id
|
next_block_hash
|
||||||
)
|
)
|
||||||
.to_string(),
|
.to_string(),
|
||||||
))?;
|
))?;
|
||||||
}
|
}
|
||||||
next_last_id_retries -= 1;
|
next_block_hash_retries -= 1;
|
||||||
// Retry ~twice during a slot
|
// Retry ~twice during a slot
|
||||||
sleep(Duration::from_millis(
|
sleep(Duration::from_millis(
|
||||||
500 * DEFAULT_TICKS_PER_SLOT / NUM_TICKS_PER_SECOND,
|
500 * DEFAULT_TICKS_PER_SLOT / NUM_TICKS_PER_SECOND,
|
||||||
|
@ -822,7 +822,7 @@ fn send_and_confirm_transaction(
|
||||||
};
|
};
|
||||||
match status {
|
match status {
|
||||||
RpcSignatureStatus::AccountInUse | RpcSignatureStatus::SignatureNotFound => {
|
RpcSignatureStatus::AccountInUse | RpcSignatureStatus::SignatureNotFound => {
|
||||||
// Fetch a new last_id and re-sign the transaction before sending it again
|
// Fetch a new block_hash and re-sign the transaction before sending it again
|
||||||
resign_transaction(rpc_client, transaction, signer)?;
|
resign_transaction(rpc_client, transaction, signer)?;
|
||||||
send_retries -= 1;
|
send_retries -= 1;
|
||||||
}
|
}
|
||||||
|
@ -899,13 +899,13 @@ fn send_and_confirm_transactions(
|
||||||
}
|
}
|
||||||
send_retries -= 1;
|
send_retries -= 1;
|
||||||
|
|
||||||
// Re-sign any failed transactions with a new last_id and retry
|
// Re-sign any failed transactions with a new block_hash and retry
|
||||||
let last_id =
|
let block_hash =
|
||||||
get_next_last_id(rpc_client, &transactions_signatures[0].0.recent_block_hash)?;
|
get_next_block_hash(rpc_client, &transactions_signatures[0].0.recent_block_hash)?;
|
||||||
transactions = transactions_signatures
|
transactions = transactions_signatures
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(mut transaction, _)| {
|
.map(|(mut transaction, _)| {
|
||||||
transaction.sign(&[signer], last_id);
|
transaction.sign(&[signer], block_hash);
|
||||||
transaction
|
transaction
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -917,8 +917,8 @@ fn resign_transaction(
|
||||||
tx: &mut Transaction,
|
tx: &mut Transaction,
|
||||||
signer_key: &Keypair,
|
signer_key: &Keypair,
|
||||||
) -> Result<(), Box<dyn error::Error>> {
|
) -> Result<(), Box<dyn error::Error>> {
|
||||||
let last_id = get_next_last_id(rpc_client, &tx.recent_block_hash)?;
|
let block_hash = get_next_block_hash(rpc_client, &tx.recent_block_hash)?;
|
||||||
tx.sign(&[signer_key], last_id);
|
tx.sign(&[signer_key], block_hash);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -928,8 +928,8 @@ pub fn request_and_confirm_airdrop(
|
||||||
signer: &Keypair,
|
signer: &Keypair,
|
||||||
tokens: u64,
|
tokens: u64,
|
||||||
) -> Result<(), Box<dyn error::Error>> {
|
) -> Result<(), Box<dyn error::Error>> {
|
||||||
let last_id = get_recent_block_hash(rpc_client)?;
|
let block_hash = get_recent_block_hash(rpc_client)?;
|
||||||
let mut tx = request_airdrop_transaction(drone_addr, &signer.pubkey(), tokens, last_id)?;
|
let mut tx = request_airdrop_transaction(drone_addr, &signer.pubkey(), tokens, block_hash)?;
|
||||||
send_and_confirm_transaction(rpc_client, &mut tx, signer)?;
|
send_and_confirm_transaction(rpc_client, &mut tx, signer)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1510,15 +1510,15 @@ mod tests {
|
||||||
let rpc_client = RpcClient::new("succeeds".to_string());
|
let rpc_client = RpcClient::new("succeeds".to_string());
|
||||||
|
|
||||||
let vec = bs58::decode(PUBKEY).into_vec().unwrap();
|
let vec = bs58::decode(PUBKEY).into_vec().unwrap();
|
||||||
let expected_last_id = Hash::new(&vec);
|
let expected_block_hash = Hash::new(&vec);
|
||||||
|
|
||||||
let last_id = get_recent_block_hash(&rpc_client);
|
let block_hash = get_recent_block_hash(&rpc_client);
|
||||||
assert_eq!(last_id.unwrap(), expected_last_id);
|
assert_eq!(block_hash.unwrap(), expected_block_hash);
|
||||||
|
|
||||||
let rpc_client = RpcClient::new("fails".to_string());
|
let rpc_client = RpcClient::new("fails".to_string());
|
||||||
|
|
||||||
let last_id = get_recent_block_hash(&rpc_client);
|
let block_hash = get_recent_block_hash(&rpc_client);
|
||||||
assert!(last_id.is_err());
|
assert!(block_hash.is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1527,8 +1527,8 @@ mod tests {
|
||||||
|
|
||||||
let key = Keypair::new();
|
let key = Keypair::new();
|
||||||
let to = Keypair::new().pubkey();
|
let to = Keypair::new().pubkey();
|
||||||
let last_id = Hash::default();
|
let block_hash = Hash::default();
|
||||||
let tx = SystemTransaction::new_account(&key, to, 50, last_id, 0);
|
let tx = SystemTransaction::new_account(&key, to, 50, block_hash, 0);
|
||||||
|
|
||||||
let signature = send_transaction(&rpc_client, &tx);
|
let signature = send_transaction(&rpc_client, &tx);
|
||||||
assert_eq!(signature.unwrap(), SIGNATURE.to_string());
|
assert_eq!(signature.unwrap(), SIGNATURE.to_string());
|
||||||
|
@ -1563,8 +1563,8 @@ mod tests {
|
||||||
|
|
||||||
let key = Keypair::new();
|
let key = Keypair::new();
|
||||||
let to = Keypair::new().pubkey();
|
let to = Keypair::new().pubkey();
|
||||||
let last_id = Hash::default();
|
let block_hash = Hash::default();
|
||||||
let mut tx = SystemTransaction::new_account(&key, to, 50, last_id, 0);
|
let mut tx = SystemTransaction::new_account(&key, to, 50, block_hash, 0);
|
||||||
|
|
||||||
let signer = Keypair::new();
|
let signer = Keypair::new();
|
||||||
|
|
||||||
|
@ -1589,9 +1589,9 @@ mod tests {
|
||||||
let vec = bs58::decode("HUu3LwEzGRsUkuJS121jzkPJW39Kq62pXCTmTa1F9jDL")
|
let vec = bs58::decode("HUu3LwEzGRsUkuJS121jzkPJW39Kq62pXCTmTa1F9jDL")
|
||||||
.into_vec()
|
.into_vec()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let last_id = Hash::new(&vec);
|
let block_hash = Hash::new(&vec);
|
||||||
let prev_tx = SystemTransaction::new_account(&key, to, 50, last_id, 0);
|
let prev_tx = SystemTransaction::new_account(&key, to, 50, block_hash, 0);
|
||||||
let mut tx = SystemTransaction::new_account(&key, to, 50, last_id, 0);
|
let mut tx = SystemTransaction::new_account(&key, to, 50, block_hash, 0);
|
||||||
|
|
||||||
resign_transaction(&rpc_client, &mut tx, &key).unwrap();
|
resign_transaction(&rpc_client, &mut tx, &key).unwrap();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue