From 46b7546d51ab44ede7f8569ec8138b75e3aaaf85 Mon Sep 17 00:00:00 2001 From: Dirk McCormick Date: Wed, 22 Jul 2020 13:55:31 -0400 Subject: [PATCH] fix: zero out gas limit --- api/test/paych.go | 42 +++++++++++++++++++++++++++++----------- node/impl/paych/paych.go | 2 +- paychmgr/paych.go | 8 ++++---- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/api/test/paych.go b/api/test/paych.go index ddbf17857..952f832ff 100644 --- a/api/test/paych.go +++ b/api/test/paych.go @@ -9,6 +9,9 @@ import ( "testing" "time" + "github.com/filecoin-project/lotus/api" + "github.com/ipfs/go-cid" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/events" @@ -72,10 +75,8 @@ func TestPaymentChannels(t *testing.T, b APIBuilder, blocktime time.Duration) { if err != nil { t.Fatal(err) } - res, err := paymentCreator.StateWaitMsg(ctx, channelInfo.ChannelMessage, 1) - if res.Receipt.ExitCode != 0 { - t.Fatal("did not successfully create payment channel") - } + + res := waitForMessage(ctx, t, paymentCreator, channelInfo.ChannelMessage, time.Second, "channel create") var params initactor.ExecReturn err = params.UnmarshalCBOR(bytes.NewReader(res.Receipt.Return)) if err != nil { @@ -123,10 +124,8 @@ func TestPaymentChannels(t *testing.T, b APIBuilder, blocktime time.Duration) { if err != nil { t.Fatal(err) } - res, err = paymentCreator.StateWaitMsg(ctx, settleMsgCid, 1) - if err != nil { - t.Fatal(err) - } + + res = waitForMessage(ctx, t, paymentCreator, settleMsgCid, time.Second, "settle") if res.Receipt.ExitCode != 0 { t.Fatal("Unable to settle payment channel") } @@ -158,7 +157,11 @@ func TestPaymentChannels(t *testing.T, b APIBuilder, blocktime time.Duration) { return preds.OnPaymentChannelActorChanged(channel, preds.OnToSendAmountChanges())(ctx, oldTs.Key(), newTs.Key()) }) - <-finished + select { + case <-finished: + case <-time.After(time.Second): + t.Fatal("Timed out waiting for receiver to submit vouchers") + } // collect funds (from receiver, though either party can do it) collectMsg, err := paymentReceiver.PaychCollect(ctx, channel) @@ -193,6 +196,23 @@ func TestPaymentChannels(t *testing.T, b APIBuilder, blocktime time.Duration) { bm.stop() } +func waitForMessage(ctx context.Context, t *testing.T, paymentCreator TestNode, msgCid cid.Cid, duration time.Duration, desc string) *api.MsgLookup { + ctx, cancel := context.WithTimeout(ctx, duration) + defer cancel() + + fmt.Println("Waiting for", desc) + res, err := paymentCreator.StateWaitMsg(ctx, msgCid, 1) + if err != nil { + fmt.Println("Error waiting for", desc, err) + t.Fatal(err) + } + if res.Receipt.ExitCode != 0 { + t.Fatal("did not successfully send %s", desc) + } + fmt.Println("Confirmed", desc) + return res +} + type blockMiner struct { ctx context.Context t *testing.T @@ -243,8 +263,8 @@ func sendFunds(ctx context.Context, t *testing.T, sender TestNode, addr address. From: senderAddr, To: addr, Value: amount, - GasLimit: 100_000_000, - GasPrice: abi.NewTokenAmount(1000), + GasLimit: 0, + GasPrice: abi.NewTokenAmount(0), } sm, err := sender.MpoolPushMessage(ctx, msg) diff --git a/node/impl/paych/paych.go b/node/impl/paych/paych.go index d20157388..6fe4aa98a 100644 --- a/node/impl/paych/paych.go +++ b/node/impl/paych/paych.go @@ -161,7 +161,7 @@ func (a *PaychAPI) PaychCollect(ctx context.Context, addr address.Address) (cid. Method: builtin.MethodsPaych.Collect, Nonce: nonce, - GasLimit: 100_000_000, + GasLimit: 0, GasPrice: types.NewInt(0), } diff --git a/paychmgr/paych.go b/paychmgr/paych.go index d78afb381..85db664cd 100644 --- a/paychmgr/paych.go +++ b/paychmgr/paych.go @@ -185,7 +185,7 @@ func (pm *Manager) checkVoucherValid(ctx context.Context, ch address.Address, sv // CheckVoucherSpendable checks if the given voucher is currently spendable func (pm *Manager) CheckVoucherSpendable(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (bool, error) { - owner, err := pm.getPaychOwner(ctx, ch) + recipient, err := pm.getPaychRecipient(ctx, ch) if err != nil { return false, err } @@ -222,7 +222,7 @@ func (pm *Manager) CheckVoucherSpendable(ctx context.Context, ch address.Address } ret, err := pm.sm.Call(ctx, &types.Message{ - From: owner, + From: recipient, To: ch, Method: builtin.MethodsPaych.UpdateChannelState, Params: enc, @@ -238,13 +238,13 @@ func (pm *Manager) CheckVoucherSpendable(ctx context.Context, ch address.Address return true, nil } -func (pm *Manager) getPaychOwner(ctx context.Context, ch address.Address) (address.Address, error) { +func (pm *Manager) getPaychRecipient(ctx context.Context, ch address.Address) (address.Address, error) { var state paych.State if _, err := pm.sm.LoadActorState(ctx, ch, &state, nil); err != nil { return address.Address{}, err } - return state.From, nil + return state.To, nil } func (pm *Manager) AddVoucher(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) {