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
3248c15b
Unverified
Commit
3248c15b
authored
Feb 27, 2021
by
Shaun Wang
Committed by
GitHub
Feb 27, 2021
Browse files
Add events for hrmp pallet. (#2532)
* Add events for hrmp pallet. * Apply review suggestions.
parent
7e627af0
Pipeline
#126148
passed with stages
in 31 minutes and 29 seconds
Changes
5
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
runtime/common/src/paras_registrar.rs
View file @
3248c15b
...
@@ -290,6 +290,7 @@ mod tests {
...
@@ -290,6 +290,7 @@ mod tests {
Staking
:
pallet_staking
::{
Module
,
Call
,
Config
<
T
>
,
Storage
,
Event
<
T
>
,
ValidateUnsigned
},
Staking
:
pallet_staking
::{
Module
,
Call
,
Config
<
T
>
,
Storage
,
Event
<
T
>
,
ValidateUnsigned
},
Session
:
pallet_session
::{
Module
,
Call
,
Storage
,
Event
,
Config
<
T
>
},
Session
:
pallet_session
::{
Module
,
Call
,
Storage
,
Event
,
Config
<
T
>
},
Initializer
:
initializer
::{
Module
,
Call
,
Storage
},
Initializer
:
initializer
::{
Module
,
Call
,
Storage
},
Hrmp
:
hrmp
::{
Module
,
Call
,
Storage
,
Event
},
}
}
);
);
...
@@ -448,6 +449,7 @@ mod tests {
...
@@ -448,6 +449,7 @@ mod tests {
}
}
impl
hrmp
::
Config
for
Test
{
impl
hrmp
::
Config
for
Test
{
type
Event
=
Event
;
type
Origin
=
Origin
;
type
Origin
=
Origin
;
type
Currency
=
pallet_balances
::
Module
<
Test
>
;
type
Currency
=
pallet_balances
::
Module
<
Test
>
;
}
}
...
...
runtime/parachains/src/hrmp.rs
View file @
3248c15b
...
@@ -21,8 +21,8 @@ use crate::{
...
@@ -21,8 +21,8 @@ use crate::{
};
};
use
parity_scale_codec
::{
Decode
,
Encode
};
use
parity_scale_codec
::{
Decode
,
Encode
};
use
frame_support
::{
use
frame_support
::{
decl_storage
,
decl_module
,
decl_error
,
ensure
,
traits
::{
Get
,
ReservableCurrency
},
weights
::
Weight
,
decl_storage
,
decl_module
,
decl_error
,
decl_event
,
ensure
,
traits
::{
Get
,
ReservableCurrency
},
StorageMap
,
StorageValue
,
dispatch
::
DispatchResult
,
weights
::
Weight
,
StorageMap
,
StorageValue
,
dispatch
::
DispatchResult
,
};
};
use
primitives
::
v1
::{
use
primitives
::
v1
::{
Balance
,
Hash
,
HrmpChannelId
,
Id
as
ParaId
,
InboundHrmpMessage
,
OutboundHrmpMessage
,
Balance
,
Hash
,
HrmpChannelId
,
Id
as
ParaId
,
InboundHrmpMessage
,
OutboundHrmpMessage
,
...
@@ -215,6 +215,9 @@ impl fmt::Debug for OutboundHrmpAcceptanceErr {
...
@@ -215,6 +215,9 @@ impl fmt::Debug for OutboundHrmpAcceptanceErr {
}
}
pub
trait
Config
:
frame_system
::
Config
+
configuration
::
Config
+
paras
::
Config
+
dmp
::
Config
{
pub
trait
Config
:
frame_system
::
Config
+
configuration
::
Config
+
paras
::
Config
+
dmp
::
Config
{
/// The outer event type.
type
Event
:
From
<
Event
>
+
Into
<<
Self
as
frame_system
::
Config
>
::
Event
>
;
type
Origin
:
From
<
crate
::
Origin
>
type
Origin
:
From
<
crate
::
Origin
>
+
From
<<
Self
as
frame_system
::
Config
>
::
Origin
>
+
From
<<
Self
as
frame_system
::
Config
>
::
Origin
>
+
Into
<
Result
<
crate
::
Origin
,
<
Self
as
Config
>
::
Origin
>>
;
+
Into
<
Result
<
crate
::
Origin
,
<
Self
as
Config
>
::
Origin
>>
;
...
@@ -332,11 +335,25 @@ decl_error! {
...
@@ -332,11 +335,25 @@ decl_error! {
}
}
}
}
decl_event!
{
pub
enum
Event
{
/// Open HRMP channel requested.
/// \[sender, recipient, proposed_max_capacity, proposed_max_message_size\]
OpenChannelRequested
(
ParaId
,
ParaId
,
u32
,
u32
),
/// Open HRMP channel accepted. \[sender, recipient\]
OpenChannelAccepted
(
ParaId
,
ParaId
),
/// HRMP channel closed. \[by_parachain, channel_id\]
ChannelClosed
(
ParaId
,
HrmpChannelId
),
}
}
decl_module!
{
decl_module!
{
/// The HRMP module.
/// The HRMP module.
pub
struct
Module
<
T
:
Config
>
for
enum
Call
where
origin
:
<
T
as
frame_system
::
Config
>
::
Origin
{
pub
struct
Module
<
T
:
Config
>
for
enum
Call
where
origin
:
<
T
as
frame_system
::
Config
>
::
Origin
{
type
Error
=
Error
<
T
>
;
type
Error
=
Error
<
T
>
;
fn
deposit_event
()
=
default
;
/// Initiate opening a channel from a parachain to a given recipient with given channel
/// Initiate opening a channel from a parachain to a given recipient with given channel
/// parameters.
/// parameters.
///
///
...
@@ -361,6 +378,12 @@ decl_module! {
...
@@ -361,6 +378,12 @@ decl_module! {
proposed_max_capacity
,
proposed_max_capacity
,
proposed_max_message_size
proposed_max_message_size
)
?
;
)
?
;
Self
::
deposit_event
(
Event
::
OpenChannelRequested
(
origin
,
recipient
,
proposed_max_capacity
,
proposed_max_message_size
));
Ok
(())
Ok
(())
}
}
...
@@ -371,6 +394,7 @@ decl_module! {
...
@@ -371,6 +394,7 @@ decl_module! {
pub
fn
hrmp_accept_open_channel
(
origin
,
sender
:
ParaId
)
->
DispatchResult
{
pub
fn
hrmp_accept_open_channel
(
origin
,
sender
:
ParaId
)
->
DispatchResult
{
let
origin
=
ensure_parachain
(
<
T
as
Config
>
::
Origin
::
from
(
origin
))
?
;
let
origin
=
ensure_parachain
(
<
T
as
Config
>
::
Origin
::
from
(
origin
))
?
;
Self
::
accept_open_channel
(
origin
,
sender
)
?
;
Self
::
accept_open_channel
(
origin
,
sender
)
?
;
Self
::
deposit_event
(
Event
::
OpenChannelAccepted
(
sender
,
origin
));
Ok
(())
Ok
(())
}
}
...
@@ -381,7 +405,8 @@ decl_module! {
...
@@ -381,7 +405,8 @@ decl_module! {
#[weight
=
0
]
#[weight
=
0
]
pub
fn
hrmp_close_channel
(
origin
,
channel_id
:
HrmpChannelId
)
->
DispatchResult
{
pub
fn
hrmp_close_channel
(
origin
,
channel_id
:
HrmpChannelId
)
->
DispatchResult
{
let
origin
=
ensure_parachain
(
<
T
as
Config
>
::
Origin
::
from
(
origin
))
?
;
let
origin
=
ensure_parachain
(
<
T
as
Config
>
::
Origin
::
from
(
origin
))
?
;
Self
::
close_channel
(
origin
,
channel_id
)
?
;
Self
::
close_channel
(
origin
,
channel_id
.clone
())
?
;
Self
::
deposit_event
(
Event
::
ChannelClosed
(
origin
,
channel_id
));
Ok
(())
Ok
(())
}
}
}
}
...
@@ -1112,6 +1137,7 @@ mod tests {
...
@@ -1112,6 +1137,7 @@ mod tests {
use
super
::
*
;
use
super
::
*
;
use
crate
::
mock
::{
use
crate
::
mock
::{
new_test_ext
,
Test
,
Configuration
,
Paras
,
Shared
,
Hrmp
,
System
,
MockGenesisConfig
,
new_test_ext
,
Test
,
Configuration
,
Paras
,
Shared
,
Hrmp
,
System
,
MockGenesisConfig
,
Event
as
MockEvent
,
};
};
use
frame_support
::{
assert_noop
,
assert_ok
,
traits
::
Currency
as
_
};
use
frame_support
::{
assert_noop
,
assert_ok
,
traits
::
Currency
as
_
};
use
primitives
::
v1
::
BlockNumber
;
use
primitives
::
v1
::
BlockNumber
;
...
@@ -1427,7 +1453,9 @@ mod tests {
...
@@ -1427,7 +1453,9 @@ mod tests {
#[test]
#[test]
fn
open_channel_works
()
{
fn
open_channel_works
()
{
let
para_a
=
1
.into
();
let
para_a
=
1
.into
();
let
para_a_origin
:
crate
::
Origin
=
1
.into
();
let
para_b
=
3
.into
();
let
para_b
=
3
.into
();
let
para_b_origin
:
crate
::
Origin
=
3
.into
();
new_test_ext
(
GenesisConfigBuilder
::
default
()
.build
())
.execute_with
(||
{
new_test_ext
(
GenesisConfigBuilder
::
default
()
.build
())
.execute_with
(||
{
// We need both A & B to be registered and alive parachains.
// We need both A & B to be registered and alive parachains.
...
@@ -1435,11 +1463,17 @@ mod tests {
...
@@ -1435,11 +1463,17 @@ mod tests {
register_parachain
(
para_b
);
register_parachain
(
para_b
);
run_to_block
(
5
,
Some
(
vec!
[
4
,
5
]));
run_to_block
(
5
,
Some
(
vec!
[
4
,
5
]));
Hrmp
::
init_open_channel
(
para_a
,
para_b
,
2
,
8
)
.unwrap
();
Hrmp
::
hrmp_
init_open_channel
(
para_a
_origin
.into
()
,
para_b
,
2
,
8
)
.unwrap
();
assert_storage_consistency_exhaustive
();
assert_storage_consistency_exhaustive
();
assert!
(
System
::
events
()
.iter
()
.any
(|
record
|
record
.event
==
MockEvent
::
hrmp
(
Event
::
OpenChannelRequested
(
para_a
,
para_b
,
2
,
8
))
));
Hrmp
::
accept_open_channel
(
para_b
,
para_a
)
.unwrap
();
Hrmp
::
hrmp_
accept_open_channel
(
para_b
_origin
.into
()
,
para_a
)
.unwrap
();
assert_storage_consistency_exhaustive
();
assert_storage_consistency_exhaustive
();
assert!
(
System
::
events
()
.iter
()
.any
(|
record
|
record
.event
==
MockEvent
::
hrmp
(
Event
::
OpenChannelAccepted
(
para_a
,
para_b
))
));
// Advance to a block 6, but without session change. That means that the channel has
// Advance to a block 6, but without session change. That means that the channel has
// not been created yet.
// not been created yet.
...
@@ -1457,6 +1491,7 @@ mod tests {
...
@@ -1457,6 +1491,7 @@ mod tests {
fn
close_channel_works
()
{
fn
close_channel_works
()
{
let
para_a
=
5
.into
();
let
para_a
=
5
.into
();
let
para_b
=
2
.into
();
let
para_b
=
2
.into
();
let
para_b_origin
:
crate
::
Origin
=
2
.into
();
new_test_ext
(
GenesisConfigBuilder
::
default
()
.build
())
.execute_with
(||
{
new_test_ext
(
GenesisConfigBuilder
::
default
()
.build
())
.execute_with
(||
{
register_parachain
(
para_a
);
register_parachain
(
para_a
);
...
@@ -1471,14 +1506,11 @@ mod tests {
...
@@ -1471,14 +1506,11 @@ mod tests {
// Close the channel. The effect is not immediate, but rather deferred to the next
// Close the channel. The effect is not immediate, but rather deferred to the next
// session change.
// session change.
Hrmp
::
close_channel
(
let
channel_id
=
HrmpChannelId
{
para_b
,
sender
:
para_a
,
HrmpChannelId
{
recipient
:
para_b
,
sender
:
para_a
,
};
recipient
:
para_b
,
Hrmp
::
hrmp_close_channel
(
para_b_origin
.into
(),
channel_id
.clone
())
.unwrap
();
},
)
.unwrap
();
assert!
(
channel_exists
(
para_a
,
para_b
));
assert!
(
channel_exists
(
para_a
,
para_b
));
assert_storage_consistency_exhaustive
();
assert_storage_consistency_exhaustive
();
...
@@ -1486,6 +1518,9 @@ mod tests {
...
@@ -1486,6 +1518,9 @@ mod tests {
run_to_block
(
8
,
Some
(
vec!
[
8
]));
run_to_block
(
8
,
Some
(
vec!
[
8
]));
assert!
(
!
channel_exists
(
para_a
,
para_b
));
assert!
(
!
channel_exists
(
para_a
,
para_b
));
assert_storage_consistency_exhaustive
();
assert_storage_consistency_exhaustive
();
assert!
(
System
::
events
()
.iter
()
.any
(|
record
|
record
.event
==
MockEvent
::
hrmp
(
Event
::
ChannelClosed
(
para_b
,
channel_id
.clone
()))
));
});
});
}
}
...
...
runtime/parachains/src/mock.rs
View file @
3248c15b
...
@@ -49,7 +49,7 @@ frame_support::construct_runtime!(
...
@@ -49,7 +49,7 @@ frame_support::construct_runtime!(
Initializer
:
initializer
::{
Module
,
Call
,
Storage
},
Initializer
:
initializer
::{
Module
,
Call
,
Storage
},
Dmp
:
dmp
::{
Module
,
Call
,
Storage
},
Dmp
:
dmp
::{
Module
,
Call
,
Storage
},
Ump
:
ump
::{
Module
,
Call
,
Storage
},
Ump
:
ump
::{
Module
,
Call
,
Storage
},
Hrmp
:
hrmp
::{
Module
,
Call
,
Storage
},
Hrmp
:
hrmp
::{
Module
,
Call
,
Storage
,
Event
},
SessionInfo
:
session_info
::{
Module
,
Call
,
Storage
},
SessionInfo
:
session_info
::{
Module
,
Call
,
Storage
},
}
}
);
);
...
@@ -126,6 +126,7 @@ impl crate::ump::Config for Test {
...
@@ -126,6 +126,7 @@ impl crate::ump::Config for Test {
}
}
impl
crate
::
hrmp
::
Config
for
Test
{
impl
crate
::
hrmp
::
Config
for
Test
{
type
Event
=
Event
;
type
Origin
=
Origin
;
type
Origin
=
Origin
;
type
Currency
=
pallet_balances
::
Module
<
Test
>
;
type
Currency
=
pallet_balances
::
Module
<
Test
>
;
}
}
...
...
runtime/rococo/src/lib.rs
View file @
3248c15b
...
@@ -196,7 +196,7 @@ construct_runtime! {
...
@@ -196,7 +196,7 @@ construct_runtime! {
Initializer
:
parachains_initializer
::{
Module
,
Call
,
Storage
},
Initializer
:
parachains_initializer
::{
Module
,
Call
,
Storage
},
Dmp
:
parachains_dmp
::{
Module
,
Call
,
Storage
},
Dmp
:
parachains_dmp
::{
Module
,
Call
,
Storage
},
Ump
:
parachains_ump
::{
Module
,
Call
,
Storage
},
Ump
:
parachains_ump
::{
Module
,
Call
,
Storage
},
Hrmp
:
parachains_hrmp
::{
Module
,
Call
,
Storage
},
Hrmp
:
parachains_hrmp
::{
Module
,
Call
,
Storage
,
Event
},
SessionInfo
:
parachains_session_info
::{
Module
,
Call
,
Storage
},
SessionInfo
:
parachains_session_info
::{
Module
,
Call
,
Storage
},
Registrar
:
paras_registrar
::{
Module
,
Call
,
Storage
},
Registrar
:
paras_registrar
::{
Module
,
Call
,
Storage
},
...
@@ -570,6 +570,7 @@ impl parachains_ump::Config for Runtime {
...
@@ -570,6 +570,7 @@ impl parachains_ump::Config for Runtime {
impl
parachains_dmp
::
Config
for
Runtime
{}
impl
parachains_dmp
::
Config
for
Runtime
{}
impl
parachains_hrmp
::
Config
for
Runtime
{
impl
parachains_hrmp
::
Config
for
Runtime
{
type
Event
=
Event
;
type
Origin
=
Origin
;
type
Origin
=
Origin
;
type
Currency
=
Balances
;
type
Currency
=
Balances
;
}
}
...
...
runtime/test-runtime/src/lib.rs
View file @
3248c15b
...
@@ -483,6 +483,7 @@ impl parachains_ump::Config for Runtime {
...
@@ -483,6 +483,7 @@ impl parachains_ump::Config for Runtime {
}
}
impl
parachains_hrmp
::
Config
for
Runtime
{
impl
parachains_hrmp
::
Config
for
Runtime
{
type
Event
=
Event
;
type
Origin
=
Origin
;
type
Origin
=
Origin
;
type
Currency
=
Balances
;
type
Currency
=
Balances
;
}
}
...
@@ -533,6 +534,7 @@ construct_runtime! {
...
@@ -533,6 +534,7 @@ construct_runtime! {
Scheduler
:
parachains_scheduler
::{
Module
,
Call
,
Storage
},
Scheduler
:
parachains_scheduler
::{
Module
,
Call
,
Storage
},
ParasSudoWrapper
:
paras_sudo_wrapper
::{
Module
,
Call
},
ParasSudoWrapper
:
paras_sudo_wrapper
::{
Module
,
Call
},
SessionInfo
:
parachains_session_info
::{
Module
,
Call
,
Storage
},
SessionInfo
:
parachains_session_info
::{
Module
,
Call
,
Storage
},
Hrmp
:
parachains_hrmp
::{
Module
,
Call
,
Storage
,
Event
},
Sudo
:
pallet_sudo
::{
Module
,
Call
,
Storage
,
Config
<
T
>
,
Event
<
T
>
},
Sudo
:
pallet_sudo
::{
Module
,
Call
,
Storage
,
Config
<
T
>
,
Event
<
T
>
},
}
}
...
...
gabriel klawitter
🏄
@gabriel
mentioned in commit
759397ed
·
Feb 27, 2021
mentioned in commit
759397ed
mentioned in commit 759397ede40b91900112e81a1adea2fda5740b1a
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