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

[TS SDK] Add account transaction management #8854

Merged
merged 6 commits into from
Jul 28, 2023
Merged

Conversation

0xmaayan
Copy link
Contributor

@0xmaayan 0xmaayan commented Jun 27, 2023

Description

based on #7987

This PR provides a layer for managing and submitting as many transactions from a single account at once.

  • AccountSequenceNumber class - a class that handles and manages an account sequence number.
  • TransactionWorker class - a class that provides workers to manage transactions, from generate through sign and submit to chain. It validates the transaction submission and monitors the submission success/failure.

In addition, provide an example demonstrates the transaction management layer and how one can implement it.

Test Plan

  1. tests are passing

  2. output from running the example against devnet using a wifi connection with download speed of 23.38 mbps and upload speed of 8.40 mbps

starting...
5 sender accounts and 5 recipient accounts created in 0.03299999237060547 seconds
5 sender accounts funded in 2.1549999713897705 seconds
5 sender account balances checked in 0.10400009155273438 seconds
sends 500 transactions to chain....
transactions sent in 59.35899996757507 seconds
transactions sent in 59.45599985122681 seconds
transactions executed in 59.46299982070923 seconds
transactions executed in 59.561999797821045 seconds
transactions sent in 59.56699991226196 seconds
transactions verified in  59.569000005722046  seconds
sender account 0xeb9f3a017bf41af5fc66e38debe5a395dd361f898ea8f37aa2ce202e3c51b874 final sequence number is 500
sender account 0x7d5606f584525c8033dd3726e5c1853fb3d6afd2efe7c348af71b00fba100dcb final sequence number is 500
sender account 0xc3a1ce16add2ddd50917dec2fa711d20d378ba5beb5a0e971c0bac2df12527a7 final sequence number is 500
sender account 0xa32ca88eeba3fa7a1513a642237b4acbe3380aff197142b8ec577dd851f6fc07 final sequence number is 500
sender account 0xae65fa420711b4e225df1caf9475bb8dc481ad3d863e5272d655f0757d737191 final sequence number is 500

@0xmaayan 0xmaayan requested a review from davidiw June 27, 2023 03:39
@0xmaayan 0xmaayan force-pushed the transaction_management branch 3 times, most recently from a5f14ec to becfa82 Compare June 27, 2023 14:35
@0xmaayan 0xmaayan linked an issue Jun 27, 2023 that may be closed by this pull request
@0xmaayan 0xmaayan requested a review from junkil-park July 5, 2023 16:25
Copy link
Contributor

@0xmigo 0xmigo left a comment

Choose a reason for hiding this comment

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

Looks good overall, some nits but good to land :)

@0xmaayan 0xmaayan force-pushed the transaction_management branch 3 times, most recently from 303b340 to 4759193 Compare July 14, 2023 19:45
Copy link
Contributor

@davidiw davidiw left a comment

Choose a reason for hiding this comment

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

good start!

I wonder if it might be useful for me to host a session that goes over what I did in Python?

Some areas of focus in this PR:

  • Needs error handling, if there's any error, the service cannot recover.
  • Limited concurrency -- we should probably make more workers that just pull on the next available transaction and another worker that just processes transactions.
  • Logging would benefit from a cleanup
  • Timestamps to indicate decent throughput would be good too
  • Descriptions of each major components

I'd also be curious to understand how you landed on EventEmitter3 versus say worker threads and making it a js only concept. It might be useful to come up with a story around this and evaluate if it even makes sense to have a high throughput construct for browsers or just node.

@0xmaayan 0xmaayan force-pushed the transaction_management branch 2 times, most recently from 30507bb to acc32e8 Compare July 17, 2023 17:36
Copy link
Contributor

@davidiw davidiw left a comment

Choose a reason for hiding this comment

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

looking good

const res = await Promise.all(waitFor);
console.log(`transactions verified`);
console.log(new Date().toTimeString());
for (const account in res) {
Copy link
Contributor

Choose a reason for hiding this comment

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

line numbers don't make sense, could you please update or hit me up with the lines that do this?

the reason I made this comment was below.. leaving comment there

async synchronize(): Promise<void> {
if (this.lastUncommintedNumber === this.currentNumber) return;

while (this.lock) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not seeing how this connects. Considering that this is a public function, it is a bit dangerous to not get the lock here. Especially with calls into initialize..

@sionescu sionescu requested a review from a team as a code owner July 18, 2023 17:17
@0xmaayan 0xmaayan force-pushed the transaction_management branch 5 times, most recently from ef8f9e8 to d8d1b36 Compare July 19, 2023 00:51
@0xmaayan 0xmaayan force-pushed the transaction_management branch 2 times, most recently from 37d2920 to 19d1543 Compare July 20, 2023 16:48
Copy link
Contributor

@davidiw davidiw left a comment

Choose a reason for hiding this comment

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

looking good

console.log("sentFailed", data);
});

