Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flamenco: adds txn generation methods #1692

Merged
merged 2 commits into from
May 16, 2024
Merged

flamenco: adds txn generation methods #1692

merged 2 commits into from
May 16, 2024

Conversation

arjain4
Copy link
Contributor

@arjain4 arjain4 commented May 1, 2024

Transaction generation for sending votes etc

@arjain4 arjain4 requested a review from lidatong May 1, 2024 16:37
@arjain4 arjain4 changed the title flamenco: Adds txn generation methods flamenco: adds txn generation methods May 1, 2024
@arjain4 arjain4 requested a review from lheeger-jump May 2, 2024 16:35
src/flamenco/txn/fd_txn_generate.c Outdated Show resolved Hide resolved
src/flamenco/txn/fd_txn_generate.c Outdated Show resolved Hide resolved
src/flamenco/txn/fd_txn_generate.c Outdated Show resolved Hide resolved
src/flamenco/txn/fd_txn_generate.c Outdated Show resolved Hide resolved
src/flamenco/txn/fd_txn_generate.c Outdated Show resolved Hide resolved
src/flamenco/txn/fd_txn_generate.h Outdated Show resolved Hide resolved
src/flamenco/txn/fd_txn_generate.h Outdated Show resolved Hide resolved
src/flamenco/txn/fd_txn_generate.h Outdated Show resolved Hide resolved
src/flamenco/txn/fd_txn_generate.h Outdated Show resolved Hide resolved
src/flamenco/txn/fd_txn_generate.h Outdated Show resolved Hide resolved
@arjain4 arjain4 marked this pull request as draft May 14, 2024 22:06
@arjain4
Copy link
Contributor Author

arjain4 commented May 14, 2024

@ptaffet-jump thank you for the review, this should have been marked as a draft actually. Started cleaning up the code and will look into simplifying these APIs. The first version was just hacked up a few months ago to prove we could send votes to solana. The design comments will be particularly helpful as we start thinking about how we'll use these again

@arjain4 arjain4 force-pushed the arjain/txn_generation branch 3 times, most recently from d1711fe to a9c25fe Compare May 15, 2024 17:23
@arjain4 arjain4 marked this pull request as ready for review May 15, 2024 17:23
@arjain4 arjain4 force-pushed the arjain/txn_generation branch 2 times, most recently from b62adff to 54052c1 Compare May 16, 2024 20:28
@arjain4 arjain4 added this pull request to the merge queue May 16, 2024
Merged via the queue into main with commit 340401d May 16, 2024
10 checks passed
@arjain4 arjain4 deleted the arjain/txn_generation branch May 16, 2024 21:52
write_ptr += compact_instr_cnt_sz;

/* Calculate offset of next instruction. */
if ( FD_UNLIKELY( txn_meta->instr_cnt > 1 ) ) {
Copy link
Contributor

@yhzhangjump yhzhangjump May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why this is txn_meta->instr_cnt > 1 instead of txn_meta->instr_cnt > 0. It seems that, even if txn_meta->instr_cnt == 1, we should recalculate write_ptr.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the write_ptr is already at the right offset for that case

program_id,
(ushort)accounts_sz,
data_sz, acct_off, data_off );
return (ulong)(instr_start - out_txn_payload);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that you are returning the old txn size instead of the new txn size. Is this deliberate? It seems more natural to return the new txn size.
Also, you never check whether we are writing more than FD_TXN_MTU bytes to out_txn_payload. It may be useful to guarantee that this function never writes overflow out_txn_payload, for security purposes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this returns the size of the just added instr

}

void
fd_txn_reset_instrs( uchar * txn_meta_ptr,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe call it fd_txn_remove_instrs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove is used for removing a single element across firedancer so i steered clear of that for this

txn_meta->readonly_unsigned_cnt = accounts->readonly_unsigned_cnt;
/* Number of signatures is encoded as a compact u16 but
can always be encoded using 1 byte here. */
txn_meta->message_off = (ushort)(num_signatures * FD_TXN_SIGNATURE_SZ + 1);
Copy link
Contributor

@yhzhangjump yhzhangjump May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If num_signatures is higher than 20, then this offset is already going beyond FD_TXN_MTU (20*64=1280>1232). It seems useful to guarantee that this function would never write beyond FD_TXN_MTU bytes from out_txn_payload.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have it setup such that the caller can specify a larger buffer. That can be changed in a follow up PR if you'd like to take a look at that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants