Skip to content

Commit 5e3da34

Browse files
committed
chore: port pythnet features
1 parent 479999b commit 5e3da34

File tree

2 files changed

+74
-14
lines changed

2 files changed

+74
-14
lines changed

runtime/src/bank.rs

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,18 @@ impl Bank {
14091409
bank.update_epoch_schedule();
14101410
bank.update_recent_blockhashes();
14111411
bank.fill_missing_sysvar_cache_entries();
1412-
bank.update_accumulator();
1412+
1413+
// If the accumulator is not moved to end of block, update the
1414+
// accumulator last to make sure that the solana fully updated
1415+
// state before the accumulator is used. bank is in a fully
1416+
// updated state before the accumulator is used.
1417+
if !bank
1418+
.feature_set
1419+
.is_active(&feature_set::move_accumulator_to_end_of_block::id())
1420+
{
1421+
bank.update_accumulator();
1422+
}
1423+
14131424
bank
14141425
}
14151426

@@ -1775,7 +1786,16 @@ impl Bank {
17751786
);
17761787

17771788
let (_, update_accumulator_time) = measure!({
1778-
new.update_accumulator();
1789+
// If the accumulator is not moved to end of block, update the
1790+
// accumulator last to make sure that all fully updated state before
1791+
// the accumulator sysvar updates. sysvars are in a fully updated
1792+
// state before the accumulator sysvar updates.
1793+
if !new
1794+
.feature_set
1795+
.is_active(&feature_set::move_accumulator_to_end_of_block::id())
1796+
{
1797+
new.update_accumulator();
1798+
}
17791799
});
17801800

17811801
let (_, fill_sysvar_cache_time) =
@@ -2367,18 +2387,35 @@ impl Bank {
23672387

23682388
// Generate the Message to emit via Wormhole.
23692389
let message = PostedMessageUnreliableData {
2370-
message: MessageData {
2371-
vaa_version: 1,
2372-
consistency_level: 1,
2373-
vaa_time: 1u32,
2374-
vaa_signature_account: Pubkey::default().to_bytes(),
2375-
submission_time: self.clock().unix_timestamp as u32,
2376-
nonce: 0,
2377-
sequence: sequence.sequence,
2378-
emitter_chain: 26,
2379-
emitter_address: accumulator_emitter_addr.to_bytes(),
2380-
payload: acc.serialize(self.slot(), ACCUMULATOR_RING_SIZE),
2381-
},
2390+
message: if !self
2391+
.feature_set
2392+
.is_active(&feature_set::zero_wormhole_message_timestamps::id())
2393+
{
2394+
MessageData {
2395+
vaa_version: 1,
2396+
consistency_level: 1,
2397+
vaa_time: 1u32,
2398+
vaa_signature_account: Pubkey::default().to_bytes(),
2399+
submission_time: self.clock().unix_timestamp as u32,
2400+
nonce: 0,
2401+
sequence: sequence.sequence,
2402+
emitter_chain: 26,
2403+
emitter_address: accumulator_emitter_addr.to_bytes(),
2404+
payload: acc.serialize(self.slot(), ACCUMULATOR_RING_SIZE),
2405+
}
2406+
} else {
2407+
// Use Default::default() to ensure zeroed VAA fields.
2408+
MessageData {
2409+
vaa_version: 1,
2410+
consistency_level: 1,
2411+
submission_time: self.clock().unix_timestamp as u32,
2412+
sequence: sequence.sequence,
2413+
emitter_chain: 26,
2414+
emitter_address: accumulator_emitter_addr.to_bytes(),
2415+
payload: acc.serialize(self.slot(), ACCUMULATOR_RING_SIZE),
2416+
..Default::default()
2417+
}
2418+
}
23822419
};
23832420

23842421
debug!("Accumulator: Wormhole message data: {:?}", message.message);
@@ -3491,6 +3528,19 @@ impl Bank {
34913528
// committed before this write lock can be obtained here.
34923529
let mut hash = self.hash.write().unwrap();
34933530
if *hash == Hash::default() {
3531+
// Update the accumulator before doing other tasks when freezing to avoid any conflicts.
3532+
if self
3533+
.feature_set
3534+
.is_active(&feature_set::move_accumulator_to_end_of_block::id())
3535+
{
3536+
self.update_accumulator();
3537+
} else {
3538+
info!(
3539+
"Accumulator: Skipping accumulating end of block because the feature is disabled. Slot: {}",
3540+
self.slot()
3541+
);
3542+
}
3543+
34943544
// finish up any deferred changes to account state
34953545
self.collect_rent_eagerly(false);
34963546
self.collect_fees();

sdk/src/feature_set.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,14 @@ pub mod enable_accumulator_sysvar {
548548
solana_sdk::declare_id!("BawYFA2oeA4CacxgQgLn6ZwRWDq1ZPXruUuEbko8oPT5");
549549
}
550550

551+
pub mod move_accumulator_to_end_of_block {
552+
solana_sdk::declare_id!("Ecz7cAP89wKDAoEJYhovFcxMcXRJiWGfFdefcSrx2Ynr");
553+
}
554+
555+
pub mod zero_wormhole_message_timestamps {
556+
solana_sdk::declare_id!("UMg4wFe51vKLHXpbdKWP8kFHWQBsCfbd67AoiyPSaH2");
557+
}
558+
551559
lazy_static! {
552560
/// Map of feature identifiers to user-visible description
553561
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
@@ -679,6 +687,8 @@ lazy_static! {
679687
(move_serialized_len_ptr_in_cpi::id(), "cpi ignore serialized_len_ptr #29592"),
680688
(enable_request_heap_frame_ix::id(), "Enable transaction to request heap frame using compute budget instruction #30076"),
681689
(enable_accumulator_sysvar::id(), "enable accumulator sysvar #<GH_ISSUE_NUMBER>"),
690+
(move_accumulator_to_end_of_block::id(), "move accumulator to end of block #<GH_ISSUE_NUMBER>"),
691+
(zero_wormhole_message_timestamps::id(), "use zeroed timestamps in wormhole messages"),
682692
/*************** ADD NEW FEATURES HERE ***************/
683693
]
684694
.iter()

0 commit comments

Comments
 (0)