MCPcopy Create free account
hub / github.com/consensus-shipyard/ipc / new

Method new

fendermint/vm/actor_interface/src/init.rs:56–140  ·  view source on GitHub ↗

Create new state instance.

(
        store: &BS,
        network_name: String,
        // Accounts from the Genesis file.
        accounts: &[Actor],
        // Pre-defined IDs for top-level EVM contracts.
        eth_builtin_i

Source from the content-addressed store, hash-verified

54impl State {
55 /// Create new state instance.
56 pub fn new<BS: Blockstore>(
57 store: &BS,
58 network_name: String,
59 // Accounts from the Genesis file.
60 accounts: &[Actor],
61 // Pre-defined IDs for top-level EVM contracts.
62 eth_builtin_ids: &BTreeSet<ActorID>,
63 // Number of dynamically deployed EVM library contracts.
64 eth_library_count: u64,
65 ) -> anyhow::Result<(Self, AddressMap)> {
66 // Returning only the addreses that belong to user accounts.
67 let mut allocated_ids = AddressMap::new();
68 // Inserting both user accounts and built-in EVM actors.
69 let mut address_map = Hamt::<&BS, ActorID>::new_with_bit_width(store, HAMT_BIT_WIDTH);
70
71 let mut set_address = |addr: Address, id: ActorID| {
72 tracing::debug!(
73 addr = addr.to_string(),
74 actor_id = id,
75 "setting init address"
76 );
77 address_map.set(addr.to_bytes().into(), id)
78 };
79
80 let addresses = accounts.iter().flat_map(|a| match &a.meta {
81 ActorMeta::Account(acc) => {
82 vec![acc.owner.0]
83 }
84 ActorMeta::Multisig(ms) => ms.signers.iter().map(|a| a.0).collect(),
85 });
86
87 let mut next_id = FIRST_NON_SINGLETON_ADDR;
88
89 for addr in addresses {
90 if allocated_ids.contains_key(&addr) {
91 continue;
92 }
93 allocated_ids.insert(addr, next_id);
94 set_address(addr, next_id).context("cannot set ID of account address")?;
95 next_id += 1;
96 }
97
98 // We will need to allocate an ID for each multisig account, however,
99 // these do not have to be recorded in the map, because their addr->ID
100 // mapping is trivial (it's an ID type address). To avoid the init actor
101 // using the same ID for something else, give it a higher ID to use next.
102 for a in accounts.iter() {
103 if let ActorMeta::Multisig { .. } = a.meta {
104 next_id += 1;
105 }
106 }
107
108 // Insert top-level EVM contracts which have fixed IDs.
109 for id in eth_builtin_ids {
110 let addr = Address::from(builtin_actor_eth_addr(*id));
111 set_address(addr, *id).context("cannot set ID of eth contract address")?;
112 }
113

Callers

nothing calls this directly

Calls 10

builtin_actor_eth_addrFunction · 0.85
collectMethod · 0.80
contextMethod · 0.80
setMethod · 0.45
intoMethod · 0.45
to_bytesMethod · 0.45
iterMethod · 0.45
contains_keyMethod · 0.45
insertMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected