Skip to content
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

pack: fix compute units #4113

Merged
merged 1 commit into from
Feb 12, 2025
Merged

pack: fix compute units #4113

merged 1 commit into from
Feb 12, 2025

Conversation

jherrera-jump
Copy link
Contributor

@jherrera-jump jherrera-jump commented Feb 6, 2025

The pack tile maintains compute cost for transactions in order to properly fill block. This PR some issues with the current calculation

  • Use loaded accounts data cost
  • Use the correct number of units for simple votes
  • Use default 200k units for config program, which will be migrated to BPF

@jherrera-jump jherrera-jump force-pushed the jherrera/pack-fix-cus branch 4 times, most recently from 06fa4fa to c4f8a00 Compare February 7, 2025 15:05
@jherrera-jump jherrera-jump marked this pull request as ready for review February 7, 2025 15:05
@jherrera-jump jherrera-jump force-pushed the jherrera/pack-fix-cus branch 8 times, most recently from fae6d65 to 9ea8ac9 Compare February 10, 2025 17:22
@mmcgee-jump
Copy link
Contributor

Can you squash and name commit like pack: <description>, thanks!

@jherrera-jump jherrera-jump force-pushed the jherrera/pack-fix-cus branch 2 times, most recently from 1e567bd to fb75b50 Compare February 10, 2025 23:57
Copy link
Contributor

@ptaffet-jump ptaffet-jump left a comment

Choose a reason for hiding this comment

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

Review in progress

src/ballet/txn/fd_txn.h Show resolved Hide resolved
@@ -107,6 +107,12 @@
transaction, using fd_txn_parse() verification rules. */
#define FD_TXN_MIN_SERIALIZED_SZ (134UL)

/* base58 decode of Vote111111111111111111111111111111111111111 */
static const uchar FD_TXN_VOTE_PROGRAM_ID[FD_TXN_ACCT_ADDR_SZ] = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you move this into the is_simple_vote function so that the scoping is more restricted?

Comment on lines 459 to 461
if( txn->instr_cnt!=1UL ) return 0;
if( txn->transaction_version!=FD_TXN_VLEGACY ) return 0;
if( txn->signature_cnt>2UL ) return 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you align the returns and add LIKELY/UNLIKELY? I'd make them unlikely. Might make sense to only make it one branch though, not sure.

if( txn->signature_cnt>2UL ) return 0;
ulong prog_id_idx = (ulong)txn->instr[0].program_id;
fd_acct_addr_t const * prog_id = addr_base + prog_id_idx;
return 0 == memcmp(prog_id->b, FD_TXN_VOTE_PROGRAM_ID, FD_TXN_ACCT_ADDR_SZ);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: spaces around parens. Also, there's fd_memeq if you'd like

src/ballet/txn/fd_txn.h Show resolved Hide resolved
Comment on lines 182 to 185
ulong loaded_accounts_data_cost = FD_COMPUTE_BUDGET_ACCOUNT_DATA_COST_PAGE_SIZE - 1UL;
loaded_accounts_data_cost = loaded_accounts_data_cost + loaded_accounts_data_size;
loaded_accounts_data_cost = loaded_accounts_data_cost / FD_COMPUTE_BUDGET_ACCOUNT_DATA_COST_PAGE_SIZE;
loaded_accounts_data_cost = loaded_accounts_data_cost * FD_COMPUTE_BUDGET_HEAP_COST;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd just make this one expression. It's just a round up, times a constant. Something like
FD_COMPUTE_BUDGET_HEAP_COST * ((loaded_account_data_size + (FD_COMPUTE_BUDGET_ACCOUNT_DATA_COST_PAGE_SIZE-1UL)/FD_COMPUTE_BUDGET_ACCOUNT_DATA_COST_PAGE_SIZE )
should be clear enough

}

ulong instr_data_cost = instr_data_sz / FD_PACK_INV_COST_PER_INSTR_DATA_BYTE; /* <= 320 */

