Skip to content

Commit ba09048

Browse files
authored
Merge pull request #400 from perun-network/feat-secondary-settle
Revert: Remove settle secondary (#351)
2 parents e09ff52 + 9a2e2ca commit ba09048

File tree

15 files changed

+49
-25
lines changed

15 files changed

+49
-25
lines changed

MAINTAINERS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
| Ilja von Hoessle | [@iljabvh](https://github.com/iljabvh) | iljabvh |
1111
| Jens Winkle | [@DragonDev1906](https://github.com/DragonDev1906) | jens#4601 |
1212
| Minh Huy Tran | [@NhoxxKienn](https://github.com/NhoxxKienn) | NhoxxKienn |
13+
| Sophia Koehler | [@sophia1ch](https://githun.com/sophia1ch) | sophia#3072 |
1314

1415
## Emeritus Maintainers
1516

NOTICE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ PolyCrypt GmbH
4444
Ilja von Hoessle <ilja@perun.network>
4545
Jens Winkle <jens@perun.network>
4646
Minh Huy Tran <huy@perun.network>
47+
Sophia Koehler <sophia@perun.network>
4748

4849
Robert Bosch GmbH
4950
Manoranjith <ponraj.manoranjitha@in.bosch.com>

channel/adjudicator.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,17 @@ type (
103103

104104
// An AdjudicatorReq collects all necessary information to make calls to the
105105
// adjudicator.
106+
//
107+
// If the Secondary flag is set to true, it is assumed that this is an
108+
// on-chain request that is executed by the other channel participants as well
109+
// and the Adjudicator backend may run an optimized on-chain transaction
110+
// protocol, possibly saving unnecessary double sending of transactions.
106111
AdjudicatorReq struct {
107-
Params *Params
108-
Acc wallet.Account
109-
Tx Transaction
110-
Idx Index // Always the own index
112+
Params *Params
113+
Acc wallet.Account
114+
Tx Transaction
115+
Idx Index // Always the own index
116+
Secondary bool // Optimized secondary call protocol
111117
}
112118

113119
// SignedState represents a signed channel state including parameters.

channel/machine.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ func (m *machine) CurrentTX() Transaction {
249249
// AdjudicatorReq returns the adjudicator request for the current channel
250250
// transaction (the current state together with all participants' signatures on
251251
// it).
252+
//
253+
// The Secondary flag is left as false. Set it manually after creating the
254+
// request if you want to use optimized sencondary adjudication logic.
252255
func (m *machine) AdjudicatorReq() AdjudicatorReq {
253256
return AdjudicatorReq{
254257
Params: &m.params,
@@ -335,8 +338,9 @@ func (m *machine) EnableFinal() error {
335338
}
336339

337340
// enableStaged checks that
338-
// 1. the current phase is `expected.From` and
339-
// 2. all signatures of the staging transactions have been set.
341+
// 1. the current phase is `expected.From` and
342+
// 2. all signatures of the staging transactions have been set.
343+
//
340344
// If successful, the staging transaction is promoted to be the current
341345
// transaction. If not, an error is returned.
342346
func (m *machine) enableStaged(expected PhaseTransition) error {

client/adjudicate.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ func (c *Channel) ForceUpdate(ctx context.Context, updater func(*channel.State))
242242
// to be mined.
243243
// Returns ChainNotReachableError if the connection to the blockchain network
244244
// fails when sending a transaction to / reading from the blockchain.
245-
func (c *Channel) Settle(ctx context.Context) (err error) {
245+
func (c *Channel) Settle(ctx context.Context, secondary bool) (err error) {
246246
if !c.State().IsFinal {
247247
err := c.ensureRegistered(ctx)
248248
if err != nil {
@@ -268,7 +268,7 @@ func (c *Channel) Settle(ctx context.Context) (err error) {
268268
}
269269

270270
// Withdraw.
271-
err = c.withdraw(ctx)
271+
err = c.withdraw(ctx, secondary)
272272
if err != nil {
273273
return
274274
}
@@ -303,14 +303,15 @@ func (c *Channel) Settle(ctx context.Context) (err error) {
303303
return nil
304304
}
305305

306-
func (c *Channel) withdraw(ctx context.Context) error {
306+
func (c *Channel) withdraw(ctx context.Context, secondary bool) error {
307307
switch {
308308
case c.IsLedgerChannel():
309309
subStates, err := c.subChannelStateMap()
310310
if err != nil {
311311
return errors.WithMessage(err, "creating sub-channel state map")
312312
}
313313
req := c.machine.AdjudicatorReq()
314+
req.Secondary = secondary
314315
if err := c.adjudicator.Withdraw(ctx, req, subStates); err != nil {
315316
return errors.WithMessage(err, "calling Withdraw")
316317
}

client/test/bob.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (r *Bob) exec(_cfg ExecConfig, ch *paymentChannel, propHandler *acceptNextP
5757
ch.sendFinal()
5858

5959
// 4th Settle channel
60-
ch.settle()
60+
ch.settleSecondary()
6161

6262
// 4th final stage
6363
r.waitStage()

client/test/channel.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,18 @@ func (ch *paymentChannel) recvFinal() {
168168
}
169169

170170
func (ch *paymentChannel) settle() {
171+
ch.settleImpl(false)
172+
}
173+
174+
func (ch *paymentChannel) settleSecondary() {
175+
ch.settleImpl(true)
176+
}
177+
178+
func (ch *paymentChannel) settleImpl(secondary bool) {
171179
ctx, cancel := context.WithTimeout(context.Background(), ch.r.timeout)
172180
defer cancel()
173181

174-
ch.r.RequireNoError(ch.Settle(ctx))
182+
ch.r.RequireNoError(ch.Settle(ctx, secondary))
175183
ch.assertBals(ch.State())
176184

177185
if ch.IsSubChannel() {

client/test/fund.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func runFredFridaTest(
129129
require.IsType(t, &client.ChannelFundingError{}, err)
130130
require.NotNil(t, chFrida)
131131
// Frida settles the channel.
132-
require.NoError(t, chFrida.Settle(ctx))
132+
require.NoError(t, chFrida.Settle(ctx, false))
133133

134134
// Fred gets the channel and settles it afterwards.
135135
chFred := <-chsFred
@@ -141,7 +141,7 @@ func runFredFridaTest(
141141
require.NoError(t, ctx.Err())
142142
}
143143
// Fred settles the channel.
144-
require.NoError(t, chFred.Settle(ctx))
144+
require.NoError(t, chFred.Settle(ctx, false))
145145

146146
// Test the final balances.
147147
balancesAfter := channel.Balances{

client/test/multiledger_dispute.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
// TestMultiLedgerDispute runs an end-to-end test of the multi-ledger
3232
// functionality in the dispute case for the implementation specified in the
3333
// test setup.
34+
//
3435
//nolint:revive // test.Test... stutters but this is OK in this special case.
3536
func TestMultiLedgerDispute(
3637
ctx context.Context,
@@ -127,9 +128,9 @@ func TestMultiLedgerDispute(
127128
require.NoError(err)
128129

129130
// Settle.
130-
err = chAliceBob.Settle(ctx)
131+
err = chAliceBob.Settle(ctx, false)
131132
require.NoError(err)
132-
err = chBobAlice.Settle(ctx)
133+
err = chBobAlice.Settle(ctx, false)
133134
require.NoError(err)
134135

135136
// Close the channels.

client/test/multiledger_happy.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
// TestMultiLedgerHappy runs an end-to-end test of the multi-ledger
2828
// functionality in the optimistic case for the implementation specified in the
2929
// test setup.
30+
//
3031
//nolint:revive // test.Test... stutters but this is OK in this special case.
3132
func TestMultiLedgerHappy(ctx context.Context, t *testing.T, mlt MultiLedgerSetup, challengeDuration uint64) {
3233
require := require.New(t)
@@ -90,8 +91,8 @@ func TestMultiLedgerHappy(ctx context.Context, t *testing.T, mlt MultiLedgerSetu
9091
require.NoError(err)
9192

9293
// Close channel.
93-
err = chAliceBob.Settle(ctx)
94+
err = chAliceBob.Settle(ctx, false)
9495
require.NoError(err)
95-
err = chBobAlice.Settle(ctx)
96+
err = chBobAlice.Settle(ctx, false)
9697
require.NoError(err)
9798
}

0 commit comments

Comments
 (0)