From bb11be6f0de52b9e388a63bc8d1180878c06d8b8 Mon Sep 17 00:00:00 2001 From: "Timothy N. Tsvetkov" Date: Wed, 13 Nov 2024 16:01:58 +0000 Subject: [PATCH] fix(executor): check holder status before using it --- executor/src/transactions/holder.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/executor/src/transactions/holder.rs b/executor/src/transactions/holder.rs index 9ff3a793..89724376 100644 --- a/executor/src/transactions/holder.rs +++ b/executor/src/transactions/holder.rs @@ -302,6 +302,8 @@ impl HolderManager { } pub async fn acquire_holder(&self, tx: Option<&TxEnvelope>) -> anyhow::Result { + use common::evm_loader::account::{self, tag}; + let existing = |meta| { let info = self.attach_info(meta, tx); AcquireHolder { @@ -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 {