diff --git a/chain/actors/actor_multisig.go b/chain/actors/actor_multisig.go index d1e33d35f..8cf11a21e 100644 --- a/chain/actors/actor_multisig.go +++ b/chain/actors/actor_multisig.go @@ -2,15 +2,18 @@ package actors import ( "bytes" + "context" "fmt" "runtime/debug" "github.com/filecoin-project/go-address" "github.com/filecoin-project/lotus/chain/actors/aerrors" "github.com/filecoin-project/lotus/chain/types" + "github.com/ipfs/go-cid" samsig "github.com/filecoin-project/specs-actors/actors/builtin/multisig" vmr "github.com/filecoin-project/specs-actors/actors/runtime" + "github.com/filecoin-project/specs-actors/actors/runtime/exitcode" cbg "github.com/whyrusleeping/cbor-gen" ) @@ -112,6 +115,10 @@ type runtimeShim struct { func (rs *runtimeShim) shimCall(f func() interface{}) (rval []byte, aerr ActorError) { defer func() { if r := recover(); r != nil { + if ar, ok := r.(ActorError); ok { + aerr = ar + return + } fmt.Println("caught one of those actor errors: ", r) debug.PrintStack() log.Errorf("ERROR") @@ -146,27 +153,81 @@ func (rs *runtimeShim) ValidateImmediateCallerIs(as ...address.Address) { panic("we like to panic when people call the wrong methods") } +func (rs *runtimeShim) ImmediateCaller() address.Address { + return rs.vmctx.Message().From +} + +func (rs *runtimeShim) Context() context.Context { + return rs.vmctx.Context() +} + +func (rs *runtimeShim) IpldGet(c cid.Cid, o vmr.CBORUnmarshalable) bool { + if err := rs.vmctx.Storage().Get(c, o); err != nil { + panic(err) // y o o o o o l l l l o o o o o + } + return true +} + +func (rs *runtimeShim) IpldPut(o vmr.CBORMarshalable) cid.Cid { + c, err := rs.vmctx.Storage().Put(o) + if err != nil { + panic(err) + } + return c +} + +func (rs *runtimeShim) Abort(code exitcode.ExitCode, msg string, args ...interface{}) { + panic(aerrors.Newf(uint8(code), msg, args...)) +} + +func (rs *runtimeShim) AbortStateMsg(msg string) { + rs.Abort(101, msg) +} + func (rs *runtimeShim) State() vmr.StateHandle { - + return &shimStateHandle{rs: rs} } -/* type shimStateHandle struct { - vmctx types.VMContext + rs *runtimeShim } -func (ssh *shimStateHandle) Release(c cid.Cid) { - +func (ssh *shimStateHandle) Readonly(obj vmr.CBORUnmarshalable) { + if err := ssh.rs.vmctx.Storage().Get(ssh.rs.vmctx.Storage().GetHead(), obj); err != nil { + panic(err) + } } -func (ssh *shimStateHandle) Take() { +func (ssh *shimStateHandle) Transaction(obj vmr.CBORAble, f func() interface{}) interface{} { + head := ssh.rs.vmctx.Storage().GetHead() + if err := ssh.rs.vmctx.Storage().Get(head, obj); err != nil { + panic(err) + } + out := f() + + c, err := ssh.rs.vmctx.Storage().Put(obj) + if err != nil { + panic(err) + } + if err := ssh.rs.vmctx.Storage().Commit(head, c); err != nil { + panic(err) + } + + return out } -func (rs *runtimeShim) AcquireState() vmr.ActorStateHandle { - return &shimStateHandle{rs.vmctx} +func (ssh *shimStateHandle) Construct(f func() vmr.CBORMarshalable) { + out := f() + + c, err := ssh.rs.vmctx.Storage().Put(out) + if err != nil { + panic(err) + } + if err := ssh.rs.vmctx.Storage().Commit(EmptyCBOR, c); err != nil { + panic(err) + } } -*/ type MultiSigConstructorParams = samsig.ConstructorParams diff --git a/chain/actors/actor_multisig_test.go b/chain/actors/actor_multisig_test.go index b6a1f651d..c7eef372c 100644 --- a/chain/actors/actor_multisig_test.go +++ b/chain/actors/actor_multisig_test.go @@ -85,7 +85,7 @@ func TestMultiSigOps(t *testing.T) { ret, _ = h.Invoke(t, outsideAddr, multSigAddr, actors.MultiSigMethods.Approve, &txIDParam) - assert.Equal(t, uint8(1), ret.ExitCode, "outsideAddr should not approve") + assert.Equal(t, uint8(18), ret.ExitCode, "outsideAddr should not approve") h.AssertBalanceChange(t, multSigAddr, 0) ret2, _ := h.Invoke(t, sig1Addr, multSigAddr, actors.MultiSigMethods.Approve, diff --git a/go.mod b/go.mod index 36556bee7..0daab3113 100644 --- a/go.mod +++ b/go.mod @@ -87,7 +87,7 @@ require ( github.com/prometheus/common v0.2.0 github.com/stretchr/testify v1.4.0 github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba - github.com/whyrusleeping/cbor-gen v0.0.0-20200122015334-52eaf73beaf5 + github.com/whyrusleeping/cbor-gen v0.0.0-20200123233031-1cdf64d27158 github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 github.com/whyrusleeping/pubsub v0.0.0-20131020042734-02de8aa2db3d go.opencensus.io v0.22.2 diff --git a/go.sum b/go.sum index afd7daee3..fa0668a1a 100644 --- a/go.sum +++ b/go.sum @@ -729,6 +729,8 @@ github.com/whyrusleeping/cbor-gen v0.0.0-20191212224538-d370462a7e8a/go.mod h1:x github.com/whyrusleeping/cbor-gen v0.0.0-20191216205031-b047b6acb3c0/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY= github.com/whyrusleeping/cbor-gen v0.0.0-20200122015334-52eaf73beaf5 h1:wqba3bIey6d92UBNPKHybEu5blL1ZKr9yzu1ycmJW04= github.com/whyrusleeping/cbor-gen v0.0.0-20200122015334-52eaf73beaf5/go.mod h1:Xj/M2wWU+QdTdRbu/L/1dIZY8/Wb2K9pAhtroQuxJJI= +github.com/whyrusleeping/cbor-gen v0.0.0-20200123233031-1cdf64d27158 h1:WXhVOwj2USAXB5oMDwRl3piOux2XMV9TANaYxXHdkoE= +github.com/whyrusleeping/cbor-gen v0.0.0-20200123233031-1cdf64d27158/go.mod h1:Xj/M2wWU+QdTdRbu/L/1dIZY8/Wb2K9pAhtroQuxJJI= github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f h1:jQa4QT2UP9WYv2nzyawpKMOCl+Z/jW7djv2/J50lj9E= github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f/go.mod h1:p9UJB6dDgdPgMJZs7UjUOdulKyRr9fqkS+6JKAInPy8= github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 h1:EKhdznlJHPMoKr0XTrX+IlJs1LH3lyx2nfr1dOlZ79k=