Skip to content

Commit

Permalink
Fix(Adjudicator): Remove dependencies on Secondary in everything that…
Browse files Browse the repository at this point in the history
… uses the AdjudicatorReq object during conclusion of a channel. Also remove functions that are necessary for the Secondary option.

Update(go.mod/go.sum): Update go.mod and go.sum to the most recent go-perun commit.

Signed-off-by: Ilja von Hoessle <[email protected]>
  • Loading branch information
iljabvh committed Jan 12, 2024
1 parent b985d8a commit 64796c1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 55 deletions.
29 changes: 1 addition & 28 deletions channel/conclude.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,8 @@ func (a *Adjudicator) ensureConcluded(ctx context.Context, req channel.Adjudicat
return nil
}

// If the secondary flag is set, we wait for someone else to conclude.
concluded, err := a.waitConcludedSecondary(ctx, req)
if err != nil {
return errors.WithMessage(err, "waiting for secondary conclude")
} else if concluded {
return nil
}

// Wait until we can conclude.
err = a.waitConcludable(ctx, req)
err := a.waitConcludable(ctx, req)
if err != nil {
return fmt.Errorf("waiting for concludability: %w", err)
}
Expand Down Expand Up @@ -161,25 +153,6 @@ func (a *Adjudicator) checkConcludedState(
}
}

func (a *Adjudicator) waitConcludedSecondary(ctx context.Context, req channel.AdjudicatorReq) (concluded bool, err error) {
// In final Register calls, as the non-initiator, we optimistically wait for
// the other party to send the transaction first for
// `secondaryWaitBlocks + TxFinalityDepth` many blocks.
if req.Tx.IsFinal && req.Secondary {
// Create subscription.
sub, events, subErr, err := a.createEventSub(ctx, req.Tx.ID, false)
if err != nil {
return false, errors.WithMessage(err, "subscribing")
}
defer sub.Close()

// Wait for concluded event.
waitBlocks := secondaryWaitBlocks + int(a.txFinalityDepth)
return waitConcludedForNBlocks(ctx, a, events, subErr, waitBlocks)
}
return false, nil
}

func (a *Adjudicator) conclude(ctx context.Context, req channel.AdjudicatorReq, subStates channel.StateMap) error {
// If the on-chain state resulted from forced execution, we do not have a fully-signed state and cannot call concludeFinal.
forceExecuted, err := a.isForceExecuted(ctx, req.Params.ID())
Expand Down
41 changes: 15 additions & 26 deletions channel/conclude_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,19 @@ func testConcludeFinal(t *testing.T, numParts int) {
ctx, cancel := context.WithTimeout(context.Background(), defaultTxTimeout)
defer cancel()
ct = pkgtest.NewConcurrent(t)
initiator := int(rng.Int31n(int32(numParts))) // pick a random initiator
for i := 0; i < numParts; i++ {
i := i
go ct.StageN("register", numParts, func(t pkgtest.ConcT) {
req := channel.AdjudicatorReq{
Params: params,
Acc: s.Accs[i],
Idx: channel.Index(i),
Tx: tx,
Secondary: (i != initiator),
Params: params,
Acc: s.Accs[i],
Idx: channel.Index(i),
Tx: tx,
}
diff, err := test.NonceDiff(s.Accs[i].Address(), s.Adjs[i], func() error {
return s.Adjs[i].Register(ctx, req, nil)
})
err := s.Adjs[i].Register(ctx, req, nil)

require.NoError(t, err, "Withdrawing should succeed")
if !req.Secondary {
// The Initiator must send a TX.
require.Equal(t, diff, 1)
} else {
// Everyone else must NOT send a TX.
require.Equal(t, diff, 0)
}

})
}
ct.Wait("register")
Expand Down Expand Up @@ -254,11 +245,10 @@ func register(ctx context.Context, adj *test.SimAdjudicator, accounts []*keystor
}

req := channel.AdjudicatorReq{
Params: ch.params,
Acc: accounts[0],
Idx: 0,
Tx: tx,
Secondary: false,
Params: ch.params,
Acc: accounts[0],
Idx: 0,
Tx: tx,
}
return adj.Register(ctx, req, sub)
}
Expand All @@ -277,11 +267,10 @@ func withdraw(ctx context.Context, adj *test.SimAdjudicator, accounts []*keystor

for i, a := range accounts {
req := channel.AdjudicatorReq{
Params: c.params,
Acc: a,
Idx: channel.Index(i),
Tx: tx,
Secondary: i != 0,
Params: c.params,
Acc: a,
Idx: channel.Index(i),
Tx: tx,
}

if err := adj.Withdraw(ctx, req, subStates); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.7.0
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
perun.network/go-perun v0.10.5
perun.network/go-perun v0.10.7-0.20230808153546-74844191e56e
polycry.pt/poly-go v0.0.0-20220301085937-fb9d71b45a37
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,8 @@ honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt
honnef.co/go/tools v0.1.3/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las=
perun.network/go-perun v0.10.5 h1:bIaAoLLh8R+RXdPh+MkCJcbtumsFkNvoVAJwb60JKjg=
perun.network/go-perun v0.10.5/go.mod h1:BGBZC3npkX457u87pjDd0NEIXr1a4dsH4H/YpLdGGe8=
perun.network/go-perun v0.10.7-0.20230808153546-74844191e56e h1:4SOKO0WZtcsQUwP5nKVUrLUohgUPIhMa8wto5iNCA/k=
perun.network/go-perun v0.10.7-0.20230808153546-74844191e56e/go.mod h1:BGBZC3npkX457u87pjDd0NEIXr1a4dsH4H/YpLdGGe8=
polycry.pt/poly-go v0.0.0-20220222131629-aa4bdbaab60b/go.mod h1:XUBrNtqgEhN3EEOP/5gh7IBd3xVHKidCjXDZfl9+kMU=
polycry.pt/poly-go v0.0.0-20220301085937-fb9d71b45a37 h1:iA5GzEa/hHfVlQpimEjPV09NATwHXxSjWNB0VVodtew=
polycry.pt/poly-go v0.0.0-20220301085937-fb9d71b45a37/go.mod h1:XUBrNtqgEhN3EEOP/5gh7IBd3xVHKidCjXDZfl9+kMU=
Expand Down

0 comments on commit 64796c1

Please sign in to comment.