diff --git a/src/flamenco/rewards/fd_rewards.c b/src/flamenco/rewards/fd_rewards.c index 87130421d1..12ed1c02c1 100644 --- a/src/flamenco/rewards/fd_rewards.c +++ b/src/flamenco/rewards/fd_rewards.c @@ -509,7 +509,7 @@ calculate_stake_vote_rewards_account_tpool( void *tpool, /* Add the stake reward to list of all stake rewards. The update is thread-safe because each index in the dlist is only ever accessed / written to once among all threads. */ - fd_stake_reward_t * stake_reward = fd_stake_reward_pool_ele( result->stake_reward_calculation.pool, i ); + fd_stake_reward_t * stake_reward = fd_stake_reward_calculation_pool_ele( result->stake_reward_calculation.pool, i ); if( FD_UNLIKELY( stake_reward==NULL ) ) { FD_LOG_WARNING(( "could not find stake reward node in pool" )); continue; @@ -578,12 +578,17 @@ calculate_stake_vote_rewards( fd_exec_slot_ctx_t * slot_ct ulong rewards_max_count = temp_info->stake_infos_len; /* Create the stake rewards pool and dlist. The pool will be destoyed after the stake rewards have been distributed. */ - result->stake_reward_calculation.pool = fd_stake_reward_pool_join( fd_stake_reward_pool_new( fd_spad_alloc( runtime_spad, - fd_stake_reward_pool_align(), - fd_stake_reward_pool_footprint( rewards_max_count ) ), - rewards_max_count ) ); - fd_stake_reward_dlist_new( &result->stake_reward_calculation.stake_rewards ); - result->stake_reward_calculation.stake_rewards_len = 0UL; + result->stake_reward_calculation.pool = fd_stake_reward_calculation_pool_join( fd_stake_reward_calculation_pool_new( fd_spad_alloc( runtime_spad, + fd_stake_reward_calculation_pool_align(), + fd_stake_reward_calculation_pool_footprint( rewards_max_count ) ), + rewards_max_count ) ); + result->stake_reward_calculation.stake_rewards = fd_spad_alloc( runtime_spad, + fd_stake_reward_calculation_dlist_align(), + fd_stake_reward_calculation_dlist_footprint() ); + + fd_stake_reward_calculation_dlist_new( result->stake_reward_calculation.stake_rewards ); + result->stake_reward_calculation.stake_rewards_len = 1UL; + result->stake_reward_calculation.stake_rewards_lengths[0] = 0; /* Create the vote rewards map. This will be destroyed after the vote rewards have been distributed. */ ulong vote_account_cnt = fd_vote_info_pair_t_map_size( temp_info->vote_states_pool, temp_info->vote_states_root ); @@ -610,13 +615,13 @@ calculate_stake_vote_rewards( fd_exec_slot_ctx_t * slot_ct /* Pre-allocate the dlist stake reward elements */ for( ulong i=0UL; istake_infos_len; i++ ) { - fd_stake_reward_t * stake_reward = fd_stake_reward_pool_ele_acquire( result->stake_reward_calculation.pool ); + fd_stake_reward_t * stake_reward = fd_stake_reward_calculation_pool_ele_acquire( result->stake_reward_calculation.pool ); if( FD_UNLIKELY( stake_reward==NULL ) ) { FD_LOG_ERR(( "insufficient space allocated for stake reward calculation pool" )); return; } stake_reward->valid = 0; - fd_stake_reward_dlist_ele_push_tail( &result->stake_reward_calculation.stake_rewards, stake_reward, result->stake_reward_calculation.pool ); + fd_stake_reward_calculation_dlist_ele_push_tail( result->stake_reward_calculation.stake_rewards, stake_reward, result->stake_reward_calculation.pool ); } fd_calculate_stake_vote_rewards_task_args_t task_args = { @@ -711,25 +716,25 @@ hash_rewards_into_partitions( fd_exec_slot_ctx_t * slot_c slot_ctx->slot_bank.slot, stake_reward_calculation->stake_rewards_len ); result->partitioned_stake_rewards.partitions_len = num_partitions; - result->partitioned_stake_rewards.partitions = fd_spad_alloc( runtime_spad, - fd_stake_reward_dlist_align(), - fd_stake_reward_dlist_footprint() * num_partitions ); + result->partitioned_stake_rewards.partitions = fd_spad_alloc( runtime_spad, + fd_partitioned_stake_rewards_dlist_align(), + fd_partitioned_stake_rewards_dlist_footprint() * num_partitions ); /* Ownership of these dlist's and the pool gets transferred to stake_rewards_by_partition, which then gets transferred to epoch_reward_status. These are eventually cleaned up when epoch_reward_status_inactive is called. */ for( ulong i = 0; i < num_partitions; ++i ) { - fd_stake_reward_dlist_new( &result->partitioned_stake_rewards.partitions[ i ] ); + fd_partitioned_stake_rewards_dlist_new( &result->partitioned_stake_rewards.partitions[ i ] ); } /* Iterate over all the stake rewards, moving references to them into the appropiate partitions. IMPORTANT: after this, we cannot use the original stake rewards dlist anymore. */ - fd_stake_reward_dlist_iter_t next_iter; - for( fd_stake_reward_dlist_iter_t iter = fd_stake_reward_dlist_iter_fwd_init( &stake_reward_calculation->stake_rewards, stake_reward_calculation->pool ); - !fd_stake_reward_dlist_iter_done( iter, &stake_reward_calculation->stake_rewards, stake_reward_calculation->pool ); + fd_stake_reward_calculation_dlist_iter_t next_iter; + for( fd_stake_reward_calculation_dlist_iter_t iter = fd_stake_reward_calculation_dlist_iter_fwd_init( stake_reward_calculation->stake_rewards, stake_reward_calculation->pool ); + !fd_stake_reward_calculation_dlist_iter_done( iter, stake_reward_calculation->stake_rewards, stake_reward_calculation->pool ); iter = next_iter ) { - fd_stake_reward_t * stake_reward = fd_stake_reward_dlist_iter_ele( iter, &stake_reward_calculation->stake_rewards, stake_reward_calculation->pool ); + fd_stake_reward_t * stake_reward = fd_stake_reward_calculation_dlist_iter_ele( iter, stake_reward_calculation->stake_rewards, stake_reward_calculation->pool ); /* Cache the next iter here, as we will overwrite the DLIST_NEXT value further down in the loop iteration. */ - next_iter = fd_stake_reward_dlist_iter_fwd_next( iter, &stake_reward_calculation->stake_rewards, stake_reward_calculation->pool ); + next_iter = fd_stake_reward_calculation_dlist_iter_fwd_next( iter, stake_reward_calculation->stake_rewards, stake_reward_calculation->pool ); if( FD_UNLIKELY( !stake_reward->valid ) ) { continue; @@ -750,8 +755,9 @@ hash_rewards_into_partitions( fd_exec_slot_ctx_t * slot_c ((uint128)ULONG_MAX + 1)); /* Move the stake reward to the partition's dlist */ - fd_stake_reward_dlist_t * partition = &result->partitioned_stake_rewards.partitions[ partition_index ]; - fd_stake_reward_dlist_ele_push_tail( partition, stake_reward, stake_reward_calculation->pool ); + fd_partitioned_stake_rewards_dlist_t * partition = &result->partitioned_stake_rewards.partitions[ partition_index ]; + fd_partitioned_stake_rewards_dlist_ele_push_tail( partition, stake_reward, stake_reward_calculation->pool ); + result->partitioned_stake_rewards.partitions_lengths[ partition_index ]++; } } @@ -916,11 +922,11 @@ distribute_epoch_reward_to_stake_acc( fd_exec_slot_ctx_t * slot_ctx, static void set_epoch_reward_status_inactive( fd_exec_slot_ctx_t * slot_ctx, fd_spad_t * runtime_spad ) { - if( slot_ctx->epoch_reward_status.discriminant == fd_epoch_reward_status_enum_Active ) { + if( slot_ctx->slot_bank.epoch_reward_status.discriminant == fd_epoch_reward_status_enum_Active ) { FD_LOG_NOTICE(( "Done partitioning rewards for current epoch" )); fd_spad_pop( runtime_spad ); } - slot_ctx->epoch_reward_status.discriminant = fd_epoch_reward_status_enum_Inactive; + slot_ctx->slot_bank.epoch_reward_status.discriminant = fd_epoch_reward_status_enum_Inactive; } /* Sets the epoch reward status to active. @@ -933,10 +939,10 @@ set_epoch_reward_status_active( fd_exec_slot_ctx_t * slot_ctx, fd_partitioned_stake_rewards_t * partitioned_rewards ) { FD_LOG_NOTICE(( "Setting epoch reward status as active" )); - slot_ctx->epoch_reward_status.discriminant = fd_epoch_reward_status_enum_Active; - slot_ctx->epoch_reward_status.inner.Active.distribution_starting_block_height = distribution_starting_block_height; + slot_ctx->slot_bank.epoch_reward_status.discriminant = fd_epoch_reward_status_enum_Active; + slot_ctx->slot_bank.epoch_reward_status.inner.Active.distribution_starting_block_height = distribution_starting_block_height; - fd_memcpy( &slot_ctx->epoch_reward_status.inner.Active.partitioned_stake_rewards, partitioned_rewards, FD_PARTITIONED_STAKE_REWARDS_FOOTPRINT ); + fd_memcpy( &slot_ctx->slot_bank.epoch_reward_status.inner.Active.partitioned_stake_rewards, partitioned_rewards, FD_PARTITIONED_STAKE_REWARDS_FOOTPRINT ); } /* Process reward credits for a partition of rewards. @@ -944,17 +950,17 @@ set_epoch_reward_status_active( fd_exec_slot_ctx_t * slot_ctx, https://github.com/anza-xyz/agave/blob/cbc8320d35358da14d79ebcada4dfb6756ffac79/runtime/src/bank/partitioned_epoch_rewards/distribution.rs#L88 */ static void -distribute_epoch_rewards_in_partition( fd_stake_reward_dlist_t * partition, +distribute_epoch_rewards_in_partition( fd_partitioned_stake_rewards_dlist_t * partition, fd_stake_reward_t * pool, fd_exec_slot_ctx_t * slot_ctx ) { ulong lamports_distributed = 0UL; ulong lamports_burned = 0UL; - for( fd_stake_reward_dlist_iter_t iter = fd_stake_reward_dlist_iter_fwd_init( partition, pool ); - !fd_stake_reward_dlist_iter_done( iter, partition, pool ); - iter = fd_stake_reward_dlist_iter_fwd_next( iter, partition, pool ) ) { - fd_stake_reward_t * stake_reward = fd_stake_reward_dlist_iter_ele( iter, partition, pool ); + for( fd_partitioned_stake_rewards_dlist_iter_t iter = fd_partitioned_stake_rewards_dlist_iter_fwd_init( partition, pool ); + !fd_partitioned_stake_rewards_dlist_iter_done( iter, partition, pool ); + iter = fd_partitioned_stake_rewards_dlist_iter_fwd_next( iter, partition, pool ) ) { + fd_stake_reward_t * stake_reward = fd_partitioned_stake_rewards_dlist_iter_ele( iter, partition, pool ); if( distribute_epoch_reward_to_stake_acc( slot_ctx, &stake_reward->stake_pubkey, @@ -991,11 +997,11 @@ fd_distribute_partitioned_epoch_rewards( fd_exec_slot_ctx_t * slot_ctx, (void)exec_spads; (void)exec_spad_cnt; - if( slot_ctx->epoch_reward_status.discriminant == fd_epoch_reward_status_enum_Inactive ) { + if( slot_ctx->slot_bank.epoch_reward_status.discriminant == fd_epoch_reward_status_enum_Inactive ) { return; } - fd_start_block_height_and_rewards_t * status = &slot_ctx->epoch_reward_status.inner.Active; + fd_start_block_height_and_rewards_t * status = &slot_ctx->slot_bank.epoch_reward_status.inner.Active; fd_slot_bank_t * slot_bank = &slot_ctx->slot_bank; ulong height = slot_bank->block_height; @@ -1012,6 +1018,7 @@ fd_distribute_partitioned_epoch_rewards( fd_exec_slot_ctx_t * slot_ctx, if( (height>=distribution_starting_block_height) && (height < distribution_end_exclusive) ) { ulong partition_index = height - distribution_starting_block_height; + FD_LOG_WARNING(( "Distributing rewards for partition %lu", partition_index )); distribute_epoch_rewards_in_partition( &status->partitioned_stake_rewards.partitions[ partition_index ], status->partitioned_stake_rewards.pool, slot_ctx ); diff --git a/src/flamenco/runtime/context/fd_exec_slot_ctx.c b/src/flamenco/runtime/context/fd_exec_slot_ctx.c index 20ffdf73e0..5a1e035e56 100644 --- a/src/flamenco/runtime/context/fd_exec_slot_ctx.c +++ b/src/flamenco/runtime/context/fd_exec_slot_ctx.c @@ -27,9 +27,6 @@ fd_exec_slot_ctx_new( void * mem, self->sysvar_cache = fd_sysvar_cache_new( fd_spad_alloc( runtime_spad, fd_sysvar_cache_align(), fd_sysvar_cache_footprint() ), runtime_spad ); - /* This is inactive by default */ - self->epoch_reward_status.discriminant = fd_epoch_reward_status_enum_Inactive; - FD_COMPILER_MFENCE(); self->magic = FD_EXEC_SLOT_CTX_MAGIC; FD_COMPILER_MFENCE(); diff --git a/src/flamenco/runtime/context/fd_exec_slot_ctx.h b/src/flamenco/runtime/context/fd_exec_slot_ctx.h index d50d3fd9b4..8a6d61b80c 100644 --- a/src/flamenco/runtime/context/fd_exec_slot_ctx.h +++ b/src/flamenco/runtime/context/fd_exec_slot_ctx.h @@ -31,9 +31,6 @@ struct __attribute__((aligned(8UL))) fd_exec_slot_ctx { ulong total_compute_units_requested; - /* TODO figure out what to do with this */ - fd_epoch_reward_status_t epoch_reward_status; - /* TODO remove this stuff */ ulong signature_cnt; fd_hash_t account_delta_hash; diff --git a/src/flamenco/types/fd_type_names.c b/src/flamenco/types/fd_type_names.c index 1afa364663..d292d4e7b1 100644 --- a/src/flamenco/types/fd_type_names.c +++ b/src/flamenco/types/fd_type_names.c @@ -1,5 +1,5 @@ // This is an auto-generated file. To add entries, edit fd_types.json -#define FD_TYPE_NAME_COUNT 243 +#define FD_TYPE_NAME_COUNT 256 static char const * fd_type_names[FD_TYPE_NAME_COUNT] = { "fd_hash", "fd_pubkey", @@ -107,6 +107,19 @@ static char const * fd_type_names[FD_TYPE_NAME_COUNT] = { "fd_firedancer_bank", "fd_cluster_type", "fd_epoch_bank", + "fd_stake_reward", + "fd_vote_reward", + "fd_point_value", + "fd_partitioned_stake_rewards", + "fd_stake_reward_calculation_partitioned", + "fd_stake_reward_calculation", + "fd_calculate_stake_vote_rewards_result", + "fd_calculate_validator_rewards_result", + "fd_calculate_rewards_and_distribute_vote_rewards_result", + "fd_partitioned_rewards_calculation", + "fd_start_block_height_and_rewards", + "fd_fd_epoch_reward_status_inner", + "fd_epoch_reward_status", "fd_slot_bank", "fd_prev_epoch_inflation_rewards", "fd_vote", diff --git a/src/flamenco/types/fd_types.c b/src/flamenco/types/fd_types.c index 7f8a60eaae..e9c6bd4cb0 100644 --- a/src/flamenco/types/fd_types.c +++ b/src/flamenco/types/fd_types.c @@ -11180,6 +11180,1232 @@ ulong fd_epoch_bank_size( fd_epoch_bank_t const * self ) { return size; } +int fd_stake_reward_encode( fd_stake_reward_t const * self, fd_bincode_encode_ctx_t * ctx ) { + int err; + err = fd_bincode_uint64_encode( self->prev, ctx ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_bincode_uint64_encode( self->next, ctx ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_bincode_uint64_encode( self->parent, ctx ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_pubkey_encode( &self->stake_pubkey, ctx ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_bincode_uint64_encode( self->credits_observed, ctx ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_bincode_uint64_encode( self->lamports, ctx ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_bincode_uint8_encode( (uchar)(self->valid), ctx ); + if( FD_UNLIKELY( err ) ) return err; + return FD_BINCODE_SUCCESS; +} +int fd_stake_reward_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + *total_sz += sizeof(fd_stake_reward_t); + void const * start_data = ctx->data; + int err = fd_stake_reward_decode_footprint_inner( ctx, total_sz ); + if( ctx->data>ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; + ctx->data = start_data; + return err; +} +int fd_stake_reward_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + if( ctx->data>=ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; + int err = 0; + err = fd_bincode_uint64_decode_footprint( ctx ); + if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) return err; + err = fd_bincode_uint64_decode_footprint( ctx ); + if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) return err; + err = fd_bincode_uint64_decode_footprint( ctx ); + if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) return err; + err = fd_pubkey_decode_footprint_inner( ctx, total_sz ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_bincode_uint64_decode_footprint( ctx ); + if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) return err; + err = fd_bincode_uint64_decode_footprint( ctx ); + if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) return err; + err = fd_bincode_uint8_decode_footprint( ctx ); + if( FD_UNLIKELY( err ) ) return err; + return 0; +} +void * fd_stake_reward_decode( void * mem, fd_bincode_decode_ctx_t * ctx ) { + fd_stake_reward_t * self = (fd_stake_reward_t *)mem; + fd_stake_reward_new( self ); + void * alloc_region = (uchar *)mem + sizeof(fd_stake_reward_t); + void * * alloc_mem = &alloc_region; + fd_stake_reward_decode_inner( mem, alloc_mem, ctx ); + return self; +} +void fd_stake_reward_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ) { + fd_stake_reward_t * self = (fd_stake_reward_t *)struct_mem; + fd_bincode_uint64_decode_unsafe( &self->prev, ctx ); + fd_bincode_uint64_decode_unsafe( &self->next, ctx ); + fd_bincode_uint64_decode_unsafe( &self->parent, ctx ); + fd_pubkey_decode_inner( &self->stake_pubkey, alloc_mem, ctx ); + fd_bincode_uint64_decode_unsafe( &self->credits_observed, ctx ); + fd_bincode_uint64_decode_unsafe( &self->lamports, ctx ); + fd_bincode_uint8_decode_unsafe( &self->valid, ctx ); +} +void fd_stake_reward_new(fd_stake_reward_t * self) { + fd_memset( self, 0, sizeof(fd_stake_reward_t) ); + fd_pubkey_new( &self->stake_pubkey ); +} +void fd_stake_reward_destroy( fd_stake_reward_t * self ) { + fd_pubkey_destroy( &self->stake_pubkey ); +} + +ulong fd_stake_reward_footprint( void ){ return FD_STAKE_REWARD_FOOTPRINT; } +ulong fd_stake_reward_align( void ){ return FD_STAKE_REWARD_ALIGN; } + +void fd_stake_reward_walk( void * w, fd_stake_reward_t const * self, fd_types_walk_fn_t fun, const char *name, uint level ) { + fun( w, self, name, FD_FLAMENCO_TYPE_MAP, "fd_stake_reward", level++ ); + fun( w, &self->prev, "prev", FD_FLAMENCO_TYPE_ULONG, "ulong", level ); + fun( w, &self->next, "next", FD_FLAMENCO_TYPE_ULONG, "ulong", level ); + fun( w, &self->parent, "parent", FD_FLAMENCO_TYPE_ULONG, "ulong", level ); + fd_pubkey_walk( w, &self->stake_pubkey, fun, "stake_pubkey", level ); + fun( w, &self->credits_observed, "credits_observed", FD_FLAMENCO_TYPE_ULONG, "ulong", level ); + fun( w, &self->lamports, "lamports", FD_FLAMENCO_TYPE_ULONG, "ulong", level ); + fun( w, &self->valid, "valid", FD_FLAMENCO_TYPE_UCHAR, "uchar", level ); + fun( w, self, name, FD_FLAMENCO_TYPE_MAP_END, "fd_stake_reward", level-- ); +} +ulong fd_stake_reward_size( fd_stake_reward_t const * self ) { + ulong size = 0; + size += sizeof(ulong); + size += sizeof(ulong); + size += sizeof(ulong); + size += fd_pubkey_size( &self->stake_pubkey ); + size += sizeof(ulong); + size += sizeof(ulong); + size += sizeof(char); + return size; +} + +int fd_vote_reward_encode( fd_vote_reward_t const * self, fd_bincode_encode_ctx_t * ctx ) { + int err; + err = fd_pubkey_encode( &self->pubkey, ctx ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_bincode_uint64_encode( self->vote_rewards, ctx ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_bincode_uint8_encode( (uchar)(self->commission), ctx ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_bincode_uint8_encode( (uchar)(self->needs_store), ctx ); + if( FD_UNLIKELY( err ) ) return err; + return FD_BINCODE_SUCCESS; +} +int fd_vote_reward_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + *total_sz += sizeof(fd_vote_reward_t); + void const * start_data = ctx->data; + int err = fd_vote_reward_decode_footprint_inner( ctx, total_sz ); + if( ctx->data>ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; + ctx->data = start_data; + return err; +} +int fd_vote_reward_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + if( ctx->data>=ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; + int err = 0; + err = fd_pubkey_decode_footprint_inner( ctx, total_sz ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_bincode_uint64_decode_footprint( ctx ); + if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) return err; + err = fd_bincode_uint8_decode_footprint( ctx ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_bincode_uint8_decode_footprint( ctx ); + if( FD_UNLIKELY( err ) ) return err; + return 0; +} +void * fd_vote_reward_decode( void * mem, fd_bincode_decode_ctx_t * ctx ) { + fd_vote_reward_t * self = (fd_vote_reward_t *)mem; + fd_vote_reward_new( self ); + void * alloc_region = (uchar *)mem + sizeof(fd_vote_reward_t); + void * * alloc_mem = &alloc_region; + fd_vote_reward_decode_inner( mem, alloc_mem, ctx ); + return self; +} +void fd_vote_reward_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ) { + fd_vote_reward_t * self = (fd_vote_reward_t *)struct_mem; + fd_pubkey_decode_inner( &self->pubkey, alloc_mem, ctx ); + fd_bincode_uint64_decode_unsafe( &self->vote_rewards, ctx ); + fd_bincode_uint8_decode_unsafe( &self->commission, ctx ); + fd_bincode_uint8_decode_unsafe( &self->needs_store, ctx ); +} +void fd_vote_reward_new(fd_vote_reward_t * self) { + fd_memset( self, 0, sizeof(fd_vote_reward_t) ); + fd_pubkey_new( &self->pubkey ); +} +void fd_vote_reward_destroy( fd_vote_reward_t * self ) { + fd_pubkey_destroy( &self->pubkey ); +} + +ulong fd_vote_reward_footprint( void ){ return FD_VOTE_REWARD_FOOTPRINT; } +ulong fd_vote_reward_align( void ){ return FD_VOTE_REWARD_ALIGN; } + +void fd_vote_reward_walk( void * w, fd_vote_reward_t const * self, fd_types_walk_fn_t fun, const char *name, uint level ) { + fun( w, self, name, FD_FLAMENCO_TYPE_MAP, "fd_vote_reward", level++ ); + fd_pubkey_walk( w, &self->pubkey, fun, "pubkey", level ); + fun( w, &self->vote_rewards, "vote_rewards", FD_FLAMENCO_TYPE_ULONG, "ulong", level ); + fun( w, &self->commission, "commission", FD_FLAMENCO_TYPE_UCHAR, "uchar", level ); + fun( w, &self->needs_store, "needs_store", FD_FLAMENCO_TYPE_UCHAR, "uchar", level ); + fun( w, self, name, FD_FLAMENCO_TYPE_MAP_END, "fd_vote_reward", level-- ); +} +ulong fd_vote_reward_size( fd_vote_reward_t const * self ) { + ulong size = 0; + size += fd_pubkey_size( &self->pubkey ); + size += sizeof(ulong); + size += sizeof(char); + size += sizeof(char); + return size; +} + +int fd_point_value_encode( fd_point_value_t const * self, fd_bincode_encode_ctx_t * ctx ) { + int err; + err = fd_bincode_uint64_encode( self->rewards, ctx ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_bincode_uint128_encode( self->points, ctx ); + if( FD_UNLIKELY( err ) ) return err; + return FD_BINCODE_SUCCESS; +} +int fd_point_value_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + *total_sz += sizeof(fd_point_value_t); + void const * start_data = ctx->data; + int err = fd_point_value_decode_footprint_inner( ctx, total_sz ); + if( ctx->data>ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; + ctx->data = start_data; + return err; +} +int fd_point_value_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + if( ctx->data>=ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; + int err = 0; + err = fd_bincode_uint64_decode_footprint( ctx ); + if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) return err; + err = fd_bincode_uint128_decode_footprint( ctx ); + if( FD_UNLIKELY( err ) ) return err; + return 0; +} +void * fd_point_value_decode( void * mem, fd_bincode_decode_ctx_t * ctx ) { + fd_point_value_t * self = (fd_point_value_t *)mem; + fd_point_value_new( self ); + void * alloc_region = (uchar *)mem + sizeof(fd_point_value_t); + void * * alloc_mem = &alloc_region; + fd_point_value_decode_inner( mem, alloc_mem, ctx ); + return self; +} +void fd_point_value_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ) { + fd_point_value_t * self = (fd_point_value_t *)struct_mem; + fd_bincode_uint64_decode_unsafe( &self->rewards, ctx ); + fd_bincode_uint128_decode_unsafe( &self->points, ctx ); +} +void fd_point_value_new(fd_point_value_t * self) { + fd_memset( self, 0, sizeof(fd_point_value_t) ); +} +void fd_point_value_destroy( fd_point_value_t * self ) { +} + +ulong fd_point_value_footprint( void ){ return FD_POINT_VALUE_FOOTPRINT; } +ulong fd_point_value_align( void ){ return FD_POINT_VALUE_ALIGN; } + +void fd_point_value_walk( void * w, fd_point_value_t const * self, fd_types_walk_fn_t fun, const char *name, uint level ) { + fun( w, self, name, FD_FLAMENCO_TYPE_MAP, "fd_point_value", level++ ); + fun( w, &self->rewards, "rewards", FD_FLAMENCO_TYPE_ULONG, "ulong", level ); + fun( w, &self->points, "points", FD_FLAMENCO_TYPE_UINT128, "uint128", level ); + fun( w, self, name, FD_FLAMENCO_TYPE_MAP_END, "fd_point_value", level-- ); +} +ulong fd_point_value_size( fd_point_value_t const * self ) { + ulong size = 0; + size += sizeof(ulong); + size += sizeof(uint128); + return size; +} + +int fd_partitioned_stake_rewards_encode( fd_partitioned_stake_rewards_t const * self, fd_bincode_encode_ctx_t * ctx ) { + int err; + if( self->partitions ) { + err = fd_bincode_uint64_encode( self->partitions_len, ctx ); + if( FD_UNLIKELY( err ) ) return err; + for( ulong i=0; i < 4096; i++ ) { + err = fd_bincode_uint64_encode( self->partitions_lengths[ i ], ctx ); + if( FD_UNLIKELY( err ) ) return err; + } + for( ulong i=0; i < self->partitions_len; i++ ) { + for( fd_partitioned_stake_rewards_dlist_iter_t iter = fd_partitioned_stake_rewards_dlist_iter_fwd_init( &self->partitions[ i ], self->pool ); + !fd_partitioned_stake_rewards_dlist_iter_done( iter, &self->partitions[ i ], self->pool ); + iter = fd_partitioned_stake_rewards_dlist_iter_fwd_next( iter, &self->partitions[ i ], self->pool ) ) { + fd_stake_reward_t * ele = fd_partitioned_stake_rewards_dlist_iter_ele( iter, &self->partitions[ i ], self->pool ); + err = fd_stake_reward_encode( ele, ctx ); + if( FD_UNLIKELY( err ) ) return err; + } + } + } else { + err = fd_bincode_uint64_encode( self->partitions_len, ctx ); + if( FD_UNLIKELY( err ) ) return err; + } + return FD_BINCODE_SUCCESS; +} +int fd_partitioned_stake_rewards_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + *total_sz += sizeof(fd_partitioned_stake_rewards_t); + void const * start_data = ctx->data; + int err = fd_partitioned_stake_rewards_decode_footprint_inner( ctx, total_sz ); + if( ctx->data>ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; + ctx->data = start_data; + return err; +} +int fd_partitioned_stake_rewards_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + if( ctx->data>=ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; + int err = 0; + ulong partitions_len; + err = fd_bincode_uint64_decode( &partitions_len, ctx ); + if( FD_UNLIKELY( err ) ) return err; + ulong total_count = 0UL; + ulong partitions_lengths[4096]; + for( ulong i=0; i<4096; i++ ) { + err = fd_bincode_uint64_decode( partitions_lengths + i, ctx ); + total_count+=partitions_lengths[ i ]; + if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) return err; + } + *total_sz += fd_partitioned_stake_rewards_pool_align() + fd_partitioned_stake_rewards_pool_footprint( total_count ); + *total_sz += fd_partitioned_stake_rewards_dlist_align() + fd_partitioned_stake_rewards_dlist_footprint()*partitions_len; + for( ulong i=0; i < partitions_len; i++ ) { + err = fd_stake_reward_decode_footprint_inner( ctx, total_sz ); + if( FD_UNLIKELY ( err ) ) return err; + } + return 0; +} +void * fd_partitioned_stake_rewards_decode( void * mem, fd_bincode_decode_ctx_t * ctx ) { + fd_partitioned_stake_rewards_t * self = (fd_partitioned_stake_rewards_t *)mem; + fd_partitioned_stake_rewards_new( self ); + void * alloc_region = (uchar *)mem + sizeof(fd_partitioned_stake_rewards_t); + void * * alloc_mem = &alloc_region; + fd_partitioned_stake_rewards_decode_inner( mem, alloc_mem, ctx ); + return self; +} +void fd_partitioned_stake_rewards_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ) { + fd_partitioned_stake_rewards_t * self = (fd_partitioned_stake_rewards_t *)struct_mem; + fd_bincode_uint64_decode_unsafe( &self->partitions_len, ctx ); + ulong total_count = 0UL; + for( ulong i=0; i < 4096; i++ ) { + fd_bincode_uint64_decode_unsafe( self->partitions_lengths + i, ctx ); + total_count += self->partitions_lengths[ i ]; + } + self->pool = fd_partitioned_stake_rewards_pool_join_new( alloc_mem, total_count ); + self->partitions = fd_partitioned_stake_rewards_dlist_join_new( alloc_mem, self->partitions_len ); + for( ulong i=0; i < self->partitions_len; i++ ) { + fd_partitioned_stake_rewards_dlist_new( &self->partitions[ i ] ); + for( ulong j=0; j < self->partitions_lengths[ i ]; j++ ) { + fd_stake_reward_t * ele = fd_partitioned_stake_rewards_pool_ele_acquire( self->pool ); + fd_stake_reward_new( ele ); + fd_stake_reward_decode_inner( ele, alloc_mem, ctx ); + fd_partitioned_stake_rewards_dlist_ele_push_tail( &self->partitions[ i ], ele, self->pool ); + } + } +} +void fd_partitioned_stake_rewards_new(fd_partitioned_stake_rewards_t * self) { + fd_memset( self, 0, sizeof(fd_partitioned_stake_rewards_t) ); +} +void fd_partitioned_stake_rewards_destroy( fd_partitioned_stake_rewards_t * self ) { + if( !self->partitions || !self->pool ) return; + for( ulong i=0; i < self->partitions_len; i++ ) { + for( fd_partitioned_stake_rewards_dlist_iter_t iter = fd_partitioned_stake_rewards_dlist_iter_fwd_init( &self->partitions[ i ], self->pool ); + !fd_partitioned_stake_rewards_dlist_iter_done( iter, &self->partitions[ i ], self->pool ); + iter = fd_partitioned_stake_rewards_dlist_iter_fwd_next( iter, &self->partitions[ i ], self->pool ) ) { + fd_stake_reward_t * ele = fd_partitioned_stake_rewards_dlist_iter_ele( iter, &self->partitions[ i ], self->pool ); + fd_stake_reward_destroy( ele ); + } + } + self->partitions = NULL; + self->pool = NULL; +} + +ulong fd_partitioned_stake_rewards_footprint( void ){ return FD_PARTITIONED_STAKE_REWARDS_FOOTPRINT; } +ulong fd_partitioned_stake_rewards_align( void ){ return FD_PARTITIONED_STAKE_REWARDS_ALIGN; } + +void fd_partitioned_stake_rewards_walk( void * w, fd_partitioned_stake_rewards_t const * self, fd_types_walk_fn_t fun, const char *name, uint level ) { + fun( w, self, name, FD_FLAMENCO_TYPE_MAP, "fd_partitioned_stake_rewards", level++ ); + if( self->partitions ) { + for( ulong i=0; i < self->partitions_len; i++ ) { + for( fd_partitioned_stake_rewards_dlist_iter_t iter = fd_partitioned_stake_rewards_dlist_iter_fwd_init( &self->partitions[ i ], self->pool ); + !fd_partitioned_stake_rewards_dlist_iter_done( iter, &self->partitions[ i ], self->pool ); + iter = fd_partitioned_stake_rewards_dlist_iter_fwd_next( iter, &self->partitions[ i ], self->pool ) ) { + fd_stake_reward_t * ele = fd_partitioned_stake_rewards_dlist_iter_ele( iter, &self->partitions[ i ], self->pool ); + fd_stake_reward_walk( w, ele, fun, "fd_stake_reward_t", level ); + } + } + } + fun( w, self, name, FD_FLAMENCO_TYPE_MAP_END, "fd_partitioned_stake_rewards", level-- ); +} +ulong fd_partitioned_stake_rewards_size( fd_partitioned_stake_rewards_t const * self ) { + ulong size = 0; + size += sizeof(ulong); + size += 4096 * sizeof(ulong); + if( self->partitions ) { + for( ulong i=0; i < self->partitions_len; i++ ) { + for( fd_partitioned_stake_rewards_dlist_iter_t iter = fd_partitioned_stake_rewards_dlist_iter_fwd_init( &self->partitions[ i ], self->pool ); + !fd_partitioned_stake_rewards_dlist_iter_done( iter, &self->partitions[ i ], self->pool ); + iter = fd_partitioned_stake_rewards_dlist_iter_fwd_next( iter, &self->partitions[ i ], self->pool ) ) { + fd_stake_reward_t * ele = fd_partitioned_stake_rewards_dlist_iter_ele( iter, &self->partitions[ i ], self->pool ); + size += fd_stake_reward_size( ele ); + } + } + } + return size; +} + +int fd_stake_reward_calculation_partitioned_encode( fd_stake_reward_calculation_partitioned_t const * self, fd_bincode_encode_ctx_t * ctx ) { + int err; + err = fd_partitioned_stake_rewards_encode( &self->partitioned_stake_rewards, ctx ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_bincode_uint64_encode( self->total_stake_rewards_lamports, ctx ); + if( FD_UNLIKELY( err ) ) return err; + return FD_BINCODE_SUCCESS; +} +int fd_stake_reward_calculation_partitioned_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + *total_sz += sizeof(fd_stake_reward_calculation_partitioned_t); + void const * start_data = ctx->data; + int err = fd_stake_reward_calculation_partitioned_decode_footprint_inner( ctx, total_sz ); + if( ctx->data>ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; + ctx->data = start_data; + return err; +} +int fd_stake_reward_calculation_partitioned_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + if( ctx->data>=ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; + int err = 0; + err = fd_partitioned_stake_rewards_decode_footprint_inner( ctx, total_sz ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_bincode_uint64_decode_footprint( ctx ); + if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) return err; + return 0; +} +void * fd_stake_reward_calculation_partitioned_decode( void * mem, fd_bincode_decode_ctx_t * ctx ) { + fd_stake_reward_calculation_partitioned_t * self = (fd_stake_reward_calculation_partitioned_t *)mem; + fd_stake_reward_calculation_partitioned_new( self ); + void * alloc_region = (uchar *)mem + sizeof(fd_stake_reward_calculation_partitioned_t); + void * * alloc_mem = &alloc_region; + fd_stake_reward_calculation_partitioned_decode_inner( mem, alloc_mem, ctx ); + return self; +} +void fd_stake_reward_calculation_partitioned_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ) { + fd_stake_reward_calculation_partitioned_t * self = (fd_stake_reward_calculation_partitioned_t *)struct_mem; + fd_partitioned_stake_rewards_decode_inner( &self->partitioned_stake_rewards, alloc_mem, ctx ); + fd_bincode_uint64_decode_unsafe( &self->total_stake_rewards_lamports, ctx ); +} +void fd_stake_reward_calculation_partitioned_new(fd_stake_reward_calculation_partitioned_t * self) { + fd_memset( self, 0, sizeof(fd_stake_reward_calculation_partitioned_t) ); + fd_partitioned_stake_rewards_new( &self->partitioned_stake_rewards ); +} +void fd_stake_reward_calculation_partitioned_destroy( fd_stake_reward_calculation_partitioned_t * self ) { + fd_partitioned_stake_rewards_destroy( &self->partitioned_stake_rewards ); +} + +ulong fd_stake_reward_calculation_partitioned_footprint( void ){ return FD_STAKE_REWARD_CALCULATION_PARTITIONED_FOOTPRINT; } +ulong fd_stake_reward_calculation_partitioned_align( void ){ return FD_STAKE_REWARD_CALCULATION_PARTITIONED_ALIGN; } + +void fd_stake_reward_calculation_partitioned_walk( void * w, fd_stake_reward_calculation_partitioned_t const * self, fd_types_walk_fn_t fun, const char *name, uint level ) { + fun( w, self, name, FD_FLAMENCO_TYPE_MAP, "fd_stake_reward_calculation_partitioned", level++ ); + fd_partitioned_stake_rewards_walk( w, &self->partitioned_stake_rewards, fun, "partitioned_stake_rewards", level ); + fun( w, &self->total_stake_rewards_lamports, "total_stake_rewards_lamports", FD_FLAMENCO_TYPE_ULONG, "ulong", level ); + fun( w, self, name, FD_FLAMENCO_TYPE_MAP_END, "fd_stake_reward_calculation_partitioned", level-- ); +} +ulong fd_stake_reward_calculation_partitioned_size( fd_stake_reward_calculation_partitioned_t const * self ) { + ulong size = 0; + size += fd_partitioned_stake_rewards_size( &self->partitioned_stake_rewards ); + size += sizeof(ulong); + return size; +} + +int fd_stake_reward_calculation_encode( fd_stake_reward_calculation_t const * self, fd_bincode_encode_ctx_t * ctx ) { + int err; + if( self->stake_rewards ) { + err = fd_bincode_uint64_encode( self->stake_rewards_len, ctx ); + if( FD_UNLIKELY( err ) ) return err; + for( ulong i=0; i < 1; i++ ) { + err = fd_bincode_uint64_encode( self->stake_rewards_lengths[ i ], ctx ); + if( FD_UNLIKELY( err ) ) return err; + } + for( ulong i=0; i < self->stake_rewards_len; i++ ) { + for( fd_stake_reward_calculation_dlist_iter_t iter = fd_stake_reward_calculation_dlist_iter_fwd_init( &self->stake_rewards[ i ], self->pool ); + !fd_stake_reward_calculation_dlist_iter_done( iter, &self->stake_rewards[ i ], self->pool ); + iter = fd_stake_reward_calculation_dlist_iter_fwd_next( iter, &self->stake_rewards[ i ], self->pool ) ) { + fd_stake_reward_t * ele = fd_stake_reward_calculation_dlist_iter_ele( iter, &self->stake_rewards[ i ], self->pool ); + err = fd_stake_reward_encode( ele, ctx ); + if( FD_UNLIKELY( err ) ) return err; + } + } + } else { + err = fd_bincode_uint64_encode( self->stake_rewards_len, ctx ); + if( FD_UNLIKELY( err ) ) return err; + } + err = fd_bincode_uint64_encode( self->total_stake_rewards_lamports, ctx ); + if( FD_UNLIKELY( err ) ) return err; + return FD_BINCODE_SUCCESS; +} +int fd_stake_reward_calculation_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + *total_sz += sizeof(fd_stake_reward_calculation_t); + void const * start_data = ctx->data; + int err = fd_stake_reward_calculation_decode_footprint_inner( ctx, total_sz ); + if( ctx->data>ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; + ctx->data = start_data; + return err; +} +int fd_stake_reward_calculation_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + if( ctx->data>=ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; + int err = 0; + ulong stake_rewards_len; + err = fd_bincode_uint64_decode( &stake_rewards_len, ctx ); + if( FD_UNLIKELY( err ) ) return err; + ulong total_count = 0UL; + ulong stake_rewards_lengths[1]; + for( ulong i=0; i<1; i++ ) { + err = fd_bincode_uint64_decode( stake_rewards_lengths + i, ctx ); + total_count+=stake_rewards_lengths[ i ]; + if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) return err; + } + *total_sz += fd_stake_reward_calculation_pool_align() + fd_stake_reward_calculation_pool_footprint( total_count ); + *total_sz += fd_stake_reward_calculation_dlist_align() + fd_stake_reward_calculation_dlist_footprint()*stake_rewards_len; + for( ulong i=0; i < stake_rewards_len; i++ ) { + err = fd_stake_reward_decode_footprint_inner( ctx, total_sz ); + if( FD_UNLIKELY ( err ) ) return err; + } + err = fd_bincode_uint64_decode_footprint( ctx ); + if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) return err; + return 0; +} +void * fd_stake_reward_calculation_decode( void * mem, fd_bincode_decode_ctx_t * ctx ) { + fd_stake_reward_calculation_t * self = (fd_stake_reward_calculation_t *)mem; + fd_stake_reward_calculation_new( self ); + void * alloc_region = (uchar *)mem + sizeof(fd_stake_reward_calculation_t); + void * * alloc_mem = &alloc_region; + fd_stake_reward_calculation_decode_inner( mem, alloc_mem, ctx ); + return self; +} +void fd_stake_reward_calculation_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ) { + fd_stake_reward_calculation_t * self = (fd_stake_reward_calculation_t *)struct_mem; + fd_bincode_uint64_decode_unsafe( &self->stake_rewards_len, ctx ); + ulong total_count = 0UL; + for( ulong i=0; i < 1; i++ ) { + fd_bincode_uint64_decode_unsafe( self->stake_rewards_lengths + i, ctx ); + total_count += self->stake_rewards_lengths[ i ]; + } + self->pool = fd_stake_reward_calculation_pool_join_new( alloc_mem, total_count ); + self->stake_rewards = fd_stake_reward_calculation_dlist_join_new( alloc_mem, self->stake_rewards_len ); + for( ulong i=0; i < self->stake_rewards_len; i++ ) { + fd_stake_reward_calculation_dlist_new( &self->stake_rewards[ i ] ); + for( ulong j=0; j < self->stake_rewards_lengths[ i ]; j++ ) { + fd_stake_reward_t * ele = fd_stake_reward_calculation_pool_ele_acquire( self->pool ); + fd_stake_reward_new( ele ); + fd_stake_reward_decode_inner( ele, alloc_mem, ctx ); + fd_stake_reward_calculation_dlist_ele_push_tail( &self->stake_rewards[ i ], ele, self->pool ); + } + } + fd_bincode_uint64_decode_unsafe( &self->total_stake_rewards_lamports, ctx ); +} +void fd_stake_reward_calculation_new(fd_stake_reward_calculation_t * self) { + fd_memset( self, 0, sizeof(fd_stake_reward_calculation_t) ); +} +void fd_stake_reward_calculation_destroy( fd_stake_reward_calculation_t * self ) { + if( !self->stake_rewards || !self->pool ) return; + for( ulong i=0; i < self->stake_rewards_len; i++ ) { + for( fd_stake_reward_calculation_dlist_iter_t iter = fd_stake_reward_calculation_dlist_iter_fwd_init( &self->stake_rewards[ i ], self->pool ); + !fd_stake_reward_calculation_dlist_iter_done( iter, &self->stake_rewards[ i ], self->pool ); + iter = fd_stake_reward_calculation_dlist_iter_fwd_next( iter, &self->stake_rewards[ i ], self->pool ) ) { + fd_stake_reward_t * ele = fd_stake_reward_calculation_dlist_iter_ele( iter, &self->stake_rewards[ i ], self->pool ); + fd_stake_reward_destroy( ele ); + } + } + self->stake_rewards = NULL; + self->pool = NULL; +} + +ulong fd_stake_reward_calculation_footprint( void ){ return FD_STAKE_REWARD_CALCULATION_FOOTPRINT; } +ulong fd_stake_reward_calculation_align( void ){ return FD_STAKE_REWARD_CALCULATION_ALIGN; } + +void fd_stake_reward_calculation_walk( void * w, fd_stake_reward_calculation_t const * self, fd_types_walk_fn_t fun, const char *name, uint level ) { + fun( w, self, name, FD_FLAMENCO_TYPE_MAP, "fd_stake_reward_calculation", level++ ); + if( self->stake_rewards ) { + for( ulong i=0; i < self->stake_rewards_len; i++ ) { + for( fd_stake_reward_calculation_dlist_iter_t iter = fd_stake_reward_calculation_dlist_iter_fwd_init( &self->stake_rewards[ i ], self->pool ); + !fd_stake_reward_calculation_dlist_iter_done( iter, &self->stake_rewards[ i ], self->pool ); + iter = fd_stake_reward_calculation_dlist_iter_fwd_next( iter, &self->stake_rewards[ i ], self->pool ) ) { + fd_stake_reward_t * ele = fd_stake_reward_calculation_dlist_iter_ele( iter, &self->stake_rewards[ i ], self->pool ); + fd_stake_reward_walk( w, ele, fun, "fd_stake_reward_t", level ); + } + } + } + fun( w, &self->total_stake_rewards_lamports, "total_stake_rewards_lamports", FD_FLAMENCO_TYPE_ULONG, "ulong", level ); + fun( w, self, name, FD_FLAMENCO_TYPE_MAP_END, "fd_stake_reward_calculation", level-- ); +} +ulong fd_stake_reward_calculation_size( fd_stake_reward_calculation_t const * self ) { + ulong size = 0; + size += sizeof(ulong); + size += 1 * sizeof(ulong); + if( self->stake_rewards ) { + for( ulong i=0; i < self->stake_rewards_len; i++ ) { + for( fd_stake_reward_calculation_dlist_iter_t iter = fd_stake_reward_calculation_dlist_iter_fwd_init( &self->stake_rewards[ i ], self->pool ); + !fd_stake_reward_calculation_dlist_iter_done( iter, &self->stake_rewards[ i ], self->pool ); + iter = fd_stake_reward_calculation_dlist_iter_fwd_next( iter, &self->stake_rewards[ i ], self->pool ) ) { + fd_stake_reward_t * ele = fd_stake_reward_calculation_dlist_iter_ele( iter, &self->stake_rewards[ i ], self->pool ); + size += fd_stake_reward_size( ele ); + } + } + } + size += sizeof(ulong); + return size; +} + +int fd_calculate_stake_vote_rewards_result_encode( fd_calculate_stake_vote_rewards_result_t const * self, fd_bincode_encode_ctx_t * ctx ) { + int err; + err = fd_stake_reward_calculation_encode( &self->stake_reward_calculation, ctx ); + if( FD_UNLIKELY( err ) ) return err; + if( self->vote_reward_map_root ) { + ulong vote_reward_map_len = fd_vote_reward_t_map_size( self->vote_reward_map_pool, self->vote_reward_map_root ); + err = fd_bincode_uint64_encode( vote_reward_map_len, ctx ); + if( FD_UNLIKELY( err ) ) return err; + for( fd_vote_reward_t_mapnode_t * n = fd_vote_reward_t_map_minimum( self->vote_reward_map_pool, self->vote_reward_map_root ); n; n = fd_vote_reward_t_map_successor( self->vote_reward_map_pool, n ) ) { + err = fd_vote_reward_encode( &n->elem, ctx ); + if( FD_UNLIKELY( err ) ) return err; + } + } else { + ulong vote_reward_map_len = 0; + err = fd_bincode_uint64_encode( vote_reward_map_len, ctx ); + if( FD_UNLIKELY( err ) ) return err; + } + return FD_BINCODE_SUCCESS; +} +int fd_calculate_stake_vote_rewards_result_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + *total_sz += sizeof(fd_calculate_stake_vote_rewards_result_t); + void const * start_data = ctx->data; + int err = fd_calculate_stake_vote_rewards_result_decode_footprint_inner( ctx, total_sz ); + if( ctx->data>ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; + ctx->data = start_data; + return err; +} +int fd_calculate_stake_vote_rewards_result_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + if( ctx->data>=ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; + int err = 0; + err = fd_stake_reward_calculation_decode_footprint_inner( ctx, total_sz ); + if( FD_UNLIKELY( err ) ) return err; + ulong vote_reward_map_len = 0UL; + err = fd_bincode_uint64_decode( &vote_reward_map_len, ctx ); + ulong vote_reward_map_cnt = fd_ulong_max( vote_reward_map_len, 15000 ); + *total_sz += fd_vote_reward_t_map_align() + fd_vote_reward_t_map_footprint( vote_reward_map_cnt ); + if( FD_UNLIKELY( err ) ) return err; + for( ulong i=0; i < vote_reward_map_len; i++ ) { + err = fd_vote_reward_decode_footprint_inner( ctx, total_sz ); + if( FD_UNLIKELY( err ) ) return err; + } + return 0; +} +void * fd_calculate_stake_vote_rewards_result_decode( void * mem, fd_bincode_decode_ctx_t * ctx ) { + fd_calculate_stake_vote_rewards_result_t * self = (fd_calculate_stake_vote_rewards_result_t *)mem; + fd_calculate_stake_vote_rewards_result_new( self ); + void * alloc_region = (uchar *)mem + sizeof(fd_calculate_stake_vote_rewards_result_t); + void * * alloc_mem = &alloc_region; + fd_calculate_stake_vote_rewards_result_decode_inner( mem, alloc_mem, ctx ); + return self; +} +void fd_calculate_stake_vote_rewards_result_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ) { + fd_calculate_stake_vote_rewards_result_t * self = (fd_calculate_stake_vote_rewards_result_t *)struct_mem; + fd_stake_reward_calculation_decode_inner( &self->stake_reward_calculation, alloc_mem, ctx ); + ulong vote_reward_map_len; + fd_bincode_uint64_decode_unsafe( &vote_reward_map_len, ctx ); + self->vote_reward_map_pool = fd_vote_reward_t_map_join_new( alloc_mem, fd_ulong_max( vote_reward_map_len, 15000 ) ); + self->vote_reward_map_root = NULL; + for( ulong i=0; i < vote_reward_map_len; i++ ) { + fd_vote_reward_t_mapnode_t * node = fd_vote_reward_t_map_acquire( self->vote_reward_map_pool ); + fd_vote_reward_new( &node->elem ); + fd_vote_reward_decode_inner( &node->elem, alloc_mem, ctx ); + fd_vote_reward_t_map_insert( self->vote_reward_map_pool, &self->vote_reward_map_root, node ); + } +} +void fd_calculate_stake_vote_rewards_result_new(fd_calculate_stake_vote_rewards_result_t * self) { + fd_memset( self, 0, sizeof(fd_calculate_stake_vote_rewards_result_t) ); + fd_stake_reward_calculation_new( &self->stake_reward_calculation ); +} +void fd_calculate_stake_vote_rewards_result_destroy( fd_calculate_stake_vote_rewards_result_t * self ) { + fd_stake_reward_calculation_destroy( &self->stake_reward_calculation ); + for( fd_vote_reward_t_mapnode_t * n = fd_vote_reward_t_map_minimum(self->vote_reward_map_pool, self->vote_reward_map_root ); n; n = fd_vote_reward_t_map_successor(self->vote_reward_map_pool, n) ) { + fd_vote_reward_destroy( &n->elem ); + } + self->vote_reward_map_pool = NULL; + self->vote_reward_map_root = NULL; +} + +ulong fd_calculate_stake_vote_rewards_result_footprint( void ){ return FD_CALCULATE_STAKE_VOTE_REWARDS_RESULT_FOOTPRINT; } +ulong fd_calculate_stake_vote_rewards_result_align( void ){ return FD_CALCULATE_STAKE_VOTE_REWARDS_RESULT_ALIGN; } + +void fd_calculate_stake_vote_rewards_result_walk( void * w, fd_calculate_stake_vote_rewards_result_t const * self, fd_types_walk_fn_t fun, const char *name, uint level ) { + fun( w, self, name, FD_FLAMENCO_TYPE_MAP, "fd_calculate_stake_vote_rewards_result", level++ ); + fd_stake_reward_calculation_walk( w, &self->stake_reward_calculation, fun, "stake_reward_calculation", level ); + if( self->vote_reward_map_root ) { + for( fd_vote_reward_t_mapnode_t * n = fd_vote_reward_t_map_minimum(self->vote_reward_map_pool, self->vote_reward_map_root ); n; n = fd_vote_reward_t_map_successor( self->vote_reward_map_pool, n ) ) { + fd_vote_reward_walk(w, &n->elem, fun, "vote_reward_map", level ); + } + } + fun( w, self, name, FD_FLAMENCO_TYPE_MAP_END, "fd_calculate_stake_vote_rewards_result", level-- ); +} +ulong fd_calculate_stake_vote_rewards_result_size( fd_calculate_stake_vote_rewards_result_t const * self ) { + ulong size = 0; + size += fd_stake_reward_calculation_size( &self->stake_reward_calculation ); + if( self->vote_reward_map_root ) { + size += sizeof(ulong); + for( fd_vote_reward_t_mapnode_t * n = fd_vote_reward_t_map_minimum( self->vote_reward_map_pool, self->vote_reward_map_root ); n; n = fd_vote_reward_t_map_successor( self->vote_reward_map_pool, n ) ) { + size += fd_vote_reward_size( &n->elem ); + } + } else { + size += sizeof(ulong); + } + return size; +} + +int fd_calculate_validator_rewards_result_encode( fd_calculate_validator_rewards_result_t const * self, fd_bincode_encode_ctx_t * ctx ) { + int err; + err = fd_calculate_stake_vote_rewards_result_encode( &self->calculate_stake_vote_rewards_result, ctx ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_point_value_encode( &self->point_value, ctx ); + if( FD_UNLIKELY( err ) ) return err; + return FD_BINCODE_SUCCESS; +} +int fd_calculate_validator_rewards_result_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + *total_sz += sizeof(fd_calculate_validator_rewards_result_t); + void const * start_data = ctx->data; + int err = fd_calculate_validator_rewards_result_decode_footprint_inner( ctx, total_sz ); + if( ctx->data>ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; + ctx->data = start_data; + return err; +} +int fd_calculate_validator_rewards_result_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + if( ctx->data>=ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; + int err = 0; + err = fd_calculate_stake_vote_rewards_result_decode_footprint_inner( ctx, total_sz ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_point_value_decode_footprint_inner( ctx, total_sz ); + if( FD_UNLIKELY( err ) ) return err; + return 0; +} +void * fd_calculate_validator_rewards_result_decode( void * mem, fd_bincode_decode_ctx_t * ctx ) { + fd_calculate_validator_rewards_result_t * self = (fd_calculate_validator_rewards_result_t *)mem; + fd_calculate_validator_rewards_result_new( self ); + void * alloc_region = (uchar *)mem + sizeof(fd_calculate_validator_rewards_result_t); + void * * alloc_mem = &alloc_region; + fd_calculate_validator_rewards_result_decode_inner( mem, alloc_mem, ctx ); + return self; +} +void fd_calculate_validator_rewards_result_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ) { + fd_calculate_validator_rewards_result_t * self = (fd_calculate_validator_rewards_result_t *)struct_mem; + fd_calculate_stake_vote_rewards_result_decode_inner( &self->calculate_stake_vote_rewards_result, alloc_mem, ctx ); + fd_point_value_decode_inner( &self->point_value, alloc_mem, ctx ); +} +void fd_calculate_validator_rewards_result_new(fd_calculate_validator_rewards_result_t * self) { + fd_memset( self, 0, sizeof(fd_calculate_validator_rewards_result_t) ); + fd_calculate_stake_vote_rewards_result_new( &self->calculate_stake_vote_rewards_result ); + fd_point_value_new( &self->point_value ); +} +void fd_calculate_validator_rewards_result_destroy( fd_calculate_validator_rewards_result_t * self ) { + fd_calculate_stake_vote_rewards_result_destroy( &self->calculate_stake_vote_rewards_result ); + fd_point_value_destroy( &self->point_value ); +} + +ulong fd_calculate_validator_rewards_result_footprint( void ){ return FD_CALCULATE_VALIDATOR_REWARDS_RESULT_FOOTPRINT; } +ulong fd_calculate_validator_rewards_result_align( void ){ return FD_CALCULATE_VALIDATOR_REWARDS_RESULT_ALIGN; } + +void fd_calculate_validator_rewards_result_walk( void * w, fd_calculate_validator_rewards_result_t const * self, fd_types_walk_fn_t fun, const char *name, uint level ) { + fun( w, self, name, FD_FLAMENCO_TYPE_MAP, "fd_calculate_validator_rewards_result", level++ ); + fd_calculate_stake_vote_rewards_result_walk( w, &self->calculate_stake_vote_rewards_result, fun, "calculate_stake_vote_rewards_result", level ); + fd_point_value_walk( w, &self->point_value, fun, "point_value", level ); + fun( w, self, name, FD_FLAMENCO_TYPE_MAP_END, "fd_calculate_validator_rewards_result", level-- ); +} +ulong fd_calculate_validator_rewards_result_size( fd_calculate_validator_rewards_result_t const * self ) { + ulong size = 0; + size += fd_calculate_stake_vote_rewards_result_size( &self->calculate_stake_vote_rewards_result ); + size += fd_point_value_size( &self->point_value ); + return size; +} + +int fd_calculate_rewards_and_distribute_vote_rewards_result_encode( fd_calculate_rewards_and_distribute_vote_rewards_result_t const * self, fd_bincode_encode_ctx_t * ctx ) { + int err; + err = fd_bincode_uint64_encode( self->total_rewards, ctx ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_bincode_uint64_encode( self->distributed_rewards, ctx ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_point_value_encode( &self->point_value, ctx ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_stake_reward_calculation_partitioned_encode( &self->stake_rewards_by_partition, ctx ); + if( FD_UNLIKELY( err ) ) return err; + return FD_BINCODE_SUCCESS; +} +int fd_calculate_rewards_and_distribute_vote_rewards_result_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + *total_sz += sizeof(fd_calculate_rewards_and_distribute_vote_rewards_result_t); + void const * start_data = ctx->data; + int err = fd_calculate_rewards_and_distribute_vote_rewards_result_decode_footprint_inner( ctx, total_sz ); + if( ctx->data>ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; + ctx->data = start_data; + return err; +} +int fd_calculate_rewards_and_distribute_vote_rewards_result_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + if( ctx->data>=ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; + int err = 0; + err = fd_bincode_uint64_decode_footprint( ctx ); + if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) return err; + err = fd_bincode_uint64_decode_footprint( ctx ); + if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) return err; + err = fd_point_value_decode_footprint_inner( ctx, total_sz ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_stake_reward_calculation_partitioned_decode_footprint_inner( ctx, total_sz ); + if( FD_UNLIKELY( err ) ) return err; + return 0; +} +void * fd_calculate_rewards_and_distribute_vote_rewards_result_decode( void * mem, fd_bincode_decode_ctx_t * ctx ) { + fd_calculate_rewards_and_distribute_vote_rewards_result_t * self = (fd_calculate_rewards_and_distribute_vote_rewards_result_t *)mem; + fd_calculate_rewards_and_distribute_vote_rewards_result_new( self ); + void * alloc_region = (uchar *)mem + sizeof(fd_calculate_rewards_and_distribute_vote_rewards_result_t); + void * * alloc_mem = &alloc_region; + fd_calculate_rewards_and_distribute_vote_rewards_result_decode_inner( mem, alloc_mem, ctx ); + return self; +} +void fd_calculate_rewards_and_distribute_vote_rewards_result_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ) { + fd_calculate_rewards_and_distribute_vote_rewards_result_t * self = (fd_calculate_rewards_and_distribute_vote_rewards_result_t *)struct_mem; + fd_bincode_uint64_decode_unsafe( &self->total_rewards, ctx ); + fd_bincode_uint64_decode_unsafe( &self->distributed_rewards, ctx ); + fd_point_value_decode_inner( &self->point_value, alloc_mem, ctx ); + fd_stake_reward_calculation_partitioned_decode_inner( &self->stake_rewards_by_partition, alloc_mem, ctx ); +} +void fd_calculate_rewards_and_distribute_vote_rewards_result_new(fd_calculate_rewards_and_distribute_vote_rewards_result_t * self) { + fd_memset( self, 0, sizeof(fd_calculate_rewards_and_distribute_vote_rewards_result_t) ); + fd_point_value_new( &self->point_value ); + fd_stake_reward_calculation_partitioned_new( &self->stake_rewards_by_partition ); +} +void fd_calculate_rewards_and_distribute_vote_rewards_result_destroy( fd_calculate_rewards_and_distribute_vote_rewards_result_t * self ) { + fd_point_value_destroy( &self->point_value ); + fd_stake_reward_calculation_partitioned_destroy( &self->stake_rewards_by_partition ); +} + +ulong fd_calculate_rewards_and_distribute_vote_rewards_result_footprint( void ){ return FD_CALCULATE_REWARDS_AND_DISTRIBUTE_VOTE_REWARDS_RESULT_FOOTPRINT; } +ulong fd_calculate_rewards_and_distribute_vote_rewards_result_align( void ){ return FD_CALCULATE_REWARDS_AND_DISTRIBUTE_VOTE_REWARDS_RESULT_ALIGN; } + +void fd_calculate_rewards_and_distribute_vote_rewards_result_walk( void * w, fd_calculate_rewards_and_distribute_vote_rewards_result_t const * self, fd_types_walk_fn_t fun, const char *name, uint level ) { + fun( w, self, name, FD_FLAMENCO_TYPE_MAP, "fd_calculate_rewards_and_distribute_vote_rewards_result", level++ ); + fun( w, &self->total_rewards, "total_rewards", FD_FLAMENCO_TYPE_ULONG, "ulong", level ); + fun( w, &self->distributed_rewards, "distributed_rewards", FD_FLAMENCO_TYPE_ULONG, "ulong", level ); + fd_point_value_walk( w, &self->point_value, fun, "point_value", level ); + fd_stake_reward_calculation_partitioned_walk( w, &self->stake_rewards_by_partition, fun, "stake_rewards_by_partition", level ); + fun( w, self, name, FD_FLAMENCO_TYPE_MAP_END, "fd_calculate_rewards_and_distribute_vote_rewards_result", level-- ); +} +ulong fd_calculate_rewards_and_distribute_vote_rewards_result_size( fd_calculate_rewards_and_distribute_vote_rewards_result_t const * self ) { + ulong size = 0; + size += sizeof(ulong); + size += sizeof(ulong); + size += fd_point_value_size( &self->point_value ); + size += fd_stake_reward_calculation_partitioned_size( &self->stake_rewards_by_partition ); + return size; +} + +int fd_partitioned_rewards_calculation_encode( fd_partitioned_rewards_calculation_t const * self, fd_bincode_encode_ctx_t * ctx ) { + int err; + if( self->vote_reward_map_root ) { + ulong vote_reward_map_len = fd_vote_reward_t_map_size( self->vote_reward_map_pool, self->vote_reward_map_root ); + err = fd_bincode_uint64_encode( vote_reward_map_len, ctx ); + if( FD_UNLIKELY( err ) ) return err; + for( fd_vote_reward_t_mapnode_t * n = fd_vote_reward_t_map_minimum( self->vote_reward_map_pool, self->vote_reward_map_root ); n; n = fd_vote_reward_t_map_successor( self->vote_reward_map_pool, n ) ) { + err = fd_vote_reward_encode( &n->elem, ctx ); + if( FD_UNLIKELY( err ) ) return err; + } + } else { + ulong vote_reward_map_len = 0; + err = fd_bincode_uint64_encode( vote_reward_map_len, ctx ); + if( FD_UNLIKELY( err ) ) return err; + } + err = fd_stake_reward_calculation_partitioned_encode( &self->stake_rewards_by_partition, ctx ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_bincode_uint64_encode( self->old_vote_balance_and_staked, ctx ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_bincode_uint64_encode( self->validator_rewards, ctx ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_bincode_double_encode( self->validator_rate, ctx ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_bincode_double_encode( self->foundation_rate, ctx ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_bincode_double_encode( self->prev_epoch_duration_in_years, ctx ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_bincode_uint64_encode( self->capitalization, ctx ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_point_value_encode( &self->point_value, ctx ); + if( FD_UNLIKELY( err ) ) return err; + return FD_BINCODE_SUCCESS; +} +int fd_partitioned_rewards_calculation_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + *total_sz += sizeof(fd_partitioned_rewards_calculation_t); + void const * start_data = ctx->data; + int err = fd_partitioned_rewards_calculation_decode_footprint_inner( ctx, total_sz ); + if( ctx->data>ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; + ctx->data = start_data; + return err; +} +int fd_partitioned_rewards_calculation_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + if( ctx->data>=ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; + int err = 0; + ulong vote_reward_map_len = 0UL; + err = fd_bincode_uint64_decode( &vote_reward_map_len, ctx ); + ulong vote_reward_map_cnt = fd_ulong_max( vote_reward_map_len, 15000 ); + *total_sz += fd_vote_reward_t_map_align() + fd_vote_reward_t_map_footprint( vote_reward_map_cnt ); + if( FD_UNLIKELY( err ) ) return err; + for( ulong i=0; i < vote_reward_map_len; i++ ) { + err = fd_vote_reward_decode_footprint_inner( ctx, total_sz ); + if( FD_UNLIKELY( err ) ) return err; + } + err = fd_stake_reward_calculation_partitioned_decode_footprint_inner( ctx, total_sz ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_bincode_uint64_decode_footprint( ctx ); + if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) return err; + err = fd_bincode_uint64_decode_footprint( ctx ); + if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) return err; + err = fd_bincode_double_decode_footprint( ctx ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_bincode_double_decode_footprint( ctx ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_bincode_double_decode_footprint( ctx ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_bincode_uint64_decode_footprint( ctx ); + if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) return err; + err = fd_point_value_decode_footprint_inner( ctx, total_sz ); + if( FD_UNLIKELY( err ) ) return err; + return 0; +} +void * fd_partitioned_rewards_calculation_decode( void * mem, fd_bincode_decode_ctx_t * ctx ) { + fd_partitioned_rewards_calculation_t * self = (fd_partitioned_rewards_calculation_t *)mem; + fd_partitioned_rewards_calculation_new( self ); + void * alloc_region = (uchar *)mem + sizeof(fd_partitioned_rewards_calculation_t); + void * * alloc_mem = &alloc_region; + fd_partitioned_rewards_calculation_decode_inner( mem, alloc_mem, ctx ); + return self; +} +void fd_partitioned_rewards_calculation_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ) { + fd_partitioned_rewards_calculation_t * self = (fd_partitioned_rewards_calculation_t *)struct_mem; + ulong vote_reward_map_len; + fd_bincode_uint64_decode_unsafe( &vote_reward_map_len, ctx ); + self->vote_reward_map_pool = fd_vote_reward_t_map_join_new( alloc_mem, fd_ulong_max( vote_reward_map_len, 15000 ) ); + self->vote_reward_map_root = NULL; + for( ulong i=0; i < vote_reward_map_len; i++ ) { + fd_vote_reward_t_mapnode_t * node = fd_vote_reward_t_map_acquire( self->vote_reward_map_pool ); + fd_vote_reward_new( &node->elem ); + fd_vote_reward_decode_inner( &node->elem, alloc_mem, ctx ); + fd_vote_reward_t_map_insert( self->vote_reward_map_pool, &self->vote_reward_map_root, node ); + } + fd_stake_reward_calculation_partitioned_decode_inner( &self->stake_rewards_by_partition, alloc_mem, ctx ); + fd_bincode_uint64_decode_unsafe( &self->old_vote_balance_and_staked, ctx ); + fd_bincode_uint64_decode_unsafe( &self->validator_rewards, ctx ); + fd_bincode_double_decode_unsafe( &self->validator_rate, ctx ); + fd_bincode_double_decode_unsafe( &self->foundation_rate, ctx ); + fd_bincode_double_decode_unsafe( &self->prev_epoch_duration_in_years, ctx ); + fd_bincode_uint64_decode_unsafe( &self->capitalization, ctx ); + fd_point_value_decode_inner( &self->point_value, alloc_mem, ctx ); +} +void fd_partitioned_rewards_calculation_new(fd_partitioned_rewards_calculation_t * self) { + fd_memset( self, 0, sizeof(fd_partitioned_rewards_calculation_t) ); + fd_stake_reward_calculation_partitioned_new( &self->stake_rewards_by_partition ); + fd_point_value_new( &self->point_value ); +} +void fd_partitioned_rewards_calculation_destroy( fd_partitioned_rewards_calculation_t * self ) { + for( fd_vote_reward_t_mapnode_t * n = fd_vote_reward_t_map_minimum(self->vote_reward_map_pool, self->vote_reward_map_root ); n; n = fd_vote_reward_t_map_successor(self->vote_reward_map_pool, n) ) { + fd_vote_reward_destroy( &n->elem ); + } + self->vote_reward_map_pool = NULL; + self->vote_reward_map_root = NULL; + fd_stake_reward_calculation_partitioned_destroy( &self->stake_rewards_by_partition ); + fd_point_value_destroy( &self->point_value ); +} + +ulong fd_partitioned_rewards_calculation_footprint( void ){ return FD_PARTITIONED_REWARDS_CALCULATION_FOOTPRINT; } +ulong fd_partitioned_rewards_calculation_align( void ){ return FD_PARTITIONED_REWARDS_CALCULATION_ALIGN; } + +void fd_partitioned_rewards_calculation_walk( void * w, fd_partitioned_rewards_calculation_t const * self, fd_types_walk_fn_t fun, const char *name, uint level ) { + fun( w, self, name, FD_FLAMENCO_TYPE_MAP, "fd_partitioned_rewards_calculation", level++ ); + if( self->vote_reward_map_root ) { + for( fd_vote_reward_t_mapnode_t * n = fd_vote_reward_t_map_minimum(self->vote_reward_map_pool, self->vote_reward_map_root ); n; n = fd_vote_reward_t_map_successor( self->vote_reward_map_pool, n ) ) { + fd_vote_reward_walk(w, &n->elem, fun, "vote_reward_map", level ); + } + } + fd_stake_reward_calculation_partitioned_walk( w, &self->stake_rewards_by_partition, fun, "stake_rewards_by_partition", level ); + fun( w, &self->old_vote_balance_and_staked, "old_vote_balance_and_staked", FD_FLAMENCO_TYPE_ULONG, "ulong", level ); + fun( w, &self->validator_rewards, "validator_rewards", FD_FLAMENCO_TYPE_ULONG, "ulong", level ); + fun( w, &self->validator_rate, "validator_rate", FD_FLAMENCO_TYPE_DOUBLE, "double", level ); + fun( w, &self->foundation_rate, "foundation_rate", FD_FLAMENCO_TYPE_DOUBLE, "double", level ); + fun( w, &self->prev_epoch_duration_in_years, "prev_epoch_duration_in_years", FD_FLAMENCO_TYPE_DOUBLE, "double", level ); + fun( w, &self->capitalization, "capitalization", FD_FLAMENCO_TYPE_ULONG, "ulong", level ); + fd_point_value_walk( w, &self->point_value, fun, "point_value", level ); + fun( w, self, name, FD_FLAMENCO_TYPE_MAP_END, "fd_partitioned_rewards_calculation", level-- ); +} +ulong fd_partitioned_rewards_calculation_size( fd_partitioned_rewards_calculation_t const * self ) { + ulong size = 0; + if( self->vote_reward_map_root ) { + size += sizeof(ulong); + for( fd_vote_reward_t_mapnode_t * n = fd_vote_reward_t_map_minimum( self->vote_reward_map_pool, self->vote_reward_map_root ); n; n = fd_vote_reward_t_map_successor( self->vote_reward_map_pool, n ) ) { + size += fd_vote_reward_size( &n->elem ); + } + } else { + size += sizeof(ulong); + } + size += fd_stake_reward_calculation_partitioned_size( &self->stake_rewards_by_partition ); + size += sizeof(ulong); + size += sizeof(ulong); + size += sizeof(double); + size += sizeof(double); + size += sizeof(double); + size += sizeof(ulong); + size += fd_point_value_size( &self->point_value ); + return size; +} + +int fd_start_block_height_and_rewards_encode( fd_start_block_height_and_rewards_t const * self, fd_bincode_encode_ctx_t * ctx ) { + int err; + err = fd_bincode_uint64_encode( self->distribution_starting_block_height, ctx ); + if( FD_UNLIKELY( err ) ) return err; + err = fd_partitioned_stake_rewards_encode( &self->partitioned_stake_rewards, ctx ); + if( FD_UNLIKELY( err ) ) return err; + return FD_BINCODE_SUCCESS; +} +int fd_start_block_height_and_rewards_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + *total_sz += sizeof(fd_start_block_height_and_rewards_t); + void const * start_data = ctx->data; + int err = fd_start_block_height_and_rewards_decode_footprint_inner( ctx, total_sz ); + if( ctx->data>ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; + ctx->data = start_data; + return err; +} +int fd_start_block_height_and_rewards_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + if( ctx->data>=ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; + int err = 0; + err = fd_bincode_uint64_decode_footprint( ctx ); + if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) return err; + err = fd_partitioned_stake_rewards_decode_footprint_inner( ctx, total_sz ); + if( FD_UNLIKELY( err ) ) return err; + return 0; +} +void * fd_start_block_height_and_rewards_decode( void * mem, fd_bincode_decode_ctx_t * ctx ) { + fd_start_block_height_and_rewards_t * self = (fd_start_block_height_and_rewards_t *)mem; + fd_start_block_height_and_rewards_new( self ); + void * alloc_region = (uchar *)mem + sizeof(fd_start_block_height_and_rewards_t); + void * * alloc_mem = &alloc_region; + fd_start_block_height_and_rewards_decode_inner( mem, alloc_mem, ctx ); + return self; +} +void fd_start_block_height_and_rewards_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ) { + fd_start_block_height_and_rewards_t * self = (fd_start_block_height_and_rewards_t *)struct_mem; + fd_bincode_uint64_decode_unsafe( &self->distribution_starting_block_height, ctx ); + fd_partitioned_stake_rewards_decode_inner( &self->partitioned_stake_rewards, alloc_mem, ctx ); +} +void fd_start_block_height_and_rewards_new(fd_start_block_height_and_rewards_t * self) { + fd_memset( self, 0, sizeof(fd_start_block_height_and_rewards_t) ); + fd_partitioned_stake_rewards_new( &self->partitioned_stake_rewards ); +} +void fd_start_block_height_and_rewards_destroy( fd_start_block_height_and_rewards_t * self ) { + fd_partitioned_stake_rewards_destroy( &self->partitioned_stake_rewards ); +} + +ulong fd_start_block_height_and_rewards_footprint( void ){ return FD_START_BLOCK_HEIGHT_AND_REWARDS_FOOTPRINT; } +ulong fd_start_block_height_and_rewards_align( void ){ return FD_START_BLOCK_HEIGHT_AND_REWARDS_ALIGN; } + +void fd_start_block_height_and_rewards_walk( void * w, fd_start_block_height_and_rewards_t const * self, fd_types_walk_fn_t fun, const char *name, uint level ) { + fun( w, self, name, FD_FLAMENCO_TYPE_MAP, "fd_start_block_height_and_rewards", level++ ); + fun( w, &self->distribution_starting_block_height, "distribution_starting_block_height", FD_FLAMENCO_TYPE_ULONG, "ulong", level ); + fd_partitioned_stake_rewards_walk( w, &self->partitioned_stake_rewards, fun, "partitioned_stake_rewards", level ); + fun( w, self, name, FD_FLAMENCO_TYPE_MAP_END, "fd_start_block_height_and_rewards", level-- ); +} +ulong fd_start_block_height_and_rewards_size( fd_start_block_height_and_rewards_t const * self ) { + ulong size = 0; + size += sizeof(ulong); + size += fd_partitioned_stake_rewards_size( &self->partitioned_stake_rewards ); + return size; +} + +int fd_fd_epoch_reward_status_inner_encode( fd_fd_epoch_reward_status_inner_t const * self, fd_bincode_encode_ctx_t * ctx ) { + int err; + err = fd_start_block_height_and_rewards_encode( &self->Active, ctx ); + if( FD_UNLIKELY( err ) ) return err; + return FD_BINCODE_SUCCESS; +} +int fd_fd_epoch_reward_status_inner_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + *total_sz += sizeof(fd_fd_epoch_reward_status_inner_t); + void const * start_data = ctx->data; + int err = fd_fd_epoch_reward_status_inner_decode_footprint_inner( ctx, total_sz ); + if( ctx->data>ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; + ctx->data = start_data; + return err; +} +int fd_fd_epoch_reward_status_inner_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + if( ctx->data>=ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; + int err = 0; + err = fd_start_block_height_and_rewards_decode_footprint_inner( ctx, total_sz ); + if( FD_UNLIKELY( err ) ) return err; + return 0; +} +void * fd_fd_epoch_reward_status_inner_decode( void * mem, fd_bincode_decode_ctx_t * ctx ) { + fd_fd_epoch_reward_status_inner_t * self = (fd_fd_epoch_reward_status_inner_t *)mem; + fd_fd_epoch_reward_status_inner_new( self ); + void * alloc_region = (uchar *)mem + sizeof(fd_fd_epoch_reward_status_inner_t); + void * * alloc_mem = &alloc_region; + fd_fd_epoch_reward_status_inner_decode_inner( mem, alloc_mem, ctx ); + return self; +} +void fd_fd_epoch_reward_status_inner_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ) { + fd_fd_epoch_reward_status_inner_t * self = (fd_fd_epoch_reward_status_inner_t *)struct_mem; + fd_start_block_height_and_rewards_decode_inner( &self->Active, alloc_mem, ctx ); +} +void fd_fd_epoch_reward_status_inner_new(fd_fd_epoch_reward_status_inner_t * self) { + fd_memset( self, 0, sizeof(fd_fd_epoch_reward_status_inner_t) ); + fd_start_block_height_and_rewards_new( &self->Active ); +} +void fd_fd_epoch_reward_status_inner_destroy( fd_fd_epoch_reward_status_inner_t * self ) { + fd_start_block_height_and_rewards_destroy( &self->Active ); +} + +ulong fd_fd_epoch_reward_status_inner_footprint( void ){ return FD_FD_EPOCH_REWARD_STATUS_INNER_FOOTPRINT; } +ulong fd_fd_epoch_reward_status_inner_align( void ){ return FD_FD_EPOCH_REWARD_STATUS_INNER_ALIGN; } + +void fd_fd_epoch_reward_status_inner_walk( void * w, fd_fd_epoch_reward_status_inner_t const * self, fd_types_walk_fn_t fun, const char *name, uint level ) { + fun( w, self, name, FD_FLAMENCO_TYPE_MAP, "fd_fd_epoch_reward_status_inner", level++ ); + fd_start_block_height_and_rewards_walk( w, &self->Active, fun, "Active", level ); + fun( w, self, name, FD_FLAMENCO_TYPE_MAP_END, "fd_fd_epoch_reward_status_inner", level-- ); +} +ulong fd_fd_epoch_reward_status_inner_size( fd_fd_epoch_reward_status_inner_t const * self ) { + ulong size = 0; + size += fd_start_block_height_and_rewards_size( &self->Active ); + return size; +} + +FD_FN_PURE uchar fd_epoch_reward_status_is_Active(fd_epoch_reward_status_t const * self) { + return self->discriminant == 0; +} +FD_FN_PURE uchar fd_epoch_reward_status_is_Inactive(fd_epoch_reward_status_t const * self) { + return self->discriminant == 1; +} +void fd_epoch_reward_status_inner_new( fd_epoch_reward_status_inner_t * self, uint discriminant ); +int fd_epoch_reward_status_inner_decode_footprint( uint discriminant, fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + int err; + switch (discriminant) { + case 0: { + err = fd_start_block_height_and_rewards_decode_footprint_inner( ctx, total_sz ); + if( FD_UNLIKELY( err ) ) return err; + return FD_BINCODE_SUCCESS; + } + case 1: { + return FD_BINCODE_SUCCESS; + } + default: return FD_BINCODE_ERR_ENCODING; + } +} +int fd_epoch_reward_status_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + *total_sz += sizeof(fd_epoch_reward_status_t); + void const * start_data = ctx->data; + int err = fd_epoch_reward_status_decode_footprint_inner( ctx, total_sz ); + if( ctx->data>ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; + ctx->data = start_data; + return err; +} +int fd_epoch_reward_status_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + if( ctx->data>=ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; + uint discriminant = 0; + int err = fd_bincode_uint32_decode( &discriminant, ctx ); + if( FD_UNLIKELY( err ) ) return err; + return fd_epoch_reward_status_inner_decode_footprint( discriminant, ctx, total_sz ); +} +void fd_epoch_reward_status_inner_decode_inner( fd_epoch_reward_status_inner_t * self, void * * alloc_mem, uint discriminant, fd_bincode_decode_ctx_t * ctx ) { + switch (discriminant) { + case 0: { + fd_start_block_height_and_rewards_decode_inner( &self->Active, alloc_mem, ctx ); + break; + } + case 1: { + break; + } + } +} +void fd_epoch_reward_status_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ) { + fd_epoch_reward_status_t * self = (fd_epoch_reward_status_t *)struct_mem; + fd_bincode_uint32_decode_unsafe( &self->discriminant, ctx ); + fd_epoch_reward_status_inner_decode_inner( &self->inner, alloc_mem, self->discriminant, ctx ); +} +void * fd_epoch_reward_status_decode( void * mem, fd_bincode_decode_ctx_t * ctx ) { + fd_epoch_reward_status_t * self = (fd_epoch_reward_status_t *)mem; + fd_epoch_reward_status_new( self ); + void * alloc_region = (uchar *)mem + sizeof(fd_epoch_reward_status_t); + void * * alloc_mem = &alloc_region; + fd_epoch_reward_status_decode_inner( mem, alloc_mem, ctx ); + return self; +} +void fd_epoch_reward_status_inner_new( fd_epoch_reward_status_inner_t * self, uint discriminant ) { + switch( discriminant ) { + case 0: { + fd_start_block_height_and_rewards_new( &self->Active ); + break; + } + case 1: { + break; + } + default: break; // FD_LOG_ERR(( "unhandled type")); + } +} +void fd_epoch_reward_status_new_disc( fd_epoch_reward_status_t * self, uint discriminant ) { + self->discriminant = discriminant; + fd_epoch_reward_status_inner_new( &self->inner, self->discriminant ); +} +void fd_epoch_reward_status_new( fd_epoch_reward_status_t * self ) { + fd_memset( self, 0, sizeof(fd_epoch_reward_status_t) ); + fd_epoch_reward_status_new_disc( self, UINT_MAX ); +} +void fd_epoch_reward_status_inner_destroy( fd_epoch_reward_status_inner_t * self, uint discriminant ) { + switch( discriminant ) { + case 0: { + fd_start_block_height_and_rewards_destroy( &self->Active ); + break; + } + default: break; // FD_LOG_ERR(( "unhandled type" )); + } +} +void fd_epoch_reward_status_destroy( fd_epoch_reward_status_t * self ) { + fd_epoch_reward_status_inner_destroy( &self->inner, self->discriminant ); +} + +ulong fd_epoch_reward_status_footprint( void ){ return FD_EPOCH_REWARD_STATUS_FOOTPRINT; } +ulong fd_epoch_reward_status_align( void ){ return FD_EPOCH_REWARD_STATUS_ALIGN; } + +void fd_epoch_reward_status_walk( void * w, fd_epoch_reward_status_t const * self, fd_types_walk_fn_t fun, const char *name, uint level ) { + fun(w, self, name, FD_FLAMENCO_TYPE_ENUM, "fd_epoch_reward_status", level++); + switch( self->discriminant ) { + case 0: { + fun( w, self, "Active", FD_FLAMENCO_TYPE_ENUM_DISC, "discriminant", level ); + fd_start_block_height_and_rewards_walk( w, &self->inner.Active, fun, "Active", level ); + break; + } + case 1: { + fun( w, self, "Inactive", FD_FLAMENCO_TYPE_ENUM_DISC, "discriminant", level ); + break; + } + } + fun( w, self, name, FD_FLAMENCO_TYPE_ENUM_END, "fd_epoch_reward_status", level-- ); +} +ulong fd_epoch_reward_status_size( fd_epoch_reward_status_t const * self ) { + ulong size = 0; + size += sizeof(uint); + switch (self->discriminant) { + case 0: { + size += fd_start_block_height_and_rewards_size( &self->inner.Active ); + break; + } + } + return size; +} + +int fd_epoch_reward_status_inner_encode( fd_epoch_reward_status_inner_t const * self, uint discriminant, fd_bincode_encode_ctx_t * ctx ) { + int err; + switch (discriminant) { + case 0: { + err = fd_start_block_height_and_rewards_encode( &self->Active, ctx ); + if( FD_UNLIKELY( err ) ) return err; + break; + } + } + return FD_BINCODE_SUCCESS; +} +int fd_epoch_reward_status_encode( fd_epoch_reward_status_t const * self, fd_bincode_encode_ctx_t * ctx ) { + int err = fd_bincode_uint32_encode( self->discriminant, ctx ); + if( FD_UNLIKELY( err ) ) return err; + return fd_epoch_reward_status_inner_encode( &self->inner, self->discriminant, ctx ); +} + int fd_slot_bank_encode( fd_slot_bank_t const * self, fd_bincode_encode_ctx_t * ctx ) { int err; err = fd_clock_timestamp_votes_encode( &self->timestamp_votes, ctx ); @@ -11238,6 +12464,8 @@ int fd_slot_bank_encode( fd_slot_bank_t const * self, fd_bincode_encode_ctx_t * } err = fd_hard_forks_encode( &self->hard_forks, ctx ); if( FD_UNLIKELY( err ) ) return err; + err = fd_epoch_reward_status_encode( &self->epoch_reward_status, ctx ); + if( FD_UNLIKELY( err ) ) return err; return FD_BINCODE_SUCCESS; } int fd_slot_bank_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { @@ -11310,6 +12538,8 @@ int fd_slot_bank_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * } err = fd_hard_forks_decode_footprint_inner( ctx, total_sz ); if( FD_UNLIKELY( err ) ) return err; + err = fd_epoch_reward_status_decode_footprint_inner( ctx, total_sz ); + if( FD_UNLIKELY( err ) ) return err; return 0; } void * fd_slot_bank_decode( void * mem, fd_bincode_decode_ctx_t * ctx ) { @@ -11355,6 +12585,7 @@ void fd_slot_bank_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincod } } fd_hard_forks_decode_inner( &self->hard_forks, alloc_mem, ctx ); + fd_epoch_reward_status_decode_inner( &self->epoch_reward_status, alloc_mem, ctx ); } void fd_slot_bank_new(fd_slot_bank_t * self) { fd_memset( self, 0, sizeof(fd_slot_bank_t) ); @@ -11371,6 +12602,7 @@ void fd_slot_bank_new(fd_slot_bank_t * self) { fd_block_hash_queue_new( &self->block_hash_queue ); fd_hash_new( &self->prev_banks_hash ); fd_hard_forks_new( &self->hard_forks ); + fd_epoch_reward_status_new( &self->epoch_reward_status ); } void fd_slot_bank_destroy( fd_slot_bank_t * self ) { fd_clock_timestamp_votes_destroy( &self->timestamp_votes ); @@ -11389,6 +12621,7 @@ void fd_slot_bank_destroy( fd_slot_bank_t * self ) { self->has_use_preceeding_epoch_stakes = 0; } fd_hard_forks_destroy( &self->hard_forks ); + fd_epoch_reward_status_destroy( &self->epoch_reward_status ); } ulong fd_slot_bank_footprint( void ){ return FD_SLOT_BANK_FOOTPRINT; } @@ -11426,6 +12659,7 @@ void fd_slot_bank_walk( void * w, fd_slot_bank_t const * self, fd_types_walk_fn_ fun( w, &self->use_preceeding_epoch_stakes, "use_preceeding_epoch_stakes", FD_FLAMENCO_TYPE_ULONG, "ulong", level ); } fd_hard_forks_walk( w, &self->hard_forks, fun, "hard_forks", level ); + fd_epoch_reward_status_walk( w, &self->epoch_reward_status, fun, "epoch_reward_status", level ); fun( w, self, name, FD_FLAMENCO_TYPE_MAP_END, "fd_slot_bank", level-- ); } ulong fd_slot_bank_size( fd_slot_bank_t const * self ) { @@ -11459,6 +12693,7 @@ ulong fd_slot_bank_size( fd_slot_bank_t const * self ) { size += sizeof(ulong); } size += fd_hard_forks_size( &self->hard_forks ); + size += fd_epoch_reward_status_size( &self->epoch_reward_status ); return size; } @@ -28408,10 +29643,12 @@ int fd_usage_cost_details_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong *total_sz += sizeof(fd_usage_cost_details_t); void const * start_data = ctx->data; int err = fd_usage_cost_details_decode_footprint_inner( ctx, total_sz ); + if( ctx->data>ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; ctx->data = start_data; return err; } int fd_usage_cost_details_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + if( ctx->data>=ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; int err = 0; err = fd_bincode_uint64_decode_footprint( ctx ); if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) return err; @@ -28499,10 +29736,12 @@ int fd_transaction_cost_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * *total_sz += sizeof(fd_transaction_cost_t); void const * start_data = ctx->data; int err = fd_transaction_cost_decode_footprint_inner( ctx, total_sz ); + if( ctx->data>ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; ctx->data = start_data; return err; } int fd_transaction_cost_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + if( ctx->data>=ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; uint discriminant = 0; int err = fd_bincode_uint32_decode( &discriminant, ctx ); if( FD_UNLIKELY( err ) ) return err; @@ -28520,7 +29759,7 @@ void fd_transaction_cost_inner_decode_inner( fd_transaction_cost_inner_t * self, } } void fd_transaction_cost_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ) { - fd_transaction_cost_t * self = (fd_transaction_cost_t *)struct_mem; /* #goated */ + fd_transaction_cost_t * self = (fd_transaction_cost_t *)struct_mem; fd_bincode_uint32_decode_unsafe( &self->discriminant, ctx ); fd_transaction_cost_inner_decode_inner( &self->inner, alloc_mem, self->discriminant, ctx ); } @@ -28528,7 +29767,7 @@ void * fd_transaction_cost_decode( void * mem, fd_bincode_decode_ctx_t * ctx ) { fd_transaction_cost_t * self = (fd_transaction_cost_t *)mem; fd_transaction_cost_new( self ); void * alloc_region = (uchar *)mem + sizeof(fd_transaction_cost_t); - void * * alloc_mem = &alloc_region; /* #goated */ + void * * alloc_mem = &alloc_region; fd_transaction_cost_decode_inner( mem, alloc_mem, ctx ); return self; } @@ -28624,10 +29863,12 @@ int fd_account_costs_pair_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong *total_sz += sizeof(fd_account_costs_pair_t); void const * start_data = ctx->data; int err = fd_account_costs_pair_decode_footprint_inner( ctx, total_sz ); + if( ctx->data>ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; ctx->data = start_data; return err; } int fd_account_costs_pair_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + if( ctx->data>=ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; int err = 0; err = fd_pubkey_decode_footprint_inner( ctx, total_sz ); if( FD_UNLIKELY( err ) ) return err; @@ -28693,10 +29934,12 @@ int fd_account_costs_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * to *total_sz += sizeof(fd_account_costs_t); void const * start_data = ctx->data; int err = fd_account_costs_decode_footprint_inner( ctx, total_sz ); + if( ctx->data>ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; ctx->data = start_data; return err; } int fd_account_costs_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + if( ctx->data>=ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; int err = 0; ulong account_costs_len = 0UL; err = fd_bincode_uint64_decode( &account_costs_len, ctx ); @@ -28798,10 +30041,12 @@ int fd_cost_tracker_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * tot *total_sz += sizeof(fd_cost_tracker_t); void const * start_data = ctx->data; int err = fd_cost_tracker_decode_footprint_inner( ctx, total_sz ); + if( ctx->data>ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; ctx->data = start_data; return err; } int fd_cost_tracker_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) { + if( ctx->data>=ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; }; int err = 0; err = fd_bincode_uint64_decode_footprint( ctx ); if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) return err; @@ -28952,6 +30197,13 @@ long fd_stake_pair_t_map_compare( fd_stake_pair_t_mapnode_t * left, fd_stake_pai long fd_clock_timestamp_vote_t_map_compare( fd_clock_timestamp_vote_t_mapnode_t * left, fd_clock_timestamp_vote_t_mapnode_t * right ) { return memcmp( left->elem.pubkey.uc, right->elem.pubkey.uc, sizeof(right->elem.pubkey) ); } +#define REDBLK_T fd_vote_reward_t_mapnode_t +#define REDBLK_NAME fd_vote_reward_t_map +#define REDBLK_IMPL_STYLE 2 +#include "../../util/tmpl/fd_redblack.c" +long fd_vote_reward_t_map_compare( fd_vote_reward_t_mapnode_t * left, fd_vote_reward_t_mapnode_t * right ) { + return memcmp( left->elem.pubkey.uc, right->elem.pubkey.uc, sizeof(right->elem.pubkey) ); +} #define REDBLK_T fd_vote_info_pair_t_mapnode_t #define REDBLK_NAME fd_vote_info_pair_t_map #define REDBLK_IMPL_STYLE 2 diff --git a/src/flamenco/types/fd_types.h b/src/flamenco/types/fd_types.h index e3559df80e..10c4a307ec 100644 --- a/src/flamenco/types/fd_types.h +++ b/src/flamenco/types/fd_types.h @@ -7,6 +7,7 @@ #include "fd_types_custom.h" #define FD_ACCOUNT_META_MAGIC 9823 +#include "../fd_flamenco_base.h" /* sdk/program/src/feature.rs#L22 */ /* Encoded Size: Dynamic */ struct __attribute__((aligned(8UL))) fd_feature { @@ -2720,6 +2721,374 @@ typedef struct fd_epoch_bank_off fd_epoch_bank_off_t; #define FD_EPOCH_BANK_OFF_FOOTPRINT sizeof(fd_epoch_bank_off_t) #define FD_EPOCH_BANK_OFF_ALIGN (16UL) +/* Encoded Size: Fixed (73 bytes) */ +struct __attribute__((aligned(8UL))) fd_stake_reward { + ulong prev; + ulong next; + ulong parent; + fd_pubkey_t stake_pubkey; + ulong credits_observed; + ulong lamports; + uchar valid; +}; +typedef struct fd_stake_reward fd_stake_reward_t; +#define FD_STAKE_REWARD_FOOTPRINT sizeof(fd_stake_reward_t) +#define FD_STAKE_REWARD_ALIGN (8UL) + +struct __attribute__((aligned(8UL))) fd_stake_reward_off { + uint prev_off; + uint next_off; + uint parent_off; + uint stake_pubkey_off; + uint credits_observed_off; + uint lamports_off; + uint valid_off; +}; +typedef struct fd_stake_reward_off fd_stake_reward_off_t; +#define FD_STAKE_REWARD_OFF_FOOTPRINT sizeof(fd_stake_reward_off_t) +#define FD_STAKE_REWARD_OFF_ALIGN (8UL) + +/* Encoded Size: Fixed (42 bytes) */ +struct __attribute__((aligned(8UL))) fd_vote_reward { + fd_pubkey_t pubkey; + ulong vote_rewards; + uchar commission; + uchar needs_store; +}; +typedef struct fd_vote_reward fd_vote_reward_t; +#define FD_VOTE_REWARD_FOOTPRINT sizeof(fd_vote_reward_t) +#define FD_VOTE_REWARD_ALIGN (8UL) + +struct __attribute__((aligned(8UL))) fd_vote_reward_off { + uint pubkey_off; + uint vote_rewards_off; + uint commission_off; + uint needs_store_off; +}; +typedef struct fd_vote_reward_off fd_vote_reward_off_t; +#define FD_VOTE_REWARD_OFF_FOOTPRINT sizeof(fd_vote_reward_off_t) +#define FD_VOTE_REWARD_OFF_ALIGN (8UL) + +/* https://github.com/anza-xyz/agave/blob/cbc8320d35358da14d79ebcada4dfb6756ffac79/programs/stake/src/points.rs#L21 */ +/* Encoded Size: Fixed (24 bytes) */ +struct __attribute__((aligned(8UL))) fd_point_value { + ulong rewards; + uint128 points; +}; +typedef struct fd_point_value fd_point_value_t; +#define FD_POINT_VALUE_FOOTPRINT sizeof(fd_point_value_t) +#define FD_POINT_VALUE_ALIGN (8UL) + +struct __attribute__((aligned(8UL))) fd_point_value_off { + uint rewards_off; + uint points_off; +}; +typedef struct fd_point_value_off fd_point_value_off_t; +#define FD_POINT_VALUE_OFF_FOOTPRINT sizeof(fd_point_value_off_t) +#define FD_POINT_VALUE_OFF_ALIGN (8UL) + +#define POOL_NAME fd_partitioned_stake_rewards_pool +#define POOL_T fd_stake_reward_t +#define POOL_NEXT parent +#include "../../util/tmpl/fd_pool.c" +static inline fd_stake_reward_t * +fd_partitioned_stake_rewards_pool_alloc( fd_valloc_t valloc, ulong num ) { + if( FD_UNLIKELY( 0 == num ) ) num = 1; // prevent underflow + return fd_partitioned_stake_rewards_pool_join( fd_partitioned_stake_rewards_pool_new( + fd_valloc_malloc( valloc, + fd_partitioned_stake_rewards_pool_align(), + fd_partitioned_stake_rewards_pool_footprint( num ) ), + num ) ); +} +static inline fd_stake_reward_t * +fd_partitioned_stake_rewards_pool_join_new( void * * alloc_mem, ulong num ) { + if( FD_UNLIKELY( 0 == num ) ) num = 1; // prevent underflow + *alloc_mem = (void*)fd_ulong_align_up( (ulong)*alloc_mem, fd_partitioned_stake_rewards_pool_align() ); + void * pool_mem = *alloc_mem; + *alloc_mem = (uchar *)*alloc_mem + fd_partitioned_stake_rewards_pool_footprint( num ); + return fd_partitioned_stake_rewards_pool_join( fd_partitioned_stake_rewards_pool_new( pool_mem, num ) ); +} +#define DLIST_NAME fd_partitioned_stake_rewards_dlist +#define DLIST_ELE_T fd_stake_reward_t +#include "../../util/tmpl/fd_dlist.c" +static inline fd_partitioned_stake_rewards_dlist_t * +fd_partitioned_stake_rewards_dlist_alloc( fd_valloc_t valloc, ulong num ) { + if( FD_UNLIKELY( 0 == num ) ) num = 1; // prevent underflow + return fd_partitioned_stake_rewards_dlist_join( fd_partitioned_stake_rewards_dlist_new( + fd_valloc_malloc( valloc, + fd_partitioned_stake_rewards_dlist_align(), + fd_partitioned_stake_rewards_dlist_footprint() ) ) ); +} +static inline fd_partitioned_stake_rewards_dlist_t * +fd_partitioned_stake_rewards_dlist_join_new( void * * alloc_mem, ulong num ) { + if( FD_UNLIKELY( 0 == num ) ) num = 1; // prevent underflow + *alloc_mem = (void*)fd_ulong_align_up( (ulong)*alloc_mem, fd_partitioned_stake_rewards_dlist_align() ); + void * dlist_mem = *alloc_mem; + *alloc_mem = (uchar *)*alloc_mem + fd_partitioned_stake_rewards_dlist_footprint(); + return fd_partitioned_stake_rewards_dlist_join( fd_partitioned_stake_rewards_dlist_new( dlist_mem ) ); +} +/* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L56 */ +/* Encoded Size: Dynamic */ +struct __attribute__((aligned(8UL))) fd_partitioned_stake_rewards { + ulong partitions_len; + ulong partitions_lengths[4096]; + fd_partitioned_stake_rewards_dlist_t * partitions; + fd_stake_reward_t * pool; +}; +typedef struct fd_partitioned_stake_rewards fd_partitioned_stake_rewards_t; +#define FD_PARTITIONED_STAKE_REWARDS_FOOTPRINT sizeof(fd_partitioned_stake_rewards_t) +#define FD_PARTITIONED_STAKE_REWARDS_ALIGN (8UL) + +struct __attribute__((aligned(8UL))) fd_partitioned_stake_rewards_off { + uint fd_partitioned_stake_rewards_off; +}; +typedef struct fd_partitioned_stake_rewards_off fd_partitioned_stake_rewards_off_t; +#define FD_PARTITIONED_STAKE_REWARDS_OFF_FOOTPRINT sizeof(fd_partitioned_stake_rewards_off_t) +#define FD_PARTITIONED_STAKE_REWARDS_OFF_ALIGN (8UL) + +/* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L131 */ +/* Encoded Size: Dynamic */ +struct __attribute__((aligned(8UL))) fd_stake_reward_calculation_partitioned { + fd_partitioned_stake_rewards_t partitioned_stake_rewards; + ulong total_stake_rewards_lamports; +}; +typedef struct fd_stake_reward_calculation_partitioned fd_stake_reward_calculation_partitioned_t; +#define FD_STAKE_REWARD_CALCULATION_PARTITIONED_FOOTPRINT sizeof(fd_stake_reward_calculation_partitioned_t) +#define FD_STAKE_REWARD_CALCULATION_PARTITIONED_ALIGN (8UL) + +struct __attribute__((aligned(8UL))) fd_stake_reward_calculation_partitioned_off { + uint partitioned_stake_rewards_off; + uint total_stake_rewards_lamports_off; +}; +typedef struct fd_stake_reward_calculation_partitioned_off fd_stake_reward_calculation_partitioned_off_t; +#define FD_STAKE_REWARD_CALCULATION_PARTITIONED_OFF_FOOTPRINT sizeof(fd_stake_reward_calculation_partitioned_off_t) +#define FD_STAKE_REWARD_CALCULATION_PARTITIONED_OFF_ALIGN (8UL) + +#define POOL_NAME fd_stake_reward_calculation_pool +#define POOL_T fd_stake_reward_t +#define POOL_NEXT parent +#include "../../util/tmpl/fd_pool.c" +static inline fd_stake_reward_t * +fd_stake_reward_calculation_pool_alloc( fd_valloc_t valloc, ulong num ) { + if( FD_UNLIKELY( 0 == num ) ) num = 1; // prevent underflow + return fd_stake_reward_calculation_pool_join( fd_stake_reward_calculation_pool_new( + fd_valloc_malloc( valloc, + fd_stake_reward_calculation_pool_align(), + fd_stake_reward_calculation_pool_footprint( num ) ), + num ) ); +} +static inline fd_stake_reward_t * +fd_stake_reward_calculation_pool_join_new( void * * alloc_mem, ulong num ) { + if( FD_UNLIKELY( 0 == num ) ) num = 1; // prevent underflow + *alloc_mem = (void*)fd_ulong_align_up( (ulong)*alloc_mem, fd_stake_reward_calculation_pool_align() ); + void * pool_mem = *alloc_mem; + *alloc_mem = (uchar *)*alloc_mem + fd_stake_reward_calculation_pool_footprint( num ); + return fd_stake_reward_calculation_pool_join( fd_stake_reward_calculation_pool_new( pool_mem, num ) ); +} +#define DLIST_NAME fd_stake_reward_calculation_dlist +#define DLIST_ELE_T fd_stake_reward_t +#include "../../util/tmpl/fd_dlist.c" +static inline fd_stake_reward_calculation_dlist_t * +fd_stake_reward_calculation_dlist_alloc( fd_valloc_t valloc, ulong num ) { + if( FD_UNLIKELY( 0 == num ) ) num = 1; // prevent underflow + return fd_stake_reward_calculation_dlist_join( fd_stake_reward_calculation_dlist_new( + fd_valloc_malloc( valloc, + fd_stake_reward_calculation_dlist_align(), + fd_stake_reward_calculation_dlist_footprint() ) ) ); +} +static inline fd_stake_reward_calculation_dlist_t * +fd_stake_reward_calculation_dlist_join_new( void * * alloc_mem, ulong num ) { + if( FD_UNLIKELY( 0 == num ) ) num = 1; // prevent underflow + *alloc_mem = (void*)fd_ulong_align_up( (ulong)*alloc_mem, fd_stake_reward_calculation_dlist_align() ); + void * dlist_mem = *alloc_mem; + *alloc_mem = (uchar *)*alloc_mem + fd_stake_reward_calculation_dlist_footprint(); + return fd_stake_reward_calculation_dlist_join( fd_stake_reward_calculation_dlist_new( dlist_mem ) ); +} +/* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L94 */ +/* Encoded Size: Dynamic */ +struct __attribute__((aligned(8UL))) fd_stake_reward_calculation { + ulong stake_rewards_len; + ulong stake_rewards_lengths[1]; + fd_stake_reward_calculation_dlist_t * stake_rewards; + fd_stake_reward_t * pool; + ulong total_stake_rewards_lamports; +}; +typedef struct fd_stake_reward_calculation fd_stake_reward_calculation_t; +#define FD_STAKE_REWARD_CALCULATION_FOOTPRINT sizeof(fd_stake_reward_calculation_t) +#define FD_STAKE_REWARD_CALCULATION_ALIGN (8UL) + +struct __attribute__((aligned(8UL))) fd_stake_reward_calculation_off { + uint fd_stake_reward_calculation_off; + uint total_stake_rewards_lamports_off; +}; +typedef struct fd_stake_reward_calculation_off fd_stake_reward_calculation_off_t; +#define FD_STAKE_REWARD_CALCULATION_OFF_FOOTPRINT sizeof(fd_stake_reward_calculation_off_t) +#define FD_STAKE_REWARD_CALCULATION_OFF_ALIGN (8UL) + +typedef struct fd_vote_reward_t_mapnode fd_vote_reward_t_mapnode_t; +#define REDBLK_T fd_vote_reward_t_mapnode_t +#define REDBLK_NAME fd_vote_reward_t_map +#define REDBLK_IMPL_STYLE 1 +#include "../../util/tmpl/fd_redblack.c" +struct fd_vote_reward_t_mapnode { + fd_vote_reward_t elem; + ulong redblack_parent; + ulong redblack_left; + ulong redblack_right; + int redblack_color; +}; +static inline fd_vote_reward_t_mapnode_t * +fd_vote_reward_t_map_alloc( fd_valloc_t valloc, ulong len ) { + if( FD_UNLIKELY( 0 == len ) ) len = 1; // prevent underflow + void * mem = fd_valloc_malloc( valloc, fd_vote_reward_t_map_align(), fd_vote_reward_t_map_footprint(len)); + return fd_vote_reward_t_map_join(fd_vote_reward_t_map_new(mem, len)); +} +static inline fd_vote_reward_t_mapnode_t * +fd_vote_reward_t_map_join_new( void * * alloc_mem, ulong len ) { + if( FD_UNLIKELY( 0 == len ) ) len = 1; // prevent underflow + *alloc_mem = (void*)fd_ulong_align_up( (ulong)*alloc_mem, fd_vote_reward_t_map_align() ); + void * map_mem = *alloc_mem; + *alloc_mem = (uchar *)*alloc_mem + fd_vote_reward_t_map_footprint( len ); + return fd_vote_reward_t_map_join( fd_vote_reward_t_map_new( map_mem, len ) ); +} +/* Encoded Size: Dynamic */ +struct __attribute__((aligned(8UL))) fd_calculate_stake_vote_rewards_result { + fd_stake_reward_calculation_t stake_reward_calculation; + fd_vote_reward_t_mapnode_t * vote_reward_map_pool; + fd_vote_reward_t_mapnode_t * vote_reward_map_root; +}; +typedef struct fd_calculate_stake_vote_rewards_result fd_calculate_stake_vote_rewards_result_t; +#define FD_CALCULATE_STAKE_VOTE_REWARDS_RESULT_FOOTPRINT sizeof(fd_calculate_stake_vote_rewards_result_t) +#define FD_CALCULATE_STAKE_VOTE_REWARDS_RESULT_ALIGN (8UL) + +struct __attribute__((aligned(8UL))) fd_calculate_stake_vote_rewards_result_off { + uint stake_reward_calculation_off; + uint vote_reward_map_off; +}; +typedef struct fd_calculate_stake_vote_rewards_result_off fd_calculate_stake_vote_rewards_result_off_t; +#define FD_CALCULATE_STAKE_VOTE_REWARDS_RESULT_OFF_FOOTPRINT sizeof(fd_calculate_stake_vote_rewards_result_off_t) +#define FD_CALCULATE_STAKE_VOTE_REWARDS_RESULT_OFF_ALIGN (8UL) + +/* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L102 */ +/* Encoded Size: Dynamic */ +struct __attribute__((aligned(8UL))) fd_calculate_validator_rewards_result { + fd_calculate_stake_vote_rewards_result_t calculate_stake_vote_rewards_result; + fd_point_value_t point_value; +}; +typedef struct fd_calculate_validator_rewards_result fd_calculate_validator_rewards_result_t; +#define FD_CALCULATE_VALIDATOR_REWARDS_RESULT_FOOTPRINT sizeof(fd_calculate_validator_rewards_result_t) +#define FD_CALCULATE_VALIDATOR_REWARDS_RESULT_ALIGN (8UL) + +struct __attribute__((aligned(8UL))) fd_calculate_validator_rewards_result_off { + uint calculate_stake_vote_rewards_result_off; + uint point_value_off; +}; +typedef struct fd_calculate_validator_rewards_result_off fd_calculate_validator_rewards_result_off_t; +#define FD_CALCULATE_VALIDATOR_REWARDS_RESULT_OFF_FOOTPRINT sizeof(fd_calculate_validator_rewards_result_off_t) +#define FD_CALCULATE_VALIDATOR_REWARDS_RESULT_OFF_ALIGN (8UL) + +/* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L138 */ +/* Encoded Size: Dynamic */ +struct __attribute__((aligned(8UL))) fd_calculate_rewards_and_distribute_vote_rewards_result { + ulong total_rewards; + ulong distributed_rewards; + fd_point_value_t point_value; + fd_stake_reward_calculation_partitioned_t stake_rewards_by_partition; +}; +typedef struct fd_calculate_rewards_and_distribute_vote_rewards_result fd_calculate_rewards_and_distribute_vote_rewards_result_t; +#define FD_CALCULATE_REWARDS_AND_DISTRIBUTE_VOTE_REWARDS_RESULT_FOOTPRINT sizeof(fd_calculate_rewards_and_distribute_vote_rewards_result_t) +#define FD_CALCULATE_REWARDS_AND_DISTRIBUTE_VOTE_REWARDS_RESULT_ALIGN (8UL) + +struct __attribute__((aligned(8UL))) fd_calculate_rewards_and_distribute_vote_rewards_result_off { + uint total_rewards_off; + uint distributed_rewards_off; + uint point_value_off; + uint stake_rewards_by_partition_off; +}; +typedef struct fd_calculate_rewards_and_distribute_vote_rewards_result_off fd_calculate_rewards_and_distribute_vote_rewards_result_off_t; +#define FD_CALCULATE_REWARDS_AND_DISTRIBUTE_VOTE_REWARDS_RESULT_OFF_FOOTPRINT sizeof(fd_calculate_rewards_and_distribute_vote_rewards_result_off_t) +#define FD_CALCULATE_REWARDS_AND_DISTRIBUTE_VOTE_REWARDS_RESULT_OFF_ALIGN (8UL) + +/* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L118 */ +/* Encoded Size: Dynamic */ +struct __attribute__((aligned(8UL))) fd_partitioned_rewards_calculation { + fd_vote_reward_t_mapnode_t * vote_reward_map_pool; + fd_vote_reward_t_mapnode_t * vote_reward_map_root; + fd_stake_reward_calculation_partitioned_t stake_rewards_by_partition; + ulong old_vote_balance_and_staked; + ulong validator_rewards; + double validator_rate; + double foundation_rate; + double prev_epoch_duration_in_years; + ulong capitalization; + fd_point_value_t point_value; +}; +typedef struct fd_partitioned_rewards_calculation fd_partitioned_rewards_calculation_t; +#define FD_PARTITIONED_REWARDS_CALCULATION_FOOTPRINT sizeof(fd_partitioned_rewards_calculation_t) +#define FD_PARTITIONED_REWARDS_CALCULATION_ALIGN (8UL) + +struct __attribute__((aligned(8UL))) fd_partitioned_rewards_calculation_off { + uint vote_reward_map_off; + uint stake_rewards_by_partition_off; + uint old_vote_balance_and_staked_off; + uint validator_rewards_off; + uint validator_rate_off; + uint foundation_rate_off; + uint prev_epoch_duration_in_years_off; + uint capitalization_off; + uint point_value_off; +}; +typedef struct fd_partitioned_rewards_calculation_off fd_partitioned_rewards_calculation_off_t; +#define FD_PARTITIONED_REWARDS_CALCULATION_OFF_FOOTPRINT sizeof(fd_partitioned_rewards_calculation_off_t) +#define FD_PARTITIONED_REWARDS_CALCULATION_OFF_ALIGN (8UL) + +/* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L60 */ +/* Encoded Size: Dynamic */ +struct __attribute__((aligned(8UL))) fd_start_block_height_and_rewards { + ulong distribution_starting_block_height; + fd_partitioned_stake_rewards_t partitioned_stake_rewards; +}; +typedef struct fd_start_block_height_and_rewards fd_start_block_height_and_rewards_t; +#define FD_START_BLOCK_HEIGHT_AND_REWARDS_FOOTPRINT sizeof(fd_start_block_height_and_rewards_t) +#define FD_START_BLOCK_HEIGHT_AND_REWARDS_ALIGN (8UL) + +struct __attribute__((aligned(8UL))) fd_start_block_height_and_rewards_off { + uint distribution_starting_block_height_off; + uint partitioned_stake_rewards_off; +}; +typedef struct fd_start_block_height_and_rewards_off fd_start_block_height_and_rewards_off_t; +#define FD_START_BLOCK_HEIGHT_AND_REWARDS_OFF_FOOTPRINT sizeof(fd_start_block_height_and_rewards_off_t) +#define FD_START_BLOCK_HEIGHT_AND_REWARDS_OFF_ALIGN (8UL) + +/* Encoded Size: Dynamic */ +struct __attribute__((aligned(8UL))) fd_fd_epoch_reward_status_inner { + fd_start_block_height_and_rewards_t Active; +}; +typedef struct fd_fd_epoch_reward_status_inner fd_fd_epoch_reward_status_inner_t; +#define FD_FD_EPOCH_REWARD_STATUS_INNER_FOOTPRINT sizeof(fd_fd_epoch_reward_status_inner_t) +#define FD_FD_EPOCH_REWARD_STATUS_INNER_ALIGN (8UL) + +struct __attribute__((aligned(8UL))) fd_fd_epoch_reward_status_inner_off { + uint Active_off; +}; +typedef struct fd_fd_epoch_reward_status_inner_off fd_fd_epoch_reward_status_inner_off_t; +#define FD_FD_EPOCH_REWARD_STATUS_INNER_OFF_FOOTPRINT sizeof(fd_fd_epoch_reward_status_inner_off_t) +#define FD_FD_EPOCH_REWARD_STATUS_INNER_OFF_ALIGN (8UL) + +union fd_epoch_reward_status_inner { + fd_start_block_height_and_rewards_t Active; +}; +typedef union fd_epoch_reward_status_inner fd_epoch_reward_status_inner_t; + +/* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L70 */ +struct fd_epoch_reward_status { + uint discriminant; + fd_epoch_reward_status_inner_t inner; +}; +typedef struct fd_epoch_reward_status fd_epoch_reward_status_t; +#define FD_EPOCH_REWARD_STATUS_FOOTPRINT sizeof(fd_epoch_reward_status_t) +#define FD_EPOCH_REWARD_STATUS_ALIGN (8UL) + /* Encoded Size: Dynamic */ struct __attribute__((aligned(128UL))) fd_slot_bank { fd_clock_timestamp_votes_t timestamp_votes; @@ -2749,6 +3118,7 @@ struct __attribute__((aligned(128UL))) fd_slot_bank { ulong use_preceeding_epoch_stakes; uchar has_use_preceeding_epoch_stakes; fd_hard_forks_t hard_forks; + fd_epoch_reward_status_t epoch_reward_status; }; typedef struct fd_slot_bank fd_slot_bank_t; #define FD_SLOT_BANK_FOOTPRINT sizeof(fd_slot_bank_t) @@ -2781,6 +3151,7 @@ struct __attribute__((aligned(128UL))) fd_slot_bank_off { uint tick_height_off; uint use_preceeding_epoch_stakes_off; uint hard_forks_off; + uint epoch_reward_status_off; }; typedef struct fd_slot_bank_off fd_slot_bank_off_t; #define FD_SLOT_BANK_OFF_FOOTPRINT sizeof(fd_slot_bank_off_t) @@ -6753,6 +7124,169 @@ int fd_epoch_bank_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * void * fd_epoch_bank_decode( void * mem, fd_bincode_decode_ctx_t * ctx ); void fd_epoch_bank_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ); +void fd_stake_reward_new( fd_stake_reward_t * self ); +int fd_stake_reward_encode( fd_stake_reward_t const * self, fd_bincode_encode_ctx_t * ctx ); +void fd_stake_reward_destroy( fd_stake_reward_t * self ); +void fd_stake_reward_walk( void * w, fd_stake_reward_t const * self, fd_types_walk_fn_t fun, const char *name, uint level ); +ulong fd_stake_reward_size( fd_stake_reward_t const * self ); +ulong fd_stake_reward_footprint( void ); +ulong fd_stake_reward_align( void ); +int fd_stake_reward_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); +int fd_stake_reward_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); +void * fd_stake_reward_decode( void * mem, fd_bincode_decode_ctx_t * ctx ); +void fd_stake_reward_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ); + +void fd_vote_reward_new( fd_vote_reward_t * self ); +int fd_vote_reward_encode( fd_vote_reward_t const * self, fd_bincode_encode_ctx_t * ctx ); +void fd_vote_reward_destroy( fd_vote_reward_t * self ); +void fd_vote_reward_walk( void * w, fd_vote_reward_t const * self, fd_types_walk_fn_t fun, const char *name, uint level ); +ulong fd_vote_reward_size( fd_vote_reward_t const * self ); +ulong fd_vote_reward_footprint( void ); +ulong fd_vote_reward_align( void ); +int fd_vote_reward_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); +int fd_vote_reward_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); +void * fd_vote_reward_decode( void * mem, fd_bincode_decode_ctx_t * ctx ); +void fd_vote_reward_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ); + +void fd_point_value_new( fd_point_value_t * self ); +int fd_point_value_encode( fd_point_value_t const * self, fd_bincode_encode_ctx_t * ctx ); +void fd_point_value_destroy( fd_point_value_t * self ); +void fd_point_value_walk( void * w, fd_point_value_t const * self, fd_types_walk_fn_t fun, const char *name, uint level ); +ulong fd_point_value_size( fd_point_value_t const * self ); +ulong fd_point_value_footprint( void ); +ulong fd_point_value_align( void ); +int fd_point_value_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); +int fd_point_value_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); +void * fd_point_value_decode( void * mem, fd_bincode_decode_ctx_t * ctx ); +void fd_point_value_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ); + +void fd_partitioned_stake_rewards_new( fd_partitioned_stake_rewards_t * self ); +int fd_partitioned_stake_rewards_encode( fd_partitioned_stake_rewards_t const * self, fd_bincode_encode_ctx_t * ctx ); +void fd_partitioned_stake_rewards_destroy( fd_partitioned_stake_rewards_t * self ); +void fd_partitioned_stake_rewards_walk( void * w, fd_partitioned_stake_rewards_t const * self, fd_types_walk_fn_t fun, const char *name, uint level ); +ulong fd_partitioned_stake_rewards_size( fd_partitioned_stake_rewards_t const * self ); +ulong fd_partitioned_stake_rewards_footprint( void ); +ulong fd_partitioned_stake_rewards_align( void ); +int fd_partitioned_stake_rewards_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); +int fd_partitioned_stake_rewards_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); +void * fd_partitioned_stake_rewards_decode( void * mem, fd_bincode_decode_ctx_t * ctx ); +void fd_partitioned_stake_rewards_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ); + +void fd_stake_reward_calculation_partitioned_new( fd_stake_reward_calculation_partitioned_t * self ); +int fd_stake_reward_calculation_partitioned_encode( fd_stake_reward_calculation_partitioned_t const * self, fd_bincode_encode_ctx_t * ctx ); +void fd_stake_reward_calculation_partitioned_destroy( fd_stake_reward_calculation_partitioned_t * self ); +void fd_stake_reward_calculation_partitioned_walk( void * w, fd_stake_reward_calculation_partitioned_t const * self, fd_types_walk_fn_t fun, const char *name, uint level ); +ulong fd_stake_reward_calculation_partitioned_size( fd_stake_reward_calculation_partitioned_t const * self ); +ulong fd_stake_reward_calculation_partitioned_footprint( void ); +ulong fd_stake_reward_calculation_partitioned_align( void ); +int fd_stake_reward_calculation_partitioned_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); +int fd_stake_reward_calculation_partitioned_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); +void * fd_stake_reward_calculation_partitioned_decode( void * mem, fd_bincode_decode_ctx_t * ctx ); +void fd_stake_reward_calculation_partitioned_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ); + +void fd_stake_reward_calculation_new( fd_stake_reward_calculation_t * self ); +int fd_stake_reward_calculation_encode( fd_stake_reward_calculation_t const * self, fd_bincode_encode_ctx_t * ctx ); +void fd_stake_reward_calculation_destroy( fd_stake_reward_calculation_t * self ); +void fd_stake_reward_calculation_walk( void * w, fd_stake_reward_calculation_t const * self, fd_types_walk_fn_t fun, const char *name, uint level ); +ulong fd_stake_reward_calculation_size( fd_stake_reward_calculation_t const * self ); +ulong fd_stake_reward_calculation_footprint( void ); +ulong fd_stake_reward_calculation_align( void ); +int fd_stake_reward_calculation_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); +int fd_stake_reward_calculation_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); +void * fd_stake_reward_calculation_decode( void * mem, fd_bincode_decode_ctx_t * ctx ); +void fd_stake_reward_calculation_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ); + +void fd_calculate_stake_vote_rewards_result_new( fd_calculate_stake_vote_rewards_result_t * self ); +int fd_calculate_stake_vote_rewards_result_encode( fd_calculate_stake_vote_rewards_result_t const * self, fd_bincode_encode_ctx_t * ctx ); +void fd_calculate_stake_vote_rewards_result_destroy( fd_calculate_stake_vote_rewards_result_t * self ); +void fd_calculate_stake_vote_rewards_result_walk( void * w, fd_calculate_stake_vote_rewards_result_t const * self, fd_types_walk_fn_t fun, const char *name, uint level ); +ulong fd_calculate_stake_vote_rewards_result_size( fd_calculate_stake_vote_rewards_result_t const * self ); +ulong fd_calculate_stake_vote_rewards_result_footprint( void ); +ulong fd_calculate_stake_vote_rewards_result_align( void ); +int fd_calculate_stake_vote_rewards_result_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); +int fd_calculate_stake_vote_rewards_result_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); +void * fd_calculate_stake_vote_rewards_result_decode( void * mem, fd_bincode_decode_ctx_t * ctx ); +void fd_calculate_stake_vote_rewards_result_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ); + +void fd_calculate_validator_rewards_result_new( fd_calculate_validator_rewards_result_t * self ); +int fd_calculate_validator_rewards_result_encode( fd_calculate_validator_rewards_result_t const * self, fd_bincode_encode_ctx_t * ctx ); +void fd_calculate_validator_rewards_result_destroy( fd_calculate_validator_rewards_result_t * self ); +void fd_calculate_validator_rewards_result_walk( void * w, fd_calculate_validator_rewards_result_t const * self, fd_types_walk_fn_t fun, const char *name, uint level ); +ulong fd_calculate_validator_rewards_result_size( fd_calculate_validator_rewards_result_t const * self ); +ulong fd_calculate_validator_rewards_result_footprint( void ); +ulong fd_calculate_validator_rewards_result_align( void ); +int fd_calculate_validator_rewards_result_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); +int fd_calculate_validator_rewards_result_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); +void * fd_calculate_validator_rewards_result_decode( void * mem, fd_bincode_decode_ctx_t * ctx ); +void fd_calculate_validator_rewards_result_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ); + +void fd_calculate_rewards_and_distribute_vote_rewards_result_new( fd_calculate_rewards_and_distribute_vote_rewards_result_t * self ); +int fd_calculate_rewards_and_distribute_vote_rewards_result_encode( fd_calculate_rewards_and_distribute_vote_rewards_result_t const * self, fd_bincode_encode_ctx_t * ctx ); +void fd_calculate_rewards_and_distribute_vote_rewards_result_destroy( fd_calculate_rewards_and_distribute_vote_rewards_result_t * self ); +void fd_calculate_rewards_and_distribute_vote_rewards_result_walk( void * w, fd_calculate_rewards_and_distribute_vote_rewards_result_t const * self, fd_types_walk_fn_t fun, const char *name, uint level ); +ulong fd_calculate_rewards_and_distribute_vote_rewards_result_size( fd_calculate_rewards_and_distribute_vote_rewards_result_t const * self ); +ulong fd_calculate_rewards_and_distribute_vote_rewards_result_footprint( void ); +ulong fd_calculate_rewards_and_distribute_vote_rewards_result_align( void ); +int fd_calculate_rewards_and_distribute_vote_rewards_result_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); +int fd_calculate_rewards_and_distribute_vote_rewards_result_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); +void * fd_calculate_rewards_and_distribute_vote_rewards_result_decode( void * mem, fd_bincode_decode_ctx_t * ctx ); +void fd_calculate_rewards_and_distribute_vote_rewards_result_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ); + +void fd_partitioned_rewards_calculation_new( fd_partitioned_rewards_calculation_t * self ); +int fd_partitioned_rewards_calculation_encode( fd_partitioned_rewards_calculation_t const * self, fd_bincode_encode_ctx_t * ctx ); +void fd_partitioned_rewards_calculation_destroy( fd_partitioned_rewards_calculation_t * self ); +void fd_partitioned_rewards_calculation_walk( void * w, fd_partitioned_rewards_calculation_t const * self, fd_types_walk_fn_t fun, const char *name, uint level ); +ulong fd_partitioned_rewards_calculation_size( fd_partitioned_rewards_calculation_t const * self ); +ulong fd_partitioned_rewards_calculation_footprint( void ); +ulong fd_partitioned_rewards_calculation_align( void ); +int fd_partitioned_rewards_calculation_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); +int fd_partitioned_rewards_calculation_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); +void * fd_partitioned_rewards_calculation_decode( void * mem, fd_bincode_decode_ctx_t * ctx ); +void fd_partitioned_rewards_calculation_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ); + +void fd_start_block_height_and_rewards_new( fd_start_block_height_and_rewards_t * self ); +int fd_start_block_height_and_rewards_encode( fd_start_block_height_and_rewards_t const * self, fd_bincode_encode_ctx_t * ctx ); +void fd_start_block_height_and_rewards_destroy( fd_start_block_height_and_rewards_t * self ); +void fd_start_block_height_and_rewards_walk( void * w, fd_start_block_height_and_rewards_t const * self, fd_types_walk_fn_t fun, const char *name, uint level ); +ulong fd_start_block_height_and_rewards_size( fd_start_block_height_and_rewards_t const * self ); +ulong fd_start_block_height_and_rewards_footprint( void ); +ulong fd_start_block_height_and_rewards_align( void ); +int fd_start_block_height_and_rewards_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); +int fd_start_block_height_and_rewards_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); +void * fd_start_block_height_and_rewards_decode( void * mem, fd_bincode_decode_ctx_t * ctx ); +void fd_start_block_height_and_rewards_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ); + +void fd_fd_epoch_reward_status_inner_new( fd_fd_epoch_reward_status_inner_t * self ); +int fd_fd_epoch_reward_status_inner_encode( fd_fd_epoch_reward_status_inner_t const * self, fd_bincode_encode_ctx_t * ctx ); +void fd_fd_epoch_reward_status_inner_destroy( fd_fd_epoch_reward_status_inner_t * self ); +void fd_fd_epoch_reward_status_inner_walk( void * w, fd_fd_epoch_reward_status_inner_t const * self, fd_types_walk_fn_t fun, const char *name, uint level ); +ulong fd_fd_epoch_reward_status_inner_size( fd_fd_epoch_reward_status_inner_t const * self ); +ulong fd_fd_epoch_reward_status_inner_footprint( void ); +ulong fd_fd_epoch_reward_status_inner_align( void ); +int fd_fd_epoch_reward_status_inner_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); +int fd_fd_epoch_reward_status_inner_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); +void * fd_fd_epoch_reward_status_inner_decode( void * mem, fd_bincode_decode_ctx_t * ctx ); +void fd_fd_epoch_reward_status_inner_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ); + +void fd_epoch_reward_status_new_disc( fd_epoch_reward_status_t * self, uint discriminant ); +void fd_epoch_reward_status_new( fd_epoch_reward_status_t * self ); +int fd_epoch_reward_status_encode( fd_epoch_reward_status_t const * self, fd_bincode_encode_ctx_t * ctx ); +void fd_epoch_reward_status_destroy( fd_epoch_reward_status_t * self ); +void fd_epoch_reward_status_walk( void * w, fd_epoch_reward_status_t const * self, fd_types_walk_fn_t fun, const char *name, uint level ); +ulong fd_epoch_reward_status_size( fd_epoch_reward_status_t const * self ); +ulong fd_epoch_reward_status_footprint( void ); +ulong fd_epoch_reward_status_align( void ); +int fd_epoch_reward_status_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); +int fd_epoch_reward_status_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ); +void * fd_epoch_reward_status_decode( void * mem, fd_bincode_decode_ctx_t * ctx ); +void fd_epoch_reward_status_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ); + +FD_FN_PURE uchar fd_epoch_reward_status_is_Active( fd_epoch_reward_status_t const * self ); +FD_FN_PURE uchar fd_epoch_reward_status_is_Inactive( fd_epoch_reward_status_t const * self ); +enum { +fd_epoch_reward_status_enum_Active = 0, +fd_epoch_reward_status_enum_Inactive = 1, +}; void fd_slot_bank_new( fd_slot_bank_t * self ); int fd_slot_bank_encode( fd_slot_bank_t const * self, fd_bincode_encode_ctx_t * ctx ); void fd_slot_bank_destroy( fd_slot_bank_t * self ); diff --git a/src/flamenco/types/fd_types.json b/src/flamenco/types/fd_types.json index a1b2836991..ef342d2c92 100644 --- a/src/flamenco/types/fd_types.json +++ b/src/flamenco/types/fd_types.json @@ -1167,6 +1167,140 @@ { "name": "rent_epoch_schedule", "type": "epoch_schedule" } ] }, + { + "name": "stake_reward", + "type": "struct", + "alignment": "8", + "fields": [ + { "name": "prev", "type": "ulong" }, + { "name": "next", "type": "ulong" }, + { "name": "parent", "type": "ulong" }, + { "name": "stake_pubkey", "type": "pubkey"}, + { "name": "credits_observed", "type": "ulong" }, + { "name": "lamports", "type": "ulong" }, + { "name": "valid", "type": "uchar" } + + ] + }, + { + "name": "vote_reward", + "type": "struct", + "alignment": "8", + "fields": [ + { "name": "pubkey", "type": "pubkey" }, + { "name": "vote_rewards", "type": "ulong" }, + { "name": "commission", "type": "uchar" }, + { "name": "needs_store", "type": "uchar" } + ] + }, + { + "name": "point_value", + "type": "struct", + "alignment": "8", + "fields": [ + { "name": "rewards", "type": "ulong" }, + { "name": "points", "type": "uint128" } + ], + "comment": "https://github.com/anza-xyz/agave/blob/cbc8320d35358da14d79ebcada4dfb6756ffac79/programs/stake/src/points.rs#L21" + }, + { + "name": "partitioned_stake_rewards", + "type": "struct", + "alignment": "8", + "fields": [ + { "name": "partitions", "type": "dlist", "dlist_t": "fd_stake_reward_t", "dlist_n": "fd_partitioned_stake_rewards", "dlist_max": "4096" } + ], + "comment": "https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L56" + }, + { + "name": "stake_reward_calculation_partitioned", + "type": "struct", + "alignment": "8", + "fields": [ + { "name": "partitioned_stake_rewards", "type": "partitioned_stake_rewards" }, + { "name": "total_stake_rewards_lamports", "type": "ulong" } + ], + "comment": "https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L131" + }, + { + "name": "stake_reward_calculation", + "type": "struct", + "alignment": "8", + "fields": [ + { "name": "stake_rewards", "type": "dlist", "dlist_t": "fd_stake_reward_t", "dlist_n": "fd_stake_reward_calculation", "dlist_max": "1" }, + { "name": "total_stake_rewards_lamports", "type": "ulong" } + ], + "comment": "https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L94" + }, + { + "name": "calculate_stake_vote_rewards_result", + "type": "struct", + "fields": [ + { "name": "stake_reward_calculation", "type": "stake_reward_calculation" }, + { "name": "vote_reward_map", "type": "map", "element": "vote_reward", "key": "pubkey", "minalloc":15000 } + ] + }, + { + "name": "calculate_validator_rewards_result", + "type": "struct", + "fields": [ + { "name": "calculate_stake_vote_rewards_result", "type": "calculate_stake_vote_rewards_result" }, + { "name": "point_value", "type": "point_value" } + ], + "comment": "https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L102" + }, + { + "name": "calculate_rewards_and_distribute_vote_rewards_result", + "type": "struct", + "fields": [ + {"name": "total_rewards", "type": "ulong" }, + {"name": "distributed_rewards", "type": "ulong" }, + { "name": "point_value", "type": "point_value" }, + { "name": "stake_rewards_by_partition", "type": "stake_reward_calculation_partitioned" } + ], + "comment": "https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L138" + }, + { + "name": "partitioned_rewards_calculation", + "type": "struct", + "fields": [ + { "name": "vote_reward_map", "type": "map", "element": "vote_reward", "key": "key", "minalloc":15000 }, + { "name": "stake_rewards_by_partition", "type": "stake_reward_calculation_partitioned" }, + { "name": "old_vote_balance_and_staked", "type": "ulong" }, + { "name": "validator_rewards", "type": "ulong" }, + { "name": "validator_rate", "type": "double" }, + { "name": "foundation_rate", "type": "double" }, + { "name": "prev_epoch_duration_in_years", "type": "double" }, + { "name": "capitalization", "type": "ulong" }, + { "name": "point_value", "type": "point_value" } + ], + "comment": "https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L118" + }, + { + "name": "start_block_height_and_rewards", + "type": "struct", + "fields": [ + { "name": "distribution_starting_block_height", "type": "ulong" }, + { "name": "partitioned_stake_rewards", "type": "partitioned_stake_rewards" } + ], + "comment": "https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L60" + }, + { + "name": "fd_epoch_reward_status_inner", + "type": "struct", + "fields": [ + { "name": "Active", "type": "start_block_height_and_rewards" } + ] + }, + { + "name": "epoch_reward_status", + "type": "enum", + "variants": [ + { "name": "Active", "type": "start_block_height_and_rewards" }, + { "name": "Inactive" } + ], + "comment": "https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L70" + }, { "name": "slot_bank", "type": "struct", @@ -1198,7 +1332,8 @@ { "name": "parent_signature_cnt", "type": "ulong" }, { "name": "tick_height", "type": "ulong" }, { "name": "use_preceeding_epoch_stakes", "type": "option", "element": "ulong", "flat": true, "comment": "The epoch for which to use the immediately preceeding epoch's stakes for leader schedule calculation. This is necessary due to how Agave's stake caches interact when loading from snapshots." }, - { "name": "hard_forks", "type": "hard_forks" } + { "name": "hard_forks", "type": "hard_forks" }, + { "name": "epoch_reward_status", "type": "epoch_reward_status" } ] }, { diff --git a/src/flamenco/types/fd_types_custom.c b/src/flamenco/types/fd_types_custom.c index fa620c2547..0f7a0fd443 100644 --- a/src/flamenco/types/fd_types_custom.c +++ b/src/flamenco/types/fd_types_custom.c @@ -218,12 +218,3 @@ void fd_tower_sync_decode_inner( void * struct_mem, void * * alloc_mem, fd_binco } fd_hash_decode_inner( &self->block_id, alloc_mem, ctx ); } - -#define REDBLK_T fd_vote_reward_t_mapnode_t -#define REDBLK_NAME fd_vote_reward_t_map -#define REDBLK_IMPL_STYLE 2 -#include "../../util/tmpl/fd_redblack.c" - -long fd_vote_reward_t_map_compare( fd_vote_reward_t_mapnode_t * left, fd_vote_reward_t_mapnode_t * right ) { - return memcmp( left->elem.pubkey.uc, right->elem.pubkey.uc, sizeof(right->elem.pubkey) ); -} diff --git a/src/flamenco/types/fd_types_custom.h b/src/flamenco/types/fd_types_custom.h index f5ad960c71..789e7e5ca1 100644 --- a/src/flamenco/types/fd_types_custom.h +++ b/src/flamenco/types/fd_types_custom.h @@ -165,188 +165,6 @@ fd_flamenco_txn_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_ /* Represents the lamport balance associated with an account. */ typedef ulong fd_acc_lamports_t; -#if FD_HAS_INT128 -/********************* Rewards types **************************************************/ -/* TODO: move these into fd_types, but first we need to add dlist support to fd_types */ -struct __attribute__((aligned(8UL))) fd_stake_reward { - /* dlist */ - ulong prev; - ulong next; - /* pool */ - ulong parent; - /* data */ - fd_pubkey_t stake_pubkey; - ulong credits_observed; - ulong lamports; - uchar valid; -}; -typedef struct fd_stake_reward fd_stake_reward_t; -#define FD_STAKE_REWARD_FOOTPRINT sizeof(fd_stake_reward_t) -#define FD_STAKE_REWARD_ALIGN (8UL) - -/* Encoded Size: Fixed (42 bytes) */ -struct __attribute__((aligned(8UL))) fd_vote_reward { - fd_pubkey_t pubkey; - ulong vote_rewards; - uchar commission; - uchar needs_store; -}; -typedef struct fd_vote_reward fd_vote_reward_t; -#define FD_VOTE_REWARD_FOOTPRINT sizeof(fd_vote_reward_t) -#define FD_VOTE_REWARD_ALIGN (8UL) - -#define DLIST_NAME fd_stake_reward_dlist -#define DLIST_ELE_T fd_stake_reward_t -#include "../../util/tmpl/fd_dlist.c" -#undef DLIST_NAME -#undef DLIST_ELE_T - -#define POOL_NAME fd_stake_reward_pool -#define POOL_T fd_stake_reward_t -#define POOL_NEXT parent -#include "../../util/tmpl/fd_pool.c" -#undef POOL_NAME -#undef POOL_T -#undef POOL_NEXT - -typedef struct fd_vote_reward_t_mapnode fd_vote_reward_t_mapnode_t; -#define REDBLK_T fd_vote_reward_t_mapnode_t -#define REDBLK_NAME fd_vote_reward_t_map -#define REDBLK_IMPL_STYLE 1 -#include "../../util/tmpl/fd_redblack.c" -struct fd_vote_reward_t_mapnode { - fd_vote_reward_t elem; - ulong redblack_parent; - ulong redblack_left; - ulong redblack_right; - int redblack_color; -}; - -/* https://github.com/anza-xyz/agave/blob/cbc8320d35358da14d79ebcada4dfb6756ffac79/programs/stake/src/points.rs#L21 */ -/* Encoded Size: Fixed (24 bytes) */ -struct __attribute__((aligned(8UL))) fd_point_value { - ulong rewards; - uint128 points; -}; -typedef struct fd_point_value fd_point_value_t; -#define FD_POINT_VALUE_FOOTPRINT sizeof(fd_point_value_t) -#define FD_POINT_VALUE_ALIGN (8UL) - -/* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L56 */ -/* Encoded Size: Dynamic */ -struct __attribute__((aligned(8UL))) fd_partitioned_stake_rewards { - ulong partitions_len; - fd_stake_reward_dlist_t * partitions; - fd_stake_reward_t * pool; -}; -typedef struct fd_partitioned_stake_rewards fd_partitioned_stake_rewards_t; -#define FD_PARTITIONED_STAKE_REWARDS_FOOTPRINT sizeof(fd_partitioned_stake_rewards_t) -#define FD_PARTITIONED_STAKE_REWARDS_ALIGN (8UL) - -/* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L131 */ -/* Encoded Size: Dynamic */ -struct __attribute__((aligned(8UL))) fd_stake_reward_calculation_partitioned { - fd_partitioned_stake_rewards_t partitioned_stake_rewards; - ulong total_stake_rewards_lamports; -}; -typedef struct fd_stake_reward_calculation_partitioned fd_stake_reward_calculation_partitioned_t; -#define FD_STAKE_REWARD_CALCULATION_PARTITIONED_FOOTPRINT sizeof(fd_stake_reward_calculation_partitioned_t) -#define FD_STAKE_REWARD_CALCULATION_PARTITIONED_ALIGN (8UL) - -/* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L94 */ -/* Encoded Size: Dynamic */ -struct __attribute__((aligned(8UL))) fd_stake_reward_calculation { - fd_stake_reward_dlist_t stake_rewards; - ulong stake_rewards_len; - fd_stake_reward_t * pool; - ulong total_stake_rewards_lamports; -}; -typedef struct fd_stake_reward_calculation fd_stake_reward_calculation_t; -#define FD_STAKE_REWARD_CALCULATION_FOOTPRINT sizeof(fd_stake_reward_calculation_t) -#define FD_STAKE_REWARD_CALCULATION_ALIGN (8UL) - -/* Encoded Size: Dynamic */ -struct __attribute__((aligned(8UL))) fd_calculate_stake_vote_rewards_result { - fd_stake_reward_calculation_t stake_reward_calculation; - fd_vote_reward_t_mapnode_t * vote_reward_map_pool; - fd_vote_reward_t_mapnode_t * vote_reward_map_root; -}; -typedef struct fd_calculate_stake_vote_rewards_result fd_calculate_stake_vote_rewards_result_t; -#define FD_CALCULATE_STAKE_VOTE_REWARDS_RESULT_FOOTPRINT sizeof(fd_calculate_stake_vote_rewards_result_t) -#define FD_CALCULATE_STAKE_VOTE_REWARDS_RESULT_ALIGN (8UL) - -/* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L102 */ -/* Encoded Size: Dynamic */ -struct __attribute__((aligned(8UL))) fd_calculate_validator_rewards_result { - fd_calculate_stake_vote_rewards_result_t calculate_stake_vote_rewards_result; - fd_point_value_t point_value; -}; -typedef struct fd_calculate_validator_rewards_result fd_calculate_validator_rewards_result_t; -#define FD_CALCULATE_VALIDATOR_REWARDS_RESULT_FOOTPRINT sizeof(fd_calculate_validator_rewards_result_t) -#define FD_CALCULATE_VALIDATOR_REWARDS_RESULT_ALIGN (8UL) - -/* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L138 */ -/* Encoded Size: Dynamic */ -struct __attribute__((aligned(8UL))) fd_calculate_rewards_and_distribute_vote_rewards_result { - ulong total_rewards; - ulong distributed_rewards; - fd_point_value_t point_value; - fd_stake_reward_calculation_partitioned_t stake_rewards_by_partition; -}; -typedef struct fd_calculate_rewards_and_distribute_vote_rewards_result fd_calculate_rewards_and_distribute_vote_rewards_result_t; -#define FD_CALCULATE_REWARDS_AND_DISTRIBUTE_VOTE_REWARDS_RESULT_FOOTPRINT sizeof(fd_calculate_rewards_and_distribute_vote_rewards_result_t) -#define FD_CALCULATE_REWARDS_AND_DISTRIBUTE_VOTE_REWARDS_RESULT_ALIGN (8UL) - -/* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L118 */ -/* Encoded Size: Dynamic */ -struct __attribute__((aligned(8UL))) fd_partitioned_rewards_calculation { - fd_vote_reward_t_mapnode_t * vote_reward_map_pool; - fd_vote_reward_t_mapnode_t * vote_reward_map_root; - fd_stake_reward_calculation_partitioned_t stake_rewards_by_partition; - ulong old_vote_balance_and_staked; - ulong validator_rewards; - double validator_rate; - double foundation_rate; - double prev_epoch_duration_in_years; - ulong capitalization; - fd_point_value_t point_value; -}; -typedef struct fd_partitioned_rewards_calculation fd_partitioned_rewards_calculation_t; -#define FD_PARTITIONED_REWARDS_CALCULATION_FOOTPRINT sizeof(fd_partitioned_rewards_calculation_t) -#define FD_PARTITIONED_REWARDS_CALCULATION_ALIGN (8UL) - -/* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L60 */ -/* Encoded Size: Dynamic */ -struct __attribute__((aligned(8UL))) fd_start_block_height_and_rewards { - ulong distribution_starting_block_height; - fd_partitioned_stake_rewards_t partitioned_stake_rewards; -}; -typedef struct fd_start_block_height_and_rewards fd_start_block_height_and_rewards_t; -#define FD_START_BLOCK_HEIGHT_AND_REWARDS_FOOTPRINT sizeof(fd_start_block_height_and_rewards_t) -#define FD_START_BLOCK_HEIGHT_AND_REWARDS_ALIGN (8UL) - -union fd_epoch_reward_status_inner { - fd_start_block_height_and_rewards_t Active; -}; -typedef union fd_epoch_reward_status_inner fd_epoch_reward_status_inner_t; - -/* https://github.com/anza-xyz/agave/blob/7117ed9653ce19e8b2dea108eff1f3eb6a3378a7/runtime/src/bank/partitioned_epoch_rewards/mod.rs#L70 */ -struct fd_epoch_reward_status { - uint discriminant; - fd_epoch_reward_status_inner_t inner; -}; -typedef struct fd_epoch_reward_status fd_epoch_reward_status_t; -#define FD_EPOCH_REWARD_STATUS_FOOTPRINT sizeof(fd_epoch_reward_status_t) -#define FD_EPOCH_REWARD_STATUS_ALIGN (8UL) - -enum { -fd_epoch_reward_status_enum_Active = 0, -fd_epoch_reward_status_enum_Inactive = 1, -}; - -/*******************************************************************************************/ -#endif - FD_PROTOTYPES_END #endif /* HEADER_fd_src_flamenco_runtime_fd_types_custom */ diff --git a/src/flamenco/types/gen_stubs.py b/src/flamenco/types/gen_stubs.py index 37e1160668..216ce86457 100644 --- a/src/flamenco/types/gen_stubs.py +++ b/src/flamenco/types/gen_stubs.py @@ -29,6 +29,8 @@ print('#define SOURCE_fd_src_flamenco_types_fd_types_c', file=body) print('#include "fd_types_custom.c"', file=body) +print('#include "../fd_flamenco_base.h"', file=header) + preambletypes = set() postambletypes = set() @@ -1180,6 +1182,242 @@ def emitWalk(self, inner): print(f' }}', file=body) print(f' }}', file=body) +class DlistMember(TypeNode): + def __init__(self, container, json): + super().__init__(json) + self.dlist_t = json["dlist_t"] + self.dlist_n = json["dlist_n"] + self.compact = ("modifier" in json and json["modifier"] == "compact") + self.dlist_max = (int(json["dlist_max"]) if "dlist_max" in json else 0) + + def emitPreamble(self): + pool_name = self.dlist_n + "_pool" + dlist_name = self.dlist_n + "_dlist" + + print(f"#define POOL_NAME {pool_name}", file=header) + print(f"#define POOL_T {self.dlist_t}", file=header) + print(f"#define POOL_NEXT parent", file=header) + print(f"#include \"../../util/tmpl/fd_pool.c\"", file=header) + + print(f'static inline {self.dlist_t} *', file=header) + print(f'{pool_name}_alloc( fd_valloc_t valloc, ulong num ) {{', file=header) + print(f' if( FD_UNLIKELY( 0 == num ) ) num = 1; // prevent underflow', file=header) + print(f' return {pool_name}_join( {pool_name}_new(', file=header) + print(f' fd_valloc_malloc( valloc,', file=header) + print(f' {pool_name}_align(),', file=header) + print(f' {pool_name}_footprint( num ) ),', file=header) + print(f' num ) );', file=header) + print("}", file=header) + print(f'static inline {self.dlist_t} *', file=header) + print(f'{pool_name}_join_new( void * * alloc_mem, ulong num ) {{', file=header) + print(f' if( FD_UNLIKELY( 0 == num ) ) num = 1; // prevent underflow', file=header) + print(f' *alloc_mem = (void*)fd_ulong_align_up( (ulong)*alloc_mem, {pool_name}_align() );', file=header) + print(f' void * pool_mem = *alloc_mem;', file=header) + print(f' *alloc_mem = (uchar *)*alloc_mem + {pool_name}_footprint( num );', file=header) + print(f' return {pool_name}_join( {pool_name}_new( pool_mem, num ) );', file=header) + print("}", file=header) + # print(f"#undef POOL_NAME", file=header) + # print(f"#undef POOL_T", file=header) + # print(f"#undef POOL_NEXT", file=header) + print(f"#define DLIST_NAME {dlist_name}", file=header) + print(f"#define DLIST_ELE_T {self.dlist_t}", file=header) + print(f'#include "../../util/tmpl/fd_dlist.c"', file=header) + print(f'static inline {dlist_name}_t *', file=header) + print(f'{dlist_name}_alloc( fd_valloc_t valloc, ulong num ) {{', file=header) + print(f' if( FD_UNLIKELY( 0 == num ) ) num = 1; // prevent underflow', file=header) + print(f' return {dlist_name}_join( {dlist_name}_new(', file=header) + print(f' fd_valloc_malloc( valloc,', file=header) + print(f' {dlist_name}_align(),', file=header) + print(f' {dlist_name}_footprint() ) ) );', file=header) + print("}", file=header) + print(f'static inline {dlist_name}_t *', file=header) + print(f'{dlist_name}_join_new( void * * alloc_mem, ulong num ) {{', file=header) + print(f' if( FD_UNLIKELY( 0 == num ) ) num = 1; // prevent underflow', file=header) + print(f' *alloc_mem = (void*)fd_ulong_align_up( (ulong)*alloc_mem, {dlist_name}_align() );', file=header) + print(f' void * dlist_mem = *alloc_mem;', file=header) + print(f' *alloc_mem = (uchar *)*alloc_mem + {dlist_name}_footprint();', file=header) + print(f' return {dlist_name}_join( {dlist_name}_new( dlist_mem ) );', file=header) + print("}", file=header) + # print(f"#undef DLIST_NAME", file=header) + # print(f"#undef DLIST_ELE_T", file=header) + + def emitPostamble(self): + pass + + def emitMember(self): + if self.compact: + print(f' ushort {self.name}_len;', file=header) + else: + print(f' ulong {self.name}_len;', file=header) + print(f' ulong {self.name}_lengths[{self.dlist_max}];', file=header) + print(f' {self.dlist_n}_dlist_t * {self.name};', file=header) + print(f' {self.dlist_t} * pool;', file=header) + + def emitOffsetMember(self): + print(f' uint {self.dlist_n}_off;', file=header) + + def emitNew(self): + pass + + def emitDestroy(self): + dlist_name = self.dlist_n + "_dlist" + dlist_t = self.dlist_t + pool_name = self.dlist_n + "_pool" + + print(f' if( !self->{self.name} || !self->pool ) return;', file=body) + print(f' for( ulong i=0; i < self->{self.name}_len; i++ ) {{', file=body) + print(f' for( {dlist_name}_iter_t iter = {dlist_name}_iter_fwd_init( &self->{self.name}[ i ], self->pool );', file=body); + print(f' !{dlist_name}_iter_done( iter, &self->{self.name}[ i ], self->pool );', file=body); + print(f' iter = {dlist_name}_iter_fwd_next( iter, &self->{self.name}[ i ], self->pool ) ) {{', file=body); + print(f' {dlist_t} * ele = {dlist_name}_iter_ele( iter, &self->{self.name}[ i ], self->pool );', file=body) + print(f' {dlist_t.rstrip("_t")}_destroy( ele );', file=body) + print(' }', file=body) + print(' }', file=body) + print(f' self->{self.name} = NULL;', file=body) + print(f' self->pool = NULL;', file=body) + + def emitDecodeFootprint(self): + dlist_name = self.dlist_n + "_dlist" + dlist_t = self.dlist_t + pool_name = self.dlist_n + "_pool" + if self.compact: + print(f' ushort {self.name}_len;', file=body) + print(f' err = fd_bincode_compact_u16_decode( &{self.name}_len, ctx );', file=body) + else: + print(f' ulong {self.name}_len;', file=body) + print(f' err = fd_bincode_uint64_decode( &{self.name}_len, ctx );', file=body) + print(' if( FD_UNLIKELY( err ) ) return err;', file=body) + print(' ulong total_count = 0UL;', file=body) + print(f' ulong {self.name}_lengths[{self.dlist_max}];', file=body) + print(f' for( ulong i=0; i<{self.dlist_max}; i++ ) {{', file=body) + print(f' err = fd_bincode_uint64_decode( {self.name}_lengths + i, ctx );', file=body) + print(f' total_count+={self.name}_lengths[ i ];', file=body) + print(' if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) return err;', file=body) + print(' }', file=body) + + print(f' *total_sz += {pool_name}_align() + {pool_name}_footprint( total_count );', file=body) + print(f' *total_sz += {dlist_name}_align() + {dlist_name}_footprint()*{self.name}_len;', file=body) + + print(f' for( ulong i=0; i < {self.name}_len; i++ ) {{', file=body) + print(f' err = {dlist_t.rstrip("_t")}_decode_footprint_inner( ctx, total_sz );', file=body) + print(f' if( FD_UNLIKELY ( err ) ) return err;', file=body) + print(' }', file=body) + + def emitDecodeInner(self): + dlist_name = self.dlist_n + "_dlist" + dlist_t = self.dlist_t + pool_name = self.dlist_n + "_pool" + + if self.compact: + print(f' fd_bincode_compact_u16_decode_unsafe( &self->{self.name}_len, ctx );', file=body) + else: + print(f' fd_bincode_uint64_decode_unsafe( &self->{self.name}_len, ctx );', file=body) + print(f' ulong total_count = 0UL;', file=body) + print(f' for( ulong i=0; i < {self.dlist_max}; i++ ) {{', file=body) + print(f' fd_bincode_uint64_decode_unsafe( self->{self.name}_lengths + i, ctx );', file=body) + print(f' total_count += self->{self.name}_lengths[ i ];', file=body) + print(' }', file=body) + + print(f' self->pool = {pool_name}_join_new( alloc_mem, total_count );', file=body) + print(f' self->{self.name} = {dlist_name}_join_new( alloc_mem, self->{self.name}_len );', file=body) + + print(f' for( ulong i=0; i < self->{self.name}_len; i++ ) {{', file=body) + # print(f' fd_partitioned_stake_rewards_dlist_t * partition = {dlist_name}_join_new( alloc_mem, self->{self.name}_len );') + # print(f' self->{self.name}[ i ] = partition;', file=body) + print(f' {dlist_name}_new( &self->{self.name}[ i ] );', file=body) + print(f' for( ulong j=0; j < self->{self.name}_lengths[ i ]; j++ ) {{', file=body) + print(f' {dlist_t} * ele = {pool_name}_ele_acquire( self->pool );', file=body) + print(f' {dlist_t.rstrip("_t")}_new( ele );', file=body) + print(f' {dlist_t.rstrip("_t")}_decode_inner( ele, alloc_mem, ctx );', file=body) + print(f' {dlist_name}_ele_push_tail( &self->{self.name}[ i ], ele, self->pool );', file=body) + print(' }', file=body) + print(' }', file=body) + + def emitEncode(self): + name = self.name + dlist_name = self.dlist_n + "_dlist" + dlist_t = self.dlist_t + + print(f' if( self->{name} ) {{', file=body) + if self.compact: + print(f' err = fd_bincode_compact_u16_encode( &self->{self.name}_len, ctx );', file=body) + else: + print(f' err = fd_bincode_uint64_encode( self->{self.name}_len, ctx );', file=body) + + print(f' if( FD_UNLIKELY( err ) ) return err;', file=body) + print(f' for( ulong i=0; i < {self.dlist_max}; i++ ) {{', file=body) + print(f' err = fd_bincode_uint64_encode( self->{self.name}_lengths[ i ], ctx );', file=body) + print(' if( FD_UNLIKELY( err ) ) return err;', file=body) + print(' }', file=body) + + print(f' for( ulong i=0; i < self->{self.name}_len; i++ ) {{', file=body) + print(f' for( {dlist_name}_iter_t iter = {dlist_name}_iter_fwd_init( &self->{self.name}[ i ], self->pool );', file=body) + print(f' !{dlist_name}_iter_done( iter, &self->{self.name}[ i ], self->pool );', file=body); + print(f' iter = {dlist_name}_iter_fwd_next( iter, &self->{self.name}[ i ], self->pool ) ) {{', file=body); + print(f' {dlist_t} * ele = {dlist_name}_iter_ele( iter, &self->{self.name}[ i ], self->pool );', file=body) + print(f' err = {dlist_t.rstrip("_t")}_encode( ele, ctx );', file=body) + print(' if( FD_UNLIKELY( err ) ) return err;', file=body) + print(' }', file=body) + print(' }', file=body) + print(' } else {', file=body) + + if self.compact: + print(f' err = fd_bincode_compact_u16_encode( &self->{self.name}_len, ctx );', file=body) + else: + print(f' err = fd_bincode_uint64_encode( self->{self.name}_len, ctx );', file=body) + print(' if( FD_UNLIKELY( err ) ) return err;', file=body) + print(' }', file=body) + + def emitSize(self, inner): + name = self.name + dlist_name = self.dlist_n + "_dlist" + dlist_t = self.dlist_t + pool = self.dlist_n + "_pool" + + if self.compact: + print(f' ushort {name}_len = (ushort){pool}_used( self->pool );', file=body) + print(f' size += fd_bincode_compact_u16_size( &{name}_len );', file=body) + else: + print(' size += sizeof(ulong);', file=body) + print(f' size += {self.dlist_max} * sizeof(ulong);', file=body) + + print(f' if( self->{name} ) {{', file=body) + print(f' for( ulong i=0; i < self->{self.name}_len; i++ ) {{', file=body) + + print(f' for( {dlist_name}_iter_t iter = {dlist_name}_iter_fwd_init( &self->{self.name}[ i ], self->pool );', file=body) + print(f' !{dlist_name}_iter_done( iter, &self->{self.name}[ i ], self->pool );', file=body); + print(f' iter = {dlist_name}_iter_fwd_next( iter, &self->{self.name}[ i ], self->pool ) ) {{', file=body); + print(f' {dlist_t} * ele = {dlist_name}_iter_ele( iter, &self->{self.name}[ i ], self->pool );', file=body) + print(f' size += {dlist_t.rstrip("_t")}_size( ele );', file=body) + print(f' }}', file=body) + print(f' }}', file=body) + print(f' }}', file=body) + + def emitWalk(self, inner): + name = self.name + dlist_name = self.dlist_n + "_dlist" + dlist_t = self.dlist_t + + print(f' if( self->{name} ) {{', file=body) + print(f' for( ulong i=0; i < self->{self.name}_len; i++ ) {{', file=body) + + print(f' for( {dlist_name}_iter_t iter = {dlist_name}_iter_fwd_init( &self->{self.name}[ i ], self->pool );', file=body) + print(f' !{dlist_name}_iter_done( iter, &self->{self.name}[ i ], self->pool );', file=body); + print(f' iter = {dlist_name}_iter_fwd_next( iter, &self->{self.name}[ i ], self->pool ) ) {{', file=body); + print(f' {dlist_t} * ele = {dlist_name}_iter_ele( iter, &self->{self.name}[ i ], self->pool );', file=body) + + if dlist_t == "uchar": + print(' fun( w, ele, "ele", FD_FLAMENCO_TYPE_UCHAR, "uchar", level );', file=body), + elif dlist_t == "ulong": + print(' fun( w, ele, "ele", FD_FLAMENCO_TYPE_ULONG, "long", level );', file=body), + elif dlist_t == "uint": + print(' fun( w, ele, "ele", FD_FLAMENCO_TYPE_UINT, "uint", level );', file=body), + else: + print(f' {dlist_t.rstrip("_t")}_walk( w, ele, fun, "{dlist_t}", level );', file=body) + print(f' }}', file=body) + print(f' }}', file=body) + print(f' }}', file=body) + class TreapMember(TypeNode): def __init__(self, container, json): @@ -1727,6 +1965,7 @@ def emitWalk(self, inner): "vector" : VectorMember, "string" : StringMember, "deque" : DequeMember, + "dlist" : DlistMember, "array" : ArrayMember, "option" : OptionMember, "map" : MapMember,