diff --git a/app/submodule/mpool/mpool_submodule.go b/app/submodule/mpool/mpool_submodule.go index 61853af7ae..ee6af4cb44 100644 --- a/app/submodule/mpool/mpool_submodule.go +++ b/app/submodule/mpool/mpool_submodule.go @@ -23,7 +23,6 @@ import ( "github.com/filecoin-project/venus/pkg/constants" "github.com/filecoin-project/venus/pkg/messagepool" "github.com/filecoin-project/venus/pkg/messagepool/journal" - "github.com/filecoin-project/venus/pkg/messagesigner" "github.com/filecoin-project/venus/pkg/repo" v0api "github.com/filecoin-project/venus/venus-shared/api/chain/v0" v1api "github.com/filecoin-project/venus/venus-shared/api/chain/v1" @@ -56,7 +55,7 @@ type MessagePoolSubmodule struct { //nolint MessageSub *pubsub.Subscription MPool *messagepool.MessagePool - msgSigner *messagesigner.MessageSigner + msgSigner *messagepool.MessageSigner chain *chain.ChainSubmodule network *network.NetworkSubmodule walletAPI v1api.IWallet @@ -95,7 +94,7 @@ func NewMpoolSubmodule(ctx context.Context, cfg messagepoolConfig, walletAPI: wallet.API(), network: network, networkCfg: cfg.Repo().Config().NetworkParams, - msgSigner: messagesigner.NewMessageSigner(wallet.WalletIntersection(), mp, cfg.Repo().MetaDatastore()), + msgSigner: messagepool.NewMessageSigner(wallet.WalletIntersection(), mp, cfg.Repo().MetaDatastore()), }, nil } diff --git a/app/submodule/wallet/wallet_api.go b/app/submodule/wallet/wallet_api.go index 19c03c1ba5..6567344166 100644 --- a/app/submodule/wallet/wallet_api.go +++ b/app/submodule/wallet/wallet_api.go @@ -10,7 +10,6 @@ import ( "github.com/filecoin-project/venus/app/submodule/wallet/remotewallet" "github.com/filecoin-project/venus/pkg/crypto" - "github.com/filecoin-project/venus/pkg/messagesigner" "github.com/filecoin-project/venus/pkg/wallet" v1api "github.com/filecoin-project/venus/venus-shared/api/chain/v1" "github.com/filecoin-project/venus/venus-shared/types" @@ -124,7 +123,7 @@ 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.Message) (*types.SignedMessage, error) { - sb, err := messagesigner.SigningBytes(msg, types.AddressProtocol2SignType(k.Protocol())) + sb, err := msg.SigningBytes(types.AddressProtocol2SignType(k.Protocol())) if err != nil { return nil, err } diff --git a/pkg/messagepool/messagepool_test.go b/pkg/messagepool/messagepool_test.go index a913ff19e8..bcc938a2c7 100644 --- a/pkg/messagepool/messagepool_test.go +++ b/pkg/messagepool/messagepool_test.go @@ -491,11 +491,12 @@ func TestCheckMessageBig(t *testing.T) { GasPremium: types.NewInt(1), Params: make([]byte, 41<<10), // 41KiB payload } + sb, err := msg.SigningBytes(types.AddressProtocol2SignType(from.Protocol())) + assert.NoError(t, err) + + sig, err := w.WalletSign(context.Background(), from, sb, types.MsgMeta{}) + assert.NoError(t, err) - sig, err := w.WalletSign(context.Background(), from, msg.Cid().Bytes(), types.MsgMeta{}) - if err != nil { - panic(err) - } sm := &types.SignedMessage{ Message: *msg, Signature: *sig, @@ -515,7 +516,10 @@ func TestCheckMessageBig(t *testing.T) { Params: make([]byte, 64<<10), // 64KiB payload } - sig, err := w.WalletSign(context.Background(), from, msg.Cid().Bytes(), types.MsgMeta{}) + sb, err := msg.SigningBytes(types.AddressProtocol2SignType(from.Protocol())) + assert.NoError(t, err) + + sig, err := w.WalletSign(context.Background(), from, sb, types.MsgMeta{}) if err != nil { panic(err) } diff --git a/pkg/messagesigner/messagesigner.go b/pkg/messagepool/messagesigner.go similarity index 86% rename from pkg/messagesigner/messagesigner.go rename to pkg/messagepool/messagesigner.go index e84bdaffa6..fb9e6b90c1 100644 --- a/pkg/messagesigner/messagesigner.go +++ b/pkg/messagepool/messagesigner.go @@ -1,4 +1,4 @@ -package messagesigner +package messagepool import ( "bytes" @@ -8,17 +8,13 @@ import ( "sync" "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/venus/pkg/wallet" "github.com/filecoin-project/venus/venus-shared/types" "github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore/namespace" - logging "github.com/ipfs/go-log/v2" cbg "github.com/whyrusleeping/cbor-gen" ) -var log = logging.Logger("messagepool") - const dsKeyActorNonce = "ActorNextNonce" type MpoolNonceAPI interface { @@ -59,7 +55,7 @@ func (ms *MessageSigner) SignMessage(ctx context.Context, msg *types.Message, cb // Sign the message with the nonce msg.Nonce = nonce - sb, err := SigningBytes(msg, types.AddressProtocol2SignType(msg.From.Protocol())) + sb, err := msg.SigningBytes(types.AddressProtocol2SignType(msg.From.Protocol())) if err != nil { return nil, err } @@ -164,19 +160,3 @@ func (ms *MessageSigner) saveNonce(ctx context.Context, addr address.Address, no func (ms *MessageSigner) dstoreKey(addr address.Address) datastore.Key { return datastore.KeyWithNamespaces([]string{dsKeyActorNonce, addr.String()}) } - -func SigningBytes(msg *types.Message, sigType crypto.SigType) ([]byte, error) { - if sigType == crypto.SigTypeDelegated { - txArgs, err := types.EthTxArgsFromMessage(msg) - if err != nil { - return nil, fmt.Errorf("failed to reconstruct eth transaction: %w", err) - } - rlpEncodedMsg, err := txArgs.ToRlpUnsignedMsg() - if err != nil { - return nil, fmt.Errorf("failed to repack eth rlp message: %w", err) - } - return rlpEncodedMsg, nil - } - - return msg.Cid().Bytes(), nil -} diff --git a/pkg/messagesigner/messagesigner_test.go b/pkg/messagepool/messagesigner_test.go similarity index 99% rename from pkg/messagesigner/messagesigner_test.go rename to pkg/messagepool/messagesigner_test.go index 00945b8f57..18ef423112 100644 --- a/pkg/messagesigner/messagesigner_test.go +++ b/pkg/messagepool/messagesigner_test.go @@ -1,5 +1,5 @@ // stm: #unit -package messagesigner +package messagepool import ( "context" diff --git a/pkg/messagepool/provider.go b/pkg/messagepool/provider.go index c6ea3aa794..514609f6aa 100644 --- a/pkg/messagepool/provider.go +++ b/pkg/messagepool/provider.go @@ -12,7 +12,6 @@ import ( "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/venus/pkg/chain" "github.com/filecoin-project/venus/pkg/config" - "github.com/filecoin-project/venus/pkg/messagesigner" "github.com/filecoin-project/venus/pkg/statemanger" "github.com/filecoin-project/venus/venus-shared/actors/policy" "github.com/filecoin-project/venus/venus-shared/types" @@ -50,7 +49,7 @@ type mpoolProvider struct { config *config.NetworkParamsConfig ps *pubsub.PubSub - lite messagesigner.MpoolNonceAPI + lite MpoolNonceAPI } var _ Provider = (*mpoolProvider)(nil) @@ -65,7 +64,7 @@ func NewProvider(sm *statemanger.Stmgr, cs *chain.Store, cms *chain.MessageStore } } -func NewProviderLite(sm *chain.Store, ps *pubsub.PubSub, noncer messagesigner.MpoolNonceAPI) Provider { +func NewProviderLite(sm *chain.Store, ps *pubsub.PubSub, noncer MpoolNonceAPI) Provider { return &mpoolProvider{sm: sm, ps: ps, lite: noncer} } diff --git a/venus-shared/actors/types/message.go b/venus-shared/actors/types/message.go index e927eb0504..0be2cc7cd7 100644 --- a/venus-shared/actors/types/message.go +++ b/venus-shared/actors/types/message.go @@ -8,6 +8,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/crypto" "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/venus/venus-shared/types/params" blocks "github.com/ipfs/go-block-format" @@ -208,4 +209,20 @@ func (m *Message) RequiredFunds() abi.TokenAmount { return abi.TokenAmount{Int: BigMul(BigInt{Int: m.GasFeeCap.Int}, NewInt(uint64(m.GasLimit))).Int} } +func (m *Message) SigningBytes(sigType crypto.SigType) ([]byte, error) { + if sigType == crypto.SigTypeDelegated { + txArgs, err := EthTxArgsFromMessage(m) + if err != nil { + return nil, fmt.Errorf("failed to reconstruct eth transaction: %w", err) + } + rlpEncodedMsg, err := txArgs.ToRlpUnsignedMsg() + if err != nil { + return nil, fmt.Errorf("failed to repack eth rlp message: %w", err) + } + return rlpEncodedMsg, nil + } + + return m.Cid().Bytes(), nil +} + var _ ChainMsg = (*Message)(nil)