Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
parity
Mirrored projects
polkadot
Commits
38f5cbc1
Unverified
Commit
38f5cbc1
authored
Jul 27, 2020
by
Cecile Tonglet
Committed by
GitHub
Jul 27, 2020
Browse files
Refactor service to allow building full (and light) node matching chain spec (#1467)
parent
f25628ac
Pipeline
#101692
passed with stages
in 25 minutes and 41 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
cli/src/browser.rs
View file @
38f5cbc1
...
...
@@ -46,8 +46,8 @@ async fn start_inner(chain_spec: String, log_level: String) -> Result<Client, Bo
info!
(
"👤 Role: {}"
,
config
.display_role
());
// Create the service. This is the most heavy initialization step.
let
(
task_manager
,
rpc_handlers
)
=
service
::
kusama_new_light
(
config
)
.map_err
(|
e
|
format!
(
"{:?}"
,
e
))
?
;
let
builder
=
service
::
NodeBuilder
::
new
(
config
)
;
let
(
task_manager
,
rpc_handlers
)
=
builder
.build_light
()
.map_err
(|
e
|
format!
(
"{:?}"
,
e
))
?
;
Ok
(
browser_utils
::
start_client
(
task_manager
,
rpc_handlers
))
}
cli/src/command.rs
View file @
38f5cbc1
...
...
@@ -106,8 +106,8 @@ pub fn run() -> Result<()> {
match
&
cli
.subcommand
{
None
=>
{
let
run
time
=
cli
.create_runner
(
&
cli
.run.base
)
?
;
let
chain_spec
=
&
run
time
.config
()
.chain_spec
;
let
run
ner
=
cli
.create_runner
(
&
cli
.run.base
)
?
;
let
chain_spec
=
&
run
ner
.config
()
.chain_spec
;
set_default_ss58_version
(
chain_spec
);
...
...
@@ -124,55 +124,32 @@ pub fn run() -> Result<()> {
info!
(
" endorsed by the "
);
info!
(
" KUSAMA FOUNDATION "
);
info!
(
"----------------------------"
);
}
runtime
.run_node_until_exit
(|
config
|
match
config
.role
{
Role
::
Light
=>
service
::
kusama_new_light
(
config
)
.map
(|(
components
,
_
)|
components
),
_
=>
service
::
kusama_new_full
(
config
,
None
,
None
,
authority_discovery_disabled
,
6000
,
grandpa_pause
,
)
.map
(|(
components
,
_
,
_
)|
components
)
})
}
else
if
chain_spec
.is_westend
()
{
runtime
.run_node_until_exit
(|
config
|
match
config
.role
{
Role
::
Light
=>
service
::
westend_new_light
(
config
)
.map
(|(
components
,
_
)|
components
),
_
=>
service
::
westend_new_full
(
config
,
None
,
None
,
authority_discovery_disabled
,
6000
,
grandpa_pause
,
)
.map
(|(
components
,
_
,
_
)|
components
)
})
}
else
{
runtime
.run_node_until_exit
(|
config
|
match
config
.role
{
Role
::
Light
=>
service
::
polkadot_new_light
(
config
)
.map
(|(
components
,
_
)|
components
),
_
=>
service
::
polkadot_new_full
(
config
,
runner
.run_node_until_exit
(|
config
|
{
let
role
=
config
.role
.clone
();
let
builder
=
service
::
NodeBuilder
::
new
(
config
);
match
role
{
Role
::
Light
=>
builder
.build_light
()
.map
(|(
task_manager
,
_
)|
task_manager
),
_
=>
builder
.build_full
(
None
,
None
,
authority_discovery_disabled
,
6000
,
grandpa_pause
,
)
.map
(|(
components
,
_
,
_
)|
components
)
}
)
}
)
,
}
}
)
},
Some
(
Subcommand
::
Base
(
subcommand
))
=>
{
let
run
time
=
cli
.create_runner
(
subcommand
)
?
;
let
chain_spec
=
&
run
time
.config
()
.chain_spec
;
let
run
ner
=
cli
.create_runner
(
subcommand
)
?
;
let
chain_spec
=
&
run
ner
.config
()
.chain_spec
;
set_default_ss58_version
(
chain_spec
);
if
chain_spec
.is_kusama
()
{
run
time
.run_subcommand
(
subcommand
,
|
config
|
run
ner
.run_subcommand
(
subcommand
,
|
config
|
service
::
new_chain_ops
::
<
service
::
kusama_runtime
::
RuntimeApi
,
service
::
KusamaExecutor
,
...
...
@@ -180,7 +157,7 @@ pub fn run() -> Result<()> {
>
(
config
)
)
}
else
if
chain_spec
.is_westend
()
{
run
time
.run_subcommand
(
subcommand
,
|
config
|
run
ner
.run_subcommand
(
subcommand
,
|
config
|
service
::
new_chain_ops
::
<
service
::
westend_runtime
::
RuntimeApi
,
service
::
WestendExecutor
,
...
...
@@ -188,7 +165,7 @@ pub fn run() -> Result<()> {
>
(
config
)
)
}
else
{
run
time
.run_subcommand
(
subcommand
,
|
config
|
run
ner
.run_subcommand
(
subcommand
,
|
config
|
service
::
new_chain_ops
::
<
service
::
polkadot_runtime
::
RuntimeApi
,
service
::
PolkadotExecutor
,
...
...
@@ -209,21 +186,21 @@ pub fn run() -> Result<()> {
}
},
Some
(
Subcommand
::
Benchmark
(
cmd
))
=>
{
let
run
time
=
cli
.create_runner
(
cmd
)
?
;
let
chain_spec
=
&
run
time
.config
()
.chain_spec
;
let
run
ner
=
cli
.create_runner
(
cmd
)
?
;
let
chain_spec
=
&
run
ner
.config
()
.chain_spec
;
set_default_ss58_version
(
chain_spec
);
if
chain_spec
.is_kusama
()
{
run
time
.sync_run
(|
config
|
{
run
ner
.sync_run
(|
config
|
{
cmd
.run
::
<
service
::
kusama_runtime
::
Block
,
service
::
KusamaExecutor
>
(
config
)
})
}
else
if
chain_spec
.is_westend
()
{
run
time
.sync_run
(|
config
|
{
run
ner
.sync_run
(|
config
|
{
cmd
.run
::
<
service
::
westend_runtime
::
Block
,
service
::
WestendExecutor
>
(
config
)
})
}
else
{
run
time
.sync_run
(|
config
|
{
run
ner
.sync_run
(|
config
|
{
cmd
.run
::
<
service
::
polkadot_runtime
::
Block
,
service
::
PolkadotExecutor
>
(
config
)
})
}
...
...
service/src/lib.rs
View file @
38f5cbc1
...
...
@@ -643,7 +643,7 @@ fn new_light<Runtime, Dispatch, Extrinsic>(mut config: Configuration) -> Result<
let
rpc_extensions
=
polkadot_rpc
::
create_light
(
light_deps
);
let
ServiceComponents
{
task_manager
,
rpc_handlers
,
..
}
=
service
::
build
(
service
::
ServiceParams
{
let
ServiceComponents
{
task_manager
,
rpc_handlers
,
..
}
=
service
::
build
(
service
::
ServiceParams
{
config
,
block_announce_validator_builder
:
None
,
finality_proof_request_builder
:
Some
(
finality_proof_request_builder
),
...
...
@@ -655,7 +655,7 @@ fn new_light<Runtime, Dispatch, Extrinsic>(mut config: Configuration) -> Result<
transaction_pool
:
transaction_pool
.clone
(),
import_queue
,
keystore
,
backend
,
task_manager
,
})
?
;
Ok
((
task_manager
,
rpc_handlers
))
}
...
...
@@ -793,26 +793,76 @@ pub struct FullNodeHandles {
pub
validation_service_handle
:
Option
<
consensus
::
ServiceHandle
>
,
}
/// Create a new Polkadot service for a light client.
pub
fn
polkadot_new_light
(
config
:
Configuration
)
->
Result
<
(
TaskManager
,
Arc
<
RpcHandlers
>
),
ServiceError
>
{
new_light
::
<
polkadot_runtime
::
RuntimeApi
,
PolkadotExecutor
,
_
>
(
config
)
/// A builder for a node.
pub
struct
NodeBuilder
{
config
:
Configuration
,
}
/// Create a new Kusama service for a light client.
pub
fn
kusama_new_light
(
config
:
Configuration
)
->
Result
<
(
TaskManager
,
Arc
<
RpcHandlers
>
),
ServiceError
>
{
new_light
::
<
kusama_runtime
::
RuntimeApi
,
KusamaExecutor
,
_
>
(
config
)
}
impl
NodeBuilder
{
/// Create a new node builder.
pub
fn
new
(
config
:
Configuration
)
->
Self
{
Self
{
config
,
}
}
/// Create a new Westend service for a light client.
pub
fn
westend_new_light
(
config
:
Configuration
,
)
->
Result
<
(
TaskManager
,
Arc
<
RpcHandlers
>
),
ServiceError
>
{
new_light
::
<
westend_runtime
::
RuntimeApi
,
KusamaExecutor
,
_
>
(
config
)
/// Build a new light node.
pub
fn
build_light
(
self
)
->
Result
<
(
TaskManager
,
Arc
<
RpcHandlers
>
),
ServiceError
>
{
if
self
.config.chain_spec
.is_kusama
()
{
new_light
::
<
kusama_runtime
::
RuntimeApi
,
KusamaExecutor
,
_
>
(
self
.config
,
)
}
else
if
self
.config.chain_spec
.is_westend
()
{
new_light
::
<
westend_runtime
::
RuntimeApi
,
WestendExecutor
,
_
>
(
self
.config
,
)
}
else
{
new_light
::
<
polkadot_runtime
::
RuntimeApi
,
PolkadotExecutor
,
_
>
(
self
.config
,
)
}
}
/// Build a new full node.
#[cfg(feature
=
"full-node"
)]
pub
fn
build_full
(
self
,
collating_for
:
Option
<
(
CollatorId
,
parachain
::
Id
)
>
,
max_block_data_size
:
Option
<
u64
>
,
authority_discovery_disabled
:
bool
,
slot_duration
:
u64
,
grandpa_pause
:
Option
<
(
u32
,
u32
)
>
,
)
->
Result
<
TaskManager
,
ServiceError
>
{
if
self
.config.chain_spec
.is_kusama
()
{
new_full
::
<
kusama_runtime
::
RuntimeApi
,
KusamaExecutor
,
_
>
(
self
.config
,
collating_for
,
max_block_data_size
,
authority_discovery_disabled
,
slot_duration
,
grandpa_pause
,
false
,
)
.map
(|(
task_manager
,
_
,
_
,
_
,
_
)|
task_manager
)
}
else
if
self
.config.chain_spec
.is_westend
()
{
new_full
::
<
westend_runtime
::
RuntimeApi
,
WestendExecutor
,
_
>
(
self
.config
,
collating_for
,
max_block_data_size
,
authority_discovery_disabled
,
slot_duration
,
grandpa_pause
,
false
,
)
.map
(|(
task_manager
,
_
,
_
,
_
,
_
)|
task_manager
)
}
else
{
new_full
::
<
polkadot_runtime
::
RuntimeApi
,
PolkadotExecutor
,
_
>
(
self
.config
,
collating_for
,
max_block_data_size
,
authority_discovery_disabled
,
slot_duration
,
grandpa_pause
,
false
,
)
.map
(|(
task_manager
,
_
,
_
,
_
,
_
)|
task_manager
)
}
}
}
Ghost User
@ghost
mentioned in commit
35697065
·
Jul 27, 2020
mentioned in commit
35697065
mentioned in commit 356970655319ba2988db9892e07dd03b25335a24
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment