node/transaction_pool/
transaction_pool_effects.rs

1use std::collections::BTreeMap;
2
3use crate::{ledger::LedgerService, snark::SnarkStore};
4
5use super::TransactionPoolEffectfulAction;
6
7impl TransactionPoolEffectfulAction {
8    pub fn effects<Store, S>(self, store: &mut Store)
9    where
10        Store: SnarkStore<S>,
11        Store::Service: LedgerService,
12    {
13        match self {
14            TransactionPoolEffectfulAction::FetchAccounts {
15                account_ids,
16                ledger_hash,
17                on_result,
18                pending_id,
19                from_source,
20            } => {
21                openmina_core::log::info!(
22                    openmina_core::log::system_time();
23                    kind = "TransactionPoolEffectfulFetchAccounts",
24                    summary = "fetching accounts for tx pool");
25                // FIXME: the ledger ctx `get_accounts` function doesn't ensure that every account we
26                // asked for is included in the result.
27                // TODO: should be asynchronous. Once asynchronous, watch out for race
28                // conditions between tx pool and transition frontier. By the time the
29                // accounts have been fetched the best tip may have changed already.
30                let accounts = match store
31                    .service()
32                    .ledger_manager()
33                    .get_accounts(&ledger_hash, account_ids.iter().cloned().collect())
34                {
35                    Ok(accounts) => accounts,
36                    Err(err) => {
37                        openmina_core::log::error!(
38                                openmina_core::log::system_time();
39                                kind = "Error",
40                                summary = "failed to fetch accounts for tx pool",
41                                error = format!("ledger {:?}, error: {:?}", ledger_hash, err));
42                        return;
43                    }
44                };
45
46                let accounts = accounts
47                    .into_iter()
48                    .map(|account| (account.id(), account))
49                    .collect::<BTreeMap<_, _>>();
50
51                store.dispatch_callback(on_result, (accounts, pending_id, from_source));
52            }
53        }
54    }
55}