Skip to content

Commit

Permalink
Refactor creator verification indexing
Browse files Browse the repository at this point in the history
* Use new Blockbuster that always updates all
creators and verification status.
* Remove deleting creators with lower sequence
numbers as it would not work due to race
conditions.
* Add concept of "empty" creator value to
support Bubblegum empty creator arrays.
* Add filtering out of old creators or having
no creators to DAS code.
* Also get authority and tree_id accounts from
Bubblegum during mint and update_metadata.
  • Loading branch information
danenbm committed Dec 18, 2023
1 parent 4b96e97 commit c9dda08
Show file tree
Hide file tree
Showing 12 changed files with 227 additions and 286 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion das_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ schemars = "0.8.6"
schemars_derive = "0.8.6"
open-rpc-derive = { version = "0.0.4"}
open-rpc-schema = { version = "0.0.4"}
blockbuster = "=0.9.0-beta.3"
blockbuster = {git = "https://github.com/metaplex-foundation/blockbuster.git", rev = "f9194397c75017808eb2d7b6f0229f43238cd317"}
anchor-lang = "0.28.0"
mpl-token-metadata = { version = "=2.0.0-beta.1", features = ["serde-feature"] }
mpl-candy-machine-core = { version = "2.0.1", features = ["no-entrypoint"] }
Expand Down
2 changes: 1 addition & 1 deletion digital_asset_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ solana-sdk = "~1.16.16"
num-traits = "0.2.15"
num-derive = "0.3.3"
thiserror = "1.0.31"
blockbuster = "=0.9.0-beta.3"
blockbuster = {git = "https://github.com/metaplex-foundation/blockbuster.git", rev = "f9194397c75017808eb2d7b6f0229f43238cd317"}
jsonpath_lib = "0.3.0"
mime_guess = "2.0.4"
url = "2.3.1"
Expand Down
37 changes: 26 additions & 11 deletions digital_asset_types/src/dao/scopes/asset.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
use crate::{
dao::{
asset::{self, Entity},
asset_authority, asset_creators, asset_data, asset_grouping, FullAsset,
GroupingSize, Pagination,
},
dapi::common::safe_select,
rpc::{response::AssetList},
use crate::dao::{
asset::{self},
asset_authority, asset_creators, asset_data, asset_grouping, FullAsset, GroupingSize,
Pagination,
};

use indexmap::IndexMap;
use sea_orm::{entity::*, query::*, ConnectionTrait, DbErr, Order};
use std::collections::{HashMap, HashSet};
use std::collections::HashMap;

pub fn paginate<'db, T>(pagination: &Pagination, limit: u64, stmt: T) -> T
pub fn paginate<T>(pagination: &Pagination, limit: u64, stmt: T) -> T
where
T: QueryFilter + QuerySelect,
{
Expand Down Expand Up @@ -313,11 +309,30 @@ pub async fn get_by_id(
.order_by_asc(asset_authority::Column::AssetId)
.all(conn)
.await?;
let creators: Vec<asset_creators::Model> = asset_creators::Entity::find()
let mut creators: Vec<asset_creators::Model> = asset_creators::Entity::find()
.filter(asset_creators::Column::AssetId.eq(asset.id.clone()))
.order_by_asc(asset_creators::Column::Position)
.all(conn)
.await?;

// If the first creator is an empty Vec, it means the creator array is empty (which is allowed
// in Bubblegum).
if !creators.is_empty() && creators[0].creator.is_empty() {
creators.clear();
} else {
// Any creators that are not the max slot_updated value are stale rows, so remove them.
let max_slot_updated = creators.iter().map(|creator| creator.slot_updated).max();
if let Some(max_slot_updated) = max_slot_updated {
creators.retain(|creator| creator.slot_updated == max_slot_updated);
}

// Any creators that are not the max seq are stale rows, so remove them.
let max_seq = creators.iter().map(|creator| creator.verified_seq).max();
if let Some(max_seq) = max_seq {
creators.retain(|creator| creator.verified_seq == max_seq);
}
}

let grouping: Vec<asset_grouping::Model> = asset_grouping::Entity::find()
.filter(asset_grouping::Column::AssetId.eq(asset.id.clone()))
.filter(asset_grouping::Column::GroupValue.is_not_null())
Expand Down
4 changes: 2 additions & 2 deletions nft_ingester/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ spl-concurrent-merkle-tree = "0.2.0"
uuid = "1.0.0"
async-trait = "0.1.53"
num-traits = "0.2.15"
blockbuster = "=0.9.0-beta.3"
blockbuster = {git = "https://github.com/metaplex-foundation/blockbuster.git", rev = "f9194397c75017808eb2d7b6f0229f43238cd317"}
figment = { version = "0.10.6", features = ["env", "toml", "yaml"] }
cadence = "0.29.0"
cadence-macros = "0.29.0"
solana-sdk = "~1.16.16"
solana-client = "~1.16.16"
spl-token = { version = ">= 3.5.0, < 5.0", features = ["no-entrypoint"] }
spl-token = { version = "4.0.0", features = ["no-entrypoint"] }
solana-transaction-status = "~1.16.16"
solana-account-decoder = "~1.16.16"
solana-geyser-plugin-interface = "~1.16.16"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
use crate::{
error::IngesterError,
program_transformers::bubblegum::{
save_changelog_event, upsert_asset_with_leaf_info,
upsert_asset_with_owner_and_delegate_info, upsert_asset_with_seq, upsert_creator_verified,
save_changelog_event, upsert_asset_creators, upsert_asset_with_leaf_info,
upsert_asset_with_owner_and_delegate_info, upsert_asset_with_seq,
},
};
use blockbuster::{
instruction::InstructionBundle,
programs::bubblegum::{BubblegumInstruction, LeafSchema, Payload},
};
use log::debug;
use mpl_bubblegum::types::Creator;
use sea_orm::{ConnectionTrait, TransactionTrait};

pub async fn process<'c, T>(
parsing_result: &BubblegumInstruction,
bundle: &InstructionBundle<'c>,
txn: &'c T,
value: bool,
cl_audits: bool,
) -> Result<(), IngesterError>
where
Expand All @@ -27,10 +27,26 @@ where
&parsing_result.tree_update,
&parsing_result.payload,
) {
let (creator, verify) = match payload {
let (updated_creators, creator, verify) = match payload {
Payload::CreatorVerification {
creator, verify, ..
} => (creator, verify),
metadata,
creator,
verify,
} => {
let updated_creators: Vec<Creator> = metadata
.creators
.iter()
.map(|c| {
let mut c = c.clone();
if c.address == *creator {
c.verified = *verify
};
c
})
.collect();

(updated_creators, creator, verify)
}
_ => {
return Err(IngesterError::ParsingError(
"Ix not parsed correctly".to_string(),
Expand Down Expand Up @@ -97,11 +113,12 @@ where
}
};

upsert_creator_verified(
// Upsert creators to `asset_creators` table.
upsert_asset_creators(
txn,
asset_id_bytes,
creator.to_bytes().to_vec(),
value,
&updated_creators,
bundle.slot as i64,
seq as i64,
)
.await?;
Expand Down
Loading

0 comments on commit c9dda08

Please sign in to comment.