Skip to content

Commit

Permalink
flamenco: add instrs reset to txn generation
Browse files Browse the repository at this point in the history
  • Loading branch information
arjain4 committed May 15, 2024
1 parent 9a5c244 commit b62adff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/flamenco/txn/fd_txn_generate.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,17 @@ fd_txn_add_instr( uchar * txn_meta_ptr,
data_sz, acct_off, data_off );
return (ulong)(write_ptr - out_txn_payload);
}

void
fd_txn_reset_instrs( uchar * txn_meta_ptr,
uchar out_txn_payload[ static FD_TXN_MTU ] ) {
fd_txn_t * txn_meta = (fd_txn_t *)txn_meta_ptr;
ulong instr_start = txn_meta->recent_blockhash_off + FD_TXN_BLOCKHASH_SZ;

ushort num_instrs = txn_meta->instr_cnt;
ulong instrs_sz = txn_meta->instr[num_instrs-1].data_off + txn_meta->instr[num_instrs-1].data_sz - instr_start;

fd_memset( (out_txn_payload + instr_start), 0UL, instrs_sz );
fd_memset( txn_meta->instr, 0UL, num_instrs * sizeof(fd_txn_instr_t) );
txn_meta->instr_cnt = 0;
}
6 changes: 6 additions & 0 deletions src/flamenco/txn/fd_txn_generate.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,10 @@ fd_txn_add_instr( uchar * txn_meta_ptr,
ulong accounts_sz,
uchar const * instr_buf,
ulong instr_buf_sz );

/* Helper method to reset the list of instrs in the metadata and
remove all instrs from the txn payload. */
void
fd_txn_reset_instrs( uchar * txn_meta_ptr,
uchar out_txn_payload[ static FD_TXN_MTU ] );
FD_PROTOTYPES_END

0 comments on commit b62adff

Please sign in to comment.