Skip to content

Commit 800bb1a

Browse files
authored
chore(lazer): remove migration code from solana contract (#2257)
1 parent 072bee2 commit 800bb1a

File tree

4 files changed

+5
-278
lines changed

4 files changed

+5
-278
lines changed

lazer/contracts/solana/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"test:anchor": "CARGO_TARGET_DIR=\"$PWD/target\" anchor test",
99
"test": "pnpm run test:format && pnpm run test:anchor",
1010
"setup": "anchor build && pnpm ts-node scripts/setup.ts",
11-
"migrate_from_0_1_0": "pnpm ts-node scripts/migrate_from_0_1_0.ts",
1211
"check_trusted_signer": "pnpm ts-node scripts/check_trusted_signer.ts"
1312
},
1413
"dependencies": {

lazer/contracts/solana/programs/pyth-lazer-solana-contract/src/lib.rs

Lines changed: 2 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ mod signature;
22

33
use {
44
crate::signature::VerifiedMessage,
5-
anchor_lang::{
6-
prelude::*, solana_program::pubkey::PUBKEY_BYTES, system_program, Discriminator,
7-
},
8-
std::{io::Cursor, mem::size_of},
5+
anchor_lang::{prelude::*, solana_program::pubkey::PUBKEY_BYTES, system_program},
6+
std::mem::size_of,
97
};
108

119
pub use {
@@ -40,24 +38,6 @@ impl TrustedSignerInfo {
4038
const SERIALIZED_LEN: usize = PUBKEY_BYTES + size_of::<i64>();
4139
}
4240

43-
/// TODO: remove this legacy storage type
44-
#[derive(AnchorDeserialize)]
45-
pub struct StorageV010 {
46-
pub top_authority: Pubkey,
47-
pub num_trusted_signers: u8,
48-
pub trusted_signers: [TrustedSignerInfo; MAX_NUM_TRUSTED_SIGNERS],
49-
}
50-
51-
impl StorageV010 {
52-
pub const SERIALIZED_LEN: usize = PUBKEY_BYTES
53-
+ size_of::<u8>()
54-
+ TrustedSignerInfo::SERIALIZED_LEN * MAX_NUM_TRUSTED_SIGNERS;
55-
56-
pub fn initialized_trusted_signers(&self) -> &[TrustedSignerInfo] {
57-
&self.trusted_signers[0..usize::from(self.num_trusted_signers)]
58-
}
59-
}
60-
6141
#[account]
6242
pub struct Storage {
6343
pub top_authority: Pubkey,
@@ -98,43 +78,6 @@ pub mod pyth_lazer_solana_contract {
9878
Ok(())
9979
}
10080

101-
pub fn migrate_from_0_1_0(ctx: Context<MigrateFrom010>, treasury: Pubkey) -> Result<()> {
102-
let old_data = ctx.accounts.storage.data.borrow();
103-
if old_data[0..ANCHOR_DISCRIMINATOR_BYTES] != Storage::DISCRIMINATOR {
104-
return Err(ProgramError::InvalidAccountData.into());
105-
}
106-
if old_data.len() != StorageV010::SERIALIZED_LEN + ANCHOR_DISCRIMINATOR_BYTES {
107-
return Err(ProgramError::InvalidAccountData.into());
108-
}
109-
let old_storage = StorageV010::deserialize(&mut &old_data[ANCHOR_DISCRIMINATOR_BYTES..])?;
110-
if old_storage.top_authority != ctx.accounts.top_authority.key() {
111-
return Err(ProgramError::MissingRequiredSignature.into());
112-
}
113-
drop(old_data);
114-
115-
let space = ANCHOR_DISCRIMINATOR_BYTES + Storage::SERIALIZED_LEN;
116-
ctx.accounts.storage.realloc(space, false)?;
117-
let min_lamports = Rent::get()?.minimum_balance(space);
118-
if ctx.accounts.storage.lamports() < min_lamports {
119-
return Err(ProgramError::AccountNotRentExempt.into());
120-
}
121-
122-
let mut new_storage = Storage {
123-
top_authority: old_storage.top_authority,
124-
treasury,
125-
single_update_fee_in_lamports: 1,
126-
num_trusted_signers: old_storage.num_trusted_signers,
127-
trusted_signers: Default::default(),
128-
_extra_space: [0; EXTRA_SPACE],
129-
};
130-
new_storage.trusted_signers[..old_storage.trusted_signers.len()]
131-
.copy_from_slice(&old_storage.trusted_signers);
132-
new_storage.try_serialize(&mut Cursor::new(
133-
&mut **ctx.accounts.storage.data.borrow_mut(),
134-
))?;
135-
Ok(())
136-
}
137-
13881
pub fn update(ctx: Context<Update>, trusted_signer: Pubkey, expires_at: i64) -> Result<()> {
13982
let num_trusted_signers: usize = ctx.accounts.storage.num_trusted_signers.into();
14083
if num_trusted_signers > ctx.accounts.storage.trusted_signers.len() {
@@ -238,19 +181,6 @@ pub struct Initialize<'info> {
238181
pub system_program: Program<'info, System>,
239182
}
240183

241-
#[derive(Accounts)]
242-
pub struct MigrateFrom010<'info> {
243-
pub top_authority: Signer<'info>,
244-
#[account(
245-
mut,
246-
seeds = [STORAGE_SEED],
247-
bump,
248-
)]
249-
/// CHECK: top_authority in storage must match top_authority account.
250-
pub storage: AccountInfo<'info>,
251-
pub system_program: Program<'info, System>,
252-
}
253-
254184
#[derive(Accounts)]
255185
pub struct Update<'info> {
256186
pub top_authority: Signer<'info>,

lazer/contracts/solana/programs/pyth-lazer-solana-contract/tests/test1.rs

Lines changed: 3 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
use {
22
anchor_lang::{prelude::AccountMeta, InstructionData},
3-
pyth_lazer_solana_contract::{ed25519_program_args, ANCHOR_DISCRIMINATOR_BYTES},
3+
pyth_lazer_solana_contract::ed25519_program_args,
44
solana_program_test::{BanksClient, BanksClientError, ProgramTest},
55
solana_sdk::{
6-
account::Account,
76
ed25519_program,
87
hash::Hash,
98
instruction::{Instruction, InstructionError},
10-
pubkey::{Pubkey, PUBKEY_BYTES},
9+
pubkey::Pubkey,
1110
signature::Keypair,
1211
signer::Signer,
13-
system_instruction, system_program, system_transaction, sysvar,
12+
system_instruction, system_program, sysvar,
1413
transaction::{Transaction, TransactionError},
1514
},
1615
std::env,
@@ -293,129 +292,3 @@ async fn test_rejects_wrong_offset() {
293292
))
294293
));
295294
}
296-
297-
#[tokio::test]
298-
async fn test_migrate_from_0_1_0() {
299-
let mut program_test = program_test();
300-
// Create a storage PDA account with the data that was produced by the program v0.1.0.
301-
let mut old_storage_data = hex::decode(
302-
"d175ffb9c4af4409aa4dcb5d31150b162b664abd843cb231cee5c0ebf759ce371d9cb36ffc653796\
303-
0174313a6525edf99936aa1477e94c72bc5cc617b21745f5f03296f3154461f214ffffffffffffff7\
304-
f00000000000000000000000000000000000000000000000000000000000000000000000000000000",
305-
)
306-
.unwrap();
307-
let top_authority = Keypair::new();
308-
// Replace top authority pubkey in storage PDA data to allow successful migration.
309-
old_storage_data[ANCHOR_DISCRIMINATOR_BYTES..ANCHOR_DISCRIMINATOR_BYTES + PUBKEY_BYTES]
310-
.copy_from_slice(&top_authority.pubkey().to_bytes());
311-
program_test.add_account(
312-
pyth_lazer_solana_contract::STORAGE_ID,
313-
Account {
314-
lamports: 1733040,
315-
data: old_storage_data,
316-
owner: pyth_lazer_solana_contract::ID,
317-
executable: false,
318-
rent_epoch: 18446744073709551615,
319-
},
320-
);
321-
let mut setup = Setup::with_program_test(program_test).await;
322-
let treasury = setup.create_treasury().await;
323-
324-
// Make sure storage PDA will be rent-exempt after resize.
325-
let tx_transfer = system_transaction::transfer(
326-
&setup.payer,
327-
&pyth_lazer_solana_contract::STORAGE_ID,
328-
10_000_000,
329-
setup.recent_blockhash,
330-
);
331-
setup
332-
.banks_client
333-
.process_transaction(tx_transfer)
334-
.await
335-
.unwrap();
336-
337-
let mut transaction_migrate_contract = Transaction::new_with_payer(
338-
&[Instruction::new_with_bytes(
339-
pyth_lazer_solana_contract::ID,
340-
&pyth_lazer_solana_contract::instruction::MigrateFrom010 { treasury }.data(),
341-
vec![
342-
AccountMeta::new(top_authority.pubkey(), true),
343-
AccountMeta::new(pyth_lazer_solana_contract::STORAGE_ID, false),
344-
AccountMeta::new_readonly(system_program::ID, false),
345-
],
346-
)],
347-
Some(&setup.payer.pubkey()),
348-
);
349-
transaction_migrate_contract.sign(&[&setup.payer, &top_authority], setup.recent_blockhash);
350-
setup
351-
.banks_client
352-
.process_transaction(transaction_migrate_contract)
353-
.await
354-
.unwrap();
355-
356-
let message = hex::decode(
357-
"b9011a82e5cddee2c1bd364c8c57e1c98a6a28d194afcad410ff412226c8b2ae931ff59a57147cb47c7307\
358-
afc2a0a1abec4dd7e835a5b7113cf5aeac13a745c6bed6c60074313a6525edf99936aa1477e94c72bc5cc61\
359-
7b21745f5f03296f3154461f2141c0075d3c7931c9773f30a240600010102000000010000e1f50500000000",
360-
)
361-
.unwrap();
362-
363-
// The contract will recognize the trusted signer without calling `set_trusted`
364-
// because it was present in the original storage PDA data.
365-
setup.verify_message(&message, treasury).await;
366-
}
367-
368-
#[tokio::test]
369-
async fn test_disallows_extra_migrate() {
370-
let mut setup = Setup::new().await;
371-
let treasury = setup.create_treasury().await;
372-
373-
let mut transaction_init_contract = Transaction::new_with_payer(
374-
&[Instruction::new_with_bytes(
375-
pyth_lazer_solana_contract::ID,
376-
&pyth_lazer_solana_contract::instruction::Initialize {
377-
top_authority: setup.payer.pubkey(),
378-
treasury,
379-
}
380-
.data(),
381-
vec![
382-
AccountMeta::new(setup.payer.pubkey(), true),
383-
AccountMeta::new(pyth_lazer_solana_contract::STORAGE_ID, false),
384-
AccountMeta::new_readonly(system_program::ID, false),
385-
],
386-
)],
387-
Some(&setup.payer.pubkey()),
388-
);
389-
transaction_init_contract.sign(&[&setup.payer], setup.recent_blockhash);
390-
setup
391-
.banks_client
392-
.process_transaction(transaction_init_contract)
393-
.await
394-
.unwrap();
395-
396-
let mut transaction_migrate_contract = Transaction::new_with_payer(
397-
&[Instruction::new_with_bytes(
398-
pyth_lazer_solana_contract::ID,
399-
&pyth_lazer_solana_contract::instruction::MigrateFrom010 { treasury }.data(),
400-
vec![
401-
AccountMeta::new(setup.payer.pubkey(), true),
402-
AccountMeta::new(pyth_lazer_solana_contract::STORAGE_ID, false),
403-
AccountMeta::new_readonly(system_program::ID, false),
404-
],
405-
)],
406-
Some(&setup.payer.pubkey()),
407-
);
408-
transaction_migrate_contract.sign(&[&setup.payer], setup.recent_blockhash);
409-
let err = setup
410-
.banks_client
411-
.process_transaction(transaction_migrate_contract)
412-
.await
413-
.unwrap_err();
414-
assert!(matches!(
415-
err,
416-
BanksClientError::TransactionError(TransactionError::InstructionError(
417-
0,
418-
InstructionError::InvalidAccountData
419-
))
420-
));
421-
}

lazer/contracts/solana/scripts/migrate_from_0_1_0.ts

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)