-
Notifications
You must be signed in to change notification settings - Fork 220
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
pack: fix compute units #4113
Conversation
06fa4fa
to
c4f8a00
Compare
c4f8a00
to
19f7610
Compare
fae6d65
to
9ea8ac9
Compare
Can you squash and name commit like |
1e567bd
to
fb75b50
Compare
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.
Review in progress
src/ballet/txn/fd_txn.h
Outdated
@@ -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] = { |
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.
Can you move this into the is_simple_vote
function so that the scoping is more restricted?
src/ballet/txn/fd_txn.h
Outdated
if( txn->instr_cnt!=1UL ) return 0; | ||
if( txn->transaction_version!=FD_TXN_VLEGACY ) return 0; | ||
if( txn->signature_cnt>2UL ) return 0; |
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.
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.
src/ballet/txn/fd_txn.h
Outdated
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); |
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.
nit: spaces around parens. Also, there's fd_memeq if you'd like
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; |
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.
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
src/disco/pack/fd_pack_cost.h
Outdated
} | ||
|
||
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); |
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.
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 ); |
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.
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 |
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.
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 ); |
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.
I'm confused by this one. Why the || 1
?
src/disco/pack/test_pack.c
Outdated
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, |
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.
Can you revert this change please?
src/disco/pack/test_pack.c
Outdated
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 ); |
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.
Maybe have make_transaction
provide the cost estimate via an out parameter? The way you have it is a bit clumsy
src/app/fdctl/run/tiles/fd_bank.c
Outdated
@@ -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 ); |
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.
Do we also need this for bundles?
84dd376
to
0bee8b1
Compare
Can you squash commits to keep stack tidy |
0bee8b1
to
dad2f55
Compare
eb85c86
to
b48aa06
Compare
38878dd
to
215cb8b
Compare
215cb8b
to
31ef576
Compare
The pack tile maintains compute cost for transactions in order to properly fill block. This PR some issues with the current calculation