Skip to content

Commit 2a323ef

Browse files
feat: allow foresters to register at any time by disabling registration phase time check (#2321)
* feat: allow foresters to register at any time by disabling registration phase time check * test: add register any time functional test --------- Co-authored-by: ananas <jorrit@lightprotocol.com>
1 parent d69cbd0 commit 2a323ef

2 files changed

Lines changed: 98 additions & 1 deletion

File tree

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
use forester_utils::forester_epoch::Epoch;
2+
use light_program_test::{
3+
program_test::{LightProgramTest, TestRpc},
4+
ProgramTestConfig,
5+
};
6+
use light_registry::{
7+
protocol_config::state::{ProtocolConfig, ProtocolConfigPda},
8+
ForesterConfig, ForesterEpochPda,
9+
};
10+
use light_test_utils::{
11+
assert_epoch::{assert_epoch_pda, assert_registered_forester_pda},
12+
register_test_forester, Rpc,
13+
};
14+
use serial_test::serial;
15+
use solana_sdk::{signature::Keypair, signer::Signer};
16+
17+
/// Verifies that foresters can register for an epoch outside the original
18+
/// registration window (slots 0-99 with default config). Previously this
19+
/// would fail with `NotInRegistrationPeriod`.
20+
#[serial]
21+
#[tokio::test]
22+
async fn test_forester_register_outside_registration_phase() {
23+
let config = ProgramTestConfig {
24+
protocol_config: ProtocolConfig::default(),
25+
with_prover: false,
26+
with_forester: false,
27+
..Default::default()
28+
};
29+
let mut rpc = LightProgramTest::new(config).await.unwrap();
30+
rpc.indexer = None;
31+
let env = rpc.test_accounts.clone();
32+
33+
let forester_keypair = Keypair::new();
34+
rpc.airdrop_lamports(&forester_keypair.pubkey(), 1_000_000_000)
35+
.await
36+
.unwrap();
37+
38+
// Register the base forester PDA.
39+
register_test_forester(
40+
&mut rpc,
41+
&env.protocol.governance_authority,
42+
&forester_keypair.pubkey(),
43+
ForesterConfig { fee: 1 },
44+
)
45+
.await
46+
.unwrap();
47+
48+
let protocol_config = rpc
49+
.get_anchor_account::<ProtocolConfigPda>(&env.protocol.governance_authority_pda)
50+
.await
51+
.unwrap()
52+
.unwrap()
53+
.config;
54+
55+
// Warp to slot 500 -- well past the old registration window (0-99).
56+
// With ProtocolConfig::default() the active phase starts at slot 100.
57+
rpc.warp_to_slot(500).unwrap();
58+
59+
// Register for epoch 0 with explicit epoch to bypass client-side
60+
// auto-detection (which would skip if not in registration phase).
61+
let registered_epoch = Epoch::register(
62+
&mut rpc,
63+
&protocol_config,
64+
&forester_keypair,
65+
&forester_keypair.pubkey(),
66+
Some(0),
67+
)
68+
.await
69+
.unwrap();
70+
71+
assert!(
72+
registered_epoch.is_some(),
73+
"Forester should be able to register outside the original registration window"
74+
);
75+
let registered_epoch = registered_epoch.unwrap();
76+
77+
let forester_epoch_pda = rpc
78+
.get_anchor_account::<ForesterEpochPda>(&registered_epoch.forester_epoch_pda)
79+
.await
80+
.unwrap()
81+
.unwrap();
82+
assert_eq!(forester_epoch_pda.epoch, 0);
83+
assert!(forester_epoch_pda.total_epoch_weight.is_none());
84+
85+
assert_epoch_pda(&mut rpc, 0, 1).await;
86+
assert_registered_forester_pda(
87+
&mut rpc,
88+
&registered_epoch.forester_epoch_pda,
89+
&forester_keypair.pubkey(),
90+
0,
91+
)
92+
.await;
93+
}

programs/registry/src/protocol_config/state.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,16 @@ impl ProtocolConfig {
184184

185185
/// In the last part of the active phase the registration phase starts.
186186
/// Returns end slot of the registration phase/start slot of the next active phase.
187+
/// Registration phase time check is temporarily disabled to allow
188+
/// foresters to register for the current epoch at any time.
187189
pub fn is_registration_phase(&self, slot: u64) -> Result<u64> {
188190
let latest_register_epoch = self.get_latest_register_epoch(slot)?;
191+
/*
189192
let latest_register_epoch_progress = self.get_latest_register_epoch_progress(slot)?;
190193
if latest_register_epoch_progress >= self.registration_phase_length {
191194
return err!(RegistryError::NotInRegistrationPeriod);
192-
}
195+
} */
196+
193197
Ok((latest_register_epoch) * self.active_phase_length
194198
+ self.genesis_slot
195199
+ self.registration_phase_length)

0 commit comments

Comments
 (0)