From cae9631a09ec127d98c18e0ceb18527195a0065f Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 10 Aug 2023 15:57:04 -0700 Subject: [PATCH] fix: explicitly specify HAMT bitwidths everywhere 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 --- actors/miner/src/testing.rs | 9 ++++++--- actors/multisig/src/testing.rs | 4 ++-- actors/power/src/testing.rs | 6 ++++-- actors/verifreg/src/testing.rs | 4 ++-- state/src/check.rs | 3 ++- test_vm/src/lib.rs | 14 ++++++++++---- 6 files changed, 26 insertions(+), 14 deletions(-) diff --git a/actors/miner/src/testing.rs b/actors/miner/src/testing.rs index 79a0ece396..4559ed9059 100644 --- a/actors/miner/src/testing.rs +++ b/actors/miner/src/testing.rs @@ -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; @@ -343,8 +343,11 @@ fn check_precommits( 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) => { diff --git a/actors/multisig/src/testing.rs b/actors/multisig/src/testing.rs index 58dc328dce..1e2f923053 100644 --- a/actors/multisig/src/testing.rs +++ b/actors/multisig/src/testing.rs @@ -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; @@ -54,7 +54,7 @@ pub fn check_state_invariants( 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( diff --git a/actors/power/src/testing.rs b/actors/power/src/testing.rs index b3c58f9efa..5f3f66c582 100644 --- a/actors/power/src/testing.rs +++ b/actors/power/src/testing.rs @@ -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::{ @@ -156,7 +158,7 @@ fn check_claims_invariants( 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)?; diff --git a/actors/verifreg/src/testing.rs b/actors/verifreg/src/testing.rs index c55e7f6735..003c204b73 100644 --- a/actors/verifreg/src/testing.rs +++ b/actors/verifreg/src/testing.rs @@ -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}; @@ -34,7 +34,7 @@ pub fn check_state_invariants( // 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)?; diff --git a/state/src/check.rs b/state/src/check.rs index 2988e7b22a..cba3dc3252 100644 --- a/state/src/check.rs +++ b/state/src/check.rs @@ -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; @@ -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 { - let map = Map::load(root, store)?; + let map = Map::load_with_config(root, store, DEFAULT_HAMT_CONFIG)?; Ok(Tree { map, store }) } diff --git a/test_vm/src/lib.rs b/test_vm/src/lib.rs index 3a350a490a..a68659b530 100644 --- a/test_vm/src/lib.rs +++ b/test_vm/src/lib.rs @@ -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, @@ -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, @@ -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() { @@ -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();