diff --git a/src/flamenco/runtime/sysvar/fd_sysvar_slot_history.c b/src/flamenco/runtime/sysvar/fd_sysvar_slot_history.c index c9ec548844..b73233ef6c 100644 --- a/src/flamenco/runtime/sysvar/fd_sysvar_slot_history.c +++ b/src/flamenco/runtime/sysvar/fd_sysvar_slot_history.c @@ -14,18 +14,19 @@ static const ulong slot_history_max_entries = 1024 * 1024; /* TODO: move into seperate bitvec library */ static const ulong bits_per_block = 8 * sizeof(ulong); -void fd_sysvar_slot_history_set( fd_slot_history_t* history, ulong i ) { - // Corrupt history, zero everything out - if ( i > history->next_slot && i - history->next_slot >= slot_history_max_entries ) { - for ( ulong j = 0; j < history->bits.bits->blocks_len; j++) { - history->bits.bits->blocks[ j ] = 0; - } - } else { - // Skipped slots, delete them from history - for (ulong j = history->next_slot; j < i; j++) { - ulong block_idx = (j / bits_per_block) % (history->bits.bits->blocks_len); - history->bits.bits->blocks[ block_idx ] &= ~( 1UL << ( j % bits_per_block ) ); - } + +void +fd_sysvar_slot_history_set( fd_slot_history_t * history, + ulong i ) { + if( FD_UNLIKELY( i > history->next_slot && i - history->next_slot >= slot_history_max_entries ) ) { + FD_LOG_WARNING(( "Ignoring out of bounds (i=%lu next_slot=%lu)", i, history->next_slot )); + return; + } + + // Skipped slots, delete them from history + for( ulong j = history->next_slot; j < i; j++ ) { + ulong block_idx = (j / bits_per_block) % (history->bits.bits->blocks_len); + history->bits.bits->blocks[ block_idx ] &= ~( 1UL << ( j % bits_per_block ) ); } ulong block_idx = (i / bits_per_block) % (history->bits.bits->blocks_len); history->bits.bits->blocks[ block_idx ] |= ( 1UL << ( i % bits_per_block ) ); @@ -50,10 +51,11 @@ int fd_sysvar_slot_history_write_history( fd_exec_slot_ctx_t * slot_ctx, } /* https://github.com/solana-labs/solana/blob/8f2c8b8388a495d2728909e30460aa40dcc5d733/sdk/program/src/slot_history.rs#L16 */ -void fd_sysvar_slot_history_init( fd_exec_slot_ctx_t * slot_ctx ) { +void +fd_sysvar_slot_history_init( fd_exec_slot_ctx_t * slot_ctx ) { /* Create a new slot history instance */ - fd_slot_history_t history; - fd_slot_history_inner_t *inner = fd_valloc_malloc( slot_ctx->valloc, 8UL, sizeof(fd_slot_history_inner_t) ); + fd_slot_history_t history = {0}; + fd_slot_history_inner_t * inner = fd_valloc_malloc( slot_ctx->valloc, 8UL, sizeof(fd_slot_history_inner_t) ); inner->blocks = fd_valloc_malloc( slot_ctx->valloc, 8UL, sizeof(ulong) * blocks_len ); memset( inner->blocks, 0, sizeof(ulong) * blocks_len ); inner->blocks_len = blocks_len;