Skip to content

Commit 8c2c19f

Browse files
committed
flamenco, runtime: set original_data_len for non-DM CPI
Also a minor drive-by fix for update_caller_account() in the CPI return edge. Use the correct source for prev_len.
1 parent 9165d8e commit 8c2c19f

File tree

5 files changed

+16
-3
lines changed

5 files changed

+16
-3
lines changed

src/flamenco/runtime/program/fd_bpf_loader_serialization.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ write_account( fd_borrowed_account_t * account,
8282
uchar const * data = account ? fd_borrowed_account_get_data( account ) : NULL;
8383
ulong dlen = account ? fd_borrowed_account_get_data_len( account ) : 0UL;
8484

85+
acc_region_metas[instr_acc_idx].original_data_len = dlen;
8586
if( copy_account_data ) {
8687
/* Copy the account data into input region buffer */
8788
fd_memcpy( *serialized_params, data, dlen );
@@ -93,6 +94,11 @@ write_account( fd_borrowed_account_t * account,
9394
fd_memset( *serialized_params, 0, MAX_PERMITTED_DATA_INCREASE + align_offset );
9495
*serialized_params += MAX_PERMITTED_DATA_INCREASE + align_offset;
9596
}
97+
/* In the non-DM case, we don't bother with setting up mem regions.
98+
So has_data_region and has_resizing_region are set to 0. */
99+
acc_region_metas[instr_acc_idx].region_idx = UINT_MAX;
100+
acc_region_metas[instr_acc_idx].has_data_region = 0U;
101+
acc_region_metas[instr_acc_idx].has_resizing_region = 0U;
96102
} else { /* direct_mapping == true */
97103
/* First, push on the region for the metadata that has just been serialized.
98104
This function will push the metadata in the serialized_params from

src/flamenco/runtime/tests/run_backtest_ci.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ src/flamenco/runtime/tests/run_ledger_backtest.sh -l mainnet-331691646-v2.2.16 -
1717
src/flamenco/runtime/tests/run_ledger_backtest.sh -l mainnet-257039990-v2.2.16 -s snapshot-257039990-BSgErEc6ppN4p91meqPvUiXPiEhbakBNHMQQ4wKmceYv.tar.zst -y 5 -m 10000000 -e 257040003 -c 2.2.16
1818
src/flamenco/runtime/tests/run_ledger_backtest.sh -l testnet-336218682-v2.2.16 -s snapshot-336218681-BDsErdHkqa5iQGCNkSvQpeon8GLFsgeNEkckrMKboJ4N.tar.zst -y 5 -m 2000000 -e 336218683 -c 2.2.16
1919
src/flamenco/runtime/tests/run_ledger_backtest.sh -l testnet-340269866 -s snapshot-340269865-7kiU4fCQMuf97vs3827n1vn1oScnkYYvvQ1sGGa1QKVE.tar.zst -y 5 -m 2000000 -e 340269872 -c 2.2.16
20+
src/flamenco/runtime/tests/run_ledger_backtest.sh -l devnet-390056400 -s snapshot-390056399-6JQvYEDzQqcrjF4EoxkWUMuskm9aGoGRG94twEqXuuri.tar.zst -y 10 -m 2000000 -e 390056406 -c 2.2.16

src/flamenco/runtime/tests/run_backtest_tests_all.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,4 @@ src/flamenco/runtime/tests/run_ledger_backtest.sh -l devnet-380592002-v2.2.16 -s
8383
src/flamenco/runtime/tests/run_ledger_backtest.sh -l testnet-336218682-v2.2.16 -s snapshot-336218681-BDsErdHkqa5iQGCNkSvQpeon8GLFsgeNEkckrMKboJ4N.tar.zst -y 5 -m 2000000 -e 336218683 -c 2.2.16
8484
src/flamenco/runtime/tests/run_ledger_backtest.sh -l testnet-340269866 -s snapshot-340269865-7kiU4fCQMuf97vs3827n1vn1oScnkYYvvQ1sGGa1QKVE.tar.zst -y 5 -m 2000000 -e 340269872 -c 2.2.16
8585
src/flamenco/runtime/tests/run_ledger_backtest.sh -l testnet-340272018 -s snapshot-340272017-SoJMtGKERj3xMB6jB7bumiHe96q4xVjHVN4kz2MGbqn.tar.zst -y 5 -m 2000000 -e 340272024 -c 2.2.16
86+
src/flamenco/runtime/tests/run_ledger_backtest.sh -l devnet-390056400 -s snapshot-390056399-6JQvYEDzQqcrjF4EoxkWUMuskm9aGoGRG94twEqXuuri.tar.zst -y 10 -m 2000000 -e 390056406 -c 2.2.16

src/flamenco/vm/fd_vm.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ struct __attribute((aligned(8UL))) fd_vm_acc_region_meta {
4141
/* offset of the accounts metadata region, relative to the start of the input region.
4242
importantly, this excludes any duplicate account markers at the beginning of the "full" metadata region. */
4343
ulong metadata_region_offset;
44+
/* FIXME: We can get rid of this field once DM is activated. This is
45+
only a hack to make the non-DM code path happy. When DM is
46+
activated, we could query the input_mem_region array for the
47+
original data len. */
48+
ulong original_data_len;
4449
};
4550
typedef struct fd_vm_acc_region_meta fd_vm_acc_region_meta_t;
4651

src/flamenco/vm/syscall/fd_vm_syscall_cpi_common.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ VM_SYSCALL_CPI_TRANSLATE_AND_UPDATE_ACCOUNTS_FUNC(
480480
caller_account->serialized_data_len = data_haddr_len;
481481
}
482482

483-
caller_account->orig_data_len = acc_region_meta->has_data_region ? vm->input_mem_regions[ acc_region_meta->region_idx ].region_sz : 0U;
483+
caller_account->orig_data_len = acc_region_meta->original_data_len;
484484

485485
////// END from_account_info
486486

@@ -557,7 +557,8 @@ VM_SYSCALL_CPI_UPDATE_CALLER_ACC_FUNC( fd_vm_t * vm,
557557

558558
ulong const updated_data_len = callee_acc->vt->get_data_len( callee_acc );
559559
if( !updated_data_len ) fd_memset( (void*)caller_acc_data, 0, caller_acc_data_len );
560-
if( caller_acc_data_len != updated_data_len ) {
560+
ulong * ref_to_len = caller_account->ref_to_len_in_vm.translated;
561+
if( *ref_to_len != updated_data_len ) {
561562
ulong max_increase = (vm->direct_mapping && vm->is_deprecated) ? 0UL : MAX_PERMITTED_DATA_INCREASE;
562563
// https://github.com/anza-xyz/agave/blob/7f3a6cf6d3c2dcc81bb38e49a5c9ef998a6f4dd9/programs/bpf_loader/src/syscalls/cpi.rs#L1387-L1397
563564
if( FD_UNLIKELY( updated_data_len>fd_ulong_sat_add( caller_account->orig_data_len, max_increase ) ) ) {
@@ -573,7 +574,6 @@ VM_SYSCALL_CPI_UPDATE_CALLER_ACC_FUNC( fd_vm_t * vm,
573574
*/
574575
caller_acc_data = FD_VM_MEM_SLICE_HADDR_ST( vm, caller_acc_data_vm_addr, alignof(uchar), updated_data_len );
575576

576-
ulong * ref_to_len = caller_account->ref_to_len_in_vm.translated;
577577
*ref_to_len = updated_data_len;
578578

579579
/* Update the serialized len field

0 commit comments

Comments
 (0)