Skip to content

Commit d79c5ec

Browse files
V14 Builtin Actors (#311)
Co-authored-by: Hubert Bugaj <lesny.rumcajs+github@gmail.com>
1 parent 3ba179e commit d79c5ec

File tree

152 files changed

+20161
-16
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+20161
-16
lines changed

.github/workflows/tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
CC: "sccache clang"
4242
CXX: "sccache clang++"
4343
- name: Run tests
44-
run: cargo test --workspace --all-features --all-targets
44+
run: RUST_MIN_STACK=8388608 cargo test --workspace --all-features --all-targets
4545
env:
4646
CC: "sccache clang"
4747
CXX: "sccache clang++"

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ base64 = "0.22"
4040
bitflags = "2.4.2"
4141
byteorder = "1.4.3"
4242
cid = { version = "0.10", default-features = false, features = ["std"] }
43+
frc42_dispatch = "7.0.0"
4344
frc42_macros = "5"
4445
frc46_token = "11"
4546
fvm_ipld_amt = "0.6.1"

actors/account/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ pub mod v10;
55
pub mod v11;
66
pub mod v12;
77
pub mod v13;
8+
pub mod v14;
89
pub mod v8;
910
pub mod v9;

actors/account/src/v14/mod.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2019-2022 ChainSafe Systems
2+
// SPDX-License-Identifier: Apache-2.0, MIT
3+
4+
use fvm_shared4::METHOD_CONSTRUCTOR;
5+
use num_derive::FromPrimitive;
6+
7+
pub use self::state::State;
8+
pub use types::*;
9+
10+
mod state;
11+
mod types;
12+
13+
/// Account actor methods available
14+
#[derive(FromPrimitive)]
15+
#[repr(u64)]
16+
pub enum Method {
17+
Constructor = METHOD_CONSTRUCTOR,
18+
PubkeyAddress = 2,
19+
// Deprecated in v10
20+
// AuthenticateMessage = 3,
21+
AuthenticateMessageExported = frc42_macros::method_hash!("AuthenticateMessage"),
22+
}

actors/account/src/v14/state.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2019-2022 ChainSafe Systems
2+
// SPDX-License-Identifier: Apache-2.0, MIT
3+
4+
use fvm_ipld_encoding::tuple::*;
5+
use fvm_shared4::address::Address;
6+
7+
/// State includes the address for the actor
8+
#[derive(Serialize_tuple, Deserialize_tuple, Debug, Clone)]
9+
pub struct State {
10+
pub address: Address,
11+
}

actors/account/src/v14/types.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use fvm_ipld_encoding::strict_bytes;
2+
use fvm_ipld_encoding::tuple::*;
3+
use fvm_shared4::address::Address;
4+
5+
#[derive(Debug, Serialize_tuple, Deserialize_tuple)]
6+
#[serde(transparent)]
7+
pub struct ConstructorParams {
8+
pub address: Address,
9+
}
10+
11+
#[derive(Debug, Serialize_tuple, Deserialize_tuple)]
12+
#[serde(transparent)]
13+
pub struct PubkeyAddressReturn {
14+
pub address: Address,
15+
}
16+
17+
#[derive(Debug, Serialize_tuple, Deserialize_tuple)]
18+
pub struct AuthenticateMessageParams {
19+
#[serde(with = "strict_bytes")]
20+
pub signature: Vec<u8>,
21+
#[serde(with = "strict_bytes")]
22+
pub message: Vec<u8>,
23+
}
24+
25+
#[derive(Debug, Serialize_tuple, Deserialize_tuple)]
26+
#[serde(transparent)]
27+
pub struct AuthenticateMessageReturn {
28+
pub authenticated: bool,
29+
}

actors/cron/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ pub mod v10;
55
pub mod v11;
66
pub mod v12;
77
pub mod v13;
8+
pub mod v14;
89
pub mod v8;
910
pub mod v9;

actors/cron/src/v14/mod.rs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2019-2022 ChainSafe Systems
2+
// SPDX-License-Identifier: Apache-2.0, MIT
3+
4+
use fvm_ipld_encoding::tuple::*;
5+
6+
use fvm_shared4::METHOD_CONSTRUCTOR;
7+
use num_derive::FromPrimitive;
8+
9+
pub use self::state::{Entry, State};
10+
11+
mod state;
12+
13+
/// Cron actor methods available
14+
#[derive(FromPrimitive)]
15+
#[repr(u64)]
16+
pub enum Method {
17+
Constructor = METHOD_CONSTRUCTOR,
18+
EpochTick = 2,
19+
}
20+
21+
/// Constructor parameters for Cron actor, contains entries
22+
/// of actors and methods to call on each epoch
23+
#[derive(Default, Debug, Serialize_tuple, Deserialize_tuple)]
24+
pub struct ConstructorParams {
25+
/// Entries is a set of actors (and corresponding methods) to call during EpochTick.
26+
pub entries: Vec<Entry>,
27+
}

actors/cron/src/v14/state.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2019-2022 ChainSafe Systems
2+
// SPDX-License-Identifier: Apache-2.0, MIT
3+
4+
use fvm_ipld_encoding::tuple::*;
5+
use fvm_shared4::address::Address;
6+
use fvm_shared4::MethodNum;
7+
8+
/// Cron actor state which holds entries to call during epoch tick
9+
#[derive(Default, Serialize_tuple, Deserialize_tuple, Clone, Debug)]
10+
pub struct State {
11+
/// Entries is a set of actors (and corresponding methods) to call during EpochTick.
12+
pub entries: Vec<Entry>,
13+
}
14+
15+
#[derive(Clone, PartialEq, Eq, Debug, Serialize_tuple, Deserialize_tuple)]
16+
pub struct Entry {
17+
/// The actor to call (ID address)
18+
pub receiver: Address,
19+
/// The method number to call (must accept empty parameters)
20+
pub method_num: MethodNum,
21+
}

actors/datacap/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ pub mod v10;
55
pub mod v11;
66
pub mod v12;
77
pub mod v13;
8+
pub mod v14;
89
pub mod v9;

actors/datacap/src/v14/mod.rs

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright 2019-2022 ChainSafe Systems
2+
// SPDX-License-Identifier: Apache-2.0, MIT
3+
4+
use frc46_token::token::TOKEN_PRECISION;
5+
use fvm_shared4::bigint::BigInt;
6+
use fvm_shared4::econ::TokenAmount;
7+
use fvm_shared4::METHOD_CONSTRUCTOR;
8+
use lazy_static::lazy_static;
9+
use num_derive::FromPrimitive;
10+
11+
pub use self::state::State;
12+
pub use self::types::*;
13+
14+
mod state;
15+
mod types;
16+
17+
pub const DATACAP_GRANULARITY: u64 = TOKEN_PRECISION;
18+
19+
lazy_static! {
20+
// > 800 EiB
21+
pub static ref INFINITE_ALLOWANCE: TokenAmount = TokenAmount::from_atto(
22+
BigInt::from(TOKEN_PRECISION)
23+
* BigInt::from(1_000_000_000_000_000_000_000_i128)
24+
);
25+
}
26+
27+
/// Datacap actor methods available
28+
#[derive(FromPrimitive)]
29+
#[repr(u64)]
30+
pub enum Method {
31+
Constructor = METHOD_CONSTRUCTOR,
32+
// Deprecated in v10
33+
// Mint = 2,
34+
// Destroy = 3,
35+
// Name = 10,
36+
// Symbol = 11,
37+
// TotalSupply = 12,
38+
// BalanceOf = 13,
39+
// Transfer = 14,
40+
// TransferFrom = 15,
41+
// IncreaseAllowance = 16,
42+
// DecreaseAllowance = 17,
43+
// RevokeAllowance = 18,
44+
// Burn = 19,
45+
// BurnFrom = 20,
46+
// Allowance = 21,
47+
// Method numbers derived from FRC-0042 standards
48+
MintExported = frc42_macros::method_hash!("Mint"),
49+
DestroyExported = frc42_macros::method_hash!("Destroy"),
50+
NameExported = frc42_macros::method_hash!("Name"),
51+
SymbolExported = frc42_macros::method_hash!("Symbol"),
52+
GranularityExported = frc42_macros::method_hash!("Granularity"),
53+
TotalSupplyExported = frc42_macros::method_hash!("TotalSupply"),
54+
BalanceExported = frc42_macros::method_hash!("Balance"),
55+
TransferExported = frc42_macros::method_hash!("Transfer"),
56+
TransferFromExported = frc42_macros::method_hash!("TransferFrom"),
57+
IncreaseAllowanceExported = frc42_macros::method_hash!("IncreaseAllowance"),
58+
DecreaseAllowanceExported = frc42_macros::method_hash!("DecreaseAllowance"),
59+
RevokeAllowanceExported = frc42_macros::method_hash!("RevokeAllowance"),
60+
BurnExported = frc42_macros::method_hash!("Burn"),
61+
BurnFromExported = frc42_macros::method_hash!("BurnFrom"),
62+
AllowanceExported = frc42_macros::method_hash!("Allowance"),
63+
}

actors/datacap/src/v14/state.rs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use frc46_token::token;
2+
use fvm_ipld_blockstore::Blockstore;
3+
use fvm_ipld_encoding::tuple::*;
4+
use fvm_shared4::address::Address;
5+
use fvm_shared4::econ::TokenAmount;
6+
use fvm_shared4::error::ExitCode;
7+
use fvm_shared4::ActorID;
8+
9+
use fil_actors_shared::v14::{ActorError, AsActorError};
10+
11+
#[derive(Debug, Serialize_tuple, Deserialize_tuple)]
12+
pub struct State {
13+
pub governor: Address,
14+
pub token: token::state::TokenState,
15+
}
16+
17+
impl State {
18+
pub fn new<BS: Blockstore>(store: &BS, governor: Address) -> Result<State, ActorError> {
19+
let token_state = token::state::TokenState::new(store)
20+
.context_code(ExitCode::USR_ILLEGAL_STATE, "failed to create token state")?;
21+
Ok(State {
22+
governor,
23+
token: token_state,
24+
})
25+
}
26+
27+
// Visible for testing
28+
pub fn balance<BS: Blockstore>(
29+
&self,
30+
bs: &BS,
31+
owner: ActorID,
32+
) -> Result<TokenAmount, ActorError> {
33+
self.token
34+
.get_balance(bs, owner)
35+
.context_code(ExitCode::USR_ILLEGAL_STATE, "failed to get balance")
36+
}
37+
}

actors/datacap/src/v14/types.rs

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
use fvm_ipld_encoding::tuple::*;
2+
use fvm_shared4::address::Address;
3+
use fvm_shared4::econ::TokenAmount;
4+
5+
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
6+
#[serde(transparent)]
7+
pub struct ConstructorParams {
8+
pub governor: Address,
9+
}
10+
11+
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
12+
#[serde(transparent)]
13+
pub struct NameReturn {
14+
pub name: String,
15+
}
16+
17+
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
18+
#[serde(transparent)]
19+
pub struct SymbolReturn {
20+
pub symbol: String,
21+
}
22+
23+
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
24+
#[serde(transparent)]
25+
pub struct TotalSupplyReturn {
26+
pub supply: TokenAmount,
27+
}
28+
29+
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
30+
#[serde(transparent)]
31+
pub struct BalanceParams {
32+
pub address: Address,
33+
}
34+
35+
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
36+
#[serde(transparent)]
37+
pub struct BalanceReturn {
38+
pub balance: TokenAmount,
39+
}
40+
41+
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
42+
#[serde(transparent)]
43+
pub struct GetAllowanceReturn {
44+
pub allowance: TokenAmount,
45+
}
46+
47+
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
48+
#[serde(transparent)]
49+
pub struct IncreaseAllowanceReturn {
50+
pub new_allowance: TokenAmount,
51+
}
52+
53+
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
54+
#[serde(transparent)]
55+
pub struct DecreaseAllowanceReturn {
56+
pub new_allowance: TokenAmount,
57+
}
58+
59+
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
60+
#[serde(transparent)]
61+
pub struct RevokeAllowanceReturn {
62+
pub old_allowance: TokenAmount,
63+
}
64+
65+
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
66+
pub struct MintParams {
67+
// Recipient of the newly minted tokens.
68+
pub to: Address,
69+
// Amount of tokens to mint.
70+
pub amount: TokenAmount,
71+
// Addresses to be granted effectively-infinite operator allowance for the recipient.
72+
pub operators: Vec<Address>,
73+
}
74+
75+
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
76+
pub struct DestroyParams {
77+
pub owner: Address,
78+
pub amount: TokenAmount,
79+
}
80+
81+
#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
82+
#[serde(transparent)]
83+
pub struct GranularityReturn {
84+
pub granularity: u64,
85+
}

actors/eam/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ pub mod v10;
55
pub mod v11;
66
pub mod v12;
77
pub mod v13;
8+
pub mod v14;

actors/eam/src/v14/mod.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2019-2022 ChainSafe Systems
2+
// SPDX-License-Identifier: Apache-2.0, MIT
3+
4+
use fvm_shared4::METHOD_CONSTRUCTOR;
5+
use num_derive::FromPrimitive;
6+
7+
#[derive(FromPrimitive)]
8+
#[repr(u64)]
9+
pub enum Method {
10+
Constructor = METHOD_CONSTRUCTOR,
11+
Create = 2,
12+
Create2 = 3,
13+
CreateExternal = 4,
14+
}

actors/ethaccount/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ pub mod v10;
55
pub mod v11;
66
pub mod v12;
77
pub mod v13;
8+
pub mod v14;

actors/ethaccount/src/v14/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2019-2022 ChainSafe Systems
2+
// SPDX-License-Identifier: Apache-2.0, MIT
3+
4+
use fvm_shared4::METHOD_CONSTRUCTOR;
5+
use num_derive::FromPrimitive;
6+
7+
pub use types::*;
8+
9+
mod types;
10+
11+
/// Ethereum Account actor methods.
12+
#[derive(FromPrimitive)]
13+
#[repr(u64)]
14+
pub enum Method {
15+
Constructor = METHOD_CONSTRUCTOR,
16+
}

actors/ethaccount/src/v14/types.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use fvm_ipld_encoding::strict_bytes;
2+
use fvm_ipld_encoding::tuple::*;
3+
4+
#[derive(Debug, Serialize_tuple, Deserialize_tuple)]
5+
pub struct AuthenticateMessageParams {
6+
#[serde(with = "strict_bytes")]
7+
pub signature: Vec<u8>,
8+
#[serde(with = "strict_bytes")]
9+
pub message: Vec<u8>,
10+
}

actors/evm/src/evm_shared/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ pub mod v10;
55
pub mod v11;
66
pub mod v12;
77
pub mod v13;
8+
pub mod v14;

0 commit comments

Comments
 (0)