services/submitter: Prototype of Transaction Submission Service #4752
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
This commit moves transaction submitter module from an old SDF project and adapts it to the current
stellar/go
API.Why
A service like this can be useful for organizations outside SDF. Also, in SDF we have multiple tx submitters in different projects, using a single, well-tested and battle proven code can save time and prevent some common mistakes.
How it works
TransactionSubmitter
is the main process responsible for submitting transactions. A transaction can be in one of four states:pending
- transaction waiting to be submitted,sending
- transaction loaded and queued to be submitted,sent
- transaction successfully sent (added to ledger)error
- error while sending.Every second
TransactionSubmitter
loadsTransactionPerSecond
transactions withpending
state from a DB and attempts to send them. In a DB transaction it changes their state tosending
.Next, one of
Channel
s is selected to actually submit tx with it's sequence number. Channels are used one after another. If tx is successfully included in the ledger the state is changed tosent
, otherwise toerror
. In case ofbad_seq
error channel state is automatically reloaded.Known limitations
The above algorithm is simple and prevents many common mistakes like attempting to send a transaction again on
error
case (which ex. can be a success but the200 OK
response was not delivered due to network issues).Below is a list of possible improvements to the system:
error
ed transactions. This is probably fine when the system is maintained by an experienced developer but it's not always a case. We could improve the algorithm to detect when theerror
is actually a final state:timebounds.max_time
and monitor ledgers to check if tx actually made it to the ledger in a given time.POST /transactions
call). Maybe we need an intermediate state? This state can be safely reverted topending
on system crash./fee_stats
endpoint in Horizon. As with previous points, txs that did not make it into ledger because of low fee should be resubmitted.PostgresStore
to support other DB engines.