Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into tomasz-impl-solochain
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpolaczyk committed Aug 27, 2024
2 parents 880f566 + c88954e commit 9117a02
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/orchestrator-chain-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ async-trait = { workspace = true }
futures = { workspace = true }
jsonrpsee = { workspace = true }
parity-scale-codec = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }

# Dancekit
Expand Down
48 changes: 44 additions & 4 deletions client/orchestrator-chain-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@
//! prove_read: generates a storage proof of a given set of keys at a given Orchestrator parent
use {
core::pin::Pin, dp_core::ParaId, futures::Stream, polkadot_overseer::Handle,
sc_client_api::StorageProof, sp_api::ApiError, sp_state_machine::StorageValue, std::sync::Arc,
core::pin::Pin,
dp_core::ParaId,
futures::Stream,
parity_scale_codec::{Decode, Encode},
polkadot_overseer::Handle,
sc_client_api::StorageProof,
sp_api::ApiError,
sp_state_machine::StorageValue,
std::sync::Arc,
};
pub use {
cumulus_primitives_core::relay_chain::Slot,
Expand Down Expand Up @@ -91,6 +98,23 @@ impl From<Box<dyn sp_state_machine::Error>> for OrchestratorChainError {
// TODO: proper errors
pub type OrchestratorChainResult<T> = Result<T, OrchestratorChainError>;

pub type DataPreserverProfileId = u64;

// Copy of Tanssi's pallet_data_preservers_runtime_api::Assignment
#[derive(
Debug, Copy, Clone, PartialEq, Eq, Encode, Decode, serde::Serialize, serde::Deserialize,
)]
pub enum DataPreserverAssignment<ParaId> {
/// Profile is not currently assigned.
NotAssigned,
/// Profile is activly assigned to this ParaId.
Active(ParaId),
/// Profile is assigned to this ParaId but is inactive for some reason.
/// It may be causes by conditions defined in the assignement configuration,
/// such as lacking payment.
Inactive(ParaId),
}

/// Trait that provides all necessary methods for interaction between collator and orchestrator chain.
#[async_trait::async_trait]
pub trait OrchestratorChainInterface: Send + Sync {
Expand All @@ -108,7 +132,7 @@ pub trait OrchestratorChainInterface: Send + Sync {
async fn prove_read(
&self,
orchestrator_parent: PHash,
relevant_keys: &[Vec<u8>],
relevant_keys: &Vec<Vec<u8>>,
) -> OrchestratorChainResult<StorageProof>;

/// Get a stream of import block notifications.
Expand Down Expand Up @@ -147,6 +171,12 @@ pub trait OrchestratorChainInterface: Send + Sync {
async fn best_block_hash(&self) -> OrchestratorChainResult<PHash>;

async fn finalized_block_hash(&self) -> OrchestratorChainResult<PHash>;

async fn data_preserver_active_assignment(
&self,
orchestrator_parent: PHash,
profile_id: DataPreserverProfileId,
) -> OrchestratorChainResult<DataPreserverAssignment<ParaId>>;
}

#[async_trait::async_trait]
Expand All @@ -169,7 +199,7 @@ where
async fn prove_read(
&self,
orchestrator_parent: PHash,
relevant_keys: &[Vec<u8>],
relevant_keys: &Vec<Vec<u8>>,
) -> OrchestratorChainResult<StorageProof> {
(**self)
.prove_read(orchestrator_parent, relevant_keys)
Expand Down Expand Up @@ -227,4 +257,14 @@ where
async fn finalized_block_hash(&self) -> OrchestratorChainResult<PHash> {
(**self).finalized_block_hash().await
}

async fn data_preserver_active_assignment(
&self,
orchestrator_parent: PHash,
profile_id: DataPreserverProfileId,
) -> OrchestratorChainResult<DataPreserverAssignment<ParaId>> {
(**self)
.data_preserver_active_assignment(orchestrator_parent, profile_id)
.await
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ use {
},
cumulus_relay_chain_interface::{PHash, PHeader, RelayChainInterface, RelayChainResult},
dc_orchestrator_chain_interface::{
BlockNumber, ContainerChainGenesisData, OrchestratorChainInterface, OrchestratorChainResult,
BlockNumber, ContainerChainGenesisData, DataPreserverAssignment, DataPreserverProfileId,
OrchestratorChainInterface, OrchestratorChainResult,
},
dp_core::{well_known_keys, Header as OrchestratorHeader},
futures::Stream,
Expand Down Expand Up @@ -105,7 +106,7 @@ impl OrchestratorChainInterface for DummyOrchestratorChainInterface {
async fn prove_read(
&self,
hash: PHash,
keys: &[Vec<u8>],
keys: &Vec<Vec<u8>>,
) -> OrchestratorChainResult<sc_client_api::StorageProof> {
self.orchestrator_client
.state_at(hash)
Expand Down Expand Up @@ -163,6 +164,14 @@ impl OrchestratorChainInterface for DummyOrchestratorChainInterface {
async fn finalized_block_hash(&self) -> OrchestratorChainResult<PHash> {
unimplemented!("Not needed for test")
}

async fn data_preserver_active_assignment(
&self,
_orchestrator_parent: PHash,
_profile_id: DataPreserverProfileId,
) -> OrchestratorChainResult<DataPreserverAssignment<ParaId>> {
unimplemented!("Not needed for test")
}
}

#[async_trait]
Expand Down

0 comments on commit 9117a02

Please sign in to comment.