From dc35f2f40ca71fc61eef2312e205ef66301967a5 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Wed, 22 Jul 2020 20:02:29 +0200 Subject: [PATCH] Use MpoolPushMessage Signed-off-by: Jakub Sztandera --- api/test/paych.go | 2 +- node/impl/paych/paych.go | 58 +++++++--------------------------------- node/node_test.go | 1 + 3 files changed, 11 insertions(+), 50 deletions(-) diff --git a/api/test/paych.go b/api/test/paych.go index 952f832ff..5972747c9 100644 --- a/api/test/paych.go +++ b/api/test/paych.go @@ -125,7 +125,7 @@ func TestPaymentChannels(t *testing.T, b APIBuilder, blocktime time.Duration) { t.Fatal(err) } - res = waitForMessage(ctx, t, paymentCreator, settleMsgCid, time.Second, "settle") + res = waitForMessage(ctx, t, paymentCreator, settleMsgCid, time.Second*10, "settle") if res.Receipt.ExitCode != 0 { t.Fatal("Unable to settle payment channel") } diff --git a/node/impl/paych/paych.go b/node/impl/paych/paych.go index 6fe4aa98a..c9f2f215d 100644 --- a/node/impl/paych/paych.go +++ b/node/impl/paych/paych.go @@ -114,32 +114,18 @@ func (a *PaychAPI) PaychSettle(ctx context.Context, addr address.Address) (cid.C return cid.Undef, err } - nonce, err := a.MpoolGetNonce(ctx, ci.Control) - if err != nil { - return cid.Undef, err - } - msg := &types.Message{ To: addr, From: ci.Control, Value: types.NewInt(0), Method: builtin.MethodsPaych.Settle, - Nonce: nonce, - - GasLimit: 0, - GasPrice: types.NewInt(0), } + smgs, err := a.MpoolPushMessage(ctx, msg) - smsg, err := a.WalletSignMessage(ctx, ci.Control, msg) if err != nil { return cid.Undef, err } - - if _, err := a.MpoolPush(ctx, smsg); err != nil { - return cid.Undef, err - } - - return smsg.Cid(), nil + return smgs.Cid(), nil } func (a *PaychAPI) PaychCollect(ctx context.Context, addr address.Address) (cid.Cid, error) { @@ -149,31 +135,18 @@ func (a *PaychAPI) PaychCollect(ctx context.Context, addr address.Address) (cid. return cid.Undef, err } - nonce, err := a.MpoolGetNonce(ctx, ci.Control) - if err != nil { - return cid.Undef, err - } - msg := &types.Message{ To: addr, From: ci.Control, Value: types.NewInt(0), Method: builtin.MethodsPaych.Collect, - Nonce: nonce, - - GasLimit: 0, - GasPrice: types.NewInt(0), } - smsg, err := a.WalletSignMessage(ctx, ci.Control, msg) + smsg, err := a.MpoolPushMessage(ctx, msg) if err != nil { return cid.Undef, err } - if _, err := a.MpoolPush(ctx, smsg); err != nil { - return cid.Undef, err - } - return smsg.Cid(), nil } @@ -253,11 +226,6 @@ func (a *PaychAPI) PaychVoucherSubmit(ctx context.Context, ch address.Address, s return cid.Undef, err } - nonce, err := a.MpoolGetNonce(ctx, ci.Control) - if err != nil { - return cid.Undef, err - } - if sv.Extra != nil || len(sv.SecretPreimage) > 0 { return cid.Undef, fmt.Errorf("cant handle more advanced payment channel stuff yet") } @@ -270,25 +238,17 @@ func (a *PaychAPI) PaychVoucherSubmit(ctx context.Context, ch address.Address, s } msg := &types.Message{ - From: ci.Control, - To: ch, - Value: types.NewInt(0), - Nonce: nonce, - Method: builtin.MethodsPaych.UpdateChannelState, - Params: enc, - GasLimit: 0, - GasPrice: types.NewInt(0), + From: ci.Control, + To: ch, + Value: types.NewInt(0), + Method: builtin.MethodsPaych.UpdateChannelState, + Params: enc, } - smsg, err := a.WalletSignMessage(ctx, ci.Control, msg) + smsg, err := a.MpoolPushMessage(ctx, msg) if err != nil { return cid.Undef, err } - if _, err := a.MpoolPush(ctx, smsg); err != nil { - return cid.Undef, err - } - - // TODO: should we wait for it...? return smsg.Cid(), nil } diff --git a/node/node_test.go b/node/node_test.go index d15763b38..be3b8a785 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -552,6 +552,7 @@ func TestPaymentChannels(t *testing.T) { logging.SetLogLevel("chainstore", "ERROR") logging.SetLogLevel("chain", "ERROR") logging.SetLogLevel("sub", "ERROR") + logging.SetLogLevel("pubsub", "ERROR") logging.SetLogLevel("storageminer", "ERROR") test.TestPaymentChannels(t, mockSbBuilder, 5*time.Millisecond)