Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Introduce srml/im-online #3079

Merged
merged 45 commits into from
Jul 20, 2019
Merged

Introduce srml/im-online #3079

merged 45 commits into from
Jul 20, 2019

Conversation

cmichi
Copy link
Contributor

@cmichi cmichi commented Jul 10, 2019

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 of Multiaddr and PeerId.to_string() in the runtime, since parity-multiaddr doesn't compile for wasm currently and libp2p::core::PeerId doesn't support encoding/serializing yet.

@cmichi cmichi added the A0-please_review Pull request needs code review. label Jul 10, 2019
@cmichi cmichi requested a review from tomusdrw July 10, 2019 10:25
srml/im-online/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@tomaka tomaka left a 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.

core/service/Cargo.toml Show resolved Hide resolved
core/offchain/src/api.rs Outdated Show resolved Hide resolved
core/offchain/Cargo.toml Outdated Show resolved Hide resolved
core/offchain/src/api.rs Outdated Show resolved Hide resolved
@tomaka
Copy link
Contributor

tomaka commented Jul 10, 2019

Also, parity-multiaddr should normally compile fine for WASM. It's used in my WASM browser demo.

core/sr-primitives/src/testing.rs Outdated Show resolved Hide resolved
cmichi and others added 7 commits July 10, 2019 15:02
Remove parity-multiaddr dependency

Co-Authored-By: Pierre Krieger <pierre.krieger1708@gmail.com>
Co-Authored-By: Pierre Krieger <pierre.krieger1708@gmail.com>
It was updated in master in the meantime.
@cmichi
Copy link
Contributor Author

cmichi commented Jul 10, 2019

@tomaka

Also, parity-multiaddr should normally compile fine for WASM. It's used in my WASM browser demo.

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?

Copy link
Contributor

@tomaka tomaka left a 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.

Copy link
Contributor

@tomusdrw tomusdrw left a 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/network/src/service.rs Outdated Show resolved Hide resolved
core/offchain/src/api.rs Outdated Show resolved Hide resolved
core/primitives/src/offchain.rs Outdated Show resolved Hide resolved
core/primitives/src/offchain.rs Outdated Show resolved Hide resolved
///
/// # Returns
///
/// - The encoded `Result<offchain::LocalNetworkState, ()>`.
Copy link
Contributor

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.

Copy link
Contributor

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)

srml/im-online/src/lib.rs Outdated Show resolved Hide resolved
srml/im-online/src/lib.rs Outdated Show resolved Hide resolved
srml/im-online/src/lib.rs Outdated Show resolved Hide resolved
srml/im-online/src/lib.rs Outdated Show resolved Hide resolved
srml/im-online/src/lib.rs Outdated Show resolved Hide resolved
@gavofyork gavofyork added A5-grumble and removed A0-please_review Pull request needs code review. labels Jul 10, 2019
srml/im-online/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@pepyakin pepyakin left a 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

core/sr-io/without_std.rs Outdated Show resolved Hide resolved
core/sr-io/without_std.rs Outdated Show resolved Hide resolved
core/sr-io/without_std.rs Outdated Show resolved Hide resolved
core/executor/src/wasm_executor.rs Outdated Show resolved Hide resolved
core/executor/src/wasm_executor.rs Outdated Show resolved Hide resolved
core/executor/src/wasm_executor.rs Outdated Show resolved Hide resolved
core/executor/src/wasm_executor.rs Outdated Show resolved Hide resolved
cmichi and others added 2 commits July 15, 2019 08:50
/// Returns information about the local node's network state.
fn network_state(&self) -> Result<OpaqueNetworkState, ()>;

/// Returns the locally configured authority public key, if available.
Copy link
Member

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.

Copy link
Contributor Author

@cmichi cmichi Jul 18, 2019

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started refactoring the offchain workers api (discussed with @tomusdrw) while @tomaka is refactoring the service factory/components. I'm on vacation till next week. The plan is to rebase #3034 on those PRs

node/runtime/src/lib.rs Outdated Show resolved Hide resolved
core/service/Cargo.toml Outdated Show resolved Hide resolved
core/offchain/Cargo.toml Outdated Show resolved Hide resolved
Copy link
Member

@gavofyork gavofyork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes needed.

@gavofyork gavofyork added this to the 2.0-k milestone Jul 19, 2019
core/network/src/service.rs Outdated Show resolved Hide resolved
@@ -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`.
Copy link
Member

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?

Copy link
Contributor Author

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()?

core/network/src/service.rs Show resolved Hide resolved
@@ -0,0 +1,442 @@
// Copyright 2017-2019 Parity Technologies (UK) Ltd.
Copy link
Member

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/im-online/src/lib.rs Outdated Show resolved Hide resolved
srml/im-online/src/lib.rs Outdated Show resolved Hide resolved
srml/im-online/src/lib.rs Outdated Show resolved Hide resolved
srml/im-online/src/lib.rs Outdated Show resolved Hide resolved
srml/im-online/src/lib.rs Outdated Show resolved Hide resolved
srml/im-online/src/lib.rs Show resolved Hide resolved
@@ -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]>;
Copy link
Member

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)).

Copy link
Member

@gavofyork gavofyork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still extraneous stuff

Copy link
Contributor

@tomaka tomaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-confirming

@gavofyork gavofyork merged commit aa8c06a into master Jul 20, 2019
@gavofyork gavofyork deleted the cmichi-srml-im-online branch July 20, 2019 01:19
@gnunicorn gnunicorn modified the milestones: 2.1, Polkadot Mar 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants