Skip to content

Commit 24e4141

Browse files
fanatidJuanito87
authored andcommitted
geyser: backport ReplicaBlockInfoV2
1 parent b00d18c commit 24e4141

File tree

5 files changed

+49
-6
lines changed

5 files changed

+49
-6
lines changed

core/src/replay_stage.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,11 +2628,14 @@ impl ReplayStage {
26282628
if let Some(ref block_metadata_notifier) = block_metadata_notifier {
26292629
let block_metadata_notifier = block_metadata_notifier.read().unwrap();
26302630
block_metadata_notifier.notify_block_metadata(
2631+
bank.parent_slot(),
2632+
&bank.parent_hash().to_string(),
26312633
bank.slot(),
26322634
&bank.last_blockhash().to_string(),
26332635
&bank.rewards,
26342636
Some(bank.clock().unix_timestamp),
26352637
Some(bank.block_height()),
2638+
bank.executed_transaction_count(),
26362639
)
26372640
}
26382641
bank_complete_time.stop();

geyser-plugin-interface/src/geyser_plugin_interface.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,22 @@ pub struct ReplicaBlockInfo<'a> {
133133
pub block_height: Option<u64>,
134134
}
135135

136+
/// Extending ReplicaBlockInfo by sending the transaction_entries_count.
137+
#[derive(Clone, Debug)]
138+
pub struct ReplicaBlockInfoV2<'a> {
139+
pub parent_slot: u64,
140+
pub parent_blockhash: &'a str,
141+
pub slot: u64,
142+
pub blockhash: &'a str,
143+
pub rewards: &'a [Reward],
144+
pub block_time: Option<UnixTimestamp>,
145+
pub block_height: Option<u64>,
146+
pub executed_transaction_count: u64,
147+
}
148+
136149
pub enum ReplicaBlockInfoVersions<'a> {
137150
V0_0_1(&'a ReplicaBlockInfo<'a>),
151+
V0_0_2(&'a ReplicaBlockInfoV2<'a>),
138152
}
139153

140154
/// Errors returned by plugin calls

geyser-plugin-manager/src/block_metadata_notifier.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use {
55
},
66
log::*,
77
solana_geyser_plugin_interface::geyser_plugin_interface::{
8-
ReplicaBlockInfo, ReplicaBlockInfoVersions,
8+
ReplicaBlockInfoV2, ReplicaBlockInfoVersions,
99
},
1010
solana_measure::measure::Measure,
1111
solana_metrics::*,
@@ -23,11 +23,14 @@ impl BlockMetadataNotifier for BlockMetadataNotifierImpl {
2323
/// Notify the block metadata
2424
fn notify_block_metadata(
2525
&self,
26+
parent_slot: u64,
27+
parent_blockhash: &str,
2628
slot: u64,
2729
blockhash: &str,
2830
rewards: &RwLock<Vec<(Pubkey, RewardInfo)>>,
2931
block_time: Option<UnixTimestamp>,
3032
block_height: Option<u64>,
33+
executed_transaction_count: u64,
3134
) {
3235
let mut plugin_manager = self.plugin_manager.write().unwrap();
3336
if plugin_manager.plugins.is_empty() {
@@ -37,9 +40,17 @@ impl BlockMetadataNotifier for BlockMetadataNotifierImpl {
3740

3841
for plugin in plugin_manager.plugins.iter_mut() {
3942
let mut measure = Measure::start("geyser-plugin-update-slot");
40-
let block_info =
41-
Self::build_replica_block_info(slot, blockhash, &rewards, block_time, block_height);
42-
let block_info = ReplicaBlockInfoVersions::V0_0_1(&block_info);
43+
let block_info = Self::build_replica_block_info(
44+
parent_slot,
45+
parent_blockhash,
46+
slot,
47+
blockhash,
48+
&rewards,
49+
block_time,
50+
block_height,
51+
executed_transaction_count,
52+
);
53+
let block_info = ReplicaBlockInfoVersions::V0_0_2(&block_info);
4354
match plugin.notify_block_metadata(block_info) {
4455
Err(err) => {
4556
error!(
@@ -84,18 +95,24 @@ impl BlockMetadataNotifierImpl {
8495
}
8596

8697
fn build_replica_block_info<'a>(
98+
parent_slot: u64,
99+
parent_blockhash: &'a str,
87100
slot: u64,
88101
blockhash: &'a str,
89102
rewards: &'a [Reward],
90103
block_time: Option<UnixTimestamp>,
91104
block_height: Option<u64>,
92-
) -> ReplicaBlockInfo<'a> {
93-
ReplicaBlockInfo {
105+
executed_transaction_count: u64,
106+
) -> ReplicaBlockInfoV2<'a> {
107+
ReplicaBlockInfoV2 {
108+
parent_slot,
109+
parent_blockhash,
94110
slot,
95111
blockhash,
96112
rewards,
97113
block_time,
98114
block_height,
115+
executed_transaction_count,
99116
}
100117
}
101118

geyser-plugin-manager/src/block_metadata_notifier_interface.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ pub trait BlockMetadataNotifier {
99
/// Notify the block metadata
1010
fn notify_block_metadata(
1111
&self,
12+
parent_slot: u64,
13+
parent_blockhash: &str,
1214
slot: u64,
1315
blockhash: &str,
1416
rewards: &RwLock<Vec<(Pubkey, RewardInfo)>>,
1517
block_time: Option<UnixTimestamp>,
1618
block_height: Option<u64>,
19+
executed_transaction_count: u64,
1720
);
1821
}
1922

runtime/src/bank.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6542,6 +6542,12 @@ impl Bank {
65426542
self.transaction_count.load(Relaxed)
65436543
}
65446544

6545+
/// Return the transaction count executed only in this bank
6546+
pub fn executed_transaction_count(&self) -> u64 {
6547+
self.transaction_count()
6548+
.saturating_sub(self.parent().map_or(0, |parent| parent.transaction_count()))
6549+
}
6550+
65456551
pub fn transaction_error_count(&self) -> u64 {
65466552
self.transaction_error_count.load(Relaxed)
65476553
}

0 commit comments

Comments
 (0)