Skip to content

Commit

Permalink
runtime_ci: introduce runtime ledger tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jumpsiegel authored and riptl committed Apr 23, 2024
1 parent 5e3c376 commit 3574d5a
Show file tree
Hide file tree
Showing 23 changed files with 464 additions and 58 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/test_ledgers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Ledgers
on:
workflow_call:
workflow_dispatch:
pull_request:
jobs:
Ledgers:
runs-on: private
env:
CC: gcc
strategy:
matrix:
test_case:
- run-runtime-test-1
- run-runtime-test-2
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: ./.github/actions/deps
- uses: ./.github/actions/hugepages

- name: build
run: |
./contrib/make-j all
- name: make ${{ matrix.test_case }}
run: |
sudo prlimit --pid $$ --memlock=-1:-1
make ${{ matrix.test_case }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*ATTIC*
/build
bin
dump
unit-test
tmp

Expand Down
5 changes: 4 additions & 1 deletion src/flamenco/capture/fd_solcap_import.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,21 @@ void write_slots( const char * in_path,
fd_solcap_writer_set_slot( writer, preimg->slot );

cJSON * json_acc = cJSON_GetObjectItem( json, "accounts" );
cJSON * acc = cJSON_GetArrayItem( json_acc, 0 );
int n = cJSON_GetArraySize( json_acc );

for( int i=0; i<n; i++ ) {
fd_scratch_push();

cJSON * acc = cJSON_GetArrayItem( json_acc, i );
fd_solcap_account_tbl_t rec[1]; memset( rec, 0, sizeof(fd_solcap_account_tbl_t) );
fd_solcap_AccountMeta meta[1]; memset( meta, 0, sizeof(fd_solcap_AccountMeta ) );
void * data = unmarshal_account( acc, rec, meta );

FD_TEST( 0==fd_solcap_write_account2( writer, rec, meta, data, meta->data_sz ) );

fd_scratch_pop();

acc = acc->next;
}

FD_TEST( 0==fd_solcap_write_bank_preimage2( writer, preimg ) );
Expand Down
1 change: 1 addition & 0 deletions src/flamenco/capture/fd_solcap_writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ fd_solcap_flush_account_table( fd_solcap_writer_t * writer ) {

/* Skip if table was overflowed. */

/* FIXME: This breaks account recording for epoch boundaries and needs to be fixed */
if( writer->account_idx >= FD_SOLCAP_ACC_TBL_CNT ) {
writer->account_idx = 0UL;
return 0;
Expand Down
10 changes: 5 additions & 5 deletions src/flamenco/nanopb/pb_decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#ifndef PB_DECODE_H_INCLUDED
#define PB_DECODE_H_INCLUDED

#include "pb.h"
#include "pb_firedancer.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -15,7 +15,7 @@ extern "C" {
/* Structure for defining custom input streams. You will need to provide
* a callback function to read the bytes from your storage, which can be
* for example a file or a network socket.
*
*
* The callback must conform to these rules:
*
* 1) Return false on IO errors. This will cause decoding to abort.
Expand All @@ -39,7 +39,7 @@ struct pb_istream_s

void *state; /* Free field for use by callback implementation */
size_t bytes_left;

#ifndef PB_NO_ERRMSG
const char *errmsg;
#endif
Expand All @@ -54,7 +54,7 @@ struct pb_istream_s
/***************************
* Main decoding functions *
***************************/

/* Decode a single protocol buffers message from input stream into a C structure.
* Returns true on success, false on any failure.
* The actual struct pointed to by dest must match the description in fields.
Expand All @@ -65,7 +65,7 @@ struct pb_istream_s
* MyMessage msg = {};
* uint8_t buffer[64];
* pb_istream_t stream;
*
*
* // ... read some data into buffer ...
*
* stream = pb_istream_from_buffer(buffer, count);
Expand Down
1 change: 1 addition & 0 deletions src/flamenco/nanopb/pb_firedancer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
#define PB_ENABLE_MALLOC 1

#include "pb.h"
#include "../../util/fd_util.h"

#endif /* HEADER_fd_src_flamenco_nanopb_pb_firedancer_h */
22 changes: 11 additions & 11 deletions src/flamenco/rewards/fd_rewards.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ calculate_reward_points_partitioned(
) {
fd_pubkey_t const * voter_acc = &n->elem.delegation.voter_pubkey;
fd_pubkey_t const * stake_acc = &n->elem.account;
// FD_LOG_WARNING(("STAKE ACC1: %32J, %32J", stake_acc->key, voter_acc->key));
// FD_LOG_WARNING(("STAKE ACC1: %32J, %32J", stake_acc->key, voter_acc->key));
calculate_reward_points_account( slot_ctx, stake_history, voter_acc, stake_acc, &points, &actual_len );
}
// FD_LOG_HEXDUMP_WARNING(( "POINTS 1", &points, 16 ));
Expand Down Expand Up @@ -510,37 +510,37 @@ calculate_stake_vote_rewards_account(
FD_BORROWED_ACCOUNT_DECL(stake_acc_rec);
int err = fd_acc_mgr_view(slot_ctx->acc_mgr, slot_ctx->funk_txn, stake_acc, stake_acc_rec);
if (FD_UNLIKELY(err != FD_ACC_MGR_SUCCESS)) {
FD_LOG_DEBUG(("stake_state::stake_state_redeem_rewards() %32J not found", stake_acc->key ));
return;
FD_LOG_DEBUG(("stake_state::stake_state_redeem_rewards() %32J not found", stake_acc ));
return;
}

if (stake_acc_rec->const_meta->info.lamports == 0) return;

fd_stake_state_v2_t stake_state = {0};
int rc = fd_stake_get_state(stake_acc_rec, &slot_ctx->valloc, &stake_state);
if ( rc != 0 ) {
// FD_LOG_ERR(("failed to read"));
return;
// FD_LOG_ERR(("failed to read"));
return;
}

if (FD_FEATURE_ACTIVE(slot_ctx, stake_minimum_delegation_for_rewards)) {
if (stake_state.inner.stake.stake.delegation.stake < min_stake_delegation) {
return;
}
if (stake_state.inner.stake.stake.delegation.stake < min_stake_delegation) {
return;
}
}

fd_vote_accounts_pair_t_mapnode_t key;
fd_memcpy(&key.elem.key, voter_acc, sizeof(fd_pubkey_t));

if (fd_vote_accounts_pair_t_map_find(epoch_bank->stakes.vote_accounts.vote_accounts_pool, epoch_bank->stakes.vote_accounts.vote_accounts_root, &key) == NULL
&& fd_vote_accounts_pair_t_map_find(slot_ctx->slot_bank.vote_account_keys.vote_accounts_pool, slot_ctx->slot_bank.vote_account_keys.vote_accounts_root, &key) == NULL) {
return;
return;
}

FD_BORROWED_ACCOUNT_DECL(voter_acc_rec);
int read_err = fd_acc_mgr_view( slot_ctx->acc_mgr, slot_ctx->funk_txn, voter_acc, voter_acc_rec );
if( read_err!=0 || 0!=memcmp( &voter_acc_rec->const_meta->info.owner, fd_solana_vote_program_id.key, sizeof(fd_pubkey_t) ) ) {
return;
return;
}

/* Read vote account */
Expand All @@ -553,7 +553,7 @@ calculate_stake_vote_rewards_account(
fd_bincode_destroy_ctx_t destroy = {.valloc = slot_ctx->valloc};
fd_vote_state_versioned_t vote_state_versioned[1] = {0};
if( fd_vote_state_versioned_decode( vote_state_versioned, &decode ) != 0 ) {
return;
return;
}

uchar commission = 0U;
Expand Down
2 changes: 1 addition & 1 deletion src/flamenco/rewards/fd_rewards_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fd_vote_reward_t_map_alloc( fd_valloc_t valloc, int lg_slot_cnt ) {

#define DEQUE_NAME deq_fd_stake_reward_t
#define DEQUE_T fd_stake_reward_t
#define DEQUE_MAX 1000000UL
#define DEQUE_MAX 2000000UL
#include "../../util/tmpl/fd_deque.c"
static inline fd_stake_reward_t *
deq_fd_stake_reward_t_alloc( fd_valloc_t valloc ) {
Expand Down
3 changes: 2 additions & 1 deletion src/flamenco/runtime/fd_bank_hash_cmp.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "fd_bank_hash_cmp.h"
#include <unistd.h>

#pragma GCC diagnostic ignored "-Wformat"
#pragma GCC diagnostic ignored "-Wformat-extra-args"
Expand Down Expand Up @@ -151,7 +152,7 @@ fd_bank_hash_cmp_check( fd_bank_hash_cmp_t * bank_hash_cmp, ulong slot ) {
cmp->theirs.hash ) );
if( ++bank_hash_cmp->mismatch_cnt >= 5U ) {
FD_LOG_WARNING( ( "Too many mismatches, shutting down!" ) );
//fd_tile_shutdown_flag = 2;
_exit(-2);
}
} else {
FD_LOG_NOTICE( ( "Bank hash match on rooted slot: %lu. hash: %32J",
Expand Down
32 changes: 17 additions & 15 deletions src/flamenco/runtime/fd_executor.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,8 @@ fd_execute_instr( fd_exec_txn_ctx_t * txn_ctx,
exec_result = FD_EXECUTOR_INSTR_ERR_INCORRECT_PROGRAM_ID;
}

// FD_LOG_NOTICE(("COMPUTE METER END %lu %lu %lu %64J", before_instr_cus - txn_ctx->compute_meter, txn_ctx->compute_meter, txn_ctx->compute_unit_limit, sig ));

if( exec_result == FD_EXECUTOR_INSTR_SUCCESS ) {
ulong ending_lamports = fd_instr_info_sum_account_lamports( instr );
// FD_LOG_WARNING(("check lamports %lu %lu %lu", starting_lamports, instr->starting_lamports, ending_lamports ));
Expand All @@ -684,6 +686,16 @@ fd_execute_instr( fd_exec_txn_ctx_t * txn_ctx,
ctx->instr_err = (uint)( -exec_result - 1 );
}

#ifdef VLOG
if ( 257035230 == ctx->slot_ctx->slot_bank.slot ) {
if ( FD_UNLIKELY( exec_result != FD_EXECUTOR_INSTR_SUCCESS ) ) {
FD_LOG_WARNING(( "instruction executed unsuccessfully: error code %d, custom err: %d, program id: %32J", exec_result, txn_ctx->custom_err, program_id_acc ));
} else {
FD_LOG_WARNING(( "instruction executed successfully: error code %d, custom err: %d, program id: %32J", exec_result, txn_ctx->custom_err, program_id_acc ));
}
}
#endif

txn_ctx->instr_stack_sz--;

/* TODO: sanity before/after checks: total lamports unchanged etc */
Expand Down Expand Up @@ -787,17 +799,6 @@ fd_execute_txn_prepare_phase1( fd_exec_slot_ctx_t * slot_ctx,

fd_executor_setup_accessed_accounts_for_txn( txn_ctx );
int compute_budget_status = fd_executor_compute_budget_program_execute_instructions( txn_ctx, txn_ctx->_txn_raw );
err = fd_executor_check_txn_accounts( txn_ctx );
if ( err != FD_RUNTIME_EXECUTE_SUCCESS ) {
return err;
}

#ifdef VLOG
fd_txn_t const *txn = txn_ctx->txn_descriptor;
fd_rawtxn_b_t const *raw_txn = txn_ctx->_txn_raw;
uchar * sig = (uchar *)raw_txn->raw + txn->signature_off;
FD_LOG_WARNING(("Preparing Transaction %64J", sig));
#endif

if ((NULL != txn_descriptor) && is_nonce) {
uchar found_fee_payer = 0;
Expand Down Expand Up @@ -1013,10 +1014,11 @@ fd_execute_txn( fd_exec_txn_ctx_t * txn_ctx ) {


for ( ushort i = 0; i < txn_ctx->txn_descriptor->instr_cnt; i++ ) {
#ifdef VLOG
if ( FD_UNLIKELY( 250555489 == txn_ctx->slot_ctx->slot_bank.slot ) )
#ifdef VLOG
if ( FD_UNLIKELY( 257037453 == txn_ctx->slot_ctx->slot_bank.slot ) )
FD_LOG_WARNING(("Start of transaction for %d for %64J", i, sig));
#endif
#endif

if ( FD_UNLIKELY( use_sysvar_instructions ) ) {
ret = fd_sysvar_instructions_update_current_instr_idx( txn_ctx, i );
if( ret != FD_ACC_MGR_SUCCESS ) {
Expand All @@ -1033,7 +1035,7 @@ fd_execute_txn( fd_exec_txn_ctx_t * txn_ctx ) {
int exec_result = fd_execute_instr( txn_ctx, &instrs[i] );
if( exec_result != FD_EXECUTOR_INSTR_SUCCESS ) {
#ifdef VLOG
if ( 250555489 == txn_ctx->slot_ctx->slot_bank.slot ) {
if ( 257037453 == txn_ctx->slot_ctx->slot_bank.slot ) {
#endif
if (exec_result == FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR ) {
#ifdef VLOG
Expand Down
3 changes: 3 additions & 0 deletions src/flamenco/runtime/fd_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ fd_executor_collect_fee( fd_exec_slot_ctx_t * slot_ctx,
FD_FN_CONST char const *
fd_executor_instr_strerror( int err );

int
fd_executor_check_txn_accounts( fd_exec_txn_ctx_t * txn_ctx );

FD_PROTOTYPES_END

#endif /* HEADER_fd_src_flamenco_runtime_fd_executor_h */
3 changes: 1 addition & 2 deletions src/flamenco/runtime/fd_hashes.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ fd_hash_account_deltas( fd_pubkey_hash_pair_t * pairs, ulong pairs_len, fd_hash_
for( ulong i = 0; i < pairs_len; ++i ) {
#ifdef VLOG
{
// if ( slot_ctx->slot_bank.slot == 240182076 ) {
//if ( slot_ctx->slot_bank.slot == 257040000 )
FD_LOG_NOTICE(( "account delta hash X { \"key\":%ld, \"pubkey\":\"%32J\", \"hash\":\"%32J\" },", i, pairs[i].pubkey->key, pairs[i].hash->hash));

/*
pubkey
slot
Expand Down
Loading

0 comments on commit 3574d5a

Please sign in to comment.