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

Commit 81ae44f

Browse files
t-nelsonsolana-grimes
authored andcommitted
Nonce: Rename instructions with VerbNoun scheme (#7775)
automerge
1 parent c948814 commit 81ae44f

File tree

4 files changed

+46
-46
lines changed

4 files changed

+46
-46
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
@@ -236,14 +236,14 @@ pub fn process_instruction(
236236
let to = next_keyed_account(keyed_accounts_iter)?;
237237
transfer_lamports(from, to, lamports)
238238
}
239-
SystemInstruction::NonceAdvance => {
239+
SystemInstruction::AdvanceNonceAccount => {
240240
let me = &mut next_keyed_account(keyed_accounts_iter)?;
241241
me.nonce_advance(
242242
&RecentBlockhashes::from_keyed_account(next_keyed_account(keyed_accounts_iter)?)?,
243243
&signers,
244244
)
245245
}
246-
SystemInstruction::NonceWithdraw(lamports) => {
246+
SystemInstruction::WithdrawNonceAccount(lamports) => {
247247
let me = &mut next_keyed_account(keyed_accounts_iter)?;
248248
let to = &mut next_keyed_account(keyed_accounts_iter)?;
249249
me.nonce_withdraw(
@@ -254,15 +254,15 @@ pub fn process_instruction(
254254
&signers,
255255
)
256256
}
257-
SystemInstruction::NonceInitialize(authorized) => {
257+
SystemInstruction::InitializeNonceAccount(authorized) => {
258258
let me = &mut next_keyed_account(keyed_accounts_iter)?;
259259
me.nonce_initialize(
260260
&authorized,
261261
&RecentBlockhashes::from_keyed_account(next_keyed_account(keyed_accounts_iter)?)?,
262262
&Rent::from_keyed_account(next_keyed_account(keyed_accounts_iter)?)?,
263263
)
264264
}
265-
SystemInstruction::NonceAuthorize(nonce_authority) => {
265+
SystemInstruction::AuthorizeNonceAccount(nonce_authority) => {
266266
let me = &mut next_keyed_account(keyed_accounts_iter)?;
267267
me.nonce_authorize(&nonce_authority, &signers)
268268
}
@@ -902,7 +902,7 @@ mod tests {
902902
super::process_instruction(
903903
&Pubkey::default(),
904904
&mut [],
905-
&serialize(&SystemInstruction::NonceAdvance).unwrap()
905+
&serialize(&SystemInstruction::AdvanceNonceAccount).unwrap()
906906
),
907907
Err(InstructionError::NotEnoughAccountKeys),
908908
);
@@ -918,7 +918,7 @@ mod tests {
918918
true,
919919
&mut Account::default(),
920920
),],
921-
&serialize(&SystemInstruction::NonceAdvance).unwrap(),
921+
&serialize(&SystemInstruction::AdvanceNonceAccount).unwrap(),
922922
),
923923
Err(InstructionError::NotEnoughAccountKeys),
924924
);
@@ -937,7 +937,7 @@ mod tests {
937937
&mut Account::default(),
938938
),
939939
],
940-
&serialize(&SystemInstruction::NonceAdvance).unwrap(),
940+
&serialize(&SystemInstruction::AdvanceNonceAccount).unwrap(),
941941
),
942942
Err(InstructionError::InvalidArgument),
943943
);
@@ -964,7 +964,7 @@ mod tests {
964964
&mut sysvar::rent::create_account(1, &Rent::free()),
965965
),
966966
],
967-
&serialize(&SystemInstruction::NonceInitialize(Pubkey::default())).unwrap(),
967+
&serialize(&SystemInstruction::InitializeNonceAccount(Pubkey::default())).unwrap(),
968968
)
969969
.unwrap();
970970
assert_eq!(
@@ -981,7 +981,7 @@ mod tests {
981981
),
982982
),
983983
],
984-
&serialize(&SystemInstruction::NonceAdvance).unwrap(),
984+
&serialize(&SystemInstruction::AdvanceNonceAccount).unwrap(),
985985
),
986986
Ok(()),
987987
);
@@ -1006,7 +1006,7 @@ mod tests {
10061006
super::process_instruction(
10071007
&Pubkey::default(),
10081008
&mut [],
1009-
&serialize(&SystemInstruction::NonceWithdraw(42)).unwrap(),
1009+
&serialize(&SystemInstruction::WithdrawNonceAccount(42)).unwrap(),
10101010
),
10111011
Err(InstructionError::NotEnoughAccountKeys),
10121012
);
@@ -1022,7 +1022,7 @@ mod tests {
10221022
true,
10231023
&mut Account::default(),
10241024
),],
1025-
&serialize(&SystemInstruction::NonceWithdraw(42)).unwrap(),
1025+
&serialize(&SystemInstruction::WithdrawNonceAccount(42)).unwrap(),
10261026
),
10271027
Err(InstructionError::NotEnoughAccountKeys),
10281028
);
@@ -1042,7 +1042,7 @@ mod tests {
10421042
&mut Account::default(),
10431043
),
10441044
],
1045-
&serialize(&SystemInstruction::NonceWithdraw(42)).unwrap(),
1045+
&serialize(&SystemInstruction::WithdrawNonceAccount(42)).unwrap(),
10461046
),
10471047
Err(InstructionError::InvalidArgument),
10481048
);
@@ -1070,7 +1070,7 @@ mod tests {
10701070
),
10711071
KeyedAccount::new(&sysvar::rent::id(), false, &mut Account::default(),),
10721072
],
1073-
&serialize(&SystemInstruction::NonceWithdraw(42)).unwrap(),
1073+
&serialize(&SystemInstruction::WithdrawNonceAccount(42)).unwrap(),
10741074
),
10751075
Err(InstructionError::InvalidArgument),
10761076
);
@@ -1102,7 +1102,7 @@ mod tests {
11021102
&mut sysvar::rent::create_account(1, &Rent::free())
11031103
),
11041104
],
1105-
&serialize(&SystemInstruction::NonceWithdraw(42)).unwrap(),
1105+
&serialize(&SystemInstruction::WithdrawNonceAccount(42)).unwrap(),
11061106
),
11071107
Ok(()),
11081108
);
@@ -1114,7 +1114,7 @@ mod tests {
11141114
super::process_instruction(
11151115
&Pubkey::default(),
11161116
&mut [],
1117-
&serialize(&SystemInstruction::NonceInitialize(Pubkey::default())).unwrap(),
1117+
&serialize(&SystemInstruction::InitializeNonceAccount(Pubkey::default())).unwrap(),
11181118
),
11191119
Err(InstructionError::NotEnoughAccountKeys),
11201120
);
@@ -1130,7 +1130,7 @@ mod tests {
11301130
true,
11311131
&mut nonce_state::create_account(1_000_000),
11321132
),],
1133-
&serialize(&SystemInstruction::NonceInitialize(Pubkey::default())).unwrap(),
1133+
&serialize(&SystemInstruction::InitializeNonceAccount(Pubkey::default())).unwrap(),
11341134
),
11351135
Err(InstructionError::NotEnoughAccountKeys),
11361136
);
@@ -1153,7 +1153,7 @@ mod tests {
11531153
&mut Account::default(),
11541154
),
11551155
],
1156-
&serialize(&SystemInstruction::NonceInitialize(Pubkey::default())).unwrap(),
1156+
&serialize(&SystemInstruction::InitializeNonceAccount(Pubkey::default())).unwrap(),
11571157
),
11581158
Err(InstructionError::InvalidArgument),
11591159
);
@@ -1180,7 +1180,7 @@ mod tests {
11801180
),
11811181
KeyedAccount::new(&sysvar::rent::id(), false, &mut Account::default(),),
11821182
],
1183-
&serialize(&SystemInstruction::NonceInitialize(Pubkey::default())).unwrap(),
1183+
&serialize(&SystemInstruction::InitializeNonceAccount(Pubkey::default())).unwrap(),
11841184
),
11851185
Err(InstructionError::InvalidArgument),
11861186
);
@@ -1211,7 +1211,7 @@ mod tests {
12111211
&mut sysvar::rent::create_account(1, &Rent::free())
12121212
),
12131213
],
1214-
&serialize(&SystemInstruction::NonceInitialize(Pubkey::default())).unwrap(),
1214+
&serialize(&SystemInstruction::InitializeNonceAccount(Pubkey::default())).unwrap(),
12151215
),
12161216
Ok(()),
12171217
);
@@ -1238,14 +1238,14 @@ mod tests {
12381238
&mut sysvar::rent::create_account(1, &Rent::free()),
12391239
),
12401240
],
1241-
&serialize(&SystemInstruction::NonceInitialize(Pubkey::default())).unwrap(),
1241+
&serialize(&SystemInstruction::InitializeNonceAccount(Pubkey::default())).unwrap(),
12421242
)
12431243
.unwrap();
12441244
assert_eq!(
12451245
super::process_instruction(
12461246
&Pubkey::default(),
12471247
&mut [KeyedAccount::new(&Pubkey::default(), true, &mut nonce_acc,),],
1248-
&serialize(&SystemInstruction::NonceAuthorize(Pubkey::default(),)).unwrap(),
1248+
&serialize(&SystemInstruction::AuthorizeNonceAccount(Pubkey::default(),)).unwrap(),
12491249
),
12501250
Ok(()),
12511251
);

