From 7b75b120cd9fd5625974ff5e718b0293f004b00a Mon Sep 17 00:00:00 2001 From: simlecode Date: Wed, 22 Dec 2021 17:50:43 +0800 Subject: [PATCH 1/2] more type and function --- pkg/chainsync/exchange/cbor_gen.go | 647 -------------------- pkg/testhelpers/empty_cid/empty_cid.go | 36 -- venus-shared/api/chain/types.go | 16 +- venus-shared/api/chain/v0/syncer.go | 2 +- venus-shared/api/chain/v0/wallet.go | 2 +- venus-shared/api/chain/v1/market.go | 1 - venus-shared/api/chain/v1/mining.go | 2 +- venus-shared/api/chain/v1/syncer.go | 2 +- venus-shared/api/chain/v1/wallet.go | 2 +- venus-shared/chain/actor.go | 24 + venus-shared/chain/block_header.go | 26 + venus-shared/chain/block_message.go | 9 + venus-shared/chain/block_message_test.go | 9 + venus-shared/chain/chain_info.go | 31 + venus-shared/chain/message.go | 21 + venus-shared/chain/param.go | 14 + venus-shared/chain/shared_func.go | 9 + venus-shared/chain/signed_message.go | 6 + venus-shared/chain/signer.go | 14 + venus-shared/chain/tipset.go | 16 + venus-shared/chain/tipset_key.go | 89 +++ venus-shared/compatible-checks/api-diff.txt | 134 ---- venus-shared/go.mod | 2 + venus-shared/wallet/key_info.go | 33 + venus-shared/wallet/msg_meta.go | 19 +- 25 files changed, 328 insertions(+), 838 deletions(-) delete mode 100644 pkg/chainsync/exchange/cbor_gen.go delete mode 100644 pkg/testhelpers/empty_cid/empty_cid.go create mode 100644 venus-shared/chain/block_message.go create mode 100644 venus-shared/chain/block_message_test.go create mode 100644 venus-shared/chain/chain_info.go create mode 100644 venus-shared/chain/signer.go diff --git a/pkg/chainsync/exchange/cbor_gen.go b/pkg/chainsync/exchange/cbor_gen.go deleted file mode 100644 index 81ec6b39df..0000000000 --- a/pkg/chainsync/exchange/cbor_gen.go +++ /dev/null @@ -1,647 +0,0 @@ -// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT. - -package exchange - -import ( - "fmt" - "io" - "sort" - - "github.com/filecoin-project/venus/pkg/types" - cid "github.com/ipfs/go-cid" - cbg "github.com/whyrusleeping/cbor-gen" - xerrors "golang.org/x/xerrors" -) - -var _ = xerrors.Errorf -var _ = cid.Undef -var _ = sort.Sort - -var lengthBufRequest = []byte{131} - -func (t *Request) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write(lengthBufRequest); err != nil { - return err - } - - scratch := make([]byte, 9) - - // t.Head ([]cid.Cid) (slice) - if len(t.Head) > cbg.MaxLength { - return xerrors.Errorf("Slice value in field t.Head was too long") - } - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Head))); err != nil { - return err - } - for _, v := range t.Head { - if err := cbg.WriteCidBuf(scratch, w, v); err != nil { - return xerrors.Errorf("failed writing cid field t.Head: %w", err) - } - } - - // t.Length (uint64) (uint64) - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Length)); err != nil { - return err - } - - // t.Options (uint64) (uint64) - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Options)); err != nil { - return err - } - - return nil -} - -func (t *Request) UnmarshalCBOR(r io.Reader) error { - *t = Request{} - - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) - - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) - if err != nil { - return err - } - if maj != cbg.MajArray { - return fmt.Errorf("cbor input should be of type array") - } - - if extra != 3 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - // t.Head ([]cid.Cid) (slice) - - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) - if err != nil { - return err - } - - if extra > cbg.MaxLength { - return fmt.Errorf("t.Head: array too large (%d)", extra) - } - - if maj != cbg.MajArray { - return fmt.Errorf("expected cbor array") - } - - if extra > 0 { - t.Head = make([]cid.Cid, extra) - } - - for i := 0; i < int(extra); i++ { - - c, err := cbg.ReadCid(br) - if err != nil { - return xerrors.Errorf("reading cid field t.Head failed: %w", err) - } - t.Head[i] = c - } - - // t.Length (uint64) (uint64) - - { - - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) - if err != nil { - return err - } - if maj != cbg.MajUnsignedInt { - return fmt.Errorf("wrong type for uint64 field") - } - t.Length = uint64(extra) - - } - // t.Options (uint64) (uint64) - - { - - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) - if err != nil { - return err - } - if maj != cbg.MajUnsignedInt { - return fmt.Errorf("wrong type for uint64 field") - } - t.Options = uint64(extra) - - } - return nil -} - -var lengthBufResponse = []byte{131} - -func (t *Response) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write(lengthBufResponse); err != nil { - return err - } - - scratch := make([]byte, 9) - - // t.Status (exchange.status) (uint64) - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Status)); err != nil { - return err - } - - // t.ErrorMessage (string) (string) - if len(t.ErrorMessage) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.ErrorMessage was too long") - } - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.ErrorMessage))); err != nil { - return err - } - if _, err := io.WriteString(w, string(t.ErrorMessage)); err != nil { - return err - } - - // t.Chain ([]*exchange.BSTipSet) (slice) - if len(t.Chain) > cbg.MaxLength { - return xerrors.Errorf("Slice value in field t.Chain was too long") - } - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Chain))); err != nil { - return err - } - for _, v := range t.Chain { - if err := v.MarshalCBOR(w); err != nil { - return err - } - } - return nil -} - -func (t *Response) UnmarshalCBOR(r io.Reader) error { - *t = Response{} - - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) - - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) - if err != nil { - return err - } - if maj != cbg.MajArray { - return fmt.Errorf("cbor input should be of type array") - } - - if extra != 3 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - // t.Status (exchange.status) (uint64) - - { - - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) - if err != nil { - return err - } - if maj != cbg.MajUnsignedInt { - return fmt.Errorf("wrong type for uint64 field") - } - t.Status = status(extra) - - } - // t.ErrorMessage (string) (string) - - { - sval, err := cbg.ReadStringBuf(br, scratch) - if err != nil { - return err - } - - t.ErrorMessage = string(sval) - } - // t.Chain ([]*exchange.BSTipSet) (slice) - - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) - if err != nil { - return err - } - - if extra > cbg.MaxLength { - return fmt.Errorf("t.Chain: array too large (%d)", extra) - } - - if maj != cbg.MajArray { - return fmt.Errorf("expected cbor array") - } - - if extra > 0 { - t.Chain = make([]*BSTipSet, extra) - } - - for i := 0; i < int(extra); i++ { - - var v BSTipSet - if err := v.UnmarshalCBOR(br); err != nil { - return err - } - - t.Chain[i] = &v - } - - return nil -} - -var lengthBufCompactedMessages = []byte{132} - -func (t *CompactedMessages) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write(lengthBufCompactedMessages); err != nil { - return err - } - - scratch := make([]byte, 9) - - // t.Bls ([]*types.UnsignedMessage) (slice) - if len(t.Bls) > cbg.MaxLength { - return xerrors.Errorf("Slice value in field t.Bls was too long") - } - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Bls))); err != nil { - return err - } - for _, v := range t.Bls { - if err := v.MarshalCBOR(w); err != nil { - return err - } - } - - // t.BlsIncludes ([][]uint64) (slice) - if len(t.BlsIncludes) > cbg.MaxLength { - return xerrors.Errorf("Slice value in field t.BlsIncludes was too long") - } - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.BlsIncludes))); err != nil { - return err - } - for _, v := range t.BlsIncludes { - if len(v) > cbg.MaxLength { - return xerrors.Errorf("Slice value in field v was too long") - } - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(v))); err != nil { - return err - } - for _, v := range v { - if err := cbg.CborWriteHeader(w, cbg.MajUnsignedInt, uint64(v)); err != nil { - return err - } - } - } - - // t.Secpk ([]*types.SignedMessage) (slice) - if len(t.Secpk) > cbg.MaxLength { - return xerrors.Errorf("Slice value in field t.Secpk was too long") - } - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Secpk))); err != nil { - return err - } - for _, v := range t.Secpk { - if err := v.MarshalCBOR(w); err != nil { - return err - } - } - - // t.SecpkIncludes ([][]uint64) (slice) - if len(t.SecpkIncludes) > cbg.MaxLength { - return xerrors.Errorf("Slice value in field t.SecpkIncludes was too long") - } - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.SecpkIncludes))); err != nil { - return err - } - for _, v := range t.SecpkIncludes { - if len(v) > cbg.MaxLength { - return xerrors.Errorf("Slice value in field v was too long") - } - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(v))); err != nil { - return err - } - for _, v := range v { - if err := cbg.CborWriteHeader(w, cbg.MajUnsignedInt, uint64(v)); err != nil { - return err - } - } - } - return nil -} - -func (t *CompactedMessages) UnmarshalCBOR(r io.Reader) error { - *t = CompactedMessages{} - - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) - - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) - if err != nil { - return err - } - if maj != cbg.MajArray { - return fmt.Errorf("cbor input should be of type array") - } - - if extra != 4 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - // t.Bls ([]*types.UnsignedMessage) (slice) - - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) - if err != nil { - return err - } - - if extra > cbg.MaxLength { - return fmt.Errorf("t.Bls: array too large (%d)", extra) - } - - if maj != cbg.MajArray { - return fmt.Errorf("expected cbor array") - } - - if extra > 0 { - t.Bls = make([]*types.UnsignedMessage, extra) - } - - for i := 0; i < int(extra); i++ { - - var v types.UnsignedMessage - if err := v.UnmarshalCBOR(br); err != nil { - return err - } - - t.Bls[i] = &v - } - - // t.BlsIncludes ([][]uint64) (slice) - - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) - if err != nil { - return err - } - - if extra > cbg.MaxLength { - return fmt.Errorf("t.BlsIncludes: array too large (%d)", extra) - } - - if maj != cbg.MajArray { - return fmt.Errorf("expected cbor array") - } - - if extra > 0 { - t.BlsIncludes = make([][]uint64, extra) - } - - for i := 0; i < int(extra); i++ { - { - var maj byte - var extra uint64 - var err error - - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) - if err != nil { - return err - } - - if extra > cbg.MaxLength { - return fmt.Errorf("t.BlsIncludes[i]: array too large (%d)", extra) - } - - if maj != cbg.MajArray { - return fmt.Errorf("expected cbor array") - } - - if extra > 0 { - t.BlsIncludes[i] = make([]uint64, extra) - } - - for j := 0; j < int(extra); j++ { - - maj, val, err := cbg.CborReadHeaderBuf(br, scratch) - if err != nil { - return xerrors.Errorf("failed to read uint64 for t.BlsIncludes[i] slice: %w", err) - } - - if maj != cbg.MajUnsignedInt { - return xerrors.Errorf("value read for array t.BlsIncludes[i] was not a uint, instead got %d", maj) - } - - t.BlsIncludes[i][j] = uint64(val) - } - - } - } - - // t.Secpk ([]*types.SignedMessage) (slice) - - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) - if err != nil { - return err - } - - if extra > cbg.MaxLength { - return fmt.Errorf("t.Secpk: array too large (%d)", extra) - } - - if maj != cbg.MajArray { - return fmt.Errorf("expected cbor array") - } - - if extra > 0 { - t.Secpk = make([]*types.SignedMessage, extra) - } - - for i := 0; i < int(extra); i++ { - - var v types.SignedMessage - if err := v.UnmarshalCBOR(br); err != nil { - return err - } - - t.Secpk[i] = &v - } - - // t.SecpkIncludes ([][]uint64) (slice) - - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) - if err != nil { - return err - } - - if extra > cbg.MaxLength { - return fmt.Errorf("t.SecpkIncludes: array too large (%d)", extra) - } - - if maj != cbg.MajArray { - return fmt.Errorf("expected cbor array") - } - - if extra > 0 { - t.SecpkIncludes = make([][]uint64, extra) - } - - for i := 0; i < int(extra); i++ { - { - var maj byte - var extra uint64 - var err error - - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) - if err != nil { - return err - } - - if extra > cbg.MaxLength { - return fmt.Errorf("t.SecpkIncludes[i]: array too large (%d)", extra) - } - - if maj != cbg.MajArray { - return fmt.Errorf("expected cbor array") - } - - if extra > 0 { - t.SecpkIncludes[i] = make([]uint64, extra) - } - - for j := 0; j < int(extra); j++ { - - maj, val, err := cbg.CborReadHeaderBuf(br, scratch) - if err != nil { - return xerrors.Errorf("failed to read uint64 for t.SecpkIncludes[i] slice: %w", err) - } - - if maj != cbg.MajUnsignedInt { - return xerrors.Errorf("value read for array t.SecpkIncludes[i] was not a uint, instead got %d", maj) - } - - t.SecpkIncludes[i][j] = uint64(val) - } - - } - } - - return nil -} - -var lengthBufBSTipSet = []byte{130} - -func (t *BSTipSet) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write(lengthBufBSTipSet); err != nil { - return err - } - - scratch := make([]byte, 9) - - // t.Blocks ([]*types.BlockHeader) (slice) - if len(t.Blocks) > cbg.MaxLength { - return xerrors.Errorf("Slice value in field t.Blocks was too long") - } - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Blocks))); err != nil { - return err - } - for _, v := range t.Blocks { - if err := v.MarshalCBOR(w); err != nil { - return err - } - } - - // t.Messages (exchange.CompactedMessages) (struct) - if err := t.Messages.MarshalCBOR(w); err != nil { - return err - } - return nil -} - -func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error { - *t = BSTipSet{} - - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) - - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) - if err != nil { - return err - } - if maj != cbg.MajArray { - return fmt.Errorf("cbor input should be of type array") - } - - if extra != 2 { - return fmt.Errorf("cbor input had wrong number of fields") - } - - // t.Blocks ([]*types.BlockHeader) (slice) - - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) - if err != nil { - return err - } - - if extra > cbg.MaxLength { - return fmt.Errorf("t.Blocks: array too large (%d)", extra) - } - - if maj != cbg.MajArray { - return fmt.Errorf("expected cbor array") - } - - if extra > 0 { - t.Blocks = make([]*types.BlockHeader, extra) - } - - for i := 0; i < int(extra); i++ { - - var v types.BlockHeader - if err := v.UnmarshalCBOR(br); err != nil { - return err - } - - t.Blocks[i] = &v - } - - // t.Messages (exchange.CompactedMessages) (struct) - - { - - b, err := br.ReadByte() - if err != nil { - return err - } - if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { - return err - } - t.Messages = new(CompactedMessages) - if err := t.Messages.UnmarshalCBOR(br); err != nil { - return xerrors.Errorf("unmarshaling t.Messages pointer: %w", err) - } - } - - } - return nil -} diff --git a/pkg/testhelpers/empty_cid/empty_cid.go b/pkg/testhelpers/empty_cid/empty_cid.go deleted file mode 100644 index a42a0610a5..0000000000 --- a/pkg/testhelpers/empty_cid/empty_cid.go +++ /dev/null @@ -1,36 +0,0 @@ -package emptycid - -import ( - "context" - "github.com/filecoin-project/specs-actors/actors/util/adt" - "github.com/filecoin-project/venus/pkg/types" - "github.com/filecoin-project/venus/pkg/util/blockstoreutil" - "github.com/ipfs/go-cid" - "github.com/ipfs/go-datastore" - cbor "github.com/ipfs/go-ipld-cbor" -) - -// EmptyMessagesCID is the cid of an empty collection of messages. -var EmptyMessagesCID cid.Cid - -// EmptyReceiptsCID is the cid of an empty collection of receipts. -var EmptyReceiptsCID cid.Cid - -// EmptyTxMetaCID is the cid of a TxMeta wrapping empty cids -var EmptyTxMetaCID cid.Cid - -func init() { - tmpCst := cbor.NewCborStore(blockstoreutil.NewBlockstore(datastore.NewMapDatastore())) - emptyAmt := adt.MakeEmptyArray(adt.WrapStore(context.Background(), tmpCst)) - emptyAMTCid, err := emptyAmt.Root() - if err != nil { - panic("could not create CID for empty AMT") - } - - EmptyMessagesCID = emptyAMTCid - EmptyReceiptsCID = emptyAMTCid - EmptyTxMetaCID, err = tmpCst.Put(context.Background(), &types.TxMeta{SecpRoot: EmptyMessagesCID, BLSRoot: EmptyMessagesCID}) - if err != nil { - panic("could not create CID for empty TxMeta") - } -} diff --git a/venus-shared/api/chain/types.go b/venus-shared/api/chain/types.go index 7cf1552e71..6cd60002e2 100644 --- a/venus-shared/api/chain/types.go +++ b/venus-shared/api/chain/types.go @@ -9,7 +9,6 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/ipfs/go-cid" - "github.com/libp2p/go-libp2p-core/peer" "github.com/filecoin-project/venus/venus-shared/actors/builtin" "github.com/filecoin-project/venus/venus-shared/actors/builtin/market" @@ -77,6 +76,8 @@ type Deadline struct { DisputableProofCount uint64 } +var MarketBalanceNil = MarketBalance{} + type MarketDeal struct { Proposal market.DealProposal State market.DealState @@ -139,12 +140,12 @@ type BlockTemplate struct { } type EstimateMessage struct { - Msg *Message + Msg *chain.Message Spec *MessageSendSpec } type EstimateResult struct { - Msg *Message + Msg *chain.Message Err string } @@ -185,15 +186,6 @@ type ChannelAvailableFunds struct { VoucherReedeemedAmt chain.BigInt } -// ChainInfo is used to track metadata about a peer and its chain. -type ChainInfo struct { - // The originator of the TipSetKey propagation wave. - Source peer.ID - // The peer that sent us the TipSetKey message. - Sender peer.ID - Head *chain.TipSet -} - type SyncState struct { ActiveSyncs []ActiveSync diff --git a/venus-shared/api/chain/v0/syncer.go b/venus-shared/api/chain/v0/syncer.go index 60932dc8f9..51acbd7cd2 100644 --- a/venus-shared/api/chain/v0/syncer.go +++ b/venus-shared/api/chain/v0/syncer.go @@ -11,7 +11,7 @@ import ( type ISyncer interface { // Rule[perm:write] - ChainSyncHandleNewTipSet(ctx context.Context, ci *chain2.ChainInfo) error + ChainSyncHandleNewTipSet(ctx context.Context, ci *chain.ChainInfo) error // Rule[perm:admin] SetConcurrent(ctx context.Context, concurrent int64) error diff --git a/venus-shared/api/chain/v0/wallet.go b/venus-shared/api/chain/v0/wallet.go index 47f36a0c03..5989045826 100644 --- a/venus-shared/api/chain/v0/wallet.go +++ b/venus-shared/api/chain/v0/wallet.go @@ -5,7 +5,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - crypto "github.com/filecoin-project/go-state-types/crypto" + "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/venus/venus-shared/chain" "github.com/filecoin-project/venus/venus-shared/wallet" diff --git a/venus-shared/api/chain/v1/market.go b/venus-shared/api/chain/v1/market.go index 27583a26ce..fc0119d888 100644 --- a/venus-shared/api/chain/v1/market.go +++ b/venus-shared/api/chain/v1/market.go @@ -4,7 +4,6 @@ import ( "context" chain2 "github.com/filecoin-project/venus/venus-shared/api/chain" - "github.com/filecoin-project/venus/venus-shared/chain" ) diff --git a/venus-shared/api/chain/v1/mining.go b/venus-shared/api/chain/v1/mining.go index e9f4b72a1f..abbebb9da9 100644 --- a/venus-shared/api/chain/v1/mining.go +++ b/venus-shared/api/chain/v1/mining.go @@ -5,8 +5,8 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - chain2 "github.com/filecoin-project/venus/venus-shared/api/chain" + chain2 "github.com/filecoin-project/venus/venus-shared/api/chain" "github.com/filecoin-project/venus/venus-shared/chain" ) diff --git a/venus-shared/api/chain/v1/syncer.go b/venus-shared/api/chain/v1/syncer.go index 104bc7ab08..fc1471f908 100644 --- a/venus-shared/api/chain/v1/syncer.go +++ b/venus-shared/api/chain/v1/syncer.go @@ -11,7 +11,7 @@ import ( type ISyncer interface { // Rule[perm:write] - ChainSyncHandleNewTipSet(ctx context.Context, ci *chain2.ChainInfo) error + ChainSyncHandleNewTipSet(ctx context.Context, ci *chain.ChainInfo) error // Rule[perm:admin] SetConcurrent(ctx context.Context, concurrent int64) error diff --git a/venus-shared/api/chain/v1/wallet.go b/venus-shared/api/chain/v1/wallet.go index b1998aff65..d45d69bade 100644 --- a/venus-shared/api/chain/v1/wallet.go +++ b/venus-shared/api/chain/v1/wallet.go @@ -5,7 +5,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - crypto "github.com/filecoin-project/go-state-types/crypto" + "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/venus/venus-shared/chain" "github.com/filecoin-project/venus/venus-shared/wallet" diff --git a/venus-shared/chain/actor.go b/venus-shared/chain/actor.go index b38937cc86..2d20c6cfc1 100644 --- a/venus-shared/chain/actor.go +++ b/venus-shared/chain/actor.go @@ -1,10 +1,14 @@ package chain import ( + "errors" + "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" ) +var ErrActorNotFound = errors.New("actor not found") + // Actor is the central abstraction of entities in the system. // // Both individual accounts, as well as contracts (user & system level) are @@ -33,3 +37,23 @@ type Actor struct { // Balance is the amount of attoFIL in the actor's account. Balance abi.TokenAmount } + +// NewActor constructs a new actor. +func NewActor(code cid.Cid, balance abi.TokenAmount, head cid.Cid) *Actor { + return &Actor{ + Code: code, + Nonce: 0, + Balance: balance, + Head: head, + } +} + +// Empty tests whether the actor's code is defined. +func (t *Actor) Empty() bool { + return !t.Code.Defined() +} + +// IncrementSeqNum increments the seq number. +func (t *Actor) IncrementSeqNum() { + t.Nonce = t.Nonce + 1 +} diff --git a/venus-shared/chain/block_header.go b/venus-shared/chain/block_header.go index dc2515bbe7..cc17a3d4e4 100644 --- a/venus-shared/chain/block_header.go +++ b/venus-shared/chain/block_header.go @@ -12,6 +12,8 @@ import ( proof2 "github.com/filecoin-project/specs-actors/v2/actors/runtime/proof" blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-cid" + cbor "github.com/ipfs/go-ipld-cbor" + node "github.com/ipfs/go-ipld-format" ) // DecodeBlock decodes raw cbor bytes into a BlockHeader. @@ -168,3 +170,27 @@ func (b *BlockHeader) SetValidated() { func (b *BlockHeader) IsValidated() bool { return b.validated } + +// ToNode converts the BlockHeader to an IPLD node. +func (b *BlockHeader) ToNode() node.Node { + buf := new(bytes.Buffer) + err := b.MarshalCBOR(buf) + if err != nil { + panic(err) + } + data := buf.Bytes() + c, err := DefaultCidBuilder.Sum(data) + if err != nil { + panic(err) + } + + blk, err := blocks.NewBlockWithCid(data, c) + if err != nil { + panic(err) + } + n, err := cbor.DecodeBlock(blk) + if err != nil { + panic(err) + } + return n +} diff --git a/venus-shared/chain/block_message.go b/venus-shared/chain/block_message.go new file mode 100644 index 0000000000..c631f35a81 --- /dev/null +++ b/venus-shared/chain/block_message.go @@ -0,0 +1,9 @@ +package chain + +// BlockMessagesInfo contains messages for one newBlock in a tipset. +type BlockMessagesInfo struct { //nolint + BlsMessages []ChainMsg + SecpkMessages []ChainMsg + + Block *BlockHeader +} diff --git a/venus-shared/chain/block_message_test.go b/venus-shared/chain/block_message_test.go new file mode 100644 index 0000000000..25b93fa8a0 --- /dev/null +++ b/venus-shared/chain/block_message_test.go @@ -0,0 +1,9 @@ +package chain + +import ( + "testing" +) + +func TestBlockMessageBasic(t *testing.T) { + // todo +} diff --git a/venus-shared/chain/chain_info.go b/venus-shared/chain/chain_info.go new file mode 100644 index 0000000000..e062c73e09 --- /dev/null +++ b/venus-shared/chain/chain_info.go @@ -0,0 +1,31 @@ +package chain + +import ( + "fmt" + + "github.com/libp2p/go-libp2p-core/peer" +) + +// ChainInfo is used to track metadata about a peer and its chain. +type ChainInfo struct { + // The originator of the TipSetKey propagation wave. + Source peer.ID + // The peer that sent us the TipSetKey message. + Sender peer.ID + Head *TipSet +} + +// NewChainInfo creates a chain info from a peer id a head tipset key and a +// chain height. +func NewChainInfo(source peer.ID, sender peer.ID, head *TipSet) *ChainInfo { + return &ChainInfo{ + Source: source, + Sender: sender, + Head: head, + } +} + +// String returns a human-readable string representation of a chain info +func (i *ChainInfo) String() string { + return fmt.Sprintf("{source=%s sender:%s height=%d head=%s}", i.Source, i.Sender, i.Head.Height(), i.Head.Key()) +} diff --git a/venus-shared/chain/message.go b/venus-shared/chain/message.go index c016b4f829..6b072f350d 100644 --- a/venus-shared/chain/message.go +++ b/venus-shared/chain/message.go @@ -7,6 +7,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/cbor" "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/venus/venus-shared/chain/params" blocks "github.com/ipfs/go-block-format" @@ -15,6 +16,16 @@ import ( const MessageVersion = 0 +type ChainMsg interface { + Cid() cid.Cid + VMMessage() *Message + ToStorageBlock() (blocks.Block, error) + // FIXME: This is the *message* length, this name is misleading. + ChainLength() int + cbor.Marshaler + cbor.Unmarshaler +} + func DecodeMessage(b []byte) (*Message, error) { var msg Message if err := msg.UnmarshalCBOR(bytes.NewReader(b)); err != nil { @@ -188,3 +199,13 @@ func (m *Message) ValidForBlockInclusion(minGas int64, version network.Version) return nil } + +func (m *Message) VMMessage() *Message { + return m +} + +func (m *Message) RequiredFunds() abi.TokenAmount { + return abi.TokenAmount{Int: BigMul(BigInt{Int: m.GasFeeCap.Int}, NewInt(uint64(m.GasLimit))).Int} +} + +var _ ChainMsg = (*Message)(nil) diff --git a/venus-shared/chain/param.go b/venus-shared/chain/param.go index 4554286c06..9a8e7f78f7 100644 --- a/venus-shared/chain/param.go +++ b/venus-shared/chain/param.go @@ -3,7 +3,12 @@ package chain import ( "math/big" + "github.com/filecoin-project/go-state-types/abi" + big2 "github.com/filecoin-project/go-state-types/big" + "github.com/ipfs/go-cid" + mh "github.com/multiformats/go-multihash" + "github.com/filecoin-project/venus/venus-shared/chain/params" ) @@ -15,3 +20,12 @@ var ( var TotalFilecoinInt = FromFil(params.FilBase) var ZeroAddress = MustParseAddress("f3yaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaby2smx7a") + +var EmptyTokenAmount = abi.TokenAmount{} + +// The multihash function identifier to use for content addresses. +const DefaultHashFunction = uint64(mh.BLAKE2B_MIN + 31) + +// A builder for all blockchain CIDs. +// Note that sector commitments use a different scheme. +var DefaultCidBuilder = cid.V1Builder{Codec: cid.DagCBOR, MhType: DefaultHashFunction} diff --git a/venus-shared/chain/shared_func.go b/venus-shared/chain/shared_func.go index 55a65665a6..23d357e619 100644 --- a/venus-shared/chain/shared_func.go +++ b/venus-shared/chain/shared_func.go @@ -2,6 +2,7 @@ package chain import ( "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" ) @@ -22,3 +23,11 @@ func MustParseCid(c string) cid.Cid { return ret } + +func NewGasFeeCap(price int64) abi.TokenAmount { + return abi.NewTokenAmount(price) +} + +func NewGasPremium(price int64) abi.TokenAmount { + return abi.NewTokenAmount(price) +} diff --git a/venus-shared/chain/signed_message.go b/venus-shared/chain/signed_message.go index 3506daa99c..7e719c82c4 100644 --- a/venus-shared/chain/signed_message.go +++ b/venus-shared/chain/signed_message.go @@ -102,3 +102,9 @@ func (smsg *SignedMessage) String() string { return fmt.Sprintf("SignedMessage cid=[%v]: %s", c, string(js)) } + +func (smsg *SignedMessage) VMMessage() *Message { + return &smsg.Message +} + +var _ ChainMsg = (*SignedMessage)(nil) diff --git a/venus-shared/chain/signer.go b/venus-shared/chain/signer.go new file mode 100644 index 0000000000..f50ad85457 --- /dev/null +++ b/venus-shared/chain/signer.go @@ -0,0 +1,14 @@ +package chain + +import ( + "context" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/crypto" +) + +// Signer signs data with a private key obtained internally from a provided address. +type Signer interface { + SignBytes(ctx context.Context, data []byte, addr address.Address) (*crypto.Signature, error) + HasAddress(ctx context.Context, addr address.Address) (bool, error) +} diff --git a/venus-shared/chain/tipset.go b/venus-shared/chain/tipset.go index 90ad4412ec..f186337c8b 100644 --- a/venus-shared/chain/tipset.go +++ b/venus-shared/chain/tipset.go @@ -15,6 +15,9 @@ type blockHeaderWithCid struct { b *BlockHeader } +// UndefTipSet is a singleton representing a nil or undefined tipset. +var UndefTipSet = &TipSet{} + func NewTipSet(bhs []*BlockHeader) (*TipSet, error) { if len(bhs) == 0 { return nil, fmt.Errorf("no blocks for tipset") @@ -134,6 +137,12 @@ func (ts *TipSet) Len() int { return len(ts.blocks) } +// At returns the i'th newBlock in the tipset. +// An index outside the half-open range [0, Len()) will panic. +func (ts *TipSet) At(i int) *BlockHeader { + return ts.blocks[i] +} + func (ts *TipSet) Blocks() []*BlockHeader { return ts.blocks } @@ -233,6 +242,13 @@ func (ts *TipSet) MinTimestamp() uint64 { return minTS } +// ToSlice returns an ordered slice of pointers to the tipset's blocks. +func (ts *TipSet) ToSlice() []*BlockHeader { + slice := make([]*BlockHeader, len(ts.blocks)) + copy(slice, ts.blocks) + return slice +} + func sortedCidArrsEqual(a, b []cid.Cid) bool { if len(a) != len(b) { return false diff --git a/venus-shared/chain/tipset_key.go b/venus-shared/chain/tipset_key.go index fbb680fe2a..3289b4807a 100644 --- a/venus-shared/chain/tipset_key.go +++ b/venus-shared/chain/tipset_key.go @@ -4,10 +4,14 @@ import ( "bytes" "encoding/json" "fmt" + "io" "strings" + "golang.org/x/xerrors" + "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" + cbg "github.com/whyrusleeping/cbor-gen" ) // TipSetKey is an immutable set of CIDs forming a unique key for a TipSet. @@ -99,6 +103,91 @@ func (tsk TipSetKey) IsEmpty() bool { return len(tsk.value) == 0 } +// ContainsAll checks if another set is a subset of this one. +// We can assume that the relative order of members of one key is +// maintained in the other since we assume that all ids are sorted +// by corresponding newBlock ticket value. +func (tipsetKey TipSetKey) ContainsAll(other TipSetKey) bool { + // Since we assume the ids must have the same relative sorting we can + // perform one pass over this set, advancing the other index whenever the + // values match. + cids := tipsetKey.Cids() + otherCids := other.Cids() + otherIdx := 0 + for i := 0; i < len(cids) && otherIdx < len(otherCids); i++ { + if cids[i].Equals(otherCids[otherIdx]) { + otherIdx++ + } + } + // otherIdx is advanced the full length only if every element was found in this set. + return otherIdx == len(otherCids) +} + +// Has checks whether the set contains `id`. +func (tipsetKey TipSetKey) Has(id cid.Cid) bool { + // Find index of the first CID not less than id. + for _, cid := range tipsetKey.Cids() { + if cid == id { + return true + } + } + return false +} + +// Equals checks whether the set contains exactly the same CIDs as another. +func (tipsetKey TipSetKey) Equals(other TipSetKey) bool { + return tipsetKey.value == other.value +} + +func (tipsetKey *TipSetKey) UnmarshalCBOR(r io.Reader) error { + br := cbg.GetPeeker(r) + scratch := make([]byte, 8) + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + + if extra > cbg.MaxLength { + return fmt.Errorf("t.Parents: array too large (%d)", extra) + } + + if maj != cbg.MajArray { + return fmt.Errorf("expected cbor array") + } + + if extra > 0 { + cids := make([]cid.Cid, extra) + for i := 0; i < int(extra); i++ { + + c, err := cbg.ReadCid(br) + if err != nil { + return xerrors.Errorf("reading cid field t.Parents failed: %v", err) + } + cids[i] = c + } + tipsetKey.value = string(encodeKey(cids)) + } + return nil +} + +func (tipsetKey TipSetKey) MarshalCBOR(w io.Writer) error { + cids := tipsetKey.Cids() + if len(cids) > cbg.MaxLength { + return xerrors.Errorf("Slice value in field t.Parents was too long") + } + scratch := make([]byte, 9) + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(cids))); err != nil { + return err + } + for _, v := range cids { + if err := cbg.WriteCidBuf(scratch, w, v); err != nil { + return xerrors.Errorf("failed writing cid field t.Parents: %v", err) + } + } + return nil +} + func encodeKey(cids []cid.Cid) []byte { buffer := new(bytes.Buffer) for _, c := range cids { diff --git a/venus-shared/compatible-checks/api-diff.txt b/venus-shared/compatible-checks/api-diff.txt index 4b6b8aaa12..e69de29bb2 100644 --- a/venus-shared/compatible-checks/api-diff.txt +++ b/venus-shared/compatible-checks/api-diff.txt @@ -1,134 +0,0 @@ -github.com/filecoin-project/venus/venus-shared/api/chain/v1.FullNode <> github.com/filecoin-project/lotus/api.FullNode: - - AuthVerify - + BlockTime - - ChainBlockstoreInfo - - ChainCheckBlockstore - - ChainGetGenesis - - ChainGetNode - + ChainGetRandomnessFromBeacon - + ChainGetRandomnessFromTickets - + ChainGetReceipts - + ChainList - + ChainSyncHandleNewTipSet - - ClientCalcCommP - - ClientCancelDataTransfer - - ClientCancelRetrievalDeal - - ClientDataTransferUpdates - - ClientDealPieceCID - - ClientDealSize - - ClientFindData - - ClientGenCar - - ClientGetDealInfo - - ClientGetDealStatus - - ClientGetDealUpdates - - ClientGetRetrievalUpdates - - ClientHasLocal - - ClientImport - - ClientListDataTransfers - - ClientListDeals - - ClientListImports - - ClientListRetrievals - - ClientMinerQueryOffer - - ClientQueryAsk - - ClientRemoveImport - - ClientRestartDataTransfer - - ClientRetrieve - - ClientRetrieveTryRestartInsufficientFunds - - ClientRetrieveWithEvents - - ClientStartDeal - - ClientStatelessDeal - - Closing - + Concurrent - - CreateBackup - - Discover - + GasBatchEstimateMessageGas - > GasEstimateMessageGas {[func(context.Context, *chain.Message, *v1.MessageSendSpec, chain.TipSetKey) (*chain.Message, error) <> func(context.Context, *types.Message, *api.MessageSendSpec, types.TipSetKey) (*types.Message, error)] base=func in type: #2 input; nested={[*v1.MessageSendSpec <> *api.MessageSendSpec] base=pointed type; nested={[v1.MessageSendSpec <> api.MessageSendSpec] base=struct field; nested={[v1.MessageSendSpec <> api.MessageSendSpec] base=exported fields count: 2 != 1; nested=nil}}}} - + GetActor - + GetEntry - + GetFullBlock - + GetParentStateRootActor - + HasPassword - - ID - + ListActor - + LockWallet - - LogAlerts - - LogList - - LogSetLevel - - MarketAddBalance - - MarketGetReserved - - MarketReleaseFunds - - MarketReserveFunds - - MarketWithdraw - + MessageWait - > MpoolBatchPushMessage {[func(context.Context, []*chain.Message, *v1.MessageSendSpec) ([]*chain.SignedMessage, error) <> func(context.Context, []*types.Message, *api.MessageSendSpec) ([]*types.SignedMessage, error)] base=func in type: #2 input; nested={[*v1.MessageSendSpec <> *api.MessageSendSpec] base=pointed type; nested={[v1.MessageSendSpec <> api.MessageSendSpec] base=struct field; nested={[v1.MessageSendSpec <> api.MessageSendSpec] base=exported fields count: 2 != 1; nested=nil}}}} - + MpoolDeleteByAdress - + MpoolPublishByAddr - + MpoolPublishMessage - > MpoolPushMessage {[func(context.Context, *chain.Message, *v1.MessageSendSpec) (*chain.SignedMessage, error) <> func(context.Context, *types.Message, *api.MessageSendSpec) (*types.SignedMessage, error)] base=func in type: #2 input; nested={[*v1.MessageSendSpec <> *api.MessageSendSpec] base=pointed type; nested={[v1.MessageSendSpec <> api.MessageSendSpec] base=struct field; nested={[v1.MessageSendSpec <> api.MessageSendSpec] base=exported fields count: 2 != 1; nested=nil}}}} - + MpoolSelects - - MsigGetAvailableBalance - - MsigGetPending - - MsigGetVestingSchedule - - NetAgentVersion - - NetAutoNatStatus - - NetBandwidthStats - - NetBandwidthStatsByPeer - - NetBandwidthStatsByProtocol - - NetBlockAdd - - NetBlockList - - NetBlockRemove - - NetConnect - - NetConnectedness - - NetDisconnect - - NetFindPeer - - NetPeerInfo - - NetPeers - - NetPubsubScores - + NetworkConnect - + NetworkFindPeer - + NetworkFindProvidersAsync - + NetworkGetBandwidthStats - + NetworkGetClosestPeers - + NetworkGetPeerAddresses - + NetworkGetPeerID - + NetworkPeers - - NodeStatus - + ProtocolParameters - + ResolveToKeyAddr - - Session - + SetConcurrent - + SetPassword - - Shutdown - - StateAllMinerFaults - - StateChangedActors - - StateCompute - - StateDecodeParams - - StateEncodeParams - - StateListMessages - + StateMinerSectorSize - + StateMinerWorkerAddress - - StateReadState - - StateReplay - - SyncCheckBad - - SyncCheckpoint - - SyncIncomingBlocks - - SyncMarkBad - - SyncUnmarkAllBad - - SyncUnmarkBad - - SyncValidateTipset - + UnLockWallet - + Verify - + VerifyEntry - > Version {[func(context.Context) (v1.Version, error) <> func(context.Context) (api.APIVersion, error)] base=func out type: #0 input; nested={[v1.Version <> api.APIVersion] base=struct field; nested={[v1.Version <> api.APIVersion] base=exported fields count: 2 != 3; nested=nil}}} - + WalletAddresses - - WalletDelete - > WalletExport {[func(address.Address, string) (*wallet.KeyInfo, error) <> func(context.Context, address.Address) (*types.KeyInfo, error)] base=func in type: #0 input; nested={[address.Address <> context.Context] base=type kinds: struct != interface; nested=nil}} - > WalletImport {[func(*wallet.KeyInfo) (address.Address, error) <> func(context.Context, *types.KeyInfo) (address.Address, error)] base=func in num: 1 != 2; nested=nil} - - WalletList - - WalletNew - + WalletNewAddress - > WalletSign {[func(context.Context, address.Address, []uint8, wallet.MsgMeta) (*crypto.Signature, error) <> func(context.Context, address.Address, []uint8) (*crypto.Signature, error)] base=func in num: 4 != 3; nested=nil} - + WalletState - - WalletValidateAddress - - WalletVerify - diff --git a/venus-shared/go.mod b/venus-shared/go.mod index d02ee087fb..ec46624d7f 100644 --- a/venus-shared/go.mod +++ b/venus-shared/go.mod @@ -17,10 +17,12 @@ require ( github.com/ipfs/go-block-format v0.0.3 github.com/ipfs/go-cid v0.1.0 github.com/ipfs/go-ipld-cbor v0.0.5 + github.com/ipfs/go-ipld-format v0.0.2 github.com/ipfs/go-log v1.0.4 github.com/libp2p/go-libp2p-core v0.8.5 github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 github.com/multiformats/go-multiaddr v0.2.2 + github.com/multiformats/go-multihash v0.0.15 github.com/stretchr/testify v1.7.0 github.com/whyrusleeping/cbor-gen v0.0.0-20210219115102-f37d292932f2 go.uber.org/zap v1.14.1 diff --git a/venus-shared/wallet/key_info.go b/venus-shared/wallet/key_info.go index fffde7b8e4..0945210227 100644 --- a/venus-shared/wallet/key_info.go +++ b/venus-shared/wallet/key_info.go @@ -3,6 +3,7 @@ package wallet import ( "encoding/json" "fmt" + "math" "github.com/filecoin-project/go-state-types/crypto" ) @@ -46,12 +47,44 @@ func (kt *KeyType) UnmarshalJSON(bb []byte) error { } } +type SigType = crypto.SigType + +const ( + SigTypeUnknown = SigType(math.MaxUint8) + + SigTypeSecp256k1 = SigType(iota) + SigTypeBLS +) + const ( + KTUnknown KeyType = "unknown" KTBLS KeyType = "bls" KTSecp256k1 KeyType = "secp256k1" KTSecp256k1Ledger KeyType = "secp256k1-ledger" ) +func KeyType2Sign(kt KeyType) SigType { + switch kt { + case KTSecp256k1: + return SigTypeSecp256k1 + case KTBLS: + return SigTypeBLS + default: + return SigTypeUnknown + } +} + +func SignType2Key(kt SigType) KeyType { + switch kt { + case SigTypeSecp256k1: + return KTSecp256k1 + case SigTypeBLS: + return KTBLS + default: + return KTUnknown + } +} + // KeyInfo is used for storing keys in KeyStore type KeyInfo struct { Type KeyType diff --git a/venus-shared/wallet/msg_meta.go b/venus-shared/wallet/msg_meta.go index 24bb12ec32..97d0a3e7cc 100644 --- a/venus-shared/wallet/msg_meta.go +++ b/venus-shared/wallet/msg_meta.go @@ -12,9 +12,22 @@ const ( MTBlock = "block" // Signing a deal proposal. signing raw cbor proposal bytes (MsgMeta.Extra is empty) - MTDealProposal = "dealproposal" - - // TODO: Deals, Vouchers, VRF + MTDealProposal = MsgType("dealproposal") + // extra is nil, 'toSign' is cbor raw bytes of 'DrawRandomParams' + // following types follow above rule + MTDrawRandomParam = MsgType("drawrandomparam") + MTSignedVoucher = MsgType("signedvoucher") + MTStorageAsk = MsgType("storageask") + MTAskResponse = MsgType("askresponse") + MTNetWorkResponse = MsgType("networkresposne") + + // reference : storagemarket/impl/remotecli.go:330 + // sign storagemarket.ClientDeal.ProposalCid, + // MsgMeta.Extra is nil, 'toSign' is market.ClientDealProposal + // storagemarket.ClientDeal.ProposalCid equals cborutil.AsIpld(market.ClientDealProposal).Cid() + MTClientDeal = MsgType("clientdeal") + + MTProviderDealState = MsgType("providerdealstate") ) type MsgMeta struct { From 6c2944bd7b05d870d24453e3859b4ed32ea4cb1a Mon Sep 17 00:00:00 2001 From: simlecode Date: Wed, 22 Dec 2021 17:52:35 +0800 Subject: [PATCH 2/2] replace type --- app/client/apiface/blockstore.go | 2 +- app/client/apiface/chain.go | 8 +- app/client/apiface/market.go | 4 +- app/client/apiface/mining.go | 4 +- app/client/apiface/mpool.go | 25 +- app/client/apiface/multisig.go | 28 +- app/client/apiface/network.go | 6 +- app/client/apiface/paych.go | 14 +- app/client/apiface/syncer.go | 6 +- app/client/apiface/v0api/blockstore.go | 2 +- app/client/apiface/v0api/chain.go | 16 +- app/client/apiface/v0api/market.go | 4 +- app/client/apiface/v0api/mining.go | 4 +- app/client/apiface/v0api/mpool.go | 17 +- app/client/apiface/v0api/multisig.go | 2 +- app/client/apiface/v0api/network.go | 2 +- app/client/apiface/v0api/paych.go | 14 +- app/client/apiface/v0api/syncer.go | 6 +- app/client/apiface/v0api/wallet.go | 6 +- app/client/apiface/wallet.go | 7 +- app/client/full.go | 195 +++--- app/client/v0api/full.go | 133 ++-- app/node/builder.go | 5 +- app/node/env.go | 5 +- app/node/helpers.go | 4 +- app/node/test/node.go | 4 +- app/submodule/apitypes/chain.go | 6 +- app/submodule/apitypes/mining.go | 2 +- app/submodule/apitypes/mpool.go | 2 +- app/submodule/apitypes/syncer.go | 8 +- app/submodule/blockstore/blockstore_api.go | 8 +- app/submodule/chain/account_api.go | 3 +- app/submodule/chain/actor_api.go | 3 +- app/submodule/chain/beacon_api.go | 3 +- app/submodule/chain/chain_submodule.go | 15 +- app/submodule/chain/chaininfo_api.go | 21 +- app/submodule/chain/miner_api.go | 24 +- app/submodule/chain/v0api/chaininfo_v0api.go | 5 +- app/submodule/config/config_test.go | 5 +- .../discovery/discovery_submodule.go | 2 +- app/submodule/market/market_api.go | 8 +- app/submodule/mining/mining_api.go | 22 +- app/submodule/mpool/mpool_api.go | 51 +- app/submodule/mpool/mpool_submodule.go | 2 +- app/submodule/multisig/multisig_api.go | 56 +- .../multisig/v0api/multisig_v0api.go | 7 +- app/submodule/network/network_api.go | 12 +- app/submodule/network/network_submodule.go | 8 +- app/submodule/network/v0api/v1_wrapper.go | 7 +- app/submodule/paych/paych_api.go | 19 +- app/submodule/syncer/chain_sync.go | 5 +- app/submodule/syncer/syncer_api.go | 17 +- app/submodule/syncer/syncer_submodule.go | 4 +- app/submodule/wallet/remotewallet/api.go | 31 +- app/submodule/wallet/remotewallet/keymap.go | 22 +- app/submodule/wallet/remotewallet/remote.go | 3 +- app/submodule/wallet/wallet_api.go | 12 +- app/submodule/wallet/wallet_submodule.go | 2 +- cmd/address.go | 2 +- cmd/chain.go | 8 +- cmd/daemon.go | 7 +- cmd/dag_integration_test.go | 2 +- cmd/dispute.go | 12 +- cmd/main.go | 17 +- cmd/message.go | 14 +- cmd/miner.go | 18 +- cmd/miner_actor.go | 25 +- cmd/miner_proving.go | 8 +- cmd/mpool.go | 21 +- cmd/multisig.go | 19 +- cmd/paych.go | 2 +- cmd/protocol.go | 2 +- cmd/seed.go | 2 +- cmd/show.go | 2 +- cmd/show_test.go | 28 +- cmd/state.go | 8 +- pkg/beacon/beacon.go | 9 +- pkg/beacon/drand.go | 2 +- pkg/beacon/mock.go | 2 +- pkg/chain/chain_index.go | 2 +- pkg/chain/circulating_supply.go | 9 +- pkg/chain/coalescer.go | 3 +- pkg/chain/coalescer_test.go | 8 +- pkg/chain/message_store.go | 64 +- pkg/chain/message_store_test.go | 13 +- pkg/chain/randomness.go | 15 +- pkg/chain/reorg.go | 2 +- pkg/chain/reorg_test.go | 10 +- pkg/chain/store.go | 19 +- pkg/chain/store_test.go | 15 +- pkg/chain/testing.go | 50 +- pkg/chain/tip_index.go | 3 +- pkg/chain/traversal.go | 6 +- pkg/chain/traversal_test.go | 15 +- pkg/chain/utils.go | 2 +- pkg/chain/waiter.go | 5 +- pkg/chain/waiter_test.go | 10 +- pkg/chainsync/chainsync.go | 5 +- pkg/chainsync/dispatcher/dispatcher.go | 7 +- pkg/chainsync/dispatcher/dispatcher_test.go | 27 +- pkg/chainsync/exchange/cbor_gen.go | 647 ++++++++++++++++++ pkg/chainsync/exchange/client.go | 4 +- pkg/chainsync/exchange/interfaces.go | 3 +- pkg/chainsync/exchange/protocol.go | 4 +- pkg/chainsync/exchange/server.go | 9 +- pkg/chainsync/slashfilter/mysqldb.go | 8 +- pkg/chainsync/slashfilter/slashfilter.go | 6 +- pkg/chainsync/syncer/syncer.go | 8 +- .../syncer/syncer_integration_test.go | 5 +- pkg/chainsync/syncer/syncer_test.go | 28 +- pkg/chainsync/types/bad_tipset_cache.go | 3 +- pkg/chainsync/types/target_tracker.go | 5 +- pkg/config/config.go | 2 +- pkg/consensus/block_validator.go | 48 +- pkg/consensus/chain_selector.go | 7 +- pkg/consensus/expected.go | 9 +- pkg/consensus/head_randomness.go | 3 +- pkg/consensus/message_validator.go | 8 +- pkg/consensus/message_validator_test.go | 33 +- pkg/consensus/processor.go | 4 +- pkg/consensus/protocol.go | 8 +- pkg/consensus/testing.go | 14 +- pkg/consensus/ticket.go | 2 +- pkg/consensus/ticket_test.go | 25 +- pkg/consensus/weight_test.go | 34 +- pkg/consensusfault/check.go | 18 +- pkg/discovery/cbor_gen.go | 4 +- pkg/discovery/hello_protocol.go | 2 +- pkg/discovery/hello_protocol_test.go | 6 +- pkg/discovery/peer_tracker.go | 3 +- pkg/discovery/peer_tracker_test.go | 7 +- pkg/events/cache.go | 5 +- pkg/events/eventAPI.go | 4 +- pkg/events/events.go | 2 +- pkg/events/events_called.go | 2 +- pkg/events/events_height.go | 3 +- pkg/events/events_test.go | 16 +- pkg/events/message_cache.go | 2 +- pkg/events/observer.go | 2 +- pkg/events/state/fastapi.go | 3 +- pkg/events/state/mock/api.go | 2 +- pkg/events/state/mock/tipset.go | 4 +- pkg/events/state/predicates.go | 19 +- pkg/events/state/predicates_test.go | 7 +- pkg/events/tscache.go | 3 +- pkg/events/tscache_test.go | 10 +- pkg/events/utils.go | 2 +- pkg/fork/fork.go | 21 +- pkg/fork/mock.go | 3 +- pkg/gen/genesis/f00_system.go | 2 +- pkg/gen/genesis/f01_init.go | 2 +- pkg/gen/genesis/f02_reward.go | 2 +- pkg/gen/genesis/f03_cron.go | 2 +- pkg/gen/genesis/f04_power.go | 2 +- pkg/gen/genesis/f05_market.go | 2 +- pkg/gen/genesis/f06_vreg.go | 2 +- pkg/gen/genesis/genesis.go | 14 +- pkg/gen/genesis/miners.go | 13 +- pkg/gen/genesis/util.go | 6 +- pkg/genesis/genesis.go | 2 +- pkg/genesis/init.go | 5 +- pkg/market/fmgr.go | 9 +- pkg/market/fundmanager.go | 6 +- pkg/market/fundmanager_test.go | 17 +- pkg/messagepool/check.go | 86 +-- pkg/messagepool/gas.go | 21 +- pkg/messagepool/gasguess/guessgas.go | 2 +- pkg/messagepool/messagepool.go | 42 +- pkg/messagepool/messagepool_test.go | 21 +- pkg/messagepool/messagesigner.go | 8 +- pkg/messagepool/messagesigner_test.go | 2 +- pkg/messagepool/provider.go | 6 +- pkg/messagepool/pruning.go | 3 +- pkg/messagepool/repub.go | 4 +- pkg/messagepool/selection.go | 2 +- pkg/messagepool/selection_test.go | 15 +- pkg/metrics/heartbeat.go | 2 +- pkg/metrics/heartbeat_test.go | 21 +- pkg/net/blocksub/validator.go | 3 +- pkg/net/blocksub/validator_test.go | 5 +- pkg/net/msgsub/validator.go | 4 +- pkg/paychmgr/manager.go | 2 +- pkg/paychmgr/mock_test.go | 22 +- pkg/paychmgr/paych.go | 10 +- pkg/paychmgr/paych_test.go | 2 +- pkg/paychmgr/paychget_test.go | 46 +- pkg/paychmgr/paychvoucherfunds_test.go | 2 +- pkg/paychmgr/pcapi.go | 26 +- pkg/paychmgr/settler/settler.go | 13 +- pkg/paychmgr/settler/stl.go | 16 +- pkg/paychmgr/simple.go | 8 +- pkg/paychmgr/state.go | 2 +- pkg/state/power_table_view.go | 10 +- pkg/state/power_table_view_test.go | 12 +- pkg/state/signer.go | 3 +- pkg/state/sigval.go | 5 +- pkg/state/sigval_test.go | 37 +- pkg/state/testing.go | 8 +- pkg/state/tree/snapshot.go | 2 +- pkg/state/tree/state.go | 13 +- pkg/state/tree/state_test.go | 11 +- pkg/state/tree/testing.go | 6 +- pkg/state/view.go | 69 +- pkg/statemanger/call.go | 7 +- pkg/statemanger/state_manger.go | 4 +- pkg/testhelpers/address.go | 31 + pkg/testhelpers/cid.go | 67 ++ pkg/testhelpers/consensus.go | 40 +- pkg/testhelpers/core.go | 60 +- pkg/testhelpers/message.go | 295 ++++++++ pkg/testhelpers/net.go | 5 +- pkg/testhelpers/singer.go | 153 +++++ pkg/testhelpers/test_daemon.go | 2 +- pkg/testhelpers/tipset.go | 16 + pkg/types/internal/atto_fil_test.go | 5 +- pkg/util/dag/dag_test.go | 5 +- pkg/vm/gas/gas_tracker.go | 8 +- pkg/vm/vmcontext/interpreter.go | 2 +- pkg/vm/vmcontext/invocation_context.go | 8 +- pkg/vm/vmcontext/runtime_adapter.go | 2 +- pkg/vm/vmcontext/syscallsStateView.go | 5 +- pkg/vm/vmcontext/types.go | 9 +- pkg/vm/vmcontext/vmcontext.go | 26 +- pkg/wallet/wallet.go | 5 +- pkg/wallet/wallet_test.go | 5 +- tools/client/main.go | 2 +- tools/conformance/driver.go | 11 +- tools/conformance/rand_record.go | 6 +- tools/conformance/runner.go | 7 +- tools/fast/action_mpool.go | 2 +- tools/fast/action_protocol.go | 3 +- tools/fast/action_show.go | 3 +- tools/fast/action_wallet.go | 5 +- tools/fast/series/wait_for_chain_message.go | 2 +- tools/gen_cbor/main.go | 29 +- tools/gengen/util/generator.go | 30 +- tools/gengen/util/gengen.go | 2 +- tools/seed/seed.go | 5 +- 238 files changed, 2613 insertions(+), 1407 deletions(-) create mode 100644 pkg/chainsync/exchange/cbor_gen.go create mode 100644 pkg/testhelpers/address.go create mode 100644 pkg/testhelpers/cid.go create mode 100644 pkg/testhelpers/message.go create mode 100644 pkg/testhelpers/singer.go create mode 100644 pkg/testhelpers/tipset.go diff --git a/app/client/apiface/blockstore.go b/app/client/apiface/blockstore.go index 73de91ca65..13a44327b3 100644 --- a/app/client/apiface/blockstore.go +++ b/app/client/apiface/blockstore.go @@ -5,7 +5,7 @@ import ( "github.com/ipfs/go-cid" - "github.com/filecoin-project/venus/app/submodule/apitypes" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" ) type IBlockStore interface { diff --git a/app/client/apiface/chain.go b/app/client/apiface/chain.go index b09494e61a..f912d896b0 100644 --- a/app/client/apiface/chain.go +++ b/app/client/apiface/chain.go @@ -8,10 +8,10 @@ import ( "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/dline" - "github.com/filecoin-project/venus/app/submodule/apitypes" "github.com/filecoin-project/venus/pkg/chain" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/venus-shared/actors/builtin/miner" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/filecoin-project/go-state-types/big" acrypto "github.com/filecoin-project/go-state-types/crypto" @@ -70,7 +70,7 @@ type IChainInfo interface { // Rule[perm:read] ChainGetBlock(ctx context.Context, id cid.Cid) (*types.BlockHeader, error) // Rule[perm:read] - ChainGetMessage(ctx context.Context, msgID cid.Cid) (*types.UnsignedMessage, error) + ChainGetMessage(ctx context.Context, msgID cid.Cid) (*types.Message, error) // Rule[perm:read] ChainGetBlockMessages(ctx context.Context, bid cid.Cid) (*apitypes.BlockMessages, error) // Rule[perm:read] @@ -189,7 +189,7 @@ type IMinerState interface { // Rule[perm:read] StateCirculatingSupply(ctx context.Context, tsk types.TipSetKey) (abi.TokenAmount, error) // Rule[perm:read] - StateMarketDeals(ctx context.Context, tsk types.TipSetKey) (map[string]types.MarketDeal, error) + StateMarketDeals(ctx context.Context, tsk types.TipSetKey) (map[string]apitypes.MarketDeal, error) // Rule[perm:read] StateMinerActiveSectors(ctx context.Context, maddr address.Address, tsk types.TipSetKey) ([]*miner.SectorOnChainInfo, error) // Rule[perm:read] diff --git a/app/client/apiface/market.go b/app/client/apiface/market.go index 3a88cbfab1..6adaa7494d 100644 --- a/app/client/apiface/market.go +++ b/app/client/apiface/market.go @@ -3,8 +3,8 @@ package apiface import ( "context" - "github.com/filecoin-project/venus/app/submodule/apitypes" - "github.com/filecoin-project/venus/pkg/types" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" ) type IMarket interface { diff --git a/app/client/apiface/mining.go b/app/client/apiface/mining.go index fd62fefbc1..ee26fcf892 100644 --- a/app/client/apiface/mining.go +++ b/app/client/apiface/mining.go @@ -5,8 +5,8 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/venus/app/submodule/apitypes" - "github.com/filecoin-project/venus/pkg/types" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" ) type IMining interface { diff --git a/app/client/apiface/mpool.go b/app/client/apiface/mpool.go index 8ef62954dc..ccc573b6ed 100644 --- a/app/client/apiface/mpool.go +++ b/app/client/apiface/mpool.go @@ -3,12 +3,11 @@ package apiface import ( "context" - "github.com/filecoin-project/venus/app/submodule/apitypes" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/venus/pkg/messagepool" - "github.com/filecoin-project/venus/pkg/types" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" + "github.com/filecoin-project/venus/venus-shared/messagepool" "github.com/ipfs/go-cid" ) @@ -36,34 +35,34 @@ type IMessagePool interface { // Rule[perm:write] MpoolPushUntrusted(ctx context.Context, smsg *types.SignedMessage) (cid.Cid, error) // Rule[perm:sign] - MpoolPushMessage(ctx context.Context, msg *types.UnsignedMessage, spec *types.MessageSendSpec) (*types.SignedMessage, error) + MpoolPushMessage(ctx context.Context, msg *types.Message, spec *apitypes.MessageSendSpec) (*types.SignedMessage, error) // Rule[perm:write] MpoolBatchPush(ctx context.Context, smsgs []*types.SignedMessage) ([]cid.Cid, error) // Rule[perm:write] MpoolBatchPushUntrusted(ctx context.Context, smsgs []*types.SignedMessage) ([]cid.Cid, error) // Rule[perm:sign] - MpoolBatchPushMessage(ctx context.Context, msgs []*types.UnsignedMessage, spec *types.MessageSendSpec) ([]*types.SignedMessage, error) + MpoolBatchPushMessage(ctx context.Context, msgs []*types.Message, spec *apitypes.MessageSendSpec) ([]*types.SignedMessage, error) // Rule[perm:read] MpoolGetNonce(ctx context.Context, addr address.Address) (uint64, error) // Rule[perm:read] MpoolSub(ctx context.Context) (<-chan messagepool.MpoolUpdate, error) // Rule[perm:read] - GasEstimateMessageGas(ctx context.Context, msg *types.UnsignedMessage, spec *types.MessageSendSpec, tsk types.TipSetKey) (*types.UnsignedMessage, error) + GasEstimateMessageGas(ctx context.Context, msg *types.Message, spec *apitypes.MessageSendSpec, tsk types.TipSetKey) (*types.Message, error) // Rule[perm:read] - GasBatchEstimateMessageGas(ctx context.Context, estimateMessages []*types.EstimateMessage, fromNonce uint64, tsk types.TipSetKey) ([]*types.EstimateResult, error) + GasBatchEstimateMessageGas(ctx context.Context, estimateMessages []*apitypes.EstimateMessage, fromNonce uint64, tsk types.TipSetKey) ([]*apitypes.EstimateResult, error) // Rule[perm:read] - GasEstimateFeeCap(ctx context.Context, msg *types.UnsignedMessage, maxqueueblks int64, tsk types.TipSetKey) (big.Int, error) + GasEstimateFeeCap(ctx context.Context, msg *types.Message, maxqueueblks int64, tsk types.TipSetKey) (big.Int, error) // Rule[perm:read] GasEstimateGasPremium(ctx context.Context, nblocksincl uint64, sender address.Address, gaslimit int64, tsk types.TipSetKey) (big.Int, error) // Rule[perm:read] - GasEstimateGasLimit(ctx context.Context, msgIn *types.UnsignedMessage, tsk types.TipSetKey) (int64, error) + GasEstimateGasLimit(ctx context.Context, msgIn *types.Message, tsk types.TipSetKey) (int64, error) // MpoolCheckMessages performs logical checks on a batch of messages // Rule[perm:read] - MpoolCheckMessages(ctx context.Context, protos []*apitypes.MessagePrototype) ([][]apitypes.MessageCheckStatus, error) + MpoolCheckMessages(ctx context.Context, protos []*messagepool.MessagePrototype) ([][]messagepool.MessageCheckStatus, error) // MpoolCheckPendingMessages performs logical checks for all pending messages from a given address // Rule[perm:read] - MpoolCheckPendingMessages(ctx context.Context, addr address.Address) ([][]apitypes.MessageCheckStatus, error) + MpoolCheckPendingMessages(ctx context.Context, addr address.Address) ([][]messagepool.MessageCheckStatus, error) // MpoolCheckReplaceMessages performs logical checks on pending messages with replacement // Rule[perm:read] - MpoolCheckReplaceMessages(ctx context.Context, msg []*types.Message) ([][]apitypes.MessageCheckStatus, error) + MpoolCheckReplaceMessages(ctx context.Context, msg []*types.Message) ([][]messagepool.MessageCheckStatus, error) } diff --git a/app/client/apiface/multisig.go b/app/client/apiface/multisig.go index d5bd29f699..62dc207d14 100644 --- a/app/client/apiface/multisig.go +++ b/app/client/apiface/multisig.go @@ -5,35 +5,35 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/venus/app/submodule/apitypes" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" + "github.com/filecoin-project/venus/venus-shared/messagepool" ) type IMultiSig interface { // Rule[perm:sign] - MsigCreate(ctx context.Context, req uint64, addrs []address.Address, duration abi.ChainEpoch, val types.BigInt, src address.Address, gp types.BigInt) (*apitypes.MessagePrototype, error) + MsigCreate(ctx context.Context, req uint64, addrs []address.Address, duration abi.ChainEpoch, val types.BigInt, src address.Address, gp types.BigInt) (*messagepool.MessagePrototype, error) // Rule[perm:sign] - MsigPropose(ctx context.Context, msig address.Address, to address.Address, amt types.BigInt, src address.Address, method uint64, params []byte) (*apitypes.MessagePrototype, error) + MsigPropose(ctx context.Context, msig address.Address, to address.Address, amt types.BigInt, src address.Address, method uint64, params []byte) (*messagepool.MessagePrototype, error) // Rule[perm:sign] - MsigAddPropose(ctx context.Context, msig address.Address, src address.Address, newAdd address.Address, inc bool) (*apitypes.MessagePrototype, error) + MsigAddPropose(ctx context.Context, msig address.Address, src address.Address, newAdd address.Address, inc bool) (*messagepool.MessagePrototype, error) // Rule[perm:sign] - MsigAddApprove(ctx context.Context, msig address.Address, src address.Address, txID uint64, proposer address.Address, newAdd address.Address, inc bool) (*apitypes.MessagePrototype, error) + MsigAddApprove(ctx context.Context, msig address.Address, src address.Address, txID uint64, proposer address.Address, newAdd address.Address, inc bool) (*messagepool.MessagePrototype, error) // Rule[perm:sign] - MsigAddCancel(ctx context.Context, msig address.Address, src address.Address, txID uint64, newAdd address.Address, inc bool) (*apitypes.MessagePrototype, error) + MsigAddCancel(ctx context.Context, msig address.Address, src address.Address, txID uint64, newAdd address.Address, inc bool) (*messagepool.MessagePrototype, error) // Rule[perm:sign] - MsigSwapPropose(ctx context.Context, msig address.Address, src address.Address, oldAdd address.Address, newAdd address.Address) (*apitypes.MessagePrototype, error) + MsigSwapPropose(ctx context.Context, msig address.Address, src address.Address, oldAdd address.Address, newAdd address.Address) (*messagepool.MessagePrototype, error) // Rule[perm:sign] - MsigSwapApprove(ctx context.Context, msig address.Address, src address.Address, txID uint64, proposer address.Address, oldAdd address.Address, newAdd address.Address) (*apitypes.MessagePrototype, error) + MsigSwapApprove(ctx context.Context, msig address.Address, src address.Address, txID uint64, proposer address.Address, oldAdd address.Address, newAdd address.Address) (*messagepool.MessagePrototype, error) // Rule[perm:sign] - MsigSwapCancel(ctx context.Context, msig address.Address, src address.Address, txID uint64, oldAdd address.Address, newAdd address.Address) (*apitypes.MessagePrototype, error) + MsigSwapCancel(ctx context.Context, msig address.Address, src address.Address, txID uint64, oldAdd address.Address, newAdd address.Address) (*messagepool.MessagePrototype, error) // Rule[perm:sign] - MsigApprove(ctx context.Context, msig address.Address, txID uint64, src address.Address) (*apitypes.MessagePrototype, error) + MsigApprove(ctx context.Context, msig address.Address, txID uint64, src address.Address) (*messagepool.MessagePrototype, error) // Rule[perm:sign] - MsigApproveTxnHash(ctx context.Context, msig address.Address, txID uint64, proposer address.Address, to address.Address, amt types.BigInt, src address.Address, method uint64, params []byte) (*apitypes.MessagePrototype, error) + MsigApproveTxnHash(ctx context.Context, msig address.Address, txID uint64, proposer address.Address, to address.Address, amt types.BigInt, src address.Address, method uint64, params []byte) (*messagepool.MessagePrototype, error) // Rule[perm:sign] - MsigCancel(ctx context.Context, msig address.Address, txID uint64, to address.Address, amt types.BigInt, src address.Address, method uint64, params []byte) (*apitypes.MessagePrototype, error) + MsigCancel(ctx context.Context, msig address.Address, txID uint64, to address.Address, amt types.BigInt, src address.Address, method uint64, params []byte) (*messagepool.MessagePrototype, error) // Rule[perm:sign] - MsigRemoveSigner(ctx context.Context, msig address.Address, proposer address.Address, toRemove address.Address, decrease bool) (*apitypes.MessagePrototype, error) + MsigRemoveSigner(ctx context.Context, msig address.Address, proposer address.Address, toRemove address.Address, decrease bool) (*messagepool.MessagePrototype, error) // Rule[perm:read] MsigGetVested(ctx context.Context, addr address.Address, start types.TipSetKey, end types.TipSetKey) (types.BigInt, error) } diff --git a/app/client/apiface/network.go b/app/client/apiface/network.go index e6eb3c40fd..41a71743ee 100644 --- a/app/client/apiface/network.go +++ b/app/client/apiface/network.go @@ -3,13 +3,13 @@ package apiface import ( "context" - "github.com/filecoin-project/venus/app/submodule/apitypes" - - "github.com/filecoin-project/venus/pkg/net" "github.com/ipfs/go-cid" "github.com/libp2p/go-libp2p-core/metrics" "github.com/libp2p/go-libp2p-core/peer" ma "github.com/multiformats/go-multiaddr" + + "github.com/filecoin-project/venus/pkg/net" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" ) type INetwork interface { diff --git a/app/client/apiface/paych.go b/app/client/apiface/paych.go index f064115895..04df2757b6 100644 --- a/app/client/apiface/paych.go +++ b/app/client/apiface/paych.go @@ -3,15 +3,13 @@ package apiface import ( "context" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/venus/app/submodule/apitypes" - "github.com/filecoin-project/venus/pkg/paychmgr" - "github.com/filecoin-project/venus/pkg/types" - "github.com/filecoin-project/specs-actors/actors/builtin/paych" "github.com/ipfs/go-cid" - "github.com/filecoin-project/go-address" + "github.com/filecoin-project/venus/pkg/paychmgr" + paychtypes "github.com/filecoin-project/venus/venus-shared/paych" ) type IPaychan interface { @@ -20,7 +18,7 @@ type IPaychan interface { // @to: the payment channel recipient // @amt: the deposits funds in the payment channel // Rule[perm:sign] - PaychGet(ctx context.Context, from, to address.Address, amt big.Int) (*apitypes.ChannelInfo, error) + PaychGet(ctx context.Context, from, to address.Address, amt big.Int) (*paychtypes.ChannelInfo, error) // PaychAvailableFunds get the status of an outbound payment channel // @pch: payment channel address // Rule[perm:sign] @@ -44,14 +42,14 @@ type IPaychan interface { // @to: the payment channel recipient // @vouchers: the outstanding (non-redeemed) vouchers // Rule[perm:sign] - PaychNewPayment(ctx context.Context, from, to address.Address, vouchers []apitypes.VoucherSpec) (*apitypes.PaymentInfo, error) + PaychNewPayment(ctx context.Context, from, to address.Address, vouchers []paychtypes.VoucherSpec) (*paychtypes.PaymentInfo, error) // PaychList list the addresses of all channels that have been created // Rule[perm:read] PaychList(ctx context.Context) ([]address.Address, error) // PaychStatus get the payment channel status // @pch: payment channel address // Rule[perm:read] - PaychStatus(ctx context.Context, pch address.Address) (*types.PaychStatus, error) + PaychStatus(ctx context.Context, pch address.Address) (*paychtypes.Status, error) // PaychSettle update payment channel status to settle // After a settlement period (currently 12 hours) either party to the payment channel can call collect on chain // @pch: payment channel address diff --git a/app/client/apiface/syncer.go b/app/client/apiface/syncer.go index fd109ee521..0bc6539845 100644 --- a/app/client/apiface/syncer.go +++ b/app/client/apiface/syncer.go @@ -4,9 +4,9 @@ import ( "context" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/venus/app/submodule/apitypes" syncTypes "github.com/filecoin-project/venus/pkg/chainsync/types" - "github.com/filecoin-project/venus/pkg/types" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" ) type ISyncer interface { @@ -23,7 +23,7 @@ type ISyncer interface { // Rule[perm:write] SyncSubmitBlock(ctx context.Context, blk *types.BlockMsg) error // Rule[perm:read] - StateCall(ctx context.Context, msg *types.UnsignedMessage, tsk types.TipSetKey) (*types.InvocResult, error) + StateCall(ctx context.Context, msg *types.Message, tsk types.TipSetKey) (*apitypes.InvocResult, error) // Rule[perm:read] SyncState(ctx context.Context) (*apitypes.SyncState, error) } diff --git a/app/client/apiface/v0api/blockstore.go b/app/client/apiface/v0api/blockstore.go index aa9c77a809..fb70a90ac9 100644 --- a/app/client/apiface/v0api/blockstore.go +++ b/app/client/apiface/v0api/blockstore.go @@ -5,7 +5,7 @@ import ( "github.com/ipfs/go-cid" - "github.com/filecoin-project/venus/app/submodule/apitypes" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" ) type IBlockStore interface { diff --git a/app/client/apiface/v0api/chain.go b/app/client/apiface/v0api/chain.go index c72f001869..1e42deded4 100644 --- a/app/client/apiface/v0api/chain.go +++ b/app/client/apiface/v0api/chain.go @@ -7,16 +7,16 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/dline" - "github.com/filecoin-project/venus/app/submodule/apitypes" - "github.com/filecoin-project/venus/pkg/chain" - "github.com/filecoin-project/venus/pkg/types" - "github.com/filecoin-project/venus/venus-shared/actors/builtin/miner" - "github.com/filecoin-project/go-state-types/big" acrypto "github.com/filecoin-project/go-state-types/crypto" + "github.com/filecoin-project/go-state-types/dline" "github.com/filecoin-project/go-state-types/network" "github.com/ipfs/go-cid" + + "github.com/filecoin-project/venus/pkg/chain" + "github.com/filecoin-project/venus/venus-shared/actors/builtin/miner" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" ) type IChain interface { @@ -64,7 +64,7 @@ type IChainInfo interface { // Rule[perm:read] ChainGetBlock(ctx context.Context, id cid.Cid) (*types.BlockHeader, error) // Rule[perm:read] - ChainGetMessage(ctx context.Context, msgID cid.Cid) (*types.UnsignedMessage, error) + ChainGetMessage(ctx context.Context, msgID cid.Cid) (*types.Message, error) // Rule[perm:read] ChainGetBlockMessages(ctx context.Context, bid cid.Cid) (*apitypes.BlockMessages, error) // Rule[perm:read] @@ -155,7 +155,7 @@ type IMinerState interface { // Rule[perm:read] StateCirculatingSupply(ctx context.Context, tsk types.TipSetKey) (abi.TokenAmount, error) // Rule[perm:read] - StateMarketDeals(ctx context.Context, tsk types.TipSetKey) (map[string]types.MarketDeal, error) + StateMarketDeals(ctx context.Context, tsk types.TipSetKey) (map[string]apitypes.MarketDeal, error) // Rule[perm:read] StateMinerActiveSectors(ctx context.Context, maddr address.Address, tsk types.TipSetKey) ([]*miner.SectorOnChainInfo, error) // Rule[perm:read] diff --git a/app/client/apiface/v0api/market.go b/app/client/apiface/v0api/market.go index cc107ec916..8eff369c15 100644 --- a/app/client/apiface/v0api/market.go +++ b/app/client/apiface/v0api/market.go @@ -3,8 +3,8 @@ package v0api import ( "context" - "github.com/filecoin-project/venus/app/submodule/apitypes" - "github.com/filecoin-project/venus/pkg/types" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" ) type IMarket interface { diff --git a/app/client/apiface/v0api/mining.go b/app/client/apiface/v0api/mining.go index ccca2ed78b..6f3fc2bcfe 100644 --- a/app/client/apiface/v0api/mining.go +++ b/app/client/apiface/v0api/mining.go @@ -5,8 +5,8 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/venus/app/submodule/apitypes" - "github.com/filecoin-project/venus/pkg/types" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" ) type IMining interface { diff --git a/app/client/apiface/v0api/mpool.go b/app/client/apiface/v0api/mpool.go index 834b1812d8..9db7446fec 100644 --- a/app/client/apiface/v0api/mpool.go +++ b/app/client/apiface/v0api/mpool.go @@ -5,8 +5,9 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/venus/pkg/messagepool" - "github.com/filecoin-project/venus/pkg/types" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" + "github.com/filecoin-project/venus/venus-shared/messagepool" "github.com/ipfs/go-cid" ) @@ -34,25 +35,25 @@ type IMessagePool interface { // Rule[perm:write] MpoolPushUntrusted(ctx context.Context, smsg *types.SignedMessage) (cid.Cid, error) // Rule[perm:sign] - MpoolPushMessage(ctx context.Context, msg *types.UnsignedMessage, spec *types.MessageSendSpec) (*types.SignedMessage, error) + MpoolPushMessage(ctx context.Context, msg *types.Message, spec *apitypes.MessageSendSpec) (*types.SignedMessage, error) // Rule[perm:write] MpoolBatchPush(ctx context.Context, smsgs []*types.SignedMessage) ([]cid.Cid, error) // Rule[perm:write] MpoolBatchPushUntrusted(ctx context.Context, smsgs []*types.SignedMessage) ([]cid.Cid, error) // Rule[perm:sign] - MpoolBatchPushMessage(ctx context.Context, msgs []*types.UnsignedMessage, spec *types.MessageSendSpec) ([]*types.SignedMessage, error) + MpoolBatchPushMessage(ctx context.Context, msgs []*types.Message, spec *apitypes.MessageSendSpec) ([]*types.SignedMessage, error) // Rule[perm:read] MpoolGetNonce(ctx context.Context, addr address.Address) (uint64, error) // Rule[perm:read] MpoolSub(ctx context.Context) (<-chan messagepool.MpoolUpdate, error) // Rule[perm:read] - GasEstimateMessageGas(ctx context.Context, msg *types.UnsignedMessage, spec *types.MessageSendSpec, tsk types.TipSetKey) (*types.UnsignedMessage, error) + GasEstimateMessageGas(ctx context.Context, msg *types.Message, spec *apitypes.MessageSendSpec, tsk types.TipSetKey) (*types.Message, error) // Rule[perm:read] - GasBatchEstimateMessageGas(ctx context.Context, estimateMessages []*types.EstimateMessage, fromNonce uint64, tsk types.TipSetKey) ([]*types.EstimateResult, error) + GasBatchEstimateMessageGas(ctx context.Context, estimateMessages []*apitypes.EstimateMessage, fromNonce uint64, tsk types.TipSetKey) ([]*apitypes.EstimateResult, error) // Rule[perm:read] - GasEstimateFeeCap(ctx context.Context, msg *types.UnsignedMessage, maxqueueblks int64, tsk types.TipSetKey) (big.Int, error) + GasEstimateFeeCap(ctx context.Context, msg *types.Message, maxqueueblks int64, tsk types.TipSetKey) (big.Int, error) // Rule[perm:read] GasEstimateGasPremium(ctx context.Context, nblocksincl uint64, sender address.Address, gaslimit int64, tsk types.TipSetKey) (big.Int, error) // Rule[perm:read] - GasEstimateGasLimit(ctx context.Context, msgIn *types.UnsignedMessage, tsk types.TipSetKey) (int64, error) + GasEstimateGasLimit(ctx context.Context, msgIn *types.Message, tsk types.TipSetKey) (int64, error) } diff --git a/app/client/apiface/v0api/multisig.go b/app/client/apiface/v0api/multisig.go index 0864bdab90..db3731c032 100644 --- a/app/client/apiface/v0api/multisig.go +++ b/app/client/apiface/v0api/multisig.go @@ -7,7 +7,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" ) type IMultiSig interface { diff --git a/app/client/apiface/v0api/network.go b/app/client/apiface/v0api/network.go index 749d7980d3..9f7464bb6a 100644 --- a/app/client/apiface/v0api/network.go +++ b/app/client/apiface/v0api/network.go @@ -3,7 +3,7 @@ package v0api import ( "context" - "github.com/filecoin-project/venus/app/submodule/apitypes" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" "github.com/filecoin-project/venus/pkg/net" "github.com/ipfs/go-cid" diff --git a/app/client/apiface/v0api/paych.go b/app/client/apiface/v0api/paych.go index 6a25683d71..ee4115b038 100644 --- a/app/client/apiface/v0api/paych.go +++ b/app/client/apiface/v0api/paych.go @@ -3,15 +3,13 @@ package v0api import ( "context" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/venus/app/submodule/apitypes" - "github.com/filecoin-project/venus/pkg/paychmgr" - "github.com/filecoin-project/venus/pkg/types" - "github.com/filecoin-project/specs-actors/actors/builtin/paych" "github.com/ipfs/go-cid" - "github.com/filecoin-project/go-address" + "github.com/filecoin-project/venus/pkg/paychmgr" + paychtypes "github.com/filecoin-project/venus/venus-shared/paych" ) type IPaychan interface { @@ -20,7 +18,7 @@ type IPaychan interface { // @to: the payment channel recipient // @amt: the deposits funds in the payment channel // Rule[perm:sign] - PaychGet(ctx context.Context, from, to address.Address, amt big.Int) (*apitypes.ChannelInfo, error) + PaychGet(ctx context.Context, from, to address.Address, amt big.Int) (*paychtypes.ChannelInfo, error) // PaychAvailableFunds get the status of an outbound payment channel // @pch: payment channel address // Rule[perm:sign] @@ -44,14 +42,14 @@ type IPaychan interface { // @to: the payment channel recipient // @vouchers: the outstanding (non-redeemed) vouchers // Rule[perm:sign] - PaychNewPayment(ctx context.Context, from, to address.Address, vouchers []apitypes.VoucherSpec) (*apitypes.PaymentInfo, error) + PaychNewPayment(ctx context.Context, from, to address.Address, vouchers []paychtypes.VoucherSpec) (*paychtypes.PaymentInfo, error) // PaychList list the addresses of all channels that have been created // Rule[perm:read] PaychList(ctx context.Context) ([]address.Address, error) // PaychStatus get the payment channel status // @pch: payment channel address // Rule[perm:read] - PaychStatus(ctx context.Context, pch address.Address) (*types.PaychStatus, error) + PaychStatus(ctx context.Context, pch address.Address) (*paychtypes.Status, error) // PaychSettle update payment channel status to settle // After a settlement period (currently 12 hours) either party to the payment channel can call collect on chain // @pch: payment channel address diff --git a/app/client/apiface/v0api/syncer.go b/app/client/apiface/v0api/syncer.go index 5902edbff9..3967e8a59d 100644 --- a/app/client/apiface/v0api/syncer.go +++ b/app/client/apiface/v0api/syncer.go @@ -4,9 +4,9 @@ import ( "context" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/venus/app/submodule/apitypes" syncTypes "github.com/filecoin-project/venus/pkg/chainsync/types" - "github.com/filecoin-project/venus/pkg/types" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" ) type ISyncer interface { @@ -23,7 +23,7 @@ type ISyncer interface { // Rule[perm:write] SyncSubmitBlock(ctx context.Context, blk *types.BlockMsg) error // Rule[perm:read] - StateCall(ctx context.Context, msg *types.UnsignedMessage, tsk types.TipSetKey) (*types.InvocResult, error) + StateCall(ctx context.Context, msg *types.Message, tsk types.TipSetKey) (*apitypes.InvocResult, error) // Rule[perm:read] SyncState(ctx context.Context) (*apitypes.SyncState, error) } diff --git a/app/client/apiface/v0api/wallet.go b/app/client/apiface/v0api/wallet.go index e516d994bd..ea20b74f12 100644 --- a/app/client/apiface/v0api/wallet.go +++ b/app/client/apiface/v0api/wallet.go @@ -6,8 +6,8 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/venus/pkg/crypto" - "github.com/filecoin-project/venus/pkg/types" - "github.com/filecoin-project/venus/pkg/wallet" + types "github.com/filecoin-project/venus/venus-shared/chain" + "github.com/filecoin-project/venus/venus-shared/wallet" ) type IWallet interface { @@ -30,7 +30,7 @@ type IWallet interface { // Rule[perm:write] WalletSetDefault(ctx context.Context, addr address.Address) error //not exists in remote // Rule[perm:sign] - WalletSignMessage(ctx context.Context, k address.Address, msg *types.UnsignedMessage) (*types.SignedMessage, error) + WalletSignMessage(ctx context.Context, k address.Address, msg *types.Message) (*types.SignedMessage, error) // Rule[perm:admin] LockWallet(ctx context.Context) error // Rule[perm:admin] diff --git a/app/client/apiface/wallet.go b/app/client/apiface/wallet.go index b9733a4f08..74b6217f50 100644 --- a/app/client/apiface/wallet.go +++ b/app/client/apiface/wallet.go @@ -5,9 +5,10 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/venus/pkg/crypto" - "github.com/filecoin-project/venus/pkg/types" - "github.com/filecoin-project/venus/pkg/wallet" + types "github.com/filecoin-project/venus/venus-shared/chain" + "github.com/filecoin-project/venus/venus-shared/wallet" ) type IWallet interface { @@ -30,7 +31,7 @@ type IWallet interface { // Rule[perm:write] WalletSetDefault(ctx context.Context, addr address.Address) error //not exists in remote // Rule[perm:sign] - WalletSignMessage(ctx context.Context, k address.Address, msg *types.UnsignedMessage) (*types.SignedMessage, error) + WalletSignMessage(ctx context.Context, k address.Address, msg *types.Message) (*types.SignedMessage, error) // Rule[perm:admin] LockWallet(ctx context.Context) error // Rule[perm:admin] diff --git a/app/client/full.go b/app/client/full.go index e6ae3ff67f..71acf4a71f 100644 --- a/app/client/full.go +++ b/app/client/full.go @@ -13,16 +13,17 @@ import ( "github.com/filecoin-project/go-state-types/dline" "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/specs-actors/actors/builtin/paych" - "github.com/filecoin-project/venus/app/submodule/apitypes" "github.com/filecoin-project/venus/pkg/chain" syncTypes "github.com/filecoin-project/venus/pkg/chainsync/types" "github.com/filecoin-project/venus/pkg/crypto" - "github.com/filecoin-project/venus/pkg/messagepool" "github.com/filecoin-project/venus/pkg/net" "github.com/filecoin-project/venus/pkg/paychmgr" - "github.com/filecoin-project/venus/pkg/types" - "github.com/filecoin-project/venus/pkg/wallet" "github.com/filecoin-project/venus/venus-shared/actors/builtin/miner" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" + "github.com/filecoin-project/venus/venus-shared/messagepool" + paychtypes "github.com/filecoin-project/venus/venus-shared/paych" + "github.com/filecoin-project/venus/venus-shared/wallet" "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" "github.com/libp2p/go-libp2p-core/metrics" @@ -123,7 +124,7 @@ type IChainInfoStruct struct { ChainExport func(p0 context.Context, p1 abi.ChainEpoch, p2 bool, p3 types.TipSetKey) (<-chan []byte, error) `perm:"read"` ChainGetBlock func(p0 context.Context, p1 cid.Cid) (*types.BlockHeader, error) `perm:"read"` ChainGetBlockMessages func(p0 context.Context, p1 cid.Cid) (*apitypes.BlockMessages, error) `perm:"read"` - ChainGetMessage func(p0 context.Context, p1 cid.Cid) (*types.UnsignedMessage, error) `perm:"read"` + ChainGetMessage func(p0 context.Context, p1 cid.Cid) (*types.Message, error) `perm:"read"` ChainGetMessagesInTipset func(p0 context.Context, p1 types.TipSetKey) ([]apitypes.Message, error) `perm:"read"` ChainGetParentMessages func(p0 context.Context, p1 cid.Cid) ([]apitypes.Message, error) `perm:"read"` ChainGetParentReceipts func(p0 context.Context, p1 cid.Cid) ([]*types.MessageReceipt, error) `perm:"read"` @@ -173,7 +174,7 @@ func (s *IChainInfoStruct) ChainGetBlockMessages(p0 context.Context, p1 cid.Cid) return s.Internal.ChainGetBlockMessages(p0, p1) } -func (s *IChainInfoStruct) ChainGetMessage(p0 context.Context, p1 cid.Cid) (*types.UnsignedMessage, error) { +func (s *IChainInfoStruct) ChainGetMessage(p0 context.Context, p1 cid.Cid) (*types.Message, error) { return s.Internal.ChainGetMessage(p0, p1) } @@ -367,43 +368,43 @@ func (s *IMarketStruct) StateMarketParticipants(p0 context.Context, p1 types.Tip type IMessagePoolStruct struct { Internal struct { - GasBatchEstimateMessageGas func(p0 context.Context, p1 []*types.EstimateMessage, p2 uint64, p3 types.TipSetKey) ([]*types.EstimateResult, error) `perm:"read"` - GasEstimateFeeCap func(p0 context.Context, p1 *types.UnsignedMessage, p2 int64, p3 types.TipSetKey) (big.Int, error) `perm:"read"` - GasEstimateGasLimit func(p0 context.Context, p1 *types.UnsignedMessage, p2 types.TipSetKey) (int64, error) `perm:"read"` - GasEstimateGasPremium func(p0 context.Context, p1 uint64, p2 address.Address, p3 int64, p4 types.TipSetKey) (big.Int, error) `perm:"read"` - GasEstimateMessageGas func(p0 context.Context, p1 *types.UnsignedMessage, p2 *types.MessageSendSpec, p3 types.TipSetKey) (*types.UnsignedMessage, error) `perm:"read"` - MpoolBatchPush func(p0 context.Context, p1 []*types.SignedMessage) ([]cid.Cid, error) `perm:"write"` - MpoolBatchPushMessage func(p0 context.Context, p1 []*types.UnsignedMessage, p2 *types.MessageSendSpec) ([]*types.SignedMessage, error) `perm:"sign"` - MpoolBatchPushUntrusted func(p0 context.Context, p1 []*types.SignedMessage) ([]cid.Cid, error) `perm:"write"` - MpoolCheckMessages func(p0 context.Context, p1 []*apitypes.MessagePrototype) ([][]apitypes.MessageCheckStatus, error) `perm:"read"` - MpoolCheckPendingMessages func(p0 context.Context, p1 address.Address) ([][]apitypes.MessageCheckStatus, error) `perm:"read"` - MpoolCheckReplaceMessages func(p0 context.Context, p1 []*types.Message) ([][]apitypes.MessageCheckStatus, error) `perm:"read"` - MpoolClear func(p0 context.Context, p1 bool) error `perm:"write"` - MpoolDeleteByAdress func(p0 context.Context, p1 address.Address) error `perm:"admin"` - MpoolGetConfig func(p0 context.Context) (*messagepool.MpoolConfig, error) `perm:"read"` - MpoolGetNonce func(p0 context.Context, p1 address.Address) (uint64, error) `perm:"read"` - MpoolPending func(p0 context.Context, p1 types.TipSetKey) ([]*types.SignedMessage, error) `perm:"read"` - MpoolPublishByAddr func(p0 context.Context, p1 address.Address) error `perm:"write"` - MpoolPublishMessage func(p0 context.Context, p1 *types.SignedMessage) error `perm:"write"` - MpoolPush func(p0 context.Context, p1 *types.SignedMessage) (cid.Cid, error) `perm:"write"` - MpoolPushMessage func(p0 context.Context, p1 *types.UnsignedMessage, p2 *types.MessageSendSpec) (*types.SignedMessage, error) `perm:"sign"` - MpoolPushUntrusted func(p0 context.Context, p1 *types.SignedMessage) (cid.Cid, error) `perm:"write"` - MpoolSelect func(p0 context.Context, p1 types.TipSetKey, p2 float64) ([]*types.SignedMessage, error) `perm:"read"` - MpoolSelects func(p0 context.Context, p1 types.TipSetKey, p2 []float64) ([][]*types.SignedMessage, error) `perm:"read"` - MpoolSetConfig func(p0 context.Context, p1 *messagepool.MpoolConfig) error `perm:"admin"` - MpoolSub func(p0 context.Context) (<-chan messagepool.MpoolUpdate, error) `perm:"read"` + GasBatchEstimateMessageGas func(p0 context.Context, p1 []*apitypes.EstimateMessage, p2 uint64, p3 types.TipSetKey) ([]*apitypes.EstimateResult, error) `perm:"read"` + GasEstimateFeeCap func(p0 context.Context, p1 *types.Message, p2 int64, p3 types.TipSetKey) (big.Int, error) `perm:"read"` + GasEstimateGasLimit func(p0 context.Context, p1 *types.Message, p2 types.TipSetKey) (int64, error) `perm:"read"` + GasEstimateGasPremium func(p0 context.Context, p1 uint64, p2 address.Address, p3 int64, p4 types.TipSetKey) (big.Int, error) `perm:"read"` + GasEstimateMessageGas func(p0 context.Context, p1 *types.Message, p2 *apitypes.MessageSendSpec, p3 types.TipSetKey) (*types.Message, error) `perm:"read"` + MpoolBatchPush func(p0 context.Context, p1 []*types.SignedMessage) ([]cid.Cid, error) `perm:"write"` + MpoolBatchPushMessage func(p0 context.Context, p1 []*types.Message, p2 *apitypes.MessageSendSpec) ([]*types.SignedMessage, error) `perm:"sign"` + MpoolBatchPushUntrusted func(p0 context.Context, p1 []*types.SignedMessage) ([]cid.Cid, error) `perm:"write"` + MpoolCheckMessages func(p0 context.Context, p1 []*messagepool.MessagePrototype) ([][]messagepool.MessageCheckStatus, error) `perm:"read"` + MpoolCheckPendingMessages func(p0 context.Context, p1 address.Address) ([][]messagepool.MessageCheckStatus, error) `perm:"read"` + MpoolCheckReplaceMessages func(p0 context.Context, p1 []*types.Message) ([][]messagepool.MessageCheckStatus, error) `perm:"read"` + MpoolClear func(p0 context.Context, p1 bool) error `perm:"write"` + MpoolDeleteByAdress func(p0 context.Context, p1 address.Address) error `perm:"admin"` + MpoolGetConfig func(p0 context.Context) (*messagepool.MpoolConfig, error) `perm:"read"` + MpoolGetNonce func(p0 context.Context, p1 address.Address) (uint64, error) `perm:"read"` + MpoolPending func(p0 context.Context, p1 types.TipSetKey) ([]*types.SignedMessage, error) `perm:"read"` + MpoolPublishByAddr func(p0 context.Context, p1 address.Address) error `perm:"write"` + MpoolPublishMessage func(p0 context.Context, p1 *types.SignedMessage) error `perm:"write"` + MpoolPush func(p0 context.Context, p1 *types.SignedMessage) (cid.Cid, error) `perm:"write"` + MpoolPushMessage func(p0 context.Context, p1 *types.Message, p2 *apitypes.MessageSendSpec) (*types.SignedMessage, error) `perm:"sign"` + MpoolPushUntrusted func(p0 context.Context, p1 *types.SignedMessage) (cid.Cid, error) `perm:"write"` + MpoolSelect func(p0 context.Context, p1 types.TipSetKey, p2 float64) ([]*types.SignedMessage, error) `perm:"read"` + MpoolSelects func(p0 context.Context, p1 types.TipSetKey, p2 []float64) ([][]*types.SignedMessage, error) `perm:"read"` + MpoolSetConfig func(p0 context.Context, p1 *messagepool.MpoolConfig) error `perm:"admin"` + MpoolSub func(p0 context.Context) (<-chan messagepool.MpoolUpdate, error) `perm:"read"` } } -func (s *IMessagePoolStruct) GasBatchEstimateMessageGas(p0 context.Context, p1 []*types.EstimateMessage, p2 uint64, p3 types.TipSetKey) ([]*types.EstimateResult, error) { +func (s *IMessagePoolStruct) GasBatchEstimateMessageGas(p0 context.Context, p1 []*apitypes.EstimateMessage, p2 uint64, p3 types.TipSetKey) ([]*apitypes.EstimateResult, error) { return s.Internal.GasBatchEstimateMessageGas(p0, p1, p2, p3) } -func (s *IMessagePoolStruct) GasEstimateFeeCap(p0 context.Context, p1 *types.UnsignedMessage, p2 int64, p3 types.TipSetKey) (big.Int, error) { +func (s *IMessagePoolStruct) GasEstimateFeeCap(p0 context.Context, p1 *types.Message, p2 int64, p3 types.TipSetKey) (big.Int, error) { return s.Internal.GasEstimateFeeCap(p0, p1, p2, p3) } -func (s *IMessagePoolStruct) GasEstimateGasLimit(p0 context.Context, p1 *types.UnsignedMessage, p2 types.TipSetKey) (int64, error) { +func (s *IMessagePoolStruct) GasEstimateGasLimit(p0 context.Context, p1 *types.Message, p2 types.TipSetKey) (int64, error) { return s.Internal.GasEstimateGasLimit(p0, p1, p2) } @@ -411,7 +412,7 @@ func (s *IMessagePoolStruct) GasEstimateGasPremium(p0 context.Context, p1 uint64 return s.Internal.GasEstimateGasPremium(p0, p1, p2, p3, p4) } -func (s *IMessagePoolStruct) GasEstimateMessageGas(p0 context.Context, p1 *types.UnsignedMessage, p2 *types.MessageSendSpec, p3 types.TipSetKey) (*types.UnsignedMessage, error) { +func (s *IMessagePoolStruct) GasEstimateMessageGas(p0 context.Context, p1 *types.Message, p2 *apitypes.MessageSendSpec, p3 types.TipSetKey) (*types.Message, error) { return s.Internal.GasEstimateMessageGas(p0, p1, p2, p3) } @@ -419,7 +420,7 @@ func (s *IMessagePoolStruct) MpoolBatchPush(p0 context.Context, p1 []*types.Sign return s.Internal.MpoolBatchPush(p0, p1) } -func (s *IMessagePoolStruct) MpoolBatchPushMessage(p0 context.Context, p1 []*types.UnsignedMessage, p2 *types.MessageSendSpec) ([]*types.SignedMessage, error) { +func (s *IMessagePoolStruct) MpoolBatchPushMessage(p0 context.Context, p1 []*types.Message, p2 *apitypes.MessageSendSpec) ([]*types.SignedMessage, error) { return s.Internal.MpoolBatchPushMessage(p0, p1, p2) } @@ -427,15 +428,15 @@ func (s *IMessagePoolStruct) MpoolBatchPushUntrusted(p0 context.Context, p1 []*t return s.Internal.MpoolBatchPushUntrusted(p0, p1) } -func (s *IMessagePoolStruct) MpoolCheckMessages(p0 context.Context, p1 []*apitypes.MessagePrototype) ([][]apitypes.MessageCheckStatus, error) { +func (s *IMessagePoolStruct) MpoolCheckMessages(p0 context.Context, p1 []*messagepool.MessagePrototype) ([][]messagepool.MessageCheckStatus, error) { return s.Internal.MpoolCheckMessages(p0, p1) } -func (s *IMessagePoolStruct) MpoolCheckPendingMessages(p0 context.Context, p1 address.Address) ([][]apitypes.MessageCheckStatus, error) { +func (s *IMessagePoolStruct) MpoolCheckPendingMessages(p0 context.Context, p1 address.Address) ([][]messagepool.MessageCheckStatus, error) { return s.Internal.MpoolCheckPendingMessages(p0, p1) } -func (s *IMessagePoolStruct) MpoolCheckReplaceMessages(p0 context.Context, p1 []*types.Message) ([][]apitypes.MessageCheckStatus, error) { +func (s *IMessagePoolStruct) MpoolCheckReplaceMessages(p0 context.Context, p1 []*types.Message) ([][]messagepool.MessageCheckStatus, error) { return s.Internal.MpoolCheckReplaceMessages(p0, p1) } @@ -471,7 +472,7 @@ func (s *IMessagePoolStruct) MpoolPush(p0 context.Context, p1 *types.SignedMessa return s.Internal.MpoolPush(p0, p1) } -func (s *IMessagePoolStruct) MpoolPushMessage(p0 context.Context, p1 *types.UnsignedMessage, p2 *types.MessageSendSpec) (*types.SignedMessage, error) { +func (s *IMessagePoolStruct) MpoolPushMessage(p0 context.Context, p1 *types.Message, p2 *apitypes.MessageSendSpec) (*types.SignedMessage, error) { return s.Internal.MpoolPushMessage(p0, p1, p2) } @@ -503,7 +504,7 @@ type IMinerStateStruct struct { StateListMiners func(p0 context.Context, p1 types.TipSetKey) ([]address.Address, error) `perm:"read"` StateLookupID func(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (address.Address, error) `perm:"read"` StateMarketBalance func(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (apitypes.MarketBalance, error) `perm:"read"` - StateMarketDeals func(p0 context.Context, p1 types.TipSetKey) (map[string]types.MarketDeal, error) `perm:"read"` + StateMarketDeals func(p0 context.Context, p1 types.TipSetKey) (map[string]apitypes.MarketDeal, error) `perm:"read"` StateMarketStorageDeal func(p0 context.Context, p1 abi.DealID, p2 types.TipSetKey) (*apitypes.MarketDeal, error) `perm:"read"` StateMinerActiveSectors func(p0 context.Context, p1 address.Address, p2 types.TipSetKey) ([]*miner.SectorOnChainInfo, error) `perm:"read"` StateMinerAvailableBalance func(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (big.Int, error) `perm:"read"` @@ -554,7 +555,7 @@ func (s *IMinerStateStruct) StateMarketBalance(p0 context.Context, p1 address.Ad return s.Internal.StateMarketBalance(p0, p1, p2) } -func (s *IMinerStateStruct) StateMarketDeals(p0 context.Context, p1 types.TipSetKey) (map[string]types.MarketDeal, error) { +func (s *IMinerStateStruct) StateMarketDeals(p0 context.Context, p1 types.TipSetKey) (map[string]apitypes.MarketDeal, error) { return s.Internal.StateMarketDeals(p0, p1) } @@ -667,47 +668,47 @@ func (s *IMiningStruct) MinerGetBaseInfo(p0 context.Context, p1 address.Address, type IMultiSigStruct struct { Internal struct { - MsigAddApprove func(p0 context.Context, p1 address.Address, p2 address.Address, p3 uint64, p4 address.Address, p5 address.Address, p6 bool) (*apitypes.MessagePrototype, error) `perm:"sign"` - MsigAddCancel func(p0 context.Context, p1 address.Address, p2 address.Address, p3 uint64, p4 address.Address, p5 bool) (*apitypes.MessagePrototype, error) `perm:"sign"` - MsigAddPropose func(p0 context.Context, p1 address.Address, p2 address.Address, p3 address.Address, p4 bool) (*apitypes.MessagePrototype, error) `perm:"sign"` - MsigApprove func(p0 context.Context, p1 address.Address, p2 uint64, p3 address.Address) (*apitypes.MessagePrototype, error) `perm:"sign"` - MsigApproveTxnHash func(p0 context.Context, p1 address.Address, p2 uint64, p3 address.Address, p4 address.Address, p5 types.BigInt, p6 address.Address, p7 uint64, p8 []byte) (*apitypes.MessagePrototype, error) `perm:"sign"` - MsigCancel func(p0 context.Context, p1 address.Address, p2 uint64, p3 address.Address, p4 types.BigInt, p5 address.Address, p6 uint64, p7 []byte) (*apitypes.MessagePrototype, error) `perm:"sign"` - MsigCreate func(p0 context.Context, p1 uint64, p2 []address.Address, p3 abi.ChainEpoch, p4 types.BigInt, p5 address.Address, p6 types.BigInt) (*apitypes.MessagePrototype, error) `perm:"sign"` - MsigGetVested func(p0 context.Context, p1 address.Address, p2 types.TipSetKey, p3 types.TipSetKey) (types.BigInt, error) `perm:"read"` - MsigPropose func(p0 context.Context, p1 address.Address, p2 address.Address, p3 types.BigInt, p4 address.Address, p5 uint64, p6 []byte) (*apitypes.MessagePrototype, error) `perm:"sign"` - MsigRemoveSigner func(p0 context.Context, p1 address.Address, p2 address.Address, p3 address.Address, p4 bool) (*apitypes.MessagePrototype, error) `perm:"sign"` - MsigSwapApprove func(p0 context.Context, p1 address.Address, p2 address.Address, p3 uint64, p4 address.Address, p5 address.Address, p6 address.Address) (*apitypes.MessagePrototype, error) `perm:"sign"` - MsigSwapCancel func(p0 context.Context, p1 address.Address, p2 address.Address, p3 uint64, p4 address.Address, p5 address.Address) (*apitypes.MessagePrototype, error) `perm:"sign"` - MsigSwapPropose func(p0 context.Context, p1 address.Address, p2 address.Address, p3 address.Address, p4 address.Address) (*apitypes.MessagePrototype, error) `perm:"sign"` + MsigAddApprove func(p0 context.Context, p1 address.Address, p2 address.Address, p3 uint64, p4 address.Address, p5 address.Address, p6 bool) (*messagepool.MessagePrototype, error) `perm:"sign"` + MsigAddCancel func(p0 context.Context, p1 address.Address, p2 address.Address, p3 uint64, p4 address.Address, p5 bool) (*messagepool.MessagePrototype, error) `perm:"sign"` + MsigAddPropose func(p0 context.Context, p1 address.Address, p2 address.Address, p3 address.Address, p4 bool) (*messagepool.MessagePrototype, error) `perm:"sign"` + MsigApprove func(p0 context.Context, p1 address.Address, p2 uint64, p3 address.Address) (*messagepool.MessagePrototype, error) `perm:"sign"` + MsigApproveTxnHash func(p0 context.Context, p1 address.Address, p2 uint64, p3 address.Address, p4 address.Address, p5 types.BigInt, p6 address.Address, p7 uint64, p8 []byte) (*messagepool.MessagePrototype, error) `perm:"sign"` + MsigCancel func(p0 context.Context, p1 address.Address, p2 uint64, p3 address.Address, p4 types.BigInt, p5 address.Address, p6 uint64, p7 []byte) (*messagepool.MessagePrototype, error) `perm:"sign"` + MsigCreate func(p0 context.Context, p1 uint64, p2 []address.Address, p3 abi.ChainEpoch, p4 types.BigInt, p5 address.Address, p6 types.BigInt) (*messagepool.MessagePrototype, error) `perm:"sign"` + MsigGetVested func(p0 context.Context, p1 address.Address, p2 types.TipSetKey, p3 types.TipSetKey) (types.BigInt, error) `perm:"read"` + MsigPropose func(p0 context.Context, p1 address.Address, p2 address.Address, p3 types.BigInt, p4 address.Address, p5 uint64, p6 []byte) (*messagepool.MessagePrototype, error) `perm:"sign"` + MsigRemoveSigner func(p0 context.Context, p1 address.Address, p2 address.Address, p3 address.Address, p4 bool) (*messagepool.MessagePrototype, error) `perm:"sign"` + MsigSwapApprove func(p0 context.Context, p1 address.Address, p2 address.Address, p3 uint64, p4 address.Address, p5 address.Address, p6 address.Address) (*messagepool.MessagePrototype, error) `perm:"sign"` + MsigSwapCancel func(p0 context.Context, p1 address.Address, p2 address.Address, p3 uint64, p4 address.Address, p5 address.Address) (*messagepool.MessagePrototype, error) `perm:"sign"` + MsigSwapPropose func(p0 context.Context, p1 address.Address, p2 address.Address, p3 address.Address, p4 address.Address) (*messagepool.MessagePrototype, error) `perm:"sign"` } } -func (s *IMultiSigStruct) MsigAddApprove(p0 context.Context, p1 address.Address, p2 address.Address, p3 uint64, p4 address.Address, p5 address.Address, p6 bool) (*apitypes.MessagePrototype, error) { +func (s *IMultiSigStruct) MsigAddApprove(p0 context.Context, p1 address.Address, p2 address.Address, p3 uint64, p4 address.Address, p5 address.Address, p6 bool) (*messagepool.MessagePrototype, error) { return s.Internal.MsigAddApprove(p0, p1, p2, p3, p4, p5, p6) } -func (s *IMultiSigStruct) MsigAddCancel(p0 context.Context, p1 address.Address, p2 address.Address, p3 uint64, p4 address.Address, p5 bool) (*apitypes.MessagePrototype, error) { +func (s *IMultiSigStruct) MsigAddCancel(p0 context.Context, p1 address.Address, p2 address.Address, p3 uint64, p4 address.Address, p5 bool) (*messagepool.MessagePrototype, error) { return s.Internal.MsigAddCancel(p0, p1, p2, p3, p4, p5) } -func (s *IMultiSigStruct) MsigAddPropose(p0 context.Context, p1 address.Address, p2 address.Address, p3 address.Address, p4 bool) (*apitypes.MessagePrototype, error) { +func (s *IMultiSigStruct) MsigAddPropose(p0 context.Context, p1 address.Address, p2 address.Address, p3 address.Address, p4 bool) (*messagepool.MessagePrototype, error) { return s.Internal.MsigAddPropose(p0, p1, p2, p3, p4) } -func (s *IMultiSigStruct) MsigApprove(p0 context.Context, p1 address.Address, p2 uint64, p3 address.Address) (*apitypes.MessagePrototype, error) { +func (s *IMultiSigStruct) MsigApprove(p0 context.Context, p1 address.Address, p2 uint64, p3 address.Address) (*messagepool.MessagePrototype, error) { return s.Internal.MsigApprove(p0, p1, p2, p3) } -func (s *IMultiSigStruct) MsigApproveTxnHash(p0 context.Context, p1 address.Address, p2 uint64, p3 address.Address, p4 address.Address, p5 types.BigInt, p6 address.Address, p7 uint64, p8 []byte) (*apitypes.MessagePrototype, error) { +func (s *IMultiSigStruct) MsigApproveTxnHash(p0 context.Context, p1 address.Address, p2 uint64, p3 address.Address, p4 address.Address, p5 types.BigInt, p6 address.Address, p7 uint64, p8 []byte) (*messagepool.MessagePrototype, error) { return s.Internal.MsigApproveTxnHash(p0, p1, p2, p3, p4, p5, p6, p7, p8) } -func (s *IMultiSigStruct) MsigCancel(p0 context.Context, p1 address.Address, p2 uint64, p3 address.Address, p4 types.BigInt, p5 address.Address, p6 uint64, p7 []byte) (*apitypes.MessagePrototype, error) { +func (s *IMultiSigStruct) MsigCancel(p0 context.Context, p1 address.Address, p2 uint64, p3 address.Address, p4 types.BigInt, p5 address.Address, p6 uint64, p7 []byte) (*messagepool.MessagePrototype, error) { return s.Internal.MsigCancel(p0, p1, p2, p3, p4, p5, p6, p7) } -func (s *IMultiSigStruct) MsigCreate(p0 context.Context, p1 uint64, p2 []address.Address, p3 abi.ChainEpoch, p4 types.BigInt, p5 address.Address, p6 types.BigInt) (*apitypes.MessagePrototype, error) { +func (s *IMultiSigStruct) MsigCreate(p0 context.Context, p1 uint64, p2 []address.Address, p3 abi.ChainEpoch, p4 types.BigInt, p5 address.Address, p6 types.BigInt) (*messagepool.MessagePrototype, error) { return s.Internal.MsigCreate(p0, p1, p2, p3, p4, p5, p6) } @@ -715,23 +716,23 @@ func (s *IMultiSigStruct) MsigGetVested(p0 context.Context, p1 address.Address, return s.Internal.MsigGetVested(p0, p1, p2, p3) } -func (s *IMultiSigStruct) MsigPropose(p0 context.Context, p1 address.Address, p2 address.Address, p3 types.BigInt, p4 address.Address, p5 uint64, p6 []byte) (*apitypes.MessagePrototype, error) { +func (s *IMultiSigStruct) MsigPropose(p0 context.Context, p1 address.Address, p2 address.Address, p3 types.BigInt, p4 address.Address, p5 uint64, p6 []byte) (*messagepool.MessagePrototype, error) { return s.Internal.MsigPropose(p0, p1, p2, p3, p4, p5, p6) } -func (s *IMultiSigStruct) MsigRemoveSigner(p0 context.Context, p1 address.Address, p2 address.Address, p3 address.Address, p4 bool) (*apitypes.MessagePrototype, error) { +func (s *IMultiSigStruct) MsigRemoveSigner(p0 context.Context, p1 address.Address, p2 address.Address, p3 address.Address, p4 bool) (*messagepool.MessagePrototype, error) { return s.Internal.MsigRemoveSigner(p0, p1, p2, p3, p4) } -func (s *IMultiSigStruct) MsigSwapApprove(p0 context.Context, p1 address.Address, p2 address.Address, p3 uint64, p4 address.Address, p5 address.Address, p6 address.Address) (*apitypes.MessagePrototype, error) { +func (s *IMultiSigStruct) MsigSwapApprove(p0 context.Context, p1 address.Address, p2 address.Address, p3 uint64, p4 address.Address, p5 address.Address, p6 address.Address) (*messagepool.MessagePrototype, error) { return s.Internal.MsigSwapApprove(p0, p1, p2, p3, p4, p5, p6) } -func (s *IMultiSigStruct) MsigSwapCancel(p0 context.Context, p1 address.Address, p2 address.Address, p3 uint64, p4 address.Address, p5 address.Address) (*apitypes.MessagePrototype, error) { +func (s *IMultiSigStruct) MsigSwapCancel(p0 context.Context, p1 address.Address, p2 address.Address, p3 uint64, p4 address.Address, p5 address.Address) (*messagepool.MessagePrototype, error) { return s.Internal.MsigSwapCancel(p0, p1, p2, p3, p4, p5) } -func (s *IMultiSigStruct) MsigSwapPropose(p0 context.Context, p1 address.Address, p2 address.Address, p3 address.Address, p4 address.Address) (*apitypes.MessagePrototype, error) { +func (s *IMultiSigStruct) MsigSwapPropose(p0 context.Context, p1 address.Address, p2 address.Address, p3 address.Address, p4 address.Address) (*messagepool.MessagePrototype, error) { return s.Internal.MsigSwapPropose(p0, p1, p2, p3, p4) } @@ -792,22 +793,22 @@ func (s *INetworkStruct) Version(p0 context.Context) (apitypes.Version, error) { type IPaychanStruct struct { Internal struct { - PaychAllocateLane func(p0 context.Context, p1 address.Address) (uint64, error) `perm:"sign"` - PaychAvailableFunds func(p0 context.Context, p1 address.Address) (*paychmgr.ChannelAvailableFunds, error) `perm:"sign"` - PaychAvailableFundsByFromTo func(p0 context.Context, p1 address.Address, p2 address.Address) (*paychmgr.ChannelAvailableFunds, error) `perm:"sign"` - PaychCollect func(p0 context.Context, p1 address.Address) (cid.Cid, error) `perm:"sign"` - PaychGet func(p0 context.Context, p1 address.Address, p2 address.Address, p3 big.Int) (*apitypes.ChannelInfo, error) `perm:"sign"` - PaychGetWaitReady func(p0 context.Context, p1 cid.Cid) (address.Address, error) `perm:"sign"` - PaychList func(p0 context.Context) ([]address.Address, error) `perm:"read"` - PaychNewPayment func(p0 context.Context, p1 address.Address, p2 address.Address, p3 []apitypes.VoucherSpec) (*apitypes.PaymentInfo, error) `perm:"sign"` - PaychSettle func(p0 context.Context, p1 address.Address) (cid.Cid, error) `perm:"sign"` - PaychStatus func(p0 context.Context, p1 address.Address) (*types.PaychStatus, error) `perm:"read"` - PaychVoucherAdd func(p0 context.Context, p1 address.Address, p2 *paych.SignedVoucher, p3 []byte, p4 big.Int) (big.Int, error) `perm:"write"` - PaychVoucherCheckSpendable func(p0 context.Context, p1 address.Address, p2 *paych.SignedVoucher, p3 []byte, p4 []byte) (bool, error) `perm:"read"` - PaychVoucherCheckValid func(p0 context.Context, p1 address.Address, p2 *paych.SignedVoucher) error `perm:"read"` - PaychVoucherCreate func(p0 context.Context, p1 address.Address, p2 big.Int, p3 uint64) (*paychmgr.VoucherCreateResult, error) `perm:"sign"` - PaychVoucherList func(p0 context.Context, p1 address.Address) ([]*paych.SignedVoucher, error) `perm:"write"` - PaychVoucherSubmit func(p0 context.Context, p1 address.Address, p2 *paych.SignedVoucher, p3 []byte, p4 []byte) (cid.Cid, error) `perm:"sign"` + PaychAllocateLane func(p0 context.Context, p1 address.Address) (uint64, error) `perm:"sign"` + PaychAvailableFunds func(p0 context.Context, p1 address.Address) (*paychmgr.ChannelAvailableFunds, error) `perm:"sign"` + PaychAvailableFundsByFromTo func(p0 context.Context, p1 address.Address, p2 address.Address) (*paychmgr.ChannelAvailableFunds, error) `perm:"sign"` + PaychCollect func(p0 context.Context, p1 address.Address) (cid.Cid, error) `perm:"sign"` + PaychGet func(p0 context.Context, p1 address.Address, p2 address.Address, p3 big.Int) (*paychtypes.ChannelInfo, error) `perm:"sign"` + PaychGetWaitReady func(p0 context.Context, p1 cid.Cid) (address.Address, error) `perm:"sign"` + PaychList func(p0 context.Context) ([]address.Address, error) `perm:"read"` + PaychNewPayment func(p0 context.Context, p1 address.Address, p2 address.Address, p3 []paychtypes.VoucherSpec) (*paychtypes.PaymentInfo, error) `perm:"sign"` + PaychSettle func(p0 context.Context, p1 address.Address) (cid.Cid, error) `perm:"sign"` + PaychStatus func(p0 context.Context, p1 address.Address) (*paychtypes.Status, error) `perm:"read"` + PaychVoucherAdd func(p0 context.Context, p1 address.Address, p2 *paych.SignedVoucher, p3 []byte, p4 big.Int) (big.Int, error) `perm:"write"` + PaychVoucherCheckSpendable func(p0 context.Context, p1 address.Address, p2 *paych.SignedVoucher, p3 []byte, p4 []byte) (bool, error) `perm:"read"` + PaychVoucherCheckValid func(p0 context.Context, p1 address.Address, p2 *paych.SignedVoucher) error `perm:"read"` + PaychVoucherCreate func(p0 context.Context, p1 address.Address, p2 big.Int, p3 uint64) (*paychmgr.VoucherCreateResult, error) `perm:"sign"` + PaychVoucherList func(p0 context.Context, p1 address.Address) ([]*paych.SignedVoucher, error) `perm:"write"` + PaychVoucherSubmit func(p0 context.Context, p1 address.Address, p2 *paych.SignedVoucher, p3 []byte, p4 []byte) (cid.Cid, error) `perm:"sign"` } } @@ -827,7 +828,7 @@ func (s *IPaychanStruct) PaychCollect(p0 context.Context, p1 address.Address) (c return s.Internal.PaychCollect(p0, p1) } -func (s *IPaychanStruct) PaychGet(p0 context.Context, p1 address.Address, p2 address.Address, p3 big.Int) (*apitypes.ChannelInfo, error) { +func (s *IPaychanStruct) PaychGet(p0 context.Context, p1 address.Address, p2 address.Address, p3 big.Int) (*paychtypes.ChannelInfo, error) { return s.Internal.PaychGet(p0, p1, p2, p3) } @@ -839,7 +840,7 @@ func (s *IPaychanStruct) PaychList(p0 context.Context) ([]address.Address, error return s.Internal.PaychList(p0) } -func (s *IPaychanStruct) PaychNewPayment(p0 context.Context, p1 address.Address, p2 address.Address, p3 []apitypes.VoucherSpec) (*apitypes.PaymentInfo, error) { +func (s *IPaychanStruct) PaychNewPayment(p0 context.Context, p1 address.Address, p2 address.Address, p3 []paychtypes.VoucherSpec) (*paychtypes.PaymentInfo, error) { return s.Internal.PaychNewPayment(p0, p1, p2, p3) } @@ -847,7 +848,7 @@ func (s *IPaychanStruct) PaychSettle(p0 context.Context, p1 address.Address) (ci return s.Internal.PaychSettle(p0, p1) } -func (s *IPaychanStruct) PaychStatus(p0 context.Context, p1 address.Address) (*types.PaychStatus, error) { +func (s *IPaychanStruct) PaychStatus(p0 context.Context, p1 address.Address) (*paychtypes.Status, error) { return s.Internal.PaychStatus(p0, p1) } @@ -877,14 +878,14 @@ func (s *IPaychanStruct) PaychVoucherSubmit(p0 context.Context, p1 address.Addre type ISyncerStruct struct { Internal struct { - ChainSyncHandleNewTipSet func(p0 context.Context, p1 *types.ChainInfo) error `perm:"write"` - ChainTipSetWeight func(p0 context.Context, p1 types.TipSetKey) (big.Int, error) `perm:"read"` - Concurrent func(p0 context.Context) int64 `perm:"read"` - SetConcurrent func(p0 context.Context, p1 int64) error `perm:"admin"` - StateCall func(p0 context.Context, p1 *types.UnsignedMessage, p2 types.TipSetKey) (*types.InvocResult, error) `perm:"read"` - SyncState func(p0 context.Context) (*apitypes.SyncState, error) `perm:"read"` - SyncSubmitBlock func(p0 context.Context, p1 *types.BlockMsg) error `perm:"write"` - SyncerTracker func(p0 context.Context) *syncTypes.TargetTracker `perm:"read"` + ChainSyncHandleNewTipSet func(p0 context.Context, p1 *types.ChainInfo) error `perm:"write"` + ChainTipSetWeight func(p0 context.Context, p1 types.TipSetKey) (big.Int, error) `perm:"read"` + Concurrent func(p0 context.Context) int64 `perm:"read"` + SetConcurrent func(p0 context.Context, p1 int64) error `perm:"admin"` + StateCall func(p0 context.Context, p1 *types.Message, p2 types.TipSetKey) (*apitypes.InvocResult, error) `perm:"read"` + SyncState func(p0 context.Context) (*apitypes.SyncState, error) `perm:"read"` + SyncSubmitBlock func(p0 context.Context, p1 *types.BlockMsg) error `perm:"write"` + SyncerTracker func(p0 context.Context) *syncTypes.TargetTracker `perm:"read"` } } @@ -904,7 +905,7 @@ func (s *ISyncerStruct) SetConcurrent(p0 context.Context, p1 int64) error { return s.Internal.SetConcurrent(p0, p1) } -func (s *ISyncerStruct) StateCall(p0 context.Context, p1 *types.UnsignedMessage, p2 types.TipSetKey) (*types.InvocResult, error) { +func (s *ISyncerStruct) StateCall(p0 context.Context, p1 *types.Message, p2 types.TipSetKey) (*apitypes.InvocResult, error) { return s.Internal.StateCall(p0, p1, p2) } @@ -935,7 +936,7 @@ type IWalletStruct struct { WalletNewAddress func(p0 address.Protocol) (address.Address, error) `perm:"write"` WalletSetDefault func(p0 context.Context, p1 address.Address) error `perm:"write"` WalletSign func(p0 context.Context, p1 address.Address, p2 []byte, p3 wallet.MsgMeta) (*crypto.Signature, error) `perm:"sign"` - WalletSignMessage func(p0 context.Context, p1 address.Address, p2 *types.UnsignedMessage) (*types.SignedMessage, error) `perm:"sign"` + WalletSignMessage func(p0 context.Context, p1 address.Address, p2 *types.Message) (*types.SignedMessage, error) `perm:"sign"` WalletState func(p0 context.Context) int `perm:"admin"` } } @@ -992,7 +993,7 @@ func (s *IWalletStruct) WalletSign(p0 context.Context, p1 address.Address, p2 [] return s.Internal.WalletSign(p0, p1, p2, p3) } -func (s *IWalletStruct) WalletSignMessage(p0 context.Context, p1 address.Address, p2 *types.UnsignedMessage) (*types.SignedMessage, error) { +func (s *IWalletStruct) WalletSignMessage(p0 context.Context, p1 address.Address, p2 *types.Message) (*types.SignedMessage, error) { return s.Internal.WalletSignMessage(p0, p1, p2) } diff --git a/app/client/v0api/full.go b/app/client/v0api/full.go index 7f9190b650..51ab9ddc4d 100644 --- a/app/client/v0api/full.go +++ b/app/client/v0api/full.go @@ -13,16 +13,17 @@ import ( "github.com/filecoin-project/go-state-types/dline" "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/specs-actors/actors/builtin/paych" - "github.com/filecoin-project/venus/app/submodule/apitypes" "github.com/filecoin-project/venus/pkg/chain" syncTypes "github.com/filecoin-project/venus/pkg/chainsync/types" "github.com/filecoin-project/venus/pkg/crypto" - "github.com/filecoin-project/venus/pkg/messagepool" "github.com/filecoin-project/venus/pkg/net" "github.com/filecoin-project/venus/pkg/paychmgr" - "github.com/filecoin-project/venus/pkg/types" - "github.com/filecoin-project/venus/pkg/wallet" "github.com/filecoin-project/venus/venus-shared/actors/builtin/miner" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" + "github.com/filecoin-project/venus/venus-shared/messagepool" + paychtypes "github.com/filecoin-project/venus/venus-shared/paych" + "github.com/filecoin-project/venus/venus-shared/wallet" "github.com/ipfs/go-cid" ipld "github.com/ipfs/go-ipld-format" "github.com/libp2p/go-libp2p-core/metrics" @@ -123,7 +124,7 @@ type IChainInfoStruct struct { ChainExport func(p0 context.Context, p1 abi.ChainEpoch, p2 bool, p3 types.TipSetKey) (<-chan []byte, error) `perm:"read"` ChainGetBlock func(p0 context.Context, p1 cid.Cid) (*types.BlockHeader, error) `perm:"read"` ChainGetBlockMessages func(p0 context.Context, p1 cid.Cid) (*apitypes.BlockMessages, error) `perm:"read"` - ChainGetMessage func(p0 context.Context, p1 cid.Cid) (*types.UnsignedMessage, error) `perm:"read"` + ChainGetMessage func(p0 context.Context, p1 cid.Cid) (*types.Message, error) `perm:"read"` ChainGetMessagesInTipset func(p0 context.Context, p1 types.TipSetKey) ([]apitypes.Message, error) `perm:"read"` ChainGetParentMessages func(p0 context.Context, p1 cid.Cid) ([]apitypes.Message, error) `perm:"read"` ChainGetParentReceipts func(p0 context.Context, p1 cid.Cid) ([]*types.MessageReceipt, error) `perm:"read"` @@ -173,7 +174,7 @@ func (s *IChainInfoStruct) ChainGetBlockMessages(p0 context.Context, p1 cid.Cid) return s.Internal.ChainGetBlockMessages(p0, p1) } -func (s *IChainInfoStruct) ChainGetMessage(p0 context.Context, p1 cid.Cid) (*types.UnsignedMessage, error) { +func (s *IChainInfoStruct) ChainGetMessage(p0 context.Context, p1 cid.Cid) (*types.Message, error) { return s.Internal.ChainGetMessage(p0, p1) } @@ -367,40 +368,40 @@ func (s *IMarketStruct) StateMarketParticipants(p0 context.Context, p1 types.Tip type IMessagePoolStruct struct { Internal struct { - GasBatchEstimateMessageGas func(p0 context.Context, p1 []*types.EstimateMessage, p2 uint64, p3 types.TipSetKey) ([]*types.EstimateResult, error) `perm:"read"` - GasEstimateFeeCap func(p0 context.Context, p1 *types.UnsignedMessage, p2 int64, p3 types.TipSetKey) (big.Int, error) `perm:"read"` - GasEstimateGasLimit func(p0 context.Context, p1 *types.UnsignedMessage, p2 types.TipSetKey) (int64, error) `perm:"read"` - GasEstimateGasPremium func(p0 context.Context, p1 uint64, p2 address.Address, p3 int64, p4 types.TipSetKey) (big.Int, error) `perm:"read"` - GasEstimateMessageGas func(p0 context.Context, p1 *types.UnsignedMessage, p2 *types.MessageSendSpec, p3 types.TipSetKey) (*types.UnsignedMessage, error) `perm:"read"` - MpoolBatchPush func(p0 context.Context, p1 []*types.SignedMessage) ([]cid.Cid, error) `perm:"write"` - MpoolBatchPushMessage func(p0 context.Context, p1 []*types.UnsignedMessage, p2 *types.MessageSendSpec) ([]*types.SignedMessage, error) `perm:"sign"` - MpoolBatchPushUntrusted func(p0 context.Context, p1 []*types.SignedMessage) ([]cid.Cid, error) `perm:"write"` - MpoolClear func(p0 context.Context, p1 bool) error `perm:"write"` - MpoolDeleteByAdress func(p0 context.Context, p1 address.Address) error `perm:"admin"` - MpoolGetConfig func(p0 context.Context) (*messagepool.MpoolConfig, error) `perm:"read"` - MpoolGetNonce func(p0 context.Context, p1 address.Address) (uint64, error) `perm:"read"` - MpoolPending func(p0 context.Context, p1 types.TipSetKey) ([]*types.SignedMessage, error) `perm:"read"` - MpoolPublishByAddr func(p0 context.Context, p1 address.Address) error `perm:"write"` - MpoolPublishMessage func(p0 context.Context, p1 *types.SignedMessage) error `perm:"write"` - MpoolPush func(p0 context.Context, p1 *types.SignedMessage) (cid.Cid, error) `perm:"write"` - MpoolPushMessage func(p0 context.Context, p1 *types.UnsignedMessage, p2 *types.MessageSendSpec) (*types.SignedMessage, error) `perm:"sign"` - MpoolPushUntrusted func(p0 context.Context, p1 *types.SignedMessage) (cid.Cid, error) `perm:"write"` - MpoolSelect func(p0 context.Context, p1 types.TipSetKey, p2 float64) ([]*types.SignedMessage, error) `perm:"read"` - MpoolSelects func(p0 context.Context, p1 types.TipSetKey, p2 []float64) ([][]*types.SignedMessage, error) `perm:"read"` - MpoolSetConfig func(p0 context.Context, p1 *messagepool.MpoolConfig) error `perm:"admin"` - MpoolSub func(p0 context.Context) (<-chan messagepool.MpoolUpdate, error) `perm:"read"` + GasBatchEstimateMessageGas func(p0 context.Context, p1 []*apitypes.EstimateMessage, p2 uint64, p3 types.TipSetKey) ([]*apitypes.EstimateResult, error) `perm:"read"` + GasEstimateFeeCap func(p0 context.Context, p1 *types.Message, p2 int64, p3 types.TipSetKey) (big.Int, error) `perm:"read"` + GasEstimateGasLimit func(p0 context.Context, p1 *types.Message, p2 types.TipSetKey) (int64, error) `perm:"read"` + GasEstimateGasPremium func(p0 context.Context, p1 uint64, p2 address.Address, p3 int64, p4 types.TipSetKey) (big.Int, error) `perm:"read"` + GasEstimateMessageGas func(p0 context.Context, p1 *types.Message, p2 *apitypes.MessageSendSpec, p3 types.TipSetKey) (*types.Message, error) `perm:"read"` + MpoolBatchPush func(p0 context.Context, p1 []*types.SignedMessage) ([]cid.Cid, error) `perm:"write"` + MpoolBatchPushMessage func(p0 context.Context, p1 []*types.Message, p2 *apitypes.MessageSendSpec) ([]*types.SignedMessage, error) `perm:"sign"` + MpoolBatchPushUntrusted func(p0 context.Context, p1 []*types.SignedMessage) ([]cid.Cid, error) `perm:"write"` + MpoolClear func(p0 context.Context, p1 bool) error `perm:"write"` + MpoolDeleteByAdress func(p0 context.Context, p1 address.Address) error `perm:"admin"` + MpoolGetConfig func(p0 context.Context) (*messagepool.MpoolConfig, error) `perm:"read"` + MpoolGetNonce func(p0 context.Context, p1 address.Address) (uint64, error) `perm:"read"` + MpoolPending func(p0 context.Context, p1 types.TipSetKey) ([]*types.SignedMessage, error) `perm:"read"` + MpoolPublishByAddr func(p0 context.Context, p1 address.Address) error `perm:"write"` + MpoolPublishMessage func(p0 context.Context, p1 *types.SignedMessage) error `perm:"write"` + MpoolPush func(p0 context.Context, p1 *types.SignedMessage) (cid.Cid, error) `perm:"write"` + MpoolPushMessage func(p0 context.Context, p1 *types.Message, p2 *apitypes.MessageSendSpec) (*types.SignedMessage, error) `perm:"sign"` + MpoolPushUntrusted func(p0 context.Context, p1 *types.SignedMessage) (cid.Cid, error) `perm:"write"` + MpoolSelect func(p0 context.Context, p1 types.TipSetKey, p2 float64) ([]*types.SignedMessage, error) `perm:"read"` + MpoolSelects func(p0 context.Context, p1 types.TipSetKey, p2 []float64) ([][]*types.SignedMessage, error) `perm:"read"` + MpoolSetConfig func(p0 context.Context, p1 *messagepool.MpoolConfig) error `perm:"admin"` + MpoolSub func(p0 context.Context) (<-chan messagepool.MpoolUpdate, error) `perm:"read"` } } -func (s *IMessagePoolStruct) GasBatchEstimateMessageGas(p0 context.Context, p1 []*types.EstimateMessage, p2 uint64, p3 types.TipSetKey) ([]*types.EstimateResult, error) { +func (s *IMessagePoolStruct) GasBatchEstimateMessageGas(p0 context.Context, p1 []*apitypes.EstimateMessage, p2 uint64, p3 types.TipSetKey) ([]*apitypes.EstimateResult, error) { return s.Internal.GasBatchEstimateMessageGas(p0, p1, p2, p3) } -func (s *IMessagePoolStruct) GasEstimateFeeCap(p0 context.Context, p1 *types.UnsignedMessage, p2 int64, p3 types.TipSetKey) (big.Int, error) { +func (s *IMessagePoolStruct) GasEstimateFeeCap(p0 context.Context, p1 *types.Message, p2 int64, p3 types.TipSetKey) (big.Int, error) { return s.Internal.GasEstimateFeeCap(p0, p1, p2, p3) } -func (s *IMessagePoolStruct) GasEstimateGasLimit(p0 context.Context, p1 *types.UnsignedMessage, p2 types.TipSetKey) (int64, error) { +func (s *IMessagePoolStruct) GasEstimateGasLimit(p0 context.Context, p1 *types.Message, p2 types.TipSetKey) (int64, error) { return s.Internal.GasEstimateGasLimit(p0, p1, p2) } @@ -408,7 +409,7 @@ func (s *IMessagePoolStruct) GasEstimateGasPremium(p0 context.Context, p1 uint64 return s.Internal.GasEstimateGasPremium(p0, p1, p2, p3, p4) } -func (s *IMessagePoolStruct) GasEstimateMessageGas(p0 context.Context, p1 *types.UnsignedMessage, p2 *types.MessageSendSpec, p3 types.TipSetKey) (*types.UnsignedMessage, error) { +func (s *IMessagePoolStruct) GasEstimateMessageGas(p0 context.Context, p1 *types.Message, p2 *apitypes.MessageSendSpec, p3 types.TipSetKey) (*types.Message, error) { return s.Internal.GasEstimateMessageGas(p0, p1, p2, p3) } @@ -416,7 +417,7 @@ func (s *IMessagePoolStruct) MpoolBatchPush(p0 context.Context, p1 []*types.Sign return s.Internal.MpoolBatchPush(p0, p1) } -func (s *IMessagePoolStruct) MpoolBatchPushMessage(p0 context.Context, p1 []*types.UnsignedMessage, p2 *types.MessageSendSpec) ([]*types.SignedMessage, error) { +func (s *IMessagePoolStruct) MpoolBatchPushMessage(p0 context.Context, p1 []*types.Message, p2 *apitypes.MessageSendSpec) ([]*types.SignedMessage, error) { return s.Internal.MpoolBatchPushMessage(p0, p1, p2) } @@ -456,7 +457,7 @@ func (s *IMessagePoolStruct) MpoolPush(p0 context.Context, p1 *types.SignedMessa return s.Internal.MpoolPush(p0, p1) } -func (s *IMessagePoolStruct) MpoolPushMessage(p0 context.Context, p1 *types.UnsignedMessage, p2 *types.MessageSendSpec) (*types.SignedMessage, error) { +func (s *IMessagePoolStruct) MpoolPushMessage(p0 context.Context, p1 *types.Message, p2 *apitypes.MessageSendSpec) (*types.SignedMessage, error) { return s.Internal.MpoolPushMessage(p0, p1, p2) } @@ -488,7 +489,7 @@ type IMinerStateStruct struct { StateListMiners func(p0 context.Context, p1 types.TipSetKey) ([]address.Address, error) `perm:"read"` StateLookupID func(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (address.Address, error) `perm:"read"` StateMarketBalance func(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (apitypes.MarketBalance, error) `perm:"read"` - StateMarketDeals func(p0 context.Context, p1 types.TipSetKey) (map[string]types.MarketDeal, error) `perm:"read"` + StateMarketDeals func(p0 context.Context, p1 types.TipSetKey) (map[string]apitypes.MarketDeal, error) `perm:"read"` StateMarketStorageDeal func(p0 context.Context, p1 abi.DealID, p2 types.TipSetKey) (*apitypes.MarketDeal, error) `perm:"read"` StateMinerActiveSectors func(p0 context.Context, p1 address.Address, p2 types.TipSetKey) ([]*miner.SectorOnChainInfo, error) `perm:"read"` StateMinerAvailableBalance func(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (big.Int, error) `perm:"read"` @@ -539,7 +540,7 @@ func (s *IMinerStateStruct) StateMarketBalance(p0 context.Context, p1 address.Ad return s.Internal.StateMarketBalance(p0, p1, p2) } -func (s *IMinerStateStruct) StateMarketDeals(p0 context.Context, p1 types.TipSetKey) (map[string]types.MarketDeal, error) { +func (s *IMinerStateStruct) StateMarketDeals(p0 context.Context, p1 types.TipSetKey) (map[string]apitypes.MarketDeal, error) { return s.Internal.StateMarketDeals(p0, p1) } @@ -777,22 +778,22 @@ func (s *INetworkStruct) Version(p0 context.Context) (apitypes.Version, error) { type IPaychanStruct struct { Internal struct { - PaychAllocateLane func(p0 context.Context, p1 address.Address) (uint64, error) `perm:"sign"` - PaychAvailableFunds func(p0 context.Context, p1 address.Address) (*paychmgr.ChannelAvailableFunds, error) `perm:"sign"` - PaychAvailableFundsByFromTo func(p0 context.Context, p1 address.Address, p2 address.Address) (*paychmgr.ChannelAvailableFunds, error) `perm:"sign"` - PaychCollect func(p0 context.Context, p1 address.Address) (cid.Cid, error) `perm:"sign"` - PaychGet func(p0 context.Context, p1 address.Address, p2 address.Address, p3 big.Int) (*apitypes.ChannelInfo, error) `perm:"sign"` - PaychGetWaitReady func(p0 context.Context, p1 cid.Cid) (address.Address, error) `perm:"sign"` - PaychList func(p0 context.Context) ([]address.Address, error) `perm:"read"` - PaychNewPayment func(p0 context.Context, p1 address.Address, p2 address.Address, p3 []apitypes.VoucherSpec) (*apitypes.PaymentInfo, error) `perm:"sign"` - PaychSettle func(p0 context.Context, p1 address.Address) (cid.Cid, error) `perm:"sign"` - PaychStatus func(p0 context.Context, p1 address.Address) (*types.PaychStatus, error) `perm:"read"` - PaychVoucherAdd func(p0 context.Context, p1 address.Address, p2 *paych.SignedVoucher, p3 []byte, p4 big.Int) (big.Int, error) `perm:"write"` - PaychVoucherCheckSpendable func(p0 context.Context, p1 address.Address, p2 *paych.SignedVoucher, p3 []byte, p4 []byte) (bool, error) `perm:"read"` - PaychVoucherCheckValid func(p0 context.Context, p1 address.Address, p2 *paych.SignedVoucher) error `perm:"read"` - PaychVoucherCreate func(p0 context.Context, p1 address.Address, p2 big.Int, p3 uint64) (*paychmgr.VoucherCreateResult, error) `perm:"sign"` - PaychVoucherList func(p0 context.Context, p1 address.Address) ([]*paych.SignedVoucher, error) `perm:"write"` - PaychVoucherSubmit func(p0 context.Context, p1 address.Address, p2 *paych.SignedVoucher, p3 []byte, p4 []byte) (cid.Cid, error) `perm:"sign"` + PaychAllocateLane func(p0 context.Context, p1 address.Address) (uint64, error) `perm:"sign"` + PaychAvailableFunds func(p0 context.Context, p1 address.Address) (*paychmgr.ChannelAvailableFunds, error) `perm:"sign"` + PaychAvailableFundsByFromTo func(p0 context.Context, p1 address.Address, p2 address.Address) (*paychmgr.ChannelAvailableFunds, error) `perm:"sign"` + PaychCollect func(p0 context.Context, p1 address.Address) (cid.Cid, error) `perm:"sign"` + PaychGet func(p0 context.Context, p1 address.Address, p2 address.Address, p3 big.Int) (*paychtypes.ChannelInfo, error) `perm:"sign"` + PaychGetWaitReady func(p0 context.Context, p1 cid.Cid) (address.Address, error) `perm:"sign"` + PaychList func(p0 context.Context) ([]address.Address, error) `perm:"read"` + PaychNewPayment func(p0 context.Context, p1 address.Address, p2 address.Address, p3 []paychtypes.VoucherSpec) (*paychtypes.PaymentInfo, error) `perm:"sign"` + PaychSettle func(p0 context.Context, p1 address.Address) (cid.Cid, error) `perm:"sign"` + PaychStatus func(p0 context.Context, p1 address.Address) (*paychtypes.Status, error) `perm:"read"` + PaychVoucherAdd func(p0 context.Context, p1 address.Address, p2 *paych.SignedVoucher, p3 []byte, p4 big.Int) (big.Int, error) `perm:"write"` + PaychVoucherCheckSpendable func(p0 context.Context, p1 address.Address, p2 *paych.SignedVoucher, p3 []byte, p4 []byte) (bool, error) `perm:"read"` + PaychVoucherCheckValid func(p0 context.Context, p1 address.Address, p2 *paych.SignedVoucher) error `perm:"read"` + PaychVoucherCreate func(p0 context.Context, p1 address.Address, p2 big.Int, p3 uint64) (*paychmgr.VoucherCreateResult, error) `perm:"sign"` + PaychVoucherList func(p0 context.Context, p1 address.Address) ([]*paych.SignedVoucher, error) `perm:"write"` + PaychVoucherSubmit func(p0 context.Context, p1 address.Address, p2 *paych.SignedVoucher, p3 []byte, p4 []byte) (cid.Cid, error) `perm:"sign"` } } @@ -812,7 +813,7 @@ func (s *IPaychanStruct) PaychCollect(p0 context.Context, p1 address.Address) (c return s.Internal.PaychCollect(p0, p1) } -func (s *IPaychanStruct) PaychGet(p0 context.Context, p1 address.Address, p2 address.Address, p3 big.Int) (*apitypes.ChannelInfo, error) { +func (s *IPaychanStruct) PaychGet(p0 context.Context, p1 address.Address, p2 address.Address, p3 big.Int) (*paychtypes.ChannelInfo, error) { return s.Internal.PaychGet(p0, p1, p2, p3) } @@ -824,7 +825,7 @@ func (s *IPaychanStruct) PaychList(p0 context.Context) ([]address.Address, error return s.Internal.PaychList(p0) } -func (s *IPaychanStruct) PaychNewPayment(p0 context.Context, p1 address.Address, p2 address.Address, p3 []apitypes.VoucherSpec) (*apitypes.PaymentInfo, error) { +func (s *IPaychanStruct) PaychNewPayment(p0 context.Context, p1 address.Address, p2 address.Address, p3 []paychtypes.VoucherSpec) (*paychtypes.PaymentInfo, error) { return s.Internal.PaychNewPayment(p0, p1, p2, p3) } @@ -832,7 +833,7 @@ func (s *IPaychanStruct) PaychSettle(p0 context.Context, p1 address.Address) (ci return s.Internal.PaychSettle(p0, p1) } -func (s *IPaychanStruct) PaychStatus(p0 context.Context, p1 address.Address) (*types.PaychStatus, error) { +func (s *IPaychanStruct) PaychStatus(p0 context.Context, p1 address.Address) (*paychtypes.Status, error) { return s.Internal.PaychStatus(p0, p1) } @@ -862,14 +863,14 @@ func (s *IPaychanStruct) PaychVoucherSubmit(p0 context.Context, p1 address.Addre type ISyncerStruct struct { Internal struct { - ChainSyncHandleNewTipSet func(p0 context.Context, p1 *types.ChainInfo) error `perm:"write"` - ChainTipSetWeight func(p0 context.Context, p1 types.TipSetKey) (big.Int, error) `perm:"read"` - Concurrent func(p0 context.Context) int64 `perm:"read"` - SetConcurrent func(p0 context.Context, p1 int64) error `perm:"admin"` - StateCall func(p0 context.Context, p1 *types.UnsignedMessage, p2 types.TipSetKey) (*types.InvocResult, error) `perm:"read"` - SyncState func(p0 context.Context) (*apitypes.SyncState, error) `perm:"read"` - SyncSubmitBlock func(p0 context.Context, p1 *types.BlockMsg) error `perm:"write"` - SyncerTracker func(p0 context.Context) *syncTypes.TargetTracker `perm:"read"` + ChainSyncHandleNewTipSet func(p0 context.Context, p1 *types.ChainInfo) error `perm:"write"` + ChainTipSetWeight func(p0 context.Context, p1 types.TipSetKey) (big.Int, error) `perm:"read"` + Concurrent func(p0 context.Context) int64 `perm:"read"` + SetConcurrent func(p0 context.Context, p1 int64) error `perm:"admin"` + StateCall func(p0 context.Context, p1 *types.Message, p2 types.TipSetKey) (*apitypes.InvocResult, error) `perm:"read"` + SyncState func(p0 context.Context) (*apitypes.SyncState, error) `perm:"read"` + SyncSubmitBlock func(p0 context.Context, p1 *types.BlockMsg) error `perm:"write"` + SyncerTracker func(p0 context.Context) *syncTypes.TargetTracker `perm:"read"` } } @@ -889,7 +890,7 @@ func (s *ISyncerStruct) SetConcurrent(p0 context.Context, p1 int64) error { return s.Internal.SetConcurrent(p0, p1) } -func (s *ISyncerStruct) StateCall(p0 context.Context, p1 *types.UnsignedMessage, p2 types.TipSetKey) (*types.InvocResult, error) { +func (s *ISyncerStruct) StateCall(p0 context.Context, p1 *types.Message, p2 types.TipSetKey) (*apitypes.InvocResult, error) { return s.Internal.StateCall(p0, p1, p2) } @@ -920,7 +921,7 @@ type IWalletStruct struct { WalletNewAddress func(p0 address.Protocol) (address.Address, error) `perm:"write"` WalletSetDefault func(p0 context.Context, p1 address.Address) error `perm:"write"` WalletSign func(p0 context.Context, p1 address.Address, p2 []byte, p3 wallet.MsgMeta) (*crypto.Signature, error) `perm:"sign"` - WalletSignMessage func(p0 context.Context, p1 address.Address, p2 *types.UnsignedMessage) (*types.SignedMessage, error) `perm:"sign"` + WalletSignMessage func(p0 context.Context, p1 address.Address, p2 *types.Message) (*types.SignedMessage, error) `perm:"sign"` WalletState func(p0 context.Context) int `perm:"admin"` } } @@ -977,7 +978,7 @@ func (s *IWalletStruct) WalletSign(p0 context.Context, p1 address.Address, p2 [] return s.Internal.WalletSign(p0, p1, p2, p3) } -func (s *IWalletStruct) WalletSignMessage(p0 context.Context, p1 address.Address, p2 *types.UnsignedMessage) (*types.SignedMessage, error) { +func (s *IWalletStruct) WalletSignMessage(p0 context.Context, p1 address.Address, p2 *types.Message) (*types.SignedMessage, error) { return s.Internal.WalletSignMessage(p0, p1, p2) } diff --git a/app/node/builder.go b/app/node/builder.go index 054322a2a0..5a9683417d 100644 --- a/app/node/builder.go +++ b/app/node/builder.go @@ -2,14 +2,15 @@ package node import ( "context" + "time" + chain2 "github.com/filecoin-project/venus/pkg/chain" "github.com/filecoin-project/venus/pkg/jwtauth" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/util/ffiwrapper/impl" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/ipfs-force-community/metrics/ratelimit" logging "github.com/ipfs/go-log" "golang.org/x/xerrors" - "time" "github.com/filecoin-project/venus/app/submodule/blockstore" "github.com/filecoin-project/venus/app/submodule/chain" diff --git a/app/node/env.go b/app/node/env.go index 6283a28de5..bd083b2726 100644 --- a/app/node/env.go +++ b/app/node/env.go @@ -3,11 +3,10 @@ package node import ( "context" - "github.com/filecoin-project/venus/app/client/apiface" - "github.com/filecoin-project/venus/app/client/apiface/v0api" - cmds "github.com/ipfs/go-ipfs-cmds" + "github.com/filecoin-project/venus/app/client/apiface" + "github.com/filecoin-project/venus/app/client/apiface/v0api" "github.com/filecoin-project/venus/app/submodule/storagenetworking" ) diff --git a/app/node/helpers.go b/app/node/helpers.go index 70370287e9..614b6d2c16 100644 --- a/app/node/helpers.go +++ b/app/node/helpers.go @@ -3,14 +3,14 @@ package node import ( "bytes" "encoding/json" - "github.com/filecoin-project/venus/pkg/types" - "github.com/filecoin-project/venus/pkg/util/blockstoreutil" "github.com/ipfs/go-cid" "github.com/ipfs/go-datastore" "github.com/pkg/errors" "github.com/filecoin-project/venus/pkg/chain" + "github.com/filecoin-project/venus/pkg/util/blockstoreutil" + types "github.com/filecoin-project/venus/venus-shared/chain" ) // readGenesisCid is a helper function that queries the provided datastore for diff --git a/app/node/test/node.go b/app/node/test/node.go index cb0965db4e..27663dd690 100644 --- a/app/node/test/node.go +++ b/app/node/test/node.go @@ -2,11 +2,11 @@ package test import ( "context" - "github.com/filecoin-project/venus/pkg/util/ffiwrapper/impl" "math/rand" "testing" - "github.com/filecoin-project/venus/pkg/types" + "github.com/filecoin-project/venus/pkg/util/ffiwrapper/impl" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/filecoin-project/go-address" "github.com/filecoin-project/venus/app/node" diff --git a/app/submodule/apitypes/chain.go b/app/submodule/apitypes/chain.go index 3d8f6085d8..5a7b7205e4 100644 --- a/app/submodule/apitypes/chain.go +++ b/app/submodule/apitypes/chain.go @@ -9,9 +9,9 @@ import ( "github.com/ipfs/go-cid" "github.com/filecoin-project/venus/pkg/chain" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/venus-shared/actors/builtin/market" "github.com/filecoin-project/venus/venus-shared/actors/builtin/power" + types "github.com/filecoin-project/venus/venus-shared/chain" ) type Partition struct { @@ -43,7 +43,7 @@ type Deadline struct { // BlsMessages[x].cid = Cids[x] // SecpkMessages[y].cid = Cids[BlsMessages.length + y] type BlockMessages struct { - BlsMessages []*types.UnsignedMessage + BlsMessages []*types.Message SecpkMessages []*types.SignedMessage Cids []cid.Cid } @@ -73,7 +73,7 @@ var MarketBalanceNil = MarketBalance{} type Message struct { Cid cid.Cid - Message *types.UnsignedMessage + Message *types.Message } type MinerPower struct { diff --git a/app/submodule/apitypes/mining.go b/app/submodule/apitypes/mining.go index 6ae394596a..aa8db82f9c 100644 --- a/app/submodule/apitypes/mining.go +++ b/app/submodule/apitypes/mining.go @@ -4,8 +4,8 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" proof2 "github.com/filecoin-project/specs-actors/v2/actors/runtime/proof" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/venus-shared/actors/builtin" + types "github.com/filecoin-project/venus/venus-shared/chain" ) type MiningBaseInfo struct { //nolint diff --git a/app/submodule/apitypes/mpool.go b/app/submodule/apitypes/mpool.go index a9e4fd6e80..a44bf2a665 100644 --- a/app/submodule/apitypes/mpool.go +++ b/app/submodule/apitypes/mpool.go @@ -1,7 +1,7 @@ package apitypes import ( - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/ipfs/go-cid" ) diff --git a/app/submodule/apitypes/syncer.go b/app/submodule/apitypes/syncer.go index e337c7e7d9..49452eb58b 100644 --- a/app/submodule/apitypes/syncer.go +++ b/app/submodule/apitypes/syncer.go @@ -2,15 +2,17 @@ package apitypes import ( "fmt" + "time" + "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/venus/pkg/types" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/ipfs/go-cid" - "time" ) type ComputeStateOutput struct { Root cid.Cid - Trace []*types.InvocResult + Trace []*apitypes.InvocResult } type SyncState struct { diff --git a/app/submodule/blockstore/blockstore_api.go b/app/submodule/blockstore/blockstore_api.go index 2797aacab5..45f21f3b84 100644 --- a/app/submodule/blockstore/blockstore_api.go +++ b/app/submodule/blockstore/blockstore_api.go @@ -2,15 +2,17 @@ package blockstore import ( "context" - "github.com/filecoin-project/venus/app/client/apiface" - "github.com/filecoin-project/venus/app/submodule/apitypes" + "sync" + "github.com/ipfs/go-blockservice" "github.com/ipfs/go-cid" offline "github.com/ipfs/go-ipfs-exchange-offline" ipld "github.com/ipfs/go-ipld-format" "github.com/ipfs/go-merkledag" "golang.org/x/xerrors" - "sync" + + "github.com/filecoin-project/venus/app/client/apiface" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" ) var _ apiface.IBlockStore = &blockstoreAPI{} diff --git a/app/submodule/chain/account_api.go b/app/submodule/chain/account_api.go index 51fdcf7289..bee1ee6713 100644 --- a/app/submodule/chain/account_api.go +++ b/app/submodule/chain/account_api.go @@ -2,8 +2,9 @@ package chain import ( "context" + "github.com/filecoin-project/venus/app/client/apiface" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/filecoin-project/go-address" "golang.org/x/xerrors" diff --git a/app/submodule/chain/actor_api.go b/app/submodule/chain/actor_api.go index 7521d68a46..f6ac184373 100644 --- a/app/submodule/chain/actor_api.go +++ b/app/submodule/chain/actor_api.go @@ -2,9 +2,10 @@ package chain import ( "context" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/venus/app/client/apiface" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" ) var _ apiface.IActor = &actorAPI{} diff --git a/app/submodule/chain/beacon_api.go b/app/submodule/chain/beacon_api.go index 6b333b4f5a..21e4053555 100644 --- a/app/submodule/chain/beacon_api.go +++ b/app/submodule/chain/beacon_api.go @@ -3,9 +3,10 @@ package chain import ( "context" "fmt" + "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/venus/app/client/apiface" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" xerrors "github.com/pkg/errors" ) diff --git a/app/submodule/chain/chain_submodule.go b/app/submodule/chain/chain_submodule.go index 31fea67130..ee8f84efff 100644 --- a/app/submodule/chain/chain_submodule.go +++ b/app/submodule/chain/chain_submodule.go @@ -2,26 +2,25 @@ package chain import ( "context" - "github.com/filecoin-project/venus/app/client/apiface" - "github.com/filecoin-project/venus/app/client/apiface/v0api" - "github.com/filecoin-project/venus/pkg/statemanger" - "github.com/filecoin-project/venus/pkg/vm" - cbor "github.com/ipfs/go-ipld-cbor" "time" - chainv0api "github.com/filecoin-project/venus/app/submodule/chain/v0api" - "github.com/ipfs/go-cid" + cbor "github.com/ipfs/go-ipld-cbor" + "github.com/filecoin-project/venus/app/client/apiface" + "github.com/filecoin-project/venus/app/client/apiface/v0api" + chainv0api "github.com/filecoin-project/venus/app/submodule/chain/v0api" "github.com/filecoin-project/venus/pkg/beacon" "github.com/filecoin-project/venus/pkg/chain" "github.com/filecoin-project/venus/pkg/consensus" "github.com/filecoin-project/venus/pkg/consensusfault" "github.com/filecoin-project/venus/pkg/fork" "github.com/filecoin-project/venus/pkg/repo" - "github.com/filecoin-project/venus/pkg/types" + "github.com/filecoin-project/venus/pkg/statemanger" "github.com/filecoin-project/venus/pkg/util/ffiwrapper" + "github.com/filecoin-project/venus/pkg/vm" "github.com/filecoin-project/venus/pkg/vmsupport" + types "github.com/filecoin-project/venus/venus-shared/chain" ) // ChainSubmodule enhances the `Node` with chain capabilities. diff --git a/app/submodule/chain/chaininfo_api.go b/app/submodule/chain/chaininfo_api.go index a9e5185a98..12e07f8138 100644 --- a/app/submodule/chain/chaininfo_api.go +++ b/app/submodule/chain/chaininfo_api.go @@ -3,23 +3,22 @@ package chain import ( "bufio" "context" - - "github.com/filecoin-project/venus/app/client/apiface" - "github.com/filecoin-project/venus/app/submodule/apitypes" - logging "github.com/ipfs/go-log/v2" "io" "time" - miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" acrypto "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/go-state-types/network" - "github.com/filecoin-project/venus/pkg/chain" - "github.com/filecoin-project/venus/pkg/types" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/ipfs/go-cid" + logging "github.com/ipfs/go-log/v2" "golang.org/x/xerrors" + + "github.com/filecoin-project/venus/app/client/apiface" + "github.com/filecoin-project/venus/pkg/chain" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" ) var _ apiface.IChainInfo = &chainInfoAPI{} @@ -148,7 +147,7 @@ func (cia *chainInfoAPI) ChainGetBlock(ctx context.Context, id cid.Cid) (*types. // ChainGetMessage reads a message referenced by the specified CID from the // chain blockstore. -func (cia *chainInfoAPI) ChainGetMessage(ctx context.Context, msgID cid.Cid) (*types.UnsignedMessage, error) { +func (cia *chainInfoAPI) ChainGetMessage(ctx context.Context, msgID cid.Cid) (*types.Message, error) { msg, err := cia.chain.MessageStore.LoadMessage(msgID) if err != nil { return nil, err @@ -247,7 +246,7 @@ func (cia *chainInfoAPI) ChainGetParentMessages(ctx context.Context, bcid cid.Ci } // TODO: need to get the number of messages better than this - pts, err := cia.chain.ChainReader.GetTipSet(types.NewTipSetKey(b.Parents.Cids()...)) + pts, err := cia.chain.ChainReader.GetTipSet(types.NewTipSetKey(b.Parents...)) if err != nil { return nil, err } @@ -281,7 +280,7 @@ func (cia *chainInfoAPI) ChainGetParentReceipts(ctx context.Context, bcid cid.Ci } // TODO: need to get the number of messages better than this - pts, err := cia.chain.ChainReader.GetTipSet(types.NewTipSetKey(b.Parents.Cids()...)) + pts, err := cia.chain.ChainReader.GetTipSet(types.NewTipSetKey(b.Parents...)) if err != nil { return nil, err } diff --git a/app/submodule/chain/miner_api.go b/app/submodule/chain/miner_api.go index 62af1df575..1fc37a3400 100644 --- a/app/submodule/chain/miner_api.go +++ b/app/submodule/chain/miner_api.go @@ -3,9 +3,6 @@ package chain import ( "context" - "github.com/filecoin-project/venus/app/client/apiface" - "github.com/filecoin-project/venus/venus-shared/actors/policy" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" @@ -13,16 +10,17 @@ import ( "github.com/filecoin-project/go-state-types/dline" "golang.org/x/xerrors" - "github.com/filecoin-project/venus/app/submodule/apitypes" + "github.com/filecoin-project/venus/app/client/apiface" "github.com/filecoin-project/venus/pkg/chain" "github.com/filecoin-project/venus/pkg/state/tree" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/venus-shared/actors/builtin" "github.com/filecoin-project/venus/venus-shared/actors/builtin/market" "github.com/filecoin-project/venus/venus-shared/actors/builtin/miner" "github.com/filecoin-project/venus/venus-shared/actors/builtin/power" "github.com/filecoin-project/venus/venus-shared/actors/builtin/reward" - types2 "github.com/filecoin-project/venus/venus-shared/chain" + "github.com/filecoin-project/venus/venus-shared/actors/policy" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" ) var _ apiface.IMinerState = &minerStateAPI{} @@ -359,7 +357,7 @@ func (msa *minerStateAPI) StateMinerPreCommitDepositForPower(ctx context.Context var sectorWeight abi.StoragePower if act, found, err := sTree.GetActor(ctx, market.Address); err != nil || !found { return big.Int{}, xerrors.Errorf("loading market actor %s: %v", maddr, err) - } else if s, err := market.Load(store, (*types2.Actor)(act)); err != nil { + } else if s, err := market.Load(store, act); err != nil { return big.Int{}, xerrors.Errorf("loading market actor state %s: %v", maddr, err) } else if w, vw, err := s.VerifyDealsForActivation(maddr, pci.DealIDs, ts.Height(), pci.Expiration); err != nil { return big.Int{}, xerrors.Errorf("verifying deals for activation: %v", err) @@ -372,7 +370,7 @@ func (msa *minerStateAPI) StateMinerPreCommitDepositForPower(ctx context.Context var powerSmoothed builtin.FilterEstimate if act, found, err := sTree.GetActor(ctx, power.Address); err != nil || !found { return big.Int{}, xerrors.Errorf("loading power actor: %v", err) - } else if s, err := power.Load(store, (*types2.Actor)(act)); err != nil { + } else if s, err := power.Load(store, act); err != nil { return big.Int{}, xerrors.Errorf("loading power actor state: %v", err) } else if p, err := s.TotalPowerSmoothed(); err != nil { return big.Int{}, xerrors.Errorf("failed to determine total power: %v", err) @@ -385,7 +383,7 @@ func (msa *minerStateAPI) StateMinerPreCommitDepositForPower(ctx context.Context return big.Int{}, xerrors.Errorf("loading miner actor: %v", err) } - rewardState, err := reward.Load(store, (*types2.Actor)(rewardActor)) + rewardState, err := reward.Load(store, rewardActor) if err != nil { return big.Int{}, xerrors.Errorf("loading reward actor state: %v", err) } @@ -419,7 +417,7 @@ func (msa *minerStateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, var sectorWeight abi.StoragePower if act, found, err := state.GetActor(ctx, market.Address); err != nil || !found { return big.Int{}, xerrors.Errorf("loading miner actor %s: %v", maddr, err) - } else if s, err := market.Load(store, (*types2.Actor)(act)); err != nil { + } else if s, err := market.Load(store, act); err != nil { return big.Int{}, xerrors.Errorf("loading market actor state %s: %v", maddr, err) } else if w, vw, err := s.VerifyDealsForActivation(maddr, pci.DealIDs, ts.Height(), pci.Expiration); err != nil { return big.Int{}, xerrors.Errorf("verifying deals for activation: %v", err) @@ -435,7 +433,7 @@ func (msa *minerStateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, ) if act, found, err := state.GetActor(ctx, power.Address); err != nil || !found { return big.Int{}, xerrors.Errorf("loading miner actor: %v", err) - } else if s, err := power.Load(store, (*types2.Actor)(act)); err != nil { + } else if s, err := power.Load(store, act); err != nil { return big.Int{}, xerrors.Errorf("loading power actor state: %v", err) } else if p, err := s.TotalPowerSmoothed(); err != nil { return big.Int{}, xerrors.Errorf("failed to determine total power: %v", err) @@ -451,7 +449,7 @@ func (msa *minerStateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, return big.Int{}, xerrors.Errorf("loading miner actor: %v", err) } - rewardState, err := reward.Load(store, (*types2.Actor)(rewardActor)) + rewardState, err := reward.Load(store, rewardActor) if err != nil { return big.Int{}, xerrors.Errorf("loading reward actor state: %v", err) } @@ -504,7 +502,7 @@ func (msa *minerStateAPI) StateCirculatingSupply(ctx context.Context, tsk types. } // StateMarketDeals returns information about every deal in the Storage Market -func (msa *minerStateAPI) StateMarketDeals(ctx context.Context, tsk types.TipSetKey) (map[string]types.MarketDeal, error) { +func (msa *minerStateAPI) StateMarketDeals(ctx context.Context, tsk types.TipSetKey) (map[string]apitypes.MarketDeal, error) { _, view, err := msa.Stmgr.ParentStateViewTsk(ctx, tsk) if err != nil { return nil, xerrors.Errorf("Stmgr.ParentStateViewTsk failed:%w", err) diff --git a/app/submodule/chain/v0api/chaininfo_v0api.go b/app/submodule/chain/v0api/chaininfo_v0api.go index 4320195057..85b5a5ad94 100644 --- a/app/submodule/chain/v0api/chaininfo_v0api.go +++ b/app/submodule/chain/v0api/chaininfo_v0api.go @@ -2,15 +2,16 @@ package v0api import ( "context" + "github.com/filecoin-project/venus/app/client/apiface" "github.com/filecoin-project/venus/app/client/apiface/v0api" "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" - "github.com/filecoin-project/venus/app/submodule/apitypes" "github.com/filecoin-project/venus/pkg/constants" - "github.com/filecoin-project/venus/pkg/types" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" ) var _ v0api.IChain = &WrapperV1IChain{} diff --git a/app/submodule/config/config_test.go b/app/submodule/config/config_test.go index 6c480f672c..ad8a1c16ea 100644 --- a/app/submodule/config/config_test.go +++ b/app/submodule/config/config_test.go @@ -3,6 +3,8 @@ package config import ( "testing" + "github.com/filecoin-project/venus/pkg/testhelpers" + "github.com/filecoin-project/go-address" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -10,7 +12,6 @@ import ( "github.com/filecoin-project/venus/pkg/config" repo2 "github.com/filecoin-project/venus/pkg/repo" tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" - "github.com/filecoin-project/venus/pkg/types" ) func TestConfigGet(t *testing.T) { @@ -72,7 +73,7 @@ func TestConfigSet(t *testing.T) { require.NoError(t, err) assert.Equal(t, ":1234", cfg.API.APIAddress) - testAddr := types.RequireIDAddress(t, 100).String() + testAddr := testhelpers.RequireIDAddress(t, 100).String() err = cfgAPI.Set("walletModule.defaultAddress", testAddr) require.NoError(t, err) assert.Equal(t, testAddr, cfg.Wallet.DefaultAddress.String()) diff --git a/app/submodule/discovery/discovery_submodule.go b/app/submodule/discovery/discovery_submodule.go index a7d1b202f4..421cc80d61 100644 --- a/app/submodule/discovery/discovery_submodule.go +++ b/app/submodule/discovery/discovery_submodule.go @@ -8,7 +8,7 @@ import ( "github.com/filecoin-project/venus/app/client/apiface/v0api" "github.com/filecoin-project/venus/app/submodule/network" "github.com/filecoin-project/venus/pkg/repo" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/libp2p/go-libp2p-core/host" "github.com/ipfs/go-cid" diff --git a/app/submodule/market/market_api.go b/app/submodule/market/market_api.go index 81f6fedc96..38901c294c 100644 --- a/app/submodule/market/market_api.go +++ b/app/submodule/market/market_api.go @@ -2,14 +2,14 @@ package market import ( "context" + + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/venus/app/client/apiface" - "github.com/filecoin-project/venus/app/submodule/apitypes" "github.com/filecoin-project/venus/pkg/statemanger" - "github.com/filecoin-project/venus/pkg/types" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" "golang.org/x/xerrors" - - "github.com/filecoin-project/go-address" ) type marketAPI struct { diff --git a/app/submodule/mining/mining_api.go b/app/submodule/mining/mining_api.go index d981289c1b..f67b22e4c1 100644 --- a/app/submodule/mining/mining_api.go +++ b/app/submodule/mining/mining_api.go @@ -17,15 +17,14 @@ import ( ffi "github.com/filecoin-project/filecoin-ffi" - "github.com/filecoin-project/venus/app/submodule/apitypes" "github.com/filecoin-project/venus/pkg/beacon" "github.com/filecoin-project/venus/pkg/chain" "github.com/filecoin-project/venus/pkg/crypto" "github.com/filecoin-project/venus/pkg/state" - "github.com/filecoin-project/venus/pkg/types" - "github.com/filecoin-project/venus/pkg/wallet" "github.com/filecoin-project/venus/venus-shared/actors/builtin/miner" - types2 "github.com/filecoin-project/venus/venus-shared/chain" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" + wtypes "github.com/filecoin-project/venus/venus-shared/wallet" ) var _ apiface.IMining = &MiningAPI{} @@ -84,7 +83,7 @@ func (miningAPI *MiningAPI) MinerGetBaseInfo(ctx context.Context, maddr address. if err != nil { return nil, xerrors.Errorf("failed to load miner actor: %v", err) } - mas, err := miner.Load(chainStore.Store(ctx), (*types2.Actor)(act)) + mas, err := miner.Load(chainStore.Store(ctx), act) if err != nil { return nil, xerrors.Errorf("failed to load miner actor state: %v", err) } @@ -195,7 +194,7 @@ func (miningAPI *MiningAPI) minerCreateBlock(ctx context.Context, bt *apitypes.B next := &types.BlockHeader{ Miner: bt.Miner, - Parents: bt.Parents, + Parents: bt.Parents.Cids(), Ticket: bt.Ticket, ElectionProof: bt.Eproof, @@ -207,7 +206,7 @@ func (miningAPI *MiningAPI) minerCreateBlock(ctx context.Context, bt *apitypes.B ParentMessageReceipts: receiptCid, } - var blsMessages []*types.UnsignedMessage + var blsMessages []*types.Message var secpkMessages []*types.SignedMessage var blsMsgCids, secpkMsgCids []cid.Cid @@ -266,9 +265,12 @@ func (miningAPI *MiningAPI) minerCreateBlock(ctx context.Context, bt *apitypes.B } if bHas { - nosigbytes := next.SignatureData() - sig, err := miningAPI.Ming.Wallet.API().WalletSign(ctx, worker, nosigbytes, wallet.MsgMeta{ - Type: wallet.MTBlock, + nosigbytes, err := next.SignatureData() + if err != nil { + return nil, err + } + sig, err := miningAPI.Ming.Wallet.API().WalletSign(ctx, worker, nosigbytes, wtypes.MsgMeta{ + Type: wtypes.MTBlock, }) if err != nil { return nil, xerrors.Errorf("failed to sign new block: %v", err) diff --git a/app/submodule/mpool/mpool_api.go b/app/submodule/mpool/mpool_api.go index b114034523..20c5a22b71 100644 --- a/app/submodule/mpool/mpool_api.go +++ b/app/submodule/mpool/mpool_api.go @@ -3,12 +3,14 @@ package mpool import ( "context" "encoding/json" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/venus/app/client/apiface" - "github.com/filecoin-project/venus/app/submodule/apitypes" "github.com/filecoin-project/venus/pkg/messagepool" - "github.com/filecoin-project/venus/pkg/types" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" + mptypes "github.com/filecoin-project/venus/venus-shared/messagepool" "github.com/ipfs/go-cid" "golang.org/x/xerrors" ) @@ -42,13 +44,28 @@ func (a *MessagePoolAPI) MpoolPush(ctx context.Context, smsg *types.SignedMessag } // MpoolGetConfig returns (a copy of) the current mpool config -func (a *MessagePoolAPI) MpoolGetConfig(context.Context) (*messagepool.MpoolConfig, error) { - return a.mp.MPool.GetConfig(), nil +func (a *MessagePoolAPI) MpoolGetConfig(context.Context) (*mptypes.MpoolConfig, error) { + cfg := a.mp.MPool.GetConfig() + return &mptypes.MpoolConfig{ + PriorityAddrs: cfg.PriorityAddrs, + SizeLimitHigh: cfg.SizeLimitHigh, + SizeLimitLow: cfg.SizeLimitLow, + ReplaceByFeeRatio: cfg.ReplaceByFeeRatio, + PruneCooldown: cfg.PruneCooldown, + GasLimitOverestimation: cfg.GasLimitOverestimation, + }, nil } // MpoolSetConfig sets the mpool config to (a copy of) the supplied config -func (a *MessagePoolAPI) MpoolSetConfig(ctx context.Context, cfg *messagepool.MpoolConfig) error { - return a.mp.MPool.SetConfig(cfg) +func (a *MessagePoolAPI) MpoolSetConfig(ctx context.Context, cfg *mptypes.MpoolConfig) error { + return a.mp.MPool.SetConfig(&messagepool.MpoolConfig{ + PriorityAddrs: cfg.PriorityAddrs, + SizeLimitHigh: cfg.SizeLimitHigh, + SizeLimitLow: cfg.SizeLimitLow, + ReplaceByFeeRatio: cfg.ReplaceByFeeRatio, + PruneCooldown: cfg.PruneCooldown, + GasLimitOverestimation: cfg.GasLimitOverestimation, + }) } // MpoolSelect returns a list of pending messages for inclusion in the next block @@ -164,7 +181,7 @@ func (a *MessagePoolAPI) MpoolPushUntrusted(ctx context.Context, smsg *types.Sig // // When maxFee is set to 0, MpoolPushMessage will guess appropriate fee // based on current chain conditions -func (a *MessagePoolAPI) MpoolPushMessage(ctx context.Context, msg *types.UnsignedMessage, spec *types.MessageSendSpec) (*types.SignedMessage, error) { +func (a *MessagePoolAPI) MpoolPushMessage(ctx context.Context, msg *types.Message, spec *apitypes.MessageSendSpec) (*types.SignedMessage, error) { cp := *msg msg = &cp inMsg := *msg @@ -252,7 +269,7 @@ func (a *MessagePoolAPI) MpoolBatchPushUntrusted(ctx context.Context, smsgs []*t } // MpoolBatchPushMessage batch pushes a unsigned message to mempool. -func (a *MessagePoolAPI) MpoolBatchPushMessage(ctx context.Context, msgs []*types.UnsignedMessage, spec *types.MessageSendSpec) ([]*types.SignedMessage, error) { +func (a *MessagePoolAPI) MpoolBatchPushMessage(ctx context.Context, msgs []*types.Message, spec *apitypes.MessageSendSpec) ([]*types.SignedMessage, error) { var smsgs []*types.SignedMessage for _, msg := range msgs { smsg, err := a.MpoolPushMessage(ctx, msg, spec) @@ -270,25 +287,25 @@ func (a *MessagePoolAPI) MpoolGetNonce(ctx context.Context, addr address.Address return a.mp.MPool.GetNonce(ctx, addr, types.EmptyTSK) } -func (a *MessagePoolAPI) MpoolSub(ctx context.Context) (<-chan messagepool.MpoolUpdate, error) { +func (a *MessagePoolAPI) MpoolSub(ctx context.Context) (<-chan mptypes.MpoolUpdate, error) { return a.mp.MPool.Updates(ctx) } // GasEstimateMessageGas estimates gas values for unset message gas fields -func (a *MessagePoolAPI) GasEstimateMessageGas(ctx context.Context, msg *types.UnsignedMessage, spec *types.MessageSendSpec, tsk types.TipSetKey) (*types.UnsignedMessage, error) { - return a.mp.MPool.GasEstimateMessageGas(ctx, &types.EstimateMessage{Msg: msg, Spec: spec}, tsk) +func (a *MessagePoolAPI) GasEstimateMessageGas(ctx context.Context, msg *types.Message, spec *apitypes.MessageSendSpec, tsk types.TipSetKey) (*types.Message, error) { + return a.mp.MPool.GasEstimateMessageGas(ctx, &apitypes.EstimateMessage{Msg: msg, Spec: spec}, tsk) } -func (a *MessagePoolAPI) GasBatchEstimateMessageGas(ctx context.Context, estimateMessages []*types.EstimateMessage, fromNonce uint64, tsk types.TipSetKey) ([]*types.EstimateResult, error) { +func (a *MessagePoolAPI) GasBatchEstimateMessageGas(ctx context.Context, estimateMessages []*apitypes.EstimateMessage, fromNonce uint64, tsk types.TipSetKey) ([]*apitypes.EstimateResult, error) { return a.mp.MPool.GasBatchEstimateMessageGas(ctx, estimateMessages, fromNonce, tsk) } // GasEstimateFeeCap estimates gas fee cap -func (a *MessagePoolAPI) GasEstimateFeeCap(ctx context.Context, msg *types.UnsignedMessage, maxqueueblks int64, tsk types.TipSetKey) (big.Int, error) { +func (a *MessagePoolAPI) GasEstimateFeeCap(ctx context.Context, msg *types.Message, maxqueueblks int64, tsk types.TipSetKey) (big.Int, error) { return a.mp.MPool.GasEstimateFeeCap(ctx, msg, maxqueueblks, tsk) } -func (a *MessagePoolAPI) GasEstimateGasLimit(ctx context.Context, msgIn *types.UnsignedMessage, tsk types.TipSetKey) (int64, error) { +func (a *MessagePoolAPI) GasEstimateGasLimit(ctx context.Context, msgIn *types.Message, tsk types.TipSetKey) (int64, error) { return a.mp.MPool.GasEstimateGasLimit(ctx, msgIn, tsk) } @@ -298,15 +315,15 @@ func (a *MessagePoolAPI) GasEstimateGasPremium(ctx context.Context, nblocksincl return a.mp.MPool.GasEstimateGasPremium(ctx, nblocksincl, sender, gaslimit, tsk, a.mp.MPool.PriceCache) } -func (a *MessagePoolAPI) MpoolCheckMessages(ctx context.Context, protos []*apitypes.MessagePrototype) ([][]apitypes.MessageCheckStatus, error) { +func (a *MessagePoolAPI) MpoolCheckMessages(ctx context.Context, protos []*mptypes.MessagePrototype) ([][]mptypes.MessageCheckStatus, error) { return a.mp.MPool.CheckMessages(ctx, protos) } -func (a *MessagePoolAPI) MpoolCheckPendingMessages(ctx context.Context, addr address.Address) ([][]apitypes.MessageCheckStatus, error) { +func (a *MessagePoolAPI) MpoolCheckPendingMessages(ctx context.Context, addr address.Address) ([][]mptypes.MessageCheckStatus, error) { return a.mp.MPool.CheckPendingMessages(ctx, addr) } -func (a *MessagePoolAPI) MpoolCheckReplaceMessages(ctx context.Context, msg []*types.Message) ([][]apitypes.MessageCheckStatus, error) { +func (a *MessagePoolAPI) MpoolCheckReplaceMessages(ctx context.Context, msg []*types.Message) ([][]mptypes.MessageCheckStatus, error) { return a.mp.MPool.CheckReplaceMessages(ctx, msg) } diff --git a/app/submodule/mpool/mpool_submodule.go b/app/submodule/mpool/mpool_submodule.go index d7ca57d798..d86d898cb1 100644 --- a/app/submodule/mpool/mpool_submodule.go +++ b/app/submodule/mpool/mpool_submodule.go @@ -26,7 +26,7 @@ import ( "github.com/filecoin-project/venus/pkg/messagepool/journal" "github.com/filecoin-project/venus/pkg/net/msgsub" "github.com/filecoin-project/venus/pkg/repo" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" ) var pubsubMsgsSyncEpochs = 10 diff --git a/app/submodule/multisig/multisig_api.go b/app/submodule/multisig/multisig_api.go index 3aa7b1e864..311bf5212d 100644 --- a/app/submodule/multisig/multisig_api.go +++ b/app/submodule/multisig/multisig_api.go @@ -3,19 +3,17 @@ package multisig import ( "context" - "github.com/filecoin-project/venus/app/client/apiface" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" multisig2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/multisig" "golang.org/x/xerrors" - "github.com/filecoin-project/venus/app/submodule/apitypes" - "github.com/filecoin-project/venus/pkg/types" + "github.com/filecoin-project/venus/app/client/apiface" "github.com/filecoin-project/venus/venus-shared/actors" "github.com/filecoin-project/venus/venus-shared/actors/builtin/multisig" - types2 "github.com/filecoin-project/venus/venus-shared/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" + "github.com/filecoin-project/venus/venus-shared/messagepool" ) var _ apiface.IMultiSig = &multiSig{} @@ -52,7 +50,7 @@ func (a *multiSig) messageBuilder(ctx context.Context, from address.Address) (mu // MsigCreate creates a multisig wallet // It takes the following params: , , //, , -func (a *multiSig) MsigCreate(ctx context.Context, req uint64, addrs []address.Address, duration abi.ChainEpoch, val types.BigInt, src address.Address, gp types.BigInt) (*apitypes.MessagePrototype, error) { +func (a *multiSig) MsigCreate(ctx context.Context, req uint64, addrs []address.Address, duration abi.ChainEpoch, val types.BigInt, src address.Address, gp types.BigInt) (*messagepool.MessagePrototype, error) { mb, err := a.messageBuilder(ctx, src) if err != nil { @@ -64,13 +62,13 @@ func (a *multiSig) MsigCreate(ctx context.Context, req uint64, addrs []address.A return nil, err } - return &apitypes.MessagePrototype{ - Message: types.UnsignedMessage(*msg), + return &messagepool.MessagePrototype{ + Message: *msg, ValidNonce: false, }, nil } -func (a *multiSig) MsigPropose(ctx context.Context, msig address.Address, to address.Address, amt types.BigInt, src address.Address, method uint64, params []byte) (*apitypes.MessagePrototype, error) { +func (a *multiSig) MsigPropose(ctx context.Context, msig address.Address, to address.Address, amt types.BigInt, src address.Address, method uint64, params []byte) (*messagepool.MessagePrototype, error) { mb, err := a.messageBuilder(ctx, src) if err != nil { @@ -82,13 +80,13 @@ func (a *multiSig) MsigPropose(ctx context.Context, msig address.Address, to add return nil, xerrors.Errorf("failed to create proposal: %w", err) } - return &apitypes.MessagePrototype{ - Message: types.UnsignedMessage(*msg), + return &messagepool.MessagePrototype{ + Message: *msg, ValidNonce: false, }, nil } -func (a *multiSig) MsigAddPropose(ctx context.Context, msig address.Address, src address.Address, newAdd address.Address, inc bool) (*apitypes.MessagePrototype, error) { +func (a *multiSig) MsigAddPropose(ctx context.Context, msig address.Address, src address.Address, newAdd address.Address, inc bool) (*messagepool.MessagePrototype, error) { enc, actErr := serializeAddParams(newAdd, inc) if actErr != nil { return nil, actErr @@ -97,7 +95,7 @@ func (a *multiSig) MsigAddPropose(ctx context.Context, msig address.Address, src return a.MsigPropose(ctx, msig, msig, big.Zero(), src, uint64(multisig.Methods.AddSigner), enc) } -func (a *multiSig) MsigAddApprove(ctx context.Context, msig address.Address, src address.Address, txID uint64, proposer address.Address, newAdd address.Address, inc bool) (*apitypes.MessagePrototype, error) { +func (a *multiSig) MsigAddApprove(ctx context.Context, msig address.Address, src address.Address, txID uint64, proposer address.Address, newAdd address.Address, inc bool) (*messagepool.MessagePrototype, error) { enc, actErr := serializeAddParams(newAdd, inc) if actErr != nil { return nil, actErr @@ -109,7 +107,7 @@ func (a *multiSig) MsigAddApprove(ctx context.Context, msig address.Address, src // MsigAddApprove approves a previously proposed AddSigner message // It takes the following params: , , , // , , -func (a *multiSig) MsigAddCancel(ctx context.Context, msig address.Address, src address.Address, txID uint64, newAdd address.Address, inc bool) (*apitypes.MessagePrototype, error) { +func (a *multiSig) MsigAddCancel(ctx context.Context, msig address.Address, src address.Address, txID uint64, newAdd address.Address, inc bool) (*messagepool.MessagePrototype, error) { enc, actErr := serializeAddParams(newAdd, inc) if actErr != nil { return nil, actErr @@ -121,7 +119,7 @@ func (a *multiSig) MsigAddCancel(ctx context.Context, msig address.Address, src // MsigSwapPropose proposes swapping 2 signers in the multisig // It takes the following params: , , // , -func (a *multiSig) MsigSwapPropose(ctx context.Context, msig address.Address, src address.Address, oldAdd address.Address, newAdd address.Address) (*apitypes.MessagePrototype, error) { +func (a *multiSig) MsigSwapPropose(ctx context.Context, msig address.Address, src address.Address, oldAdd address.Address, newAdd address.Address) (*messagepool.MessagePrototype, error) { enc, actErr := serializeSwapParams(oldAdd, newAdd) if actErr != nil { return nil, actErr @@ -133,7 +131,7 @@ func (a *multiSig) MsigSwapPropose(ctx context.Context, msig address.Address, sr // MsigSwapApprove approves a previously proposed SwapSigner // It takes the following params: , , , // , , -func (a *multiSig) MsigSwapApprove(ctx context.Context, msig address.Address, src address.Address, txID uint64, proposer address.Address, oldAdd address.Address, newAdd address.Address) (*apitypes.MessagePrototype, error) { +func (a *multiSig) MsigSwapApprove(ctx context.Context, msig address.Address, src address.Address, txID uint64, proposer address.Address, oldAdd address.Address, newAdd address.Address) (*messagepool.MessagePrototype, error) { enc, actErr := serializeSwapParams(oldAdd, newAdd) if actErr != nil { return nil, actErr @@ -142,7 +140,7 @@ func (a *multiSig) MsigSwapApprove(ctx context.Context, msig address.Address, sr return a.MsigApproveTxnHash(ctx, msig, txID, proposer, msig, big.Zero(), src, uint64(multisig.Methods.SwapSigner), enc) } -func (a *multiSig) MsigSwapCancel(ctx context.Context, msig address.Address, src address.Address, txID uint64, oldAdd address.Address, newAdd address.Address) (*apitypes.MessagePrototype, error) { +func (a *multiSig) MsigSwapCancel(ctx context.Context, msig address.Address, src address.Address, txID uint64, oldAdd address.Address, newAdd address.Address) (*messagepool.MessagePrototype, error) { enc, actErr := serializeSwapParams(oldAdd, newAdd) if actErr != nil { return nil, actErr @@ -154,7 +152,7 @@ func (a *multiSig) MsigSwapCancel(ctx context.Context, msig address.Address, src // MsigSwapCancel cancels a previously proposed SwapSigner message // It takes the following params: , , , // , -func (a *multiSig) MsigApprove(ctx context.Context, msig address.Address, txID uint64, src address.Address) (*apitypes.MessagePrototype, error) { +func (a *multiSig) MsigApprove(ctx context.Context, msig address.Address, txID uint64, src address.Address) (*messagepool.MessagePrototype, error) { return a.msigApproveOrCancelSimple(ctx, MsigApprove, msig, txID, src) } @@ -164,14 +162,14 @@ func (a *multiSig) MsigApprove(ctx context.Context, msig address.Address, txID u // exactly the transaction you think you are. // It takes the following params: , , , , , // , , -func (a *multiSig) MsigApproveTxnHash(ctx context.Context, msig address.Address, txID uint64, proposer address.Address, to address.Address, amt types.BigInt, src address.Address, method uint64, params []byte) (*apitypes.MessagePrototype, error) { +func (a *multiSig) MsigApproveTxnHash(ctx context.Context, msig address.Address, txID uint64, proposer address.Address, to address.Address, amt types.BigInt, src address.Address, method uint64, params []byte) (*messagepool.MessagePrototype, error) { return a.msigApproveOrCancelTxnHash(ctx, MsigApprove, msig, txID, proposer, to, amt, src, method, params) } // MsigCancel cancels a previously-proposed multisig message // It takes the following params: , , , , // , , -func (a *multiSig) MsigCancel(ctx context.Context, msig address.Address, txID uint64, to address.Address, amt types.BigInt, src address.Address, method uint64, params []byte) (*apitypes.MessagePrototype, error) { +func (a *multiSig) MsigCancel(ctx context.Context, msig address.Address, txID uint64, to address.Address, amt types.BigInt, src address.Address, method uint64, params []byte) (*messagepool.MessagePrototype, error) { return a.msigApproveOrCancelTxnHash(ctx, MsigCancel, msig, txID, src, to, amt, src, method, params) } @@ -180,7 +178,7 @@ func (a *multiSig) MsigCancel(ctx context.Context, msig address.Address, txID ui // send the message from, the address to be removed, and a boolean // indicating whether or not the signing threshold should be lowered by one // along with the address removal. -func (a *multiSig) MsigRemoveSigner(ctx context.Context, msig address.Address, proposer address.Address, toRemove address.Address, decrease bool) (*apitypes.MessagePrototype, error) { +func (a *multiSig) MsigRemoveSigner(ctx context.Context, msig address.Address, proposer address.Address, toRemove address.Address, decrease bool) (*messagepool.MessagePrototype, error) { enc, actErr := serializeRemoveParams(toRemove, decrease) if actErr != nil { return nil, actErr @@ -214,7 +212,7 @@ func (a *multiSig) MsigGetVested(ctx context.Context, addr address.Address, star return types.EmptyInt, xerrors.Errorf("failed to load multisig actor at end epoch: %w", err) } - msas, err := multisig.Load(a.store.Store(ctx), (*types2.Actor)(act)) + msas, err := multisig.Load(a.store.Store(ctx), act) if err != nil { return types.EmptyInt, xerrors.Errorf("failed to load multisig actor state: %w", err) } @@ -232,7 +230,7 @@ func (a *multiSig) MsigGetVested(ctx context.Context, addr address.Address, star return types.BigSub(startLk, endLk), nil } -func (a *multiSig) msigApproveOrCancelSimple(ctx context.Context, operation MsigProposeResponse, msig address.Address, txID uint64, src address.Address) (*apitypes.MessagePrototype, error) { +func (a *multiSig) msigApproveOrCancelSimple(ctx context.Context, operation MsigProposeResponse, msig address.Address, txID uint64, src address.Address) (*messagepool.MessagePrototype, error) { if msig == address.Undef { return nil, xerrors.Errorf("must provide multisig address") } @@ -246,7 +244,7 @@ func (a *multiSig) msigApproveOrCancelSimple(ctx context.Context, operation Msig return nil, err } - var msg *types2.Message + var msg *types.Message switch operation { case MsigApprove: msg, err = mb.Approve(msig, txID, nil) @@ -259,10 +257,10 @@ func (a *multiSig) msigApproveOrCancelSimple(ctx context.Context, operation Msig return nil, err } - return &apitypes.MessagePrototype{Message: types.UnsignedMessage(*msg), ValidNonce: false}, nil + return &messagepool.MessagePrototype{Message: *msg, ValidNonce: false}, nil } -func (a *multiSig) msigApproveOrCancelTxnHash(ctx context.Context, operation MsigProposeResponse, msig address.Address, txID uint64, proposer address.Address, to address.Address, amt types.BigInt, src address.Address, method uint64, params []byte) (*apitypes.MessagePrototype, error) { +func (a *multiSig) msigApproveOrCancelTxnHash(ctx context.Context, operation MsigProposeResponse, msig address.Address, txID uint64, proposer address.Address, to address.Address, amt types.BigInt, src address.Address, method uint64, params []byte) (*messagepool.MessagePrototype, error) { if msig == address.Undef { return nil, xerrors.Errorf("must provide multisig address") } @@ -292,7 +290,7 @@ func (a *multiSig) msigApproveOrCancelTxnHash(ctx context.Context, operation Msi return nil, err } - var msg *types2.Message + var msg *types.Message switch operation { case MsigApprove: msg, err = mb.Approve(msig, txID, &p) @@ -305,8 +303,8 @@ func (a *multiSig) msigApproveOrCancelTxnHash(ctx context.Context, operation Msi return nil, err } - return &apitypes.MessagePrototype{ - Message: types.UnsignedMessage(*msg), + return &messagepool.MessagePrototype{ + Message: *msg, ValidNonce: false, }, nil } diff --git a/app/submodule/multisig/v0api/multisig_v0api.go b/app/submodule/multisig/v0api/multisig_v0api.go index c2cc2158f5..8d9c2328b3 100644 --- a/app/submodule/multisig/v0api/multisig_v0api.go +++ b/app/submodule/multisig/v0api/multisig_v0api.go @@ -2,13 +2,14 @@ package v0api import ( "context" + "github.com/filecoin-project/venus/app/client/apiface" "github.com/filecoin-project/venus/app/client/apiface/v0api" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/venus/app/submodule/apitypes" - "github.com/filecoin-project/venus/pkg/types" + "github.com/filecoin-project/venus/venus-shared/messagepool" "github.com/ipfs/go-cid" "golang.org/x/xerrors" ) @@ -20,7 +21,7 @@ type WrapperV1IMultiSig struct { var _ v0api.IMultiSig = (*WrapperV1IMultiSig)(nil) -func (a *WrapperV1IMultiSig) executePrototype(ctx context.Context, p *apitypes.MessagePrototype) (cid.Cid, error) { +func (a *WrapperV1IMultiSig) executePrototype(ctx context.Context, p *messagepool.MessagePrototype) (cid.Cid, error) { sm, err := a.IMessagePool.MpoolPushMessage(ctx, &p.Message, nil) if err != nil { return cid.Undef, xerrors.Errorf("pushing message: %w", err) diff --git a/app/submodule/network/network_api.go b/app/submodule/network/network_api.go index 4aa7c56f45..45969f4242 100644 --- a/app/submodule/network/network_api.go +++ b/app/submodule/network/network_api.go @@ -2,15 +2,17 @@ package network import ( "context" - "github.com/filecoin-project/venus/app/client/apiface" - "github.com/filecoin-project/venus/app/submodule/apitypes" - "github.com/filecoin-project/venus/pkg/constants" - "github.com/filecoin-project/venus/pkg/net" "github.com/ipfs/go-cid" "github.com/libp2p/go-libp2p-core/metrics" "github.com/libp2p/go-libp2p-core/peer" ma "github.com/multiformats/go-multiaddr" + + "github.com/filecoin-project/venus/app/client/apiface" + "github.com/filecoin-project/venus/pkg/constants" + "github.com/filecoin-project/venus/pkg/net" + "github.com/filecoin-project/venus/venus-shared/api" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" ) var _ apiface.INetwork = &networkAPI{} @@ -62,7 +64,7 @@ func (na *networkAPI) NetworkPeers(ctx context.Context, verbose, latency, stream func (na *networkAPI) Version(context.Context) (apitypes.Version, error) { return apitypes.Version{ Version: constants.UserVersion(), - APIVersion: constants.FullAPIVersion1, + APIVersion: api.Version(constants.FullAPIVersion1), }, nil } diff --git a/app/submodule/network/network_submodule.go b/app/submodule/network/network_submodule.go index 9ba8cc629c..ce285ab6b8 100644 --- a/app/submodule/network/network_submodule.go +++ b/app/submodule/network/network_submodule.go @@ -14,8 +14,8 @@ import ( dtnet "github.com/filecoin-project/go-data-transfer/network" dtgstransport "github.com/filecoin-project/go-data-transfer/transport/graphsync" "github.com/filecoin-project/venus/pkg/repo" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/util/blockstoreutil" + types "github.com/filecoin-project/venus/venus-shared/chain" blocks "github.com/ipfs/go-block-format" bserv "github.com/ipfs/go-blockservice" "github.com/ipfs/go-datastore" @@ -255,10 +255,10 @@ func (networkSubmodule *NetworkSubmodule) FetchMessagesByCids( ctx context.Context, service bserv.BlockService, cids []cid.Cid, -) ([]*types.UnsignedMessage, error) { - out := make([]*types.UnsignedMessage, len(cids)) +) ([]*types.Message, error) { + out := make([]*types.Message, len(cids)) err := networkSubmodule.fetchCids(ctx, service, cids, func(idx int, blk blocks.Block) error { - var msg types.UnsignedMessage + var msg types.Message if err := msg.UnmarshalCBOR(bytes.NewReader(blk.RawData())); err != nil { return err } diff --git a/app/submodule/network/v0api/v1_wrapper.go b/app/submodule/network/v0api/v1_wrapper.go index 1c8daa13d4..2fff6daec9 100644 --- a/app/submodule/network/v0api/v1_wrapper.go +++ b/app/submodule/network/v0api/v1_wrapper.go @@ -2,10 +2,11 @@ package v0api import ( "context" - "github.com/filecoin-project/venus/app/client/apiface" - "github.com/filecoin-project/venus/app/submodule/apitypes" + "github.com/filecoin-project/venus/app/client/apiface" "github.com/filecoin-project/venus/pkg/constants" + "github.com/filecoin-project/venus/venus-shared/api" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" ) type WrapperV1INetwork struct { @@ -18,7 +19,7 @@ func (w *WrapperV1INetwork) Version(ctx context.Context) (apitypes.Version, erro return apitypes.Version{}, err } - ver.APIVersion = constants.FullAPIVersion0 + ver.APIVersion = api.Version(constants.FullAPIVersion0) return ver, nil } diff --git a/app/submodule/paych/paych_api.go b/app/submodule/paych/paych_api.go index 2a88d1da11..cbc4e4ae99 100644 --- a/app/submodule/paych/paych_api.go +++ b/app/submodule/paych/paych_api.go @@ -10,9 +10,8 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/specs-actors/actors/builtin/paych" - "github.com/filecoin-project/venus/app/submodule/apitypes" "github.com/filecoin-project/venus/pkg/paychmgr" - "github.com/filecoin-project/venus/pkg/types" + paychtypes "github.com/filecoin-project/venus/venus-shared/paych" ) type PaychAPI struct { @@ -23,15 +22,13 @@ func NewPaychAPI(p *paychmgr.Manager) *PaychAPI { return &PaychAPI{p} } -type PaychStatus = types.PaychStatus //nolint - -func (a *PaychAPI) PaychGet(ctx context.Context, from, to address.Address, amt big.Int) (*apitypes.ChannelInfo, error) { +func (a *PaychAPI) PaychGet(ctx context.Context, from, to address.Address, amt big.Int) (*paychtypes.ChannelInfo, error) { ch, mcid, err := a.paychMgr.GetPaych(ctx, from, to, amt) if err != nil { return nil, err } - return &apitypes.ChannelInfo{ + return &paychtypes.ChannelInfo{ Channel: ch, WaitSentinel: mcid, }, nil @@ -53,7 +50,7 @@ func (a *PaychAPI) PaychAllocateLane(ctx context.Context, ch address.Address) (u return a.paychMgr.AllocateLane(ch) } -func (a *PaychAPI) PaychNewPayment(ctx context.Context, from, to address.Address, vouchers []apitypes.VoucherSpec) (*apitypes.PaymentInfo, error) { +func (a *PaychAPI) PaychNewPayment(ctx context.Context, from, to address.Address, vouchers []paychtypes.VoucherSpec) (*paychtypes.PaymentInfo, error) { amount := vouchers[len(vouchers)-1].Amount // TODO: Fix free fund tracking in PaychGet @@ -90,7 +87,7 @@ func (a *PaychAPI) PaychNewPayment(ctx context.Context, from, to address.Address svs[i] = sv.Voucher } - return &apitypes.PaymentInfo{ + return &paychtypes.PaymentInfo{ Channel: ch.Channel, WaitSentinel: ch.WaitSentinel, Vouchers: svs, @@ -101,14 +98,14 @@ func (a *PaychAPI) PaychList(ctx context.Context) ([]address.Address, error) { return a.paychMgr.ListChannels() } -func (a *PaychAPI) PaychStatus(ctx context.Context, pch address.Address) (*types.PaychStatus, error) { +func (a *PaychAPI) PaychStatus(ctx context.Context, pch address.Address) (*paychtypes.Status, error) { ci, err := a.paychMgr.GetChannelInfo(pch) if err != nil { return nil, err } - return &types.PaychStatus{ + return &paychtypes.Status{ ControlAddr: ci.Control, - Direction: types.PCHDir(ci.Direction), + Direction: paychtypes.PCHDir(ci.Direction), }, nil } diff --git a/app/submodule/syncer/chain_sync.go b/app/submodule/syncer/chain_sync.go index 63a99c5c5d..6d540f67f1 100644 --- a/app/submodule/syncer/chain_sync.go +++ b/app/submodule/syncer/chain_sync.go @@ -1,9 +1,10 @@ package syncer import ( - "github.com/filecoin-project/venus/pkg/chainsync" - "github.com/filecoin-project/venus/pkg/types" "time" + + "github.com/filecoin-project/venus/pkg/chainsync" + types "github.com/filecoin-project/venus/venus-shared/chain" ) type chainSync interface { diff --git a/app/submodule/syncer/syncer_api.go b/app/submodule/syncer/syncer_api.go index 8290ee79b1..c972e6cf0a 100644 --- a/app/submodule/syncer/syncer_api.go +++ b/app/submodule/syncer/syncer_api.go @@ -2,14 +2,15 @@ package syncer import ( "context" - "github.com/filecoin-project/venus/app/client/apiface" "time" - "github.com/filecoin-project/venus/app/submodule/apitypes" + "github.com/filecoin-project/venus/app/client/apiface" syncTypes "github.com/filecoin-project/venus/pkg/chainsync/types" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" + stmgrtypes "github.com/filecoin-project/venus/venus-shared/stmgr" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/venus/pkg/types" logging "github.com/ipfs/go-log/v2" xerrors "github.com/pkg/errors" ) @@ -57,7 +58,7 @@ func (sa *syncerAPI) ChainSyncHandleNewTipSet(ctx context.Context, ci *types.Cha func (sa *syncerAPI) SyncSubmitBlock(ctx context.Context, blk *types.BlockMsg) error { //todo many dot. how to get directly chainModule := sa.syncer.ChainModule - parent, err := chainModule.ChainReader.GetBlock(ctx, blk.Header.Parents.Cids()[0]) + parent, err := chainModule.ChainReader.GetBlock(ctx, blk.Header.Parents[0]) if err != nil { return xerrors.Errorf("loading parent block: %v", err) } @@ -87,7 +88,7 @@ func (sa *syncerAPI) SyncSubmitBlock(ctx context.Context, blk *types.BlockMsg) e return xerrors.Errorf("provided messages did not match block: %v", err) } - ts, err := types.NewTipSet(blk.Header) + ts, err := types.NewTipSet([]*types.BlockHeader{blk.Header}) if err != nil { return xerrors.Errorf("somehow failed to make a tipset out of a single block: %v", err) } @@ -124,7 +125,7 @@ func (sa *syncerAPI) SyncSubmitBlock(ctx context.Context, blk *types.BlockMsg) e // StateCall applies the message to the tipset's parent state. The // message is not applied on-top-of the messages in the passed-in // tipset. -func (sa *syncerAPI) StateCall(ctx context.Context, msg *types.UnsignedMessage, tsk types.TipSetKey) (*types.InvocResult, error) { +func (sa *syncerAPI) StateCall(ctx context.Context, msg *types.Message, tsk types.TipSetKey) (*apitypes.InvocResult, error) { start := time.Now() ts, err := sa.syncer.ChainModule.ChainReader.GetTipSet(tsk) if err != nil { @@ -137,11 +138,11 @@ func (sa *syncerAPI) StateCall(ctx context.Context, msg *types.UnsignedMessage, duration := time.Since(start) mcid := msg.Cid() - return &types.InvocResult{ + return &apitypes.InvocResult{ MsgCid: mcid, Msg: msg, MsgRct: &ret.Receipt, - ExecutionTrace: &types.ExecutionTrace{}, + ExecutionTrace: stmgrtypes.ExecutionTrace{}, Duration: duration, }, nil } diff --git a/app/submodule/syncer/syncer_submodule.go b/app/submodule/syncer/syncer_submodule.go index 9239ce6d9b..d73f1fc9b9 100644 --- a/app/submodule/syncer/syncer_submodule.go +++ b/app/submodule/syncer/syncer_submodule.go @@ -33,8 +33,8 @@ import ( "github.com/filecoin-project/venus/pkg/net/pubsub" "github.com/filecoin-project/venus/pkg/repo" "github.com/filecoin-project/venus/pkg/state" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/vm/gas" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/ipfs/go-blockservice" ) @@ -232,7 +232,7 @@ func (syncer *SyncerSubmodule) handleIncomingBlocks(ctx context.Context, msg pub syncer.NetworkModule.Host.ConnManager().TagPeer(sender, "new-block", 20) log.Infof("fetch message success at %s", bm.Header.Cid()) - ts, _ := types.NewTipSet(header) + ts, _ := types.NewTipSet([]*types.BlockHeader{header}) chainInfo := types.NewChainInfo(source, sender, ts) if err = syncer.ChainSyncManager.BlockProposer().SendGossipBlock(chainInfo); err != nil { diff --git a/app/submodule/wallet/remotewallet/api.go b/app/submodule/wallet/remotewallet/api.go index dd11bad02d..88fc65a8aa 100644 --- a/app/submodule/wallet/remotewallet/api.go +++ b/app/submodule/wallet/remotewallet/api.go @@ -10,15 +10,16 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/venus/pkg/wallet" + types "github.com/filecoin-project/venus/venus-shared/wallet" ) type IWallet interface { - WalletNew(context.Context, wallet.KeyType) (address.Address, error) + WalletNew(context.Context, types.KeyType) (address.Address, error) WalletHas(ctx context.Context, address address.Address) (bool, error) WalletList(ctx context.Context) ([]address.Address, error) - WalletSign(ctx context.Context, signer address.Address, toSign []byte, meta wallet.MsgMeta) (*wallet.Signature, error) - WalletExport(ctx context.Context, addr address.Address) (*wallet.KeyInfo, error) - WalletImport(context.Context, *wallet.KeyInfo) (address.Address, error) + WalletSign(ctx context.Context, signer address.Address, toSign []byte, meta types.MsgMeta) (*wallet.Signature, error) + WalletExport(ctx context.Context, addr address.Address) (*types.KeyInfo, error) + WalletImport(context.Context, *types.KeyInfo) (address.Address, error) WalletDelete(context.Context, address.Address) error } @@ -27,17 +28,17 @@ var _ IWallet = &WalletAPIAdapter{} // wallet API permissions constraints type WalletAPIAdapter struct { Internal struct { - WalletNew func(ctx context.Context, kt wallet.KeyType) (address.Address, error) `perm:"admin"` - WalletHas func(ctx context.Context, address address.Address) (bool, error) `perm:"write"` - WalletList func(ctx context.Context) ([]address.Address, error) `perm:"write"` - WalletSign func(ctx context.Context, signer address.Address, toSign []byte, meta wallet.MsgMeta) (*wallet.Signature, error) `perm:"sign"` - WalletExport func(ctx context.Context, addr address.Address) (*wallet.KeyInfo, error) `perm:"admin"` - WalletImport func(ctx context.Context, ki *wallet.KeyInfo) (address.Address, error) `perm:"admin"` - WalletDelete func(ctx context.Context, addr address.Address) error `perm:"admin"` + WalletNew func(ctx context.Context, kt types.KeyType) (address.Address, error) `perm:"admin"` + WalletHas func(ctx context.Context, address address.Address) (bool, error) `perm:"write"` + WalletList func(ctx context.Context) ([]address.Address, error) `perm:"write"` + WalletSign func(ctx context.Context, signer address.Address, toSign []byte, meta types.MsgMeta) (*wallet.Signature, error) `perm:"sign"` + WalletExport func(ctx context.Context, addr address.Address) (*types.KeyInfo, error) `perm:"admin"` + WalletImport func(ctx context.Context, ki *types.KeyInfo) (address.Address, error) `perm:"admin"` + WalletDelete func(ctx context.Context, addr address.Address) error `perm:"admin"` } } -func (c *WalletAPIAdapter) WalletNew(ctx context.Context, keyType wallet.KeyType) (address.Address, error) { +func (c *WalletAPIAdapter) WalletNew(ctx context.Context, keyType types.KeyType) (address.Address, error) { return c.Internal.WalletNew(ctx, keyType) } @@ -49,15 +50,15 @@ func (c *WalletAPIAdapter) WalletList(ctx context.Context) ([]address.Address, e return c.Internal.WalletList(ctx) } -func (c *WalletAPIAdapter) WalletSign(ctx context.Context, signer address.Address, toSign []byte, meta wallet.MsgMeta) (*wallet.Signature, error) { +func (c *WalletAPIAdapter) WalletSign(ctx context.Context, signer address.Address, toSign []byte, meta types.MsgMeta) (*wallet.Signature, error) { return c.Internal.WalletSign(ctx, signer, toSign, meta) } -func (c *WalletAPIAdapter) WalletExport(ctx context.Context, a address.Address) (*wallet.KeyInfo, error) { +func (c *WalletAPIAdapter) WalletExport(ctx context.Context, a address.Address) (*types.KeyInfo, error) { return c.Internal.WalletExport(ctx, a) } -func (c *WalletAPIAdapter) WalletImport(ctx context.Context, ki *wallet.KeyInfo) (address.Address, error) { +func (c *WalletAPIAdapter) WalletImport(ctx context.Context, ki *types.KeyInfo) (address.Address, error) { return c.Internal.WalletImport(ctx, ki) } diff --git a/app/submodule/wallet/remotewallet/keymap.go b/app/submodule/wallet/remotewallet/keymap.go index 956daad2d5..2d0fd6e521 100644 --- a/app/submodule/wallet/remotewallet/keymap.go +++ b/app/submodule/wallet/remotewallet/keymap.go @@ -4,31 +4,31 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/venus/pkg/crypto" - "github.com/filecoin-project/venus/pkg/wallet" + types "github.com/filecoin-project/venus/venus-shared/wallet" ) -var keyMapper = map[address.Protocol]wallet.KeyType{ - address.SECP256K1: wallet.KTSecp256k1, - address.BLS: wallet.KTBLS, +var keyMapper = map[address.Protocol]types.KeyType{ + address.SECP256K1: types.KTSecp256k1, + address.BLS: types.KTBLS, } -func GetKeyType(p address.Protocol) wallet.KeyType { +func GetKeyType(p address.Protocol) types.KeyType { k, ok := keyMapper[p] if ok { return k } - return wallet.KTUnknown + return types.KTUnknown } -func ConvertRemoteKeyInfo(key *crypto.KeyInfo) *wallet.KeyInfo { - return &wallet.KeyInfo{ +func ConvertRemoteKeyInfo(key *crypto.KeyInfo) *types.KeyInfo { + return &types.KeyInfo{ PrivateKey: key.Key(), - Type: wallet.SignType2Key(key.SigType), + Type: types.SignType2Key(key.SigType), } } -func ConvertLocalKeyInfo(key *wallet.KeyInfo) *crypto.KeyInfo { +func ConvertLocalKeyInfo(key *types.KeyInfo) *crypto.KeyInfo { ki := &crypto.KeyInfo{ - SigType: wallet.KeyType2Sign(key.Type), + SigType: types.KeyType2Sign(key.Type), } ki.SetPrivateKey(key.PrivateKey) diff --git a/app/submodule/wallet/remotewallet/remote.go b/app/submodule/wallet/remotewallet/remote.go index 4e1b3763a6..87cac4d09f 100644 --- a/app/submodule/wallet/remotewallet/remote.go +++ b/app/submodule/wallet/remotewallet/remote.go @@ -9,6 +9,7 @@ import ( "github.com/filecoin-project/venus/pkg/crypto" "github.com/filecoin-project/venus/pkg/wallet" + types "github.com/filecoin-project/venus/venus-shared/wallet" ) var _ wallet.WalletIntersection = &remoteWallet{} @@ -72,6 +73,6 @@ func (w *remoteWallet) Export(addr address.Address, password string) (*crypto.Ke return ConvertLocalKeyInfo(key), nil } -func (w *remoteWallet) WalletSign(keyAddr address.Address, msg []byte, meta wallet.MsgMeta) (*crypto.Signature, error) { +func (w *remoteWallet) WalletSign(keyAddr address.Address, msg []byte, meta types.MsgMeta) (*crypto.Signature, error) { return w.IWallet.WalletSign(context.Background(), keyAddr, msg, meta) } diff --git a/app/submodule/wallet/wallet_api.go b/app/submodule/wallet/wallet_api.go index a9977e0a5e..8ddafaebfe 100644 --- a/app/submodule/wallet/wallet_api.go +++ b/app/submodule/wallet/wallet_api.go @@ -3,14 +3,16 @@ package wallet import ( "context" "errors" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/venus/app/client/apiface" "golang.org/x/xerrors" + "github.com/filecoin-project/venus/app/client/apiface" "github.com/filecoin-project/venus/pkg/crypto" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/wallet" + types "github.com/filecoin-project/venus/venus-shared/chain" + wtypes "github.com/filecoin-project/venus/venus-shared/wallet" ) var _ apiface.IWallet = &WalletAPI{} @@ -102,7 +104,7 @@ func (walletAPI *WalletAPI) WalletExport(addr address.Address, password string) } // WalletSign signs the given bytes using the given address. -func (walletAPI *WalletAPI) WalletSign(ctx context.Context, k address.Address, msg []byte, meta wallet.MsgMeta) (*crypto.Signature, error) { +func (walletAPI *WalletAPI) WalletSign(ctx context.Context, k address.Address, msg []byte, meta wtypes.MsgMeta) (*crypto.Signature, error) { keyAddr, err := walletAPI.walletModule.Chain.Stmgr.ResolveToKeyAddress(ctx, k, nil) if err != nil { return nil, xerrors.Errorf("ResolveTokeyAddress failed:%v", err) @@ -111,13 +113,13 @@ func (walletAPI *WalletAPI) WalletSign(ctx context.Context, k address.Address, m } // WalletSignMessage signs the given message using the given address. -func (walletAPI *WalletAPI) WalletSignMessage(ctx context.Context, k address.Address, msg *types.UnsignedMessage) (*types.SignedMessage, error) { +func (walletAPI *WalletAPI) WalletSignMessage(ctx context.Context, k address.Address, msg *types.Message) (*types.SignedMessage, error) { mb, err := msg.ToStorageBlock() if err != nil { return nil, xerrors.Errorf("serializing message: %w", err) } - sign, err := walletAPI.WalletSign(ctx, k, mb.Cid().Bytes(), wallet.MsgMeta{Type: wallet.MTChainMsg}) + sign, err := walletAPI.WalletSign(ctx, k, mb.Cid().Bytes(), wtypes.MsgMeta{Type: wtypes.MTChainMsg}) if err != nil { return nil, xerrors.Errorf("failed to sign message: %w", err) } diff --git a/app/submodule/wallet/wallet_submodule.go b/app/submodule/wallet/wallet_submodule.go index 4a9db98be6..32ede1f173 100644 --- a/app/submodule/wallet/wallet_submodule.go +++ b/app/submodule/wallet/wallet_submodule.go @@ -15,8 +15,8 @@ import ( pconfig "github.com/filecoin-project/venus/pkg/config" "github.com/filecoin-project/venus/pkg/repo" "github.com/filecoin-project/venus/pkg/state" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/wallet" + types "github.com/filecoin-project/venus/venus-shared/chain" ) var log = logging.Logger("wallet") diff --git a/cmd/address.go b/cmd/address.go index 58b86915d3..57265ff237 100644 --- a/cmd/address.go +++ b/cmd/address.go @@ -19,8 +19,8 @@ import ( "github.com/filecoin-project/venus/app/node" "github.com/filecoin-project/venus/cmd/tablewriter" "github.com/filecoin-project/venus/pkg/crypto" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/wallet" + types "github.com/filecoin-project/venus/venus-shared/chain" ) var errMissPassword = errors.New("the wallet is missing password, please use command `venus wallet set-password` to set password") diff --git a/cmd/chain.go b/cmd/chain.go index fbf9e7e91c..3d40c724fc 100644 --- a/cmd/chain.go +++ b/cmd/chain.go @@ -19,9 +19,9 @@ import ( "github.com/filecoin-project/venus/app/client/apiface" "github.com/filecoin-project/venus/app/node" - "github.com/filecoin-project/venus/app/submodule/apitypes" "github.com/filecoin-project/venus/pkg/constants" - "github.com/filecoin-project/venus/pkg/types" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" ) var chainCmd = &cmds.Command{ @@ -213,7 +213,7 @@ var chainGetBlockCmd = &cmds.Command{ cblock := struct { types.BlockHeader - BlsMessages []*types.UnsignedMessage + BlsMessages []*types.Message SecpkMessages []*types.SignedMessage ParentReceipts []*types.MessageReceipt ParentMessages []cid.Cid @@ -256,7 +256,7 @@ var chainGetMessageCmd = &cmds.Command{ return re.Emit(msg) }, - Type: types.UnsignedMessage{}, + Type: types.Message{}, } var chainGetMessagesCmd = &cmds.Command{ diff --git a/cmd/daemon.go b/cmd/daemon.go index 7f9183d10b..1ff055760a 100644 --- a/cmd/daemon.go +++ b/cmd/daemon.go @@ -5,14 +5,16 @@ import ( "context" "encoding/json" "fmt" - "github.com/filecoin-project/venus/pkg/constants" - "github.com/filecoin-project/venus/pkg/util/ulimit" "io" "io/ioutil" "net/http" "net/url" "os" + "github.com/filecoin-project/venus/pkg/constants" + "github.com/filecoin-project/venus/pkg/util/ulimit" + types "github.com/filecoin-project/venus/venus-shared/chain" + paramfetch "github.com/filecoin-project/go-paramfetch" "github.com/filecoin-project/venus/fixtures/asset" @@ -35,7 +37,6 @@ import ( "github.com/filecoin-project/venus/pkg/journal" "github.com/filecoin-project/venus/pkg/migration" "github.com/filecoin-project/venus/pkg/repo" - "github.com/filecoin-project/venus/pkg/types" gengen "github.com/filecoin-project/venus/tools/gengen/util" ) diff --git a/cmd/dag_integration_test.go b/cmd/dag_integration_test.go index f396023a5f..1fda6df796 100644 --- a/cmd/dag_integration_test.go +++ b/cmd/dag_integration_test.go @@ -3,7 +3,6 @@ package cmd_test import ( "bytes" "context" - "github.com/filecoin-project/venus/pkg/types" "testing" cbor "github.com/ipfs/go-ipld-cbor" @@ -12,6 +11,7 @@ import ( "github.com/filecoin-project/venus/app/node/test" "github.com/filecoin-project/venus/pkg/constants" tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" + types "github.com/filecoin-project/venus/venus-shared/chain" ) func TestDagDaemon(t *testing.T) { diff --git a/cmd/dispute.go b/cmd/dispute.go index 313a8f490b..4a29788361 100644 --- a/cmd/dispute.go +++ b/cmd/dispute.go @@ -7,9 +7,6 @@ import ( "strconv" "time" - "github.com/filecoin-project/venus/app/client/apiface" - "github.com/filecoin-project/venus/venus-shared/actors" - builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" miner3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/miner" @@ -21,9 +18,12 @@ import ( logging "github.com/ipfs/go-log/v2" + "github.com/filecoin-project/venus/app/client/apiface" "github.com/filecoin-project/venus/app/node" chainpkg "github.com/filecoin-project/venus/pkg/chain" - "github.com/filecoin-project/venus/pkg/types" + "github.com/filecoin-project/venus/venus-shared/actors" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" ) var disputeLog = logging.Logger("disputer") @@ -414,13 +414,13 @@ func getSender(ctx context.Context, api apiface.IWallet, fromStr string) (addres return addr, nil } -func getMaxFee(maxStr string) (*types.MessageSendSpec, error) { +func getMaxFee(maxStr string) (*apitypes.MessageSendSpec, error) { if maxStr != "" { maxFee, err := types.ParseFIL(maxStr) if err != nil { return nil, xerrors.Errorf("parsing max-fee: %w", err) } - return &types.MessageSendSpec{ + return &apitypes.MessageSendSpec{ MaxFee: types.BigInt(maxFee), }, nil } diff --git a/cmd/main.go b/cmd/main.go index d5f3a36fae..fd71c614de 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -19,7 +19,7 @@ import ( "github.com/filecoin-project/venus/app/node" "github.com/filecoin-project/venus/app/paths" "github.com/filecoin-project/venus/pkg/repo" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" ) const ( @@ -392,24 +392,25 @@ var limitOption = cmds.Int64Option("gas-limit", "Maximum GasUnits this message i func parseGasOptions(req *cmds.Request) (fbig.Int, fbig.Int, int64, error) { var ( - feecap = types.ZeroFIL - premium = types.ZeroFIL + feecap = types.FIL{Int: types.NewInt(0).Int} + premium = types.FIL{Int: types.NewInt(0).Int} ok = false gasLimitInt = int64(0) ) + var err error feecapOption := req.Options["gas-feecap"] if feecapOption != nil { - feecap, ok = types.NewAttoFILFromString(feecapOption.(string), 10) - if !ok { + feecap, err = types.ParseFIL(feecapOption.(string)) + if err != nil { return types.ZeroFIL, types.ZeroFIL, 0, errors.New("invalid gas price (specify FIL as a decimal number)") } } premiumOption := req.Options["gas-premium"] if premiumOption != nil { - premium, ok = types.NewAttoFILFromString(premiumOption.(string), 10) - if !ok { + premium, err = types.ParseFIL(premiumOption.(string)) + if err != nil { return types.ZeroFIL, types.ZeroFIL, 0, errors.New("invalid gas price (specify FIL as a decimal number)") } } @@ -423,5 +424,5 @@ func parseGasOptions(req *cmds.Request) (fbig.Int, fbig.Int, int64, error) { } } - return feecap, premium, gasLimitInt, nil + return fbig.Int{Int: feecap.Int}, fbig.Int{Int: premium.Int}, gasLimitInt, nil } diff --git a/cmd/message.go b/cmd/message.go index 9c31313398..fa3b4b8db4 100644 --- a/cmd/message.go +++ b/cmd/message.go @@ -19,9 +19,9 @@ import ( "github.com/filecoin-project/venus/app/node" "github.com/filecoin-project/venus/pkg/chain" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/vm" "github.com/filecoin-project/venus/venus-shared/actors/builtin" + types "github.com/filecoin-project/venus/venus-shared/chain" ) // MessageSendResult is the return type for message send command @@ -56,9 +56,9 @@ var msgSendCmd = &cmds.Command{ return err } v := req.Arguments[1] - val, ok := types.NewAttoFILFromFILString(v) - if !ok { - return errors.New("mal-formed value") + val, err := types.ParseFIL(v) + if err != nil { + return xerrors.Errorf("mal-formed value: %v", err) } methodID := builtin.MethodSend @@ -103,10 +103,10 @@ var msgSendCmd = &cmds.Command{ params = decparams } - msg := &types.UnsignedMessage{ + msg := &types.Message{ From: fromAddr, To: toAddr, - Value: val, + Value: abi.TokenAmount{Int: val.Int}, GasPremium: premium, GasFeeCap: feecap, GasLimit: gasLimit, @@ -171,7 +171,7 @@ func decodeTypedParams(ctx context.Context, fapi *node.Env, to address.Address, // WaitResult is the result of a message wait call. type WaitResult struct { - Message *types.UnsignedMessage + Message *types.Message Receipt *types.MessageReceipt Signature vm.ActorMethodSignature } diff --git a/cmd/miner.go b/cmd/miner.go index 86bbd259e9..6ee3a9d0c1 100644 --- a/cmd/miner.go +++ b/cmd/miner.go @@ -18,7 +18,6 @@ import ( "github.com/filecoin-project/venus/app/node" "github.com/filecoin-project/venus/app/submodule/chain" "github.com/filecoin-project/venus/pkg/constants" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/util/blockstoreutil" "github.com/filecoin-project/venus/pkg/wallet" "github.com/filecoin-project/venus/venus-shared/actors" @@ -26,7 +25,8 @@ import ( "github.com/filecoin-project/venus/venus-shared/actors/builtin/miner" "github.com/filecoin-project/venus/venus-shared/actors/builtin/power" "github.com/filecoin-project/venus/venus-shared/actors/policy" - types2 "github.com/filecoin-project/venus/venus-shared/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" + "github.com/filecoin-project/venus/venus-shared/chain/params" ) var minerCmdLog = logging.Logger("miner.cmd") @@ -72,7 +72,7 @@ var newMinerCmd = &cmds.Command{ } gp, _ := req.Options["gas-premium"].(string) - gasPrice, err := types.BigFromString(gp) + gasPrice, err := types.ParseFIL(gp) if err != nil { return xerrors.Errorf("failed to parse gas-price flag: %s", err) } @@ -100,7 +100,7 @@ var newMinerCmd = &cmds.Command{ // make sure the worker account exists on chain _, err = env.(*node.Env).ChainAPI.StateLookupID(ctx, worker, types.EmptyTSK) if err != nil { - signed, err := env.(*node.Env).MessagePoolAPI.MpoolPushMessage(ctx, &types.UnsignedMessage{ + signed, err := env.(*node.Env).MessagePoolAPI.MpoolPushMessage(ctx, &types.Message{ From: owner, To: worker, Value: big.NewInt(0), @@ -156,7 +156,7 @@ var newMinerCmd = &cmds.Command{ sender = faddr } - createStorageMinerMsg := &types.UnsignedMessage{ + createStorageMinerMsg := &types.Message{ To: power.Address, From: sender, Value: big.Zero(), @@ -165,7 +165,7 @@ var newMinerCmd = &cmds.Command{ Params: params, GasLimit: 0, - GasPremium: gasPrice, + GasPremium: abi.TokenAmount{Int: gasPrice.Int}, } signed, err := env.(*node.Env).MessagePoolAPI.MpoolPushMessage(ctx, createStorageMinerMsg, nil) @@ -188,7 +188,7 @@ var newMinerCmd = &cmds.Command{ } var retval power2.CreateMinerReturn - if err := retval.UnmarshalCBOR(bytes.NewReader(mw.Receipt.ReturnValue)); err != nil { + if err := retval.UnmarshalCBOR(bytes.NewReader(mw.Receipt.Return)); err != nil { return err } @@ -251,7 +251,7 @@ var minerInfoCmd = &cmds.Command{ } tbs := blockstoreutil.NewTieredBstore(chain.NewAPIBlockstore(blockstoreAPI), blockstoreutil.NewTemporary()) - mas, err := miner.Load(adt.WrapStore(ctx, cbor.NewCborStore(tbs)), (*types2.Actor)(mact)) + mas, err := miner.Load(adt.WrapStore(ctx, cbor.NewCborStore(tbs)), mact) if err != nil { return err } @@ -307,7 +307,7 @@ var minerInfoCmd = &cmds.Command{ if !pow.HasMinPower { writer.Println("Below minimum power threshold, no blocks will be won") } else { - expWinChance := float64(big.Mul(qpercI, big.NewInt(int64(types.BlocksPerEpoch))).Int64()) / 1000000 + expWinChance := float64(big.Mul(qpercI, big.NewInt(int64(params.BlocksPerEpoch))).Int64()) / 1000000 if expWinChance > 0 { if expWinChance > 1 { expWinChance = 1 diff --git a/cmd/miner_actor.go b/cmd/miner_actor.go index 665b3e8a4b..3a5331433a 100644 --- a/cmd/miner_actor.go +++ b/cmd/miner_actor.go @@ -22,11 +22,10 @@ import ( "github.com/filecoin-project/venus/app/node" "github.com/filecoin-project/venus/app/submodule/chain" "github.com/filecoin-project/venus/cmd/tablewriter" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/venus-shared/actors" "github.com/filecoin-project/venus/venus-shared/actors/adt" "github.com/filecoin-project/venus/venus-shared/actors/builtin/miner" - types2 "github.com/filecoin-project/venus/venus-shared/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" ) var minerActorCmd = &cmds.Command{ @@ -93,7 +92,7 @@ var actorSetAddrsCmd = &cmds.Command{ gasLimit, _ := req.Options["gas-limit"].(int64) - smsg, err := env.(*node.Env).MessagePoolAPI.MpoolPushMessage(ctx, &types.UnsignedMessage{ + smsg, err := env.(*node.Env).MessagePoolAPI.MpoolPushMessage(ctx, &types.Message{ To: maddr, From: mi.Worker, Value: big.NewInt(0), @@ -145,7 +144,7 @@ var actorSetPeeridCmd = &cmds.Command{ gasLimit, _ := req.Options["gas-limit"].(int64) - smsg, err := env.(*node.Env).MessagePoolAPI.MpoolPushMessage(ctx, &types.UnsignedMessage{ + smsg, err := env.(*node.Env).MessagePoolAPI.MpoolPushMessage(ctx, &types.Message{ To: maddr, From: mi.Worker, Value: big.NewInt(0), @@ -208,7 +207,7 @@ var actorWithdrawCmd = &cmds.Command{ return err } - smsg, err := env.(*node.Env).MessagePoolAPI.MpoolPushMessage(ctx, &types.UnsignedMessage{ + smsg, err := env.(*node.Env).MessagePoolAPI.MpoolPushMessage(ctx, &types.Message{ To: maddr, From: mi.Owner, Value: big.NewInt(0), @@ -240,7 +239,7 @@ var actorWithdrawCmd = &cmds.Command{ if nv >= network.Version14 { var withdrawn abi.TokenAmount - if err := withdrawn.UnmarshalCBOR(bytes.NewReader(wait.Receipt.ReturnValue)); err != nil { + if err := withdrawn.UnmarshalCBOR(bytes.NewReader(wait.Receipt.Return)); err != nil { return err } @@ -295,7 +294,7 @@ var actorRepayDebtCmd = &cmds.Command{ store := adt.WrapStore(ctx, cbor.NewCborStore(chain.NewAPIBlockstore(env.(*node.Env).BlockStoreAPI))) - mst, err := miner.Load(store, (*types2.Actor)(mact)) + mst, err := miner.Load(store, mact) if err != nil { return err } @@ -327,7 +326,7 @@ var actorRepayDebtCmd = &cmds.Command{ return xerrors.Errorf("sender isn't a controller of miner: %s", fromID) } - smsg, err := env.(*node.Env).MessagePoolAPI.MpoolPushMessage(ctx, &types.UnsignedMessage{ + smsg, err := env.(*node.Env).MessagePoolAPI.MpoolPushMessage(ctx, &types.Message{ To: maddr, From: fromID, Value: amount, @@ -387,7 +386,7 @@ var actorSetOwnerCmd = &cmds.Command{ return xerrors.Errorf("serializing params: %w", err) } - smsg, err := env.(*node.Env).MessagePoolAPI.MpoolPushMessage(ctx, &types.UnsignedMessage{ + smsg, err := env.(*node.Env).MessagePoolAPI.MpoolPushMessage(ctx, &types.Message{ From: mi.Owner, To: maddr, Method: miner.Methods.ChangeOwnerAddress, @@ -413,7 +412,7 @@ var actorSetOwnerCmd = &cmds.Command{ return err } - smsg, err = env.(*node.Env).MessagePoolAPI.MpoolPushMessage(ctx, &types.UnsignedMessage{ + smsg, err = env.(*node.Env).MessagePoolAPI.MpoolPushMessage(ctx, &types.Message{ From: newAddr, To: maddr, Method: miner.Methods.ChangeOwnerAddress, @@ -634,7 +633,7 @@ var actorControlSet = &cmds.Command{ return xerrors.Errorf("serializing params: %w", err) } - smsg, err := env.(*node.Env).MessagePoolAPI.MpoolPushMessage(ctx, &types.UnsignedMessage{ + smsg, err := env.(*node.Env).MessagePoolAPI.MpoolPushMessage(ctx, &types.Message{ From: mi.Owner, To: maddr, Method: miner.Methods.ChangeWorkerAddress, @@ -711,7 +710,7 @@ var actorProposeChangeWorker = &cmds.Command{ return xerrors.Errorf("serializing params: %w", err) } - smsg, err := env.(*node.Env).MessagePoolAPI.MpoolPushMessage(ctx, &types.UnsignedMessage{ + smsg, err := env.(*node.Env).MessagePoolAPI.MpoolPushMessage(ctx, &types.Message{ From: mi.Owner, To: maddr, Method: miner.Methods.ChangeWorkerAddress, @@ -810,7 +809,7 @@ var actorConfirmChangeWorker = &cmds.Command{ return re.Emit("Pass --really-do-it to actually execute this action") } - smsg, err := env.(*node.Env).MessagePoolAPI.MpoolPushMessage(ctx, &types.UnsignedMessage{ + smsg, err := env.(*node.Env).MessagePoolAPI.MpoolPushMessage(ctx, &types.Message{ From: mi.Owner, To: maddr, Method: miner.Methods.ConfirmUpdateWorkerKey, diff --git a/cmd/miner_proving.go b/cmd/miner_proving.go index 5a29e5b709..6e3b44a6ea 100644 --- a/cmd/miner_proving.go +++ b/cmd/miner_proving.go @@ -6,8 +6,6 @@ import ( "strconv" "text/tabwriter" - "github.com/filecoin-project/venus/pkg/types" - "github.com/filecoin-project/go-address" cmds "github.com/ipfs/go-ipfs-cmds" cbor "github.com/ipfs/go-ipld-cbor" @@ -17,7 +15,7 @@ import ( "github.com/filecoin-project/venus/app/submodule/chain" "github.com/filecoin-project/venus/venus-shared/actors/adt" "github.com/filecoin-project/venus/venus-shared/actors/builtin/miner" - types2 "github.com/filecoin-project/venus/venus-shared/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" ) var minerProvingCmd = &cmds.Command{ @@ -64,7 +62,7 @@ var provingInfoCmd = &cmds.Command{ stor := adt.WrapStore(ctx, cbor.NewCborStore(chain.NewAPIBlockstore(env.(*node.Env).BlockStoreAPI))) - mas, err := miner.Load(stor, (*types2.Actor)(mact)) + mas, err := miner.Load(stor, mact) if err != nil { return err } @@ -325,7 +323,7 @@ var provingFaultsCmd = &cmds.Command{ return err } - mas, err := miner.Load(stor, (*types2.Actor)(mact)) + mas, err := miner.Load(stor, mact) if err != nil { return err } diff --git a/cmd/mpool.go b/cmd/mpool.go index 5af635197f..ac6c00c58d 100644 --- a/cmd/mpool.go +++ b/cmd/mpool.go @@ -20,7 +20,9 @@ import ( "github.com/filecoin-project/venus/pkg/config" "github.com/filecoin-project/venus/pkg/constants" "github.com/filecoin-project/venus/pkg/messagepool" - "github.com/filecoin-project/venus/pkg/types" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" + mptypes "github.com/filecoin-project/venus/venus-shared/messagepool" ) var mpoolCmd = &cmds.Command{ @@ -291,27 +293,16 @@ var mpoolReplaceCmd = &cmds.Command{ msg := found.Message - //msg := types.Message{ - // From: from, - // To: from, - // Method: 2, - // Value: types.FromFil(0), - // Nonce: nonce, - // GasLimit: 100000000, - // GasFeeCap: types.NewInt(100 + 4000000000), - // GasPremium: types.NewInt(5000000000), - //} - if auto { minRBF := messagepool.ComputeMinRBF(msg.GasPremium) - var mss *types.MessageSendSpec + var mss *apitypes.MessageSendSpec if len(maxFee) > 0 { maxFee, err := big.FromString(maxFee) if err != nil { return fmt.Errorf("parsing max-spend: %w", err) } - mss = &types.MessageSendSpec{ + mss = &apitypes.MessageSendSpec{ MaxFee: maxFee, } } @@ -656,7 +647,7 @@ var mpoolConfig = &cmds.Command{ ctx := context.TODO() if len(req.Arguments) > 0 { - cfg := new(messagepool.MpoolConfig) + cfg := new(mptypes.MpoolConfig) paras := req.Arguments[0] err := json.Unmarshal([]byte(paras), cfg) diff --git a/cmd/multisig.go b/cmd/multisig.go index ac5ad84851..31575ff8c6 100644 --- a/cmd/multisig.go +++ b/cmd/multisig.go @@ -20,12 +20,11 @@ import ( sbchain "github.com/filecoin-project/venus/app/submodule/chain" "github.com/filecoin-project/venus/pkg/chain" "github.com/filecoin-project/venus/pkg/constants" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/venus-shared/actors" "github.com/filecoin-project/venus/venus-shared/actors/adt" "github.com/filecoin-project/venus/venus-shared/actors/builtin" "github.com/filecoin-project/venus/venus-shared/actors/builtin/multisig" - types2 "github.com/filecoin-project/venus/venus-shared/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/ipfs/go-cid" cmds "github.com/ipfs/go-ipfs-cmds" cbor "github.com/ipfs/go-ipld-cbor" @@ -133,7 +132,7 @@ var msigCreateCmd = &cmds.Command{ } // get address of newly created miner var execreturn init2.ExecReturn - if err := execreturn.UnmarshalCBOR(bytes.NewReader(wait.Receipt.ReturnValue)); err != nil { + if err := execreturn.UnmarshalCBOR(bytes.NewReader(wait.Receipt.Return)); err != nil { return err } // TODO: maybe register this somewhere @@ -178,7 +177,7 @@ var msigInspectCmd = &cmds.Command{ if err != nil { return err } - mstate, err := multisig.Load(store, (*types2.Actor)(act)) + mstate, err := multisig.Load(store, act) if err != nil { return err } @@ -383,7 +382,7 @@ var msigProposeCmd = &cmds.Command{ } var retval msig2.ProposeReturn - if err := retval.UnmarshalCBOR(bytes.NewReader(wait.Receipt.ReturnValue)); err != nil { + if err := retval.UnmarshalCBOR(bytes.NewReader(wait.Receipt.Return)); err != nil { return fmt.Errorf("failed to unmarshal propose return value: %w", err) } fmt.Fprintf(buf, "Transaction ID: %d\n", retval.TxnID) @@ -447,7 +446,7 @@ var msigRemoveProposeCmd = &cmds.Command{ } var ret multisig.ProposeReturn - err = ret.UnmarshalCBOR(bytes.NewReader(wait.Receipt.ReturnValue)) + err = ret.UnmarshalCBOR(bytes.NewReader(wait.Receipt.Return)) if err != nil { return xerrors.Errorf("decoding proposal return: %w", err) } @@ -613,7 +612,7 @@ var msigAddProposeCmd = &cmds.Command{ } var ret multisig.ProposeReturn - err = ret.UnmarshalCBOR(bytes.NewReader(wait.Receipt.ReturnValue)) + err = ret.UnmarshalCBOR(bytes.NewReader(wait.Receipt.Return)) if err != nil { return xerrors.Errorf("decoding proposal return: %w", err) } @@ -805,7 +804,7 @@ var msigSwapProposeCmd = &cmds.Command{ return fmt.Errorf("swap proposal returned exit %d", wait.Receipt.ExitCode) } var ret multisig.ProposeReturn - err = ret.UnmarshalCBOR(bytes.NewReader(wait.Receipt.ReturnValue)) + err = ret.UnmarshalCBOR(bytes.NewReader(wait.Receipt.Return)) if err != nil { return xerrors.Errorf("decoding proposal return: %w", err) } @@ -1010,7 +1009,7 @@ var msigLockProposeCmd = &cmds.Command{ return fmt.Errorf("lock proposal returned exit %d", wait.Receipt.ExitCode) } var ret multisig.ProposeReturn - err = ret.UnmarshalCBOR(bytes.NewReader(wait.Receipt.ReturnValue)) + err = ret.UnmarshalCBOR(bytes.NewReader(wait.Receipt.Return)) if err != nil { return xerrors.Errorf("decoding proposal return: %w", err) } @@ -1289,7 +1288,7 @@ var msigProposeThresholdCmd = &cmds.Command{ return fmt.Errorf("change threshold proposal returned exit %d", wait.Receipt.ExitCode) } var ret multisig.ProposeReturn - err = ret.UnmarshalCBOR(bytes.NewReader(wait.Receipt.ReturnValue)) + err = ret.UnmarshalCBOR(bytes.NewReader(wait.Receipt.Return)) if err != nil { return xerrors.Errorf("decoding proposal return: %w", err) } diff --git a/cmd/paych.go b/cmd/paych.go index ea5699a620..d434beda7c 100644 --- a/cmd/paych.go +++ b/cmd/paych.go @@ -14,8 +14,8 @@ import ( "github.com/filecoin-project/venus/app/node" "github.com/filecoin-project/venus/pkg/constants" "github.com/filecoin-project/venus/pkg/paychmgr" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/venus-shared/actors/builtin/paych" + types "github.com/filecoin-project/venus/venus-shared/chain" cmds "github.com/ipfs/go-ipfs-cmds" "golang.org/x/xerrors" ) diff --git a/cmd/protocol.go b/cmd/protocol.go index 2a6b90ac94..6237999d95 100644 --- a/cmd/protocol.go +++ b/cmd/protocol.go @@ -2,7 +2,7 @@ package cmd import ( "github.com/filecoin-project/venus/app/node" - "github.com/filecoin-project/venus/app/submodule/apitypes" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" cmds "github.com/ipfs/go-ipfs-cmds" ) diff --git a/cmd/seed.go b/cmd/seed.go index 1539631bc9..f9c6dbde32 100644 --- a/cmd/seed.go +++ b/cmd/seed.go @@ -25,9 +25,9 @@ import ( "github.com/filecoin-project/venus/pkg/crypto" "github.com/filecoin-project/venus/pkg/gen" "github.com/filecoin-project/venus/pkg/gen/genesis" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/tools/seed" "github.com/filecoin-project/venus/venus-shared/actors/builtin/miner" + types "github.com/filecoin-project/venus/venus-shared/chain" ) var seedCmd = &cmds.Command{ diff --git a/cmd/show.go b/cmd/show.go index f9673777f8..b1059ae75c 100644 --- a/cmd/show.go +++ b/cmd/show.go @@ -2,7 +2,7 @@ package cmd import ( "github.com/filecoin-project/venus/app/node" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/ipfs/go-cid" cmds "github.com/ipfs/go-ipfs-cmds" diff --git a/cmd/show_test.go b/cmd/show_test.go index 121d45e697..e4f82f5ad3 100644 --- a/cmd/show_test.go +++ b/cmd/show_test.go @@ -3,10 +3,15 @@ package cmd_test import ( "context" "encoding/json" + "testing" + + "github.com/filecoin-project/venus/pkg/testhelpers" + + "github.com/ipfs/go-cid" + "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/venus/pkg/crypto" - emptycid "github.com/filecoin-project/venus/pkg/testhelpers/empty_cid" - "testing" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -14,7 +19,6 @@ import ( "github.com/filecoin-project/venus/app/node/test" "github.com/filecoin-project/venus/fixtures/fortest" tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" - "github.com/filecoin-project/venus/pkg/types" ) // Receipt is what is returned by executing a message on the vm. @@ -134,7 +138,7 @@ func TestBlockDaemon(t *testing.T) { _, err := mockBlock(t) require.NoError(t, err) - emptyMessagesLine := cmdClient.RunSuccessFirstLine(ctx, "show", "messages", emptycid.EmptyMessagesCID.String(), "--enc", "json") + emptyMessagesLine := cmdClient.RunSuccessFirstLine(ctx, "show", "messages", testhelpers.EmptyMessagesCID.String(), "--enc", "json") var messageCollection []*types.SignedMessage require.NoError(t, json.Unmarshal([]byte(emptyMessagesLine), &messageCollection)) @@ -154,7 +158,7 @@ func TestBlockDaemon(t *testing.T) { _, err := mockBlock(t) require.NoError(t, err) - emptyReceiptsLine := cmdClient.RunSuccessFirstLine(ctx, "show", "receipts", emptycid.EmptyReceiptsCID.String(), "--enc", "json") + emptyReceiptsLine := cmdClient.RunSuccessFirstLine(ctx, "show", "receipts", testhelpers.EmptyReceiptsCID.String(), "--enc", "json") var receipts []Receipt require.NoError(t, json.Unmarshal([]byte(emptyReceiptsLine), &receipts)) @@ -228,21 +232,21 @@ func TestBlockDaemon(t *testing.T) { func mockBlock(t *testing.T) (*types.BlockHeader, error) { b := &types.BlockHeader{ - Miner: types.NewForTestGetter()(), - Ticket: types.Ticket{VRFProof: []byte{0x01, 0x02, 0x03}}, + Miner: testhelpers.NewForTestGetter()(), + Ticket: &types.Ticket{VRFProof: []byte{0x01, 0x02, 0x03}}, ElectionProof: &types.ElectionProof{VRFProof: []byte{0x0a, 0x0b}}, Height: 2, - BeaconEntries: []*types.BeaconEntry{ + BeaconEntries: []types.BeaconEntry{ { Round: 1, Data: []byte{0x3}, }, }, - Messages: types.CidFromString(t, "somecid"), - ParentMessageReceipts: types.CidFromString(t, "somecid"), - Parents: types.NewTipSetKey(types.CidFromString(t, "somecid")), + Messages: testhelpers.CidFromString(t, "somecid"), + ParentMessageReceipts: testhelpers.CidFromString(t, "somecid"), + Parents: []cid.Cid{testhelpers.CidFromString(t, "somecid")}, ParentWeight: big.NewInt(1000), - ParentStateRoot: types.CidFromString(t, "somecid"), + ParentStateRoot: testhelpers.CidFromString(t, "somecid"), Timestamp: 1, BlockSig: &crypto.Signature{ Type: crypto.SigTypeBLS, diff --git a/cmd/state.go b/cmd/state.go index fb68763731..80cbec28a5 100644 --- a/cmd/state.go +++ b/cmd/state.go @@ -19,10 +19,10 @@ import ( "golang.org/x/xerrors" "github.com/filecoin-project/venus/app/node" - "github.com/filecoin-project/venus/app/submodule/apitypes" "github.com/filecoin-project/venus/pkg/constants" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/venus-shared/actors/builtin" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" ) // ActorView represents a generic way to represent details about any actor to the user. @@ -79,7 +79,7 @@ var stateWaitMsgCmd = &cmds.Command{ writer.Printf("message was executed in tipset: %s\n", mw.TipSet.Cids()) writer.Printf("Exit Code: %d\n", mw.Receipt.ExitCode) writer.Printf("Gas Used: %d\n", mw.Receipt.GasUsed) - writer.Printf("Return: %x\n", mw.Receipt.ReturnValue) + writer.Printf("Return: %x\n", mw.Receipt.Return) return re.Emit(buf) }, @@ -109,7 +109,7 @@ var stateSearchMsgCmd = &cmds.Command{ writer.Printf("message was executed in tipset: %s", mw.TipSet.Cids()) writer.Printf("\nExit Code: %d", mw.Receipt.ExitCode) writer.Printf("\nGas Used: %d", mw.Receipt.GasUsed) - writer.Printf("\nReturn: %x", mw.Receipt.ReturnValue) + writer.Printf("\nReturn: %x", mw.Receipt.Return) } else { writer.Print("message was not found on chain") } diff --git a/pkg/beacon/beacon.go b/pkg/beacon/beacon.go index e9e6783641..7b0b6df551 100644 --- a/pkg/beacon/beacon.go +++ b/pkg/beacon/beacon.go @@ -2,10 +2,10 @@ package beacon import ( "context" - "github.com/filecoin-project/venus/pkg/types" "time" "github.com/filecoin-project/go-state-types/abi" + types "github.com/filecoin-project/venus/venus-shared/chain" logging "github.com/ipfs/go-log" "golang.org/x/xerrors" ) @@ -43,7 +43,7 @@ func ValidateBlockValues(bSchedule Schedule, h *types.BlockHeader, parentEpoch a if len(h.BeaconEntries) != 2 { return xerrors.Errorf("expected two beacon entries at beacon fork, got %d", len(h.BeaconEntries)) } - err := currBeacon.VerifyEntry(*h.BeaconEntries[1], *h.BeaconEntries[0]) + err := currBeacon.VerifyEntry(h.BeaconEntries[1], h.BeaconEntries[0]) if err != nil { return xerrors.Errorf("beacon at fork point invalid: (%v, %v): %w", h.BeaconEntries[1], h.BeaconEntries[0], err) @@ -72,10 +72,11 @@ func ValidateBlockValues(bSchedule Schedule, h *types.BlockHeader, parentEpoch a } for i, e := range h.BeaconEntries { - if err := b.VerifyEntry(*e, *prevEntry); err != nil { + if err := b.VerifyEntry(e, *prevEntry); err != nil { return xerrors.Errorf("beacon entry %d (%d - %x (%d)) was invalid: %w", i, e.Round, e.Data, len(e.Data), err) } - prevEntry = e + prevEntry = &h.BeaconEntries[i] + } return nil diff --git a/pkg/beacon/drand.go b/pkg/beacon/drand.go index 5b33d4ef2e..ce28fc08a3 100644 --- a/pkg/beacon/drand.go +++ b/pkg/beacon/drand.go @@ -18,7 +18,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" cfg "github.com/filecoin-project/venus/pkg/config" "github.com/filecoin-project/venus/pkg/constants" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" ) // DrandBeacon connects Lotus with a drand network in order to provide diff --git a/pkg/beacon/mock.go b/pkg/beacon/mock.go index 48d53fe047..4187c1400b 100644 --- a/pkg/beacon/mock.go +++ b/pkg/beacon/mock.go @@ -4,10 +4,10 @@ import ( "bytes" "context" "encoding/binary" - "github.com/filecoin-project/venus/pkg/types" "time" "github.com/filecoin-project/go-state-types/abi" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/minio/blake2b-simd" "golang.org/x/xerrors" ) diff --git a/pkg/chain/chain_index.go b/pkg/chain/chain_index.go index 9d98fa87e8..cbc5d134a7 100644 --- a/pkg/chain/chain_index.go +++ b/pkg/chain/chain_index.go @@ -2,9 +2,9 @@ package chain import ( "context" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/go-state-types/abi" + types "github.com/filecoin-project/venus/venus-shared/chain" lru "github.com/hashicorp/golang-lru" xerrors "github.com/pkg/errors" ) diff --git a/pkg/chain/circulating_supply.go b/pkg/chain/circulating_supply.go index 44e2524bba..cc6a2f62b8 100644 --- a/pkg/chain/circulating_supply.go +++ b/pkg/chain/circulating_supply.go @@ -23,7 +23,6 @@ import ( "github.com/filecoin-project/venus/venus-shared/actors/builtin/market" "github.com/filecoin-project/venus/venus-shared/actors/builtin/power" "github.com/filecoin-project/venus/venus-shared/actors/builtin/reward" - types "github.com/filecoin-project/venus/venus-shared/chain" ) type ICirculatingSupplyCalcualtor interface { @@ -132,7 +131,7 @@ func (caculator *CirculatingSupplyCalculator) GetCirculatingSupplyDetailed(ctx c /*func (c *Expected) processBlock(ctx context.Context, ts *block.TipSet) (cid.Cid, []types.MessageReceipt, error) { var secpMessages [][]*types.SignedMessage - var blsMessages [][]*types.UnsignedMessage + var blsMessages [][]*types.Message for i := 0; i < ts.Len(); i++ { blk := ts.At(i) secpMsgs, blsMsgs, err := c.messageStore.LoadMetaMessages(ctx, blk.Messages.Cid) @@ -371,7 +370,7 @@ func GetFilMined(ctx context.Context, st tree.Tree) (abi.TokenAmount, error) { return big.Zero(), xerrors.Errorf("failed to load reward actor state: %v", err) } - rst, err := reward.Load(adt.WrapStore(ctx, st.GetStore()), (*types.Actor)(ractor)) + rst, err := reward.Load(adt.WrapStore(ctx, st.GetStore()), ractor) if err != nil { return big.Zero(), err } @@ -411,7 +410,7 @@ func getFilMarketLocked(ctx context.Context, st tree.Tree) (abi.TokenAmount, err return big.Zero(), xerrors.Errorf("failed to load market actor: %v", err) } - mst, err := market.Load(adt.WrapStore(ctx, st.GetStore()), (*types.Actor)(act)) + mst, err := market.Load(adt.WrapStore(ctx, st.GetStore()), act) if err != nil { return big.Zero(), xerrors.Errorf("failed to load market state: %v", err) } @@ -425,7 +424,7 @@ func getFilPowerLocked(ctx context.Context, st tree.Tree) (abi.TokenAmount, erro return big.Zero(), xerrors.Errorf("failed to load power actor: %v", err) } - pst, err := power.Load(adt.WrapStore(ctx, st.GetStore()), (*types.Actor)(pactor)) + pst, err := power.Load(adt.WrapStore(ctx, st.GetStore()), pactor) if err != nil { return big.Zero(), xerrors.Errorf("failed to load power state: %v", err) } diff --git a/pkg/chain/coalescer.go b/pkg/chain/coalescer.go index fac77f7acb..380b4c6f9a 100644 --- a/pkg/chain/coalescer.go +++ b/pkg/chain/coalescer.go @@ -2,8 +2,9 @@ package chain import ( "context" - "github.com/filecoin-project/venus/pkg/types" "time" + + types "github.com/filecoin-project/venus/venus-shared/chain" ) // WrapHeadChangeCoalescer wraps a ReorgNotifee with a head change coalescer. diff --git a/pkg/chain/coalescer_test.go b/pkg/chain/coalescer_test.go index 48f88ac2cc..6d8f4e72ab 100644 --- a/pkg/chain/coalescer_test.go +++ b/pkg/chain/coalescer_test.go @@ -2,7 +2,6 @@ package chain import ( "fmt" - "github.com/filecoin-project/venus/pkg/types" "testing" "time" @@ -14,6 +13,7 @@ import ( "github.com/filecoin-project/venus/pkg/constants" "github.com/filecoin-project/venus/pkg/crypto" tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" + types "github.com/filecoin-project/venus/venus-shared/chain" ) func mkAddress(i uint64) address.Address { @@ -54,10 +54,10 @@ func mkBlock(parents *types.TipSet, weightInc int64, ticketNonce uint64) *types. ElectionProof: &types.ElectionProof{ VRFProof: []byte(fmt.Sprintf("====%d=====", ticketNonce)), }, - Ticket: types.Ticket{ + Ticket: &types.Ticket{ VRFProof: []byte(fmt.Sprintf("====%d=====", ticketNonce)), }, - Parents: tsKey, + Parents: tsKey.Cids(), ParentMessageReceipts: c, BLSAggregate: &crypto.Signature{Type: crypto.SigTypeBLS, Data: []byte("boo! im a signature")}, ParentWeight: weight, @@ -71,7 +71,7 @@ func mkBlock(parents *types.TipSet, weightInc int64, ticketNonce uint64) *types. } func mkTipSet(blks ...*types.BlockHeader) *types.TipSet { - ts, err := types.NewTipSet(blks...) + ts, err := types.NewTipSet(blks) if err != nil { panic(err) } diff --git a/pkg/chain/message_store.go b/pkg/chain/message_store.go index d62ac5b6f9..9e213947d5 100644 --- a/pkg/chain/message_store.go +++ b/pkg/chain/message_store.go @@ -23,28 +23,28 @@ import ( "github.com/filecoin-project/venus/pkg/config" "github.com/filecoin-project/venus/pkg/constants" "github.com/filecoin-project/venus/pkg/state/tree" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/util/blockstoreutil" + types "github.com/filecoin-project/venus/venus-shared/chain" ) // MessageProvider is an interface exposing the load methods of the // MessageStore. type MessageProvider interface { LoadTipSetMessage(ctx context.Context, ts *types.TipSet) ([]types.BlockMessagesInfo, error) - LoadMetaMessages(context.Context, cid.Cid) ([]*types.SignedMessage, []*types.UnsignedMessage, error) + LoadMetaMessages(context.Context, cid.Cid) ([]*types.SignedMessage, []*types.Message, error) ReadMsgMetaCids(ctx context.Context, mmc cid.Cid) ([]cid.Cid, []cid.Cid, error) - LoadUnsignedMessagesFromCids(blsCids []cid.Cid) ([]*types.UnsignedMessage, error) + LoadUnsignedMessagesFromCids(blsCids []cid.Cid) ([]*types.Message, error) LoadSignedMessagesFromCids(secpCids []cid.Cid) ([]*types.SignedMessage, error) LoadReceipts(context.Context, cid.Cid) ([]types.MessageReceipt, error) - LoadTxMeta(context.Context, cid.Cid) (types.TxMeta, error) + LoadTxMeta(context.Context, cid.Cid) (types.MessageRoot, error) } // MessageWriter is an interface exposing the write methods of the // MessageStore. type MessageWriter interface { - StoreMessages(ctx context.Context, secpMessages []*types.SignedMessage, blsMessages []*types.UnsignedMessage) (cid.Cid, error) + StoreMessages(ctx context.Context, secpMessages []*types.SignedMessage, blsMessages []*types.Message) (cid.Cid, error) StoreReceipts(context.Context, []types.MessageReceipt) (cid.Cid, error) - StoreTxMeta(context.Context, types.TxMeta) (cid.Cid, error) + StoreTxMeta(context.Context, types.MessageRoot) (cid.Cid, error) } // MessageStore stores and loads collections of signed messages and receipts. @@ -60,14 +60,14 @@ func NewMessageStore(bs blockstore.Blockstore, fkCfg *config.ForkUpgradeConfig) // LoadMetaMessages loads the signed messages in the collection with cid c from ipld // storage. -func (ms *MessageStore) LoadMetaMessages(ctx context.Context, metaCid cid.Cid) ([]*types.SignedMessage, []*types.UnsignedMessage, error) { +func (ms *MessageStore) LoadMetaMessages(ctx context.Context, metaCid cid.Cid) ([]*types.SignedMessage, []*types.Message, error) { // load txmeta meta, err := ms.LoadTxMeta(ctx, metaCid) if err != nil { return nil, nil, err } - secpCids, err := ms.loadAMTCids(ctx, meta.SecpRoot) + secpCids, err := ms.loadAMTCids(ctx, meta.SecpkRoot) if err != nil { return nil, nil, err } @@ -78,7 +78,7 @@ func (ms *MessageStore) LoadMetaMessages(ctx context.Context, metaCid cid.Cid) ( return nil, nil, err } - blsCids, err := ms.loadAMTCids(ctx, meta.BLSRoot) + blsCids, err := ms.loadAMTCids(ctx, meta.BlsRoot) if err != nil { return nil, nil, err } @@ -99,11 +99,11 @@ func (ms *MessageStore) ReadMsgMetaCids(ctx context.Context, mmc cid.Cid) ([]cid return nil, nil, err } - secpCids, err := ms.loadAMTCids(ctx, meta.SecpRoot) + secpCids, err := ms.loadAMTCids(ctx, meta.SecpkRoot) if err != nil { return nil, nil, err } - blsCids, err := ms.loadAMTCids(ctx, meta.BLSRoot) + blsCids, err := ms.loadAMTCids(ctx, meta.BlsRoot) if err != nil { return nil, nil, err } @@ -126,12 +126,12 @@ func (ms *MessageStore) LoadMessage(mid cid.Cid) (types.ChainMsg, error) { } //LoadUnsignedMessage load unsigned messages in tipset -func (ms *MessageStore) LoadUnsignedMessage(mid cid.Cid) (*types.UnsignedMessage, error) { +func (ms *MessageStore) LoadUnsignedMessage(mid cid.Cid) (*types.Message, error) { messageBlock, err := ms.bs.Get(mid) if err != nil { return nil, errors.Wrapf(err, "failed to get bls message %s", mid) } - message := &types.UnsignedMessage{} + message := &types.Message{} if err := message.UnmarshalCBOR(bytes.NewReader(messageBlock.RawData())); err != nil { return nil, errors.Wrapf(err, "could not decode bls message %s", mid) } @@ -154,8 +154,8 @@ func (ms *MessageStore) LoadSignedMessage(mid cid.Cid) (*types.SignedMessage, er } //LoadUnsignedMessagesFromCids load unsigned messages of cid array -func (ms *MessageStore) LoadUnsignedMessagesFromCids(blsCids []cid.Cid) ([]*types.UnsignedMessage, error) { - blsMsgs := make([]*types.UnsignedMessage, len(blsCids)) +func (ms *MessageStore) LoadUnsignedMessagesFromCids(blsCids []cid.Cid) ([]*types.Message, error) { + blsMsgs := make([]*types.Message, len(blsCids)) for i, c := range blsCids { message, err := ms.LoadUnsignedMessage(c) if err != nil { @@ -181,8 +181,8 @@ func (ms *MessageStore) LoadSignedMessagesFromCids(secpCids []cid.Cid) ([]*types // StoreMessages puts the input signed messages to a collection and then writes // this collection to ipld storage. The cid of the collection is returned. -func (ms *MessageStore) StoreMessages(ctx context.Context, secpMessages []*types.SignedMessage, blsMessages []*types.UnsignedMessage) (cid.Cid, error) { - var ret types.TxMeta +func (ms *MessageStore) StoreMessages(ctx context.Context, secpMessages []*types.SignedMessage, blsMessages []*types.Message) (cid.Cid, error) { + var ret types.MessageRoot var err error // store secp messages @@ -203,7 +203,7 @@ func (ms *MessageStore) StoreMessages(ctx context.Context, secpMessages []*types if err != nil { return cid.Undef, errors.Wrap(err, "could not store secp cids as AMT") } - ret.SecpRoot = secpRaw + ret.SecpkRoot = secpRaw // store bls messages blsMsgArr := adt.MakeEmptyArray(adt.WrapStore(context.TODO(), as)) @@ -222,15 +222,15 @@ func (ms *MessageStore) StoreMessages(ctx context.Context, secpMessages []*types if err != nil { return cid.Undef, errors.Wrap(err, "could not store bls cids as AMT") } - ret.BLSRoot = blsRaw + ret.BlsRoot = blsRaw return ms.StoreTxMeta(ctx, ret) } //load message from tipset NOTICE skip message with the same nonce -func (ms *MessageStore) LoadTipSetMesssages(ctx context.Context, ts *types.TipSet) ([][]*types.SignedMessage, [][]*types.UnsignedMessage, error) { +func (ms *MessageStore) LoadTipSetMesssages(ctx context.Context, ts *types.TipSet) ([][]*types.SignedMessage, [][]*types.Message, error) { var secpMessages [][]*types.SignedMessage - var blsMessages [][]*types.UnsignedMessage + var blsMessages [][]*types.Message applied := make(map[address.Address]uint64) @@ -240,7 +240,7 @@ func (ms *MessageStore) LoadTipSetMesssages(ctx context.Context, ts *types.TipSe return nil, nil, errors.Wrapf(err, "failed to load state tree %s", ts.Blocks()[0].ParentStateRoot.String()) } - selectMsg := func(m *types.UnsignedMessage) (bool, error) { + selectMsg := func(m *types.Message) (bool, error) { var sender address.Address if ts.Height() >= ms.fkCfg.UpgradeHyperdriveHeight { sender, err = st.LookupID(m.From) @@ -273,7 +273,7 @@ func (ms *MessageStore) LoadTipSetMesssages(ctx context.Context, ts *types.TipSe } var blksecpMessages []*types.SignedMessage - var blkblsMessages []*types.UnsignedMessage + var blkblsMessages []*types.Message for _, msg := range blsMsgs { b, err := selectMsg(msg) @@ -373,15 +373,15 @@ func (ms *MessageStore) loadAMTCids(ctx context.Context, c cid.Cid) ([]cid.Cid, } // LoadTxMeta loads the secproot, blsroot data from the message store -func (ms *MessageStore) LoadTxMeta(ctx context.Context, c cid.Cid) (types.TxMeta, error) { +func (ms *MessageStore) LoadTxMeta(ctx context.Context, c cid.Cid) (types.MessageRoot, error) { metaBlock, err := ms.bs.Get(c) if err != nil { - return types.TxMeta{}, errors.Wrapf(err, "failed to get tx meta %s", c) + return types.MessageRoot{}, errors.Wrapf(err, "failed to get tx meta %s", c) } - var meta types.TxMeta + var meta types.MessageRoot if err := meta.UnmarshalCBOR(bytes.NewReader(metaBlock.RawData())); err != nil { - return types.TxMeta{}, errors.Wrapf(err, "could not decode tx meta %s", c) + return types.MessageRoot{}, errors.Wrapf(err, "could not decode tx meta %s", c) } return meta, nil } @@ -397,7 +397,7 @@ func (ms *MessageStore) LoadTipSetMessage(ctx context.Context, ts *types.TipSet) return nil, errors.Errorf("failed to load state tree") } - selectMsg := func(m *types.UnsignedMessage) (bool, error) { + selectMsg := func(m *types.Message) (bool, error) { var sender address.Address if ts.Height() >= ms.fkCfg.UpgradeHyperdriveHeight { sender, err = st.LookupID(m.From) @@ -483,7 +483,7 @@ func (ms *MessageStore) StoreMessage(message types.ChainMsg) (cid.Cid, error) { } // StoreTxMeta writes the secproot, blsroot block to the message store -func (ms *MessageStore) StoreTxMeta(ctx context.Context, meta types.TxMeta) (cid.Cid, error) { +func (ms *MessageStore) StoreTxMeta(ctx context.Context, meta types.MessageRoot) (cid.Cid, error) { return cbor.NewCborStore(ms.bs).Put(ctx, &meta) } @@ -642,9 +642,9 @@ func ComputeMsgMeta(bs blockstore.Blockstore, bmsgCids, smsgCids []cid.Cid) (cid return cid.Undef, err } - mrcid, err := store.Put(store.Context(), &types.TxMeta{ - BLSRoot: bmroot, - SecpRoot: smroot, + mrcid, err := store.Put(store.Context(), &types.MessageRoot{ + BlsRoot: bmroot, + SecpkRoot: smroot, }) if err != nil { return cid.Undef, errors.Wrap(err, "failed to put msgmeta") diff --git a/pkg/chain/message_store_test.go b/pkg/chain/message_store_test.go index 166f7a4bcc..c40a62761b 100644 --- a/pkg/chain/message_store_test.go +++ b/pkg/chain/message_store_test.go @@ -2,7 +2,6 @@ package chain_test import ( "context" - "github.com/filecoin-project/venus/pkg/testhelpers/testflags" "testing" "github.com/ipfs/go-datastore" @@ -11,14 +10,16 @@ import ( "github.com/filecoin-project/venus/pkg/chain" "github.com/filecoin-project/venus/pkg/config" - "github.com/filecoin-project/venus/pkg/types" + "github.com/filecoin-project/venus/pkg/testhelpers" + "github.com/filecoin-project/venus/pkg/testhelpers/testflags" + types "github.com/filecoin-project/venus/venus-shared/chain" ) func TestMessageStoreMessagesHappy(t *testing.T) { testflags.UnitTest(t) ctx := context.Background() - keys := types.MustGenerateKeyInfo(2, 42) - mm := types.NewMessageMaker(t, keys) + keys := testhelpers.MustGenerateKeyInfo(2, 42) + mm := testhelpers.NewMessageMaker(t, keys) alice := mm.Addresses()[0] bob := mm.Addresses()[1] @@ -36,7 +37,7 @@ func TestMessageStoreMessagesHappy(t *testing.T) { bs := blockstore.NewBlockstore(datastore.NewMapDatastore()) ms := chain.NewMessageStore(bs, config.DefaultForkUpgradeParam) - msgsCid, err := ms.StoreMessages(ctx, msgs, []*types.UnsignedMessage{}) + msgsCid, err := ms.StoreMessages(ctx, msgs, []*types.Message{}) assert.NoError(t, err) rtMsgs, _, err := ms.LoadMetaMessages(ctx, msgsCid) @@ -47,7 +48,7 @@ func TestMessageStoreMessagesHappy(t *testing.T) { func TestMessageStoreReceiptsHappy(t *testing.T) { ctx := context.Background() - mr := types.NewReceiptMaker() + mr := testhelpers.NewReceiptMaker() receipts := []types.MessageReceipt{ mr.NewReceipt(), diff --git a/pkg/chain/randomness.go b/pkg/chain/randomness.go index 273b2c7841..b79eb8aa8d 100644 --- a/pkg/chain/randomness.go +++ b/pkg/chain/randomness.go @@ -4,13 +4,14 @@ import ( "bytes" "context" "encoding/binary" + "math/rand" + "github.com/filecoin-project/venus/pkg/beacon" + types "github.com/filecoin-project/venus/venus-shared/chain" "golang.org/x/xerrors" - "math/rand" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/crypto" - "github.com/filecoin-project/venus/pkg/types" "github.com/minio/blake2b-simd" "github.com/pkg/errors" ) @@ -136,7 +137,6 @@ func (c *ChainRandomnessSource) GetBeaconRandomnessTipset(ctx context.Context, r // in which no blocks were produced (an empty tipset or "null block"). A caller desiring a unique see for each epoch // should blend in some distinguishing value (such as the epoch itself) into a hash of this ticket. func (c *ChainRandomnessSource) GetChainRandomness(ctx context.Context, epoch abi.ChainEpoch, lookback bool) (types.Ticket, error) { - var ticket types.Ticket if !c.head.IsEmpty() { start, err := c.reader.GetTipSet(c.head) if err != nil { @@ -159,12 +159,9 @@ func (c *ChainRandomnessSource) GetChainRandomness(ctx context.Context, epoch ab if err != nil { return types.Ticket{}, err } - ticket = tip.MinTicket() - } else { - return types.Ticket{}, xerrors.Errorf("cannot get ticket for empty tipset") + return *tip.MinTicket(), nil } - - return ticket, nil + return types.Ticket{}, xerrors.Errorf("cannot get ticket for empty tipset") } // network v0-12 @@ -250,7 +247,7 @@ func (c *ChainRandomnessSource) extractBeaconEntryForEpoch(ctx context.Context, cbe := randTS.Blocks()[0].BeaconEntries for _, v := range cbe { if v.Round == round { - return v, nil + return &v, nil } } diff --git a/pkg/chain/reorg.go b/pkg/chain/reorg.go index 93b8f1a58b..45958159af 100644 --- a/pkg/chain/reorg.go +++ b/pkg/chain/reorg.go @@ -2,7 +2,7 @@ package chain import ( "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/pkg/errors" ) diff --git a/pkg/chain/reorg_test.go b/pkg/chain/reorg_test.go index a15802222a..dcc4d5a398 100644 --- a/pkg/chain/reorg_test.go +++ b/pkg/chain/reorg_test.go @@ -2,15 +2,17 @@ package chain_test import ( "context" - "github.com/filecoin-project/venus/pkg/types" "testing" + "github.com/filecoin-project/venus/pkg/testhelpers" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/stretchr/testify/assert" "github.com/filecoin-project/venus/pkg/chain" tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" + types "github.com/filecoin-project/venus/venus-shared/chain" ) func TestIsReorgFork(t *testing.T) { @@ -90,7 +92,7 @@ func getSubsetOldNewCommon(ctx context.Context, t *testing.T, builder *chain.Bui block1 := builder.AppendBlockOnBlocks(commonHead) block2 := builder.AppendBlockOnBlocks(commonHead) - oldHead := types.RequireNewTipSet(t, block1) - superset := types.RequireNewTipSet(t, block1, block2) - return oldHead, superset, types.RequireNewTipSet(t, commonHead) + oldHead := testhelpers.RequireNewTipSet(t, block1) + superset := testhelpers.RequireNewTipSet(t, block1, block2) + return oldHead, superset, testhelpers.RequireNewTipSet(t, commonHead) } diff --git a/pkg/chain/store.go b/pkg/chain/store.go index 91717f0ad8..88c07ed697 100644 --- a/pkg/chain/store.go +++ b/pkg/chain/store.go @@ -34,7 +34,6 @@ import ( "github.com/filecoin-project/venus/pkg/metrics/tracing" "github.com/filecoin-project/venus/pkg/repo" "github.com/filecoin-project/venus/pkg/state/tree" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/util" "github.com/filecoin-project/venus/venus-shared/actors/adt" "github.com/filecoin-project/venus/venus-shared/actors/builtin" @@ -46,7 +45,7 @@ import ( "github.com/filecoin-project/venus/venus-shared/actors/builtin/reward" "github.com/filecoin-project/venus/venus-shared/actors/builtin/verifreg" "github.com/filecoin-project/venus/venus-shared/actors/policy" - types2 "github.com/filecoin-project/venus/venus-shared/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" ) // HeadChangeTopic is the topic used to publish new heads. @@ -163,7 +162,7 @@ func NewStore(chainDs repo.Datastore, bsstore: bsstore, headEvents: pubsub.New(64), - checkPoint: types.UndefTipSet.Key(), + checkPoint: types.EmptyTSK, genesis: genesisCid, reorgNotifeeCh: make(chan ReorgNotifee), tsCache: tsCache, @@ -406,7 +405,7 @@ func (store *Store) GetTipSet(key types.TipSetKey) (*types.TipSet, error) { blks[idx] = blk } - ts, err := types.NewTipSet(blks...) + ts, err := types.NewTipSet(blks) if err != nil { return nil, err } @@ -502,7 +501,7 @@ func (store *Store) GetLatestBeaconEntry(ts *types.TipSet) (*types.BeaconEntry, for i := 0; i < 20; i++ { cbe := cur.At(0).BeaconEntries if len(cbe) > 0 { - return cbe[len(cbe)-1], nil + return &cbe[len(cbe)-1], nil } if cur.Height() == 0 { @@ -921,10 +920,10 @@ func (store *Store) WalkSnapshot(ctx context.Context, ts *types.TipSet, inclRece } if b.Height > 0 { - blocksToWalk = append(blocksToWalk, b.Parents.Cids()...) + blocksToWalk = append(blocksToWalk, b.Parents...) } else { // include the genesis block - cids = append(cids, b.Parents.Cids()...) + cids = append(cids, b.Parents...) } out := cids @@ -1097,7 +1096,7 @@ func (store *Store) getCirculatingSupply(ctx context.Context, height abi.ChainEp unCirc = big.Add(unCirc, actor.Balance) case a == market.Address: - mst, err := market.Load(adtStore, (*types2.Actor)(actor)) + mst, err := market.Load(adtStore, actor) if err != nil { return err } @@ -1114,7 +1113,7 @@ func (store *Store) getCirculatingSupply(ctx context.Context, height abi.ChainEp circ = big.Add(circ, actor.Balance) case builtin.IsStorageMinerActor(actor.Code): - mst, err := miner.Load(adtStore, (*types2.Actor)(actor)) + mst, err := miner.Load(adtStore, actor) if err != nil { return err } @@ -1131,7 +1130,7 @@ func (store *Store) getCirculatingSupply(ctx context.Context, height abi.ChainEp } case builtin.IsMultisigActor(actor.Code): - mst, err := multisig.Load(adtStore, (*types2.Actor)(actor)) + mst, err := multisig.Load(adtStore, actor) if err != nil { return err } diff --git a/pkg/chain/store_test.go b/pkg/chain/store_test.go index 96c006f5f1..3e426e7cc7 100644 --- a/pkg/chain/store_test.go +++ b/pkg/chain/store_test.go @@ -5,17 +5,16 @@ import ( "testing" "github.com/filecoin-project/go-address" - emptycid "github.com/filecoin-project/venus/pkg/testhelpers/empty_cid" + "github.com/filecoin-project/venus/pkg/chain" + "github.com/filecoin-project/venus/pkg/repo" + "github.com/filecoin-project/venus/pkg/testhelpers" + tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" "github.com/filecoin-project/venus/pkg/util/test" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/ipfs/go-cid" cbor "github.com/ipfs/go-ipld-cbor" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - - "github.com/filecoin-project/venus/pkg/chain" - "github.com/filecoin-project/venus/pkg/repo" - tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" - "github.com/filecoin-project/venus/pkg/types" ) type CborBlockStore struct { @@ -52,7 +51,7 @@ func requirePutTestChain(ctx context.Context, t *testing.T, cborStore *CborBlock tsas := &chain.TipSetMetadata{ TipSet: ts, TipSetStateRoot: ts.At(0).ParentStateRoot, - TipSetReceipts: emptycid.EmptyReceiptsCID, + TipSetReceipts: testhelpers.EmptyReceiptsCID, } requirePutBlocksToCborStore(t, cborStore.cborStore, tsas.TipSet.Blocks()...) require.NoError(t, cborStore.PutTipSetMetadata(ctx, tsas)) @@ -86,7 +85,7 @@ func TestPutTipSet(t *testing.T) { genTsas := &chain.TipSetMetadata{ TipSet: genTS, TipSetStateRoot: genTS.At(0).ParentStateRoot, - TipSetReceipts: emptycid.EmptyReceiptsCID, + TipSetReceipts: testhelpers.EmptyReceiptsCID, } err := cs.PutTipSetMetadata(ctx, genTsas) assert.NoError(t, err) diff --git a/pkg/chain/testing.go b/pkg/chain/testing.go index c66ebb4452..66569ad8ef 100644 --- a/pkg/chain/testing.go +++ b/pkg/chain/testing.go @@ -31,9 +31,9 @@ import ( "github.com/filecoin-project/venus/pkg/config" "github.com/filecoin-project/venus/pkg/crypto" "github.com/filecoin-project/venus/pkg/repo" - emptycid "github.com/filecoin-project/venus/pkg/testhelpers/empty_cid" - "github.com/filecoin-project/venus/pkg/types" + "github.com/filecoin-project/venus/pkg/testhelpers" "github.com/filecoin-project/venus/pkg/util" + types "github.com/filecoin-project/venus/venus-shared/chain" ) // Builder builds fake chains and acts as a provider and fetcher for the chain thus generated. @@ -89,7 +89,7 @@ func (f *Builder) FakeStateEvaluator() *FakeStateEvaluator { func (f *Builder) LoadTipSetMessage(ctx context.Context, ts *types.TipSet) ([]types.BlockMessagesInfo, error) { // gather message applied := make(map[address.Address]uint64) - selectMsg := func(m *types.UnsignedMessage) (bool, error) { + selectMsg := func(m *types.Message) (bool, error) { // The first match for a sender is guaranteed to have correct nonce -- the block isn't valid otherwise if _, ok := applied[m.From]; !ok { applied[m.From] = m.Nonce @@ -219,12 +219,12 @@ func NewBuilderWithDeps(t *testing.T, miner address.Address, sb StateBuilder, st tipStateCids: make(map[string]cid.Cid), } ctx := context.TODO() - _, err := b.mstore.StoreMessages(ctx, []*types.SignedMessage{}, []*types.UnsignedMessage{}) + _, err := b.mstore.StoreMessages(ctx, []*types.SignedMessage{}, []*types.Message{}) require.NoError(t, err) _, err = b.mstore.StoreReceipts(ctx, []types.MessageReceipt{}) require.NoError(t, err) // append genesis - nullState := types.CidFromString(t, "null") + nullState := testhelpers.CidFromString(t, "null") b.tipStateCids[types.NewTipSetKey().String()] = nullState // create a fixed genesis @@ -259,7 +259,7 @@ func NewBuilderWithDeps(t *testing.T, miner address.Address, sb StateBuilder, st func (f *Builder) AppendBlockOnBlocks(parents ...*types.BlockHeader) *types.BlockHeader { var tip *types.TipSet if len(parents) > 0 { - tip = types.RequireNewTipSet(f.t, parents...) + tip = testhelpers.RequireNewTipSet(f.t, parents...) } return f.AppendBlockOn(tip) } @@ -283,7 +283,7 @@ func (f *Builder) FlushHead(ctx context.Context) error { func (f *Builder) AppendManyBlocksOnBlocks(height int, parents ...*types.BlockHeader) *types.BlockHeader { var tip *types.TipSet if len(parents) > 0 { - tip = types.RequireNewTipSet(f.t, parents...) + tip = testhelpers.RequireNewTipSet(f.t, parents...) } return f.BuildManyOn(height, tip, nil).At(0) } @@ -302,7 +302,7 @@ func (f *Builder) AppendManyOn(height int, parent *types.TipSet) *types.TipSet { func (f *Builder) BuildOnBlock(parent *types.BlockHeader, build func(b *BlockBuilder)) *types.BlockHeader { var tip *types.TipSet if parent != nil { - tip = types.RequireNewTipSet(f.t, parent) + tip = testhelpers.RequireNewTipSet(f.t, parent) } return f.BuildOneOn(tip, build).At(0) } @@ -374,14 +374,14 @@ func (f *Builder) BuildOrphaTipset(parent *types.TipSet, width int, build func(b f.seq++ b := &types.BlockHeader{ - Ticket: ticket, + Ticket: &ticket, Miner: f.minerAddress, BeaconEntries: nil, ParentWeight: parentWeight, - Parents: parent.Key(), + Parents: parent.Key().Cids(), Height: height, - Messages: emptycid.EmptyTxMetaCID, - ParentMessageReceipts: emptycid.EmptyReceiptsCID, + Messages: testhelpers.EmptyTxMetaCID, + ParentMessageReceipts: testhelpers.EmptyReceiptsCID, BLSAggregate: &emptyBLSSig, // Omitted fields below // ParentStateRoot: stateRoot, @@ -422,7 +422,7 @@ func (f *Builder) BuildOrphaTipset(parent *types.TipSet, width int, build func(b blocks = append(blocks, b) } - return types.RequireNewTipSet(f.t, blocks...) + return testhelpers.RequireNewTipSet(f.t, blocks...) } // StateForKey loads (or computes) the state root for a tipset key. @@ -501,7 +501,7 @@ type BlockBuilder struct { // SetTicket sets the block's ticket. func (bb *BlockBuilder) SetTicket(raw []byte) { - bb.block.Ticket = types.Ticket{VRFProof: types.VRFPi(raw)} + bb.block.Ticket = &types.Ticket{VRFProof: raw} } // SetTimestamp sets the block's timestamp. @@ -521,7 +521,7 @@ func (bb *BlockBuilder) SetBlockSig(signature crypto.Signature) { } // AddMessages adds a message & receipt collection to the block. -func (bb *BlockBuilder) AddMessages(secpmsgs []*types.SignedMessage, blsMsgs []*types.UnsignedMessage) { +func (bb *BlockBuilder) AddMessages(secpmsgs []*types.SignedMessage, blsMsgs []*types.Message) { ctx := context.Background() meta, err := bb.messages.StoreMessages(ctx, secpmsgs, blsMsgs) @@ -562,9 +562,9 @@ func (FakeStateBuilder) ComputeState(prev cid.Cid, blockmsg []types.BlockMessage mCId := msg.Cid() inputs = append(inputs, mCId) receipts = append(receipts, types.MessageReceipt{ - ExitCode: 0, - ReturnValue: mCId.Bytes(), - GasUsed: 3, + ExitCode: 0, + Return: mCId.Bytes(), + GasUsed: 3, }) } } @@ -695,7 +695,7 @@ func (e *FakeStateEvaluator) RunStateTransition(ctx context.Context, ts *types.T } func (e *FakeStateEvaluator) ValidateFullBlock(ctx context.Context, blk *types.BlockHeader) error { - parent, err := e.ChainStore.GetTipSet(blk.Parents) + parent, err := e.ChainStore.GetTipSet(types.NewTipSetKey(blk.Parents...)) if err != nil { return err } @@ -772,7 +772,7 @@ func (f *Builder) GetTipSet(key types.TipSetKey) (*types.TipSet, error) { } blocks = append(blocks, &blk) } - return types.NewTipSet(blocks...) + return types.NewTipSet(blocks) } // FetchTipSets fetchs the tipset at `tsKey` from the fetchers blockStore backed by the Builder. @@ -853,7 +853,7 @@ func (f *Builder) LoadReceipts(ctx context.Context, c cid.Cid) ([]types.MessageR } // LoadTxMeta returns the tx meta wrapper tracked by the builder. -func (f *Builder) LoadTxMeta(ctx context.Context, metaCid cid.Cid) (types.TxMeta, error) { +func (f *Builder) LoadTxMeta(ctx context.Context, metaCid cid.Cid) (types.MessageRoot, error) { return f.mstore.LoadTxMeta(ctx, metaCid) } @@ -863,11 +863,11 @@ func (f *Builder) StoreReceipts(ctx context.Context, receipts []types.MessageRec } // StoreTxMeta stores a tx meta -func (f *Builder) StoreTxMeta(ctx context.Context, meta types.TxMeta) (cid.Cid, error) { +func (f *Builder) StoreTxMeta(ctx context.Context, meta types.MessageRoot) (cid.Cid, error) { return f.mstore.StoreTxMeta(ctx, meta) } -func (f *Builder) LoadUnsignedMessagesFromCids(blsCids []cid.Cid) ([]*types.UnsignedMessage, error) { +func (f *Builder) LoadUnsignedMessagesFromCids(blsCids []cid.Cid) ([]*types.Message, error) { return f.mstore.LoadUnsignedMessagesFromCids(blsCids) } @@ -876,7 +876,7 @@ func (f *Builder) LoadSignedMessagesFromCids(secpCids []cid.Cid) ([]*types.Signe } // LoadMessages returns the message collections tracked by the builder. -func (f *Builder) LoadMetaMessages(ctx context.Context, metaCid cid.Cid) ([]*types.SignedMessage, []*types.UnsignedMessage, error) { +func (f *Builder) LoadMetaMessages(ctx context.Context, metaCid cid.Cid) ([]*types.SignedMessage, []*types.Message, error) { return f.mstore.LoadMetaMessages(ctx, metaCid) } @@ -942,7 +942,7 @@ func (f *Builder) GeneratorGenesis() *types.TipSet { cur, err := types.DecodeBlock(bsBlk.RawData()) require.NoError(f.t, err) - ts, err := types.NewTipSet(cur) + ts, err := types.NewTipSet([]*types.BlockHeader{cur}) require.NoError(f.t, err) return ts diff --git a/pkg/chain/tip_index.go b/pkg/chain/tip_index.go index bb1a53e9f4..53a09e699a 100644 --- a/pkg/chain/tip_index.go +++ b/pkg/chain/tip_index.go @@ -5,11 +5,10 @@ import ( "sync" "github.com/filecoin-project/go-state-types/abi" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/ipfs/go-cid" "github.com/pkg/errors" "golang.org/x/xerrors" - - "github.com/filecoin-project/venus/pkg/types" ) var ( diff --git a/pkg/chain/traversal.go b/pkg/chain/traversal.go index 98fa613c09..34b886c505 100644 --- a/pkg/chain/traversal.go +++ b/pkg/chain/traversal.go @@ -3,9 +3,9 @@ package chain import ( "context" "errors" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/go-state-types/abi" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/ipfs/go-cid" ) @@ -70,7 +70,7 @@ func LoadTipSetBlocks(ctx context.Context, store BlockProvider, key types.TipSet } blocks = append(blocks, blk) } - return types.NewTipSet(blocks...) + return types.NewTipSet(blocks) } type tipsetFromBlockProvider struct { @@ -187,7 +187,7 @@ func FindLatestDRAND(ctx context.Context, start *types.TipSet, reader TipSetProv entries := ts.At(0).BeaconEntries if len(entries) > 0 { - return entries[len(entries)-1], nil + return &entries[len(entries)-1], nil } // No entries, simply move on to the next ancestor } diff --git a/pkg/chain/traversal_test.go b/pkg/chain/traversal_test.go index 43b010ead8..56f11fd6a0 100644 --- a/pkg/chain/traversal_test.go +++ b/pkg/chain/traversal_test.go @@ -4,7 +4,7 @@ import ( "context" "testing" - "github.com/filecoin-project/venus/pkg/types" + "github.com/filecoin-project/venus/pkg/testhelpers" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" @@ -13,6 +13,7 @@ import ( "github.com/filecoin-project/venus/pkg/chain" tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" + types "github.com/filecoin-project/venus/venus-shared/chain" ) func TestIterAncestors(t *testing.T) { @@ -29,9 +30,9 @@ func TestIterAncestors(t *testing.T) { b12 := store.AppendBlockOnBlocks(root) b21 := store.AppendBlockOnBlocks(b11, b12) - t0 := types.RequireNewTipSet(t, root) - t1 := types.RequireNewTipSet(t, b11, b12) - t2 := types.RequireNewTipSet(t, b21) + t0 := testhelpers.RequireNewTipSet(t, root) + t1 := testhelpers.RequireNewTipSet(t, b11, b12) + t2 := testhelpers.RequireNewTipSet(t, b21) it := chain.IterAncestors(ctx, store, t2) assert.False(t, it.Complete()) @@ -58,9 +59,9 @@ func TestIterAncestors(t *testing.T) { b12 := store.AppendBlockOnBlocks(root) b21 := store.AppendBlockOnBlocks(b11, b12) - types.RequireNewTipSet(t, root) - t1 := types.RequireNewTipSet(t, b11, b12) - t2 := types.RequireNewTipSet(t, b21) + testhelpers.RequireNewTipSet(t, root) + t1 := testhelpers.RequireNewTipSet(t, b11, b12) + t2 := testhelpers.RequireNewTipSet(t, b21) it := chain.IterAncestors(ctx, store, t2) assert.False(t, it.Complete()) diff --git a/pkg/chain/utils.go b/pkg/chain/utils.go index 5d502e0722..4d4b3d8034 100644 --- a/pkg/chain/utils.go +++ b/pkg/chain/utils.go @@ -5,8 +5,8 @@ import ( "runtime" "strings" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/util/blockstoreutil" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/rt" diff --git a/pkg/chain/waiter.go b/pkg/chain/waiter.go index 623e91dbc9..bdde237dab 100644 --- a/pkg/chain/waiter.go +++ b/pkg/chain/waiter.go @@ -7,13 +7,12 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/venus/pkg/constants" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/ipfs/go-cid" bstore "github.com/ipfs/go-ipfs-blockstore" cbor "github.com/ipfs/go-ipld-cbor" "github.com/pkg/errors" "golang.org/x/xerrors" - - "github.com/filecoin-project/venus/pkg/types" ) type MsgLookup struct { @@ -57,7 +56,7 @@ type ChainMessage struct { //nolint } // WaitPredicate is a function that identifies a message and returns true when found. -type WaitPredicate func(msg *types.UnsignedMessage, msgCid cid.Cid) bool +type WaitPredicate func(msg *types.Message, msgCid cid.Cid) bool // NewWaiter returns a new Waiter. func NewWaiter(chainStore waiterChainReader, messages MessageProvider, bs bstore.Blockstore, cst cbor.IpldStore) *Waiter { diff --git a/pkg/chain/waiter_test.go b/pkg/chain/waiter_test.go index a4be33bf9a..fd29b634e8 100644 --- a/pkg/chain/waiter_test.go +++ b/pkg/chain/waiter_test.go @@ -3,22 +3,24 @@ package chain import ( "context" "fmt" - "github.com/filecoin-project/venus/pkg/constants" "testing" "time" + "github.com/filecoin-project/venus/pkg/testhelpers" + + "github.com/filecoin-project/venus/pkg/constants" + "github.com/filecoin-project/go-address" _ "github.com/filecoin-project/venus/pkg/crypto/bls" _ "github.com/filecoin-project/venus/pkg/crypto/secp" tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" - "github.com/filecoin-project/venus/pkg/types" cbor "github.com/ipfs/go-ipld-cbor" "github.com/stretchr/testify/assert" ) -var mockSigner, _ = types.NewMockSignersAndKeyInfo(10) +var mockSigner, _ = testhelpers.NewMockSignersAndKeyInfo(10) -var newSignedMessage = types.NewSignedMessageForTestGetter(mockSigner) +var newSignedMessage = testhelpers.NewSignedMessageForTestGetter(mockSigner) func setupTest(t *testing.T) (cbor.IpldStore, *Store, *MessageStore, *Waiter) { builder := NewBuilder(t, address.Undef) diff --git a/pkg/chainsync/chainsync.go b/pkg/chainsync/chainsync.go index b7daa07686..90ae44eb0a 100644 --- a/pkg/chainsync/chainsync.go +++ b/pkg/chainsync/chainsync.go @@ -2,16 +2,17 @@ package chainsync import ( "context" + chain2 "github.com/filecoin-project/venus/app/submodule/chain" + "github.com/filecoin-project/venus/pkg/chainsync/exchange" "github.com/filecoin-project/venus/pkg/chainsync/types" "github.com/filecoin-project/venus/pkg/consensus" "github.com/filecoin-project/venus/pkg/statemanger" - types2 "github.com/filecoin-project/venus/pkg/types" + types2 "github.com/filecoin-project/venus/venus-shared/chain" blockstore "github.com/ipfs/go-ipfs-blockstore" "github.com/filecoin-project/venus/pkg/chainsync/dispatcher" - "github.com/filecoin-project/venus/pkg/chainsync/exchange" "github.com/filecoin-project/venus/pkg/chainsync/syncer" "github.com/filecoin-project/venus/pkg/clock" "github.com/filecoin-project/venus/pkg/fork" diff --git a/pkg/chainsync/dispatcher/dispatcher.go b/pkg/chainsync/dispatcher/dispatcher.go index 267f7dbdaa..4abc9d9bee 100644 --- a/pkg/chainsync/dispatcher/dispatcher.go +++ b/pkg/chainsync/dispatcher/dispatcher.go @@ -3,14 +3,15 @@ package dispatcher import ( "container/list" "context" - "github.com/filecoin-project/venus/pkg/chainsync/types" - types2 "github.com/filecoin-project/venus/pkg/types" - "github.com/streadway/handy/atomic" "runtime/debug" "sync" atmoic2 "sync/atomic" "time" + "github.com/filecoin-project/venus/pkg/chainsync/types" + types2 "github.com/filecoin-project/venus/venus-shared/chain" + "github.com/streadway/handy/atomic" + logging "github.com/ipfs/go-log/v2" ) diff --git a/pkg/chainsync/dispatcher/dispatcher_test.go b/pkg/chainsync/dispatcher/dispatcher_test.go index ae9a4ff8c9..ee0cd221e3 100644 --- a/pkg/chainsync/dispatcher/dispatcher_test.go +++ b/pkg/chainsync/dispatcher/dispatcher_test.go @@ -2,19 +2,24 @@ package dispatcher_test import ( "context" + "testing" + "time" + + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/venus/pkg/testhelpers" + fbig "github.com/filecoin-project/go-state-types/big" acrypto "github.com/filecoin-project/go-state-types/crypto" proof2 "github.com/filecoin-project/specs-actors/v2/actors/runtime/proof" syncTypes "github.com/filecoin-project/venus/pkg/chainsync/types" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "testing" - "time" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/venus/pkg/chainsync/dispatcher" tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" - "github.com/filecoin-project/venus/pkg/types" ) type mockSyncer struct { @@ -147,25 +152,25 @@ func requirePop(t *testing.T, q *syncTypes.TargetTracker) *syncTypes.Target { // an int. The tipset key is a faked cid from the string of that integer and // the height is that integer. func chainInfoWithHeightAndWeight(t *testing.T, h int, weight int64) *types.ChainInfo { - newAddress := types.NewForTestGetter() + newAddress := testhelpers.NewForTestGetter() posts := []proof2.PoStProof{{PoStProof: abi.RegisteredPoStProof_StackedDrgWinning32GiBV1, ProofBytes: []byte{0x07}}} blk := &types.BlockHeader{ Miner: newAddress(), - Ticket: types.Ticket{VRFProof: []byte{0x03, 0x01, 0x02}}, + Ticket: &types.Ticket{VRFProof: []byte{0x03, 0x01, 0x02}}, ElectionProof: &types.ElectionProof{VRFProof: []byte{0x0c, 0x0d}}, - BeaconEntries: []*types.BeaconEntry{ + BeaconEntries: []types.BeaconEntry{ { Round: 44, Data: []byte{0xc0}, }, }, Height: abi.ChainEpoch(h), - Messages: types.CidFromString(t, "someothercid"), - ParentMessageReceipts: types.CidFromString(t, "someothercid"), - Parents: types.NewTipSetKey(types.CidFromString(t, "someothercid")), + Messages: testhelpers.CidFromString(t, "someothercid"), + ParentMessageReceipts: testhelpers.CidFromString(t, "someothercid"), + Parents: []cid.Cid{testhelpers.CidFromString(t, "someothercid")}, ParentWeight: fbig.NewInt(weight), ForkSignaling: 2, - ParentStateRoot: types.CidFromString(t, "someothercid"), + ParentStateRoot: testhelpers.CidFromString(t, "someothercid"), Timestamp: 4, ParentBaseFee: abi.NewTokenAmount(20), WinPoStProof: posts, @@ -174,7 +179,7 @@ func chainInfoWithHeightAndWeight(t *testing.T, h int, weight int64) *types.Chai Data: []byte{0x4}, }, } - b, _ := types.NewTipSet(blk) + b, _ := types.NewTipSet([]*types.BlockHeader{blk}) return &types.ChainInfo{ Head: b, } diff --git a/pkg/chainsync/exchange/cbor_gen.go b/pkg/chainsync/exchange/cbor_gen.go new file mode 100644 index 0000000000..604aec8982 --- /dev/null +++ b/pkg/chainsync/exchange/cbor_gen.go @@ -0,0 +1,647 @@ +// Code generated by github.com/whyrusleeping/cbor-gen. DO NOT EDIT. + +package exchange + +import ( + "fmt" + "io" + "sort" + + chain "github.com/filecoin-project/venus/venus-shared/chain" + cid "github.com/ipfs/go-cid" + cbg "github.com/whyrusleeping/cbor-gen" + xerrors "golang.org/x/xerrors" +) + +var _ = xerrors.Errorf +var _ = cid.Undef +var _ = sort.Sort + +var lengthBufRequest = []byte{131} + +func (t *Request) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + if _, err := w.Write(lengthBufRequest); err != nil { + return err + } + + scratch := make([]byte, 9) + + // t.Head ([]cid.Cid) (slice) + if len(t.Head) > cbg.MaxLength { + return xerrors.Errorf("Slice value in field t.Head was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Head))); err != nil { + return err + } + for _, v := range t.Head { + if err := cbg.WriteCidBuf(scratch, w, v); err != nil { + return xerrors.Errorf("failed writing cid field t.Head: %w", err) + } + } + + // t.Length (uint64) (uint64) + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Length)); err != nil { + return err + } + + // t.Options (uint64) (uint64) + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Options)); err != nil { + return err + } + + return nil +} + +func (t *Request) UnmarshalCBOR(r io.Reader) error { + *t = Request{} + + br := cbg.GetPeeker(r) + scratch := make([]byte, 8) + + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + if maj != cbg.MajArray { + return fmt.Errorf("cbor input should be of type array") + } + + if extra != 3 { + return fmt.Errorf("cbor input had wrong number of fields") + } + + // t.Head ([]cid.Cid) (slice) + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + + if extra > cbg.MaxLength { + return fmt.Errorf("t.Head: array too large (%d)", extra) + } + + if maj != cbg.MajArray { + return fmt.Errorf("expected cbor array") + } + + if extra > 0 { + t.Head = make([]cid.Cid, extra) + } + + for i := 0; i < int(extra); i++ { + + c, err := cbg.ReadCid(br) + if err != nil { + return xerrors.Errorf("reading cid field t.Head failed: %w", err) + } + t.Head[i] = c + } + + // t.Length (uint64) (uint64) + + { + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + if maj != cbg.MajUnsignedInt { + return fmt.Errorf("wrong type for uint64 field") + } + t.Length = uint64(extra) + + } + // t.Options (uint64) (uint64) + + { + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + if maj != cbg.MajUnsignedInt { + return fmt.Errorf("wrong type for uint64 field") + } + t.Options = uint64(extra) + + } + return nil +} + +var lengthBufResponse = []byte{131} + +func (t *Response) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + if _, err := w.Write(lengthBufResponse); err != nil { + return err + } + + scratch := make([]byte, 9) + + // t.Status (exchange.status) (uint64) + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Status)); err != nil { + return err + } + + // t.ErrorMessage (string) (string) + if len(t.ErrorMessage) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.ErrorMessage was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.ErrorMessage))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.ErrorMessage)); err != nil { + return err + } + + // t.Chain ([]*exchange.BSTipSet) (slice) + if len(t.Chain) > cbg.MaxLength { + return xerrors.Errorf("Slice value in field t.Chain was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Chain))); err != nil { + return err + } + for _, v := range t.Chain { + if err := v.MarshalCBOR(w); err != nil { + return err + } + } + return nil +} + +func (t *Response) UnmarshalCBOR(r io.Reader) error { + *t = Response{} + + br := cbg.GetPeeker(r) + scratch := make([]byte, 8) + + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + if maj != cbg.MajArray { + return fmt.Errorf("cbor input should be of type array") + } + + if extra != 3 { + return fmt.Errorf("cbor input had wrong number of fields") + } + + // t.Status (exchange.status) (uint64) + + { + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + if maj != cbg.MajUnsignedInt { + return fmt.Errorf("wrong type for uint64 field") + } + t.Status = status(extra) + + } + // t.ErrorMessage (string) (string) + + { + sval, err := cbg.ReadStringBuf(br, scratch) + if err != nil { + return err + } + + t.ErrorMessage = string(sval) + } + // t.Chain ([]*exchange.BSTipSet) (slice) + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + + if extra > cbg.MaxLength { + return fmt.Errorf("t.Chain: array too large (%d)", extra) + } + + if maj != cbg.MajArray { + return fmt.Errorf("expected cbor array") + } + + if extra > 0 { + t.Chain = make([]*BSTipSet, extra) + } + + for i := 0; i < int(extra); i++ { + + var v BSTipSet + if err := v.UnmarshalCBOR(br); err != nil { + return err + } + + t.Chain[i] = &v + } + + return nil +} + +var lengthBufCompactedMessages = []byte{132} + +func (t *CompactedMessages) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + if _, err := w.Write(lengthBufCompactedMessages); err != nil { + return err + } + + scratch := make([]byte, 9) + + // t.Bls ([]*chain.Message) (slice) + if len(t.Bls) > cbg.MaxLength { + return xerrors.Errorf("Slice value in field t.Bls was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Bls))); err != nil { + return err + } + for _, v := range t.Bls { + if err := v.MarshalCBOR(w); err != nil { + return err + } + } + + // t.BlsIncludes ([][]uint64) (slice) + if len(t.BlsIncludes) > cbg.MaxLength { + return xerrors.Errorf("Slice value in field t.BlsIncludes was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.BlsIncludes))); err != nil { + return err + } + for _, v := range t.BlsIncludes { + if len(v) > cbg.MaxLength { + return xerrors.Errorf("Slice value in field v was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(v))); err != nil { + return err + } + for _, v := range v { + if err := cbg.CborWriteHeader(w, cbg.MajUnsignedInt, uint64(v)); err != nil { + return err + } + } + } + + // t.Secpk ([]*chain.SignedMessage) (slice) + if len(t.Secpk) > cbg.MaxLength { + return xerrors.Errorf("Slice value in field t.Secpk was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Secpk))); err != nil { + return err + } + for _, v := range t.Secpk { + if err := v.MarshalCBOR(w); err != nil { + return err + } + } + + // t.SecpkIncludes ([][]uint64) (slice) + if len(t.SecpkIncludes) > cbg.MaxLength { + return xerrors.Errorf("Slice value in field t.SecpkIncludes was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.SecpkIncludes))); err != nil { + return err + } + for _, v := range t.SecpkIncludes { + if len(v) > cbg.MaxLength { + return xerrors.Errorf("Slice value in field v was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(v))); err != nil { + return err + } + for _, v := range v { + if err := cbg.CborWriteHeader(w, cbg.MajUnsignedInt, uint64(v)); err != nil { + return err + } + } + } + return nil +} + +func (t *CompactedMessages) UnmarshalCBOR(r io.Reader) error { + *t = CompactedMessages{} + + br := cbg.GetPeeker(r) + scratch := make([]byte, 8) + + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + if maj != cbg.MajArray { + return fmt.Errorf("cbor input should be of type array") + } + + if extra != 4 { + return fmt.Errorf("cbor input had wrong number of fields") + } + + // t.Bls ([]*chain.Message) (slice) + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + + if extra > cbg.MaxLength { + return fmt.Errorf("t.Bls: array too large (%d)", extra) + } + + if maj != cbg.MajArray { + return fmt.Errorf("expected cbor array") + } + + if extra > 0 { + t.Bls = make([]*chain.Message, extra) + } + + for i := 0; i < int(extra); i++ { + + var v chain.Message + if err := v.UnmarshalCBOR(br); err != nil { + return err + } + + t.Bls[i] = &v + } + + // t.BlsIncludes ([][]uint64) (slice) + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + + if extra > cbg.MaxLength { + return fmt.Errorf("t.BlsIncludes: array too large (%d)", extra) + } + + if maj != cbg.MajArray { + return fmt.Errorf("expected cbor array") + } + + if extra > 0 { + t.BlsIncludes = make([][]uint64, extra) + } + + for i := 0; i < int(extra); i++ { + { + var maj byte + var extra uint64 + var err error + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + + if extra > cbg.MaxLength { + return fmt.Errorf("t.BlsIncludes[i]: array too large (%d)", extra) + } + + if maj != cbg.MajArray { + return fmt.Errorf("expected cbor array") + } + + if extra > 0 { + t.BlsIncludes[i] = make([]uint64, extra) + } + + for j := 0; j < int(extra); j++ { + + maj, val, err := cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return xerrors.Errorf("failed to read uint64 for t.BlsIncludes[i] slice: %w", err) + } + + if maj != cbg.MajUnsignedInt { + return xerrors.Errorf("value read for array t.BlsIncludes[i] was not a uint, instead got %d", maj) + } + + t.BlsIncludes[i][j] = uint64(val) + } + + } + } + + // t.Secpk ([]*chain.SignedMessage) (slice) + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + + if extra > cbg.MaxLength { + return fmt.Errorf("t.Secpk: array too large (%d)", extra) + } + + if maj != cbg.MajArray { + return fmt.Errorf("expected cbor array") + } + + if extra > 0 { + t.Secpk = make([]*chain.SignedMessage, extra) + } + + for i := 0; i < int(extra); i++ { + + var v chain.SignedMessage + if err := v.UnmarshalCBOR(br); err != nil { + return err + } + + t.Secpk[i] = &v + } + + // t.SecpkIncludes ([][]uint64) (slice) + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + + if extra > cbg.MaxLength { + return fmt.Errorf("t.SecpkIncludes: array too large (%d)", extra) + } + + if maj != cbg.MajArray { + return fmt.Errorf("expected cbor array") + } + + if extra > 0 { + t.SecpkIncludes = make([][]uint64, extra) + } + + for i := 0; i < int(extra); i++ { + { + var maj byte + var extra uint64 + var err error + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + + if extra > cbg.MaxLength { + return fmt.Errorf("t.SecpkIncludes[i]: array too large (%d)", extra) + } + + if maj != cbg.MajArray { + return fmt.Errorf("expected cbor array") + } + + if extra > 0 { + t.SecpkIncludes[i] = make([]uint64, extra) + } + + for j := 0; j < int(extra); j++ { + + maj, val, err := cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return xerrors.Errorf("failed to read uint64 for t.SecpkIncludes[i] slice: %w", err) + } + + if maj != cbg.MajUnsignedInt { + return xerrors.Errorf("value read for array t.SecpkIncludes[i] was not a uint, instead got %d", maj) + } + + t.SecpkIncludes[i][j] = uint64(val) + } + + } + } + + return nil +} + +var lengthBufBSTipSet = []byte{130} + +func (t *BSTipSet) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + if _, err := w.Write(lengthBufBSTipSet); err != nil { + return err + } + + scratch := make([]byte, 9) + + // t.Blocks ([]*chain.BlockHeader) (slice) + if len(t.Blocks) > cbg.MaxLength { + return xerrors.Errorf("Slice value in field t.Blocks was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Blocks))); err != nil { + return err + } + for _, v := range t.Blocks { + if err := v.MarshalCBOR(w); err != nil { + return err + } + } + + // t.Messages (exchange.CompactedMessages) (struct) + if err := t.Messages.MarshalCBOR(w); err != nil { + return err + } + return nil +} + +func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error { + *t = BSTipSet{} + + br := cbg.GetPeeker(r) + scratch := make([]byte, 8) + + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + if maj != cbg.MajArray { + return fmt.Errorf("cbor input should be of type array") + } + + if extra != 2 { + return fmt.Errorf("cbor input had wrong number of fields") + } + + // t.Blocks ([]*chain.BlockHeader) (slice) + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + + if extra > cbg.MaxLength { + return fmt.Errorf("t.Blocks: array too large (%d)", extra) + } + + if maj != cbg.MajArray { + return fmt.Errorf("expected cbor array") + } + + if extra > 0 { + t.Blocks = make([]*chain.BlockHeader, extra) + } + + for i := 0; i < int(extra); i++ { + + var v chain.BlockHeader + if err := v.UnmarshalCBOR(br); err != nil { + return err + } + + t.Blocks[i] = &v + } + + // t.Messages (exchange.CompactedMessages) (struct) + + { + + b, err := br.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := br.UnreadByte(); err != nil { + return err + } + t.Messages = new(CompactedMessages) + if err := t.Messages.UnmarshalCBOR(br); err != nil { + return xerrors.Errorf("unmarshaling t.Messages pointer: %w", err) + } + } + + } + return nil +} diff --git a/pkg/chainsync/exchange/client.go b/pkg/chainsync/exchange/client.go index afa98ede45..aa83a31035 100644 --- a/pkg/chainsync/exchange/client.go +++ b/pkg/chainsync/exchange/client.go @@ -10,7 +10,6 @@ import ( "time" cborutil "github.com/filecoin-project/go-cbor-util" - "github.com/filecoin-project/venus/pkg/types" logging "github.com/ipfs/go-log" "github.com/libp2p/go-libp2p-core/host" @@ -21,6 +20,7 @@ import ( "golang.org/x/xerrors" "github.com/filecoin-project/venus/pkg/net" + types "github.com/filecoin-project/venus/venus-shared/chain" ) var exchangeClientLogger = logging.Logger("exchange.client") @@ -191,7 +191,7 @@ func (c *client) processResponse(req *Request, res *Response, tipsets []*types.T } } - validRes.tipsets[i], err = types.NewTipSet(res.Chain[i].Blocks...) + validRes.tipsets[i], err = types.NewTipSet(res.Chain[i].Blocks) if err != nil { return nil, xerrors.Errorf("invalid tipset blocks at height (head - %d): %w", i, err) } diff --git a/pkg/chainsync/exchange/interfaces.go b/pkg/chainsync/exchange/interfaces.go index 5fb8dec405..67d2919ec1 100644 --- a/pkg/chainsync/exchange/interfaces.go +++ b/pkg/chainsync/exchange/interfaces.go @@ -2,9 +2,10 @@ package exchange import ( "context" - "github.com/filecoin-project/venus/pkg/types" "github.com/libp2p/go-libp2p-core/peer" + + types "github.com/filecoin-project/venus/venus-shared/chain" ) // Server is the responder side of the ChainExchange protocol. It accepts diff --git a/pkg/chainsync/exchange/protocol.go b/pkg/chainsync/exchange/protocol.go index b9622a0e1b..357b599f66 100644 --- a/pkg/chainsync/exchange/protocol.go +++ b/pkg/chainsync/exchange/protocol.go @@ -5,8 +5,8 @@ import ( "github.com/ipfs/go-cid" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/venus-shared/actors/policy" + types "github.com/filecoin-project/venus/venus-shared/chain" logging "github.com/ipfs/go-log" "golang.org/x/xerrors" ) @@ -155,7 +155,7 @@ type BSTipSet struct { // FIXME: The logic to decompress this structure should belong // to itself, not to the consumer. type CompactedMessages struct { - Bls []*types.UnsignedMessage + Bls []*types.Message BlsIncludes [][]uint64 Secpk []*types.SignedMessage diff --git a/pkg/chainsync/exchange/server.go b/pkg/chainsync/exchange/server.go index 1a83a7778d..85e82119fa 100644 --- a/pkg/chainsync/exchange/server.go +++ b/pkg/chainsync/exchange/server.go @@ -4,9 +4,10 @@ import ( "bufio" "context" "fmt" + "time" + cborutil "github.com/filecoin-project/go-cbor-util" logging "github.com/ipfs/go-log" - "time" "go.opencensus.io/trace" "golang.org/x/xerrors" @@ -15,7 +16,7 @@ import ( "github.com/libp2p/go-libp2p-core/host" inet "github.com/libp2p/go-libp2p-core/network" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" ) var exchangeServerLog = logging.Logger("exchange.server") @@ -27,7 +28,7 @@ type chainReader interface { type messageStore interface { ReadMsgMetaCids(ctx context.Context, mmc cid.Cid) ([]cid.Cid, []cid.Cid, error) - LoadUnsignedMessagesFromCids(cids []cid.Cid) ([]*types.UnsignedMessage, error) + LoadUnsignedMessagesFromCids(cids []cid.Cid) ([]*types.Message, error) LoadSignedMessagesFromCids(cids []cid.Cid) ([]*types.SignedMessage, error) } @@ -217,7 +218,7 @@ func collectChainSegment(cr chainReader, mr messageStore, req *validatedRequest) } } -func GatherMessages(cr chainReader, mr messageStore, ts *types.TipSet) ([]*types.UnsignedMessage, [][]uint64, []*types.SignedMessage, [][]uint64, error) { +func GatherMessages(cr chainReader, mr messageStore, ts *types.TipSet) ([]*types.Message, [][]uint64, []*types.SignedMessage, [][]uint64, error) { blsmsgmap := make(map[cid.Cid]uint64) secpkmsgmap := make(map[cid.Cid]uint64) var secpkincl, blsincl [][]uint64 diff --git a/pkg/chainsync/slashfilter/mysqldb.go b/pkg/chainsync/slashfilter/mysqldb.go index 6b6fb9bb70..7735011371 100644 --- a/pkg/chainsync/slashfilter/mysqldb.go +++ b/pkg/chainsync/slashfilter/mysqldb.go @@ -4,7 +4,6 @@ import ( "time" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/venus/pkg/types" "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log/v2" @@ -13,6 +12,7 @@ import ( "gorm.io/gorm" "github.com/filecoin-project/venus/pkg/config" + types "github.com/filecoin-project/venus/venus-shared/chain" ) var log = logging.Logger("mysql") @@ -88,7 +88,7 @@ func (f *MysqlSlashFilter) checkSameHeightFault(bh *types.BlockHeader) error { //checkSameParentFault check whether the miner mined block on the same parent func (f *MysqlSlashFilter) checkSameParentFault(bh *types.BlockHeader) error { var bk MinedBlock - err := f._db.Model(&MinedBlock{}).Take(&bk, "miner=? and parent_key=?", bh.Miner.String(), bh.Parents.String()).Error + err := f._db.Model(&MinedBlock{}).Take(&bk, "miner=? and parent_key=?", bh.Miner.String(), types.NewTipSetKey(bh.Parents...).String()).Error if err == gorm.ErrRecordNotFound { return nil } @@ -130,7 +130,7 @@ func (f *MysqlSlashFilter) MinedBlock(bh *types.BlockHeader, parentEpoch abi.Cha } var found bool - for _, c := range bh.Parents.Cids() { + for _, c := range bh.Parents { if c.Equals(parent) { found = true } @@ -148,7 +148,7 @@ func (f *MysqlSlashFilter) MinedBlock(bh *types.BlockHeader, parentEpoch abi.Cha return f._db.Save(&MinedBlock{ ParentEpoch: int64(parentEpoch), - ParentKey: bh.Parents.String(), + ParentKey: types.NewTipSetKey(bh.Parents...).String(), Epoch: int64(bh.Height), Miner: bh.Miner.String(), Cid: bh.Cid().String(), diff --git a/pkg/chainsync/slashfilter/slashfilter.go b/pkg/chainsync/slashfilter/slashfilter.go index feb063452e..9b7b52a1ff 100644 --- a/pkg/chainsync/slashfilter/slashfilter.go +++ b/pkg/chainsync/slashfilter/slashfilter.go @@ -2,7 +2,6 @@ package slashfilter import ( "fmt" - "github.com/filecoin-project/venus/pkg/types" "golang.org/x/xerrors" @@ -11,6 +10,7 @@ import ( "github.com/ipfs/go-datastore/namespace" "github.com/filecoin-project/go-state-types/abi" + types "github.com/filecoin-project/venus/venus-shared/chain" ) //ISlashFilter used to detect whether the miner mined a invalidated block , support local db and mysql storage @@ -42,7 +42,7 @@ func (f *LocalSlashFilter) MinedBlock(bh *types.BlockHeader, parentEpoch abi.Cha } } - parentsKey := ds.NewKey(fmt.Sprintf("/%s/%s", bh.Miner, bh.Parents.String())) + parentsKey := ds.NewKey(fmt.Sprintf("/%s/%s", bh.Miner, types.NewTipSetKey(bh.Parents...).String())) { // time-offset mining faults (2 blocks with the same parents) if err := checkFault(f.byParents, parentsKey, bh, "time-offset mining faults"); err != nil { @@ -73,7 +73,7 @@ func (f *LocalSlashFilter) MinedBlock(bh *types.BlockHeader, parentEpoch abi.Cha } var found bool - for _, c := range bh.Parents.Cids() { + for _, c := range bh.Parents { if c.Equals(parent) { found = true } diff --git a/pkg/chainsync/syncer/syncer.go b/pkg/chainsync/syncer/syncer.go index 7cb002095b..888b0cb716 100644 --- a/pkg/chainsync/syncer/syncer.go +++ b/pkg/chainsync/syncer/syncer.go @@ -24,9 +24,9 @@ import ( "github.com/filecoin-project/venus/pkg/fork" "github.com/filecoin-project/venus/pkg/metrics" "github.com/filecoin-project/venus/pkg/metrics/tracing" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/util/blockstoreutil" "github.com/filecoin-project/venus/venus-shared/actors/policy" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/ipfs/go-cid" blockstore "github.com/ipfs/go-ipfs-blockstore" logging "github.com/ipfs/go-log/v2" @@ -98,7 +98,7 @@ type ChainReaderWriter interface { //messageStore used to save and load message from db type messageStore interface { LoadTipSetMessage(ctx context.Context, ts *types.TipSet) ([]types.BlockMessagesInfo, error) - LoadMetaMessages(context.Context, cid.Cid) ([]*types.SignedMessage, []*types.UnsignedMessage, error) + LoadMetaMessages(context.Context, cid.Cid) ([]*types.SignedMessage, []*types.Message, error) LoadReceipts(context.Context, cid.Cid) ([]types.MessageReceipt, error) StoreReceipts(context.Context, []types.MessageReceipt) (cid.Cid, error) } @@ -701,7 +701,7 @@ func (syncer *Syncer) exceedsForkLength(synced, external *types.TipSet) (bool, e // either validate it here, or ensure that its validated elsewhere (maybe make // sure the blocksync code checks it?) // maybe this code should actually live in blocksync?? -func zipTipSetAndMessages(bs blockstore.Blockstore, ts *types.TipSet, allbmsgs []*types.UnsignedMessage, allsmsgs []*types.SignedMessage, bmi, smi [][]uint64) (*types.FullTipSet, error) { +func zipTipSetAndMessages(bs blockstore.Blockstore, ts *types.TipSet, allbmsgs []*types.Message, allsmsgs []*types.SignedMessage, bmi, smi [][]uint64) (*types.FullTipSet, error) { if len(ts.Blocks()) != len(smi) || len(ts.Blocks()) != len(bmi) { return nil, fmt.Errorf("msgincl length didnt match tipset size") } @@ -720,7 +720,7 @@ func zipTipSetAndMessages(bs blockstore.Blockstore, ts *types.TipSet, allbmsgs [ smsgCids = append(smsgCids, mCid) } - var bmsgs []*types.UnsignedMessage + var bmsgs []*types.Message var bmsgCids []cid.Cid for _, m := range bmi[bi] { bmsgs = append(bmsgs, allbmsgs[m]) diff --git a/pkg/chainsync/syncer/syncer_integration_test.go b/pkg/chainsync/syncer/syncer_integration_test.go index 09c08e0386..4c688328f1 100644 --- a/pkg/chainsync/syncer/syncer_integration_test.go +++ b/pkg/chainsync/syncer/syncer_integration_test.go @@ -2,12 +2,13 @@ package syncer_test import ( "context" - "github.com/filecoin-project/venus/pkg/statemanger" "testing" "time" + "github.com/filecoin-project/venus/pkg/statemanger" + "github.com/filecoin-project/venus/pkg/chainsync/types" - types2 "github.com/filecoin-project/venus/pkg/types" + types2 "github.com/filecoin-project/venus/venus-shared/chain" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/pkg/chainsync/syncer/syncer_test.go b/pkg/chainsync/syncer/syncer_test.go index 34940086ef..ded1dbc988 100644 --- a/pkg/chainsync/syncer/syncer_test.go +++ b/pkg/chainsync/syncer/syncer_test.go @@ -5,22 +5,22 @@ import ( "testing" "time" - "github.com/filecoin-project/venus/pkg/statemanger" + "github.com/filecoin-project/venus/pkg/testhelpers" - syncTypes "github.com/filecoin-project/venus/pkg/chainsync/types" - emptycid "github.com/filecoin-project/venus/pkg/testhelpers/empty_cid" + "github.com/filecoin-project/venus/pkg/statemanger" "github.com/filecoin-project/go-address" "github.com/filecoin-project/venus/pkg/chain" "github.com/filecoin-project/venus/pkg/chainsync/syncer" + syncTypes "github.com/filecoin-project/venus/pkg/chainsync/types" "github.com/filecoin-project/venus/pkg/clock" _ "github.com/filecoin-project/venus/pkg/crypto/bls" _ "github.com/filecoin-project/venus/pkg/crypto/secp" "github.com/filecoin-project/venus/pkg/fork" tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/util/test" "github.com/filecoin-project/venus/venus-shared/actors/policy" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/ipfs/go-cid" "github.com/pkg/errors" "github.com/stretchr/testify/assert" @@ -375,7 +375,7 @@ func TestSubsetParent(t *testing.T) { // Sync one tipset with a parent equal to a subset of an existing // tipset in the bsstore: {B1, B2} -> {C1, C2} - tipB1B2 := types.RequireNewTipSet(t, tipB1B2B3.At(0), tipB1B2B3.At(1)) + tipB1B2 := testhelpers.RequireNewTipSet(t, tipB1B2B3.At(0), tipB1B2B3.At(1)) tipC1C2 := builder.AppendOn(tipB1B2, 2) target2 := &syncTypes.Target{ @@ -390,7 +390,7 @@ func TestSubsetParent(t *testing.T) { // Sync another tipset with a parent equal to a subset of the tipset // just synced: C1 -> D1 - tipC1 := types.RequireNewTipSet(t, tipC1C2.At(0)) + tipC1 := testhelpers.RequireNewTipSet(t, tipC1C2.At(0)) tipD1OnC1 := builder.AppendOn(tipC1, 1) target3 := &syncTypes.Target{ @@ -463,9 +463,9 @@ type poisonValidator struct { func (pv *poisonValidator) RunStateTransition(ctx context.Context, ts *types.TipSet) (cid.Cid, cid.Cid, error) { stamp := ts.At(0).Timestamp if pv.fullFailureTS == stamp { - return emptycid.EmptyTxMetaCID, emptycid.EmptyTxMetaCID, errors.New("run state transition fails on poison timestamp") + return testhelpers.EmptyTxMetaCID, testhelpers.EmptyTxMetaCID, errors.New("run state transition fails on poison timestamp") } - return emptycid.EmptyTxMetaCID, emptycid.EmptyTxMetaCID, nil + return testhelpers.EmptyTxMetaCID, testhelpers.EmptyTxMetaCID, nil } func (pv *poisonValidator) ValidateFullBlock(ctx context.Context, blk *types.BlockHeader) error { @@ -503,8 +503,8 @@ func TestSemanticallyBadTipSetFails(t *testing.T) { genesis := builder.Store().GetHead() // Build a chain with messages that will fail semantic header validation - kis := types.MustGenerateKeyInfo(1, 42) - mm := types.NewMessageMaker(t, kis) + kis := testhelpers.MustGenerateKeyInfo(1, 42) + mm := testhelpers.NewMessageMaker(t, kis) alice := mm.Addresses()[0] m1 := mm.NewSignedMessage(alice, 0) m2 := mm.NewSignedMessage(alice, 1) @@ -513,7 +513,7 @@ func TestSemanticallyBadTipSetFails(t *testing.T) { link1 := builder.BuildOneOn(genesis, func(bb *chain.BlockBuilder) { bb.AddMessages( []*types.SignedMessage{m1, m2, m3}, - []*types.UnsignedMessage{}, + []*types.Message{}, ) bb.SetTimestamp(98) // poison header val }) @@ -540,11 +540,11 @@ func TestStoresMessageReceipts(t *testing.T) { builder, syncer := setup(ctx, t) genesis := builder.Store().GetHead() - keys := types.MustGenerateKeyInfo(1, 42) - mm := types.NewMessageMaker(t, keys) + keys := testhelpers.MustGenerateKeyInfo(1, 42) + mm := testhelpers.NewMessageMaker(t, keys) alice := mm.Addresses()[0] t1 := builder.Build(genesis, 4, func(b *chain.BlockBuilder, i int) { - b.AddMessages([]*types.SignedMessage{}, []*types.UnsignedMessage{mm.NewUnsignedMessage(alice, uint64(i))}) + b.AddMessages([]*types.SignedMessage{}, []*types.Message{mm.NewUnsignedMessage(alice, uint64(i))}) }) target1 := &syncTypes.Target{ diff --git a/pkg/chainsync/types/bad_tipset_cache.go b/pkg/chainsync/types/bad_tipset_cache.go index 7689c2a3e1..a77771f0d3 100644 --- a/pkg/chainsync/types/bad_tipset_cache.go +++ b/pkg/chainsync/types/bad_tipset_cache.go @@ -1,8 +1,9 @@ package types import ( - "github.com/filecoin-project/venus/pkg/types" "sync" + + types "github.com/filecoin-project/venus/venus-shared/chain" ) // BadTipSetCache keeps track of bad tipsets that the syncer should not try to diff --git a/pkg/chainsync/types/target_tracker.go b/pkg/chainsync/types/target_tracker.go index e26d5458cf..6ad61e467e 100644 --- a/pkg/chainsync/types/target_tracker.go +++ b/pkg/chainsync/types/target_tracker.go @@ -8,9 +8,10 @@ import ( "time" fbig "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/venus/pkg/types" "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log/v2" + + types "github.com/filecoin-project/venus/venus-shared/chain" ) var log = logging.Logger("chainsync.target") @@ -282,7 +283,7 @@ func (tq *TargetTracker) widen(t *Target) (*Target, bool) { blks = append(blks, blk) } - newHead, err := types.NewTipSet(blks...) + newHead, err := types.NewTipSet(blks) if err != nil { return nil, false } diff --git a/pkg/config/config.go b/pkg/config/config.go index b6443baef1..38ac57b4ae 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -17,7 +17,7 @@ import ( "github.com/pkg/errors" "github.com/filecoin-project/venus/pkg/constants" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" ) const ( diff --git a/pkg/consensus/block_validator.go b/pkg/consensus/block_validator.go index 4b85ee0e7a..71731d979a 100644 --- a/pkg/consensus/block_validator.go +++ b/pkg/consensus/block_validator.go @@ -30,14 +30,13 @@ import ( "github.com/filecoin-project/venus/pkg/fork" appstate "github.com/filecoin-project/venus/pkg/state" "github.com/filecoin-project/venus/pkg/state/tree" - "github.com/filecoin-project/venus/pkg/types" bstore "github.com/filecoin-project/venus/pkg/util/blockstoreutil" "github.com/filecoin-project/venus/pkg/vm/gas" "github.com/filecoin-project/venus/venus-shared/actors/adt" "github.com/filecoin-project/venus/venus-shared/actors/builtin" "github.com/filecoin-project/venus/venus-shared/actors/builtin/miner" "github.com/filecoin-project/venus/venus-shared/actors/builtin/power" - types2 "github.com/filecoin-project/venus/venus-shared/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/hashicorp/go-multierror" lru "github.com/hashicorp/golang-lru" "github.com/ipfs/go-cid" @@ -141,7 +140,7 @@ func (bv *BlockValidator) ValidateFullBlock(ctx context.Context, blk *types.Bloc } func (bv *BlockValidator) validateBlock(ctx context.Context, blk *types.BlockHeader) error { - parent, err := bv.chainState.GetTipSet(blk.Parents) + parent, err := bv.chainState.GetTipSet(types.NewTipSetKey(blk.Parents...)) if err != nil { return xerrors.Errorf("load parent tipset failed %w", err) } @@ -220,7 +219,11 @@ func (bv *BlockValidator) validateBlock(ctx context.Context, blk *types.BlockHea blockSigCheck := async.Err(func() error { // Validate block signature - return crypto.Verify(blk.BlockSig, workerAddr, blk.SignatureData()) + data, err := blk.SignatureData() + if err != nil { + return err + } + return crypto.Verify(blk.BlockSig, workerAddr, data) }) beaconValuesCheck := async.Err(func() error { @@ -239,7 +242,7 @@ func (bv *BlockValidator) validateBlock(ctx context.Context, blk *types.BlockHea sampleEpoch := blk.Height - constants.TicketRandomnessLookback bSmokeHeight := blk.Height > bv.config.ForkUpgradeParam.UpgradeSmokeHeight - if err := bv.tv.IsValidTicket(ctx, blk.Parents, beaconBase, bSmokeHeight, sampleEpoch, blk.Miner, workerAddr, blk.Ticket); err != nil { + if err := bv.tv.IsValidTicket(ctx, types.NewTipSetKey(blk.Parents...), beaconBase, bSmokeHeight, sampleEpoch, blk.Miner, workerAddr, *blk.Ticket); err != nil { return xerrors.Errorf("invalid ticket: %s in block %s %w", blk.Ticket.String(), blk.Cid(), err) } return nil @@ -414,9 +417,9 @@ func (bv *BlockValidator) validateMsgMeta(ctx context.Context, msg *types.BlockM return err } - mrcid, err := store.Put(store.Context(), &types.TxMeta{ - BLSRoot: bmroot, - SecpRoot: smroot, + mrcid, err := store.Put(store.Context(), &types.MessageRoot{ + BlsRoot: bmroot, + SecpkRoot: smroot, }) if err != nil { @@ -482,7 +485,7 @@ func (bv *BlockValidator) minerIsValid(ctx context.Context, maddr address.Addres return xerrors.New("power actor not found") } - ps, err := power.Load(adt.WrapStore(ctx, vms), (*types2.Actor)(pact)) + ps, err := power.Load(adt.WrapStore(ctx, vms), pact) if err != nil { return err } @@ -508,10 +511,10 @@ func (bv *BlockValidator) ValidateBlockBeacon(blk *types.BlockHeader, parentEpoc func (bv *BlockValidator) beaconBaseEntry(ctx context.Context, blk *types.BlockHeader) (*types.BeaconEntry, error) { if len(blk.BeaconEntries) > 0 { - return blk.BeaconEntries[len(blk.BeaconEntries)-1], nil + return &blk.BeaconEntries[len(blk.BeaconEntries)-1], nil } - parent, err := bv.chainState.GetTipSet(blk.Parents) + parent, err := bv.chainState.GetTipSet(types.NewTipSetKey(blk.Parents...)) if err != nil { return nil, err } @@ -536,7 +539,7 @@ func (bv *BlockValidator) ValidateBlockWinner(ctx context.Context, waddr address rBeacon := prevEntry if len(blk.BeaconEntries) != 0 { - rBeacon = blk.BeaconEntries[len(blk.BeaconEntries)-1] + rBeacon = &blk.BeaconEntries[len(blk.BeaconEntries)-1] } buf := new(bytes.Buffer) if err := blk.Miner.MarshalCBOR(buf); err != nil { @@ -607,7 +610,7 @@ func (bv *BlockValidator) MinerEligibleToMine(ctx context.Context, addr address. return false, xerrors.New("power actor not found") } - pstate, err := power.Load(adt.WrapStore(ctx, bv.cstore), (*types2.Actor)(pact)) + pstate, err := power.Load(adt.WrapStore(ctx, bv.cstore), pact) if err != nil { return false, err } @@ -621,7 +624,7 @@ func (bv *BlockValidator) MinerEligibleToMine(ctx context.Context, addr address. return false, xerrors.Errorf("miner actor %s not found", addr) } - mstate, err := miner.Load(adt.WrapStore(ctx, vms), (*types2.Actor)(mact)) + mstate, err := miner.Load(adt.WrapStore(ctx, vms), mact) if err != nil { return false, err } @@ -671,7 +674,7 @@ func (bv *BlockValidator) minerHasMinPower(ctx context.Context, addr address.Add return false, xerrors.New("power actor not found") } - ps, err := power.Load(adt.WrapStore(ctx, vms), (*types2.Actor)(pact)) + ps, err := power.Load(adt.WrapStore(ctx, vms), pact) if err != nil { return false, err } @@ -698,7 +701,7 @@ func (bv *BlockValidator) VerifyWinningPoStProof(ctx context.Context, nv network rbase := prevBeacon if len(blk.BeaconEntries) > 0 { - rbase = blk.BeaconEntries[len(blk.BeaconEntries)-1] + rbase = &blk.BeaconEntries[len(blk.BeaconEntries)-1] } rand, err := chain.DrawRandomness(rbase.Data, acrypto.DomainSeparationTag_WinningPoStChallengeSeed, blk.Height, buf.Bytes()) @@ -863,9 +866,9 @@ func (bv *BlockValidator) checkBlockMessages(ctx context.Context, sigValidator * return xerrors.Errorf("get secpMsgs root failed: %v", err) } - txMeta := &types.TxMeta{ - BLSRoot: bmroot, - SecpRoot: smroot, + txMeta := &types.MessageRoot{ + BlsRoot: bmroot, + SecpkRoot: smroot, } b, err := chain.MakeBlock(txMeta) if err != nil { @@ -953,8 +956,11 @@ func checkBlockSignature(ctx context.Context, blk *types.BlockHeader, worker add return xerrors.New("block signature not present") } - sigb := blk.SignatureData() - err := crypto.Verify(blk.BlockSig, worker, sigb) + sigb, err := blk.SignatureData() + if err != nil { + return err + } + err = crypto.Verify(blk.BlockSig, worker, sigb) if err == nil { blk.SetValidated() } diff --git a/pkg/consensus/chain_selector.go b/pkg/consensus/chain_selector.go index 9a567615bb..a816df7ee8 100644 --- a/pkg/consensus/chain_selector.go +++ b/pkg/consensus/chain_selector.go @@ -6,16 +6,17 @@ package consensus import ( "context" "errors" - logging "github.com/ipfs/go-log/v2" "math/big" + logging "github.com/ipfs/go-log/v2" + fbig "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/venus/pkg/types" cbor "github.com/ipfs/go-ipld-cbor" xerrors "github.com/pkg/errors" "github.com/filecoin-project/venus/pkg/constants" "github.com/filecoin-project/venus/pkg/state" + types "github.com/filecoin-project/venus/venus-shared/chain" ) var log = logging.Logger("chain_selector") @@ -108,7 +109,7 @@ func breakWeightTie(ts1, ts2 *types.TipSet) bool { // blocks are already sorted by ticket for i := 0; i < s; i++ { - if ts1.Blocks()[i].Ticket.Less(&ts2.Blocks()[i].Ticket) { + if ts1.Blocks()[i].Ticket.Less(ts2.Blocks()[i].Ticket) { log.Infof("weight tie broken in favour of %s", ts1.Key()) return true } diff --git a/pkg/consensus/expected.go b/pkg/consensus/expected.go index 3baace77d2..244fe484e9 100644 --- a/pkg/consensus/expected.go +++ b/pkg/consensus/expected.go @@ -3,29 +3,28 @@ package consensus import "C" import ( "context" - "github.com/filecoin-project/venus/pkg/vm/vmcontext" "time" - "golang.org/x/xerrors" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/venus/pkg/config" + "github.com/filecoin-project/venus/pkg/vm/vmcontext" "github.com/ipfs/go-cid" blockstore "github.com/ipfs/go-ipfs-blockstore" cbor "github.com/ipfs/go-ipld-cbor" logging "github.com/ipfs/go-log" "github.com/pkg/errors" "go.opencensus.io/trace" + "golang.org/x/xerrors" "github.com/filecoin-project/venus/pkg/chain" "github.com/filecoin-project/venus/pkg/fork" appstate "github.com/filecoin-project/venus/pkg/state" "github.com/filecoin-project/venus/pkg/state/tree" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/vm" "github.com/filecoin-project/venus/pkg/vm/gas" + types "github.com/filecoin-project/venus/venus-shared/chain" ) var ( @@ -46,7 +45,7 @@ const AllowableClockDriftSecs = uint64(1) type Processor interface { // ProcessTipSet processes all messages in a tip set. ProcessTipSet(context.Context, *types.TipSet, *types.TipSet, []types.BlockMessagesInfo, vm.VmOption) (cid.Cid, []types.MessageReceipt, error) - ProcessImplicitMessage(context.Context, *types.UnsignedMessage, vm.VmOption) (*vm.Ret, error) + ProcessImplicitMessage(context.Context, *types.Message, vm.VmOption) (*vm.Ret, error) } // TicketValidator validates that an input ticket is valid. diff --git a/pkg/consensus/head_randomness.go b/pkg/consensus/head_randomness.go index 855d1c65b4..c16a7c4827 100644 --- a/pkg/consensus/head_randomness.go +++ b/pkg/consensus/head_randomness.go @@ -2,11 +2,12 @@ package consensus import ( "context" + "github.com/filecoin-project/venus/pkg/vm/vmcontext" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/filecoin-project/go-state-types/abi" acrypto "github.com/filecoin-project/go-state-types/crypto" - "github.com/filecoin-project/venus/pkg/types" ) //ChainRandomness define randomness method in filecoin diff --git a/pkg/consensus/message_validator.go b/pkg/consensus/message_validator.go index 691fb097b5..a1fcad7118 100644 --- a/pkg/consensus/message_validator.go +++ b/pkg/consensus/message_validator.go @@ -12,7 +12,7 @@ import ( "github.com/filecoin-project/venus/pkg/crypto" "github.com/filecoin-project/venus/pkg/metrics" "github.com/filecoin-project/venus/pkg/state" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" ) var invReceiverUndefCt *metrics.Int64Counter @@ -25,7 +25,7 @@ var invNegativeValueCt *metrics.Int64Counter var invGasAboveBlockLimitCt *metrics.Int64Counter // The maximum allowed message value. -var msgMaxValue = types.NewAttoFILFromFIL(2e9) +var msgMaxValue = types.FromFil(2e9) // These gas cost values must match those in vm/gas. // TODO: Look up gas costs from the same place the VM gets them, keyed by epoch. https://github.com/filecoin-project/venus/issues/3955 @@ -75,7 +75,7 @@ func (v *DefaultMessageSyntaxValidator) ValidateSignedMessageSyntax(ctx context. // ValidateUnsignedMessageSyntax validates unisigned message syntax and state-independent invariants. // Used for bls messages included in blocks. -func (v *DefaultMessageSyntaxValidator) ValidateUnsignedMessageSyntax(ctx context.Context, msg *types.UnsignedMessage) error { +func (v *DefaultMessageSyntaxValidator) ValidateUnsignedMessageSyntax(ctx context.Context, msg *types.Message) error { buf := new(bytes.Buffer) err := msg.MarshalCBOR(buf) if err != nil { @@ -84,7 +84,7 @@ func (v *DefaultMessageSyntaxValidator) ValidateUnsignedMessageSyntax(ctx contex return v.validateMessageSyntaxShared(ctx, msg, int64(buf.Len())) } -func (v *DefaultMessageSyntaxValidator) validateMessageSyntaxShared(ctx context.Context, msg *types.UnsignedMessage, msgLen int64) error { +func (v *DefaultMessageSyntaxValidator) validateMessageSyntaxShared(ctx context.Context, msg *types.Message, msgLen int64) error { if msg.Version != types.MessageVersion { return fmt.Errorf("version %d, expected %d", msg.Version, types.MessageVersion) } diff --git a/pkg/consensus/message_validator_test.go b/pkg/consensus/message_validator_test.go index 29040e0de8..ade771b464 100644 --- a/pkg/consensus/message_validator_test.go +++ b/pkg/consensus/message_validator_test.go @@ -6,6 +6,8 @@ import ( "testing" "github.com/filecoin-project/venus/pkg/constants" + "github.com/filecoin-project/venus/pkg/testhelpers" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/ipfs/go-cid" "github.com/stretchr/testify/assert" @@ -21,10 +23,9 @@ import ( _ "github.com/filecoin-project/venus/pkg/crypto/secp" "github.com/filecoin-project/venus/pkg/state" tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" - "github.com/filecoin-project/venus/pkg/types" ) -var keys = types.MustGenerateKeyInfo(2, 42) +var keys = testhelpers.MustGenerateKeyInfo(2, 42) var addresses = make([]address.Address, len(keys)) var methodID = abi.MethodNum(21231) @@ -45,10 +46,10 @@ func TestBLSSignatureValidationConfiguration(t *testing.T) { from, err := address.NewBLSAddress(pubKey[:]) require.NoError(t, err) - msg := types.NewMeteredMessage(from, addresses[1], 0, types.ZeroFIL, methodID, []byte("params"), types.NewGasFeeCap(1), types.NewGasPremium(1), 300) + msg := testhelpers.NewMeteredMessage(from, addresses[1], 0, types.ZeroFIL, methodID, []byte("params"), types.NewGasFeeCap(1), types.NewGasPremium(1), 300) mmsgCid := msg.Cid() - var signer = types.NewMockSigner(keys) + var signer = testhelpers.NewMockSigner(keys) signer.AddrKeyInfo[msg.From] = keys[0] sig, err := signer.SignBytes(ctx, mmsgCid.Bytes(), msg.From) require.NoError(t, err) @@ -71,7 +72,7 @@ func TestBLSSignatureValidationConfiguration(t *testing.T) { func TestMessageSyntaxValidator(t *testing.T) { tf.UnitTest(t) - var signer = types.NewMockSigner(keys) + var signer = testhelpers.NewMockSigner(keys) alice := addresses[0] bob := addresses[1] @@ -79,25 +80,25 @@ func TestMessageSyntaxValidator(t *testing.T) { ctx := context.Background() t.Run("Actor not found is not an error", func(t *testing.T) { - msg, err := types.NewSignedMessage(ctx, *newMessage(t, bob, alice, 0, 0, 1, 5000), signer) + msg, err := testhelpers.NewSignedMessage(ctx, *newMessage(t, bob, alice, 0, 0, 1, 5000), signer) require.NoError(t, err) assert.NoError(t, validator.ValidateSignedMessageSyntax(ctx, msg)) }) t.Run("self send passes", func(t *testing.T) { - msg, err := types.NewSignedMessage(ctx, *newMessage(t, alice, alice, 100, 5, 1, 5000), signer) + msg, err := testhelpers.NewSignedMessage(ctx, *newMessage(t, alice, alice, 100, 5, 1, 5000), signer) require.NoError(t, err) assert.NoError(t, validator.ValidateSignedMessageSyntax(ctx, msg), "self") }) t.Run("negative value fails", func(t *testing.T) { - msg, err := types.NewSignedMessage(ctx, *newMessage(t, alice, alice, 100, -5, 1, 5000), signer) + msg, err := testhelpers.NewSignedMessage(ctx, *newMessage(t, alice, alice, 100, -5, 1, 5000), signer) require.NoError(t, err) assert.Errorf(t, validator.ValidateSignedMessageSyntax(ctx, msg), "negative") }) t.Run("block gas limit fails", func(t *testing.T) { - msg, err := types.NewSignedMessage(ctx, *newMessage(t, alice, bob, 100, 5, 1, constants.BlockGasLimit+1), signer) + msg, err := testhelpers.NewSignedMessage(ctx, *newMessage(t, alice, bob, 100, 5, 1, constants.BlockGasLimit+1), signer) require.NoError(t, err) assert.Errorf(t, validator.ValidateSignedMessageSyntax(ctx, msg), "block limit") }) @@ -111,14 +112,14 @@ func newActor(t *testing.T, balanceAF int, nonce uint64) *types.Actor { } func newMessage(t *testing.T, from, to address.Address, nonce uint64, valueAF int, - gasPrice int64, gasLimit int64) *types.UnsignedMessage { - val, ok := types.NewAttoFILFromString(fmt.Sprintf("%d", valueAF), 10) - require.True(t, ok, "invalid attofil") - return types.NewMeteredMessage( + gasPrice int64, gasLimit int64) *types.Message { + val, err := types.ParseFIL(fmt.Sprintf("%d", valueAF)) + require.Nil(t, err, "invalid attofil") + return testhelpers.NewMeteredMessage( from, to, nonce, - val, + abi.TokenAmount{Int: val.Int}, methodID, []byte("params"), types.NewGasFeeCap(gasPrice), @@ -145,12 +146,12 @@ func NewMockIngestionValidatorAPI() *FakeIngestionValidatorAPI { } func (api *FakeIngestionValidatorAPI) GetHead() *types.TipSet { - ts, _ := types.NewTipSet(api.Block) + ts, _ := types.NewTipSet([]*types.BlockHeader{api.Block}) return ts } func (api *FakeIngestionValidatorAPI) GetTipSet(key types.TipSetKey) (*types.TipSet, error) { - return types.NewTipSet(api.Block) + return types.NewTipSet([]*types.BlockHeader{api.Block}) } func (api *FakeIngestionValidatorAPI) GetActorAt(ctx context.Context, key *types.TipSet, a address.Address) (*types.Actor, error) { diff --git a/pkg/consensus/processor.go b/pkg/consensus/processor.go index 7e1e71d082..aa69caef6b 100644 --- a/pkg/consensus/processor.go +++ b/pkg/consensus/processor.go @@ -8,7 +8,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/venus/pkg/metrics/tracing" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/filecoin-project/venus/pkg/vm" ) @@ -73,7 +73,7 @@ func (p *DefaultProcessor) ProcessTipSet(ctx context.Context, } //ProcessImplicitMessage compute the state of specify message but this functions skip value, gas,check -func (p *DefaultProcessor) ProcessImplicitMessage(ctx context.Context, msg *types.UnsignedMessage, vmOption vm.VmOption) (ret *vm.Ret, err error) { +func (p *DefaultProcessor) ProcessImplicitMessage(ctx context.Context, msg *types.Message, vmOption vm.VmOption) (ret *vm.Ret, err error) { ctx, span := trace.StartSpan(ctx, "DefaultProcessor.ProcessImplicitMessage") span.AddAttributes(trace.StringAttribute("message", msg.String())) defer tracing.AddErrorEndSpan(ctx, span, &err) diff --git a/pkg/consensus/protocol.go b/pkg/consensus/protocol.go index 7840152b00..612878f864 100644 --- a/pkg/consensus/protocol.go +++ b/pkg/consensus/protocol.go @@ -11,9 +11,9 @@ package consensus // except for errors in the case the stores do not have a mapping. import ( "context" - "github.com/ipfs/go-cid" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" + "github.com/ipfs/go-cid" ) // Protocol is an interface defining a blockchain consensus protocol. The @@ -25,10 +25,10 @@ import ( type Protocol interface { StateTransformer // Call compute message result of specify message - Call(ctx context.Context, msg *types.UnsignedMessage, ts *types.TipSet) (*vm.Ret, error) + Call(ctx context.Context, msg *types.Message, ts *types.TipSet) (*vm.Ret, error) // CallWithGas compute message result of specify message base on messages in mpool - CallWithGas(ctx context.Context, msg *types.UnsignedMessage, priorMsgs []types.ChainMsg, ts *types.TipSet) (*vm.Ret, error) + CallWithGas(ctx context.Context, msg *types.Message, priorMsgs []types.ChainMsg, ts *types.TipSet) (*vm.Ret, error) } */ diff --git a/pkg/consensus/testing.go b/pkg/consensus/testing.go index 6af8cf86cf..1e0a8d9145 100644 --- a/pkg/consensus/testing.go +++ b/pkg/consensus/testing.go @@ -11,13 +11,13 @@ import ( "github.com/stretchr/testify/require" "github.com/filecoin-project/venus/pkg/state" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" ) // RequireNewTipSet instantiates and returns a new tipset of the given blocks // and requires that the setup validation succeed. func RequireNewTipSet(require *require.Assertions, blks ...*types.BlockHeader) *types.TipSet { - ts, err := types.NewTipSet(blks...) + ts, err := types.NewTipSet(blks) require.NoError(err) return ts } @@ -44,7 +44,7 @@ func (mv *FakeMessageValidator) ValidateSignedMessageSyntax(ctx context.Context, return nil } -func (mv *FakeMessageValidator) ValidateUnsignedMessageSyntax(ctx context.Context, msg *types.UnsignedMessage) error { +func (mv *FakeMessageValidator) ValidateUnsignedMessageSyntax(ctx context.Context, msg *types.Message) error { return nil } @@ -53,7 +53,7 @@ type FakeTicketMachine struct{} // MakeTicket returns a fake ticket func (ftm *FakeTicketMachine) MakeTicket(ctx context.Context, base types.TipSetKey, epoch abi.ChainEpoch, miner address.Address, entry *types.BeaconEntry, newPeriod bool, worker address.Address, signer types.Signer) (types.Ticket, error) { - return MakeFakeTicketForTest(), nil + return *MakeFakeTicketForTest(), nil } // IsValidTicket always returns true @@ -72,11 +72,11 @@ func (ftv *FailingTicketValidator) IsValidTicket(ctx context.Context, base types } // MakeFakeTicketForTest creates a fake ticket -func MakeFakeTicketForTest() types.Ticket { +func MakeFakeTicketForTest() *types.Ticket { val := make([]byte, 65) val[0] = 200 - return types.Ticket{ - VRFProof: types.VRFPi(val[:]), + return &types.Ticket{ + VRFProof: val[:], } } diff --git a/pkg/consensus/ticket.go b/pkg/consensus/ticket.go index 2aace0bd28..e3c3a9c830 100644 --- a/pkg/consensus/ticket.go +++ b/pkg/consensus/ticket.go @@ -13,7 +13,7 @@ import ( "github.com/pkg/errors" "github.com/filecoin-project/venus/pkg/crypto" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" ) type ChainSampler interface { diff --git a/pkg/consensus/ticket_test.go b/pkg/consensus/ticket_test.go index c8fac27038..39b0685763 100644 --- a/pkg/consensus/ticket_test.go +++ b/pkg/consensus/ticket_test.go @@ -2,9 +2,13 @@ package consensus_test import ( "context" - "github.com/filecoin-project/venus/pkg/constants" "testing" + "github.com/filecoin-project/venus/pkg/testhelpers" + + "github.com/filecoin-project/venus/pkg/constants" + types "github.com/filecoin-project/venus/venus-shared/chain" + fbig "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-address" @@ -16,21 +20,20 @@ import ( tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" "github.com/filecoin-project/venus/pkg/consensus" - "github.com/filecoin-project/venus/pkg/types" ) func TestGenValidTicketChain(t *testing.T) { tf.UnitTest(t) ctx := context.Background() - head, _ := types.NewTipSet(mockBlock()) // Tipset key is unused by fake randomness + head, _ := types.NewTipSet([]*types.BlockHeader{mockBlock()}) // Tipset key is unused by fake randomness loader := newMockTipsetLoader(head) // Interleave 3 signers - kis := types.MustGenerateBLSKeyInfo(3, 0) + kis := testhelpers.MustGenerateBLSKeyInfo(3, 0) miner, err := address.NewIDAddress(uint64(1)) require.NoError(t, err) - signer := types.NewMockSigner(kis) + signer := testhelpers.NewMockSigner(kis) addr1 := requireAddress(t, &kis[0]) addr2 := requireAddress(t, &kis[1]) addr3 := requireAddress(t, &kis[2]) @@ -62,13 +65,13 @@ func requireValidTicket(ctx context.Context, t *testing.T, tm *consensus.TicketM func TestNextTicketFailsWithInvalidSigner(t *testing.T) { ctx := context.Background() - head, _ := types.NewTipSet(mockBlock()) // Tipset key is unused by fake randomness + head, _ := types.NewTipSet([]*types.BlockHeader{mockBlock()}) // Tipset key is unused by fake randomness loader := newMockTipsetLoader(head) miner, err := address.NewIDAddress(uint64(1)) require.NoError(t, err) - signer, _ := types.NewMockSignersAndKeyInfo(1) - badAddr := types.RequireIDAddress(t, 100) + signer, _ := testhelpers.NewMockSignersAndKeyInfo(1) + badAddr := testhelpers.RequireIDAddress(t, 100) tm := consensus.NewTicketMachine(loader) electionEntry := &types.BeaconEntry{} newPeriod := false @@ -86,10 +89,10 @@ func requireAddress(t *testing.T, ki *crypto.KeyInfo) address.Address { func mockBlock() *types.BlockHeader { mockCid, _ := constants.DefaultCidBuilder.Sum([]byte("mock")) return &types.BlockHeader{ - Miner: types.NewForTestGetter()(), - Ticket: types.Ticket{VRFProof: []byte{0x01, 0x02, 0x03}}, + Miner: testhelpers.NewForTestGetter()(), + Ticket: &types.Ticket{VRFProof: []byte{0x01, 0x02, 0x03}}, ElectionProof: &types.ElectionProof{VRFProof: []byte{0x0a, 0x0b}}, - BeaconEntries: []*types.BeaconEntry{ + BeaconEntries: []types.BeaconEntry{ { Round: 5, Data: []byte{0x0c}, diff --git a/pkg/consensus/weight_test.go b/pkg/consensus/weight_test.go index 9a6f9ffd65..ff299c7fdd 100644 --- a/pkg/consensus/weight_test.go +++ b/pkg/consensus/weight_test.go @@ -2,10 +2,12 @@ package consensus_test import ( "context" - emptycid "github.com/filecoin-project/venus/pkg/testhelpers/empty_cid" - "github.com/filecoin-project/venus/pkg/types" "testing" + "github.com/filecoin-project/venus/pkg/testhelpers" + + types "github.com/filecoin-project/venus/venus-shared/chain" + "github.com/filecoin-project/go-state-types/abi" fbig "github.com/filecoin-project/go-state-types/big" "github.com/ipfs/go-cid" @@ -24,13 +26,13 @@ func TestWeight(t *testing.T) { fakeTree := tree.NewFromString(t, "test-Weight-StateCid", cst) fakeRoot, err := fakeTree.Flush(ctx) require.NoError(t, err) - addrGetter := types.NewForTestGetter() + addrGetter := testhelpers.NewForTestGetter() minerAddr := addrGetter() // We only care about total power for the weight function // Total is 16, so bitlen is 5, log2b is 4 viewer := makeStateViewer(fakeRoot, abi.NewStoragePower(16)) ticket := consensus.MakeFakeTicketForTest() - toWeigh := types.RequireNewTipSet(t, &types.BlockHeader{ + toWeigh := testhelpers.RequireNewTipSet(t, &types.BlockHeader{ Miner: minerAddr, ParentWeight: fbig.Zero(), Ticket: ticket, @@ -38,8 +40,8 @@ func TestWeight(t *testing.T) { WinCount: 1, }, ParentStateRoot: fakeRoot, - Messages: emptycid.EmptyMessagesCID, - ParentMessageReceipts: emptycid.EmptyReceiptsCID, + Messages: testhelpers.EmptyMessagesCID, + ParentMessageReceipts: testhelpers.EmptyReceiptsCID, }) sel := consensus.NewChainSelector(cst, &viewer) @@ -80,7 +82,7 @@ func TestWeight(t *testing.T) { t.Run("non-zero parent weight", func(t *testing.T) { parentWeight := fbig.NewInt(int64(49)) - toWeighWithParent := types.RequireNewTipSet(t, &types.BlockHeader{ + toWeighWithParent := testhelpers.RequireNewTipSet(t, &types.BlockHeader{ Miner: minerAddr, ParentWeight: parentWeight, Ticket: ticket, @@ -88,8 +90,8 @@ func TestWeight(t *testing.T) { WinCount: 1, }, ParentStateRoot: fakeRoot, - Messages: emptycid.EmptyMessagesCID, - ParentMessageReceipts: emptycid.EmptyReceiptsCID, + Messages: testhelpers.EmptyMessagesCID, + ParentMessageReceipts: testhelpers.EmptyReceiptsCID, }) // 49 + (4*256) + (4*1*1*256/2*5) = 1175 @@ -99,7 +101,7 @@ func TestWeight(t *testing.T) { }) t.Run("many blocks", func(t *testing.T) { - toWeighThreeBlock := types.RequireNewTipSet(t, + toWeighThreeBlock := testhelpers.RequireNewTipSet(t, &types.BlockHeader{ Miner: minerAddr, ParentWeight: fbig.Zero(), @@ -109,8 +111,8 @@ func TestWeight(t *testing.T) { WinCount: 1, }, ParentStateRoot: fakeRoot, - Messages: emptycid.EmptyMessagesCID, - ParentMessageReceipts: emptycid.EmptyReceiptsCID, + Messages: testhelpers.EmptyMessagesCID, + ParentMessageReceipts: testhelpers.EmptyReceiptsCID, }, &types.BlockHeader{ Miner: minerAddr, @@ -121,8 +123,8 @@ func TestWeight(t *testing.T) { WinCount: 1, }, ParentStateRoot: fakeRoot, - Messages: emptycid.EmptyMessagesCID, - ParentMessageReceipts: emptycid.EmptyReceiptsCID, + Messages: testhelpers.EmptyMessagesCID, + ParentMessageReceipts: testhelpers.EmptyReceiptsCID, }, &types.BlockHeader{ Miner: minerAddr, @@ -133,8 +135,8 @@ func TestWeight(t *testing.T) { WinCount: 1, }, ParentStateRoot: fakeRoot, - Messages: emptycid.EmptyMessagesCID, - ParentMessageReceipts: emptycid.EmptyReceiptsCID, + Messages: testhelpers.EmptyMessagesCID, + ParentMessageReceipts: testhelpers.EmptyReceiptsCID, }, ) // 0 + (4*256) + (4*3*1*256/2*5) = 1331 diff --git a/pkg/consensusfault/check.go b/pkg/consensusfault/check.go index f76632912c..d59d14ec0e 100644 --- a/pkg/consensusfault/check.go +++ b/pkg/consensusfault/check.go @@ -9,13 +9,12 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/venus/pkg/fork" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/vm" "github.com/filecoin-project/venus/pkg/vm/vmcontext" "github.com/filecoin-project/venus/venus-shared/actors/adt" "github.com/filecoin-project/venus/venus-shared/actors/builtin/miner" "github.com/filecoin-project/venus/venus-shared/actors/policy" - types2 "github.com/filecoin-project/venus/venus-shared/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" cbornode "github.com/ipfs/go-ipld-cbor" "github.com/filecoin-project/venus/pkg/config" @@ -101,7 +100,9 @@ func (s *ConsensusFaultChecker) VerifyConsensusFault(ctx context.Context, h1, h2 // Time-offset mining fault: two blocks with the same parent but different epochs. // The curEpoch check is redundant at time of writing, but included for robustness to future changes to this method. // The blocks have a common ancestor by definition (the parent). - if b1.Parents.Equals(b2.Parents) && b1.Height != b2.Height { + b1PKey := types.NewTipSetKey(b1.Parents...) + b2PKey := types.NewTipSetKey(b2.Parents...) + if b1PKey.Equals(b2PKey) && b1.Height != b2.Height { fault = &runtime5.ConsensusFault{ Target: b1.Miner, Epoch: b2.Height, @@ -117,7 +118,8 @@ func (s *ConsensusFaultChecker) VerifyConsensusFault(ctx context.Context, h1, h2 if innerErr != nil { return nil, errors.Wrapf(innerErr, "failed to decode extra") } - if b1.Height == b3.Height && b3.Parents.Equals(b1.Parents) && !b2.Parents.Has(b1.Cid()) && b2.Parents.Has(b3.Cid()) { + b3PKey := types.NewTipSetKey(b3.Parents...) + if b1.Height == b3.Height && b3PKey.Equals(b1PKey) && !b2PKey.Has(b1.Cid()) && b2PKey.Has(b3.Cid()) { fault = &runtime5.ConsensusFault{ Target: b1.Miner, Epoch: b2.Height, @@ -161,7 +163,7 @@ func verifyBlockSignature(ctx context.Context, blk types.BlockHeader, nv network return errors.Wrapf(err, "failed to get miner actor") } - mas, err := miner.Load(adt.WrapStore(ctx, gasIpld), (*types2.Actor)(act)) + mas, err := miner.Load(adt.WrapStore(ctx, gasIpld), act) if err != nil { return xerrors.Errorf("failed to load state for miner %s", receiver) } @@ -175,7 +177,11 @@ func verifyBlockSignature(ctx context.Context, blk types.BlockHeader, nv network return errors.Errorf("no consensus fault: block %s has nil signature", blk.Cid()) } - err = state.NewSignatureValidator(view).ValidateSignature(ctx, blk.SignatureData(), info.Worker, *blk.BlockSig) + sd, err := blk.SignatureData() + if err != nil { + return err + } + err = state.NewSignatureValidator(view).ValidateSignature(ctx, sd, info.Worker, *blk.BlockSig) if err != nil { return errors.Wrapf(err, "no consensus fault: block %s signature invalid", blk.Cid()) } diff --git a/pkg/discovery/cbor_gen.go b/pkg/discovery/cbor_gen.go index 713690136c..17579c33b3 100644 --- a/pkg/discovery/cbor_gen.go +++ b/pkg/discovery/cbor_gen.go @@ -30,7 +30,7 @@ func (t *HelloMessage) MarshalCBOR(w io.Writer) error { scratch := make([]byte, 9) - // t.HeaviestTipSetCids (internal.TipSetKey) (struct) + // t.HeaviestTipSetCids (chain.TipSetKey) (struct) if err := t.HeaviestTipSetCids.MarshalCBOR(w); err != nil { return err } @@ -78,7 +78,7 @@ func (t *HelloMessage) UnmarshalCBOR(r io.Reader) error { return fmt.Errorf("cbor input had wrong number of fields") } - // t.HeaviestTipSetCids (internal.TipSetKey) (struct) + // t.HeaviestTipSetCids (chain.TipSetKey) (struct) { diff --git a/pkg/discovery/hello_protocol.go b/pkg/discovery/hello_protocol.go index ea9fd20e55..5d45756c52 100644 --- a/pkg/discovery/hello_protocol.go +++ b/pkg/discovery/hello_protocol.go @@ -8,7 +8,7 @@ import ( "github.com/filecoin-project/venus/pkg/chain" "github.com/filecoin-project/venus/pkg/chainsync/exchange" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/libp2p/go-libp2p-core/peer" "github.com/filecoin-project/go-state-types/abi" diff --git a/pkg/discovery/hello_protocol_test.go b/pkg/discovery/hello_protocol_test.go index dc9e1dc95a..ffc443aa65 100644 --- a/pkg/discovery/hello_protocol_test.go +++ b/pkg/discovery/hello_protocol_test.go @@ -2,12 +2,9 @@ package discovery_test import ( "context" - "github.com/filecoin-project/venus/pkg/types" "testing" "time" - "github.com/filecoin-project/venus/pkg/net" - "github.com/filecoin-project/venus/pkg/repo" ds "github.com/ipfs/go-datastore" "github.com/libp2p/go-libp2p-core/host" dht "github.com/libp2p/go-libp2p-kad-dht" @@ -21,8 +18,11 @@ import ( "github.com/filecoin-project/venus/pkg/chain" "github.com/filecoin-project/venus/pkg/discovery" + "github.com/filecoin-project/venus/pkg/net" + "github.com/filecoin-project/venus/pkg/repo" th "github.com/filecoin-project/venus/pkg/testhelpers" tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" + types "github.com/filecoin-project/venus/venus-shared/chain" ) type mockHelloCallback struct { diff --git a/pkg/discovery/peer_tracker.go b/pkg/discovery/peer_tracker.go index 4e10e2b54f..b2b318392b 100644 --- a/pkg/discovery/peer_tracker.go +++ b/pkg/discovery/peer_tracker.go @@ -4,8 +4,7 @@ import ( "sort" "sync" - "github.com/filecoin-project/venus/pkg/types" - + types "github.com/filecoin-project/venus/venus-shared/chain" logging "github.com/ipfs/go-log/v2" "github.com/libp2p/go-libp2p-core/network" "github.com/libp2p/go-libp2p-core/peer" diff --git a/pkg/discovery/peer_tracker_test.go b/pkg/discovery/peer_tracker_test.go index a015e8cbec..39134395e0 100644 --- a/pkg/discovery/peer_tracker_test.go +++ b/pkg/discovery/peer_tracker_test.go @@ -2,12 +2,13 @@ package discovery_test import ( "context" - "github.com/filecoin-project/venus/pkg/types" - "github.com/filecoin-project/venus/pkg/util/test" - "github.com/libp2p/go-libp2p-core/network" "testing" "time" + "github.com/filecoin-project/venus/pkg/util/test" + types "github.com/filecoin-project/venus/venus-shared/chain" + "github.com/libp2p/go-libp2p-core/network" + "github.com/filecoin-project/venus/pkg/discovery" "github.com/libp2p/go-libp2p-core/peer" mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" diff --git a/pkg/events/cache.go b/pkg/events/cache.go index 88adff2966..3d742ccade 100644 --- a/pkg/events/cache.go +++ b/pkg/events/cache.go @@ -9,13 +9,14 @@ import ( "github.com/ipfs/go-cid" "github.com/filecoin-project/venus/pkg/chain" - "github.com/filecoin-project/venus/pkg/types" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" ) type uncachedAPI interface { ChainNotify(context.Context) <-chan []*chain.HeadChange ChainGetPath(ctx context.Context, from, to types.TipSetKey) ([]*chain.HeadChange, error) - StateSearchMsg(ctx context.Context, from types.TipSetKey, msg cid.Cid, limit abi.ChainEpoch, allowReplaced bool) (*chain.MsgLookup, error) + StateSearchMsg(ctx context.Context, from types.TipSetKey, msg cid.Cid, limit abi.ChainEpoch, allowReplaced bool) (*apitypes.MsgLookup, error) StateGetActor(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*types.Actor, error) // optional / for CalledMsg diff --git a/pkg/events/eventAPI.go b/pkg/events/eventAPI.go index c7d7c6255f..bacefbf0a9 100644 --- a/pkg/events/eventAPI.go +++ b/pkg/events/eventAPI.go @@ -7,9 +7,9 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" - "github.com/filecoin-project/venus/app/submodule/apitypes" "github.com/filecoin-project/venus/pkg/chain" - "github.com/filecoin-project/venus/pkg/types" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" ) // A TipSetObserver receives notifications of tipsets diff --git a/pkg/events/events.go b/pkg/events/events.go index b991a0a007..5f3daf222e 100644 --- a/pkg/events/events.go +++ b/pkg/events/events.go @@ -7,7 +7,7 @@ import ( logging "github.com/ipfs/go-log/v2" "github.com/filecoin-project/venus/pkg/constants" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" ) var log = logging.Logger("events") diff --git a/pkg/events/events_called.go b/pkg/events/events_called.go index 896a4e32a2..b747dc35ac 100644 --- a/pkg/events/events_called.go +++ b/pkg/events/events_called.go @@ -10,7 +10,7 @@ import ( "golang.org/x/xerrors" "github.com/filecoin-project/venus/pkg/constants" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" ) const NoTimeout = math.MaxInt64 diff --git a/pkg/events/events_height.go b/pkg/events/events_height.go index 81b4ee0cb3..8099db498d 100644 --- a/pkg/events/events_height.go +++ b/pkg/events/events_height.go @@ -4,9 +4,8 @@ import ( "context" "sync" - "github.com/filecoin-project/venus/pkg/types" - "github.com/filecoin-project/go-state-types/abi" + types "github.com/filecoin-project/venus/venus-shared/chain" "go.opencensus.io/trace" "golang.org/x/xerrors" ) diff --git a/pkg/events/events_test.go b/pkg/events/events_test.go index 74e46de623..a2141cb737 100644 --- a/pkg/events/events_test.go +++ b/pkg/events/events_test.go @@ -18,11 +18,11 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/crypto" - "github.com/filecoin-project/venus/app/submodule/apitypes" "github.com/filecoin-project/venus/pkg/chain" "github.com/filecoin-project/venus/pkg/constants" tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" - "github.com/filecoin-project/venus/pkg/types" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" ) var dummyCid cid.Cid @@ -144,7 +144,7 @@ func (fcs *fakeCS) ChainGetTipSet(ctx context.Context, key types.TipSetKey) (*ty return fcs.tipsets[key], nil } -func (fcs *fakeCS) StateSearchMsg(ctx context.Context, from types.TipSetKey, msg cid.Cid, limit abi.ChainEpoch, allowReplaced bool) (*chain.MsgLookup, error) { +func (fcs *fakeCS) StateSearchMsg(ctx context.Context, from types.TipSetKey, msg cid.Cid, limit abi.ChainEpoch, allowReplaced bool) (*apitypes.MsgLookup, error) { fcs.mu.Lock() defer fcs.mu.Unlock() fcs.callNumber["StateSearchMsg"] = fcs.callNumber["StateSearchMsg"] + 1 @@ -181,9 +181,9 @@ func (fcs *fakeCS) makeTs(t *testing.T, parents []cid.Cid, h abi.ChainEpoch, msg Height: h, Miner: a, - Parents: types.NewTipSetKey(parents...), + Parents: parents, - Ticket: types.Ticket{VRFProof: []byte{byte(h % 2)}}, + Ticket: &types.Ticket{VRFProof: []byte{byte(h % 2)}}, ParentStateRoot: dummyCid, Messages: msgcid, @@ -196,9 +196,9 @@ func (fcs *fakeCS) makeTs(t *testing.T, parents []cid.Cid, h abi.ChainEpoch, msg Height: h, Miner: b, - Parents: types.NewTipSetKey(parents...), + Parents: parents, - Ticket: types.Ticket{VRFProof: []byte{byte((h + 1) % 2)}}, + Ticket: &types.Ticket{VRFProof: []byte{byte((h + 1) % 2)}}, ParentStateRoot: dummyCid, Messages: msgcid, @@ -207,7 +207,7 @@ func (fcs *fakeCS) makeTs(t *testing.T, parents []cid.Cid, h abi.ChainEpoch, msg BlockSig: &crypto.Signature{Type: crypto.SigTypeBLS}, BLSAggregate: &crypto.Signature{Type: crypto.SigTypeBLS}, }, - }...) + }) if fcs.tipsets == nil { fcs.tipsets = map[types.TipSetKey]*types.TipSet{} diff --git a/pkg/events/message_cache.go b/pkg/events/message_cache.go index 9f866bed18..266fe390cb 100644 --- a/pkg/events/message_cache.go +++ b/pkg/events/message_cache.go @@ -7,7 +7,7 @@ import ( lru "github.com/hashicorp/golang-lru" "github.com/ipfs/go-cid" - "github.com/filecoin-project/venus/app/submodule/apitypes" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" ) type messageCache struct { diff --git a/pkg/events/observer.go b/pkg/events/observer.go index 8f0a675798..50fc261afb 100644 --- a/pkg/events/observer.go +++ b/pkg/events/observer.go @@ -11,7 +11,7 @@ import ( "github.com/filecoin-project/venus/pkg/chain" "github.com/filecoin-project/venus/pkg/constants" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" ) var ObserveDuration = time.Second * 45 diff --git a/pkg/events/state/fastapi.go b/pkg/events/state/fastapi.go index f329bcf5a0..622695ba65 100644 --- a/pkg/events/state/fastapi.go +++ b/pkg/events/state/fastapi.go @@ -4,8 +4,7 @@ import ( "context" "github.com/filecoin-project/go-address" - - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" ) type FastChainAPI interface { diff --git a/pkg/events/state/mock/api.go b/pkg/events/state/mock/api.go index 23023f14b9..dd8e6ed3a0 100644 --- a/pkg/events/state/mock/api.go +++ b/pkg/events/state/mock/api.go @@ -9,8 +9,8 @@ import ( "github.com/ipfs/go-cid" "golang.org/x/xerrors" - "github.com/filecoin-project/venus/pkg/types" blockstore "github.com/filecoin-project/venus/pkg/util/blockstoreutil" + types "github.com/filecoin-project/venus/venus-shared/chain" ) type MockAPI struct { diff --git a/pkg/events/state/mock/tipset.go b/pkg/events/state/mock/tipset.go index 04b7d7e7f5..1efda23e52 100644 --- a/pkg/events/state/mock/tipset.go +++ b/pkg/events/state/mock/tipset.go @@ -3,7 +3,7 @@ package test import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/crypto" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/ipfs/go-cid" ) @@ -23,5 +23,5 @@ func MockTipset(minerAddr address.Address, timestamp uint64) (*types.TipSet, err BlockSig: &crypto.Signature{Type: crypto.SigTypeBLS}, BLSAggregate: &crypto.Signature{Type: crypto.SigTypeBLS}, Timestamp: timestamp, - }}...) + }}) } diff --git a/pkg/events/state/predicates.go b/pkg/events/state/predicates.go index 2d1f7c29a5..b83cdd08df 100644 --- a/pkg/events/state/predicates.go +++ b/pkg/events/state/predicates.go @@ -10,13 +10,12 @@ import ( "github.com/filecoin-project/venus/app/submodule/chain" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/venus-shared/actors/adt" init_ "github.com/filecoin-project/venus/venus-shared/actors/builtin/init" "github.com/filecoin-project/venus/venus-shared/actors/builtin/market" "github.com/filecoin-project/venus/venus-shared/actors/builtin/miner" "github.com/filecoin-project/venus/venus-shared/actors/builtin/paych" - types2 "github.com/filecoin-project/venus/venus-shared/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" ) // UserData is the data returned from the DiffTipSetKeyFunc @@ -73,11 +72,11 @@ type DiffStorageMarketStateFunc func(ctx context.Context, oldState market.State, // OnStorageMarketActorChanged calls diffStorageMarketState when the state changes for the market actor func (sp *StatePredicates) OnStorageMarketActorChanged(diffStorageMarketState DiffStorageMarketStateFunc) DiffTipSetKeyFunc { return sp.OnActorStateChanged(market.Address, func(ctx context.Context, oldActorState, newActorState *types.Actor) (changed bool, user UserData, err error) { - oldState, err := market.Load(adt.WrapStore(ctx, sp.cst), (*types2.Actor)(oldActorState)) + oldState, err := market.Load(adt.WrapStore(ctx, sp.cst), oldActorState) if err != nil { return false, nil, err } - newState, err := market.Load(adt.WrapStore(ctx, sp.cst), (*types2.Actor)(newActorState)) + newState, err := market.Load(adt.WrapStore(ctx, sp.cst), newActorState) if err != nil { return false, nil, err } @@ -309,11 +308,11 @@ type DiffMinerActorStateFunc func(ctx context.Context, oldState miner.State, new func (sp *StatePredicates) OnInitActorChange(diffInitActorState DiffInitActorStateFunc) DiffTipSetKeyFunc { return sp.OnActorStateChanged(init_.Address, func(ctx context.Context, oldActorState, newActorState *types.Actor) (changed bool, user UserData, err error) { - oldState, err := init_.Load(adt.WrapStore(ctx, sp.cst), (*types2.Actor)(oldActorState)) + oldState, err := init_.Load(adt.WrapStore(ctx, sp.cst), oldActorState) if err != nil { return false, nil, err } - newState, err := init_.Load(adt.WrapStore(ctx, sp.cst), (*types2.Actor)(newActorState)) + newState, err := init_.Load(adt.WrapStore(ctx, sp.cst), newActorState) if err != nil { return false, nil, err } @@ -324,11 +323,11 @@ func (sp *StatePredicates) OnInitActorChange(diffInitActorState DiffInitActorSta func (sp *StatePredicates) OnMinerActorChange(minerAddr address.Address, diffMinerActorState DiffMinerActorStateFunc) DiffTipSetKeyFunc { return sp.OnActorStateChanged(minerAddr, func(ctx context.Context, oldActorState, newActorState *types.Actor) (changed bool, user UserData, err error) { - oldState, err := miner.Load(adt.WrapStore(ctx, sp.cst), (*types2.Actor)(oldActorState)) + oldState, err := miner.Load(adt.WrapStore(ctx, sp.cst), oldActorState) if err != nil { return false, nil, err } - newState, err := miner.Load(adt.WrapStore(ctx, sp.cst), (*types2.Actor)(newActorState)) + newState, err := miner.Load(adt.WrapStore(ctx, sp.cst), newActorState) if err != nil { return false, nil, err } @@ -372,11 +371,11 @@ type DiffPaymentChannelStateFunc func(ctx context.Context, oldState paych.State, // OnPaymentChannelActorChanged calls diffPaymentChannelState when the state changes for the the payment channel actor func (sp *StatePredicates) OnPaymentChannelActorChanged(paychAddr address.Address, diffPaymentChannelState DiffPaymentChannelStateFunc) DiffTipSetKeyFunc { return sp.OnActorStateChanged(paychAddr, func(ctx context.Context, oldActorState, newActorState *types.Actor) (changed bool, user UserData, err error) { - oldState, err := paych.Load(adt.WrapStore(ctx, sp.cst), (*types2.Actor)(oldActorState)) + oldState, err := paych.Load(adt.WrapStore(ctx, sp.cst), oldActorState) if err != nil { return false, nil, err } - newState, err := paych.Load(adt.WrapStore(ctx, sp.cst), (*types2.Actor)(newActorState)) + newState, err := paych.Load(adt.WrapStore(ctx, sp.cst), newActorState) if err != nil { return false, nil, err } diff --git a/pkg/events/state/predicates_test.go b/pkg/events/state/predicates_test.go index 9743cd689a..b30274bbf7 100644 --- a/pkg/events/state/predicates_test.go +++ b/pkg/events/state/predicates_test.go @@ -6,11 +6,10 @@ import ( test "github.com/filecoin-project/venus/pkg/events/state/mock" tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" - "github.com/filecoin-project/venus/pkg/types" bstore "github.com/filecoin-project/venus/pkg/util/blockstoreutil" "github.com/filecoin-project/venus/venus-shared/actors/builtin/market" "github.com/filecoin-project/venus/venus-shared/actors/builtin/miner" - types2 "github.com/filecoin-project/venus/venus-shared/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/ipfs/go-cid" cbornode "github.com/ipfs/go-ipld-cbor" @@ -207,7 +206,7 @@ func TestMarketPredicates(t *testing.T) { marketState0 := test.CreateEmptyMarketState(t, store) marketCid, err := store.Put(ctx, marketState0) require.NoError(t, err) - marketState, err := market.Load(store, &types2.Actor{ + marketState, err := market.Load(store, &types.Actor{ Code: builtin2.StorageMarketActorCodeID, Head: marketCid, }) @@ -320,7 +319,7 @@ func TestMarketPredicates(t *testing.T) { marketState0 := test.CreateEmptyMarketState(t, store) marketCid, err := store.Put(ctx, marketState0) require.NoError(t, err) - marketState, err := market.Load(store, &types2.Actor{ + marketState, err := market.Load(store, &types.Actor{ Code: builtin2.StorageMarketActorCodeID, Head: marketCid, }) diff --git a/pkg/events/tscache.go b/pkg/events/tscache.go index 07dcb72fa2..d8cfaacd6f 100644 --- a/pkg/events/tscache.go +++ b/pkg/events/tscache.go @@ -5,9 +5,8 @@ import ( "sync" "github.com/filecoin-project/go-state-types/abi" + types "github.com/filecoin-project/venus/venus-shared/chain" "golang.org/x/xerrors" - - "github.com/filecoin-project/venus/pkg/types" ) type tsCacheAPI interface { diff --git a/pkg/events/tscache_test.go b/pkg/events/tscache_test.go index f3e216495a..0c47f2a9b0 100644 --- a/pkg/events/tscache_test.go +++ b/pkg/events/tscache_test.go @@ -11,7 +11,7 @@ import ( "github.com/stretchr/testify/require" tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" ) type tsCacheAPIFailOnStorageCall struct { @@ -67,8 +67,8 @@ func (h *cacheHarness) addWithParents(parents []cid.Cid) { ParentMessageReceipts: dummyCid, BlockSig: &crypto.Signature{Type: crypto.SigTypeBLS}, BLSAggregate: &crypto.Signature{Type: crypto.SigTypeBLS}, - Parents: types.NewTipSetKey(parents...), - }}...) + Parents: parents, + }}) require.NoError(h.t, err) require.NoError(h.t, h.tsc.add(ts)) h.height++ @@ -209,8 +209,8 @@ func TestTsCacheSkip(t *testing.T) { BlockSig: &crypto.Signature{Type: crypto.SigTypeBLS}, BLSAggregate: &crypto.Signature{Type: crypto.SigTypeBLS}, // With parents that don't match the last block. - Parents: types.EmptyTSK, - }}...) + Parents: types.EmptyTSK.Cids(), + }}) require.NoError(h.t, err) err = h.tsc.add(ts) require.Error(t, err) diff --git a/pkg/events/utils.go b/pkg/events/utils.go index 9023ac5e96..e9b62282f6 100644 --- a/pkg/events/utils.go +++ b/pkg/events/utils.go @@ -6,7 +6,7 @@ import ( "golang.org/x/xerrors" "github.com/filecoin-project/venus/pkg/constants" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" ) // CheckMsg convenience function for checking and matching messages diff --git a/pkg/fork/fork.go b/pkg/fork/fork.go index c20d8f5ef7..84b7973305 100644 --- a/pkg/fork/fork.go +++ b/pkg/fork/fork.go @@ -44,13 +44,12 @@ import ( "github.com/filecoin-project/venus/pkg/config" "github.com/filecoin-project/venus/pkg/constants" vmstate "github.com/filecoin-project/venus/pkg/state/tree" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/util/blockstoreutil" "github.com/filecoin-project/venus/venus-shared/actors/adt" "github.com/filecoin-project/venus/venus-shared/actors/builtin" init_ "github.com/filecoin-project/venus/venus-shared/actors/builtin/init" "github.com/filecoin-project/venus/venus-shared/actors/builtin/multisig" - types2 "github.com/filecoin-project/venus/venus-shared/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" ) var log = logging.Logger("fork") @@ -636,11 +635,11 @@ func (c *ChainFork) ParentState(ts *types.TipSet) cid.Cid { func (c *ChainFork) UpgradeFaucetBurnRecovery(ctx context.Context, cache MigrationCache, root cid.Cid, epoch abi.ChainEpoch, ts *types.TipSet) (cid.Cid, error) { // Some initial parameters - FundsForMiners := types.NewAttoFILFromFIL(1_000_000) + FundsForMiners := types.FromFil(1_000_000) LookbackEpoch := abi.ChainEpoch(32000) - AccountCap := types.NewAttoFILFromFIL(0) - BaseMinerBalance := types.NewAttoFILFromFIL(20) - DesiredReimbursementBalance := types.NewAttoFILFromFIL(5_000_000) + AccountCap := types.FromFil(0) + BaseMinerBalance := types.FromFil(20) + DesiredReimbursementBalance := types.FromFil(5_000_000) isSystemAccount := func(addr address.Address) (bool, error) { id, err := address.IDFromAddress(addr) @@ -896,7 +895,7 @@ func (c *ChainFork) UpgradeFaucetBurnRecovery(ctx context.Context, cache Migrati return cid.Undef, xerrors.Errorf("checking final state balance failed: %v", err) } - exp := types.NewAttoFILFromFIL(constants.FilBase) + exp := types.FromFil(constants.FilBase) if !exp.Equals(total) { return cid.Undef, xerrors.Errorf("resultant state tree account balance was not correct: %s", total) } @@ -913,7 +912,7 @@ func setNetworkName(ctx context.Context, store adt.Store, tree *vmstate.State, n return xerrors.New("did not find init actor") } - initState, err := init_.Load(store, (*types2.Actor)(ia)) + initState, err := init_.Load(store, ia) if err != nil { return xerrors.Errorf("reading init state: %v", err) } @@ -942,7 +941,7 @@ func resetGenesisMsigs0(ctx context.Context, sm *ChainFork, store adt0.Store, tr return xerrors.Errorf("getting genesis block: %v", err) } - gts, err := types.NewTipSet(gb) + gts, err := types.NewTipSet([]*types.BlockHeader{gb}) if err != nil { return xerrors.Errorf("getting genesis tipset: %v", err) } @@ -1024,7 +1023,7 @@ func splitGenesisMultisig0(ctx context.Context, addr address.Address, store adt0 return xerrors.Errorf("did not find actor: %s", addr.String()) } - mst, err := multisig.Load(store, (*types2.Actor)(mact)) + mst, err := multisig.Load(store, mact) if err != nil { return xerrors.Errorf("getting msig state: %v", err) } @@ -1500,7 +1499,7 @@ func terminateActor(ctx context.Context, tree *vmstate.State, addr address.Addre return types.ErrActorNotFound } - ias, err := init_.Load(&vmstate.AdtStore{IpldStore: tree.Store}, (*types2.Actor)(ia)) + ias, err := init_.Load(&vmstate.AdtStore{IpldStore: tree.Store}, ia) if err != nil { return xerrors.Errorf("loading init actor state: %v", err) } diff --git a/pkg/fork/mock.go b/pkg/fork/mock.go index 711179768d..55402b4320 100644 --- a/pkg/fork/mock.go +++ b/pkg/fork/mock.go @@ -2,8 +2,9 @@ package fork import ( "context" + "github.com/filecoin-project/venus/pkg/config" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/network" diff --git a/pkg/gen/genesis/f00_system.go b/pkg/gen/genesis/f00_system.go index 19cf3432a9..eea94fcdb5 100644 --- a/pkg/gen/genesis/f00_system.go +++ b/pkg/gen/genesis/f00_system.go @@ -11,8 +11,8 @@ import ( cbor "github.com/ipfs/go-ipld-cbor" - "github.com/filecoin-project/venus/pkg/types" bstore "github.com/filecoin-project/venus/pkg/util/blockstoreutil" + types "github.com/filecoin-project/venus/venus-shared/chain" ) func SetupSystemActor(ctx context.Context, bs bstore.Blockstore, av actors.Version) (*types.Actor, error) { diff --git a/pkg/gen/genesis/f01_init.go b/pkg/gen/genesis/f01_init.go index ae4746a7ba..27b5500886 100644 --- a/pkg/gen/genesis/f01_init.go +++ b/pkg/gen/genesis/f01_init.go @@ -15,10 +15,10 @@ import ( cbg "github.com/whyrusleeping/cbor-gen" "golang.org/x/xerrors" - "github.com/filecoin-project/venus/pkg/types" bstore "github.com/filecoin-project/venus/pkg/util/blockstoreutil" "github.com/filecoin-project/venus/venus-shared/actors" init_ "github.com/filecoin-project/venus/venus-shared/actors/builtin/init" + types "github.com/filecoin-project/venus/venus-shared/chain" ) func SetupInitActor(ctx context.Context, bs bstore.Blockstore, netname string, initialActors []Actor, rootVerifier Actor, remainder Actor, av actors.Version) (int64, *types.Actor, map[address.Address]address.Address, error) { diff --git a/pkg/gen/genesis/f02_reward.go b/pkg/gen/genesis/f02_reward.go index d221f131d1..adfe1deb47 100644 --- a/pkg/gen/genesis/f02_reward.go +++ b/pkg/gen/genesis/f02_reward.go @@ -7,12 +7,12 @@ import ( "github.com/filecoin-project/venus/venus-shared/actors" "github.com/filecoin-project/venus/venus-shared/actors/adt" "github.com/filecoin-project/venus/venus-shared/actors/builtin/reward" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/filecoin-project/go-state-types/big" cbor "github.com/ipfs/go-ipld-cbor" - "github.com/filecoin-project/venus/pkg/types" bstore "github.com/filecoin-project/venus/pkg/util/blockstoreutil" ) diff --git a/pkg/gen/genesis/f03_cron.go b/pkg/gen/genesis/f03_cron.go index 92bc48b2a1..7c36d58e51 100644 --- a/pkg/gen/genesis/f03_cron.go +++ b/pkg/gen/genesis/f03_cron.go @@ -10,8 +10,8 @@ import ( "github.com/filecoin-project/venus/venus-shared/actors/adt" "github.com/filecoin-project/venus/venus-shared/actors/builtin/cron" - "github.com/filecoin-project/venus/pkg/types" bstore "github.com/filecoin-project/venus/pkg/util/blockstoreutil" + types "github.com/filecoin-project/venus/venus-shared/chain" ) func SetupCronActor(ctx context.Context, bs bstore.Blockstore, av actors.Version) (*types.Actor, error) { diff --git a/pkg/gen/genesis/f04_power.go b/pkg/gen/genesis/f04_power.go index 04a04dae4d..4a575d0390 100644 --- a/pkg/gen/genesis/f04_power.go +++ b/pkg/gen/genesis/f04_power.go @@ -11,8 +11,8 @@ import ( cbor "github.com/ipfs/go-ipld-cbor" - "github.com/filecoin-project/venus/pkg/types" bstore "github.com/filecoin-project/venus/pkg/util/blockstoreutil" + types "github.com/filecoin-project/venus/venus-shared/chain" ) func SetupStoragePowerActor(ctx context.Context, bs bstore.Blockstore, av actors.Version) (*types.Actor, error) { diff --git a/pkg/gen/genesis/f05_market.go b/pkg/gen/genesis/f05_market.go index 84909f30a1..0f470614be 100644 --- a/pkg/gen/genesis/f05_market.go +++ b/pkg/gen/genesis/f05_market.go @@ -10,8 +10,8 @@ import ( "github.com/filecoin-project/venus/venus-shared/actors/adt" "github.com/filecoin-project/venus/venus-shared/actors/builtin/market" - "github.com/filecoin-project/venus/pkg/types" bstore "github.com/filecoin-project/venus/pkg/util/blockstoreutil" + types "github.com/filecoin-project/venus/venus-shared/chain" ) func SetupStorageMarketActor(ctx context.Context, bs bstore.Blockstore, av actors.Version) (*types.Actor, error) { diff --git a/pkg/gen/genesis/f06_vreg.go b/pkg/gen/genesis/f06_vreg.go index 0f3e44a8e1..329c43b7e5 100644 --- a/pkg/gen/genesis/f06_vreg.go +++ b/pkg/gen/genesis/f06_vreg.go @@ -13,8 +13,8 @@ import ( "github.com/filecoin-project/specs-actors/actors/util/adt" - "github.com/filecoin-project/venus/pkg/types" bstore "github.com/filecoin-project/venus/pkg/util/blockstoreutil" + types "github.com/filecoin-project/venus/venus-shared/chain" ) var RootVerifierID address.Address diff --git a/pkg/gen/genesis/genesis.go b/pkg/gen/genesis/genesis.go index 478ec83f7b..7c6abe4bdd 100644 --- a/pkg/gen/genesis/genesis.go +++ b/pkg/gen/genesis/genesis.go @@ -10,6 +10,7 @@ import ( "github.com/filecoin-project/venus/pkg/fork" "github.com/filecoin-project/venus/pkg/util/ffiwrapper/impl" "github.com/filecoin-project/venus/pkg/vmsupport" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/filecoin-project/venus/pkg/config" "github.com/filecoin-project/venus/pkg/vm/gas" @@ -58,7 +59,6 @@ import ( "github.com/filecoin-project/venus/pkg/chain" sigs "github.com/filecoin-project/venus/pkg/crypto" "github.com/filecoin-project/venus/pkg/repo" - "github.com/filecoin-project/venus/pkg/types" bstore "github.com/filecoin-project/venus/pkg/util/blockstoreutil" "github.com/filecoin-project/venus/pkg/vm" ) @@ -589,9 +589,9 @@ func MakeGenesisBlock(ctx context.Context, rep repo.Repo, bs bstore.Blockstore, return nil, xerrors.Errorf("amt build failed: %w", err) } - mm := &types.TxMeta{ - BLSRoot: emptyroot, - SecpRoot: emptyroot, + mm := &types.MessageRoot{ + BlsRoot: emptyroot, + SecpkRoot: emptyroot, } mmb, err := mm.ToStorageBlock() if err != nil { @@ -605,7 +605,7 @@ func MakeGenesisBlock(ctx context.Context, rep repo.Repo, bs bstore.Blockstore, tickBuf := make([]byte, 32) _, _ = rand.Read(tickBuf) - genesisticket := types.Ticket{ + genesisticket := &types.Ticket{ VRFProof: tickBuf, } @@ -634,7 +634,7 @@ func MakeGenesisBlock(ctx context.Context, rep repo.Repo, bs bstore.Blockstore, b := &types.BlockHeader{ Miner: system.Address, Ticket: genesisticket, - Parents: types.NewTipSetKey(filecoinGenesisCid), + Parents: types.NewTipSetKey(filecoinGenesisCid).Cids(), Height: 0, ParentWeight: types.NewInt(0), ParentStateRoot: stateroot, @@ -644,7 +644,7 @@ func MakeGenesisBlock(ctx context.Context, rep repo.Repo, bs bstore.Blockstore, BlockSig: nil, Timestamp: template.Timestamp, ElectionProof: new(types.ElectionProof), - BeaconEntries: []*types.BeaconEntry{ + BeaconEntries: []types.BeaconEntry{ { Round: 0, Data: make([]byte, 32), diff --git a/pkg/gen/genesis/miners.go b/pkg/gen/genesis/miners.go index dfeadeaf6b..d63d40809f 100644 --- a/pkg/gen/genesis/miners.go +++ b/pkg/gen/genesis/miners.go @@ -19,7 +19,6 @@ import ( "github.com/filecoin-project/venus/venus-shared/actors/policy" "github.com/filecoin-project/venus/venus-shared/actors/adt" - types2 "github.com/filecoin-project/venus/venus-shared/chain" "github.com/filecoin-project/go-state-types/network" @@ -50,12 +49,12 @@ import ( "github.com/filecoin-project/venus/pkg/consensusfault" "github.com/filecoin-project/venus/pkg/fork" "github.com/filecoin-project/venus/pkg/state/tree" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/util/ffiwrapper/impl" "github.com/filecoin-project/venus/pkg/vm" "github.com/filecoin-project/venus/pkg/vm/gas" "github.com/filecoin-project/venus/pkg/vm/vmcontext" "github.com/filecoin-project/venus/pkg/vmsupport" + types "github.com/filecoin-project/venus/venus-shared/chain" ) func MinerAddress(genesisIndex uint64) address.Address { @@ -179,7 +178,7 @@ func SetupStorageMiners(ctx context.Context, cs *chain.Store, sroot cid.Cid, min return cid.Undef, xerrors.New("actor not found") } - mst, err := miner.Load(adt.WrapStore(ctx, cst), (*types2.Actor)(mact)) + mst, err := miner.Load(adt.WrapStore(ctx, cst), mact) if err != nil { return cid.Undef, xerrors.Errorf("getting newly created miner state: %w", err) } @@ -287,7 +286,7 @@ func SetupStorageMiners(ctx context.Context, cs *chain.Store, sroot cid.Cid, min return cid.Undef, xerrors.New("power actor not exist") } - pst, err := power.Load(adt.WrapStore(ctx, cst), (*types2.Actor)(pact)) + pst, err := power.Load(adt.WrapStore(ctx, cst), pact) if err != nil { return cid.Undef, xerrors.Errorf("getting power state: %w", err) } @@ -370,7 +369,7 @@ func SetupStorageMiners(ctx context.Context, cs *chain.Store, sroot cid.Cid, min return cid.Undef, xerrors.New("power actor not exist") } - pst, err := power.Load(adt.WrapStore(ctx, cst), (*types2.Actor)(pact)) + pst, err := power.Load(adt.WrapStore(ctx, cst), pact) if err != nil { return cid.Undef, xerrors.Errorf("getting power state: %w", err) } @@ -477,7 +476,7 @@ func SetupStorageMiners(ctx context.Context, cs *chain.Store, sroot cid.Cid, min return cid.Undef, xerrors.New("actor not found") } - mst, err := miner.Load(adt.WrapStore(ctx, cst), (*types2.Actor)(mact)) + mst, err := miner.Load(adt.WrapStore(ctx, cst), mact) if err != nil { return cid.Undef, xerrors.Errorf("getting miner state: %w", err) } @@ -515,7 +514,7 @@ func SetupStorageMiners(ctx context.Context, cs *chain.Store, sroot cid.Cid, min return cid.Undef, xerrors.New("actor not found") } - pst, err := power.Load(adt.WrapStore(ctx, cst), (*types2.Actor)(pact)) + pst, err := power.Load(adt.WrapStore(ctx, cst), pact) if err != nil { return cid.Undef, xerrors.Errorf("getting power state: %w", err) } diff --git a/pkg/gen/genesis/util.go b/pkg/gen/genesis/util.go index fb68840879..4fdf2ccffc 100644 --- a/pkg/gen/genesis/util.go +++ b/pkg/gen/genesis/util.go @@ -9,9 +9,9 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/vm" "github.com/filecoin-project/venus/venus-shared/actors" + types "github.com/filecoin-project/venus/venus-shared/chain" ) func mustEnc(i cbg.CBORMarshaler) []byte { @@ -32,7 +32,7 @@ func doExecValue(ctx context.Context, vmi vm.Interpreter, to, from address.Addre return nil, xerrors.Errorf("actor (%s) not found", from) } - ret, err := vmi.ApplyImplicitMessage(&types.UnsignedMessage{ + ret, err := vmi.ApplyImplicitMessage(&types.Message{ To: to, From: from, Method: method, @@ -49,5 +49,5 @@ func doExecValue(ctx context.Context, vmi vm.Interpreter, to, from address.Addre return nil, xerrors.Errorf("failed to call method: %w", ret.Receipt.String()) } - return ret.Receipt.ReturnValue, nil + return ret.Receipt.Return, nil } diff --git a/pkg/genesis/genesis.go b/pkg/genesis/genesis.go index f0204272d5..7987c86b1d 100644 --- a/pkg/genesis/genesis.go +++ b/pkg/genesis/genesis.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "github.com/filecoin-project/venus/pkg/types" "io/ioutil" "os" @@ -31,6 +30,7 @@ import ( "github.com/filecoin-project/venus/pkg/state/tree" "github.com/filecoin-project/venus/pkg/util/blockstoreutil" "github.com/filecoin-project/venus/pkg/vm" + types "github.com/filecoin-project/venus/venus-shared/chain" ) var glog = logging.Logger("genesis") diff --git a/pkg/genesis/init.go b/pkg/genesis/init.go index a14ea831df..7c2b4f66c8 100644 --- a/pkg/genesis/init.go +++ b/pkg/genesis/init.go @@ -3,9 +3,10 @@ package genesis import ( "context" "encoding/json" + "github.com/filecoin-project/venus/pkg/chain" "github.com/filecoin-project/venus/pkg/config" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" bstore "github.com/ipfs/go-ipfs-blockstore" cbor "github.com/ipfs/go-ipld-cbor" @@ -23,7 +24,7 @@ func Init(ctx context.Context, r repo.Repo, bs bstore.Blockstore, cst cbor.IpldS if err != nil { return nil, err } - genTipSet, err := types.NewTipSet(genesis) + genTipSet, err := types.NewTipSet([]*types.BlockHeader{genesis}) if err != nil { return nil, errors.Wrap(err, "failed to generate genesis block") } diff --git a/pkg/market/fmgr.go b/pkg/market/fmgr.go index 5b4d32a7e2..771fbd2a54 100644 --- a/pkg/market/fmgr.go +++ b/pkg/market/fmgr.go @@ -2,19 +2,20 @@ package market import ( "context" + "github.com/filecoin-project/venus/app/client/apiface" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/venus/app/submodule/apitypes" - "github.com/filecoin-project/venus/pkg/types" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" "github.com/ipfs/go-cid" ) // fundManagerAPI is the specific methods called by the FundManager // (used by the tests) type fundManager interface { - MpoolPushMessage(context.Context, *types.UnsignedMessage, *types.MessageSendSpec) (*types.SignedMessage, error) + MpoolPushMessage(context.Context, *types.Message, *apitypes.MessageSendSpec) (*types.SignedMessage, error) StateMarketBalance(context.Context, address.Address, types.TipSetKey) (apitypes.MarketBalance, error) StateWaitMsg(ctx context.Context, c cid.Cid, confidence uint64, limit abi.ChainEpoch, allowReplaced bool) (*apitypes.MsgLookup, error) } @@ -35,7 +36,7 @@ func newFundmanager(p *FundManagerParams) fundManager { return fmAPI } -func (o *fmgr) MpoolPushMessage(ctx context.Context, msg *types.UnsignedMessage, spec *types.MessageSendSpec) (*types.SignedMessage, error) { +func (o *fmgr) MpoolPushMessage(ctx context.Context, msg *types.Message, spec *apitypes.MessageSendSpec) (*types.SignedMessage, error) { return o.MPoolAPI.MpoolPushMessage(ctx, msg, spec) } diff --git a/pkg/market/fundmanager.go b/pkg/market/fundmanager.go index b530068e5a..5e2cc99549 100644 --- a/pkg/market/fundmanager.go +++ b/pkg/market/fundmanager.go @@ -10,9 +10,9 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/venus/pkg/constants" "github.com/filecoin-project/venus/pkg/repo" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/venus-shared/actors" "github.com/filecoin-project/venus/venus-shared/actors/builtin/market" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" @@ -667,7 +667,7 @@ func (env *fundManagerEnvironment) AddFunds( return cid.Undef, err } - smsg, aerr := env.api.MpoolPushMessage(ctx, &types.UnsignedMessage{ + smsg, aerr := env.api.MpoolPushMessage(ctx, &types.Message{ To: market.Address, From: wallet, Value: amt, @@ -695,7 +695,7 @@ func (env *fundManagerEnvironment) WithdrawFunds( return cid.Undef, xerrors.Errorf("serializing params: %w", err) } - smsg, aerr := env.api.MpoolPushMessage(ctx, &types.UnsignedMessage{ + smsg, aerr := env.api.MpoolPushMessage(ctx, &types.Message{ To: market.Address, From: wallet, Value: big.NewInt(0), diff --git a/pkg/market/fundmanager_test.go b/pkg/market/fundmanager_test.go index d6c67bf2ad..71c055caeb 100644 --- a/pkg/market/fundmanager_test.go +++ b/pkg/market/fundmanager_test.go @@ -4,15 +4,14 @@ import ( "bytes" "context" - "github.com/filecoin-project/venus/app/submodule/apitypes" - "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/venus/pkg/config" tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" "github.com/filecoin-project/venus/pkg/wallet" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/stretchr/testify/assert" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/venus-shared/actors/builtin/market" "github.com/ipfs/go-datastore" @@ -654,7 +653,7 @@ func setup(t *testing.T) *scaffold { } } -func checkAddMessageFields(t *testing.T, msg *types.UnsignedMessage, from address.Address, to address.Address, amt abi.TokenAmount) { +func checkAddMessageFields(t *testing.T, msg *types.Message, from address.Address, to address.Address, amt abi.TokenAmount) { require.Equal(t, from, msg.From) require.Equal(t, market.Address, msg.To) require.Equal(t, amt, msg.Value) @@ -665,7 +664,7 @@ func checkAddMessageFields(t *testing.T, msg *types.UnsignedMessage, from addres require.Equal(t, to, paramsTo) } -func checkWithdrawMessageFields(t *testing.T, msg *types.UnsignedMessage, from address.Address, addr address.Address, amt abi.TokenAmount) { +func checkWithdrawMessageFields(t *testing.T, msg *types.Message, from address.Address, addr address.Address, amt abi.TokenAmount) { require.Equal(t, from, msg.From) require.Equal(t, market.Address, msg.To) require.Equal(t, abi.NewTokenAmount(0), msg.Value) @@ -702,7 +701,7 @@ func newMockFundManagerAPI(wallet address.Address) *mockFundManagerAPI { } } -func (mapi *mockFundManagerAPI) MpoolPushMessage(ctx context.Context, msg *types.UnsignedMessage, spec *types.MessageSendSpec) (*types.SignedMessage, error) { +func (mapi *mockFundManagerAPI) MpoolPushMessage(ctx context.Context, msg *types.Message, spec *apitypes.MessageSendSpec) (*types.SignedMessage, error) { mapi.lk.Lock() defer mapi.lk.Unlock() @@ -713,7 +712,7 @@ func (mapi *mockFundManagerAPI) MpoolPushMessage(ctx context.Context, msg *types return smsg, nil } -func (mapi *mockFundManagerAPI) getSentMessage(c cid.Cid) *types.UnsignedMessage { +func (mapi *mockFundManagerAPI) getSentMessage(c cid.Cid) *types.Message { mapi.lk.Lock() defer mapi.lk.Unlock() @@ -814,8 +813,8 @@ func (mapi *mockFundManagerAPI) StateWaitMsg(ctx context.Context, c cid.Cid, con res := &apitypes.MsgLookup{ Message: c, Receipt: types.MessageReceipt{ - ExitCode: 0, - ReturnValue: nil, + ExitCode: 0, + Return: nil, }, } ready := make(chan struct{}) diff --git a/pkg/messagepool/check.go b/pkg/messagepool/check.go index 250cda67bc..718d6cab41 100644 --- a/pkg/messagepool/check.go +++ b/pkg/messagepool/check.go @@ -10,16 +10,16 @@ import ( "github.com/filecoin-project/go-state-types/big" "golang.org/x/xerrors" - "github.com/filecoin-project/venus/app/submodule/apitypes" "github.com/filecoin-project/venus/pkg/constants" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/vm/gas" + types "github.com/filecoin-project/venus/venus-shared/chain" + "github.com/filecoin-project/venus/venus-shared/messagepool" ) var baseFeeUpperBoundFactor = types.NewInt(10) // CheckMessages performs a set of logic checks for a list of messages, prior to submitting it to the mpool -func (mp *MessagePool) CheckMessages(ctx context.Context, protos []*apitypes.MessagePrototype) ([][]apitypes.MessageCheckStatus, error) { +func (mp *MessagePool) CheckMessages(ctx context.Context, protos []*messagepool.MessagePrototype) ([][]messagepool.MessageCheckStatus, error) { flex := make([]bool, len(protos)) msgs := make([]*types.Message, len(protos)) for i, p := range protos { @@ -30,7 +30,7 @@ func (mp *MessagePool) CheckMessages(ctx context.Context, protos []*apitypes.Mes } // CheckPendingMessages performs a set of logical sets for all messages pending from a given actor -func (mp *MessagePool) CheckPendingMessages(ctx context.Context, from address.Address) ([][]apitypes.MessageCheckStatus, error) { +func (mp *MessagePool) CheckPendingMessages(ctx context.Context, from address.Address) ([][]messagepool.MessageCheckStatus, error) { var msgs []*types.Message mp.lk.Lock() mset, ok := mp.pending[from] @@ -54,7 +54,7 @@ func (mp *MessagePool) CheckPendingMessages(ctx context.Context, from address.Ad // CheckReplaceMessages performs a set of logical checks for related messages while performing a // replacement. -func (mp *MessagePool) CheckReplaceMessages(ctx context.Context, replace []*types.Message) ([][]apitypes.MessageCheckStatus, error) { +func (mp *MessagePool) CheckReplaceMessages(ctx context.Context, replace []*types.Message) ([][]messagepool.MessageCheckStatus, error) { msgMap := make(map[address.Address]map[uint64]*types.Message) count := 0 @@ -99,7 +99,7 @@ func (mp *MessagePool) CheckReplaceMessages(ctx context.Context, replace []*type // flexibleNonces should be either nil or of len(msgs), it signifies that message at given index // has non-determied nonce at this point -func (mp *MessagePool) checkMessages(ctx context.Context, msgs []*types.Message, interned bool, flexibleNonces []bool) (result [][]apitypes.MessageCheckStatus, err error) { +func (mp *MessagePool) checkMessages(ctx context.Context, msgs []*types.Message, interned bool, flexibleNonces []bool) (result [][]messagepool.MessageCheckStatus, err error) { if mp.api.IsLite() { return nil, nil } @@ -130,14 +130,14 @@ func (mp *MessagePool) checkMessages(ctx context.Context, msgs []*types.Message, state := make(map[address.Address]*actorState) balances := make(map[address.Address]big.Int) - result = make([][]apitypes.MessageCheckStatus, len(msgs)) + result = make([][]messagepool.MessageCheckStatus, len(msgs)) for i, m := range msgs { // pre-check: actor nonce - check := apitypes.MessageCheckStatus{ + check := messagepool.MessageCheckStatus{ Cid: m.Cid(), - CheckStatus: apitypes.CheckStatus{ - Code: apitypes.CheckStatusMessageGetStateNonce, + CheckStatus: messagepool.CheckStatus{ + Code: messagepool.CheckStatusMessageGetStateNonce, }, } @@ -184,10 +184,10 @@ func (mp *MessagePool) checkMessages(ctx context.Context, msgs []*types.Message, } // pre-check: actor balance - check = apitypes.MessageCheckStatus{ + check = messagepool.MessageCheckStatus{ Cid: m.Cid(), - CheckStatus: apitypes.CheckStatus{ - Code: apitypes.CheckStatusMessageGetStateBalance, + CheckStatus: messagepool.CheckStatus{ + Code: messagepool.CheckStatusMessageGetStateBalance, }, } @@ -218,10 +218,10 @@ func (mp *MessagePool) checkMessages(ctx context.Context, msgs []*types.Message, } // 1. Serialization - check = apitypes.MessageCheckStatus{ + check = messagepool.MessageCheckStatus{ Cid: m.Cid(), - CheckStatus: apitypes.CheckStatus{ - Code: apitypes.CheckStatusMessageSerialize, + CheckStatus: messagepool.CheckStatus{ + Code: messagepool.CheckStatusMessageSerialize, }, } @@ -236,10 +236,10 @@ func (mp *MessagePool) checkMessages(ctx context.Context, msgs []*types.Message, result[i] = append(result[i], check) // 2. Message size - check = apitypes.MessageCheckStatus{ + check = messagepool.MessageCheckStatus{ Cid: m.Cid(), - CheckStatus: apitypes.CheckStatus{ - Code: apitypes.CheckStatusMessageSize, + CheckStatus: messagepool.CheckStatus{ + Code: messagepool.CheckStatusMessageSize, }, } @@ -253,10 +253,10 @@ func (mp *MessagePool) checkMessages(ctx context.Context, msgs []*types.Message, result[i] = append(result[i], check) // 3. Syntactic validation - check = apitypes.MessageCheckStatus{ + check = messagepool.MessageCheckStatus{ Cid: m.Cid(), - CheckStatus: apitypes.CheckStatus{ - Code: apitypes.CheckStatusMessageValidity, + CheckStatus: messagepool.CheckStatus{ + Code: messagepool.CheckStatusMessageValidity, }, } @@ -278,10 +278,10 @@ func (mp *MessagePool) checkMessages(ctx context.Context, msgs []*types.Message, // 4. Min Gas minGas := gas.NewPricesSchedule(mp.forkParams).PricelistByEpoch(epoch).OnChainMessage(m.ChainLength()) - check = apitypes.MessageCheckStatus{ + check = messagepool.MessageCheckStatus{ Cid: m.Cid(), - CheckStatus: apitypes.CheckStatus{ - Code: apitypes.CheckStatusMessageMinGas, + CheckStatus: messagepool.CheckStatus{ + Code: messagepool.CheckStatusMessageMinGas, Hint: map[string]interface{}{ "minGas": minGas, }, @@ -298,10 +298,10 @@ func (mp *MessagePool) checkMessages(ctx context.Context, msgs []*types.Message, result[i] = append(result[i], check) // 5. Min Base Fee - check = apitypes.MessageCheckStatus{ + check = messagepool.MessageCheckStatus{ Cid: m.Cid(), - CheckStatus: apitypes.CheckStatus{ - Code: apitypes.CheckStatusMessageMinBaseFee, + CheckStatus: messagepool.CheckStatus{ + Code: messagepool.CheckStatusMessageMinBaseFee, }, } @@ -318,10 +318,10 @@ func (mp *MessagePool) checkMessages(ctx context.Context, msgs []*types.Message, } // 6. Base Fee - check = apitypes.MessageCheckStatus{ + check = messagepool.MessageCheckStatus{ Cid: m.Cid(), - CheckStatus: apitypes.CheckStatus{ - Code: apitypes.CheckStatusMessageBaseFee, + CheckStatus: messagepool.CheckStatus{ + Code: messagepool.CheckStatusMessageBaseFee, Hint: map[string]interface{}{ "baseFee": baseFee, }, @@ -338,10 +338,10 @@ func (mp *MessagePool) checkMessages(ctx context.Context, msgs []*types.Message, result[i] = append(result[i], check) // 7. Base Fee lower bound - check = apitypes.MessageCheckStatus{ + check = messagepool.MessageCheckStatus{ Cid: m.Cid(), - CheckStatus: apitypes.CheckStatus{ - Code: apitypes.CheckStatusMessageBaseFeeLowerBound, + CheckStatus: messagepool.CheckStatus{ + Code: messagepool.CheckStatusMessageBaseFeeLowerBound, Hint: map[string]interface{}{ "baseFeeLowerBound": baseFeeLowerBound, "baseFee": baseFee, @@ -359,10 +359,10 @@ func (mp *MessagePool) checkMessages(ctx context.Context, msgs []*types.Message, result[i] = append(result[i], check) // 8. Base Fee upper bound - check = apitypes.MessageCheckStatus{ + check = messagepool.MessageCheckStatus{ Cid: m.Cid(), - CheckStatus: apitypes.CheckStatus{ - Code: apitypes.CheckStatusMessageBaseFeeUpperBound, + CheckStatus: messagepool.CheckStatus{ + Code: messagepool.CheckStatusMessageBaseFeeUpperBound, Hint: map[string]interface{}{ "baseFeeUpperBound": baseFeeUpperBound, "baseFee": baseFee, @@ -382,10 +382,10 @@ func (mp *MessagePool) checkMessages(ctx context.Context, msgs []*types.Message, // stateful checks checkState: // 9. Message Nonce - check = apitypes.MessageCheckStatus{ + check = messagepool.MessageCheckStatus{ Cid: m.Cid(), - CheckStatus: apitypes.CheckStatus{ - Code: apitypes.CheckStatusMessageNonce, + CheckStatus: messagepool.CheckStatus{ + Code: messagepool.CheckStatusMessageNonce, Hint: map[string]interface{}{ "nextNonce": st.nextNonce, }, @@ -407,10 +407,10 @@ func (mp *MessagePool) checkMessages(ctx context.Context, msgs []*types.Message, st.requiredFunds.Add(st.requiredFunds, m.Value.Int) // 10. Balance - check = apitypes.MessageCheckStatus{ + check = messagepool.MessageCheckStatus{ Cid: m.Cid(), - CheckStatus: apitypes.CheckStatus{ - Code: apitypes.CheckStatusMessageBalance, + CheckStatus: messagepool.CheckStatus{ + Code: messagepool.CheckStatusMessageBalance, Hint: map[string]interface{}{ "requiredFunds": big.Int{Int: stdbig.NewInt(0).Set(st.requiredFunds)}, }, diff --git a/pkg/messagepool/gas.go b/pkg/messagepool/gas.go index fe718a5ab6..17a9384250 100644 --- a/pkg/messagepool/gas.go +++ b/pkg/messagepool/gas.go @@ -16,10 +16,11 @@ import ( "github.com/filecoin-project/venus/pkg/constants" "github.com/filecoin-project/venus/pkg/fork" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/vm" "github.com/filecoin-project/venus/venus-shared/actors/builtin" "github.com/filecoin-project/venus/venus-shared/actors/builtin/paych" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" ) const MinGasPremium = 100e3 @@ -73,7 +74,7 @@ func (g *GasPriceCache) GetTSGasStats(provider Provider, ts *types.TipSet) ([]Ga func (mp *MessagePool) GasEstimateFeeCap( ctx context.Context, - msg *types.UnsignedMessage, + msg *types.Message, maxqueueblks int64, tsk types.TipSetKey, ) (big.Int, error) { @@ -183,7 +184,7 @@ func (mp *MessagePool) GasEstimateGasPremium( return premium, nil } -func (mp *MessagePool) GasEstimateGasLimit(ctx context.Context, msgIn *types.UnsignedMessage, tsk types.TipSetKey) (int64, error) { +func (mp *MessagePool) GasEstimateGasLimit(ctx context.Context, msgIn *types.Message, tsk types.TipSetKey) (int64, error) { if tsk.IsEmpty() { ts, err := mp.api.ChainHead() if err != nil { @@ -272,7 +273,7 @@ func (mp *MessagePool) evalMessageGasLimit(ctx context.Context, msgIn *types.Mes return res.Receipt.GasUsed + 76e3, nil } -func (mp *MessagePool) GasEstimateMessageGas(ctx context.Context, estimateMessage *types.EstimateMessage, _ types.TipSetKey) (*types.Message, error) { +func (mp *MessagePool) GasEstimateMessageGas(ctx context.Context, estimateMessage *apitypes.EstimateMessage, _ types.TipSetKey) (*types.Message, error) { if estimateMessage == nil || estimateMessage.Msg == nil { return nil, xerrors.Errorf("estimate message is nil") } @@ -309,7 +310,7 @@ func (mp *MessagePool) GasEstimateMessageGas(ctx context.Context, estimateMessag return estimateMessage.Msg, nil } -func (mp *MessagePool) GasBatchEstimateMessageGas(ctx context.Context, estimateMessages []*types.EstimateMessage, fromNonce uint64, tsk types.TipSetKey) ([]*types.EstimateResult, error) { +func (mp *MessagePool) GasBatchEstimateMessageGas(ctx context.Context, estimateMessages []*apitypes.EstimateMessage, fromNonce uint64, tsk types.TipSetKey) ([]*apitypes.EstimateResult, error) { if len(estimateMessages) == 0 { return nil, xerrors.New("estimate messages are empty") } @@ -331,7 +332,7 @@ func (mp *MessagePool) GasBatchEstimateMessageGas(ctx context.Context, estimateM priorMsgs = append(priorMsgs, m) } - var estimateResults []*types.EstimateResult + var estimateResults []*apitypes.EstimateResult for _, estimateMessage := range estimateMessages { estimateMsg := estimateMessage.Msg estimateMsg.Nonce = fromNonce @@ -345,7 +346,7 @@ func (mp *MessagePool) GasBatchEstimateMessageGas(ctx context.Context, estimateM gasUsed, err := mp.evalMessageGasLimit(ctx, estimateMsg, priorMsgs, ts) if err != nil { estimateMsg.Nonce = 0 - estimateResults = append(estimateResults, &types.EstimateResult{ + estimateResults = append(estimateResults, &apitypes.EstimateResult{ Msg: estimateMsg, Err: fmt.Sprintf("estimating gas limit: %v", err), }) @@ -358,7 +359,7 @@ func (mp *MessagePool) GasBatchEstimateMessageGas(ctx context.Context, estimateM gasPremium, err := mp.GasEstimateGasPremium(ctx, 10, estimateMsg.From, estimateMsg.GasLimit, types.TipSetKey{}, mp.PriceCache) if err != nil { estimateMsg.Nonce = 0 - estimateResults = append(estimateResults, &types.EstimateResult{ + estimateResults = append(estimateResults, &apitypes.EstimateResult{ Msg: estimateMsg, Err: fmt.Sprintf("estimating gas premium: %v", err), }) @@ -371,7 +372,7 @@ func (mp *MessagePool) GasBatchEstimateMessageGas(ctx context.Context, estimateM feeCap, err := mp.GasEstimateFeeCap(ctx, estimateMsg, 20, types.EmptyTSK) if err != nil { estimateMsg.Nonce = 0 - estimateResults = append(estimateResults, &types.EstimateResult{ + estimateResults = append(estimateResults, &apitypes.EstimateResult{ Msg: estimateMsg, Err: fmt.Sprintf("estimating fee cap: %v", err), }) @@ -382,7 +383,7 @@ func (mp *MessagePool) GasBatchEstimateMessageGas(ctx context.Context, estimateM CapGasFee(mp.GetMaxFee, estimateMsg, estimateMessage.Spec) - estimateResults = append(estimateResults, &types.EstimateResult{ + estimateResults = append(estimateResults, &apitypes.EstimateResult{ Msg: estimateMsg, }) priorMsgs = append(priorMsgs, estimateMsg) diff --git a/pkg/messagepool/gasguess/guessgas.go b/pkg/messagepool/gasguess/guessgas.go index b0b06dabda..966b500691 100644 --- a/pkg/messagepool/gasguess/guessgas.go +++ b/pkg/messagepool/gasguess/guessgas.go @@ -6,8 +6,8 @@ import ( "github.com/ipfs/go-cid" "golang.org/x/xerrors" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/venus-shared/actors/builtin" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" diff --git a/pkg/messagepool/messagepool.go b/pkg/messagepool/messagepool.go index d3f8ed9608..6938953f5c 100644 --- a/pkg/messagepool/messagepool.go +++ b/pkg/messagepool/messagepool.go @@ -5,7 +5,6 @@ import ( "context" "errors" "fmt" - "github.com/filecoin-project/venus/pkg/statemanger" "math" stdbig "math/big" "os" @@ -38,22 +37,13 @@ import ( "github.com/filecoin-project/venus/pkg/messagepool/journal" "github.com/filecoin-project/venus/pkg/net/msgsub" "github.com/filecoin-project/venus/pkg/repo" - "github.com/filecoin-project/venus/pkg/types" + "github.com/filecoin-project/venus/pkg/statemanger" "github.com/filecoin-project/venus/pkg/vm/gas" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" + mptypes "github.com/filecoin-project/venus/venus-shared/messagepool" ) -type MpoolChange int - -const ( - MpoolAdd MpoolChange = iota - MpoolRemove -) - -type MpoolUpdate struct { - Type MpoolChange - Message *types.SignedMessage -} - var log = logging.Logger("messagepool") var futureDebug = false @@ -116,7 +106,7 @@ type MessagePoolEvt struct { // nolint } type MessagePoolEvtMessage struct { // nolint - types.UnsignedMessage + types.Message CID cid.Cid } @@ -216,7 +206,7 @@ func ComputeMinRBF(curPrem abi.TokenAmount) abi.TokenAmount { return big.Add(minPrice, big.NewInt(1)) } -func CapGasFee(mff DefaultMaxFeeFunc, msg *types.Message, sendSepc *types.MessageSendSpec) { +func CapGasFee(mff DefaultMaxFeeFunc, msg *types.Message, sendSepc *apitypes.MessageSendSpec) { var maxFee abi.TokenAmount if sendSepc != nil { maxFee = sendSepc.MaxFee @@ -1027,8 +1017,8 @@ func (mp *MessagePool) addLocked(ctx context.Context, m *types.SignedMessage, st } } - mp.changes.Pub(MpoolUpdate{ - Type: MpoolAdd, + mp.changes.Pub(mptypes.MpoolUpdate{ + Type: mptypes.MpoolAdd, Message: m, }, localUpdates) @@ -1036,7 +1026,7 @@ func (mp *MessagePool) addLocked(ctx context.Context, m *types.SignedMessage, st mc := m.Cid() return MessagePoolEvt{ Action: "add", - Messages: []MessagePoolEvtMessage{{UnsignedMessage: m.Message, CID: mc}}, + Messages: []MessagePoolEvtMessage{{Message: m.Message, CID: mc}}, } }) @@ -1163,15 +1153,15 @@ func (mp *MessagePool) remove(ctx context.Context, from address.Address, nonce u } if m, ok := mset.msgs[nonce]; ok { - mp.changes.Pub(MpoolUpdate{ - Type: MpoolRemove, + mp.changes.Pub(mptypes.MpoolUpdate{ + Type: mptypes.MpoolRemove, Message: m, }, localUpdates) mp.journal.RecordEvent(mp.evtTypes[evtTypeMpoolRemove], func() interface{} { return MessagePoolEvt{ Action: "remove", - Messages: []MessagePoolEvtMessage{{UnsignedMessage: m.Message, CID: m.Cid()}}} + Messages: []MessagePoolEvtMessage{{Message: m.Message, CID: m.Cid()}}} }) mp.currentSize-- @@ -1499,7 +1489,7 @@ func (mp *MessagePool) MessagesForBlocks(blks []*types.BlockHeader) ([]*types.Si return out, nil } -func (mp *MessagePool) RecoverSig(msg *types.UnsignedMessage) *types.SignedMessage { +func (mp *MessagePool) RecoverSig(msg *types.Message) *types.SignedMessage { val, ok := mp.blsSigCache.Get(msg.Cid()) if !ok { return nil @@ -1516,8 +1506,8 @@ func (mp *MessagePool) RecoverSig(msg *types.UnsignedMessage) *types.SignedMessa } } -func (mp *MessagePool) Updates(ctx context.Context) (<-chan MpoolUpdate, error) { - out := make(chan MpoolUpdate, 20) +func (mp *MessagePool) Updates(ctx context.Context) (<-chan mptypes.MpoolUpdate, error) { + out := make(chan mptypes.MpoolUpdate, 20) sub := mp.changes.Sub(localUpdates) go func() { @@ -1528,7 +1518,7 @@ func (mp *MessagePool) Updates(ctx context.Context) (<-chan MpoolUpdate, error) select { case u := <-sub: select { - case out <- u.(MpoolUpdate): + case out <- u.(mptypes.MpoolUpdate): case <-ctx.Done(): return case <-mp.closer: diff --git a/pkg/messagepool/messagepool_test.go b/pkg/messagepool/messagepool_test.go index 3effda2392..c17216e280 100644 --- a/pkg/messagepool/messagepool_test.go +++ b/pkg/messagepool/messagepool_test.go @@ -23,8 +23,9 @@ import ( "github.com/filecoin-project/venus/pkg/messagepool/gasguess" "github.com/filecoin-project/venus/pkg/repo" tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/wallet" + types "github.com/filecoin-project/venus/venus-shared/chain" + wtypes "github.com/filecoin-project/venus/venus-shared/wallet" ) func init() { @@ -54,7 +55,7 @@ func mkAddress(i uint64) address.Address { } func mkMessage(from, to address.Address, nonce uint64, w *wallet.Wallet) *types.SignedMessage { - msg := &types.UnsignedMessage{ + msg := &types.Message{ To: to, From: from, Value: tbig.NewInt(1), @@ -65,7 +66,7 @@ func mkMessage(from, to address.Address, nonce uint64, w *wallet.Wallet) *types. } c := msg.Cid() - sig, err := w.WalletSign(from, c.Bytes(), wallet.MsgMeta{}) + sig, err := w.WalletSign(from, c.Bytes(), wtypes.MsgMeta{}) if err != nil { panic(err) } @@ -105,10 +106,10 @@ func mkBlock(parents *types.TipSet, weightInc int64, ticketNonce uint64) *types. ElectionProof: &types.ElectionProof{ VRFProof: []byte(fmt.Sprintf("====%d=====", ticketNonce)), }, - Ticket: types.Ticket{ + Ticket: &types.Ticket{ VRFProof: []byte(fmt.Sprintf("====%d=====", ticketNonce)), }, - Parents: tsKey, + Parents: tsKey.Cids(), ParentMessageReceipts: c, BLSAggregate: &crypto.Signature{Type: crypto.SigTypeBLS, Data: []byte("boo! im a signature")}, ParentWeight: weight, @@ -122,7 +123,7 @@ func mkBlock(parents *types.TipSet, weightInc int64, ticketNonce uint64) *types. } func mkTipSet(blks ...*types.BlockHeader) *types.TipSet { - ts, err := types.NewTipSet(blks...) + ts, err := types.NewTipSet(blks) if err != nil { panic(err) } @@ -173,7 +174,7 @@ func (tma *testMpoolAPI) setStateNonce(addr address.Address, v uint64) { } func (tma *testMpoolAPI) setBalance(addr address.Address, v uint64) { - tma.balance[addr] = types.NewAttoFILFromFIL(v) + tma.balance[addr] = types.FromFil(v) } func (tma *testMpoolAPI) setBalanceRaw(addr address.Address, v tbig.Int) { @@ -265,7 +266,7 @@ func (tma *testMpoolAPI) StateAccountKey(ctx context.Context, addr address.Addre return addr, nil } -func (tma *testMpoolAPI) MessagesForBlock(h *types.BlockHeader) ([]*types.UnsignedMessage, []*types.SignedMessage, error) { +func (tma *testMpoolAPI) MessagesForBlock(h *types.BlockHeader) ([]*types.Message, []*types.SignedMessage, error) { return nil, tma.bmsgs[h.Cid()], nil } @@ -404,7 +405,7 @@ func TestCheckMessageBig(t *testing.T) { Params: make([]byte, 41<<10), // 41KiB payload } - sig, err := w.WalletSign(from, msg.Cid().Bytes(), wallet.MsgMeta{}) + sig, err := w.WalletSign(from, msg.Cid().Bytes(), wtypes.MsgMeta{}) if err != nil { panic(err) } @@ -427,7 +428,7 @@ func TestCheckMessageBig(t *testing.T) { Params: make([]byte, 64<<10), // 64KiB payload } - sig, err := w.WalletSign(from, msg.Cid().Bytes(), wallet.MsgMeta{}) + sig, err := w.WalletSign(from, msg.Cid().Bytes(), wtypes.MsgMeta{}) if err != nil { panic(err) } diff --git a/pkg/messagepool/messagesigner.go b/pkg/messagepool/messagesigner.go index 5de818a9d7..32ee6643d9 100644 --- a/pkg/messagepool/messagesigner.go +++ b/pkg/messagepool/messagesigner.go @@ -6,6 +6,8 @@ import ( "sync" "github.com/filecoin-project/venus/pkg/wallet" + types "github.com/filecoin-project/venus/venus-shared/chain" + mptypes "github.com/filecoin-project/venus/venus-shared/wallet" "github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore/namespace" @@ -13,8 +15,6 @@ import ( "golang.org/x/xerrors" "github.com/filecoin-project/go-address" - - "github.com/filecoin-project/venus/pkg/types" ) const dsKeyActorNonce = "ActorNextNonce" @@ -62,8 +62,8 @@ func (ms *MessageSigner) SignMessage(ctx context.Context, msg *types.Message, cb return nil, xerrors.Errorf("serializing message: %w", err) } - sig, err := ms.wallet.WalletSign(msg.From, mb.Cid().Bytes(), wallet.MsgMeta{ - Type: wallet.MTChainMsg, + sig, err := ms.wallet.WalletSign(msg.From, mb.Cid().Bytes(), mptypes.MsgMeta{ + Type: mptypes.MTChainMsg, Extra: mb.RawData(), }) if err != nil { diff --git a/pkg/messagepool/messagesigner_test.go b/pkg/messagepool/messagesigner_test.go index 05906f6ebd..94a876f30c 100644 --- a/pkg/messagepool/messagesigner_test.go +++ b/pkg/messagepool/messagesigner_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/filecoin-project/venus/pkg/repo" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/stretchr/testify/assert" "golang.org/x/xerrors" @@ -19,7 +20,6 @@ import ( "github.com/filecoin-project/go-address" tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" - "github.com/filecoin-project/venus/pkg/types" "github.com/ipfs/go-datastore" _ "github.com/filecoin-project/venus/pkg/crypto/bls" diff --git a/pkg/messagepool/provider.go b/pkg/messagepool/provider.go index 765a0a5376..67e93abcf2 100644 --- a/pkg/messagepool/provider.go +++ b/pkg/messagepool/provider.go @@ -9,8 +9,8 @@ import ( "github.com/filecoin-project/venus/pkg/chain" "github.com/filecoin-project/venus/pkg/config" "github.com/filecoin-project/venus/pkg/statemanger" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/venus-shared/actors/policy" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/ipfs/go-cid" pubsub "github.com/libp2p/go-libp2p-pubsub" "golang.org/x/xerrors" @@ -31,7 +31,7 @@ type Provider interface { GetActorAfter(address.Address, *types.TipSet) (*types.Actor, error) StateAccountKeyAtFinality(context.Context, address.Address, *types.TipSet) (address.Address, error) StateAccountKey(context.Context, address.Address, *types.TipSet) (address.Address, error) - MessagesForBlock(block2 *types.BlockHeader) ([]*types.UnsignedMessage, []*types.SignedMessage, error) + MessagesForBlock(block2 *types.BlockHeader) ([]*types.Message, []*types.SignedMessage, error) MessagesForTipset(*types.TipSet) ([]types.ChainMsg, error) LoadTipSet(tsk types.TipSetKey) (*types.TipSet, error) ChainComputeBaseFee(ctx context.Context, ts *types.TipSet) (tbig.Int, error) @@ -137,7 +137,7 @@ func (mpp *mpoolProvider) StateAccountKey(ctx context.Context, addr address.Addr return mpp.stmgr.ResolveToKeyAddress(ctx, addr, ts) } -func (mpp *mpoolProvider) MessagesForBlock(h *types.BlockHeader) ([]*types.UnsignedMessage, []*types.SignedMessage, error) { +func (mpp *mpoolProvider) MessagesForBlock(h *types.BlockHeader) ([]*types.Message, []*types.SignedMessage, error) { secpMsgs, blsMsgs, err := mpp.cms.LoadMetaMessages(context.TODO(), h.Messages) return blsMsgs, secpMsgs, err } diff --git a/pkg/messagepool/pruning.go b/pkg/messagepool/pruning.go index f46fd32733..f0380897c6 100644 --- a/pkg/messagepool/pruning.go +++ b/pkg/messagepool/pruning.go @@ -6,10 +6,9 @@ import ( "time" "github.com/filecoin-project/go-address" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/ipfs/go-cid" "golang.org/x/xerrors" - - "github.com/filecoin-project/venus/pkg/types" ) func (mp *MessagePool) pruneExcessMessages() error { diff --git a/pkg/messagepool/repub.go b/pkg/messagepool/repub.go index 772619fd41..927b483b70 100644 --- a/pkg/messagepool/repub.go +++ b/pkg/messagepool/repub.go @@ -13,7 +13,7 @@ import ( "github.com/filecoin-project/venus/pkg/constants" "github.com/filecoin-project/venus/pkg/messagepool/gasguess" "github.com/filecoin-project/venus/pkg/net/msgsub" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" ) const repubMsgLimit = 30 @@ -154,7 +154,7 @@ LOOP: mp.journal.RecordEvent(mp.evtTypes[evtTypeMpoolRepub], func() interface{} { msgsEv := make([]MessagePoolEvtMessage, 0, len(msgs)) for _, m := range msgs { - msgsEv = append(msgsEv, MessagePoolEvtMessage{UnsignedMessage: m.Message, CID: m.Cid()}) + msgsEv = append(msgsEv, MessagePoolEvtMessage{Message: m.Message, CID: m.Cid()}) } return MessagePoolEvt{ Action: "repub", diff --git a/pkg/messagepool/selection.go b/pkg/messagepool/selection.go index 22f16a9afe..f43504cc25 100644 --- a/pkg/messagepool/selection.go +++ b/pkg/messagepool/selection.go @@ -13,7 +13,7 @@ import ( tbig "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/venus/pkg/constants" "github.com/filecoin-project/venus/pkg/messagepool/gasguess" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" ) var bigBlockGasLimit = big.NewInt(constants.BlockGasLimit) diff --git a/pkg/messagepool/selection_test.go b/pkg/messagepool/selection_test.go index 581d40bc72..813780d2da 100644 --- a/pkg/messagepool/selection_test.go +++ b/pkg/messagepool/selection_test.go @@ -25,8 +25,9 @@ import ( "github.com/filecoin-project/venus/pkg/config" "github.com/filecoin-project/venus/pkg/constants" "github.com/filecoin-project/venus/pkg/messagepool/gasguess" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/wallet" + types "github.com/filecoin-project/venus/venus-shared/chain" + mtypes "github.com/filecoin-project/venus/venus-shared/wallet" _ "github.com/filecoin-project/venus/pkg/crypto/secp" @@ -41,11 +42,11 @@ func init() { const UpgradeBreezeHeight = 41280 func makeTestMessage(w *wallet.Wallet, from, to address.Address, nonce uint64, gasLimit int64, gasPrice uint64) *types.SignedMessage { - msg := &types.UnsignedMessage{ + msg := &types.Message{ From: from, To: to, Method: 2, - Value: types.NewAttoFILFromFIL(0), + Value: types.FromFil(0), Nonce: nonce, GasLimit: gasLimit, GasFeeCap: tbig.NewInt(int64(100) + int64(gasPrice)), @@ -53,7 +54,7 @@ func makeTestMessage(w *wallet.Wallet, from, to address.Address, nonce uint64, g } c := msg.Cid() - sig, err := w.WalletSign(from, c.Bytes(), wallet.MsgMeta{}) + sig, err := w.WalletSign(from, c.Bytes(), mtypes.MsgMeta{}) if err != nil { panic(err) } @@ -1235,7 +1236,7 @@ func TestGasReward(t *testing.T) { test := test t.Run(fmt.Sprintf("%v", test), func(t *testing.T) { msg := &types.SignedMessage{ - Message: types.UnsignedMessage{ + Message: types.Message{ GasLimit: 10, GasFeeCap: tbig.NewInt(int64(test.FeeCap)), GasPremium: tbig.NewInt(int64(test.Premium)), @@ -1250,7 +1251,7 @@ func TestGasReward(t *testing.T) { } type SignedMessage struct { - Message types.UnsignedMessage + Message types.Message Signature crypto.Signature } @@ -1330,7 +1331,7 @@ readLoop: m.Message.Nonce -= baseNonce c := m.Message.Cid() - sig, err := w.WalletSign(localActor, c.Bytes(), wallet.MsgMeta{}) + sig, err := w.WalletSign(localActor, c.Bytes(), mtypes.MsgMeta{}) if err != nil { t.Fatal(err) } diff --git a/pkg/metrics/heartbeat.go b/pkg/metrics/heartbeat.go index 12bab5ef9f..96425943ec 100644 --- a/pkg/metrics/heartbeat.go +++ b/pkg/metrics/heartbeat.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "github.com/filecoin-project/venus/pkg/types" "sync" "time" @@ -20,6 +19,7 @@ import ( "github.com/ipfs/go-cid" "github.com/filecoin-project/venus/pkg/config" + types "github.com/filecoin-project/venus/venus-shared/chain" ) // HeartbeatProtocol is the libp2p protocol used for the heartbeat service diff --git a/pkg/metrics/heartbeat_test.go b/pkg/metrics/heartbeat_test.go index c872de0ae3..1526c69d67 100644 --- a/pkg/metrics/heartbeat_test.go +++ b/pkg/metrics/heartbeat_test.go @@ -7,7 +7,9 @@ import ( "fmt" "testing" - emptycid "github.com/filecoin-project/venus/pkg/testhelpers/empty_cid" + "github.com/filecoin-project/venus/pkg/testhelpers" + + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/filecoin-project/go-state-types/abi" "github.com/stretchr/testify/assert" @@ -26,7 +28,6 @@ import ( "github.com/filecoin-project/venus/pkg/config" "github.com/filecoin-project/venus/pkg/metrics" tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" - "github.com/filecoin-project/venus/pkg/types" ) var testCid cid.Cid @@ -188,16 +189,16 @@ func TestHeartbeatRunSuccess(t *testing.T) { } func mustMakeTipset(t *testing.T, height abi.ChainEpoch) *types.TipSet { - ts, err := types.NewTipSet(&types.BlockHeader{ - Miner: types.NewForTestGetter()(), - Ticket: types.Ticket{VRFProof: []byte{0}}, - Parents: types.TipSetKey{}, + ts, err := types.NewTipSet([]*types.BlockHeader{{ + Miner: testhelpers.NewForTestGetter()(), + Ticket: &types.Ticket{VRFProof: []byte{0}}, + Parents: types.TipSetKey{}.Cids(), ParentWeight: fbig.Zero(), Height: height, - ParentMessageReceipts: emptycid.EmptyMessagesCID, - Messages: emptycid.EmptyTxMetaCID, - ParentStateRoot: emptycid.EmptyTxMetaCID, - }) + ParentMessageReceipts: testhelpers.EmptyMessagesCID, + Messages: testhelpers.EmptyTxMetaCID, + ParentStateRoot: testhelpers.EmptyTxMetaCID, + }}) if err != nil { t.Fatal(err) } diff --git a/pkg/net/blocksub/validator.go b/pkg/net/blocksub/validator.go index b41f10aefa..0107b06c40 100644 --- a/pkg/net/blocksub/validator.go +++ b/pkg/net/blocksub/validator.go @@ -3,12 +3,13 @@ package blocksub import ( "bytes" "context" - "github.com/filecoin-project/venus/pkg/types" + "github.com/ipfs/go-log/v2" "github.com/libp2p/go-libp2p-core/peer" pubsub "github.com/libp2p/go-libp2p-pubsub" "github.com/filecoin-project/venus/pkg/metrics" + types "github.com/filecoin-project/venus/venus-shared/chain" ) var blockTopicLogger = log.Logger("net/block_validator") diff --git a/pkg/net/blocksub/validator_test.go b/pkg/net/blocksub/validator_test.go index 194a22fcdd..4f45bc7bdc 100644 --- a/pkg/net/blocksub/validator_test.go +++ b/pkg/net/blocksub/validator_test.go @@ -4,18 +4,19 @@ import ( "bytes" "context" "fmt" + "testing" + "github.com/filecoin-project/go-address" - "github.com/filecoin-project/venus/pkg/types" pubsub "github.com/libp2p/go-libp2p-pubsub" pubsubpb "github.com/libp2p/go-libp2p-pubsub/pb" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "testing" "github.com/filecoin-project/venus/pkg/chain" "github.com/filecoin-project/venus/pkg/net/blocksub" th "github.com/filecoin-project/venus/pkg/testhelpers" tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" + types "github.com/filecoin-project/venus/venus-shared/chain" ) func TestBlockTopicValidator(t *testing.T) { diff --git a/pkg/net/msgsub/validator.go b/pkg/net/msgsub/validator.go index d15f300833..f8e42f8d44 100644 --- a/pkg/net/msgsub/validator.go +++ b/pkg/net/msgsub/validator.go @@ -6,11 +6,11 @@ import ( logging "github.com/ipfs/go-log" "github.com/libp2p/go-libp2p-core/peer" - "github.com/libp2p/go-libp2p-pubsub" + pubsub "github.com/libp2p/go-libp2p-pubsub" "github.com/filecoin-project/venus/pkg/consensus" "github.com/filecoin-project/venus/pkg/metrics" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" ) var messageTopicLogger = logging.Logger("net/message_validator") diff --git a/pkg/paychmgr/manager.go b/pkg/paychmgr/manager.go index f753336e92..053c84e372 100644 --- a/pkg/paychmgr/manager.go +++ b/pkg/paychmgr/manager.go @@ -6,7 +6,7 @@ import ( "sync" "github.com/filecoin-project/venus/pkg/statemanger" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/filecoin-project/go-state-types/big" "github.com/ipfs/go-cid" diff --git a/pkg/paychmgr/mock_test.go b/pkg/paychmgr/mock_test.go index a0a50799c7..0c765f252d 100644 --- a/pkg/paychmgr/mock_test.go +++ b/pkg/paychmgr/mock_test.go @@ -7,8 +7,9 @@ import ( crypto2 "github.com/filecoin-project/venus/pkg/crypto" "github.com/filecoin-project/venus/pkg/vm" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" - "github.com/filecoin-project/venus/pkg/chain" "github.com/filecoin-project/venus/pkg/constants" "github.com/filecoin-project/venus/venus-shared/actors/builtin/market" @@ -18,7 +19,6 @@ import ( "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/go-state-types/network" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/venus-shared/actors/builtin/paych" ) @@ -48,7 +48,7 @@ type mockStateManager struct { accountState map[address.Address]address.Address paychState map[address.Address]mockPchState response *vm.Ret - lastCall *types.UnsignedMessage + lastCall *types.Message } func newMockStateManager() *mockStateManager { @@ -97,14 +97,14 @@ func (sm *mockStateManager) setCallResponse(response *vm.Ret) { sm.response = response } -func (sm *mockStateManager) getLastCall() *types.UnsignedMessage { +func (sm *mockStateManager) getLastCall() *types.Message { sm.lk.Lock() defer sm.lk.Unlock() return sm.lastCall } -func (sm *mockStateManager) Call(ctx context.Context, msg *types.UnsignedMessage, ts *types.TipSet) (*vm.Ret, error) { +func (sm *mockStateManager) Call(ctx context.Context, msg *types.Message, ts *types.TipSet) (*vm.Ret, error) { sm.lk.Lock() defer sm.lk.Unlock() @@ -140,7 +140,7 @@ func newMockPaychAPI() *mockPaychAPI { } } -func (pchapi *mockPaychAPI) StateWaitMsg(ctx context.Context, mcid cid.Cid, confidence uint64) (*chain.MsgLookup, error) { +func (pchapi *mockPaychAPI) StateWaitMsg(ctx context.Context, mcid cid.Cid, confidence uint64) (*apitypes.MsgLookup, error) { pchapi.lk.Lock() response := make(chan types.MessageReceipt) @@ -151,14 +151,14 @@ func (pchapi *mockPaychAPI) StateWaitMsg(ctx context.Context, mcid cid.Cid, conf }() delete(pchapi.waitingResponses, mcid) - return &chain.MsgLookup{Receipt: response.receipt}, nil + return &apitypes.MsgLookup{Receipt: response.receipt}, nil } pchapi.waitingCalls[mcid] = &waitingCall{response: response} pchapi.lk.Unlock() receipt := <-response - return &chain.MsgLookup{Receipt: receipt}, nil + return &apitypes.MsgLookup{Receipt: receipt}, nil } func (pchapi *mockPaychAPI) receiveMsgResponse(mcid cid.Cid, receipt types.MessageReceipt) { @@ -186,8 +186,8 @@ func (pchapi *mockPaychAPI) close() { defer pchapi.lk.Unlock() success := types.MessageReceipt{ - ExitCode: 0, - ReturnValue: []byte{}, + ExitCode: 0, + Return: []byte{}, } for mcid, call := range pchapi.waitingCalls { delete(pchapi.waitingCalls, mcid) @@ -195,7 +195,7 @@ func (pchapi *mockPaychAPI) close() { } } -func (pchapi *mockPaychAPI) MpoolPushMessage(ctx context.Context, msg *types.UnsignedMessage, spec *types.MessageSendSpec) (*types.SignedMessage, error) { +func (pchapi *mockPaychAPI) MpoolPushMessage(ctx context.Context, msg *types.Message, spec *apitypes.MessageSendSpec) (*types.SignedMessage, error) { pchapi.lk.Lock() defer pchapi.lk.Unlock() diff --git a/pkg/paychmgr/paych.go b/pkg/paychmgr/paych.go index e8117a0fa3..70bcbabb47 100644 --- a/pkg/paychmgr/paych.go +++ b/pkg/paychmgr/paych.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/filecoin-project/venus/pkg/crypto" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/ipfs/go-cid" "golang.org/x/xerrors" @@ -321,7 +321,7 @@ func (ca *channelAccessor) checkVoucherSpendable(ctx context.Context, ch address return false, err } - ret, err := ca.api.Call(ctx, (*types.UnsignedMessage)(mes), nil) + ret, err := ca.api.Call(ctx, mes, nil) if err != nil { return false, err } @@ -438,7 +438,7 @@ func (ca *channelAccessor) submitVoucher(ctx context.Context, ch address.Address return cid.Undef, err } - smsg, err := ca.api.MpoolPushMessage(ctx, (*types.UnsignedMessage)(msg), nil) + smsg, err := ca.api.MpoolPushMessage(ctx, msg, nil) if err != nil { return cid.Undef, err } @@ -594,7 +594,7 @@ func (ca *channelAccessor) settle(ctx context.Context, ch address.Address) (cid. if err != nil { return cid.Undef, err } - smgs, err := ca.api.MpoolPushMessage(ctx, (*types.UnsignedMessage)(msg), nil) + smgs, err := ca.api.MpoolPushMessage(ctx, msg, nil) if err != nil { return cid.Undef, err } @@ -626,7 +626,7 @@ func (ca *channelAccessor) collect(ctx context.Context, ch address.Address) (cid return cid.Undef, err } - smsg, err := ca.api.MpoolPushMessage(ctx, (*types.UnsignedMessage)(msg), nil) + smsg, err := ca.api.MpoolPushMessage(ctx, msg, nil) if err != nil { return cid.Undef, err } diff --git a/pkg/paychmgr/paych_test.go b/pkg/paychmgr/paych_test.go index e42c7006f0..c1c56a2162 100644 --- a/pkg/paychmgr/paych_test.go +++ b/pkg/paychmgr/paych_test.go @@ -8,6 +8,7 @@ import ( crypto2 "github.com/filecoin-project/venus/pkg/crypto" tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" "github.com/filecoin-project/venus/pkg/vm" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/ipfs/go-cid" ds "github.com/ipfs/go-datastore" @@ -24,7 +25,6 @@ import ( _ "github.com/filecoin-project/venus/pkg/crypto/bls" _ "github.com/filecoin-project/venus/pkg/crypto/secp" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/venus-shared/actors/builtin/paych" paychmock "github.com/filecoin-project/venus/venus-shared/actors/builtin/paych/mock" ) diff --git a/pkg/paychmgr/paychget_test.go b/pkg/paychmgr/paychget_test.go index 5894296fc5..68c8bc4762 100644 --- a/pkg/paychmgr/paychget_test.go +++ b/pkg/paychmgr/paychget_test.go @@ -7,6 +7,7 @@ import ( "time" tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" + types "github.com/filecoin-project/venus/venus-shared/chain" cborrpc "github.com/filecoin-project/go-cbor-util" "github.com/ipfs/go-cid" @@ -23,7 +24,6 @@ import ( _ "github.com/filecoin-project/venus/pkg/crypto/bls" _ "github.com/filecoin-project/venus/pkg/crypto/secp" - "github.com/filecoin-project/venus/pkg/types" lotusinit "github.com/filecoin-project/venus/venus-shared/actors/builtin/init" "github.com/filecoin-project/venus/venus-shared/actors/builtin/paych" paychmock "github.com/filecoin-project/venus/venus-shared/actors/builtin/paych/mock" @@ -37,8 +37,8 @@ func testChannelResponse(t *testing.T, ch address.Address) types.MessageReceipt createChannelRetBytes, err := cborrpc.Dump(&createChannelRet) require.NoError(t, err) createChannelResponse := types.MessageReceipt{ - ExitCode: 0, - ReturnValue: createChannelRetBytes, + ExitCode: 0, + Return: createChannelRetBytes, } return createChannelResponse } @@ -185,8 +185,8 @@ func TestPaychGetCreateChannelWithErrorThenCreateAgain(t *testing.T) { // 1. Set up create channel response (sent in response to WaitForMsg()) // This response indicates an error. errResponse := types.MessageReceipt{ - ExitCode: 1, // error - ReturnValue: []byte{}, + ExitCode: 1, // error + Return: []byte{}, } done := make(chan struct{}) @@ -250,8 +250,8 @@ func TestPaychGetRecoverAfterError(t *testing.T) { // Send error create channel response mock.receiveMsgResponse(mcid, types.MessageReceipt{ - ExitCode: 1, // error - ReturnValue: []byte{}, + ExitCode: 1, // error + Return: []byte{}, }) // Send create message for a channel again @@ -312,8 +312,8 @@ func TestPaychGetRecoverAfterAddFundsError(t *testing.T) { // Send error add funds response mock.receiveMsgResponse(mcid2, types.MessageReceipt{ - ExitCode: 1, // error - ReturnValue: []byte{}, + ExitCode: 1, // error + Return: []byte{}, }) _, err = mgr.GetPaychWaitReady(ctx, mcid2) @@ -339,8 +339,8 @@ func TestPaychGetRecoverAfterAddFundsError(t *testing.T) { // Send success add funds response mock.receiveMsgResponse(mcid3, types.MessageReceipt{ - ExitCode: 0, - ReturnValue: []byte{}, + ExitCode: 0, + Return: []byte{}, }) _, err = mgr.GetPaychWaitReady(ctx, mcid3) @@ -484,8 +484,8 @@ func TestPaychGetRestartAfterAddFundsMsg(t *testing.T) { // Send success add funds response mock2.receiveMsgResponse(mcid2, types.MessageReceipt{ - ExitCode: 0, - ReturnValue: []byte{}, + ExitCode: 0, + Return: []byte{}, }) _, err = mgr2.GetPaychWaitReady(ctx, mcid2) @@ -553,8 +553,8 @@ func TestPaychGetWait(t *testing.T) { go func() { // 6. Send add funds response addFundsResponse := types.MessageReceipt{ - ExitCode: 0, - ReturnValue: []byte{}, + ExitCode: 0, + Return: []byte{}, } mock.receiveMsgResponse(addFundsMsgCid, addFundsResponse) }() @@ -604,8 +604,8 @@ func TestPaychGetWaitErr(t *testing.T) { // 3. Send error response to create channel response := types.MessageReceipt{ - ExitCode: 1, // error - ReturnValue: []byte{}, + ExitCode: 1, // error + Return: []byte{}, } mock.receiveMsgResponse(mcid, response) @@ -714,8 +714,8 @@ func TestPaychGetMergeAddFunds(t *testing.T) { // Send success add funds response mock.receiveMsgResponse(addFundsMcid1, types.MessageReceipt{ - ExitCode: 0, - ReturnValue: []byte{}, + ExitCode: 0, + Return: []byte{}, }) // Wait for add funds response @@ -812,8 +812,8 @@ func TestPaychGetMergeAddFundsCtxCancelOne(t *testing.T) { // Send success add funds response mock.receiveMsgResponse(addFundsMcid2, types.MessageReceipt{ - ExitCode: 0, - ReturnValue: []byte{}, + ExitCode: 0, + Return: []byte{}, }) // Wait for add funds response @@ -1027,8 +1027,8 @@ func TestPaychAvailableFunds(t *testing.T) { // Send success add funds response mock.receiveMsgResponse(addFundsMcid, types.MessageReceipt{ - ExitCode: 0, - ReturnValue: []byte{}, + ExitCode: 0, + Return: []byte{}, }) // Wait for add funds response diff --git a/pkg/paychmgr/paychvoucherfunds_test.go b/pkg/paychmgr/paychvoucherfunds_test.go index 3d191378ce..2bbab71cef 100644 --- a/pkg/paychmgr/paychvoucherfunds_test.go +++ b/pkg/paychmgr/paychvoucherfunds_test.go @@ -5,7 +5,7 @@ import ( "testing" tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" diff --git a/pkg/paychmgr/pcapi.go b/pkg/paychmgr/pcapi.go index 3161e844c5..96bad8a6a7 100644 --- a/pkg/paychmgr/pcapi.go +++ b/pkg/paychmgr/pcapi.go @@ -2,33 +2,31 @@ package paychmgr import ( "context" - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/venus/app/submodule/apitypes" - "github.com/filecoin-project/venus/pkg/chain" - - "github.com/ipfs/go-cid" "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/network" + "github.com/ipfs/go-cid" "github.com/filecoin-project/venus/pkg/constants" "github.com/filecoin-project/venus/pkg/crypto" - "github.com/filecoin-project/venus/pkg/types" - "github.com/filecoin-project/venus/pkg/wallet" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" + wallettypes "github.com/filecoin-project/venus/venus-shared/wallet" ) // paychDependencyAPI defines the API methods needed by the payment channel manager type paychDependencyAPI interface { StateAccountKey(context.Context, address.Address, types.TipSetKey) (address.Address, error) - StateWaitMsg(ctx context.Context, msg cid.Cid, confidence uint64) (*chain.MsgLookup, error) + StateWaitMsg(ctx context.Context, msg cid.Cid, confidence uint64) (*apitypes.MsgLookup, error) WalletHas(ctx context.Context, addr address.Address) (bool, error) WalletSign(ctx context.Context, k address.Address, msg []byte) (*crypto.Signature, error) StateNetworkVersion(context.Context, types.TipSetKey) (network.Version, error) - MpoolPushMessage(ctx context.Context, msg *types.UnsignedMessage, maxFee *types.MessageSendSpec) (*types.SignedMessage, error) + MpoolPushMessage(ctx context.Context, msg *types.Message, maxFee *apitypes.MessageSendSpec) (*types.SignedMessage, error) } type IMessagePush interface { - MpoolPushMessage(ctx context.Context, msg *types.UnsignedMessage, spec *types.MessageSendSpec) (*types.SignedMessage, error) + MpoolPushMessage(ctx context.Context, msg *types.Message, spec *apitypes.MessageSendSpec) (*types.SignedMessage, error) } type IChainInfo interface { @@ -39,7 +37,7 @@ type IChainInfo interface { type IWalletAPI interface { WalletHas(ctx context.Context, addr address.Address) (bool, error) - WalletSign(ctx context.Context, k address.Address, msg []byte, meta wallet.MsgMeta) (*crypto.Signature, error) + WalletSign(ctx context.Context, k address.Address, msg []byte, meta wallettypes.MsgMeta) (*crypto.Signature, error) } type pcAPI struct { mpAPI IMessagePush @@ -54,17 +52,17 @@ func newPaychDependencyAPI(mpAPI IMessagePush, c IChainInfo, w IWalletAPI) paych func (o *pcAPI) StateAccountKey(ctx context.Context, address address.Address, tsk types.TipSetKey) (address.Address, error) { return o.chainInfoAPI.StateAccountKey(ctx, address, tsk) } -func (o *pcAPI) StateWaitMsg(ctx context.Context, msg cid.Cid, confidence uint64) (*chain.MsgLookup, error) { +func (o *pcAPI) StateWaitMsg(ctx context.Context, msg cid.Cid, confidence uint64) (*apitypes.MsgLookup, error) { return o.chainInfoAPI.StateWaitMsg(ctx, msg, confidence, constants.LookbackNoLimit, true) } -func (o *pcAPI) MpoolPushMessage(ctx context.Context, msg *types.UnsignedMessage, maxFee *types.MessageSendSpec) (*types.SignedMessage, error) { +func (o *pcAPI) MpoolPushMessage(ctx context.Context, msg *types.Message, maxFee *apitypes.MessageSendSpec) (*types.SignedMessage, error) { return o.mpAPI.MpoolPushMessage(ctx, msg, maxFee) } func (o *pcAPI) WalletHas(ctx context.Context, addr address.Address) (bool, error) { return o.walletAPI.WalletHas(ctx, addr) } func (o *pcAPI) WalletSign(ctx context.Context, k address.Address, msg []byte) (*crypto.Signature, error) { - return o.walletAPI.WalletSign(ctx, k, msg, wallet.MsgMeta{Type: wallet.MTSignedVoucher}) + return o.walletAPI.WalletSign(ctx, k, msg, wallettypes.MsgMeta{Type: wallettypes.MTSignedVoucher}) } func (o *pcAPI) StateNetworkVersion(ctx context.Context, ts types.TipSetKey) (network.Version, error) { return o.chainInfoAPI.StateNetworkVersion(ctx, ts) diff --git a/pkg/paychmgr/settler/settler.go b/pkg/paychmgr/settler/settler.go index 05fa6709fd..8e0eb74064 100644 --- a/pkg/paychmgr/settler/settler.go +++ b/pkg/paychmgr/settler/settler.go @@ -6,11 +6,12 @@ import ( "github.com/filecoin-project/venus/pkg/constants" "github.com/filecoin-project/venus/pkg/events" + types "github.com/filecoin-project/venus/venus-shared/chain" + paychtypes "github.com/filecoin-project/venus/venus-shared/paych" "github.com/filecoin-project/venus/pkg/paychmgr" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/venus-shared/actors/builtin/paych" "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log/v2" @@ -24,9 +25,9 @@ type API struct { } type PaymentChannelSettler interface { check(ts *types.TipSet) (done bool, more bool, err error) - messageHandler(msg *types.UnsignedMessage, rec *types.MessageReceipt, ts *types.TipSet, curH abi.ChainEpoch) (more bool, err error) + messageHandler(msg *types.Message, rec *types.MessageReceipt, ts *types.TipSet, curH abi.ChainEpoch) (more bool, err error) revertHandler(ctx context.Context, ts *types.TipSet) error - matcher(msg *types.UnsignedMessage) (matched bool, err error) + matcher(msg *types.Message) (matched bool, err error) } type paymentChannelSettler struct { ctx context.Context @@ -44,7 +45,7 @@ func (pcs *paymentChannelSettler) check(ts *types.TipSet) (done bool, more bool, return false, true, nil } -func (pcs *paymentChannelSettler) messageHandler(msg *types.UnsignedMessage, rec *types.MessageReceipt, ts *types.TipSet, curH abi.ChainEpoch) (more bool, err error) { +func (pcs *paymentChannelSettler) messageHandler(msg *types.Message, rec *types.MessageReceipt, ts *types.TipSet, curH abi.ChainEpoch) (more bool, err error) { // Ignore unsuccessful settle messages if rec.ExitCode != 0 { return true, nil @@ -80,7 +81,7 @@ func (pcs *paymentChannelSettler) revertHandler(ctx context.Context, ts *types.T return nil } -func (pcs *paymentChannelSettler) matcher(msg *types.UnsignedMessage) (matched bool, err error) { +func (pcs *paymentChannelSettler) matcher(msg *types.Message) (matched bool, err error) { // Check if this is a settle payment channel message if msg.Method != paych.Methods.Settle { return false, nil @@ -97,7 +98,7 @@ func (pcs *paymentChannelSettler) matcher(msg *types.UnsignedMessage) (matched b if err != nil { return false, err } - if status.Direction == types.PCHInbound { + if status.Direction == paychtypes.PCHInbound { return true, nil } } diff --git a/pkg/paychmgr/settler/stl.go b/pkg/paychmgr/settler/stl.go index f1a4cdb7eb..4a14b7b73f 100644 --- a/pkg/paychmgr/settler/stl.go +++ b/pkg/paychmgr/settler/stl.go @@ -3,23 +3,23 @@ package settler import ( "context" - "github.com/filecoin-project/venus/pkg/chain" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + paychtypes "github.com/filecoin-project/venus/venus-shared/paych" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/venus/pkg/paychmgr" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/venus-shared/actors/builtin/paych" "github.com/ipfs/go-cid" ) type Settler interface { PaychList(context.Context) ([]address.Address, error) - PaychStatus(ctx context.Context, pch address.Address) (*types.PaychStatus, error) + PaychStatus(ctx context.Context, pch address.Address) (*paychtypes.Status, error) PaychVoucherCheckSpendable(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (bool, error) PaychVoucherList(context.Context, address.Address) ([]*paych.SignedVoucher, error) PaychVoucherSubmit(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error) - StateWaitMsg(ctx context.Context, cid cid.Cid, confidence uint64, limit abi.ChainEpoch, allowReplaced bool) (*chain.MsgLookup, error) + StateWaitMsg(ctx context.Context, cid cid.Cid, confidence uint64, limit abi.ChainEpoch, allowReplaced bool) (*apitypes.MsgLookup, error) } type settler struct { @@ -35,14 +35,14 @@ func (o *settler) PaychList(context.Context) ([]address.Address, error) { return o.mgr.ListChannels() } -func (o *settler) PaychStatus(ctx context.Context, pch address.Address) (*types.PaychStatus, error) { +func (o *settler) PaychStatus(ctx context.Context, pch address.Address) (*paychtypes.Status, error) { ci, err := o.mgr.GetChannelInfo(pch) if err != nil { return nil, err } - return &types.PaychStatus{ + return &paychtypes.Status{ ControlAddr: ci.Control, - Direction: types.PCHDir(ci.Direction), + Direction: paychtypes.PCHDir(ci.Direction), }, nil } func (o *settler) PaychVoucherCheckSpendable(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (bool, error) { @@ -63,6 +63,6 @@ func (o *settler) PaychVoucherList(ctx context.Context, pch address.Address) ([] func (o *settler) PaychVoucherSubmit(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error) { return o.mgr.SubmitVoucher(ctx, ch, sv, secret, proof) } -func (o *settler) StateWaitMsg(ctx context.Context, cid cid.Cid, confidence uint64, lookbackLimit abi.ChainEpoch, allowReplaced bool) (*chain.MsgLookup, error) { +func (o *settler) StateWaitMsg(ctx context.Context, cid cid.Cid, confidence uint64, lookbackLimit abi.ChainEpoch, allowReplaced bool) (*apitypes.MsgLookup, error) { return o.ciAPI.StateWaitMsg(ctx, cid, confidence, lookbackLimit, allowReplaced) } diff --git a/pkg/paychmgr/simple.go b/pkg/paychmgr/simple.go index f8dd71ce12..01d0de0521 100644 --- a/pkg/paychmgr/simple.go +++ b/pkg/paychmgr/simple.go @@ -16,7 +16,7 @@ import ( init2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/init" "github.com/filecoin-project/venus/pkg/constants" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" ) // paychFundsRes is the response to a create channel or add funds request @@ -386,7 +386,7 @@ func (ca *channelAccessor) createPaych(ctx context.Context, amt big.Int) (cid.Ci return cid.Undef, err } - smsg, err := ca.api.MpoolPushMessage(ctx, (*types.UnsignedMessage)(msg), nil) + smsg, err := ca.api.MpoolPushMessage(ctx, msg, nil) if err != nil { return cid.Undef, xerrors.Errorf("initializing paych actor: %w", err) } @@ -437,7 +437,7 @@ func (ca *channelAccessor) waitPaychCreateMsg(channelID string, mcid cid.Cid) er // This "works" because it hasn't changed from v0 to v2, but we still // need an abstraction here. var decodedReturn init2.ExecReturn - err = decodedReturn.UnmarshalCBOR(bytes.NewReader(mwait.Receipt.ReturnValue)) + err = decodedReturn.UnmarshalCBOR(bytes.NewReader(mwait.Receipt.Return)) if err != nil { log.Error(err) return err @@ -459,7 +459,7 @@ func (ca *channelAccessor) waitPaychCreateMsg(channelID string, mcid cid.Cid) er // addFunds sends a message to add funds to the channel and returns the message cid func (ca *channelAccessor) addFunds(ctx context.Context, channelInfo *ChannelInfo, amt big.Int) (*cid.Cid, error) { - msg := &types.UnsignedMessage{ + msg := &types.Message{ To: *channelInfo.Channel, From: channelInfo.Control, Value: amt, diff --git a/pkg/paychmgr/state.go b/pkg/paychmgr/state.go index cae9357bbf..e770595259 100644 --- a/pkg/paychmgr/state.go +++ b/pkg/paychmgr/state.go @@ -4,10 +4,10 @@ import ( "context" "github.com/filecoin-project/venus/pkg/statemanger" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/filecoin-project/go-address" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/venus-shared/actors/builtin/paych" ) diff --git a/pkg/state/power_table_view.go b/pkg/state/power_table_view.go index e946aedd8a..fc26648f99 100644 --- a/pkg/state/power_table_view.go +++ b/pkg/state/power_table_view.go @@ -7,7 +7,6 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/network" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/util/ffiwrapper" "github.com/filecoin-project/venus/venus-shared/actors/builtin" "github.com/filecoin-project/venus/venus-shared/actors/builtin/miner" @@ -21,11 +20,18 @@ type PowerStateView interface { GetMinerWorkerRaw(ctx context.Context, maddr address.Address) (address.Address, error) MinerInfo(ctx context.Context, maddr address.Address, nv network.Version) (*miner.MinerInfo, error) MinerSectorInfo(ctx context.Context, maddr address.Address, sectorNum abi.SectorNumber) (*miner.SectorOnChainInfo, error) - PowerNetworkTotal(ctx context.Context) (*types.NetworkPower, error) + PowerNetworkTotal(ctx context.Context) (*NetworkPower, error) MinerClaimedPower(ctx context.Context, miner address.Address) (raw, qa abi.StoragePower, err error) GetSectorsForWinningPoSt(ctx context.Context, nv network.Version, pv ffiwrapper.Verifier, maddr address.Address, rand abi.PoStRandomness) ([]builtin.SectorInfo, error) } +type NetworkPower struct { + RawBytePower abi.StoragePower + QualityAdjustedPower abi.StoragePower + MinerCount int64 + MinPowerMinerCount int64 +} + // FaultStateView is a view of chain state for adjustment of miner power claims based on changes since the // power state's lookback (primarily, the miner ceasing to be registered). type FaultStateView interface { diff --git a/pkg/state/power_table_view_test.go b/pkg/state/power_table_view_test.go index 2160210cc5..2be1b96bc8 100644 --- a/pkg/state/power_table_view_test.go +++ b/pkg/state/power_table_view_test.go @@ -4,6 +4,8 @@ import ( "context" "testing" + "github.com/filecoin-project/venus/pkg/testhelpers" + cbor "github.com/ipfs/go-ipld-cbor" "github.com/filecoin-project/go-address" @@ -18,8 +20,8 @@ import ( "github.com/filecoin-project/venus/pkg/repo" "github.com/filecoin-project/venus/pkg/state" tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" - "github.com/filecoin-project/venus/pkg/types" gengen "github.com/filecoin-project/venus/tools/gengen/util" + types "github.com/filecoin-project/venus/venus-shared/chain" ) func TestTotal(t *testing.T) { @@ -30,7 +32,7 @@ func TestTotal(t *testing.T) { ctx := context.Background() numCommittedSectors := uint64(19) numMiners := 3 - kis := types.MustGenerateBLSKeyInfo(numMiners, 0) + kis := testhelpers.MustGenerateBLSKeyInfo(numMiners, 0) cst, _, root := requireMinerWithNumCommittedSectors(ctx, t, numCommittedSectors, kis) @@ -50,7 +52,7 @@ func TestMiner(t *testing.T) { tf.UnitTest(t) ctx := context.Background() - kis := types.MustGenerateBLSKeyInfo(1, 0) + kis := testhelpers.MustGenerateBLSKeyInfo(1, 0) numCommittedSectors := uint64(10) cst, addrs, root := requireMinerWithNumCommittedSectors(ctx, t, numCommittedSectors, kis) @@ -73,7 +75,7 @@ func TestNoPowerAfterSlash(t *testing.T) { ctx := context.Background() numCommittedSectors := uint64(19) numMiners := 3 - kis := types.MustGenerateBLSKeyInfo(numMiners, 0) + kis := testhelpers.MustGenerateBLSKeyInfo(numMiners, 0) cstPower, addrsPower, rootPower := requireMinerWithNumCommittedSectors(ctx, t, numCommittedSectors, kis) cstFaults, _, rootFaults := requireMinerWithNumCommittedSectors(ctx, t, numCommittedSectors, kis[0:2]) // drop the third key table := state.NewPowerTableView(state.NewView(cstPower, rootPower), state.NewView(cstFaults, rootFaults)) @@ -91,7 +93,7 @@ func TestTotalPowerUnaffectedBySlash(t *testing.T) { ctx := context.Background() numCommittedSectors := uint64(19) numMiners := 3 - kis := types.MustGenerateBLSKeyInfo(numMiners, 0) + kis := testhelpers.MustGenerateBLSKeyInfo(numMiners, 0) cstPower, _, rootPower := requireMinerWithNumCommittedSectors(ctx, t, numCommittedSectors, kis) cstFaults, _, rootFaults := requireMinerWithNumCommittedSectors(ctx, t, numCommittedSectors, kis[0:2]) // drop the third key table := state.NewPowerTableView(state.NewView(cstPower, rootPower), state.NewView(cstFaults, rootFaults)) diff --git a/pkg/state/signer.go b/pkg/state/signer.go index eec1376382..05ecfc0d76 100644 --- a/pkg/state/signer.go +++ b/pkg/state/signer.go @@ -2,10 +2,11 @@ package state import ( "context" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/venus/pkg/crypto" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/wallet" + types "github.com/filecoin-project/venus/venus-shared/chain" ) //todo remove Account view a nd headsignerview diff --git a/pkg/state/sigval.go b/pkg/state/sigval.go index 5b85fbbea6..dc2e32b5cc 100644 --- a/pkg/state/sigval.go +++ b/pkg/state/sigval.go @@ -2,11 +2,12 @@ package state import ( "context" + "github.com/filecoin-project/go-address" "github.com/pkg/errors" "github.com/filecoin-project/venus/pkg/crypto" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" ) // @@ -36,7 +37,7 @@ func (v *SignatureValidator) ValidateMessageSignature(ctx context.Context, msg * } //ValidateBLSMessageAggregate validate bls aggregate message -func (v *SignatureValidator) ValidateBLSMessageAggregate(ctx context.Context, msgs []*types.UnsignedMessage, sig *crypto.Signature) error { +func (v *SignatureValidator) ValidateBLSMessageAggregate(ctx context.Context, msgs []*types.Message, sig *crypto.Signature) error { if sig == nil { if len(msgs) > 0 { return errors.New("Invalid empty BLS sig over messages") diff --git a/pkg/state/sigval_test.go b/pkg/state/sigval_test.go index 72cd87ee3c..e3ad14158b 100644 --- a/pkg/state/sigval_test.go +++ b/pkg/state/sigval_test.go @@ -4,16 +4,19 @@ import ( "bytes" "context" "fmt" - "github.com/filecoin-project/venus/pkg/state" "testing" + "github.com/filecoin-project/venus/pkg/testhelpers" + + "github.com/filecoin-project/venus/pkg/state" + types "github.com/filecoin-project/venus/venus-shared/chain" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" - "github.com/filecoin-project/venus/pkg/types" _ "github.com/filecoin-project/venus/pkg/crypto/bls" _ "github.com/filecoin-project/venus/pkg/crypto/secp" @@ -39,25 +42,25 @@ func TestSignMessageOk(t *testing.T) { tf.UnitTest(t) ctx := context.Background() - ms, kis := types.NewMockSignersAndKeyInfo(1) + ms, kis := testhelpers.NewMockSignersAndKeyInfo(1) keyAddr, err := kis[0].Address() require.NoError(t, err) t.Run("no resolution", func(t *testing.T) { v := state.NewSignatureValidator(&fakeStateView{}) // No resolution needed. - msg := types.NewMeteredMessage(keyAddr, keyAddr, 1, types.ZeroFIL, builtin.MethodSend, nil, types.NewAttoFILFromFIL(0), types.NewAttoFILFromFIL(0), 1) - smsg, err := types.NewSignedMessage(ctx, *msg, ms) + msg := testhelpers.NewMeteredMessage(keyAddr, keyAddr, 1, types.ZeroFIL, builtin.MethodSend, nil, types.FromFil(0), types.FromFil(0), 1) + smsg, err := testhelpers.NewSignedMessage(ctx, *msg, ms) require.NoError(t, err) assert.NoError(t, v.ValidateMessageSignature(ctx, smsg)) }) t.Run("resolution required", func(t *testing.T) { - idAddress := types.RequireIDAddress(t, 1) + idAddress := testhelpers.RequireIDAddress(t, 1) // Use ID address in message but sign with corresponding key address. stateView := &fakeStateView{keys: map[address.Address]address.Address{ idAddress: keyAddr, }} v := state.NewSignatureValidator(stateView) - msg := types.NewMeteredMessage(idAddress, idAddress, 1, types.ZeroFIL, builtin.MethodSend, nil, types.NewAttoFILFromFIL(0), types.NewAttoFILFromFIL(0), 1) + msg := testhelpers.NewMeteredMessage(idAddress, idAddress, 1, types.ZeroFIL, builtin.MethodSend, nil, types.FromFil(0), types.FromFil(0), 1) msgCid := msg.Cid() sig, err := ms.SignBytes(ctx, msgCid.Bytes(), keyAddr) require.NoError(t, err) @@ -75,7 +78,7 @@ func TestBadFrom(t *testing.T) { tf.UnitTest(t) ctx := context.Background() - signer, kis := types.NewMockSignersAndKeyInfo(2) + signer, kis := testhelpers.NewMockSignersAndKeyInfo(2) keyAddr, err := kis[0].Address() require.NoError(t, err) otherAddr, err := kis[1].Address() @@ -85,7 +88,7 @@ func TestBadFrom(t *testing.T) { v := state.NewSignatureValidator(&fakeStateView{}) // Can't use NewSignedMessage constructor as it always signs with msg.From. - msg := types.NewMeteredMessage(keyAddr, keyAddr, 1, types.ZeroFIL, builtin.MethodSend, nil, types.NewAttoFILFromFIL(0), types.NewAttoFILFromFIL(0), 1) + msg := testhelpers.NewMeteredMessage(keyAddr, keyAddr, 1, types.ZeroFIL, builtin.MethodSend, nil, types.FromFil(0), types.FromFil(0), 1) buf := new(bytes.Buffer) err = msg.MarshalCBOR(buf) require.NoError(t, err) @@ -98,7 +101,7 @@ func TestBadFrom(t *testing.T) { assert.Error(t, v.ValidateMessageSignature(ctx, smsg)) }) t.Run("resolution required", func(t *testing.T) { - idAddress := types.RequireIDAddress(t, 1) + idAddress := testhelpers.RequireIDAddress(t, 1) // Use ID address in message but sign with corresponding key address. stateView := &fakeStateView{keys: map[address.Address]address.Address{ idAddress: keyAddr, @@ -106,7 +109,7 @@ func TestBadFrom(t *testing.T) { v := state.NewSignatureValidator(stateView) // Can't use NewSignedMessage constructor as it always signs with msg.From. - msg := types.NewMeteredMessage(idAddress, idAddress, 1, types.ZeroFIL, builtin.MethodSend, nil, types.NewAttoFILFromFIL(0), types.NewAttoFILFromFIL(0), 1) + msg := testhelpers.NewMeteredMessage(idAddress, idAddress, 1, types.ZeroFIL, builtin.MethodSend, nil, types.FromFil(0), types.FromFil(0), 1) buf := new(bytes.Buffer) err = msg.MarshalCBOR(buf) require.NoError(t, err) @@ -125,13 +128,13 @@ func TestSignedMessageBadSignature(t *testing.T) { tf.UnitTest(t) ctx := context.Background() - signer, kis := types.NewMockSignersAndKeyInfo(1) + signer, kis := testhelpers.NewMockSignersAndKeyInfo(1) keyAddr, err := kis[0].Address() require.NoError(t, err) v := state.NewSignatureValidator(&fakeStateView{}) // no resolution needed - msg := types.NewMeteredMessage(keyAddr, keyAddr, 1, types.ZeroFIL, builtin.MethodSend, nil, types.NewAttoFILFromFIL(0), types.NewAttoFILFromFIL(0), 1) - smsg, err := types.NewSignedMessage(ctx, *msg, signer) + msg := testhelpers.NewMeteredMessage(keyAddr, keyAddr, 1, types.ZeroFIL, builtin.MethodSend, nil, types.FromFil(0), types.FromFil(0), 1) + smsg, err := testhelpers.NewSignedMessage(ctx, *msg, signer) require.NoError(t, err) assert.NoError(t, v.ValidateMessageSignature(ctx, smsg)) @@ -145,13 +148,13 @@ func TestSignedMessageCorrupted(t *testing.T) { ctx := context.Background() - signer, kis := types.NewMockSignersAndKeyInfo(1) + signer, kis := testhelpers.NewMockSignersAndKeyInfo(1) keyAddr, err := kis[0].Address() require.NoError(t, err) v := state.NewSignatureValidator(&fakeStateView{}) // no resolution needed - msg := types.NewMeteredMessage(keyAddr, keyAddr, 1, types.ZeroFIL, builtin.MethodSend, nil, types.NewAttoFILFromFIL(0), types.NewAttoFILFromFIL(0), 1) - smsg, err := types.NewSignedMessage(ctx, *msg, signer) + msg := testhelpers.NewMeteredMessage(keyAddr, keyAddr, 1, types.ZeroFIL, builtin.MethodSend, nil, types.FromFil(0), types.FromFil(0), 1) + smsg, err := testhelpers.NewSignedMessage(ctx, *msg, signer) require.NoError(t, err) assert.NoError(t, v.ValidateMessageSignature(ctx, smsg)) diff --git a/pkg/state/testing.go b/pkg/state/testing.go index cd607c635e..dabda1c15d 100644 --- a/pkg/state/testing.go +++ b/pkg/state/testing.go @@ -3,8 +3,6 @@ package state import ( "context" - "github.com/filecoin-project/venus/pkg/types" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" @@ -22,14 +20,14 @@ import ( // FakeStateView is a fake state view. type FakeStateView struct { NetworkName string - Power *types.NetworkPower + Power *NetworkPower Miners map[address.Address]*FakeMinerState } // NewFakeStateView creates a new fake state view. func NewFakeStateView(rawBytePower, qaPower abi.StoragePower, minerCount, minPowerMinerCount int64) *FakeStateView { return &FakeStateView{ - Power: &types.NetworkPower{ + Power: &NetworkPower{ RawBytePower: rawBytePower, QualityAdjustedPower: qaPower, MinerCount: minerCount, @@ -100,7 +98,7 @@ func (v *FakeStateView) MinerProvingPeriod(ctx context.Context, maddr address.Ad return m.ProvingPeriodStart, m.ProvingPeriodEnd, m.PoStFailures, nil } -func (v *FakeStateView) PowerNetworkTotal(_ context.Context) (*types.NetworkPower, error) { +func (v *FakeStateView) PowerNetworkTotal(_ context.Context) (*NetworkPower, error) { return v.Power, nil } diff --git a/pkg/state/tree/snapshot.go b/pkg/state/tree/snapshot.go index fc7fb6403b..152c2c9c5c 100644 --- a/pkg/state/tree/snapshot.go +++ b/pkg/state/tree/snapshot.go @@ -2,7 +2,7 @@ package tree import ( "github.com/filecoin-project/go-address" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" ) type stateSnaps struct { diff --git a/pkg/state/tree/state.go b/pkg/state/tree/state.go index a6ba66896a..b692f05dd2 100644 --- a/pkg/state/tree/state.go +++ b/pkg/state/tree/state.go @@ -6,8 +6,6 @@ import ( "fmt" "io" - "github.com/filecoin-project/venus/venus-shared/chain" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/network" @@ -19,15 +17,14 @@ import ( "go.opencensus.io/trace" "golang.org/x/xerrors" - "github.com/filecoin-project/venus/pkg/types" - "github.com/filecoin-project/venus/venus-shared/actors/adt" - init_ "github.com/filecoin-project/venus/venus-shared/actors/builtin/init" - states0 "github.com/filecoin-project/specs-actors/actors/states" states2 "github.com/filecoin-project/specs-actors/v2/actors/states" states3 "github.com/filecoin-project/specs-actors/v3/actors/states" states4 "github.com/filecoin-project/specs-actors/v4/actors/states" states5 "github.com/filecoin-project/specs-actors/v5/actors/states" + "github.com/filecoin-project/venus/venus-shared/actors/adt" + init_ "github.com/filecoin-project/venus/venus-shared/actors/builtin/init" + types "github.com/filecoin-project/venus/venus-shared/chain" ) type StateTreeVersion uint64 //nolint @@ -294,7 +291,7 @@ func (st *State) lookupIDinternal(addr address.Address) (address.Address, error) return address.Undef, xerrors.Errorf("getting init actor: %v", err) } - ias, err := init_.Load(&AdtStore{st.Store}, (*chain.Actor)(act)) + ias, err := init_.Load(&AdtStore{st.Store}, act) if err != nil { return address.Undef, xerrors.Errorf("loading init actor state: %v", err) } @@ -440,7 +437,7 @@ func (st *State) ClearSnapshot() { func (st *State) RegisterNewAddress(addr ActorKey) (address.Address, error) { var out address.Address err := st.MutateActor(init_.Address, func(initact *types.Actor) error { - ias, err := init_.Load(&AdtStore{st.Store}, (*chain.Actor)(initact)) + ias, err := init_.Load(&AdtStore{st.Store}, initact) if err != nil { return err } diff --git a/pkg/state/tree/state_test.go b/pkg/state/tree/state_test.go index a1ab698ae9..936822a81e 100644 --- a/pkg/state/tree/state_test.go +++ b/pkg/state/tree/state_test.go @@ -2,20 +2,21 @@ package tree import ( "context" - cbor "github.com/ipfs/go-ipld-cbor" "testing" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" + "github.com/filecoin-project/venus/pkg/testhelpers" "github.com/ipfs/go-cid" + cbor "github.com/ipfs/go-ipld-cbor" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/filecoin-project/venus/pkg/constants" "github.com/filecoin-project/venus/pkg/repo" tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" ) func TestStatePutGet(t *testing.T) { @@ -30,7 +31,7 @@ func TestStatePutGet(t *testing.T) { t.Fatal(err) } - addrGetter := types.NewForTestGetter() + addrGetter := testhelpers.NewForTestGetter() addr1 := addrGetter() addr2 := addrGetter() AddAccount(t, tree, cst, addr1) @@ -81,7 +82,7 @@ func TestStateErrors(t *testing.T) { t.Fatal(err) } - AddAccount(t, tree, cst, types.NewForTestGetter()()) + AddAccount(t, tree, cst, testhelpers.NewForTestGetter()()) c, err := constants.DefaultCidBuilder.Sum([]byte("cats")) assert.NoError(t, err) @@ -101,7 +102,7 @@ func TestGetAllActors(t *testing.T) { if err != nil { t.Fatal(err) } - addr := types.NewForTestGetter()() + addr := testhelpers.NewForTestGetter()() newActor := types.Actor{Code: builtin2.AccountActorCodeID, Nonce: 1234, Balance: abi.NewTokenAmount(123)} AddAccount(t, tree, cst, addr) diff --git a/pkg/state/tree/testing.go b/pkg/state/tree/testing.go index cba9bf1beb..84d4826955 100644 --- a/pkg/state/tree/testing.go +++ b/pkg/state/tree/testing.go @@ -2,19 +2,19 @@ package tree import ( "context" + "testing" + "github.com/filecoin-project/go-state-types/abi" builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/builtin/account" init0 "github.com/filecoin-project/specs-actors/actors/builtin/init" "github.com/filecoin-project/specs-actors/actors/util/adt" - "testing" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/filecoin-project/go-address" "github.com/ipfs/go-cid" cbor "github.com/ipfs/go-ipld-cbor" "github.com/stretchr/testify/require" - - "github.com/filecoin-project/venus/pkg/types" ) // NewFromString sets a state tree based on an int. diff --git a/pkg/state/view.go b/pkg/state/view.go index b6b03c8ecc..8947f59800 100644 --- a/pkg/state/view.go +++ b/pkg/state/view.go @@ -4,7 +4,8 @@ import ( "context" "strconv" - types2 "github.com/filecoin-project/venus/venus-shared/chain" + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/dline" @@ -17,7 +18,6 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" vmstate "github.com/filecoin-project/venus/pkg/state/tree" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/util/ffiwrapper" "github.com/filecoin-project/venus/venus-shared/actors/adt" "github.com/filecoin-project/venus/venus-shared/actors/builtin" @@ -386,7 +386,7 @@ func (v *View) StateVerifiedClientStatus(ctx context.Context, addr addr.Address) return abi.NewStoragePower(0), err } - state, err := verifreg.Load(adt.WrapStore(ctx, v.ipldStore), (*types2.Actor)(act)) + state, err := verifreg.Load(adt.WrapStore(ctx, v.ipldStore), act) if err != nil { return abi.NewStoragePower(0), err } @@ -404,7 +404,7 @@ func (v *View) StateVerifiedClientStatus(ctx context.Context, addr addr.Address) } // StateMarketStorageDeal returns information about the indicated deal -func (v *View) StateMarketStorageDeal(ctx context.Context, dealID abi.DealID) (*types.MarketDeal, error) { +func (v *View) StateMarketStorageDeal(ctx context.Context, dealID abi.DealID) (*apitypes.MarketDeal, error) { state, err := v.LoadMarketState(ctx) if err != nil { return nil, err @@ -438,14 +438,14 @@ func (v *View) StateMarketStorageDeal(ctx context.Context, dealID abi.DealID) (* return nil, xerrors.New("deal state not found") } - return &types.MarketDeal{ + return &apitypes.MarketDeal{ Proposal: *dealProposal, State: *dealState, }, nil } // Returns the storage power actor's values for network total power. -func (v *View) PowerNetworkTotal(ctx context.Context) (*types.NetworkPower, error) { +func (v *View) PowerNetworkTotal(ctx context.Context) (*NetworkPower, error) { st, err := v.LoadPowerActor(ctx) if err != nil { return nil, err @@ -461,7 +461,7 @@ func (v *View) PowerNetworkTotal(ctx context.Context) (*types.NetworkPower, erro return nil, err } - return &types.NetworkPower{ + return &NetworkPower{ RawBytePower: tp.RawBytePower, QualityAdjustedPower: tp.QualityAdjPower, MinerCount: int64(minerCount), @@ -505,7 +505,7 @@ func (v *View) PaychActorParties(ctx context.Context, paychAddr addr.Address) (f return addr.Undef, addr.Undef, err } - state, err := paychActor.Load(adt.WrapStore(ctx, v.ipldStore), (*types2.Actor)(a)) + state, err := paychActor.Load(adt.WrapStore(ctx, v.ipldStore), a) if err != nil { return addr.Undef, addr.Undef, err } @@ -540,29 +540,6 @@ func (v *View) StateMinerProvingDeadline(ctx context.Context, addr addr.Address, return di.NextNotElapsed(), nil } -// StateMinerActiveSectors returns info about sectors that a given miner is actively proving. -func (v *View) StateMinerSectors(ctx context.Context, addr addr.Address, filter *bitfield.BitField, key types.TipSetKey) ([]*types.ChainSectorInfo, error) { - mas, err := v.LoadMinerState(ctx, addr) - if err != nil { - return nil, xerrors.WithMessage(err, "failed to get proving dealline") - } - - siset, err := mas.LoadSectors(filter) - if err != nil { - return nil, err - } - - sset := make([]*types.ChainSectorInfo, len(siset)) - for i, val := range siset { - sset[i] = &types.ChainSectorInfo{ - Info: *val, - ID: val.SectorNumber, - } - } - - return sset, nil -} - // StateSectorExpiration returns epoch at which given sector will expire func (v *View) StateSectorExpiration(ctx context.Context, maddr addr.Address, sectorNumber abi.SectorNumber, key types.TipSetKey) (*miner.SectorExpiration, error) { mas, err := v.LoadMinerState(ctx, maddr) @@ -583,7 +560,7 @@ func (v *View) StateMinerAvailableBalance(ctx context.Context, maddr addr.Addres return big.Int{}, err } - mas, err := miner.Load(adt.WrapStore(context.TODO(), v.ipldStore), (*types2.Actor)(actor)) + mas, err := miner.Load(adt.WrapStore(context.TODO(), v.ipldStore), actor) if err != nil { return big.Int{}, xerrors.Errorf("failed to load miner actor state: %v", err) } @@ -644,8 +621,8 @@ func (v *View) StateMinerPower(ctx context.Context, maddr addr.Address, tsk type } // StateMarketDeals returns information about every deal in the Storage Market -func (v *View) StateMarketDeals(ctx context.Context, tsk types.TipSetKey) (map[string]types.MarketDeal, error) { - out := map[string]types.MarketDeal{} +func (v *View) StateMarketDeals(ctx context.Context, tsk types.TipSetKey) (map[string]apitypes.MarketDeal, error) { + out := map[string]apitypes.MarketDeal{} state, err := v.LoadMarketState(ctx) if err != nil { @@ -669,7 +646,7 @@ func (v *View) StateMarketDeals(ctx context.Context, tsk types.TipSetKey) (map[s } else if !found { s = market.EmptyDealState() } - out[strconv.FormatInt(int64(dealID), 10)] = types.MarketDeal{ + out[strconv.FormatInt(int64(dealID), 10)] = apitypes.MarketDeal{ Proposal: d, State: *s, } @@ -730,7 +707,7 @@ func (v *View) ResolveToKeyAddr(ctx context.Context, address addr.Address) (addr return addr.Undef, xerrors.Errorf("failed to find actor: %s", address) } - aast, err := account.Load(adt.WrapStore(context.TODO(), v.ipldStore), (*types2.Actor)(act)) + aast, err := account.Load(adt.WrapStore(context.TODO(), v.ipldStore), act) if err != nil { return addr.Undef, xerrors.Errorf("failed to get account actor state for %s: %v", address, err) } @@ -744,12 +721,12 @@ func (v *View) LoadInitState(ctx context.Context) (notinit.State, error) { return nil, err } - return notinit.Load(adt.WrapStore(ctx, v.ipldStore), (*types2.Actor)(actr)) + return notinit.Load(adt.WrapStore(ctx, v.ipldStore), actr) } //LoadPaychState get pay channel state for actor func (v *View) LoadPaychState(ctx context.Context, actor *types.Actor) (paychActor.State, error) { - return paychActor.Load(adt.WrapStore(context.TODO(), v.ipldStore), (*types2.Actor)(actor)) + return paychActor.Load(adt.WrapStore(context.TODO(), v.ipldStore), actor) } //LoadMinerState return miner state @@ -763,7 +740,7 @@ func (v *View) LoadMinerState(ctx context.Context, maddr addr.Address) (miner.St return nil, err } - return miner.Load(adt.WrapStore(context.TODO(), v.ipldStore), (*types2.Actor)(actr)) + return miner.Load(adt.WrapStore(context.TODO(), v.ipldStore), actr) } func (v *View) LoadPowerActor(ctx context.Context) (power.State, error) { @@ -772,7 +749,7 @@ func (v *View) LoadPowerActor(ctx context.Context) (power.State, error) { return nil, err } - return power.Load(adt.WrapStore(ctx, v.ipldStore), (*types2.Actor)(actr)) + return power.Load(adt.WrapStore(ctx, v.ipldStore), actr) } func (v *View) LoadVerifregActor(ctx context.Context) (verifreg.State, error) { @@ -781,7 +758,7 @@ func (v *View) LoadVerifregActor(ctx context.Context) (verifreg.State, error) { return nil, err } - return verifreg.Load(adt.WrapStore(ctx, v.ipldStore), (*types2.Actor)(actr)) + return verifreg.Load(adt.WrapStore(ctx, v.ipldStore), actr) } // nolint @@ -791,7 +768,7 @@ func (v *View) LoadRewardState(ctx context.Context) (reward.State, error) { return nil, err } - return reward.Load(adt.WrapStore(ctx, v.ipldStore), (*types2.Actor)(actr)) + return reward.Load(adt.WrapStore(ctx, v.ipldStore), actr) } // nolint @@ -801,7 +778,7 @@ func (v *View) LoadPowerState(ctx context.Context) (power.State, error) { return nil, err } - return power.Load(adt.WrapStore(ctx, v.ipldStore), (*types2.Actor)(actr)) + return power.Load(adt.WrapStore(ctx, v.ipldStore), actr) } func (v *View) LoadMarketState(ctx context.Context) (market.State, error) { @@ -810,7 +787,7 @@ func (v *View) LoadMarketState(ctx context.Context) (market.State, error) { return nil, err } - return market.Load(adt.WrapStore(ctx, v.ipldStore), (*types2.Actor)(actr)) + return market.Load(adt.WrapStore(ctx, v.ipldStore), actr) } // nolint @@ -824,7 +801,7 @@ func (v *View) LoadAccountState(ctx context.Context, a addr.Address) (account.St return nil, err } - return account.Load(adt.WrapStore(context.TODO(), v.ipldStore), (*types2.Actor)(actr)) + return account.Load(adt.WrapStore(context.TODO(), v.ipldStore), actr) } //loadActor load actor of address in db @@ -850,7 +827,7 @@ func getFilMarketLocked(ctx context.Context, ipldStore cbor.IpldStore, st vmstat return big.Zero(), xerrors.Errorf("failed to load market actor: %v", err) } - mst, err := market.Load(adt.WrapStore(ctx, ipldStore), (*types2.Actor)(mactor)) + mst, err := market.Load(adt.WrapStore(ctx, ipldStore), mactor) if err != nil { return big.Zero(), xerrors.Errorf("failed to load market state: %v", err) } diff --git a/pkg/statemanger/call.go b/pkg/statemanger/call.go index c107cce928..e461b48f7d 100644 --- a/pkg/statemanger/call.go +++ b/pkg/statemanger/call.go @@ -3,9 +3,11 @@ package statemanger import ( "context" "fmt" + "github.com/filecoin-project/venus/pkg/consensus" "github.com/filecoin-project/venus/pkg/state" "github.com/filecoin-project/venus/pkg/vm/vmcontext" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" @@ -19,12 +21,11 @@ import ( "github.com/filecoin-project/venus/pkg/constants" "github.com/filecoin-project/venus/pkg/fork" "github.com/filecoin-project/venus/pkg/state/tree" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/vm" ) // CallWithGas used to estimate message gaslimit, for each incoming message ,should execute after priorMsg in mpool -func (s *Stmgr) CallWithGas(ctx context.Context, msg *types.UnsignedMessage, priorMsgs []types.ChainMsg, ts *types.TipSet) (*vm.Ret, error) { +func (s *Stmgr) CallWithGas(ctx context.Context, msg *types.Message, priorMsgs []types.ChainMsg, ts *types.TipSet) (*vm.Ret, error) { var ( err error stateRoot cid.Cid @@ -118,7 +119,7 @@ func (s *Stmgr) CallWithGas(ctx context.Context, msg *types.UnsignedMessage, pri } // Call used for api invoke to compute a msg base on specify tipset, if the tipset is null, use latest tipset in db -func (s *Stmgr) Call(ctx context.Context, msg *types.UnsignedMessage, ts *types.TipSet) (*vm.Ret, error) { +func (s *Stmgr) Call(ctx context.Context, msg *types.Message, ts *types.TipSet) (*vm.Ret, error) { ctx, span := trace.StartSpan(ctx, "statemanager.Call") defer span.End() diff --git a/pkg/statemanger/state_manger.go b/pkg/statemanger/state_manger.go index c0b2a938de..995ccb1d03 100644 --- a/pkg/statemanger/state_manger.go +++ b/pkg/statemanger/state_manger.go @@ -12,11 +12,11 @@ import ( "github.com/filecoin-project/venus/pkg/fork" appstate "github.com/filecoin-project/venus/pkg/state" "github.com/filecoin-project/venus/pkg/state/tree" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/vm" "github.com/filecoin-project/venus/pkg/vm/gas" "github.com/filecoin-project/venus/venus-shared/actors/builtin/market" "github.com/filecoin-project/venus/venus-shared/actors/builtin/paych" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log/v2" "go.opencensus.io/trace" @@ -28,7 +28,7 @@ import ( type IStateManager interface { ResolveToKeyAddress(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) GetPaychState(ctx context.Context, addr address.Address, ts *types.TipSet) (*types.Actor, paych.State, error) - Call(ctx context.Context, msg *types.UnsignedMessage, ts *types.TipSet) (*vm.Ret, error) + Call(ctx context.Context, msg *types.Message, ts *types.TipSet) (*vm.Ret, error) GetMarketState(ctx context.Context, ts *types.TipSet) (market.State, error) } diff --git a/pkg/testhelpers/address.go b/pkg/testhelpers/address.go new file mode 100644 index 0000000000..0045415733 --- /dev/null +++ b/pkg/testhelpers/address.go @@ -0,0 +1,31 @@ +package testhelpers + +import ( + "fmt" + "testing" + + "github.com/filecoin-project/go-address" +) + +func RequireIDAddress(t *testing.T, i int) address.Address { + a, err := address.NewIDAddress(uint64(i)) + if err != nil { + t.Fatalf("failed to make address: %v", err) + } + return a +} + +// NewForTestGetter returns a closure that returns an address unique to that invocation. +// The address is unique wrt the closure returned, not globally. +func NewForTestGetter() func() address.Address { + i := 0 + return func() address.Address { + s := fmt.Sprintf("address%d", i) + i++ + newAddr, err := address.NewSecp256k1Address([]byte(s)) + if err != nil { + panic(err) + } + return newAddr + } +} diff --git a/pkg/testhelpers/cid.go b/pkg/testhelpers/cid.go new file mode 100644 index 0000000000..135976765e --- /dev/null +++ b/pkg/testhelpers/cid.go @@ -0,0 +1,67 @@ +package testhelpers + +import ( + "context" + "testing" + + "github.com/filecoin-project/specs-actors/actors/util/adt" + "github.com/filecoin-project/venus/pkg/constants" + "github.com/filecoin-project/venus/pkg/util/blockstoreutil" + types "github.com/filecoin-project/venus/venus-shared/chain" + "github.com/ipfs/go-cid" + "github.com/ipfs/go-datastore" + cbor "github.com/ipfs/go-ipld-cbor" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +// EmptyMessagesCID is the cid of an empty collection of messages. +var EmptyMessagesCID cid.Cid + +// EmptyReceiptsCID is the cid of an empty collection of receipts. +var EmptyReceiptsCID cid.Cid + +// EmptyTxMetaCID is the cid of a TxMeta wrapping empty cids +var EmptyTxMetaCID cid.Cid + +func init() { + tmpCst := cbor.NewCborStore(blockstoreutil.NewBlockstore(datastore.NewMapDatastore())) + emptyAmt := adt.MakeEmptyArray(adt.WrapStore(context.Background(), tmpCst)) + emptyAMTCid, err := emptyAmt.Root() + if err != nil { + panic("could not create CID for empty AMT") + } + + EmptyMessagesCID = emptyAMTCid + EmptyReceiptsCID = emptyAMTCid + EmptyTxMetaCID, err = tmpCst.Put(context.Background(), &types.MessageRoot{SecpkRoot: EmptyMessagesCID, BlsRoot: EmptyMessagesCID}) + if err != nil { + panic("could not create CID for empty TxMeta") + } +} + +// CidFromString generates Cid from string input +func CidFromString(t *testing.T, input string) cid.Cid { + c, err := constants.DefaultCidBuilder.Sum([]byte(input)) + require.NoError(t, err) + return c +} + +// HasCid allows two values with CIDs to be compared. +type HasCid interface { + Cid() cid.Cid +} + +// AssertHaveSameCid asserts that two values have identical CIDs. +func AssertHaveSameCid(t *testing.T, m HasCid, n HasCid) { + if !m.Cid().Equals(n.Cid()) { + assert.Fail(t, "CIDs don't match", "not equal %v %v", m.Cid(), n.Cid()) + } +} + +// AssertCidsEqual asserts that two CIDS are identical. +func AssertCidsEqual(t *testing.T, m cid.Cid, n cid.Cid) { + if !m.Equals(n) { + assert.Fail(t, "CIDs don't match", "not equal %v %v", m, n) + } +} diff --git a/pkg/testhelpers/consensus.go b/pkg/testhelpers/consensus.go index 8934102fa0..243ca54f17 100644 --- a/pkg/testhelpers/consensus.go +++ b/pkg/testhelpers/consensus.go @@ -2,47 +2,13 @@ package testhelpers import ( "context" - fbig "github.com/filecoin-project/go-state-types/big" + pubsub "github.com/libp2p/go-libp2p-pubsub" - "testing" - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/ipfs/go-cid" - "github.com/stretchr/testify/require" - - bls "github.com/filecoin-project/filecoin-ffi" - "github.com/filecoin-project/venus/pkg/consensus" - "github.com/filecoin-project/venus/pkg/crypto" - "github.com/filecoin-project/venus/pkg/types" ) -// RequireSignedTestBlockFromTipSet creates a block with a valid signature by -// the passed in miner work and a Miner field set to the minerAddr. -func RequireSignedTestBlockFromTipSet(t *testing.T, baseTipSet types.TipSet, stateRootCid cid.Cid, receiptRootCid cid.Cid, height abi.ChainEpoch, minerAddr address.Address, minerWorker address.Address, signer types.Signer) *types.BlockHeader { - ticket := consensus.MakeFakeTicketForTest() - emptyBLSSig := crypto.Signature{ - Type: crypto.SigTypeBLS, - Data: (*bls.Aggregate([]bls.Signature{}))[:], - } - - b := &types.BlockHeader{ - Miner: minerAddr, - Ticket: ticket, - Parents: baseTipSet.Key(), - ParentWeight: fbig.NewInt(int64(height * 10000)), - Height: height, - ParentStateRoot: stateRootCid, - ParentMessageReceipts: receiptRootCid, - BLSAggregate: &emptyBLSSig, - } - sig, err := signer.SignBytes(context.TODO(), b.SignatureData(), minerWorker) - require.NoError(t, err) - b.BlockSig = sig - - return b -} - // FakeBlockValidator passes everything as valid type FakeBlockValidator struct{} @@ -67,7 +33,7 @@ func (fbv *FakeBlockValidator) ValidateMessagesSyntax(ctx context.Context, messa } // ValidateUnsignedMessagesSyntax does nothing -func (fbv *FakeBlockValidator) ValidateUnsignedMessagesSyntax(ctx context.Context, messages []*types.UnsignedMessage) error { +func (fbv *FakeBlockValidator) ValidateUnsignedMessagesSyntax(ctx context.Context, messages []*types.Message) error { return nil } diff --git a/pkg/testhelpers/core.go b/pkg/testhelpers/core.go index ef8fb0e7d4..4811048d78 100644 --- a/pkg/testhelpers/core.go +++ b/pkg/testhelpers/core.go @@ -3,41 +3,39 @@ package testhelpers import ( "context" "errors" + "math/rand" + "testing" + "github.com/filecoin-project/go-state-types/abi" fbig "github.com/filecoin-project/go-state-types/big" acrypto "github.com/filecoin-project/go-state-types/crypto" - "math/rand" - "testing" - "github.com/filecoin-project/go-address" "github.com/ipfs/go-cid" - cbor "github.com/ipfs/go-ipld-cbor" "github.com/libp2p/go-libp2p-core/peer" "github.com/stretchr/testify/require" - "github.com/filecoin-project/venus/pkg/state/tree" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" ) // RequireMakeStateTree takes a map of addresses to actors and stores them on // the state tree, requiring that all its steps succeed. -func RequireMakeStateTree(t *testing.T, cst cbor.IpldStore, acts map[address.Address]*types.Actor) (cid.Cid, *tree.State) { - ctx := context.Background() - tree, err := tree.NewState(cst, tree.StateTreeVersion0) - if err != nil { - t.Fatal(err) - } - - for addr, act := range acts { - err := tree.SetActor(ctx, addr, act) - require.NoError(t, err) - } - - c, err := tree.Flush(ctx) - require.NoError(t, err) - - return c, tree -} +//func RequireMakeStateTree(t *testing.T, cst cbor.IpldStore, acts map[address.Address]*types.Actor) (cid.Cid, *tree.State) { +// ctx := context.Background() +// tree, err := tree.NewState(cst, tree.StateTreeVersion0) +// if err != nil { +// t.Fatal(err) +// } +// +// for addr, act := range acts { +// err := tree.SetActor(ctx, addr, act) +// require.NoError(t, err) +// } +// +// c, err := tree.Flush(ctx) +// require.NoError(t, err) +// +// return c, tree +//} // RequireRandomPeerID returns a new libp2p peer ID or panics. func RequireRandomPeerID(t *testing.T) peer.ID { @@ -70,24 +68,24 @@ func RequireTipset(t *testing.T) *types.TipSet { } func RequireTipsetWithHeight(t *testing.T, height abi.ChainEpoch) *types.TipSet { - newAddress := types.NewForTestGetter() + newAddress := NewForTestGetter() blk := &types.BlockHeader{ Miner: newAddress(), - Ticket: types.Ticket{VRFProof: []byte{0x03, 0x01, 0x02}}, + Ticket: &types.Ticket{VRFProof: []byte{0x03, 0x01, 0x02}}, ElectionProof: &types.ElectionProof{VRFProof: []byte{0x0c, 0x0d}}, - BeaconEntries: []*types.BeaconEntry{ + BeaconEntries: []types.BeaconEntry{ { Round: 44, Data: []byte{0xc0}, }, }, Height: height, - Messages: types.CidFromString(t, "someothercid"), - ParentMessageReceipts: types.CidFromString(t, "someothercid"), - Parents: types.NewTipSetKey(types.CidFromString(t, "someothercid")), + Messages: CidFromString(t, "someothercid"), + ParentMessageReceipts: CidFromString(t, "someothercid"), + Parents: []cid.Cid{CidFromString(t, "someothercid")}, ParentWeight: fbig.NewInt(1), ForkSignaling: 2, - ParentStateRoot: types.CidFromString(t, "someothercid"), + ParentStateRoot: CidFromString(t, "someothercid"), Timestamp: 4, ParentBaseFee: abi.NewTokenAmount(20), BlockSig: &acrypto.Signature{ @@ -95,6 +93,6 @@ func RequireTipsetWithHeight(t *testing.T, height abi.ChainEpoch) *types.TipSet Data: []byte{0x4}, }, } - b, _ := types.NewTipSet(blk) + b, _ := types.NewTipSet([]*types.BlockHeader{blk}) return b } diff --git a/pkg/testhelpers/message.go b/pkg/testhelpers/message.go new file mode 100644 index 0000000000..f11fc860c1 --- /dev/null +++ b/pkg/testhelpers/message.go @@ -0,0 +1,295 @@ +package testhelpers + +import ( + "context" + "fmt" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/filecoin-project/venus/pkg/crypto" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/venus/pkg/constants" + types "github.com/filecoin-project/venus/venus-shared/chain" + "github.com/ipfs/go-cid" + cbor "github.com/ipfs/go-ipld-cbor" +) + +// NewMessage creates a new message. +func NewMessage(from, to address.Address, nonce uint64, value abi.TokenAmount, method abi.MethodNum, params []byte) *types.Message { + return &types.Message{ + Version: 0, + To: to, + From: from, + Nonce: nonce, + Value: value, + Method: method, + Params: params, + } +} + +// NewMeteredMessage adds gas price and gas limit to the message +func NewMeteredMessage(from, to address.Address, nonce uint64, value abi.TokenAmount, method abi.MethodNum, params []byte, gasFeeCap, gasPremium abi.TokenAmount, limit int64) *types.Message { + return &types.Message{ + Version: 0, + To: to, + From: from, + Nonce: nonce, + Value: value, + GasFeeCap: gasFeeCap, + GasPremium: gasPremium, + GasLimit: limit, + Method: method, + Params: params, + } +} + +// NewSignedMessage accepts a message `msg` and a signer `s`. NewSignedMessage returns a `SignedMessage` containing +// a signature derived from the serialized `msg` and `msg.From` +// NOTE: this method can only sign message with From being a public-key type address, not an ID address. +// We should deprecate this and move to more explicit signing via an address resolver. +func NewSignedMessage(ctx context.Context, msg types.Message, s types.Signer) (*types.SignedMessage, error) { + msgCid := msg.Cid() + + sig, err := s.SignBytes(ctx, msgCid.Bytes(), msg.From) + if err != nil { + return nil, err + } + + return &types.SignedMessage{ + Message: msg, + Signature: *sig, + }, nil +} + +// NewSignedMessageForTestGetter returns a closure that returns a SignedMessage unique to that invocation. +// The message is unique wrt the closure returned, not globally. You can use this function +// in tests instead of manually creating messages -- it both reduces duplication and gives us +// exactly one place to create valid messages for tests if messages require validation in the +// future. +// TODO support chosing from address +func NewSignedMessageForTestGetter(ms MockSigner) func(uint64) *types.SignedMessage { + i := 0 + return func(nonce uint64) *types.SignedMessage { + s := fmt.Sprintf("smsg%d", i) + i++ + newAddr, err := address.NewSecp256k1Address([]byte(s + "-to")) + if err != nil { + panic(err) + } + msg := NewMeteredMessage( + ms.Addresses[0], // from needs to be an address from the signer + newAddr, + nonce, + types.ZeroFIL, + 0, + []byte("params"), + types.ZeroFIL, + types.ZeroFIL, + 0, + ) + smsg, err := NewSignedMessage(context.TODO(), *msg, &ms) + if err != nil { + panic(err) + } + return smsg + } +} + +// NewCidForTestGetter returns a closure that returns a Cid unique to that invocation. +// The Cid is unique wrt the closure returned, not globally. You can use this function +// in tests. +func NewCidForTestGetter() func() cid.Cid { + i := 31337 + return func() cid.Cid { + obj, err := cbor.WrapObject([]int{i}, constants.DefaultHashFunction, -1) + if err != nil { + panic(err) + } + i++ + return obj.Cid() + } +} + +// NewMessageForTestGetter returns a closure that returns a message unique to that invocation. +// The message is unique wrt the closure returned, not globally. You can use this function +// in tests instead of manually creating messages -- it both reduces duplication and gives us +// exactly one place to create valid messages for tests if messages require validation in the +// future. +func NewMessageForTestGetter() func() *types.Message { + i := 0 + return func() *types.Message { + s := fmt.Sprintf("msg%d", i) + i++ + from, err := address.NewSecp256k1Address([]byte(s + "-from")) + if err != nil { + panic(err) + } + to, err := address.NewSecp256k1Address([]byte(s + "-to")) + if err != nil { + panic(err) + } + return NewMessage( + from, + to, + 0, + types.ZeroFIL, + abi.MethodNum(10000+i), + nil) + } +} + +// NewMsgs returns n messages. The messages returned are unique to this invocation +// but are not unique globally (ie, a second call to NewMsgs will return the same +// set of messages). +func NewMsgs(n int) []*types.Message { + newMsg := NewMessageForTestGetter() + msgs := make([]*types.Message, n) + for i := 0; i < n; i++ { + msgs[i] = newMsg() + msgs[i].Nonce = uint64(i) + } + return msgs +} + +// NewSignedMsgs returns n signed messages. The messages returned are unique to this invocation +// but are not unique globally (ie, a second call to NewSignedMsgs will return the same +// set of messages). +func NewSignedMsgs(n uint, ms MockSigner) []*types.SignedMessage { + var err error + newMsg := NewMessageForTestGetter() + smsgs := make([]*types.SignedMessage, n) + for i := uint(0); i < n; i++ { + msg := newMsg() + msg.From = ms.Addresses[0] + msg.Nonce = uint64(i) + msg.GasFeeCap = types.ZeroFIL + msg.GasPremium = types.ZeroFIL + msg.GasLimit = 0 + smsgs[i], err = NewSignedMessage(context.TODO(), *msg, ms) + if err != nil { + panic(err) + } + } + return smsgs +} + +// SignMsgs returns a slice of signed messages where the original messages +// are `msgs`, if signing one of the `msgs` fails an error is returned +func SignMsgs(ms MockSigner, msgs []*types.Message) ([]*types.SignedMessage, error) { + var smsgs []*types.SignedMessage + for _, m := range msgs { + s, err := NewSignedMessage(context.TODO(), *m, ms) + if err != nil { + return nil, err + } + smsgs = append(smsgs, s) + } + return smsgs, nil +} + +// NewMsgsWithAddrs returns a slice of `n` messages who's `From` field's are pulled +// from `a`. This method should be used when the addresses returned are to be signed +// at a later point. +func NewMsgsWithAddrs(n int, a []address.Address) []*types.Message { + if n > len(a) { + panic("cannot create more messages than there are addresess for") + } + newMsg := NewMessageForTestGetter() + msgs := make([]*types.Message, n) + for i := 0; i < n; i++ { + msgs[i] = newMsg() + msgs[i].From = a[i] + } + return msgs +} + +// MessageMaker creates unique, signed messages for use in tests. +type MessageMaker struct { + DefaultGasFeeCap types.BigInt + DefaultGasPremium types.BigInt + DefaultGasUnits int64 + + signer *MockSigner + seq uint + t *testing.T +} + +// NewMessageMaker creates a new message maker with a set of signing keys. +func NewMessageMaker(t *testing.T, keys []crypto.KeyInfo) *MessageMaker { + addresses := make([]address.Address, len(keys)) + signer := NewMockSigner(keys) + + for i, key := range keys { + addr, _ := key.Address() + addresses[i] = addr + } + + return &MessageMaker{types.ZeroFIL, types.ZeroFIL, 0, &signer, 0, t} +} + +// Addresses returns the addresses for which this maker can sign messages. +func (mm *MessageMaker) Addresses() []address.Address { + return mm.signer.Addresses +} + +// Signer returns the signer with which this maker signs messages. +func (mm *MessageMaker) Signer() *MockSigner { + return mm.signer +} + +// NewUnsignedMessage creates a new message. +func (mm *MessageMaker) NewUnsignedMessage(from address.Address, nonce uint64) *types.Message { + seq := mm.seq + mm.seq++ + to, err := address.NewSecp256k1Address([]byte("destination")) + require.NoError(mm.t, err) + return NewMeteredMessage( + from, + to, + nonce, + types.ZeroFIL, + abi.MethodNum(9000+seq), + []byte("params"), + mm.DefaultGasFeeCap, + mm.DefaultGasPremium, + mm.DefaultGasUnits) +} + +// NewSignedMessage creates a new signed message. +func (mm *MessageMaker) NewSignedMessage(from address.Address, nonce uint64) *types.SignedMessage { + msg := mm.NewUnsignedMessage(from, nonce) + signed, err := NewSignedMessage(context.TODO(), *msg, mm.signer) + require.NoError(mm.t, err) + return signed +} + +// EmptyReceipts returns a slice of n empty receipts. +func EmptyReceipts(n int) []*types.MessageReceipt { + out := make([]*types.MessageReceipt, n) + for i := 0; i < n; i++ { + out[i] = &types.MessageReceipt{} + } + return out +} + +// ReceiptMaker generates unique receipts +type ReceiptMaker struct { + seq uint +} + +// NewReceiptMaker creates a new receipt maker +func NewReceiptMaker() *ReceiptMaker { + return &ReceiptMaker{0} +} + +// NewReceipt creates a new distinct receipt. +func (rm *ReceiptMaker) NewReceipt() types.MessageReceipt { + seq := rm.seq + rm.seq++ + return types.MessageReceipt{ + Return: []byte(fmt.Sprintf("%d", seq)), + } +} diff --git a/pkg/testhelpers/net.go b/pkg/testhelpers/net.go index ce1bacbeff..2ba8415d01 100644 --- a/pkg/testhelpers/net.go +++ b/pkg/testhelpers/net.go @@ -8,9 +8,8 @@ import ( "testing" "time" - "github.com/filecoin-project/venus/pkg/types" - "github.com/filecoin-project/venus/pkg/chainsync/exchange" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/ipfs/go-cid" "github.com/libp2p/go-libp2p-core/connmgr" "github.com/libp2p/go-libp2p-core/event" @@ -213,7 +212,7 @@ func (f *TestFetcher) FetchTipSets(ctx context.Context, tsKey types.TipSetKey, f return nil, err } - ts, err := types.NewTipSet(res...) + ts, err := types.NewTipSet(res) if err != nil { return nil, err } diff --git a/pkg/testhelpers/singer.go b/pkg/testhelpers/singer.go new file mode 100644 index 0000000000..135e033c20 --- /dev/null +++ b/pkg/testhelpers/singer.go @@ -0,0 +1,153 @@ +package testhelpers + +import ( + "bytes" + "context" + "crypto/rand" + "errors" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/venus/pkg/crypto" +) + +// MockSigner implements the Signer interface +type MockSigner struct { + AddrKeyInfo map[address.Address]crypto.KeyInfo + Addresses []address.Address + PubKeys [][]byte +} + +// NewMockSigner returns a new mock signer, capable of signing data with +// keys (addresses derived from) in keyinfo +func NewMockSigner(kis []crypto.KeyInfo) MockSigner { + var ms MockSigner + ms.AddrKeyInfo = make(map[address.Address]crypto.KeyInfo) + for _, k := range kis { + // extract public key + pub, err := k.PublicKey() + if err != nil { + panic(err) + } + + var newAddr address.Address + if k.SigType == crypto.SigTypeSecp256k1 { + newAddr, err = address.NewSecp256k1Address(pub) + } else if k.SigType == crypto.SigTypeBLS { + newAddr, err = address.NewBLSAddress(pub) + } + if err != nil { + panic(err) + } + ms.Addresses = append(ms.Addresses, newAddr) + ms.AddrKeyInfo[newAddr] = k + ms.PubKeys = append(ms.PubKeys, pub) + } + return ms +} + +// NewMockSignersAndKeyInfo is a convenience function to generate a mock +// signers with some keys. +func NewMockSignersAndKeyInfo(numSigners int) (MockSigner, []crypto.KeyInfo) { + ki := MustGenerateKeyInfo(numSigners, 42) + signer := NewMockSigner(ki) + return signer, ki +} + +// MustGenerateMixedKeyInfo produces m bls keys and n secp keys. +// BLS and Secp will be interleaved. The keys will be valid, but not deterministic. +func MustGenerateMixedKeyInfo(m int, n int) []crypto.KeyInfo { + info := []crypto.KeyInfo{} + for m > 0 && n > 0 { + if m > 0 { + ki, err := crypto.NewBLSKeyFromSeed(rand.Reader) + if err != nil { + panic(err) + } + info = append(info, ki) + m-- + } + + if n > 0 { + ki, err := crypto.NewSecpKeyFromSeed(rand.Reader) + if err != nil { + panic(err) + } + info = append(info, ki) + n-- + } + } + return info +} + +// MustGenerateBLSKeyInfo produces n distinct BLS keyinfos. +func MustGenerateBLSKeyInfo(n int, seed byte) []crypto.KeyInfo { + token := bytes.Repeat([]byte{seed}, 512) + var keyinfos []crypto.KeyInfo + for i := 0; i < n; i++ { + token[0] = byte(i) + ki, err := crypto.NewBLSKeyFromSeed(bytes.NewReader(token)) + if err != nil { + panic(err) + } + keyinfos = append(keyinfos, ki) + } + return keyinfos +} + +// MustGenerateKeyInfo generates `n` distinct keyinfos using seed `seed`. +// The result is deterministic (for stable tests), don't use this for real keys! +func MustGenerateKeyInfo(n int, seed byte) []crypto.KeyInfo { + token := bytes.Repeat([]byte{seed}, 512) + var keyinfos []crypto.KeyInfo + for i := 0; i < n; i++ { + token[0] = byte(i) + ki, err := crypto.NewSecpKeyFromSeed(bytes.NewReader(token)) + if err != nil { + panic(err) + } + keyinfos = append(keyinfos, ki) + } + return keyinfos +} + +// SignBytes cryptographically signs `data` using the `addr`. +func (ms MockSigner) SignBytes(_ context.Context, data []byte, addr address.Address) (*crypto.Signature, error) { + ki, ok := ms.AddrKeyInfo[addr] + if !ok { + return nil, errors.New("unknown address") + } + var sig *crypto.Signature + err := ki.UsePrivateKey(func(privateKey []byte) error { + var err error + sig, err = crypto.Sign(data, privateKey, ki.SigType) + + return err + }) + return sig, err +} + +// HasAddress returns whether the signer can sign with this address +func (ms MockSigner) HasAddress(_ context.Context, addr address.Address) (bool, error) { + return true, nil +} + +// GetAddressForPubKey looks up a KeyInfo address associated with a given PublicKeyForSecpSecretKey for a MockSigner +func (ms MockSigner) GetAddressForPubKey(pk []byte) (address.Address, error) { + var addr address.Address + + for _, ki := range ms.AddrKeyInfo { + testPk, err := ki.PublicKey() + if err != nil { + return address.Undef, err + } + + if bytes.Equal(testPk, pk) { + addr, err := ki.Address() + if err != nil { + return addr, errors.New("could not fetch address") + } + return addr, nil + } + } + return addr, errors.New("public key not found in wallet") +} diff --git a/pkg/testhelpers/test_daemon.go b/pkg/testhelpers/test_daemon.go index b0d9e1396e..d741e01c36 100644 --- a/pkg/testhelpers/test_daemon.go +++ b/pkg/testhelpers/test_daemon.go @@ -30,7 +30,7 @@ import ( "github.com/filecoin-project/venus/build/project" "github.com/filecoin-project/venus/pkg/config" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" ) const ( diff --git a/pkg/testhelpers/tipset.go b/pkg/testhelpers/tipset.go new file mode 100644 index 0000000000..7518420d18 --- /dev/null +++ b/pkg/testhelpers/tipset.go @@ -0,0 +1,16 @@ +package testhelpers + +import ( + "testing" + + types "github.com/filecoin-project/venus/venus-shared/chain" + "github.com/stretchr/testify/require" +) + +// RequireNewTipSet instantiates and returns a new tipset of the given blocks +// and requires that the setup validation succeed. +func RequireNewTipSet(t *testing.T, blks ...*types.BlockHeader) *types.TipSet { + ts, err := types.NewTipSet(blks) + require.NoError(t, err) + return ts +} diff --git a/pkg/types/internal/atto_fil_test.go b/pkg/types/internal/atto_fil_test.go index 3d4f0b5357..f4f6eec969 100644 --- a/pkg/types/internal/atto_fil_test.go +++ b/pkg/types/internal/atto_fil_test.go @@ -1,11 +1,12 @@ package internal import ( + "math/big" + "testing" + specsbig "github.com/filecoin-project/go-state-types/big" tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" "github.com/stretchr/testify/assert" - "math/big" - "testing" ) func mustParseBigInt(s string) big.Int { diff --git a/pkg/util/dag/dag_test.go b/pkg/util/dag/dag_test.go index 761cd3f405..f3c310faf9 100644 --- a/pkg/util/dag/dag_test.go +++ b/pkg/util/dag/dag_test.go @@ -5,6 +5,8 @@ import ( "testing" "time" + "github.com/filecoin-project/venus/pkg/testhelpers" + "github.com/filecoin-project/go-address" "github.com/ipfs/go-blockservice" "github.com/ipfs/go-datastore" @@ -16,7 +18,6 @@ import ( "github.com/filecoin-project/venus/pkg/chain" tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" - "github.com/filecoin-project/venus/pkg/types" ) func TestDAGGet(t *testing.T) { @@ -47,7 +48,7 @@ func TestDAGGet(t *testing.T) { dserv := merkledag.NewDAGService(blkserv) dag := NewDAG(dserv) - someCid := types.CidFromString(t, "somecid") + someCid := testhelpers.CidFromString(t, "somecid") _, err := dag.GetNode(ctx, someCid.String()) assert.EqualError(t, err, "merkledag: not found") diff --git a/pkg/vm/gas/gas_tracker.go b/pkg/vm/gas/gas_tracker.go index 5f32635376..86b6466eff 100644 --- a/pkg/vm/gas/gas_tracker.go +++ b/pkg/vm/gas/gas_tracker.go @@ -6,8 +6,8 @@ import ( "github.com/filecoin-project/go-state-types/exitcode" - types2 "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/vm/runtime" + types "github.com/filecoin-project/venus/venus-shared/stmgr" ) // GasTracker maintains the stateView of gas usage throughout the execution of a message. @@ -15,12 +15,12 @@ type GasTracker struct { //nolint GasAvailable int64 GasUsed int64 - ExecutionTrace types2.ExecutionTrace + ExecutionTrace types.ExecutionTrace NumActorsCreated uint64 //nolint AllowInternal bool //nolint CallerValidated bool //nolint LastGasChargeTime time.Time //nolint - LastGasCharge *types2.GasTrace + LastGasCharge *types.GasTrace } // NewGasTracker initializes a new empty gas tracker @@ -54,7 +54,7 @@ func (t *GasTracker) TryCharge(gasCharge GasCharge) bool { t.LastGasCharge.TimeTaken = now.Sub(t.LastGasChargeTime) } - gasTrace := types2.GasTrace{ + gasTrace := types.GasTrace{ Name: gasCharge.Name, Extra: gasCharge.Extra, diff --git a/pkg/vm/vmcontext/interpreter.go b/pkg/vm/vmcontext/interpreter.go index 421bd80922..3a802fda80 100644 --- a/pkg/vm/vmcontext/interpreter.go +++ b/pkg/vm/vmcontext/interpreter.go @@ -4,7 +4,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/venus/pkg/state/tree" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/ipfs/go-cid" ) diff --git a/pkg/vm/vmcontext/invocation_context.go b/pkg/vm/vmcontext/invocation_context.go index eec517e478..da7d6c3330 100644 --- a/pkg/vm/vmcontext/invocation_context.go +++ b/pkg/vm/vmcontext/invocation_context.go @@ -5,8 +5,6 @@ import ( "encoding/binary" "fmt" - types2 "github.com/filecoin-project/venus/venus-shared/chain" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" @@ -18,7 +16,6 @@ import ( ipfscbor "github.com/ipfs/go-ipld-cbor" xerrors "github.com/pkg/errors" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/vm/dispatch" "github.com/filecoin-project/venus/pkg/vm/gas" "github.com/filecoin-project/venus/pkg/vm/runtime" @@ -28,6 +25,7 @@ import ( "github.com/filecoin-project/venus/venus-shared/actors/builtin" "github.com/filecoin-project/venus/venus-shared/actors/builtin/account" init_ "github.com/filecoin-project/venus/venus-shared/actors/builtin/init" + types "github.com/filecoin-project/venus/venus-shared/chain" ) var gasOnActorExec = gas.NewGasCharge("OnActorExec", 0, 0) @@ -305,7 +303,7 @@ func (ctx *invocationContext) resolveTarget(target address.Address) (*types.Acto } // get init State - state, err := init_.Load(ctx.vm.ContextStore(), (*types2.Actor)(initActorEntry)) + state, err := init_.Load(ctx.vm.ContextStore(), initActorEntry) if err != nil { panic(err) } @@ -402,7 +400,7 @@ func (ctx *invocationContext) resolveToKeyAddr(addr address.Address) (address.Ad return address.Undef, xerrors.Errorf("failed to find actor: %s", addr) } - aast, err := account.Load(adt.WrapStore(ctx.vm.context, ctx.vm.store), (*types2.Actor)(act)) + aast, err := account.Load(adt.WrapStore(ctx.vm.context, ctx.vm.store), act) if err != nil { return address.Undef, xerrors.Errorf("failed to get account actor State for %s: %v", addr, err) } diff --git a/pkg/vm/vmcontext/runtime_adapter.go b/pkg/vm/vmcontext/runtime_adapter.go index 012242fe85..a398a9e781 100644 --- a/pkg/vm/vmcontext/runtime_adapter.go +++ b/pkg/vm/vmcontext/runtime_adapter.go @@ -6,7 +6,6 @@ import ( "github.com/filecoin-project/venus/venus-shared/actors/aerrors" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/venus-shared/actors/builtin" "github.com/ipfs/go-cid" @@ -25,6 +24,7 @@ import ( rt5 "github.com/filecoin-project/specs-actors/v5/actors/runtime" "github.com/filecoin-project/venus/pkg/vm/gas" "github.com/filecoin-project/venus/pkg/vm/runtime" + types "github.com/filecoin-project/venus/venus-shared/chain" ) var EmptyObjectCid cid.Cid diff --git a/pkg/vm/vmcontext/syscallsStateView.go b/pkg/vm/vmcontext/syscallsStateView.go index b70abf9aef..024d7e92ae 100644 --- a/pkg/vm/vmcontext/syscallsStateView.go +++ b/pkg/vm/vmcontext/syscallsStateView.go @@ -11,7 +11,6 @@ import ( "github.com/filecoin-project/venus/venus-shared/actors/adt" "github.com/filecoin-project/venus/venus-shared/actors/builtin/account" "github.com/filecoin-project/venus/venus-shared/actors/builtin/miner" - types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/pkg/errors" ) @@ -40,7 +39,7 @@ func (vm *syscallsStateView) ResolveToKeyAddr(ctx context.Context, accountAddr a if !found { return address.Undef, fmt.Errorf("signer resolution found no such actor %s", accountAddr) } - accountState, err := account.Load(adt.WrapStore(vm.context, vm.ctx.gasIpld), (*types.Actor)(accountActor)) + accountState, err := account.Load(adt.WrapStore(vm.context, vm.ctx.gasIpld), accountActor) if err != nil { // This error is internal, shouldn't propagate as on-chain failure panic(fmt.Errorf("signer resolution failed To lost stateView for %s ", accountAddr)) @@ -59,7 +58,7 @@ func (vm *syscallsStateView) MinerInfo(ctx context.Context, maddr address.Addres return nil, fmt.Errorf("miner resolution found no such actor %s", maddr) } - accountState, err := miner.Load(adt.WrapStore(vm.context, vm.ctx.gasIpld), (*types.Actor)(accountActor)) + accountState, err := miner.Load(adt.WrapStore(vm.context, vm.ctx.gasIpld), accountActor) if err != nil { panic(fmt.Errorf("signer resolution failed To lost stateView for %s ", maddr)) } diff --git a/pkg/vm/vmcontext/types.go b/pkg/vm/vmcontext/types.go index 6bf021b30f..21f3527138 100644 --- a/pkg/vm/vmcontext/types.go +++ b/pkg/vm/vmcontext/types.go @@ -2,10 +2,12 @@ package vmcontext import ( "context" + acrypto "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/go-state-types/exitcode" "github.com/filecoin-project/venus/pkg/state" "github.com/filecoin-project/venus/pkg/util/blockstoreutil" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/network" @@ -13,7 +15,6 @@ import ( "github.com/filecoin-project/venus/pkg/fork" "github.com/filecoin-project/venus/pkg/state/tree" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/vm/dispatch" "github.com/filecoin-project/venus/pkg/vm/gas" ) @@ -70,8 +71,8 @@ type Ret struct { // Failure returns with a non-zero exit code. func Failure(exitCode exitcode.ExitCode, gasAmount int64) types.MessageReceipt { return types.MessageReceipt{ - ExitCode: exitCode, - ReturnValue: []byte{}, - GasUsed: gasAmount, + ExitCode: exitCode, + Return: []byte{}, + GasUsed: gasAmount, } } diff --git a/pkg/vm/vmcontext/vmcontext.go b/pkg/vm/vmcontext/vmcontext.go index 37511f8874..789badcd83 100644 --- a/pkg/vm/vmcontext/vmcontext.go +++ b/pkg/vm/vmcontext/vmcontext.go @@ -23,7 +23,6 @@ import ( rt5 "github.com/filecoin-project/specs-actors/v5/actors/runtime" "github.com/filecoin-project/venus/pkg/state/tree" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/util/blockstoreutil" "github.com/filecoin-project/venus/pkg/vm/dispatch" "github.com/filecoin-project/venus/pkg/vm/gas" @@ -33,7 +32,8 @@ import ( "github.com/filecoin-project/venus/venus-shared/actors/builtin/cron" initActor "github.com/filecoin-project/venus/venus-shared/actors/builtin/init" "github.com/filecoin-project/venus/venus-shared/actors/builtin/reward" - types2 "github.com/filecoin-project/venus/venus-shared/chain" + types "github.com/filecoin-project/venus/venus-shared/chain" + types2 "github.com/filecoin-project/venus/venus-shared/stmgr" ) const MaxCallDepth = 4096 @@ -76,7 +76,7 @@ type ActorImplLookup interface { GetActorImpl(code cid.Cid, rt runtime.Runtime) (dispatch.Dispatcher, *dispatch.ExcuteError) } -func VmMessageFromUnsignedMessage(msg *types.UnsignedMessage) VmMessage { //nolint +func VmMessageFromUnsignedMessage(msg *types.Message) VmMessage { //nolint return VmMessage{ From: msg.From, To: msg.To, @@ -183,7 +183,7 @@ func (vm *VM) normalizeAddress(addr address.Address) (address.Address, bool) { } // get a view into the actor stateView - initActorState, err := initActor.Load(adt.WrapStore(vm.context, vm.store), (*types2.Actor)(initActorEntry)) + initActorState, err := initActor.Load(adt.WrapStore(vm.context, vm.store), initActorEntry) if err != nil { panic(err) } @@ -286,7 +286,7 @@ func (vm *VM) ApplyTipSetMessages(blocks []types.BlockMessagesInfo, ts *types.Ti msgGasOutput, _ := json.MarshalIndent(ret.OutPuts, "", "\t") vm.debugger.Println(string(msgGasOutput)) - var valuedTraces []*types.GasTrace + var valuedTraces []*types2.GasTrace for _, trace := range ret.GasTracker.ExecutionTrace.GasCharges { if trace.TotalGas > 0 { valuedTraces = append(valuedTraces, trace) @@ -395,9 +395,9 @@ func (vm *VM) applyImplicitMessage(imsg VmMessage) (*Ret, error) { GasTracker: gasTank, OutPuts: gas.GasOutputs{}, Receipt: types.MessageReceipt{ - ExitCode: code, - ReturnValue: ret, - GasUsed: 0, + ExitCode: code, + Return: ret, + GasUsed: 0, }, }, nil } @@ -414,7 +414,7 @@ func (vm *VM) ApplyMessage(msg types.ChainMsg) (*Ret, error) { } // applyMessage applies the message To the current stateView. -func (vm *VM) applyMessage(msg *types.UnsignedMessage, onChainMsgSize int) (*Ret, error) { +func (vm *VM) applyMessage(msg *types.Message, onChainMsgSize int) (*Ret, error) { vm.SetCurrentEpoch(vm.vmOption.Epoch) // This Method does not actually execute the message itself, // but rather deals with the pre/post processing of a message. @@ -619,14 +619,14 @@ func (vm *VM) applyMessage(msg *types.UnsignedMessage, onChainMsgSize int) (*Ret GasTracker: gasTank, OutPuts: gasOutputs, Receipt: types.MessageReceipt{ - ExitCode: code, - ReturnValue: ret, - GasUsed: gasUsed, + ExitCode: code, + Return: ret, + GasUsed: gasUsed, }, }, nil } -func (vm *VM) shouldBurn(ctx context.Context, msg *types.UnsignedMessage, errcode exitcode.ExitCode) (bool, error) { +func (vm *VM) shouldBurn(ctx context.Context, msg *types.Message, errcode exitcode.ExitCode) (bool, error) { if vm.NtwkVersion() <= network.Version12 { // Check to see if we should burn funds. We avoid burning on successful // window post. This won't catch _indirect_ window post calls, but this diff --git a/pkg/wallet/wallet.go b/pkg/wallet/wallet.go index c3923d0928..0e0b0eefef 100644 --- a/pkg/wallet/wallet.go +++ b/pkg/wallet/wallet.go @@ -12,6 +12,7 @@ import ( "github.com/pkg/errors" "github.com/filecoin-project/venus/pkg/crypto" + types "github.com/filecoin-project/venus/venus-shared/wallet" ) var TestPassword = []byte("test-password") @@ -27,7 +28,7 @@ type WalletIntersection interface { NewAddress(p address.Protocol) (address.Address, error) Import(ki *crypto.KeyInfo) (address.Address, error) Export(addr address.Address, password string) (*crypto.KeyInfo, error) - WalletSign(keyAddr address.Address, msg []byte, meta MsgMeta) (*crypto.Signature, error) + WalletSign(keyAddr address.Address, msg []byte, meta types.MsgMeta) (*crypto.Signature, error) HasPassword() bool } @@ -203,7 +204,7 @@ func (w *Wallet) Export(addr address.Address, password string) (*crypto.KeyInfo, } //WalletSign used to sign message with private key -func (w *Wallet) WalletSign(addr address.Address, msg []byte, meta MsgMeta) (*crypto.Signature, error) { +func (w *Wallet) WalletSign(addr address.Address, msg []byte, meta types.MsgMeta) (*crypto.Signature, error) { ki, err := w.Find(addr) if err != nil { return nil, err diff --git a/pkg/wallet/wallet_test.go b/pkg/wallet/wallet_test.go index 55b93124e2..03f0c27bac 100644 --- a/pkg/wallet/wallet_test.go +++ b/pkg/wallet/wallet_test.go @@ -4,6 +4,8 @@ import ( "bytes" "testing" + "github.com/filecoin-project/venus/pkg/testhelpers" + "github.com/filecoin-project/go-address" "github.com/ipfs/go-datastore" "github.com/stretchr/testify/assert" @@ -13,7 +15,6 @@ import ( "github.com/filecoin-project/venus/pkg/config" "github.com/filecoin-project/venus/pkg/crypto" tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags" - "github.com/filecoin-project/venus/pkg/types" ) func newWalletAndDSBackend(t *testing.T) (*Wallet, *DSBackend) { @@ -49,7 +50,7 @@ func TestWalletSimple(t *testing.T) { assert.Equal(t, fs, backend) t.Log("find unknown address") - randomAddr := types.NewForTestGetter()() + randomAddr := testhelpers.NewForTestGetter()() assert.False(t, w.HasAddress(randomAddr)) diff --git a/tools/client/main.go b/tools/client/main.go index 52bb52a492..93fd67151f 100644 --- a/tools/client/main.go +++ b/tools/client/main.go @@ -15,7 +15,7 @@ import ( "github.com/filecoin-project/venus/app/client" "github.com/filecoin-project/venus/app/client/v0api" "github.com/filecoin-project/venus/pkg/constants" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" ) const Filecoin = "Filecoin" diff --git a/tools/conformance/driver.go b/tools/conformance/driver.go index 9ee18e0462..4095559033 100644 --- a/tools/conformance/driver.go +++ b/tools/conformance/driver.go @@ -2,11 +2,12 @@ package conformance import ( "context" - "github.com/filecoin-project/venus/pkg/util/ffiwrapper/impl" - "github.com/filecoin-project/venus/pkg/vm/vmcontext" gobig "math/big" "os" + "github.com/filecoin-project/venus/pkg/util/ffiwrapper/impl" + "github.com/filecoin-project/venus/pkg/vm/vmcontext" + "github.com/filecoin-project/venus/pkg/vm/gas" cbor "github.com/ipfs/go-ipld-cbor" @@ -27,8 +28,8 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/test-vectors/schema" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/tools/conformance/chaos" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/ipfs/go-cid" ds "github.com/ipfs/go-datastore" blockstore "github.com/ipfs/go-ipfs-blockstore" @@ -222,7 +223,7 @@ func (d *Driver) ExecuteTipset(bs blockstore.Blockstore, chainDs ds.Batching, pr type ExecuteMessageParams struct { Preroot cid.Cid Epoch abi.ChainEpoch - Message *types.UnsignedMessage + Message *types.Message CircSupply abi.TokenAmount BaseFee abi.TokenAmount @@ -325,7 +326,7 @@ func (d *Driver) ExecuteMessage(bs blockstore.Blockstore, params ExecuteMessageP // others untouched. // TODO: generate a signature in the DSL so that it's encoded in // the test vector. -func toChainMsg(msg *types.UnsignedMessage) (ret types.ChainMsg) { +func toChainMsg(msg *types.Message) (ret types.ChainMsg) { ret = msg if msg.From.Protocol() == address.SECP256K1 { ret = &types.SignedMessage{ diff --git a/tools/conformance/rand_record.go b/tools/conformance/rand_record.go index b1c2ec8a52..69f32271c7 100644 --- a/tools/conformance/rand_record.go +++ b/tools/conformance/rand_record.go @@ -3,11 +3,11 @@ package conformance import ( "context" "fmt" - "github.com/filecoin-project/venus/app/client/apiface" - "github.com/filecoin-project/venus/pkg/vm/vmcontext" "sync" - "github.com/filecoin-project/venus/pkg/types" + "github.com/filecoin-project/venus/app/client/apiface" + "github.com/filecoin-project/venus/pkg/vm/vmcontext" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/crypto" diff --git a/tools/conformance/runner.go b/tools/conformance/runner.go index 59f0629a78..8655b25aeb 100644 --- a/tools/conformance/runner.go +++ b/tools/conformance/runner.go @@ -6,12 +6,14 @@ import ( "context" "encoding/base64" "fmt" - "github.com/filecoin-project/venus/pkg/util/blockstoreutil" "io/ioutil" "os" "os/exec" "strconv" + "github.com/filecoin-project/venus/pkg/util/blockstoreutil" + types "github.com/filecoin-project/venus/venus-shared/chain" + "github.com/fatih/color" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/exitcode" @@ -24,7 +26,6 @@ import ( "github.com/ipfs/go-merkledag" "github.com/ipld/go-car" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/vm" ) @@ -147,7 +148,7 @@ func AssertMsgResult(r Reporter, expected *schema.Receipt, actual *vm.Ret, label if expected, actual := expected.GasUsed, actual.Receipt.GasUsed; expected != actual { r.Errorf("gas used of msg %s did not match; expected: %d, got: %d", label, expected, actual) } - if expected, actual := []byte(expected.ReturnValue), actual.Receipt.ReturnValue; !bytes.Equal(expected, actual) { + if expected, actual := []byte(expected.ReturnValue), actual.Receipt.Return; !bytes.Equal(expected, actual) { r.Errorf("return value of msg %s did not match; expected: %s, got: %s", label, base64.StdEncoding.EncodeToString(expected), base64.StdEncoding.EncodeToString(actual)) } } diff --git a/tools/fast/action_mpool.go b/tools/fast/action_mpool.go index 8167f06570..ce7fc3af53 100644 --- a/tools/fast/action_mpool.go +++ b/tools/fast/action_mpool.go @@ -3,7 +3,7 @@ package fast import ( "context" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" ) // MpoolLs runs the `mpool ls` command against the filecoin process. diff --git a/tools/fast/action_protocol.go b/tools/fast/action_protocol.go index 9c322d9cd7..0278f7c6f8 100644 --- a/tools/fast/action_protocol.go +++ b/tools/fast/action_protocol.go @@ -2,7 +2,8 @@ package fast import ( "context" - "github.com/filecoin-project/venus/app/submodule/apitypes" + + apitypes "github.com/filecoin-project/venus/venus-shared/api/chain" ) // Protocol runs the `protocol` command against the filecoin process diff --git a/tools/fast/action_show.go b/tools/fast/action_show.go index 45d4ab879e..207c6a956d 100644 --- a/tools/fast/action_show.go +++ b/tools/fast/action_show.go @@ -3,9 +3,8 @@ package fast import ( "context" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/ipfs/go-cid" - - "github.com/filecoin-project/venus/pkg/types" ) // ShowHeader runs the `show header` command against the filecoin process diff --git a/tools/fast/action_wallet.go b/tools/fast/action_wallet.go index 1f5aa8c04a..2eb64f2dee 100644 --- a/tools/fast/action_wallet.go +++ b/tools/fast/action_wallet.go @@ -2,16 +2,17 @@ package fast import ( "context" + "strings" + fbig "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/venus/cmd" "github.com/libp2p/go-libp2p-core/peer" - "strings" "github.com/filecoin-project/go-address" files "github.com/ipfs/go-ipfs-files" "github.com/filecoin-project/venus/pkg/crypto" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" ) // AddressNew runs the address new command against the filecoin process. diff --git a/tools/fast/series/wait_for_chain_message.go b/tools/fast/series/wait_for_chain_message.go index 44003cad28..482d1d1886 100644 --- a/tools/fast/series/wait_for_chain_message.go +++ b/tools/fast/series/wait_for_chain_message.go @@ -5,8 +5,8 @@ import ( "fmt" "io" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/tools/fast" + types "github.com/filecoin-project/venus/venus-shared/chain" "github.com/ipfs/go-cid" ) diff --git a/tools/gen_cbor/main.go b/tools/gen_cbor/main.go index 2ebec30d05..66c4de6828 100644 --- a/tools/gen_cbor/main.go +++ b/tools/gen_cbor/main.go @@ -7,7 +7,6 @@ import ( "github.com/filecoin-project/venus/pkg/market" "github.com/filecoin-project/venus/pkg/paychmgr" "github.com/filecoin-project/venus/pkg/state/tree" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/vm/dispatch" gen "github.com/whyrusleeping/cbor-gen" ) @@ -27,20 +26,20 @@ func main() { panic(err) } - if err := gen.WriteTupleEncodersToFile("./pkg/types/internal/cbor_gen.go", "internal", - types.MessageReceipt{}, - types.SignedMessage{}, - types.UnsignedMessage{}, - types.TxMeta{}, - types.Actor{}, - types.BeaconEntry{}, - types.BlockHeader{}, - types.Ticket{}, - types.ElectionProof{}, - types.BlockMsg{}, - ); err != nil { - panic(err) - } + //if err := gen.WriteTupleEncodersToFile("./pkg/types/internal/cbor_gen.go", "internal", + // types.MessageReceipt{}, + // types.SignedMessage{}, + // types.TxMeta{}, + // types.UnsignedMessage{}, + // types.Actor{}, + // types.BeaconEntry{}, + // types.BlockHeader{}, + // types.Ticket{}, + // types.ElectionProof{}, + // types.BlockMsg{}, + //); err != nil { + // panic(err) + //} if err := gen.WriteTupleEncodersToFile("./pkg/discovery/cbor_gen.go", "discovery", discovery.HelloMessage{}, diff --git a/tools/gengen/util/generator.go b/tools/gengen/util/generator.go index b426a76220..1292abb2ca 100644 --- a/tools/gengen/util/generator.go +++ b/tools/gengen/util/generator.go @@ -4,12 +4,12 @@ import ( "bytes" "context" "fmt" - "github.com/filecoin-project/venus/pkg/util/ffiwrapper/impl" - "github.com/filecoin-project/venus/pkg/vm/vmcontext" "io" mrand "math/rand" "github.com/filecoin-project/venus/pkg/fork" + "github.com/filecoin-project/venus/pkg/util/ffiwrapper/impl" + "github.com/filecoin-project/venus/pkg/vm/vmcontext" "github.com/filecoin-project/go-address" ds "github.com/ipfs/go-datastore" @@ -41,17 +41,17 @@ import ( "github.com/filecoin-project/venus/pkg/genesis" gfcstate "github.com/filecoin-project/venus/pkg/state" "github.com/filecoin-project/venus/pkg/state/tree" - "github.com/filecoin-project/venus/pkg/types" blockstore "github.com/filecoin-project/venus/pkg/util/blockstoreutil" "github.com/filecoin-project/venus/pkg/vm" "github.com/filecoin-project/venus/pkg/vm/gas" "github.com/filecoin-project/venus/pkg/vmsupport" + types "github.com/filecoin-project/venus/venus-shared/chain" ) const InitialBaseFee = 100e6 var ( - rewardActorInitialBalance = types.NewAttoFILFromFIL(1.4e9) + rewardActorInitialBalance = types.FromFil(1.4e9) ) type GenesisGenerator struct { @@ -304,12 +304,12 @@ func (g *GenesisGenerator) setupPrealloc() error { return err } - value, ok := types.NewAttoFILFromFILString(v) - if !ok { + value, err := types.ParseFIL(v) + if err != nil { return fmt.Errorf("failed to parse FIL value '%s'", v) } - _, err = g.vm.ApplyGenesisMessage(builtin.RewardActorAddr, addr, builtin.MethodSend, value, nil) + _, err = g.vm.ApplyGenesisMessage(builtin.RewardActorAddr, addr, builtin.MethodSend, abi.TokenAmount{Int: value.Int}, nil) if err != nil { return err } @@ -329,7 +329,7 @@ func (g *GenesisGenerator) genBlock(ctx context.Context) (cid.Cid, error) { return cid.Undef, err } - meta := &types.TxMeta{SecpRoot: emptyAMTCid, BLSRoot: emptyAMTCid} + meta := &types.MessageRoot{SecpkRoot: emptyAMTCid, BlsRoot: emptyAMTCid} metaCid, err := g.cst.Put(ctx, meta) if err != nil { return cid.Undef, err @@ -337,10 +337,10 @@ func (g *GenesisGenerator) genBlock(ctx context.Context) (cid.Cid, error) { geneblk := &types.BlockHeader{ Miner: builtin.SystemActorAddr, - Ticket: genesis.Ticket, - BeaconEntries: []*types.BeaconEntry{{Data: []byte{0xca, 0xfe, 0xfa, 0xce}}}, + Ticket: &genesis.Ticket, + BeaconEntries: []types.BeaconEntry{{Data: []byte{0xca, 0xfe, 0xfa, 0xce}}}, ElectionProof: new(types.ElectionProof), - Parents: types.NewTipSetKey(), + Parents: types.NewTipSetKey().Cids(), ParentWeight: big.Zero(), Height: 0, ParentStateRoot: stateRoot, @@ -610,7 +610,7 @@ func (g *GenesisGenerator) createMiner(ctx context.Context, m *CreateStorageMine } // get miner ID address createMinerReturn := power.CreateMinerReturn{} - err = createMinerReturn.UnmarshalCBOR(bytes.NewReader(out.Receipt.ReturnValue)) + err = createMinerReturn.UnmarshalCBOR(bytes.NewReader(out.Receipt.Return)) if err != nil { return address.Undef, address.Undef, err } @@ -675,7 +675,7 @@ func (g *GenesisGenerator) publishDeals(actorAddr, clientAddr address.Address, c return nil, xerrors.Errorf("execute genesis msg error") } publishStoreageDealsReturn := market.PublishStorageDealsReturn{} - err = publishStoreageDealsReturn.UnmarshalCBOR(bytes.NewReader(out.Receipt.ReturnValue)) + err = publishStoreageDealsReturn.UnmarshalCBOR(bytes.NewReader(out.Receipt.Return)) if err != nil { return nil, err } @@ -696,7 +696,7 @@ func (g *GenesisGenerator) getDealWeight(dealID abi.DealID, sectorExpiry abi.Cha return big.Zero(), big.Zero(), xerrors.Errorf("execute genesis msg error") } verifyDealsReturn := market.VerifyDealsForActivationReturn{} - err = verifyDealsReturn.UnmarshalCBOR(bytes.NewReader(weightOut.Receipt.ReturnValue)) + err = verifyDealsReturn.UnmarshalCBOR(bytes.NewReader(weightOut.Receipt.Return)) if err != nil { return big.Zero(), big.Zero(), err } @@ -716,7 +716,7 @@ func (g *GenesisGenerator) doExecValue(ctx context.Context, to, from address.Add if ret.Receipt.ExitCode != 0 { return nil, xerrors.Errorf("execute genesis msg error") } - return ret.Receipt.ReturnValue, nil + return ret.Receipt.Return, nil } func (g *GenesisGenerator) currentTotalPower(ctx context.Context, maddr address.Address) (*power.CurrentTotalPowerReturn, error) { diff --git a/tools/gengen/util/gengen.go b/tools/gengen/util/gengen.go index f730c00327..f32a02d405 100644 --- a/tools/gengen/util/gengen.go +++ b/tools/gengen/util/gengen.go @@ -19,7 +19,7 @@ import ( "github.com/filecoin-project/venus/pkg/crypto" "github.com/filecoin-project/venus/pkg/genesis" - "github.com/filecoin-project/venus/pkg/types" + types "github.com/filecoin-project/venus/venus-shared/chain" ) // CreateStorageMinerConfig holds configuration options used to create a storage diff --git a/tools/seed/seed.go b/tools/seed/seed.go index 9d08b139eb..b9cd5b1605 100644 --- a/tools/seed/seed.go +++ b/tools/seed/seed.go @@ -7,13 +7,15 @@ import ( "encoding/hex" "encoding/json" "fmt" - "github.com/filecoin-project/venus/pkg/util/ffiwrapper/impl" "io/ioutil" "os" "path/filepath" "strconv" "strings" + "github.com/filecoin-project/venus/pkg/util/ffiwrapper/impl" + types "github.com/filecoin-project/venus/venus-shared/chain" + ffi "github.com/filecoin-project/filecoin-ffi" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-commp-utils/zerocomm" @@ -31,7 +33,6 @@ import ( "github.com/filecoin-project/venus/pkg/crypto" "github.com/filecoin-project/venus/pkg/gen/genesis" - "github.com/filecoin-project/venus/pkg/types" "github.com/filecoin-project/venus/pkg/util/ffiwrapper/basicfs" "github.com/filecoin-project/venus/pkg/util/storiface" )