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

Make ValidationPool accepts execution mode to run custom command or in process validation #1622

Merged
14 commits merged into from
Sep 9, 2020

Conversation

cecton
Copy link
Contributor

@cecton cecton commented Aug 21, 2020

Related to paritytech/cumulus#199
Also related to paritytech/cumulus#201 for the actual use

This change will make the polkadot test service use the "test mode" of the validation pool.

I also moved the test flag from the validate_candidate to the pool directly which looks like a refactoring but my actual goal was is to pass the test mode all the way down to the Validation pool. This will be done for v1 of the validation.

@cecton cecton added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. labels Aug 21, 2020
@@ -132,6 +132,9 @@ pub struct ServiceBuilder<C, N, P, SC, SP> {
pub keystore: KeyStorePtr,
/// The maximum block-data size in bytes.
pub max_block_data_size: Option<u64>,
/// The validation worker is called using the subcommand `--nocapture validation_worker` instead
/// of `validation-worker`, suitable for test environment.
pub test_mode: bool,
Copy link
Member

Choose a reason for hiding this comment

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

Why don't we pass an enum here:

enum ValidationExecutionMode {
    Local,
    Remote {
        binary: Path,
        args: Vec<String>,
    }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair point!

I don't know if we need that much flexibility 🤔 do you think? Nobody touched this except me recently and only for testing.

Well! I don't mind changing it for an enum! Should I proceed with the changes?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, this makes this parameter also more clear on what it does.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 8a5aa08

Forked at: bf7ccb8
Parent branch: origin/master
@@ -391,6 +393,15 @@ pub fn new_full<RuntimeApi, Executor>(

polkadot_network_service.register_availability_store(availability_store.clone());

let execution_mode = if test_mode {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
let execution_mode = if test_mode {
let execution_mode = if !test_mode {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wait what. Why? The whole point was to get this on the worker args for the tests. Am I missing something?

Copy link
Member

Choose a reason for hiding this comment

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

See my other comment, this makes no sense. In test mode you don't want to start the external worker and do it as thread instead. You mixed the concepts here totally. You should read the code of the validation again that decides on whether to start a validation worker or to run it inside the process.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh no it's fine I get it now!

So Local would be use by the integration test on cumulus because we don't need it to be interruptible (or any more sophisticated), just need it to run for a few seconds during the test and everything is stopped anyway (because tests have their own process in Rust which is great I think).

Remote is the currently supported case in polkadot (and polkadot's tests!) where a background tasks is ran by spawning a new child process.

ez pz

service/src/lib.rs Outdated Show resolved Hide resolved
cecton and others added 4 commits August 25, 2020 01:03
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Parent branch: origin/master
Forked at: bf7ccb8
Parent branch: origin/master
Forked at: bf7ccb8
Parent branch: origin/master
Forked at: bf7ccb8
Comment on lines 262 to 268
let (cmd, args) = match execution_mode {
ValidationExecutionMode::Local => (
env::current_exe()?,
WORKER_ARGS.iter().map(|x| x.to_string()).collect()
),
ValidationExecutionMode::Remote { binary, args } => (binary, args),
};
Copy link
Member

Choose a reason for hiding this comment

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

Wait. You clear did not understand what Local and Remote mean here.

Local => Run the verification inside the current process
Remote => Use the given external command and args to start a worker.

Copy link
Member

Choose a reason for hiding this comment

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

I actually would prefer an enum option to use default args and executable name. Defaults should work in all cases other than testing, and requiring the user to always specify executable/args would be bad API design. It is very much an internal implementation details and it only leaks away because tests require special handling.

Copy link
Member

Choose a reason for hiding this comment

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

What you mean by enum option?

Copy link
Member

Choose a reason for hiding this comment

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

An enum value that does not require setting executable name for out-of-process validation. E.g. RemoteDefault or simply Remote. Basically something like this:

pub enum ValidationExecutionMode {
	InProcess,
        ExternalProcessSelfHost, 
	ExternalProcessCustomHost {
		binary: PathBuf,
		args: Vec<String>,
	},

Copy link
Member

Choose a reason for hiding this comment

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

Okay. Sounds reasonable.

@@ -391,6 +393,15 @@ pub fn new_full<RuntimeApi, Executor>(

polkadot_network_service.register_availability_store(availability_store.clone());

let execution_mode = if test_mode {
Copy link
Member

Choose a reason for hiding this comment

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

See my other comment, this makes no sense. In test mode you don't want to start the external worker and do it as thread instead. You mixed the concepts here totally. You should read the code of the validation again that decides on whether to start a validation worker or to run it inside the process.

@arkpar
Copy link
Member

arkpar commented Aug 25, 2020

See my other comment, this makes no sense. In test mode you don't want to start the external worker and do it as thread instead.

Some tests rely on the interruptable execution support. I would prefer all test to run as close to the real world usage as possible. The current version of this PR supports out of process execution for tests and I see no problem with that.

@bkchr
Copy link
Member

bkchr commented Aug 25, 2020

See my other comment, this makes no sense. In test mode you don't want to start the external worker and do it as thread instead.

Some tests rely on the interruptable execution support. I would prefer all test to run as close to the real world usage as possible. The current version of this PR supports out of process execution for tests and I see no problem with that.

Yeah and that is totally find and is still supported. I also don't want to remove support for this. However, @cecton had the problem that she wrote an integration tests and was not aware of the remote test execution. And this lead to some nested loop of always starting the same process over and over again.

For our integration test usage it is totally fine to run the validation in the process and that is what this pr is about.

So, what I imagined is the following:

  • You can specify if you want to run the validation worker "local" aka in the process or "remote" aka as a new process
  • This is configured when setting up the validation pool.
  • We can make the internals easier that used Local, Remote and RemoteTest, by merging the later ones. So, when specifying the Remote we give the path to the executable and the arguments.

@arkpar
Copy link
Member

arkpar commented Aug 26, 2020

Yeah and that is totally find and is still supported. I also don't want to remove support for this. However, @cecton had the problem that she wrote an integration tests and was not aware of the remote test execution. And this lead to some nested loop of always starting the same process over and over again.

Right, but this PR fixes that. It allows for tests to run in external process.

For our integration test usage it is totally fine to run the validation in the process and that is what this pr is about.

Are you sure about that? This might not be important for unit tests, but integration tests should be as close to real life behaviour as possible.

@bkchr
Copy link
Member

bkchr commented Aug 26, 2020

Yeah I know, but it is also weird to replicate always this extra test that is being called as the worker. The worker only exists to make validation interruptable and more observabale. I'm not that convinced that this feature is that important to test.

@cecton
Copy link
Contributor Author

cecton commented Aug 30, 2020

For our integration test usage it is totally fine to run the validation in the process and that is what this pr is about.

Are you sure about that? This might not be important for unit tests, but integration tests should be as close to real life behaviour as possible.

Yes I know it sounds weird but as far as cumulus is concerned we don't really test that polkadot can run its validation in a subprocess properly. That is a test done in polkadot. We trust that polkadot is working and is tested. In cumulus we only care that both chains interact properly. Thus the simplest (and with less pitfalls) implementation is better.

However, @cecton had the problem that she wrote an integration tests and was not aware of the remote test execution.

No no I was very aware of that. I did made the subcommand for the original integration tests. I just forgot about it and this time no error message warned me of my mistake (1). What I mean is: this is a human mistake and this is a pitfall.

(1) in the original integration test the command failed when received arguments it couldn't parse. Here it's the test binary that is ran and it doesn't fail easily, it tries to find a test called "validation-worker", filters out everything, and exit with a status 0. This is pure evil.

@cecton cecton changed the title Propagate test mode all the way down to ValidationPool Make ValidationPool accepts execution mode to run custom command or in process validation Sep 2, 2020
Forked at: bf7ccb8
Parent branch: origin/master
@cecton
Copy link
Contributor Author

cecton commented Sep 2, 2020

@bkchr @arkpar ok this is ready for review

cecton added a commit that referenced this pull request Sep 2, 2020
…n process validation (#1622)

Squashed commit of the following:

commit 3eec1ef
Author: Cecile Tonglet <cecile@parity.io>
Date:   Wed Sep 2 11:43:47 2020 +0200

    CLEANUP

    Forked at: bf7ccb8
    Parent branch: origin/master

commit 50ba484
Author: Cecile Tonglet <cecile@parity.io>
Date:   Wed Sep 2 11:42:07 2020 +0200

    Add test

commit 33ced08
Author: Cecile Tonglet <cecile@parity.io>
Date:   Wed Sep 2 11:21:57 2020 +0200

    Run validation inside the same process

commit 4e113ba
Author: Cecile Tonglet <cecile@parity.io>
Date:   Wed Sep 2 10:25:06 2020 +0200

    Adapt code to review suggestions

commit f46e7a7
Merge: 6301515 e2ebf25
Author: Cecile Tonglet <cecile@parity.io>
Date:   Wed Sep 2 10:03:04 2020 +0200

    Merge commit e2ebf25 (no conflict)

    Parent branch: origin/master
    Forked at: bf7ccb8

commit 6301515
Merge: 7f57373 01ffc66
Author: Cecile Tonglet <cecile@parity.io>
Date:   Tue Aug 25 01:09:27 2020 +0200

    Merge commit 01ffc66 (no conflict)

    Parent branch: origin/master
    Forked at: bf7ccb8

commit 7f57373
Merge: 1fd2987 00202d3
Author: Cecile Tonglet <cecile@parity.io>
Date:   Tue Aug 25 01:09:22 2020 +0200

    Merge commit 00202d3 (conflicts)

    Parent branch: origin/master
    Forked at: bf7ccb8

commit 1fd2987
Merge: 41cb5b5 62cf5b9
Author: Cecile Tonglet <cecile@parity.io>
Date:   Tue Aug 25 01:05:23 2020 +0200

    Merge commit 62cf5b9 (no conflict)

    Parent branch: origin/master
    Forked at: bf7ccb8

commit 41cb5b5
Author: Cecile Tonglet <cecile@parity.io>
Date:   Tue Aug 25 01:03:31 2020 +0200

    Update service/src/lib.rs

    Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

commit 8a5aa08
Author: Cecile Tonglet <cecile@parity.io>
Date:   Fri Aug 21 19:06:36 2020 +0200

    WIP

    Forked at: bf7ccb8
    Parent branch: origin/master

commit b7a97df
Author: Cecile Tonglet <cecile@parity.io>
Date:   Fri Aug 21 15:56:21 2020 +0200

    Fix test

commit e28eed7
Author: Cecile Tonglet <cecile@parity.io>
Date:   Fri Aug 21 15:37:13 2020 +0200

    Update validation/src/validation_service/mod.rs

commit 8c880f7
Author: Cecile Tonglet <cecile@parity.io>
Date:   Fri Aug 21 15:02:45 2020 +0200

    Propagate test mode all the way down to ValidationPool

commit d32b42a
Author: Cecile Tonglet <cecile@parity.io>
Date:   Fri Aug 21 15:27:56 2020 +0200

    Initial commit

    Forked at: bf7ccb8
    Parent branch: origin/master
cecton added a commit that referenced this pull request Sep 3, 2020
…n process validation (#1622)

Squashed commit of the following:

commit 3eec1ef
Author: Cecile Tonglet <cecile@parity.io>
Date:   Wed Sep 2 11:43:47 2020 +0200

    CLEANUP

    Forked at: bf7ccb8
    Parent branch: origin/master

commit 50ba484
Author: Cecile Tonglet <cecile@parity.io>
Date:   Wed Sep 2 11:42:07 2020 +0200

    Add test

commit 33ced08
Author: Cecile Tonglet <cecile@parity.io>
Date:   Wed Sep 2 11:21:57 2020 +0200

    Run validation inside the same process

commit 4e113ba
Author: Cecile Tonglet <cecile@parity.io>
Date:   Wed Sep 2 10:25:06 2020 +0200

    Adapt code to review suggestions

commit f46e7a7
Merge: 6301515 e2ebf25
Author: Cecile Tonglet <cecile@parity.io>
Date:   Wed Sep 2 10:03:04 2020 +0200

    Merge commit e2ebf25 (no conflict)

    Parent branch: origin/master
    Forked at: bf7ccb8

commit 6301515
Merge: 7f57373 01ffc66
Author: Cecile Tonglet <cecile@parity.io>
Date:   Tue Aug 25 01:09:27 2020 +0200

    Merge commit 01ffc66 (no conflict)

    Parent branch: origin/master
    Forked at: bf7ccb8

commit 7f57373
Merge: 1fd2987 00202d3
Author: Cecile Tonglet <cecile@parity.io>
Date:   Tue Aug 25 01:09:22 2020 +0200

    Merge commit 00202d3 (conflicts)

    Parent branch: origin/master
    Forked at: bf7ccb8

commit 1fd2987
Merge: 41cb5b5 62cf5b9
Author: Cecile Tonglet <cecile@parity.io>
Date:   Tue Aug 25 01:05:23 2020 +0200

    Merge commit 62cf5b9 (no conflict)

    Parent branch: origin/master
    Forked at: bf7ccb8

commit 41cb5b5
Author: Cecile Tonglet <cecile@parity.io>
Date:   Tue Aug 25 01:03:31 2020 +0200

    Update service/src/lib.rs

    Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

commit 8a5aa08
Author: Cecile Tonglet <cecile@parity.io>
Date:   Fri Aug 21 19:06:36 2020 +0200

    WIP

    Forked at: bf7ccb8
    Parent branch: origin/master

commit b7a97df
Author: Cecile Tonglet <cecile@parity.io>
Date:   Fri Aug 21 15:56:21 2020 +0200

    Fix test

commit e28eed7
Author: Cecile Tonglet <cecile@parity.io>
Date:   Fri Aug 21 15:37:13 2020 +0200

    Update validation/src/validation_service/mod.rs

commit 8c880f7
Author: Cecile Tonglet <cecile@parity.io>
Date:   Fri Aug 21 15:02:45 2020 +0200

    Propagate test mode all the way down to ValidationPool

commit d32b42a
Author: Cecile Tonglet <cecile@parity.io>
Date:   Fri Aug 21 15:27:56 2020 +0200

    Initial commit

    Forked at: bf7ccb8
    Parent branch: origin/master
@cecton
Copy link
Contributor Author

cecton commented Sep 9, 2020

bot merge

@ghost
Copy link

ghost commented Sep 9, 2020

Trying merge.

@ghost ghost merged commit 61dd388 into master Sep 9, 2020
@ghost ghost deleted the cecton-test-mode-all-the-way-down branch September 9, 2020 10:17
cecton added a commit that referenced this pull request Sep 9, 2020
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants