Skip to content

Commit 905e7b6

Browse files
riptlripatel-fd
authored andcommitted
types: remove unused solana_account_meta type
This type doesn't require a serializer, move it to solcap
1 parent 04dc4a9 commit 905e7b6

File tree

10 files changed

+35
-233
lines changed

10 files changed

+35
-233
lines changed

src/flamenco/capture/fd_solcap_writer.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "fd_solcap_proto.h"
55
#include "fd_solcap.pb.h"
6-
#include "../types/fd_types.h"
6+
#include "../types/fd_types_custom.h"
77

88
/* fd_solcap_writer_t is an opaque handle to a capture writer object.
99
Currently, it implements writing SOLCAP_V1_BANK files. See below
@@ -14,6 +14,25 @@ typedef struct fd_solcap_writer fd_solcap_writer_t;
1414

1515
FD_PROTOTYPES_BEGIN
1616

17+
struct __attribute__((packed)) fd_solana_account_meta {
18+
ulong lamports;
19+
uchar owner[32];
20+
uchar executable;
21+
uchar padding[3];
22+
};
23+
typedef struct fd_solana_account_meta fd_solana_account_meta_t;
24+
25+
static inline fd_solana_account_meta_t *
26+
fd_solana_account_meta_init( fd_solana_account_meta_t * meta,
27+
ulong lamports,
28+
void const * owner,
29+
int exec_bit ) {
30+
meta->lamports = lamports;
31+
fd_memcpy( meta->owner, owner, sizeof(fd_pubkey_t) );
32+
meta->executable = !!exec_bit;
33+
return meta;
34+
}
35+
1736
/* fd_solcap_writer_t object lifecycle API ****************************/
1837

1938
/* fd_solcap_writer_{align,footprint} return align and footprint

src/flamenco/runtime/fd_hashes.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,17 @@ fd_hashes_update_lthash( fd_txn_account_t const * account,
9999
if( capture_ctx && capture_ctx->capture &&
100100
fd_bank_slot_get( bank )>=capture_ctx->solcap_start_slot &&
101101
memcmp( prev_account_hash->bytes, new_hash->bytes, sizeof(fd_lthash_value_t))!=0 ) {
102-
fd_solana_account_meta_t meta = fd_txn_account_get_solana_meta( account );
102+
fd_solana_account_meta_t meta[1];
103+
fd_solana_account_meta_init(
104+
meta,
105+
fd_txn_account_get_lamports ( account ),
106+
fd_txn_account_get_owner ( account ),
107+
fd_txn_account_is_executable( account )
108+
);
103109
int err = fd_solcap_write_account(
104110
capture_ctx->capture,
105111
account->pubkey,
106-
&meta,
112+
meta,
107113
fd_txn_account_get_data( account ),
108114
fd_txn_account_get_data_len( account ) );
109115
if( FD_UNLIKELY( err ) ) {

src/flamenco/runtime/fd_runtime.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,12 @@ fd_runtime_buffer_solcap_account_update( fd_txn_account_t * account,
792792
/* Write the message to the buffer */
793793
fd_capture_ctx_account_update_msg_t * account_update_msg = (fd_capture_ctx_account_update_msg_t *)(capture_ctx->account_updates_buffer_ptr);
794794
account_update_msg->pubkey = *account->pubkey;
795-
account_update_msg->info = fd_txn_account_get_solana_meta( account );
795+
fd_solana_account_meta_init(
796+
&account_update_msg->info,
797+
fd_txn_account_get_lamports ( account ),
798+
fd_txn_account_get_owner ( account ),
799+
fd_txn_account_is_executable( account )
800+
);
796801
account_update_msg->data_sz = meta->dlen;
797802
account_update_msg->bank_idx = bank->idx;
798803
memcpy( account_update_msg->hash.uc, lthash->bytes, sizeof(fd_hash_t) );

src/flamenco/runtime/fd_txn_account.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -485,14 +485,3 @@ void
485485
fd_txn_account_set_mutable( fd_txn_account_t * acct ) {
486486
acct->is_mutable = 1;
487487
}
488-
489-
fd_solana_account_meta_t
490-
fd_txn_account_get_solana_meta( fd_txn_account_t const * acct ) {
491-
fd_solana_account_meta_t meta = {
492-
.lamports = acct->meta->lamports,
493-
.rent_epoch = ULONG_MAX,
494-
.executable = acct->meta->executable,
495-
};
496-
memcpy( meta.owner, acct->meta->owner, sizeof(fd_pubkey_t) );
497-
return meta;
498-
}

