Skip to content

Commit ed82197

Browse files
committed
Cleanup
1 parent 12e57e3 commit ed82197

8 files changed

Lines changed: 50 additions & 141 deletions

File tree

src/args/commit_state.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ pub struct CommitBumps {
1212
pub delegation_record: u8,
1313
pub delegation_metadata: u8,
1414
pub validator_fees_vault: u8,
15-
pub program_config: u8,
1615
}
1716

1817
#[repr(C)]
@@ -33,7 +32,7 @@ pub struct CommitFinalizeArgs {
3332
/// bumps of the PDA accounts to be validated by the ix
3433
pub bumps: CommitBumps,
3534

36-
pub reserved_padding: [u8; 2],
35+
pub reserved_padding: [u8; 3],
3736
}
3837

3938
pub type CommitFinalizeArgsWithBuffer<'a> = ArgsWithBuffer<'a, CommitFinalizeArgs>;

src/instruction_builder/commit_finalize.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,21 @@ use crate::discriminator::DlpDiscriminator;
77
use crate::pod_view::PodView;
88
use crate::{
99
delegation_metadata_seeds_from_delegated_account,
10-
delegation_record_seeds_from_delegated_account, program_config_seeds_from_program_id,
11-
total_size_budget, validator_fees_vault_seeds_from_validator, AccountSizeClass,
12-
DLP_PROGRAM_DATA_SIZE_CLASS,
10+
delegation_record_seeds_from_delegated_account, total_size_budget,
11+
validator_fees_vault_seeds_from_validator, AccountSizeClass, DLP_PROGRAM_DATA_SIZE_CLASS,
1312
};
1413

1514
pub struct CommitPDAs {
1615
pub delegation_record: Pubkey,
1716
pub delegation_metadata: Pubkey,
1817
pub validator_fees_vault: Pubkey,
19-
pub program_config: Pubkey,
2018
}
2119

2220
/// Builds a commit finalize instruction.
2321
/// See [crate::processor::process_commit_finalize] for docs.
2422
pub fn commit_finalize(
2523
validator: Pubkey,
2624
delegated_account: Pubkey,
27-
delegated_account_owner: Pubkey,
2825
args: &mut CommitFinalizeArgs,
2926
state_or_diff: &[u8],
3027
) -> (Instruction, CommitPDAs) {
@@ -43,17 +40,11 @@ pub fn commit_finalize(
4340
&crate::id(),
4441
);
4542

46-
let program_config = Pubkey::find_program_address(
47-
program_config_seeds_from_program_id!(delegated_account_owner),
48-
&crate::id(),
49-
);
50-
5143
// save the bumps in the args
5244
args.bumps = CommitBumps {
5345
delegation_record: delegation_record.1,
5446
delegation_metadata: delegation_metadata.1,
5547
validator_fees_vault: validator_fees_vault.1,
56-
program_config: program_config.1,
5748
};
5849

5950
(
@@ -65,7 +56,6 @@ pub fn commit_finalize(
6556
AccountMeta::new_readonly(delegation_record.0, false),
6657
AccountMeta::new(delegation_metadata.0, false),
6758
AccountMeta::new_readonly(validator_fees_vault.0, false),
68-
AccountMeta::new_readonly(program_config.0, false),
6959
AccountMeta::new_readonly(system_program::id(), false),
7060
],
7161
data: [
@@ -79,7 +69,6 @@ pub fn commit_finalize(
7969
delegation_record: delegation_record.0,
8070
delegation_metadata: delegation_metadata.0,
8171
validator_fees_vault: validator_fees_vault.0,
82-
program_config: program_config.0,
8372
},
8473
)
8574
}
@@ -97,7 +86,6 @@ pub fn commit_finalize_size_budget(delegated_account: AccountSizeClass) -> u32 {
9786
AccountSizeClass::Tiny, // delegation_record_pda
9887
AccountSizeClass::Tiny, // delegation_metadata_pda
9988
AccountSizeClass::Tiny, // validator_fees_vault_pda
100-
AccountSizeClass::Tiny, // program_config_pda
10189
AccountSizeClass::Tiny, // system_program
10290
])
10391
}

src/processor/fast/commit_finalize.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ use crate::{require_n_accounts, DiffSet};
1919
/// 2: `[]` the delegation record
2020
/// 3: `[writable]` the delegation metadata
2121
/// 4: `[]` the validator fees vault
22-
/// 5: `[]` the program config account
23-
/// 6: `[]` system program
22+
/// 5: `[]` system program
2423
///
2524
/// Instruction Data: CommitFinalizeArgsWithBuffer
2625
///
@@ -35,9 +34,8 @@ pub fn process_commit_finalize(
3534
delegation_record_account,
3635
delegation_metadata_account,
3736
validator_fees_vault,
38-
program_config_account,
3937
_system_program,
40-
] = require_n_accounts!(accounts, 7);
38+
] = require_n_accounts!(accounts, 6);
4139

4240
let args = CommitFinalizeArgsWithBuffer::from_bytes(data)?;
4341

