Skip to content
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

Cron actor implementation #281

Merged
merged 4 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
45 changes: 23 additions & 22 deletions vm/actor/src/builtin/cron/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
mod state;

pub use self::state::{Entry, State};
use crate::{assert_empty_params, empty_return};
use crate::{assert_empty_params, empty_return, SYSTEM_ACTOR_ADDR};
use address::Address;
use ipld_blockstore::BlockStore;
use num_derive::FromPrimitive;
use num_traits::FromPrimitive;
use runtime::{ActorCode, Runtime};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use vm::{ExitCode, MethodNum, Serialized, METHOD_CONSTRUCTOR};
use vm::{ExitCode, MethodNum, Serialized, TokenAmount, METHOD_CONSTRUCTOR};

/// Cron actor methods available
#[derive(FromPrimitive)]
Expand Down Expand Up @@ -57,37 +58,37 @@ impl<'de> Deserialize<'de> for ConstructorParams {
pub struct Actor;
impl Actor {
/// Constructor for Cron actor
fn constructor<BS, RT>(_rt: &RT, _params: ConstructorParams)
fn constructor<BS, RT>(rt: &RT, params: ConstructorParams)
where
BS: BlockStore,
RT: Runtime<BS>,
{
// TODO now finished spec
todo!()
let sys_ref: &Address = &SYSTEM_ACTOR_ADDR;
rt.validate_immediate_caller_is(std::iter::once(sys_ref));
rt.create(&State {
entries: params.entries,
})
}
/// epoch_tick executes built-in periodic actions, run at every Epoch.
/// Executes built-in periodic actions, run at every Epoch.
/// epoch_tick(r) is called after all other messages in the epoch have been applied.
/// This can be seen as an implicit last message.
fn epoch_tick<BS, RT>(_rt: &RT)
fn epoch_tick<BS, RT>(rt: &RT)
where
BS: BlockStore,
RT: Runtime<BS>,
{
// self.entries is basically a static registry for now, loaded
// in the interpreter static registry.
// TODO update to new spec
todo!()
// for entry in &self.entries {
// let res = rt.send_catching_errors(InvocInput {
// to: entry.to_addr.clone(),
// method: entry.method_num,
// params: Serialized::default(),
// value: TokenAmount::new(0),
// });
// if let Err(e) = res {
// return e.into();
// }
// }
let sys_ref: &Address = &SYSTEM_ACTOR_ADDR;
rt.validate_immediate_caller_is(std::iter::once(sys_ref));

let st: State = rt.state();
for entry in st.entries {
rt.send::<Serialized>(
&entry.receiver,
entry.method_num,
&Serialized::default(),
&TokenAmount::new(0),
);
}
}
}

Expand Down
7 changes: 5 additions & 2 deletions vm/actor/src/builtin/cron/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0, MIT

use address::Address;
use encoding::Cbor;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use vm::MethodNum;

Expand All @@ -13,8 +14,8 @@ pub struct State {
}

pub struct Entry {
receiver: Address,
method_num: MethodNum,
pub receiver: Address,
pub method_num: MethodNum,
}

impl Serialize for State {
Expand All @@ -26,6 +27,8 @@ impl Serialize for State {
}
}

impl Cbor for State {}

impl<'de> Deserialize<'de> for State {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
Expand Down