Skip to content

Commit b4a716b

Browse files
authored
Set epoch schedule sysvar to match mainnet in surfnet init (#435)
1 parent 7334c0f commit b4a716b

File tree

3 files changed

+52
-10
lines changed

3 files changed

+52
-10
lines changed

crates/core/src/surfnet/locker.rs

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use solana_client::{
3434
use solana_clock::{Clock, Slot, UnixTimestamp};
3535
use solana_commitment_config::{CommitmentConfig, CommitmentLevel};
3636
use solana_epoch_info::EpochInfo;
37+
use solana_epoch_schedule::EpochSchedule;
3738
use solana_hash::Hash;
3839
use solana_loader_v3_interface::{get_program_data_address, state::UpgradeableLoaderState};
3940
use solana_message::{
@@ -215,23 +216,30 @@ impl SurfnetSvmLocker {
215216
do_profile_instructions: bool,
216217
log_bytes_limit: Option<usize>,
217218
) -> SurfpoolResult<EpochInfo> {
218-
let mut epoch_info = if let Some(remote_client) = remote_ctx {
219-
remote_client.get_epoch_info().await?
219+
let (mut epoch_info, epoch_schedule) = if let Some(remote_client) = remote_ctx {
220+
let epoch_info = remote_client.get_epoch_info().await?;
221+
let epoch_schedule = remote_client.get_epoch_schedule().await?;
222+
(epoch_info, epoch_schedule)
220223
} else {
221-
EpochInfo {
222-
epoch: 0,
223-
slot_index: 0,
224-
slots_in_epoch: SLOTS_PER_EPOCH,
225-
absolute_slot: FINALIZATION_SLOT_THRESHOLD,
226-
block_height: FINALIZATION_SLOT_THRESHOLD,
227-
transaction_count: None,
228-
}
224+
let epoch_schedule = EpochSchedule::without_warmup();
225+
(
226+
EpochInfo {
227+
epoch: 0,
228+
slot_index: 0,
229+
slots_in_epoch: epoch_schedule.slots_per_epoch,
230+
absolute_slot: FINALIZATION_SLOT_THRESHOLD,
231+
block_height: FINALIZATION_SLOT_THRESHOLD,
232+
transaction_count: None,
233+
},
234+
epoch_schedule,
235+
)
229236
};
230237
epoch_info.transaction_count = None;
231238

232239
self.with_svm_writer(|svm_writer| {
233240
svm_writer.initialize(
234241
epoch_info.clone(),
242+
epoch_schedule.clone(),
235243
slot_time,
236244
remote_ctx,
237245
do_profile_instructions,
@@ -3776,6 +3784,7 @@ mod tests {
37763784

37773785
use solana_account::Account;
37783786
use solana_account_decoder::UiAccountEncoding;
3787+
use solana_epoch_schedule::EpochSchedule;
37793788
use solana_transaction_status::TransactionStatusMeta;
37803789

37813790
use super::*;
@@ -4836,4 +4845,28 @@ mod tests {
48364845
assert!(sigs.contains(&sig_a.to_string()));
48374846
assert!(sigs.contains(&sig_b.to_string()));
48384847
}
4848+
4849+
#[tokio::test(flavor = "multi_thread")]
4850+
async fn initializes_epoch_schedule_without_warmup_when_offline() {
4851+
let (surfnet_svm, _simnet_events_rx, _geyser_events_rx) = SurfnetSvm::default();
4852+
let svm_locker = SurfnetSvmLocker::new(surfnet_svm);
4853+
4854+
svm_locker
4855+
.initialize(400, &None, false, None)
4856+
.await
4857+
.expect("initialize should succeed");
4858+
4859+
let epoch_schedule =
4860+
svm_locker.with_svm_reader(|svm_reader| svm_reader.inner.get_sysvar::<EpochSchedule>());
4861+
4862+
assert!(
4863+
!epoch_schedule.warmup,
4864+
"offline initialization should disable warmup to match mainnet"
4865+
);
4866+
assert_eq!(
4867+
epoch_schedule.get_first_slot_in_epoch(886),
4868+
886_u64 * 432_000,
4869+
"first slot should align with mainnet epoch boundaries when warmup is disabled"
4870+
);
4871+
}
48394872
}

crates/core/src/surfnet/remote.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use solana_client::{
2020
use solana_clock::Slot;
2121
use solana_commitment_config::CommitmentConfig;
2222
use solana_epoch_info::EpochInfo;
23+
use solana_epoch_schedule::EpochSchedule;
2324
use solana_hash::Hash;
2425
use solana_loader_v3_interface::get_program_data_address;
2526
use solana_pubkey::Pubkey;
@@ -91,6 +92,10 @@ impl SurfnetRemoteClient {
9192
self.client.get_epoch_info().await.map_err(Into::into)
9293
}
9394

95+
pub async fn get_epoch_schedule(&self) -> SurfpoolResult<EpochSchedule> {
96+
self.client.get_epoch_schedule().await.map_err(Into::into)
97+
}
98+
9499
pub async fn get_account(
95100
&self,
96101
pubkey: &Pubkey,

crates/core/src/surfnet/svm.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use solana_client::{
2727
use solana_clock::{Clock, Slot};
2828
use solana_commitment_config::{CommitmentConfig, CommitmentLevel};
2929
use solana_epoch_info::EpochInfo;
30+
use solana_epoch_schedule::EpochSchedule;
3031
use solana_feature_gate_interface::Feature;
3132
use solana_genesis_config::GenesisConfig;
3233
use solana_hash::Hash;
@@ -652,6 +653,7 @@ impl SurfnetSvm {
652653
pub fn initialize(
653654
&mut self,
654655
epoch_info: EpochInfo,
656+
epoch_schedule: EpochSchedule,
655657
slot_time: u64,
656658
remote_ctx: &Option<SurfnetRemoteClient>,
657659
do_profile_instructions: bool,
@@ -675,6 +677,8 @@ impl SurfnetSvm {
675677
let _ = self.register_idl(template.idl, None);
676678
}
677679

680+
self.inner.set_sysvar(&epoch_schedule);
681+
678682
if let Some(remote_client) = remote_ctx {
679683
let _ = self
680684
.simnet_events_tx

0 commit comments

Comments
 (0)