Skip to content

Commit

Permalink
Remove settle secondary (hyperledger-labs#351)
Browse files Browse the repository at this point in the history
* Remove settle secondary parameter

Signed-off-by: Matthias Geihs <[email protected]>

* Remove secondary from AdjudicatorReq

Signed-off-by: Matthias Geihs <[email protected]>

Signed-off-by: Matthias Geihs <[email protected]>
  • Loading branch information
matthiasgeihs authored Oct 7, 2022
1 parent fb372d3 commit be6e072
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 42 deletions.
14 changes: 4 additions & 10 deletions channel/adjudicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,11 @@ 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
Secondary bool // Optimized secondary call protocol
Params *Params
Acc wallet.Account
Tx Transaction
Idx Index // Always the own index
}

// SignedState represents a signed channel state including parameters.
Expand Down
3 changes: 0 additions & 3 deletions channel/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,6 @@ 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
7 changes: 3 additions & 4 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, secondary bool) (err error) {
func (c *Channel) Settle(ctx context.Context) (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, secondary bool) (err error) {
}

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

func (c *Channel) withdraw(ctx context.Context, secondary bool) error {
func (c *Channel) withdraw(ctx context.Context) 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.settleSecondary()
ch.settle()

// 4th final stage
r.waitStage()
Expand Down
10 changes: 1 addition & 9 deletions client/test/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,10 @@ 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, secondary))
ch.r.RequireNoError(ch.Settle(ctx))
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, false))
require.NoError(t, chFrida.Settle(ctx))

// 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, false))
require.NoError(t, chFred.Settle(ctx))

// Test the final balances.
balancesAfter := channel.Balances{
Expand Down
4 changes: 2 additions & 2 deletions client/test/multiledger_dispute.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ func TestMultiLedgerDispute(
require.NoError(err)

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

// Close the channels.
Expand Down
4 changes: 2 additions & 2 deletions client/test/multiledger_happy.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ func TestMultiLedgerHappy(ctx context.Context, t *testing.T, mlt MultiLedgerSetu
require.NoError(err)

// Close channel.
err = chAliceBob.Settle(ctx, false)
err = chAliceBob.Settle(ctx)
require.NoError(err)
err = chBobAlice.Settle(ctx, false)
err = chBobAlice.Settle(ctx)
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.settleSecondary()
ch.settle()

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, false))
r.RequireNoError(ch.Settle(ctx))
}

// ----------------- 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, true))
r.RequireNoError(ch.Settle(ctx))
}
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.settleSecondary()
ch.settle()
}

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, false)
err := ch.Settle(ctx)
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, false)
err := chs[i].Settle(ctx)
assert.NoErrorf(err, "settle channel: %d", i)
}

Expand Down
5 changes: 2 additions & 3 deletions watcher/local/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,8 @@ 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,
Secondary: false,
Params: params,
Tx: tx,
}
}

Expand Down

0 comments on commit be6e072

Please sign in to comment.