Skip to content

Commit

Permalink
refactor: remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
lidatong committed Aug 10, 2023
1 parent 5935cc3 commit fb4265b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 41 deletions.
33 changes: 9 additions & 24 deletions src/tango/stake/fd_stake.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "../mvcc/fd_mvcc.h"
#include "fd_stake.h"
#include <stdio.h>

ulong
fd_stake_align( void ) {
Expand Down Expand Up @@ -83,49 +84,33 @@ fd_stake_nodes_laddr( fd_stake_t * stake ) {
}

void
fd_stake_write( fd_stake_t * stake, uchar * data, ulong sz ) {
fd_stake_deser( fd_stake_t * stake, uchar * data, ulong sz ) {
fd_mvcc_begin_write( &stake->mvcc );

fd_stake_node_t * staked_nodes = fd_stake_nodes_laddr( stake );
fd_stake_node_clear( staked_nodes );
ulong total_stake = 0;
for ( ulong off = 0; off < sz; off += 40 ) {
/* 32-byte aligned. dcache is 128-byte aligned. 128 % 32 = 0. */
fd_stake_pubkey_t * pubkey = (fd_stake_pubkey_t *)( fd_type_pun( data + off ) );
/* 8-byte aligned. 32 + 8 = 40. 40 % 8 = 0. */
ulong * stake =
(ulong *)( fd_type_pun( data + off + sizeof( fd_stake_pubkey_t ) ) );
ulong stake =
*(ulong *)( fd_type_pun( data + off + sizeof( fd_stake_pubkey_t ) ) );
fd_stake_node_t * staked_node = fd_stake_node_insert( staked_nodes, *pubkey );
if ( staked_node == NULL ) staked_node = fd_stake_node_query( staked_nodes, *pubkey, NULL );
if ( staked_node == NULL ) {
FD_LOG_HEXDUMP_WARNING( ( "failed to insert pubkey", pubkey, sizeof( fd_stake_pubkey_t ) ) );
continue;
}
staked_node->stake = *stake;
staked_node->stake = stake;
total_stake += stake;
}
printf("writing total stake %lu\n", stake->total_stake);
stake->total_stake = total_stake;

fd_mvcc_end_write( &stake->mvcc );
}

fd_stake_t *
fd_stake_read( fd_stake_t * stake ) {
ulong begin = fd_mvcc_begin_read( &stake->mvcc );
return fd_ptr_if(begin % 2, NULL, stake);

// /* TODO maintain old/new */
// fd_stake_t * read;
// fd_ptr_if(begin % 1 == 0, stake->old, stake->new)
// if (begin % 1 == 0) {
// read =
// } else {

// }
// ulong end = fd_mvcc_end_read( &stake->mvcc );
// if (end != begin) {
// return NULL;
// }
// return read;
}

void
fd_stake_dump( fd_stake_t * stake ) {
fd_stake_node_t * staked_nodes = fd_stake_nodes_laddr( stake );
Expand Down
22 changes: 10 additions & 12 deletions src/tango/stake/fd_stake.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#ifndef HEADER_fd_src_tango_stake_fd_stake_h
#define HEADER_fd_src_tango_stake_fd_stake_h

#include "../../ballet/txn/fd_txn.h"
#include "../mvcc/fd_mvcc.h"

/* double cache line */
#define FD_STAKE_ALIGN ( 128 )
#define FD_STAKE_ALIGN 128UL

/* maximum lg # of staked nodes we can track */
#define FD_STAKE_LG_SLOT_CNT ( 16 )
#define FD_STAKE_LG_SLOT_CNT 16UL

/* 32-bytes, as with all Solana pubkeys */
#define FD_STAKE_PUBKEY_SZ 32UL

/* opaque */
#define FD_STAKE_MAGIC ( 0xF17EDA2CE757A1E0 ) /* FIREDANCER STAKE V0 */
#define FD_STAKE_MAGIC 0xF17EDA2CE757A1E0 /* FIREDANCER STAKE V0 */

struct fd_stake_private {
ulong magic; /* == FD_STAKE_MAGIC */
Expand All @@ -22,7 +24,7 @@ struct fd_stake_private {
typedef struct fd_stake_private fd_stake_t;

struct fd_stake_pubkey {
uchar pubkey[FD_TXN_PUBKEY_SZ];
uchar pubkey[FD_STAKE_PUBKEY_SZ];
};

typedef struct fd_stake_pubkey fd_stake_pubkey_t;
Expand All @@ -41,13 +43,9 @@ typedef struct fd_stake_node fd_stake_node_t;
#define MAP_KEY_T fd_stake_pubkey_t
#define MAP_KEY_NULL pubkey_null
#define MAP_KEY_INVAL( k ) !( memcmp( &k, &pubkey_null, sizeof( fd_stake_pubkey_t ) ) )
#define MAP_KEY_EQUAL( k0, k1 ) !( memcmp( ( k0.pubkey ), ( k1.pubkey ), FD_TXN_PUBKEY_SZ ) )
// #define MAP_KEY_EQUAL( k0, k1 ) map_key_equal(k0, k1)
// #define MAP_KEY_EQUAL( k0, k1 ) (sizeof(k0.pubkey) == sizeof(k1.pubkey))
#define MAP_KEY_EQUAL( k0, k1 ) !( memcmp( ( k0.pubkey ), ( k1.pubkey ), FD_STAKE_PUBKEY_SZ ) )
#define MAP_KEY_EQUAL_IS_SLOW 1
#define MAP_KEY_HASH( key ) ( (uint)( fd_hash( 0UL, key.pubkey, FD_TXN_PUBKEY_SZ ) ) )
// #define MAP_KEY_HASH( key ) ( fd_uint_load_4( fd_type_pun( &key.pubkey ) ) )
// #define MAP_KEY_HASH( key ) ( *(uint *)( fd_type_pun( &key.pubkey ) ) ) /* FIXME UB */
#define MAP_KEY_HASH( key ) ( (uint)( fd_hash( 0UL, key.pubkey, FD_STAKE_PUBKEY_SZ ) ) )
#include "../../util/tmpl/fd_map_dynamic.c"

ulong
Expand Down Expand Up @@ -127,7 +125,7 @@ fd_stake_read( fd_stake_t * stake);
...
----------- */
void
fd_stake_write( fd_stake_t * stake, uchar * data, ulong sz );
fd_stake_deser( fd_stake_t * stake, uchar * data, ulong sz );

void
fd_stake_dump( fd_stake_t * stake );
Expand Down
5 changes: 0 additions & 5 deletions src/tango/stake/test_stake.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ test_stake( void ) {
FD_TEST( staked_node );
FD_TEST( staked_node->stake == i );
}

stake->mvcc.version = 0;
FD_TEST( fd_stake_read( stake ) );
stake->mvcc.version = 1;
FD_TEST( !fd_stake_read( stake ) );
}

int
Expand Down

0 comments on commit fb4265b

Please sign in to comment.