Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polkadot-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
parity
Mirrored projects
polkadot-sdk
Commits
5946d6f7
Commit
5946d6f7
authored
5 years ago
by
Benjamin Kampmann
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Allow node to add externalities extensions (#4583)
* allow extensions to be extensible from the outside
parent
426c1570
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
substrate/client/api/src/execution_extensions.rs
+24
-2
24 additions, 2 deletions
substrate/client/api/src/execution_extensions.rs
substrate/client/service/src/builder.rs
+8
-0
8 additions, 0 deletions
substrate/client/service/src/builder.rs
with
32 additions
and
2 deletions
substrate/client/api/src/execution_extensions.rs
+
24
−
2
View file @
5946d6f7
...
...
@@ -62,6 +62,18 @@ impl Default for ExecutionStrategies {
}
}
/// Generate the starting set of ExternalitiesExtensions based upon the given capabilities
pub
trait
ExtensionsFactory
:
Send
+
Sync
{
/// Make `Extensions` for given Capapbilities
fn
extensions_for
(
&
self
,
capabilities
:
offchain
::
Capabilities
)
->
Extensions
;
}
impl
ExtensionsFactory
for
()
{
fn
extensions_for
(
&
self
,
_capabilities
:
offchain
::
Capabilities
)
->
Extensions
{
Extensions
::
new
()
}
}
/// A producer of execution extensions for offchain calls.
///
/// This crate aggregates extensions available for the offchain calls
...
...
@@ -70,7 +82,10 @@ impl Default for ExecutionStrategies {
pub
struct
ExecutionExtensions
<
Block
:
traits
::
Block
>
{
strategies
:
ExecutionStrategies
,
keystore
:
Option
<
BareCryptoStorePtr
>
,
// FIXME: these two are only RwLock because of https://github.com/paritytech/substrate/issues/4587
// remove when fixed.
transaction_pool
:
RwLock
<
Option
<
Weak
<
dyn
sp_transaction_pool
::
OffchainSubmitTransaction
<
Block
>>>>
,
extensions_factory
:
RwLock
<
Box
<
dyn
ExtensionsFactory
>>
,
}
impl
<
Block
:
traits
::
Block
>
Default
for
ExecutionExtensions
<
Block
>
{
...
...
@@ -79,6 +94,7 @@ impl<Block: traits::Block> Default for ExecutionExtensions<Block> {
strategies
:
Default
::
default
(),
keystore
:
None
,
transaction_pool
:
RwLock
::
new
(
None
),
extensions_factory
:
RwLock
::
new
(
Box
::
new
(())),
}
}
}
...
...
@@ -90,7 +106,8 @@ impl<Block: traits::Block> ExecutionExtensions<Block> {
keystore
:
Option
<
BareCryptoStorePtr
>
,
)
->
Self
{
let
transaction_pool
=
RwLock
::
new
(
None
);
Self
{
strategies
,
keystore
,
transaction_pool
}
let
extensions_factory
=
Box
::
new
(());
Self
{
strategies
,
keystore
,
extensions_factory
:
RwLock
::
new
(
extensions_factory
),
transaction_pool
}
}
/// Get a reference to the execution strategies.
...
...
@@ -98,6 +115,11 @@ impl<Block: traits::Block> ExecutionExtensions<Block> {
&
self
.strategies
}
/// Set the new extensions_factory
pub
fn
set_extensions_factory
(
&
self
,
maker
:
Box
<
dyn
ExtensionsFactory
>
)
{
*
self
.extensions_factory
.write
()
=
maker
;
}
/// Register transaction pool extension.
///
/// To break retain cycle between `Client` and `TransactionPool` we require this
...
...
@@ -135,7 +157,7 @@ impl<Block: traits::Block> ExecutionExtensions<Block> {
let
capabilities
=
context
.capabilities
();
let
mut
extensions
=
E
xtensions
::
new
(
);
let
mut
extensions
=
self
.e
xtensions
_factory
.read
()
.extensions_for
(
capabilities
);
if
capabilities
.has
(
offchain
::
Capability
::
Keystore
)
{
if
let
Some
(
keystore
)
=
self
.keystore
.as_ref
()
{
...
...
This diff is collapsed.
Click to expand it.
substrate/client/service/src/builder.rs
+
8
−
0
View file @
5946d6f7
...
...
@@ -22,6 +22,7 @@ use sc_client_api::{
self
,
BlockchainEvents
,
backend
::
RemoteBackend
,
light
::
RemoteBlockchain
,
execution_extensions
::
ExtensionsFactory
,
};
use
sc_client
::
Client
;
use
sc_chain_spec
::{
RuntimeGenesis
,
Extension
};
...
...
@@ -746,6 +747,13 @@ ServiceBuilder<
+
TransactionPoolMaintainer
<
Block
=
TBl
,
Hash
=
<
TBl
as
BlockT
>
::
Hash
>
,
TRpc
:
sc_rpc
::
RpcExtension
<
sc_rpc
::
Metadata
>
+
Clone
,
{
/// Set an ExecutionExtensionsFactory
pub
fn
with_execution_extensions_factory
(
self
,
execution_extensions_factory
:
Box
<
dyn
ExtensionsFactory
>
)
->
Result
<
Self
,
Error
>
{
self
.client
.execution_extensions
()
.set_extensions_factory
(
execution_extensions_factory
);
Ok
(
self
)
}
/// Builds the service.
pub
fn
build
(
self
)
->
Result
<
Service
<
TBl
,
...
...
This diff is collapsed.
Click to expand it.
Preview
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!
Save comment
Cancel
Please
register
or
sign in
to comment