Skip to content

Commit

Permalink
fix: ignore unknown noop txns
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasPennie committed Aug 23, 2023
1 parent ab0ef9f commit 80f2b11
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 54 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions blockbuster/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ borsh = "~0.10.3"
thiserror = "1.0.32"
solana-sdk = "~1.16.5"
anchor-lang = { version = "0.28.0"}
log = "0.4.17"

[dev-dependencies]
rand = "0.8.5"
Expand Down
102 changes: 48 additions & 54 deletions blockbuster/src/programs/bubblegum/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use log::warn;

use crate::{
error::BlockbusterError,
instruction::InstructionBundle,
Expand All @@ -21,28 +23,17 @@ pub use spl_account_compression::events::{
AccountCompressionEvent::{self, ApplicationData, ChangeLog},
ApplicationDataEvent, ChangeLogEvent, ChangeLogEventV1,
};

use spl_noop;

#[derive(Eq, PartialEq)]
pub enum Payload {
Unknown,
MintV1 {
args: MetadataArgs,
},
Decompress {
args: MetadataArgs,
},
CancelRedeem {
root: [u8; 32],
},
CreatorVerification {
creator: Pubkey,
verify: bool
},
CollectionVerification {
collection: Pubkey,
verify: bool
},
MintV1 { args: MetadataArgs },
Decompress { args: MetadataArgs },
CancelRedeem { root: [u8; 32] },
CreatorVerification { creator: Pubkey, verify: bool },
CollectionVerification { collection: Pubkey, verify: bool },
}
//TODO add more of the parsing here to minimize program transformer code
pub struct BubblegumInstruction {
Expand Down Expand Up @@ -104,6 +95,7 @@ impl ProgramParser for BubblegumParser {
bundle: &InstructionBundle,
) -> Result<Box<(dyn ParseResult + 'static)>, BlockbusterError> {
let InstructionBundle {
txn_id,
instruction,
inner_ix,
keys,
Expand All @@ -127,32 +119,41 @@ impl ProgramParser for BubblegumParser {
if let Some(inner_ix_data) = cix.data() {
let inner_ix_data = inner_ix_data.iter().collect::<Vec<_>>();
if !inner_ix_data.is_empty() {
match AccountCompressionEvent::try_from_slice(&inner_ix_data)? {
ChangeLog(changelog_event) => {
let ChangeLogEvent::V1(changelog_event) = changelog_event;
b_inst.tree_update = Some(changelog_event);
}
ApplicationData(app_data) => {
let ApplicationDataEvent::V1(app_data) = app_data;
let app_data = app_data.application_data;

let event_type_byte = if !app_data.is_empty() {
&app_data[0..1]
} else {
return Err(BlockbusterError::DeserializationError);
};

match BubblegumEventType::try_from_slice(event_type_byte)? {
BubblegumEventType::Uninitialized => {
return Err(
BlockbusterError::MissingBubblegumEventData,
);
}
BubblegumEventType::LeafSchemaEvent => {
b_inst.leaf_update =
Some(LeafSchemaEvent::try_from_slice(&app_data)?);
match AccountCompressionEvent::try_from_slice(&inner_ix_data) {
Ok(result) => match result {
ChangeLog(changelog_event) => {
let ChangeLogEvent::V1(changelog_event) = changelog_event;
b_inst.tree_update = Some(changelog_event);
}
ApplicationData(app_data) => {
let ApplicationDataEvent::V1(app_data) = app_data;
let app_data = app_data.application_data;

let event_type_byte = if !app_data.is_empty() {
&app_data[0..1]
} else {
return Err(BlockbusterError::DeserializationError);
};

match BubblegumEventType::try_from_slice(event_type_byte)? {
BubblegumEventType::Uninitialized => {
return Err(
BlockbusterError::MissingBubblegumEventData,
);
}
BubblegumEventType::LeafSchemaEvent => {
b_inst.leaf_update = Some(
LeafSchemaEvent::try_from_slice(&app_data)?,
);
}
}
}
},
Err(e) => {
warn!(
"Error while deserializing txn {:?} with noop data: {:?}",
txn_id, e
);
}
}
}
Expand Down Expand Up @@ -189,20 +190,16 @@ impl ProgramParser for BubblegumParser {
b_inst.payload = Some(Payload::CancelRedeem { root: slice });
}
InstructionName::VerifyCreator => {
b_inst.payload =
Some(build_creator_verification_payload(keys, true)?);
b_inst.payload = Some(build_creator_verification_payload(keys, true)?);
}
InstructionName::UnverifyCreator => {
b_inst.payload =
Some(build_creator_verification_payload(keys, false)?);
b_inst.payload = Some(build_creator_verification_payload(keys, false)?);
}
InstructionName::VerifyCollection | InstructionName::SetAndVerifyCollection => {
b_inst.payload =
Some(build_collection_verification_payload(keys, true)?);
b_inst.payload = Some(build_collection_verification_payload(keys, true)?);
}
InstructionName::UnverifyCollection => {
b_inst.payload =
Some(build_collection_verification_payload(keys, false)?);
b_inst.payload = Some(build_collection_verification_payload(keys, false)?);
}
InstructionName::Unknown => {}
_ => {}
Expand All @@ -226,7 +223,7 @@ fn build_creator_verification_payload(
.0;
Ok(Payload::CreatorVerification {
creator: Pubkey::new_from_array(creator),
verify
verify,
})
}

Expand All @@ -242,8 +239,5 @@ fn build_collection_verification_payload(
.ok_or(BlockbusterError::InstructionParsingError)?
.0;
let collection: Pubkey = Pubkey::try_from_slice(&collection_raw)?;
Ok(Payload::CollectionVerification {
collection,
verify
})
Ok(Payload::CollectionVerification { collection, verify })
}

0 comments on commit 80f2b11

Please sign in to comment.