-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Conversation
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 way we fetch external addresses is really not great and goes in the opposite direction of what I'm doing, but considering that this is pressing this is an acceptable approach I'll do some refactoring later.
Also, |
Remove parity-multiaddr dependency Co-Authored-By: Pierre Krieger <pierre.krieger1708@gmail.com>
Co-Authored-By: Pierre Krieger <pierre.krieger1708@gmail.com>
…te into cmichi-srml-im-online
It was updated in master in the meantime.
Ok, thanks. I'll keep the encoded version in WASM for now, since we will probably never need the info in WASM, but only "outside". So we can save the dependency until there is a need to have the encoded object in WASM. I addressed your comments, can you please take a look again? |
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 non-runtime part looks good to me. Someone else should give their approval for the runtime part.
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.
A bunch of grumbles.
core/sr-io/without_std.rs
Outdated
/// | ||
/// # Returns | ||
/// | ||
/// - The encoded `Result<offchain::LocalNetworkState, ()>`. |
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 was about to write a comment that other methods usually don't encode the data, but try to return them using some primitives, but actually I think it's quite alright (I think this small performance hit is acceptable, especially for offchain workers).
@pepyakin any reason why we don't do that for every call? We could even have a single method that needs to be implemented by Rust host that just takes (method: *const u8, method_len: u32, params: *const u8, method_len: u32)
and returns a scale-encoded result. That would simplify the wasm_executor
and externalities a lot.
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.
That's a good question and I cannot answer it properly because I wasn't the most involved person in designing and adding the externalities.
About the single syscall-like entrypoint: I actually had some thoughts about this kind of design for srml-contracts wasm environment. This kind of build up would add some inflexibility and overhead into the substrate host interface. This doesn't just harms the compilation efficiency, but also introduces more high-level problems. For instance, if your runtime wants to call a function that takes two buffers and you have them at hand you cannot pass them directly and would have to encode them probably (re)allocating more than once.
Also, there is another special thing about this design: it has properties of dynamic dispatch. The default way of interaction between a wasm instance and the host is by resolving all imports at the instantiation time and if the instance imports something that doesn't exist the instance cannot be instantiated. On the other hand, with such a dynamic dispatch it would instantiate successfully (cause it imports only the syscall entrypoint) but when it would fail only at the runtime when it tries to call a non-supported function. In general this can be a feature or an issue, but I am inclined to think that in the case of substrate it is more an issue since I doubt that there is a lot to do with conditional logic (the runtime should behave the same regardless the set of available functions).
But yeah, it would definitely make the interface simpler.
As a reference, there is #2334 to achieve the same (but arguably more complex than what you propose)
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.
Gave a brief review, will do another round later
Co-Authored-By: Sergei Pepyakin <sergei@parity.io>
/// Returns information about the local node's network state. | ||
fn network_state(&self) -> Result<OpaqueNetworkState, ()>; | ||
|
||
/// Returns the locally configured authority public key, if available. |
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.
What is the "authority public key"? There are several keys in use for authorities now.
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.
There exists a trait for that with this implementation, which I call to get the current authority public key. This whole part is currently getting reworked in #3034, so I had the assumption that it's still fine in master?
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.
ok
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.
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.
Changes needed.
@@ -520,6 +562,8 @@ enum ServerToWorkerMsg<B: BlockT, S: NetworkSpecialization<B>> { | |||
/// You are encouraged to poll this in a separate background thread or task. | |||
#[must_use = "The NetworkWorker must be polled in order for the network to work"] | |||
pub struct NetworkWorker<B: BlockT + 'static, S: NetworkSpecialization<B>, H: ExHashT> { | |||
/// Updated by the `NetworkWorker` and loaded by the `NetworkService`. |
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 loaded by the networkservice?
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.
Here: https://github.com/paritytech/substrate/pull/3079/files#diff-a045635f3eec17c06b3c7ac7944acceaR500, do you have concerns regarding the name "loading" being associated with the method load()
?
srml/im-online/src/lib.rs
Outdated
@@ -0,0 +1,442 @@ | |||
// Copyright 2017-2019 Parity Technologies (UK) Ltd. |
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 copyright date is incorrect. It should be just 2019.
srml/aura/src/lib.rs
Outdated
@@ -156,7 +156,7 @@ pub trait Trait: timestamp::Trait { | |||
type HandleReport: HandleReport; | |||
|
|||
/// The identifier type for an authority. | |||
type AuthorityId: Member + Parameter + TypedKey + Default; | |||
type AuthorityId: Member + Parameter + TypedKey + Default + AsRef<[u8]>; |
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.
No - there is no need for AsRef([u8]) when it already implies Encode
: just switch whatever(id.as_ref())
to id.using_encoded(|b| whatever(b))
.
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.
Still extraneous stuff
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.
Re-confirming
Addresses #2719.
There are not yet any tests, I'll add those in a follow-up PR. The PR is mostly here to quickly get this into the review pipeline and master.
I currently keep only the
Vec<u8>
version ofMultiaddr
andPeerId.to_string()
in the runtime, sinceparity-multiaddr
doesn't compile for wasm currently andlibp2p::core::PeerId
doesn't support encoding/serializing yet.