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

Init actor sketch #169

Merged
merged 5 commits into from Mar 20, 2019
Merged

Init actor sketch #169

merged 5 commits into from Mar 20, 2019

Conversation

whyrusleeping
Copy link
Member

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.

This was referenced Mar 5, 2019
actors.md Outdated

Parameters:

- code Cid
Copy link
Contributor

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?

Copy link
Member Author

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?
Copy link
Contributor

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?

Copy link
Member Author

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 {
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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?

Copy link
Member Author

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
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Contributor

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)

Copy link
Member Author

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.

Copy link
Contributor

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 {
Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Contributor

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

Copy link
Member Author

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

Copy link
Contributor

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))
Copy link
Member

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.

Copy link
Member Author

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
Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

done

actors.md Outdated
```go
func Exec(code Cid, params []byte) Address {
// Get the actor ID for this actor.
actorID = len(self.AddressMap)
Copy link
Member Author

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

Copy link
Contributor

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) {
Copy link
Member Author

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.

Copy link
Contributor

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

Copy link
Member Author

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

@whyrusleeping
Copy link
Member Author

@dignifiedquire thanks for the help! I expanded on the CreateActor call (broke it into the individual steps to make it clearer, since thats not documented anywhere else), and switched back to using the the explicitly tracked actor ID in the state.

@whyrusleeping whyrusleeping merged commit 9ffcbb4 into master Mar 20, 2019
@whyrusleeping whyrusleeping deleted the feat/init-actor branch March 20, 2019 23:07
@frrist frrist mentioned this pull request Apr 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants