Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
30 changes: 20 additions & 10 deletions backend/ethereum/channel/funder.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,23 +336,33 @@ func (f *Funder) waitForFundingConfirmation(ctx context.Context, request channel
log.Debugf("peer[%d]: got: %v, remaining for [%d,%d] = %v. N: %d", request.Idx, event.Amount, asset.assetIndex, idx, amount, N)

case <-ctx.Done():
var indices []channel.Index
for k, bals := range agreement {
if bals.Sign() == 1 {
indices = append(indices, channel.Index(k))
}
}
if len(indices) != 0 {
return &channel.AssetFundingError{Asset: asset.assetIndex, TimedOutPeers: indices}
}
return nil
return fundingTimeoutError(agreement, asset)
case err := <-subErr:
// Resolve race between ctx and subErr, as ctx fires both events.
select {
case <-ctx.Done():
return fundingTimeoutError(agreement, asset)
default:
}
return err
}
}
return nil
}

func fundingTimeoutError(agreement []channel.Bal, asset assetHolder) error {
var indices []channel.Index
for k, bals := range agreement {
if bals.Sign() == 1 {
indices = append(indices, channel.Index(k))
}
}
if len(indices) != 0 {
return &channel.AssetFundingError{Asset: asset.assetIndex, TimedOutPeers: indices}
}
return nil
}

func partIdx(partID [32]byte, fundingIDs [][32]byte) int {
for i, id := range fundingIDs {
if id == partID {
Expand Down
6 changes: 3 additions & 3 deletions backend/ethereum/channel/funder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func testFundingTimeout(t *testing.T, faultyPeer, n int) {
for i, funder := range funders {
sleepTime := time.Millisecond * time.Duration(rng.Int63n(10)+1)
i, funder := i, funder
go ct.StageN("funding loop", n, func(rt pkgtest.ConcT) {
go ct.StageN("funding loop", n, func(t pkgtest.ConcT) {
// Faulty peer does not fund the channel.
if i == faultyPeer {
return
Expand All @@ -307,13 +307,13 @@ func testFundingTimeout(t *testing.T, faultyPeer, n int) {
req := channel.NewFundingReq(params, &channel.State{Allocation: *alloc}, channel.Index(i), alloc.Balances)
err := funder.Fund(ctx, *req)
require.Error(t, err)
require.True(rt, channel.IsFundingTimeoutError(err), "funder should return FundingTimeoutError")
require.True(t, channel.IsFundingTimeoutError(err), "funder should return FundingTimeoutError")
pErr := errors.Cause(err).(channel.FundingTimeoutError) // unwrap error
// Check that `faultyPeer` is reported as faulty.
require.Len(t, pErr.Errors, len(alloc.Assets))
for _, e := range pErr.Errors {
require.Len(t, e.TimedOutPeers, 1)
assert.Equal(t, channel.Index(faultyPeer), e.TimedOutPeers[0], "Peer should be detected as erroneous")
require.Equal(t, channel.Index(faultyPeer), e.TimedOutPeers[0], "Peer should be detected as erroneous")
}
outer:
for a := 0; a < len(alloc.Assets); a++ {
Expand Down