Conversation
Since it's used for |
|
Just my current thoughts (no need to comment now). So from what I understand nonce should prevent Alice from resubmitting the same swap again after it has been claimed/cancelled. With current pallet it is possible. So if Bob is using some permanent account, Alice may swap until Bob's account depletes. I don't yet see how nonce may solve this problem (given current pallet implementation) - Alice may reuse the same signature in all |
cda7e8f to
5cd1b54
Compare
tomusdrw
left a comment
There was a problem hiding this comment.
Looks good! One critical thing (crate_swap enforcing LockClaim block number) and some smaller suggestions.
modules/token-swap/src/lib.rs
Outdated
| /// Current `spec_version` of the Bridged chain. | ||
| type BridgedChainSpecVersion: Get<u32>; | ||
| /// Current weight of the transfer call at the Bridged chain. | ||
| type BridgedChainTransferWeight: Get<Weight>; | ||
| /// Tokens balance type at the Bridged chain. | ||
| type BridgedBalance: Parameter; | ||
| /// Account identifier type at the Bridged chain. | ||
| type BridgedAccountId: Parameter; | ||
| /// Account public key type at the Bridged chain. | ||
| type BridgedAccountPublic: Parameter; | ||
| /// Account signature type at the Bridged chain. | ||
| type BridgedAccountSignature: Parameter; | ||
| /// Converter from raw hash (derived from Bridged chain account) to This chain account. | ||
| type FromBridgedToThisAccountIdConverter: Convert<H256, Self::AccountId>; |
There was a problem hiding this comment.
Couldn't we group all Bridged* types into one larger interface? Ideally why we can't extract that from any already existing chain representations? Wouldn't extending pallet-bridge-messages::Config trait help here a lot in removing the duplicates?
There was a problem hiding this comment.
I can move Balance, AccountId, Public and Signature fields from relay_substrate_client::Chain to bp_runtime::Chain. But that would also mean that even if you only deploying GRANPA pallet you'll need to specify those types as well. Other fields are too specific for messaging or this pallet needs.
Let's do that in a separate PR, though - it'll touch (I assume) too many files. So list of PRs to get this pallet ready:
- this ^^ refactoring;
- integrating into Millau or Rialto runtimes;
- Support dedicated lanes for pallets #962
- weights
| /// 4) the `bridged_currency_transfer_signature` is valid and generated by the owner of the | ||
| /// `target_public_at_bridged_chain` account. | ||
| /// | ||
| /// Violating rule#1 will lead to losing your `source_balance_at_this_chain` tokens. Violating other |
There was a problem hiding this comment.
Hmm, AFAICT if the swap is in Failed state you can still cancel it, no? So no funds should be lost.
There was a problem hiding this comment.
If you've signed any call that has succeeded at the target chain (e.g. system::remark), you can't cancel it on this chain.
There was a problem hiding this comment.
Oh, yeah, you're right. Actually given we allow arbitrary calls here, I'd suggest having the user provide weight as well. This will enable calling into proxy accounts, mutlisigs, etc. Also one less thing the pallet needs to know about the remote chain.
There was a problem hiding this comment.
Right. I've also moved bridged_chain_spec_version to arguments
Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
* token swap pallet * token swap type (replay protection) * post-merge fixes * post-merge fix * Update modules/token-swap/src/lib.rs Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * Update modules/token-swap/src/lib.rs Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * add missing comment part * Update modules/token-swap/src/lib.rs Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * starting claim after lock period is over is forbidden * move spec_version and weight to arguments Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
* token swap pallet * token swap type (replay protection) * post-merge fixes * post-merge fix * Update modules/token-swap/src/lib.rs Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * Update modules/token-swap/src/lib.rs Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * add missing comment part * Update modules/token-swap/src/lib.rs Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * starting claim after lock period is over is forbidden * move spec_version and weight to arguments Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
closes #543 (second option is implemented)
on top of #935 => draft
It won't probably be reviewed (or I'll be unable to respond to review) until at least mid May - I'm opening it early, because I have some questions + some changes for messages pallet that may be illustrated with this PR.
So the actual set of questions:
I'm not sure why we need this unique;random_noncementioned in Token swap pallet #543 @tomusdrw . I guess it is somewhat linked to the replay protection, but I don't see how it can be exploited. Could you elaborate? Without reviewing the code - just the explanation on why we need itI'm not yet sure how to deal with weights ofUpdate delivery confirmation transaction weights to account for delivery callbacks #1012.OnMessagesDeliveredcallbacks (see Relay basic single-bit message dispatch results back to the source chain #935 (comment)). Most probably it'll be pre-hardcoded to1 db read + 1 write per delivered message. Then all callbacks must be implemented as something like:for message in &messages { if check_if_we_are_waiting_this_message(message) { remember_to_do_something_in_next_on_initialize(); } }TODOs for this PR:
deal with this comment - so iiuccda7e8ftransaction_idmust be used to protect against Alice starting the claim again. I've missed that part when implementingTODOs for parallel PRs:
addThis probably can be solved by using customenum MessageOrigin { Runtime, Root, User }and pass it to theLaneMessageVerifier::verify_message()instead of the currentsender. This would allow to implement lanes that are dedicated to some applications or general usage lanesand then passing this origin to the
send_messagefunction. So this is most probably for the runtime-integration PR;TODOs for future PRs: