Skip to content

Commit 9af3b15

Browse files
inital framework
1 parent 2f4ff84 commit 9af3b15

File tree

3 files changed

+141
-0
lines changed

3 files changed

+141
-0
lines changed

src/flamenco/stakes/fd_vote_states.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "fd_vote_states.h"
2+
3+
fd_vote_state_ele_t *
4+
fd_vote_states_get_pool( fd_vote_states_t const * vote_states ) {
5+
FD_SCRATCH_ALLOC_INIT( l, vote_states );
6+
FD_SCRATCH_ALLOC_APPEND( l, fd_vote_states_align(), sizeof(fd_vote_states_t) );
7+
uchar * pool = FD_SCRATCH_ALLOC_APPEND( l, fd_vote_states_align(), fd_vote_states_footprint( vote_states->max_vote_accounts ) );
8+
return fd_vote_states_pool_join( pool );
9+
}
10+
11+
fd_vote_state_map_t *
12+
fd_vote_states_get_map( fd_vote_states_t const * vote_states ) {
13+
FD_SCRATCH_ALLOC_INIT( l, vote_states );
14+
FD_SCRATCH_ALLOC_APPEND( l, fd_vote_states_align(), sizeof(fd_vote_states_t) );
15+
FD_SCRATCH_ALLOC_APPEND( l, fd_vote_state_pool_align(), fd_vote_state_pool_footprint( vote_states->max_vote_accounts ) );
16+
ulong map_chain_cnt = fd_vote_state_map_chain_cnt_est( vote_states->max_vote_accounts );
17+
uchar * map = FD_SCRATCH_ALLOC_APPEND( l, fd_vote_state_map_align(), fd_vote_state_map_footprint( map_chain_cnt ) );
18+
return fd_vote_state_map_join( map );
19+
}

src/flamenco/stakes/fd_vote_states.h

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#ifndef HEADER_fd_src_flamenco_stakes_fd_vote_states_h
2+
#define HEADER_fd_src_flamenco_stakes_fd_vote_states_h
3+
4+
#include "../fd_flamenco_base.h"
5+
#include "../types/fd_types.h"
6+
7+
#define FD_VOTE_STATES_MAGIC (0x01231965UL)
8+
9+
struct fd_vote_state_ele {
10+
fd_pubkey_t vote_account;
11+
ulong next_; /* Internal pool/map use */
12+
/* TODO: fill in vote state ele fields*/
13+
};
14+
typedef struct fd_vote_state fd_vote_state_t;
15+
16+
#define POOL_NAME fd_vote_state_pool
17+
#define POOL_T fd_vote_state_ele_t
18+
#define POOL_NEXT next_
19+
#include "../../util/tmpl/fd_pool.c"
20+
21+
#define MAP_NAME fd_vote_state_map
22+
#define MAP_KEY_T fd_pubkey_t
23+
#define MAP_ELE_T fd_vote_state_ele_t
24+
#define MAP_KEY vote_account
25+
#define MAP_KEY_EQ(k0,k1) (!(memcmp(&(k0)->key,&(k1)->key,sizeof(fd_pubkey_t))))
26+
#define MAP_KEY_HASH(key,seed) (fd_hash( seed, key, sizeof(fd_pubkey_t) ))
27+
#define MAP_NEXT next_
28+
#include "../../util/tmpl/fd_map_chain.c"
29+
30+
struct fd_vote_states {
31+
ulong magic;
32+
ulong max_vote_accounts;
33+
};
34+
typedef struct fd_vote_states fd_vote_states_t;
35+
36+
FD_PROTOTYPES_BEGIN
37+
38+
/* fd_vote_states_get_pool returns the underlying pool that the
39+
vote states uses to manage the vote states. */
40+
41+
fd_vote_state_ele_t *
42+
fd_vote_states_get_pool( fd_vote_states_t const * vote_states );
43+
44+
/* fd_vote_states_get_map returns the underlying map that the
45+
vote states uses to manage the vote states. */
46+
47+
fd_vote_state_map_t *
48+
fd_vote_states_get_map( fd_vote_states_t const * vote_states );
49+
50+
/* fd_vote_states_align returns the minimum alignment required for a
51+
vote states struct. */
52+
53+
ulong
54+
fd_vote_states_align( void );
55+
56+
/* fd_vote_states_footprint returns the footprint of the vote states
57+
struct for a given amount of max vote accounts. */
58+
59+
ulong
60+
fd_vote_states_footprint( ulong max_vote_accounts );
61+
62+
/* fd_vote_states_new creates a new vote states struct
63+
with a given amount of max vote accounts. It formats a memory region
64+
which is sized based off of the number of vote accounts. */
65+
66+
void *
67+
fd_vote_states_new( void * mem, ulong max_vote_accounts );
68+
69+
/* fd_vote_states_join joins a vote states struct from a
70+
memory region. There can be multiple valid joins for a given memory
71+
region but the caller is responsible for accessing memory in a
72+
thread-safe manner. */
73+
74+
fd_vote_states_t *
75+
fd_vote_states_join( void * mem );
76+
77+
/* fd_vote_states_leave returns the vote states struct from a memory
78+
region. This function returns a pointer to the vote states struct
79+
and does not take ownership of the memory region. */
80+
81+
void *
82+
fd_vote_states_leave( fd_vote_states_t * self );
83+
84+
/* fd_vote_states_delete unformats a memory region that was
85+
formatted by fd_vote_states_new. */
86+
87+
void *
88+
fd_vote_states_delete( void * mem );
89+
90+
91+
FD_PROTOTYPES_END
92+
93+
#endif /* HEADER_fd_src_flamenco_stakes_fd_vote_states_h */
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "fd_stake_delegations.h"
2+
#include "../runtime/fd_runtime_const.h"
3+
4+
int main( int argc, char ** argv ) {
5+
fd_boot( &argc, &argv );
6+
7+
char const * name = fd_env_strip_cmdline_cstr ( &argc, &argv, "--wksp", NULL, NULL );
8+
char const * _page_sz = fd_env_strip_cmdline_cstr ( &argc, &argv, "--page-sz", NULL, "gigantic" );
9+
ulong page_cnt = fd_env_strip_cmdline_ulong( &argc, &argv, "--page-cnt", NULL, 1UL );
10+
ulong near_cpu = fd_env_strip_cmdline_ulong( &argc, &argv, "--near-cpu", NULL, fd_log_cpu_id() );
11+
ulong wksp_tag = fd_env_strip_cmdline_ulong( &argc, &argv, "--wksp-tag", NULL, 1234UL );
12+
13+
fd_wksp_t * wksp;
14+
if( name ) {
15+
FD_LOG_NOTICE(( "Attaching to --wksp %s", name ));
16+
wksp = fd_wksp_attach( name );
17+
} else {
18+
FD_LOG_NOTICE(( "--wksp not specified, using an anonymous local workspace, --page-sz %s, --page-cnt %lu, --near-cpu %lu",
19+
_page_sz, page_cnt, near_cpu ));
20+
wksp = fd_wksp_new_anonymous( fd_cstr_to_shmem_page_sz( _page_sz ), page_cnt, near_cpu, "wksp", 0UL );
21+
}
22+
23+
FD_TEST( wksp );
24+
(void)wksp_tag;
25+
26+
FD_LOG_NOTICE(( "pass" ));
27+
fd_halt();
28+
return 0;
29+
}

0 commit comments

Comments
 (0)