Skip to content

Commit 23007ca

Browse files
committed
improv : optimize more cus
1 parent 8fbfef7 commit 23007ca

40 files changed

+402
-603
lines changed

Cargo.lock

Lines changed: 0 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[workspace]
22
resolver = "2"
3-
members = [ "api", "client", "cli", "network", "program", "example" ]
3+
members = [ "api", "client", "cli", "network", "program"]
44

55
[workspace.package]
66
version = "0.2.1"

api/src/instruction/miner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub fn build_register_ix(
5050
name: &str
5151
) -> Instruction {
5252
let name = utils::to_name(name);
53-
let (miner_address, _bump) = miner_find_pda(signer, name);
53+
let (miner_address, _bump) = miner_find_pda(&signer, name);
5454

5555
Instruction {
5656
program_id: crate::ID,

api/src/instruction/program.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,25 @@ pub fn build_initialize_ix(
3535
let (block_pda, _block_bump) = block_pda();
3636
let (mint_pda, _mint_bump) = mint_pda();
3737
let (treasury_pda, _treasury_bump) = treasury_pda();
38-
let (treasury_ata, _treasury_ata_bump) = treasury_ata();
38+
let (treasury_ata, _treasury_ata_bump) = treasury_find_ata();
3939
let (metadata_pda, _metadata_bump) = metadata_find_pda(mint_pda);
4040

4141
let name = utils::to_name("genesis");
42-
let (tape_pda, _tape_bump) = tape_find_pda(signer, &name);
43-
let (writer_pda, _writer_bump) = writer_find_pda(tape_pda);
42+
let (tape_pda, _tape_bump) = tape_find_pda(&signer, &name);
43+
let (writer_pda, _writer_bump) = writer_find_pda(&tape_pda);
4444

4545
assert_eq!(treasury_ata, TREASURY_ATA);
4646

4747
Instruction {
4848
program_id: crate::ID,
4949
accounts: vec![
5050
AccountMeta::new(signer, true),
51-
AccountMeta::new(archive_pda, false),
52-
AccountMeta::new(epoch_pda, false),
53-
AccountMeta::new(block_pda, false),
51+
AccountMeta::new(*archive_pda, false),
52+
AccountMeta::new(*epoch_pda, false),
53+
AccountMeta::new(*block_pda, false),
5454
AccountMeta::new(metadata_pda, false),
55-
AccountMeta::new(mint_pda, false),
56-
AccountMeta::new(treasury_pda, false),
55+
AccountMeta::new(*mint_pda, false),
56+
AccountMeta::new(*treasury_pda, false),
5757
AccountMeta::new(treasury_ata, false),
5858
AccountMeta::new(tape_pda, false),
5959
AccountMeta::new(writer_pda, false),
@@ -63,14 +63,15 @@ pub fn build_initialize_ix(
6363
AccountMeta::new_readonly(spl_associated_token_account::ID, false),
6464
AccountMeta::new_readonly(mpl_token_metadata::ID, false),
6565
AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
66-
AccountMeta::new_readonly(sysvar::rent::ID, false)
66+
AccountMeta::new_readonly(sysvar::rent::ID, false),
67+
AccountMeta::new_readonly(sysvar::clock::ID, false)
68+
6769
],
6870
data: Initialize {}.to_bytes(),
6971
}
7072
}
7173

7274
pub fn build_airdrop_ix(
73-
signer: Pubkey,
7475
beneficiary: Pubkey,
7576
amount: u64
7677
) -> Instruction {
@@ -80,10 +81,9 @@ pub fn build_airdrop_ix(
8081
Instruction {
8182
program_id: crate::ID,
8283
accounts: vec![
83-
AccountMeta::new(signer, true),
8484
AccountMeta::new(beneficiary, false),
85-
AccountMeta::new(mint_pda, false),
86-
AccountMeta::new(treasury_pda, false),
85+
AccountMeta::new(*mint_pda, false),
86+
AccountMeta::new(*treasury_pda, false),
8787
AccountMeta::new_readonly(spl_token::ID, false),
8888
],
8989
data: Airdrop {

api/src/instruction/spool.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use steel::*;
22
use crate::{
3-
consts::*, pda::spool_find_pda,
3+
consts::*, pda::spool_find_pda, types::ProofPath,
44
};
55

66
#[repr(u8)]
@@ -56,7 +56,7 @@ pub fn build_create_ix(
5656
miner_address: Pubkey,
5757
number: u64,
5858
) -> Instruction {
59-
let (spool_address, _bump) = spool_find_pda(miner_address, number);
59+
let (spool_address, _bump) = spool_find_pda(&miner_address, number);
6060

6161
Instruction {
6262
program_id: crate::ID,
@@ -65,7 +65,6 @@ pub fn build_create_ix(
6565
AccountMeta::new(miner_address, false),
6666
AccountMeta::new(spool_address, false),
6767
AccountMeta::new_readonly(solana_program::system_program::ID, false),
68-
AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
6968
AccountMeta::new_readonly(sysvar::clock::ID, false),
7069
],
7170
data: Create {
@@ -79,14 +78,13 @@ pub fn build_destroy_ix(
7978
miner_address: Pubkey,
8079
number: u64,
8180
) -> Instruction {
82-
let (spool_address, _bump) = spool_find_pda(miner_address, number);
81+
let (spool_address, _bump) = spool_find_pda(&miner_address, number);
8382

8483
Instruction {
8584
program_id: crate::ID,
8685
accounts: vec![
8786
AccountMeta::new(signer, true),
8887
AccountMeta::new(spool_address, false),
89-
AccountMeta::new_readonly(solana_program::system_program::ID, false),
9088
],
9189
data: Destroy {}.to_bytes(),
9290
}

api/src/instruction/tape.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ pub fn build_create_ix(
6868
) -> Instruction {
6969
let name = utils::to_name(name);
7070

71-
let (tape_address, _tape_bump) = tape_find_pda(signer, &name);
72-
let (writer_address, _writer_bump) = writer_find_pda(tape_address);
71+
let (tape_address, _tape_bump) = tape_find_pda(&signer, &name);
72+
let (writer_address, _writer_bump) = writer_find_pda(&tape_address);
7373

7474
Instruction {
7575
program_id: crate::ID,
@@ -78,7 +78,7 @@ pub fn build_create_ix(
7878
AccountMeta::new(tape_address, false),
7979
AccountMeta::new(writer_address, false),
8080
AccountMeta::new_readonly(solana_program::system_program::ID, false),
81-
AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
81+
AccountMeta::new_readonly(sysvar::clock::ID, false),
8282
],
8383
data: Create {
8484
name,
@@ -119,6 +119,7 @@ pub fn build_write_ix(
119119
AccountMeta::new(signer, true),
120120
AccountMeta::new(tape, false),
121121
AccountMeta::new(writer, false),
122+
AccountMeta::new_readonly(sysvar::clock::ID, false)
122123
],
123124
data: ix_data,
124125
}

api/src/pda.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,23 @@ pub fn pda_derive_address<const N: usize>(
7171
unreachable!("deriving a pda is only available on target `solana`");
7272
}
7373

74-
pub fn archive_pda() -> (Pubkey, u8) {
75-
(ARCHIVE_ADDRESS, ARCHIVE_BUMP)
74+
pub const fn archive_pda() -> (&'static Pubkey, u8) {
75+
(&ARCHIVE_ADDRESS, ARCHIVE_BUMP)
7676
}
7777

78-
pub fn epoch_pda() -> (Pubkey, u8) {
79-
(EPOCH_ADDRESS, EPOCH_BUMP)
78+
pub const fn epoch_pda() -> (&'static Pubkey, u8) {
79+
(&EPOCH_ADDRESS, EPOCH_BUMP)
8080
}
8181

82-
pub fn block_pda() -> (Pubkey, u8) {
83-
(BLOCK_ADDRESS, BLOCK_BUMP)
82+
pub const fn block_pda() -> (&'static Pubkey, u8) {
83+
(&BLOCK_ADDRESS, BLOCK_BUMP)
8484
}
8585

86-
pub fn treasury_pda() -> (Pubkey, u8) {
87-
(TREASURY_ADDRESS, TREASURY_BUMP)
86+
pub const fn treasury_pda() -> (&'static Pubkey, u8) {
87+
(&TREASURY_ADDRESS, TREASURY_BUMP)
8888
}
8989

90-
pub fn treasury_ata() -> (Pubkey, u8) {
90+
pub fn treasury_find_ata() -> (Pubkey, u8) {
9191
let (treasury_pda,_bump) = treasury_pda();
9292
let (mint_pda, _bump) = mint_pda();
9393
Pubkey::find_program_address(
@@ -100,42 +100,42 @@ pub fn treasury_ata() -> (Pubkey, u8) {
100100
)
101101
}
102102

103-
pub fn mint_pda() -> (Pubkey, u8) {
104-
(MINT_ADDRESS, MINT_BUMP)
103+
pub const fn mint_pda() -> (&'static Pubkey, u8) {
104+
(&MINT_ADDRESS, MINT_BUMP)
105105
}
106106

107-
pub fn metadata_find_pda(mint: Pubkey) -> (Pubkey, u8) {
107+
pub fn metadata_find_pda(mint: &Pubkey) -> (Pubkey, u8) {
108108
Pubkey::find_program_address(
109109
&[METADATA, mpl_token_metadata::ID.as_ref(), mint.as_ref() ],
110110
&mpl_token_metadata::ID,
111111
)
112112
}
113113

114-
pub fn tape_find_pda(authority: Pubkey, name: &[u8; NAME_LEN]) -> (Pubkey, u8) {
114+
pub fn tape_find_pda(authority: &Pubkey, name: &[u8; NAME_LEN]) -> (Pubkey, u8) {
115115
Pubkey::find_program_address(&[TAPE, authority.as_ref(), name.as_ref()], &crate::id())
116116
}
117117

118-
pub fn tape_derive_pda(authority: Pubkey, name: &[u8; NAME_LEN], bump: u8) -> Pubkey {
118+
pub fn tape_derive_pda(authority: &Pubkey, name: &[u8; NAME_LEN], bump: u8) -> Pubkey {
119119
pda_derive_address(
120120
&[TAPE, authority.as_ref(), name.as_ref()],
121121
Some(bump),
122122
&crate::id(),
123123
)
124124
}
125125

126-
pub fn writer_find_pda(tape: Pubkey) -> (Pubkey, u8) {
126+
pub fn writer_find_pda(tape: &Pubkey) -> (Pubkey, u8) {
127127
Pubkey::find_program_address(&[WRITER, tape.as_ref()], &crate::id())
128128
}
129129

130-
pub fn writer_derive_pda(tape: Pubkey, bump: u8) -> Pubkey {
130+
pub fn writer_derive_pda(tape: &Pubkey, bump: u8) -> Pubkey {
131131
pda_derive_address(&[WRITER, tape.as_ref()], Some(bump), &crate::id())
132132
}
133133

134-
pub fn miner_find_pda(authority: Pubkey, name: [u8; NAME_LEN]) -> (Pubkey, u8) {
134+
pub fn miner_find_pda(authority: &Pubkey, name: [u8; NAME_LEN]) -> (Pubkey, u8) {
135135
Pubkey::find_program_address(&[MINER, authority.as_ref(), name.as_ref()], &crate::id())
136136
}
137137

138-
pub fn miner_derive_pda(authority: Pubkey, name: &[u8; NAME_LEN], bump: u8) -> Pubkey {
138+
pub fn miner_derive_pda(authority: &Pubkey, name: &[u8; NAME_LEN], bump: u8) -> Pubkey {
139139
pda_derive_address(
140140
&[MINER, authority.as_ref(), name.as_ref()],
141141
Some(bump),
@@ -144,14 +144,14 @@ pub fn miner_derive_pda(authority: Pubkey, name: &[u8; NAME_LEN], bump: u8) -> P
144144
}
145145

146146

147-
pub fn spool_find_pda(miner: Pubkey, number: u64) -> (Pubkey, u8) {
147+
pub fn spool_find_pda(miner: &Pubkey, number: u64) -> (Pubkey, u8) {
148148
Pubkey::find_program_address(
149149
&[SPOOL, miner.as_ref(), number.to_le_bytes().as_ref()],
150150
&crate::id(),
151151
)
152152
}
153153

154-
pub fn spool_derive_pda(miner: Pubkey, number: u64, bump: u8) -> Pubkey {
154+
pub fn spool_derive_pda(miner: &Pubkey, number: u64, bump: u8) -> Pubkey {
155155
pda_derive_address(
156156
&[SPOOL, miner.as_ref(), &number.to_le_bytes()],
157157
Some(bump),

api/src/state/tape.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ pub struct Tape {
2121
pub last_rent_block: u64,
2222
pub total_segments: u64,
2323

24-
pub total_segments: u64,
25-
2624
pub pda_bump: u64,
25+
26+
// +Phantom Vec<Hash> for merkle subtree nodes (up to 4096).
2727
}
2828

2929
#[repr(u64)]

cli/src/commands/network.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub async fn handle_register(
110110

111111
log::print_info("Registering miner...");
112112

113-
let (miner_address, _) = miner_find_pda(context.payer().pubkey(), to_name(&name));
113+
let (miner_address, _) = miner_find_pda(&context.payer().pubkey(), to_name(&name));
114114

115115
register_miner(context.rpc(), context.payer(), &name).await?;
116116

@@ -135,8 +135,8 @@ pub async fn get_or_create_miner(
135135
let (miner_address, name) = match (pubkey_opt, name_opt) {
136136
(Some(_), Some(_)) => bail!("Cannot provide both pubkey and name"),
137137
(Some(p), None) => (Pubkey::from_str(&p)?, None),
138-
(None, Some(n)) => (miner_find_pda(payer.pubkey(), to_name(&n)).0, Some(n)),
139-
(None, None) => (miner_find_pda(payer.pubkey(), to_name("default")).0, Some("default".to_string())),
138+
(None, Some(n)) => (miner_find_pda(&payer.pubkey(), to_name(&n)).0, Some(n)),
139+
(None, None) => (miner_find_pda(&payer.pubkey(), to_name("default")).0, Some("default".to_string())),
140140
};
141141

142142
let miner_account = get_miner_account(client, &miner_address).await;

client/src/program/airdrop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub async fn airdrop_tokens(
1818
amount: u64,
1919
) -> Result<Signature> {
2020
let compute_budget_ix = ComputeBudgetInstruction::set_compute_unit_limit(50_000);
21-
let airdrop_ix = build_airdrop_ix(signer.pubkey(), beneficiary, amount);
21+
let airdrop_ix = build_airdrop_ix(beneficiary, amount);
2222

2323
let signature = build_send_and_confirm_tx(
2424
&[compute_budget_ix, airdrop_ix],

0 commit comments

Comments
 (0)