Skip to content

Commit 60a42c4

Browse files
riptlripatel-fd
authored andcommitted
Move stake_weight out of fd_types
1 parent a5005a0 commit 60a42c4

File tree

12 files changed

+33
-247
lines changed

12 files changed

+33
-247
lines changed

src/discof/poh/fd_poh_tile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@
313313
#include "../../disco/pack/fd_pack.h"
314314
#include "../../ballet/sha256/fd_sha256.h"
315315
#include "../../disco/metrics/fd_metrics.h"
316-
#include "../../util/pod/fd_pod_format.h"
316+
#include "../../util/pod/fd_pod.h"
317317
#include "../../disco/shred/fd_shredder.h"
318318
#include "../../disco/keyguard/fd_keyload.h"
319319
#include "../../disco/keyguard/fd_keyswitch.h"

src/flamenco/leaders/fd_leaders.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
rotation. */
2929

3030
#include "fd_leaders_base.h"
31-
#include "../types/fd_types.h"
3231
#include "../../ballet/wsample/fd_wsample.h"
3332

3433
#define FD_ULONG_MAX( a, b ) (__builtin_choose_expr( __builtin_constant_p( a ) & __builtin_constant_p( b ), \

src/flamenco/leaders/fd_leaders_base.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#ifndef HEADER_fd_src_flamenco_leaders_fd_leaders_base_h
22
#define HEADER_fd_src_flamenco_leaders_fd_leaders_base_h
33

4-
#include "../fd_flamenco_base.h"
5-
#include "../types/fd_types.h"
4+
#include "../types/fd_types_custom.h"
65

76
#define MAX_SLOTS_PER_EPOCH 432000UL
87
#define MAX_PUB_CNT 50000UL

src/flamenco/snapshot/fd_snapshot_http.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "fd_snapshot_http.h"
22
#include "../../waltz/http/picohttpparser.h"
3-
#include "fd_snapshot.h"
3+
#include "../../util/net/fd_ip4.h"
44

55
#include <assert.h>
66
#include <errno.h>

src/flamenco/snapshot/fuzz_snapshot_http.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <unistd.h>
1818

1919
#include "../../util/sanitize/fd_fuzz.h"
20+
#include "../../util/net/fd_ip4.h"
2021
#include "fd_snapshot_http.h"
2122