transactionWorker.on(TransactionWorkerEvents.TransactionExecuted, async (data) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

so this is where you're confirming success and syncing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

technically we confirm it here https://github.com/aptos-labs/aptos-core/pull/8854/files#diff-52d3c5103be2ebfaf76511751a50a8fc3ce5f720a77ddd6fed4e74891074edb0R172 , if execution succeed/failed we emit a TransactionExecuted/TransactionExecutionFailed event that the client can listen to and do whatever they want.

async synchronize(): Promise<void> {
if (this.lastUncommintedNumber === this.currentNumber) return;

while (this.lock) {
Copy link
Contributor

Choose a reason for hiding this comment

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

👋

@0xmaayan 0xmaayan force-pushed the transaction_management branch 2 times, most recently from fb45c61 to e9083be Compare July 21, 2023 16:48
Copy link
Contributor

@davidiw davidiw left a comment

Choose a reason for hiding this comment

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

unblocking, but please wait for the lock in synchronize

async synchronize(): Promise<void> {
if (this.lastUncommintedNumber === this.currentNumber) return;

this.lock = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

you can't get the lock without waiting for it, you could theoretically have multiple calls to synchronize... I don't think anything would really bad happen because of the excessive serial nature here, but....

0xmaayan added 5 commits July 27, 2023 15:21
transaction management layer

add sequnce number tests

transaction worker class

add transaction worker and queue class

add start and stop to transaction worker

add txn worker tests

write full flow test

add account transactions management
@0xmaayan 0xmaayan force-pushed the transaction_management branch from e9083be to 2583fc8 Compare July 27, 2023 19:52
@0xmaayan 0xmaayan force-pushed the transaction_management branch from 2583fc8 to ebf3233 Compare July 27, 2023 21:39
@0xmaayan 0xmaayan enabled auto-merge (squash) July 27, 2023 21:39
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

✅ Forge suite compat success on aptos-node-v1.5.1 ==> ebf3233569b4b6f7e5c0ffd36656f86321fe1a14

Compatibility test results for aptos-node-v1.5.1 ==> ebf3233569b4b6f7e5c0ffd36656f86321fe1a14 (PR)
1. Check liveness of validators at old version: aptos-node-v1.5.1
compatibility::simple-validator-upgrade::liveness-check : committed: 4390 txn/s, latency: 7205 ms, (p50: 7800 ms, p90: 9800 ms, p99: 11800 ms), latency samples: 166820
2. Upgrading first Validator to new version: ebf3233569b4b6f7e5c0ffd36656f86321fe1a14
compatibility::simple-validator-upgrade::single-validator-upgrade : committed: 1836 txn/s, latency: 15700 ms, (p50: 18600 ms, p90: 22100 ms, p99: 22600 ms), latency samples: 91840
3. Upgrading rest of first batch to new version: ebf3233569b4b6f7e5c0ffd36656f86321fe1a14
compatibility::simple-validator-upgrade::half-validator-upgrade : committed: 1847 txn/s, latency: 15667 ms, (p50: 19000 ms, p90: 22000 ms, p99: 22300 ms), latency samples: 92360
4. upgrading second batch to new version: ebf3233569b4b6f7e5c0ffd36656f86321fe1a14
compatibility::simple-validator-upgrade::rest-validator-upgrade : committed: 2359 txn/s, latency: 9364 ms, (p50: 10200 ms, p90: 13300 ms, p99: 13800 ms), latency samples: 139200
5. check swarm health
Compatibility test for aptos-node-v1.5.1 ==> ebf3233569b4b6f7e5c0ffd36656f86321fe1a14 passed
Test Ok

@github-actions
Copy link
Contributor

✅ Forge suite realistic_env_max_load success on ebf3233569b4b6f7e5c0ffd36656f86321fe1a14

two traffics test: inner traffic : committed: 6356 txn/s, latency: 6153 ms, (p50: 5700 ms, p90: 7800 ms, p99: 12300 ms), latency samples: 2758860
two traffics test : committed: 100 txn/s, latency: 3092 ms, (p50: 2800 ms, p90: 3700 ms, p99: 7100 ms), latency samples: 1760
Max round gap was 1 [limit 4] at version 1301731. Max no progress secs was 4.011074 [limit 10] at version 1301731.
Test Ok

@github-actions
Copy link
Contributor

✅ Forge suite framework_upgrade success on aptos-node-v1.5.1 ==> ebf3233569b4b6f7e5c0ffd36656f86321fe1a14

Compatibility test results for aptos-node-v1.5.1 ==> ebf3233569b4b6f7e5c0ffd36656f86321fe1a14 (PR)
Upgrade the nodes to version: ebf3233569b4b6f7e5c0ffd36656f86321fe1a14
framework_upgrade::framework-upgrade::full-framework-upgrade : committed: 4057 txn/s, latency: 7654 ms, (p50: 6900 ms, p90: 11700 ms, p99: 22900 ms), latency samples: 166360
5. check swarm health
Compatibility test for aptos-node-v1.5.1 ==> ebf3233569b4b6f7e5c0ffd36656f86321fe1a14 passed
Test Ok

@0xmaayan 0xmaayan merged commit ffdeefe into main Jul 28, 2023
@0xmaayan 0xmaayan deleted the transaction_management branch July 28, 2023 00:37
gedigi pushed a commit that referenced this pull request Aug 2, 2023
* add account transaction management

transaction management layer

add sequnce number tests

transaction worker class

add transaction worker and queue class

add start and stop to transaction worker

add txn worker tests

write full flow test

add account transactions management

* add method comments

* address comments

* implement async queue

* events as enum

* address feedback
xbtmatt pushed a commit that referenced this pull request Aug 13, 2023
* add account transaction management

transaction management layer

add sequnce number tests

transaction worker class

add transaction worker and queue class

add start and stop to transaction worker

add txn worker tests

write full flow test

add account transactions management

* add method comments

* address comments

* implement async queue

* events as enum

* address feedback
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.

[TS SDK] transaction management layer
4 participants