Skip to content
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

Rename constant to what bridge relayers expect #236

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions pallets/chainbridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use sp_std::prelude::*;
const DEFAULT_RELAYER_THRESHOLD: u32 = 1;
pub const MODULE_ID: PalletId = PalletId(*b"cb/bridg");

pub type ChainId = u8;
pub type ChainIdentity = u8;
pub type DepositNonce = u64;
pub type ResourceId = [u8; 32];

Expand Down Expand Up @@ -142,7 +142,7 @@ pub mod pallet {
/// This must be unique and must not collide with existing IDs within a set of bridged
/// chains.
#[pallet::constant]
type ChainId: Get<ChainId>;
type ChainIdentity: Get<ChainIdentity>;

#[pallet::constant]
type ProposalLifetime: Get<<Self as frame_system::Config>::BlockNumber>;
Expand All @@ -154,7 +154,7 @@ pub mod pallet {
/// All whitelisted chains and their respective transaction counts
#[pallet::storage]
#[pallet::getter(fn chains)]
pub type ChainNonces<T: Config> = StorageMap<_, Blake2_128Concat, ChainId, DepositNonce>;
pub type ChainNonces<T: Config> = StorageMap<_, Blake2_128Concat, ChainIdentity, DepositNonce>;

/// Tracks current relayer set
#[pallet::storage]
Expand All @@ -173,7 +173,7 @@ pub mod pallet {
pub type Votes<T: Config> = StorageDoubleMap<
_,
Blake2_128Concat,
ChainId,
ChainIdentity,
Blake2_128Concat,
(DepositNonce, T::Proposal),
ProposalVotes<T::AccountId, T::BlockNumber>,
Expand Down Expand Up @@ -241,31 +241,31 @@ pub mod pallet {
/// Vote threshold has changed (new_threshold)
RelayerThresholdChanged(u32),
/// Chain now available for transfers (chain_id)
ChainWhitelisted(ChainId),
ChainWhitelisted(ChainIdentity),
/// Relayer added to set
RelayerAdded(T::AccountId),
/// Relayer removed from set
RelayerRemoved(T::AccountId),
/// FunglibleTransfer is for relaying fungibles (dest_id, nonce, resource_id, amount,
/// recipient, metadata)
FungibleTransfer(ChainId, DepositNonce, ResourceId, U256, Vec<u8>),
FungibleTransfer(ChainIdentity, DepositNonce, ResourceId, U256, Vec<u8>),
/// NonFungibleTransfer is for relaying NFTS (dest_id, nonce, resource_id, token_id,
/// recipient, metadata)
NonFungibleTransfer(ChainId, DepositNonce, ResourceId, Vec<u8>, Vec<u8>, Vec<u8>),
NonFungibleTransfer(ChainIdentity, DepositNonce, ResourceId, Vec<u8>, Vec<u8>, Vec<u8>),
/// GenericTransfer is for a generic data payload (dest_id, nonce, resource_id, metadata)
GenericTransfer(ChainId, DepositNonce, ResourceId, Vec<u8>),
GenericTransfer(ChainIdentity, DepositNonce, ResourceId, Vec<u8>),
/// Vote submitted in favour of proposal
VoteFor(ChainId, DepositNonce, T::AccountId),
VoteFor(ChainIdentity, DepositNonce, T::AccountId),
/// Vot submitted against proposal
VoteAgainst(ChainId, DepositNonce, T::AccountId),
VoteAgainst(ChainIdentity, DepositNonce, T::AccountId),
/// Voting successful for a proposal
ProposalApproved(ChainId, DepositNonce),
ProposalApproved(ChainIdentity, DepositNonce),
/// Voting rejected a proposal
ProposalRejected(ChainId, DepositNonce),
ProposalRejected(ChainIdentity, DepositNonce),
/// Execution of call succeeded
ProposalSucceeded(ChainId, DepositNonce),
ProposalSucceeded(ChainIdentity, DepositNonce),
/// Execution of call failed
ProposalFailed(ChainId, DepositNonce),
ProposalFailed(ChainIdentity, DepositNonce),
}

#[pallet::call]
Expand Down Expand Up @@ -323,7 +323,7 @@ pub mod pallet {
/// # </weight>
#[pallet::call_index(3)]
#[pallet::weight(195_000_000)]
pub fn whitelist_chain(origin: OriginFor<T>, id: ChainId) -> DispatchResult {
pub fn whitelist_chain(origin: OriginFor<T>, id: ChainIdentity) -> DispatchResult {
Self::ensure_admin(origin)?;
Self::whitelist(id)
}
Expand Down Expand Up @@ -365,7 +365,7 @@ pub mod pallet {
pub fn acknowledge_proposal(
origin: OriginFor<T>,
nonce: DepositNonce,
src_id: ChainId,
src_id: ChainIdentity,
r_id: ResourceId,
call: Box<<T as Config>::Proposal>,
) -> DispatchResult {
Expand All @@ -387,7 +387,7 @@ pub mod pallet {
pub fn reject_proposal(
origin: OriginFor<T>,
nonce: DepositNonce,
src_id: ChainId,
src_id: ChainIdentity,
r_id: ResourceId,
call: Box<<T as Config>::Proposal>,
) -> DispatchResult {
Expand All @@ -412,7 +412,7 @@ pub mod pallet {
pub fn eval_vote_state(
origin: OriginFor<T>,
nonce: DepositNonce,
src_id: ChainId,
src_id: ChainIdentity,
prop: Box<<T as Config>::Proposal>,
) -> DispatchResult {
ensure_signed(origin)?;
Expand Down Expand Up @@ -446,12 +446,12 @@ pub mod pallet {
}

/// Checks if a chain exists as a whitelisted destination
pub fn chain_whitelisted(id: ChainId) -> bool {
pub fn chain_whitelisted(id: ChainIdentity) -> bool {
Self::chains(id).is_some()
}

/// Increments the deposit nonce for the specified chain ID
fn bump_nonce(id: ChainId) -> DepositNonce {
fn bump_nonce(id: ChainIdentity) -> DepositNonce {
let nonce = Self::chains(id).unwrap_or_default() + 1;
<ChainNonces<T>>::insert(id, nonce);
nonce
Expand Down Expand Up @@ -480,9 +480,9 @@ pub mod pallet {
}

/// Whitelist a chain ID for transfer
pub fn whitelist(id: ChainId) -> DispatchResult {
pub fn whitelist(id: ChainIdentity) -> DispatchResult {
// Cannot whitelist this chain
ensure!(id != T::ChainId::get(), Error::<T>::InvalidChainId);
ensure!(id != T::ChainIdentity::get(), Error::<T>::InvalidChainId);
// Cannot whitelist with an existing entry
ensure!(!Self::chain_whitelisted(id), Error::<T>::ChainAlreadyWhitelisted);
<ChainNonces<T>>::insert(id, 0);
Expand Down Expand Up @@ -515,7 +515,7 @@ pub mod pallet {
fn commit_vote(
who: T::AccountId,
nonce: DepositNonce,
src_id: ChainId,
src_id: ChainIdentity,
prop: Box<T::Proposal>,
in_favour: bool,
) -> DispatchResult {
Expand Down Expand Up @@ -550,7 +550,7 @@ pub mod pallet {
/// Attempts to finalize or cancel the proposal if the vote count allows.
fn try_resolve_proposal(
nonce: DepositNonce,
src_id: ChainId,
src_id: ChainIdentity,
prop: Box<T::Proposal>,
) -> DispatchResult {
if let Some(mut votes) = <Votes<T>>::get(src_id, (nonce, prop.clone())) {
Expand All @@ -576,7 +576,7 @@ pub mod pallet {
fn vote_for(
who: T::AccountId,
nonce: DepositNonce,
src_id: ChainId,
src_id: ChainIdentity,
prop: Box<T::Proposal>,
) -> DispatchResult {
Self::commit_vote(who, nonce, src_id, prop.clone(), true)?;
Expand All @@ -588,7 +588,7 @@ pub mod pallet {
fn vote_against(
who: T::AccountId,
nonce: DepositNonce,
src_id: ChainId,
src_id: ChainIdentity,
prop: Box<T::Proposal>,
) -> DispatchResult {
Self::commit_vote(who, nonce, src_id, prop.clone(), false)?;
Expand All @@ -597,7 +597,7 @@ pub mod pallet {

/// Execute the proposal and signals the result as an event
fn finalize_execution(
src_id: ChainId,
src_id: ChainIdentity,
nonce: DepositNonce,
call: Box<T::Proposal>,
) -> DispatchResult {
Expand All @@ -610,15 +610,15 @@ pub mod pallet {
}

/// Cancels a proposal.
fn cancel_execution(src_id: ChainId, nonce: DepositNonce) -> DispatchResult {
fn cancel_execution(src_id: ChainIdentity, nonce: DepositNonce) -> DispatchResult {
Self::deposit_event(Event::ProposalRejected(src_id, nonce));
Ok(())
}

/// Initiates a transfer of a fungible asset out of the chain. This should be called by
/// another pallet.
pub fn transfer_fungible(
dest_id: ChainId,
dest_id: ChainIdentity,
resource_id: ResourceId,
to: Vec<u8>,
amount: U256,
Expand All @@ -633,7 +633,7 @@ pub mod pallet {
/// Initiates a transfer of a nonfungible asset out of the chain. This should be called by
/// another pallet.
pub fn transfer_nonfungible(
dest_id: ChainId,
dest_id: ChainIdentity,
resource_id: ResourceId,
token_id: Vec<u8>,
to: Vec<u8>,
Expand All @@ -656,7 +656,7 @@ pub mod pallet {
/// Initiates a transfer of generic data out of the chain. This should be called by another
/// pallet.
pub fn transfer_generic(
dest_id: ChainId,
dest_id: ChainIdentity,
resource_id: ResourceId,
metadata: Vec<u8>,
) -> DispatchResult {
Expand Down
6 changes: 3 additions & 3 deletions pallets/chainbridge/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl pallet_balances::Config for Test {
}

parameter_types! {
pub const TestChainId: u8 = 5;
pub const TestChainIdentity: u8 = 5;
pub const ProposalLifetime: u64 = 50;
pub BridgeAccountId: u64 = AccountIdConversion::<u64>::into_account_truncating(&MODULE_ID);
}
Expand All @@ -79,7 +79,7 @@ impl crate::pallet::Config for Test {
type RuntimeEvent = RuntimeEvent;
type AdminOrigin = frame_system::EnsureRoot<Self::AccountId>;
type Proposal = RuntimeCall;
type ChainId = TestChainId;
type ChainIdentity = TestChainIdentity;
type ProposalLifetime = ProposalLifetime;
type BridgeAccountId = BridgeAccountId;
}
Expand Down Expand Up @@ -118,7 +118,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
}

pub fn new_test_ext_initialized(
src_id: ChainId,
src_id: ChainIdentity,
r_id: ResourceId,
resource: Vec<u8>,
) -> sp_io::TestExternalities {
Expand Down
6 changes: 3 additions & 3 deletions pallets/chainbridge/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use frame_support::{assert_noop, assert_ok};
use super::{
mock::{
assert_events, new_test_ext, Balances, Bridge, ProposalLifetime, RuntimeCall, RuntimeEvent,
RuntimeOrigin, System, Test, TestChainId, ENDOWED_BALANCE, RELAYER_A, RELAYER_B, RELAYER_C,
TEST_THRESHOLD,
RuntimeOrigin, System, Test, TestChainIdentity, ENDOWED_BALANCE, RELAYER_A, RELAYER_B,
RELAYER_C, TEST_THRESHOLD,
},
*,
};
Expand Down Expand Up @@ -99,7 +99,7 @@ fn whitelist_chain() {

assert_ok!(Bridge::whitelist_chain(RuntimeOrigin::root(), 0));
assert_noop!(
Bridge::whitelist_chain(RuntimeOrigin::root(), TestChainId::get()),
Bridge::whitelist_chain(RuntimeOrigin::root(), TestChainIdentity::get()),
Error::<Test>::InvalidChainId
);

Expand Down
6 changes: 3 additions & 3 deletions pallets/erc20/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub mod pallet {
pub fn transfer_hash(
origin: OriginFor<T>,
hash: T::Hash,
dest_id: bridge::ChainId,
dest_id: bridge::ChainIdentity,
) -> DispatchResult {
ensure_signed(origin)?;

Expand All @@ -89,7 +89,7 @@ pub mod pallet {
origin: OriginFor<T>,
amount: BalanceOf<T>,
recipient: Vec<u8>,
dest_id: bridge::ChainId,
dest_id: bridge::ChainIdentity,
) -> DispatchResult {
let source = ensure_signed(origin)?;
ensure!(<bridge::Pallet<T>>::chain_whitelisted(dest_id), Error::<T>::InvalidTransfer);
Expand All @@ -114,7 +114,7 @@ pub mod pallet {
origin: OriginFor<T>,
recipient: Vec<u8>,
token_id: U256,
dest_id: bridge::ChainId,
dest_id: bridge::ChainIdentity,
) -> DispatchResult {
let source = ensure_signed(origin)?;
ensure!(<bridge::Pallet<T>>::chain_whitelisted(dest_id), Error::<T>::InvalidTransfer);
Expand Down
4 changes: 2 additions & 2 deletions pallets/erc20/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ impl pallet_balances::Config for Test {
}

parameter_types! {
pub const TestChainId: u8 = 5;
pub const TestChainIdentity: u8 = 5;
pub const ProposalLifetime: u64 = 100;
}

impl bridge::Config for Test {
type Event = Event;
type AdminOrigin = frame_system::EnsureRoot<Self::AccountId>;
type Proposal = Call;
type ChainId = TestChainId;
type ChainIdentity = TestChainIdentity;
type ProposalLifetime = ProposalLifetime;
}

Expand Down
4 changes: 2 additions & 2 deletions runtime/cere-dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ impl pallet_vesting::Config for Runtime {
}

parameter_types! {
pub const ChainId: u8 = 1;
pub const ChainIdentity: u8 = 1;
pub const ProposalLifetime: BlockNumber = 1000;
pub BridgeAccountId: AccountId = AccountIdConversion::<AccountId>::into_account_truncating(&pallet_chainbridge::MODULE_ID);
}
Expand All @@ -1235,7 +1235,7 @@ impl pallet_chainbridge::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type AdminOrigin = frame_system::EnsureRoot<Self::AccountId>;
type Proposal = RuntimeCall;
type ChainId = ChainId;
type ChainIdentity = ChainIdentity;
type ProposalLifetime = ProposalLifetime;
type BridgeAccountId = BridgeAccountId;
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/cere/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ impl pallet_vesting::Config for Runtime {
}

parameter_types! {
pub const ChainId: u8 = 1;
pub const ChainIdentity: u8 = 1;
pub const ProposalLifetime: BlockNumber = 1000;
pub BridgeAccountId: AccountId = AccountIdConversion::<AccountId>::into_account_truncating(&pallet_chainbridge::MODULE_ID);
}
Expand All @@ -1240,7 +1240,7 @@ impl pallet_chainbridge::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type AdminOrigin = frame_system::EnsureRoot<Self::AccountId>;
type Proposal = RuntimeCall;
type ChainId = ChainId;
type ChainIdentity = ChainIdentity;
type ProposalLifetime = ProposalLifetime;
type BridgeAccountId = BridgeAccountId;
}
Expand Down
Loading