-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Submit (& sign) extrinsics from the runtime. #3514
Conversation
| } | ||
| } | ||
|
|
||
| impl<Call, Extra> Encode for SignedPayload<Call, Extra> where |
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 is this implementation required?
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.
The generic Signer works on anything that is Encode. I'll rather remove the using_encoded function, I've only added it to be able to document the behavior.
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.
You can also put documentation on top of a trait implementation. It will be shown in rustdocs as welll.
| /// Get an encoded version of this payload. | ||
| /// | ||
| /// Payloads longer than 256 bytes are going to be `blake2_256`-hashed. | ||
| pub fn using_encoded<O>(&self, f: impl FnOnce(&[u8]) -> O) -> O { |
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.
Maybe we should give this a different name?
| /// is going to be different than the `SignaturePayload` - so the thing the extrinsic | ||
| /// actually contains. | ||
| pub struct SignedPayload<Call, Extra: SignedExtension> { | ||
| raw_payload: ( |
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 could not find a reason but I just wonder if you also argued/tought of making this a flat struct rather than one with a single element of a tuple? or is there a strong reason?
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, makes sense. I guess, arguably self.raw_payload.using_encoded is more readable than self.0, but indeed it feels simpler to avoid naming it.
| type ReportLatency = ReportLatency; | ||
| } | ||
|
|
||
| impl system::offchain::CreateTransaction<Runtime, UncheckedExtrinsic> for Runtime { |
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.
where is this being used?
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.
We pass this as SubmitTransaction to im-online:
type SubmitTransaction = TransactionSubmitter<ImOnlineId, Runtime, UncheckedExtrinsic>;
(see Runtime as the second parameter)
Co-Authored-By: Bastian Köcher <[email protected]>
|
|
||
| impl<Account, Signature, AppPublic> Signer<Account, Signature> for AppPublic where | ||
| AppPublic: RuntimeAppPublic + From<Account>, | ||
| AppPublic::Signature: Into<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 am a bit unclear on these new crypto types: what do the bounds here translate to? Who will end up having this impl?
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.
My understanding:
So we have a low-level crypto types (like sr25519 and ed25519) that are commonly used within the "core" runtime part (as AccountId, etc).
We also have application-specific crypto types, which are basically wrappers for the low-level types with additional information about the module (i.e. application) they are coming from.
So for instance, im-online is (or may be) using sr25519 as the crypto type, but instead of sr25119::Public you will rather use im_online::app::Public, as this type has additional APP_ID identification to know it's coming from im_online module.
The APP_ID is very useful especially when querying the Keystore cause we might have many sr25519 keys, but only one (or some) of them will be the one used by im_online module.
So the bounds here basically say:
Please let me know the application-specific crypto type that you want to use for a particular
Account.
Now that I think of it, in the future it might actually be better to use AppPublic instead of Account right from the start (i.e. when we initiate the signing), rather then convert in the middle of the process.
I'll refactor this if I find it more convenient to use that way, when equivocations reporting will be implemented.
| println!("Using a genesis hash of {}", HexDisplay::from(&genesis_hash.as_ref())); | ||
|
|
||
| let raw_payload = ( | ||
| let raw_payload = SignedPayload::from_raw( |
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.
great that this was identified! I exactly had in on a personal todo list to: check subkey with signed extension.
If not here, at some point I would like to add some tests to it to make sure subkey is always generating stuff that can be verified by node (if that's a correct assumption).
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.
Just a bunch of questions; looks good!
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.
LGTM. So the idea is that when we use these APIs for equivocation reporting we'll have to call them under offchain context?
|
@andresilva yes. There is a special |
* Abstract constructing extrinsic and signing. * Initial impl of signer. * Implement get payload. * Clean up the code. * Improve docs. * Bump version. * Update core/sr-primitives/src/generic/unchecked_extrinsic.rs Co-Authored-By: Bastian Köcher <[email protected]> * Fix tests & address grumbles. * Fix build. * Fix runtime tests. * Fix bound test. * Fix bound test.
This PR introduces a helper types to construct, sign and submit transactions from within the runtime.
I've refactored the
im-onlinecode to use the new types and also created a way to submit signed transactions. That's going to be needed for instance for equivocation reporting.Also all places where signatures where constructed (and hashed) are now replaced with
SignedPayload. Proper typing onExtraalso detected a bug insubkey(where the transfers did not contain the correctSignedExtensionspayload).Note that to actually use this API, the call needs to be invoked in the specific
OffchainCallcontext.