Skip to content

fix:support-classic-accounts-trustlines #1746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions cmd/soroban-cli/src/commands/snapshot/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use stellar_xdr::curr::{
LedgerKeyClaimableBalance, LedgerKeyConfigSetting, LedgerKeyContractCode,
LedgerKeyContractData, LedgerKeyData, LedgerKeyLiquidityPool, LedgerKeyOffer,
LedgerKeyTrustLine, LedgerKeyTtl, Limited, Limits, ReadXdr, ScAddress, ScContractInstance,
ScVal,
ScVal, TrustLineAsset,
};
use tokio::fs::OpenOptions;
use tokio::io::BufReader;
Expand Down Expand Up @@ -289,7 +289,14 @@ impl Cmd {
}
let keep = match &key {
LedgerKey::Account(k) => current.account_ids.contains(&k.account_id),
LedgerKey::Trustline(k) => current.account_ids.contains(&k.account_id),
LedgerKey::Trustline(k) => {
current.account_ids.contains(&k.account_id) ||
current.account_ids.iter().any(|id| match &k.asset {
TrustLineAsset::CreditAlphanum4(a4) => a4.issuer == *id,
TrustLineAsset::CreditAlphanum12(a12) => a12.issuer == *id,
Comment on lines -292 to +296
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pulling in every trustline for an asset unfortunately doesn't scale well with the current implementation of snapshots, which was why I left it out. If you pass in the address for a very popular asset, the file becomes huge and unusable.

For assets with much less trust lines though I can see this being very useful so maybe we should add it.

I think this use case will be better served by the following issue that hopefully we can implement in the near future:

Thoguhts @fnando ?

_ => false, // Ignore non-credit assets
})
},
LedgerKey::ContractData(k) => current.contract_ids.contains(&k.contract),
LedgerKey::ContractCode(e) => current.wasm_hashes.contains(&e.hash),
_ => false,
Expand All @@ -299,7 +306,7 @@ impl Cmd {
}
seen.insert(key.clone());
let Some(val) = val else { continue };
match &val.data {
let should_save = match &val.data {
LedgerEntryData::ContractData(e) => {
// If a contract instance references contract
// executable stored in another ledger entry, add
Expand All @@ -319,7 +326,7 @@ impl Cmd {
hex::encode(hash)
));
}
}
}
ScVal::ContractInstance(ScContractInstance {
executable: ContractExecutable::StellarAsset,
storage: Some(storage),
Expand All @@ -333,24 +340,25 @@ impl Cmd {
Asset::CreditAlphanum4(a4) => Some(a4.issuer),
Asset::CreditAlphanum12(a12) => Some(a12.issuer),
} {
print.infoln(format!(
"Adding asset issuer {issuer} to search"
));
print.infoln(format!("Adding asset issuer {issuer} to search"));
next.account_ids.insert(issuer);
}
}
}
_ => {}
}
}
keep
true
}
_ => false,
LedgerEntryData::ContractCode(_) => true,
_ => false
};
snapshot
.ledger_entries
.push((Box::new(key), (Box::new(val), Some(u32::MAX))));
count_saved += 1;
if should_save {
snapshot
.ledger_entries
.push((Box::new(key), (Box::new(val), Some(u32::MAX))));
count_saved += 1;
}
}
if count_saved > 0 {
print.infoln(format!("Found {count_saved} entries"));
Expand Down
Loading