I’ve recently been diving into the shared actor model, and still have a few questions about what’s happening both directly and under the hood of the actor syntax in the following two examples.
Thank you in advance for bearing with me through my lack of/incomplete understanding!
First example: (from various documentation examples)
shared (install) actor class MyClass(someone : Principal) = this {
...
shared({ caller = initializer }) actor class MyClass() = this {
...
shared ({ caller = owner }) actor class MyClass() = this {
...
- What is happening under the hood with the
install
and deconstructed{caller = initializer/owner}
bindings in these two shared actor examples? What does the whole(install)
parameter object look like and how can I know all potential options for using it (what is it’s type if deconstructed)? - Would
install.caller
in the first example ==caller
in the second example? - Is the difference between creating multiple actors via multiple plain actors (
actor MyActor
) vs. actor classes (actor class MyActor()
) that the latter creates separate canisters for each actor, vs. the former creates multiple actors within the same canister?
Second example
In this part of the mini-bigmap poc from the middle of last year by @Gabriel, a specific actor (the management canister) is defined within a shared actor class.
shared ({caller = owner}) actor class Container() = this {
...
let IC = actor "aaaaa-aa" : actor {
...
}
}
In addition to the translated interface spec definitions, the author then defines an additional utility set of functions inside the let IC =
bound actor, one of which is:
// dynamically install a new Bucket
func newEmptyBucket(): async Bucket {
Cycles.add(cycleShare);
let b = await Buckets.Bucket();
let _ = await updateCanister(b); // update canister permissions and settings
let s = await b.getSize();
Debug.print("new canister principal is " # debug_show(Principal.toText(Principal.fromActor(b))) );
Debug.print("initial size is " # debug_show(s));
let _ = canisterMap.put(Principal.fromActor(b), threshold);
var v : CanisterState<Bucket, Nat> = {
bucket = b;
var size = s;
};
canisters[canisters.size() + 1 ] := ?v;
b;
}
- What is the affect of nesting actors like this? What if they were nested actor classes?
- It seems we’re able to define the management canister like
actor "aaaaa-aa"
. What is the difference between:
a.actor "thisisastring123" { ... }
b.actor MyActor { ... }
- The management canister interface spec looks to be fixed in the methods that can be called on it. How is the author able to create a
newEmptyBucket()
method within this management canister represented actor? - What is the recommended way to call the management canister?
a. Create functions in a nested"aaaaa-aa"
actor and then communicate with the management canister through these functions defined on the “aaaaa-aa” actor
b. Call thecreate canister
method defined in the interface spec
c. Another way?