forked from romanz/electrs
-
Notifications
You must be signed in to change notification settings - Fork 131
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
Add /txs endpoint to submit tx packages #119
Open
stevenroose
wants to merge
1
commit into
Blockstream:new-index
Choose a base branch
from
stevenroose:submit-tx-package
base: new-index
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding the transactions to the
Mempool
one-by-one will no longer work once #89 is merged. This is due to 5c8c785, which ensures that the electrs mempool store is always complete and consistent, with no possibility of missing parents. The previous behavior where children could be added to the store without their parents was wrong.For this to work, you'll have to call
Mempool::add()
with a HashMap containing the entire package.The transactions could be retrieved from bitcoind like
broadcast_raw()
/add_by_txid()
are currently implemented, but it would be nicer to use the transactions we already have fromtxshex
. Possibly with a sanity check that they match thetxid
s returned fromsubmitpackage
. And it would probably be a good idea to attempt deserializing the transactions before sending them over them tobitcoind
, as an additional sanity check.Tx broadcast is the only API endpoint that results in a json-rpc call being made to bitcoind, all other queries are served directly from electrs' own db. So we should give some extra care to what we allow to be passed through. Probably a good idea to also limit the package size by tx count and/or bytes.
Apologies that this complicates your PR 😅 Pre-validation and limits were probably needed regardless, but supporting package submission makes them a higher priority.
Thanks for sending this! Package submission would be a great addition to the API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related the hex vs tx thing, I just did exactly what the current
broadcast_raw
does: it does the same thing.Also, generally the packages are ordered so that the parents go before the child, but you're right that's probably not always the case. Adding by hashmap is not a big deal I think.
I agreed that limits on package size make a lot of sense. Any ideas for sensible limits?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can put a bit more work in this, I'm currently actually in need for this API. I have no idea how to effectively test electrs, though. So I'll probably contact you about that :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. It wouldn't be terrible if that remained that way but would be nice to improve it :)
Perhaps worth mentioning that even if bitcoind sends them back that way, the ordering might still be lost on the way because
tx-results
is returned as a JSON object that doesn't have a guaranteed order (like an array would).I'm not sure really, open to suggestions. but I guess we could start with a relatively low limit and increase it if needed, maybe something like 5 transactions and 2500 bytes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more thing to note is that
Mempool::add()
expects to be called with new transactions only, so you'd need to remove any transactions that are already known from the hashmap.(The existing code shouldn't ever add known transactions, but
Mempool::add()
should still probably be fixed up to handle this more sanely - either skip known transactions or fail with an error. Right now it will mess up the indexes >.<)