Skip to content

Commit

Permalink
Code Cleanup. (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
austbot authored Sep 14, 2022
1 parent e6c84c1 commit 1127bd8
Show file tree
Hide file tree
Showing 26 changed files with 1,680 additions and 1,319 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions plerkle/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "plerkle"
description = "Geyser plugin with dynamic config reloading, message bus agnostic abstractions and a whole lot of fun."
version = "0.0.7"
version = "0.0.8"
authors = ["Metaplex Developers <[email protected]>"]
repository = "https://github.com/metaplex-foundation/digital-asset-validator-plugin"
license = "AGPL-3.0"
Expand Down Expand Up @@ -32,9 +32,9 @@ chrono = "0.4.19" # did anyone say leftpad ?
solana-runtime = "1.11.3"
tracing = "0.1.35"
hex = "0.4.3"
plerkle_messenger = { path="../plerkle_messenger", version = "0.0.7", features = ["redis"] }
plerkle_messenger = { path="../plerkle_messenger", version = "0.0.8", features = ["redis"] }
flatbuffers = "2.1.2"
plerkle_serialization = { path="../plerkle_serialization", version = "0.0.7" }
plerkle_serialization = { path="../plerkle_serialization", version = "0.0.8" }
tokio = { version = "1.17.0", features = ["full"] }
figment = { version = "0.10.6", features = ["env", "test"] }

Expand Down
4 changes: 3 additions & 1 deletion plerkle/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
edition = "2021"
edition = "2021"
imports_granularity="Crate"
reorder_imports = true
3 changes: 2 additions & 1 deletion plerkle/src/accounts_selector.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use {log::*, std::collections::HashSet};
use log::*;
use std::collections::HashSet;

#[derive(Debug)]
pub(crate) struct AccountsSelector {
Expand Down
79 changes: 36 additions & 43 deletions plerkle/src/geyser_plugin_nft.rs
Original file line number Diff line number Diff line change
@@ -1,45 +1,40 @@
use solana_geyser_plugin_interface::geyser_plugin_interface::{ReplicaAccountInfoV2, ReplicaTransactionInfo, ReplicaTransactionInfoV2};
use {
crate::{
accounts_selector::AccountsSelector,
error::PlerkleError,
serializer::{
serialize_account, serialize_block, serialize_slot_status, serialize_transaction,
},
transaction_selector::TransactionSelector,
},
cadence::BufferedUdpMetricSink,
cadence::QueuingMetricSink,
cadence::StatsdClient,
cadence_macros::*,
figment::{providers::Env, Figment},
flatbuffers::FlatBufferBuilder,
log::*,
plerkle_messenger::MessengerConfig,
plerkle_messenger::{
select_messenger,
Messenger, ACCOUNT_STREAM, BLOCK_STREAM, SLOT_STREAM, TRANSACTION_STREAM,
},
serde::Deserialize,
solana_geyser_plugin_interface::geyser_plugin_interface::{
GeyserPlugin, GeyserPluginError, ReplicaAccountInfoVersions, ReplicaBlockInfoVersions,
ReplicaTransactionInfoVersions, Result, SlotStatus,
},
solana_sdk::{message::AccountKeys, pubkey::Pubkey},
std::net::UdpSocket,
std::{
fmt::{Debug, Formatter},
fs::File,
io::Read,
},
tokio::{
self as tokio,
time::Instant,
runtime::{Builder, Runtime},
sync::mpsc::{self as mpsc, Sender},
use crate::{
accounts_selector::AccountsSelector,
error::PlerkleError,
metrics::safe_metric,
serializer::{
serialize_account, serialize_block, serialize_slot_status, serialize_transaction,
},
transaction_selector::TransactionSelector,
};
use cadence::{BufferedUdpMetricSink, QueuingMetricSink, StatsdClient};
use cadence_macros::*;
use figment::{providers::Env, Figment};
use flatbuffers::FlatBufferBuilder;
use log::*;
use plerkle_messenger::{
select_messenger, Messenger, MessengerConfig, ACCOUNT_STREAM, BLOCK_STREAM, SLOT_STREAM,
TRANSACTION_STREAM,
};
use serde::Deserialize;
use solana_geyser_plugin_interface::geyser_plugin_interface::{
GeyserPlugin, GeyserPluginError, ReplicaAccountInfoV2, ReplicaAccountInfoVersions,
ReplicaBlockInfoVersions, ReplicaTransactionInfoV2,
ReplicaTransactionInfoVersions, Result, SlotStatus,
};
use solana_sdk::{message::AccountKeys, pubkey::Pubkey};
use std::{
fmt::{Debug, Formatter},
fs::File,
io::Read,
net::UdpSocket,
};
use tokio::{
self as tokio,
runtime::{Builder, Runtime},
sync::mpsc::{self as mpsc, Sender},
time::Instant,
};
use crate::metrics::safe_metric;

struct SerializedData<'a> {
stream: &'static str,
Expand Down Expand Up @@ -364,9 +359,7 @@ impl GeyserPlugin for Plerkle<'static> {
}
};

if transaction_info.is_vote
|| transaction_info.transaction_status_meta.status.is_err()
{
if transaction_info.is_vote || transaction_info.transaction_status_meta.status.is_err() {
return Ok(());
}

Expand Down
66 changes: 29 additions & 37 deletions plerkle/src/serializer.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
use {
chrono::{Utc},
flatbuffers::FlatBufferBuilder,
plerkle_serialization::{
account_info_generated::account_info::{AccountInfo, AccountInfoArgs},
block_info_generated,
slot_status_info_generated::slot_status_info::{self, SlotStatusInfo, SlotStatusInfoArgs},
transaction_info_generated::transaction_info::{
self, TransactionInfo, TransactionInfoArgs,
},
},
solana_geyser_plugin_interface::geyser_plugin_interface::{
ReplicaAccountInfoV2, ReplicaBlockInfo, ReplicaTransactionInfoV2, SlotStatus,
},
solana_runtime::bank::RewardType,
use chrono::Utc;
use flatbuffers::FlatBufferBuilder;
use plerkle_serialization::{
AccountInfo, AccountInfoArgs, BlockInfo, BlockInfoArgs, CompiledInstruction,
CompiledInstructionArgs, InnerInstructions, InnerInstructionsArgs, Pubkey as FBPubkey, Reward,
RewardArgs, RewardType as FBRewardType, SlotStatusInfo, SlotStatusInfoArgs,
Status as FBSlotStatus, TransactionInfo, TransactionInfoArgs,
};
use solana_geyser_plugin_interface::geyser_plugin_interface::{
ReplicaAccountInfoV2, ReplicaBlockInfo, ReplicaTransactionInfoV2, SlotStatus,
};
use solana_runtime::bank::RewardType;

pub fn serialize_account<'a>(
mut builder: FlatBufferBuilder<'a>,
Expand Down Expand Up @@ -55,9 +51,9 @@ pub fn serialize_slot_status<'a>(
) -> FlatBufferBuilder<'a> {
// Convert to flatbuffer enum.
let status = match status {
SlotStatus::Confirmed => slot_status_info::Status::Confirmed,
SlotStatus::Processed => slot_status_info::Status::Processed,
SlotStatus::Rooted => slot_status_info::Status::Rooted,
SlotStatus::Confirmed => FBSlotStatus::Confirmed,
SlotStatus::Processed => FBSlotStatus::Processed,
SlotStatus::Rooted => FBSlotStatus::Rooted,
};

// Serialize everything into Slot Status Info table.
Expand Down Expand Up @@ -87,7 +83,7 @@ pub fn serialize_transaction<'a>(
let account_keys = if account_keys_len > 0 {
let mut account_keys_fb_vec = Vec::with_capacity(account_keys_len);
for key in account_keys.iter() {
let pubkey = transaction_info::Pubkey::new(&key.to_bytes());
let pubkey = FBPubkey::new(&key.to_bytes());
account_keys_fb_vec.push(pubkey);
}
Some(builder.create_vector(&account_keys_fb_vec))
Expand Down Expand Up @@ -124,9 +120,9 @@ pub fn serialize_transaction<'a>(
let program_id_index = compiled_instruction.program_id_index;
let accounts = Some(builder.create_vector(&compiled_instruction.accounts));
let data = Some(builder.create_vector(&compiled_instruction.data));
instructions_fb_vec.push(transaction_info::CompiledInstruction::create(
instructions_fb_vec.push(CompiledInstruction::create(
&mut builder,
&transaction_info::CompiledInstructionArgs {
&CompiledInstructionArgs {
program_id_index,
accounts,
data,
Expand All @@ -135,9 +131,9 @@ pub fn serialize_transaction<'a>(
}

let instructions = Some(builder.create_vector(&instructions_fb_vec));
overall_fb_vec.push(transaction_info::InnerInstructions::create(
overall_fb_vec.push(InnerInstructions::create(
&mut builder,
&transaction_info::InnerInstructionsArgs {
&InnerInstructionsArgs {
index,
instructions,
},
Expand All @@ -157,9 +153,9 @@ pub fn serialize_transaction<'a>(
let program_id_index = compiled_instruction.program_id_index;
let accounts = Some(builder.create_vector(&compiled_instruction.accounts));
let data = Some(builder.create_vector(&compiled_instruction.data));
instructions_fb_vec.push(transaction_info::CompiledInstruction::create(
instructions_fb_vec.push(CompiledInstruction::create(
&mut builder,
&transaction_info::CompiledInstructionArgs {
&CompiledInstructionArgs {
program_id_index,
accounts,
data,
Expand Down Expand Up @@ -209,24 +205,20 @@ pub fn serialize_block<'a>(

let reward_type = if let Some(reward) = reward.reward_type {
match reward {
RewardType::Fee => Some(block_info_generated::block_info::RewardType::Fee),
RewardType::Rent => Some(block_info_generated::block_info::RewardType::Rent),
RewardType::Staking => {
Some(block_info_generated::block_info::RewardType::Staking)
}
RewardType::Voting => {
Some(block_info_generated::block_info::RewardType::Voting)
}
RewardType::Fee => Some(FBRewardType::Fee),
RewardType::Rent => Some(FBRewardType::Rent),
RewardType::Staking => Some(FBRewardType::Staking),
RewardType::Voting => Some(FBRewardType::Voting),
}
} else {
None
};

let commission = reward.commission;

rewards_fb_vec.push(block_info_generated::block_info::Reward::create(
rewards_fb_vec.push(Reward::create(
&mut builder,
&block_info_generated::block_info::RewardArgs {
&RewardArgs {
pubkey,
lamports,
post_balance,
Expand All @@ -241,9 +233,9 @@ pub fn serialize_block<'a>(
};

// Serialize everything into Block Info table.
let block_info = block_info_generated::block_info::BlockInfo::create(
let block_info = BlockInfo::create(
&mut builder,
&block_info_generated::block_info::BlockInfoArgs {
&BlockInfoArgs {
slot: block_info.slot,
blockhash,
rewards,
Expand Down
4 changes: 2 additions & 2 deletions plerkle_messenger/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[package]
name = "plerkle_messenger"
description = "Metaplex Messenger trait for Geyser plugin producer/consumer patterns."
version = "0.0.7"
version = "0.0.8"
authors = ["Metaplex Developers <[email protected]>"]
repository = "https://github.com/metaplex-foundation/digital-asset-validator-plugin"
license = "AGPL-3.0"
edition = "2021"
readme = "Readme.md"

[dependencies]
plerkle_serialization = { path = "../plerkle_serialization", version = "0.0.7" }
plerkle_serialization = { path = "../plerkle_serialization", version = "0.0.8" }
redis = { version = "0.21.5", features = ["aio", "tokio-comp", "streams"], optional = true }
metaplex-pulsar = { version = "4.1.1", optional = true }
log = "0.4.11"
Expand Down
4 changes: 3 additions & 1 deletion plerkle_messenger/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
edition = "2021"
edition = "2021"
imports_granularity="Crate"
reorder_imports = true
5 changes: 2 additions & 3 deletions plerkle_messenger/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod redis_messenger;
mod pulsar_messenger;
mod redis_messenger;

#[cfg(feature = "redis")]
pub use crate::redis_messenger::*;
Expand All @@ -10,5 +10,4 @@ pub use crate::pulsar_messenger::*;
mod error;
mod plerkle_messenger;

pub use crate::plerkle_messenger::*;
pub use crate::error::*;
pub use crate::{error::*, plerkle_messenger::*};
Loading

0 comments on commit 1127bd8

Please sign in to comment.