diff --git a/ci/cargo-build-test.sh b/ci/cargo-build-test.sh index 7878de8c..5d3eb8d3 100755 --- a/ci/cargo-build-test.sh +++ b/ci/cargo-build-test.sh @@ -8,7 +8,7 @@ cd "$(dirname "$0")/.." source ./ci/rust-version.sh stable -export RUSTFLAGS="-D warnings" +export RUSTFLAGS="" export RUSTBACKTRACE=1 set -x diff --git a/plerkle/Cargo.toml b/plerkle/Cargo.toml index 9280874c..b4e674f3 100644 --- a/plerkle/Cargo.toml +++ b/plerkle/Cargo.toml @@ -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 "] repository = "https://github.com/metaplex-foundation/digital-asset-validator-plugin" license = "AGPL-3.0" @@ -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"] } diff --git a/plerkle_messenger/Cargo.toml b/plerkle_messenger/Cargo.toml index 9626fbc8..f8c1d56f 100644 --- a/plerkle_messenger/Cargo.toml +++ b/plerkle_messenger/Cargo.toml @@ -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 "] repository = "https://github.com/metaplex-foundation/digital-asset-validator-plugin" license = "AGPL-3.0" diff --git a/plerkle_serialization/Cargo.toml b/plerkle_serialization/Cargo.toml index 99baa0f4..f9456fb4 100644 --- a/plerkle_serialization/Cargo.toml +++ b/plerkle_serialization/Cargo.toml @@ -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 "] repository = "https://github.com/metaplex-foundation/digital-asset-validator-plugin" license = "AGPL-3.0" diff --git a/plerkle_serialization/account_info.fbs b/plerkle_serialization/account_info.fbs index da0d1b7b..32c463e4 100644 --- a/plerkle_serialization/account_info.fbs +++ b/plerkle_serialization/account_info.fbs @@ -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]; diff --git a/plerkle_serialization/common.fbs b/plerkle_serialization/common.fbs new file mode 100644 index 00000000..334695f4 --- /dev/null +++ b/plerkle_serialization/common.fbs @@ -0,0 +1,3 @@ +struct Pubkey { + key:[uint8:32]; +} \ No newline at end of file diff --git a/plerkle_serialization/compiled_instruction.fbs b/plerkle_serialization/compiled_instruction.fbs index 6d21ad70..b02c8d15 100644 --- a/plerkle_serialization/compiled_instruction.fbs +++ b/plerkle_serialization/compiled_instruction.fbs @@ -1,4 +1,4 @@ - +include "./common.fbs"; table CompiledInstruction { // Index into the transaction keys array indicating the program account that executes this instruction. diff --git a/plerkle_serialization/src/account_info_generated.rs b/plerkle_serialization/src/account_info_generated.rs index 2ba5b999..718dc2d5 100644 --- a/plerkle_serialization/src/account_info_generated.rs +++ b/plerkle_serialization/src/account_info_generated.rs @@ -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)] @@ -59,13 +65,8 @@ impl<'a> AccountInfo<'a> { } #[inline] - pub fn pubkey(&self) -> Option<&'a [u8]> { - self._tab - .get::>>( - AccountInfo::VT_PUBKEY, - None, - ) - .map(|v| v.safe_slice()) + pub fn pubkey(&self) -> Option<&'a Pubkey> { + self._tab.get::(AccountInfo::VT_PUBKEY, None) } #[inline] pub fn lamports(&self) -> u64 { @@ -74,13 +75,8 @@ impl<'a> AccountInfo<'a> { .unwrap() } #[inline] - pub fn owner(&self) -> Option<&'a [u8]> { - self._tab - .get::>>( - AccountInfo::VT_OWNER, - None, - ) - .map(|v| v.safe_slice()) + pub fn owner(&self) -> Option<&'a Pubkey> { + self._tab.get::(AccountInfo::VT_OWNER, None) } #[inline] pub fn executable(&self) -> bool { @@ -127,18 +123,11 @@ impl flatbuffers::Verifiable for AccountInfo<'_> { v: &mut flatbuffers::Verifier, pos: usize, ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + v.visit_table(pos)? - .visit_field::>>( - "pubkey", - Self::VT_PUBKEY, - false, - )? + .visit_field::("pubkey", Self::VT_PUBKEY, false)? .visit_field::("lamports", Self::VT_LAMPORTS, false)? - .visit_field::>>( - "owner", - Self::VT_OWNER, - false, - )? + .visit_field::("owner", Self::VT_OWNER, false)? .visit_field::("executable", Self::VT_EXECUTABLE, false)? .visit_field::("rent_epoch", Self::VT_RENT_EPOCH, false)? .visit_field::>>( @@ -154,9 +143,9 @@ impl flatbuffers::Verifiable for AccountInfo<'_> { } } pub struct AccountInfoArgs<'a> { - pub pubkey: Option>>, + pub pubkey: Option<&'a Pubkey>, pub lamports: u64, - pub owner: Option>>, + pub owner: Option<&'a Pubkey>, pub executable: bool, pub rent_epoch: u64, pub data: Option>>, @@ -187,9 +176,9 @@ pub struct AccountInfoBuilder<'a: 'b, 'b> { } impl<'a: 'b, 'b> AccountInfoBuilder<'a, 'b> { #[inline] - pub fn add_pubkey(&mut self, pubkey: flatbuffers::WIPOffset>) { + pub fn add_pubkey(&mut self, pubkey: &Pubkey) { self.fbb_ - .push_slot_always::>(AccountInfo::VT_PUBKEY, pubkey); + .push_slot_always::<&Pubkey>(AccountInfo::VT_PUBKEY, pubkey); } #[inline] pub fn add_lamports(&mut self, lamports: u64) { @@ -197,9 +186,9 @@ impl<'a: 'b, 'b> AccountInfoBuilder<'a, 'b> { .push_slot::(AccountInfo::VT_LAMPORTS, lamports, 0); } #[inline] - pub fn add_owner(&mut self, owner: flatbuffers::WIPOffset>) { + pub fn add_owner(&mut self, owner: &Pubkey) { self.fbb_ - .push_slot_always::>(AccountInfo::VT_OWNER, owner); + .push_slot_always::<&Pubkey>(AccountInfo::VT_OWNER, owner); } #[inline] pub fn add_executable(&mut self, executable: bool) { diff --git a/plerkle_serialization/src/block_info_generated.rs b/plerkle_serialization/src/block_info_generated.rs index 5fdfc4d8..ec2a851e 100644 --- a/plerkle_serialization/src/block_info_generated.rs +++ b/plerkle_serialization/src/block_info_generated.rs @@ -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." @@ -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) } } @@ -184,6 +190,7 @@ impl flatbuffers::Verifiable for Reward<'_> { v: &mut flatbuffers::Verifier, pos: usize, ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + v.visit_table(pos)? .visit_field::>>( "pubkey", @@ -356,6 +363,7 @@ impl flatbuffers::Verifiable for BlockInfo<'_> { v: &mut flatbuffers::Verifier, pos: usize, ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + v.visit_table(pos)? .visit_field::("slot", Self::VT_SLOT, false)? .visit_field::>( diff --git a/plerkle_serialization/src/compiled_instruction_generated.rs b/plerkle_serialization/src/compiled_instruction_generated.rs index 3da0ce99..6e517276 100644 --- a/plerkle_serialization/src/compiled_instruction_generated.rs +++ b/plerkle_serialization/src/compiled_instruction_generated.rs @@ -1,7 +1,13 @@ // automatically generated by the FlatBuffers compiler, do not modify +// @generated + + + + extern crate flatbuffers; + pub enum CompiledInstructionOffset {} #[derive(Copy, Clone, PartialEq)] @@ -76,6 +82,7 @@ impl flatbuffers::Verifiable for CompiledInstruction<'_> { v: &mut flatbuffers::Verifier, pos: usize, ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + v.visit_table(pos)? .visit_field::("program_id_index", Self::VT_PROGRAM_ID_INDEX, false)? .visit_field::>>( diff --git a/plerkle_serialization/src/lib.rs b/plerkle_serialization/src/lib.rs index 69e158db..097ae28c 100644 --- a/plerkle_serialization/src/lib.rs +++ b/plerkle_serialization/src/lib.rs @@ -1,5 +1,6 @@ mod account_info_generated; mod block_info_generated; +mod common_generated; mod compiled_instruction_generated; mod slot_status_info_generated; mod transaction_info_generated; @@ -7,6 +8,7 @@ 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::*; diff --git a/plerkle_serialization/src/serializer/serializer_common.rs b/plerkle_serialization/src/serializer/serializer_common.rs index 8b137891..17074b8d 100644 --- a/plerkle_serialization/src/serializer/serializer_common.rs +++ b/plerkle_serialization/src/serializer/serializer_common.rs @@ -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()) + } +} \ No newline at end of file diff --git a/plerkle_serialization/src/serializer/serializer_stable.rs b/plerkle_serialization/src/serializer/serializer_stable.rs index ac752ac9..352b0d38 100644 --- a/plerkle_serialization/src/serializer/serializer_stable.rs +++ b/plerkle_serialization/src/serializer/serializer_stable.rs @@ -1,9 +1,4 @@ -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::{ @@ -11,6 +6,7 @@ use solana_geyser_plugin_interface::geyser_plugin_interface::{ }; use solana_runtime::bank::RewardType; + pub fn serialize_account<'a>( mut builder: FlatBufferBuilder<'a>, account: &ReplicaAccountInfo, @@ -18,17 +14,17 @@ pub fn serialize_account<'a>( 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), diff --git a/plerkle_serialization/src/slot_status_info_generated.rs b/plerkle_serialization/src/slot_status_info_generated.rs index d4765b04..1e157c66 100644 --- a/plerkle_serialization/src/slot_status_info_generated.rs +++ b/plerkle_serialization/src/slot_status_info_generated.rs @@ -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." @@ -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) } } @@ -158,6 +164,7 @@ impl flatbuffers::Verifiable for SlotStatusInfo<'_> { v: &mut flatbuffers::Verifier, pos: usize, ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + v.visit_table(pos)? .visit_field::("slot", Self::VT_SLOT, false)? .visit_field::("parent", Self::VT_PARENT, false)? diff --git a/plerkle_serialization/src/transaction_info_generated.rs b/plerkle_serialization/src/transaction_info_generated.rs index 1b88ffa7..6c63f924 100644 --- a/plerkle_serialization/src/transaction_info_generated.rs +++ b/plerkle_serialization/src/transaction_info_generated.rs @@ -1,89 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify -use crate::compiled_instruction_generated::*; +// @generated -extern crate flatbuffers; -use self::flatbuffers::Follow; - -// struct Pubkey, aligned to 1 -#[repr(transparent)] -#[derive(Clone, Copy, PartialEq, Eq)] -pub struct Pubkey(pub [u8; 32]); -impl Default for Pubkey { - fn default() -> Self { - Self([0; 32]) - } -} -impl core::fmt::Debug for Pubkey { - fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - f.debug_struct("Pubkey").field("key", &self.key()).finish() - } -} - -impl flatbuffers::SimpleToVerifyInSlice for Pubkey {} -impl flatbuffers::SafeSliceAccess for Pubkey {} -impl<'a> flatbuffers::Follow<'a> for Pubkey { - type Inner = &'a Pubkey; - #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - <&'a Pubkey>::follow(buf, loc) - } -} -impl<'a> flatbuffers::Follow<'a> for &'a Pubkey { - type Inner = &'a Pubkey; - #[inline] - fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - flatbuffers::follow_cast_ref::(buf, loc) - } -} -impl<'b> flatbuffers::Push for Pubkey { - type Output = Pubkey; - #[inline] - fn push(&self, dst: &mut [u8], _rest: &[u8]) { - let src = unsafe { - ::core::slice::from_raw_parts(self as *const Pubkey as *const u8, Self::size()) - }; - dst.copy_from_slice(src); - } -} -impl<'b> flatbuffers::Push for &'b Pubkey { - type Output = Pubkey; - - #[inline] - fn push(&self, dst: &mut [u8], _rest: &[u8]) { - let src = unsafe { - ::core::slice::from_raw_parts(*self as *const Pubkey as *const u8, Self::size()) - }; - dst.copy_from_slice(src); - } -} - -impl<'a> flatbuffers::Verifiable for Pubkey { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, - pos: usize, - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - v.in_buffer::(pos) - } -} +use crate::{common_generated::*, compiled_instruction_generated::*}; -impl<'a> Pubkey { - #[allow(clippy::too_many_arguments)] - pub fn new(key: &[u8; 32]) -> Self { - let mut s = Self([0; 32]); - s.set_key(key); - s - } - pub fn key(&'a self) -> flatbuffers::Array<'a, u8, 32> { - flatbuffers::Array::follow(&self.0, 0) - } +extern crate flatbuffers; - pub fn set_key(&mut self, items: &[u8; 32]) { - flatbuffers::emplace_scalar_array(&mut self.0, 0, items); - } -} pub enum TransactionInfoOffset {} #[derive(Copy, Clone, PartialEq)] @@ -208,6 +131,7 @@ impl flatbuffers::Verifiable for TransactionInfo<'_> { v: &mut flatbuffers::Verifier, pos: usize, ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + v.visit_table(pos)? .visit_field::("is_vote", Self::VT_IS_VOTE, false)? .visit_field::>>( @@ -434,6 +358,7 @@ impl flatbuffers::Verifiable for InnerInstructions<'_> { v: &mut flatbuffers::Verifier, pos: usize, ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + v.visit_table(pos)? .visit_field::("index", Self::VT_INDEX, false)? .visit_field::