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
Init actor sketch #169
Init actor sketch #169
Conversation
actors.md
Outdated
|
||
Parameters: | ||
|
||
- code Cid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where do I get this Cid from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have a list of well known CIDs somewhere for the builtin actors
actors.md
Outdated
|
||
addr := VM.CreateActor(code, msg.Value, DecodeParams(params)) | ||
|
||
// TODO: where is this mapping stored? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might as well store it in this actor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah... that doesnt seem like the worst thing to do. I'll come up with some pros and cons in a bit
TODO: the type of params should probably just be variadic set of arguments. Making it be a `[]byte` here kinda sucks | ||
|
||
```go | ||
func Exec(code Cid, params []byte) Address { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the gas cost for this clear?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, its not a fixed value if thats what youre asking. This will have to pay gas for whatever code is in the actors constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be added, or should all gas related things be added in one go later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do gas related stuff later in a big gas push
// TODO: where is this mapping stored? | ||
SetIDMapping(actorID, addr) | ||
|
||
return addr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how do I get the ID from the addr?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking that nodes would just create and store a reverse index locally. Storing a two-way mapping on-chain seems expensive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alternatively, I was talking with @frrist about a setup where the primary state tree is a map[ID]Actor
, and separately we store a map[Address]ID
. This would allow users to shift around keys for their accounts, and maybe other things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we said a map[PubKey]ID
when we initially talked about this, is that what we mean by Address
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using the ID
as primary identifier in the state tree would be neat. Having a map[Address]ID
around, should also address any reordering concerns that could appear due to different ID
assignments. We could store this mapping in the InitActor
, given it is the actor that actually adds entries to this mapping.
Allowing key changes would need some more thought, because if I simply change my key there is no information about my new address (the one derived from my new key) in the Addresss -> ID
map. So this would require having at least an AddMapping(from Address, to ID)
call to the InitActor
(or the place that manages this mapping)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, i'm in support of IDs being used as the primary mapping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
actors.md
Outdated
actorID := self.NextActorID | ||
self.NextActorID++ | ||
|
||
if code == InitActorCodeCid { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be a white list for now, given there are many actors we don't want other to launch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually don't mind people launching their own storage market with its own miners. I think that would be interesting. There could be other storage markets for users who don't want to participate in block production, or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we allow that, then we should have a way to ask the chain directly for the official versions, to reduce chances that anyone is scammed/or accidentally uses a wrong version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah... maybe it makes the most sense to not allow other storage markets for now then too. Can always re-enable it later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -38,7 +74,7 @@ func CreateStorageMiner(pubkey PublicKey, pledge BytesAmount, pid PeerID) Addres | |||
Fatal("not enough funds to cover required collateral") | |||
} | |||
|
|||
newminer := VM.CreateActor(MinerActor, msg.Value, pubkey, pledge, pid) | |||
newminer := InitActor.Exec(MinerActorCodeCid, EncodeParams(pubkey, pledge, pid)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about retaining the descriptive InitActor.CreateActor
name? Exec
is opaque and also limits future change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We really wanted to stick to unix terminology here, where exec
is the accepted terminology for taking a given piece of code and instantiating a new process running it.
actors.md
Outdated
- code Cid | ||
- params []byte | ||
|
||
TODO: the type of params should probably just be variadic set of arguments. Making it be a `[]byte` here kinda sucks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@whyrusleeping depends on the level this spec is written, on a low level this has to be []byte
serialized in some form to pass through variadic arguments. But if this is meant to describe a high level I would agree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think this can be a little higher level, how things get encoded precisely is discussed elsewhere. But this document should match closely the actual actors that get written.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
adf9a59
to
f844d70
Compare
actors.md
Outdated
```go | ||
func Exec(code Cid, params []byte) Address { | ||
// Get the actor ID for this actor. | ||
actorID = len(self.AddressMap) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think relying on the size of this map to keep track of the next ID may end up being error prone, i'm worried that if we allow actors to be deleted, this will result in unexpected behavior
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are not wrong, it just felt nicer to use this given the fact that we don't have deletion atm, but I am fine reverting to keeping track of the id manually
actors.md
Outdated
|
||
// Ensure that singeltons can be only launched once. | ||
// TODO: do we want to enforce this? If so how should actors be marked as such? | ||
if IsSingletonActor(code) && self.hasInstance(code) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tricky. I see what youre doing here, making it so that we can use the init actor itself to launch the other protected actors at network launch. I think maybe we can fake that all for now, and just have a simple whitelist here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized something, do we have a way to get the code Cid from the actor currently? If not we should have this, such that I can check if a certain actor is spawned from this particular code cid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should definitely have that, i don't think its exposed right now in an easy to use way
@dignifiedquire thanks for the help! I expanded on the |
Working on the init actor (we've only been talking about it for two years at this point). This will be the new way to create actors (answering questions for other PRs that needs to be able to create actors), it will also track and allocate actor IDs (though there may be some arguments for not tracking it here, i'll go through that later).
With this, we also remove the 'create actor' from the VM context, cleaning that logic up a bit. The weirdness now is that the init actor is a 'priveleged' actor, in that it can make calls that no other actor can make.