Skip to content

Commit

Permalink
Merge master and integration/builtin-api into next (#918)
Browse files Browse the repository at this point in the history
* Remove the market actor state mutation pattern (#734)

Fixes #656

* Proof of concept exported API for Account actor (#797)

* Export stable methods for public access (#807)

* Export Datacap Actor methods

* Export Init Actor methods

* Export Market Actor methods

* Export Miner Actor methods

* Export Multisig Actor methods

* Export Verifreg Actor methods

* Address review

* Restrict internal APIs of all actors (#809)

* Exported API method for market actor escrow/locked balance (#812)

* Power actor: Add exported getters for raw power (#810)

* Power actor: Add exported getters for raw power

* FRC-XXXX is FRC-0042

* Power actor: network_raw_power: Return this_epoch_raw_byte_power

* Power actor: miner_raw_power: Return whether above consensus min power

* Power actor: types: serialize one-element structs transparently

* Address review

* Miner actor: Add exported getters for info and monies (#811)

* Miner actor: Add exported getters for info and monies

* Tweak comment

* Miner actor: Replace GetWorker and GetControls with IsControllingAddress

* Miner actor: Add exported GetAvailableBalance

* Miner actor: Add exported GetVestingFunds

* Miner actor: Remove exported monies getters

* Miner actor: types: serialize one-element structs transparently

* Address review

* Address review

* Built-in market API for deal proposal metadata (#818)

* Call exported authenticate method from PSD (#829)


Co-authored-by: zenground0 <[email protected]>

* Drop CALLER_TYPES_SIGNABLE and signable caller validation (#821)

* Market actor: Minor improvements to two exported getters (#826)

* Market actor: GetDealTermExported: Return (start_epoch, duration)

* Market actor: Export getter for deal total price

* Exported API for market deal activation state (#819)

* Paych actor: Drop account req, use AuthenticateMessage to verify sigs (#824)

* Paych actor: Drop account req, use AuthenticateMessage to verify sigs

* Address review

* Address review

* Account actor: Deprecate AuthenticateMessage (#856)

* Market actor: Export PublishStorageDeals (#857)

* Miner: Export several more methods (#863)

* Miner: Export ChangeWorkerAddress

* Miner: Export ChangePeerID

* Miner: Export WithdrawBalance

* Miner: Export ChangeMultiaddrs

* Miner: Export ConfirmUpdateWorkerKey

* Miner: Export RepayDebt

* Miner: Export ChangeOwnerAddress

* Miner: Add exported getters for PeerID & multiaddrs

* Miner: Refactor: Rename ConfirmUpdateWorkerKey to ConfirmChangeWorkerAddress

* Power actor: Export methods to CreateMiner and get miner counts (#868)

* Power: Export CreateMiner

* Power Actor: Export MinerCount and MinerConsensusCount

* Update actors/power/src/lib.rs

Co-authored-by: Alex <[email protected]>

Co-authored-by: Alex <[email protected]>

* Verifreg: Export AddVerifiedClient and GetClaims (#873)

* Verifreg: Rename AddVerifierClientParams to AddVerifiedClientParams

* Verifreg: Export AddVerifiedClient and GetClaims

* Datacap actor: Modify exported methods (#909)

* Datacap: Export Mint and Destroy

* Datacap actor: Deprecate all internal methods

* Datacap actor: Rename BalanceOf to Balance

* Datacap actor: Add Granularity method

* fix: comments on newly exported methods (#910)

Co-authored-by: RK <[email protected]>
Co-authored-by: Alex <[email protected]>
Co-authored-by: ZenGround0 <[email protected]>
Co-authored-by: zenground0 <[email protected]>
  • Loading branch information
5 people authored Dec 7, 2022
1 parent 0aa4a4c commit 3c417b8
Show file tree
Hide file tree
Showing 15 changed files with 881 additions and 844 deletions.
77 changes: 44 additions & 33 deletions actors/datacap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,29 @@ lazy_static! {
#[repr(u64)]
pub enum Method {
Constructor = METHOD_CONSTRUCTOR,
// Non-standard.
Mint = 2,
Destroy = 3,
// Static method numbers for token standard methods, for private use.
Name = 10,
Symbol = 11,
TotalSupply = 12,
BalanceOf = 13,
Transfer = 14,
TransferFrom = 15,
IncreaseAllowance = 16,
DecreaseAllowance = 17,
RevokeAllowance = 18,
Burn = 19,
BurnFrom = 20,
Allowance = 21,
// Deprecated in v10
// Mint = 2,
// Destroy = 3,
// Name = 10,
// Symbol = 11,
// TotalSupply = 12,
// BalanceOf = 13,
// Transfer = 14,
// TransferFrom = 15,
// IncreaseAllowance = 16,
// DecreaseAllowance = 17,
// RevokeAllowance = 18,
// Burn = 19,
// BurnFrom = 20,
// Allowance = 21,
// Method numbers derived from FRC-0042 standards
MintExported = frc42_dispatch::method_hash!("Mint"),
DestroyExported = frc42_dispatch::method_hash!("Destroy"),
NameExported = frc42_dispatch::method_hash!("Name"),
SymbolExported = frc42_dispatch::method_hash!("Symbol"),
GranularityExported = frc42_dispatch::method_hash!("GranularityExported"),
TotalSupplyExported = frc42_dispatch::method_hash!("TotalSupply"),
BalanceOfExported = frc42_dispatch::method_hash!("BalanceOf"),
BalanceExported = frc42_dispatch::method_hash!("Balance"),
TransferExported = frc42_dispatch::method_hash!("Transfer"),
TransferFromExported = frc42_dispatch::method_hash!("TransferFrom"),
IncreaseAllowanceExported = frc42_dispatch::method_hash!("IncreaseAllowance"),
Expand Down Expand Up @@ -108,6 +110,11 @@ impl Actor {
Ok("DCAP".to_string())
}

pub fn granularity(rt: &mut impl Runtime) -> Result<GranularityReturn, ActorError> {
rt.validate_immediate_caller_accept_any()?;
Ok(GranularityReturn { granularity: DATACAP_GRANULARITY })
}

pub fn total_supply(rt: &mut impl Runtime, _: ()) -> Result<TokenAmount, ActorError> {
rt.validate_immediate_caller_accept_any()?;
let mut st: State = rt.state()?;
Expand All @@ -116,7 +123,7 @@ impl Actor {
Ok(token.total_supply())
}

pub fn balance_of(rt: &mut impl Runtime, address: Address) -> Result<TokenAmount, ActorError> {
pub fn balance(rt: &mut impl Runtime, address: Address) -> Result<TokenAmount, ActorError> {
// NOTE: mutability and method caller here are awkward for a read-only call
rt.validate_immediate_caller_accept_any()?;
let mut st: State = rt.state()?;
Expand Down Expand Up @@ -477,59 +484,63 @@ impl ActorCode for Actor {
Self::constructor(rt, cbor::deserialize_params(params)?)?;
Ok(RawBytes::default())
}
Some(Method::Mint) => {
Some(Method::MintExported) => {
let ret = Self::mint(rt, cbor::deserialize_params(params)?)?;
serialize(&ret, "mint result")
}
Some(Method::Destroy) => {
Some(Method::DestroyExported) => {
let ret = Self::destroy(rt, cbor::deserialize_params(params)?)?;
serialize(&ret, "destroy result")
}
Some(Method::Name) | Some(Method::NameExported) => {
Some(Method::NameExported) => {
let ret = Self::name(rt)?;
serialize(&ret, "name result")
}
Some(Method::Symbol) | Some(Method::SymbolExported) => {
Some(Method::SymbolExported) => {
let ret = Self::symbol(rt)?;
serialize(&ret, "symbol result")
}
Some(Method::TotalSupply) | Some(Method::TotalSupplyExported) => {
Some(Method::GranularityExported) => {
let ret = Self::granularity(rt)?;
serialize(&ret, "granularity result")
}
Some(Method::TotalSupplyExported) => {
let ret = Self::total_supply(rt, cbor::deserialize_params(params)?)?;
serialize(&ret, "total_supply result")
}
Some(Method::BalanceOf) | Some(Method::BalanceOfExported) => {
let ret = Self::balance_of(rt, cbor::deserialize_params(params)?)?;
Some(Method::BalanceExported) => {
let ret = Self::balance(rt, cbor::deserialize_params(params)?)?;
serialize(&ret, "balance_of result")
}
Some(Method::Transfer) | Some(Method::TransferExported) => {
Some(Method::TransferExported) => {
let ret = Self::transfer(rt, cbor::deserialize_params(params)?)?;
serialize(&ret, "transfer result")
}
Some(Method::TransferFrom) | Some(Method::TransferFromExported) => {
Some(Method::TransferFromExported) => {
let ret = Self::transfer_from(rt, cbor::deserialize_params(params)?)?;
serialize(&ret, "transfer_from result")
}
Some(Method::IncreaseAllowance) | Some(Method::IncreaseAllowanceExported) => {
Some(Method::IncreaseAllowanceExported) => {
let ret = Self::increase_allowance(rt, cbor::deserialize_params(params)?)?;
serialize(&ret, "increase_allowance result")
}
Some(Method::DecreaseAllowance) | Some(Method::DecreaseAllowanceExported) => {
Some(Method::DecreaseAllowanceExported) => {
let ret = Self::decrease_allowance(rt, cbor::deserialize_params(params)?)?;
serialize(&ret, "decrease_allowance result")
}
Some(Method::RevokeAllowance) | Some(Method::RevokeAllowanceExported) => {
Some(Method::RevokeAllowanceExported) => {
Self::revoke_allowance(rt, cbor::deserialize_params(params)?)?;
Ok(RawBytes::default())
}
Some(Method::Burn) | Some(Method::BurnExported) => {
Some(Method::BurnExported) => {
let ret = Self::burn(rt, cbor::deserialize_params(params)?)?;
serialize(&ret, "burn result")
}
Some(Method::BurnFrom) | Some(Method::BurnFromExported) => {
Some(Method::BurnFromExported) => {
let ret = Self::burn_from(rt, cbor::deserialize_params(params)?)?;
serialize(&ret, "burn_from result")
}
Some(Method::Allowance) | Some(Method::AllowanceExported) => {
Some(Method::AllowanceExported) => {
let ret = Self::allowance(rt, cbor::deserialize_params(params)?)?;
serialize(&ret, "allowance result")
}
Expand Down
6 changes: 6 additions & 0 deletions actors/datacap/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ pub struct DestroyParams {
}

impl Cbor for DestroyParams {}

#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
#[serde(transparent)]
pub struct GranularityReturn {
pub granularity: u64,
}
65 changes: 24 additions & 41 deletions actors/datacap/tests/datacap_actor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,26 @@ lazy_static! {

mod construction {
use crate::*;
use fil_actor_datacap::{Actor, GranularityReturn, Method, DATACAP_GRANULARITY};
use fil_actors_runtime::VERIFIED_REGISTRY_ACTOR_ADDR;
use fvm_ipld_encoding::RawBytes;
use fvm_shared::MethodNum;

#[test]
fn construct_with_verified() {
let mut rt = new_runtime();
let h = Harness { governor: VERIFIED_REGISTRY_ACTOR_ADDR };
h.construct_and_verify(&mut rt, &h.governor);
h.check_state(&rt);

rt.expect_validate_caller_any();
let ret: GranularityReturn = rt
.call::<Actor>(Method::GranularityExported as MethodNum, &RawBytes::default())
.unwrap()
.deserialize()
.unwrap();
rt.verify();
assert_eq!(ret.granularity, DATACAP_GRANULARITY)
}
}

Expand All @@ -34,9 +46,7 @@ mod mint {

use fil_actor_datacap::{Actor, Method, MintParams, INFINITE_ALLOWANCE};
use fil_actors_runtime::cbor::serialize;
use fil_actors_runtime::test_utils::{
expect_abort_contains_message, make_identity_cid, MARKET_ACTOR_CODE_ID,
};
use fil_actors_runtime::test_utils::{expect_abort_contains_message, MARKET_ACTOR_CODE_ID};
use fil_actors_runtime::{STORAGE_MARKET_ACTOR_ADDR, VERIFIED_REGISTRY_ACTOR_ADDR};
use fvm_ipld_encoding::RawBytes;
use std::ops::Sub;
Expand All @@ -53,32 +63,17 @@ mod mint {
assert_eq!(amt, ret.supply);
assert_eq!(amt, ret.balance);
assert_eq!(amt, h.get_supply(&rt));
assert_eq!(amt, h.get_balance(&rt, &*ALICE));
assert_eq!(amt, h.get_balance(&mut rt, &*ALICE));

let ret = h.mint(&mut rt, &*BOB, &amt, vec![]).unwrap();
assert_eq!(&amt * 2, ret.supply);
assert_eq!(amt, ret.balance);
assert_eq!(&amt * 2, h.get_supply(&rt));
assert_eq!(amt, h.get_balance(&rt, &*BOB));
assert_eq!(amt, h.get_balance(&mut rt, &*BOB));

h.check_state(&rt);
}

#[test]
fn requires_builtin_caller() {
let (mut rt, h) = make_harness();
let amt = TokenAmount::from_whole(1);
let params = MintParams { to: *ALICE, amount: amt, operators: vec![] };

rt.set_caller(make_identity_cid(b"1234"), Address::new_id(1000));
expect_abort_contains_message(
ExitCode::USR_FORBIDDEN,
"must be built-in",
rt.call::<Actor>(Method::Mint as MethodNum, &serialize(&params, "params").unwrap()),
);
h.check_state(&rt);
}

#[test]
fn requires_verifreg_caller() {
let (mut rt, h) = make_harness();
Expand All @@ -90,7 +85,10 @@ mod mint {
expect_abort_contains_message(
ExitCode::USR_FORBIDDEN,
"caller address",
rt.call::<Actor>(Method::Mint as MethodNum, &serialize(&params, "params").unwrap()),
rt.call::<Actor>(
Method::MintExported as MethodNum,
&serialize(&params, "params").unwrap(),
),
);
h.check_state(&rt);
}
Expand Down Expand Up @@ -206,33 +204,15 @@ mod transfer {
mod destroy {
use crate::{make_harness, ALICE, BOB};
use fil_actor_datacap::DestroyParams;
use fil_actors_runtime::test_utils::{
expect_abort_contains_message, make_identity_cid, ACCOUNT_ACTOR_CODE_ID,
};
use fil_actors_runtime::test_utils::{expect_abort_contains_message, ACCOUNT_ACTOR_CODE_ID};
use fil_actors_runtime::VERIFIED_REGISTRY_ACTOR_ADDR;
use fvm_shared::address::Address;
use fvm_shared::econ::TokenAmount;
use fvm_shared::MethodNum;

use fil_actor_datacap::{Actor, Method};
use fil_actors_runtime::cbor::serialize;
use fvm_shared::error::ExitCode;

#[test]
fn requires_builtin_caller() {
let (mut rt, h) = make_harness();
let amt = TokenAmount::from_whole(1);
let params = DestroyParams { owner: *ALICE, amount: amt };

rt.set_caller(make_identity_cid(b"1234"), Address::new_id(1000));
expect_abort_contains_message(
ExitCode::USR_FORBIDDEN,
"must be built-in",
rt.call::<Actor>(Method::Destroy as MethodNum, &serialize(&params, "params").unwrap()),
);
h.check_state(&rt);
}

#[test]
fn only_governor_allowed() {
let (mut rt, h) = make_harness();
Expand All @@ -248,7 +228,10 @@ mod destroy {
expect_abort_contains_message(
ExitCode::USR_FORBIDDEN,
"caller address",
rt.call::<Actor>(Method::Destroy as MethodNum, &serialize(&params, "params").unwrap()),
rt.call::<Actor>(
Method::DestroyExported as MethodNum,
&serialize(&params, "params").unwrap(),
),
);

// Destroying from 0 allowance having governor works
Expand Down
34 changes: 25 additions & 9 deletions actors/datacap/tests/harness/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ impl Harness {

let params = MintParams { to: *to, amount: amount.clone(), operators };
rt.set_caller(*VERIFREG_ACTOR_CODE_ID, VERIFIED_REGISTRY_ACTOR_ADDR);
let ret =
rt.call::<DataCapActor>(Method::Mint as MethodNum, &serialize(&params, "params")?)?;
let ret = rt.call::<DataCapActor>(
Method::MintExported as MethodNum,
&serialize(&params, "params")?,
)?;

rt.verify();
Ok(ret.deserialize().unwrap())
Expand All @@ -111,8 +113,10 @@ impl Harness {
let params = DestroyParams { owner: *owner, amount: amount.clone() };

rt.set_caller(*VERIFREG_ACTOR_CODE_ID, VERIFIED_REGISTRY_ACTOR_ADDR);
let ret =
rt.call::<DataCapActor>(Method::Destroy as MethodNum, &serialize(&params, "params")?)?;
let ret = rt.call::<DataCapActor>(
Method::DestroyExported as MethodNum,
&serialize(&params, "params")?,
)?;

rt.verify();
Ok(ret.deserialize().unwrap())
Expand Down Expand Up @@ -155,8 +159,10 @@ impl Harness {
);

let params = TransferParams { to: *to, amount: amount.clone(), operator_data };
let ret =
rt.call::<DataCapActor>(Method::Transfer as MethodNum, &serialize(&params, "params")?)?;
let ret = rt.call::<DataCapActor>(
Method::TransferExported as MethodNum,
&serialize(&params, "params")?,
)?;

rt.verify();
Ok(ret.deserialize().unwrap())
Expand Down Expand Up @@ -202,7 +208,7 @@ impl Harness {
let params =
TransferFromParams { to: *to, from: *from, amount: amount.clone(), operator_data };
let ret = rt.call::<DataCapActor>(
Method::TransferFrom as MethodNum,
Method::TransferFromExported as MethodNum,
&serialize(&params, "params")?,
)?;

Expand All @@ -216,8 +222,18 @@ impl Harness {
}

// Reads a balance from state directly.
pub fn get_balance(&self, rt: &MockRuntime, address: &Address) -> TokenAmount {
rt.get_state::<State>().token.get_balance(rt.store(), address.id().unwrap()).unwrap()
pub fn get_balance(&self, rt: &mut MockRuntime, address: &Address) -> TokenAmount {
rt.expect_validate_caller_any();
let ret = rt
.call::<DataCapActor>(
Method::BalanceExported as MethodNum,
&serialize(&address, "params").unwrap(),
)
.unwrap()
.deserialize()
.unwrap();
rt.verify();
ret
}

// Reads allowance from state directly
Expand Down
1 change: 1 addition & 0 deletions actors/init/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub enum Method {
InstallCode = 4,
// Method numbers derived from FRC-0042 standards
ExecExported = frc42_dispatch::method_hash!("Exec"),
// TODO: Export new methods if appropriate
}

/// Init actor
Expand Down
2 changes: 1 addition & 1 deletion actors/market/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub mod verifreg {
}

pub mod datacap {
pub const TRANSFER_FROM_METHOD: u64 = 15;
pub const TRANSFER_FROM_METHOD: u64 = frc42_dispatch::method_hash!("TransferFrom");
}

pub mod reward {
Expand Down
Loading

0 comments on commit 3c417b8

Please sign in to comment.