Skip to content

Commit 17ac78d

Browse files
committed
Merge branch 'main' into nervos_ckb
2 parents 4d68d28 + f824816 commit 17ac78d

File tree

154 files changed

+2988
-2357
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

154 files changed

+2988
-2357
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
release:
88

99
env:
10-
go-version: 1.17
10+
go-version: 1.18
1111

1212
jobs:
1313
check-copyright:
@@ -39,7 +39,7 @@ jobs:
3939
- name: golangci-lint
4040
uses: golangci/golangci-lint-action@v3
4141
with:
42-
version: v1.43
42+
version: v1.45
4343

4444
- name: Lint proto files
4545
uses: plexsystems/protolint-action@v0.6.0

.golangci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ linters-settings:
5454
# Default values:
5555
- ^print.*$
5656
- 'fmt\.Print.*'
57-
57+
exclude-rules:
58+
- path: ".*\\.pb\\.go$" # Exclude protobuf generated files.
5859
issues:
5960
# Re-enable default excludes.
6061
include:

CHANGELOG.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,38 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.13.0] Metis - 2025-01-19 [:boom:]
8+
Support for multiple backends, allowing multiple address implementations per client. This enables the simultaneous use of several smaller backends, enhancing modularization.
9+
10+
## Added :boom:
11+
12+
* Backend field in Allocation [#410]
13+
14+
* Added interface restrictions to ensure cross-contract compatibility, including new functions and fields in interfaces such as Asset and Address [#410]
15+
16+
## Changed
17+
18+
* Updade action cache [#409]
19+
20+
* Update workflow go version to 1.18 [#410]
21+
22+
* Global Backend map in wire and wallet module [#410]
23+
24+
* Global Randomizer map in wallet and channel tests [#410]
25+
26+
* Participant map to allow multiple addresses per participant [#410] :boom:
27+
28+
* Code refactoring from channel ID map to singular channel ID [#413]
29+
30+
[#409]: https://github.com/hyperledger-labs/go-perun/pull/409
31+
[#410]: https://github.com/hyperledger-labs/go-perun/pull/410
32+
[#413]: https://github.com/hyperledger-labs/go-perun/pull/413
33+
34+
## Legend
35+
- <span id="breaking">:boom:</span> This is a breaking change, e.g., it changes the external API.
36+
37+
[:boom:]: #breaking
38+
739
## [0.12.0] Leda - 2024-11-19 [:boom:]
840
Flexibility in funding for payment channels and basic Layer-2 security.
941

apps/payment/app_internal_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019 - See NOTICE file for copyright holders.
1+
// Copyright 2025 - See NOTICE file for copyright holders.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@ import (
2727

2828
func TestApp_Def(t *testing.T) {
2929
rng := pkgtest.Prng(t)
30-
def := test.NewRandomAppID(rng)
30+
def := test.NewRandomAppID(rng, channel.TestBackendID)
3131
app := &App{def}
3232
assert.True(t, app.Def().Equal(app.Def()))
3333
}

apps/payment/randomizer.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019 - See NOTICE file for copyright holders.
1+
// Copyright 2025 - See NOTICE file for copyright holders.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -17,6 +17,8 @@ package payment
1717
import (
1818
"math/rand"
1919

20+
"perun.network/go-perun/wallet"
21+
2022
"perun.network/go-perun/channel"
2123
"perun.network/go-perun/channel/test"
2224
)
@@ -27,8 +29,8 @@ type Randomizer struct{}
2729
var _ test.AppRandomizer = (*Randomizer)(nil)
2830

2931
// NewRandomApp always returns a payment app with a different address.
30-
func (*Randomizer) NewRandomApp(rng *rand.Rand) channel.App {
31-
return &App{test.NewRandomAppID(rng)}
32+
func (*Randomizer) NewRandomApp(rng *rand.Rand, bID wallet.BackendID) channel.App {
33+
return &App{test.NewRandomAppID(rng, bID)}
3234
}
3335

3436
// NewRandomData returns NoData because a PaymentApp does not have data.

apps/payment/randomizer_internal_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019 - See NOTICE file for copyright holders.
1+
// Copyright 2025 - See NOTICE file for copyright holders.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@ func TestRandomizer(t *testing.T) {
2828
rng := pkgtest.Prng(t)
2929

3030
r := new(Randomizer)
31-
app := r.NewRandomApp(rng)
31+
app := r.NewRandomApp(rng, channel.TestBackendID)
3232
channel.RegisterApp(app)
3333
regApp, err := channel.Resolve(app.Def())
3434
assert.NoError(t, err)

apps/payment/resolver_internal_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019 - See NOTICE file for copyright holders.
1+
// Copyright 2025 - See NOTICE file for copyright holders.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -32,7 +32,7 @@ func TestResolver(t *testing.T) {
3232
rng := pkgtest.Prng(t)
3333
assert, require := assert.New(t), require.New(t)
3434

35-
def := ctest.NewRandomAppID(rng)
35+
def := ctest.NewRandomAppID(rng, channel.TestBackendID)
3636
channel.RegisterAppResolver(def.Equal, &Resolver{})
3737

3838
app, err := channel.Resolve(def)

backend/sim/channel/app.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 - See NOTICE file for copyright holders.
1+
// Copyright 2025 - See NOTICE file for copyright holders.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -48,5 +48,5 @@ func (id AppID) Key() channel.AppIDKey {
4848
// NewRandomAppID generates a new random app identifier.
4949
func NewRandomAppID(rng *rand.Rand) AppID {
5050
addr := wallet.NewRandomAddress(rng)
51-
return AppID{addr}
51+
return AppID{Address: addr}
5252
}

backend/sim/channel/asset.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019 - See NOTICE file for copyright holders.
1+
// Copyright 2025 - See NOTICE file for copyright holders.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -65,3 +65,9 @@ func (a Asset) Equal(b channel.Asset) bool {
6565
}
6666
return a.ID == simAsset.ID
6767
}
68+
69+
// Address returns the address of the asset.
70+
func (a Asset) Address() []byte {
71+
data, _ := a.MarshalBinary()
72+
return data
73+
}

backend/sim/channel/backend.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019 - See NOTICE file for copyright holders.
1+
// Copyright 2025 - See NOTICE file for copyright holders.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -33,23 +33,22 @@ type backend struct{}
3333
var _ channel.Backend = new(backend)
3434

3535
// CalcID calculates a channel's ID by hashing all fields of its parameters.
36-
func (*backend) CalcID(p *channel.Params) (id channel.ID) {
36+
func (*backend) CalcID(p *channel.Params) (id channel.ID, err error) {
3737
w := sha256.New()
3838

3939
// Write Parts
40-
for _, addr := range p.Parts {
41-
if err := perunio.Encode(w, addr); err != nil {
42-
log.Panic("Could not write to sha256 hasher")
43-
}
40+
if err := perunio.Encode(w, wallet.AddressMapArray{Addr: p.Parts}); err != nil {
41+
log.Panic("Could not write to sha256 hasher")
4442
}
4543

46-
err := perunio.Encode(w, p.Nonce, p.ChallengeDuration, channel.OptAppEnc{App: p.App}, p.LedgerChannel, p.VirtualChannel)
44+
err = perunio.Encode(w, p.Nonce, p.ChallengeDuration, channel.OptAppEnc{App: p.App}, p.LedgerChannel, p.VirtualChannel)
4745
if err != nil {
48-
log.Panic("Could not write to sha256 hasher")
46+
return
4947
}
5048

5149
if copy(id[:], w.Sum(nil)) != channel.IDLen {
52-
log.Panic("Could not copy id")
50+
err = errors.New("Could not copy id")
51+
return
5352
}
5453
return
5554
}
@@ -83,7 +82,7 @@ func (b *backend) NewAsset() channel.Asset {
8382

8483
// NewAppID returns an object of type AppID, which can be used for
8584
// unmarshalling an app identifier from its binary representation.
86-
func (b *backend) NewAppID() channel.AppID {
85+
func (b *backend) NewAppID() (channel.AppID, error) {
8786
addr := &simwallet.Address{}
88-
return AppID{addr}
87+
return AppID{addr}, nil
8988
}

backend/sim/channel/channel_internal_test.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019 - See NOTICE file for copyright holders.
1+
// Copyright 2025 - See NOTICE file for copyright holders.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -17,6 +17,8 @@ package channel
1717
import (
1818
"testing"
1919

20+
"perun.network/go-perun/channel"
21+
2022
chtest "perun.network/go-perun/channel/test"
2123
"perun.network/go-perun/wallet"
2224
wtest "perun.network/go-perun/wallet/test"
@@ -36,11 +38,13 @@ func newChannelSetup(t *testing.T) *chtest.Setup {
3638
params2, state2 := chtest.NewRandomParamsAndState(rng, chtest.WithIsFinal(!state.IsFinal), chtest.WithNumLocked(int(rng.Int31n(4)+1)))
3739

3840
return &chtest.Setup{
39-
Params: params,
40-
Params2: params2,
41-
State: state,
42-
State2: state2,
43-
Account: wtest.NewRandomAccount(rng),
44-
RandomAddress: func() wallet.Address { return wtest.NewRandomAddress(rng) },
41+
Params: params,
42+
Params2: params2,
43+
State: state,
44+
State2: state2,
45+
Account: wtest.NewRandomAccount(rng, channel.TestBackendID),
46+
RandomAddress: func() map[wallet.BackendID]wallet.Address {
47+
return wtest.NewRandomAddresses(rng, channel.TestBackendID)
48+
},
4549
}
4650
}

backend/sim/channel/init.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019 - See NOTICE file for copyright holders.
1+
// Copyright 2025 - See NOTICE file for copyright holders.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -22,9 +22,9 @@ import (
2222
)
2323

2424
func init() {
25-
channel.SetBackend(new(backend))
26-
test.SetRandomizer(new(randomizer))
25+
channel.SetBackend(new(backend), channel.TestBackendID)
26+
test.SetRandomizer(new(randomizer), channel.TestBackendID)
2727
test.SetNewRandomAppID(func(r *rand.Rand) channel.AppID {
2828
return NewRandomAppID(r)
29-
})
29+
}, channel.TestBackendID)
3030
}

backend/sim/wallet/account.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019 - See NOTICE file for copyright holders.
1+
// Copyright 2025 - See NOTICE file for copyright holders.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -57,7 +57,7 @@ func NewRandomAccount(rng io.Reader) *Account {
5757

5858
// Address returns the address of this account.
5959
func (a *Account) Address() wallet.Address {
60-
return wallet.Address((*Address)(&a.privKey.PublicKey))
60+
return (*Address)(&a.privKey.PublicKey)
6161
}
6262

6363
// SignData is used to sign data with this account. If the account is locked,

backend/sim/wallet/address.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019 - See NOTICE file for copyright holders.
1+
// Copyright 2025 - See NOTICE file for copyright holders.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -20,13 +20,20 @@ import (
2020
"io"
2121
"math/big"
2222

23+
"perun.network/go-perun/channel"
24+
2325
"perun.network/go-perun/log"
2426
"perun.network/go-perun/wallet"
2527
)
2628

2729
// Address represents a simulated address.
2830
type Address ecdsa.PublicKey
2931

32+
// BackendID returns the backend id of the address.
33+
func (a Address) BackendID() wallet.BackendID {
34+
return channel.TestBackendID
35+
}
36+
3037
const (
3138
// elemLen is the length of the binary representation of a single element
3239
// of the address in bytes.
@@ -54,6 +61,21 @@ func NewRandomAddress(rng io.Reader) *Address {
5461
}
5562
}
5663

64+
// NewRandomAddresses creates a new address using the randomness
65+
// provided by rng.
66+
func NewRandomAddresses(rng io.Reader) map[wallet.BackendID]wallet.Address {
67+
privateKey, err := ecdsa.GenerateKey(curve, rng)
68+
if err != nil {
69+
log.Panicf("Creation of account failed with error", err)
70+
}
71+
72+
return map[wallet.BackendID]wallet.Address{channel.TestBackendID: &Address{
73+
Curve: privateKey.Curve,
74+
X: privateKey.X,
75+
Y: privateKey.Y,
76+
}}
77+
}
78+
5779
// Bytes converts this address to bytes.
5880
func (a *Address) Bytes() []byte {
5981
data := a.byteArray()
@@ -90,9 +112,11 @@ func (a *Address) Equal(addr wallet.Address) bool {
90112
}
91113

92114
// Cmp checks the ordering of two addresses according to following definition:
93-
// -1 if (a.X < addr.X) || ((a.X == addr.X) && (a.Y < addr.Y))
94-
// 0 if (a.X == addr.X) && (a.Y == addr.Y)
95-
// +1 if (a.X > addr.X) || ((a.X == addr.X) && (a.Y > addr.Y))
115+
//
116+
// -1 if (a.X < addr.X) || ((a.X == addr.X) && (a.Y < addr.Y))
117+
// 0 if (a.X == addr.X) && (a.Y == addr.Y)
118+
// +1 if (a.X > addr.X) || ((a.X == addr.X) && (a.Y > addr.Y))
119+
//
96120
// So the X coordinate is weighted higher.
97121
// Pancis if the passed address is of the wrong type.
98122
func (a *Address) Cmp(addr wallet.Address) int {

backend/sim/wallet/init.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019 - See NOTICE file for copyright holders.
1+
// Copyright 2025 - See NOTICE file for copyright holders.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -15,11 +15,12 @@
1515
package wallet
1616

1717
import (
18+
"perun.network/go-perun/channel"
1819
"perun.network/go-perun/wallet"
1920
"perun.network/go-perun/wallet/test"
2021
)
2122

2223
func init() {
23-
wallet.SetBackend(new(Backend))
24-
test.SetRandomizer(newRandomizer())
24+
wallet.SetBackend(new(Backend), channel.TestBackendID)
25+
test.SetRandomizer(newRandomizer(), channel.TestBackendID)
2526
}

0 commit comments

Comments
 (0)