src/flamenco/runtime/fd_txn_account.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,6 @@ fd_txn_account_set_readonly( fd_txn_account_t * acct );
220220
void
221221
fd_txn_account_set_mutable( fd_txn_account_t * acct );
222222

223-
fd_solana_account_meta_t
224-
fd_txn_account_get_solana_meta( fd_txn_account_t const * acct );
225-
226223
FD_PROTOTYPES_END
227224

228225
#endif /* HEADER_fd_src_flamenco_runtime_fd_txn_account_h */

src/flamenco/types/fd_fuzz_types.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -198,29 +198,6 @@ void *fd_solana_account_stored_meta_generate( void *mem, void **alloc_mem, fd_rn
198198
return mem;
199199
}
200200

201-
void *fd_solana_account_meta_generate( void *mem, void **alloc_mem, fd_rng_t * rng ) {
202-
fd_solana_account_meta_t *self = (fd_solana_account_meta_t *) mem;
203-
*alloc_mem = (uchar *) *alloc_mem + sizeof(fd_solana_account_meta_t);
204-
fd_solana_account_meta_new(mem);
205-
self->lamports = fd_rng_ulong( rng );
206-
self->rent_epoch = fd_rng_ulong( rng );
207-
LLVMFuzzerMutate( &self->owner[0], sizeof(self->owner), sizeof(self->owner) );
208-
self->executable = fd_rng_uchar( rng );
209-
LLVMFuzzerMutate( self->padding, 3, 3 );
210-
return mem;
211-
}
212-
213-
void *fd_solana_account_hdr_generate( void *mem, void **alloc_mem, fd_rng_t * rng ) {
214-
fd_solana_account_hdr_t *self = (fd_solana_account_hdr_t *) mem;
215-
*alloc_mem = (uchar *) *alloc_mem + sizeof(fd_solana_account_hdr_t);
216-
fd_solana_account_hdr_new(mem);
217-
fd_solana_account_stored_meta_generate( &self->meta, alloc_mem, rng );
218-
fd_solana_account_meta_generate( &self->info, alloc_mem, rng );
219-
LLVMFuzzerMutate( self->padding, 4, 4 );
220-
fd_hash_generate( &self->hash, alloc_mem, rng );
221-
return mem;
222-
}
223-
224201
void *fd_delegation_generate( void *mem, void **alloc_mem, fd_rng_t * rng ) {
225202
fd_delegation_t *self = (fd_delegation_t *) mem;
226203
*alloc_mem = (uchar *) *alloc_mem + sizeof(fd_delegation_t);

src/flamenco/types/fd_types.c

Lines changed: 0 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -918,135 +918,6 @@ void fd_solana_account_stored_meta_walk( void * w, fd_solana_account_stored_meta
918918
fun( w, self->pubkey, "pubkey", FD_FLAMENCO_TYPE_HASH256, "uchar[32]", level, 0 );
919919
fun( w, self, name, FD_FLAMENCO_TYPE_MAP_END, "fd_solana_account_stored_meta", level--, 0 );
920920
}
921-
int fd_solana_account_meta_encode( fd_solana_account_meta_t const * self, fd_bincode_encode_ctx_t * ctx ) {
922-
int err;
923-
err = fd_bincode_uint64_encode( self->lamports, ctx );
924-
if( FD_UNLIKELY( err ) ) return err;
925-
err = fd_bincode_uint64_encode( self->rent_epoch, ctx );
926-
if( FD_UNLIKELY( err ) ) return err;
927-
err = fd_bincode_bytes_encode( self->owner, sizeof(self->owner), ctx );
928-
if( FD_UNLIKELY( err ) ) return err;
929-
err = fd_bincode_bool_encode( (uchar)(self->executable), ctx );
930-
if( FD_UNLIKELY( err ) ) return err;
931-
err = fd_bincode_bytes_encode( self->padding, 3, ctx );
932-
if( FD_UNLIKELY( err ) ) return err;
933-
return FD_BINCODE_SUCCESS;
934-
}
935-
static int fd_solana_account_meta_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) {
936-
if( ctx->data>=ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; };
937-
int err = 0;
938-
err = fd_bincode_uint64_decode_footprint( ctx );
939-
if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) return err;
940-
err = fd_bincode_uint64_decode_footprint( ctx );
941-
if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) return err;
942-
err = fd_bincode_bytes_decode_footprint( 32, ctx );
943-
if( FD_UNLIKELY( err ) ) return err;
944-
err = fd_bincode_bool_decode_footprint( ctx );
945-
if( FD_UNLIKELY( err ) ) return err;
946-
err = fd_bincode_bytes_decode_footprint( 3, ctx );
947-
if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) return err;
948-
return 0;
949-
}
950-
int fd_solana_account_meta_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) {
951-
*total_sz += sizeof(fd_solana_account_meta_t);
952-
void const * start_data = ctx->data;
953-
int err = fd_solana_account_meta_decode_footprint_inner( ctx, total_sz );
954-
if( ctx->data>ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; };
955-
ctx->data = start_data;
956-
return err;
957-
}
958-
static void fd_solana_account_meta_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ) {
959-
fd_solana_account_meta_t * self = (fd_solana_account_meta_t *)struct_mem;
960-
fd_bincode_uint64_decode_unsafe( &self->lamports, ctx );
961-
fd_bincode_uint64_decode_unsafe( &self->rent_epoch, ctx );
962-
fd_bincode_bytes_decode_unsafe( &self->owner[0], sizeof(self->owner), ctx );
963-
fd_bincode_bool_decode_unsafe( &self->executable, ctx );
964-
fd_bincode_bytes_decode_unsafe( self->padding, 3, ctx );
965-
}
966-
void * fd_solana_account_meta_decode( void * mem, fd_bincode_decode_ctx_t * ctx ) {
967-
fd_solana_account_meta_t * self = (fd_solana_account_meta_t *)mem;
968-
fd_solana_account_meta_new( self );
969-
void * alloc_region = (uchar *)mem + sizeof(fd_solana_account_meta_t);
970-
void * * alloc_mem = &alloc_region;
971-
fd_solana_account_meta_decode_inner( mem, alloc_mem, ctx );
972-
return self;
973-
}
974-
void fd_solana_account_meta_new(fd_solana_account_meta_t * self) {
975-
fd_memset( self, 0, sizeof(fd_solana_account_meta_t) );
976-
}
977-
void fd_solana_account_meta_walk( void * w, fd_solana_account_meta_t const * self, fd_types_walk_fn_t fun, const char *name, uint level, uint varint ) {
978-
(void) varint;
979-
fun( w, self, name, FD_FLAMENCO_TYPE_MAP, "fd_solana_account_meta", level++, 0 );
980-
fun( w, &self->lamports, "lamports", FD_FLAMENCO_TYPE_ULONG, "ulong", level, 0 );
981-
fun( w, &self->rent_epoch, "rent_epoch", FD_FLAMENCO_TYPE_ULONG, "ulong", level, 0 );
982-
fun( w, self->owner, "owner", FD_FLAMENCO_TYPE_HASH256, "uchar[32]", level, 0 );
983-
fun( w, &self->executable, "executable", FD_FLAMENCO_TYPE_BOOL, "bool", level, 0 );
984-
fun(w, self->padding, "padding", FD_FLAMENCO_TYPE_UCHAR, "uchar", level, 0 );
985-
fun( w, self, name, FD_FLAMENCO_TYPE_MAP_END, "fd_solana_account_meta", level--, 0 );
986-
}
987-
int fd_solana_account_hdr_encode( fd_solana_account_hdr_t const * self, fd_bincode_encode_ctx_t * ctx ) {
988-
int err;
989-
err = fd_solana_account_stored_meta_encode( &self->meta, ctx );
990-
if( FD_UNLIKELY( err ) ) return err;
991-
err = fd_solana_account_meta_encode( &self->info, ctx );
992-
if( FD_UNLIKELY( err ) ) return err;
993-
err = fd_bincode_bytes_encode( self->padding, 4, ctx );
994-
if( FD_UNLIKELY( err ) ) return err;
995-
err = fd_hash_encode( &self->hash, ctx );
996-
if( FD_UNLIKELY( err ) ) return err;
997-
return FD_BINCODE_SUCCESS;
998-
}
999-
static int fd_solana_account_hdr_decode_footprint_inner( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) {
1000-
if( ctx->data>=ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; };
1001-
int err = 0;
1002-
err = fd_solana_account_stored_meta_decode_footprint_inner( ctx, total_sz );
1003-
if( FD_UNLIKELY( err ) ) return err;
1004-
err = fd_solana_account_meta_decode_footprint_inner( ctx, total_sz );
1005-
if( FD_UNLIKELY( err ) ) return err;
1006-
err = fd_bincode_bytes_decode_footprint( 4, ctx );
1007-
if( FD_UNLIKELY( err!=FD_BINCODE_SUCCESS ) ) return err;
1008-
err = fd_hash_decode_footprint_inner( ctx, total_sz );
1009-
if( FD_UNLIKELY( err ) ) return err;
1010-
return 0;
1011-
}
1012-
int fd_solana_account_hdr_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz ) {
1013-
*total_sz += sizeof(fd_solana_account_hdr_t);
1014-
void const * start_data = ctx->data;
1015-
int err = fd_solana_account_hdr_decode_footprint_inner( ctx, total_sz );
1016-
if( ctx->data>ctx->dataend ) { return FD_BINCODE_ERR_OVERFLOW; };
1017-
ctx->data = start_data;
1018-
return err;
1019-
}
1020-
static void fd_solana_account_hdr_decode_inner( void * struct_mem, void * * alloc_mem, fd_bincode_decode_ctx_t * ctx ) {
1021-
fd_solana_account_hdr_t * self = (fd_solana_account_hdr_t *)struct_mem;
1022-
fd_solana_account_stored_meta_decode_inner( &self->meta, alloc_mem, ctx );
1023-
fd_solana_account_meta_decode_inner( &self->info, alloc_mem, ctx );
1024-
fd_bincode_bytes_decode_unsafe( self->padding, 4, ctx );
1025-
fd_hash_decode_inner( &self->hash, alloc_mem, ctx );
1026-
}
1027-
void * fd_solana_account_hdr_decode( void * mem, fd_bincode_decode_ctx_t * ctx ) {
1028-
fd_solana_account_hdr_t * self = (fd_solana_account_hdr_t *)mem;
1029-
fd_solana_account_hdr_new( self );
1030-
void * alloc_region = (uchar *)mem + sizeof(fd_solana_account_hdr_t);
1031-
void * * alloc_mem = &alloc_region;
1032-
fd_solana_account_hdr_decode_inner( mem, alloc_mem, ctx );
1033-
return self;
1034-
}
1035-
void fd_solana_account_hdr_new(fd_solana_account_hdr_t * self) {
1036-
fd_memset( self, 0, sizeof(fd_solana_account_hdr_t) );
1037-
fd_solana_account_stored_meta_new( &self->meta );
1038-
fd_solana_account_meta_new( &self->info );
1039-
fd_hash_new( &self->hash );
1040-
}
1041-
void fd_solana_account_hdr_walk( void * w, fd_solana_account_hdr_t const * self, fd_types_walk_fn_t fun, const char *name, uint level, uint varint ) {
1042-
(void) varint;
1043-
fun( w, self, name, FD_FLAMENCO_TYPE_MAP, "fd_solana_account_hdr", level++, 0 );
1044-
fd_solana_account_stored_meta_walk( w, &self->meta, fun, "meta", level, 0 );
1045-
fd_solana_account_meta_walk( w, &self->info, fun, "info", level, 0 );
1046-
fun(w, self->padding, "padding", FD_FLAMENCO_TYPE_UCHAR, "uchar", level, 0 );
1047-
fd_hash_walk( w, &self->hash, fun, "hash", level, 0 );
1048-
fun( w, self, name, FD_FLAMENCO_TYPE_MAP_END, "fd_solana_account_hdr", level--, 0 );
1049-
}
1050921
int fd_delegation_encode( fd_delegation_t const * self, fd_bincode_encode_ctx_t * ctx ) {
1051922
int err;
1052923
err = fd_pubkey_encode( &self->voter_pubkey, ctx );

src/flamenco/types/fd_types.h

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -176,27 +176,6 @@ struct __attribute__((packed)) fd_solana_account_stored_meta {
176176
typedef struct fd_solana_account_stored_meta fd_solana_account_stored_meta_t;
177177
#define FD_SOLANA_ACCOUNT_STORED_META_ALIGN (8UL)
178178

179-
/* Encoded Size: Fixed (52 bytes) */
180-
struct __attribute__((packed)) fd_solana_account_meta {
181-
ulong lamports;
182-
ulong rent_epoch;
183-
uchar owner[32];
184-
uchar executable;
185-
uchar padding[3];
186-
};
187-
typedef struct fd_solana_account_meta fd_solana_account_meta_t;
188-
#define FD_SOLANA_ACCOUNT_META_ALIGN (8UL)
189-
190-
/* Encoded Size: Fixed (136 bytes) */
191-
struct __attribute__((packed)) fd_solana_account_hdr {
192-
fd_solana_account_stored_meta_t meta;
193-
fd_solana_account_meta_t info;
194-
uchar padding[4];
195-
fd_hash_t hash;
196-
};
197-
typedef struct fd_solana_account_hdr fd_solana_account_hdr_t;
198-
#define FD_SOLANA_ACCOUNT_HDR_ALIGN (8UL)
199-
200179
/* https://github.com/solana-labs/solana/blob/8f2c8b8388a495d2728909e30460aa40dcc5d733/sdk/program/src/stake/state.rs#L303 */
201180
/* Encoded Size: Fixed (64 bytes) */
202181
struct fd_delegation {
@@ -2066,22 +2045,6 @@ static inline int fd_solana_account_stored_meta_decode_footprint( fd_bincode_dec
20662045
}
20672046
void * fd_solana_account_stored_meta_decode( void * mem, fd_bincode_decode_ctx_t * ctx );
20682047

2069-
void fd_solana_account_meta_new( fd_solana_account_meta_t * self );
2070-
int fd_solana_account_meta_encode( fd_solana_account_meta_t const * self, fd_bincode_encode_ctx_t * ctx );
2071-
void fd_solana_account_meta_walk( void * w, fd_solana_account_meta_t const * self, fd_types_walk_fn_t fun, const char *name, uint level, uint varint );
2072-
static inline ulong fd_solana_account_meta_size( fd_solana_account_meta_t const * self ) { (void)self; return 52UL; }
2073-
static inline ulong fd_solana_account_meta_align( void ) { return FD_SOLANA_ACCOUNT_META_ALIGN; }
2074-
int fd_solana_account_meta_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz );
2075-
void * fd_solana_account_meta_decode( void * mem, fd_bincode_decode_ctx_t * ctx );
2076-
2077-
void fd_solana_account_hdr_new( fd_solana_account_hdr_t * self );
2078-
int fd_solana_account_hdr_encode( fd_solana_account_hdr_t const * self, fd_bincode_encode_ctx_t * ctx );
2079-
void fd_solana_account_hdr_walk( void * w, fd_solana_account_hdr_t const * self, fd_types_walk_fn_t fun, const char *name, uint level, uint varint );
2080-
static inline ulong fd_solana_account_hdr_size( fd_solana_account_hdr_t const * self ) { (void)self; return 136UL; }
2081-
static inline ulong fd_solana_account_hdr_align( void ) { return FD_SOLANA_ACCOUNT_HDR_ALIGN; }
2082-
int fd_solana_account_hdr_decode_footprint( fd_bincode_decode_ctx_t * ctx, ulong * total_sz );
2083-
void * fd_solana_account_hdr_decode( void * mem, fd_bincode_decode_ctx_t * ctx );
2084-
20852048
static inline void fd_delegation_new( fd_delegation_t * self ) { fd_memset( self, 0, sizeof(fd_delegation_t) ); }
20862049
int fd_delegation_encode( fd_delegation_t const * self, fd_bincode_encode_ctx_t * ctx );
20872050
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 & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -167,29 +167,6 @@
167167
{ "name": "pubkey", "type": "uchar[32]" }
168168
]
169169
},
170-
{
171-
"name": "solana_account_meta",
172-
"packed": true,
173-
"type": "struct",
174-
"fields": [
175-
{ "name": "lamports", "type": "ulong" },
176-
{ "name": "rent_epoch", "type": "ulong" },
177-
{ "name": "owner", "type": "uchar[32]" },
178-
{ "name": "executable", "type": "bool" },
179-
{ "name": "padding", "type": "array", "element": "uchar", "length": 3 }
180-
]
181-
},
182-
{
183-
"name": "solana_account_hdr",
184-
"packed": true,
185-
"type": "struct",
186-
"fields": [
187-
{ "name": "meta", "type": "solana_account_stored_meta" },
188-
{ "name": "info", "type": "solana_account_meta" },
189-
{ "name": "padding", "type": "array", "element": "uchar", "length": 4 },
190-
{ "name": "hash", "type": "hash" }
191-
]
192-
},
193170
{
194171
"name": "delegation",
195172
"type": "struct",

src/flamenco/types/fd_types_reflect_generated.c

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)