Skip to content

Commit

Permalink
Merge branch 'main' into 381_wire_authentication
Browse files Browse the repository at this point in the history
Signed-off-by: Minh Huy, Tran <[email protected]>
  • Loading branch information
NhoxxKienn authored Feb 26, 2024
2 parents e3d734f + d51ee68 commit 91691e7
Show file tree
Hide file tree
Showing 25 changed files with 328 additions and 176 deletions.
47 changes: 45 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,49 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [0.11.0] Kiviuq - 2024-02-21 [:boom:]
Exposure of protobuf converters & `SignedState`, abstraction of tests and bug fixes.

## Added
- Add Fabric to backend list in README: [#377]
- Create new type `TransparentChannel` to expose `SignedState`: [#389]
- Update backend compatibility list in README: [#392]
- Add MAINTAINERS.md file, Update NOTICE: [#394]

## Fixed
- Fix sub-channel test: [#359]
- Fix Multi-Adjudicator Subscription: [#366]
- Use correct identity for client tests: [#376]
- Fix link to white paper in README: [#379]
- Fix linter copyright year checking in CI: [#389]
- Fix failing unit tests: [#399]

## Changed [:boom:]
- Abstract multiledger test, making it usable by backends: [#355]
- Abstract fund recovery test, making it usable by backends: [#370]
- Abstract virtual channel test, making it usable by backends: [#375]
- Expose protobuf converters: [#384] [#393]
- Use absolute module path in wire.proto: [#383]
- Create AppID Type to generalize app identifiers: [#378] [:boom:]


[#359]: https://github.com/hyperledger-labs/go-perun/pull/359
[#355]: https://github.com/hyperledger-labs/go-perun/pull/355
[#366]: https://github.com/hyperledger-labs/go-perun/pull/366
[#370]: https://github.com/hyperledger-labs/go-perun/pull/370
[#375]: https://github.com/hyperledger-labs/go-perun/pull/375
[#376]: https://github.com/hyperledger-labs/go-perun/pull/376
[#377]: https://github.com/hyperledger-labs/go-perun/pull/377
[#378]: https://github.com/hyperledger-labs/go-perun/pull/378
[#379]: https://github.com/hyperledger-labs/go-perun/pull/379
[#383]: https://github.com/hyperledger-labs/go-perun/pull/383
[#384]: https://github.com/hyperledger-labs/go-perun/pull/384
[#389]: https://github.com/hyperledger-labs/go-perun/pull/389
[#392]: https://github.com/hyperledger-labs/go-perun/pull/392
[#393]: https://github.com/hyperledger-labs/go-perun/pull/393
[#394]: https://github.com/hyperledger-labs/go-perun/pull/394
[#399]: https://github.com/hyperledger-labs/go-perun/pull/399


## [0.10.0] Janus - 2022-05-25 [:warning:]
Multi-ledger payment channels.
Expand Down Expand Up @@ -389,7 +431,8 @@ Initial release.
[:warning:]: #warning
[:boom:]: #breaking

[Unreleased]: https://github.com/hyperledger-labs/go-perun/compare/v0.10.0...HEAD
[Unreleased]: https://github.com/hyperledger-labs/go-perun/compare/v0.11.0...HEAD
[0.11.0]: https://github.com/hyperledger-labs/go-perun/compare/v0.10.0...v0.11.0
[0.10.0]: https://github.com/hyperledger-labs/go-perun/compare/v0.9.1...v0.10.0
[0.9.1]: https://github.com/hyperledger-labs/go-perun/compare/v0.9.0...v0.9.1
[0.9.0]: https://github.com/hyperledger-labs/go-perun/compare/v0.8.0...v0.9.0
Expand Down
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
2 changes: 2 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Chair of Applied Cryptography, Technische Universität Darmstadt, Germany
Marius van der Wijden <[email protected]>

PolyCrypt GmbH
Jan Bormet <[email protected]>
Norbert Dzikowski <[email protected]>
Matthias Geihs <[email protected]>
Philipp-Florens Lehwalder <[email protected]>
Expand All @@ -43,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
2 changes: 1 addition & 1 deletion channel/test/app_randomizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type AppRandomizer interface {
NewRandomData(*rand.Rand) channel.Data
}

var appRandomizer AppRandomizer = &MockAppRandomizer{}
var appRandomizer AppRandomizer = NewMockAppRandomizer()

// isAppRandomizerSet tracks whether the AppRandomizer was already set
// with `SetAppRandomizer`.
Expand Down
11 changes: 6 additions & 5 deletions channel/test/app_randomizer_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ func TestAppRandomizerSet(t *testing.T) {
assert.NotNil(t, appRandomizer, "appRandomizer should be default initialized")
assert.False(t, isAppRandomizerSet, "isAppRandomizerSet should be defaulted to false")

// old := appRandomizer
assert.NotPanics(t, func() { SetAppRandomizer(&MockAppRandomizer{}) }, "first SetAppRandomizer() should work")

old := appRandomizer
assert.NotPanics(t, func() { SetAppRandomizer(NewMockAppRandomizer()) }, "first SetAppRandomizer() should work")
assert.True(t, isAppRandomizerSet, "isAppRandomizerSet should be true")
assert.NotNil(t, appRandomizer, "appRandomizer should not be nil")
// assert.False(t, old == appRandomizer, "appRandomizer should have changed")
assert.False(t, old == appRandomizer, "appRandomizer should have changed")

old := appRandomizer
assert.Panics(t, func() { SetAppRandomizer(&MockAppRandomizer{}) }, "second SetAppRandomizer() should panic")
old = appRandomizer
assert.Panics(t, func() { SetAppRandomizer(NewMockAppRandomizer()) }, "second SetAppRandomizer() should panic")
assert.True(t, isAppRandomizerSet, "isAppRandomizerSet should be true")
assert.NotNil(t, appRandomizer, "appRandomizer should not be nil")
assert.True(t, old == appRandomizer, "appRandomizer should not have changed")
Expand Down
15 changes: 14 additions & 1 deletion channel/test/mock_app_randomizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@ package test
import (
"math/rand"

"github.com/google/uuid"
"perun.network/go-perun/channel"
)

// MockAppRandomizer implements the AppRandomizer interface.
type MockAppRandomizer struct{}
type MockAppRandomizer struct {
id uuid.UUID // Unique identifier for each instance
}

// NewMockAppRandomizer creates a new instance of MockAppRandomizer with a unique identifier.
func NewMockAppRandomizer() *MockAppRandomizer {
return &MockAppRandomizer{id: uuid.New()}
}

// NewRandomApp creates a new MockApp with a random address.
func (MockAppRandomizer) NewRandomApp(rng *rand.Rand) channel.App {
Expand All @@ -32,3 +40,8 @@ func (MockAppRandomizer) NewRandomApp(rng *rand.Rand) channel.App {
func (MockAppRandomizer) NewRandomData(rng *rand.Rand) channel.Data {
return channel.NewMockOp(channel.MockOp(rng.Uint64()))
}

// Equal returns false for any comparison, ensuring two MockAppRandomizers are always considered different.
func (m *MockAppRandomizer) Equal(other *MockAppRandomizer) bool {
return m.id != other.id
}
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 err
}
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
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ require (
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-cmp v0.5.4 // indirect
github.com/google/uuid v1.6.0
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.1.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
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
Loading

0 comments on commit 91691e7

Please sign in to comment.