@@ -59,7 +57,6 @@ pub fn process_commit_finalize(
5957
delegation_record_account,
6058
delegation_metadata_account,
6159
validator_fees_vault,
62-
program_config_account,
6360
};
6461

6562
process_commit_finalize_internal(commit_args)

src/processor/fast/commit_state.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,6 @@ pub(crate) fn process_commit_state_internal(
184184
return Err(DlpError::InvalidAuthority.into());
185185
}
186186

187-
// TODO (snawaz): what exactly is ensured here? why can't the delegated_account's lamports be
188-
// different?
189-
//
190187
// If there was an issue with the lamport accounting in the past, abort (this should never happen)
191188
if args.delegated_account.lamports() < delegation_record.lamports {
192189
log!(
@@ -200,8 +197,6 @@ pub(crate) fn process_commit_state_internal(
200197
// We need to do that so that the finalizer already have all the lamports from the validators ready at finalize time
201198
// The finalizer can return any extra lamport to the validator during finalize, but this acts as the validator's proof of collateral
202199
if args.commit_record_lamports > delegation_record.lamports {
203-
// TODO (snawaz): commit_state_account does not exist yet. So how do we transfer lamports
204-
// to non-existent account? we can do that when we create it?
205200
system::Transfer {
206201
from: args.validator,
207202
to: args.commit_state_account,

src/processor/fast/internal/commit_finalize_internal.rs

Lines changed: 33 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ use pinocchio_log::log;
55
use crate::args::CommitBumps;
66
use crate::error::DlpError;
77
use crate::pod_view::PodView;
8-
use crate::processor::fast::{to_pinocchio_program_error, NewState};
9-
use crate::state::{DelegationMetadataFast, DelegationRecord, ProgramConfig};
8+
use crate::processor::fast::NewState;
9+
use crate::state::{DelegationMetadataFast, DelegationRecord};
1010
use crate::{
1111
apply_diff_in_place, pda, require, require_eq, require_eq_keys, require_ge,
12-
require_initialized_pda, require_initialized_pda_fast, require_owned_by,
13-
require_program_config, require_program_config_fast, require_signer,
12+
require_initialized_pda_fast, require_owned_by, require_signer,
1413
};
1514

1615
/// Arguments for the commit state internal function
@@ -24,7 +23,6 @@ pub(crate) struct CommitFinalizeInternalArgs<'a> {
2423
pub(crate) delegation_record_account: &'a AccountInfo,
2524
pub(crate) delegation_metadata_account: &'a AccountInfo,
2625
pub(crate) validator_fees_vault: &'a AccountInfo,
27-
pub(crate) program_config_account: &'a AccountInfo,
2826
}
2927

3028
/// Commit a new state of a delegated Pda
@@ -36,77 +34,41 @@ pub(crate) fn process_commit_finalize_internal(
3634

3735
require_signer!(args.validator);
3836

39-
// additional cost: 4105
40-
if false {
41-
require_initialized_pda!(
42-
args.delegation_record_account,
43-
&[
44-
pda::DELEGATION_RECORD_TAG,
45-
args.delegated_account.key(),
46-
&[args.bumps.delegation_record]
47-
],
37+
require_initialized_pda_fast!(
38+
args.delegation_record_account,
39+
&[
40+
pda::DELEGATION_RECORD_TAG,
41+
args.delegated_account.key(),
42+
&[args.bumps.delegation_record],
4843
&crate::fast::ID,
49-
false
50-
);
44+
PDA_MARKER
45+
],
46+
false
47+
);
5148

52-
require_initialized_pda!(
53-
args.delegation_metadata_account,
54-
&[
55-
pda::DELEGATION_METADATA_TAG,
56-
args.delegated_account.key(),
57-
&[args.bumps.delegation_metadata]
58-
],
49+
require_initialized_pda_fast!(
50+
args.delegation_metadata_account,
51+
&[
52+
pda::DELEGATION_METADATA_TAG,
53+
args.delegated_account.key(),
54+
&[args.bumps.delegation_metadata],
5955
&crate::fast::ID,
60-
true
61-
);
56+
PDA_MARKER
57+
],
58+
true
59+
);
6260

63-
require_initialized_pda!(
64-
args.validator_fees_vault,
65-
&[
66-
pda::VALIDATOR_FEES_VAULT_TAG,
67-
args.validator.key(),
68-
&[args.bumps.validator_fees_vault]
69-
],
61+
require_initialized_pda_fast!(
62+
args.validator_fees_vault,
63+
&[
64+
pda::VALIDATOR_FEES_VAULT_TAG,
65+
args.validator.key(),
66+
&[args.bumps.validator_fees_vault],
7067
&crate::fast::ID,
71-
false
72-
);
73-
} else {
74-
require_initialized_pda_fast!(
75-
args.delegation_record_account,
76-
&[
77-
pda::DELEGATION_RECORD_TAG,
78-
args.delegated_account.key(),
79-
&[args.bumps.delegation_record],
80-
&crate::fast::ID,
81-
PDA_MARKER
82-
],
83-
false
84-
);
85-
86-
require_initialized_pda_fast!(
87-
args.delegation_metadata_account,
88-
&[
89-
pda::DELEGATION_METADATA_TAG,
90-
args.delegated_account.key(),
91-
&[args.bumps.delegation_metadata],
92-
&crate::fast::ID,
93-
PDA_MARKER
94-
],
95-
true
96-
);
97-
98-
require_initialized_pda_fast!(
99-
args.validator_fees_vault,
100-
&[
101-
pda::VALIDATOR_FEES_VAULT_TAG,
102-
args.validator.key(),
103-
&[args.bumps.validator_fees_vault],
104-
&crate::fast::ID,
105-
PDA_MARKER
106-
],
107-
false
108-
);
109-
}
68+
PDA_MARKER
69+
],
70+
false
71+
);
11072

11173
// validate and update metadata
11274
{
@@ -148,41 +110,6 @@ pub(crate) fn process_commit_finalize_internal(
148110
// .invoke()?;
149111
// }
150112

151-
// cost = 197 CU
152-
if false {
153-
// Load the program configuration and validate it, if any
154-
let has_program_config = if false {
155-
require_program_config!(
156-
args.program_config_account,
157-
delegation_record.owner.as_array(),
158-
args.bumps.program_config,
159-
false
160-
)
161-
} else {
162-
require_program_config_fast!(
163-
args.program_config_account,
164-
delegation_record.owner.as_array(),
165-
args.bumps.program_config,
166-
false
167-
)
168-
};
169-
if has_program_config {
170-
let program_config_data = args.program_config_account.try_borrow_data()?;
171-
172-
let program_config =
173-
ProgramConfig::try_from_bytes_with_discriminator(&program_config_data)
174-
.map_err(to_pinocchio_program_error)?;
175-
if !program_config
176-
.approved_validators
177-
.contains(&(*args.validator.key()).into())
178-
{
179-
log!("validator is not whitelisted in the program config: ");
180-
pubkey::log(args.validator.key());
181-
return Err(DlpError::InvalidWhitelistProgramConfig.into());
182-
}
183-
}
184-
}
185-
186113
args.delegated_account.resize(args.new_state.data_len())?;
187114

188115
// copy the new state to the delegated account

src/processor/fast/utils/requires.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,13 @@ macro_rules! require_initialized_pda {
266266
#[macro_export]
267267
macro_rules! require_initialized_pda_fast {
268268
($info:expr, $seeds: expr, $is_writable: expr) => {{
269-
use solana_sha256_hasher::hashv;
270-
let pda = hashv($seeds).to_bytes();
269+
//
270+
// Ideally, we want to der
271+
//
272+
//
273+
//
274+
let pda = solana_sha256_hasher::hashv($seeds).to_bytes();
275+
271276
if !pubkey_eq($info.key(), &pda) {
272277
log!(
273278
"require_initialized_pda!({}, {}, {}); pubkey_eq failed",
@@ -395,7 +400,7 @@ macro_rules! require_program_config_fast {
395400
$program,
396401
&[$bump],
397402
&$crate::fast::ID,
398-
PDA_MARKER
403+
pinocchio::pubkey::PDA_MARKER
399404
],
400405
$is_writable
401406
);

src/state/delegation_metadata.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ impl<'a> DelegationMetadataFast<'a> {
3737
pub fn from_account(account: &'a AccountInfo) -> Result<Self, ProgramError> {
3838
require_ge!(
3939
account.data_len(),
40-
8 // last_update_nonce
41-
+ 1 // is_undelegatable
40+
8 // discriminator
41+
+ 8 // last_update_nonce
42+
+ 1 // is_undelegatable
4243
+ 32 // rent_payer
4344
+ 4, // seeds (at least 4)
4445
ProgramError::InvalidAccountData

tests/test_commit_finalize.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ use solana_sdk::{
1414
};
1515

1616
use crate::fixtures::{
17-
get_delegation_metadata_data, get_delegation_record_data, DELEGATED_PDA_ID,
18-
DELEGATED_PDA_OWNER_ID, TEST_AUTHORITY,
17+
get_delegation_metadata_data, get_delegation_record_data, DELEGATED_PDA_ID, TEST_AUTHORITY,
1918
};
2019

2120
mod fixtures;
@@ -31,7 +30,6 @@ async fn test_commit_finalize_perf() {
3130
let (ix, pdas) = dlp::instruction_builder::commit_finalize(
3231
authority.pubkey(),
3332
DELEGATED_PDA_ID,
34-
DELEGATED_PDA_OWNER_ID,
3533
&mut CommitFinalizeArgs {
3634
commit_id: 1,
3735
allow_undelegation: true.into(),
@@ -94,7 +92,6 @@ async fn test_commit_finalize_out_of_order() {
9492
let (ix, _pdas) = dlp::instruction_builder::commit_finalize(
9593
authority.pubkey(),
9694
DELEGATED_PDA_ID,
97-
DELEGATED_PDA_OWNER_ID,
9895
&mut CommitFinalizeArgs {
9996
commit_id: 2, // this is the min value which will cause NonceOutOfOrder
10097
allow_undelegation: true.into(),

0 commit comments

Comments
 (0)