-
Notifications
You must be signed in to change notification settings - Fork 24
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 atomic name trades #325
base: master-4.0.2
Are you sure you want to change the base?
Conversation
Implements signing for sighash types other than `ALL` for segwit inputs. fixes spesmilo#7408 Backported from Electrum 4.2.0.
a47f2ce
to
dbadb99
Compare
@domob1812 @yanmaani Feel free to review. Functional tests aren't added yet; I will do so before merging, but it's currently working well enough that it should be reviewable. Workflow is to use |
Functional tests are added now; this is a candidate for merging. |
@ryancdotorg FYI this PR implements your NameTrade non-interactive scheme. |
neat |
@domob1812 @yanmaani note that I'd like Namecoin Core to wind up with the same RPC API as Electrum-NMC for this (modulo inherent differences between Core and Electrum), so if there are any issues with this API that might block it from being merged to Namecoin Core, please bring those up before this is merged. |
Note that if this PR is approved, it will be applied to |
Notes on review:
First of all, as for the implementation:
Now on to the higher-level stuff. As you say, it's of great importance that Namecoin Core and Electrum-NMC are consistent here, both in respect of:
As for the interface, the API that I've written some (unfinished) code1 for is:
In this respect, the code is very similar but not fully the same. In particular, why do you do the following?
Why not just make I've also thought it'd be very useful to be able to specify extra options, in particular a locktime. Either you'd have one option for each such "gadget", or there could perhaps be a singular option that added transaction flags. What do you reckon would be best? (This is not a blocker, but would be very nice to have soon-ish so you can do auctions etc) As concerns the second point, would it be possible to have unit tests that load specific private keys and ensure that the offers generated are bit-for-bit identical? If not, I think it would at least be reasonable to throw in some test vector offers and make sure that they can be accepted. Footnotes
|
From a quick glance (I don't have time for more at the moment and in the forseeable future) the API looks fine to me (and pretty straight-forward). Have you thought about using PSBTs instead of raw transactions, though? |
Good review, thanks.
@yanmaani Electrum commands use Decimals, not floats. So there shouldn't be any issues with rounding. The intent of doing the equality check is to avoid surprises, even if they are surprises that we expect the user to find pleasant. (I can imagine scenarios in which the two parties are friends or otherwise have an existing relationship, in which case one party might want to notify the other party if they accidentally fat-fingered a price and are selling a name for much less than intended.) That said, I think it would be reasonable to modify the Exception messages to explicitly say what the Offer amount is and what the user-entered amount is, so that users have a little more context if there's a mismatch.
The commands don't handle coin locking, whether by marking coins as spent or frozen. This is consistent with all other Electrum commands. E.g. if you run
Standard convention in Electrum's RPC API is that the user specifies fees separately from the amount, via the
I don't want to try to process an Offer that's in an unexpected form, so I do as much validation as possible before I process it. It's not clear to me that all of these are security-critical, but it seems safer this way.
I tried briefly to abstract the buy and sell commands into a metacommand, but it turned out to be harder to read. I think the code that parses the amount of the Offer might be able to use some helper functions that Electrum already has; last I looked most of those helper functions don't support name operations properly, but maybe that can be improved.
Namecoin Core has an atomic trade functional test; the tests in this PR follow a similar workflow (though it's simpler because this API is higher-level than what Namecoin Core has). I'm not opposed to adding extra checks that Namecoin Core's test doesn't have.
Standard Electrum convention is to use separate parameters for things like
I know the unit tests can load a specific seed and check that transactions match exactly. I'm not sure how easy it is to do that with RPC commands. It's probably not very hard; I will look into it.
@domob1812 I asked the Bitcoin Core guys about this, and they said that PSBT is the wrong format for this use case. PSBT exists for use cases where a given scriptSig needs collaboration from multiple users in order to construct (e.g. a multisig scriptSig); the network serialization format of transactions doesn't have any defined way to include empty or partially-constructed scriptSigs. The use case in this PR doesn't have that issue; each scriptSig is fully defined by one user, so there is no circumstance where empty or partial scriptSigs have to hit the wire. The fact that different scriptSigs are written by different users doesn't change that. Given this, the Bitcoin Core guys told me that the standard network serialization format used by the raw transaction API is the correct way to do this. Given that @domob1812 is mostly occupied, I'll assume that code review from @yanmaani is sufficient, unless Daniel registers an objection to something. |
That's true if you enter it as a Decimal, as opposed to calling it directly with a float.
I am not convinced that this is a good idea, and it will lead to an inconsistent API between the two versions. At the very least, the error messages should say whether it's too much or too little, and these should be two separate error conditions/types. If the price is too much, I would strongly suggest, if the established practice for error messages permits it, that the message explicitly suggests to lower your price to the asking price. (Also, see below)
OK, I think this is fine. Maybe it should be an option - we might want some offers to be mutually exclusive - but that's for a future GUI patch. Anyway, you should probably document these decisions explicitly in the code.
Bitcoin Core does that too, no?
Not true. Consider Bitcoin - they had $50/txn fees at some points in time. If such fees happen on Namecoin, users will have to pay very big sums compared to their potential gain, even if the tx is small.
If so, why would you have the "exact amount" API? If users are trading with their friends and they fat-finger the amount, then surely by the same measure they should just be able to review before sending? IMO, including footguns is always a bad idea, even if people have the option of double-checking. It's still not great if people can get that badly punished on fees. Especially for the case of selling names, I also don't see how it's consistent with current practice. When you send a payment request for 1 mBTC, you're implicitly asking the payer to pay 1.01 mBTC or whatever the fees are, no? So "fees are on top of the amount" can only logically apply for the buyer. (That said, if he is the maker, then the taker=seller will set the fees anyway, and so since this only applies for taker=buyer, it seems better to go "all the way" to be consistent on both sides and across implementations.)
I'm not sure that this is a great idea, since it makes the function harder to read. At the very least, why not put the not-strictly-necessary checks into a separate function?
What about writing a tiny helper function that calculates net loss/gain from a tx, and using it only for this code?
Yes, but Namecoin Core doesn't have a high-level API for atomic name trades (yet!). So the test should be much more advanced, since the Core test just does basic smoke testing to ensure this is a supported feature. As far as I can see, these are the possible cases to test:
Are Electrum tests also supposed to be 100%?
Great!
It's not possible for
Sounds good.
Great! |
Ok, makes sense - in this case, the transaction is collaborative, but not the individual signatures. Concept ACK from my side, but yeah, I won't be able to review the Python code (and even if I were, I'm not an expert in Python and/or Electrum anyway). |
Merged to 4.0.6 branch per consensus with @yanmaani. Leaving this PR open to track subsequent improvements from his review. |
No description provided.