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

Add data_preserver_active_assignment fn to OrchestratorChainInterface #32

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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
32 changes: 32 additions & 0 deletions client/orchestrator-chain-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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,
parity_scale_codec::{Encode, Decode}
};
pub use {
cumulus_primitives_core::relay_chain::Slot,
Expand Down Expand Up @@ -91,6 +92,21 @@ 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 Down Expand Up @@ -147,6 +163,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 Down Expand Up @@ -227,4 +249,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 @@ -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
Loading