Skip to content

Commit

Permalink
Merge pull request #72 from holaplex/main
Browse files Browse the repository at this point in the history
Release 10/10
  • Loading branch information
kespinola authored Oct 10, 2023
2 parents 07f0931 + efeacbc commit c879cf3
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 108 deletions.
14 changes: 0 additions & 14 deletions Cargo.lock

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

42 changes: 28 additions & 14 deletions consumer/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,11 +546,7 @@ impl Processor {
self.process_nft(
EventKind::RetryMintToCollection,
&key,
self.retry_mint_to_collection(
&UncompressedRef(self.solana()),
&key,
payload,
),
self.retry_mint_to_collection(&key, payload),
)
.await
},
Expand Down Expand Up @@ -625,11 +621,7 @@ impl Processor {
self.process_nft(
EventKind::RetryMintOpenDrop,
&key,
self.retry_mint_to_collection(
&UncompressedRef(self.solana()),
&key,
payload,
),
self.retry_mint_to_collection(&key, payload),
)
.await
},
Expand Down Expand Up @@ -1185,11 +1177,8 @@ impl Processor {
Ok(tx.into())
}

async fn retry_mint_to_collection<
B: MintBackend<MintMetaplexMetadataTransaction, MintMetaplexAddresses>,
>(
async fn retry_mint_to_collection(
&self,
backend: &B,
key: &SolanaNftEventKey,
payload: MintMetaplexMetadataTransaction,
) -> ProcessResult<SolanaPendingTransaction> {
Expand All @@ -1202,6 +1191,31 @@ impl Processor {

let collection = collection.ok_or(ProcessorErrorKind::RecordNotFound)?;

if payload.compressed {
let backend = &CompressedRef(self.solana());

let tx = backend
.mint(&collection, payload)
.map_err(ProcessorErrorKind::Solana)?;

let leaf_model = CompressionLeaf::find_by_id(conn, id)
.await?
.ok_or(ProcessorErrorKind::RecordNotFound)?;

let mut compression_leaf: compression_leafs::ActiveModel = leaf_model.into();

compression_leaf.merkle_tree = Set(tx.addresses.merkle_tree.to_string());
compression_leaf.tree_authority = Set(tx.addresses.tree_authority.to_string());
compression_leaf.tree_delegate = Set(tx.addresses.tree_delegate.to_string());
compression_leaf.leaf_owner = Set(tx.addresses.leaf_owner.to_string());

compression_leaf.update(conn).await?;

return Ok(tx.into());
}

let backend = &UncompressedRef(self.solana());

let tx = backend
.mint(&collection, payload)
.map_err(ProcessorErrorKind::Solana)?;
Expand Down
65 changes: 39 additions & 26 deletions consumer/src/solana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ use mpl_token_metadata::{
},
state::{Creator, DataV2, EDITION, PREFIX},
};
use solana_client::rpc_client::RpcClient as SolanaRpcClient;
use solana_client::{
client_error::{ClientError, ClientErrorKind},
rpc_client::RpcClient as SolanaRpcClient,
};
use solana_program::{
instruction::Instruction, program_pack::Pack, pubkey::Pubkey,
system_instruction::create_account, system_program,
Expand Down Expand Up @@ -59,16 +62,18 @@ use crate::{
},
};

macro_rules! call_with_retry {
macro_rules! with_retry {
($expr:expr) => {{
(|| $expr)
.retry(
&ExponentialBuilder::default()
.with_jitter()
.with_min_delay(Duration::from_millis(30))
.with_max_times(10),
.with_max_times(15),
)
.call()
.notify(|err: &ClientError, dur: Duration| {
error!("retrying error {:?} in {:?}", err, dur);
})
}};
}

Expand Down Expand Up @@ -201,9 +206,11 @@ impl Solana {
&self,
signature: &Signature,
) -> Result<u32, SolanaAssetIdError> {
let response = self
.rpc()
.get_transaction(signature, UiTransactionEncoding::Json)?;
let response = with_retry!(
self.rpc()
.get_transaction(signature, UiTransactionEncoding::Json)
)
.call()?;

let meta = response
.transaction
Expand Down Expand Up @@ -247,10 +254,7 @@ impl Solana {
let signatures = transaction
.signed_message_signatures
.iter()
.map(|s| {
Signature::from_str(s)
.map_err(|e| anyhow!(format!("failed to parse signature: {e}")))
})
.map(|s| Signature::from_str(s).context("failed to parse signature"))
.collect::<Result<Vec<Signature>>>()?;

let message = bincode::deserialize(
Expand All @@ -265,13 +269,21 @@ impl Solana {
message,
};

call_with_retry!(self.rpc().send_and_confirm_transaction(&transaction))
.map(|s| s.to_string())
let signature = with_retry!(self.rpc().send_and_confirm_transaction(&transaction))
.when(|e| {
!matches!(
e.kind,
ClientErrorKind::TransactionError(_) | ClientErrorKind::SigningError(_)
)
})
.call()
.map_err(|e| {
let msg = format!("failed to submit transaction: {e}");
let msg = format!("failed to send transaction: {e}");
error!(msg);
anyhow!(msg)
})
})?;

Ok(signature.to_string())
}
}

Expand Down Expand Up @@ -323,8 +335,8 @@ impl<'a> CollectionBackend for UncompressedRef<'a> {
);
let len = spl_token::state::Mint::LEN;

let rent = call_with_retry!(rpc.get_minimum_balance_for_rent_exemption(len))?;
let blockhash = call_with_retry!(rpc.get_latest_blockhash())?;
let rent = with_retry!(rpc.get_minimum_balance_for_rent_exemption(len)).call()?;
let blockhash = with_retry!(rpc.get_latest_blockhash()).call()?;

let create_account_ins = solana_program::system_instruction::create_account(
&payer,
Expand Down Expand Up @@ -473,7 +485,7 @@ impl<'a> CollectionBackend for UncompressedRef<'a> {
None,
);

let blockhash = call_with_retry!(rpc.get_latest_blockhash())?;
let blockhash = with_retry!(rpc.get_latest_blockhash()).call()?;

let message =
solana_program::message::Message::new_with_blockhash(&[ins], Some(&payer), &blockhash);
Expand Down Expand Up @@ -525,7 +537,7 @@ impl<'a> CollectionBackend for UncompressedRef<'a> {
&mpl_token_metadata::ID,
);

let blockhash = call_with_retry!(rpc.get_latest_blockhash())?;
let blockhash = with_retry!(rpc.get_latest_blockhash()).call()?;

let update_ins: Instruction = mpl_token_metadata::instruction::update_metadata_accounts_v2(
mpl_token_metadata::ID,
Expand Down Expand Up @@ -588,7 +600,7 @@ impl<'a> CollectionBackend for UncompressedRef<'a> {
let mut message: solana_program::message::Message =
bincode::deserialize(&revision.serialized_message)?;

let blockhash = call_with_retry!(rpc.get_latest_blockhash())?;
let blockhash = with_retry!(rpc.get_latest_blockhash()).call()?;
message.recent_blockhash = blockhash;

Ok(TransactionResponse {
Expand Down Expand Up @@ -673,7 +685,7 @@ impl<'a> CollectionBackend for UncompressedRef<'a> {

let instructions = vec![unverify_ins, verify_ins];

let blockhash = call_with_retry!(rpc.get_latest_blockhash())?;
let blockhash = with_retry!(rpc.get_latest_blockhash()).call()?;

let message = solana_program::message::Message::new_with_blockhash(
&instructions,
Expand Down Expand Up @@ -743,7 +755,8 @@ impl<'a> MintBackend<MintMetaplexEditionTransaction, MintEditionAddresses> for E
];
let (metadata_key, _) = Pubkey::find_program_address(metadata_seeds, &program_pubkey);

let rent = call_with_retry!(rpc.get_minimum_balance_for_rent_exemption(state::Mint::LEN))?;
let rent =
with_retry!(rpc.get_minimum_balance_for_rent_exemption(state::Mint::LEN)).call()?;

let mut instructions = vec![
create_account(
Expand Down Expand Up @@ -781,7 +794,7 @@ impl<'a> MintBackend<MintMetaplexEditionTransaction, MintEditionAddresses> for E
edition,
));

let blockhash = call_with_retry!(rpc.get_latest_blockhash())?;
let blockhash = with_retry!(rpc.get_latest_blockhash()).call()?;

let message = solana_program::message::Message::new_with_blockhash(
&instructions,
Expand Down Expand Up @@ -829,7 +842,7 @@ impl<'a> TransferBackend<collection_mints::Model, TransferAssetAddresses> for Un
let recipient: Pubkey = recipient_address.parse()?;
let mint_address: Pubkey = collection_mint.mint.parse()?;
let payer: Pubkey = self.0.treasury_wallet_address;
let blockhash = call_with_retry!(rpc.get_latest_blockhash())?;
let blockhash = with_retry!(rpc.get_latest_blockhash()).call()?;
let source_ata = get_associated_token_address(&sender, &mint_address);
let destination_ata = get_associated_token_address(&recipient, &mint_address);

Expand Down Expand Up @@ -1126,8 +1139,8 @@ impl<'a> MintBackend<MintMetaplexMetadataTransaction, MintMetaplexAddresses>
);
let associated_token_account = get_associated_token_address(&recipient, &mint.pubkey());
let len = spl_token::state::Mint::LEN;
let rent = call_with_retry!(rpc.get_minimum_balance_for_rent_exemption(len))?;
let blockhash = call_with_retry!(rpc.get_latest_blockhash())?;
let rent = with_retry!(rpc.get_minimum_balance_for_rent_exemption(len)).call()?;
let blockhash = with_retry!(rpc.get_latest_blockhash()).call()?;

let create_account_ins = solana_program::system_instruction::create_account(
&payer,
Expand Down
2 changes: 1 addition & 1 deletion core/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct DbArgs {
pub connection_timeout: u64,
#[arg(long, env, default_value_t = 10)]
pub acquire_timeout: u64,
#[arg(long, env, default_value_t = 60)]
#[arg(long, env, default_value_t = 10)]
pub idle_timeout: u64,
#[arg(long, env)]
pub database_url: String,
Expand Down
2 changes: 0 additions & 2 deletions indexer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ solana-program = "1.14"
anchor-lang = "0.26.0"
yellowstone-grpc-client = { git = "https://github.com/rpcpool/yellowstone-grpc", tag = "v1.7.1+solana.1.16.1" }
yellowstone-grpc-proto = { git = "https://github.com/rpcpool/yellowstone-grpc", tag = "v1.7.1+solana.1.16.1" }
dashmap = "5.4.0"
spl-token = "=3.5.0"
solana-client = "1.14"
backoff = { version = "0.4.0", features = ["tokio"] }


[dependencies.hub-core]
package = "holaplex-hub-core"
version = "0.5.6"
Expand Down
Loading

0 comments on commit c879cf3

Please sign in to comment.