Skip to content

Commit

Permalink
FIP-0050: API between user-programmed actors and built-in actors (fil…
Browse files Browse the repository at this point in the history
…ecoin-project#1004)

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

* Export stable methods for public access (filecoin-project#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 (filecoin-project#809)

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

* Power actor: Add exported getters for raw power (filecoin-project#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 (filecoin-project#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 (filecoin-project#818)

* Call exported authenticate method from PSD (filecoin-project#829)

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

* Drop CALLER_TYPES_SIGNABLE and signable caller validation (filecoin-project#821)

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

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

* Market actor: Export getter for deal total price

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

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

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

* Address review

* Address review

* Account actor: Deprecate AuthenticateMessage (filecoin-project#856)

* Market actor: Export PublishStorageDeals (filecoin-project#857)

* Miner: Export several more methods (filecoin-project#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 (filecoin-project#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 (filecoin-project#873)

* Verifreg: Rename AddVerifierClientParams to AddVerifiedClientParams

* Verifreg: Export AddVerifiedClient and GetClaims

* Datacap actor: Modify exported methods (filecoin-project#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 (filecoin-project#910)

* Miner: Export method to GetPendingOwner

* MarketNotifyDeal (filecoin-project#944)

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

* Verifreg: Call AuthenticateMessage instead of validating siggys

* Multisig: Do not export any functionality (filecoin-project#967)

* use const for EX_DEAL_EXPIRED (filecoin-project#954)

* Address review

Co-authored-by: Alex <[email protected]>
Co-authored-by: ZenGround0 <[email protected]>
Co-authored-by: zenground0 <[email protected]>
Co-authored-by: Shashank <[email protected]>
  • Loading branch information
5 people authored and shamb0 committed Jan 31, 2023
1 parent aa083b4 commit c7f4279
Show file tree
Hide file tree
Showing 53 changed files with 408 additions and 489 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions actors/account/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use num_traits::FromPrimitive;
use crate::types::AuthenticateMessageParams;
use fil_actors_runtime::builtin::singletons::SYSTEM_ACTOR_ADDR;
use fil_actors_runtime::runtime::{ActorCode, Runtime};
use fil_actors_runtime::{actor_dispatch, ActorDowncast};
use fil_actors_runtime::{actor_dispatch, restrict_internal_api, ActorDowncast};
use fil_actors_runtime::{actor_error, ActorError};

pub use self::state::State;
Expand Down Expand Up @@ -106,7 +106,7 @@ impl ActorCode for Actor {
actor_dispatch! {
Constructor => constructor,
PubkeyAddress => pubkey_address,
AuthenticateMessage => authenticate_message,
AuthenticateMessageExported => authenticate_message,
UniversalReceiverHook => universal_receiver_hook,
}
}
15 changes: 12 additions & 3 deletions actors/account/tests/account_actor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,11 @@ fn authenticate_message() {

let addr = Address::new_secp256k1(&[2; fvm_shared::address::SECP_PUB_LEN]).unwrap();
rt.expect_validate_caller_addr(vec![SYSTEM_ACTOR_ADDR]);

rt.call::<AccountActor>(1, IpldBlock::serialize_cbor(&addr).unwrap()).unwrap();
rt.call::<AccountActor>(
Method::Constructor as MethodNum,
IpldBlock::serialize_cbor(&addr).unwrap(),
)
.unwrap();

let state: State = rt.get_state();
assert_eq!(state.address, addr);
Expand All @@ -113,7 +116,13 @@ fn authenticate_message() {
plaintext: vec![],
result: Ok(()),
});
assert!(rt.call::<AccountActor>(3, params.clone()).unwrap().is_none());

assert!(rt
.call::<AccountActor>(Method::AuthenticateMessageExported as MethodNum, params.clone())
.unwrap()
.is_none());

rt.verify();

// Invalid signature
rt.expect_validate_caller_any();
Expand Down
4 changes: 3 additions & 1 deletion actors/cron/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// SPDX-License-Identifier: Apache-2.0, MIT

use fil_actors_runtime::runtime::{ActorCode, Runtime};
use fil_actors_runtime::{actor_dispatch, actor_error, ActorError, SYSTEM_ACTOR_ADDR};
use fil_actors_runtime::{
actor_dispatch, actor_error, restrict_internal_api, ActorError, SYSTEM_ACTOR_ADDR,
};

use fvm_ipld_encoding::tuple::*;
use fvm_shared::econ::TokenAmount;
Expand Down
39 changes: 23 additions & 16 deletions actors/datacap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use num_traits::{FromPrimitive, Zero};

use fil_actors_runtime::runtime::{ActorCode, Runtime};
use fil_actors_runtime::{
actor_dispatch, actor_error, ActorContext, ActorError, AsActorError, SYSTEM_ACTOR_ADDR,
actor_dispatch, actor_error, restrict_internal_api, ActorContext, ActorError, AsActorError,
SYSTEM_ACTOR_ADDR,
};
use fvm_ipld_encoding::ipld_block::IpldBlock;

Expand Down Expand Up @@ -107,6 +108,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 @@ -115,7 +121,7 @@ impl Actor {
Ok(token.total_supply())
}

pub fn balance_of(rt: &mut impl Runtime, params: Address) -> Result<TokenAmount, ActorError> {
pub fn balance(rt: &mut impl Runtime, params: 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 @@ -457,19 +463,20 @@ impl ActorCode for Actor {
type Methods = Method;
actor_dispatch! {
Constructor => constructor,
Mint => mint,
Destroy => destroy,
Name => name,
Symbol => symbol,
TotalSupply => total_supply,
BalanceOf => balance_of,
Transfer => transfer,
TransferFrom => transfer_from,
IncreaseAllowance => increase_allowance,
DecreaseAllowance => decrease_allowance,
RevokeAllowance => revoke_allowance,
Burn => burn,
BurnFrom => burn_from,
Allowance => allowance,
MintExported => mint,
DestroyExported => destroy,
NameExported => name,
SymbolExported => symbol,
GranularityExported => granularity,
TotalSupplyExported => total_supply,
BalanceExported => balance,
TransferExported => transfer,
TransferFromExported => transfer_from,
IncreaseAllowanceExported => increase_allowance,
DecreaseAllowanceExported => decrease_allowance,
RevokeAllowanceExported => revoke_allowance,
BurnExported => burn,
BurnFromExported => burn_from,
AllowanceExported => allowance,
}
}
6 changes: 6 additions & 0 deletions actors/datacap/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ pub struct DestroyParams {
#[serde(with = "bigint_ser")]
pub amount: BigInt,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
#[serde(transparent)]
pub struct GranularityReturn {
pub granularity: u64,
}
12 changes: 6 additions & 6 deletions actors/datacap/tests/datacap_actor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ 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]
Expand All @@ -30,7 +29,8 @@ mod construction {

rt.expect_validate_caller_any();
let ret: GranularityReturn = rt
.call::<Actor>(Method::GranularityExported as MethodNum, &RawBytes::default())
.call::<Actor>(Method::GranularityExported as MethodNum, None)
.unwrap()
.unwrap()
.deserialize()
.unwrap();
Expand Down Expand Up @@ -83,13 +83,13 @@ 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);
}
Expand All @@ -106,7 +106,7 @@ mod mint {
ExitCode::USR_FORBIDDEN,
"caller address",
rt.call::<Actor>(
Method::Mint as MethodNum,
Method::MintExported as MethodNum,
IpldBlock::serialize_cbor(&params).unwrap(),
),
);
Expand Down Expand Up @@ -249,7 +249,7 @@ mod destroy {
ExitCode::USR_FORBIDDEN,
"caller address",
rt.call::<Actor>(
Method::Destroy as MethodNum,
Method::DestroyExported as MethodNum,
IpldBlock::serialize_cbor(&params).unwrap(),
),
);
Expand Down
11 changes: 6 additions & 5 deletions actors/datacap/tests/harness/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ 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,
Method::MintExported as MethodNum,
IpldBlock::serialize_cbor(&params).unwrap(),
)?;

Expand All @@ -116,7 +116,7 @@ impl Harness {

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

Expand Down Expand Up @@ -162,7 +162,7 @@ impl Harness {

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

Expand Down Expand Up @@ -210,7 +210,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,
IpldBlock::serialize_cbor(&params).unwrap(),
)?;

Expand All @@ -229,9 +229,10 @@ impl Harness {
let ret = rt
.call::<DataCapActor>(
Method::BalanceExported as MethodNum,
&serialize(&address, "params").unwrap(),
IpldBlock::serialize_cbor(&address).unwrap(),
)
.unwrap()
.unwrap()
.deserialize()
.unwrap();
rt.verify();
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 = "10.0.0-alpha.1", path = "../../runtime" }
frc42_dispatch = "1.0.0"
frc42_dispatch = "3.0.0"
fvm_shared = { version = "2.0.0-alpha.2", default-features = false }
fvm_ipld_hamt = "0.5.1"
serde = { version = "1.0.136", features = ["derive"] }
Expand Down
3 changes: 2 additions & 1 deletion actors/init/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use fil_actors_runtime::runtime::builtins::Type;
use fil_actors_runtime::runtime::{ActorCode, Runtime};

use fil_actors_runtime::{
actor_dispatch, actor_error, ActorContext, ActorError, SYSTEM_ACTOR_ADDR,
actor_dispatch, actor_error, restrict_internal_api, ActorContext, ActorError, SYSTEM_ACTOR_ADDR,
};
use fvm_shared::address::Address;
use fvm_shared::{ActorID, MethodNum, METHOD_CONSTRUCTOR};
Expand Down Expand Up @@ -103,6 +103,7 @@ impl ActorCode for Actor {
actor_dispatch! {
Constructor => constructor,
Exec => exec,
ExecExported => exec,
}
}

Expand Down
14 changes: 9 additions & 5 deletions actors/init/tests/init_actor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ fn exec_restricted_correctly() {
"must be built-in",
rt.call::<InitActor>(
Method::Exec as MethodNum,
&serialize(&exec_params, "params").unwrap(),
IpldBlock::serialize_cbor(&exec_params).unwrap(),
),
);

Expand All @@ -335,18 +335,22 @@ fn exec_restricted_correctly() {
rt.expect_send(
expected_id_addr,
METHOD_CONSTRUCTOR,
RawBytes::serialize(&fake_constructor_params).unwrap(),
IpldBlock::serialize_cbor(&fake_constructor_params).unwrap(),
TokenAmount::zero(),
RawBytes::default(),
None,
ExitCode::OK,
);

rt.expect_validate_caller_any();

let ret = rt
.call::<InitActor>(Method::ExecExported as u64, &RawBytes::serialize(&exec_params).unwrap())
.call::<InitActor>(
Method::ExecExported as u64,
IpldBlock::serialize_cbor(&exec_params).unwrap(),
)
.unwrap()
.unwrap();
let exec_ret: ExecReturn = RawBytes::deserialize(&ret).unwrap();
let exec_ret: ExecReturn = ret.deserialize().unwrap();
assert_eq!(unique_address, exec_ret.robust_address, "Robust address does not macth");
assert_eq!(expected_id_addr, exec_ret.id_address, "Id address does not match");
check_state(&rt);
Expand Down
1 change: 1 addition & 0 deletions actors/market/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ fil_actors_runtime = { version = "10.0.0-alpha.1", path = "../../runtime"}

anyhow = "1.0.65"
cid = { version = "0.8.3", default-features = false, features = ["serde-codec"] }
frc42_dispatch = "3.0.0"
frc46_token = "3.1.0"
fvm_ipld_bitfield = "0.5.2"
fvm_ipld_blockstore = "0.1.1"
Expand Down
16 changes: 10 additions & 6 deletions actors/market/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::collections::{BTreeMap, BTreeSet};

use cid::multihash::{Code, MultihashDigest, MultihashGeneric};
use cid::Cid;
use fil_actors_runtime::{extract_send_result, FIRST_ACTOR_SPECIFIC_EXIT_CODE};
use frc46_token::token::types::{BalanceReturn, TransferFromParams, TransferFromReturn};
use fil_actors_runtime::{restrict_internal_api, FIRST_ACTOR_SPECIFIC_EXIT_CODE};
use frc46_token::token::types::{TransferFromParams, TransferFromReturn};
use fvm_ipld_bitfield::BitField;
use fvm_ipld_blockstore::Blockstore;
use fvm_ipld_hamt::BytesKey;
Expand Down Expand Up @@ -316,7 +316,6 @@ impl Actor {
// Must happen after signature verification and before taking cid.
deal.proposal.provider = Address::new_id(provider_id);
deal.proposal.client = Address::new_id(client_id);

let serialized_proposal = serialize(&deal.proposal, "normalized deal proposal")
.context_code(ExitCode::USR_SERIALIZATION, "failed to serialize")?;
let pcid = rt_serialized_deal_cid(rt, &serialized_proposal).map_err(
Expand Down Expand Up @@ -361,7 +360,12 @@ impl Actor {
total_provider_lockup = provider_lockup;
total_client_lockup.insert(client_id, client_lockup);
proposal_cid_lookup.insert(pcid);
valid_deals.push(ValidDeal { proposal: deal.proposal, serialized_proposal, cid: pcid });
valid_deals.push(ValidDeal {
proposal: deal.proposal,
serialized_proposal,
cid: pcid,
allocation: allocation_id,
});
valid_input_bf.set(di as u64)
}

Expand Down Expand Up @@ -446,15 +450,15 @@ impl Actor {

// notify clients ignoring any errors
for (i, valid_deal) in valid_deals.iter().enumerate() {
_ = extract_send_result(rt.send_simple(
_ = rt.send(
&valid_deal.proposal.client,
MARKET_NOTIFY_DEAL_METHOD,
IpldBlock::serialize_cbor(&MarketNotifyDealParams {
proposal: valid_deal.serialized_proposal.to_vec(),
deal_id: new_deal_ids[i],
})?,
TokenAmount::zero(),
));
);
}

Ok(PublishStorageDealsReturn { ids: new_deal_ids, valid_deals: valid_input_bf })
Expand Down
4 changes: 2 additions & 2 deletions actors/market/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct WithdrawBalanceParams {
pub amount: TokenAmount,
}

#[derive(Serialize_tuple, Deserialize_tuple)]
#[derive(Serialize_tuple, Deserialize_tuple, Debug, Clone, Eq, PartialEq)]
#[serde(transparent)]
pub struct WithdrawBalanceReturn {
pub amount_withdrawn: TokenAmount,
Expand All @@ -52,7 +52,7 @@ pub struct PublishStorageDealsParams {
pub deals: Vec<ClientDealProposal>,
}

#[derive(Serialize_tuple, Deserialize_tuple, Debug)]
#[derive(Serialize_tuple, Deserialize_tuple, Debug, Clone, PartialEq)] // Add Eq when BitField does
pub struct PublishStorageDealsReturn {
pub ids: Vec<DealID>,
pub valid_deals: BitField,
Expand Down
Loading

0 comments on commit c7f4279

Please sign in to comment.