-
Notifications
You must be signed in to change notification settings - Fork 51
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 signature verification + additional validation in xcm-core-buyer #559
Conversation
pallets/xcm-core-buyer/src/lib.rs
Outdated
{ | ||
let block_number = <frame_system::Pallet<T>>::block_number(); | ||
|
||
let current_nonce = CollatorSignatureNonce::<T>::get(); |
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.
Why do we need a nonce? Can't we use the block number as the nonce for example?
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.
Hmm. Yeah. We can use block number as nonce. But problem is that it is not guaranteed at which block this tx will be included and any tx signed with earlier block number can become invalid.
So, the idea is to have nonce just like a substrate account.
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 don't like that it's an extra storage map. But block number won't work, because the tx may not be included in the next block, you're right. Container chain block number (from author-noting pallet) also won't work, because in case of failure we won't be able to retry... There must be something that we can use though.
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.
It is not extra storage map. It's just one storage value at the moment.
I think it is nice trade off between amount of space and the uncertainity.
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.
Oh, really? Sorry, I haven't look into the code yet, but what will happen if two collators try to buy a core in the same block? Will it work or will it fail?
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 of them would succeed and other one would fail. That is sort of drawback. This is the reason why I wanted it originally as storage map.
On second thought, let me modify it as storage map first and then we can arrive at equivalent solution later on.
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.
Yeah I agree, let's work with a storage map now, write some tests to make sure everything works, and then we can think about how to remove this storage map.
f1734ea
to
17e822d
Compare
Coverage Report@@ Coverage Diff @@
## master add-parathread-support-part-2 +/- ##
=================================================================
+ Coverage 69.19% 69.31% +0.12%
+ Files 221 223 +2
+ Lines 39049 39193 +144
=================================================================
+ Hits 27017 27165 +148
- Misses 12032 12028 -4
|
3392279
to
0c0cbf2
Compare
pallets/xcm-core-buyer/src/lib.rs
Outdated
#[cfg(test)] | ||
pub fn set_signature(&mut self, signature: PublicKey::Signature) { | ||
self.signature = signature; | ||
} |
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 would make the fields public instead of having setters
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 only want to make the fields publicly accessible for testing. Can I do that?
Reason being is that if you mutate this struct, it will become invalid as either public key or signature changes.
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.
For types that can be deserialized from bytes, such as this one that implements Decode
, you must assume they can be in an invalid state anyway, so I don't see much benefit from having private fields.
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.
Oh. I did not meant it for validation. Verify function will return false
in that case anyway.
My idea was to indicate anybody who is using this structure in non-test environment to be able to just call new
and get valid instance which they cannot modify as any change there can render the struct invalid and call to fail. So, basically reduce the error surface for anybody working with the struct.
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.
@tmpolaczyk Now, the fields are public. :)
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.
Cool, thank you
let current_slot = T::SlotBeacon::slot(); | ||
if !parathread_params.slot_frequency.should_parathread_buy_core( | ||
Slot::from(current_slot as u64), | ||
Slot::from(2u64), |
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.
Slot::from(2u64), | |
Slot::from(2u64), |
this should be a config parameter probably no?
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.
yes. I have added to-do for that.
I general I like the approach taken but I am missing a bunch of integration tests (with the xcm-emulator, if possible). Any other tests we can run @tmpolaczyk? I feel like any dev-test wont work so at most we can do the zombienet one you have already. To adapt the zombienet test we are going to need to:
Also I have not seen the client-change related to the change of the runtime-api (I think instead of slot_frequency it's called some other thing now), so we should probably modify that too |
We don't have any zombienet tests? I see the one in |
a77eb4d
to
a932640
Compare
a932640
to
6319a74
Compare
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 think it looks great now, great job! I have a few questions though:
-
We have in our xcm-emulator tests tests that use
force_buy_core
. How difficult would it be to implement one that usesbuy_core
? I am not sure which collators do we set there but if they are collators that are backed by a private key (e.g., Alice) we could do this right? -
The zombienet parathread test version can be changed once the node changes are implemented
It is not much of effort to replace
Sure. |
proof, | ||
} = call | ||
{ | ||
let block_number = <frame_system::Pallet<T>>::block_number(); |
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 added the block number to be able to do
.and_provides((block_number, para_id))
because without that, only a single unsigned transaction would ever be included by the block builder. Now that we have the nonce we probably don't need it. But I don't know a good alternative, (para_id, nonce)
won't work because the nonce can be the same for different collators... So probably it's better to just leave it like it is. And unfortunately this is going to be very hard to test...
Description
This PR adds signature verification in the xcm-core-buyer. So that only collator can purchase the core. Apart from that the pallet now only allows collator to buy core if it is inline with the slot frequency.
Changes are as follows:
Remaining: