Skip to content

Commit

Permalink
fix: auto-create the burnt funds account (#1894)
Browse files Browse the repository at this point in the history
The FVM relies on this so it can burn funds on self-destruct.
  • Loading branch information
Stebalien authored Sep 22, 2023
1 parent fd428a2 commit 27631fd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
28 changes: 27 additions & 1 deletion testing/integration/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
// SPDX-License-Identifier: Apache-2.0, MIT
use anyhow::{Context, Result};
use cid::Cid;
use fvm::machine::Manifest;
use fvm::machine::{Manifest, BURNT_FUNDS_ACTOR_ID};
use fvm::state_tree::{ActorState, StateTree};
use fvm::{init_actor, system_actor};
use fvm_ipld_blockstore::Blockstore;
use fvm_ipld_encoding::CborStore;
use fvm_shared::address::Address;
use fvm_shared::ActorID;
use multihash::Code;

Expand Down Expand Up @@ -90,3 +91,28 @@ pub fn set_eam_actor(state_tree: &mut StateTree<impl Blockstore>, eam_code_cid:
state_tree.set_actor(EAM_ACTOR_ID, eam_actor_state);
Ok(())
}

pub fn set_burnt_funds_account(
state_tree: &mut StateTree<impl Blockstore>,
account_code_cid: Cid,
) -> Result<()> {
let state = fvm::account_actor::State {
address: Address::new_id(BURNT_FUNDS_ACTOR_ID),
};

let account_state_cid = state_tree
.store()
.put_cbor(&state, Code::Blake2b256)
.context(FailedToSetState("burnt funds account actor".to_owned()))?;

let actor_state = ActorState {
code: account_code_cid,
state: account_state_cid,
sequence: 0,
balance: Default::default(),
delegated_address: None,
};

state_tree.set_actor(BURNT_FUNDS_ACTOR_ID, actor_state);
Ok(())
}
7 changes: 5 additions & 2 deletions testing/integration/src/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ use lazy_static::lazy_static;
use libsecp256k1::{PublicKey, SecretKey};
use multihash::Code;

use crate::builtin::{fetch_builtin_code_cid, set_eam_actor, set_init_actor, set_sys_actor};
use crate::builtin::{
fetch_builtin_code_cid, set_burnt_funds_account, set_eam_actor, set_init_actor, set_sys_actor,
};
use crate::dummy::DummyExterns;
use crate::error::Error::{FailedToFlushTree, NoManifestInformation};

Expand Down Expand Up @@ -96,10 +98,11 @@ where
let init_state = init_actor::State::new_test(&blockstore);
let mut state_tree = StateTree::new(blockstore, stv).map_err(anyhow::Error::from)?;

// Deploy init, sys, and eam actors
// Deploy init, sys, burn, and eam actors
let sys_state = system_actor::State { builtin_actors };
set_sys_actor(&mut state_tree, sys_state, sys_code_cid)?;
set_init_actor(&mut state_tree, init_code_cid, init_state)?;
set_burnt_funds_account(&mut state_tree, accounts_code_cid)?;
set_eam_actor(&mut state_tree, eam_code_cid)?;

Ok(Tester {
Expand Down

0 comments on commit 27631fd

Please sign in to comment.