From 1d0d4294356e6b0baf38ea2b580fbccd00028ab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 6 Feb 2020 20:49:21 +0100 Subject: [PATCH 1/3] actors: Drop refs to multisig_actor.go --- chain/actors/actor_multisig.go | 128 ---------------------------- chain/actors/actor_multisig_test.go | 16 ++-- chain/types/message.go | 2 +- cli/multisig.go | 33 +++---- go.mod | 2 +- go.sum | 2 + node/impl/full/state.go | 3 +- 7 files changed, 33 insertions(+), 153 deletions(-) delete mode 100644 chain/actors/actor_multisig.go diff --git a/chain/actors/actor_multisig.go b/chain/actors/actor_multisig.go deleted file mode 100644 index 59fa745b3..000000000 --- a/chain/actors/actor_multisig.go +++ /dev/null @@ -1,128 +0,0 @@ -package actors - -import ( - samsig "github.com/filecoin-project/specs-actors/actors/builtin/multisig" -) - -type MultiSigActor struct{} -type MultiSigActorState = samsig.MultiSigActorState -type MultiSigTransaction = samsig.MultiSigTransaction -type TxnID = samsig.TxnID - -type musigMethods struct { - MultiSigConstructor uint64 - Propose uint64 - Approve uint64 - Cancel uint64 - ClearCompleted uint64 - AddSigner uint64 - RemoveSigner uint64 - SwapSigner uint64 - ChangeRequirement uint64 -} - -var MultiSigMethods = musigMethods{1, 2, 3, 4, 5, 6, 7, 8, 9} - -type MultiSigConstructorParams = samsig.ConstructorParams -type MultiSigProposeParams = samsig.ProposeParams -type MultiSigTxID = samsig.TxnIDParams -type MultiSigAddSignerParam = samsig.AddSignerParams -type MultiSigRemoveSignerParam = samsig.RemoveSignerParams -type MultiSigSwapSignerParams = samsig.SwapSignerParams -type MultiSigChangeReqParams = samsig.ChangeNumApprovalsThresholdParams - -/* -func (msa MultiSigActor) Exports() []interface{} { - return []interface{}{ - 1: msa.MultiSigConstructor, - 2: msa.Propose, - 3: msa.Approve, - 4: msa.Cancel, - //5: msa.ClearCompleted, - 6: msa.AddSigner, - 7: msa.RemoveSigner, - 8: msa.SwapSigner, - 9: msa.ChangeRequirement, - } -} - - - -func (MultiSigActor) MultiSigConstructor(act *types.Actor, vmctx types.VMContext, - params *MultiSigConstructorParams) ([]byte, ActorError) { - - shim := &runtimeShim{vmctx: vmctx} - return shim.shimCall(func() interface{} { - return (&samsig.MultiSigActor{}).Constructor(shim, params) - }) -} - - -func (msa MultiSigActor) Propose(act *types.Actor, vmctx types.VMContext, - params *MultiSigProposeParams) ([]byte, ActorError) { - - shim := &runtimeShim{vmctx: vmctx} - return shim.shimCall(func() interface{} { - return (&samsig.MultiSigActor{}).Propose(shim, params) - }) -} - - -func (msa MultiSigActor) Approve(act *types.Actor, vmctx types.VMContext, - params *MultiSigTxID) ([]byte, ActorError) { - - shim := &runtimeShim{vmctx: vmctx} - return shim.shimCall(func() interface{} { - return (&samsig.MultiSigActor{}).Approve(shim, params) - }) -} - -func (msa MultiSigActor) Cancel(act *types.Actor, vmctx types.VMContext, - params *MultiSigTxID) ([]byte, ActorError) { - - shim := &runtimeShim{vmctx: vmctx} - return shim.shimCall(func() interface{} { - return (&samsig.MultiSigActor{}).Cancel(shim, params) - }) -} - - -func (msa MultiSigActor) AddSigner(act *types.Actor, vmctx types.VMContext, - params *MultiSigAddSignerParam) ([]byte, ActorError) { - - shim := &runtimeShim{vmctx: vmctx} - return shim.shimCall(func() interface{} { - return (&samsig.MultiSigActor{}).AddSigner(shim, params) - }) -} - - -func (msa MultiSigActor) RemoveSigner(act *types.Actor, vmctx types.VMContext, - params *MultiSigRemoveSignerParam) ([]byte, ActorError) { - - shim := &runtimeShim{vmctx: vmctx} - return shim.shimCall(func() interface{} { - return (&samsig.MultiSigActor{}).RemoveSigner(shim, params) - }) -} - - -func (msa MultiSigActor) SwapSigner(act *types.Actor, vmctx types.VMContext, - params *MultiSigSwapSignerParams) ([]byte, ActorError) { - - shim := &runtimeShim{vmctx: vmctx} - return shim.shimCall(func() interface{} { - return (&samsig.MultiSigActor{}).SwapSigner(shim, params) - }) -} - - -func (msa MultiSigActor) ChangeRequirement(act *types.Actor, vmctx types.VMContext, - params *MultiSigChangeReqParams) ([]byte, ActorError) { - - shim := &runtimeShim{vmctx: vmctx} - return shim.shimCall(func() interface{} { - return (&samsig.MultiSigActor{}).ChangeNumApprovalsThreshold(shim, params) - }) -} -*/ diff --git a/chain/actors/actor_multisig_test.go b/chain/actors/actor_multisig_test.go index c7eef372c..3b68b25f6 100644 --- a/chain/actors/actor_multisig_test.go +++ b/chain/actors/actor_multisig_test.go @@ -3,6 +3,8 @@ package actors_test import ( "testing" + "github.com/filecoin-project/specs-actors/actors/builtin" + samsig "github.com/filecoin-project/specs-actors/actors/builtin/multisig" cbor "github.com/ipfs/go-ipld-cbor" "github.com/stretchr/testify/assert" cbg "github.com/whyrusleeping/cbor-gen" @@ -26,7 +28,7 @@ func TestMultiSigCreate(t *testing.T) { h := NewHarness(t, opts...) ret, _ := h.CreateActor(t, creatorAddr, actors.MultisigCodeCid, - &actors.MultiSigConstructorParams{ + &samsig.ConstructorParams{ Signers: []address.Address{creatorAddr, sig1Addr, sig2Addr}, NumApprovalsThreshold: 2, }) @@ -53,7 +55,7 @@ func TestMultiSigOps(t *testing.T) { HarnessAddr(&outsideAddr, 100000), HarnessActor(&multSigAddr, &creatorAddr, actors.MultisigCodeCid, func() cbg.CBORMarshaler { - return &actors.MultiSigConstructorParams{ + return &samsig.ConstructorParams{ Signers: []address.Address{creatorAddr, sig1Addr, sig2Addr}, NumApprovalsThreshold: 2, } @@ -73,22 +75,22 @@ func TestMultiSigOps(t *testing.T) { { // Transfer funds outside of multsig const sendVal = 1000 - ret, _ := h.Invoke(t, creatorAddr, multSigAddr, actors.MultiSigMethods.Propose, - &actors.MultiSigProposeParams{ + ret, _ := h.Invoke(t, creatorAddr, multSigAddr, uint64(builtin.MethodsMultisig.Propose), + &samsig.ProposeParams{ To: outsideAddr, Value: big.NewInt(sendVal), }) ApplyOK(t, ret) - var txIDParam actors.MultiSigTxID + var txIDParam samsig.TxnIDParams err := cbor.DecodeInto(ret.Return, &txIDParam.ID) assert.NoError(t, err, "decoding txid") - ret, _ = h.Invoke(t, outsideAddr, multSigAddr, actors.MultiSigMethods.Approve, + ret, _ = h.Invoke(t, outsideAddr, multSigAddr, uint64(builtin.MethodsMultisig.Approve), &txIDParam) 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, + ret2, _ := h.Invoke(t, sig1Addr, multSigAddr, uint64(builtin.MethodsMultisig.Approve), &txIDParam) ApplyOK(t, ret2) diff --git a/chain/types/message.go b/chain/types/message.go index 8d08dc53c..4ed940b67 100644 --- a/chain/types/message.go +++ b/chain/types/message.go @@ -22,7 +22,7 @@ type Message struct { GasPrice BigInt GasLimit BigInt - Method uint64 + Method uint64 // TODO: decide Params []byte } diff --git a/cli/multisig.go b/cli/multisig.go index 38d6b72ef..85a716cd9 100644 --- a/cli/multisig.go +++ b/cli/multisig.go @@ -12,17 +12,20 @@ import ( "text/tabwriter" "github.com/filecoin-project/go-address" - "github.com/filecoin-project/lotus/api" - "github.com/filecoin-project/lotus/api/apibstore" - actors "github.com/filecoin-project/lotus/chain/actors" - types "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/specs-actors/actors/abi" + "github.com/filecoin-project/specs-actors/actors/builtin" + samsig "github.com/filecoin-project/specs-actors/actors/builtin/multisig" cid "github.com/ipfs/go-cid" "github.com/ipfs/go-hamt-ipld" cbor "github.com/ipfs/go-ipld-cbor" cbg "github.com/whyrusleeping/cbor-gen" "golang.org/x/xerrors" "gopkg.in/urfave/cli.v2" + + "github.com/filecoin-project/lotus/api" + "github.com/filecoin-project/lotus/api/apibstore" + actors "github.com/filecoin-project/lotus/chain/actors" + types "github.com/filecoin-project/lotus/chain/types" ) var multisigCmd = &cli.Command{ @@ -90,7 +93,7 @@ var msigCreateCmd = &cli.Command{ } // Set up constructor parameters for multisig - msigParams := &actors.MultiSigConstructorParams{ + msigParams := &samsig.ConstructorParams{ Signers: addrs, NumApprovalsThreshold: required, } @@ -183,7 +186,7 @@ var msigInspectCmd = &cli.Command{ return err } - var mstate actors.MultiSigActorState + var mstate samsig.MultiSigActorState if err := mstate.UnmarshalCBOR(bytes.NewReader(obj)); err != nil { return err } @@ -223,7 +226,7 @@ var msigInspectCmd = &cli.Command{ }, } -func GetMultisigPending(ctx context.Context, lapi api.FullNode, hroot cid.Cid) (map[int64]*actors.MultiSigTransaction, error) { +func GetMultisigPending(ctx context.Context, lapi api.FullNode, hroot cid.Cid) (map[int64]*samsig.MultiSigTransaction, error) { bs := apibstore.NewAPIBlockstore(lapi) cst := cbor.NewCborStore(bs) @@ -232,10 +235,10 @@ func GetMultisigPending(ctx context.Context, lapi api.FullNode, hroot cid.Cid) ( return nil, err } - txs := make(map[int64]*actors.MultiSigTransaction) + txs := make(map[int64]*samsig.MultiSigTransaction) err = nd.ForEach(ctx, func(k string, val interface{}) error { d := val.(*cbg.Deferred) - var tx actors.MultiSigTransaction + var tx samsig.MultiSigTransaction if err := tx.UnmarshalCBOR(bytes.NewReader(d.Raw)); err != nil { return err } @@ -252,7 +255,7 @@ func GetMultisigPending(ctx context.Context, lapi api.FullNode, hroot cid.Cid) ( return txs, nil } -func state(tx *actors.MultiSigTransaction) string { +func state(tx *samsig.MultiSigTransaction) string { /* // TODO(why): I strongly disagree with not having these... but i need to move forward if tx.Complete { return "done" @@ -315,7 +318,7 @@ var msigProposeCmd = &cli.Command{ params = p } - enc, err := actors.SerializeParams(&actors.MultiSigProposeParams{ + enc, err := actors.SerializeParams(&samsig.ProposeParams{ To: dest, Value: abi.TokenAmount(types.BigInt(value)), Method: abi.MethodNum(method), @@ -344,7 +347,7 @@ var msigProposeCmd = &cli.Command{ To: msig, From: from, Value: types.NewInt(0), - Method: actors.MultiSigMethods.Propose, + Method: uint64(builtin.MethodsMultisig.Propose), Params: enc, GasLimit: types.NewInt(100000), GasPrice: types.NewInt(1), @@ -403,8 +406,8 @@ var msigApproveCmd = &cli.Command{ return err } - enc, err := actors.SerializeParams(&actors.MultiSigTxID{ - ID: actors.TxnID(txid), + enc, err := actors.SerializeParams(&samsig.TxnIDParams{ + ID: samsig.TxnID(txid), }) if err != nil { return err @@ -429,7 +432,7 @@ var msigApproveCmd = &cli.Command{ To: msig, From: from, Value: types.NewInt(0), - Method: actors.MultiSigMethods.Approve, + Method: uint64(builtin.MethodsMultisig.Approve), Params: enc, GasLimit: types.NewInt(100000), GasPrice: types.NewInt(1), diff --git a/go.mod b/go.mod index 40e12064f..60bbf4c55 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/filecoin-project/go-paramfetch v0.0.1 github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200203173614-42d67726bb62 github.com/filecoin-project/go-statestore v0.1.0 - github.com/filecoin-project/specs-actors v0.0.0-20200204204849-b1474eeb2fb5 + github.com/filecoin-project/specs-actors v0.0.0-20200206185502-20fc70907293 github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1 github.com/go-ole/go-ole v1.2.4 // indirect github.com/gorilla/mux v1.7.3 diff --git a/go.sum b/go.sum index bf45b106d..8c377f2b3 100644 --- a/go.sum +++ b/go.sum @@ -125,6 +125,8 @@ github.com/filecoin-project/go-statestore v0.1.0 h1:t56reH59843TwXHkMcwyuayStBIi github.com/filecoin-project/go-statestore v0.1.0/go.mod h1:LFc9hD+fRxPqiHiaqUEZOinUJB4WARkRfNl10O7kTnI= github.com/filecoin-project/specs-actors v0.0.0-20200204204849-b1474eeb2fb5 h1:rDyP5UTPFxdfS7D5I0XLdaQZZoNGYTic1X9ptKmRSlM= github.com/filecoin-project/specs-actors v0.0.0-20200204204849-b1474eeb2fb5/go.mod h1:9vrrnLVhF2Zz6R3VBI7lKxQYRvPpsc1FTUyNqCvuYME= +github.com/filecoin-project/specs-actors v0.0.0-20200206185502-20fc70907293 h1:k/xtj90OknHTVOJikJ9mnf81UN2BaflS3R83OUg3BJM= +github.com/filecoin-project/specs-actors v0.0.0-20200206185502-20fc70907293/go.mod h1:gx4vDpIVf3AfF23iyVn9PNQhKy7wGQDrhxNyCHDzG8I= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1 h1:EzDjxMg43q1tA2c0MV3tNbaontnHLplHyFF6M5KiVP0= diff --git a/node/impl/full/state.go b/node/impl/full/state.go index b2b7c1a67..d380c4cfc 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -7,6 +7,7 @@ import ( "strconv" "github.com/filecoin-project/go-amt-ipld/v2" + samsig "github.com/filecoin-project/specs-actors/actors/builtin/multisig" cid "github.com/ipfs/go-cid" "github.com/ipfs/go-hamt-ipld" @@ -416,7 +417,7 @@ func (a *StateAPI) MsigGetAvailableBalance(ctx context.Context, addr address.Add ts = a.Chain.GetHeaviestTipSet() } - var st actors.MultiSigActorState + var st samsig.MultiSigActorState act, err := a.StateManager.LoadActorState(ctx, addr, &st, ts) if err != nil { return types.EmptyInt, xerrors.Errorf("failed to load multisig actor state: %w", err) From 3d3c1dbbb47b95fd7cf18538995e2e011660022f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 6 Feb 2020 20:56:35 +0100 Subject: [PATCH 2/3] import key algs in wallet --- chain/wallet/wallet.go | 4 ++++ cmd/lotus-seed/main.go | 6 ++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/chain/wallet/wallet.go b/chain/wallet/wallet.go index 3e5d506a8..df860b045 100644 --- a/chain/wallet/wallet.go +++ b/chain/wallet/wallet.go @@ -10,6 +10,10 @@ import ( "golang.org/x/xerrors" "github.com/filecoin-project/go-address" + + _ "github.com/filecoin-project/lotus/lib/sigs/bls" + _ "github.com/filecoin-project/lotus/lib/sigs/secp" + "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/lib/sigs" ) diff --git a/cmd/lotus-seed/main.go b/cmd/lotus-seed/main.go index f6e351508..3480619d7 100644 --- a/cmd/lotus-seed/main.go +++ b/cmd/lotus-seed/main.go @@ -1,15 +1,12 @@ package main import ( + "encoding/json" "fmt" "os" "path/filepath" - "encoding/json" - sectorbuilder "github.com/filecoin-project/go-sectorbuilder" - _ "github.com/filecoin-project/lotus/lib/sigs/bls" - _ "github.com/filecoin-project/lotus/lib/sigs/secp" "github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore/namespace" @@ -20,6 +17,7 @@ import ( "gopkg.in/urfave/cli.v2" "github.com/filecoin-project/go-address" + "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/cmd/lotus-seed/seed" "github.com/filecoin-project/lotus/genesis" From fc8bf8c15dfccfb1c7c249184be8364f162ebe62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 6 Feb 2020 20:57:13 +0100 Subject: [PATCH 3/3] Fix validation with extracted msig --- chain/validation/message.go | 20 +++++++++++--------- go.sum | 2 -- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/chain/validation/message.go b/chain/validation/message.go index 2e497184f..d0f6201ea 100644 --- a/chain/validation/message.go +++ b/chain/validation/message.go @@ -10,7 +10,9 @@ import ( vaddress "github.com/filecoin-project/chain-validation/pkg/state/address" vtypes "github.com/filecoin-project/chain-validation/pkg/state/types" + "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/go-address" + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/types" ) @@ -83,14 +85,14 @@ var methods = []uint64{ vchain.StorageMinerGetPeerID: actors.MAMethods.GetPeerID, vchain.StorageMinerGetSectorSize: actors.MAMethods.GetSectorSize, - vchain.MultiSigConstructor: actors.MultiSigMethods.MultiSigConstructor, - vchain.MultiSigPropose: actors.MultiSigMethods.Propose, - vchain.MultiSigApprove: actors.MultiSigMethods.Approve, - vchain.MultiSigCancel: actors.MultiSigMethods.Cancel, - vchain.MultiSigClearCompleted: actors.MultiSigMethods.ClearCompleted, - vchain.MultiSigAddSigner: actors.MultiSigMethods.AddSigner, - vchain.MultiSigRemoveSigner: actors.MultiSigMethods.RemoveSigner, - vchain.MultiSigSwapSigner: actors.MultiSigMethods.SwapSigner, - vchain.MultiSigChangeRequirement: actors.MultiSigMethods.ChangeRequirement, + vchain.MultiSigConstructor: uint64(builtin.MethodsMultisig.Constructor), + vchain.MultiSigPropose: uint64(builtin.MethodsMultisig.Propose), + vchain.MultiSigApprove: uint64(builtin.MethodsMultisig.Approve), + vchain.MultiSigCancel: uint64(builtin.MethodsMultisig.Cancel), + vchain.MultiSigClearCompleted: uint64(builtin.MethodsMultisig.ClearCompleted), + vchain.MultiSigAddSigner: uint64(builtin.MethodsMultisig.AddSigner), + vchain.MultiSigRemoveSigner: uint64(builtin.MethodsMultisig.RemoveSigner), + vchain.MultiSigSwapSigner: uint64(builtin.MethodsMultisig.SwapSigner), + vchain.MultiSigChangeRequirement: uint64(builtin.MethodsMultisig.ChangeNumApprovalsThreshold), // More to follow... } diff --git a/go.sum b/go.sum index 8c377f2b3..7470c18b1 100644 --- a/go.sum +++ b/go.sum @@ -123,8 +123,6 @@ github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200203173614-42d67726bb6 github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200203173614-42d67726bb62/go.mod h1:jNGVCDihkMFnraYVLH1xl4ceZQVxx/u4dOORrTKeRi0= github.com/filecoin-project/go-statestore v0.1.0 h1:t56reH59843TwXHkMcwyuayStBIiWBRilQjQ+5IiwdQ= github.com/filecoin-project/go-statestore v0.1.0/go.mod h1:LFc9hD+fRxPqiHiaqUEZOinUJB4WARkRfNl10O7kTnI= -github.com/filecoin-project/specs-actors v0.0.0-20200204204849-b1474eeb2fb5 h1:rDyP5UTPFxdfS7D5I0XLdaQZZoNGYTic1X9ptKmRSlM= -github.com/filecoin-project/specs-actors v0.0.0-20200204204849-b1474eeb2fb5/go.mod h1:9vrrnLVhF2Zz6R3VBI7lKxQYRvPpsc1FTUyNqCvuYME= github.com/filecoin-project/specs-actors v0.0.0-20200206185502-20fc70907293 h1:k/xtj90OknHTVOJikJ9mnf81UN2BaflS3R83OUg3BJM= github.com/filecoin-project/specs-actors v0.0.0-20200206185502-20fc70907293/go.mod h1:gx4vDpIVf3AfF23iyVn9PNQhKy7wGQDrhxNyCHDzG8I= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=