Skip to content

Commit

Permalink
pubkey in account as type
Browse files Browse the repository at this point in the history
  • Loading branch information
austbot committed Sep 27, 2022
1 parent f696844 commit 36ef759
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 136 deletions.
2 changes: 1 addition & 1 deletion ci/cargo-build-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ cd "$(dirname "$0")/.."

source ./ci/rust-version.sh stable

export RUSTFLAGS="-D warnings"
export RUSTFLAGS=""
export RUSTBACKTRACE=1

set -x
Expand Down
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.4.0"
version = "0.4.1"
authors = ["Metaplex Developers <[email protected]>"]
repository = "https://github.com/metaplex-foundation/digital-asset-validator-plugin"
license = "AGPL-3.0"
Expand Down Expand Up @@ -33,9 +33,9 @@ cadence-macros = "0.29.0"
chrono = "0.4.19"
tracing = "0.1.35"
hex = "0.4.3"
plerkle_messenger = { path = "../plerkle_messenger", version = "0.4.0", features = ["redis"] }
plerkle_messenger = { path = "../plerkle_messenger", version = "0.4.1", features = ["redis"] }
flatbuffers = "2.1.2"
plerkle_serialization = { path = "../plerkle_serialization", version = "0.4.0" }
plerkle_serialization = { path = "../plerkle_serialization", version = "0.4.1" }
tokio = { version = "1.17.0", features = ["full"] }
figment = { version = "0.10.6", features = ["env", "test"] }

Expand Down
2 changes: 1 addition & 1 deletion plerkle_messenger/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "plerkle_messenger"
description = "Metaplex Messenger trait for Geyser plugin producer/consumer patterns."
version = "0.4.0"
version = "0.4.1"
authors = ["Metaplex Developers <[email protected]>"]
repository = "https://github.com/metaplex-foundation/digital-asset-validator-plugin"
license = "AGPL-3.0"
Expand Down
2 changes: 1 addition & 1 deletion plerkle_serialization/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "plerkle_serialization"
description = "Metaplex Flatbuffers Plerkle Serialization for Geyser plugin producer/consumer patterns."
version = "0.4.0"
version = "0.4.1"
authors = ["Metaplex Developers <[email protected]>"]
repository = "https://github.com/metaplex-foundation/digital-asset-validator-plugin"
license = "AGPL-3.0"
Expand Down
7 changes: 3 additions & 4 deletions plerkle_serialization/account_info.fbs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Flatbuffer IDL for Account Info schema.


include "./common.fbs";

