Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit 0f6ed37

Browse files
t-nelsonmergify-bot
authored andcommitted
Nonce: Rename instructions with VerbNoun scheme (#7775)
automerge (cherry picked from commit 81ae44f) # Conflicts: # sdk/src/system_instruction.rs
1 parent 353cfb1 commit 0f6ed37

File tree

4 files changed

+78
-45
lines changed

4 files changed

+78
-45
lines changed

book/src/implemented-proposals/durable-tx-nonces.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ account data. A transaction is now constructed in the normal way, but with the
2626
following additional requirements:
2727

2828
1) The durable nonce value is used in the `recent_blockhash` field
29-
2) A `NonceAdvance` instruction is the first issued in the transaction
29+
2) An `AdvanceNonceAccount` instruction is the first issued in the transaction
3030

3131
### Contract Mechanics
3232

@@ -67,7 +67,7 @@ A client wishing to use this feature starts by creating a nonce account under
6767
the system program. This account will be in the `Uninitialized` state with no
6868
stored hash, and thus unusable.
6969

70-
To initialize a newly created account, a `NonceInitialize` instruction must be
70+
To initialize a newly created account, an `InitializeNonceAccount` instruction must be
7171
issued. This instruction takes one parameter, the `Pubkey` of the account's
7272
[authority](../offline-signing/durable-nonce.md#nonce-authority). Nonce accounts
7373
must be [rent-exempt](rent.md#two-tiered-rent-regime) to meet the data-persistence
@@ -76,27 +76,27 @@ deposited before they can be initialized. Upon successful initialization, the
7676
cluster's most recent blockhash is stored along with specified nonce authority
7777
`Pubkey`.
7878

79-
The `NonceAdvance` instruction is used to manage the account's stored nonce
79+
The `AdvanceNonceAccount` instruction is used to manage the account's stored nonce
8080
value. It stores the cluster's most recent blockhash in the account's state data,
8181
failing if that matches the value already stored there. This check prevents
8282
replaying transactions within the same block.
8383

8484
Due to nonce accounts' [rent-exempt](rent.md#two-tiered-rent-regime) requirement,
8585
a custom withdraw instruction is used to move funds out of the account.
86-
The `NonceWithdraw` instruction takes a single argument, lamports to withdraw,
86+
The `WithdrawNonceAccount` instruction takes a single argument, lamports to withdraw,
8787
and enforces rent-exemption by preventing the account's balance from falling
8888
below the rent-exempt minimum. An exception to this check is if the final balance
8989
would be zero lamports, which makes the account eligible for deletion. This
9090
account closure detail has an additional requirement that the stored nonce value
91-
must not match the cluster's most recent blockhash, as per `NonceAdvance`.
91+
must not match the cluster's most recent blockhash, as per `AdvanceNonceAccount`.
9292

9393
The account's [nonce authority](../offline-signing/durable-nonce.md#nonce-authority)
94-
can be changed using the `NonceAuthorize` instruction. It takes one parameter,
94+
can be changed using the `AuthorizeNonceAccount` instruction. It takes one parameter,
9595
the `Pubkey` of the new authority. Executing this instruction grants full
9696
control over the account and its balance to the new authority.
9797

9898
{% hint style="info" %}
99-
`NonceAdvance`, `NonceWithdraw` and `NonceAuthorize` all require the current
99+
`AdvanceNonceAccount`, `WithdrawNonceAccount` and `AuthorizeNonceAccount` all require the current
100100
[nonce authority](../offline-signing/durable-nonce.md#nonce-authority) for the
101101
account to sign the transaction.
102102
{% endhint %}
@@ -108,7 +108,7 @@ an extant `recent_blockhash` on the transaction and prevent fee theft via
108108
failed transaction replay, runtime modifications are necessary.
109109

110110
Any transaction failing the usual `check_hash_age` validation will be tested
111-
for a Durable Transaction Nonce. This is signaled by including a `NonceAdvance`
111+
for a Durable Transaction Nonce. This is signaled by including a `AdvanceNonceAccount`
112112
instruction as the first instruction in the transaction.
113113

114114
If the runtime determines that a Durable Transaction Nonce is in use, it will
@@ -124,10 +124,10 @@ If all three of the above checks succeed, the transaction is allowed to continue
124124
validation.
125125

126126
Since transactions that fail with an `InstructionError` are charged a fee and
127-
changes to their state rolled back, there is an opportunity for fee theft if a
128-
`NonceAdvance` instruction is reverted. A malicious validator could replay the
127+
changes to their state rolled back, there is an opportunity for fee theft if an
128+
`AdvanceNonceAccount` instruction is reverted. A malicious validator could replay the
129129
failed transaction until the stored nonce is successfully advanced. Runtime
130130
changes prevent this behavior. When a durable nonce transaction fails with an
131-
`InstructionError` aside from the `NonceAdvance` instruction, the nonce account
131+
`InstructionError` aside from the `AdvanceNonceAccount` instruction, the nonce account
132132
is rolled back to its pre-execution state as usual. Then the runtime advances
133133
its nonce value and the advanced nonce account stored as if it succeeded.

runtime/src/nonce_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn transaction_uses_durable_nonce(tx: &Transaction) -> Option<&CompiledInstr
2424
}
2525
})
2626
.filter(|maybe_ix| match limited_deserialize(&maybe_ix.data) {
27-
Ok(SystemInstruction::NonceAdvance) => true,
27+
Ok(SystemInstruction::AdvanceNonceAccount) => true,
2828
_ => false,
2929
})
3030
}

