Skip to content

Commit

Permalink
fix: explicitly specify HAMT bitwidths everywhere (#1364)
Browse files Browse the repository at this point in the history
This _doesn't_ migrate to the new `Map2` interface everywhere, it just
avoids the use of `Hamt::load` and `Hamt::new`, which will be deprecated
in the next release of `fvm_ipld_hamt`.

part of #1346
  • Loading branch information
Stebalien authored Aug 11, 2023
1 parent 7e11334 commit 266b3bb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
9 changes: 6 additions & 3 deletions actors/miner/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
SectorOnChainInfo, SectorPreCommitOnChainInfo, Sectors, State,
};
use fil_actors_runtime::runtime::Policy;
use fil_actors_runtime::{parse_uint_key, Map, MessageAccumulator};
use fil_actors_runtime::{parse_uint_key, Map, MessageAccumulator, DEFAULT_HAMT_CONFIG};
use fvm_ipld_bitfield::BitField;
use fvm_ipld_blockstore::Blockstore;
use fvm_ipld_encoding::CborStore;
Expand Down Expand Up @@ -343,8 +343,11 @@ fn check_precommits<BS: Blockstore>(

let mut precommit_total = TokenAmount::zero();

let precommited_sectors =
Map::<_, SectorPreCommitOnChainInfo>::load(&state.pre_committed_sectors, store);
let precommited_sectors = Map::<_, SectorPreCommitOnChainInfo>::load_with_config(
&state.pre_committed_sectors,
store,
DEFAULT_HAMT_CONFIG,
);

match precommited_sectors {
Ok(precommited_sectors) => {
Expand Down
3 changes: 2 additions & 1 deletion state/src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use fil_actor_reward::State as RewardState;
use fil_actor_verifreg::{DataCap, State as VerifregState};

use fil_actors_runtime::runtime::Policy;
use fil_actors_runtime::DEFAULT_HAMT_CONFIG;
use fil_actors_runtime::VERIFIED_REGISTRY_ACTOR_ADDR;

use fil_actors_runtime::Map;
Expand Down Expand Up @@ -82,7 +83,7 @@ where
impl<'a, BS: Blockstore> Tree<'a, BS> {
/// Loads a tree from a root CID and store
pub fn load(store: &'a BS, root: &Cid) -> anyhow::Result<Self> {
let map = Map::load(root, store)?;
let map = Map::load_with_config(root, store, DEFAULT_HAMT_CONFIG)?;

Ok(Tree { map, store })
}
Expand Down
14 changes: 10 additions & 4 deletions test_vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use fil_actor_verifreg::State as VerifRegState;
use fil_actors_runtime::cbor::serialize;
use fil_actors_runtime::runtime::builtins::Type;
use fil_actors_runtime::runtime::{Policy, Primitives, EMPTY_ARR_CID};
use fil_actors_runtime::test_utils::*;
use fil_actors_runtime::DATACAP_TOKEN_ACTOR_ADDR;
use fil_actors_runtime::{test_utils::*, DEFAULT_HAMT_CONFIG};
use fil_actors_runtime::{
BURNT_FUNDS_ACTOR_ADDR, CRON_ACTOR_ADDR, EAM_ACTOR_ADDR, INIT_ACTOR_ADDR, REWARD_ACTOR_ADDR,
STORAGE_MARKET_ACTOR_ADDR, STORAGE_POWER_ACTOR_ADDR, SYSTEM_ACTOR_ADDR,
Expand Down Expand Up @@ -70,7 +70,11 @@ where
BS: Blockstore,
{
pub fn new(store: &'bs MemoryBlockstore) -> TestVM<'bs, MemoryBlockstore> {
let mut actors = Hamt::<&'bs MemoryBlockstore, ActorState, BytesKey, Sha256>::new(store);
let mut actors =
Hamt::<&'bs MemoryBlockstore, ActorState, BytesKey, Sha256>::new_with_config(
store,
DEFAULT_HAMT_CONFIG,
);
TestVM {
primitives: FakePrimitives {},
store,
Expand Down Expand Up @@ -240,9 +244,10 @@ where

pub fn checkpoint(&self) -> Cid {
// persist cache on top of latest checkpoint and clear
let mut actors = Hamt::<&'bs BS, ActorState, BytesKey, Sha256>::load(
let mut actors = Hamt::<&'bs BS, ActorState, BytesKey, Sha256>::load_with_config(
&self.state_root.borrow(),
self.store,
DEFAULT_HAMT_CONFIG,
)
.unwrap();
for (addr, act) in self.actors_cache.borrow().iter() {
Expand Down Expand Up @@ -383,9 +388,10 @@ where
return Some(act.clone());
}
// go to persisted map
let actors = Hamt::<&'bs BS, ActorState, BytesKey, Sha256>::load(
let actors = Hamt::<&'bs BS, ActorState, BytesKey, Sha256>::load_with_config(
&self.state_root.borrow(),
self.store,
DEFAULT_HAMT_CONFIG,
)
.unwrap();
let actor = actors.get(&address.to_bytes()).unwrap().cloned();
Expand Down

0 comments on commit 266b3bb

Please sign in to comment.