Skip to main content

Automatic Tx Machine 🏧

Tests

An async EVM transaction retry machine. Programmatically queue, broadcast, and retrying (speedup) transactions. Transactions are queued and broadcasted in a first-in-first-out (FIFO) order.

The machine is designed to be used in a long-running process, like a server.

Diagram

Installation

pip install atxm

Usage

from eth_account.local import LocalAccount
from web3 import Web3, HTTPProvider
from atxm import AutomaticTxMachine
from twisted.internet import reactor


account = LocalAccount.from_keyfile('path/to/keyfile', 'password')
w3 = Web3(HTTPProvider("http://localhost:8545"))

transaction = {
    'chainId': 80001,
    'to': '0x1234567890123456789012345678901234567890',
    'nonce': 0,
    'value': 0,
    'gas': 21000,
    'maxFeePerGas': '1',
    'maxPriorityFeePerGas': '1',
}

machine = AutomaticTxMachine(w3=w3)
future_tx = machine.queue_transaction(
    signer=account,
    params=transaction,
    on_broadcast_failure=...,
    on_fault=...,
    on_finalized=...,
    on_insufficient_funds=...,
)

reactor.run()

Features

Futures

The tracker returns a FutureTx instance when a transaction is queued. The FutureTx instance can be used to track the transaction's lifecycle and to retrieve the transaction's receipt when it is finalized.

Retry Strategies

The tracker supports a generic configurable interface for retry strategies (AsynxTxStrategy). These strategies are used to determine when to retry a transaction and how to do so. They can be configured to use any kind of custom context, like gas oracles.

Lifecycle Hooks

Hooks are fired in a dedicated thread for lifecycle events.

  • on_broadcast (Optional): When a transaction is broadcasted.
  • on_broadcast_failure: When a transaction fails to broadcast.
  • on_finalized: When a transaction is finalized (successful or reverted).
  • on_fault: When a transaction error occurred.
  • on_insufficient_funds: When the account associated with the transaction does not have enough funds for the transaction.
Crash-Tolerance

Internal state is written to a file to help recover from crashes and restarts. Internally caches LocalAccount instances in-memory which in combination with disk i/o is used to recover from async task restarts.

Throttle

There are three rates, work (fast scan), idle (slow scan) and sleep (zero activity). This reduces the use of resources when there are no transactions to track. When a transaction is queued, the machine wakes up and goes to work. When all work is complete it eases into idle mode and eventually goes to sleep.

Event Loop Support

Currently, the machine is designed to work with the Twisted reactor. However, it can be adapted to work with any event loop.

Release files for atxm 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for atxm 0.5.0
File Size Uploaded
atxm-0.5.0.tar.gz 54.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for atxm 0.5.0
File Interpreter ABI Platform
atxm-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 98.2 kB

Release files / atxm-0.5.0.tar.gz

Download URL atxm-0.5.0.tar.gz
Size 54.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7605ab9d2d56b9326511fc4e46fd543ce1369a3d0eb7ec906219de225cb7ceae
BLAKE2b-256 checksum
How to use checksums
3314b242831de31709d03994c51994a984b01fe958d45d893915713a34dce8b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Release files / atxm-0.5.0-py3-none-any.whl

Download URL atxm-0.5.0-py3-none-any.whl
Size 43.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9af8663fe13e2b86d7956c1c8aa485b640bc5c08019a6b7090cfb7c6ac34acc5
BLAKE2b-256 checksum
How to use checksums
2af97d5365b5b1da294a7004db9d6babf745ffd0aadeec9bbd892dc730d4e173
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page