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

Add resolve_address method on v0 init actor #147

Closed
wants to merge 1 commit into from
Closed
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
31 changes: 30 additions & 1 deletion actors/init/src/v0/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
// SPDX-License-Identifier: Apache-2.0, MIT

use cid::Cid;
use fil_actors_shared::v9::{make_map_with_root_and_bitwidth, shared::HAMT_BIT_WIDTH};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure the v9 versions of these functions are identical to the v0 versions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry intended to raise this as draft PR, will test and confirm

use fvm_ipld_blockstore::Blockstore;
use fvm_ipld_encoding::tuple::*;
use fvm_shared::ActorID;
use fvm_shared::{
address::{Address, Protocol},
ActorID,
};

/// Defines first available ID address after builtin actors
pub const FIRST_NON_SINGLETON_ADDR: ActorID = 100;
Expand All @@ -24,4 +29,28 @@ impl State {
network_name,
}
}

/// `ResolveAddress` resolves an address to an ID-address, if possible.
/// If the provided address is an ID address, it is returned as-is.
/// This means that mapped ID-addresses (which should only appear as values, not keys) and
/// singleton actor addresses (which are not in the map) pass through unchanged.
///
/// Returns an ID-address and `true` if the address was already an ID-address or was resolved
/// in the mapping.
/// Returns an undefined address and `false` if the address was not an ID-address and not found
/// in the mapping.
/// Returns an error only if state was inconsistent.
pub fn resolve_address<BS: Blockstore>(
&self,
store: &BS,
addr: &Address,
) -> anyhow::Result<Option<Address>> {
if addr.protocol() == Protocol::ID {
return Ok(Some(*addr));
}

let map = make_map_with_root_and_bitwidth(&self.address_map, store, HAMT_BIT_WIDTH)?;

Ok(map.get(&addr.to_bytes())?.copied().map(Address::new_id))
}
}
2 changes: 1 addition & 1 deletion forest
Submodule forest updated 118 files