sdk/src/system_instruction.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ pub enum SystemInstruction {
9292
space: u64,
9393
program_id: Pubkey,
9494
},
95-
/// `NonceAdvance` consumes a stored nonce, replacing it with a successor
95+
/// `AdvanceNonceAccount` consumes a stored nonce, replacing it with a successor
9696
///
9797
/// Expects 2 Accounts:
9898
/// 0 - A NonceAccount
9999
/// 1 - RecentBlockhashes sysvar
100100
///
101101
/// The current authority must sign a transaction executing this instrucion
102-
NonceAdvance,
103-
/// `NonceWithdraw` transfers funds out of the nonce account
102+
AdvanceNonceAccount,
103+
/// `WithdrawNonceAccount` transfers funds out of the nonce account
104104
///
105105
/// Expects 4 Accounts:
106106
/// 0 - A NonceAccount
@@ -112,8 +112,8 @@ pub enum SystemInstruction {
112112
/// account balance above the rent exempt reserve or at zero.
113113
///
114114
/// The current authority must sign a transaction executing this instruction
115-
NonceWithdraw(u64),
116-
/// `NonceInitialize` drives state of Uninitalized NonceAccount to Initialized,
115+
WithdrawNonceAccount(u64),
116+
/// `InitializeNonceAccount` drives state of Uninitalized NonceAccount to Initialized,
117117
/// setting the nonce value.
118118
///
119119
/// Expects 3 Accounts:
@@ -126,8 +126,8 @@ pub enum SystemInstruction {
126126
///
127127
/// No signatures are required to execute this instruction, enabling derived
128128
/// nonce account addresses
129-
NonceInitialize(Pubkey),
130-
/// `NonceAuthorize` changes the entity authorized to execute nonce instructions
129+
InitializeNonceAccount(Pubkey),
130+
/// `AuthorizeNonceAccount` changes the entity authorized to execute nonce instructions
131131
/// on the account
132132
///
133133
/// Expects 1 Account:
@@ -136,7 +136,7 @@ pub enum SystemInstruction {
136136
/// The `Pubkey` parameter identifies the entity to authorize
137137
///
138138
/// The current authority must sign a transaction executing this instruction
139-
NonceAuthorize(Pubkey),
139+
AuthorizeNonceAccount(Pubkey),
140140
}
141141

142142
pub fn create_account(
@@ -256,7 +256,7 @@ pub fn create_nonce_account_with_seed(
256256
),
257257
Instruction::new(
258258
system_program::id(),
259-
&SystemInstruction::NonceInitialize(*authority),
259+
&SystemInstruction::InitializeNonceAccount(*authority),
260260
vec![
261261
AccountMeta::new(*nonce_pubkey, false),
262262
AccountMeta::new_readonly(recent_blockhashes::id(), false),
@@ -282,7 +282,7 @@ pub fn create_nonce_account(
282282
),
283283
Instruction::new(
284284
system_program::id(),
285-
&SystemInstruction::NonceInitialize(*authority),
285+
&SystemInstruction::InitializeNonceAccount(*authority),
286286
vec![
287287
AccountMeta::new(*nonce_pubkey, false),
288288
AccountMeta::new_readonly(recent_blockhashes::id(), false),
@@ -300,7 +300,7 @@ pub fn nonce_advance(nonce_pubkey: &Pubkey, authorized_pubkey: &Pubkey) -> Instr
300300
.with_signer(authorized_pubkey);
301301
Instruction::new(
302302
system_program::id(),
303-
&SystemInstruction::NonceAdvance,
303+
&SystemInstruction::AdvanceNonceAccount,
304304
account_metas,
305305
)
306306
}
@@ -320,7 +320,7 @@ pub fn nonce_withdraw(
320320
.with_signer(authorized_pubkey);
321321
Instruction::new(
322322
system_program::id(),
323-
&SystemInstruction::NonceWithdraw(lamports),
323+
&SystemInstruction::WithdrawNonceAccount(lamports),
324324
account_metas,
325325
)
326326
}
@@ -333,7 +333,7 @@ pub fn nonce_authorize(
333333
let account_metas = vec![AccountMeta::new(*nonce_pubkey, false)].with_signer(authorized_pubkey);
334334
Instruction::new(
335335
system_program::id(),
336-
&SystemInstruction::NonceAuthorize(*new_authority),
336+
&SystemInstruction::AuthorizeNonceAccount(*new_authority),
337337
account_metas,
338338
)
339339
}

0 commit comments

Comments
 (0)