-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Runtime: Argo Bridge #5155
Merged
Merged
Runtime: Argo Bridge #5155
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
37f3d91
WIP: argo bridge
freakstatic 69263df
change Argo Bridge configs
freakstatic 299ecf8
tests: improve Argo Bridge tests
freakstatic 5330221
fix: use the right destination account on finalize_inbound_transfer
freakstatic cbde78c
fix: Argo Bridge - add new error (OperatorAccountNotSet)
freakstatic c649652
add const for number of max remote chains
freakstatic 6fe1642
Add Argo Bridge benchmark tests
freakstatic 60830b1
change RemoteAccount comment
freakstatic 8f3c830
bump spec version to 2004
freakstatic e1db690
add Argo Bridge pallet to benchmarks definition
freakstatic 3c20a1f
tests: add benchmarking tests to Argo Bridge pallet
freakstatic afedc96
update Argo Bridge weights
freakstatic 0faf5ec
Update Proposals Codex benchmarking to include Argo Bridge constraint…
freakstatic 0fb0b20
small improvements on Argo Bridge benchmarking
freakstatic bed43b0
fix clippy warnings
kdembler 0f48abc
Merge pull request #2 from kdembler/argo-clippy
freakstatic b278c08
fix: add missing argo bridge configs to project codex pallet
freakstatic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use node_runtime::{argo_bridge::types::BridgeStatus, ArgoBridgeConfig}; | ||
|
||
pub fn production_config() -> ArgoBridgeConfig { | ||
ArgoBridgeConfig { | ||
status: BridgeStatus::Paused, | ||
mint_allowance: 0, | ||
bridging_fee: 0, | ||
thawn_duration: 1, | ||
..Default::default() | ||
} | ||
} | ||
|
||
pub fn testing_config() -> ArgoBridgeConfig { | ||
ArgoBridgeConfig { | ||
status: BridgeStatus::Paused, | ||
mint_allowance: 0, | ||
bridging_fee: 0, | ||
thawn_duration: 1, | ||
..Default::default() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
[package] | ||
name = "pallet-argo-bridge" | ||
version = '1.0.0' | ||
authors = ['Joystream contributors'] | ||
edition = '2018' | ||
|
||
[dependencies] | ||
sp-io = { package = 'sp-io', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'} | ||
sp-std = { package = 'sp-std', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'} | ||
sp-runtime = { package = 'sp-runtime', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'} | ||
frame-support = { package = 'frame-support', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'} | ||
frame-system = { package = 'frame-system', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'} | ||
sp-arithmetic = { package = 'sp-arithmetic', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'} | ||
common = { package = 'pallet-common', default-features = false, path = '../common'} | ||
storage = { package = 'pallet-storage', default-features = false, path = '../storage'} | ||
balances = { package = 'pallet-balances', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'} | ||
membership = { package = 'pallet-membership', default-features = false, path = '../membership'} | ||
codec = { package = 'parity-scale-codec', version = '3.1.2', default-features = false, features = ['derive'] } | ||
serde = {version = '1.0.101', features = ['derive'], optional = true} | ||
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } | ||
sp-core = { package = 'sp-core', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9', optional = true } | ||
|
||
# Benchmarking dependencies | ||
frame-benchmarking = { package = 'frame-benchmarking', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9', optional = true} | ||
|
||
[dev-dependencies] | ||
sp-core = { package = 'sp-core', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9' } | ||
randomness-collective-flip = { package = 'pallet-insecure-randomness-collective-flip', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'} | ||
staking-handler = { package = 'pallet-staking-handler', default-features = false, path = '../staking-handler'} | ||
pallet-timestamp = { package = 'pallet-timestamp', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'} | ||
sp-storage = { package = 'sp-storage', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'} | ||
|
||
[features] | ||
default = ['std', 'runtime-benchmarks'] | ||
runtime-benchmarks = [ | ||
"frame-benchmarking/runtime-benchmarks", | ||
'sp-core', | ||
"common/runtime-benchmarks", | ||
] | ||
std = [ | ||
'sp-std/std', | ||
'sp-io/std', | ||
'sp-runtime/std', | ||
'frame-support/std', | ||
'frame-system/std', | ||
'sp-arithmetic/std', | ||
'common/std', | ||
'storage/std', | ||
'balances/std', | ||
'membership/std', | ||
'codec/std', | ||
'serde', | ||
'scale-info/std', | ||
'frame-benchmarking?/std', | ||
] | ||
try-runtime = ["frame-support/try-runtime"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#![cfg(feature = "runtime-benchmarks")] | ||
|
||
use frame_support::{assert_err, assert_ok}; | ||
|
||
use super::*; | ||
use crate::types::*; | ||
use crate::Module as ArgoBridge; | ||
use balances::Pallet as Balances; | ||
use core::convert::TryFrom; | ||
use frame_benchmarking::v1::{account, benchmarks}; | ||
use frame_system::Pallet as System; | ||
use frame_system::{EventRecord, RawOrigin}; | ||
use sp_runtime::traits::One; | ||
use sp_std::convert::TryInto; | ||
use sp_std::vec; | ||
|
||
use crate::{BridgeConstraints, BridgeStatus, RemoteAccount, RemoteTransfer}; | ||
|
||
const SEED: u32 = 0; | ||
|
||
// We create this trait because we need to be compatible with the runtime | ||
// in the mock for tests. In that case we need to be able to have `membership_id == account_id` | ||
// We can't create an account from an `u32` or from a memberhsip_dd, | ||
// so this trait allows us to get an account id from an u32, in the case of `64` which is what | ||
// the mock use we get the parameter as a return. | ||
// In the case of `AccountId32` we use the method provided by `frame_benchmarking` to get an | ||
// AccountId. | ||
pub trait CreateAccountId { | ||
fn create_account_id(id: u32) -> Self; | ||
} | ||
|
||
impl CreateAccountId for u64 { | ||
fn create_account_id(id: u32) -> Self { | ||
id.into() | ||
} | ||
} | ||
|
||
impl CreateAccountId for u32 { | ||
fn create_account_id(id: u32) -> Self { | ||
id.into() | ||
} | ||
} | ||
|
||
impl CreateAccountId for sp_core::crypto::AccountId32 { | ||
fn create_account_id(id: u32) -> Self { | ||
account::<Self>("default", id, SEED) | ||
} | ||
} | ||
|
||
fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) { | ||
let events = frame_system::Pallet::<T>::events(); | ||
let system_event: <T as frame_system::Config>::RuntimeEvent = generic_event.into(); | ||
assert!( | ||
!events.is_empty(), | ||
"If you are checking for last event there must be at least 1 event" | ||
); | ||
let EventRecord { event, .. } = &events[events.len() - 1]; | ||
assert_eq!(event, &system_event); | ||
} | ||
|
||
benchmarks! { | ||
where_clause { | ||
where | ||
T: balances::Config, | ||
T::AccountId: CreateAccountId | ||
} | ||
|
||
request_outbound_transfer{ | ||
let fee: BalanceOf<T> = 10u32.into(); | ||
let remote_chains = BoundedVec::try_from(vec![1u32]).unwrap(); | ||
let parameters = BridgeConstraints { | ||
operator_account: Some(T::AccountId::create_account_id(1u32.into())), | ||
pauser_accounts: Some(vec![T::AccountId::create_account_id(2u32.into())]), | ||
bridging_fee: Some(fee), | ||
thawn_duration: None::<T::BlockNumber>, | ||
remote_chains: Some(remote_chains) | ||
}; | ||
assert_ok!(ArgoBridge::<T>::update_bridge_constrains( | ||
RawOrigin::Root.into(), | ||
parameters | ||
)); | ||
|
||
let dest_account = RemoteAccount { | ||
account: [0; 32], | ||
chain_id: 1, | ||
}; | ||
let sender = T::AccountId::create_account_id(1u32.into()); | ||
let origin = RawOrigin::Signed(sender); | ||
let transfer_id = ArgoBridge::<T>::next_transfer_id(); | ||
let amount = 100u32.into(); | ||
}: _(origin, dest_account, amount, fee) | ||
verify { | ||
let sender = T::AccountId::create_account_id(1u32.into()); | ||
assert_last_event::<T>( | ||
RawEvent::OutboundTransferRequested(transfer_id, sender, dest_account, amount, fee).into()); | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use crate::Module; | ||
use frame_support::decl_error; | ||
use sp_std::convert::TryInto; | ||
|
||
decl_error! { | ||
pub enum Error for Module<T: crate::Config> { | ||
|
||
/// Bridge not on active state | ||
BridgeNotActive, | ||
|
||
/// Insufficient JOY Balance to cover the transaction costs | ||
InsufficientJoyBalance, | ||
|
||
/// The bridging_fee changed since the request transfer | ||
FeeDifferentThanExpected, | ||
|
||
/// Not enough mint allowance for transaction | ||
InsufficienBridgMintAllowance, | ||
freakstatic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// Operator account required | ||
NotOperatorAccount, | ||
freakstatic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// Pauser account required | ||
NotPauserAccount, | ||
|
||
/// Number of pauser accounts over the maximum allowed | ||
InvalidNumberOfPauserAccounts, | ||
|
||
/// Current block is lower than thawn_started_at + thawn_duration | ||
freakstatic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ThawnNotFinished, | ||
|
||
/// ChainId is not on the list of the supported chains | ||
NotSupportedRemoteChainId | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#![allow(clippy::unused_unit)] | ||
|
||
use frame_support::decl_event; | ||
|
||
use crate::{RemoteAccount, RemoteTransfer, TransferId}; | ||
|
||
use crate::types::*; | ||
|
||
// Balance type alias | ||
type BalanceOf<T> = <T as balances::Config>::Balance; | ||
|
||
decl_event!( | ||
pub enum Event<T> | ||
where | ||
AccountId = <T as frame_system::Config>::AccountId, | ||
Balance = BalanceOf<T>, | ||
BridgeConstraints = BridgeConstraintsOf<T>, | ||
{ | ||
OutboundTransferRequested(TransferId, AccountId, RemoteAccount, Balance, Balance), | ||
InboundTransferFinalized(RemoteTransfer, AccountId, Balance), | ||
BridgePaused(AccountId), | ||
BridgeThawnStarted(AccountId), | ||
freakstatic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
BridgeThawnFinished(), | ||
BridgeConfigUpdated(BridgeConstraints), | ||
} | ||
); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think that you can set the mint allowance storage variable to be
0
by default since I don't think any other initial value is plausible