Skip to content

Commit

Permalink
fix: explicitly specify HAMT bitwidths everywhere
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 committed Aug 10, 2023
1 parent f46d4dc commit cae9631
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 14 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
4 changes: 2 additions & 2 deletions actors/multisig/src/testing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{collections::HashSet, iter::FromIterator};

use anyhow::anyhow;
use fil_actors_runtime::{Map, MessageAccumulator};
use fil_actors_runtime::{Map, MessageAccumulator, DEFAULT_HAMT_CONFIG};
use fvm_ipld_blockstore::Blockstore;
use fvm_shared::address::Address;
use integer_encoding::VarInt;
Expand Down Expand Up @@ -54,7 +54,7 @@ pub fn check_state_invariants<BS: Blockstore>(
let mut max_tx_id = TxnID(-1);
let mut pending_tx_count = 0u64;

match Map::<_, Transaction>::load(&state.pending_txs, store) {
match Map::<_, Transaction>::load_with_config(&state.pending_txs, store, DEFAULT_HAMT_CONFIG) {
Ok(transactions) => {
let ret = transactions.for_each(|tx_id, transaction| {
let tx_id = TxnID(
Expand Down
6 changes: 4 additions & 2 deletions actors/power/src/testing.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::collections::HashMap;

use fil_actors_runtime::{parse_uint_key, runtime::Policy, Map, MessageAccumulator, Multimap};
use fil_actors_runtime::{
parse_uint_key, runtime::Policy, Map, MessageAccumulator, Multimap, DEFAULT_HAMT_CONFIG,
};
use fvm_ipld_blockstore::Blockstore;
use fvm_ipld_encoding::RawBytes;
use fvm_shared::{
Expand Down Expand Up @@ -156,7 +158,7 @@ fn check_claims_invariants<BS: Blockstore>(
let mut qa_power = StoragePower::zero();
let mut claims_with_sufficient_power_count = 0;

match Map::<_, Claim>::load(&state.claims, store) {
match Map::<_, Claim>::load_with_config(&state.claims, store, DEFAULT_HAMT_CONFIG) {
Ok(claims) => {
let ret = claims.for_each(|key, claim| {
let address = Address::from_bytes(key)?;
Expand Down
4 changes: 2 additions & 2 deletions actors/verifreg/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use fil_actors_runtime::runtime::policy_constants::{
};
use fil_actors_runtime::shared::HAMT_BIT_WIDTH;
use fil_actors_runtime::{
make_map_with_root_and_bitwidth, parse_uint_key, Map, MessageAccumulator,
make_map_with_root_and_bitwidth, parse_uint_key, Map, MessageAccumulator, DEFAULT_HAMT_CONFIG,
};
use fvm_ipld_blockstore::Blockstore;
use fvm_shared::address::{Address, Protocol};
Expand All @@ -34,7 +34,7 @@ pub fn check_state_invariants<BS: Blockstore>(

// Load and check verifiers
let mut all_verifiers = HashMap::new();
match Map::<_, BigIntDe>::load(&state.verifiers, store) {
match Map::<_, BigIntDe>::load_with_config(&state.verifiers, store, DEFAULT_HAMT_CONFIG) {
Ok(verifiers) => {
let ret = verifiers.for_each(|key, cap| {
let verifier = Address::from_bytes(key)?;
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 cae9631

Please sign in to comment.