Skip to content

Commit ee15a14

Browse files
authored
undo MessageToRelay PDA udpate (#88)
1 parent 54a2575 commit ee15a14

3 files changed

Lines changed: 14 additions & 20 deletions

File tree

solana/programs/base_relayer/src/constants.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,3 @@ pub const SCALE: u128 = 1_000_000;
55

66
#[constant]
77
pub const CFG_SEED: &[u8] = b"config";
8-
9-
#[constant]
10-
pub const MSG_SEED: &[u8] = b"message";

solana/programs/base_relayer/src/instructions/pay_for_relay.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
use anchor_lang::prelude::*;
22

33
use crate::{
4-
constants::{CFG_SEED, MSG_SEED},
4+
constants::CFG_SEED,
55
internal::check_and_pay_for_gas,
66
state::{Cfg, MessageToRelay},
77
};
88

99
#[derive(Accounts)]
10-
#[instruction(outgoing_message: Pubkey)]
1110
pub struct PayForRelay<'info> {
1211
/// The account that pays for transaction fees and account creation.
1312
/// Must be mutable to deduct lamports for account rent and gas fees.
@@ -25,7 +24,7 @@ pub struct PayForRelay<'info> {
2524
#[account(mut, address = cfg.gas_config.gas_fee_receiver @ PayForRelayError::IncorrectGasFeeReceiver)]
2625
pub gas_fee_receiver: AccountInfo<'info>,
2726

28-
#[account(init, payer = payer, seeds = [MSG_SEED, outgoing_message.as_ref()], bump, space = 8 + MessageToRelay::INIT_SPACE)]
27+
#[account(init, payer = payer, space = 8 + MessageToRelay::INIT_SPACE)]
2928
pub message_to_relay: Account<'info, MessageToRelay>,
3029

3130
/// System program required for creating new accounts.
@@ -71,6 +70,7 @@ mod tests {
7170
solana_program::{instruction::Instruction, system_program},
7271
InstructionData,
7372
};
73+
use solana_keypair::Keypair;
7474
use solana_message::Message;
7575
use solana_signer::Signer;
7676
use solana_transaction::Transaction;
@@ -88,14 +88,13 @@ mod tests {
8888
let gas_limit: u64 = 123_456;
8989

9090
// New account to be initialized by the instruction
91-
let (message_to_relay, _) =
92-
Pubkey::find_program_address(&[MSG_SEED, outgoing_message.as_ref()], &crate::ID);
91+
let message_to_relay = Keypair::new();
9392

9493
let accounts = accounts::PayForRelay {
9594
payer: payer_pk,
9695
cfg: config_pda,
9796
gas_fee_receiver: TEST_GAS_FEE_RECEIVER,
98-
message_to_relay,
97+
message_to_relay: message_to_relay.pubkey(),
9998
system_program: system_program::ID,
10099
}
101100
.to_account_metas(None);
@@ -111,7 +110,7 @@ mod tests {
111110
};
112111

113112
let tx = Transaction::new(
114-
&[&payer],
113+
&[&payer, &message_to_relay],
115114
Message::new(&[ix], Some(&payer_pk)),
116115
svm.latest_blockhash(),
117116
);
@@ -120,7 +119,7 @@ mod tests {
120119
.expect("failed to send transaction");
121120

122121
// Assert message account was initialized with expected fields
123-
let msg_account = svm.get_account(&message_to_relay).unwrap();
122+
let msg_account = svm.get_account(&message_to_relay.pubkey()).unwrap();
124123
let msg = MessageToRelay::try_deserialize(&mut &msg_account.data[..]).unwrap();
125124
assert_eq!(msg.outgoing_message, outgoing_message);
126125
assert_eq!(msg.gas_limit, gas_limit);

solana/programs/base_relayer/src/internal/gas_config.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ pub enum GasConfigError {
7373
#[cfg(test)]
7474
mod tests {
7575
use super::*;
76-
use crate::constants::MSG_SEED;
7776
use crate::internal::{Eip1559, Eip1559Config};
7877
use crate::state::Cfg;
7978
use crate::test_utils::{mock_clock, setup_program_and_svm, TEST_GAS_FEE_RECEIVER};
8079
use crate::{accounts, instruction};
8180
use anchor_lang::solana_program::{instruction::Instruction, system_program};
8281
use anchor_lang::InstructionData;
82+
use solana_keypair::Keypair;
8383
use solana_message::Message;
8484
use solana_signer::Signer as _;
8585
use solana_transaction::Transaction;
@@ -165,13 +165,12 @@ mod tests {
165165

166166
// Now pay for relay with gas_limit=123; base_fee=1 => transfer=246
167167
let outgoing_message = Pubkey::new_unique();
168-
let (message_to_relay, _) =
169-
Pubkey::find_program_address(&[MSG_SEED, outgoing_message.as_ref()], &crate::ID);
168+
let message_to_relay = Keypair::new();
170169
let accounts = accounts::PayForRelay {
171170
payer: payer_pk,
172171
cfg: cfg_pda,
173172
gas_fee_receiver: TEST_GAS_FEE_RECEIVER,
174-
message_to_relay,
173+
message_to_relay: message_to_relay.pubkey(),
175174
system_program: system_program::ID,
176175
}
177176
.to_account_metas(None);
@@ -188,7 +187,7 @@ mod tests {
188187
};
189188

190189
let tx = Transaction::new(
191-
&[&payer],
190+
&[&payer, &message_to_relay],
192191
Message::new(&[ix], Some(&payer_pk)),
193192
svm.latest_blockhash(),
194193
);
@@ -256,13 +255,12 @@ mod tests {
256255

257256
let gas_limit = 1_000u64;
258257
let outgoing_message = Pubkey::new_unique();
259-
let (message_to_relay, _) =
260-
Pubkey::find_program_address(&[MSG_SEED, outgoing_message.as_ref()], &crate::ID);
258+
let message_to_relay = Keypair::new();
261259
let accounts = accounts::PayForRelay {
262260
payer: payer_pk,
263261
cfg: cfg_pda,
264262
gas_fee_receiver: TEST_GAS_FEE_RECEIVER,
265-
message_to_relay,
263+
message_to_relay: message_to_relay.pubkey(),
266264
system_program: system_program::ID,
267265
}
268266
.to_account_metas(None);
@@ -278,7 +276,7 @@ mod tests {
278276
};
279277

280278
let tx = Transaction::new(
281-
&[&payer],
279+
&[&payer, &message_to_relay],
282280
Message::new(&[ix], Some(&payer_pk)),
283281
svm.latest_blockhash(),
284282
);

0 commit comments

Comments
 (0)