ulong fee[1];
uint compute[1];
fd_compute_budget_program_finalize( cbp, txn->instr_cnt, fee, compute );
ulong loaded_account_data_cost[1];
fd_compute_budget_program_finalize( cbp, txn->instr_cnt, fee, compute, loaded_account_data_cost);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
fd_compute_budget_program_finalize( cbp, txn->instr_cnt, fee, compute, loaded_account_data_cost);
fd_compute_budget_program_finalize( cbp, txn->instr_cnt, fee, compute, loaded_account_data_cost );

Copy link
Contributor

@ptaffet-jump ptaffet-jump left a comment

Choose a reason for hiding this comment

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

Overall looking good! I'm sorry you had to deal with test_pack, but thanks for making it much more robust!

#define FD_PACK_COST_PER_ED25519_SIGNATURE ( 2400UL)
#define FD_PACK_COST_PER_SECP256K1_SIGNATURE ( 6690UL)
#define FD_PACK_COST_PER_WRITABLE_ACCT ( 300UL)
#define FD_PACK_INV_COST_PER_INSTR_DATA_BYTE ( 4UL)

/* The computation here is similar to the computation for the max
fd_txn_t size. There are various things a transaction can include
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to update FD_PACK_MAX_TXN_COST and FD_PACK_MIN_TXN_COST. I'm happy to help with those.

ulong loaded_accounts_data_cost = 0UL;
fd_compute_budget_program_finalize( &state, txn->instr_cnt, &rewards, &compute, &loaded_accounts_data_cost);
FD_TEST( rewards == expected_fee_lamports );
FD_TEST( (ulong)compute == expected_max_cu || 1 );
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused by this one. Why the || 1?

pack_outcome_t * outcome ) {
fd_pack_limits_t limits[1] = { {
.max_cost_per_block = FD_PACK_MAX_COST_PER_BLOCK,
.max_vote_cost_per_block = FD_PACK_MAX_VOTE_COST_PER_BLOCK,
.max_write_cost_per_acct = FD_PACK_MAX_WRITE_COST_PER_ACCT,
.max_data_bytes_per_block = MAX_DATA_PER_BLOCK,
.max_data_bytes_per_block = max_data_bytes_per_block,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you revert this change please?

schedule_validate_microblock( pack, 30000UL, 0.0f, 1UL, 0UL, 0UL, &outcome ); /* conflict gone.*/
ulong pack_cost_estimate = 0UL;
uint flags = 0UL;
rewards += make_transaction( i, 500U, 500U, 11.0, "A", "B" ); pack_cost_estimate += fd_pack_compute_cost((fd_txn_t const *)txn_scratch[ i ], payload_scratch[ i ], &flags, NULL, NULL, NULL, NULL); insert( i++, pack );
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe have make_transaction provide the cost estimate via an out parameter? The way you have it is a bit clumsy

@@ -95,8 +96,8 @@ before_frag( fd_bank_ctx_t * ctx,
}

extern void * fd_ext_bank_pre_balance_info( void const * bank, void * txns, ulong txn_cnt );
extern void * fd_ext_bank_load_and_execute_txns( void const * bank, void * txns, ulong txn_cnt, int * out_processing_results, int * out_transaction_err, uint * out_consumed_cus );
extern int fd_ext_bank_execute_and_commit_bundle( void const * bank, void * txns, ulong txn_cnt, uint * out_consumed_cus );
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we also need this for bundles?

@mmcgee-jump
Copy link
Contributor

Can you squash commits to keep stack tidy

@jherrera-jump jherrera-jump force-pushed the jherrera/pack-fix-cus branch 2 times, most recently from eb85c86 to b48aa06 Compare February 12, 2025 21:11
@jherrera-jump jherrera-jump force-pushed the jherrera/pack-fix-cus branch 2 times, most recently from 38878dd to 215cb8b Compare February 12, 2025 22:34
ptaffet-jump
ptaffet-jump previously approved these changes Feb 12, 2025
@jherrera-jump jherrera-jump added this pull request to the merge queue Feb 12, 2025
Merged via the queue into main with commit 4d173a0 Feb 12, 2025
10 of 11 checks passed
@jherrera-jump jherrera-jump deleted the jherrera/pack-fix-cus branch February 12, 2025 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants