Skip to content

Commit

Permalink
feat: update sdk & shared for TokenAmount and hashing changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Stebalien committed Aug 31, 2022
1 parent f5855ac commit 2a8d3d5
Show file tree
Hide file tree
Showing 124 changed files with 1,262 additions and 1,307 deletions.
340 changes: 166 additions & 174 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion actors/account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ crate-type = ["cdylib", "lib"]

[dependencies]
fil_actors_runtime = { version = "9.0.0-alpha.1", path = "../../runtime", features = ["fil-actor"] }
fvm_shared = { version = "0.8.0", default-features = false }
fvm_shared = { version = "2.0.0-alpha.2", default-features = false }
serde = { version = "1.0.136", features = ["derive"] }
num-traits = "0.2.14"
num-derive = "0.3.3"
Expand Down
2 changes: 1 addition & 1 deletion actors/cron/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ crate-type = ["cdylib", "lib"]

[dependencies]
fil_actors_runtime = { version = "9.0.0-alpha.1", path = "../../runtime", features = ["fil-actor"] }
fvm_shared = { version = "0.8.0", default-features = false }
fvm_shared = { version = "2.0.0-alpha.2", default-features = false }
num-traits = "0.2.14"
num-derive = "0.3.3"
log = "0.4.14"
Expand Down
4 changes: 2 additions & 2 deletions actors/cron/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use fvm_shared::econ::TokenAmount;

use fvm_shared::{MethodNum, METHOD_CONSTRUCTOR};
use num_derive::FromPrimitive;
use num_traits::FromPrimitive;
use num_traits::{FromPrimitive, Zero};

pub use self::state::{Entry, State};

Expand Down Expand Up @@ -68,7 +68,7 @@ impl Actor {
&entry.receiver,
entry.method_num,
RawBytes::default(),
TokenAmount::from(0u8),
TokenAmount::zero(),
);
if let Err(e) = res {
log::error!(
Expand Down
10 changes: 6 additions & 4 deletions actors/cron/tests/cron_actor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use fil_actors_runtime::test_utils::*;
use fil_actors_runtime::SYSTEM_ACTOR_ADDR;
use fvm_ipld_encoding::RawBytes;
use fvm_shared::address::Address;
use fvm_shared::econ::TokenAmount;
use fvm_shared::error::ExitCode;
use num_traits::Zero;

fn check_state(rt: &MockRuntime) {
let (_, acc) = check_state_invariants(&rt.get_state());
Expand Down Expand Up @@ -79,31 +81,31 @@ fn epoch_tick_with_entries() {
entry1.receiver,
entry1.method_num,
RawBytes::default(),
0u8.into(),
TokenAmount::zero(),
RawBytes::default(),
ExitCode::OK,
);
rt.expect_send(
entry2.receiver,
entry2.method_num,
RawBytes::default(),
0u8.into(),
TokenAmount::zero(),
RawBytes::default(),
ExitCode::USR_ILLEGAL_ARGUMENT,
);
rt.expect_send(
entry3.receiver,
entry3.method_num,
RawBytes::default(),
0u8.into(),
TokenAmount::zero(),
RawBytes::default(),
ExitCode::OK,
);
rt.expect_send(
entry4.receiver,
entry4.method_num,
RawBytes::default(),
0u8.into(),
TokenAmount::zero(),
RawBytes::default(),
ExitCode::OK,
);
Expand Down
2 changes: 1 addition & 1 deletion actors/init/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ crate-type = ["cdylib", "lib"]

[dependencies]
fil_actors_runtime = { version = "9.0.0-alpha.1", path = "../../runtime", features = ["fil-actor"] }
fvm_shared = { version = "0.8.0", default-features = false }
fvm_shared = { version = "2.0.0-alpha.2", default-features = false }
fvm_ipld_hamt = "0.5.1"
serde = { version = "1.0.136", features = ["derive"] }
num-traits = "0.2.14"
Expand Down
15 changes: 8 additions & 7 deletions actors/init/tests/init_actor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use fvm_shared::address::Address;
use fvm_shared::econ::TokenAmount;
use fvm_shared::error::ExitCode;
use fvm_shared::{HAMT_BIT_WIDTH, METHOD_CONSTRUCTOR};
use num_traits::Zero;
use serde::Serialize;

fn check_state(rt: &MockRuntime) {
Expand Down Expand Up @@ -72,7 +73,7 @@ fn repeated_robust_address() {
expected_id_addr,
METHOD_CONSTRUCTOR,
RawBytes::serialize(&fake_params).unwrap(),
0u8.into(),
TokenAmount::zero(),
RawBytes::default(),
ExitCode::OK,
);
Expand Down Expand Up @@ -116,8 +117,8 @@ fn create_2_payment_channels() {
let pay_channel_string = format!("paych_{}", n);
let paych = pay_channel_string.as_bytes();

rt.set_balance(TokenAmount::from(100));
rt.value_received = TokenAmount::from(100);
rt.set_balance(TokenAmount::from_atto(100));
rt.value_received = TokenAmount::from_atto(100);

let unique_address = Address::new_actor(paych);
rt.new_actor_addr = Some(Address::new_actor(paych));
Expand All @@ -129,7 +130,7 @@ fn create_2_payment_channels() {
let fake_params = ConstructorParams { network_name: String::from("fake_param") };

// expect anne creating a payment channel to trigger a send to the payment channels constructor
let balance = TokenAmount::from(100u8);
let balance = TokenAmount::from_atto(100u8);

rt.expect_send(
expected_id_addr,
Expand Down Expand Up @@ -177,7 +178,7 @@ fn create_storage_miner() {
expected_id_addr,
METHOD_CONSTRUCTOR,
RawBytes::serialize(&fake_params).unwrap(),
0u8.into(),
TokenAmount::zero(),
RawBytes::default(),
ExitCode::OK,
);
Expand Down Expand Up @@ -228,7 +229,7 @@ fn create_multisig_actor() {
expected_id_addr,
METHOD_CONSTRUCTOR,
RawBytes::serialize(&fake_params).unwrap(),
0u8.into(),
TokenAmount::zero(),
RawBytes::default(),
ExitCode::OK,
);
Expand Down Expand Up @@ -263,7 +264,7 @@ fn sending_constructor_failure() {
expected_id_addr,
METHOD_CONSTRUCTOR,
RawBytes::serialize(&fake_params).unwrap(),
0u8.into(),
TokenAmount::zero(),
RawBytes::default(),
ExitCode::USR_ILLEGAL_STATE,
);
Expand Down
2 changes: 1 addition & 1 deletion actors/market/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ crate-type = ["cdylib", "lib"]
[dependencies]
fil_actors_runtime = { version = "9.0.0-alpha.1", path = "../../runtime", features = ["fil-actor"] }
fvm_ipld_hamt = "0.5.1"
fvm_shared = { version = "0.8.0", default-features = false }
fvm_shared = { version = "2.0.0-alpha.2", default-features = false }
fvm_ipld_bitfield = "0.5.2"
num-traits = "0.2.14"
num-derive = "0.3.3"
Expand Down
57 changes: 32 additions & 25 deletions actors/market/src/balance_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ use cid::Cid;
use fvm_ipld_blockstore::Blockstore;
use fvm_ipld_hamt::Error as HamtError;
use fvm_shared::address::Address;
use fvm_shared::bigint::bigint_ser::BigIntDe;
use fvm_shared::econ::TokenAmount;
use num_traits::{Signed, Zero};
use num_traits::Zero;

use fil_actors_runtime::{make_empty_map, make_map_with_root_and_bitwidth, Map};

pub const BALANCE_TABLE_BITWIDTH: u32 = 6;

/// Balance table which handles getting and updating token balances specifically
pub struct BalanceTable<'a, BS>(pub Map<'a, BS, BigIntDe>);
pub struct BalanceTable<'a, BS>(pub Map<'a, BS, TokenAmount>);

impl<'a, BS> BalanceTable<'a, BS>
where
Expand All @@ -38,9 +37,9 @@ where
/// Gets token amount for given address in balance table
pub fn get(&self, key: &Address) -> Result<TokenAmount, HamtError> {
if let Some(v) = self.0.get(&key.to_bytes())? {
Ok(v.0.clone())
Ok(v.clone())
} else {
Ok(0.into())
Ok(TokenAmount::zero())
}
}

Expand All @@ -54,7 +53,7 @@ where
self.0.delete(&key.to_bytes())?;
Ok(())
} else {
self.0.set(key.to_bytes().into(), BigIntDe(sum))?;
self.0.set(key.to_bytes().into(), sum)?;
Ok(())
}
}
Expand Down Expand Up @@ -93,10 +92,10 @@ where
/// Returns total balance held by this balance table
#[allow(dead_code)]
pub fn total(&self) -> Result<TokenAmount, HamtError> {
let mut total = TokenAmount::default();
let mut total = TokenAmount::zero();

self.0.for_each(|_, v: &BigIntDe| {
total += &v.0;
self.0.for_each(|_, v: &TokenAmount| {
total += v;
Ok(())
})?;

Expand All @@ -119,7 +118,7 @@ mod tests {
let store = MemoryBlockstore::default();
let mut bt = BalanceTable::new(&store);

assert_eq!(bt.total().unwrap(), TokenAmount::from(0u8));
assert!(bt.total().unwrap().is_zero());

struct TotalTestCase<'a> {
amount: u64,
Expand All @@ -134,9 +133,9 @@ mod tests {
];

for t in cases.iter() {
bt.add(t.addr, &TokenAmount::from(t.amount)).unwrap();
bt.add(t.addr, &TokenAmount::from_atto(t.amount)).unwrap();

assert_eq!(bt.total().unwrap(), TokenAmount::from(t.total));
assert_eq!(bt.total().unwrap(), TokenAmount::from_atto(t.total));
}
}

Expand All @@ -146,29 +145,37 @@ mod tests {
let store = MemoryBlockstore::default();
let mut bt = BalanceTable::new(&store);

bt.add(&addr, &TokenAmount::from(80u8)).unwrap();
assert_eq!(bt.get(&addr).unwrap(), TokenAmount::from(80u8));
bt.add(&addr, &TokenAmount::from_atto(80u8)).unwrap();
assert_eq!(bt.get(&addr).unwrap(), TokenAmount::from_atto(80u8));
// Test subtracting past minimum only subtracts correct amount
assert_eq!(
bt.subtract_with_minimum(&addr, &TokenAmount::from(20u8), &TokenAmount::from(70u8))
.unwrap(),
TokenAmount::from(10u8)
bt.subtract_with_minimum(
&addr,
&TokenAmount::from_atto(20u8),
&TokenAmount::from_atto(70u8)
)
.unwrap(),
TokenAmount::from_atto(10u8)
);
assert_eq!(bt.get(&addr).unwrap(), TokenAmount::from(70u8));
assert_eq!(bt.get(&addr).unwrap(), TokenAmount::from_atto(70u8));

// Test subtracting to limit
assert_eq!(
bt.subtract_with_minimum(&addr, &TokenAmount::from(10u8), &TokenAmount::from(60u8))
.unwrap(),
TokenAmount::from(10u8)
bt.subtract_with_minimum(
&addr,
&TokenAmount::from_atto(10u8),
&TokenAmount::from_atto(60u8)
)
.unwrap(),
TokenAmount::from_atto(10u8)
);
assert_eq!(bt.get(&addr).unwrap(), TokenAmount::from(60u8));
assert_eq!(bt.get(&addr).unwrap(), TokenAmount::from_atto(60u8));

// Test must subtract success
bt.must_subtract(&addr, &TokenAmount::from(10u8)).unwrap();
assert_eq!(bt.get(&addr).unwrap(), TokenAmount::from(50u8));
bt.must_subtract(&addr, &TokenAmount::from_atto(10u8)).unwrap();
assert_eq!(bt.get(&addr).unwrap(), TokenAmount::from_atto(50u8));

// Test subtracting more than available
assert!(bt.must_subtract(&addr, &TokenAmount::from(100u8)).is_err());
assert!(bt.must_subtract(&addr, &TokenAmount::from_atto(100u8)).is_err());
}
}
4 changes: 0 additions & 4 deletions actors/market/src/deal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use fil_actors_runtime::DealWeight;
use fvm_ipld_encoding::tuple::*;
use fvm_ipld_encoding::{BytesSer, Cbor};
use fvm_shared::address::Address;
use fvm_shared::bigint::bigint_ser;
use fvm_shared::clock::ChainEpoch;
use fvm_shared::commcid::{FIL_COMMITMENT_UNSEALED, SHA2_256_TRUNC254_PADDED};
use fvm_shared::crypto::signature::Signature;
Expand Down Expand Up @@ -108,12 +107,9 @@ pub struct DealProposal {
// otherwise it is invalid.
pub start_epoch: ChainEpoch,
pub end_epoch: ChainEpoch,
#[serde(with = "bigint_ser")]
pub storage_price_per_epoch: TokenAmount,

#[serde(with = "bigint_ser")]
pub provider_collateral: TokenAmount,
#[serde(with = "bigint_ser")]
pub client_collateral: TokenAmount,
}

Expand Down
1 change: 0 additions & 1 deletion actors/market/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ pub mod power {
pub raw_byte_power: StoragePower,
#[serde(with = "bigint_ser")]
pub quality_adj_power: StoragePower,
#[serde(with = "bigint_ser")]
pub pledge_collateral: TokenAmount,
pub quality_adj_power_smoothed: FilterEstimate,
}
Expand Down
Loading

0 comments on commit 2a8d3d5

Please sign in to comment.