-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathcommit_diff.rs
More file actions
88 lines (85 loc) · 3.42 KB
/
Copy pathcommit_diff.rs
File metadata and controls
88 lines (85 loc) · 3.42 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
use dlp::{
args::CommitDiffArgs,
discriminator::DlpDiscriminator,
pda::{
commit_record_pda_from_delegated_account,
commit_state_pda_from_delegated_account,
delegation_metadata_pda_from_delegated_account,
delegation_record_pda_from_delegated_account,
program_config_from_program_id,
validator_fees_vault_pda_from_validator,
},
total_size_budget, AccountSizeClass, DLP_PROGRAM_DATA_SIZE_CLASS,
};
use solana_program::{
instruction::{AccountMeta, Instruction},
pubkey::Pubkey,
};
use solana_sdk_ids::system_program;
use crate::compat::{borsh::to_vec, Compatize, Modernize};
/// Builds a commit state instruction.
/// See [dlp::processor::fast::process_commit_diff] for docs.
pub fn commit_diff(
validator: Pubkey,
delegated_account: Pubkey,
delegated_account_owner: Pubkey,
commit_args: CommitDiffArgs,
) -> Instruction {
let commit_args = to_vec(&commit_args).unwrap();
let validator_compat = validator.compatize();
let delegated_account_compat = delegated_account.compatize();
let delegated_account_owner_compat = delegated_account_owner.compatize();
let delegation_record_pda =
delegation_record_pda_from_delegated_account(&delegated_account_compat)
.modernize();
let commit_state_pda =
commit_state_pda_from_delegated_account(&delegated_account_compat)
.modernize();
let commit_record_pda =
commit_record_pda_from_delegated_account(&delegated_account_compat)
.modernize();
let validator_fees_vault_pda =
validator_fees_vault_pda_from_validator(&validator_compat).modernize();
let delegation_metadata_pda =
delegation_metadata_pda_from_delegated_account(
&delegated_account_compat,
)
.modernize();
let program_config_pda =
program_config_from_program_id(&delegated_account_owner_compat)
.modernize();
Instruction {
program_id: dlp::id().modernize(),
accounts: vec![
AccountMeta::new(validator, true),
AccountMeta::new_readonly(delegated_account, false),
AccountMeta::new(commit_state_pda, false),
AccountMeta::new(commit_record_pda, false),
AccountMeta::new_readonly(delegation_record_pda, false),
AccountMeta::new(delegation_metadata_pda, false),
AccountMeta::new_readonly(validator_fees_vault_pda, false),
AccountMeta::new_readonly(program_config_pda, false),
AccountMeta::new_readonly(system_program::id(), false),
],
data: [DlpDiscriminator::CommitDiff.to_vec(), commit_args].concat(),
}
}
///
/// Returns accounts-data-size budget for commit_diff instruction.
///
/// This value can be used with ComputeBudgetInstruction::SetLoadedAccountsDataSizeLimit
///
pub fn commit_diff_size_budget(delegated_account: AccountSizeClass) -> u32 {
total_size_budget(&[
DLP_PROGRAM_DATA_SIZE_CLASS,
AccountSizeClass::Tiny, // validator
delegated_account, // delegated_account
delegated_account, // commit_state_pda
AccountSizeClass::Tiny, // commit_record_pda
AccountSizeClass::Tiny, // delegation_record_pda
AccountSizeClass::Tiny, // delegation_metadata_pda
AccountSizeClass::Tiny, // validator_fees_vault_pda
AccountSizeClass::Tiny, // program_config_pda
AccountSizeClass::Tiny, // system_program
])
}