Skip to content

Commit 21e811b

Browse files
ksn6AshwinSekar
authored andcommitted
feat: update clock sysvar in BlockComponentProcessor (anza-xyz#595)
Now that we can process `BlockComponent`s during replay, update the clock sysvar when we observe the block footer. This PR exposes the Alpenglow clock to `BlockComponentProcessor`, which we'll next modify to enforce the Alpenglow clock bounds outlined in solana-foundation/solana-improvement-documents#363.
1 parent e7ac7e8 commit 21e811b

File tree

5 files changed

+44
-15
lines changed

5 files changed

+44
-15
lines changed

core/src/block_creation_loop.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use {
2626
solana_runtime::{
2727
bank::{Bank, NewBankOptions},
2828
bank_forks::BankForks,
29+
block_component_processor::BlockComponentProcessor,
2930
leader_schedule_utils::{last_of_consecutive_leader_slots, leader_slot_index},
3031
},
3132
solana_version::version,
@@ -136,17 +137,15 @@ enum StartLeaderError {
136137
),
137138
}
138139

139-
fn produce_block_footer(block_producer_time_nanos: u64) -> VersionedBlockMarker {
140-
let footer = BlockFooterV1 {
140+
fn produce_block_footer(block_producer_time_nanos: u64) -> BlockFooterV1 {
141+
BlockFooterV1 {
141142
bank_hash: Hash::default(),
142143
block_producer_time_nanos,
143144
block_user_agent: format!("agave/{}", version!()).into_bytes(),
144145
final_cert: None,
145146
skip_reward_cert: None,
146147
notar_reward_cert: None,
147-
};
148-
149-
VersionedBlockMarker::new_block_footer(footer)
148+
}
150149
}
151150

152151
/// The block creation loop.
@@ -402,7 +401,7 @@ fn record_and_complete_block(
402401
let mut w_poh_recorder = poh_recorder.write().unwrap();
403402
let block_producer_time_nanos = w_poh_recorder.working_bank_block_producer_time_nanos();
404403
let footer = produce_block_footer(block_producer_time_nanos);
405-
w_poh_recorder.send_marker(footer)?;
404+
w_poh_recorder.send_marker(VersionedBlockMarker::new_block_footer(footer.clone()))?;
406405

407406
// Alpentick and clear bank
408407
let bank = w_poh_recorder
@@ -419,9 +418,14 @@ fn record_and_complete_block(
419418
// Set the tick height for the bank to max_tick_height - 1, so that PohRecorder::flush_cache()
420419
// will properly increment the tick_height to max_tick_height.
421420
bank.set_tick_height(max_tick_height - 1);
422-
// Write the single tick for this slot
421+
422+
BlockComponentProcessor::update_bank_with_footer(
423+
bank.clone(),
424+
&footer,
425+
);
426+
423427
drop(bank);
424-
w_poh_recorder.tick_alpenglow(max_tick_height);
428+
w_poh_recorder.tick_alpenglow(max_tick_height, footer);
425429

426430
Ok(())
427431
}

ledger/src/blockstore_processor.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,12 @@ pub fn confirm_slot(
15781578
}
15791579
BlockComponent::BlockMarker(marker) => {
15801580
processor
1581-
.on_marker(&marker, migration_status, is_final)
1581+
.on_marker(
1582+
bank.clone_without_scheduler(),
1583+
&marker,
1584+
migration_status,
1585+
is_final,
1586+
)
15821587
.inspect_err(|err| {
15831588
warn!("Block component processing failed for slot {slot}: {err:?}",);
15841589
})?;

poh/src/poh_recorder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use {
2323
log::*,
2424
solana_clock::{BankId, NUM_CONSECUTIVE_LEADER_SLOTS, Slot},
2525
solana_entry::{
26-
block_component::VersionedBlockMarker,
26+
block_component::{BlockFooterV1, VersionedBlockMarker},
2727
entry::Entry,
2828
poh::{Poh, PohEntry},
2929
},
@@ -930,7 +930,7 @@ impl PohRecorder {
930930
.as_nanos() as u64
931931
}
932932

933-
pub fn tick_alpenglow(&mut self, slot_max_tick_height: u64) {
933+
pub fn tick_alpenglow(&mut self, slot_max_tick_height: u64, _footer: BlockFooterV1) {
934934
let (poh_entry, tick_lock_contention_us) = measure_us!({
935935
let mut poh_l = self.poh.lock().unwrap();
936936
poh_l.tick()

runtime/src/bank.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,12 @@ impl Bank {
14521452
let (_, update_sysvars_time_us) = measure_us!({
14531453
new.update_slot_hashes();
14541454
new.update_stake_history(Some(parent.epoch()));
1455-
new.update_clock(Some(parent.epoch()));
1455+
1456+
// If Alpenglow is enabled, update the clock from the footer.
1457+
if new.get_alpenglow_genesis_certificate().is_none() {
1458+
new.update_clock(Some(parent.epoch()));
1459+
}
1460+
14561461
new.update_last_restart_slot()
14571462
});
14581463

runtime/src/block_component_processor.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
use {
2+
crate::bank::Bank,
23
agave_votor_messages::migration::MigrationStatus,
34
solana_entry::block_component::{
4-
BlockMarkerV1, VersionedBlockFooter, VersionedBlockHeader, VersionedBlockMarker,
5+
BlockFooterV1, BlockMarkerV1, VersionedBlockFooter, VersionedBlockHeader,
6+
VersionedBlockMarker,
57
},
8+
std::sync::Arc,
69
thiserror::Error,
710
};
811

@@ -63,6 +66,7 @@ impl BlockComponentProcessor {
6366

6467
pub fn on_marker(
6568
&mut self,
69+
bank: Arc<Bank>,
6670
marker: &VersionedBlockMarker,
6771
migration_status: &MigrationStatus,
6872
is_final: bool,
@@ -75,7 +79,7 @@ impl BlockComponentProcessor {
7579
let VersionedBlockMarker::V1(marker) = marker;
7680

7781
match marker {
78-
BlockMarkerV1::BlockFooter(footer) => self.on_footer(footer.inner()),
82+
BlockMarkerV1::BlockFooter(footer) => self.on_footer(bank, footer.inner()),
7983
BlockMarkerV1::BlockHeader(header) => self.on_header(header.inner()),
8084
// We process UpdateParent messages on shred ingest, so no callback needed here.
8185
BlockMarkerV1::UpdateParent(_) => Ok(()),
@@ -91,7 +95,8 @@ impl BlockComponentProcessor {
9195

9296
fn on_footer(
9397
&mut self,
94-
_footer: &VersionedBlockFooter,
98+
bank: Arc<Bank>,
99+
footer: &VersionedBlockFooter,
95100
) -> Result<(), BlockComponentProcessorError> {
96101
// The block header must be the first component of each block.
97102
if !self.has_header {
@@ -102,6 +107,9 @@ impl BlockComponentProcessor {
102107
return Err(BlockComponentProcessorError::MultipleBlockFooters);
103108
}
104109

110+
let VersionedBlockFooter::V1(footer) = footer;
111+
Self::update_bank_with_footer(bank, footer);
112+
105113
self.has_footer = true;
106114
Ok(())
107115
}
@@ -117,4 +125,11 @@ impl BlockComponentProcessor {
117125
self.has_header = true;
118126
Ok(())
119127
}
128+
129+
pub fn update_bank_with_footer(bank: Arc<Bank>, footer: &BlockFooterV1) {
130+
// Update clock sysvar from footer timestamp.
131+
bank.update_clock_from_footer(footer.block_producer_time_nanos as i64);
132+
133+
// TODO: rewards
134+
}
120135
}

0 commit comments

Comments
 (0)