Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify Voucher locks in VoucherValidUnlocked #5609

Merged
merged 4 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions paychmgr/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ func (pm *Manager) trackInboundChannel(ctx context.Context, ch address.Address)
return pm.store.TrackChannel(stateCi)
}

// TODO: secret vs proof doesn't make sense, there is only one, not two
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we had both at some point in the past

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We did. But it wasn't usable so we removed it from actors.

func (pm *Manager) SubmitVoucher(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error) {
if len(proof) > 0 {
return cid.Undef, errProofNotSupported
Expand Down
14 changes: 14 additions & 0 deletions paychmgr/paych.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,20 @@ func (ca *channelAccessor) checkVoucherValidUnlocked(ctx context.Context, ch add
return nil, xerrors.Errorf("voucher ChannelAddr doesn't match channel address, got %s, expected %s", sv.ChannelAddr, ch)
}

// check voucher is unlocked
Stebalien marked this conversation as resolved.
Show resolved Hide resolved
if sv.Extra != nil {
return nil, xerrors.Errorf("voucher is Message Locked")
}
if sv.TimeLockMax != 0 {
return nil, xerrors.Errorf("voucher is Max Time Locked")
}
if sv.TimeLockMin != 0 {
return nil, xerrors.Errorf("voucher is Min Time Locked")
}
if len(sv.SecretPreimage) != 0 {
return nil, xerrors.Errorf("voucher is Hash Locked")
}

// Load payment channel actor state
act, pchState, err := ca.sa.loadPaychActorState(ctx, ch)
if err != nil {
Expand Down
18 changes: 7 additions & 11 deletions paychmgr/paych_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ func TestCheckSpendable(t *testing.T) {
voucherLane := uint64(1)
nonce := uint64(1)
voucherAmount := big.NewInt(1)
voucher := createTestVoucherWithExtra(t, s.ch, voucherLane, nonce, voucherAmount, s.fromKeyPrivate)
voucher := createTestVoucher(t, s.ch, voucherLane, nonce, voucherAmount, s.fromKeyPrivate)

// Add voucher
minDelta := big.NewInt(0)
Expand Down Expand Up @@ -660,38 +660,34 @@ func TestSubmitVoucher(t *testing.T) {
voucherLane := uint64(1)
nonce := uint64(1)
voucherAmount := big.NewInt(1)
voucher := createTestVoucherWithExtra(t, s.ch, voucherLane, nonce, voucherAmount, s.fromKeyPrivate)
voucher := createTestVoucher(t, s.ch, voucherLane, nonce, voucherAmount, s.fromKeyPrivate)

// Add voucher
minDelta := big.NewInt(0)
_, err := s.mgr.AddVoucherInbound(ctx, s.ch, voucher, nil, minDelta)
require.NoError(t, err)

// Submit voucher
secret := []byte("secret")
submitCid, err := s.mgr.SubmitVoucher(ctx, s.ch, voucher, secret, nil)
submitCid, err := s.mgr.SubmitVoucher(ctx, s.ch, voucher, nil, nil)
require.NoError(t, err)

// Check that the secret was passed through correctly
msg := s.mock.pushedMessages(submitCid)
var p paych2.UpdateChannelStateParams
err = p.UnmarshalCBOR(bytes.NewReader(msg.Message.Params))
require.NoError(t, err)
require.Equal(t, secret, p.Secret)

// Submit a voucher without first adding it
nonce++
voucherAmount = big.NewInt(3)
secret3 := []byte("secret2")
voucher = createTestVoucherWithExtra(t, s.ch, voucherLane, nonce, voucherAmount, s.fromKeyPrivate)
submitCid, err = s.mgr.SubmitVoucher(ctx, s.ch, voucher, secret3, nil)
voucher = createTestVoucher(t, s.ch, voucherLane, nonce, voucherAmount, s.fromKeyPrivate)
submitCid, err = s.mgr.SubmitVoucher(ctx, s.ch, voucher, nil, nil)
require.NoError(t, err)

msg = s.mock.pushedMessages(submitCid)
var p3 paych2.UpdateChannelStateParams
err = p3.UnmarshalCBOR(bytes.NewReader(msg.Message.Params))
require.NoError(t, err)
require.Equal(t, secret3, p3.Secret)

// Verify that vouchers are marked as submitted
vis, err := s.mgr.ListVouchers(ctx, s.ch)
Expand All @@ -703,7 +699,7 @@ func TestSubmitVoucher(t *testing.T) {
}

// Attempting to submit the same voucher again should fail
_, err = s.mgr.SubmitVoucher(ctx, s.ch, voucher, secret3, nil)
_, err = s.mgr.SubmitVoucher(ctx, s.ch, voucher, nil, nil)
require.Error(t, err)
}

Expand Down Expand Up @@ -790,7 +786,7 @@ func createTestVoucher(t *testing.T, ch address.Address, voucherLane uint64, non
return sv
}

func createTestVoucherWithExtra(t *testing.T, ch address.Address, voucherLane uint64, nonce uint64, voucherAmount big.Int, key []byte) *paych2.SignedVoucher {
func createTestVoucherWithExtra(t *testing.T, ch address.Address, voucherLane uint64, nonce uint64, voucherAmount big.Int, key []byte) *paych2.SignedVoucher { //nolint:deadcode
sv := &paych2.SignedVoucher{
ChannelAddr: ch,
Lane: voucherLane,
Expand Down