2223
struct shared_state {

src/flamenco/types/fd_fuzz_types.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -387,30 +387,6 @@ void *fd_account_keys_generate( void *mem, void **alloc_mem, fd_rng_t * rng ) {
387387
return mem;
388388
}
389389

390-
void *fd_stake_weight_generate( void *mem, void **alloc_mem, fd_rng_t * rng ) {
391-
fd_stake_weight_t *self = (fd_stake_weight_t *) mem;
392-
*alloc_mem = (uchar *) *alloc_mem + sizeof(fd_stake_weight_t);
393-
fd_stake_weight_new(mem);
394-
fd_pubkey_generate( &self->key, alloc_mem, rng );
395-
self->stake = fd_rng_ulong( rng );
396-
return mem;
397-
}
398-
399-
void *fd_stake_weights_generate( void *mem, void **alloc_mem, fd_rng_t * rng ) {
400-
fd_stake_weights_t *self = (fd_stake_weights_t *) mem;
401-
*alloc_mem = (uchar *) *alloc_mem + sizeof(fd_stake_weights_t);
402-
fd_stake_weights_new(mem);
403-
ulong stake_weights_len = fd_rng_ulong( rng ) % 8;
404-
self->stake_weights_pool = fd_stake_weight_t_map_join_new( alloc_mem, stake_weights_len );
405-
self->stake_weights_root = NULL;
406-
for( ulong i=0; i < stake_weights_len; i++ ) {
407-
fd_stake_weight_t_mapnode_t * node = fd_stake_weight_t_map_acquire( self->stake_weights_pool );
408-
fd_stake_weight_generate( &node->elem, alloc_mem, rng );
409-
fd_stake_weight_t_map_insert( self->stake_weights_pool, &self->stake_weights_root, node );
410-
}
411-
return mem;
412-
}
413-
414390
void *fd_delegation_generate( void *mem, void **alloc_mem, fd_rng_t * rng ) {
415391
fd_delegation_t *self = (fd_delegation_t *) mem;
416392
*alloc_mem = (uchar *) *alloc_mem + sizeof(fd_delegation_t);

src/flamenco/types/fd_types.c

Lines changed: 0 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,139 +2248,6 @@ ulong fd_account_keys_size_global( fd_account_keys_global_t const * self ) {
22482248
return size;
22492249
}
22502250

2251-
int fd_stake_weight_encode( fd_stake_weight_t const * self, fd_bincode_encode_ctx_t * ctx ) {
2252-
int err;
2253-
err = fd_pubkey_encode( &self->key, ctx );
2254-
if( FD_UNLIKELY( err ) ) return err;
2255-
err = fd_bincode_uint64_encode( self->stake, ctx );
2256-
if( FD_UNLIKELY( err ) ) return err;
2257-
return FD_BINCODE_SUCCESS;
2258-
}
2259-
static inline int fd_stake_weight_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) {
2260-
if( (ulong)ctx->data + 40UL > (ulong)ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; };
2261-
ctx->data = (void *)( (ulong)ctx->data + 40UL );
2262-
return 0;
2263-
}
2264-
static void fd_stake_weight_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ) {
2265-
fd_stake_weight_t * self = (fd_stake_weight_t *)struct_mem;
2266-
fd_pubkey_decode_inner( &self->key, alloc_mem, ctx );
2267-
fd_bincode_uint64_decode_unsafe( &self->stake, ctx );
2268-
}
2269-
void * fd_stake_weight_decode( void * mem, fd_bincode_decode_ctx_t * ctx ) {
2270-
fd_stake_weight_t * self = (fd_stake_weight_t *)mem;
2271-
fd_stake_weight_new( self );
2272-
void * alloc_region = (uchar *)mem + sizeof(fd_stake_weight_t);
2273-
void * * alloc_mem = &alloc_region;
2274-
fd_stake_weight_decode_inner( mem, alloc_mem, ctx );
2275-
return self;
2276-
}
2277-
void fd_stake_weight_walk( void * w, fd_stake_weight_t const * self, fd_types_walk_fn_t fun, const char *name, uint level, uint varint ) {
2278-
(void) varint;
2279-
fun( w, self, name, FD_FLAMENCO_TYPE_MAP, "fd_stake_weight", level++, 0 );
2280-
fd_pubkey_walk( w, &self->key, fun, "key", level, 0 );
2281-
fun( w, &self->stake, "stake", FD_FLAMENCO_TYPE_ULONG, "ulong", level, 0 );
2282-
fun( w, self, name, FD_FLAMENCO_TYPE_MAP_END, "fd_stake_weight", level--, 0 );
2283-
}
2284-
ulong fd_stake_weight_size( fd_stake_weight_t const * self ) {
2285-
ulong size = 0;
2286-
size += fd_pubkey_size( &self->key );
2287-
size += sizeof(ulong);
2288-
return size;
2289-
}
2290-
2291-
int fd_stake_weights_encode( fd_stake_weights_t const * self, fd_bincode_encode_ctx_t * ctx ) {
2292-
int err;
2293-
if( self->stake_weights_root ) {
2294-
ulong stake_weights_len = fd_stake_weight_t_map_size( self->stake_weights_pool, self->stake_weights_root );
2295-
err = fd_bincode_uint64_encode( stake_weights_len, ctx );
2296-
if( FD_UNLIKELY( err ) ) return err;
2297-
for( fd_stake_weight_t_mapnode_t * n = fd_stake_weight_t_map_minimum( self->stake_weights_pool, self->stake_weights_root ); n; n = fd_stake_weight_t_map_successor( self->stake_weights_pool, n ) ) {
2298-
err = fd_stake_weight_encode( &n->elem, ctx );
2299-
if( FD_UNLIKELY( err ) ) return err;
2300-
}
2301-
} else {
2302-
ulong stake_weights_len = 0;
2303-
err = fd_bincode_uint64_encode( stake_weights_len, ctx );
2304-
if( FD_UNLIKELY( err ) ) return err;
2305-
}
2306-
return FD_BINCODE_SUCCESS;
2307-
}
2308-
static int fd_stake_weights_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) {
2309-
if( ctx->data>=ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; };
2310-
int err = 0;
2311-
ulong stake_weights_len = 0UL;
2312-
err = fd_bincode_uint64_decode( &stake_weights_len, ctx );
2313-
ulong stake_weights_cnt = !!stake_weights_len ? stake_weights_len : 1;
2314-
*total_sz += fd_stake_weight_t_map_align() + fd_stake_weight_t_map_footprint( stake_weights_cnt );
2315-
if( FD_UNLIKELY( err ) ) return err;
2316-
for( ulong i=0; i < stake_weights_len; i++ ) {
2317-
err = fd_stake_weight_decode_footprint_inner( ctx, total_sz );
2318-
if( FD_UNLIKELY( err ) ) return err;
2319-
}
2320-
return 0;
2321-
}
2322-
int fd_stake_weights_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) {
2323-
*total_sz += sizeof(fd_stake_weights_t);
2324-
void const * start_data = ctx->data;
2325-
int err = fd_stake_weights_decode_footprint_inner( ctx, total_sz );
2326-
if( ctx->data>ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; };
2327-
ctx->data = start_data;
2328-
return err;
2329-
}
2330-
static void fd_stake_weights_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ) {
2331-
fd_stake_weights_t * self = (fd_stake_weights_t *)struct_mem;
2332-
ulong stake_weights_len;
2333-
fd_bincode_uint64_decode_unsafe( &stake_weights_len, ctx );
2334-
self->stake_weights_pool = fd_stake_weight_t_map_join_new( alloc_mem, stake_weights_len );
2335-
self->stake_weights_root = NULL;
2336-
for( ulong i=0; i < stake_weights_len; i++ ) {
2337-
fd_stake_weight_t_mapnode_t * node = fd_stake_weight_t_map_acquire( self->stake_weights_pool );
2338-
fd_stake_weight_new( &node->elem );
2339-
fd_stake_weight_decode_inner( &node->elem, alloc_mem, ctx );
2340-
fd_stake_weight_t_mapnode_t * out = NULL;;
2341-
fd_stake_weight_t_map_insert_or_replace( self->stake_weights_pool, &self->stake_weights_root, node, &out );
2342-
if( out != NULL ) {
2343-
// Unclear how to release the memory...
2344-
fd_stake_weight_t_map_release( self->stake_weights_pool, out );
2345-
}
2346-
}
2347-
}
2348-
void * fd_stake_weights_decode( void * mem, fd_bincode_decode_ctx_t * ctx ) {
2349-
fd_stake_weights_t * self = (fd_stake_weights_t *)mem;
2350-
fd_stake_weights_new( self );
2351-
void * alloc_region = (uchar *)mem + sizeof(fd_stake_weights_t);
2352-
void * * alloc_mem = &alloc_region;
2353-
fd_stake_weights_decode_inner( mem, alloc_mem, ctx );
2354-
return self;
2355-
}
2356-
void fd_stake_weights_new(fd_stake_weights_t * self) {
2357-
fd_memset( self, 0, sizeof(fd_stake_weights_t) );
2358-
}
2359-
void fd_stake_weights_walk( void * w, fd_stake_weights_t const * self, fd_types_walk_fn_t fun, const char *name, uint level, uint varint ) {
2360-
(void) varint;
2361-
fun( w, self, name, FD_FLAMENCO_TYPE_MAP, "fd_stake_weights", level++, 0 );
2362-
if( self->stake_weights_root ) {
2363-
for( fd_stake_weight_t_mapnode_t * n = fd_stake_weight_t_map_minimum(self->stake_weights_pool, self->stake_weights_root ); n; n = fd_stake_weight_t_map_successor( self->stake_weights_pool, n ) ) {
2364-
fd_stake_weight_walk(w, &n->elem, fun, "stake_weights", level, 0 );
2365-
}
2366-
}
2367-
fun( w, self, name, FD_FLAMENCO_TYPE_MAP_END, "fd_stake_weights", level--, 0 );
2368-
}
2369-
ulong fd_stake_weights_size( fd_stake_weights_t const * self ) {
2370-
ulong size = 0;
2371-
if( self->stake_weights_root ) {
2372-
size += sizeof(ulong);
2373-
ulong max = fd_stake_weight_t_map_max( self->stake_weights_pool );
2374-
size += fd_stake_weight_t_map_footprint( max );
2375-
for( fd_stake_weight_t_mapnode_t * n = fd_stake_weight_t_map_minimum( self->stake_weights_pool, self->stake_weights_root ); n; n = fd_stake_weight_t_map_successor( self->stake_weights_pool, n ) ) {
2376-
size += fd_stake_weight_size( &n->elem ) - sizeof(fd_stake_weight_t);
2377-
}
2378-
} else {
2379-
size += sizeof(ulong);
2380-
}
2381-
return size;
2382-
}
2383-
23842251
int fd_delegation_encode( fd_delegation_t const * self, fd_bincode_encode_ctx_t * ctx ) {
23852252
int err;
23862253
err = fd_pubkey_encode( &self->voter_pubkey, ctx );
@@ -27074,13 +26941,6 @@ long fd_vote_accounts_pair_global_t_map_compare( fd_vote_accounts_pair_global_t_
2707426941
long fd_account_keys_pair_t_map_compare( fd_account_keys_pair_t_mapnode_t * left, fd_account_keys_pair_t_mapnode_t * right ) {
2707526942
return memcmp( left->elem.key.uc, right->elem.key.uc, sizeof(right->elem.key) );
2707626943
}
27077-
#define REDBLK_T fd_stake_weight_t_mapnode_t
27078-
#define REDBLK_NAME fd_stake_weight_t_map
27079-
#define REDBLK_IMPL_STYLE 2
27080-
#include "../../util/tmpl/fd_redblack.c"
27081-
long fd_stake_weight_t_map_compare( fd_stake_weight_t_mapnode_t * left, fd_stake_weight_t_mapnode_t * right ) {
27082-
return memcmp( left->elem.key.uc, right->elem.key.uc, sizeof(right->elem.key) );
27083-
}
2708426944
#define REDBLK_T fd_delegation_pair_t_mapnode_t
2708526945
#define REDBLK_NAME fd_delegation_pair_t_map
2708626946
#define REDBLK_IMPL_STYLE 2

src/flamenco/types/fd_types.h

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -458,43 +458,6 @@ static FD_FN_UNUSED void fd_account_keys_account_keys_pool_update( fd_account_ke
458458
static FD_FN_UNUSED void fd_account_keys_account_keys_root_update( fd_account_keys_global_t * type, fd_account_keys_pair_t_mapnode_t * root ) {
459459
type->account_keys_root_offset = !!root ? (ulong)root - (ulong)type : 0UL;
460460
}
461-
/* fd_stake_weight_t assigns an Ed25519 public key (node identity) a stake weight number measured in lamports */
462-
/* Encoded Size: Fixed (40 bytes) */
463-
struct __attribute__((packed)) fd_stake_weight {
464-
fd_pubkey_t key;
465-
ulong stake;
466-
};
467-
typedef struct fd_stake_weight fd_stake_weight_t;
468-
#define FD_STAKE_WEIGHT_ALIGN (8UL)
469-
470-
typedef struct fd_stake_weight_t_mapnode fd_stake_weight_t_mapnode_t;
471-
#define REDBLK_T fd_stake_weight_t_mapnode_t
472-
#define REDBLK_NAME fd_stake_weight_t_map
473-
#define REDBLK_IMPL_STYLE 1
474-
#include "../../util/tmpl/fd_redblack.c"
475-
struct fd_stake_weight_t_mapnode {
476-
fd_stake_weight_t elem;
477-
ulong redblack_parent;
478-
ulong redblack_left;
479-
ulong redblack_right;
480-
int redblack_color;
481-
};
482-
static inline fd_stake_weight_t_mapnode_t *
483-
fd_stake_weight_t_map_join_new( void * * alloc_mem, ulong len ) {
484-
if( FD_UNLIKELY( 0 == len ) ) len = 1; // prevent underflow
485-
*alloc_mem = (void*)fd_ulong_align_up( (ulong)*alloc_mem, fd_stake_weight_t_map_align() );
486-
void * map_mem = *alloc_mem;
487-
*alloc_mem = (uchar *)*alloc_mem + fd_stake_weight_t_map_footprint( len );
488-
return fd_stake_weight_t_map_join( fd_stake_weight_t_map_new( map_mem, len ) );
489-
}
490-
/* Encoded Size: Dynamic */
491-
struct fd_stake_weights {
492-
fd_stake_weight_t_mapnode_t * stake_weights_pool;
493-
fd_stake_weight_t_mapnode_t * stake_weights_root;
494-
};
495-
typedef struct fd_stake_weights fd_stake_weights_t;
496-
#define FD_STAKE_WEIGHTS_ALIGN alignof(fd_stake_weights_t)
497-
498461
/* https://github.com/solana-labs/solana/blob/8f2c8b8388a495d2728909e30460aa40dcc5d733/sdk/program/src/stake/state.rs#L303 */
499462
/* Encoded Size: Fixed (64 bytes) */
500463
struct fd_delegation {
@@ -3956,26 +3919,6 @@ void * fd_account_keys_decode_global( void * mem, fd_bincode_decode_ctx_t * ctx
39563919
int fd_account_keys_encode_global( fd_account_keys_global_t const * self, fd_bincode_encode_ctx_t * ctx );
39573920
ulong fd_account_keys_size_global( fd_account_keys_global_t const * self );
39583921

3959-
static inline void fd_stake_weight_new( fd_stake_weight_t * self ) { fd_memset( self, 0, sizeof(fd_stake_weight_t) ); }
3960-
int fd_stake_weight_encode( fd_stake_weight_t const * self, fd_bincode_encode_ctx_t * ctx );
3961-
void fd_stake_weight_walk( void * w, fd_stake_weight_t const * self, fd_types_walk_fn_t fun, const char *name, uint level, uint varint );
3962-
ulong fd_stake_weight_size( fd_stake_weight_t const * self );
3963-
static inline ulong fd_stake_weight_align( void ) { return FD_STAKE_WEIGHT_ALIGN; }
3964-
static inline int fd_stake_weight_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) {
3965-
*total_sz += sizeof(fd_stake_weight_t);
3966-
if( (ulong)ctx->data + 40UL > (ulong)ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; };
3967-
return 0;
3968-
}
3969-
void * fd_stake_weight_decode( void * mem, fd_bincode_decode_ctx_t * ctx );
3970-
3971-
void fd_stake_weights_new( fd_stake_weights_t * self );
3972-
int fd_stake_weights_encode( fd_stake_weights_t const * self, fd_bincode_encode_ctx_t * ctx );
3973-
void fd_stake_weights_walk( void * w, fd_stake_weights_t const * self, fd_types_walk_fn_t fun, const char *name, uint level, uint varint );
3974-
ulong fd_stake_weights_size( fd_stake_weights_t const * self );
3975-
static inline ulong fd_stake_weights_align( void ) { return FD_STAKE_WEIGHTS_ALIGN; }
3976-
int fd_stake_weights_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz );
3977-
void * fd_stake_weights_decode( void * mem, fd_bincode_decode_ctx_t * ctx );
3978-
39793922
static inline void fd_delegation_new( fd_delegation_t * self ) { fd_memset( self, 0, sizeof(fd_delegation_t) ); }
39803923
int fd_delegation_encode( fd_delegation_t const * self, fd_bincode_encode_ctx_t * ctx );
39813924
void fd_delegation_walk( void * w, fd_delegation_t const * self, fd_types_walk_fn_t fun, const char *name, uint level, uint varint );

src/flamenco/types/fd_types.json

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -285,23 +285,6 @@
285285
{ "name": "account_keys", "type": "map", "element": "account_keys_pair", "key": "key", "minalloc":100000 }
286286
]
287287
},
288-
{
289-
"name": "stake_weight",
290-
"packed": true,
291-
"type": "struct",
292-
"fields": [
293-
{ "name": "key", "type": "pubkey" },
294-
{ "name": "stake", "type": "ulong" }
295-
],
296-
"comment": "fd_stake_weight_t assigns an Ed25519 public key (node identity) a stake weight number measured in lamports"
297-
},
298-
{
299-
"name": "stake_weights",
300-
"type": "struct",
301-
"fields": [
302-
{ "name": "stake_weights", "type": "map", "element": "stake_weight", "key": "key" }
303-
]
304-
},
305288
{
306289
"name": "delegation",
307290
"type": "struct",

src/flamenco/types/fd_types_custom.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,3 +343,11 @@ void fd_vote_accounts_decode_inner_global( void * struct_mem, void * * alloc_mem
343343
self->vote_accounts_pool_offset = (ulong)fd_vote_accounts_pair_global_t_map_leave( vote_accounts_pool ) - (ulong)struct_mem;
344344
self->vote_accounts_root_offset = (ulong)vote_accounts_root - (ulong)struct_mem;
345345
}
346+
347+
#define REDBLK_T fd_stake_weight_t_mapnode_t
348+
#define REDBLK_NAME fd_stake_weight_t_map
349+
#define REDBLK_IMPL_STYLE 2
350+
#include "../../util/tmpl/fd_redblack.c"
351+
long fd_stake_weight_t_map_compare( fd_stake_weight_t_mapnode_t * left, fd_stake_weight_t_mapnode_t * right ) {
352+
return memcmp( left->elem.key.uc, right->elem.key.uc, sizeof(right->elem.key) );
353+
}

0 commit comments

Comments
 (0)