Skip to content

Commit

Permalink
refactor: Publish storage deals (#599)
Browse files Browse the repository at this point in the history
  • Loading branch information
aidan46 authored Nov 25, 2024
1 parent 71d4a20 commit aa21def
Show file tree
Hide file tree
Showing 15 changed files with 355 additions and 411 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ subxt = { version = "0.38.0" }
subxt-signer = "0.38.0"
syn = { version = "2.0.53" }
tempfile = "3.10.1"
thiserror = { version = "2.0.3" }
thiserror = { version = "2.0.3", default-features = false }
tokio = "1.37.0"
tokio-stream = "0.1.15"
tokio-util = "0.7.11"
Expand Down
Binary file modified cli/artifacts/metadata.scale
Binary file not shown.
6 changes: 3 additions & 3 deletions cli/polka-storage-provider/client/src/commands/proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use polka_storage_proofs::{
use polka_storage_provider_common::commp::{calculate_piece_commitment, CommPError};
use primitives_commitment::{
piece::{PaddedPieceSize, PieceInfo},
Commitment,
Commitment, CommitmentError,
};
use primitives_proofs::{derive_prover_id, RegisteredPoStProof, RegisteredSealProof};
use storagext::multipair::{MultiPairArgs, MultiPairSigner};
Expand Down Expand Up @@ -444,8 +444,8 @@ pub enum UtilsCommandError {
InvalidPieceFile(PathBuf, std::io::Error),
#[error("provided invalid CommP {0}, error: {1}")]
InvalidPieceCommP(String, cid::Error),
#[error("invalid piece type")]
InvalidPieceType(String, &'static str),
#[error("invalid piece type, error: {1}")]
InvalidPieceType(String, CommitmentError),
#[error("file {0} is invalid CARv2 file {1}")]
InvalidCARv2(PathBuf, mater::Error),
#[error("no signer key was provider")]
Expand Down
2 changes: 1 addition & 1 deletion cli/polka-storage/storagext/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ serde_json = { workspace = true }
sha2 = { workspace = true }
subxt = { workspace = true, features = ["jsonrpsee", "substrate-compat"] }
subxt-signer = { workspace = true, features = ["subxt"] }
thiserror = { workspace = true }
thiserror = { workspace = true, default-features = true }
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
tracing = { workspace = true }
tracing-subscriber = { workspace = true, features = ["env-filter"] }
Expand Down
2 changes: 1 addition & 1 deletion cli/polka-storage/storagext/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub mod display;
derive = "::serde::Serialize"
),
derive_for_type(
path = "pallet_market::pallet::DealSettlementError",
path = "pallet_market::error::DealSettlementError",
derive = "::serde::Serialize"
),
derive_for_type(
Expand Down
18 changes: 17 additions & 1 deletion docs/src/architecture/pallets/market.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ The Market Pallet actions can fail with following errors:
- `InsufficientFreeFunds` - Market participants do not have enough free funds.
- `NoProposalsToBePublished` - `publish_storage_deals` was called with an empty list of `deals`.
- `ProposalsPublishedByIncorrectStorageProvider` - Is returned when calling `publish_storage_deals` and the deals in a list are not published by the same storage provider.
- `AllProposalsInvalid` - `publish_storage_deals` call was supplied with a list of `deals` which are all invalid.
- `DuplicateDeal` - There is more than one deal with this ID in the Sector.
- `DealNotFound` - Tried to activate a deal that is not in the system.
- `DealActivationError` - Tried to activate a deal, but data was malformed.
Expand All @@ -222,6 +221,23 @@ The Market Pallet actions can fail with following errors:
- Deal is not pending.
- `DealsTooLargeToFitIntoSector` - Sum of all deals piece sizes for a sector exceeds sector size. The sector size is based on the registered proof type. We currently only support registered `StackedDRG2KiBV1P1` proofs, which have 2KiB sector sizes.
- `TooManyDealsPerBlock` - Tried to activate too many deals at a given `start_block`.
- `StorageProviderNotRegistered` - An account tries to call `publish_storage_deals` but is not registered as a storage provider.
- `CommD` - An error occurred when trying to calculate CommD.
- `TooManyPendingDeals` - A storage provider tried to propose a deal, but there are too many pending deals. The pending deals should be activated or wait for expiry.
- `InvalidProvider` - A deal was tried to be activated by a provider which does not own it.
- `StartBlockElapsed` - A storage provider tries to activate a deal after the start block.
- `SectorExpiresBeforeDeal` - Sector containing the deal will expire before the deal is supposed to end.
- `InvalidDealState` - A deal was attempted to be activated twice.
- `DealNotPending` - A storage provider tried to activate a deal which is not in the pending proposals.
- `WrongClientSignatureOnProposal` - The client signature did not match the client's public key and data.
- `DealEndBeforeStart` - A deal was attempted to be published but the end block is before the start block and the deal is rejected.
- `DealStartExpired` - A deal was attempted to be published but the start block is in the past and the deal is rejected.
- `DealNotPublished` - A deal was attempted to be published but is not in the correct state.
- `DealDurationOutOfBounds` - A deal was attempted to be published but the duration is not between [MinDealDuration](#constants) and [MaxDealDuration](#constants).
- `InvalidPieceCid` - The deal trying to be published has an invalid piece Cid.
- `DealIsNotActive` - When a sector is being terminated but the deal state is not active. This is the result of a programmer bug. Please [report an issue](https://github.com/eigerco/polka-storage-book/issues/new) to the developers.
- `InvalidCaller` - A deal was found that does not belong to the storage provider. This is the result of a programmer bug. Please [report an issue](https://github.com/eigerco/polka-storage-book/issues/new) to the developers.
- `DealNotFound` - A deal was attempted to be fetched but could not be found. This is the result of a programmer bug. Please [report an issue](https://github.com/eigerco/polka-storage-book/issues/new) to the developers.
- `UnexpectedValidationError` - `publish_storage_deals`'s core logic was invoked with a broken invariant that should be called by `validate_deals`. Please [report an issue](https://github.com/eigerco/polka-storage-book/issues/new) to the developers.
- `DealPreconditionFailed` - Due to a programmer bug. Please [report an issue](https://github.com/eigerco/polka-storage-book/issues/new) to the developers.

Expand Down
1 change: 1 addition & 0 deletions pallets/market/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ multihash-codetable = { workspace = true, features = ["blake2b"] }
primitives-commitment = { workspace = true }
primitives-proofs = { workspace = true, default-features = false }
scale-info = { workspace = true, default-features = false, features = ["derive"] }
thiserror = { workspace = true, default-features = false }

# frame deps
frame-benchmarking = { workspace = true, default-features = false, optional = true }
Expand Down
48 changes: 48 additions & 0 deletions pallets/market/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use codec::{Decode, Encode};
use primitives_commitment::{piece::PaddedPieceSizeError, CommitmentError};
use scale_info::TypeInfo;

// Clone and PartialEq required because of the BoundedVec<(DealId, DealSettlementError)>
#[derive(TypeInfo, Encode, Decode, Clone, PartialEq, thiserror::Error)]
pub enum DealSettlementError {
/// The deal is going to be slashed.
#[error("DealSettlementError: Slashed Deal")]
SlashedDeal,
/// The deal last update is in the future — i.e. `last_update_block > current_block`.
#[error("DealSettlementError: Future Last Update")]
FutureLastUpdate,
/// The deal was not found.
#[error("DealSettlementError: Deal Not Found")]
DealNotFound,
/// The deal is too early to settle.
#[error("DealSettlementError: Early Settlement")]
EarlySettlement,
/// The deal has expired
#[error("DealSettlementError: Expired Deal")]
ExpiredDeal,
/// Deal is not activated
#[error("DealSettlementError: Deal Not Active")]
DealNotActive,
}

impl core::fmt::Debug for DealSettlementError {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
core::fmt::Display::fmt(self, f)
}
}

// TODO: Implement TypeInfo for inner error so we can store them here.
// For now logging will the error will do
#[derive(TypeInfo, Encode, Decode, Clone, PartialEq, thiserror::Error)]
pub enum CommDError {
#[error("CommDError for commitment {0}")]
CommitmentError(CommitmentError),
#[error("CommDError for piece size {0}")]
PaddedPieceSizeError(PaddedPieceSizeError),
}

impl core::fmt::Debug for CommDError {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
core::fmt::Display::fmt(self, f)
}
}
Loading

0 comments on commit aa21def

Please sign in to comment.