Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Duniter v2S
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
rust
Duniter v2S
Commits
163cb9d3
Commit
163cb9d3
authored
3 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
ref(node): normalize chain spec runtime type identification
parent
fcfe9f0e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!18
Several things
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
node/src/command.rs
+21
-25
21 additions, 25 deletions
node/src/command.rs
node/src/service.rs
+27
-25
27 additions, 25 deletions
node/src/service.rs
with
48 additions
and
50 deletions
node/src/command.rs
+
21
−
25
View file @
163cb9d3
...
...
@@ -22,7 +22,7 @@ use crate::service::G1Executor;
use
crate
::
service
::
GDevExecutor
;
#[cfg(feature
=
"gtest"
)]
use
crate
::
service
::
GTestExecutor
;
use
crate
::
service
::
Identify
Variant
;
use
crate
::
service
::
{
Identify
RuntimeType
,
RuntimeType
}
;
use
crate
::{
chain_spec
,
service
};
use
sc_cli
::{
ChainSpec
,
RuntimeVersion
,
SubstrateCli
};
...
...
@@ -74,17 +74,13 @@ impl SubstrateCli for Cli {
.unwrap_or
(
false
)
};
enum
RuntimeType
{
G1
,
GDev
,
GTest
,
}
let
runtime_type
=
if
starts_with
(
"g1"
)
{
RuntimeType
::
G1
}
else
if
starts_with
(
"gdem"
)
||
starts_with
(
"gtest"
)
{
}
else
if
starts_with
(
"gdem"
)
{
RuntimeType
::
GTest
}
else
if
starts_with
(
"dev"
)
||
starts_with
(
"gdev"
)
{
RuntimeType
::
GDev
}
else
if
starts_with
(
"g
dev
"
)
{
}
else
if
starts_with
(
"g
t
"
)
{
RuntimeType
::
GTest
}
else
{
panic!
(
"unknown runtime"
)
...
...
@@ -108,13 +104,13 @@ impl SubstrateCli for Cli {
}
fn
native_runtime_version
(
spec
:
&
Box
<
dyn
ChainSpec
>
)
->
&
'static
RuntimeVersion
{
match
spec
{
match
spec
.runtime_type
()
{
#[cfg(feature
=
"g1"
)]
spec
if
spec
.is_main
()
=>
&
g1_runtime
::
VERSION
,
RuntimeType
::
G1
=>
&
g1_runtime
::
VERSION
,
#[cfg(feature
=
"gtest"
)]
spec
if
spec
.is_t
est
()
=>
&
gtest_runtime
::
VERSION
,
RuntimeType
::
GT
est
=>
&
gtest_runtime
::
VERSION
,
#[cfg(feature
=
"gdev"
)]
spec
if
spec
.is_dev
()
=>
&
gdev_runtime
::
VERSION
,
RuntimeType
::
GDev
=>
&
gdev_runtime
::
VERSION
,
_
=>
panic!
(
"unknown runtime"
),
}
}
...
...
@@ -130,19 +126,19 @@ pub fn run() -> sc_cli::Result<()> {
let
runner
=
cli
.create_runner
(
cmd
)
?
;
runner
.sync_run
(|
config
|
{
if
cmd
.shared_params.dev
{
match
&
config
.chain_spec
{
match
config
.chain_spec
.runtime_type
()
{
#[cfg(feature
=
"g1"
)]
chain_spec
if
chain_spec
.is_main
()
=>
cmd
.run
(
RuntimeType
::
G1
=>
cmd
.run
(
Box
::
new
(
chain_spec
::
g1
::
development_chain_spec
()
?
),
config
.network
,
),
#[cfg(feature
=
"gtest"
)]
chain_spec
if
chain_spec
.is_t
est
()
=>
cmd
.run
(
RuntimeType
::
GT
est
=>
cmd
.run
(
Box
::
new
(
chain_spec
::
gtest
::
development_chain_spec
()
?
),
config
.network
,
),
#[cfg(feature
=
"gdev"
)]
chain_spec
if
chain_spec
.is_dev
()
=>
cmd
.run
(
RuntimeType
::
GDev
=>
cmd
.run
(
Box
::
new
(
chain_spec
::
gdev
::
development_chain_spec
()
?
),
config
.network
,
),
...
...
@@ -197,16 +193,16 @@ pub fn run() -> sc_cli::Result<()> {
let
runner
=
cli
.create_runner
(
cmd
)
?
;
let
chain_spec
=
&
runner
.config
()
.chain_spec
;
match
chain_spec
{
match
chain_spec
.runtime_type
()
{
#[cfg(feature
=
"g1"
)]
chain_spec
if
chain_spec
.is_main
()
=>
{
RuntimeType
::
G1
=>
{
runner
.sync_run
(|
config
|
cmd
.run
::
<
g1_runtime
::
Block
,
G1Executor
>
(
config
))
}
#[cfg(feature
=
"gtest"
)]
chain_spec
if
chain_spec
.is_t
est
()
=>
runner
RuntimeType
::
GT
est
=>
runner
.sync_run
(|
config
|
cmd
.run
::
<
gtest_runtime
::
Block
,
GTestExecutor
>
(
config
)),
#[cfg(feature
=
"gdev"
)]
chain_spec
if
chain_spec
.is_dev
()
=>
runner
RuntimeType
::
GDev
=>
runner
.sync_run
(|
config
|
cmd
.run
::
<
gdev_runtime
::
Block
,
GDevExecutor
>
(
config
)),
_
=>
Err
(
sc_cli
::
Error
::
Application
(
"unknown runtime"
.into
())),
}
...
...
@@ -219,19 +215,19 @@ pub fn run() -> sc_cli::Result<()> {
None
=>
{
let
runner
=
cli
.create_runner
(
&
cli
.run
)
?
;
runner
.run_node_until_exit
(|
config
|
async
move
{
match
&
config
.chain_spec
{
match
config
.chain_spec
.runtime_type
()
{
#[cfg(feature
=
"g1"
)]
chain_spec
if
chain_spec
.is_main
()
=>
{
RuntimeType
::
G1
=>
{
service
::
new_full
::
<
g1_runtime
::
RuntimeApi
,
G1Executor
>
(
config
,
None
)
.map_err
(
sc_cli
::
Error
::
Service
)
}
#[cfg(feature
=
"gtest"
)]
chain_spec
if
chain_spec
.is_t
est
()
=>
{
RuntimeType
::
GT
est
=>
{
service
::
new_full
::
<
gtest_runtime
::
RuntimeApi
,
GTestExecutor
>
(
config
,
None
)
.map_err
(
sc_cli
::
Error
::
Service
)
}
#[cfg(feature
=
"gdev"
)]
chain_spec
if
chain_spec
.is_dev
()
=>
{
RuntimeType
::
GDev
=>
{
service
::
new_full
::
<
gdev_runtime
::
RuntimeApi
,
GDevExecutor
>
(
config
,
Some
(
cli
.sealing
),
...
...
This diff is collapsed.
Click to expand it.
node/src/service.rs
+
27
−
25
View file @
163cb9d3
...
...
@@ -98,30 +98,32 @@ impl sc_executor::NativeExecutionDispatch for G1Executor {
}
}
/// Can be called for a `Configuration` to check if it is a configuration for
/// a particular network.
pub
trait
IdentifyVariant
{
/// Returns `true` if this is a configuration for the `main` network.
fn
is_main
(
&
self
)
->
bool
;
/// Returns `true` if this is a configuration for the `test` network.
fn
is_test
(
&
self
)
->
bool
;
/// Returns `true` if this is a configuration for a dev network.
fn
is_dev
(
&
self
)
->
bool
;
pub
enum
RuntimeType
{
G1
,
GDev
,
GTest
,
}
impl
IdentifyVariant
for
Box
<
dyn
sc_chain_spec
::
ChainSpec
>
{
fn
is_main
(
&
self
)
->
bool
{
self
.id
()
.starts_with
(
"g1"
)
}
fn
is_test
(
&
self
)
->
bool
{
self
.id
()
.starts_with
(
"gdem"
)
||
self
.id
()
.starts_with
(
"gtest"
)
}
/// Can be called for a `Configuration` to check if it is a configuration for
/// a particular runtime type.
pub
trait
IdentifyRuntimeType
{
/// Returns the runtime type
fn
runtime_type
(
&
self
)
->
RuntimeType
;
}
fn
is_dev
(
&
self
)
->
bool
{
self
.id
()
.starts_with
(
"dev"
)
||
self
.id
()
.starts_with
(
"gdev"
)
impl
IdentifyRuntimeType
for
Box
<
dyn
sc_chain_spec
::
ChainSpec
>
{
fn
runtime_type
(
&
self
)
->
RuntimeType
{
if
self
.id
()
.starts_with
(
"g1"
)
{
RuntimeType
::
G1
}
else
if
self
.id
()
.starts_with
(
"gdem"
)
{
RuntimeType
::
GTest
}
else
if
self
.id
()
.starts_with
(
"dev"
)
||
self
.id
()
.starts_with
(
"gdev"
)
{
RuntimeType
::
GDev
}
else
if
self
.id
()
.starts_with
(
"gt"
)
{
RuntimeType
::
GTest
}
else
{
panic!
(
"unknown runtime"
)
}
}
}
...
...
@@ -138,9 +140,9 @@ pub fn new_chain_ops(
),
ServiceError
,
>
{
match
&
config
.chain_spec
{
match
config
.chain_spec
.runtime_type
()
{
#[cfg(feature
=
"g1"
)]
chain_spec
if
chain_spec
.is_main
()
=>
{
RuntimeType
::
G1
::
G1
=>
{
let
PartialComponents
{
client
,
backend
,
...
...
@@ -156,7 +158,7 @@ pub fn new_chain_ops(
))
}
#[cfg(feature
=
"gtest"
)]
chain_spec
if
chain_spec
.is_t
est
()
=>
{
RuntimeType
::
GT
est
=>
{
let
PartialComponents
{
client
,
backend
,
...
...
@@ -172,7 +174,7 @@ pub fn new_chain_ops(
))
}
#[cfg(feature
=
"gdev"
)]
chain_spec
if
chain_spec
.is_dev
()
=>
{
RuntimeType
::
GDev
=>
{
let
PartialComponents
{
client
,
backend
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment