Skip to content

Commit

Permalink
feat: add commitment flag to config
Browse files Browse the repository at this point in the history
  • Loading branch information
RequescoS committed Feb 14, 2024
1 parent 8d1d657 commit fffcb12
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
3 changes: 2 additions & 1 deletion config/geyser-plugin-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"send_accounts": true,
"send_blocks": true,
"skip_vote_txs": true,
"skip_deploy_txs": true
"skip_deploy_txs": true,
"cache_until_finalized": false
}
2 changes: 2 additions & 0 deletions solana-geyser-plugin-scaffold/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub struct Config {

pub skip_vote_txs: bool,
pub skip_deploy_txs: bool,

pub cache_until_finalized: bool,
}

impl Config {
Expand Down
27 changes: 20 additions & 7 deletions solana-geyser-plugin-scaffold/src/geyser_plugin_hook.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::fb_serializers::update_types::{AccountUpdate, TransactionUpdate};
use crate::fb_serializers::{
serialize_account, serialize_block, serialize_metadata, serialize_transaction,
serialize_account, serialize_block, serialize_metadata, serialize_slot, serialize_transaction,
};
use crate::{config::Config, metrics::Metrics};
use log::info;
Expand Down Expand Up @@ -132,6 +132,10 @@ impl GeyserPlugin for GeyserPluginHook {
}

let data = serialize_account(acc_update);
if !inner.config.cache_until_finalized {
inner.socket.publish(data)?;
return Ok(());
}

let slot_data = inner
.cache
Expand All @@ -158,15 +162,16 @@ impl GeyserPlugin for GeyserPluginHook {
}

/// Event: a slot status is updated.
fn update_slot_status(
&self,
slot: u64,
_parent: Option<u64>,
status: SlotStatus,
) -> Result<()> {
fn update_slot_status(&self, slot: u64, parent: Option<u64>, status: SlotStatus) -> Result<()> {
self.with_inner(
|| GeyserPluginError::SlotStatusUpdateError { msg: UNINIT.into() },
|inner| {
if !inner.config.cache_until_finalized {
let data = serialize_slot(slot, parent, status);
inner.socket.publish(data)?;
return Ok(());
}

if status != SlotStatus::Rooted {
return Ok(());
}
Expand Down Expand Up @@ -212,6 +217,10 @@ impl GeyserPlugin for GeyserPluginHook {
}

let data = serialize_transaction(&tx_update)?;
if !inner.config.cache_until_finalized {
inner.socket.publish(data)?;
return Ok(());
}

let slot_data = inner
.cache
Expand Down Expand Up @@ -242,6 +251,10 @@ impl GeyserPlugin for GeyserPluginHook {

let block_update = &blockinfo.into();
let data = serialize_block(block_update);
if !inner.config.cache_until_finalized {
inner.socket.publish(data)?;
return Ok(());
}

let slot_data = inner
.cache
Expand Down

0 comments on commit fffcb12

Please sign in to comment.