runtime/src/system_instruction_processor.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,14 @@ pub fn process_instruction(
221221
let to = next_keyed_account(keyed_accounts_iter)?;
222222
transfer_lamports(from, to, lamports)
223223
}
224-
SystemInstruction::NonceAdvance => {
224+
SystemInstruction::AdvanceNonceAccount => {
225225
let me = &mut next_keyed_account(keyed_accounts_iter)?;
226226
me.nonce_advance(
227227
&RecentBlockhashes::from_keyed_account(next_keyed_account(keyed_accounts_iter)?)?,
228228
&signers,
229229
)
230230
}
231-
SystemInstruction::NonceWithdraw(lamports) => {
231+
SystemInstruction::WithdrawNonceAccount(lamports) => {
232232
let me = &mut next_keyed_account(keyed_accounts_iter)?;
233233
let to = &mut next_keyed_account(keyed_accounts_iter)?;
234234
me.nonce_withdraw(
@@ -239,15 +239,15 @@ pub fn process_instruction(
239239
&signers,
240240
)
241241
}
242-
SystemInstruction::NonceInitialize(authorized) => {
242+
SystemInstruction::InitializeNonceAccount(authorized) => {
243243
let me = &mut next_keyed_account(keyed_accounts_iter)?;
244244
me.nonce_initialize(
245245
&authorized,
246246
&RecentBlockhashes::from_keyed_account(next_keyed_account(keyed_accounts_iter)?)?,
247247
&Rent::from_keyed_account(next_keyed_account(keyed_accounts_iter)?)?,
248248
)
249249
}
250-
SystemInstruction::NonceAuthorize(nonce_authority) => {
250+
SystemInstruction::AuthorizeNonceAccount(nonce_authority) => {
251251
let me = &mut next_keyed_account(keyed_accounts_iter)?;
252252
me.nonce_authorize(&nonce_authority, &signers)
253253
}
@@ -882,7 +882,7 @@ mod tests {
882882
super::process_instruction(
883883
&Pubkey::default(),
884884
&mut [],
885-
&serialize(&SystemInstruction::NonceAdvance).unwrap()
885+
&serialize(&SystemInstruction::AdvanceNonceAccount).unwrap()
886886
),
887887
Err(InstructionError::NotEnoughAccountKeys),
888888
);
@@ -898,7 +898,7 @@ mod tests {
898898
true,
899899
&mut Account::default(),
900900
),],
901-
&serialize(&SystemInstruction::NonceAdvance).unwrap(),
901+
&serialize(&SystemInstruction::AdvanceNonceAccount).unwrap(),
902902
),
903903
Err(InstructionError::NotEnoughAccountKeys),
904904
);
@@ -917,7 +917,7 @@ mod tests {
917917
&mut Account::default(),
918918
),
919919
],
920-
&serialize(&SystemInstruction::NonceAdvance).unwrap(),
920+
&serialize(&SystemInstruction::AdvanceNonceAccount).unwrap(),
921921
),
922922
Err(InstructionError::InvalidArgument),
923923
);
@@ -944,7 +944,7 @@ mod tests {
944944
&mut sysvar::rent::create_account(1, &Rent::free()),
945945
),
946946
],
947-
&serialize(&SystemInstruction::NonceInitialize(Pubkey::default())).unwrap(),
947+
&serialize(&SystemInstruction::InitializeNonceAccount(Pubkey::default())).unwrap(),
948948
)
949949
.unwrap();
950950
assert_eq!(
@@ -961,7 +961,7 @@ mod tests {
961961
),
962962
),
963963
],
964-
&serialize(&SystemInstruction::NonceAdvance).unwrap(),
964+
&serialize(&SystemInstruction::AdvanceNonceAccount).unwrap(),
965965
),
966966
Ok(()),
967967
);
@@ -986,7 +986,7 @@ mod tests {
986986
super::process_instruction(
987987
&Pubkey::default(),
988988
&mut [],
989-
&serialize(&SystemInstruction::NonceWithdraw(42)).unwrap(),
989+
&serialize(&SystemInstruction::WithdrawNonceAccount(42)).unwrap(),
990990
),
991991
Err(InstructionError::NotEnoughAccountKeys),
992992
);
@@ -1002,7 +1002,7 @@ mod tests {
10021002
true,
10031003
&mut Account::default(),
10041004
),],
1005-
&serialize(&SystemInstruction::NonceWithdraw(42)).unwrap(),
1005+
&serialize(&SystemInstruction::WithdrawNonceAccount(42)).unwrap(),
10061006
),
10071007
Err(InstructionError::NotEnoughAccountKeys),
10081008
);
@@ -1022,7 +1022,7 @@ mod tests {
10221022
&mut Account::default(),
10231023
),
10241024
],
1025-
&serialize(&SystemInstruction::NonceWithdraw(42)).unwrap(),
1025+
&serialize(&SystemInstruction::WithdrawNonceAccount(42)).unwrap(),
10261026
),
10271027
Err(InstructionError::InvalidArgument),
10281028
);
@@ -1050,7 +1050,7 @@ mod tests {
10501050
),
10511051
KeyedAccount::new(&sysvar::rent::id(), false, &mut Account::default(),),
10521052
],
1053-
&serialize(&SystemInstruction::NonceWithdraw(42)).unwrap(),
1053+
&serialize(&SystemInstruction::WithdrawNonceAccount(42)).unwrap(),
10541054
),
10551055
Err(InstructionError::InvalidArgument),
10561056
);
@@ -1082,7 +1082,7 @@ mod tests {
10821082
&mut sysvar::rent::create_account(1, &Rent::free())
10831083
),
10841084
],
1085-
&serialize(&SystemInstruction::NonceWithdraw(42)).unwrap(),
1085+
&serialize(&SystemInstruction::WithdrawNonceAccount(42)).unwrap(),
10861086
),
10871087
Ok(()),
10881088
);
@@ -1094,7 +1094,7 @@ mod tests {
10941094
super::process_instruction(
10951095
&Pubkey::default(),
10961096
&mut [],
1097-
&serialize(&SystemInstruction::NonceInitialize(Pubkey::default())).unwrap(),
1097+
&serialize(&SystemInstruction::InitializeNonceAccount(Pubkey::default())).unwrap(),
10981098
),
10991099
Err(InstructionError::NotEnoughAccountKeys),
11001100
);
@@ -1110,7 +1110,7 @@ mod tests {
11101110
true,
11111111
&mut nonce_state::create_account(1_000_000),
11121112
),],
1113-
&serialize(&SystemInstruction::NonceInitialize(Pubkey::default())).unwrap(),
1113+
&serialize(&SystemInstruction::InitializeNonceAccount(Pubkey::default())).unwrap(),
11141114
),
11151115
Err(InstructionError::NotEnoughAccountKeys),
11161116
);
@@ -1133,7 +1133,7 @@ mod tests {
11331133
&mut Account::default(),
11341134
),
11351135
],
1136-
&serialize(&SystemInstruction::NonceInitialize(Pubkey::default())).unwrap(),
1136+
&serialize(&SystemInstruction::InitializeNonceAccount(Pubkey::default())).unwrap(),
11371137
),
11381138
Err(InstructionError::InvalidArgument),
11391139
);
@@ -1160,7 +1160,7 @@ mod tests {
11601160
),
11611161
KeyedAccount::new(&sysvar::rent::id(), false, &mut Account::default(),),
11621162
],
1163-
&serialize(&SystemInstruction::NonceInitialize(Pubkey::default())).unwrap(),
1163+
&serialize(&SystemInstruction::InitializeNonceAccount(Pubkey::default())).unwrap(),
11641164
),
11651165
Err(InstructionError::InvalidArgument),
11661166
);
@@ -1191,7 +1191,7 @@ mod tests {
11911191
&mut sysvar::rent::create_account(1, &Rent::free())
11921192
),
11931193
],
1194-
&serialize(&SystemInstruction::NonceInitialize(Pubkey::default())).unwrap(),
1194+
&serialize(&SystemInstruction::InitializeNonceAccount(Pubkey::default())).unwrap(),
11951195
),
11961196
Ok(()),
11971197
);
@@ -1218,14 +1218,14 @@ mod tests {
12181218
&mut sysvar::rent::create_account(1, &Rent::free()),
12191219
),
12201220
],
1221-
&serialize(&SystemInstruction::NonceInitialize(Pubkey::default())).unwrap(),
1221+
&serialize(&SystemInstruction::InitializeNonceAccount(Pubkey::default())).unwrap(),
12221222
)
12231223
.unwrap();
12241224
assert_eq!(
12251225
super::process_instruction(
12261226
&Pubkey::default(),
12271227
&mut [KeyedAccount::new(&Pubkey::default(), true, &mut nonce_acc,),],
1228-
&serialize(&SystemInstruction::NonceAuthorize(Pubkey::default(),)).unwrap(),
1228+
&serialize(&SystemInstruction::AuthorizeNonceAccount(Pubkey::default(),)).unwrap(),
12291229
),
12301230
Ok(()),
12311231
);

