Skip to content

Commit

Permalink
Market actor update (#593)
Browse files Browse the repository at this point in the history
* Update methods and constructor

* wip setting up market state mutations

* Implement all state mutation setup

* Wip implement market state functions

* Finish market state

* Update policy and switch other types to signed bigint

* Fix test compilation

* Update market types

* Implement add and withdraw methods

* Implement publish_storage_deals

* Implement verify and activate deal

* update miner sector terminate

* implement compute data commitment

* Implement other actor methods

* market actor cleanup

* Update to using exit codes from assumed dropped

* Update error handling to check if delete doesn't remove element and comment updates

* clippy
  • Loading branch information
austinabell authored Aug 6, 2020
1 parent 44c1cd9 commit 9035396
Show file tree
Hide file tree
Showing 23 changed files with 1,504 additions and 1,010 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.

2 changes: 2 additions & 0 deletions ipld/cid/src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,7 @@ build_codec_enum! {
0xb1 => BitcoinTx,
0xc0 => ZcashBlock,
0xc1 => ZcashTx,
0x101 => FilCommitmentUnsealed,
0x102 => FilCommitmentSealed,
0x0129 => DagJSON,
}
27 changes: 27 additions & 0 deletions ipld/hamt/src/hamt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,33 @@ where
}
}

/// Returns `true` if a value exists for the given key in the HAMT.
///
/// The key may be any borrowed form of the map's key type, but
/// `Hash` and `Eq` on the borrowed form *must* match those for
/// the key type.
///
/// # Examples
///
/// ```
/// use ipld_hamt::Hamt;
///
/// let store = db::MemoryDB::default();
///
/// let mut map: Hamt<usize, _> = Hamt::new(&store);
/// map.set(1, "a".to_string()).unwrap();
/// assert_eq!(map.contains_key(&1).unwrap(), true);
/// assert_eq!(map.contains_key(&2).unwrap(), false);
/// ```
#[inline]
pub fn contains_key<Q: ?Sized>(&self, k: &Q) -> Result<bool, Error>
where
K: Borrow<Q>,
Q: Hash + Eq,
{
Ok(self.root.get(k, self.store, self.bit_width)?.is_some())
}

/// Removes a key from the HAMT, returning the value at the key if the key
/// was previously in the HAMT.
///
Expand Down
5 changes: 2 additions & 3 deletions types/src/sector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pub use self::seal::*;

use encoding::{repr::*, tuple::*};
use num_bigint::BigInt;
use num_bigint::BigUint;
use num_derive::FromPrimitive;
use std::fmt;
use vm::ActorID;
Expand All @@ -22,10 +21,10 @@ pub type SectorNumber = u64;
pub type StoragePower = BigInt;

/// The unit of spacetime committed to the network
pub type Spacetime = BigUint;
pub type Spacetime = BigInt;

/// Unit of sector quality
pub type SectorQuality = BigUint;
pub type SectorQuality = BigInt;

/// SectorSize indicates one of a set of possible sizes in the network.
#[derive(Clone, Debug, PartialEq, Copy, FromPrimitive, Serialize_repr, Deserialize_repr)]
Expand Down
1 change: 1 addition & 0 deletions vm/actor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ derive_builder = "0.9"
byteorder = "1.3.4"
ahash = "0.4"
base64 = "0.12.1"
log = "0.4.8"

[dev-dependencies]
db = { path = "../../node/db" }
Expand Down
20 changes: 19 additions & 1 deletion vm/actor/src/builtin/market/deal.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2020 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use crate::DealWeight;
use address::Address;
use cid::Cid;
use cid::{multihash::Code, Cid, Codec, Prefix, Version};
use clock::ChainEpoch;
use crypto::Signature;
use encoding::tuple::*;
Expand All @@ -11,6 +12,17 @@ use fil_types::PaddedPieceSize;
use num_bigint::bigint_ser;
use vm::TokenAmount;

// TODO this hash code should probably be in common place
const SHA2_256_TRUNC254_PADDED: u64 = 0x1012;

/// Cid prefix for piece Cids
pub const PIECE_CID_PREFIX: Prefix = Prefix {
version: Version::V1,
codec: Codec::FilCommitmentUnsealed,
mh_type: Code::Custom(SHA2_256_TRUNC254_PADDED),
mh_len: 32,
};

/// Note: Deal Collateral is only released and returned to clients and miners
/// when the storage deal stops counting towards power. In the current iteration,
/// it will be released when the sector containing the storage deals expires,
Expand Down Expand Up @@ -48,6 +60,10 @@ impl DealProposal {
pub fn duration(&self) -> ChainEpoch {
self.end_epoch - self.start_epoch
}
/// Computes weight for a deal proposal, which is a function of its size and duration.
pub fn weight(&self) -> DealWeight {
DealWeight::from(self.duration()) * self.piece_size.0
}
pub fn total_storage_fee(&self) -> TokenAmount {
self.storage_price_per_epoch.clone() * self.duration() as u64
}
Expand All @@ -66,6 +82,8 @@ pub struct ClientDealProposal {
pub client_signature: Signature,
}

impl Cbor for ClientDealProposal {}

#[derive(Clone, Debug, PartialEq, Copy, Serialize_tuple, Deserialize_tuple)]
pub struct DealState {
pub sector_start_epoch: ChainEpoch, // -1 if not yet included in proven sector
Expand Down
Loading

0 comments on commit 9035396

Please sign in to comment.