OMG this is killing me
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
This commit is contained in:
parent
218e965869
commit
9da31fb6ad
@ -13,13 +13,22 @@ import (
|
||||
hamt "github.com/ipfs/go-hamt-ipld"
|
||||
cbor "github.com/ipfs/go-ipld-cbor"
|
||||
logging "github.com/ipfs/go-log"
|
||||
mh "github.com/multiformats/go-multihash"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var log = logging.Logger("actors")
|
||||
|
||||
var EmptyCBOR cid.Cid
|
||||
|
||||
func init() {
|
||||
cbor.RegisterCborType(ExecParams{})
|
||||
cbor.RegisterCborType(struct{}{})
|
||||
n, err := cbor.WrapObject(struct{}{}, mh.SHA2_256, -1)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
EmptyCBOR = n.Cid()
|
||||
}
|
||||
|
||||
type InitActor struct{}
|
||||
@ -102,9 +111,13 @@ func (ia InitActor) Exec(act *types.Actor, vmctx types.VMContext, p *ExecParams)
|
||||
actor := types.Actor{
|
||||
Code: p.Code,
|
||||
Balance: vmctx.Message().Value,
|
||||
Head: cid.Undef,
|
||||
Head: EmptyCBOR,
|
||||
Nonce: 0,
|
||||
}
|
||||
_, err = vmctx.Storage().Put(struct{}{})
|
||||
if err != nil {
|
||||
return types.InvokeRet{}, err
|
||||
}
|
||||
|
||||
// The call to the actors constructor will set up the initial state
|
||||
// from the given parameters, setting `actor.Head` to a new value when successful.
|
||||
@ -128,6 +141,11 @@ func (ia InitActor) Exec(act *types.Actor, vmctx types.VMContext, p *ExecParams)
|
||||
return types.InvokeRet{}, errors.Wrap(err, "inserting new actor into state tree")
|
||||
}
|
||||
|
||||
_, _, err = vmctx.Send(idAddr, 0, vmctx.Message().Value, p.Params)
|
||||
if err != nil {
|
||||
return types.InvokeRet{}, err
|
||||
}
|
||||
|
||||
c, err := vmctx.Storage().Put(self)
|
||||
if err != nil {
|
||||
return types.InvokeRet{}, err
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"github.com/filecoin-project/go-lotus/chain/address"
|
||||
"github.com/filecoin-project/go-lotus/chain/types"
|
||||
|
||||
"github.com/ipfs/go-cid"
|
||||
cbor "github.com/ipfs/go-ipld-cbor"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
)
|
||||
@ -56,7 +55,8 @@ type StorageMinerActorState struct {
|
||||
//NextDoneSet BitField
|
||||
|
||||
// Deals this miner has been slashed for since the last post submission.
|
||||
ArbitratedDeals map[cid.Cid]struct{}
|
||||
//TODO: unsupported map key type "Cid" (if you want to use struct keys, your atlas needs a transform to string)
|
||||
//ArbitratedDeals map[cid.Cid]struct{}
|
||||
|
||||
// Amount of power this miner has.
|
||||
Power types.BigInt
|
||||
@ -77,6 +77,12 @@ type StorageMinerConstructorParams struct {
|
||||
PeerID peer.ID
|
||||
}
|
||||
|
||||
func (sma StorageMinerActor) Exports() []interface{} {
|
||||
return []interface{}{
|
||||
sma.StorageMinerActor,
|
||||
}
|
||||
}
|
||||
|
||||
func (sma StorageMinerActor) StorageMinerActor(act *types.Actor, vmctx types.VMContext, params *StorageMinerConstructorParams) (types.InvokeRet, error) {
|
||||
var self StorageMinerActorState
|
||||
self.Owner = vmctx.Message().From
|
||||
@ -90,7 +96,7 @@ func (sma StorageMinerActor) StorageMinerActor(act *types.Actor, vmctx types.VMC
|
||||
return types.InvokeRet{}, err
|
||||
}
|
||||
|
||||
if err := storage.Commit(cid.Undef, c); err != nil {
|
||||
if err := storage.Commit(EmptyCBOR, c); err != nil {
|
||||
return types.InvokeRet{}, err
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,6 @@ const SectorSize = 1024
|
||||
func init() {
|
||||
cbor.RegisterCborType(StorageMarketState{})
|
||||
cbor.RegisterCborType(CreateStorageMinerParams{})
|
||||
cbor.RegisterCborType(struct{}{})
|
||||
}
|
||||
|
||||
type StorageMarketActor struct{}
|
||||
|
@ -58,9 +58,14 @@ func TestVMInvokeMethod(t *testing.T) {
|
||||
vm, addrs := setupVMTestEnv(t)
|
||||
from := addrs[0]
|
||||
|
||||
cenc, err := cbor.DumpObject(StorageMinerConstructorParams{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
execparams := &ExecParams{
|
||||
Code: StorageMinerCodeCid,
|
||||
Params: []byte("cats"),
|
||||
Params: cenc,
|
||||
}
|
||||
enc, err := cbor.DumpObject(execparams)
|
||||
if err != nil {
|
||||
|
@ -1 +0,0 @@
|
||||
package actors
|
@ -71,12 +71,12 @@ func (h *Harness) Execute() *chain.StateTree {
|
||||
for i, step := range h.Steps {
|
||||
h.currStep = i
|
||||
ret, err := h.vm.ApplyMessage(&step.M)
|
||||
step.Ret(h.t, ret)
|
||||
step.Err(h.t, err)
|
||||
step.Ret(h.t, ret)
|
||||
}
|
||||
stateroot, err := h.vm.Flush(context.TODO())
|
||||
if err != nil {
|
||||
h.t.Fatal(err)
|
||||
h.t.Fatalf("%+v", err)
|
||||
}
|
||||
cst := hamt.CSTFromBstore(h.bs)
|
||||
state, err := chain.LoadStateTree(cst, stateroot)
|
||||
@ -95,7 +95,7 @@ func (h *Harness) DumpObject(obj interface{}) []byte {
|
||||
}
|
||||
func (h *Harness) NoError(t *testing.T, err error) {
|
||||
if err != nil {
|
||||
t.Fatalf("Expected no errors from applying message in step %d. Got %s", h.currStep, err)
|
||||
t.Fatalf("Error in step %d: %s", h.currStep, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,13 +111,16 @@ func TestVMInvokeHarness(t *testing.T) {
|
||||
Params: h.DumpObject(
|
||||
&ExecParams{
|
||||
Code: StorageMinerCodeCid,
|
||||
Params: []byte("cats"),
|
||||
Params: h.DumpObject(&StorageMinerConstructorParams{}),
|
||||
}),
|
||||
GasPrice: types.NewInt(1),
|
||||
GasLimit: types.NewInt(1),
|
||||
Value: types.NewInt(0),
|
||||
},
|
||||
Ret: func(t *testing.T, ret *types.MessageReceipt) {
|
||||
if ret == nil {
|
||||
t.Fatal("ret is nil")
|
||||
}
|
||||
if ret.ExitCode != 0 {
|
||||
t.Fatal("invocation failed: ", ret.ExitCode)
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package chain
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
@ -26,6 +25,7 @@ func newInvoker() *invoker {
|
||||
// add builtInCode using: register(cid, singleton)
|
||||
inv.register(actors.InitActorCodeCid, actors.InitActor{})
|
||||
inv.register(actors.StorageMarketActorCodeCid, actors.StorageMarketActor{})
|
||||
inv.register(actors.StorageMinerCodeCid, actors.StorageMinerActor{})
|
||||
|
||||
return inv
|
||||
}
|
||||
@ -34,7 +34,7 @@ func (inv *invoker) Invoke(act *types.Actor, vmctx *VMContext, method uint64, pa
|
||||
|
||||
code, ok := inv.builtInCode[act.Code]
|
||||
if !ok {
|
||||
return types.InvokeRet{}, errors.New("no code for actor")
|
||||
return types.InvokeRet{}, fmt.Errorf("no code for actor %s", act.Code)
|
||||
}
|
||||
if method >= uint64(len(code)) || code[method] == nil {
|
||||
return types.InvokeRet{}, fmt.Errorf("no method %d on actor", method)
|
||||
|
12
chain/vm.go
12
chain/vm.go
@ -8,6 +8,7 @@ import (
|
||||
"github.com/filecoin-project/go-lotus/chain/address"
|
||||
"github.com/filecoin-project/go-lotus/chain/types"
|
||||
"github.com/filecoin-project/go-lotus/lib/bufbstore"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
bserv "github.com/ipfs/go-blockservice"
|
||||
cid "github.com/ipfs/go-cid"
|
||||
@ -88,7 +89,12 @@ func (vmc *VMContext) Send(to address.Address, method uint64, value types.BigInt
|
||||
|
||||
nvmctx := vmc.vm.makeVMContext(toAct.Head, msg)
|
||||
|
||||
return vmc.vm.Invoke(toAct, nvmctx, method, params)
|
||||
res, ret, err := vmc.vm.Invoke(toAct, nvmctx, method, params)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
// We need probably copy here the content from sub-vmcontext to this vm-context
|
||||
// I think, @why??
|
||||
}
|
||||
|
||||
// BlockHeight returns the height of the block this message was added to the chain in
|
||||
@ -237,11 +243,11 @@ func (vm *VM) Flush(ctx context.Context) (cid.Cid, error) {
|
||||
|
||||
root, err := vm.cstate.Flush()
|
||||
if err != nil {
|
||||
return cid.Undef, err
|
||||
return cid.Undef, xerrors.Errorf("flushing vm: %w", err)
|
||||
}
|
||||
|
||||
if err := ipld.Copy(ctx, from, to, root); err != nil {
|
||||
return cid.Undef, err
|
||||
return cid.Undef, xerrors.Errorf("copying tree: %w", err)
|
||||
}
|
||||
|
||||
return root, nil
|
||||
|
Loading…
Reference in New Issue
Block a user