Skip to content

Merge master and integration/builtin-api into next #918

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

Merged
merged 20 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
dc8077c
Remove the market actor state mutation pattern (#734)
shamb0 Dec 5, 2022
cb64ec0
Proof of concept exported API for Account actor (#797)
anorth Nov 6, 2022
09a067b
Export stable methods for public access (#807)
arajasek Nov 7, 2022
f9452de
Restrict internal APIs of all actors (#809)
arajasek Nov 7, 2022
c5f05f2
Exported API method for market actor escrow/locked balance (#812)
anorth Nov 8, 2022
0ee2340
Power actor: Add exported getters for raw power (#810)
arajasek Nov 9, 2022
ae81212
Built-in market API for deal proposal metadata (#818)
anorth Nov 9, 2022
7594b3c
Call exported authenticate method from PSD (#829)
ZenGround0 Nov 11, 2022
3dafa6e
Drop CALLER_TYPES_SIGNABLE and signable caller validation (#821)
arajasek Nov 15, 2022
05f7b96
Market actor: Minor improvements to two exported getters (#826)
arajasek Nov 15, 2022
969f086
Exported API for market deal activation state (#819)
anorth Nov 15, 2022
5370afd
Paych actor: Drop account req, use AuthenticateMessage to verify sigs…
arajasek Nov 16, 2022
456c44d
Account actor: Deprecate AuthenticateMessage (#856)
arajasek Nov 17, 2022
069a4d5
Market actor: Export PublishStorageDeals (#857)
arajasek Nov 19, 2022
117a539
Miner: Export several more methods (#863)
arajasek Nov 22, 2022
325a499
Power actor: Export methods to CreateMiner and get miner counts (#868)
arajasek Nov 23, 2022
532757d
Verifreg: Export AddVerifiedClient and GetClaims (#873)
arajasek Nov 28, 2022
d41d29a
Datacap actor: Modify exported methods (#909)
arajasek Dec 5, 2022
6f734d8
fix: comments on newly exported methods (#910)
arajasek Dec 5, 2022
8dfff12
Merge branch 'integration/builtin-api' into asr/merge-apis-into-next
arajasek Dec 7, 2022
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
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