Repository navigation
Expand file tree
/
Copy pathcommit_finalize.rs
More file actions
95 lines (87 loc) · 3.13 KB
/
Copy pathcommit_finalize.rs
File metadata and controls
95 lines (87 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
use dlp::{
args::{CommitBumps, CommitFinalizeArgs},
delegation_metadata_seeds_from_delegated_account,
delegation_record_seeds_from_delegated_account,
discriminator::DlpDiscriminator,
pod_view::PodView,
total_size_budget, validator_fees_vault_seeds_from_validator,
AccountSizeClass, DLP_PROGRAM_DATA_SIZE_CLASS,
};
use solana_program::{
instruction::{AccountMeta, Instruction},
pubkey::Pubkey,
};
use solana_sdk_ids::system_program;
use crate::compat::Modernize;
pub struct CommitPDAs {
pub delegation_record: Pubkey,
pub delegation_metadata: Pubkey,
pub validator_fees_vault: Pubkey,
}
/// Builds a commit finalize instruction.
/// See [dlp::processor::process_commit_finalize] for docs.
pub fn commit_finalize(
validator: Pubkey,
delegated_account: Pubkey,
args: &mut CommitFinalizeArgs,
state_or_diff: &[u8],
) -> (Instruction, CommitPDAs) {
let delegation_record = Pubkey::find_program_address(
delegation_record_seeds_from_delegated_account!(delegated_account),
&dlp::id().modernize(),
);
let delegation_metadata = Pubkey::find_program_address(
delegation_metadata_seeds_from_delegated_account!(delegated_account),
&dlp::id().modernize(),
);
let validator_fees_vault = Pubkey::find_program_address(
validator_fees_vault_seeds_from_validator!(validator),
&dlp::id().modernize(),
);
// save the bumps in the args
args.bumps = CommitBumps {
delegation_record: delegation_record.1,
delegation_metadata: delegation_metadata.1,
validator_fees_vault: validator_fees_vault.1,
};
(
Instruction {
program_id: dlp::id().modernize(),
accounts: vec![
AccountMeta::new(validator, true),
AccountMeta::new(delegated_account, false),
AccountMeta::new(delegation_record.0, false),
AccountMeta::new(delegation_metadata.0, false),
AccountMeta::new(validator_fees_vault.0, false),
AccountMeta::new_readonly(system_program::id(), false),
],
data: [
DlpDiscriminator::CommitFinalize.to_vec(),
args.to_bytes(),
state_or_diff.to_vec(),
]
.concat(),
},
CommitPDAs {
delegation_record: delegation_record.0,
delegation_metadata: delegation_metadata.0,
validator_fees_vault: validator_fees_vault.0,
},
)
}
///
/// Returns accounts-data-size budget for commit_finalize instruction.
///
/// This value can be used with ComputeBudgetInstruction::SetLoadedAccountsDataSizeLimit
///
pub fn commit_finalize_size_budget(delegated_account: AccountSizeClass) -> u32 {
total_size_budget(&[
DLP_PROGRAM_DATA_SIZE_CLASS,
AccountSizeClass::Tiny, // validator
delegated_account, // delegated_account
AccountSizeClass::Tiny, // delegation_record_pda
AccountSizeClass::Tiny, // delegation_metadata_pda
AccountSizeClass::Tiny, // validator_fees_vault_pda
AccountSizeClass::Tiny, // system_program
])
}