Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

BridgeHub subtree update #2820

Merged
merged 4 commits into from
Jul 4, 2023
Merged
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
22 changes: 21 additions & 1 deletion bridges/modules/grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,12 @@ pub mod pallet {
justification.votes_ancestries.len().saturated_into(),
))]
pub fn submit_finality_proof(
_origin: OriginFor<T>,
origin: OriginFor<T>,
finality_target: Box<BridgedHeader<T, I>>,
justification: GrandpaJustification<BridgedHeader<T, I>>,
) -> DispatchResultWithPostInfo {
Self::ensure_not_halted().map_err(Error::<T, I>::BridgeModule)?;
ensure_signed(origin)?;

let (hash, number) = (finality_target.hash(), *finality_target.number());
log::trace!(
Expand Down Expand Up @@ -1414,4 +1415,23 @@ mod tests {
fn maybe_headers_to_keep_returns_correct_value() {
assert_eq!(MaybeHeadersToKeep::<TestRuntime, ()>::get(), Some(mock::HeadersToKeep::get()));
}

#[test]
fn submit_finality_proof_requires_signed_origin() {
run_test(|| {
initialize_substrate_bridge();

let header = test_header(1);
let justification = make_default_justification(&header);

assert_noop!(
Pallet::<TestRuntime>::submit_finality_proof(
RuntimeOrigin::root(),
Box::new(header),
justification,
),
DispatchError::BadOrigin,
);
})
}
}
26 changes: 24 additions & 2 deletions bridges/modules/parachains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,13 @@ pub mod pallet {
parachains.len() as _,
))]
pub fn submit_parachain_heads(
_origin: OriginFor<T>,
origin: OriginFor<T>,
at_relay_block: (RelayBlockNumber, RelayBlockHash),
parachains: Vec<(ParaId, ParaHash)>,
parachain_heads_proof: ParaHeadsProof,
) -> DispatchResultWithPostInfo {
Self::ensure_not_halted().map_err(Error::<T, I>::BridgeModule)?;
ensure_signed(origin)?;

// we'll need relay chain header to verify that parachains heads are always increasing.
let (relay_block_number, relay_block_hash) = at_relay_block;
Expand Down Expand Up @@ -417,7 +418,7 @@ pub mod pallet {
});

// we're refunding weight if update has not happened and if pruning has not happened
let is_update_happened = matches!(update_result, Ok(_));
let is_update_happened = update_result.is_ok();
if !is_update_happened {
actual_weight = actual_weight.saturating_sub(
WeightInfoOf::<T, I>::parachain_head_storage_write_weight(
Expand Down Expand Up @@ -1579,4 +1580,25 @@ pub(crate) mod tests {
Some(mock::TOTAL_PARACHAINS * mock::HeadsToKeep::get()),
);
}

#[test]
fn submit_finality_proof_requires_signed_origin() {
run_test(|| {
let (state_root, proof, parachains) =
prepare_parachain_heads_proof::<RegularParachainHeader>(vec![(1, head_data(1, 0))]);

initialize(state_root);

// `submit_parachain_heads()` should fail when the pallet is halted.
assert_noop!(
Pallet::<TestRuntime>::submit_parachain_heads(
RuntimeOrigin::root(),
(0, test_relay_header(0, state_root).hash()),
parachains,
proof,
),
DispatchError::BadOrigin
);
})
}
}
4 changes: 4 additions & 0 deletions bridges/primitives/chain-bridge-hub-cumulus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,13 @@ pub type Address = MultiAddress<AccountId, ()>;
// `ensure_able_to_receive_confirmation` test.

/// Maximal number of unrewarded relayer entries at inbound lane for Cumulus-based parachains.
/// Note: this value is security-relevant, decreasing it should not be done without careful
/// analysis (like the one above).
pub const MAX_UNREWARDED_RELAYERS_IN_CONFIRMATION_TX: MessageNonce = 1024;

/// Maximal number of unconfirmed messages at inbound lane for Cumulus-based parachains.
/// Note: this value is security-relevant, decreasing it should not be done without careful
/// analysis (like the one above).
pub const MAX_UNCONFIRMED_MESSAGES_IN_CONFIRMATION_TX: MessageNonce = 4096;

/// Extra signed extension data that is used by all bridge hubs.
Expand Down
2 changes: 1 addition & 1 deletion bridges/primitives/header-chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
finality-grandpa = { version = "0.16.2", default-features = false }
scale-info = { version = "2.6.0", default-features = false, features = ["derive"] }
scale-info = { version = "2.9.0", default-features = false, features = ["derive"] }
serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] }

# Bridge dependencies
Expand Down
2 changes: 1 addition & 1 deletion bridges/primitives/messages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive", "bit-vec"] }
scale-info = { version = "2.6.0", default-features = false, features = ["bit-vec", "derive"] }
scale-info = { version = "2.9.0", default-features = false, features = ["bit-vec", "derive"] }
serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] }

# Bridge dependencies
Expand Down
2 changes: 1 addition & 1 deletion bridges/primitives/parachains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] }
impl-trait-for-tuples = "0.2"
scale-info = { version = "2.6.0", default-features = false, features = ["derive"] }
scale-info = { version = "2.9.0", default-features = false, features = ["derive"] }

# Bridge dependencies

Expand Down
2 changes: 1 addition & 1 deletion bridges/primitives/polkadot-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] }
parity-util-mem = { version = "0.12.0", optional = true }
scale-info = { version = "2.6.0", default-features = false, features = ["derive"] }
scale-info = { version = "2.9.0", default-features = false, features = ["derive"] }
serde = { version = "1.0", optional = true, features = ["derive"] }

# Bridge Dependencies
Expand Down
2 changes: 1 addition & 1 deletion bridges/primitives/relayers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"

[dependencies]
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive", "bit-vec"] }
scale-info = { version = "2.6.0", default-features = false, features = ["bit-vec", "derive"] }
scale-info = { version = "2.9.0", default-features = false, features = ["bit-vec", "derive"] }

# Bridge Dependencies

Expand Down
2 changes: 1 addition & 1 deletion bridges/primitives/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ codec = { package = "parity-scale-codec", version = "3.1.5", default-features =
hash-db = { version = "0.16.0", default-features = false }
impl-trait-for-tuples = "0.2.2"
num-traits = { version = "0.2", default-features = false }
scale-info = { version = "2.6.0", default-features = false, features = ["derive", "serde"] }
scale-info = { version = "2.9.0", default-features = false, features = ["derive"] }
serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] }

# Substrate Dependencies
Expand Down
2 changes: 1 addition & 1 deletion scripts/bridges_update_subtree.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

set -e

BRIDGES_BRANCH="${BRANCH:-master}"
BRIDGES_BRANCH="${BRANCH:-polkadot-staging}"
BRIDGES_TARGET_DIR="${TARGET_DIR:-bridges}"

function fetch() {
Expand Down