Skip to content

Commit

Permalink
fix(executor): check holder status before using it
Browse files Browse the repository at this point in the history
  • Loading branch information
tukan committed Nov 13, 2024
1 parent 0233706 commit bb11be6
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions executor/src/transactions/holder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ impl HolderManager {
}

pub async fn acquire_holder(&self, tx: Option<&TxEnvelope>) -> anyhow::Result<AcquireHolder> {
use common::evm_loader::account::{self, tag};

let existing = |meta| {
let info = self.attach_info(meta, tx);
AcquireHolder {
Expand All @@ -310,8 +312,21 @@ impl HolderManager {
}
};

if let Ok(meta) = self.receiver.try_recv() {
return Ok(existing(meta));
while let Ok(meta) = self.receiver.try_recv() {
debug!(%self.operator, idx = meta.idx, pubkey = %meta.pubkey, "requesting holder state");
let Some(mut account) = self.solana_api.get_account(&meta.pubkey).await? else {
debug!(%self.operator, idx = meta.idx, pubkey = %meta.pubkey, "holder does not exists");
let _ = self.counter.fetch_sub(1, SeqCst);
continue;
};
debug!(%self.operator, idx = meta.idx, pubkey = %meta.pubkey, ?account, "holder exists");
let account_info = (&meta.pubkey, &mut account).into_account_info();
let state = tag(&self.program_id, &account_info).context("invalid holder account")?;
// TODO: what's the correct check here?
if state == account::TAG_EMPTY {
return Ok(existing(meta));
}
let _ = self.counter.fetch_sub(1, SeqCst);
}

if self.counter.load(SeqCst) < self.max_holders {
Expand Down

0 comments on commit bb11be6

Please sign in to comment.