sdk/src/system_instruction.rs

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@ pub enum SystemInstruction {
9191
space: u64,
9292
program_id: Pubkey,
9393
},
94-
/// `NonceAdvance` consumes a stored nonce, replacing it with a successor
94+
/// `AdvanceNonceAccount` consumes a stored nonce, replacing it with a successor
9595
///
9696
/// Expects 2 Accounts:
9797
/// 0 - A NonceAccount
9898
/// 1 - RecentBlockhashes sysvar
9999
///
100100
/// The current authority must sign a transaction executing this instrucion
101-
NonceAdvance,
102-
/// `NonceWithdraw` transfers funds out of the nonce account
101+
AdvanceNonceAccount,
102+
/// `WithdrawNonceAccount` transfers funds out of the nonce account
103103
///
104104
/// Expects 4 Accounts:
105105
/// 0 - A NonceAccount
@@ -111,8 +111,8 @@ pub enum SystemInstruction {
111111
/// account balance above the rent exempt reserve or at zero.
112112
///
113113
/// The current authority must sign a transaction executing this instruction
114-
NonceWithdraw(u64),
115-
/// `NonceInitialize` drives state of Uninitalized NonceAccount to Initialized,
114+
WithdrawNonceAccount(u64),
115+
/// `InitializeNonceAccount` drives state of Uninitalized NonceAccount to Initialized,
116116
/// setting the nonce value.
117117
///
118118
/// Expects 3 Accounts:
@@ -125,8 +125,8 @@ pub enum SystemInstruction {
125125
///
126126
/// No signatures are required to execute this instruction, enabling derived
127127
/// nonce account addresses
128-
NonceInitialize(Pubkey),
129-
/// `NonceAuthorize` changes the entity authorized to execute nonce instructions
128+
InitializeNonceAccount(Pubkey),
129+
/// `AuthorizeNonceAccount` changes the entity authorized to execute nonce instructions
130130
/// on the account
131131
///
132132
/// Expects 1 Account:
@@ -135,7 +135,7 @@ pub enum SystemInstruction {
135135
/// The `Pubkey` parameter identifies the entity to authorize
136136
///
137137
/// The current authority must sign a transaction executing this instruction
138-
NonceAuthorize(Pubkey),
138+
AuthorizeNonceAccount(Pubkey),
139139
}
140140

141141
pub fn create_account(
@@ -230,6 +230,39 @@ pub fn create_address_with_seed(
230230
))
231231
}
232232

233+
<<<<<<< HEAD
234+
=======
235+
pub fn create_nonce_account_with_seed(
236+
from_pubkey: &Pubkey,
237+
nonce_pubkey: &Pubkey,
238+
base: &Pubkey,
239+
seed: &str,
240+
authority: &Pubkey,
241+
lamports: u64,
242+
) -> Vec<Instruction> {
243+
vec![
244+
create_account_with_seed(
245+
from_pubkey,
246+
nonce_pubkey,
247+
base,
248+
seed,
249+
lamports,
250+
NonceState::size() as u64,
251+
&system_program::id(),
252+
),
253+
Instruction::new(
254+
system_program::id(),
255+
&SystemInstruction::InitializeNonceAccount(*authority),
256+
vec![
257+
AccountMeta::new(*nonce_pubkey, false),
258+
AccountMeta::new_readonly(recent_blockhashes::id(), false),
259+
AccountMeta::new_readonly(rent::id(), false),
260+
],
261+
),
262+
]
263+
}
264+
265+
>>>>>>> 81ae44f85... Nonce: Rename instructions with VerbNoun scheme (#7775)
233266
pub fn create_nonce_account(
234267
from_pubkey: &Pubkey,
235268
nonce_pubkey: &Pubkey,
@@ -246,7 +279,7 @@ pub fn create_nonce_account(
246279
),
247280
Instruction::new(
248281
system_program::id(),
249-
&SystemInstruction::NonceInitialize(*authority),
282+
&SystemInstruction::InitializeNonceAccount(*authority),
250283
vec![
251284
AccountMeta::new(*nonce_pubkey, false),
252285
AccountMeta::new_readonly(recent_blockhashes::id(), false),
@@ -264,7 +297,7 @@ pub fn nonce_advance(nonce_pubkey: &Pubkey, authorized_pubkey: &Pubkey) -> Instr
264297
.with_signer(authorized_pubkey);
265298
Instruction::new(
266299
system_program::id(),
267-
&SystemInstruction::NonceAdvance,
300+
&SystemInstruction::AdvanceNonceAccount,
268301
account_metas,
269302
)
270303
}
@@ -284,7 +317,7 @@ pub fn nonce_withdraw(
284317
.with_signer(authorized_pubkey);
285318
Instruction::new(
286319
system_program::id(),
287-
&SystemInstruction::NonceWithdraw(lamports),
320+
&SystemInstruction::WithdrawNonceAccount(lamports),
288321
account_metas,
289322
)
290323
}
@@ -297,7 +330,7 @@ pub fn nonce_authorize(
297330
let account_metas = vec![AccountMeta::new(*nonce_pubkey, false)].with_signer(authorized_pubkey);
298331
Instruction::new(
299332
system_program::id(),
300-
&SystemInstruction::NonceAuthorize(*new_authority),
333+
&SystemInstruction::AuthorizeNonceAccount(*new_authority),
301334
account_metas,
302335
)
303336
}

0 commit comments

Comments
 (0)