Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ WORKDIR /parity-bridges-common

COPY . .

USER root
RUN rustup toolchain uninstall stable && \
rustup toolchain uninstall nightly && \
rustup toolchain install stable && \
rustup toolchain install nightly && \
rustup target add wasm32-unknown-unknown --toolchain nightly
ARG PROJECT=substrate-relay
RUN cargo build --release --verbose -p ${PROJECT} && \
strip ./target/release/${PROJECT}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ To run a Rialto node for example, you can use the following command:

```bash
docker run -p 30333:30333 -p 9933:9933 -p 9944:9944 \
-it paritytech/rialto-bridge-node --dev --tmp \
-it local/rialto-bridge-node --dev --tmp \
--rpc-cors=all --unsafe-rpc-external --unsafe-ws-external
```

Expand Down
23 changes: 9 additions & 14 deletions bin/millau/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,33 +795,28 @@ impl_runtime_apis! {
}

impl bp_rialto::RialtoFinalityApi<Block> for Runtime {
fn best_finalized() -> (bp_rialto::BlockNumber, bp_rialto::Hash) {
let header = BridgeRialtoGrandpa::best_finalized();
(header.number, header.hash())
fn best_finalized() -> Option<(bp_rialto::BlockNumber, bp_rialto::Hash)> {
BridgeRialtoGrandpa::best_finalized().map(|header| (header.number, header.hash()))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think we could use the new HeaderIdProvider::id() in these implementations. Could we also return an Option<HeaderId> here ? Or are we limited to basic types like tuples for the values returned by the API methods ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - I think it could be done. Thank you!

}
}

impl bp_westend::WestendFinalityApi<Block> for Runtime {
fn best_finalized() -> (bp_westend::BlockNumber, bp_westend::Hash) {
let header = BridgeWestendGrandpa::best_finalized();
(header.number, header.hash())
fn best_finalized() -> Option<(bp_westend::BlockNumber, bp_westend::Hash)> {
BridgeWestendGrandpa::best_finalized().map(|header| (header.number, header.hash()))
}
}

impl bp_rialto_parachain::RialtoParachainFinalityApi<Block> for Runtime {
fn best_finalized() -> (bp_rialto::BlockNumber, bp_rialto::Hash) {
fn best_finalized() -> Option<(bp_rialto::BlockNumber, bp_rialto::Hash)> {
// the parachains finality pallet is never decoding parachain heads, so it is
// only done in the integration code
use bp_rialto_parachain::RIALTO_PARACHAIN_ID;
let best_rialto_parachain_head = pallet_bridge_parachains::Pallet::<
let encoded_head = pallet_bridge_parachains::Pallet::<
Runtime,
WithRialtoParachainsInstance,
>::best_parachain_head(RIALTO_PARACHAIN_ID.into())
.and_then(|encoded_header| bp_rialto_parachain::Header::decode(&mut &encoded_header.0[..]).ok());
match best_rialto_parachain_head {
Some(head) => (*head.number(), head.hash()),
None => (Default::default(), Default::default()),
}
>::best_parachain_head(RIALTO_PARACHAIN_ID.into())?;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I would use bp_rialto_parachain::RIALTO_PARACHAIN_ID directly and remove the use statement above.

let head = bp_rialto_parachain::Header::decode(&mut &encoded_head.0[..]).ok()?;
Some((*head.number(), head.hash()))
}
}

Expand Down
5 changes: 2 additions & 3 deletions bin/rialto-parachain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,9 +683,8 @@ impl_runtime_apis! {
}

impl bp_millau::MillauFinalityApi<Block> for Runtime {
fn best_finalized() -> (bp_millau::BlockNumber, bp_millau::Hash) {
let header = BridgeMillauGrandpa::best_finalized();
(header.number, header.hash())
fn best_finalized() -> Option<(bp_millau::BlockNumber, bp_millau::Hash)> {
BridgeMillauGrandpa::best_finalized().map(|header| (header.number, header.hash()))
}
}

Expand Down
5 changes: 2 additions & 3 deletions bin/rialto/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,8 @@ impl_runtime_apis! {
}

impl bp_millau::MillauFinalityApi<Block> for Runtime {
fn best_finalized() -> (bp_millau::BlockNumber, bp_millau::Hash) {
let header = BridgeMillauGrandpa::best_finalized();
(header.number, header.hash())
fn best_finalized() -> Option<(bp_millau::BlockNumber, bp_millau::Hash)> {
BridgeMillauGrandpa::best_finalized().map(|header| (header.number, header.hash()))
}
}

Expand Down
2 changes: 1 addition & 1 deletion deployments/bridges/rialto-millau/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ services:
LETSENCRYPT_EMAIL: admin@parity.io

relay-millau-rialto: &sub-bridge-relay
image: paritytech/substrate-relay
image: local/substrate-relay
entrypoint: /entrypoints/relay-millau-rialto-entrypoint.sh
volumes:
- ./bridges/rialto-millau/entrypoints:/entrypoints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ services:
LETSENCRYPT_EMAIL: admin@parity.io

relay-millau-rialto-parachain: &sub-bridge-relay
image: paritytech/substrate-relay
image: local/substrate-relay
entrypoint: /entrypoints/relay-millau-rialto-parachain-entrypoint.sh
volumes:
- ./bridges/rialto-parachain-millau/entrypoints:/entrypoints
Expand Down
4 changes: 2 additions & 2 deletions deployments/bridges/westend-millau/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
version: '3.5'
services:
relay-headers-westend-to-millau-1:
image: paritytech/substrate-relay
image: local/substrate-relay
entrypoint: /entrypoints/relay-headers-westend-to-millau-entrypoint.sh
volumes:
- ./bridges/westend-millau/entrypoints:/entrypoints
Expand All @@ -15,7 +15,7 @@ services:
- millau-node-alice

relay-headers-westend-to-millau-2:
image: paritytech/substrate-relay
image: local/substrate-relay
entrypoint: /entrypoints/relay-headers-westend-to-millau-entrypoint.sh
volumes:
- ./bridges/westend-millau/entrypoints:/entrypoints
Expand Down
2 changes: 1 addition & 1 deletion deployments/networks/millau.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
version: '3.5'
services:
millau-node-alice: &millau-bridge-node
image: paritytech/millau-bridge-node
image: local/millau-bridge-node
entrypoint:
- /home/user/millau-bridge-node
- --execution=Native
Expand Down
4 changes: 2 additions & 2 deletions deployments/networks/rialto-parachain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
version: '3.5'
services:
rialto-parachain-collator-alice: &rialto-parachain-collator
image: paritytech/rialto-parachain-collator
image: local/rialto-parachain-collator
entrypoint: >
/home/user/rialto-parachain-collator
--alice
Expand Down Expand Up @@ -77,7 +77,7 @@ services:
- "20644:9944"

rialto-parachain-registrar:
image: paritytech/substrate-relay
image: local/substrate-relay
entrypoint: /entrypoints/rialto-parachain-registrar-entrypoint.sh
volumes:
- ./networks/entrypoints:/entrypoints
Expand Down
4 changes: 2 additions & 2 deletions deployments/networks/rialto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
version: '3.5'
services:
rialto-node-alice: &rialto-bridge-node
image: paritytech/rialto-bridge-node
image: local/rialto-bridge-node
entrypoint:
- /home/user/rialto-bridge-node
- --execution=Native
Expand Down Expand Up @@ -94,7 +94,7 @@ services:
- "10344:9944"

rialto-chainspec-exporter:
image: paritytech/rialto-bridge-node
image: local/rialto-bridge-node
entrypoint: /entrypoints/rialto-chainspec-exporter-entrypoint.sh
volumes:
- ./networks/entrypoints:/entrypoints
Expand Down
12 changes: 2 additions & 10 deletions modules/grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,17 +537,9 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
///
/// Returns a dummy header if there is no best header. This can only happen
/// if the pallet has not been initialized yet.
pub fn best_finalized() -> BridgedHeader<T, I> {
pub fn best_finalized() -> Option<BridgedHeader<T, I>> {
let hash = <BestFinalized<T, I>>::get();
<ImportedHeaders<T, I>>::get(hash).unwrap_or_else(|| {
<BridgedHeader<T, I>>::new(
Default::default(),
Default::default(),
Default::default(),
Default::default(),
Default::default(),
)
})
<ImportedHeaders<T, I>>::get(hash)
}

/// Check if a particular header is known to the bridge pallet.
Expand Down
2 changes: 1 addition & 1 deletion primitives/chain-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ sp_api::decl_runtime_apis! {
/// Kusama runtime itself.
pub trait KusamaFinalityApi {
/// Returns number and hash of the best finalized header known to the bridge module.
fn best_finalized() -> (BlockNumber, Hash);
fn best_finalized() -> Option<(BlockNumber, Hash)>;
}

/// Outbound message lane API for messages that are sent to Kusama chain.
Expand Down
2 changes: 1 addition & 1 deletion primitives/chain-millau/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ sp_api::decl_runtime_apis! {
/// Millau runtime itself.
pub trait MillauFinalityApi {
/// Returns number and hash of the best finalized header known to the bridge module.
fn best_finalized() -> (BlockNumber, Hash);
fn best_finalized() -> Option<(BlockNumber, Hash)>;
}

/// Outbound message lane API for messages that are sent to Millau chain.
Expand Down
2 changes: 1 addition & 1 deletion primitives/chain-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ sp_api::decl_runtime_apis! {
/// Polkadot runtime itself.
pub trait PolkadotFinalityApi {
/// Returns number and hash of the best finalized header known to the bridge module.
fn best_finalized() -> (BlockNumber, Hash);
fn best_finalized() -> Option<(BlockNumber, Hash)>;
}

/// Outbound message lane API for messages that are sent to Polkadot chain.
Expand Down
2 changes: 1 addition & 1 deletion primitives/chain-rialto-parachain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ sp_api::decl_runtime_apis! {
/// RialtoParachain runtime itself.
pub trait RialtoParachainFinalityApi {
/// Returns number and hash of the best finalized header known to the bridge module.
fn best_finalized() -> (BlockNumber, Hash);
fn best_finalized() -> Option<(BlockNumber, Hash)>;
}

/// Outbound message lane API for messages that are sent to RialtoParachain chain.
Expand Down
2 changes: 1 addition & 1 deletion primitives/chain-rialto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ sp_api::decl_runtime_apis! {
/// Rialto runtime itself.
pub trait RialtoFinalityApi {
/// Returns number and hash of the best finalized header known to the bridge module.
fn best_finalized() -> (BlockNumber, Hash);
fn best_finalized() -> Option<(BlockNumber, Hash)>;
}

/// Outbound message lane API for messages that are sent to Rialto chain.
Expand Down
2 changes: 1 addition & 1 deletion primitives/chain-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ sp_api::decl_runtime_apis! {
/// Rococo runtime itself.
pub trait RococoFinalityApi {
/// Returns number and hash of the best finalized header known to the bridge module.
fn best_finalized() -> (BlockNumber, Hash);
fn best_finalized() -> Option<(BlockNumber, Hash)>;
}

/// Outbound message lane API for messages that are sent to Rococo chain.
Expand Down
2 changes: 1 addition & 1 deletion primitives/chain-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,6 @@ sp_api::decl_runtime_apis! {
/// Westend runtime itself.
pub trait WestendFinalityApi {
/// Returns number and hash of the best finalized header known to the bridge module.
fn best_finalized() -> (BlockNumber, Hash);
fn best_finalized() -> Option<(BlockNumber, Hash)>;
}
}
2 changes: 1 addition & 1 deletion primitives/chain-wococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ sp_api::decl_runtime_apis! {
/// Wococo runtime itself.
pub trait WococoFinalityApi {
/// Returns number and hash of the best finalized header known to the bridge module.
fn best_finalized() -> (BlockNumber, Hash);
fn best_finalized() -> Option<(BlockNumber, Hash)>;
}

/// Outbound message lane API for messages that are sent to Wococo chain.
Expand Down
6 changes: 3 additions & 3 deletions primitives/header-chain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub trait InclusionProofVerifier {
/// A trait for pallets which want to keep track of finalized headers from a bridged chain.
pub trait HeaderChain<H, E> {
/// Get the best finalized header known to the header chain.
fn best_finalized() -> H;
fn best_finalized() -> Option<H>;

/// Get the best authority set known to the header chain.
fn authority_set() -> AuthoritySet;
Expand All @@ -98,8 +98,8 @@ pub trait HeaderChain<H, E> {
}

impl<H: Default, E> HeaderChain<H, E> for () {
fn best_finalized() -> H {
H::default()
fn best_finalized() -> Option<H> {
None
}

fn authority_set() -> AuthoritySet {
Expand Down
5 changes: 5 additions & 0 deletions relays/lib-substrate-relay/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,9 @@ pub enum Error<Hash: Debug + MaybeDisplay, HeaderNumber: Debug + MaybeDisplay> {
/// Failed to retrieve best finalized source header hash from the target chain.
#[error("Failed to retrieve best finalized {0} header from the target chain: {1}")]
RetrieveBestFinalizedHeaderHash(&'static str, client::Error),
/// Failed to submit signed extrinsic from to the target chain.
#[error(
"Failed to retrieve `is_initialized` flag of the with-{0} finality pallet at {1}: {2:?}"
)]
IsInitializedRetrieve(&'static str, &'static str, client::Error),
}
19 changes: 18 additions & 1 deletion relays/lib-substrate-relay/src/finality/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use std::marker::PhantomData;

/// Finality enfine, used by the Substrate chain.
#[async_trait]
pub trait Engine<C: Chain> {
pub trait Engine<C: Chain>: Send {
/// Unique consensus engine identifier.
const ID: ConsensusEngineId;
/// Type of finality proofs, used by consensus engine.
Expand All @@ -59,6 +59,23 @@ pub trait Engine<C: Chain> {
async fn prepare_initialization_data(
client: Client<C>,
) -> Result<Self::InitializationData, Error<HashOf<C>, BlockNumberOf<C>>>;

/// Returns `Ok(true)` if finality pallet at the bridged chain has already been initialized.
async fn is_initialized<TargetChain: Chain>(
target_client: &Client<TargetChain>,
) -> Result<bool, SubstrateError> {
Ok(target_client
.raw_storage_value(Self::is_initialized_key(), None)
.await?
.is_some())
}

/// Returns `Ok(true)` if finality pallet at the bridged chain is halted.
async fn is_halted<TargetChain: Chain>(
target_client: &Client<TargetChain>,
) -> Result<bool, SubstrateError> {
Ok(target_client.storage_value(Self::is_halted_key(), None).await?.unwrap_or(false))
}
}

/// GRANDPA finality engine.
Expand Down
21 changes: 4 additions & 17 deletions relays/lib-substrate-relay/src/finality/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

use crate::{error::Error, finality::engine::Engine};

use relay_substrate_client::{BlockNumberOf, Chain, Client, Error as SubstrateError, HashOf};
use relay_substrate_client::{Chain, Client, Error as SubstrateError};
use sp_core::Bytes;
use sp_runtime::traits::Header as HeaderT;

Expand Down Expand Up @@ -80,7 +80,9 @@ where
+ Send
+ 'static,
{
let is_initialized = is_initialized::<E, SourceChain, TargetChain>(&target_client).await?;
let is_initialized = E::is_initialized(&target_client)
.await
.map_err(|e| Error::IsInitializedRetrieve(SourceChain::NAME, TargetChain::NAME, e))?;
if is_initialized {
log::info!(
target: "bridge",
Expand Down Expand Up @@ -108,18 +110,3 @@ where
.map_err(|err| Error::SubmitTransaction(TargetChain::NAME, err))?;
Ok(Some(initialization_tx_hash))
}

/// Returns `Ok(true)` if bridge has already been initialized.
pub(crate) async fn is_initialized<
E: Engine<SourceChain>,
SourceChain: Chain,
TargetChain: Chain,
>(
target_client: &Client<TargetChain>,
) -> Result<bool, Error<HashOf<SourceChain>, BlockNumberOf<SourceChain>>> {
Ok(target_client
.raw_storage_value(E::is_initialized_key(), None)
.await
.map_err(|err| Error::RetrieveBestFinalizedHeaderHash(SourceChain::NAME, err))?
.is_some())
}
9 changes: 3 additions & 6 deletions relays/lib-substrate-relay/src/finality/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,12 @@ impl<P: SubstrateFinalitySyncPipeline> SubstrateFinalityTarget<P> {

/// Ensure that the bridge pallet at target chain is active.
pub async fn ensure_pallet_active(&self) -> Result<(), Error> {
let is_halted = self.client.storage_value(P::FinalityEngine::is_halted_key(), None).await?;
if is_halted.unwrap_or(false) {
let is_halted = P::FinalityEngine::is_halted(&self.client).await?;
if is_halted {
return Err(Error::BridgePalletIsHalted)
}

let is_initialized =
super::initialize::is_initialized::<P::FinalityEngine, P::SourceChain, P::TargetChain>(
&self.client,
)
let is_initialized = P::FinalityEngine::is_initialized(&self.client)
.await
.map_err(|e| Error::Custom(e.to_string()))?;
if !is_initialized {
Expand Down
Loading