Cleanup stragglers from move-to-transfer rename (#3947)

This commit is contained in:
Greg Fitzgerald
2019-04-23 13:30:42 -06:00
committed by GitHub
parent 7372ec9e1a
commit 29698fcd38
9 changed files with 39 additions and 35 deletions

View File

@ -10,7 +10,7 @@ client's account.
A drone is a simple signing service. It listens for requests to sign A drone is a simple signing service. It listens for requests to sign
*transaction data*. Once received, the drone validates the request however it *transaction data*. Once received, the drone validates the request however it
sees fit. It may, for example, only accept transaction data with a sees fit. It may, for example, only accept transaction data with a
`SystemInstruction::Move` instruction transferring only up to a certain amount `SystemInstruction::Transfer` instruction transferring only up to a certain amount
of tokens. If the drone accepts the transaction, it returns an `Ok(Signature)` of tokens. If the drone accepts the transaction, it returns an `Ok(Signature)`
where `Signature` is a signature of the transaction data using the drone's where `Signature` is a signature of the transaction data using the drone's
private key. If it rejects the transaction data, it returns a `DroneError` private key. If it rejects the transaction data, it returns a `DroneError`
@ -76,7 +76,7 @@ beyond a certain *age*.
If the transaction data size is smaller than the size of the returned signature If the transaction data size is smaller than the size of the returned signature
(or descriptive error), a single client can flood the network. Considering (or descriptive error), a single client can flood the network. Considering
that a simple `Move` operation requires two public keys (each 32 bytes) and a that a simple `Transfer` operation requires two public keys (each 32 bytes) and a
`fee` field, and that the returned signature is 64 bytes (and a byte to `fee` field, and that the returned signature is 64 bytes (and a byte to
indicate `Ok`), consideration for this attack may not be required. indicate `Ok`), consideration for this attack may not be required.

View File

@ -3,8 +3,8 @@
A client *app* interacts with a Solana cluster by sending it *transactions* A client *app* interacts with a Solana cluster by sending it *transactions*
with one or more *instructions*. The Solana *runtime* passes those instructions with one or more *instructions*. The Solana *runtime* passes those instructions
to user-contributed *programs*. An instruction might, for example, tell a to user-contributed *programs*. An instruction might, for example, tell a
program to move *lamports* from one *account* to another or create an interactive program to transfer *lamports* from one *account* to another or create an interactive
contract that governs how lamports are moved. Instructions are executed contract that governs how lamports are transfered. Instructions are executed
atomically. If any instruction is invalid, any changes made within the atomically. If any instruction is invalid, any changes made within the
transaction are discarded. transaction are discarded.

View File

@ -67,7 +67,7 @@ data array and assign it to a Program.
* `Assign` - Allows the user to assign an existing account to a program. * `Assign` - Allows the user to assign an existing account to a program.
* `Move` - Moves lamports between accounts. * `Transfer` - Transfers lamports between accounts.
## Program State Security ## Program State Security

View File

@ -158,7 +158,8 @@ mod tests {
bank.transfer(42, &mint_keypair, &system_pubkey).unwrap(); bank.transfer(42, &mint_keypair, &system_pubkey).unwrap();
let (bank_client, from_keypair, config_keypair) = create_config_client(bank, mint_keypair); let (bank_client, from_keypair, config_keypair) = create_config_client(bank, mint_keypair);
let move_instruction = system_instruction::transfer(&system_pubkey, &Pubkey::default(), 42); let transfer_instruction =
system_instruction::transfer(&system_pubkey, &Pubkey::default(), 42);
let my_config = MyConfig::new(42); let my_config = MyConfig::new(42);
let mut store_instruction = let mut store_instruction =
config_instruction::store(&from_keypair.pubkey(), &config_keypair.pubkey(), &my_config); config_instruction::store(&from_keypair.pubkey(), &config_keypair.pubkey(), &my_config);
@ -166,7 +167,7 @@ mod tests {
store_instruction.accounts[1].is_signer = false; store_instruction.accounts[1].is_signer = false;
// Don't sign the transaction with `config_client` // Don't sign the transaction with `config_client`
let message = Message::new(vec![move_instruction, store_instruction]); let message = Message::new(vec![transfer_instruction, store_instruction]);
bank_client bank_client
.send_message(&[&system_keypair], message) .send_message(&[&system_keypair], message)
.unwrap_err(); .unwrap_err();

View File

@ -202,8 +202,8 @@ mod tests {
// Sneak in an instruction so that the transaction is signed but // Sneak in an instruction so that the transaction is signed but
// the 0th account in the second instruction is not! The program // the 0th account in the second instruction is not! The program
// needs to check that it's signed. // needs to check that it's signed.
let move_ix = system_instruction::transfer(&mallory_id, &vote_id, 1); let transfer_ix = system_instruction::transfer(&mallory_id, &vote_id, 1);
let message = Message::new(vec![move_ix, vote_ix]); let message = Message::new(vec![transfer_ix, vote_ix]);
let result = bank_client.send_message(&[&mallory_keypair], message); let result = bank_client.send_message(&[&mallory_keypair], message);
// And ensure there's no vote. // And ensure there's no vote.

View File

@ -1593,14 +1593,14 @@ mod tests {
let key2 = Keypair::new(); let key2 = Keypair::new();
let parent = Arc::new(Bank::new(&genesis_block)); let parent = Arc::new(Bank::new(&genesis_block));
let tx_move_mint_to_1 = let tx_transfer_mint_to_1 =
system_transaction::transfer(&mint_keypair, &key1.pubkey(), 1, genesis_block.hash(), 0); system_transaction::transfer(&mint_keypair, &key1.pubkey(), 1, genesis_block.hash(), 0);
trace!("parent process tx "); trace!("parent process tx ");
assert_eq!(parent.process_transaction(&tx_move_mint_to_1), Ok(())); assert_eq!(parent.process_transaction(&tx_transfer_mint_to_1), Ok(()));
trace!("done parent process tx "); trace!("done parent process tx ");
assert_eq!(parent.transaction_count(), 1); assert_eq!(parent.transaction_count(), 1);
assert_eq!( assert_eq!(
parent.get_signature_status(&tx_move_mint_to_1.signatures[0]), parent.get_signature_status(&tx_transfer_mint_to_1.signatures[0]),
Some(Ok(())) Some(Ok(()))
); );
@ -1608,18 +1608,18 @@ mod tests {
let bank = new_from_parent(&parent); let bank = new_from_parent(&parent);
trace!("done new form parent"); trace!("done new form parent");
assert_eq!( assert_eq!(
bank.get_signature_status(&tx_move_mint_to_1.signatures[0]), bank.get_signature_status(&tx_transfer_mint_to_1.signatures[0]),
Some(Ok(())) Some(Ok(()))
); );
assert_eq!(bank.transaction_count(), parent.transaction_count()); assert_eq!(bank.transaction_count(), parent.transaction_count());
let tx_move_1_to_2 = let tx_transfer_1_to_2 =
system_transaction::transfer(&key1, &key2.pubkey(), 1, genesis_block.hash(), 0); system_transaction::transfer(&key1, &key2.pubkey(), 1, genesis_block.hash(), 0);
assert_eq!(bank.process_transaction(&tx_move_1_to_2), Ok(())); assert_eq!(bank.process_transaction(&tx_transfer_1_to_2), Ok(()));
assert_eq!(bank.transaction_count(), 2); assert_eq!(bank.transaction_count(), 2);
assert_eq!(parent.transaction_count(), 1); assert_eq!(parent.transaction_count(), 1);
assert_eq!( assert_eq!(
parent.get_signature_status(&tx_move_1_to_2.signatures[0]), parent.get_signature_status(&tx_transfer_1_to_2.signatures[0]),
None None
); );
@ -1630,11 +1630,11 @@ mod tests {
assert_eq!(bank.get_balance(&key2.pubkey()), 1); assert_eq!(bank.get_balance(&key2.pubkey()), 1);
trace!("start"); trace!("start");
assert_eq!( assert_eq!(
bank.get_signature_status(&tx_move_mint_to_1.signatures[0]), bank.get_signature_status(&tx_transfer_mint_to_1.signatures[0]),
Some(Ok(())) Some(Ok(()))
); );
assert_eq!( assert_eq!(
bank.get_signature_status(&tx_move_1_to_2.signatures[0]), bank.get_signature_status(&tx_transfer_1_to_2.signatures[0]),
Some(Ok(())) Some(Ok(()))
); );
@ -1731,13 +1731,13 @@ mod tests {
bank.fee_calculator.lamports_per_signature = 2; bank.fee_calculator.lamports_per_signature = 2;
let key = Keypair::new(); let key = Keypair::new();
let mut move_instruction = let mut transfer_instruction =
system_instruction::transfer(&mint_keypair.pubkey(), &key.pubkey(), 0); system_instruction::transfer(&mint_keypair.pubkey(), &key.pubkey(), 0);
move_instruction.accounts[0].is_signer = false; transfer_instruction.accounts[0].is_signer = false;
let tx = Transaction::new_signed_instructions( let tx = Transaction::new_signed_instructions(
&Vec::<&Keypair>::new(), &Vec::<&Keypair>::new(),
vec![move_instruction], vec![transfer_instruction],
bank.last_blockhash(), bank.last_blockhash(),
); );
@ -1813,9 +1813,9 @@ mod tests {
let (genesis_block, mint_keypair) = GenesisBlock::new(500); let (genesis_block, mint_keypair) = GenesisBlock::new(500);
let bank = Arc::new(Bank::new(&genesis_block)); let bank = Arc::new(Bank::new(&genesis_block));
let key1 = Keypair::new(); let key1 = Keypair::new();
let tx_move_mint_to_1 = let tx_transfer_mint_to_1 =
system_transaction::transfer(&mint_keypair, &key1.pubkey(), 1, genesis_block.hash(), 0); system_transaction::transfer(&mint_keypair, &key1.pubkey(), 1, genesis_block.hash(), 0);
assert_eq!(bank.process_transaction(&tx_move_mint_to_1), Ok(())); assert_eq!(bank.process_transaction(&tx_transfer_mint_to_1), Ok(()));
assert_eq!(bank.is_delta.load(Ordering::Relaxed), true); assert_eq!(bank.is_delta.load(Ordering::Relaxed), true);
} }
@ -1827,9 +1827,9 @@ mod tests {
assert_eq!(bank.is_votable(), false); assert_eq!(bank.is_votable(), false);
// Set is_delta to true // Set is_delta to true
let tx_move_mint_to_1 = let tx_transfer_mint_to_1 =
system_transaction::transfer(&mint_keypair, &key1.pubkey(), 1, genesis_block.hash(), 0); system_transaction::transfer(&mint_keypair, &key1.pubkey(), 1, genesis_block.hash(), 0);
assert_eq!(bank.process_transaction(&tx_move_mint_to_1), Ok(())); assert_eq!(bank.process_transaction(&tx_transfer_mint_to_1), Ok(()));
assert_eq!(bank.is_votable(), false); assert_eq!(bank.is_votable(), false);
// Register enough ticks to hit max tick height // Register enough ticks to hit max tick height

View File

@ -160,12 +160,12 @@ mod tests {
// Create 2-2 Multisig Transfer instruction. // Create 2-2 Multisig Transfer instruction.
let bob_pubkey = Pubkey::new_rand(); let bob_pubkey = Pubkey::new_rand();
let mut move_instruction = system_instruction::transfer(&john_pubkey, &bob_pubkey, 42); let mut transfer_instruction = system_instruction::transfer(&john_pubkey, &bob_pubkey, 42);
move_instruction transfer_instruction
.accounts .accounts
.push(AccountMeta::new(jane_pubkey, true)); .push(AccountMeta::new(jane_pubkey, true));
let message = Message::new(vec![move_instruction]); let message = Message::new(vec![transfer_instruction]);
bank_client.send_message(&doe_keypairs, message).unwrap(); bank_client.send_message(&doe_keypairs, message).unwrap();
assert_eq!(bank_client.get_balance(&bob_pubkey).unwrap(), 42); assert_eq!(bank_client.get_balance(&bob_pubkey).unwrap(), 42);
} }

View File

@ -50,7 +50,10 @@ fn assign_account_to_program(
keyed_accounts[FROM_ACCOUNT_INDEX].account.owner = *program_id; keyed_accounts[FROM_ACCOUNT_INDEX].account.owner = *program_id;
Ok(()) Ok(())
} }
fn move_lamports(keyed_accounts: &mut [KeyedAccount], lamports: u64) -> Result<(), SystemError> { fn transfer_lamports(
keyed_accounts: &mut [KeyedAccount],
lamports: u64,
) -> Result<(), SystemError> {
if lamports > keyed_accounts[FROM_ACCOUNT_INDEX].account.lamports { if lamports > keyed_accounts[FROM_ACCOUNT_INDEX].account.lamports {
debug!( debug!(
"Transfer: insufficient lamports ({}, need {})", "Transfer: insufficient lamports ({}, need {})",
@ -91,7 +94,7 @@ pub fn process_instruction(
} }
assign_account_to_program(keyed_accounts, &program_id) assign_account_to_program(keyed_accounts, &program_id)
} }
SystemInstruction::Transfer { lamports } => move_lamports(keyed_accounts, lamports), SystemInstruction::Transfer { lamports } => transfer_lamports(keyed_accounts, lamports),
} }
.map_err(|e| InstructionError::CustomError(e as u32)) .map_err(|e| InstructionError::CustomError(e as u32))
} else { } else {
@ -249,7 +252,7 @@ mod tests {
} }
#[test] #[test]
fn test_move_lamports() { fn test_transfer_lamports() {
let from = Pubkey::new_rand(); let from = Pubkey::new_rand();
let mut from_account = Account::new(100, 0, &Pubkey::new(&[2; 32])); // account owner should not matter let mut from_account = Account::new(100, 0, &Pubkey::new(&[2; 32])); // account owner should not matter
let to = Pubkey::new_rand(); let to = Pubkey::new_rand();
@ -258,7 +261,7 @@ mod tests {
KeyedAccount::new(&from, true, &mut from_account), KeyedAccount::new(&from, true, &mut from_account),
KeyedAccount::new(&to, false, &mut to_account), KeyedAccount::new(&to, false, &mut to_account),
]; ];
move_lamports(&mut keyed_accounts, 50).unwrap(); transfer_lamports(&mut keyed_accounts, 50).unwrap();
let from_lamports = from_account.lamports; let from_lamports = from_account.lamports;
let to_lamports = to_account.lamports; let to_lamports = to_account.lamports;
assert_eq!(from_lamports, 50); assert_eq!(from_lamports, 50);
@ -269,7 +272,7 @@ mod tests {
KeyedAccount::new(&from, true, &mut from_account), KeyedAccount::new(&from, true, &mut from_account),
KeyedAccount::new(&to, false, &mut to_account), KeyedAccount::new(&to, false, &mut to_account),
]; ];
let result = move_lamports(&mut keyed_accounts, 100); let result = transfer_lamports(&mut keyed_accounts, 100);
assert_eq!(result, Err(SystemError::ResultWithNegativeLamports)); assert_eq!(result, Err(SystemError::ResultWithNegativeLamports));
assert_eq!(from_account.lamports, 50); assert_eq!(from_account.lamports, 50);
assert_eq!(to_account.lamports, 51); assert_eq!(to_account.lamports, 51);

View File

@ -66,7 +66,7 @@ pub fn transfer(
_fee: u64, _fee: u64,
) -> Transaction { ) -> Transaction {
let from_pubkey = from_keypair.pubkey(); let from_pubkey = from_keypair.pubkey();
let move_instruction = system_instruction::transfer(&from_pubkey, to, lamports); let transfer_instruction = system_instruction::transfer(&from_pubkey, to, lamports);
let instructions = vec![move_instruction]; let instructions = vec![transfer_instruction];
Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash) Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash)
} }