-
Notifications
You must be signed in to change notification settings - Fork 92
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
SIMD-0186: Loaded Transaction Data Size Specification #186
base: main
Are you sure you want to change the base?
Changes from 10 commits
092a67c
04e283b
c694155
078a6f9
8c0603b
a015ab7
64db94f
ec59003
173f092
194c751
59bf637
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
--- | ||
simd: '0186' | ||
title: Loaded Transaction Data Size Specification | ||
authors: | ||
- Hanako Mumei | ||
category: Standard | ||
type: Core | ||
status: Review | ||
created: 2024-10-20 | ||
feature: (fill in with feature tracking issues once accepted) | ||
--- | ||
|
||
## Summary | ||
|
||
Before a transaction can be executed, every account it may read from or write to | ||
must be loaded, including any programs it may call. The amount of data a | ||
transaction is allowed to load is capped, and if it exceeds that limit, loading | ||
is aborted. This functionality is already implemented in the validator. | ||
|
||
This SIMD defines a new algorithm for calculating the consensus-enforced total | ||
size of loaded transaction data during transaction processing. | ||
|
||
## Motivation | ||
|
||
Transaction data size accounting is currently unspecified, and the | ||
implementation-defined algorithm used in the Agave client exhibits some | ||
surprising behaviors: | ||
|
||
* BPF loaders required by instructions' program IDs are counted against | ||
transaction data size. BPF loaders required by CPI programs are not. If a | ||
required BPF loader is also included in the accounts list, it is counted twice. | ||
* The size of a program owned by LoaderV3 may or may not include the size of its | ||
programdata depending on how the program account is used on the transaction. | ||
Programdata is also itself counted if included in the transaction accounts list. | ||
This means programdata may be counted zero, one, or two times per transaction. | ||
* Due to certain quirks of implementation, loader-owned accounts which do not | ||
contain valid programs for execution may or may not be counted against the | ||
transaction data size total depending on how they are used on the transaction. | ||
This includes, but is not limited to, LoaderV3 buffer accounts, and accounts | ||
which fail ELF validation. | ||
|
||
All validator clients must arrive at precisely the same transaction data size | ||
for all transactions because a difference of one byte can determine whether a | ||
transaction is executed or failed, and thus affects consensus. Also, we want the | ||
calculated transaction data size to correspond well with the actual amount of | ||
data the transaction requests. | ||
|
||
Therefore, this SIMD seeks to specify an algorithm that is straightforward to | ||
implement in a client-agnostic way, while also accurately accounting for all | ||
account data required by the transaction. | ||
|
||
## New Terminology | ||
|
||
No new terms are introduced by this SIMD, however we define these for clarity: | ||
|
||
* Instruction account: an account passed to an instruction in its accounts | ||
array, which allows the program to view the actual bytes contained in the | ||
account. CPI can only happen through programs provided as instruction accounts. | ||
* Transaction accounts list: all accounts for the transaction, which includes | ||
instruction accounts, the fee-payer, program IDs, and any extra accounts added | ||
to the list but not explicitly available to programs. | ||
* LoaderV3 program account: an account owned by | ||
`BPFLoaderUpgradeab1e11111111111111111111111` which contains in its account data | ||
the first four bytes `02 00 00 00` followed by a pubkey which points to an | ||
account which is defined as the program's programdata account. | ||
|
||
For the purposes of this SIMD, we make no assumptions about the contents of the | ||
programdata account. | ||
|
||
## Detailed Design | ||
|
||
The proposed algorithm is as follows: | ||
|
||
1. The set of accounts that determine loaded transaction data size is defined as | ||
the unique intersection of: | ||
* The set of account keys explicitly specified on the transaction, | ||
irrespective of how they are used. | ||
* The set of programdata accounts referenced by the LoaderV3 program | ||
accounts specified on the transaction. | ||
2. Each account's size is defined as the byte length of its data prior to | ||
transaction execution plus 64 bytes to account for metadata. | ||
3. There is an additional flat 8248 byte cost for transactions that use an | ||
address lookup table, accounting for the 8192 bytes for the maximum size of such | ||
a table plus 56 bytes for metadata. | ||
4. The total transaction loaded account data size is the sum of these sizes. | ||
|
||
Transactions may include a | ||
`ComputeBudgetInstruction::SetLoadedAccountsDataSizeLimit` instruction to define | ||
a lower data size limit for the transaction. Otherwise, the default limit is | ||
64MiB (`64 * 1024 * 1024` bytes). | ||
|
||
If a transaction exceeds its data size limit, the transaction is failed. Fees | ||
will be charged once `enable_transaction_loading_failure_fees` is enabled. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where will this be checked? Do transactions that fail this check make it into blocks? Do you mind clarifying this in the SIMD? 🙏 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok i updated the wording to:
the idea is we arent changing any of the logic about how loading works here, the existing flow stays the same (loading happens at the same time in the same place of transaction processing, what kind of error you get if you exceed the limit, how that error is handled and how its reflected in ledger history, etc) the only thing that changes is what the number of bytes you arrive at will be and how you determine what that number is |
||
|
||
Adding required loaders to transaction data size is abolished. They are treated | ||
the same as any other account: counted if used in a manner described by 1, not | ||
counted otherwise. | ||
|
||
Read-only and writable accounts are treated the same. In the future, when direct | ||
mapping is enabled, this SIMD may be amended to count them differently. | ||
|
||
We include programdata size for LoaderV3 programs because using the program | ||
account on a transaction forces an unconditional load of programdata to compile | ||
the program for execution. We always count it, even when the program account is | ||
not a transaction program ID, because the program must be available for CPI. | ||
|
||
There is no special handling for any account owned by the native loader, | ||
LoaderV1, or LoaderV2. | ||
|
||
Account size for programs owned by LoaderV4 is left undefined. This SIMD should | ||
be amended to define the required semantics before LoaderV4 is enabled on any | ||
network. | ||
|
||
## Alternatives Considered | ||
|
||
* Transaction data size accounting is already enabled, so the null option is to | ||
enshrine the current Agave behavior in the protocol. This is undesirable because | ||
the current behavior is highly idiosyncratic, and LoaderV3 program sizes are | ||
routinely undercounted. | ||
* Builtin programs are backed by accounts that only contain the program name as | ||
a string, typically making them 15-40 bytes. We could impose a larger fixed cost | ||
for these. However, they must be made available for all programs anyway, and | ||
most of them are likely to be ported to BPF eventually, so this adds complexity | ||
for no real benefit. | ||
* Several slightly different algorithms were considered for handling LoaderV3 | ||
programs in particular, for instance only counting programs that are valid for | ||
execution in the current slot. However, this would implicitly couple transaction | ||
data size with the results of ELF validation, which is highly undesirable. | ||
* We considered skipping loading of accounts included in the transaction | ||
accounts list but not used as an instruction account, program ID, or fee-payer. | ||
However, [SIMD-0163]( | ||
https://github.com/solana-foundation/solana-improvement-documents/pull/163) | ||
intends to leverage these accounts to make CPI more CU-efficient. | ||
|
||
## Impact | ||
|
||
The primary impact is this SIMD makes correctly implementing transaction data | ||
size accounting much easier for other validator clients. | ||
|
||
It makes the calculated size of transactions which include program accounts for | ||
CPI somewhat larger, but given the generous 64MiB limit, it is unlikely that any | ||
existing users will be affected. Based on an investigation of a 30-day window, | ||
transactions larger than 30MiB are virtually never seen. | ||
|
||
## Security Considerations | ||
|
||
Security impact is minimal because this SIMD merely simplifies an existing | ||
feature. Care must be taken to implement the rules exactly. | ||
|
||
This SIMD requires a feature gate. | ||
|
||
## Backwards Compatibility | ||
|
||
Transactions that currently have a total transaction data size close to the | ||
64MiB limit, which call LoaderV3 programs via CPI, may now exceed it and fail. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh just realized we should probably also include ALT account sizes as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm but ALTs are not read or write locked by the transaction so they could be extended in parallel so we can't use the actual size. Maybe just use the max size of
LOOKUP_TABLE_META_SIZE + LOOKUP_TABLE_MAX_ADDRESSES * 32
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it possible to know whether an ALT was used at all in transaction processing? my understanding is resolution happens too early and all the information is erased. im not sure if there is an easy solution to this or if we should defer adding it to transaction data size after the ALT async execution simd changes how that code works
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible, we could simply include that information in static meta and make it available to the account loader. The ALT SIMD changes will most likely only really cover failure cases so I don't think we need to defer this decision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're just using the max size of a table, we don't need to store any additional information in static meta. We have the number of ALTs in the message itself.
and I (accidently) have already exposed getting that information in
SVMMessage
trait, so we should be able to get it in our specific implementation easily.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(based on discussion we are considering a flat 8192 byte cost for ALT usage, pending feedback from @tao-stones)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be 8248 byte cost because there is space in the ALT accounts for 56 bytes of metadata as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8248 * 8 / 32000 = 2 CU
, that doesn't sound bad at all.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, let's go forward with that in the proposal for now then