Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
arjain4 committed May 15, 2024
1 parent 1dc4535 commit 3c11edd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 40 deletions.
22 changes: 9 additions & 13 deletions src/flamenco/txn/fd_txn_generate.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ fd_txn_base_generate( uchar out_txn_meta[ static FD_TXN_MAX_SZ ],
uchar * opt_recent_blockhash ) {

FD_TEST(num_signatures <= 128);
*out_txn_payload = (uchar)num_signatures;
/* Fill out txn metadata */
fd_txn_t * txn_meta = (fd_txn_t *) out_txn_meta;
txn_meta->acct_addr_cnt = accounts->acct_cnt;
Expand Down Expand Up @@ -78,11 +79,11 @@ fd_txn_base_generate( uchar out_txn_meta[ static FD_TXN_MAX_SZ ],

/* Write recent blockhash */
if( FD_LIKELY( opt_recent_blockhash ) ) {
memcpy( write_ptr, opt_recent_blockhash, 32UL );
memcpy( write_ptr, opt_recent_blockhash, FD_TXN_BLOCKHASH_SZ );
} else {
memset( write_ptr, 0UL, 32UL );
memset( write_ptr, 0UL, FD_TXN_BLOCKHASH_SZ );
}
write_ptr += 32UL;
write_ptr += FD_TXN_BLOCKHASH_SZ;

return (ulong)(write_ptr - out_txn_payload);
}
Expand All @@ -93,9 +94,8 @@ fd_txn_add_instr( uchar * txn_meta_ptr,
uchar program_id,
uchar const * accounts,
ulong accounts_sz,
fd_build_instr_fun instr_fun,
uchar const * opt_build_args,
ulong opt_args_sz ) {
uchar const * instr_buf,
ulong instr_buf_sz ) {

fd_txn_t * txn_meta = (fd_txn_t *) txn_meta_ptr;
FD_TEST( txn_meta->instr_cnt < FD_TXN_INSTR_MAX );
Expand All @@ -110,6 +110,7 @@ fd_txn_add_instr( uchar * txn_meta_ptr,

write_ptr += compact_instr_cnt_sz;

/* Calculate offset of next instruction. */
if ( txn_meta->instr_cnt > 1 ) {
write_ptr = out_txn_payload + txn_meta->instr[txn_meta->instr_cnt-2].data_off + txn_meta->instr[txn_meta->instr_cnt-2].data_sz;
}
Expand All @@ -125,16 +126,11 @@ fd_txn_add_instr( uchar * txn_meta_ptr,
fd_memcpy( write_ptr, accounts, accounts_sz );
write_ptr += accounts_sz;

/* Build instruction data */
uchar instr_buf[FD_TXN_MTU];
if( opt_build_args == NULL ) {
FD_TEST(opt_args_sz == 0);
}
ushort data_sz = (*instr_fun)( instr_buf, opt_build_args, opt_args_sz );
ushort data_sz = instr_buf_sz;
uint compact_data_len_sz = fd_cu16_enc( data_sz, write_ptr );
write_ptr += compact_data_len_sz;

/* Copy data array over */
/* Copy data buffer over */
ushort data_off = (ushort) (write_ptr - out_txn_payload);
fd_memcpy( write_ptr, instr_buf, data_sz );
write_ptr += data_sz;
Expand Down
31 changes: 4 additions & 27 deletions src/flamenco/txn/fd_txn_generate.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,6 @@ struct fd_txn_accounts {

typedef struct fd_txn_accounts fd_txn_accounts_t;

/* Instruction builder function signature. Accepts an output buffer and optional argument.
Returns the size of the instruction.
An example of such a function used for testing:
ushort build_vote_state_update_instr( uchar * out_buf, uchar * FD_PARAM_UNUSED opt_args, ulong FD_PARAM_UNUSED opt_args_len ) {
fd_vote_instruction_t vote_instr;
vote_instr.discriminant = fd_vote_instruction_enum_update_vote_state;
fd_vote_state_update_t update;
memset(&update, 0, sizeof(fd_vote_state_update_t));
getrandom( update.hash.key, 32UL, 0 );
ulong ts = (ulong)fd_log_wallclock();
update.timestamp = &ts;
vote_instr.inner.update_vote_state = update;
fd_bincode_encode_ctx_t encode = {.data = out_buf, .dataend = (out_buf + FD_TXN_MTU)};
fd_vote_instruction_encode( &vote_instr, &encode );
(void) opt_args;
(void) opt_args_len;
return (ushort)fd_vote_instruction_size( &vote_instr );
}
*/
typedef ushort (*fd_build_instr_fun)( uchar * buf_out, uchar * opt_arg, ulong arg_sz );

FD_PROTOTYPES_BEGIN

/* Method used to create a template for a txn (useful for pre-staging and re-use) */
Expand All @@ -58,15 +36,14 @@ fd_txn_base_generate( uchar out_txn_meta[ static FD_TXN_MAX_SZ ],

/* Method used for adding an instruction to a txn being generated.
The accounts param is a list of indices to the accounts in the txn.
opt_build_args can be NULL, opt_args_len should correspondingly
be set to 0. */
The instruction buffer contains the data for the instruction to
be added. */
ulong
fd_txn_add_instr( uchar * txn_meta_ptr,
uchar out_txn_payload[ static FD_TXN_MTU ],
uchar program_id,
uchar const * accounts,
ulong accounts_sz,
fd_build_instr_fun instr_fun,
uchar const * opt_build_args,
ulong opt_args_sz );
uchar const * instr_buf,
ulong instr_buf_sz );
FD_PROTOTYPES_END

0 comments on commit 3c11edd

Please sign in to comment.