Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Application fees#30137

Closed
godmodegalactus wants to merge 6 commits into
solana-labs:masterfrom
blockworks-foundation:application-fees
Closed

Application fees#30137
godmodegalactus wants to merge 6 commits into
solana-labs:masterfrom
blockworks-foundation:application-fees

Conversation

@godmodegalactus
Copy link
Copy Markdown
Contributor

Problem

As described in solana-foundation/solana-improvement-documents#16 this is an implementation of application fees using the modification of account structure to store the information about application fees.

Summary of Changes

Modifying the Account structure to store the application fees for the account. As the rent epoch is deprecated and being removed we use the same we change the rent_epoch to rent_epoch_or_application_fees. Added a boolean has_application_fees to switch between rent epoch and application fees. These changes did not affect the size of the account structure.

Also added a new native program App1icationFees1111111111111111111111111111 to update and rebate application fees. The application fee can be updated by the instruction UpdateFee, this will update the structure ApplicationFeeChanges in invoke context and application fees will be updated at the end of slot. These application fees for each account will be taken from the payer when payer write locks the account. These fees will be saved in a map application_fees_collected a member of the bank and will be transfered to the respective accounts when the bank is frozen. The rewards for the bank will be updated accordingly. If there are more than one different application fees updates for the same account with in one slot all the updates will be rejected.

Fixes #

@mergify mergify Bot added community Community contribution need:merge-assist labels Feb 5, 2023
@mergify mergify Bot requested a review from a team February 5, 2023 09:16
…he account structure adding a new field `has_application_fee` and changing `rent_epoch` \

 to `rent_epoch_or_application_fees`.
Adding a new native program to manage application fees and implementing unit tests for the program and accounts.
Ok(())
}

fn rebate(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is there anything I can do here?

Copy link
Copy Markdown
Contributor

@apfitzge apfitzge left a comment

Choose a reason for hiding this comment

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

Added some initial thoughts, mostly focused around the accounts and this line from the PR description:

These changes did not affect the size of the account structure.

That doesn't seem to be the case to me from looking at the code. I gave a potential suggestion on how to do that.

I still need to go over the actual program for fees & rebates.

Comment thread cli-output/src/cli_output.rs Outdated
Comment thread cli-output/src/cli_output.rs Outdated
Comment thread program-runtime/src/invoke_context.rs Outdated
Comment thread runtime/src/accounts.rs Outdated
Comment thread runtime/src/accounts_db.rs Outdated
Comment thread runtime/src/append_vec.rs Outdated
Comment thread sdk/src/account.rs Outdated
pub executable: bool,
/// the epoch at which this account will next owe rent
pub rent_epoch: Epoch,
// has application fees
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: ///

Comment thread sdk/src/account.rs Outdated
// has application fees
pub has_application_fees: bool,
/// the epoch at which this account will next owe rent or application fees for the account
/// switched by the boolean above
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

switched by the boolean above

What does this mean?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ahh it means that is has_application_fees is true rent_epoch_or_application_fees represents application_fees else it represents rent_epoch. May be wording is not correct.

Comment thread sdk/src/reward_type.rs Outdated
let mut rebated_amount = None;
if let Some(lamports_rebated) = lamports_rebated {
rebated_amount = Some(*lamports_rebated);
// add these in rabates map
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// add these in rabates map
// add these in rebates map

…pplication_fees on same byte as exectuable to have same size for AccountMeta in append_vec
Comment thread runtime/src/append_vec.rs Outdated
Comment thread runtime/src/append_vec.rs Outdated

#![cfg(feature = "full")]

crate::declare_id!("App1icationFees1111111111111111111111111111");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe include this to BUILT_IN_INSTRUCTION_COSTS in runtime::block_cost_limits, with some cost?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok will do,

Comment thread sdk/src/transaction_context.rs
Comment thread sdk/program/src/instruction.rs Outdated
Comment thread runtime/src/accounts.rs Outdated
Comment thread runtime/src/accounts.rs Outdated
let mut payer_index = 0;

// we reverse the iteration over keys so that we collect all the application fees
// and then validate fees at the last
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure if understand this 100%. Will application_fee change transaction base fee (by bank.calculate_fee()) that used in validate_fee_payer()? OK, so the collected application_fees are added on top of tx's base_fee before validate_fee_payer(), then the payer_account will be deducted by sum(application_fee) _ base_fee. Am I correct? If so, wondering how would "bankless leader" validates fee payer without loading and exam-ing all accounts.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes application fees are on top of base fees. So we need to load all the accounts to calculate application fees and then charge the payer application fees + base fees. Good question about the bankless leader though. I though the bankless leader will not execute transactions just order them. I think it will have to load accounts anyways to test if the transaction is valid and if the accounts do exist.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

gotcha. Yeah, need to think about bankless leader bit more. The idea was to cache each payer account's balance, which is populated/updated by replay stage. Leader adjust payer account's balance by transaction's base fee as it packs it into block, thus far without having to load accounts. With Application Fee, it seems necessary to load all accounts tho. Something to think about.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wondering if possible that leader can just read application_fee instruction from transaction to know how much the transaction is willing to pay application fee(s), much like what compute_budget does today? Leader only needs to know how much, doesn't need to care about accounts or anything else.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread runtime/src/accounts.rs
)?;

if !validated_fee_payer && message.is_non_loader_key(i) {
if account.has_application_fees() {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Additional check if the account is writable or not.

@github-actions github-actions Bot added the stale [bot only] Added to stale content; results in auto-close after a week. label Feb 28, 2023
@github-actions github-actions Bot closed this Mar 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

community Community contribution need:merge-assist stale [bot only] Added to stale content; results in auto-close after a week.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants