Skip to content

Commit

Permalink
Revert: Remove settle secondary (#351)
Browse files Browse the repository at this point in the history
Chore: Add author for this commit.

Signed-off-by: Sophia Koehler <[email protected]>

chore: update NOTICE.

Signed-off-by: Sophia Koehler <[email protected]>
  • Loading branch information
sophia1ch committed Feb 20, 2024
1 parent 0b444cb commit 35ed061
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 25 deletions.
1 change: 1 addition & 0 deletions MAINTAINERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
| Ilja von Hoessle | [@iljabvh](https://github.com/iljabvh) | iljabvh |
| Jens Winkle | [@DragonDev1906](https://github.com/DragonDev1906) | jens#4601 |
| Minh Huy Tran | [@NhoxxKienn](https://github.com/NhoxxKienn) | NhoxxKienn |
| Sophia Koehler | [@sophia1ch](https://githun.com/sophia1ch) | sophia#3072 |

## Emeritus Maintainers

Expand Down
1 change: 1 addition & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ PolyCrypt GmbH
Ilja von Hoessle <[email protected]>
Jens Winkle <[email protected]>
Minh Huy Tran <[email protected]>
Sophia Koehler <[email protected]>

Robert Bosch GmbH
Manoranjith <[email protected]>
Expand Down
14 changes: 10 additions & 4 deletions channel/adjudicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,17 @@ type (

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

// SignedState represents a signed channel state including parameters.
Expand Down
8 changes: 6 additions & 2 deletions channel/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ func (m *machine) CurrentTX() Transaction {
// AdjudicatorReq returns the adjudicator request for the current channel
// transaction (the current state together with all participants' signatures on
// it).
//
// The Secondary flag is left as false. Set it manually after creating the
// request if you want to use optimized sencondary adjudication logic.
func (m *machine) AdjudicatorReq() AdjudicatorReq {
return AdjudicatorReq{
Params: &m.params,
Expand Down Expand Up @@ -335,8 +338,9 @@ func (m *machine) EnableFinal() error {
}

// enableStaged checks that
// 1. the current phase is `expected.From` and
// 2. all signatures of the staging transactions have been set.
// 1. the current phase is `expected.From` and
// 2. all signatures of the staging transactions have been set.
//
// If successful, the staging transaction is promoted to be the current
// transaction. If not, an error is returned.
func (m *machine) enableStaged(expected PhaseTransition) error {
Expand Down
7 changes: 4 additions & 3 deletions client/adjudicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func (c *Channel) ForceUpdate(ctx context.Context, updater func(*channel.State))
// to be mined.
// Returns ChainNotReachableError if the connection to the blockchain network
// fails when sending a transaction to / reading from the blockchain.
func (c *Channel) Settle(ctx context.Context) (err error) {
func (c *Channel) Settle(ctx context.Context, secondary bool) (err error) {
if !c.State().IsFinal {
err := c.ensureRegistered(ctx)
if err != nil {
Expand All @@ -268,7 +268,7 @@ func (c *Channel) Settle(ctx context.Context) (err error) {
}

// Withdraw.
err = c.withdraw(ctx)
err = c.withdraw(ctx, secondary)
if err != nil {
return
}
Expand Down Expand Up @@ -303,14 +303,15 @@ func (c *Channel) Settle(ctx context.Context) (err error) {
return nil
}

func (c *Channel) withdraw(ctx context.Context) error {
func (c *Channel) withdraw(ctx context.Context, secondary bool) error {
switch {
case c.IsLedgerChannel():
subStates, err := c.subChannelStateMap()
if err != nil {
return errors.WithMessage(err, "creating sub-channel state map")
}
req := c.machine.AdjudicatorReq()
req.Secondary = secondary
if err := c.adjudicator.Withdraw(ctx, req, subStates); err != nil {
return errors.WithMessage(err, "calling Withdraw")
}
Expand Down
2 changes: 1 addition & 1 deletion client/test/bob.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (r *Bob) exec(_cfg ExecConfig, ch *paymentChannel, propHandler *acceptNextP
ch.sendFinal()

// 4th Settle channel
ch.settle()
ch.settleSecondary()

// 4th final stage
r.waitStage()
Expand Down
10 changes: 9 additions & 1 deletion client/test/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,18 @@ func (ch *paymentChannel) recvFinal() {
}

func (ch *paymentChannel) settle() {
ch.settleImpl(false)
}

func (ch *paymentChannel) settleSecondary() {
ch.settleImpl(true)
}

func (ch *paymentChannel) settleImpl(secondary bool) {
ctx, cancel := context.WithTimeout(context.Background(), ch.r.timeout)
defer cancel()

ch.r.RequireNoError(ch.Settle(ctx))
ch.r.RequireNoError(ch.Settle(ctx, secondary))
ch.assertBals(ch.State())

if ch.IsSubChannel() {
Expand Down
4 changes: 2 additions & 2 deletions client/test/fund.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func runFredFridaTest(
require.IsType(t, &client.ChannelFundingError{}, err)
require.NotNil(t, chFrida)
// Frida settles the channel.
require.NoError(t, chFrida.Settle(ctx))
require.NoError(t, chFrida.Settle(ctx, false))

// Fred gets the channel and settles it afterwards.
chFred := <-chsFred
Expand All @@ -141,7 +141,7 @@ func runFredFridaTest(
require.NoError(t, ctx.Err())
}
// Fred settles the channel.
require.NoError(t, chFred.Settle(ctx))
require.NoError(t, chFred.Settle(ctx, false))

// Test the final balances.
balancesAfter := channel.Balances{
Expand Down
5 changes: 3 additions & 2 deletions client/test/multiledger_dispute.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
// TestMultiLedgerDispute runs an end-to-end test of the multi-ledger
// functionality in the dispute case for the implementation specified in the
// test setup.
//
//nolint:revive // test.Test... stutters but this is OK in this special case.
func TestMultiLedgerDispute(
ctx context.Context,
Expand Down Expand Up @@ -127,9 +128,9 @@ func TestMultiLedgerDispute(
require.NoError(err)

// Settle.
err = chAliceBob.Settle(ctx)
err = chAliceBob.Settle(ctx, false)
require.NoError(err)
err = chBobAlice.Settle(ctx)
err = chBobAlice.Settle(ctx, false)
require.NoError(err)

// Close the channels.
Expand Down
5 changes: 3 additions & 2 deletions client/test/multiledger_happy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
// TestMultiLedgerHappy runs an end-to-end test of the multi-ledger
// functionality in the optimistic case for the implementation specified in the
// test setup.
//
//nolint:revive // test.Test... stutters but this is OK in this special case.
func TestMultiLedgerHappy(ctx context.Context, t *testing.T, mlt MultiLedgerSetup, challengeDuration uint64) {
require := require.New(t)
Expand Down Expand Up @@ -90,8 +91,8 @@ func TestMultiLedgerHappy(ctx context.Context, t *testing.T, mlt MultiLedgerSetu
require.NoError(err)

// Close channel.
err = chAliceBob.Settle(ctx)
err = chAliceBob.Settle(ctx, false)
require.NoError(err)
err = chBobAlice.Settle(ctx)
err = chBobAlice.Settle(ctx, false)
require.NoError(err)
}
2 changes: 1 addition & 1 deletion client/test/persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (r *Petra) Execute(cfg ExecConfig) {
// 6. Finalize restored channel
ch.recvFinal()

ch.settle()
ch.settleSecondary()

r.RequireNoError(r.Close())
}
Expand Down
4 changes: 2 additions & 2 deletions client/test/progression.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (r *Paul) exec(_cfg ExecConfig, ch *paymentChannel) {
r.waitStage()

// withdraw
r.RequireNoError(ch.Settle(ctx))
r.RequireNoError(ch.Settle(ctx, false))
}

// ----------------- BEGIN PAULA -----------------
Expand Down Expand Up @@ -181,5 +181,5 @@ func (r *Paula) exec(_cfg ExecConfig, ch *paymentChannel, _ *acceptNextPropHandl
r.RequireNoErrorf(e.Timeout().Wait(ctx), "waiting for progression timeout")

// withdraw
r.RequireNoError(ch.Settle(ctx))
r.RequireNoError(ch.Settle(ctx, true))
}
2 changes: 1 addition & 1 deletion client/test/subchannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (r *Tim) exec(_cfg ExecConfig, ledgerChannel *paymentChannel, propHandler *

finalizeAndSettle := func(ch *paymentChannel) {
ch.recvFinal()
ch.settle()
ch.settleSecondary()
}

for i, ch := range subChannels {
Expand Down
4 changes: 2 additions & 2 deletions client/test/virtualchannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestVirtualChannelOptimistic( //nolint:revive // test.Test... stutters but
success.Add(len(chs))
for _, ch := range chs {
go func(ch *client.Channel) {
err := ch.Settle(ctx)
err := ch.Settle(ctx, false)
if err != nil {
vct.errs <- err
return
Expand Down Expand Up @@ -102,7 +102,7 @@ func TestVirtualChannelDispute( //nolint:revive // test.Test... stutters but OK

// Settle the channels in a random order.
for _, i := range rand.Perm(len(chs)) {
err := chs[i].Settle(ctx)
err := chs[i].Settle(ctx, false)
assert.NoErrorf(err, "settle channel: %d", i)
}

Expand Down
5 changes: 3 additions & 2 deletions watcher/local/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,9 @@ func makeSignedState(params *channel.Params, tx channel.Transaction) channel.Sig

func makeAdjudicatorReq(params *channel.Params, tx channel.Transaction) channel.AdjudicatorReq {
return channel.AdjudicatorReq{
Params: params,
Tx: tx,
Params: params,
Tx: tx,
Secondary: false,
}
}

Expand Down

0 comments on commit 35ed061

Please sign in to comment.