table AccountInfo {
pubkey:[uint8];
pubkey:Pubkey;
lamports:uint64;
owner:[uint8];
owner:Pubkey;
executable:bool;
rent_epoch:uint64;
data:[uint8];
Expand Down
3 changes: 3 additions & 0 deletions plerkle_serialization/common.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
struct Pubkey {
key:[uint8:32];
}
2 changes: 1 addition & 1 deletion plerkle_serialization/compiled_instruction.fbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

include "./common.fbs";

table CompiledInstruction {
// Index into the transaction keys array indicating the program account that executes this instruction.
Expand Down
49 changes: 19 additions & 30 deletions plerkle_serialization/src/account_info_generated.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
// automatically generated by the FlatBuffers compiler, do not modify

// @generated

use crate::common_generated::*;


extern crate flatbuffers;


pub enum AccountInfoOffset {}
#[derive(Copy, Clone, PartialEq)]

Expand Down Expand Up @@ -59,13 +65,8 @@ impl<'a> AccountInfo<'a> {
}

#[inline]
pub fn pubkey(&self) -> Option<&'a [u8]> {
self._tab
.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(
AccountInfo::VT_PUBKEY,
None,
)
.map(|v| v.safe_slice())
pub fn pubkey(&self) -> Option<&'a Pubkey> {
self._tab.get::<Pubkey>(AccountInfo::VT_PUBKEY, None)
}
#[inline]
pub fn lamports(&self) -> u64 {
Expand All @@ -74,13 +75,8 @@ impl<'a> AccountInfo<'a> {
.unwrap()
}
#[inline]
pub fn owner(&self) -> Option<&'a [u8]> {
self._tab
.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(
AccountInfo::VT_OWNER,
None,
)
.map(|v| v.safe_slice())
pub fn owner(&self) -> Option<&'a Pubkey> {
self._tab.get::<Pubkey>(AccountInfo::VT_OWNER, None)
}
#[inline]
pub fn executable(&self) -> bool {
Expand Down Expand Up @@ -127,18 +123,11 @@ impl flatbuffers::Verifiable for AccountInfo<'_> {
v: &mut flatbuffers::Verifier,
pos: usize,
) -> Result<(), flatbuffers::InvalidFlatbuffer> {

v.visit_table(pos)?
.visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, u8>>>(
"pubkey",
Self::VT_PUBKEY,
false,
)?
.visit_field::<Pubkey>("pubkey", Self::VT_PUBKEY, false)?
.visit_field::<u64>("lamports", Self::VT_LAMPORTS, false)?
.visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, u8>>>(
"owner",
Self::VT_OWNER,
false,
)?
.visit_field::<Pubkey>("owner", Self::VT_OWNER, false)?
.visit_field::<bool>("executable", Self::VT_EXECUTABLE, false)?
.visit_field::<u64>("rent_epoch", Self::VT_RENT_EPOCH, false)?
.visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, u8>>>(
Expand All @@ -154,9 +143,9 @@ impl flatbuffers::Verifiable for AccountInfo<'_> {
}
}
pub struct AccountInfoArgs<'a> {
pub pubkey: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, u8>>>,
pub pubkey: Option<&'a Pubkey>,
pub lamports: u64,
pub owner: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, u8>>>,
pub owner: Option<&'a Pubkey>,
pub executable: bool,
pub rent_epoch: u64,
pub data: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, u8>>>,
Expand Down Expand Up @@ -187,19 +176,19 @@ pub struct AccountInfoBuilder<'a: 'b, 'b> {
}
impl<'a: 'b, 'b> AccountInfoBuilder<'a, 'b> {
#[inline]
pub fn add_pubkey(&mut self, pubkey: flatbuffers::WIPOffset<flatbuffers::Vector<'b, u8>>) {
pub fn add_pubkey(&mut self, pubkey: &Pubkey) {
self.fbb_
.push_slot_always::<flatbuffers::WIPOffset<_>>(AccountInfo::VT_PUBKEY, pubkey);
.push_slot_always::<&Pubkey>(AccountInfo::VT_PUBKEY, pubkey);
}
#[inline]
pub fn add_lamports(&mut self, lamports: u64) {
self.fbb_
.push_slot::<u64>(AccountInfo::VT_LAMPORTS, lamports, 0);
}
#[inline]
pub fn add_owner(&mut self, owner: flatbuffers::WIPOffset<flatbuffers::Vector<'b, u8>>) {
pub fn add_owner(&mut self, owner: &Pubkey) {
self.fbb_
.push_slot_always::<flatbuffers::WIPOffset<_>>(AccountInfo::VT_OWNER, owner);
.push_slot_always::<&Pubkey>(AccountInfo::VT_OWNER, owner);
}
#[inline]
pub fn add_executable(&mut self, executable: bool) {
Expand Down
8 changes: 8 additions & 0 deletions plerkle_serialization/src/block_info_generated.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// automatically generated by the FlatBuffers compiler, do not modify

// @generated



extern crate flatbuffers;


#[deprecated(
since = "2.0.0",
note = "Use associated constants instead. This will no longer be generated in 2021."
Expand Down Expand Up @@ -96,6 +101,7 @@ impl<'a> flatbuffers::Verifiable for RewardType {
v: &mut flatbuffers::Verifier,
pos: usize,
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
use self::flatbuffers::Verifiable;
u8::run_verifier(v, pos)
}
}
Expand Down Expand Up @@ -184,6 +190,7 @@ impl flatbuffers::Verifiable for Reward<'_> {
v: &mut flatbuffers::Verifier,
pos: usize,
) -> Result<(), flatbuffers::InvalidFlatbuffer> {

v.visit_table(pos)?
.visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, u8>>>(
"pubkey",
Expand Down Expand Up @@ -356,6 +363,7 @@ impl flatbuffers::Verifiable for BlockInfo<'_> {
v: &mut flatbuffers::Verifier,
pos: usize,
) -> Result<(), flatbuffers::InvalidFlatbuffer> {

v.visit_table(pos)?
.visit_field::<u64>("slot", Self::VT_SLOT, false)?
.visit_field::<flatbuffers::ForwardsUOffset<&str>>(
Expand Down
7 changes: 7 additions & 0 deletions plerkle_serialization/src/compiled_instruction_generated.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
// automatically generated by the FlatBuffers compiler, do not modify

// @generated




extern crate flatbuffers;


pub enum CompiledInstructionOffset {}
#[derive(Copy, Clone, PartialEq)]

Expand Down Expand Up @@ -76,6 +82,7 @@ impl flatbuffers::Verifiable for CompiledInstruction<'_> {
v: &mut flatbuffers::Verifier,
pos: usize,
) -> Result<(), flatbuffers::InvalidFlatbuffer> {

v.visit_table(pos)?
.visit_field::<u8>("program_id_index", Self::VT_PROGRAM_ID_INDEX, false)?
.visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, u8>>>(
Expand Down
2 changes: 2 additions & 0 deletions plerkle_serialization/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
mod account_info_generated;
mod block_info_generated;
mod common_generated;
mod compiled_instruction_generated;
mod slot_status_info_generated;
mod transaction_info_generated;

pub mod serializer;
pub use account_info_generated::*;
pub use block_info_generated::*;
pub use common_generated::*;
pub use compiled_instruction_generated::*;
pub use slot_status_info_generated::*;
pub use transaction_info_generated::*;
7 changes: 7 additions & 0 deletions plerkle_serialization/src/serializer/serializer_common.rs
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
use crate::Pubkey;

impl From<&[u8]> for Pubkey {
fn from(slice: &[u8]) -> Self {
let arr = <[u8; 32]>::try_from(slice);
Pubkey::new(&arr.unwrap())
}
}
16 changes: 6 additions & 10 deletions plerkle_serialization/src/serializer/serializer_stable.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
use crate::{
AccountInfo, AccountInfoArgs, BlockInfo, BlockInfoArgs, CompiledInstruction,
CompiledInstructionArgs, InnerInstructions, InnerInstructionsArgs, Pubkey as FBPubkey, Reward,
RewardArgs, RewardType as FBRewardType, SlotStatusInfo, SlotStatusInfoArgs,
Status as FBSlotStatus, TransactionInfo, TransactionInfoArgs,
};
use crate::{AccountInfo, AccountInfoArgs, BlockInfo, BlockInfoArgs, CompiledInstruction, CompiledInstructionArgs, InnerInstructions, InnerInstructionsArgs, Pubkey as FBPubkey, Pubkey, Reward, RewardArgs, RewardType as FBRewardType, SlotStatusInfo, SlotStatusInfoArgs, Status as FBSlotStatus, TransactionInfo, TransactionInfoArgs};
use chrono::Utc;
use flatbuffers::FlatBufferBuilder;
use solana_geyser_plugin_interface::geyser_plugin_interface::{
ReplicaAccountInfo, ReplicaBlockInfo, ReplicaTransactionInfo, SlotStatus,
};
use solana_runtime::bank::RewardType;


pub fn serialize_account<'a>(
mut builder: FlatBufferBuilder<'a>,
account: &ReplicaAccountInfo,
slot: u64,
is_startup: bool,
) -> FlatBufferBuilder<'a> {
// Serialize vector data.
let pubkey = builder.create_vector(account.pubkey);
let owner = builder.create_vector(account.owner);
let pubkey: Pubkey = account.pubkey.into();
let owner: Pubkey = account.owner.into();
let data = builder.create_vector(account.data);

// Serialize everything into Account Info table.
let account_info = AccountInfo::create(
&mut builder,
&AccountInfoArgs {
pubkey: Some(pubkey),
pubkey: Some(&pubkey),
lamports: account.lamports,
owner: Some(owner),
owner: Some(&owner),
executable: account.executable,
rent_epoch: account.rent_epoch,
data: Some(data),
Expand Down
7 changes: 7 additions & 0 deletions plerkle_serialization/src/slot_status_info_generated.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// automatically generated by the FlatBuffers compiler, do not modify

// @generated



extern crate flatbuffers;


#[deprecated(
since = "2.0.0",
note = "Use associated constants instead. This will no longer be generated in 2021."
Expand Down Expand Up @@ -89,6 +94,7 @@ impl<'a> flatbuffers::Verifiable for Status {
v: &mut flatbuffers::Verifier,
pos: usize,
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
use self::flatbuffers::Verifiable;
i8::run_verifier(v, pos)
}
}
Expand Down Expand Up @@ -158,6 +164,7 @@ impl flatbuffers::Verifiable for SlotStatusInfo<'_> {
v: &mut flatbuffers::Verifier,
pos: usize,
) -> Result<(), flatbuffers::InvalidFlatbuffer> {

v.visit_table(pos)?
.visit_field::<u64>("slot", Self::VT_SLOT, false)?
.visit_field::<u64>("parent", Self::VT_PARENT, false)?
Expand Down
Loading

0 comments on commit 36ef759

Please sign in to comment.