From 4c4b10c6177783622eb51f1b33888bc44034192b Mon Sep 17 00:00:00 2001 From: Shrenuj Bansal Date: Tue, 13 Sep 2022 16:33:55 -0400 Subject: [PATCH] Ignore uuid check for messages with uuid not set --- itests/mpool_msg_uuid_test.go | 52 +++++++++++++++++++++++++++++++++++ node/impl/full/mpool.go | 7 +++-- 2 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 itests/mpool_msg_uuid_test.go diff --git a/itests/mpool_msg_uuid_test.go b/itests/mpool_msg_uuid_test.go new file mode 100644 index 000000000..74e2f2a23 --- /dev/null +++ b/itests/mpool_msg_uuid_test.go @@ -0,0 +1,52 @@ +package itests + +import ( + "context" + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/go-state-types/exitcode" + "github.com/filecoin-project/lotus/api" + "github.com/filecoin-project/lotus/chain/types" + "github.com/filecoin-project/lotus/itests/kit" + "github.com/filecoin-project/lotus/node/config" + "github.com/stretchr/testify/require" + "testing" + "time" +) + +func TestMsgWithoutUuidWithMaxFee(t *testing.T) { + ctx := context.Background() + + kit.QuietMiningLogs() + + node, _, ens := kit.EnsembleMinimal(t, kit.MockProofs()) + ens.InterconnectAll().BeginMining(10 * time.Millisecond) + + bal, err := node.WalletBalance(ctx, node.DefaultKey.Address) + require.NoError(t, err) + + // send self half of account balance + msgHalfBal := &types.Message{ + From: node.DefaultKey.Address, + To: node.DefaultKey.Address, + Value: big.Div(bal, big.NewInt(2)), + } + smHalfBal, err := node.MpoolPushMessage(ctx, msgHalfBal, &api.MessageSendSpec{MaxFee: abi.TokenAmount(config.DefaultDefaultMaxFee)}) + require.NoError(t, err) + mLookup, err := node.StateWaitMsg(ctx, smHalfBal.Cid(), 3, api.LookbackNoLimit, true) + require.NoError(t, err) + require.Equal(t, exitcode.Ok, mLookup.Receipt.ExitCode) + + msgQuarterBal := &types.Message{ + From: node.DefaultKey.Address, + To: node.DefaultKey.Address, + Value: big.Div(bal, big.NewInt(4)), + } + smQuarterBal, err := node.MpoolPushMessage(ctx, msgQuarterBal, &api.MessageSendSpec{MaxFee: abi.TokenAmount(config.DefaultDefaultMaxFee)}) + require.NoError(t, err) + + require.Equal(t, msgQuarterBal.Value, smQuarterBal.Message.Value) + mLookup, err = node.StateWaitMsg(ctx, smQuarterBal.Cid(), 3, api.LookbackNoLimit, true) + require.NoError(t, err) + require.Equal(t, exitcode.Ok, mLookup.Receipt.ExitCode) +} diff --git a/node/impl/full/mpool.go b/node/impl/full/mpool.go index 98b2ac8a6..a9f1ebda9 100644 --- a/node/impl/full/mpool.go +++ b/node/impl/full/mpool.go @@ -3,6 +3,7 @@ package full import ( "context" "encoding/json" + "github.com/google/uuid" "github.com/ipfs/go-cid" "go.uber.org/fx" @@ -142,8 +143,8 @@ func (a *MpoolAPI) MpoolPushMessage(ctx context.Context, msg *types.Message, spe msg = &cp inMsg := *msg - // Check if this uuid has already been processed - if spec != nil { + // Check if this uuid has already been processed. Ignore if uuid is not populated + if (spec != nil) && (spec.MsgUuid != uuid.UUID{}) { signedMessage, err := a.MessageSigner.GetSignedMessage(ctx, spec.MsgUuid) if err == nil { log.Warnf("Message already processed. cid=%s", signedMessage.Cid()) @@ -206,7 +207,7 @@ func (a *MpoolAPI) MpoolPushMessage(ctx context.Context, msg *types.Message, spe } // Store uuid->signed message in datastore - if spec != nil { + if (spec != nil) && (spec.MsgUuid != uuid.UUID{}) { err = a.MessageSigner.StoreSignedMessage(ctx, spec.MsgUuid, signedMsg) if err != nil { return nil, err