From 66fee7591b548c7ce0b9b570aed37fc410ee5a18 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Wed, 21 Aug 2024 14:09:05 +0200 Subject: [PATCH 01/36] feat(wallet, channel): Change backend to map of backends feat(Asset, Adjudicator): Add AssetID struct to identify assets with LedgerID and BackendID feat(persistence, wire): Use map[int]Address to identify clients Signed-off-by: Sophia Koehler --- backend/sim/channel/app.go | 2 +- backend/sim/channel/backend.go | 21 +- backend/sim/channel/channel_internal_test.go | 2 +- backend/sim/channel/init.go | 2 +- backend/sim/wallet/account.go | 4 +- backend/sim/wallet/address.go | 28 +- backend/sim/wallet/init.go | 2 +- backend/sim/wallet/wallet.go | 30 +- backend/sim/wallet/wallet_internal_test.go | 2 +- backend/sim/wallet/wallet_test.go | 6 +- backend/sim/wire/account.go | 6 +- channel/allocation.go | 18 +- channel/app.go | 66 +- channel/backend.go | 78 +- channel/backendtest.go | 4 +- channel/machine.go | 5 +- channel/multi/adjudicator.go | 40 +- channel/multi/asset.go | 32 +- channel/multi/funder.go | 64 +- channel/params.go | 44 +- channel/persistence/keyvalue/persister.go | 8 +- channel/persistence/keyvalue/restorer.go | 26 +- channel/persistence/nonpersister.go | 8 +- channel/persistence/persistence.go | 10 +- channel/persistence/statemachine_test.go | 4 +- channel/persistence/test/channel.go | 22 +- channel/persistence/test/peerchans.go | 29 +- .../test/peerchans_internal_test.go | 4 +- channel/persistence/test/persistrestorer.go | 6 +- .../persistence/test/persistrestorertest.go | 10 +- channel/state.go | 15 +- channel/test/backend.go | 16 +- channel/test/randomizer.go | 23 +- channel/test/randomopts.go | 40 +- channel/transaction.go | 2 +- client/adjudicate.go | 4 +- client/appchannel_test.go | 2 +- client/channel.go | 28 +- client/channelconn.go | 13 +- client/client.go | 8 +- client/client_internal_test.go | 2 +- client/client_role_test.go | 10 +- client/client_test.go | 12 +- client/clientconn.go | 6 +- client/payment_test.go | 2 +- client/proposal.go | 54 +- client/proposal_internal_test.go | 12 +- client/proposalmsgs.go | 54 +- client/restore.go | 8 +- client/restore_internal_test.go | 6 +- client/subchannel.go | 2 +- client/subchannel_test.go | 4 +- client/sync.go | 4 +- client/test/backend.go | 8 +- client/test/fund.go | 5 +- client/test/handler.go | 2 +- client/test/multiledger.go | 46 +- client/test/multiledger_dispute.go | 4 +- client/test/multiledger_happy.go | 4 +- client/test/persistence.go | 6 +- client/test/proposalmsgs.go | 4 +- client/test/randomproposal.go | 10 +- client/test/role.go | 30 +- client/test/virtualchannel.go | 10 +- client/update.go | 4 +- client/updatemsgs.go | 4 +- client/virtual_channel.go | 10 +- go.mod | 2 +- wallet/account.go | 2 +- wallet/address.go | 194 ++- wallet/address_test.go | 48 +- wallet/backend.go | 49 +- wallet/sig.go | 5 +- wallet/test/randomizer.go | 35 +- wallet/test/wallet.go | 20 +- wallet/test/walletbench.go | 4 +- wallet/wallet.go | 6 +- wire/account.go | 14 +- wire/address.go | 127 +- wire/bus.go | 2 +- wire/encode.go | 4 +- wire/hybridbus.go | 2 +- wire/localbus.go | 8 +- wire/net/bus.go | 18 +- wire/net/dialer.go | 2 +- wire/net/endpoint.go | 6 +- wire/net/endpoint_internal_test.go | 9 +- wire/net/endpoint_registry.go | 72 +- wire/net/endpoint_registry_external_test.go | 15 +- wire/net/endpoint_registry_internal_test.go | 8 +- wire/net/exchange_addr.go | 38 +- wire/net/exchange_addr_internal_test.go | 3 +- wire/net/simple/account.go | 4 +- wire/net/simple/address.go | 17 +- wire/net/simple/dialer.go | 8 +- wire/net/simple/dialer_internal_test.go | 6 +- wire/net/simple/simple_exchange_addr_test.go | 7 +- wire/net/test/connhub.go | 2 +- wire/net/test/dialer.go | 2 +- wire/net/test/listenermap.go | 13 +- wire/perunio/serializer/serializer.go | 48 +- wire/perunio/test/serializertest.go | 1 + wire/protobuf/proposalmsgs.go | 159 ++- wire/protobuf/serializer.go | 26 +- wire/protobuf/wire.pb.go | 1228 ++++++++++------- wire/protobuf/wire.proto | 36 +- wire/test/bustest.go | 14 +- wire/test/randomizer.go | 17 +- 108 files changed, 2112 insertions(+), 1226 deletions(-) diff --git a/backend/sim/channel/app.go b/backend/sim/channel/app.go index c7502b3da..7bf2601fe 100644 --- a/backend/sim/channel/app.go +++ b/backend/sim/channel/app.go @@ -48,5 +48,5 @@ func (id AppID) Key() channel.AppIDKey { // NewRandomAppID generates a new random app identifier. func NewRandomAppID(rng *rand.Rand) AppID { addr := wallet.NewRandomAddress(rng) - return AppID{addr} + return AppID{Address: addr} } diff --git a/backend/sim/channel/backend.go b/backend/sim/channel/backend.go index 57e53ad7b..f00289008 100644 --- a/backend/sim/channel/backend.go +++ b/backend/sim/channel/backend.go @@ -33,23 +33,22 @@ type backend struct{} var _ channel.Backend = new(backend) // CalcID calculates a channel's ID by hashing all fields of its parameters. -func (*backend) CalcID(p *channel.Params) (id channel.ID) { +func (*backend) CalcID(p *channel.Params) (id channel.ID, err error) { w := sha256.New() // Write Parts - for _, addr := range p.Parts { - if err := perunio.Encode(w, addr); err != nil { - log.Panic("Could not write to sha256 hasher") - } + if err := perunio.Encode(w, wallet.AddressMapArray{p.Parts}); err != nil { + log.Panic("Could not write to sha256 hasher") } - err := perunio.Encode(w, p.Nonce, p.ChallengeDuration, channel.OptAppEnc{App: p.App}, p.LedgerChannel, p.VirtualChannel) + err = perunio.Encode(w, p.Nonce, p.ChallengeDuration, channel.OptAppEnc{App: p.App}, p.LedgerChannel, p.VirtualChannel) if err != nil { - log.Panic("Could not write to sha256 hasher") + return } if copy(id[:], w.Sum(nil)) != channel.IDLen { - log.Panic("Could not copy id") + err = errors.New("Could not copy id") + return } return } @@ -71,7 +70,7 @@ func (b *backend) Verify(addr wallet.Address, state *channel.State, sig []byte) if err := state.Encode(buff); err != nil { return false, errors.WithMessage(err, "pack state") } - return wallet.VerifySignature(buff.Bytes(), sig, addr) + return wallet.VerifySignature(buff.Bytes(), sig, map[int]wallet.Address{addr.BackendID(): addr}) } // NewAsset returns a variable of type Asset, which can be used @@ -83,7 +82,7 @@ func (b *backend) NewAsset() channel.Asset { // NewAppID returns an object of type AppID, which can be used for // unmarshalling an app identifier from its binary representation. -func (b *backend) NewAppID() channel.AppID { +func (b *backend) NewAppID() (channel.AppID, error) { addr := &simwallet.Address{} - return AppID{addr} + return AppID{addr}, nil } diff --git a/backend/sim/channel/channel_internal_test.go b/backend/sim/channel/channel_internal_test.go index 2980df34d..59a8af3b0 100644 --- a/backend/sim/channel/channel_internal_test.go +++ b/backend/sim/channel/channel_internal_test.go @@ -41,6 +41,6 @@ func newChannelSetup(t *testing.T) *chtest.Setup { State: state, State2: state2, Account: wtest.NewRandomAccount(rng), - RandomAddress: func() wallet.Address { return wtest.NewRandomAddress(rng) }, + RandomAddress: func() map[int]wallet.Address { return wtest.NewRandomAddresses(rng) }, } } diff --git a/backend/sim/channel/init.go b/backend/sim/channel/init.go index b8dac016b..6e2d76004 100644 --- a/backend/sim/channel/init.go +++ b/backend/sim/channel/init.go @@ -22,7 +22,7 @@ import ( ) func init() { - channel.SetBackend(new(backend)) + channel.SetBackend(new(backend), 0) test.SetRandomizer(new(randomizer)) test.SetNewRandomAppID(func(r *rand.Rand) channel.AppID { return NewRandomAppID(r) diff --git a/backend/sim/wallet/account.go b/backend/sim/wallet/account.go index 4dec64423..ef510e187 100644 --- a/backend/sim/wallet/account.go +++ b/backend/sim/wallet/account.go @@ -56,8 +56,8 @@ func NewRandomAccount(rng io.Reader) *Account { } // Address returns the address of this account. -func (a *Account) Address() wallet.Address { - return wallet.Address((*Address)(&a.privKey.PublicKey)) +func (a *Account) Address() map[int]wallet.Address { + return map[int]wallet.Address{0: (*Address)(&a.privKey.PublicKey)} } // SignData is used to sign data with this account. If the account is locked, diff --git a/backend/sim/wallet/address.go b/backend/sim/wallet/address.go index 6b4d4a49f..0ca984876 100644 --- a/backend/sim/wallet/address.go +++ b/backend/sim/wallet/address.go @@ -27,6 +27,11 @@ import ( // Address represents a simulated address. type Address ecdsa.PublicKey +// BackendID returns the backend id of the address. +func (a Address) BackendID() int { + return 0 +} + const ( // elemLen is the length of the binary representation of a single element // of the address in bytes. @@ -54,6 +59,21 @@ func NewRandomAddress(rng io.Reader) *Address { } } +// NewRandomAddresses creates a new address using the randomness +// provided by rng. +func NewRandomAddresses(rng io.Reader) map[int]wallet.Address { + privateKey, err := ecdsa.GenerateKey(curve, rng) + if err != nil { + log.Panicf("Creation of account failed with error", err) + } + + return map[int]wallet.Address{0: &Address{ + Curve: privateKey.Curve, + X: privateKey.X, + Y: privateKey.Y, + }} +} + // Bytes converts this address to bytes. func (a *Address) Bytes() []byte { data := a.byteArray() @@ -90,9 +110,11 @@ func (a *Address) Equal(addr wallet.Address) bool { } // Cmp checks the ordering of two addresses according to following definition: -// -1 if (a.X < addr.X) || ((a.X == addr.X) && (a.Y < addr.Y)) -// 0 if (a.X == addr.X) && (a.Y == addr.Y) -// +1 if (a.X > addr.X) || ((a.X == addr.X) && (a.Y > addr.Y)) +// +// -1 if (a.X < addr.X) || ((a.X == addr.X) && (a.Y < addr.Y)) +// 0 if (a.X == addr.X) && (a.Y == addr.Y) +// +1 if (a.X > addr.X) || ((a.X == addr.X) && (a.Y > addr.Y)) +// // So the X coordinate is weighted higher. // Pancis if the passed address is of the wrong type. func (a *Address) Cmp(addr wallet.Address) int { diff --git a/backend/sim/wallet/init.go b/backend/sim/wallet/init.go index 8a5d5c68a..587b22e08 100644 --- a/backend/sim/wallet/init.go +++ b/backend/sim/wallet/init.go @@ -20,6 +20,6 @@ import ( ) func init() { - wallet.SetBackend(new(Backend)) + wallet.SetBackend(new(Backend), 0) test.SetRandomizer(newRandomizer()) } diff --git a/backend/sim/wallet/wallet.go b/backend/sim/wallet/wallet.go index 0f660b2fa..4b17d83b5 100644 --- a/backend/sim/wallet/wallet.go +++ b/backend/sim/wallet/wallet.go @@ -61,11 +61,11 @@ type Wallet struct { // Unlock retrieves the account belonging to the supplied address, and unlocks // it. If the address does not have a corresponding account in the wallet, // returns an error. -func (w *Wallet) Unlock(a wallet.Address) (wallet.Account, error) { +func (w *Wallet) Unlock(a map[int]wallet.Address) (wallet.Account, error) { w.accMutex.RLock() defer w.accMutex.RUnlock() - - acc, ok := w.accs[wallet.Key(a)] + key := wallet.Key(a) + acc, ok := w.accs[key] if !ok { return nil, errors.Errorf("unlock unknown address: %v", a) } @@ -87,11 +87,11 @@ func (w *Wallet) LockAll() { // IncrementUsage increases an account's usage count, which is used for // resource management. Panics if the wallet does not have an account that // corresponds to the supplied address. -func (w *Wallet) IncrementUsage(a wallet.Address) { +func (w *Wallet) IncrementUsage(a map[int]wallet.Address) { w.accMutex.RLock() defer w.accMutex.RUnlock() - - acc, ok := w.accs[wallet.Key(a)] + key := wallet.Key(a) + acc, ok := w.accs[key] if !ok { panic("invalid address") } @@ -103,11 +103,11 @@ func (w *Wallet) IncrementUsage(a wallet.Address) { // locks and deletes the account from the wallet. Panics if the call is not // matched to another preceding IncrementUsage call or if the supplied address // does not correspond to any of the wallet's accounts. -func (w *Wallet) DecrementUsage(a wallet.Address) { +func (w *Wallet) DecrementUsage(a map[int]wallet.Address) { w.accMutex.Lock() defer w.accMutex.Unlock() - - acc, ok := w.accs[wallet.Key(a)] + key := wallet.Key(a) + acc, ok := w.accs[key] if !ok { panic("invalid address") } @@ -119,18 +119,18 @@ func (w *Wallet) DecrementUsage(a wallet.Address) { if newCount == 0 { acc.locked.Set() - delete(w.accs, wallet.Key(a)) + delete(w.accs, key) } } // UsageCount retrieves an account's usage count (controlled via IncrementUsage // and DecrementUsage). Panics if the supplied address does not correspond to // any of the wallet's accounts. -func (w *Wallet) UsageCount(a wallet.Address) int { +func (w *Wallet) UsageCount(a map[int]wallet.Address) int { w.accMutex.RLock() defer w.accMutex.RUnlock() - - acc, ok := w.accs[wallet.Key(a)] + key := wallet.Key(a) + acc, ok := w.accs[key] if !ok { panic("invalid address") } @@ -171,7 +171,7 @@ func (w *Wallet) AddAccount(acc *Account) error { func (w *Wallet) HasAccount(acc *Account) bool { w.accMutex.RLock() defer w.accMutex.RUnlock() - - _, ok := w.accs[wallet.Key(acc.Address())] + key := wallet.Key(acc.Address()) + _, ok := w.accs[key] return ok } diff --git a/backend/sim/wallet/wallet_internal_test.go b/backend/sim/wallet/wallet_internal_test.go index b6f6a4d7f..4ac7e8f77 100644 --- a/backend/sim/wallet/wallet_internal_test.go +++ b/backend/sim/wallet/wallet_internal_test.go @@ -98,7 +98,7 @@ func newWalletSetup(rng *rand.Rand) *test.Setup { panic(err) } - addressNotInWallet := NewRandomAccount(rng).Address() + addressNotInWallet := NewRandomAccount(rng).Address()[0] addrMarshalled, err := addressNotInWallet.MarshalBinary() if err != nil { panic(err) diff --git a/backend/sim/wallet/wallet_test.go b/backend/sim/wallet/wallet_test.go index 1f1989b00..2a9ee1dbd 100644 --- a/backend/sim/wallet/wallet_test.go +++ b/backend/sim/wallet/wallet_test.go @@ -75,7 +75,7 @@ func TestWallet_Unlock(t *testing.T) { }) t.Run("unknown unlock", func(t *testing.T) { - acc, err := w.Unlock(wallet.NewRandomAddress(rng)) + acc, err := w.Unlock(wallet.NewRandomAddresses(rng)) assert.Error(t, err) assert.Nil(t, acc) }) @@ -123,7 +123,7 @@ func TestWallet_UsageCounting(t *testing.T) { }) t.Run("invalid address", func(t *testing.T) { - assert.Panics(t, func() { w.IncrementUsage(wallet.NewRandomAddress(rng)) }) - assert.Panics(t, func() { w.DecrementUsage(wallet.NewRandomAddress(rng)) }) + assert.Panics(t, func() { w.IncrementUsage(wallet.NewRandomAddresses(rng)) }) + assert.Panics(t, func() { w.DecrementUsage(wallet.NewRandomAddresses(rng)) }) }) } diff --git a/backend/sim/wire/account.go b/backend/sim/wire/account.go index 191cbcd17..4f8e1704d 100644 --- a/backend/sim/wire/account.go +++ b/backend/sim/wire/account.go @@ -22,11 +22,11 @@ import ( // Account is a wire account. type Account struct { - addr wire.Address + addr map[int]wire.Address } // Address returns the account's address. -func (acc *Account) Address() wire.Address { +func (acc *Account) Address() map[int]wire.Address { return acc.addr } @@ -38,6 +38,6 @@ func (acc *Account) Sign(msg []byte) ([]byte, error) { // NewRandomAccount generates a new random account. func NewRandomAccount(rng *rand.Rand) *Account { return &Account{ - addr: NewRandomAddress(rng), + addr: map[int]wire.Address{0: NewRandomAddress(rng)}, } } diff --git a/channel/allocation.go b/channel/allocation.go index d0f04038e..b299af66f 100644 --- a/channel/allocation.go +++ b/channel/allocation.go @@ -62,6 +62,8 @@ type ( // // Locked holds the locked allocations to sub-app-channels. Allocation struct { + // Backends is the indexes to which backend the assets belong to + Backends []int // Assets are the asset types held in this channel Assets []Asset // Balances is the allocation of assets to the Params.Parts @@ -109,9 +111,10 @@ var ( ) // NewAllocation returns a new allocation for the given number of participants and assets. -func NewAllocation(numParts int, assets ...Asset) *Allocation { +func NewAllocation(numParts int, backends []int, assets ...Asset) *Allocation { return &Allocation{ Assets: assets, + Backends: backends, Balances: MakeBalances(len(assets), numParts), } } @@ -185,6 +188,12 @@ func (a *Allocation) NumParts() int { // Clone returns a deep copy of the Allocation object. // If it is nil, it returns nil. func (a Allocation) Clone() (clone Allocation) { + if a.Backends != nil { + clone.Backends = make([]int, len(a.Backends)) + for i, bID := range a.Backends { + clone.Backends[i] = bID + } + } if a.Assets != nil { clone.Assets = make([]Asset, len(a.Assets)) for i, asset := range a.Assets { @@ -352,8 +361,13 @@ func (a *Allocation) Decode(r io.Reader) error { } // decode assets a.Assets = make([]Asset, numAssets) + a.Backends = make([]int, numAssets) for i := range a.Assets { - asset := NewAsset() + // decode backend index + if err := perunio.Decode(r); err != nil { + return errors.WithMessagef(err, "decoding backend index for asset %d", i) + } + asset := NewAsset(a.Backends[i]) if err := perunio.Decode(r, asset); err != nil { return errors.WithMessagef(err, "decoding asset %d", i) } diff --git a/channel/app.go b/channel/app.go index 417bd41f1..239d4ec37 100644 --- a/channel/app.go +++ b/channel/app.go @@ -151,6 +151,11 @@ type OptAppEnc struct { App } +// OptAppEncMap makes an optional App value encodable. +type OptAppEncMap struct { + App map[int]App +} + // Encode encodes an optional App value. func (e OptAppEnc) Encode(w io.Writer) error { if IsNoApp(e.App) { @@ -159,11 +164,37 @@ func (e OptAppEnc) Encode(w io.Writer) error { return perunio.Encode(w, true, e.App.Def()) } +// Encode encodes an optional App value. +func (e OptAppEncMap) Encode(w io.Writer) error { + if e.App == nil { + return perunio.Encode(w, false) + } + // Encode the map length first + if err := perunio.Encode(w, len(e.App)); err != nil { + return err + } + // Encode each map entry + for key, app := range e.App { + if IsNoApp(app) { + return errors.New("app in map is nil") + } + if err := perunio.Encode(w, key, app.Def()); err != nil { + return err + } + } + return nil +} + // OptAppDec makes an optional App value decodable. type OptAppDec struct { App *App } +// OptAppDecMap makes an optional App value decodable. +type OptAppDecMap struct { + App *map[int]App +} + // Decode decodes an optional App value. func (d OptAppDec) Decode(r io.Reader) (err error) { var hasApp bool @@ -174,7 +205,7 @@ func (d OptAppDec) Decode(r io.Reader) (err error) { *d.App = NoApp() return nil } - appDef := backend.NewAppID() + appDef, _ := backend[0].NewAppID() err = perunio.Decode(r, appDef) if err != nil { return errors.WithMessage(err, "decode app address") @@ -183,6 +214,39 @@ func (d OptAppDec) Decode(r io.Reader) (err error) { return errors.WithMessage(err, "resolve app") } +// Decode decodes an optional App value. +func (d OptAppDecMap) Decode(r io.Reader) (err error) { + var mapLen int + if err := perunio.Decode(r, &mapLen); err != nil { + return err + } + *d.App = make(map[int]App, mapLen) + for i := 0; i < mapLen; i++ { + var key int + if err := perunio.Decode(r, &key); err != nil { + return err + } + var hasApp bool + if err := perunio.Decode(r, &hasApp); err != nil { + return err + } + if !hasApp { + (*d.App)[key] = nil + continue + } + var appID AppID + if err := perunio.Decode(r, &appID); err != nil { + return err + } + app, err := Resolve(appID) + if err != nil { + return errors.WithMessage(err, "resolve app") + } + (*d.App)[key] = app + } + return nil +} + // OptAppAndDataEnc makes an optional pair of App definition and Data encodable. type OptAppAndDataEnc struct { App App diff --git a/channel/backend.go b/channel/backend.go index be57819de..68e1e8421 100644 --- a/channel/backend.go +++ b/channel/backend.go @@ -15,12 +15,13 @@ package channel import ( + "errors" "perun.network/go-perun/wallet" ) // backend is set to the global channel backend. Must not be set directly but // through importing the needed backend. -var backend Backend +var backend map[int]Backend // Backend is an interface that needs to be implemented for every blockchain. // It provides basic functionalities to the framework. @@ -30,7 +31,7 @@ type Backend interface { // In order to guarantee non-malleability of States, any parameters omitted // from the CalcID digest need to be signed together with the State in // Sign(). - CalcID(*Params) ID + CalcID(*Params) (ID, error) // Sign signs a channel's State with the given Account. // Returns the signature or an error. @@ -46,41 +47,88 @@ type Backend interface { // NewAppID returns an object of type AppID, which can be used for // unmarshalling an app identifier from its binary representation. - NewAppID() AppID + NewAppID() (AppID, error) } // SetBackend sets the global channel backend. Must not be called directly but // through importing the needed backend. -func SetBackend(b Backend) { - if backend != nil { +func SetBackend(b Backend, id int) { + if backend == nil { + backend = make(map[int]Backend) + } + if backend[id] != nil { panic("channel backend already set") } - backend = b + backend[id] = b } // CalcID calculates the CalcID. -func CalcID(p *Params) ID { - return backend.CalcID(p) +func CalcID(p *Params) (ID, error) { + var lastErr error + for _, b := range backend { + id, err := b.CalcID(p) + if err == nil { + return id, nil + } else { + lastErr = err + } + } + + if lastErr != nil { + return ID{}, errors.Join(lastErr) + } + + return ID{}, errors.New("no valid ID found") } // Sign creates a signature from the account a on state s. func Sign(a wallet.Account, s *State) (wallet.Sig, error) { - return backend.Sign(a, s) + errs := make([]error, len(backend)) + for _, b := range backend { + sig, err := b.Sign(a, s) + if err == nil { + return sig, nil + } else { + errs = append(errs, err) + } + } + if len(errs) > 0 { + return nil, errors.Join(errs...) + } + return nil, errors.New("no valid signature found") } // Verify verifies that a signature was a valid signature from addr on a state. -func Verify(addr wallet.Address, state *State, sig wallet.Sig) (bool, error) { - return backend.Verify(addr, state, sig) +func Verify(a map[int]wallet.Address, state *State, sig wallet.Sig) (bool, error) { + errs := make([]error, len(backend)) + for i, addr := range a { + v, err := backend[i].Verify(addr, state, sig) + if v { + return true, nil + } else { + errs = append(errs, err) + } + } + if len(errs) > 0 { + return false, errors.Join(errs...) + } + return false, errors.New("could not validate signature") } // NewAsset returns a variable of type Asset, which can be used // for unmarshalling an asset from its binary representation. -func NewAsset() Asset { - return backend.NewAsset() +func NewAsset(id int) Asset { + return backend[id].NewAsset() } // NewAppID returns an object of type AppID, which can be used for // unmarshalling an app identifier from its binary representation. -func NewAppID() AppID { - return backend.NewAppID() +func NewAppID() (AppID, error) { + for i := range backend { + id, err := backend[i].NewAppID() + if err == nil { + return id, nil + } + } + return nil, errors.New("no backend found") } diff --git a/channel/backendtest.go b/channel/backendtest.go index 087f04ed8..81b1a661c 100644 --- a/channel/backendtest.go +++ b/channel/backendtest.go @@ -24,7 +24,7 @@ import ( // SetBackendTest is a generic backend test. func SetBackendTest(t *testing.T) { t.Helper() - assert.Panics(t, func() { SetBackend(nil) }, "nil backend set should panic") + assert.Panics(t, func() { SetBackend(nil, 0) }, "nil backend set should panic") require.NotNil(t, backend, "backend should be already set by init()") - assert.Panics(t, func() { SetBackend(backend) }, "setting a backend twice should panic") + assert.Panics(t, func() { SetBackend(backend[0], 0) }, "setting a backend twice should panic") } diff --git a/channel/machine.go b/channel/machine.go index 0175a2067..f9585177b 100644 --- a/channel/machine.go +++ b/channel/machine.go @@ -16,9 +16,8 @@ package channel import ( "fmt" - stdio "io" - "github.com/pkg/errors" + stdio "io" "perun.network/go-perun/log" "perun.network/go-perun/wallet" @@ -224,6 +223,7 @@ func (m *machine) Sig() (sig wallet.Sig, err error) { } if m.stagingTX.Sigs[m.idx] == nil { + sig, err = Sign(m.acc, m.stagingTX.State) if err != nil { return @@ -289,7 +289,6 @@ func (m *machine) AddSig(idx Index, sig wallet.Sig) error { if m.stagingTX.Sigs[idx] != nil { return errors.Errorf("signature for idx %d already present (ID: %x)", idx, m.params.id) } - if ok, err := Verify(m.params.Parts[idx], m.stagingTX.State, sig); err != nil { return err } else if !ok { diff --git a/channel/multi/adjudicator.go b/channel/multi/adjudicator.go index 5fa5d9db2..43a16a77e 100644 --- a/channel/multi/adjudicator.go +++ b/channel/multi/adjudicator.go @@ -23,24 +23,24 @@ import ( // Adjudicator is a multi-ledger adjudicator. type Adjudicator struct { - adjudicators map[LedgerIDMapKey]channel.Adjudicator + adjudicators map[AssetID]channel.Adjudicator } // NewAdjudicator creates a new adjudicator. func NewAdjudicator() *Adjudicator { return &Adjudicator{ - adjudicators: make(map[LedgerIDMapKey]channel.Adjudicator), + adjudicators: make(map[AssetID]channel.Adjudicator), } } // RegisterAdjudicator registers an adjudicator for a given ledger. -func (a *Adjudicator) RegisterAdjudicator(l LedgerID, la channel.Adjudicator) { - a.adjudicators[l.MapKey()] = la +func (a *Adjudicator) RegisterAdjudicator(l AssetID, la channel.Adjudicator) { + a.adjudicators[l] = la } // LedgerAdjudicator returns the adjudicator for a given ledger. -func (a *Adjudicator) LedgerAdjudicator(l LedgerID) (channel.Adjudicator, bool) { - adj, ok := a.adjudicators[l.MapKey()] +func (a *Adjudicator) LedgerAdjudicator(l AssetID) (channel.Adjudicator, bool) { + adj, ok := a.adjudicators[l] return adj, ok } @@ -48,12 +48,12 @@ func (a *Adjudicator) LedgerAdjudicator(l LedgerID) (channel.Adjudicator, bool) // all relevant adjudicators. If any of the calls fails, the method returns an // error. func (a *Adjudicator) Register(ctx context.Context, req channel.AdjudicatorReq, subStates []channel.SignedState) error { - ledgers, err := assets(req.Tx.Assets).LedgerIDs() + assetIds, err := assets(req.Tx.Assets).LedgerIDs() if err != nil { return err } - err = a.dispatch(ledgers, func(la channel.Adjudicator) error { + err = a.dispatch(assetIds, func(la channel.Adjudicator) error { return la.Register(ctx, req, subStates) }) return err @@ -63,12 +63,12 @@ func (a *Adjudicator) Register(ctx context.Context, req channel.AdjudicatorReq, // Progress calls to all relevant adjudicators. If any of the calls fails, the // method returns an error. func (a *Adjudicator) Progress(ctx context.Context, req channel.ProgressReq) error { - ledgers, err := assets(req.Tx.Assets).LedgerIDs() + assetIds, err := assets(req.Tx.Assets).LedgerIDs() if err != nil { return err } - err = a.dispatch(ledgers, func(la channel.Adjudicator) error { + err = a.dispatch(assetIds, func(la channel.Adjudicator) error { return la.Progress(ctx, req) }) return err @@ -78,31 +78,31 @@ func (a *Adjudicator) Progress(ctx context.Context, req channel.ProgressReq) err // Withdraw calls to all relevant adjudicators. If any of the calls fails, the // method returns an error. func (a *Adjudicator) Withdraw(ctx context.Context, req channel.AdjudicatorReq, subStates channel.StateMap) error { - ledgers, err := assets(req.Tx.Assets).LedgerIDs() + assetIds, err := assets(req.Tx.Assets).LedgerIDs() if err != nil { return err } - err = a.dispatch(ledgers, func(la channel.Adjudicator) error { + err = a.dispatch(assetIds, func(la channel.Adjudicator) error { return la.Withdraw(ctx, req, subStates) }) return err } // dispatch dispatches an adjudicator call on all given ledgers. -func (a *Adjudicator) dispatch(ledgers []LedgerID, f func(channel.Adjudicator) error) error { - n := len(ledgers) +func (a *Adjudicator) dispatch(assetIds []AssetID, f func(channel.Adjudicator) error) error { + n := len(assetIds) errs := make(chan error, n) - for _, l := range ledgers { - go func(l LedgerID) { + for _, l := range assetIds { + go func(l AssetID) { err := func() error { - id := l.MapKey() - la, ok := a.adjudicators[id] + adjs, ok := a.adjudicators[l] if !ok { - return fmt.Errorf("Adjudicator not found for ledger %v", id) + return fmt.Errorf("adjudicator not found for id %v", l) } - err := f(la) + // Call the provided function f with the Adjudicator + err := f(adjs) return err }() errs <- err diff --git a/channel/multi/asset.go b/channel/multi/asset.go index 50507b5c3..048e7e55d 100644 --- a/channel/multi/asset.go +++ b/channel/multi/asset.go @@ -24,7 +24,12 @@ type ( // Asset defines a multi-ledger asset. Asset interface { channel.Asset - LedgerID() LedgerID + AssetID() AssetID + } + + AssetID struct { + BackendID uint32 + LedgerId LedgerID } // LedgerIDMapKey is the map key representation of a ledger identifier. @@ -39,32 +44,27 @@ type ( ) // LedgerIDs returns the identifiers of the associated ledgers. -func (a assets) LedgerIDs() ([]LedgerID, error) { - ids := make(map[LedgerIDMapKey]LedgerID) +func (a assets) LedgerIDs() ([]AssetID, error) { + var result []AssetID for _, asset := range a { ma, ok := asset.(Asset) if !ok { - return nil, fmt.Errorf("wrong asset type: expected multi.Asset, got %T", a) + return nil, fmt.Errorf("wrong asset type: expected Asset, got %T", asset) } - id := ma.LedgerID() - ids[id.MapKey()] = id - } + assetID := ma.AssetID() - idsArray := make([]LedgerID, len(ids)) - i := 0 - for _, v := range ids { - idsArray[i] = v - i++ + // Append the pair of IDs to the result slice + result = append(result, assetID) } - return idsArray, nil + return result, nil } // IsMultiLedgerAssets returns whether the assets are from multiple ledgers. func IsMultiLedgerAssets(assets []channel.Asset) bool { hasMulti := false - var id LedgerID + var id AssetID for _, asset := range assets { multiAsset, ok := asset.(Asset) switch { @@ -72,8 +72,8 @@ func IsMultiLedgerAssets(assets []channel.Asset) bool { continue case !hasMulti: hasMulti = true - id = multiAsset.LedgerID() - case id.MapKey() != multiAsset.LedgerID().MapKey(): + id = multiAsset.AssetID() + case id.LedgerId.MapKey() != multiAsset.AssetID().LedgerId.MapKey(): return true } } diff --git a/channel/multi/funder.go b/channel/multi/funder.go index 95c904596..bf107636a 100644 --- a/channel/multi/funder.go +++ b/channel/multi/funder.go @@ -26,27 +26,27 @@ import ( // funders is a map of LedgerIDs corresponding to a funder on some chain. // egoisticChains is a map of LedgerIDs corresponding to a boolean indicating whether the chain should be funded last. type Funder struct { - funders map[LedgerIDMapKey]channel.Funder - egoisticChains map[LedgerIDMapKey]bool + funders map[AssetID]channel.Funder + egoisticChains map[AssetID]bool } // NewFunder creates a new funder. func NewFunder() *Funder { return &Funder{ - funders: make(map[LedgerIDMapKey]channel.Funder), - egoisticChains: make(map[LedgerIDMapKey]bool), + funders: make(map[AssetID]channel.Funder), + egoisticChains: make(map[AssetID]bool), } } // RegisterFunder registers a funder for a given ledger. -func (f *Funder) RegisterFunder(l LedgerID, lf channel.Funder) { - f.funders[l.MapKey()] = lf - f.egoisticChains[l.MapKey()] = false +func (f *Funder) RegisterFunder(l AssetID, lf channel.Funder) { + f.funders[l] = lf + f.egoisticChains[l] = false } // SetEgoisticChain sets the egoistic chain flag for a given ledger. -func (f *Funder) SetEgoisticChain(l LedgerID, egoistic bool) { - f.egoisticChains[l.MapKey()] = egoistic +func (f *Funder) SetEgoisticChain(l AssetID, id int, egoistic bool) { + f.egoisticChains[l] = egoistic } // Fund funds a multi-ledger channel. It dispatches funding calls to all @@ -58,16 +58,16 @@ func (f *Funder) Fund(ctx context.Context, request channel.FundingReq) error { ctx, cancel := context.WithTimeout(ctx, d) defer cancel() - ledgers, err := assets(request.State.Assets).LedgerIDs() + assetIDs, err := assets(request.State.Assets).LedgerIDs() if err != nil { return err } - var egoisticLedgers []LedgerID - var nonEgoisticLedgers []LedgerID + var egoisticLedgers []AssetID + var nonEgoisticLedgers []AssetID - for _, l := range ledgers { - if f.egoisticChains[l.MapKey()] { + for _, l := range assetIDs { + if f.egoisticChains[l] { egoisticLedgers = append(egoisticLedgers, l) } else { nonEgoisticLedgers = append(nonEgoisticLedgers, l) @@ -89,29 +89,35 @@ func (f *Funder) Fund(ctx context.Context, request channel.FundingReq) error { return nil } -func fundLedgers(ctx context.Context, request channel.FundingReq, ledgers []LedgerID, funders map[LedgerIDMapKey]channel.Funder) error { - n := len(ledgers) +func fundLedgers(ctx context.Context, request channel.FundingReq, assetIDs []AssetID, funders map[AssetID]channel.Funder) error { + // Calculate the total number of funders + n := len(assetIDs) + errs := make(chan error, n) - for _, le := range ledgers { - go func(le LedgerID) { - errs <- func() error { - id := le.MapKey() - lf, ok := funders[id] - if !ok { - return fmt.Errorf("Funder not found for ledger %v", id) - } - - err := lf.Fund(ctx, request) - return err - }() - }(le) + + // Iterate over blockchains to get the LedgerIDs + for _, assetID := range assetIDs { + go func(assetID AssetID) { + // Get the Funder from the funders map + funder, ok := funders[assetID] + if !ok { + errs <- fmt.Errorf("funder map not found for blockchain %d and ledger %d", assetID.BackendID, assetID.LedgerId) + return + } + + // Call the Fund method + err := funder.Fund(ctx, request) + errs <- err + }(assetID) } + // Collect errors for i := 0; i < n; i++ { err := <-errs if err != nil { return err } } + return nil } diff --git a/channel/params.go b/channel/params.go index d872b8ea6..1079f9a83 100644 --- a/channel/params.go +++ b/channel/params.go @@ -63,7 +63,7 @@ type Params struct { // ChallengeDuration in seconds during disputes ChallengeDuration uint64 // Parts are the channel participants - Parts []wallet.Address + Parts []map[int]wallet.Address // App identifies the application that this channel is running. It is // optional, and if nil, signifies that a channel is a payment channel. App App `cloneable:"shallow"` @@ -84,10 +84,20 @@ func (p *Params) ID() ID { // appDef optional: if it is nil, it describes a payment channel. The channel id // is also calculated here and persisted because it probably is an expensive // hash operation. -func NewParams(challengeDuration uint64, parts []wallet.Address, app App, nonce Nonce, ledger bool, virtual bool) (*Params, error) { +func NewParams(challengeDuration uint64, parts []map[int]wallet.Address, app App, nonce Nonce, ledger bool, virtual bool) (*Params, error) { if err := ValidateParameters(challengeDuration, len(parts), app, nonce); err != nil { return nil, errors.WithMessage(err, "invalid parameter for NewParams") } + for _, ps := range parts { + for id, p := range ps { + if backend[p.BackendID()] == nil { + return nil, errors.Errorf("no backend with id %d", p.BackendID()) + } + if id != p.BackendID() { + return nil, errors.Errorf("participant %v has wrong backend id %d", p, p.BackendID()) + } + } + } return NewParamsUnsafe(challengeDuration, parts, app, nonce, ledger, virtual), nil } @@ -130,7 +140,7 @@ func ValidateParameters(challengeDuration uint64, numParts int, app App, nonce N // NewParamsUnsafe creates Params from the given data and does NOT perform // sanity checks. The channel id is also calculated here and persisted because // it probably is an expensive hash operation. -func NewParamsUnsafe(challengeDuration uint64, parts []wallet.Address, app App, nonce Nonce, ledger bool, virtual bool) *Params { +func NewParamsUnsafe(challengeDuration uint64, parts []map[int]wallet.Address, app App, nonce Nonce, ledger bool, virtual bool) *Params { p := &Params{ ChallengeDuration: challengeDuration, Parts: parts, @@ -139,17 +149,32 @@ func NewParamsUnsafe(challengeDuration uint64, parts []wallet.Address, app App, LedgerChannel: ledger, VirtualChannel: virtual, } + // probably an expensive hash operation, do it only once during creation. - p.id = CalcID(p) + id, err := CalcID(p) + if err != nil || id == Zero { + log.Panicf("Could not calculate channel id: %v", err) + } + p.id = id return p } +// CloneAddress returns a clone of an Address using its binary marshaling +// implementation. It panics if an error occurs during binary (un)marshaling. +func CloneAddresses(as []map[int]wallet.Address) []map[int]wallet.Address { + var cloneMap []map[int]wallet.Address + for _, a := range as { + cloneMap = append(cloneMap, wallet.CloneAddressesMap(a)) + } + return cloneMap +} + // Clone returns a deep copy of Params. func (p *Params) Clone() *Params { return &Params{ id: p.ID(), ChallengeDuration: p.ChallengeDuration, - Parts: wallet.CloneAddresses(p.Parts), + Parts: CloneAddresses(p.Parts), App: p.App, Nonce: new(big.Int).Set(p.Nonce), LedgerChannel: p.LedgerChannel, @@ -159,10 +184,11 @@ func (p *Params) Clone() *Params { // Encode uses the pkg/io module to serialize a params instance. func (p *Params) Encode(w stdio.Writer) error { + return perunio.Encode(w, p.ChallengeDuration, - wallet.AddressesWithLen(p.Parts), - OptAppEnc{p.App}, + wallet.AddressMapArray{p.Parts}, + OptAppEnc{App: p.App}, p.Nonce, p.LedgerChannel, p.VirtualChannel, @@ -173,7 +199,7 @@ func (p *Params) Encode(w stdio.Writer) error { func (p *Params) Decode(r stdio.Reader) error { var ( challengeDuration uint64 - parts wallet.AddressesWithLen + parts wallet.AddressMapArray app App nonce Nonce ledger bool @@ -192,7 +218,7 @@ func (p *Params) Decode(r stdio.Reader) error { return err } - _p, err := NewParams(challengeDuration, parts, app, nonce, ledger, virtual) + _p, err := NewParams(challengeDuration, parts.Addr, app, nonce, ledger, virtual) if err != nil { return err } diff --git a/channel/persistence/keyvalue/persister.go b/channel/persistence/keyvalue/persister.go index 6f606cce6..05fa3a111 100644 --- a/channel/persistence/keyvalue/persister.go +++ b/channel/persistence/keyvalue/persister.go @@ -32,7 +32,7 @@ import ( ) // ChannelCreated inserts a channel into the database. -func (pr *PersistRestorer) ChannelCreated(_ context.Context, s channel.Source, peers []wire.Address, parent *channel.ID) error { +func (pr *PersistRestorer) ChannelCreated(_ context.Context, s channel.Source, peers []map[int]wire.Address, parent *channel.ID) error { db := pr.channelDB(s.ID()).NewBatch() // Write the channel data in the "Channel" table. numParts := len(s.Params().Parts) @@ -47,7 +47,7 @@ func (pr *PersistRestorer) ChannelCreated(_ context.Context, s channel.Source, p } // Write peers in the "Channel" table. - if err := dbPut(db, prefix.Peers, wire.AddressesWithLen(peers)); err != nil { + if err := dbPut(db, prefix.Peers, (*wire.AddressMapArray)(&peers)); err != nil { return errors.WithMessage(err, "putting peers into channel table") } @@ -244,9 +244,9 @@ func decodeIdxFromDBKey(key string) (int, error) { return strconv.Atoi(vals[len(vals)-1]) } -func peerChannelKey(p wire.Address, ch channel.ID) (string, error) { +func peerChannelKey(p map[int]wire.Address, ch channel.ID) (string, error) { var key bytes.Buffer - if err := perunio.Encode(&key, p); err != nil { + if err := perunio.Encode(&key, wire.AddressDecMap(p)); err != nil { return "", errors.WithMessage(err, "encoding peer address") } key.WriteString(":channel:") diff --git a/channel/persistence/keyvalue/restorer.go b/channel/persistence/keyvalue/restorer.go index 6dfea22cd..f7f1ada8c 100644 --- a/channel/persistence/keyvalue/restorer.go +++ b/channel/persistence/keyvalue/restorer.go @@ -41,20 +41,20 @@ type ChannelIterator struct { } // ActivePeers returns a list of all peers with which a channel is persisted. -func (pr *PersistRestorer) ActivePeers(ctx context.Context) ([]wire.Address, error) { +func (pr *PersistRestorer) ActivePeers(ctx context.Context) ([]map[int]wire.Address, error) { it := sortedkv.NewTable(pr.db, prefix.PeerDB).NewIterator() - peermap := make(map[wire.AddrKey]wire.Address) + peermap := make(map[wire.AddrKey]map[int]wire.Address) for it.Next() { - addr := wire.NewAddress() - err := perunio.Decode(bytes.NewBufferString(it.Key()), addr) + var addr map[int]wire.Address + err := perunio.Decode(bytes.NewBufferString(it.Key()), (*wire.AddressDecMap)(&addr)) if err != nil { return nil, errors.WithMessagef(err, "decoding peer key (%x)", it.Key()) } - peermap[wire.Key(addr)] = addr + peermap[wire.Keys(addr)] = addr } - peers := make([]wire.Address, 0, len(peermap)) + peers := make([]map[int]wire.Address, 0, len(peermap)) for _, peer := range peermap { peers = append(peers, peer) } @@ -63,13 +63,13 @@ func (pr *PersistRestorer) ActivePeers(ctx context.Context) ([]wire.Address, err // channelPeers returns a slice of peer addresses for a given channel id from // the db of PersistRestorer. -func (pr *PersistRestorer) channelPeers(id channel.ID) ([]wire.Address, error) { - var ps wire.AddressesWithLen +func (pr *PersistRestorer) channelPeers(id channel.ID) ([]map[int]wire.Address, error) { + var ps wire.AddressMapArray peers, err := pr.channelDB(id).Get(prefix.Peers) if err != nil { return nil, errors.WithMessage(err, "unable to get peerlist from db") } - return []wire.Address(ps), errors.WithMessage(perunio.Decode(bytes.NewBuffer([]byte(peers)), &ps), + return ps, errors.WithMessage(perunio.Decode(bytes.NewBuffer([]byte(peers)), &ps), "decoding peerlist") } @@ -83,7 +83,7 @@ func (pr *PersistRestorer) RestoreAll() (persistence.ChannelIterator, error) { // RestorePeer should return an iterator over all persisted channels which // the given peer is a part of. -func (pr *PersistRestorer) RestorePeer(addr wire.Address) (persistence.ChannelIterator, error) { +func (pr *PersistRestorer) RestorePeer(addr map[int]wire.Address) (persistence.ChannelIterator, error) { it := &ChannelIterator{restorer: pr} chandb := sortedkv.NewTable(pr.db, prefix.ChannelDB) @@ -106,9 +106,9 @@ func (pr *PersistRestorer) RestorePeer(addr wire.Address) (persistence.ChannelIt } // peerChannelsKey creates a db-key-string for a given wire.Address. -func peerChannelsKey(addr wire.Address) (string, error) { +func peerChannelsKey(addr map[int]wire.Address) (string, error) { var key strings.Builder - if err := perunio.Encode(&key, addr); err != nil { + if err := perunio.Encode(&key, wire.AddressDecMap(addr)); err != nil { return "", errors.WithMessage(err, "encoding peer address") } key.WriteString(":channel:") @@ -157,7 +157,7 @@ func (i *ChannelIterator) Next(context.Context) bool { !i.decodeNext("index", &i.ch.IdxV, noOpts) || !i.decodeNext("params", i.ch.ParamsV, noOpts) || !i.decodeNext("parent", optChannelIDDec{&i.ch.Parent}, noOpts) || - !i.decodeNext("peers", (*wire.AddressesWithLen)(&i.ch.PeersV), noOpts) || + !i.decodeNext("peers", (*wire.AddressMapArray)(&i.ch.PeersV), noOpts) || !i.decodeNext("phase", &i.ch.PhaseV, noOpts) { return false } diff --git a/channel/persistence/nonpersister.go b/channel/persistence/nonpersister.go index 8efab461d..5334718d8 100644 --- a/channel/persistence/nonpersister.go +++ b/channel/persistence/nonpersister.go @@ -32,7 +32,7 @@ type nonPersistRestorer struct{} // Persister implementation -func (nonPersistRestorer) ChannelCreated(context.Context, channel.Source, []wire.Address, *channel.ID) error { +func (nonPersistRestorer) ChannelCreated(context.Context, channel.Source, []map[int]wire.Address, *channel.ID) error { return nil } func (nonPersistRestorer) ChannelRemoved(context.Context, channel.ID) error { return nil } @@ -44,13 +44,15 @@ func (nonPersistRestorer) Close() error // Restorer implementation -func (nonPersistRestorer) ActivePeers(context.Context) ([]wire.Address, error) { return nil, nil } +func (nonPersistRestorer) ActivePeers(context.Context) ([]map[int]wire.Address, error) { + return nil, nil +} func (nonPersistRestorer) RestoreAll() (ChannelIterator, error) { return emptyChanIterator{}, nil } -func (nonPersistRestorer) RestorePeer(wire.Address) (ChannelIterator, error) { +func (nonPersistRestorer) RestorePeer(map[int]wire.Address) (ChannelIterator, error) { return emptyChanIterator{}, nil } diff --git a/channel/persistence/persistence.go b/channel/persistence/persistence.go index 30705dfe2..0750cf0a4 100644 --- a/channel/persistence/persistence.go +++ b/channel/persistence/persistence.go @@ -35,7 +35,7 @@ type ( // state will be empty. The passed peers are the channel network peers, // which should also be persisted. The parent field is the parent // channel's ID, or nil, if it is a ledger channel. - ChannelCreated(ctx context.Context, source channel.Source, peers []wire.Address, parent *channel.ID) error + ChannelCreated(ctx context.Context, source channel.Source, peers []map[int]wire.Address, parent *channel.ID) error // ChannelRemoved is called by the client when a channel is removed because // it has been successfully settled and its data is no longer needed. All @@ -72,11 +72,11 @@ type ( Restorer interface { // ActivePeers should return a list of all peers with which any channel is // persisted. - ActivePeers(context.Context) ([]wire.Address, error) + ActivePeers(context.Context) ([]map[int]wire.Address, error) // RestorePeer should return an iterator over all persisted channels which // the given peer is a part of. - RestorePeer(wire.Address) (ChannelIterator, error) + RestorePeer(map[int]wire.Address) (ChannelIterator, error) // RestoreChannel should return the channel with the requested ID. RestoreChannel(context.Context, channel.ID) (*Channel, error) @@ -125,7 +125,7 @@ type ( // sub-channel, also holds the parent channel's ID. Channel struct { chSource - PeersV []wire.Address + PeersV []map[int]wire.Address Parent *channel.ID } ) @@ -156,7 +156,7 @@ func NewChannel() *Channel { // FromSource creates a new Channel object from given `channel.Source`, the // channel's network peers, and the parent channel ID, if it exists. -func FromSource(s channel.Source, ps []wire.Address, parent *channel.ID) *Channel { +func FromSource(s channel.Source, ps []map[int]wire.Address, parent *channel.ID) *Channel { return &Channel{ chSource{ IdxV: s.Idx(), diff --git a/channel/persistence/statemachine_test.go b/channel/persistence/statemachine_test.go index c5e731ebf..4cf8b1a1b 100644 --- a/channel/persistence/statemachine_test.go +++ b/channel/persistence/statemachine_test.go @@ -40,7 +40,9 @@ func TestStateMachine(t *testing.T) { const n = 5 // number of participants accs, parts := wtest.NewRandomAccounts(rng, n) // local participant idx 0 - params := ctest.NewRandomParams(rng, ctest.WithParts(parts...)) + params := ctest.NewRandomParams(rng, ctest.WithParts(parts)) + t.Log("Participants:", parts, "accs:", accs) + t.Log("Params:", params) csm, err := channel.NewStateMachine(accs[0], *params) require.NoError(err) diff --git a/channel/persistence/test/channel.go b/channel/persistence/test/channel.go index 9cd8857dd..bde5aed0a 100644 --- a/channel/persistence/test/channel.go +++ b/channel/persistence/test/channel.go @@ -32,7 +32,7 @@ import ( // as the associated persister and restorer. type Channel struct { accounts []wallet.Account - peers []wire.Address + peers []map[int]wire.Address parent *channel.ID *persistence.StateMachine @@ -52,12 +52,12 @@ func NewRandomChannel( t require.TestingT, pr persistence.PersistRestorer, user channel.Index, - peers []wire.Address, + peers []map[int]wire.Address, parent *Channel, rng *rand.Rand, ) (c *Channel) { accs, parts := wtest.NewRandomAccounts(rng, len(peers)) - params := ctest.NewRandomParams(rng, ctest.WithParts(parts...)) + params := ctest.NewRandomParams(rng, ctest.WithParts(parts)) csm, err := channel.NewStateMachine(accs[0], *params) require.NoError(t, err) @@ -82,10 +82,10 @@ func NewRandomChannel( return c } -func requireEqualPeers(t require.TestingT, expected, actual []wire.Address) { +func requireEqualPeers(t require.TestingT, expected, actual []map[int]wire.Address) { require.Equal(t, len(expected), len(actual)) for i, p := range expected { - if !p.Equal(actual[i]) { + if !EqualWireMaps(p, actual[i]) { t.Errorf("restored peers for channel do not match\nexpected: %v\nactual: %v", actual, expected) t.FailNow() @@ -93,6 +93,18 @@ func requireEqualPeers(t require.TestingT, expected, actual []wire.Address) { } } +func EqualWireMaps(a, b map[int]wire.Address) bool { + if len(a) != len(b) { + return false + } + for i, addr := range a { + if !addr.Equal(b[i]) { + return false + } + } + return true +} + // AssertPersisted reads the channel state from the restorer and compares it // to the actual channel state. If an error occurs while restoring the channel // or if the restored channel does not match the actual channel state, then the diff --git a/channel/persistence/test/peerchans.go b/channel/persistence/test/peerchans.go index 5861340ff..a4832edf6 100644 --- a/channel/persistence/test/peerchans.go +++ b/channel/persistence/test/peerchans.go @@ -16,6 +16,7 @@ package test import ( "bytes" + "fmt" "perun.network/go-perun/channel" "perun.network/go-perun/wire" @@ -24,7 +25,7 @@ import ( type peerChans map[string][]channel.ID -func (pc peerChans) ID(p wire.Address) []channel.ID { +func (pc peerChans) ID(p map[int]wire.Address) []channel.ID { ids, ok := pc[peerKey(p)] if !ok { return nil @@ -32,23 +33,24 @@ func (pc peerChans) ID(p wire.Address) []channel.ID { return ids } -func (pc peerChans) Peers() []wire.Address { - ps := make([]wire.Address, 0, len(pc)) +func (pc peerChans) Peers() []map[int]wire.Address { + ps := make([]map[int]wire.Address, 0, len(pc)) for k := range pc { - ps = append(ps, peerFromKey(k)) + pk, _ := peerFromKey(k) + ps = append(ps, pk) } return ps } // Add adds the given channel id to each peer's id list. -func (pc peerChans) Add(id channel.ID, ps ...wire.Address) { +func (pc peerChans) Add(id channel.ID, ps ...map[int]wire.Address) { for _, p := range ps { pc.add(id, p) } } // Don't use add, use Add. -func (pc peerChans) add(id channel.ID, p wire.Address) { +func (pc peerChans) add(id channel.ID, p map[int]wire.Address) { pk := peerKey(p) ids := pc[pk] // nil ok, since we append pc[pk] = append(ids, id) @@ -74,20 +76,21 @@ func (pc peerChans) Delete(id channel.ID) { } } -func peerKey(a wire.Address) string { +func peerKey(a map[int]wire.Address) string { key := new(bytes.Buffer) - err := perunio.Encode(key, a) + err := perunio.Encode(key, wire.AddressDecMap(a)) if err != nil { panic("error encoding peer key: " + err.Error()) } return key.String() } -func peerFromKey(s string) wire.Address { - p := wire.NewAddress() - err := perunio.Decode(bytes.NewBuffer([]byte(s)), p) +func peerFromKey(s string) (map[int]wire.Address, error) { + p := make(map[int]wire.Address) + decMap := wire.AddressDecMap(p) + err := perunio.Decode(bytes.NewBuffer([]byte(s)), &decMap) if err != nil { - panic("error decoding peer key: " + err.Error()) + return nil, fmt.Errorf("error decoding peer key: %w", err) } - return p + return decMap, nil } diff --git a/channel/persistence/test/peerchans_internal_test.go b/channel/persistence/test/peerchans_internal_test.go index 33c59d4fb..fe68475a0 100644 --- a/channel/persistence/test/peerchans_internal_test.go +++ b/channel/persistence/test/peerchans_internal_test.go @@ -30,7 +30,7 @@ func TestEndpointChans(t *testing.T) { assert := assert.New(t) rng := pkgtest.Prng(t) id := []channel.ID{ctest.NewRandomChannelID(rng), ctest.NewRandomChannelID(rng)} - ps := wiretest.NewRandomAddresses(rng, 3) + ps := wiretest.NewRandomAddressesMap(rng, 3) pc := make(peerChans) pc.Add(id[0], ps...) @@ -43,7 +43,7 @@ func TestEndpointChans(t *testing.T) { pc.Delete(id[0]) // p[1] should be deleted as id[0] was their only channel assert.ElementsMatch(id[1:], pc.ID(ps[0])) assert.ElementsMatch(id[1:], pc.ID(ps[2])) - assert.ElementsMatch([]wire.Address{ps[0], ps[2]}, pc.Peers()) + assert.ElementsMatch([]map[int]wire.Address{ps[0], ps[2]}, pc.Peers()) assert.Nil(pc.ID(ps[1])) pc.Delete(id[1]) // now all peers should have been deleted diff --git a/channel/persistence/test/persistrestorer.go b/channel/persistence/test/persistrestorer.go index e1b9879ea..0bfafda14 100644 --- a/channel/persistence/test/persistrestorer.go +++ b/channel/persistence/test/persistrestorer.go @@ -57,7 +57,7 @@ func NewPersistRestorer(t *testing.T) *PersistRestorer { // ChannelCreated fully persists all of the source's data. func (pr *PersistRestorer) ChannelCreated( - _ context.Context, source channel.Source, peers []wire.Address, parent *channel.ID, + _ context.Context, source channel.Source, peers []map[int]wire.Address, parent *channel.ID, ) error { pr.mu.Lock() defer pr.mu.Unlock() @@ -182,7 +182,7 @@ func (pr *PersistRestorer) channel(id channel.ID) (*persistence.Channel, bool) { // Restorer implementation // ActivePeers returns all peers that channels are persisted for. -func (pr *PersistRestorer) ActivePeers(context.Context) ([]wire.Address, error) { +func (pr *PersistRestorer) ActivePeers(context.Context) ([]map[int]wire.Address, error) { pr.mu.RLock() defer pr.mu.RUnlock() @@ -191,7 +191,7 @@ func (pr *PersistRestorer) ActivePeers(context.Context) ([]wire.Address, error) // RestorePeer returns an iterator over all persisted channels which // the given peer is a part of. -func (pr *PersistRestorer) RestorePeer(peer wire.Address) (persistence.ChannelIterator, error) { +func (pr *PersistRestorer) RestorePeer(peer map[int]wire.Address) (persistence.ChannelIterator, error) { pr.mu.RLock() defer pr.mu.RUnlock() diff --git a/channel/persistence/test/persistrestorertest.go b/channel/persistence/test/persistrestorertest.go index bc5552930..c13f070fa 100644 --- a/channel/persistence/test/persistrestorertest.go +++ b/channel/persistence/test/persistrestorertest.go @@ -32,7 +32,7 @@ import ( // Client is a mock client that can be used to create channels. type Client struct { - addr wire.Address + addr map[int]wire.Address rng *rand.Rand pr persistence.PersistRestorer @@ -55,9 +55,9 @@ func NewClient(ctx context.Context, t *testing.T, rng *rand.Rand, pr persistence // NewChannel creates a new channel with the supplied peer as the other // participant. The client's participant index is randomly chosen. -func (c *Client) NewChannel(t require.TestingT, p wire.Address, parent *Channel) *Channel { +func (c *Client) NewChannel(t require.TestingT, p map[int]wire.Address, parent *Channel) *Channel { idx := c.rng.Intn(channelNumPeers) - peers := make([]wire.Address, channelNumPeers) + peers := make([]map[int]wire.Address, channelNumPeers) peers[idx] = c.addr peers[idx^1] = p @@ -94,7 +94,7 @@ func GenericPersistRestorerTest( ct := pkgtest.NewConcurrent(t) c := NewClient(ctx, t, rng, pr) - peers := test.NewRandomAddresses(rng, numPeers) + peers := test.NewRandomAddressesMap(rng, numPeers) channels := make([]map[channel.ID]*Channel, numPeers) var prevCh *Channel @@ -185,7 +185,7 @@ func GenericPersistRestorerTest( peerLoop: for idx, addr := range peers { for _, paddr := range persistedPeers { - if addr.Equal(paddr) { + if EqualWireMaps(addr, paddr) { continue peerLoop // found, next address } } diff --git a/channel/state.go b/channel/state.go index 758728a70..a2f349a75 100644 --- a/channel/state.go +++ b/channel/state.go @@ -17,6 +17,7 @@ package channel import ( "encoding" "io" + "perun.network/go-perun/wire" "github.com/pkg/errors" @@ -78,7 +79,7 @@ func newState(params *Params, initBals Allocation, initData Data) (*State, error n := len(params.Parts) for _, asset := range initBals.Balances { if n != len(asset) { - return nil, errors.New("number of participants in parameters and initial balances don't match") + return nil, errors.Errorf("number of participants in parameters and initial balances don't match: parts: %d, balances: %d", n, len(asset)) } } if err := initBals.Valid(); err != nil { @@ -158,3 +159,15 @@ func (s *State) Equal(t *State) error { func (s *State) ToSubAlloc() *SubAlloc { return NewSubAlloc(s.ID, s.Allocation.Sum(), nil) } + +func EqualWireMaps(a, b map[int]wire.Address) bool { + if len(a) != len(b) { + return false + } + for i, addr := range a { + if !addr.Equal(b[i]) { + return false + } + } + return true +} diff --git a/channel/test/backend.go b/channel/test/backend.go index e109df926..90b516d85 100644 --- a/channel/test/backend.go +++ b/channel/test/backend.go @@ -25,7 +25,7 @@ import ( "perun.network/go-perun/wallet" ) -type addressCreator = func() wallet.Address +type addressCreator = func() map[int]wallet.Address // Setup provides all objects needed for the generic channel tests. type ( @@ -73,7 +73,8 @@ func mergeTestOpts(opts ...GenericTestOption) GenericTestOptions { func GenericBackendTest(t *testing.T, s *Setup, opts ...GenericTestOption) { t.Helper() require := require.New(t) - ID := channel.CalcID(s.Params) + ID, err := channel.CalcID(s.Params) + require.NoError(err, "CalcID should not return an error") require.Equal(ID, s.State.ID, "ChannelID(params) should match the States ID") require.Equal(ID, s.Params.ID(), "ChannelID(params) should match the Params ID") require.NotNil(s.State.Data, "State data can not be nil") @@ -95,12 +96,13 @@ func GenericBackendTest(t *testing.T, s *Setup, opts ...GenericTestOption) { func genericChannelIDTest(t *testing.T, s *Setup) { t.Helper() require.NotNil(t, s.Params.Parts, "params.Parts can not be nil") - assert.Panics(t, func() { channel.CalcID(nil) }, "ChannelID(nil) should panic") + _, err := channel.CalcID(s.Params) + assert.NoError(t, err, "CalcID should not return an error") // Check that modifying the state changes the id for _, modParams := range buildModifiedParams(s.Params, s.Params2, s) { params := modParams - ID := channel.CalcID(¶ms) + ID, _ := channel.CalcID(¶ms) assert.NotEqual(t, ID, s.State.ID, "Channel ids should differ") } } @@ -114,7 +116,9 @@ func genericSignTest(t *testing.T, s *Setup) { func genericVerifyTest(t *testing.T, s *Setup, opts ...GenericTestOption) { t.Helper() addr := s.Account.Address() - require.Equal(t, channel.CalcID(s.Params), s.Params.ID(), "Invalid test params") + id, err := channel.CalcID(s.Params) + require.NoError(t, err, "CalcID should not return an error") + require.Equal(t, s.Params.ID(), id, "Invalid test params") sig, err := channel.Sign(s.Account, s.State) require.NoError(t, err, "Sign should not return an error") @@ -164,7 +168,7 @@ func buildModifiedParams(p1, p2 *channel.Params, s *Setup) (ret []channel.Params // Modify Parts[0] { modParams := *p1 - modParams.Parts = make([]wallet.Address, len(p1.Parts)) + modParams.Parts = make([]map[int]wallet.Address, len(p1.Parts)) copy(modParams.Parts, p1.Parts) modParams.Parts[0] = s.RandomAddress() ret = appendModParams(ret, modParams) diff --git a/channel/test/randomizer.go b/channel/test/randomizer.go index f1303f23e..26c13505e 100644 --- a/channel/test/randomizer.go +++ b/channel/test/randomizer.go @@ -82,8 +82,9 @@ func NewRandomAllocation(rng *rand.Rand, opts ...RandomOpt) *channel.Allocation assets := NewRandomAssets(rng, opt) bals := NewRandomBalances(rng, opt) locked := NewRandomLocked(rng, opt) + backends := NewRandomBackends(rng, len(assets), opt) - alloc := &channel.Allocation{Assets: assets, Balances: bals, Locked: locked} + alloc := &channel.Allocation{Backends: backends, Assets: assets, Balances: bals, Locked: locked} updateOpts(opts, WithAllocation(alloc)) return alloc } @@ -157,11 +158,11 @@ func NewRandomParams(rng *rand.Rand, opts ...RandomOpt) *channel.Params { return params } numParts := opt.NumParts(rng) - var parts []wallet.Address + var parts []map[int]wallet.Address if parts = opt.Parts(); parts == nil { - parts = make([]wallet.Address, numParts) + parts = make([]map[int]wallet.Address, numParts) for i := range parts { - parts[i] = test.NewRandomAddress(rng) + parts[i] = map[int]wallet.Address{0: test.NewRandomAddress(rng)} } } if firstPart := opt.FirstPart(); firstPart != nil { @@ -304,6 +305,18 @@ func NewRandomBalances(rng *rand.Rand, opts ...RandomOpt) channel.Balances { return balances } +// NewRandomBackends generates new random backend IDs. +// Options: `WithNumAssets` and `WithBackendIDs`. +func NewRandomBackends(rng *rand.Rand, num int, opts ...RandomOpt) []int { + backends := make([]int, num) + for i := range backends { + backends[i] = 0 + } + + updateOpts(opts, WithBackendIDs(backends)) + return backends +} + // NewRandomTransaction generates a new random `channel.Transaction`. // `sigMask` defines which signatures are generated. `len(sigmask)` is // assumed to be the number of participants. @@ -313,7 +326,7 @@ func NewRandomTransaction(rng *rand.Rand, sigMask []bool, opts ...RandomOpt) *ch opt := mergeRandomOpts(opts...) numParts := len(sigMask) accs, addrs := test.NewRandomAccounts(rng, numParts) - params := NewRandomParams(rng, WithParts(addrs...), opt) + params := NewRandomParams(rng, WithParts(addrs), opt) state := NewRandomState(rng, WithID(params.ID()), WithNumParts(numParts), opt) sigs := make([]wallet.Sig, numParts) diff --git a/channel/test/randomopts.go b/channel/test/randomopts.go index ba4d348e3..e1345888c 100644 --- a/channel/test/randomopts.go +++ b/channel/test/randomopts.go @@ -65,6 +65,16 @@ func WithApp(app channel.App) RandomOpt { return RandomOpt{"app": app, "appDef": appDef} } +// WithBackend sets the `backend` that should be used. +func WithBackend(id int) RandomOpt { + return RandomOpt{"backend": id} +} + +// WithBackendIDs sets the `backend` that should be used. +func WithBackendIDs(id []int) RandomOpt { + return RandomOpt{"backendIDs": id} +} + // WithoutApp configures a NoApp and NoData. func WithoutApp() RandomOpt { return RandomOpt{"app": channel.NoApp(), "appDef": nil, "appData": channel.NoData()} @@ -112,7 +122,7 @@ func WithChallengeDuration(d uint64) RandomOpt { } // WithFirstPart sets the first participant that should be used in randomly generated Params. Overrides `WithParts`. -func WithFirstPart(part wallet.Address) RandomOpt { +func WithFirstPart(part map[int]wallet.Address) RandomOpt { return RandomOpt{"firstPart": part} } @@ -182,12 +192,12 @@ func WithState(state *channel.State) RandomOpt { // WithParams sets the `Params` that should be used. // Also sets `WithID`, `WithChallengeDuration`, `WithParts`, `WithApp` and `WithNonce`. func WithParams(params *channel.Params) RandomOpt { - return RandomOpt{"params": params}.Append(WithID(params.ID()), WithChallengeDuration(params.ChallengeDuration), WithParts(params.Parts...), WithApp(params.App), WithNonce(params.Nonce)) + return RandomOpt{"params": params}.Append(WithID(params.ID()), WithChallengeDuration(params.ChallengeDuration), WithParts(params.Parts), WithApp(params.App), WithNonce(params.Nonce)) } // WithParts sets the `Parts` that should be used when generating Params. // Also sets `WithNumParts`. -func WithParts(parts ...wallet.Address) RandomOpt { +func WithParts(parts []map[int]wallet.Address) RandomOpt { return RandomOpt{"parts": parts, "numParts": len(parts)} } @@ -291,6 +301,22 @@ func (o RandomOpt) Assets() []channel.Asset { return o["assets"].([]channel.Asset) } +// Backend returns the `Backend` value of the `RandomOpt`. +func (o RandomOpt) Backend() (int, error) { + if _, ok := o["backend"]; !ok { + return 0, fmt.Errorf("backend not set") + } + return o["backend"].(int), nil +} + +// BackendID returns the `BackendID` value from `Allocation` of the `RandomOpt`. +func (o RandomOpt) BackendID() ([]int, error) { + if _, ok := o["backendIDs"]; !ok { + return []int{0}, fmt.Errorf("backend not set") + } + return o["backendIDs"].([]int), nil +} + // Balances returns the `Balances` value of the `RandomOpt`. // If not present, returns nil. func (o RandomOpt) Balances() channel.Balances { @@ -330,11 +356,11 @@ func (o RandomOpt) ID() (id channel.ID, valid bool) { // FirstPart returns the `FirstPart` value of the `RandomOpt`. // If not present, returns nil. -func (o RandomOpt) FirstPart() wallet.Address { +func (o RandomOpt) FirstPart() map[int]wallet.Address { if _, ok := o["firstPart"]; !ok { return nil } - return o["firstPart"].(wallet.Address) + return o["firstPart"].(map[int]wallet.Address) } // IsFinal returns the `IsFinal` value of the `RandomOpt`. @@ -472,11 +498,11 @@ func (o RandomOpt) Params() *channel.Params { // Parts returns the `Parts` value of the `RandomOpt`. // If not present, returns nil. -func (o RandomOpt) Parts() []wallet.Address { +func (o RandomOpt) Parts() []map[int]wallet.Address { if _, ok := o["parts"]; !ok { return nil } - return o["parts"].([]wallet.Address) + return o["parts"].([]map[int]wallet.Address) } // Version returns the `Version` value of the `RandomOpt`. diff --git a/channel/transaction.go b/channel/transaction.go index 1539d2f86..d1314dc0e 100644 --- a/channel/transaction.go +++ b/channel/transaction.go @@ -78,5 +78,5 @@ func (t *Transaction) Decode(r io.Reader) error { t.Sigs = make([]wallet.Sig, t.State.NumParts()) - return wallet.DecodeSparseSigs(r, &t.Sigs) + return wallet.DecodeSparseSigs(r, &t.Sigs, t.State.Allocation.Backends) } diff --git a/client/adjudicate.go b/client/adjudicate.go index 362a8f294..beefe8522 100644 --- a/client/adjudicate.go +++ b/client/adjudicate.go @@ -339,9 +339,9 @@ func (c *Channel) withdraw(ctx context.Context, secondary bool) error { } // hasParticipant returns we are participating in the channel. -func (c *Channel) hasParticipant(id wire.Address) bool { +func (c *Channel) hasParticipant(id map[int]wire.Address) bool { for _, p := range c.Peers() { - if id.Equal(p) { + if channel.EqualWireMaps(id, p) { return true } } diff --git a/client/appchannel_test.go b/client/appchannel_test.go index fbbeae345..adf088762 100644 --- a/client/appchannel_test.go +++ b/client/appchannel_test.go @@ -42,7 +42,7 @@ func TestProgression(t *testing.T) { execConfig := &clienttest.ProgressionExecConfig{ BaseExecConfig: clienttest.MakeBaseExecConfig( - [2]wire.Address{setups[0].Identity.Address(), setups[1].Identity.Address()}, + [2]map[int]wire.Address{setups[0].Identity.Address(), setups[1].Identity.Address()}, chtest.NewRandomAsset(rng), [2]*big.Int{big.NewInt(99), big.NewInt(1)}, client.WithApp(app, channel.NewMockOp(channel.OpValid)), diff --git a/client/channel.go b/client/channel.go index b17335562..a9cce6035 100644 --- a/client/channel.go +++ b/client/channel.go @@ -55,33 +55,33 @@ type Channel struct { func (c *Client) newChannel( acc wallet.Account, parent *Channel, - peers []wire.Address, + peers []map[int]wire.Address, // peerIdx, BackendID -> Address params channel.Params, ) (*Channel, error) { machine, err := channel.NewStateMachine(acc, params) if err != nil { return nil, errors.WithMessage(err, "creating state machine") } - return c.channelFromMachine(machine, parent, peers...) + return c.channelFromMachine(machine, parent, peers) } // channelFromSource is used to create a channel controller from restored data. -func (c *Client) channelFromSource(s channel.Source, parent *Channel, peers ...wire.Address) (*Channel, error) { - acc, err := c.wallet.Unlock(s.Params().Parts[s.Idx()]) +func (c *Client) channelFromSource(s channel.Source, parent *Channel, peers []map[int]wire.Address) (*Channel, error) { + accs, err := c.wallet.Unlock(s.Params().Parts[s.Idx()]) if err != nil { return nil, errors.WithMessage(err, "unlocking account for channel") } - machine, err := channel.RestoreStateMachine(acc, s) + machine, err := channel.RestoreStateMachine(accs, s) if err != nil { return nil, errors.WithMessage(err, "restoring state machine") } - return c.channelFromMachine(machine, parent, peers...) + return c.channelFromMachine(machine, parent, peers) } // channelFromMachine creates a channel controller around the passed state machine. -func (c *Client) channelFromMachine(machine *channel.StateMachine, parent *Channel, peers ...wire.Address) (*Channel, error) { +func (c *Client) channelFromMachine(machine *channel.StateMachine, parent *Channel, peers []map[int]wire.Address) (*Channel, error) { logger := c.logChan(machine.ID()) machine.SetLog(logger) // client logger has more fields pmachine := persistence.FromStateMachine(machine, c.pr) @@ -170,7 +170,7 @@ func (c *Channel) Phase() channel.Phase { // Peers returns the Perun network addresses of all peers, in the order // of the channel participants. -func (c *Channel) Peers() []wire.Address { +func (c *Channel) Peers() []map[int]wire.Address { return c.conn.Peers() } @@ -240,3 +240,15 @@ func (c *Channel) initExchangeSigsAndEnable(ctx context.Context) error { func (c *Channel) hasLockedFunds() bool { return len(c.machine.State().Locked) > 0 } + +func sortPeers(peer map[int][]wire.Address) []map[int]wire.Address { + peerNum := 0 + for i := range peer { + peerNum = len(peer[i]) + } + peerSlice := make([]map[int]wire.Address, peerNum) + for p := 0; p < peerNum; p++ { + peerSlice[p] = GetPeerMapWire(peer, p) + } + return peerSlice +} diff --git a/client/channelconn.go b/client/channelconn.go index ea1e9d5e8..8cdca55f9 100644 --- a/client/channelconn.go +++ b/client/channelconn.go @@ -16,7 +16,6 @@ package client import ( "context" - "github.com/pkg/errors" "golang.org/x/sync/errgroup" @@ -34,7 +33,7 @@ type channelConn struct { pub wire.Publisher // outgoing message publisher r *wire.Relay // update response relay/incoming messages - peers []wire.Address + peers []map[int]wire.Address idx channel.Index // our index log log.Logger @@ -42,7 +41,7 @@ type channelConn struct { // newChannelConn creates a new channel connection for the given channel ID. It // subscribes on the subscriber to all messages regarding this channel. -func newChannelConn(id channel.ID, peers []wire.Address, idx channel.Index, sub wire.Subscriber, pub wire.Publisher) (_ *channelConn, err error) { +func newChannelConn(id channel.ID, peers []map[int]wire.Address, idx channel.Index, sub wire.Subscriber, pub wire.Publisher) (_ *channelConn, err error) { // relay to receive all update responses relay := wire.NewRelay() // we cache all responses for the lifetime of the relay @@ -84,7 +83,7 @@ func newChannelConn(id channel.ID, peers []wire.Address, idx channel.Index, sub }, nil } -func (c *channelConn) sender() wire.Address { +func (c *channelConn) sender() map[int]wire.Address { return c.peers[c.idx] } @@ -119,7 +118,7 @@ func (c *channelConn) Send(ctx context.Context, msg wire.Msg) error { // Peers returns the ordered list of peer addresses. Note that the own peer is // included in the list. -func (c *channelConn) Peers() []wire.Address { +func (c *channelConn) Peers() []map[int]wire.Address { return c.peers } @@ -147,7 +146,7 @@ type ( // with Next(), which returns the peer's channel index and the message. channelMsgRecv struct { *wire.Receiver - peers []wire.Address + peers []map[int]wire.Address log log.Logger } ) @@ -159,7 +158,7 @@ func (r *channelMsgRecv) Next(ctx context.Context) (channel.Index, ChannelMsg, e if err != nil { return 0, nil, err } - idx := wire.IndexOfAddr(r.peers, env.Sender) + idx := wire.IndexOfAddrs(r.peers, env.Sender) if idx == -1 { return 0, nil, errors.Errorf("channel connection received message from unexpected peer %v", env.Sender) } diff --git a/client/client.go b/client/client.go index 0fc28ee82..d4ae3484a 100644 --- a/client/client.go +++ b/client/client.go @@ -35,7 +35,7 @@ import ( // // Currently, only the two-party protocol is fully implemented. type Client struct { - address wire.Address + address map[int]wire.Address conn clientConn channels chanRegistry funder channel.Funder @@ -68,7 +68,7 @@ type Client struct { // // If any argument is nil, New panics. func New( - address wire.Address, + address map[int]wire.Address, bus wire.Bus, funder channel.Funder, adjudicator channel.Adjudicator, @@ -201,7 +201,7 @@ func (c *Client) SetLog(l log.Logger) { c.log = l } -func (c *Client) logPeer(p wire.Address) log.Logger { +func (c *Client) logPeer(p map[int]wire.Address) log.Logger { return c.log.WithField("peer", p) } @@ -220,7 +220,7 @@ func (c *Client) Restore(ctx context.Context) error { var eg errgroup.Group for _, p := range ps { - if p.Equal(c.address) { + if channel.EqualWireMaps(p, c.address) { continue // skip own peer } p := p diff --git a/client/client_internal_test.go b/client/client_internal_test.go index fee1f27a8..0c5a639f3 100644 --- a/client/client_internal_test.go +++ b/client/client_internal_test.go @@ -28,7 +28,7 @@ func TestClient_Channel(t *testing.T) { rng := test.Prng(t) // dummy client that only has an id and a registry c := &Client{ - address: wiretest.NewRandomAddress(rng), + address: wiretest.NewRandomAddressesMap(rng, 1)[0], channels: makeChanRegistry(), } diff --git a/client/client_role_test.go b/client/client_role_test.go index 0af84af4f..4e4c60862 100644 --- a/client/client_role_test.go +++ b/client/client_role_test.go @@ -34,7 +34,7 @@ import ( const ( roleOperationTimeout = 1 * time.Second - twoPartyTestTimeout = 10 * time.Second + twoPartyTestTimeout = 20 * time.Second ) func NewSetups(rng *rand.Rand, names []string) []ctest.RoleSetup { @@ -56,12 +56,12 @@ func NewSetups(rng *rand.Rand, names []string) []ctest.RoleSetup { Name: names[i], Identity: wiretest.NewRandomAccount(rng), Bus: bus, - Funder: backend.NewFunder(acc.Address()), - Adjudicator: backend.NewAdjudicator(acc.Address()), + Funder: backend.NewFunder(acc.Address()[0]), + Adjudicator: backend.NewAdjudicator(acc.Address()[0]), Watcher: watcher, Wallet: w, Timeout: roleOperationTimeout, - BalanceReader: backend.NewBalanceReader(acc.Address()), + BalanceReader: backend.NewBalanceReader(acc.Address()[0]), ChallengeDuration: 60, Errors: make(chan error), } @@ -84,7 +84,7 @@ func runAliceBobTest(ctx context.Context, t *testing.T, setup func(*rand.Rand) ( cfg := &ctest.AliceBobExecConfig{ BaseExecConfig: ctest.MakeBaseExecConfig( - [2]wire.Address{setups[0].Identity.Address(), setups[1].Identity.Address()}, + [2]map[int]wire.Address{setups[0].Identity.Address(), setups[1].Identity.Address()}, chtest.NewRandomAsset(rng), [2]*big.Int{big.NewInt(100), big.NewInt(100)}, app, diff --git a/client/client_test.go b/client/client_test.go index 1e89d0153..343ff73bd 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -43,13 +43,13 @@ func (d DummyBus) Publish(context.Context, *wire.Envelope) error { return errors.New("DummyBus.Publish called") } -func (d DummyBus) SubscribeClient(wire.Consumer, wire.Address) error { +func (d DummyBus) SubscribeClient(wire.Consumer, map[int]wire.Address) error { return nil } func TestClient_New_NilArgs(t *testing.T) { rng := test.Prng(t) - id := wiretest.NewRandomAddress(rng) + id := wiretest.NewRandomAddressesMap(rng, 1)[0] backend := &ctest.MockBackend{} b, f, a, w := &DummyBus{t}, &ctest.MockFunder{}, &ctest.MockAdjudicator{}, wtest.RandomWallet() watcher, err := local.NewWatcher(backend) @@ -67,7 +67,7 @@ func TestClient_Handle_NilArgs(t *testing.T) { backend := &ctest.MockBackend{} watcher, err := local.NewWatcher(backend) require.NoError(t, err, "initializing the watcher should not error") - c, err := client.New(wiretest.NewRandomAddress(rng), + c, err := client.New(wiretest.NewRandomAddressesMap(rng, 1)[0], &DummyBus{t}, &ctest.MockFunder{}, &ctest.MockAdjudicator{}, wtest.RandomWallet(), watcher) require.NoError(t, err) @@ -82,7 +82,7 @@ func TestClient_New(t *testing.T) { backend := &ctest.MockBackend{} watcher, err := local.NewWatcher(backend) require.NoError(t, err, "initializing the watcher should not error") - c, err := client.New(wiretest.NewRandomAddress(rng), + c, err := client.New(wiretest.NewRandomAddressesMap(rng, 1)[0], &DummyBus{t}, &ctest.MockFunder{}, &ctest.MockAdjudicator{}, wtest.RandomWallet(), watcher) assert.NoError(t, err) require.NotNil(t, c) @@ -111,8 +111,8 @@ func TestChannelRejection(t *testing.T) { ) // Create channel proposal. - parts := []wire.Address{alice.Identity.Address(), bob.Identity.Address()} - initAlloc := channel.NewAllocation(len(parts), asset) + parts := []map[int]wire.Address{alice.Identity.Address(), bob.Identity.Address()} + initAlloc := channel.NewAllocation(len(parts), []int{0}, asset) prop, err := client.NewLedgerChannelProposal( challengeDuration, alice.WalletAddress, diff --git a/client/clientconn.go b/client/clientconn.go index 660320e14..5daae446e 100644 --- a/client/clientconn.go +++ b/client/clientconn.go @@ -28,11 +28,11 @@ type clientConn struct { *wire.Relay // Client relay, subscribed to the bus. Embedded for methods Subscribe and Cache. bus wire.Bus reqRecv *wire.Receiver // subscription to incoming requests - sender wire.Address + sender map[int]wire.Address log.Embedding } -func makeClientConn(address wire.Address, bus wire.Bus) (c clientConn, err error) { +func makeClientConn(address map[int]wire.Address, bus wire.Bus) (c clientConn, err error) { c.Embedding = log.MakeEmbedding(log.WithField("id", address)) c.sender = address c.bus = bus @@ -76,7 +76,7 @@ func (c clientConn) nextReq(ctx context.Context) (*wire.Envelope, error) { // pubMsg publishes the given message on the wire bus, setting the own client as // the sender. -func (c *clientConn) pubMsg(ctx context.Context, msg wire.Msg, rec wire.Address) error { +func (c *clientConn) pubMsg(ctx context.Context, msg wire.Msg, rec map[int]wire.Address) error { c.Log().WithField("peer", rec).Debugf("Publishing message: %v: %+v", msg.Type(), msg) return c.bus.Publish(ctx, &wire.Envelope{ Sender: c.sender, diff --git a/client/payment_test.go b/client/payment_test.go index 027693200..817e61a01 100644 --- a/client/payment_test.go +++ b/client/payment_test.go @@ -55,7 +55,7 @@ func TestPaymentDispute(t *testing.T) { cfg := &ctest.MalloryCarolExecConfig{ BaseExecConfig: ctest.MakeBaseExecConfig( - [2]wire.Address{setups[mallory].Identity.Address(), setups[carol].Identity.Address()}, + [2]map[int]wire.Address{setups[mallory].Identity.Address(), setups[carol].Identity.Address()}, chtest.NewRandomAsset(rng), [2]*big.Int{big.NewInt(100), big.NewInt(1)}, client.WithoutApp(), diff --git a/client/proposal.go b/client/proposal.go index 39c524a2c..ad000b8aa 100644 --- a/client/proposal.go +++ b/client/proposal.go @@ -62,7 +62,7 @@ type ( // panic. ProposalResponder struct { client *Client - peer wire.Address + peer map[int]wire.Address req ChannelProposal called atomic.Bool } @@ -128,21 +128,21 @@ func (r *ProposalResponder) Accept(ctx context.Context, acc ChannelProposalAccep } // SetEgoisticChain sets the egoistic chain flag for a given ledger. -func (r *ProposalResponder) SetEgoisticChain(egoistic multi.LedgerID) { +func (r *ProposalResponder) SetEgoisticChain(egoistic multi.AssetID, id int) { mf, ok := r.client.funder.(*multi.Funder) if !ok { log.Panic("unexpected type for funder") } - mf.SetEgoisticChain(egoistic, true) + mf.SetEgoisticChain(egoistic, id, true) } // RemoveEgoisticChain removes the egoistic chain flag for a given ledger. -func (r *ProposalResponder) RemoveEgoisticChain(egoistic multi.LedgerID) { +func (r *ProposalResponder) RemoveEgoisticChain(egoistic multi.AssetID, id int) { mf, ok := r.client.funder.(*multi.Funder) if !ok { log.Panic("unexpected type for funder") } - mf.SetEgoisticChain(egoistic, false) + mf.SetEgoisticChain(egoistic, id, false) } // Reject lets the user signal that they reject the channel proposal. @@ -252,7 +252,7 @@ func (c *Client) cleanupChannelOpening(prop ChannelProposal, ourIdx channel.Inde // The proposer is expected to be the first peer in the participant list. // // This handler is dispatched from the Client.Handle routine. -func (c *Client) handleChannelProposal(handler ProposalHandler, p wire.Address, req ChannelProposal) { +func (c *Client) handleChannelProposal(handler ProposalHandler, p map[int]wire.Address, req ChannelProposal) { ourIdx := channel.Index(ProposeeIdx) // Prepare and cleanup, e.g., for locking and unlocking parent channel. @@ -275,7 +275,7 @@ func (c *Client) handleChannelProposal(handler ProposalHandler, p wire.Address, } func (c *Client) handleChannelProposalAcc( - ctx context.Context, p wire.Address, + ctx context.Context, p map[int]wire.Address, prop ChannelProposal, acc ChannelProposalAccept, ) (ch *Channel, err error) { if err := c.validChannelProposalAcc(prop, acc); err != nil { @@ -301,7 +301,7 @@ func (c *Client) handleChannelProposalAcc( func (c *Client) acceptChannelProposal( ctx context.Context, prop ChannelProposal, - p wire.Address, + p map[int]wire.Address, acc ChannelProposalAccept, ) (*Channel, error) { if acc == nil { @@ -324,7 +324,7 @@ func (c *Client) acceptChannelProposal( } func (c *Client) handleChannelProposalRej( - ctx context.Context, p wire.Address, + ctx context.Context, p map[int]wire.Address, req ChannelProposal, reason string, ) error { msgReject := &ChannelProposalRejMsg{ @@ -405,7 +405,7 @@ func (c *Client) proposeTwoPartyChannel( func (c *Client) validTwoPartyProposal( proposal ChannelProposal, ourIdx channel.Index, - peerAddr wire.Address, + peerAddr map[int]wire.Address, ) error { if err := proposal.Valid(); err != nil { return err @@ -432,12 +432,12 @@ func (c *Client) validTwoPartyProposal( peerIdx := ourIdx ^ 1 // In the 2PCPP, the proposer is expected to have index 0 - if !peers[peerIdx].Equal(peerAddr) { + if !channel.EqualWireMaps(peers[peerIdx], peerAddr) { return errors.Errorf("remote peer doesn't have peer index %d", peerIdx) } // In the 2PCPP, the receiver is expected to have index 1 - if !peers[ourIdx].Equal(c.address) { + if !channel.EqualWireMaps(peers[ourIdx], c.address) { return errors.Errorf("we don't have peer index %d", ourIdx) } @@ -534,8 +534,8 @@ func (c *Client) validChannelProposalAcc( return nil } -func participants(proposer, proposee wallet.Address) []wallet.Address { - parts := make([]wallet.Address, proposalNumParts) +func participants(proposer, proposee map[int]wallet.Address) []map[int]wallet.Address { + parts := make([]map[int]wallet.Address, proposalNumParts) parts[ProposerIdx] = proposer parts[ProposeeIdx] = proposee return parts @@ -590,7 +590,7 @@ func (c *Client) completeCPP( return nil, errors.New("channel already exists") } - account, err := c.wallet.Unlock(params.Parts[partIdx]) + accounts, err := c.wallet.Unlock(params.Parts[partIdx]) if err != nil { return nil, errors.WithMessage(err, "unlocking account") } @@ -601,7 +601,7 @@ func (c *Client) completeCPP( } peers := c.proposalPeers(prop) - ch, err := c.newChannel(account, parent, peers, *params) + ch, err := c.newChannel(accounts, parent, peers, *params) if err != nil { return nil, err } @@ -622,7 +622,7 @@ func (c *Client) completeCPP( return ch, errors.WithMessage(err, "exchanging initial sigs and enabling state") } - c.wallet.IncrementUsage(params.Parts[partIdx]) + c.wallet.IncrementUsage(params.Parts[int(partIdx)]) return ch, nil } @@ -648,7 +648,7 @@ func (c *Client) proposalParent(prop ChannelProposal, partIdx channel.Index) (pa func (c *Client) mpcppParts( prop ChannelProposal, acc ChannelProposalAccept, -) (parts []wallet.Address) { +) (parts []map[int]wallet.Address) { switch p := prop.(type) { case *LedgerChannelProposalMsg: ledgerAcc, ok := acc.(*LedgerChannelProposalAccMsg) @@ -782,7 +782,7 @@ type version1Cache struct { type cachedUpdate struct { uh UpdateHandler - p wire.Address + p map[int]wire.Address m ChannelUpdateProposal } @@ -802,3 +802,19 @@ func newChannelFundingError(err error) *ChannelFundingError { func (e ChannelFundingError) Error() string { return fmt.Sprintf("channel funding failed: %v", e.Err.Error()) } + +func GetPeerMap(peers map[int][]wallet.Address, index int) map[int]wallet.Address { + address := make(map[int]wallet.Address) + for i, p := range peers { + address[i] = p[index] + } + return address +} + +func GetPeerMapWire(peers map[int][]wire.Address, index int) map[int]wire.Address { + address := make(map[int]wire.Address) + for i, p := range peers { + address[i] = p[index] + } + return address +} diff --git a/client/proposal_internal_test.go b/client/proposal_internal_test.go index 981ea8f8f..467140fc2 100644 --- a/client/proposal_internal_test.go +++ b/client/proposal_internal_test.go @@ -35,12 +35,12 @@ func TestClient_validTwoPartyProposal(t *testing.T) { // dummy client that only has an id c := &Client{ - address: wiretest.NewRandomAddress(rng), + address: wiretest.NewRandomAddressesMap(rng, 1)[0], } validProp := NewRandomLedgerChannelProposal(rng, channeltest.WithNumParts(2)) validProp.Peers[0] = c.address // set us as the proposer peerAddr := validProp.Peers[1] // peer at 1 as receiver - require.False(t, peerAddr.Equal(c.address)) + require.False(t, channel.EqualWireMaps(peerAddr, c.address)) require.Len(t, validProp.Peers, 2) validProp3Peers := NewRandomLedgerChannelProposal(rng, channeltest.WithNumParts(3)) @@ -51,7 +51,7 @@ func TestClient_validTwoPartyProposal(t *testing.T) { tests := []struct { prop *LedgerChannelProposalMsg ourIdx channel.Index - peerAddr wire.Address + peerAddr map[int]wire.Address valid bool }{ { @@ -97,7 +97,7 @@ func TestChannelProposal_assertValidNumParts(t *testing.T) { rng := pkgtest.Prng(t) c := NewRandomLedgerChannelProposal(rng) require.NoError(c.assertValidNumParts()) - c.Peers = make([]wire.Address, channel.MaxNumParts+1) + c.Peers = make([]map[int]wire.Address, channel.MaxNumParts+1) require.Error(c.assertValidNumParts()) } @@ -151,10 +151,10 @@ func NewRandomBaseChannelProposal(rng *rand.Rand, opts ...channeltest.RandomOpt) func NewRandomLedgerChannelProposal(rng *rand.Rand, opts ...channeltest.RandomOpt) *LedgerChannelProposalMsg { opt := make(channeltest.RandomOpt).Append(opts...) base := NewRandomBaseChannelProposal(rng, opt) - peers := wiretest.NewRandomAddresses(rng, base.NumPeers()) + peers := wiretest.NewRandomAddressesMap(rng, base.NumPeers()) return &LedgerChannelProposalMsg{ BaseChannelProposal: base, - Participant: wallettest.NewRandomAddress(rng), + Participant: wallettest.NewRandomAddresses(rng), Peers: peers, } } diff --git a/client/proposalmsgs.go b/client/proposalmsgs.go index 6115587ce..90d484a0e 100644 --- a/client/proposalmsgs.go +++ b/client/proposalmsgs.go @@ -114,8 +114,8 @@ type ( // LedgerChannelProposalMsg is a channel proposal for ledger channels. LedgerChannelProposalMsg struct { BaseChannelProposal - Participant wallet.Address // Proposer's address in the channel. - Peers []wire.Address // Participants' wire addresses. + Participant map[int]wallet.Address // Proposer's address in the channel. + Peers []map[int]wire.Address // Participants' wire addresses. } // SubChannelProposalMsg is a channel proposal for subchannels. @@ -127,7 +127,7 @@ type ( // proposalPeers returns the wire addresses of a proposed channel's // participants. -func (c *Client) proposalPeers(p ChannelProposal) (peers []wire.Address) { +func (c *Client) proposalPeers(p ChannelProposal) (peers []map[int]wire.Address) { switch prop := p.(type) { case *LedgerChannelProposalMsg: peers = prop.Peers @@ -230,7 +230,7 @@ func (p *BaseChannelProposal) Valid() error { // Accept constructs an accept message that belongs to a proposal message. It // should be used instead of manually constructing an accept message. func (p LedgerChannelProposalMsg) Accept( - participant wallet.Address, + participant map[int]wallet.Address, nonceShare ProposalOpts, ) *LedgerChannelProposalAccMsg { if !nonceShare.isNonce() { @@ -259,9 +259,9 @@ func (LedgerChannelProposalMsg) Matches(acc ChannelProposalAccept) bool { // For more information, see ProposalOpts. func NewLedgerChannelProposal( challengeDuration uint64, - participant wallet.Address, + participant map[int]wallet.Address, initBals *channel.Allocation, - peers []wire.Address, + peers []map[int]wire.Address, opts ...ProposalOpts, ) (prop *LedgerChannelProposalMsg, err error) { prop = &LedgerChannelProposalMsg{ @@ -287,16 +287,16 @@ func (p LedgerChannelProposalMsg) Encode(w io.Writer) error { } return perunio.Encode(w, p.BaseChannelProposal, - p.Participant, - wire.AddressesWithLen(p.Peers)) + wallet.AddressDecMap(p.Participant), + wire.AddressMapArray(p.Peers)) } // Decode decodes a ledger channel proposal. func (p *LedgerChannelProposalMsg) Decode(r io.Reader) error { err := perunio.Decode(r, &p.BaseChannelProposal, - wallet.AddressDec{Addr: &p.Participant}, - (*wire.AddressesWithLen)(&p.Peers)) + (*wallet.AddressDecMap)(&p.Participant), + (*wire.AddressMapArray)(&p.Peers)) if err != nil { return err } @@ -404,7 +404,7 @@ type ( // each channel instantiation. LedgerChannelProposalAccMsg struct { BaseChannelProposalAcc - Participant wallet.Address // Responder's participant address. + Participant map[int]wallet.Address // Responder's participant address. } // SubChannelProposalAccMsg is the accept message type corresponding to sub @@ -452,14 +452,14 @@ func (acc *LedgerChannelProposalAccMsg) Base() *BaseChannelProposalAcc { func (acc LedgerChannelProposalAccMsg) Encode(w io.Writer) error { return perunio.Encode(w, acc.BaseChannelProposalAcc, - acc.Participant) + wallet.AddressDecMap(acc.Participant)) } // Decode decodes a LedgerChannelProposalAcc from an io.Reader. func (acc *LedgerChannelProposalAccMsg) Decode(r io.Reader) error { return perunio.Decode(r, &acc.BaseChannelProposalAcc, - wallet.AddressDec{Addr: &acc.Participant}) + (*wallet.AddressDecMap)(&acc.Participant)) } // Type returns wire.SubChannelProposalAcc. @@ -517,26 +517,26 @@ type ( // VirtualChannelProposalMsg is a channel proposal for virtual channels. VirtualChannelProposalMsg struct { BaseChannelProposal - Proposer wallet.Address // Proposer's address in the channel. - Peers []wire.Address // Participants' wire addresses. - Parents []channel.ID // Parent channels for each participant. - IndexMaps [][]channel.Index // Index mapping for each participant in relation to the root channel. + Proposer map[int]wallet.Address // Proposer's address in the channel. + Peers []map[int]wire.Address // Participants' wire addresses. + Parents []channel.ID // Parent channels for each participant. + IndexMaps [][]channel.Index // Index mapping for each participant in relation to the root channel. } // VirtualChannelProposalAccMsg is the accept message type corresponding to // virtual channel proposals. VirtualChannelProposalAccMsg struct { BaseChannelProposalAcc - Responder wallet.Address // Responder's participant address. + Responder map[int]wallet.Address // Responder's participant address. } ) // NewVirtualChannelProposal creates a virtual channel proposal. func NewVirtualChannelProposal( challengeDuration uint64, - participant wallet.Address, + participant map[int]wallet.Address, initBals *channel.Allocation, - peers []wire.Address, + peers []map[int]wire.Address, parents []channel.ID, indexMaps [][]channel.Index, opts ...ProposalOpts, @@ -564,8 +564,8 @@ func (p VirtualChannelProposalMsg) Encode(w io.Writer) error { return perunio.Encode( w, p.BaseChannelProposal, - p.Proposer, - wire.AddressesWithLen(p.Peers), + wallet.AddressDecMap(p.Proposer), + wire.AddressMapArray(p.Peers), channelIDsWithLen(p.Parents), indexMapsWithLen(p.IndexMaps), ) @@ -576,8 +576,8 @@ func (p *VirtualChannelProposalMsg) Decode(r io.Reader) error { return perunio.Decode( r, &p.BaseChannelProposal, - wallet.AddressDec{Addr: &p.Proposer}, - (*wire.AddressesWithLen)(&p.Peers), + (*wallet.AddressDecMap)(&p.Proposer), + (*wire.AddressMapArray)(&p.Peers), (*channelIDsWithLen)(&p.Parents), (*indexMapsWithLen)(&p.IndexMaps), ) @@ -590,7 +590,7 @@ func (VirtualChannelProposalMsg) Type() wire.Type { // Accept constructs an accept message that belongs to a proposal message. func (p VirtualChannelProposalMsg) Accept( - responder wallet.Address, + responder map[int]wallet.Address, opts ...ProposalOpts, ) *VirtualChannelProposalAccMsg { _opts := union(opts...) @@ -618,10 +618,10 @@ func (acc *VirtualChannelProposalAccMsg) Base() *BaseChannelProposalAcc { // Encode encodes the message into an io.Writer. func (acc VirtualChannelProposalAccMsg) Encode(w io.Writer) error { - return perunio.Encode(w, acc.BaseChannelProposalAcc, acc.Responder) + return perunio.Encode(w, acc.BaseChannelProposalAcc, wallet.AddressDecMap(acc.Responder)) } // Decode decodes a message from an io.Reader. func (acc *VirtualChannelProposalAccMsg) Decode(r io.Reader) error { - return perunio.Decode(r, &acc.BaseChannelProposalAcc, wallet.AddressDec{Addr: &acc.Responder}) + return perunio.Decode(r, &acc.BaseChannelProposalAcc, (*wallet.AddressDecMap)(&acc.Responder)) } diff --git a/client/restore.go b/client/restore.go index ad50cc2ce..95972b49e 100644 --- a/client/restore.go +++ b/client/restore.go @@ -24,7 +24,7 @@ import ( "perun.network/go-perun/wire" ) -type channelFromSourceSig = func(*Client, *persistence.Channel, *Channel, ...wire.Address) (*Channel, error) +type channelFromSourceSig = func(*Client, *persistence.Channel, *Channel, ...map[int]wire.Address) (*Channel, error) // clientChannelFromSource is the production behaviour of reconstructChannel. // During testing, it is replaced by a simpler function that needs much less @@ -33,9 +33,9 @@ func clientChannelFromSource( c *Client, ch *persistence.Channel, parent *Channel, - peers ...wire.Address, + peers ...map[int]wire.Address, ) (*Channel, error) { - return c.channelFromSource(ch, parent, peers...) + return c.channelFromSource(ch, parent, peers) } func (c *Client) reconstructChannel( @@ -66,7 +66,7 @@ func (c *Client) reconstructChannel( return ch } -func (c *Client) restorePeerChannels(ctx context.Context, p wire.Address) (err error) { +func (c *Client) restorePeerChannels(ctx context.Context, p map[int]wire.Address) (err error) { it, err := c.pr.RestorePeer(p) if err != nil { return errors.WithMessagef(err, "restoring channels for peer: %v", err) diff --git a/client/restore_internal_test.go b/client/restore_internal_test.go index c2b8a723f..4ec201578 100644 --- a/client/restore_internal_test.go +++ b/client/restore_internal_test.go @@ -36,7 +36,7 @@ func patchChFromSource( c *Client, ch *persistence.Channel, parent *Channel, - peers ...wire.Address, + peers ...map[int]wire.Address, ) (*Channel, error) { acc, _ := wallettest.RandomWallet().Unlock(ch.ParamsV.Parts[ch.IdxV]) machine, _ := channel.NewStateMachine(acc, *ch.ParamsV) @@ -109,13 +109,13 @@ func TestRestoreChannelCollection(t *testing.T) { // mkRndChan creates a single random channel. func mkRndChan(rng *rand.Rand) *persistence.Channel { - parts := make([]wallet.Address, channel.MaxNumParts) + parts := make([]map[int]wallet.Address, channel.MaxNumParts) for i := range parts { parts[i] = wallettest.NewRandomAccount(rng).Address() } ch := persistence.NewChannel() ch.IdxV = channel.Index(rng.Intn(channel.MaxNumParts)) - ch.ParamsV = test.NewRandomParams(rng, test.WithParts(parts...)) + ch.ParamsV = test.NewRandomParams(rng, test.WithParts(parts)) sigs := make([]bool, channel.MaxNumParts) opts := test.WithParams(ch.ParamsV) ch.StagingTXV = *test.NewRandomTransaction(rng, sigs, opts) diff --git a/client/subchannel.go b/client/subchannel.go index aced8688d..15e65f7fa 100644 --- a/client/subchannel.go +++ b/client/subchannel.go @@ -39,7 +39,7 @@ func (c *Channel) equalParticipants(_c *Channel) bool { } for i, _a := range a { - if !_a.Equal(b[i]) { + if !channel.EqualWireMaps(_a, b[i]) { return false } } diff --git a/client/subchannel_test.go b/client/subchannel_test.go index 2f07cda0b..93005760e 100644 --- a/client/subchannel_test.go +++ b/client/subchannel_test.go @@ -38,7 +38,7 @@ func TestSubChannelHappy(t *testing.T) { cfg := ctest.NewSusieTimExecConfig( ctest.MakeBaseExecConfig( - [2]wire.Address{setups[0].Identity.Address(), setups[1].Identity.Address()}, + [2]map[int]wire.Address{setups[0].Identity.Address(), setups[1].Identity.Address()}, chtest.NewRandomAsset(rng), [2]*big.Int{big.NewInt(100), big.NewInt(100)}, client.WithoutApp(), @@ -75,7 +75,7 @@ func TestSubChannelDispute(t *testing.T) { } baseCfg := ctest.MakeBaseExecConfig( - [2]wire.Address{setups[0].Identity.Address(), setups[1].Identity.Address()}, + [2]map[int]wire.Address{setups[0].Identity.Address(), setups[1].Identity.Address()}, chtest.NewRandomAsset(rng), [2]*big.Int{big.NewInt(100), big.NewInt(100)}, client.WithoutApp(), diff --git a/client/sync.go b/client/sync.go index efe60e810..205006a04 100644 --- a/client/sync.go +++ b/client/sync.go @@ -32,7 +32,7 @@ var syncReplyTimeout = 10 * time.Second // exists, it just sends the current channel data to the requester. If the // own channel is in the Signing phase, the ongoing update is discarded so that // the channel is reverted to the Acting phase. -func (c *Client) handleSyncMsg(peer wire.Address, msg *ChannelSyncMsg) { +func (c *Client) handleSyncMsg(peer map[int]wire.Address, msg *ChannelSyncMsg) { log := c.logChan(msg.ID()).WithField("peer", peer) ch, ok := c.channels.Channel(msg.ID()) if !ok { @@ -68,7 +68,7 @@ func (c *Client) handleSyncMsg(peer wire.Address, msg *ChannelSyncMsg) { // syncChannel synchronizes the channel state with the given peer and modifies // the current state if required. // nolint:unused -func (c *Client) syncChannel(ctx context.Context, ch *persistence.Channel, p wire.Address) (err error) { +func (c *Client) syncChannel(ctx context.Context, ch *persistence.Channel, p map[int]wire.Address) (err error) { recv := wire.NewReceiver() defer recv.Close() // ignore error id := ch.ID() diff --git a/client/test/backend.go b/client/test/backend.go index 2ea22648e..f3a9e1c5d 100644 --- a/client/test/backend.go +++ b/client/test/backend.go @@ -39,7 +39,7 @@ type ( latestEvents map[channel.ID]channel.AdjudicatorEvent eventSubs map[channel.ID][]*MockSubscription balances map[addressMapKey]map[assetMapKey]*big.Int - id LedgerID + id multi.AssetID } rng interface { @@ -70,12 +70,12 @@ func NewMockBackend(rng *rand.Rand, id string) *MockBackend { latestEvents: make(map[channel.ID]channel.AdjudicatorEvent), eventSubs: make(map[channel.ID][]*MockSubscription), balances: make(map[string]map[string]*big.Int), - id: LedgerID(id), + id: multi.AssetID{0, LedgerID(id)}, } } // ID returns the ledger's identifier. -func (b *MockBackend) ID() LedgerID { +func (b *MockBackend) ID() multi.AssetID { return b.id } @@ -526,7 +526,7 @@ func (f *assetHolder) Fund(req channel.FundingReq, b *MockBackend, acc wallet.Ad for i, asset := range req.State.Assets { ma, ok := asset.(*MultiLedgerAsset) - if ok && ma.LedgerID() != b.ID() { + if ok && ma.AssetID() != b.ID() { continue } diff --git a/client/test/fund.go b/client/test/fund.go index 76a15900d..788585253 100644 --- a/client/test/fund.go +++ b/client/test/fund.go @@ -113,9 +113,9 @@ func runFredFridaTest( ) // Create the proposal. - initAlloc := channel.NewAllocation(numParts, asset) + initAlloc := channel.NewAllocation(numParts, []int{0}, asset) initAlloc.SetAssetBalances(asset, []*big.Int{fridaInitBal, fredInitBal}) - parts := []wire.Address{fridaWireAddr, fredWireAddr} + parts := []map[int]wire.Address{fridaWireAddr, fredWireAddr} prop, err := client.NewLedgerChannelProposal( challengeDuration, fridaWalletAddr, @@ -126,6 +126,7 @@ func runFredFridaTest( // Frida sends the proposal. chFrida, err := frida.ProposeChannel(ctx, prop) + t.Log(err.Error()) require.IsType(t, &client.ChannelFundingError{}, err) require.NotNil(t, chFrida) // Frida settles the channel. diff --git a/client/test/handler.go b/client/test/handler.go index b0813985f..4f25bc318 100644 --- a/client/test/handler.go +++ b/client/test/handler.go @@ -26,7 +26,7 @@ import ( // AlwaysAcceptChannelHandler returns a channel proposal handler that accepts // all channel proposals. -func AlwaysAcceptChannelHandler(ctx context.Context, addr wallet.Address, channels chan *client.Channel, errs chan<- error) client.ProposalHandlerFunc { +func AlwaysAcceptChannelHandler(ctx context.Context, addr map[int]wallet.Address, channels chan *client.Channel, errs chan<- error) client.ProposalHandlerFunc { return func(cp client.ChannelProposal, pr *client.ProposalResponder) { switch cp := cp.(type) { case *client.LedgerChannelProposalMsg: diff --git a/client/test/multiledger.go b/client/test/multiledger.go index bf9ee1cdb..53833f22a 100644 --- a/client/test/multiledger.go +++ b/client/test/multiledger.go @@ -92,12 +92,16 @@ func SetupMultiLedgerTest(t *testing.T) MultiLedgerSetup { // MultiLedgerAsset is a multi-ledger asset. type MultiLedgerAsset struct { - id LedgerID + id multi.AssetID asset channel.Asset } +func (a *MultiLedgerAsset) AssetID() multi.AssetID { + return a.id +} + // NewMultiLedgerAsset returns a new multi-ledger asset. -func NewMultiLedgerAsset(id LedgerID, asset channel.Asset) *MultiLedgerAsset { +func NewMultiLedgerAsset(id multi.AssetID, asset channel.Asset) *MultiLedgerAsset { return &MultiLedgerAsset{ id: id, asset: asset, @@ -111,18 +115,18 @@ func (a *MultiLedgerAsset) Equal(b channel.Asset) bool { return false } - return a.id.MapKey() == bm.id.MapKey() && a.asset.Equal(bm.asset) + return a.id.LedgerId.MapKey() == bm.id.LedgerId.MapKey() && a.asset.Equal(bm.asset) && a.id.BackendID == bm.id.BackendID } // LedgerID returns the asset's ledger ID. -func (a *MultiLedgerAsset) LedgerID() multi.LedgerID { +func (a *MultiLedgerAsset) LedgerID() multi.AssetID { return a.id } // MarshalBinary encodes the asset to its byte representation. func (a *MultiLedgerAsset) MarshalBinary() ([]byte, error) { var buf bytes.Buffer - err := perunio.Encode(&buf, string(a.id), a.asset) + err := perunio.Encode(&buf, string(a.id.LedgerId.MapKey()), a.id.BackendID, a.asset) if err != nil { return nil, err } @@ -133,14 +137,14 @@ func (a *MultiLedgerAsset) MarshalBinary() ([]byte, error) { // UnmarshalBinary decodes the asset from its byte representation. func (a *MultiLedgerAsset) UnmarshalBinary(data []byte) error { buf := bytes.NewBuffer(data) - return perunio.Decode(buf, string(a.id), a.asset) + return perunio.Decode(buf, string(a.id.LedgerId.MapKey()), a.id.BackendID, a.asset) } // MultiLedgerClient represents a test client. type MultiLedgerClient struct { *client.Client - WireAddress wire.Address - WalletAddress wallet.Address + WireAddress map[int]wire.Address + WalletAddress map[int]wallet.Address Events chan channel.AdjudicatorEvent Adjudicator1, Adjudicator2 channel.Adjudicator BalanceReader1, BalanceReader2 BalanceReader @@ -160,7 +164,7 @@ func setupClient( require := require.New(t) // Setup identity. - wireAddr := wiretest.NewRandomAddress(rng) + wireAddr := wiretest.NewRandomAddressesMap(rng, 1) // Setup wallet and account. w := wtest.NewWallet() @@ -168,20 +172,24 @@ func setupClient( // Setup funder. funder := multi.NewFunder() - funder.RegisterFunder(l1.ID(), l1.NewFunder(acc.Address())) - funder.RegisterFunder(l2.ID(), l2.NewFunder(acc.Address())) + for _, add := range acc.Address() { + funder.RegisterFunder(l1.ID(), l1.NewFunder(add)) + funder.RegisterFunder(l2.ID(), l2.NewFunder(add)) + } // Setup adjudicator. adj := multi.NewAdjudicator() - adj.RegisterAdjudicator(l1.ID(), l1.NewAdjudicator(acc.Address())) - adj.RegisterAdjudicator(l2.ID(), l2.NewAdjudicator(acc.Address())) + for _, add := range acc.Address() { + adj.RegisterAdjudicator(l1.ID(), l1.NewAdjudicator(add)) + adj.RegisterAdjudicator(l2.ID(), l2.NewAdjudicator(add)) + } // Setup watcher. watcher, err := local.NewWatcher(adj) require.NoError(err) c, err := client.New( - wireAddr, + wireAddr[0], bus, funder, adj, @@ -192,12 +200,12 @@ func setupClient( return MultiLedgerClient{ Client: c, - WireAddress: wireAddr, + WireAddress: wireAddr[0], WalletAddress: acc.Address(), Events: make(chan channel.AdjudicatorEvent), - Adjudicator1: l1.NewAdjudicator(acc.Address()), - Adjudicator2: l2.NewAdjudicator(acc.Address()), - BalanceReader1: l1.NewBalanceReader(acc.Address()), - BalanceReader2: l2.NewBalanceReader(acc.Address()), + Adjudicator1: l1.NewAdjudicator(acc.Address()[0]), + Adjudicator2: l2.NewAdjudicator(acc.Address()[0]), + BalanceReader1: l1.NewBalanceReader(acc.Address()[0]), + BalanceReader2: l2.NewBalanceReader(acc.Address()[0]), } } diff --git a/client/test/multiledger_dispute.go b/client/test/multiledger_dispute.go index b153f4435..036b69ec4 100644 --- a/client/test/multiledger_dispute.go +++ b/client/test/multiledger_dispute.go @@ -61,8 +61,8 @@ func TestMultiLedgerDispute( // Establish ledger channel between Alice and Bob. // Create channel proposal. - parts := []wire.Address{alice.WireAddress, bob.WireAddress} - initAlloc := channel.NewAllocation(len(parts), mlt.Asset1, mlt.Asset2) + parts := []map[int]wire.Address{alice.WireAddress, bob.WireAddress} + initAlloc := channel.NewAllocation(len(parts), []int{0}, mlt.Asset1, mlt.Asset2) initAlloc.Balances = initBals prop, err := client.NewLedgerChannelProposal( challengeDuration, diff --git a/client/test/multiledger_happy.go b/client/test/multiledger_happy.go index 9ec8c021b..49bd7a8eb 100644 --- a/client/test/multiledger_happy.go +++ b/client/test/multiledger_happy.go @@ -41,8 +41,8 @@ func TestMultiLedgerHappy(ctx context.Context, t *testing.T, mlt MultiLedgerSetu // Establish ledger channel between Alice and Bob. // Create channel proposal. - parts := []wire.Address{alice.WireAddress, bob.WireAddress} - initAlloc := channel.NewAllocation(len(parts), mlt.Asset1, mlt.Asset2) + parts := []map[int]wire.Address{alice.WireAddress, bob.WireAddress} + initAlloc := channel.NewAllocation(len(parts), []int{0}, mlt.Asset1, mlt.Asset2) initAlloc.Balances = initBals prop, err := client.NewLedgerChannelProposal( challengeDuration, diff --git a/client/test/persistence.go b/client/test/persistence.go index d44a12fda..bc46c40cf 100644 --- a/client/test/persistence.go +++ b/client/test/persistence.go @@ -214,11 +214,11 @@ func (r *multiClientRole) Errors() <-chan error { return r.errs } -type addresses []wire.Address +type addresses []map[int]wire.Address -func (a addresses) contains(b wire.Address) bool { +func (a addresses) contains(b map[int]wire.Address) bool { for _, addr := range a { - if addr.Equal(b) { + if channel.EqualWireMaps(addr, b) { return true } } diff --git a/client/test/proposalmsgs.go b/client/test/proposalmsgs.go index c8984807a..40fe150f6 100644 --- a/client/test/proposalmsgs.go +++ b/client/test/proposalmsgs.go @@ -67,7 +67,7 @@ func channelProposalAccSerializationTest(t *testing.T, serializerTest func(t *te t.Run("ledger channel", func(t *testing.T) { for i := 0; i < 16; i++ { proposal := NewRandomLedgerChannelProposal(rng) - m := proposal.Accept(wallettest.NewRandomAddress(rng), client.WithNonceFrom(rng)) + m := proposal.Accept(wallettest.NewRandomAddresses(rng), client.WithNonceFrom(rng)) serializerTest(t, m) } }) @@ -85,7 +85,7 @@ func channelProposalAccSerializationTest(t *testing.T, serializerTest func(t *te var err error proposal, err := NewRandomVirtualChannelProposal(rng) require.NoError(t, err) - m := proposal.Accept(wallettest.NewRandomAddress(rng)) + m := proposal.Accept(wallettest.NewRandomAddresses(rng)) serializerTest(t, m) } }) diff --git a/client/test/randomproposal.go b/client/test/randomproposal.go index be2f67cec..da7d198cd 100644 --- a/client/test/randomproposal.go +++ b/client/test/randomproposal.go @@ -30,18 +30,18 @@ const randomProposalNumParts = 2 // NewRandomLedgerChannelProposal creates a random channel proposal with the supplied // options. Number of participants is fixed to randomProposalNumParts. func NewRandomLedgerChannelProposal(rng *rand.Rand, opts ...client.ProposalOpts) *client.LedgerChannelProposalMsg { - return NewRandomLedgerChannelProposalBy(rng, wallettest.NewRandomAddress(rng), opts...) + return NewRandomLedgerChannelProposalBy(rng, wallettest.NewRandomAddresses(rng), opts...) } // NewRandomLedgerChannelProposalBy creates a random channel proposal with the // supplied options and proposer. Number of participants is fixed to // randomProposalNumParts. -func NewRandomLedgerChannelProposalBy(rng *rand.Rand, proposer wallet.Address, opts ...client.ProposalOpts) *client.LedgerChannelProposalMsg { +func NewRandomLedgerChannelProposalBy(rng *rand.Rand, proposer map[int]wallet.Address, opts ...client.ProposalOpts) *client.LedgerChannelProposalMsg { prop, err := client.NewLedgerChannelProposal( rng.Uint64(), proposer, channeltest.NewRandomAllocation(rng, channeltest.WithNumParts(randomProposalNumParts)), - wiretest.NewRandomAddresses(rng, randomProposalNumParts), + wiretest.NewRandomAddressesMap(rng, randomProposalNumParts), opts...) if err != nil { panic("Error generating random channel proposal: " + err.Error()) @@ -65,9 +65,9 @@ func NewRandomVirtualChannelProposal(rng *rand.Rand, opts ...client.ProposalOpts numParts := 2 return client.NewVirtualChannelProposal( rng.Uint64(), - wallettest.NewRandomAddress(rng), + wallettest.NewRandomAddresses(rng), channeltest.NewRandomAllocation(rng, channeltest.WithNumParts(numParts)), - wiretest.NewRandomAddresses(rng, numParts), + wiretest.NewRandomAddressesMap(rng, numParts), channeltest.NewRandomChannelIDs(rng, numParts), channeltest.NewRandomIndexMaps(rng, numParts, numParts), opts...) diff --git a/client/test/role.go b/client/test/role.go index 211f7bef5..db570696c 100644 --- a/client/test/role.go +++ b/client/test/role.go @@ -85,18 +85,18 @@ type ( // ExecConfig contains additional config parameters for the tests. ExecConfig interface { - Peers() [2]wire.Address // must match the RoleSetup.Identity's - Asset() channel.Asset // single Asset to use in this channel - InitBals() [2]*big.Int // channel deposit of each role - App() client.ProposalOpts // must be either WithApp or WithoutApp + Peers() [2]map[int]wire.Address // must match the RoleSetup.Identity's + Asset() channel.Asset // single Asset to use in this channel + InitBals() [2]*big.Int // channel deposit of each role + App() client.ProposalOpts // must be either WithApp or WithoutApp } // BaseExecConfig contains base config parameters. BaseExecConfig struct { - peers [2]wire.Address // must match the RoleSetup.Identity's - asset channel.Asset // single Asset to use in this channel - initBals [2]*big.Int // channel deposit of each role - app client.ProposalOpts // must be either WithApp or WithoutApp + peers [2]map[int]wire.Address // must match the RoleSetup.Identity's + asset channel.Asset // single Asset to use in this channel + initBals [2]*big.Int // channel deposit of each role + app client.ProposalOpts // must be either WithApp or WithoutApp } // An Executer is a Role that can execute a protocol. @@ -118,7 +118,7 @@ type ( Client struct { *client.Client RoleSetup - WalletAddress wallet.Address + WalletAddress map[int]wallet.Address } ) @@ -174,7 +174,7 @@ func ExecuteTwoPartyTest(ctx context.Context, t *testing.T, role [2]Executer, cf // MakeBaseExecConfig creates a new BaseExecConfig. func MakeBaseExecConfig( - peers [2]wire.Address, + peers [2]map[int]wire.Address, asset channel.Asset, initBals [2]*big.Int, app client.ProposalOpts, @@ -188,7 +188,7 @@ func MakeBaseExecConfig( } // Peers returns the peer addresses. -func (c *BaseExecConfig) Peers() [2]wire.Address { +func (c *BaseExecConfig) Peers() [2]map[int]wire.Address { return c.peers } @@ -297,10 +297,10 @@ func (r *role) waitStage() { // Idxs maps the passed addresses to the indices in the 2-party-channel. If the // setup's Identity is not found in peers, Idxs panics. -func (r *role) Idxs(peers [2]wire.Address) (our, their channel.Index) { - if r.setup.Identity.Address().Equal(peers[0]) { +func (r *role) Idxs(peers [2]map[int]wire.Address) (our, their channel.Index) { + if channel.EqualWireMaps(r.setup.Identity.Address(), peers[0]) { return 0, 1 - } else if r.setup.Identity.Address().Equal(peers[1]) { + } else if channel.EqualWireMaps(r.setup.Identity.Address(), peers[1]) { return 1, 0 } panic("identity not in peers") @@ -397,7 +397,7 @@ func (r *role) LedgerChannelProposal(rng *rand.Rand, cfg ExecConfig) *client.Led } peers, asset, bals := cfg.Peers(), cfg.Asset(), cfg.InitBals() - alloc := channel.NewAllocation(len(peers), asset) + alloc := channel.NewAllocation(len(peers), []int{0}, asset) alloc.SetAssetBalances(asset, bals[:]) prop, err := client.NewLedgerChannelProposal( diff --git a/client/test/virtualchannel.go b/client/test/virtualchannel.go index 5d1449160..121774dbc 100644 --- a/client/test/virtualchannel.go +++ b/client/test/virtualchannel.go @@ -217,8 +217,8 @@ func setupVirtualChannelTest( go ingrid.Client.Handle(openingProposalHandlerIngrid, updateProposalHandlerIngrid) // Establish ledger channel between Alice and Ingrid. - peersAlice := []wire.Address{alice.Identity.Address(), ingrid.Identity.Address()} - initAllocAlice := channel.NewAllocation(len(peersAlice), asset) + peersAlice := []map[int]wire.Address{alice.Identity.Address(), ingrid.Identity.Address()} + initAllocAlice := channel.NewAllocation(len(peersAlice), []int{0}, asset) initAllocAlice.SetAssetBalances(asset, vct.initBalsAlice) lcpAlice, err := client.NewLedgerChannelProposal( setup.ChallengeDuration, @@ -237,8 +237,8 @@ func setupVirtualChannelTest( } // Establish ledger channel between Bob and Ingrid. - peersBob := []wire.Address{bob.Identity.Address(), ingrid.Identity.Address()} - initAllocBob := channel.NewAllocation(len(peersBob), asset) + peersBob := []map[int]wire.Address{bob.Identity.Address(), ingrid.Identity.Address()} + initAllocBob := channel.NewAllocation(len(peersBob), []int{0}, asset) initAllocBob.SetAssetBalances(asset, vct.initBalsBob) lcpBob, err := client.NewLedgerChannelProposal( setup.ChallengeDuration, @@ -293,7 +293,7 @@ func setupVirtualChannelTest( setup.ChallengeDuration, alice.WalletAddress, &initAllocVirtual, - []wire.Address{alice.Identity.Address(), bob.Identity.Address()}, + []map[int]wire.Address{alice.Identity.Address(), bob.Identity.Address()}, []channel.ID{vct.chAliceIngrid.ID(), vct.chBobIngrid.ID()}, [][]channel.Index{indexMapAlice, indexMapBob}, ) diff --git a/client/update.go b/client/update.go index 363b84c0f..e848b5e42 100644 --- a/client/update.go +++ b/client/update.go @@ -33,7 +33,7 @@ import ( // is unknown, an error is logged. // // This handler is dispatched from the Client.Handle routine. -func (c *Client) handleChannelUpdate(uh UpdateHandler, p wire.Address, m ChannelUpdateProposal) { +func (c *Client) handleChannelUpdate(uh UpdateHandler, p map[int]wire.Address, m ChannelUpdateProposal) { ch, ok := c.channels.Channel(m.Base().ID()) if !ok { if !c.cacheVersion1Update(uh, p, m) { @@ -45,7 +45,7 @@ func (c *Client) handleChannelUpdate(uh UpdateHandler, p wire.Address, m Channel ch.handleUpdateReq(pidx, m, uh) //nolint:contextcheck } -func (c *Client) cacheVersion1Update(uh UpdateHandler, p wire.Address, m ChannelUpdateProposal) bool { +func (c *Client) cacheVersion1Update(uh UpdateHandler, p map[int]wire.Address, m ChannelUpdateProposal) bool { c.version1Cache.mu.Lock() defer c.version1Cache.mu.Unlock() diff --git a/client/updatemsgs.go b/client/updatemsgs.go index 6a06f3250..8631c8a3c 100644 --- a/client/updatemsgs.go +++ b/client/updatemsgs.go @@ -255,7 +255,7 @@ func (m *VirtualChannelFundingProposalMsg) Decode(r io.Reader) (err error) { } m.Initial.Sigs = make([]wallet.Sig, m.Initial.State.NumParts()) - return wallet.DecodeSparseSigs(r, &m.Initial.Sigs) + return wallet.DecodeSparseSigs(r, &m.Initial.Sigs, m.Initial.State.Allocation.Backends) } // Type returns the message type. @@ -293,5 +293,5 @@ func (m *VirtualChannelSettlementProposalMsg) Decode(r io.Reader) (err error) { } m.Final.Sigs = make([]wallet.Sig, m.Final.State.NumParts()) - return wallet.DecodeSparseSigs(r, &m.Final.Sigs) + return wallet.DecodeSparseSigs(r, &m.Final.Sigs, m.Final.State.Allocation.Backends) } diff --git a/client/virtual_channel.go b/client/virtual_channel.go index c903fc88f..18d19be3c 100644 --- a/client/virtual_channel.go +++ b/client/virtual_channel.go @@ -150,10 +150,10 @@ func (c *Channel) watchVirtual() error { // dummyAcount represents an address but cannot be used for signing. type dummyAccount struct { - address wallet.Address + address map[int]wallet.Address } -func (a *dummyAccount) Address() wallet.Address { +func (a *dummyAccount) Address() map[int]wallet.Address { return a.address } @@ -163,7 +163,7 @@ func (a *dummyAccount) SignData([]byte) ([]byte, error) { const hubIndex = 0 // The hub's index in a virtual channel machine. -func (c *Client) persistVirtualChannel(ctx context.Context, parent *Channel, peers []wire.Address, params channel.Params, state channel.State, sigs []wallet.Sig) (*Channel, error) { +func (c *Client) persistVirtualChannel(ctx context.Context, parent *Channel, peers []map[int]wire.Address, params channel.Params, state channel.State, sigs []wallet.Sig) (*Channel, error) { cID := params.ID() if _, err := c.Channel(cID); err == nil { return nil, errors.New("channel already exists") @@ -379,8 +379,8 @@ func (c *Client) gatherChannels(props ...*VirtualChannelFundingProposalMsg) ([]* return channels, nil } -func (c *Client) gatherPeers(channels ...*Channel) (peers []wire.Address) { - peers = make([]wire.Address, len(channels)) +func (c *Client) gatherPeers(channels ...*Channel) (peers []map[int]wire.Address) { + peers = make([]map[int]wire.Address, len(channels)) for i, ch := range channels { chPeers := ch.Peers() if len(chPeers) != gatherNumPeers { diff --git a/go.mod b/go.mod index 18373cc42..f92b466e0 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module perun.network/go-perun -go 1.17 +go 1.18 require ( github.com/pkg/errors v0.9.1 diff --git a/wallet/account.go b/wallet/account.go index 2785bf55d..d1863f57a 100644 --- a/wallet/account.go +++ b/wallet/account.go @@ -17,7 +17,7 @@ package wallet // Account represents a single account. type Account interface { // Address used by this account. - Address() Address + Address() map[int]Address // SignData requests a signature from this account. // It returns the signature or an error. diff --git a/wallet/address.go b/wallet/address.go index ec89873e1..8beeb9ae6 100644 --- a/wallet/address.go +++ b/wallet/address.go @@ -17,6 +17,7 @@ package wallet import ( "bytes" "encoding" + "encoding/binary" "fmt" stdio "io" "strings" @@ -42,14 +43,18 @@ type Address interface { // Equal returns wether the two addresses are equal. The implementation // must be equivalent to checking `Address.Cmp(Address) == 0`. Equal(Address) bool + // BackendID returns the id of the backend that created this address. + BackendID() int } // IndexOfAddr returns the index of the given address in the address slice, // or -1 if it is not part of the slice. -func IndexOfAddr(addrs []Address, addr Address) int { - for i, a := range addrs { - if addr.Equal(a) { - return i +func IndexOfAddr(addrs []map[int]Address, addr map[int]Address) int { + for i, as := range addrs { + for j, a := range as { + if a.Equal(addr[j]) { + return i + } } } @@ -64,7 +69,7 @@ func CloneAddress(a Address) Address { log.WithError(err).Panic("error binary-marshaling Address") } - clone := NewAddress() + clone := NewAddress(a.BackendID()) if err := clone.UnmarshalBinary(data); err != nil { log.WithError(err).Panic("error binary-unmarshaling Address") } @@ -82,103 +87,154 @@ func CloneAddresses(as []Address) []Address { return clones } -// Addresses is a helper type for encoding and decoding address slices in -// situations where the length of the slice is known. -type Addresses []Address - -// AddressesWithLen is a helper type for encoding and decoding address slices -// of unknown length. -type AddressesWithLen []Address - -// addressSliceLen is needed to break the import cycle with channel. It should -// be the same as channel.Index. -type addressSliceLen = uint16 +// CloneAddressesMap returns a clone of a map of Addresses using their binary +// marshaling implementation. It panics if an error occurs during binary +// (un)marshaling. +func CloneAddressesMap(as map[int]Address) map[int]Address { + clones := make(map[int]Address) + for i, a := range as { + clones[i] = CloneAddress(a) + } + return clones +} -// AddressDec is a helper type to decode single wallet addresses. -type AddressDec struct { - Addr *Address +// AddressMapArray is a helper type for encoding and decoding arrays of address maps. +type AddressMapArray struct { + Addr []map[int]Address } +// AddressDecMap is a helper type for encoding and decoding address maps. +type AddressDecMap map[int]Address + // AddrKey is a non-human readable representation of an `Address`. // It can be compared and therefore used as a key in a map. -type AddrKey string +type AddrKey struct { + key string +} -// Encode encodes a wallet address slice, the length of which is known to the -// following decode operation. -func (a Addresses) Encode(w stdio.Writer) error { +// Encode encodes first the length of the map, +// then all Addresses and their key in the map. +func (a AddressDecMap) Encode(w stdio.Writer) error { + length := int32(len(a)) + if err := perunio.Encode(w, length); err != nil { + return errors.WithMessage(err, "encoding map length") + } for i, addr := range a { + if err := perunio.Encode(w, int32(i)); err != nil { + return errors.WithMessage(err, "encoding map index") + } if err := perunio.Encode(w, addr); err != nil { - return errors.WithMessagef(err, "encoding %d-th address", i) + return errors.WithMessagef(err, "encoding %d-th address map entry", i) } } - return nil } -// Encode encodes a wallet address slice, the length of which is unknown to the -// following decode operation. -func (a AddressesWithLen) Encode(w stdio.Writer) error { - return perunio.Encode(w, - addressSliceLen(len(a)), - (Addresses)(a)) -} - -// Decode decodes a wallet address slice of known length. The slice has to be -// allocated to the correct size already. -func (a Addresses) Decode(r stdio.Reader) (err error) { - for i := range a { - a[i] = NewAddress() - err = perunio.Decode(r, a[i]) - if err != nil { - return errors.WithMessagef(err, "decoding %d-th address", i) +// Encode encodes first the length of the array, +// then all AddressDecMaps in the array. +func (a AddressMapArray) Encode(w stdio.Writer) error { + length := int32(len(a.Addr)) + if err := perunio.Encode(w, length); err != nil { + return errors.WithMessage(err, "encoding array length") + } + for i, addr := range a.Addr { + if err := perunio.Encode(w, (*AddressDecMap)(&addr)); err != nil { + return errors.WithMessagef(err, "encoding %d-th address array entry", i) } } return nil } -// Decode decodes a wallet address slice of unknown length. -func (a *AddressesWithLen) Decode(r stdio.Reader) (err error) { - var parts addressSliceLen - if err = perunio.Decode(r, &parts); err != nil { - return errors.WithMessage(err, "decoding count") +// Decode decodes the map length first, then all Addresses and their key in the map. +func (a *AddressDecMap) Decode(r stdio.Reader) (err error) { + var mapLen int32 + if err := perunio.Decode(r, &mapLen); err != nil { + return errors.WithMessage(err, "decoding map length") } - - *a = make(AddressesWithLen, parts) - return (*Addresses)(a).Decode(r) + *a = make(map[int]Address, mapLen) + for i := 0; i < int(mapLen); i++ { + var idx int32 + if err := perunio.Decode(r, &idx); err != nil { + return errors.WithMessage(err, "decoding map index") + } + addr := NewAddress(int(idx)) + if err := perunio.Decode(r, addr); err != nil { + return errors.WithMessagef(err, "decoding %d-th address map entry", i) + } + (*a)[int(idx)] = addr + } + return nil } -// Decode decodes a single wallet address. -func (a AddressDec) Decode(r stdio.Reader) (err error) { - *a.Addr = NewAddress() - err = perunio.Decode(r, *a.Addr) - return err +// Decode decodes the array length first, then all AddressDecMaps in the array. +func (a *AddressMapArray) Decode(r stdio.Reader) (err error) { + var mapLen int32 + if err := perunio.Decode(r, &mapLen); err != nil { + return errors.WithMessage(err, "decoding array length") + } + a.Addr = make([]map[int]Address, mapLen) + for i := 0; i < int(mapLen); i++ { + if err := perunio.Decode(r, (*AddressDecMap)(&a.Addr[i])); err != nil { + return errors.WithMessagef(err, "decoding %d-th address map entry", i) + } + } + return nil } -// Key returns the `AddrKey` corresponding to the passed `Address`. +// Key returns the `AddrKey` corresponding to the passed `map[int]Address`. // The `Address` can be retrieved with `FromKey`. -// Panics when the `Address` can't be encoded. -func Key(a Address) AddrKey { +// Returns an error if the `map[int]Address` can't be encoded. +func Key(a map[int]Address) AddrKey { var buff strings.Builder - if err := perunio.Encode(&buff, a); err != nil { - panic("Could not encode address in AddrKey: " + err.Error()) + // Encode the number of elements in the map first. + length := int32(len(a)) // Using int32 to encode the length + err := binary.Write(&buff, binary.BigEndian, length) + if err != nil { + log.Panic("could not encode map length in Key: ", err) + + } + // Iterate over the map and encode each key-value pair. + for id, addr := range a { + if err := binary.Write(&buff, binary.BigEndian, int32(id)); err != nil { + log.Panicf("could not encode map length in AddrKey: " + err.Error()) + } + if err := perunio.Encode(&buff, addr); err != nil { + log.Panicf("could not encode map[int]Address in AddrKey: " + err.Error()) + } } - return AddrKey(buff.String()) + return AddrKey{buff.String()} } -// FromKey returns the `Address` corresponding to the passed `AddrKey` +// FromKey returns the `map[int]Address` corresponding to the passed `AddrKey` // created by `Key`. -// Panics when the `Address` can't be decoded. -func FromKey(k AddrKey) Address { - a := NewAddress() - err := perunio.Decode(bytes.NewBuffer([]byte(k)), a) - if err != nil { - panic("Could not decode address in FromKey: " + err.Error()) +// Returns an error if the `map[int]Address` can't be decoded. +func FromKey(k AddrKey) map[int]Address { + buff := bytes.NewBuffer([]byte(k.key)) + var numElements int32 + + // Manually decode the number of elements in the map. + if err := binary.Read(buff, binary.BigEndian, &numElements); err != nil { + log.Panicf("could not decode map length in FromKey: " + err.Error()) + } + a := make(map[int]Address, numElements) + // Decode each key-value pair and insert them into the map. + for i := 0; i < int(numElements); i++ { + var id int32 + if err := binary.Read(buff, binary.BigEndian, &id); err != nil { + log.Panicf("could not decode map length in FromKey: " + err.Error()) + } + addr := NewAddress(int(id)) + if err := perunio.Decode(buff, addr); err != nil { + log.Panicf("could not decode map[int]Address in FromKey: " + err.Error()) + } + a[int(id)] = addr } return a } // Equal Returns whether the passed `Address` has the same key as the // receiving `AddrKey`. -func (k AddrKey) Equal(a Address) bool { - return k == Key(a) +func (k AddrKey) Equal(a map[int]Address) bool { + key := Key(a) + return k == key } diff --git a/wallet/address_test.go b/wallet/address_test.go index afb536e1d..8e7c5aa35 100644 --- a/wallet/address_test.go +++ b/wallet/address_test.go @@ -28,7 +28,7 @@ import ( ) type testAddresses struct { - addrs wallet.AddressesWithLen + addrs wallet.AddressMapArray } func (t *testAddresses) Encode(w io.Writer) error { @@ -39,22 +39,36 @@ func (t *testAddresses) Decode(r io.Reader) error { return t.addrs.Decode(r) } +type testAddress struct { + addrs wallet.AddressDecMap +} + +func (t *testAddress) Encode(w io.Writer) error { + return t.addrs.Encode(w) +} + +func (t *testAddress) Decode(r io.Reader) error { + return t.addrs.Decode(r) +} + func TestAddresses_Serializer(t *testing.T) { rng := pkgtest.Prng(t) + addr := wallettest.NewRandomAddressesMap(rng, 1)[0] + peruniotest.GenericSerializerTest(t, &testAddress{addrs: addr}) - addrs := wallettest.NewRandomAddresses(rng, 0) - peruniotest.GenericSerializerTest(t, &testAddresses{addrs}) + addrs := wallettest.NewRandomAddressesMap(rng, 0) + peruniotest.GenericSerializerTest(t, &testAddresses{addrs: wallet.AddressMapArray{Addr: addrs}}) - addrs = wallettest.NewRandomAddresses(rng, 1) - peruniotest.GenericSerializerTest(t, &testAddresses{addrs}) + addrs = wallettest.NewRandomAddressesMap(rng, 1) + peruniotest.GenericSerializerTest(t, &testAddresses{addrs: wallet.AddressMapArray{addrs}}) - addrs = wallettest.NewRandomAddresses(rng, 5) - peruniotest.GenericSerializerTest(t, &testAddresses{addrs}) + addrs = wallettest.NewRandomAddressesMap(rng, 5) + peruniotest.GenericSerializerTest(t, &testAddresses{addrs: wallet.AddressMapArray{addrs}}) } func TestAddrKey_Equal(t *testing.T) { rng := pkgtest.Prng(t) - addrs := wallettest.NewRandomAddresses(rng, 10) + addrs := wallettest.NewRandomAddressesMap(rng, 10) // Test all properties of an equivalence relation. for i, a := range addrs { @@ -79,13 +93,13 @@ func TestAddrKey_Equal(t *testing.T) { func TestAddrKey(t *testing.T) { rng := pkgtest.Prng(t) - addrs := wallettest.NewRandomAddresses(rng, 10) + addrs := wallettest.NewRandomAddressesMap(rng, 10) for _, a := range addrs { // Test that Key and FromKey are dual to each other. require.Equal(t, wallet.Key(a), wallet.Key(wallet.FromKey(wallet.Key(a)))) // Test that FromKey returns the correct Address. - require.True(t, a.Equal(wallet.FromKey(wallet.Key(a)))) + require.True(t, EqualWalletMaps(a, wallet.FromKey(wallet.Key(a)))) } } @@ -99,7 +113,7 @@ func TestCloneAddress(t *testing.T) { func TestCloneAddresses(t *testing.T) { rng := pkgtest.Prng(t) - addrs := wallettest.NewRandomAddresses(rng, 3) + addrs := wallettest.NewRandomAddressArray(rng, 3) addrs0 := wallet.CloneAddresses(addrs) require.Equal(t, addrs, addrs0) require.NotSame(t, addrs, addrs0) @@ -107,3 +121,15 @@ func TestCloneAddresses(t *testing.T) { require.NotSame(t, a, addrs0[i]) } } + +func EqualWalletMaps(a, b map[int]wallet.Address) bool { + if len(a) != len(b) { + return false + } + for i, addr := range a { + if !addr.Equal(b[i]) { + return false + } + } + return true +} diff --git a/wallet/backend.go b/wallet/backend.go index 43565fc78..aaba189fe 100644 --- a/wallet/backend.go +++ b/wallet/backend.go @@ -15,12 +15,13 @@ package wallet import ( + "errors" "io" ) // backend is set to the global wallet backend. Must not be set directly but // through importing the needed backend. -var backend Backend +var backend map[int]Backend // Backend provides useful methods for this blockchain. type Backend interface { @@ -40,25 +41,53 @@ type Backend interface { // SetBackend sets the global wallet backend. Must not be called directly but // through importing the needed backend. -func SetBackend(b Backend) { - if backend != nil { +func SetBackend(b Backend, id int) { + if backend == nil { + backend = make(map[int]Backend) + + } + if backend[id] != nil { panic("wallet backend already set") } - backend = b + backend[id] = b } // NewAddress returns a variable of type Address, which can be used // for unmarshalling an address from its binary representation. -func NewAddress() Address { - return backend.NewAddress() +func NewAddress(id int) Address { + return backend[id].NewAddress() } -// DecodeSig calls DecodeSig of the current backend. +// DecodeSig calls DecodeSig of all Backends and returns an error if none return a valid signature. func DecodeSig(r io.Reader) (Sig, error) { - return backend.DecodeSig(r) + var errs []error + for _, b := range backend { + sig, err := b.DecodeSig(r) + if err == nil { + return sig, nil + } else { + errs = append(errs, err) + } + } + + if len(errs) > 0 { + // Join all errors into a single error message. + return nil, errors.Join(errs...) + } + + return nil, errors.New("no valid signature found") } // VerifySignature calls VerifySignature of the current backend. -func VerifySignature(msg []byte, sign Sig, a Address) (bool, error) { - return backend.VerifySignature(msg, sign, a) +func VerifySignature(msg []byte, sign Sig, a map[int]Address) (bool, error) { + var errs []error + for _, addr := range a { + v, err := backend[addr.BackendID()].VerifySignature(msg, sign, addr) + if err == nil && v { + return v, nil + } else { + errs = append(errs, err) + } + } + return false, errors.Join(errs...) } diff --git a/wallet/sig.go b/wallet/sig.go index 98a0375ec..30b7859a0 100644 --- a/wallet/sig.go +++ b/wallet/sig.go @@ -47,7 +47,8 @@ const bitsPerByte = 8 // SigDec is a helper type to decode signatures. type SigDec struct { - Sig *Sig + Sig *Sig + BackendID int } // Decode decodes a single signature. @@ -83,7 +84,7 @@ func EncodeSparseSigs(w io.Writer, sigs []Sig) error { } // DecodeSparseSigs decodes a collection of signatures in the form (mask, sig, sig, sig, ...). -func DecodeSparseSigs(r io.Reader, sigs *[]Sig) (err error) { +func DecodeSparseSigs(r io.Reader, sigs *[]Sig, backendIDs []int) (err error) { masklen := int(math.Ceil(float64(len(*sigs)) / float64(bitsPerByte))) mask := make([]uint8, masklen) diff --git a/wallet/test/randomizer.go b/wallet/test/randomizer.go index 4171d120b..a43232856 100644 --- a/wallet/test/randomizer.go +++ b/wallet/test/randomizer.go @@ -67,6 +67,12 @@ func NewRandomAddress(rng *rand.Rand) wallet.Address { return randomizer.NewRandomAddress(rng) } +// NewRandomAddressMap returns a new random address by calling the currently set +// wallet randomizer. +func NewRandomAddresses(rng *rand.Rand) map[int]wallet.Address { + return map[int]wallet.Address{0: randomizer.NewRandomAddress(rng)} +} + // RandomWallet returns the randomizer backend's wallet. All accounts created // with NewRandomAccount can be found in this wallet. func RandomWallet() Wallet { @@ -89,9 +95,9 @@ func NewWallet() Wallet { // NewRandomAccounts returns a slice of new random accounts // by calling NewRandomAccount. -func NewRandomAccounts(rng *rand.Rand, n int) ([]wallet.Account, []wallet.Address) { +func NewRandomAccounts(rng *rand.Rand, n int) ([]wallet.Account, []map[int]wallet.Address) { accs := make([]wallet.Account, n) - addrs := make([]wallet.Address, n) + addrs := make([]map[int]wallet.Address, n) for i := range accs { accs[i] = NewRandomAccount(rng) addrs[i] = accs[i].Address() @@ -99,11 +105,34 @@ func NewRandomAccounts(rng *rand.Rand, n int) ([]wallet.Account, []wallet.Addres return accs, addrs } +// NewRandomAccounts returns a slice of new random accounts +// by calling NewRandomAccount. +func NewRandomAccountsMap(rng *rand.Rand, n int) (map[int][]wallet.Account, []map[int]wallet.Address) { + accs := make([]wallet.Account, n) + mapAccs := make(map[int][]wallet.Account) + mapAddrs := make([]map[int]wallet.Address, n) + for i := range accs { + accs[i] = NewRandomAccount(rng) + } + mapAccs[0] = accs + mapAddrs[0] = accs[0].Address() + return mapAccs, mapAddrs +} + // NewRandomAddresses returns a slice of new random addresses. -func NewRandomAddresses(rng *rand.Rand, n int) []wallet.Address { +func NewRandomAddressArray(rng *rand.Rand, n int) []wallet.Address { addrs := make([]wallet.Address, n) for i := range addrs { addrs[i] = NewRandomAddress(rng) } return addrs } + +// NewRandomAddresses returns a slice of new random addresses. +func NewRandomAddressesMap(rng *rand.Rand, n int) []map[int]wallet.Address { + addrs := make([]map[int]wallet.Address, n) + for i := range addrs { + addrs[i] = NewRandomAddresses(rng) + } + return addrs +} diff --git a/wallet/test/wallet.go b/wallet/test/wallet.go index 83d469076..5b764698a 100644 --- a/wallet/test/wallet.go +++ b/wallet/test/wallet.go @@ -32,12 +32,12 @@ type UnlockedAccount func() (wallet.Account, error) // Setup provides all objects needed for the generic tests. type Setup struct { - Backend wallet.Backend // backend implementation - Wallet wallet.Wallet // the wallet instance used for testing - AddressInWallet wallet.Address // an address of an account in the test wallet - ZeroAddress wallet.Address // an address that is less or equal to any other address - DataToSign []byte // some data to sign - AddressMarshalled []byte // a valid nonzero address not in the wallet + Backend wallet.Backend // backend implementation + Wallet wallet.Wallet // the wallet instance used for testing + AddressInWallet map[int]wallet.Address // an address of an account in the test wallet + ZeroAddress wallet.Address // an address that is less or equal to any other address + DataToSign []byte // some data to sign + AddressMarshalled []byte // a valid nonzero address not in the wallet } // TestAccountWithWalletAndBackend tests an account implementation together with @@ -49,7 +49,7 @@ func TestAccountWithWalletAndBackend(t *testing.T, s *Setup) { //nolint:revive / // Check unlocked account sig, err := acc.SignData(s.DataToSign) assert.NoError(t, err, "Sign with unlocked account should succeed") - valid, err := s.Backend.VerifySignature(s.DataToSign, sig, acc.Address()) + valid, err := s.Backend.VerifySignature(s.DataToSign, sig, acc.Address()[0]) assert.True(t, valid, "Verification should succeed") assert.NoError(t, err, "Verification should not produce error") @@ -64,20 +64,20 @@ func TestAccountWithWalletAndBackend(t *testing.T, s *Setup) { //nolint:revive / copy(tampered, sig) // Invalidate the signature and check for error tampered[0] = ^sig[0] - valid, err = s.Backend.VerifySignature(s.DataToSign, tampered, acc.Address()) + valid, err = s.Backend.VerifySignature(s.DataToSign, tampered, acc.Address()[0]) if valid && err == nil { t.Error("Verification of invalid signature should produce error or return false") } // Truncate the signature and check for error tampered = sig[:len(sig)-1] - valid, err = s.Backend.VerifySignature(s.DataToSign, tampered, acc.Address()) + valid, err = s.Backend.VerifySignature(s.DataToSign, tampered, acc.Address()[0]) if valid && err != nil { t.Error("Verification of invalid signature should produce error or return false") } // Expand the signature and check for error //nolint:gocritic tampered = append(sig, 0) - valid, err = s.Backend.VerifySignature(s.DataToSign, tampered, acc.Address()) + valid, err = s.Backend.VerifySignature(s.DataToSign, tampered, acc.Address()[0]) if valid && err != nil { t.Error("Verification of invalid signature should produce error or return false") } diff --git a/wallet/test/walletbench.go b/wallet/test/walletbench.go index 5ba272bae..5c8c6882e 100644 --- a/wallet/test/walletbench.go +++ b/wallet/test/walletbench.go @@ -53,7 +53,7 @@ func GenericBackendBenchmark(b *testing.B, s *Setup) { func benchBackendVerifySig(b *testing.B, s *Setup) { b.Helper() - // We dont want to measure the SignDataWithPW here, just need it for the verification + // We do not want to measure the SignDataWithPW here, just need it for the verification b.StopTimer() perunAcc, err := s.Wallet.Unlock(s.AddressInWallet) require.NoError(b, err) @@ -62,7 +62,7 @@ func benchBackendVerifySig(b *testing.B, s *Setup) { b.StartTimer() for n := 0; n < b.N; n++ { - ok, err := s.Backend.VerifySignature(s.DataToSign, signature, perunAcc.Address()) + ok, err := s.Backend.VerifySignature(s.DataToSign, signature, perunAcc.Address()[0]) if !ok { b.Fatal(err) diff --git a/wallet/wallet.go b/wallet/wallet.go index 621598749..a630025fb 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -24,7 +24,7 @@ type Wallet interface { // LockAll has been called, or a matching count of IncrementUsage and // DecrementUsage calls on the account's address has been made. Unlock may // be called multiple times for the same Address by the Perun SDK. - Unlock(Address) (Account, error) + Unlock(map[int]Address) (Account, error) // LockAll is called by the framework when a Client shuts down. This should // release all temporary resources held by the wallet, and accesses to @@ -36,7 +36,7 @@ type Wallet interface { // The address passed to the function belongs to the Account the Client is // using to participate in the channel. Implementing this function with any // behavior is not essential. - IncrementUsage(Address) + IncrementUsage(map[int]Address) // DecrementUsage is called whenever a channel is settled. The address // passed to the function belongs to the Account the Client is using to @@ -46,5 +46,5 @@ type Wallet interface { // the wallet implementation. In that event, the affected account does not // have to be able to sign messages anymore. Implementing this function with // any behavior is not essential. - DecrementUsage(Address) + DecrementUsage(map[int]Address) } diff --git a/wire/account.go b/wire/account.go index d8e2dc908..98955077d 100644 --- a/wire/account.go +++ b/wire/account.go @@ -32,7 +32,7 @@ func init() { // authenticity within the Perun peer-to-peer network. type Account interface { // Address used by this account. - Address() Address + Address() map[int]Address // Sign signs the given message with this account's private key. Sign(msg []byte) ([]byte, error) @@ -81,9 +81,15 @@ func (m *AuthResponseMsg) Decode(r io.Reader) (err error) { // NewAuthResponseMsg creates an authentication response message. func NewAuthResponseMsg(acc Account) (Msg, error) { - addressBytes, err := acc.Address().MarshalBinary() - if err != nil { - return nil, fmt.Errorf("failed to marshal address: %w", err) + addressMap := acc.Address() + var addressBytes []byte + addressBytes = append(addressBytes, byte(len(addressMap))) + for _, addr := range addressMap { + addrBytes, err := addr.MarshalBinary() + if err != nil { + return nil, fmt.Errorf("failed to marshal address: %w", err) + } + addressBytes = append(addressBytes, addrBytes...) } signature, err := acc.Sign(addressBytes) if err != nil { diff --git a/wire/address.go b/wire/address.go index de48ab1ec..8028ebd80 100644 --- a/wire/address.go +++ b/wire/address.go @@ -24,8 +24,8 @@ import ( ) var ( - _ perunio.Serializer = (*Addresses)(nil) - _ perunio.Serializer = (*AddressesWithLen)(nil) + _ perunio.Serializer = (*AddressDecMap)(nil) + _ perunio.Serializer = (*AddressMapArray)(nil) ) // Address is a Perun node's network address, which is used as a permanent @@ -46,55 +46,80 @@ type Address interface { Verify(msg []byte, sig []byte) error } -// Addresses is a helper type for encoding and decoding address slices in -// situations where the length of the slice is known. -type Addresses []Address +// AddressMapArray is a helper type for encoding and decoding address maps. +type AddressMapArray []map[int]Address -// AddressesWithLen is a helper type for encoding and decoding address slices -// of unknown length. -type AddressesWithLen []Address +// AddressDecMap is a helper type for encoding and decoding arrays of address maps. +type AddressDecMap map[int]Address -type addressSliceLen = uint16 - -// Encode encodes wire addresses. -func (a Addresses) Encode(w stdio.Writer) error { +// Encode encodes first the length of the map, +// then all Addresses and their key in the map. +func (a AddressDecMap) Encode(w stdio.Writer) error { + length := int32(len(a)) // Using int32 to encode the length + if err := perunio.Encode(w, length); err != nil { + return errors.WithMessage(err, "encoding map length") + } for i, addr := range a { + if err := perunio.Encode(w, int32(i)); err != nil { + return errors.WithMessage(err, "encoding map index") + } if err := perunio.Encode(w, addr); err != nil { - return errors.WithMessagef(err, "encoding %d-th address", i) + return errors.WithMessagef(err, "encoding %d-th address map entry", i) } } - return nil } -// Encode encodes wire addresses with length. -func (a AddressesWithLen) Encode(w stdio.Writer) error { - return perunio.Encode(w, - addressSliceLen(len(a)), - (Addresses)(a)) +// Encode encodes first the length of the array, +// then all AddressDecMaps in the array. +func (a AddressMapArray) Encode(w stdio.Writer) error { + length := int32(len(a)) // Using int32 to encode the length + if err := perunio.Encode(w, length); err != nil { + return errors.WithMessage(err, "encoding array length") + } + for i, addr := range a { + if err := perunio.Encode(w, AddressDecMap(addr)); err != nil { + return errors.WithMessagef(err, "encoding %d-th address array entry", i) + } + } + return nil } -// Decode decodes wallet addresses. -func (a Addresses) Decode(r stdio.Reader) error { - for i := range a { - a[i] = NewAddress() - err := perunio.Decode(r, a[i]) - if err != nil { - return errors.WithMessagef(err, "decoding %d-th address", i) +// Decode decodes the map length first, then all Addresses and their key in the map. +func (a *AddressDecMap) Decode(r stdio.Reader) (err error) { + var mapLen int32 + if err := perunio.Decode(r, &mapLen); err != nil { + return errors.WithMessage(err, "decoding map length") + } + *a = make(map[int]Address, mapLen) + for i := 0; i < int(mapLen); i++ { + var idx int32 + if err := perunio.Decode(r, &idx); err != nil { + return errors.WithMessage(err, "decoding map index") + } + addr := NewAddress() + if err := perunio.Decode(r, addr); err != nil { + return errors.WithMessagef(err, "decoding %d-th address map entry", i) } + (*a)[int(idx)] = addr } return nil } -// Decode decodes a wallet address slice of unknown length. -func (a *AddressesWithLen) Decode(r stdio.Reader) error { - var n addressSliceLen - if err := perunio.Decode(r, &n); err != nil { - return errors.WithMessage(err, "decoding count") +// Decode decodes the array length first, then all AddressDecMaps in the array. +// Decode decodes the array length first, then all AddressDecMaps in the array. +func (a *AddressMapArray) Decode(r stdio.Reader) (err error) { + var mapLen int32 + if err := perunio.Decode(r, &mapLen); err != nil { + return errors.WithMessage(err, "decoding array length") } - - *a = make(AddressesWithLen, n) - return (*Addresses)(a).Decode(r) + *a = make([]map[int]Address, mapLen) + for i := 0; i < int(mapLen); i++ { + if err := perunio.Decode(r, (*AddressDecMap)(&(*a)[i])); err != nil { + return errors.WithMessagef(err, "decoding %d-th address map entry", i) + } + } + return nil } // IndexOfAddr returns the index of the given address in the address slice, @@ -109,6 +134,30 @@ func IndexOfAddr(addrs []Address, addr Address) int { return -1 } +// IndexOfAddr returns the index of the given address in the address slice, +// or -1 if it is not part of the slice. +func IndexOfAddrs(addrs []map[int]Address, addr map[int]Address) int { + for i, a := range addrs { + if addrEqual(a, addr) { + return i + } + } + + return -1 +} + +func addrEqual(a, b map[int]Address) bool { + if len(a) != len(b) { + return false + } + for i, addr := range a { + if !addr.Equal(b[i]) { + return false + } + } + return true +} + // AddrKey is a non-human readable representation of an `Address`. // It can be compared and therefore used as a key in a map. type AddrKey string @@ -123,3 +172,13 @@ func Key(a Address) AddrKey { } return AddrKey(buff.String()) } + +// Keys returns the `AddrKey` corresponding to the passed `map[int]Address`. +func Keys(addressMap map[int]Address) AddrKey { + var keyParts []string + for _, addr := range addressMap { + key := Key(addr) + keyParts = append(keyParts, string(key)) // Assuming Address has a String() method. + } + return AddrKey(strings.Join(keyParts, "|")) +} diff --git a/wire/bus.go b/wire/bus.go index e19c4cb2a..c4967248e 100644 --- a/wire/bus.go +++ b/wire/bus.go @@ -22,5 +22,5 @@ type Bus interface { // SubscribeClient should route all messages with clientAddr as recipient to // the provided Consumer. Every address may only be subscribed to once. - SubscribeClient(c Consumer, clientAddr Address) error + SubscribeClient(c Consumer, clientAddr map[int]Address) error } diff --git a/wire/encode.go b/wire/encode.go index eec724d2b..9327e89e9 100644 --- a/wire/encode.go +++ b/wire/encode.go @@ -35,8 +35,8 @@ type ( // An Envelope encapsulates a message with routing information, that is, the // sender and intended recipient. Envelope struct { - Sender Address // Sender of the message. - Recipient Address // Recipient of the message. + Sender map[int]Address // Sender of the message. + Recipient map[int]Address // Recipient of the message. // Msg contained in this Envelope. Not embedded so Envelope doesn't implement Msg. Msg Msg } diff --git a/wire/hybridbus.go b/wire/hybridbus.go index 18569860b..4c1e63687 100644 --- a/wire/hybridbus.go +++ b/wire/hybridbus.go @@ -88,7 +88,7 @@ func (b *hybridBus) Publish(ctx context.Context, e *Envelope) error { } // SubscribeClient subscribes an envelope consumer to all sub-buses. -func (b *hybridBus) SubscribeClient(c Consumer, receiver Address) error { +func (b *hybridBus) SubscribeClient(c Consumer, receiver map[int]Address) error { errg := errors.NewGatherer() for _, bus := range b.buses { errg.Add(bus.SubscribeClient(c, receiver)) diff --git a/wire/localbus.go b/wire/localbus.go index 499c24c41..d08592fd2 100644 --- a/wire/localbus.go +++ b/wire/localbus.go @@ -58,7 +58,7 @@ func (h *LocalBus) Publish(ctx context.Context, e *Envelope) error { // SubscribeClient implements wire.Bus.SubscribeClient. There can only be one // subscription per receiver address. // When the Consumer closes, its subscription is removed. -func (h *LocalBus) SubscribeClient(c Consumer, receiver Address) error { +func (h *LocalBus) SubscribeClient(c Consumer, receiver map[int]Address) error { recv := h.ensureRecv(receiver) recv.recv = c close(recv.exists) @@ -66,7 +66,7 @@ func (h *LocalBus) SubscribeClient(c Consumer, receiver Address) error { c.OnCloseAlways(func() { h.mutex.Lock() defer h.mutex.Unlock() - delete(h.recvs, Key(receiver)) + delete(h.recvs, Keys(receiver)) log.WithField("id", receiver).Debug("Client unsubscribed.") }) @@ -77,8 +77,8 @@ func (h *LocalBus) SubscribeClient(c Consumer, receiver Address) error { // ensureRecv ensures that there is an entry for a recipient address in the // bus' receiver map, and returns it. If it creates a new receiver, it is only // a placeholder until a subscription appears. -func (h *LocalBus) ensureRecv(a Address) *localBusReceiver { - key := Key(a) +func (h *LocalBus) ensureRecv(a map[int]Address) *localBusReceiver { + key := Keys(a) // First, we only use a read lock, hoping that the receiver already exists. h.mutex.RLock() recv, ok := h.recvs[key] diff --git a/wire/net/bus.go b/wire/net/bus.go index 90161aad0..015ed756d 100644 --- a/wire/net/bus.go +++ b/wire/net/bus.go @@ -50,7 +50,7 @@ func NewBus(id wire.Account, d Dialer, s wire.EnvelopeSerializer) *Bus { recvs: make(map[wire.AddrKey]wire.Consumer), } - onNewEndpoint := func(wire.Address) wire.Consumer { return b.mainRecv } + onNewEndpoint := func(map[int]wire.Address) wire.Consumer { return b.mainRecv } b.reg = NewEndpointRegistry(id, onNewEndpoint, d, s) go b.dispatchMsgs() @@ -65,7 +65,7 @@ func (b *Bus) Listen(l Listener) { // SubscribeClient subscribes a new client to the bus. Duplicate subscriptions // are forbidden and will cause a panic. The supplied consumer will receive all // messages that are sent to the requested address. -func (b *Bus) SubscribeClient(c wire.Consumer, addr wire.Address) error { +func (b *Bus) SubscribeClient(c wire.Consumer, addr map[int]wire.Address) error { b.addSubscriber(c, addr) c.OnCloseAlways(func() { b.removeSubscriber(addr) }) return nil @@ -114,15 +114,15 @@ func (b *Bus) Close() error { return b.reg.Close() } -func (b *Bus) addSubscriber(c wire.Consumer, addr wire.Address) { +func (b *Bus) addSubscriber(c wire.Consumer, addr map[int]wire.Address) { b.mutex.Lock() defer b.mutex.Unlock() - if _, ok := b.recvs[wire.Key(addr)]; ok { + if _, ok := b.recvs[wire.Keys(addr)]; ok { log.Panic("duplicate SubscribeClient") } - b.recvs[wire.Key(addr)] = c + b.recvs[wire.Keys(addr)] = c } // ctx returns the context of the bus' registry. @@ -140,7 +140,7 @@ func (b *Bus) dispatchMsgs() { } b.mutex.Lock() - r, ok := b.recvs[wire.Key(e.Recipient)] + r, ok := b.recvs[wire.Keys(e.Recipient)] b.mutex.Unlock() if !ok { log.WithField("sender", e.Sender). @@ -152,13 +152,13 @@ func (b *Bus) dispatchMsgs() { } } -func (b *Bus) removeSubscriber(addr wire.Address) { +func (b *Bus) removeSubscriber(addr map[int]wire.Address) { b.mutex.Lock() defer b.mutex.Unlock() - if _, ok := b.recvs[wire.Key(addr)]; !ok { + if _, ok := b.recvs[wire.Keys(addr)]; !ok { log.Panic("deleting nonexisting subscriber") } - delete(b.recvs, wire.Key(addr)) + delete(b.recvs, wire.Keys(addr)) } diff --git a/wire/net/dialer.go b/wire/net/dialer.go index 967fc48ca..0f3640e46 100644 --- a/wire/net/dialer.go +++ b/wire/net/dialer.go @@ -31,7 +31,7 @@ type Dialer interface { // // Dial needs to be reentrant, and concurrent calls to Close() must abort // any ongoing Dial() calls. - Dial(ctx context.Context, addr wire.Address, ser wire.EnvelopeSerializer) (Conn, error) + Dial(ctx context.Context, addr map[int]wire.Address, ser wire.EnvelopeSerializer) (Conn, error) // Close aborts any ongoing calls to Dial(). // // Close() needs to be reentrant, and repeated calls to Close() need to diff --git a/wire/net/endpoint.go b/wire/net/endpoint.go index 5b0b5d8b1..95034ebf6 100644 --- a/wire/net/endpoint.go +++ b/wire/net/endpoint.go @@ -34,8 +34,8 @@ import ( // Sending messages to a node is done via the Send() method. To receive messages // from an Endpoint, use the Receiver helper type (by subscribing). type Endpoint struct { - Address wire.Address // The Endpoint's Perun address. - conn Conn // The Endpoint's connection. + Address map[int]wire.Address // The Endpoint's Perun address. + conn Conn // The Endpoint's connection. sending sync.Mutex // Blocks multiple Send calls. } @@ -96,7 +96,7 @@ func (p *Endpoint) Close() (err error) { } // newEndpoint creates a new Endpoint from a wire Address and connection. -func newEndpoint(addr wire.Address, conn Conn) *Endpoint { +func newEndpoint(addr map[int]wire.Address, conn Conn) *Endpoint { return &Endpoint{ Address: addr, conn: conn, diff --git a/wire/net/endpoint_internal_test.go b/wire/net/endpoint_internal_test.go index d1ca3f691..a1eca3514 100644 --- a/wire/net/endpoint_internal_test.go +++ b/wire/net/endpoint_internal_test.go @@ -17,6 +17,7 @@ package net import ( "context" "math/rand" + "perun.network/go-perun/channel" "sync" "testing" "time" @@ -53,7 +54,7 @@ func makeSetup(rng *rand.Rand) *setup { } // Dial simulates creating a connection to a. -func (s *setup) Dial(ctx context.Context, addr wire.Address, _ wire.EnvelopeSerializer) (Conn, error) { +func (s *setup) Dial(ctx context.Context, addr map[int]wire.Address, _ wire.EnvelopeSerializer) (Conn, error) { s.mutex.RLock() defer s.mutex.RUnlock() @@ -65,10 +66,10 @@ func (s *setup) Dial(ctx context.Context, addr wire.Address, _ wire.EnvelopeSeri a, b := newPipeConnPair() //nolint:gocritic - if addr.Equal(s.alice.endpoint.Address) { // Dialing Bob? + if channel.EqualWireMaps(addr, s.alice.endpoint.Address) { // Dialing Bob? s.bob.Registry.addEndpoint(s.bob.endpoint.Address, b, true) // Bob accepts connection. return a, nil - } else if addr.Equal(s.bob.endpoint.Address) { // Dialing Alice? + } else if channel.EqualWireMaps(addr, s.bob.endpoint.Address) { // Dialing Alice? s.alice.Registry.addEndpoint(s.alice.endpoint.Address, a, true) // Alice accepts connection. return b, nil } else { @@ -97,7 +98,7 @@ type client struct { // makeClient creates a simulated test client. func makeClient(conn Conn, rng *rand.Rand, dialer Dialer) *client { receiver := wire.NewReceiver() - registry := NewEndpointRegistry(wiretest.NewRandomAccount(rng), func(wire.Address) wire.Consumer { + registry := NewEndpointRegistry(wiretest.NewRandomAccount(rng), func(map[int]wire.Address) wire.Consumer { return receiver }, dialer, perunio.Serializer()) diff --git a/wire/net/endpoint_registry.go b/wire/net/endpoint_registry.go index 149edf1b3..03d13d85f 100644 --- a/wire/net/endpoint_registry.go +++ b/wire/net/endpoint_registry.go @@ -16,6 +16,7 @@ package net import ( "context" + "perun.network/go-perun/channel/persistence/test" "sync" "sync/atomic" "time" @@ -31,9 +32,9 @@ import ( // dialingEndpoint is an endpoint that is being dialed, but has no connection // associated with it yet. type dialingEndpoint struct { - Address wire.Address // The Endpoint's address. - created chan struct{} // Triggered when the Endpoint is created. - createdAt *Endpoint // Contains the finished Endpoint when it exists. + Address map[int]wire.Address // The Endpoint's address. + created chan struct{} // Triggered when the Endpoint is created. + createdAt *Endpoint // Contains the finished Endpoint when it exists. } // fullEndpoint describes an endpoint that is held within the registry. @@ -51,7 +52,7 @@ func newFullEndpoint(e *Endpoint) *fullEndpoint { } } -func newDialingEndpoint(addr wire.Address) *dialingEndpoint { +func newDialingEndpoint(addr map[int]wire.Address) *dialingEndpoint { return &dialingEndpoint{ Address: addr, created: make(chan struct{}), @@ -63,9 +64,9 @@ func newDialingEndpoint(addr wire.Address) *dialingEndpoint { // connections. It should not be used manually, but only internally by a // wire.Bus. type EndpointRegistry struct { - id wire.Account // The identity of the node. - dialer Dialer // Used for dialing peers. - onNewEndpoint func(wire.Address) wire.Consumer // Selects Consumer for new Endpoints' receive loop. + id wire.Account // The identity of the node. + dialer Dialer // Used for dialing peers. + onNewEndpoint func(map[int]wire.Address) wire.Consumer // Selects Consumer for new Endpoints' receive loop. ser wire.EnvelopeSerializer endpoints map[wire.AddrKey]*fullEndpoint // The list of all of all established Endpoints. @@ -83,7 +84,7 @@ const exchangeAddrsTimeout = 10 * time.Second // called before the peer starts receiving messages. func NewEndpointRegistry( id wire.Account, - onNewEndpoint func(wire.Address) wire.Consumer, + onNewEndpoint func(map[int]wire.Address) wire.Consumer, dialer Dialer, ser wire.EnvelopeSerializer, ) *EndpointRegistry { @@ -167,7 +168,7 @@ func (r *EndpointRegistry) setupConn(conn Conn) error { ctx, cancel := context.WithTimeout(r.Ctx(), exchangeAddrsTimeout) defer cancel() - var peerAddr wire.Address + var peerAddr map[int]wire.Address var err error if peerAddr, err = ExchangeAddrsPassive(ctx, r.id, conn); err != nil { conn.Close() @@ -175,7 +176,7 @@ func (r *EndpointRegistry) setupConn(conn Conn) error { return err } - if peerAddr.Equal(r.id.Address()) { + if test.EqualWireMaps(peerAddr, r.id.Address()) { r.Log().Error("dialed by self") return errors.New("dialed by self") } @@ -187,11 +188,11 @@ func (r *EndpointRegistry) setupConn(conn Conn) error { // Endpoint looks up an Endpoint via its perun address. If the Endpoint does not // exist yet, it is dialed. Does not return until the peer is dialed or the // context is closed. -func (r *EndpointRegistry) Endpoint(ctx context.Context, addr wire.Address) (*Endpoint, error) { +func (r *EndpointRegistry) Endpoint(ctx context.Context, addr map[int]wire.Address) (*Endpoint, error) { log := r.Log().WithField("peer", addr) - key := wire.Key(addr) + key := wire.Keys(addr) - if addr.Equal(r.id.Address()) { + if test.EqualWireMaps(addr, r.id.Address()) { log.Panic("tried to dial self") } @@ -217,11 +218,11 @@ func (r *EndpointRegistry) Endpoint(ctx context.Context, addr wire.Address) (*En func (r *EndpointRegistry) authenticatedDial( ctx context.Context, - addr wire.Address, + addr map[int]wire.Address, de *dialingEndpoint, created bool, ) (ret *Endpoint, _ error) { - key := wire.Key(addr) + key := wire.Keys(addr) // Short cut: another dial for that peer is already in progress. if !created { @@ -261,8 +262,8 @@ func (r *EndpointRegistry) authenticatedDial( } // dialingEndpoint retrieves or creates a dialingEndpoint for the passed address. -func (r *EndpointRegistry) dialingEndpoint(a wire.Address) (_ *dialingEndpoint, created bool) { - key := wire.Key(a) +func (r *EndpointRegistry) dialingEndpoint(a map[int]wire.Address) (_ *dialingEndpoint, created bool) { + key := wire.Keys(a) entry, ok := r.dialing[key] if !ok { entry = newDialingEndpoint(a) @@ -283,17 +284,17 @@ func (r *EndpointRegistry) NumPeers() int { // Has return true if and only if there is a peer with the given address in the // registry. The function does not differentiate between regular and // placeholder peers. -func (r *EndpointRegistry) Has(addr wire.Address) bool { +func (r *EndpointRegistry) Has(addr map[int]wire.Address) bool { r.mutex.Lock() defer r.mutex.Unlock() - _, ok := r.endpoints[wire.Key(addr)] + _, ok := r.endpoints[wire.Keys(addr)] return ok } // addEndpoint adds a new peer to the registry. -func (r *EndpointRegistry) addEndpoint(addr wire.Address, conn Conn, dialer bool) *Endpoint { +func (r *EndpointRegistry) addEndpoint(addr map[int]wire.Address, conn Conn, dialer bool) *Endpoint { r.Log().WithField("peer", addr).Trace("EndpointRegistry.addEndpoint") e := newEndpoint(addr, conn) @@ -317,8 +318,8 @@ func (r *EndpointRegistry) addEndpoint(addr wire.Address, conn Conn, dialer bool } // fullEndpoint retrieves or creates a fullEndpoint for the passed address. -func (r *EndpointRegistry) fullEndpoint(addr wire.Address, e *Endpoint) (_ *fullEndpoint, created bool) { - key := wire.Key(addr) +func (r *EndpointRegistry) fullEndpoint(addr map[int]wire.Address, e *Endpoint) (_ *fullEndpoint, created bool) { + key := wire.Keys(addr) r.mutex.Lock() defer r.mutex.Unlock() entry, ok := r.endpoints[key] @@ -332,7 +333,7 @@ func (r *EndpointRegistry) fullEndpoint(addr wire.Address, e *Endpoint) (_ *full // replace sets a new endpoint and resolves ties when both parties dial each // other concurrently. It returns the endpoint that is selected after potential // tie resolving, and whether the supplied endpoint was closed in the process. -func (p *fullEndpoint) replace(newValue *Endpoint, self wire.Address, dialer bool) (updated *Endpoint, closed bool) { +func (p *fullEndpoint) replace(newValue *Endpoint, self map[int]wire.Address, dialer bool) (updated *Endpoint, closed bool) { // If there was no previous endpoint, just set the new one. wasNil := atomic.CompareAndSwapPointer(&p.endpoint, nil, unsafe.Pointer(newValue)) if wasNil { @@ -344,11 +345,24 @@ func (p *fullEndpoint) replace(newValue *Endpoint, self wire.Address, dialer boo // close on both sides. Close the endpoint that is created by the dialer // with the lesser Perun address and return the previously existing // endpoint. - if dialer == (self.Cmp(newValue.Address) < 0) { - if err := newValue.Close(); err != nil { - log.Warn("newValue dialer already closed") + for key, selfAddr := range self { + // Check if the same key exists in newValue.Address + newAddr, exists := newValue.Address[key] + + // If the key does not exist in newValue.Address, you might skip it or handle it + if !exists { + continue // or handle this scenario according to your requirements + } + + // Compare the addresses + if dialer == (selfAddr.Cmp(newAddr) < 0) { + // If selfAddr is "lesser", close the new value + if err := newValue.Close(); err != nil { + log.Warn("newValue dialer already closed") + } + // Return the existing endpoint associated with this key + return p.Endpoint(), true } - return p.Endpoint(), true } // Otherwise, install the new endpoint and close the old endpoint. @@ -369,10 +383,10 @@ func (p *fullEndpoint) delete(expectedOldValue *Endpoint) { atomic.CompareAndSwapPointer(&p.endpoint, unsafe.Pointer(expectedOldValue), nil) } -func (r *EndpointRegistry) find(addr wire.Address) *Endpoint { +func (r *EndpointRegistry) find(addr map[int]wire.Address) *Endpoint { r.mutex.RLock() defer r.mutex.RUnlock() - if e, ok := r.endpoints[wire.Key(addr)]; ok { + if e, ok := r.endpoints[wire.Keys(addr)]; ok { return e.Endpoint() } return nil diff --git a/wire/net/endpoint_registry_external_test.go b/wire/net/endpoint_registry_external_test.go index 486ade7e5..18a5ee8e6 100644 --- a/wire/net/endpoint_registry_external_test.go +++ b/wire/net/endpoint_registry_external_test.go @@ -16,6 +16,7 @@ package net_test import ( "context" + "perun.network/go-perun/channel" "testing" "time" @@ -34,7 +35,7 @@ import ( var timeout = 100 * time.Millisecond -func nilConsumer(wire.Address) wire.Consumer { return nil } +func nilConsumer(map[int]wire.Address) wire.Consumer { return nil } // Two nodes (1 dialer, 1 listener node) .Get() each other. func TestEndpointRegistry_Get_Pair(t *testing.T) { @@ -59,14 +60,14 @@ func TestEndpointRegistry_Get_Pair(t *testing.T) { p, err := dialerReg.Endpoint(ctx, listenerID.Address()) assert.NoError(err) require.NotNil(p) - assert.True(p.Address.Equal(listenerID.Address())) + assert.True(channel.EqualWireMaps(p.Address, listenerID.Address())) // should allow the listener routine to add the peer to its registry time.Sleep(timeout) p, err = listenerReg.Endpoint(ctx, dialerID.Address()) assert.NoError(err) require.NotNil(p) - assert.True(p.Address.Equal(dialerID.Address())) + assert.True(channel.EqualWireMaps(p.Address, dialerID.Address())) listenerReg.Close() dialerReg.Close() @@ -85,8 +86,8 @@ func TestEndpointRegistry_Get_Multiple(t *testing.T) { dialerID := wiretest.NewRandomAccount(rng) listenerID := wiretest.NewRandomAccount(rng) dialer := hub.NewNetDialer() - logPeer := func(addr wire.Address) wire.Consumer { - t.Logf("subscribing %s\n", addr) + logPeer := func(addr map[int]wire.Address) wire.Consumer { + t.Logf("subscribing %s\n", wire.Keys(addr)) return nil } dialerReg := net.NewEndpointRegistry(dialerID, logPeer, dialer, perunio.Serializer()) @@ -109,7 +110,7 @@ func TestEndpointRegistry_Get_Multiple(t *testing.T) { p, err := dialerReg.Endpoint(ctx, listenerID.Address()) assert.NoError(err) if p != nil { - assert.True(p.Address.Equal(listenerID.Address())) + assert.True(channel.EqualWireMaps(p.Address, listenerID.Address())) } peers <- p }() @@ -138,7 +139,7 @@ func TestEndpointRegistry_Get_Multiple(t *testing.T) { p, err := listenerReg.Endpoint(ctx, dialerID.Address()) assert.NoError(err) assert.NotNil(p) - assert.True(p.Address.Equal(dialerID.Address())) + assert.True(channel.EqualWireMaps(p.Address, dialerID.Address())) assert.Equal(1, listener.NumAccepted()) listenerReg.Close() diff --git a/wire/net/endpoint_registry_internal_test.go b/wire/net/endpoint_registry_internal_test.go index 34160e1e6..66edb80f3 100644 --- a/wire/net/endpoint_registry_internal_test.go +++ b/wire/net/endpoint_registry_internal_test.go @@ -51,7 +51,7 @@ func (d *mockDialer) Close() error { return nil } -func (d *mockDialer) Dial(ctx context.Context, addr wire.Address, _ wire.EnvelopeSerializer) (Conn, error) { +func (d *mockDialer) Dial(ctx context.Context, addr map[int]wire.Address, _ wire.EnvelopeSerializer) (Conn, error) { d.mutex.Lock() defer d.mutex.Unlock() @@ -104,7 +104,7 @@ func newMockListener() *mockListener { return &mockListener{dialer: mockDialer{dial: make(chan Conn)}} } -func nilConsumer(wire.Address) wire.Consumer { return nil } +func nilConsumer(map[int]wire.Address) wire.Consumer { return nil } // TestRegistry_Get tests that when calling Get(), existing peers are returned, // and when unknown peers are requested, a temporary peer is create that is @@ -125,7 +125,7 @@ func TestRegistry_Get(t *testing.T) { r := NewEndpointRegistry(id, nilConsumer, dialer, perunio.Serializer()) existing := newEndpoint(peerAddr, newMockConn()) - r.endpoints[wire.Key(peerAddr)] = newFullEndpoint(existing) + r.endpoints[wire.Keys(peerAddr)] = newFullEndpoint(existing) ctxtest.AssertTerminates(t, timeout, func() { p, err := r.Endpoint(context.Background(), peerAddr) assert.NoError(t, err) @@ -366,7 +366,7 @@ func TestRegistry_addEndpoint_Subscribe(t *testing.T) { called := false r := NewEndpointRegistry( wiretest.NewRandomAccount(rng), - func(wire.Address) wire.Consumer { called = true; return nil }, + func(map[int]wire.Address) wire.Consumer { called = true; return nil }, nil, perunio.Serializer(), ) diff --git a/wire/net/exchange_addr.go b/wire/net/exchange_addr.go index 658052f0d..0b382334a 100644 --- a/wire/net/exchange_addr.go +++ b/wire/net/exchange_addr.go @@ -17,6 +17,7 @@ package net import ( "context" "fmt" + "perun.network/go-perun/channel/persistence/test" "github.com/pkg/errors" @@ -27,11 +28,11 @@ import ( // AuthenticationError describes an error which occures when the ExchangeAddrs // protcol fails because it got a different Address than expected. type AuthenticationError struct { - Sender, Receiver, Own wire.Address + Sender, Receiver, Own map[int]wire.Address } // NewAuthenticationError creates a new AuthenticationError. -func NewAuthenticationError(sender, receiver, own wire.Address, msg string) error { +func NewAuthenticationError(sender, receiver, own map[int]wire.Address, msg string) error { return errors.Wrap(&AuthenticationError{ Sender: sender, Receiver: receiver, @@ -56,7 +57,7 @@ func IsAuthenticationError(err error) bool { // In the future, it will be extended to become a proper authentication // protocol. The protocol will then exchange Perun addresses and establish // authenticity. -func ExchangeAddrsActive(ctx context.Context, id wire.Account, peer wire.Address, conn Conn) error { +func ExchangeAddrsActive(ctx context.Context, id wire.Account, peer map[int]wire.Address, conn Conn) error { var err error ok := pkg.TerminatesCtx(ctx, func() { authMsg, err2 := wire.NewAuthResponseMsg(id) @@ -81,8 +82,8 @@ func ExchangeAddrsActive(ctx context.Context, id wire.Account, peer wire.Address err = errors.Errorf("expected AuthResponse wire msg, got %v", e.Msg.Type()) } else if check := VerifyAddressSignature(peer, e.Msg.(*wire.AuthResponseMsg).Signature); check != nil { err = errors.WithMessage(err, "verifying peer address's signature") - } else if !e.Recipient.Equal(id.Address()) && - !e.Sender.Equal(peer) { + } else if !test.EqualWireMaps(e.Recipient, id.Address()) && + !test.EqualWireMaps(e.Sender, peer) { err = NewAuthenticationError(e.Sender, e.Recipient, id.Address(), "unmatched response sender or recipient") } }) @@ -97,8 +98,8 @@ func ExchangeAddrsActive(ctx context.Context, id wire.Account, peer wire.Address // ExchangeAddrsPassive executes the passive role of the address exchange // protocol. It is executed by the person that listens for incoming connections. -func ExchangeAddrsPassive(ctx context.Context, id wire.Account, conn Conn) (wire.Address, error) { - var addr wire.Address +func ExchangeAddrsPassive(ctx context.Context, id wire.Account, conn Conn) (map[int]wire.Address, error) { + var addr map[int]wire.Address var err error ok := pkg.TerminatesCtx(ctx, func() { var e *wire.Envelope @@ -106,7 +107,7 @@ func ExchangeAddrsPassive(ctx context.Context, id wire.Account, conn Conn) (wire err = errors.WithMessage(err, "receiving auth message") } else if _, ok := e.Msg.(*wire.AuthResponseMsg); !ok { err = errors.Errorf("expected AuthResponse wire msg, got %v", e.Msg.Type()) - } else if !e.Recipient.Equal(id.Address()) { + } else if !test.EqualWireMaps(e.Recipient, id.Address()) { err = NewAuthenticationError(e.Sender, e.Recipient, id.Address(), "unmatched response sender or recipient") } else if err = VerifyAddressSignature(e.Sender, e.Msg.(*wire.AuthResponseMsg).Signature); err != nil { err = errors.WithMessage(err, "verifying peer address's signature") @@ -140,10 +141,21 @@ func ExchangeAddrsPassive(ctx context.Context, id wire.Account, conn Conn) (wire // VerifyAddressSignature verifies a signature against the hash of an address. // It relies on the MarshalBinary method of the provided wire.Address interface to generate the address hash. // In case the MarshalBinary method doesn't produce the expected hash, the verification may fail. -func VerifyAddressSignature(addr wire.Address, sig []byte) error { - addressBytes, err := addr.MarshalBinary() - if err != nil { - return fmt.Errorf("failed to marshal address: %w", err) +func VerifyAddressSignature(addrs map[int]wire.Address, sig []byte) error { + var addressBytes []byte + addressBytes = append(addressBytes, byte(len(addrs))) + for _, addr := range addrs { + addrBytes, err := addr.MarshalBinary() + if err != nil { + return fmt.Errorf("failed to marshal address: %w", err) + } + addressBytes = append(addressBytes, addrBytes...) + } + for _, addr := range addrs { + err := addr.Verify(addressBytes, sig) + if err != nil { + return err + } } - return addr.Verify(addressBytes, sig) + return nil } diff --git a/wire/net/exchange_addr_internal_test.go b/wire/net/exchange_addr_internal_test.go index 4abf6f83c..0b160ca60 100644 --- a/wire/net/exchange_addr_internal_test.go +++ b/wire/net/exchange_addr_internal_test.go @@ -16,6 +16,7 @@ package net import ( "context" + "perun.network/go-perun/channel" "sync" "testing" @@ -50,7 +51,7 @@ func TestExchangeAddrs_Success(t *testing.T) { recvAddr0, err := ExchangeAddrsPassive(context.Background(), account1, conn1) assert.NoError(t, err) - assert.True(t, recvAddr0.Equal(account0.Address())) + assert.True(t, channel.EqualWireMaps(recvAddr0, account0.Address())) }() err := ExchangeAddrsActive(context.Background(), account0, account1.Address(), conn0) diff --git a/wire/net/simple/account.go b/wire/net/simple/account.go index 799a59ab6..6e8e954c4 100644 --- a/wire/net/simple/account.go +++ b/wire/net/simple/account.go @@ -32,8 +32,8 @@ type Account struct { } // Address returns the account's address. -func (acc *Account) Address() wire.Address { - return acc.addr +func (acc *Account) Address() map[int]wire.Address { + return map[int]wire.Address{0: acc.addr} } // Sign signs the given message with the account's private key. diff --git a/wire/net/simple/address.go b/wire/net/simple/address.go index 7ed03e226..9cbf8d554 100644 --- a/wire/net/simple/address.go +++ b/wire/net/simple/address.go @@ -33,7 +33,7 @@ type Address struct { } // NewAddress returns a new address. -func NewAddress(host string) *Address { +func NewAddress(host string) wire.Address { return &Address{ Name: host, } @@ -192,6 +192,21 @@ func NewRandomAddress(rng *rand.Rand) *Address { return a } +// NewRandomAddress returns a new random peer address. +func NewRandomAddresses(rng *rand.Rand) map[int]wire.Address { + const addrLen = 32 + l := rng.Intn(addrLen) + d := make([]byte, l) + if _, err := rng.Read(d); err != nil { + panic(err) + } + + a := Address{ + Name: string(d), + } + return map[int]wire.Address{0: &a} +} + // Verify verifies a message signature. func (a *Address) Verify(msg []byte, sig []byte) error { hashed := sha256.Sum256(msg) diff --git a/wire/net/simple/dialer.go b/wire/net/simple/dialer.go index 82016ef27..7000c37af 100644 --- a/wire/net/simple/dialer.go +++ b/wire/net/simple/dialer.go @@ -77,11 +77,11 @@ func (d *Dialer) host(key wire.AddrKey) (string, bool) { } // Dial implements Dialer.Dial(). -func (d *Dialer) Dial(ctx context.Context, addr wire.Address, ser wire.EnvelopeSerializer) (wirenet.Conn, error) { +func (d *Dialer) Dial(ctx context.Context, addr map[int]wire.Address, ser wire.EnvelopeSerializer) (wirenet.Conn, error) { done := make(chan struct{}) defer close(done) - host, ok := d.host(wire.Key(addr)) + host, ok := d.host(wire.Keys(addr)) if !ok { return nil, errors.New("peer not found") } @@ -107,9 +107,9 @@ func (d *Dialer) Dial(ctx context.Context, addr wire.Address, ser wire.EnvelopeS } // Register registers a network address for a peer address. -func (d *Dialer) Register(addr wire.Address, address string) { +func (d *Dialer) Register(addr map[int]wire.Address, address string) { d.mutex.Lock() defer d.mutex.Unlock() - d.peers[wire.Key(addr)] = address + d.peers[wire.Keys(addr)] = address } diff --git a/wire/net/simple/dialer_internal_test.go b/wire/net/simple/dialer_internal_test.go index a493eb9fb..9d0eaa410 100644 --- a/wire/net/simple/dialer_internal_test.go +++ b/wire/net/simple/dialer_internal_test.go @@ -66,7 +66,7 @@ func TestDialer_Register(t *testing.T) { _, ok := d.host(key) require.False(t, ok) - d.Register(addr, "host") + d.Register(map[int]wire.Address{0: addr}, "host") host, ok := d.host(key) assert.True(t, ok) @@ -135,7 +135,7 @@ func TestDialer_Dial(t *testing.T) { }) t.Run("unknown host", func(t *testing.T) { - noHostAddr := NewRandomAddress(rng) + noHostAddr := NewRandomAddresses(rng) d.Register(noHostAddr, "no such host") ctxtest.AssertTerminates(t, timeout, func() { @@ -147,7 +147,7 @@ func TestDialer_Dial(t *testing.T) { t.Run("unknown address", func(t *testing.T) { ctxtest.AssertTerminates(t, timeout, func() { - unkownAddr := NewRandomAddress(rng) + unkownAddr := NewRandomAddresses(rng) conn, err := d.Dial(context.Background(), unkownAddr, ser) assert.Error(t, err) assert.Nil(t, conn) diff --git a/wire/net/simple/simple_exchange_addr_test.go b/wire/net/simple/simple_exchange_addr_test.go index 4dbd13646..4ba562640 100644 --- a/wire/net/simple/simple_exchange_addr_test.go +++ b/wire/net/simple/simple_exchange_addr_test.go @@ -22,6 +22,7 @@ import ( "context" "math/rand" "net" + "perun.network/go-perun/channel" "sync" "testing" "time" @@ -61,7 +62,7 @@ func TestExchangeAddrs_Success(t *testing.T) { recvAddr0, err := wirenet.ExchangeAddrsPassive(context.Background(), account1, conn1) assert.NoError(t, err) - assert.True(t, recvAddr0.Equal(account0.Address())) + assert.True(t, channel.EqualWireMaps(recvAddr0, account0.Address())) }() err := wirenet.ExchangeAddrsActive(context.Background(), account0, account1.Address(), conn0) @@ -105,8 +106,8 @@ func newPipeConnPair() (a wirenet.Conn, b wirenet.Conn) { // recipient generated using randomness from rng. func newRandomEnvelope(rng *rand.Rand, m wire.Msg) *wire.Envelope { return &wire.Envelope{ - Sender: NewRandomAddress(rng), - Recipient: NewRandomAddress(rng), + Sender: NewRandomAddresses(rng), + Recipient: NewRandomAddresses(rng), Msg: m, } } diff --git a/wire/net/test/connhub.go b/wire/net/test/connhub.go index 1c958b78c..e5b744b70 100644 --- a/wire/net/test/connhub.go +++ b/wire/net/test/connhub.go @@ -35,7 +35,7 @@ type ConnHub struct { // NewNetListener creates a new test listener for the given address. // Registers the new listener in the hub. Panics if the address was already // entered or the hub is closed. -func (h *ConnHub) NewNetListener(addr wire.Address) *Listener { +func (h *ConnHub) NewNetListener(addr map[int]wire.Address) *Listener { h.mutex.RLock() defer h.mutex.RUnlock() diff --git a/wire/net/test/dialer.go b/wire/net/test/dialer.go index b6bec0738..e13c6367a 100644 --- a/wire/net/test/dialer.go +++ b/wire/net/test/dialer.go @@ -44,7 +44,7 @@ func NewDialer(hub *ConnHub) *Dialer { } // Dial tries to connect to a wire. -func (d *Dialer) Dial(ctx context.Context, address wire.Address, ser wire.EnvelopeSerializer) (wirenet.Conn, error) { +func (d *Dialer) Dial(ctx context.Context, address map[int]wire.Address, ser wire.EnvelopeSerializer) (wirenet.Conn, error) { if d.IsClosed() { return nil, errors.New("dialer closed") } diff --git a/wire/net/test/listenermap.go b/wire/net/test/listenermap.go index 8592002be..05759fba8 100644 --- a/wire/net/test/listenermap.go +++ b/wire/net/test/listenermap.go @@ -15,6 +15,7 @@ package test import ( + "perun.network/go-perun/channel/persistence/test" "sync" "github.com/pkg/errors" @@ -23,7 +24,7 @@ import ( // listenerMapEntry is a key-value entry inside a listener map. type listenerMapEntry struct { - key wire.Address + key map[int]wire.Address value *Listener } @@ -35,9 +36,9 @@ type listenerMap struct { // findEntry is not mutexed, and is only to be called from within the type's // other functions. -func (m *listenerMap) findEntry(key wire.Address) (listenerMapEntry, int, bool) { +func (m *listenerMap) findEntry(key map[int]wire.Address) (listenerMapEntry, int, bool) { for i, v := range m.entries { - if v.key.Equal(key) { + if test.EqualWireMaps(v.key, key) { return v, i, true } } @@ -45,7 +46,7 @@ func (m *listenerMap) findEntry(key wire.Address) (listenerMapEntry, int, bool) return listenerMapEntry{}, -1, false } -func (m *listenerMap) find(key wire.Address) (*Listener, bool) { +func (m *listenerMap) find(key map[int]wire.Address) (*Listener, bool) { m.mutex.RLock() defer m.mutex.RUnlock() @@ -55,7 +56,7 @@ func (m *listenerMap) find(key wire.Address) (*Listener, bool) { return nil, false } -func (m *listenerMap) insert(key wire.Address, value *Listener) error { +func (m *listenerMap) insert(key map[int]wire.Address, value *Listener) error { m.mutex.Lock() defer m.mutex.Unlock() if _, _, ok := m.findEntry(key); ok { @@ -65,7 +66,7 @@ func (m *listenerMap) insert(key wire.Address, value *Listener) error { return nil } -func (m *listenerMap) erase(key wire.Address) error { +func (m *listenerMap) erase(key map[int]wire.Address) error { m.mutex.Lock() defer m.mutex.Unlock() diff --git a/wire/perunio/serializer/serializer.go b/wire/perunio/serializer/serializer.go index ff86ae6d1..fa8849620 100644 --- a/wire/perunio/serializer/serializer.go +++ b/wire/perunio/serializer/serializer.go @@ -15,6 +15,7 @@ package serializer import ( + "encoding/binary" "io" "github.com/pkg/errors" @@ -31,7 +32,7 @@ type serializer struct{} // Encode encodes the envelope into the wire using perunio encoding format. func (serializer) Encode(w io.Writer, env *wire.Envelope) error { - if err := perunio.Encode(w, env.Sender, env.Recipient); err != nil { + if err := perunio.Encode(w, wire.AddressDecMap(env.Sender), wire.AddressDecMap(env.Recipient)); err != nil { return err } return wire.EncodeMsg(env.Msg, w) @@ -40,14 +41,45 @@ func (serializer) Encode(w io.Writer, env *wire.Envelope) error { // Decode decodes an envelope from the wire using perunio encoding format. func (serializer) Decode(r io.Reader) (env *wire.Envelope, err error) { env = &wire.Envelope{} - env.Sender = wire.NewAddress() - if err = perunio.Decode(r, env.Sender); err != nil { - return env, errors.WithMessage(err, "decoding sender address") + err = perunio.Decode(r, (*wire.AddressDecMap)(&env.Sender)) + if err != nil { + return env, errors.WithMessage(err, "decoding sender addresses") } - env.Recipient = wire.NewAddress() - if err = perunio.Decode(r, env.Recipient); err != nil { - return env, errors.WithMessage(err, "decoding recipient address") + + // Decode the Recipient map + err = perunio.Decode(r, (*wire.AddressDecMap)(&env.Recipient)) + if err != nil { + return env, errors.WithMessage(err, "decoding recipient addresses") } + + // Decode the message env.Msg, err = wire.DecodeMsg(r) - return env, err + if err != nil { + return env, errors.WithMessage(err, "decoding message") + } + + return env, nil +} + +// decodeAddressMap decodes a map[int]Address from the reader. +func decodeAddressMap(r io.Reader) (map[int]wire.Address, error) { + var numEntries int32 + if err := binary.Read(r, binary.BigEndian, &numEntries); err != nil { + return nil, errors.New("could not decode map length: " + err.Error()) + } + + addrMap := make(map[int]wire.Address, numEntries) + for i := 0; i < int(numEntries); i++ { + var idx int32 + if err := binary.Read(r, binary.BigEndian, &idx); err != nil { + return nil, errors.New("could not decode map index: " + err.Error()) + } + addrs := wire.NewAddress() + if err := perunio.Decode(r, addrs); err != nil { + return nil, errors.WithMessagef(err, "decoding %d-th address map entry", i) + } + addrMap[int(idx)] = addrs + } + + return addrMap, nil } diff --git a/wire/perunio/test/serializertest.go b/wire/perunio/test/serializertest.go index 709f5eec9..79e39afd6 100644 --- a/wire/perunio/test/serializertest.go +++ b/wire/perunio/test/serializertest.go @@ -46,6 +46,7 @@ func genericDecodeEncodeTest(t *testing.T, serializers ...perunio.Serializer) { } w.Close() }() + t.Log("v: ", v) dest := reflect.New(reflect.TypeOf(v).Elem()) err := perunio.Decode(br, dest.Interface().(perunio.Serializer)) diff --git a/wire/protobuf/proposalmsgs.go b/wire/protobuf/proposalmsgs.go index af1b6b44b..cd2335e2a 100644 --- a/wire/protobuf/proposalmsgs.go +++ b/wire/protobuf/proposalmsgs.go @@ -15,9 +15,12 @@ package protobuf import ( + "bytes" + "encoding/binary" "fmt" "math" "math/big" + "perun.network/go-perun/log" "github.com/pkg/errors" "perun.network/go-perun/channel" @@ -126,35 +129,65 @@ func ToChannelProposalRejMsg(protoEnvMsg *Envelope_ChannelProposalRejMsg) (msg * } // ToWalletAddr converts a protobuf wallet address to a wallet.Address. -func ToWalletAddr(protoAddr []byte) (wallet.Address, error) { - addr := wallet.NewAddress() - return addr, addr.UnmarshalBinary(protoAddr) +func ToWalletAddr(protoAddr *Address) (map[int]wallet.Address, error) { + addrMap := make(map[int]wallet.Address) + for i := range protoAddr.AddressMapping { + var k int32 + if err := binary.Read(bytes.NewReader(protoAddr.AddressMapping[i].Key), binary.BigEndian, &k); err != nil { + return nil, fmt.Errorf("failed to read key: %w", err) + } + addr := wallet.NewAddress(int(k)) + if err := addr.UnmarshalBinary(protoAddr.AddressMapping[i].Address); err != nil { + return nil, fmt.Errorf("failed to unmarshal address for key %d: %w", k, err) + } + + addrMap[int(k)] = addr + } + return addrMap, nil +} + +// ToWireAddr converts a protobuf wallet address to a wallet.Address. +func ToWireAddr(protoAddr *Address) (map[int]wire.Address, error) { + addrMap := make(map[int]wire.Address) + for i := range protoAddr.AddressMapping { + var k int32 + if err := binary.Read(bytes.NewReader(protoAddr.AddressMapping[i].Key), binary.BigEndian, &k); err != nil { + return nil, fmt.Errorf("failed to read key: %w", err) + } + addr := wire.NewAddress() + if err := addr.UnmarshalBinary(protoAddr.AddressMapping[i].Address); err != nil { + return nil, fmt.Errorf("failed to unmarshal address for key %d: %w", k, err) + } + + addrMap[int(k)] = addr + } + return addrMap, nil } // ToWalletAddrs converts protobuf wallet addresses to a slice of wallet.Address. -func ToWalletAddrs(protoAddrs [][]byte) ([]wallet.Address, error) { - addrs := make([]wallet.Address, len(protoAddrs)) +func ToWalletAddrs(protoAddrs []*Address) ([]map[int]wallet.Address, error) { + addrs := make([]map[int]wallet.Address, len(protoAddrs)) for i := range protoAddrs { - addrs[i] = wallet.NewAddress() - err := addrs[i].UnmarshalBinary(protoAddrs[i]) + addrMap, err := ToWalletAddr(protoAddrs[i]) if err != nil { return nil, errors.WithMessagef(err, "%d'th address", i) } + addrs[i] = addrMap } return addrs, nil } // ToWireAddrs converts protobuf wire addresses to a slice of wire.Address. -func ToWireAddrs(protoAddrs [][]byte) ([]wire.Address, error) { - addrs := make([]wire.Address, len(protoAddrs)) - for i := range protoAddrs { - addrs[i] = wire.NewAddress() - err := addrs[i].UnmarshalBinary(protoAddrs[i]) +func ToWireAddrs(protoAddrs []*Address) ([]map[int]wire.Address, error) { + addrMap := make([]map[int]wire.Address, len(protoAddrs)) + var err error + for i, addMap := range protoAddrs { + addrMap[i], err = ToWireAddr(addMap) if err != nil { return nil, errors.WithMessagef(err, "%d'th address", i) } } - return addrs, nil + return addrMap, nil } // ToBaseChannelProposal converts a protobuf BaseChannelProposal to a client BaseChannelProposal. @@ -167,9 +200,6 @@ func ToBaseChannelProposal(protoProp *BaseChannelProposal) (prop client.BaseChan return prop, errors.WithMessage(err, "init bals") } prop.FundingAgreement = ToBalances(protoProp.FundingAgreement) - if err != nil { - return prop, errors.WithMessage(err, "funding agreement") - } prop.App, prop.InitData, err = ToAppAndData(protoProp.App, protoProp.InitData) return prop, err } @@ -187,7 +217,7 @@ func ToApp(protoApp []byte) (app channel.App, err error) { app = channel.NoApp() return app, nil } - appDef := channel.NewAppID() + appDef, _ := channel.NewAppID() err = appDef.UnmarshalBinary(protoApp) if err != nil { return app, err @@ -203,7 +233,7 @@ func ToAppAndData(protoApp, protoData []byte) (app channel.App, data channel.Dat data = channel.NoData() return app, data, nil } - appDef := channel.NewAppID() + appDef, _ := channel.NewAppID() err = appDef.UnmarshalBinary(protoApp) if err != nil { return nil, nil, err @@ -216,12 +246,39 @@ func ToAppAndData(protoApp, protoData []byte) (app channel.App, data channel.Dat return app, data, data.UnmarshalBinary(protoData) } +// ToIntSlice converts a [][]byte field from a protobuf message to a []int. +func ToIntSlice(backends [][]byte) ([]int, error) { + ints := make([]int, len(backends)) + + for i, backend := range backends { + if len(backend) != 4 { + return nil, fmt.Errorf("backend %d length is not 4 bytes", i) + } + + var value int32 + err := binary.Read(bytes.NewReader(backend), binary.BigEndian, &value) + if err != nil { + return nil, fmt.Errorf("failed to convert backend %d bytes to int: %w", i, err) + } + + ints[i] = int(value) + } + + return ints, nil +} + // ToAllocation converts a protobuf allocation to a channel.Allocation. func ToAllocation(protoAlloc *Allocation) (alloc *channel.Allocation, err error) { alloc = &channel.Allocation{} + alloc.Backends, err = ToIntSlice(protoAlloc.Backends) + if err != nil { + return nil, errors.WithMessage(err, "backends") + } + log.Printf("ToAllocation: alloc.Backends length: %d, protoAlloc.Assets length: %d", len(alloc.Backends), len(protoAlloc.Assets)) + log.Println("ToAllocation: ", alloc.Backends) alloc.Assets = make([]channel.Asset, len(protoAlloc.Assets)) for i := range protoAlloc.Assets { - alloc.Assets[i] = channel.NewAsset() + alloc.Assets[i] = channel.NewAsset(alloc.Backends[i]) err = alloc.Assets[i].UnmarshalBinary(protoAlloc.Assets[i]) if err != nil { return nil, errors.WithMessagef(err, "%d'th asset", i) @@ -366,15 +423,58 @@ func FromChannelProposalRejMsg(msg *client.ChannelProposalRejMsg) (_ *Envelope_C } // FromWalletAddr converts a wallet.Address to a protobuf wallet address. -func FromWalletAddr(addr wallet.Address) ([]byte, error) { - return addr.MarshalBinary() +func FromWalletAddr(addr map[int]wallet.Address) (*Address, error) { + var addressMappings []*AddressMapping + + for key, address := range addr { + keyBytes := make([]byte, 4) + binary.BigEndian.PutUint32(keyBytes, uint32(key)) + + addressBytes, err := address.MarshalBinary() + if err != nil { + return nil, fmt.Errorf("failed to marshal address for key %d: %w", key, err) + } + + addressMappings = append(addressMappings, &AddressMapping{ + Key: keyBytes, + Address: addressBytes, + }) + } + + return &Address{ + AddressMapping: addressMappings, + }, nil +} + +// FromWireAddr converts a wallet.Address to a protobuf wire address. +func FromWireAddr(addr map[int]wire.Address) (*Address, error) { + var addressMappings []*AddressMapping + + for key, address := range addr { + keyBytes := make([]byte, 4) + binary.BigEndian.PutUint32(keyBytes, uint32(key)) + + addressBytes, err := address.MarshalBinary() + if err != nil { + return nil, fmt.Errorf("failed to marshal address for key %d: %w", key, err) + } + + addressMappings = append(addressMappings, &AddressMapping{ + Key: keyBytes, + Address: addressBytes, + }) + } + + return &Address{ + AddressMapping: addressMappings, + }, nil } // FromWalletAddrs converts a slice of wallet.Address to protobuf wallet addresses. -func FromWalletAddrs(addrs []wallet.Address) (protoAddrs [][]byte, err error) { - protoAddrs = make([][]byte, len(addrs)) +func FromWalletAddrs(addrs []map[int]wallet.Address) (protoAddrs []*Address, err error) { + protoAddrs = make([]*Address, len(addrs)) for i := range addrs { - protoAddrs[i], err = addrs[i].MarshalBinary() + protoAddrs[i], err = FromWalletAddr(addrs[i]) if err != nil { return nil, errors.WithMessagef(err, "%d'th address", i) } @@ -383,10 +483,10 @@ func FromWalletAddrs(addrs []wallet.Address) (protoAddrs [][]byte, err error) { } // FromWireAddrs converts a slice of wire.Address to protobuf wire addresses. -func FromWireAddrs(addrs []wire.Address) (protoAddrs [][]byte, err error) { - protoAddrs = make([][]byte, len(addrs)) +func FromWireAddrs(addrs []map[int]wire.Address) (protoAddrs []*Address, err error) { + protoAddrs = make([]*Address, len(addrs)) for i := range addrs { - protoAddrs[i], err = addrs[i].MarshalBinary() + protoAddrs[i], err = FromWireAddr(addrs[i]) if err != nil { return nil, errors.WithMessagef(err, "%d'th address", i) } @@ -453,6 +553,11 @@ func FromAppAndData(app channel.App, data channel.Data) (protoApp, protoData []b // FromAllocation converts a channel.Allocation to a protobuf Allocation. func FromAllocation(alloc channel.Allocation) (protoAlloc *Allocation, err error) { protoAlloc = &Allocation{} + protoAlloc.Backends = make([][]byte, len(alloc.Backends)) + for i := range alloc.Backends { + protoAlloc.Backends[i] = make([]byte, 4) + binary.BigEndian.PutUint32(protoAlloc.Backends[i], uint32(alloc.Backends[i])) + } protoAlloc.Assets = make([][]byte, len(alloc.Assets)) for i := range alloc.Assets { protoAlloc.Assets[i], err = alloc.Assets[i].MarshalBinary() diff --git a/wire/protobuf/serializer.go b/wire/protobuf/serializer.go index ef18432f8..f68c332fa 100644 --- a/wire/protobuf/serializer.go +++ b/wire/protobuf/serializer.go @@ -79,7 +79,8 @@ func (serializer) Encode(w io.Writer, env *wire.Envelope) (err error) { //nolint if err != nil { return err } - protoEnv.Sender, protoEnv.Recipient, err = marshalSenderRecipient(env) + sender, recipient, err := marshalSenderRecipient(env) + protoEnv.Sender, protoEnv.Recipient = sender, recipient if err != nil { return err } @@ -87,12 +88,12 @@ func (serializer) Encode(w io.Writer, env *wire.Envelope) (err error) { //nolint return writeEnvelope(w, protoEnv) } -func marshalSenderRecipient(env *wire.Envelope) ([]byte, []byte, error) { - sender, err := env.Sender.MarshalBinary() +func marshalSenderRecipient(env *wire.Envelope) (*Address, *Address, error) { + sender, err := FromWireAddr(env.Sender) if err != nil { return nil, nil, errors.WithMessage(err, "marshalling sender address") } - recipient, err := env.Recipient.MarshalBinary() + recipient, err := FromWireAddr(env.Recipient) return sender, recipient, errors.WithMessage(err, "marshalling recipient address") } @@ -118,7 +119,8 @@ func (serializer) Decode(r io.Reader) (env *wire.Envelope, err error) { //nolint return nil, err } - env.Sender, env.Recipient, err = unmarshalSenderRecipient(protoEnv) + sender, recipient, err := unmarshalSenderRecipient(protoEnv) + env.Sender, env.Recipient = sender, recipient if err != nil { return nil, err } @@ -179,12 +181,14 @@ func readEnvelope(r io.Reader) (*Envelope, error) { return &protoEnv, errors.Wrap(proto.Unmarshal(data, &protoEnv), "unmarshalling envelope") } -func unmarshalSenderRecipient(protoEnv *Envelope) (wire.Address, wire.Address, error) { - sender := wire.NewAddress() - if err := sender.UnmarshalBinary(protoEnv.Sender); err != nil { +func unmarshalSenderRecipient(protoEnv *Envelope) (map[int]wire.Address, map[int]wire.Address, error) { + sender, err := ToWireAddr(protoEnv.Sender) + if err != nil { return nil, nil, errors.Wrap(err, "unmarshalling sender address") } - recipient := wire.NewAddress() - err := recipient.UnmarshalBinary(protoEnv.Recipient) - return sender, recipient, errors.Wrap(err, "unmarshalling recipient address") + recipient, err1 := ToWireAddr(protoEnv.Recipient) + if err1 != nil { + return nil, nil, errors.Wrap(err, "unmarshalling recipient address") + } + return sender, recipient, nil } diff --git a/wire/protobuf/wire.pb.go b/wire/protobuf/wire.pb.go index 49a605f46..bb4c388eb 100644 --- a/wire/protobuf/wire.pb.go +++ b/wire/protobuf/wire.pb.go @@ -16,8 +16,8 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.27.1 -// protoc v4.25.2 +// protoc-gen-go v1.34.2 +// protoc v3.20.3 // source: wire.proto package protobuf @@ -44,12 +44,13 @@ type Envelope struct { unknownFields protoimpl.UnknownFields // sender of the message. - Sender []byte `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` + Sender *Address `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` // intended recipient of the message. - Recipient []byte `protobuf:"bytes,2,opt,name=recipient,proto3" json:"recipient,omitempty"` + Recipient *Address `protobuf:"bytes,2,opt,name=recipient,proto3" json:"recipient,omitempty"` // msg should contain on the valid message types. // // Types that are assignable to Msg: + // // *Envelope_PingMsg // *Envelope_PongMsg // *Envelope_ShutdownMsg @@ -102,14 +103,14 @@ func (*Envelope) Descriptor() ([]byte, []int) { return file_wire_proto_rawDescGZIP(), []int{0} } -func (x *Envelope) GetSender() []byte { +func (x *Envelope) GetSender() *Address { if x != nil { return x.Sender } return nil } -func (x *Envelope) GetRecipient() []byte { +func (x *Envelope) GetRecipient() *Address { if x != nil { return x.Recipient } @@ -446,6 +447,110 @@ func (x *Balances) GetBalances() []*Balance { return nil } +// AddressMapping represents an element of a address mapping. +type AddressMapping struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Address []byte `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` +} + +func (x *AddressMapping) Reset() { + *x = AddressMapping{} + if protoimpl.UnsafeEnabled { + mi := &file_wire_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *AddressMapping) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AddressMapping) ProtoMessage() {} + +func (x *AddressMapping) ProtoReflect() protoreflect.Message { + mi := &file_wire_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AddressMapping.ProtoReflect.Descriptor instead. +func (*AddressMapping) Descriptor() ([]byte, []int) { + return file_wire_proto_rawDescGZIP(), []int{3} +} + +func (x *AddressMapping) GetKey() []byte { + if x != nil { + return x.Key + } + return nil +} + +func (x *AddressMapping) GetAddress() []byte { + if x != nil { + return x.Address + } + return nil +} + +// Address represents the map of addresses for each participant in the channel. +type Address struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + AddressMapping []*AddressMapping `protobuf:"bytes,1,rep,name=address_mapping,json=addressMapping,proto3" json:"address_mapping,omitempty"` +} + +func (x *Address) Reset() { + *x = Address{} + if protoimpl.UnsafeEnabled { + mi := &file_wire_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Address) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Address) ProtoMessage() {} + +func (x *Address) ProtoReflect() protoreflect.Message { + mi := &file_wire_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Address.ProtoReflect.Descriptor instead. +func (*Address) Descriptor() ([]byte, []int) { + return file_wire_proto_rawDescGZIP(), []int{4} +} + +func (x *Address) GetAddressMapping() []*AddressMapping { + if x != nil { + return x.AddressMapping + } + return nil +} + // IndexMap represents the mapping of a participant indices in a sub allocation // or a virtual channel funding proposal to the corresponding indices in the // parent channel. @@ -460,7 +565,7 @@ type IndexMap struct { func (x *IndexMap) Reset() { *x = IndexMap{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[3] + mi := &file_wire_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -473,7 +578,7 @@ func (x *IndexMap) String() string { func (*IndexMap) ProtoMessage() {} func (x *IndexMap) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[3] + mi := &file_wire_proto_msgTypes[5] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -486,7 +591,7 @@ func (x *IndexMap) ProtoReflect() protoreflect.Message { // Deprecated: Use IndexMap.ProtoReflect.Descriptor instead. func (*IndexMap) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{3} + return file_wire_proto_rawDescGZIP(), []int{5} } func (x *IndexMap) GetIndexMap() []uint32 { @@ -510,7 +615,7 @@ type SubAlloc struct { func (x *SubAlloc) Reset() { *x = SubAlloc{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[4] + mi := &file_wire_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -523,7 +628,7 @@ func (x *SubAlloc) String() string { func (*SubAlloc) ProtoMessage() {} func (x *SubAlloc) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[4] + mi := &file_wire_proto_msgTypes[6] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -536,7 +641,7 @@ func (x *SubAlloc) ProtoReflect() protoreflect.Message { // Deprecated: Use SubAlloc.ProtoReflect.Descriptor instead. func (*SubAlloc) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{4} + return file_wire_proto_rawDescGZIP(), []int{6} } func (x *SubAlloc) GetId() []byte { @@ -566,15 +671,16 @@ type Allocation struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Assets [][]byte `protobuf:"bytes,1,rep,name=assets,proto3" json:"assets,omitempty"` - Balances *Balances `protobuf:"bytes,2,opt,name=balances,proto3" json:"balances,omitempty"` - Locked []*SubAlloc `protobuf:"bytes,3,rep,name=locked,proto3" json:"locked,omitempty"` + Backends [][]byte `protobuf:"bytes,1,rep,name=backends,proto3" json:"backends,omitempty"` + Assets [][]byte `protobuf:"bytes,2,rep,name=assets,proto3" json:"assets,omitempty"` + Balances *Balances `protobuf:"bytes,3,opt,name=balances,proto3" json:"balances,omitempty"` + Locked []*SubAlloc `protobuf:"bytes,4,rep,name=locked,proto3" json:"locked,omitempty"` } func (x *Allocation) Reset() { *x = Allocation{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[5] + mi := &file_wire_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -587,7 +693,7 @@ func (x *Allocation) String() string { func (*Allocation) ProtoMessage() {} func (x *Allocation) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[5] + mi := &file_wire_proto_msgTypes[7] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -600,7 +706,14 @@ func (x *Allocation) ProtoReflect() protoreflect.Message { // Deprecated: Use Allocation.ProtoReflect.Descriptor instead. func (*Allocation) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{5} + return file_wire_proto_rawDescGZIP(), []int{7} +} + +func (x *Allocation) GetBackends() [][]byte { + if x != nil { + return x.Backends + } + return nil } func (x *Allocation) GetAssets() [][]byte { @@ -642,7 +755,7 @@ type BaseChannelProposal struct { func (x *BaseChannelProposal) Reset() { *x = BaseChannelProposal{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[6] + mi := &file_wire_proto_msgTypes[8] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -655,7 +768,7 @@ func (x *BaseChannelProposal) String() string { func (*BaseChannelProposal) ProtoMessage() {} func (x *BaseChannelProposal) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[6] + mi := &file_wire_proto_msgTypes[8] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -668,7 +781,7 @@ func (x *BaseChannelProposal) ProtoReflect() protoreflect.Message { // Deprecated: Use BaseChannelProposal.ProtoReflect.Descriptor instead. func (*BaseChannelProposal) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{6} + return file_wire_proto_rawDescGZIP(), []int{8} } func (x *BaseChannelProposal) GetProposalId() []byte { @@ -733,7 +846,7 @@ type BaseChannelProposalAcc struct { func (x *BaseChannelProposalAcc) Reset() { *x = BaseChannelProposalAcc{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[7] + mi := &file_wire_proto_msgTypes[9] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -746,7 +859,7 @@ func (x *BaseChannelProposalAcc) String() string { func (*BaseChannelProposalAcc) ProtoMessage() {} func (x *BaseChannelProposalAcc) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[7] + mi := &file_wire_proto_msgTypes[9] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -759,7 +872,7 @@ func (x *BaseChannelProposalAcc) ProtoReflect() protoreflect.Message { // Deprecated: Use BaseChannelProposalAcc.ProtoReflect.Descriptor instead. func (*BaseChannelProposalAcc) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{7} + return file_wire_proto_rawDescGZIP(), []int{9} } func (x *BaseChannelProposalAcc) GetProposalId() []byte { @@ -782,19 +895,19 @@ type Params struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id []byte `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - ChallengeDuration uint64 `protobuf:"varint,2,opt,name=challenge_duration,json=challengeDuration,proto3" json:"challenge_duration,omitempty"` - Parts [][]byte `protobuf:"bytes,3,rep,name=parts,proto3" json:"parts,omitempty"` - App []byte `protobuf:"bytes,4,opt,name=app,proto3" json:"app,omitempty"` - Nonce []byte `protobuf:"bytes,5,opt,name=nonce,proto3" json:"nonce,omitempty"` - LedgerChannel bool `protobuf:"varint,6,opt,name=ledger_channel,json=ledgerChannel,proto3" json:"ledger_channel,omitempty"` - VirtualChannel bool `protobuf:"varint,7,opt,name=virtual_channel,json=virtualChannel,proto3" json:"virtual_channel,omitempty"` + Id []byte `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + ChallengeDuration uint64 `protobuf:"varint,2,opt,name=challenge_duration,json=challengeDuration,proto3" json:"challenge_duration,omitempty"` + Parts []*Address `protobuf:"bytes,3,rep,name=parts,proto3" json:"parts,omitempty"` + App []byte `protobuf:"bytes,4,opt,name=app,proto3" json:"app,omitempty"` + Nonce []byte `protobuf:"bytes,5,opt,name=nonce,proto3" json:"nonce,omitempty"` + LedgerChannel bool `protobuf:"varint,6,opt,name=ledger_channel,json=ledgerChannel,proto3" json:"ledger_channel,omitempty"` + VirtualChannel bool `protobuf:"varint,7,opt,name=virtual_channel,json=virtualChannel,proto3" json:"virtual_channel,omitempty"` } func (x *Params) Reset() { *x = Params{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[8] + mi := &file_wire_proto_msgTypes[10] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -807,7 +920,7 @@ func (x *Params) String() string { func (*Params) ProtoMessage() {} func (x *Params) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[8] + mi := &file_wire_proto_msgTypes[10] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -820,7 +933,7 @@ func (x *Params) ProtoReflect() protoreflect.Message { // Deprecated: Use Params.ProtoReflect.Descriptor instead. func (*Params) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{8} + return file_wire_proto_rawDescGZIP(), []int{10} } func (x *Params) GetId() []byte { @@ -837,7 +950,7 @@ func (x *Params) GetChallengeDuration() uint64 { return 0 } -func (x *Params) GetParts() [][]byte { +func (x *Params) GetParts() []*Address { if x != nil { return x.Parts } @@ -889,7 +1002,7 @@ type State struct { func (x *State) Reset() { *x = State{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[9] + mi := &file_wire_proto_msgTypes[11] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -902,7 +1015,7 @@ func (x *State) String() string { func (*State) ProtoMessage() {} func (x *State) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[9] + mi := &file_wire_proto_msgTypes[11] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -915,7 +1028,7 @@ func (x *State) ProtoReflect() protoreflect.Message { // Deprecated: Use State.ProtoReflect.Descriptor instead. func (*State) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{9} + return file_wire_proto_rawDescGZIP(), []int{11} } func (x *State) GetId() []byte { @@ -973,7 +1086,7 @@ type Transaction struct { func (x *Transaction) Reset() { *x = Transaction{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[10] + mi := &file_wire_proto_msgTypes[12] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -986,7 +1099,7 @@ func (x *Transaction) String() string { func (*Transaction) ProtoMessage() {} func (x *Transaction) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[10] + mi := &file_wire_proto_msgTypes[12] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -999,7 +1112,7 @@ func (x *Transaction) ProtoReflect() protoreflect.Message { // Deprecated: Use Transaction.ProtoReflect.Descriptor instead. func (*Transaction) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{10} + return file_wire_proto_rawDescGZIP(), []int{12} } func (x *Transaction) GetState() *State { @@ -1030,7 +1143,7 @@ type SignedState struct { func (x *SignedState) Reset() { *x = SignedState{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[11] + mi := &file_wire_proto_msgTypes[13] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1043,7 +1156,7 @@ func (x *SignedState) String() string { func (*SignedState) ProtoMessage() {} func (x *SignedState) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[11] + mi := &file_wire_proto_msgTypes[13] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1056,7 +1169,7 @@ func (x *SignedState) ProtoReflect() protoreflect.Message { // Deprecated: Use SignedState.ProtoReflect.Descriptor instead. func (*SignedState) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{11} + return file_wire_proto_rawDescGZIP(), []int{13} } func (x *SignedState) GetParams() *Params { @@ -1093,7 +1206,7 @@ type ChannelUpdate struct { func (x *ChannelUpdate) Reset() { *x = ChannelUpdate{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[12] + mi := &file_wire_proto_msgTypes[14] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1106,7 +1219,7 @@ func (x *ChannelUpdate) String() string { func (*ChannelUpdate) ProtoMessage() {} func (x *ChannelUpdate) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[12] + mi := &file_wire_proto_msgTypes[14] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1119,7 +1232,7 @@ func (x *ChannelUpdate) ProtoReflect() protoreflect.Message { // Deprecated: Use ChannelUpdate.ProtoReflect.Descriptor instead. func (*ChannelUpdate) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{12} + return file_wire_proto_rawDescGZIP(), []int{14} } func (x *ChannelUpdate) GetState() *State { @@ -1148,7 +1261,7 @@ type PingMsg struct { func (x *PingMsg) Reset() { *x = PingMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[13] + mi := &file_wire_proto_msgTypes[15] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1161,7 +1274,7 @@ func (x *PingMsg) String() string { func (*PingMsg) ProtoMessage() {} func (x *PingMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[13] + mi := &file_wire_proto_msgTypes[15] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1174,7 +1287,7 @@ func (x *PingMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use PingMsg.ProtoReflect.Descriptor instead. func (*PingMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{13} + return file_wire_proto_rawDescGZIP(), []int{15} } func (x *PingMsg) GetCreated() int64 { @@ -1196,7 +1309,7 @@ type PongMsg struct { func (x *PongMsg) Reset() { *x = PongMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[14] + mi := &file_wire_proto_msgTypes[16] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1209,7 +1322,7 @@ func (x *PongMsg) String() string { func (*PongMsg) ProtoMessage() {} func (x *PongMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[14] + mi := &file_wire_proto_msgTypes[16] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1222,7 +1335,7 @@ func (x *PongMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use PongMsg.ProtoReflect.Descriptor instead. func (*PongMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{14} + return file_wire_proto_rawDescGZIP(), []int{16} } func (x *PongMsg) GetCreated() int64 { @@ -1244,7 +1357,7 @@ type ShutdownMsg struct { func (x *ShutdownMsg) Reset() { *x = ShutdownMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[15] + mi := &file_wire_proto_msgTypes[17] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1257,7 +1370,7 @@ func (x *ShutdownMsg) String() string { func (*ShutdownMsg) ProtoMessage() {} func (x *ShutdownMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[15] + mi := &file_wire_proto_msgTypes[17] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1270,7 +1383,7 @@ func (x *ShutdownMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use ShutdownMsg.ProtoReflect.Descriptor instead. func (*ShutdownMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{15} + return file_wire_proto_rawDescGZIP(), []int{17} } func (x *ShutdownMsg) GetReason() string { @@ -1292,7 +1405,7 @@ type AuthResponseMsg struct { func (x *AuthResponseMsg) Reset() { *x = AuthResponseMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[16] + mi := &file_wire_proto_msgTypes[18] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1305,7 +1418,7 @@ func (x *AuthResponseMsg) String() string { func (*AuthResponseMsg) ProtoMessage() {} func (x *AuthResponseMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[16] + mi := &file_wire_proto_msgTypes[18] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1318,7 +1431,7 @@ func (x *AuthResponseMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use AuthResponseMsg.ProtoReflect.Descriptor instead. func (*AuthResponseMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{16} + return file_wire_proto_rawDescGZIP(), []int{18} } func (x *AuthResponseMsg) GetSignature() []byte { @@ -1335,14 +1448,14 @@ type LedgerChannelProposalMsg struct { unknownFields protoimpl.UnknownFields BaseChannelProposal *BaseChannelProposal `protobuf:"bytes,1,opt,name=base_channel_proposal,json=baseChannelProposal,proto3" json:"base_channel_proposal,omitempty"` - Participant []byte `protobuf:"bytes,2,opt,name=participant,proto3" json:"participant,omitempty"` - Peers [][]byte `protobuf:"bytes,3,rep,name=peers,proto3" json:"peers,omitempty"` + Participant *Address `protobuf:"bytes,2,opt,name=participant,proto3" json:"participant,omitempty"` + Peers []*Address `protobuf:"bytes,3,rep,name=peers,proto3" json:"peers,omitempty"` } func (x *LedgerChannelProposalMsg) Reset() { *x = LedgerChannelProposalMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[17] + mi := &file_wire_proto_msgTypes[19] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1355,7 +1468,7 @@ func (x *LedgerChannelProposalMsg) String() string { func (*LedgerChannelProposalMsg) ProtoMessage() {} func (x *LedgerChannelProposalMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[17] + mi := &file_wire_proto_msgTypes[19] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1368,7 +1481,7 @@ func (x *LedgerChannelProposalMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use LedgerChannelProposalMsg.ProtoReflect.Descriptor instead. func (*LedgerChannelProposalMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{17} + return file_wire_proto_rawDescGZIP(), []int{19} } func (x *LedgerChannelProposalMsg) GetBaseChannelProposal() *BaseChannelProposal { @@ -1378,14 +1491,14 @@ func (x *LedgerChannelProposalMsg) GetBaseChannelProposal() *BaseChannelProposal return nil } -func (x *LedgerChannelProposalMsg) GetParticipant() []byte { +func (x *LedgerChannelProposalMsg) GetParticipant() *Address { if x != nil { return x.Participant } return nil } -func (x *LedgerChannelProposalMsg) GetPeers() [][]byte { +func (x *LedgerChannelProposalMsg) GetPeers() []*Address { if x != nil { return x.Peers } @@ -1399,13 +1512,13 @@ type LedgerChannelProposalAccMsg struct { unknownFields protoimpl.UnknownFields BaseChannelProposalAcc *BaseChannelProposalAcc `protobuf:"bytes,1,opt,name=base_channel_proposal_acc,json=baseChannelProposalAcc,proto3" json:"base_channel_proposal_acc,omitempty"` - Participant []byte `protobuf:"bytes,2,opt,name=participant,proto3" json:"participant,omitempty"` + Participant *Address `protobuf:"bytes,2,opt,name=participant,proto3" json:"participant,omitempty"` } func (x *LedgerChannelProposalAccMsg) Reset() { *x = LedgerChannelProposalAccMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[18] + mi := &file_wire_proto_msgTypes[20] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1418,7 +1531,7 @@ func (x *LedgerChannelProposalAccMsg) String() string { func (*LedgerChannelProposalAccMsg) ProtoMessage() {} func (x *LedgerChannelProposalAccMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[18] + mi := &file_wire_proto_msgTypes[20] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1431,7 +1544,7 @@ func (x *LedgerChannelProposalAccMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use LedgerChannelProposalAccMsg.ProtoReflect.Descriptor instead. func (*LedgerChannelProposalAccMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{18} + return file_wire_proto_rawDescGZIP(), []int{20} } func (x *LedgerChannelProposalAccMsg) GetBaseChannelProposalAcc() *BaseChannelProposalAcc { @@ -1441,7 +1554,7 @@ func (x *LedgerChannelProposalAccMsg) GetBaseChannelProposalAcc() *BaseChannelPr return nil } -func (x *LedgerChannelProposalAccMsg) GetParticipant() []byte { +func (x *LedgerChannelProposalAccMsg) GetParticipant() *Address { if x != nil { return x.Participant } @@ -1461,7 +1574,7 @@ type SubChannelProposalMsg struct { func (x *SubChannelProposalMsg) Reset() { *x = SubChannelProposalMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[19] + mi := &file_wire_proto_msgTypes[21] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1474,7 +1587,7 @@ func (x *SubChannelProposalMsg) String() string { func (*SubChannelProposalMsg) ProtoMessage() {} func (x *SubChannelProposalMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[19] + mi := &file_wire_proto_msgTypes[21] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1487,7 +1600,7 @@ func (x *SubChannelProposalMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use SubChannelProposalMsg.ProtoReflect.Descriptor instead. func (*SubChannelProposalMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{19} + return file_wire_proto_rawDescGZIP(), []int{21} } func (x *SubChannelProposalMsg) GetBaseChannelProposal() *BaseChannelProposal { @@ -1516,7 +1629,7 @@ type SubChannelProposalAccMsg struct { func (x *SubChannelProposalAccMsg) Reset() { *x = SubChannelProposalAccMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[20] + mi := &file_wire_proto_msgTypes[22] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1529,7 +1642,7 @@ func (x *SubChannelProposalAccMsg) String() string { func (*SubChannelProposalAccMsg) ProtoMessage() {} func (x *SubChannelProposalAccMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[20] + mi := &file_wire_proto_msgTypes[22] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1542,7 +1655,7 @@ func (x *SubChannelProposalAccMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use SubChannelProposalAccMsg.ProtoReflect.Descriptor instead. func (*SubChannelProposalAccMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{20} + return file_wire_proto_rawDescGZIP(), []int{22} } func (x *SubChannelProposalAccMsg) GetBaseChannelProposalAcc() *BaseChannelProposalAcc { @@ -1559,8 +1672,8 @@ type VirtualChannelProposalMsg struct { unknownFields protoimpl.UnknownFields BaseChannelProposal *BaseChannelProposal `protobuf:"bytes,1,opt,name=base_channel_proposal,json=baseChannelProposal,proto3" json:"base_channel_proposal,omitempty"` - Proposer []byte `protobuf:"bytes,2,opt,name=proposer,proto3" json:"proposer,omitempty"` - Peers [][]byte `protobuf:"bytes,3,rep,name=peers,proto3" json:"peers,omitempty"` + Proposer *Address `protobuf:"bytes,2,opt,name=proposer,proto3" json:"proposer,omitempty"` + Peers []*Address `protobuf:"bytes,3,rep,name=peers,proto3" json:"peers,omitempty"` Parents [][]byte `protobuf:"bytes,4,rep,name=parents,proto3" json:"parents,omitempty"` IndexMaps []*IndexMap `protobuf:"bytes,5,rep,name=index_maps,json=indexMaps,proto3" json:"index_maps,omitempty"` } @@ -1568,7 +1681,7 @@ type VirtualChannelProposalMsg struct { func (x *VirtualChannelProposalMsg) Reset() { *x = VirtualChannelProposalMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[21] + mi := &file_wire_proto_msgTypes[23] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1581,7 +1694,7 @@ func (x *VirtualChannelProposalMsg) String() string { func (*VirtualChannelProposalMsg) ProtoMessage() {} func (x *VirtualChannelProposalMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[21] + mi := &file_wire_proto_msgTypes[23] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1594,7 +1707,7 @@ func (x *VirtualChannelProposalMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use VirtualChannelProposalMsg.ProtoReflect.Descriptor instead. func (*VirtualChannelProposalMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{21} + return file_wire_proto_rawDescGZIP(), []int{23} } func (x *VirtualChannelProposalMsg) GetBaseChannelProposal() *BaseChannelProposal { @@ -1604,14 +1717,14 @@ func (x *VirtualChannelProposalMsg) GetBaseChannelProposal() *BaseChannelProposa return nil } -func (x *VirtualChannelProposalMsg) GetProposer() []byte { +func (x *VirtualChannelProposalMsg) GetProposer() *Address { if x != nil { return x.Proposer } return nil } -func (x *VirtualChannelProposalMsg) GetPeers() [][]byte { +func (x *VirtualChannelProposalMsg) GetPeers() []*Address { if x != nil { return x.Peers } @@ -1639,13 +1752,13 @@ type VirtualChannelProposalAccMsg struct { unknownFields protoimpl.UnknownFields BaseChannelProposalAcc *BaseChannelProposalAcc `protobuf:"bytes,1,opt,name=base_channel_proposal_acc,json=baseChannelProposalAcc,proto3" json:"base_channel_proposal_acc,omitempty"` - Responder []byte `protobuf:"bytes,2,opt,name=responder,proto3" json:"responder,omitempty"` + Responder *Address `protobuf:"bytes,2,opt,name=responder,proto3" json:"responder,omitempty"` } func (x *VirtualChannelProposalAccMsg) Reset() { *x = VirtualChannelProposalAccMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[22] + mi := &file_wire_proto_msgTypes[24] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1658,7 +1771,7 @@ func (x *VirtualChannelProposalAccMsg) String() string { func (*VirtualChannelProposalAccMsg) ProtoMessage() {} func (x *VirtualChannelProposalAccMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[22] + mi := &file_wire_proto_msgTypes[24] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1671,7 +1784,7 @@ func (x *VirtualChannelProposalAccMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use VirtualChannelProposalAccMsg.ProtoReflect.Descriptor instead. func (*VirtualChannelProposalAccMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{22} + return file_wire_proto_rawDescGZIP(), []int{24} } func (x *VirtualChannelProposalAccMsg) GetBaseChannelProposalAcc() *BaseChannelProposalAcc { @@ -1681,7 +1794,7 @@ func (x *VirtualChannelProposalAccMsg) GetBaseChannelProposalAcc() *BaseChannelP return nil } -func (x *VirtualChannelProposalAccMsg) GetResponder() []byte { +func (x *VirtualChannelProposalAccMsg) GetResponder() *Address { if x != nil { return x.Responder } @@ -1701,7 +1814,7 @@ type ChannelProposalRejMsg struct { func (x *ChannelProposalRejMsg) Reset() { *x = ChannelProposalRejMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[23] + mi := &file_wire_proto_msgTypes[25] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1714,7 +1827,7 @@ func (x *ChannelProposalRejMsg) String() string { func (*ChannelProposalRejMsg) ProtoMessage() {} func (x *ChannelProposalRejMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[23] + mi := &file_wire_proto_msgTypes[25] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1727,7 +1840,7 @@ func (x *ChannelProposalRejMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use ChannelProposalRejMsg.ProtoReflect.Descriptor instead. func (*ChannelProposalRejMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{23} + return file_wire_proto_rawDescGZIP(), []int{25} } func (x *ChannelProposalRejMsg) GetProposalId() []byte { @@ -1757,7 +1870,7 @@ type ChannelUpdateMsg struct { func (x *ChannelUpdateMsg) Reset() { *x = ChannelUpdateMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[24] + mi := &file_wire_proto_msgTypes[26] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1770,7 +1883,7 @@ func (x *ChannelUpdateMsg) String() string { func (*ChannelUpdateMsg) ProtoMessage() {} func (x *ChannelUpdateMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[24] + mi := &file_wire_proto_msgTypes[26] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1783,7 +1896,7 @@ func (x *ChannelUpdateMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use ChannelUpdateMsg.ProtoReflect.Descriptor instead. func (*ChannelUpdateMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{24} + return file_wire_proto_rawDescGZIP(), []int{26} } func (x *ChannelUpdateMsg) GetChannelUpdate() *ChannelUpdate { @@ -1815,7 +1928,7 @@ type VirtualChannelFundingProposalMsg struct { func (x *VirtualChannelFundingProposalMsg) Reset() { *x = VirtualChannelFundingProposalMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[25] + mi := &file_wire_proto_msgTypes[27] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1828,7 +1941,7 @@ func (x *VirtualChannelFundingProposalMsg) String() string { func (*VirtualChannelFundingProposalMsg) ProtoMessage() {} func (x *VirtualChannelFundingProposalMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[25] + mi := &file_wire_proto_msgTypes[27] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1841,7 +1954,7 @@ func (x *VirtualChannelFundingProposalMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use VirtualChannelFundingProposalMsg.ProtoReflect.Descriptor instead. func (*VirtualChannelFundingProposalMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{25} + return file_wire_proto_rawDescGZIP(), []int{27} } func (x *VirtualChannelFundingProposalMsg) GetChannelUpdateMsg() *ChannelUpdateMsg { @@ -1879,7 +1992,7 @@ type VirtualChannelSettlementProposalMsg struct { func (x *VirtualChannelSettlementProposalMsg) Reset() { *x = VirtualChannelSettlementProposalMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[26] + mi := &file_wire_proto_msgTypes[28] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1892,7 +2005,7 @@ func (x *VirtualChannelSettlementProposalMsg) String() string { func (*VirtualChannelSettlementProposalMsg) ProtoMessage() {} func (x *VirtualChannelSettlementProposalMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[26] + mi := &file_wire_proto_msgTypes[28] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1905,7 +2018,7 @@ func (x *VirtualChannelSettlementProposalMsg) ProtoReflect() protoreflect.Messag // Deprecated: Use VirtualChannelSettlementProposalMsg.ProtoReflect.Descriptor instead. func (*VirtualChannelSettlementProposalMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{26} + return file_wire_proto_rawDescGZIP(), []int{28} } func (x *VirtualChannelSettlementProposalMsg) GetChannelUpdateMsg() *ChannelUpdateMsg { @@ -1936,7 +2049,7 @@ type ChannelUpdateAccMsg struct { func (x *ChannelUpdateAccMsg) Reset() { *x = ChannelUpdateAccMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[27] + mi := &file_wire_proto_msgTypes[29] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1949,7 +2062,7 @@ func (x *ChannelUpdateAccMsg) String() string { func (*ChannelUpdateAccMsg) ProtoMessage() {} func (x *ChannelUpdateAccMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[27] + mi := &file_wire_proto_msgTypes[29] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1962,7 +2075,7 @@ func (x *ChannelUpdateAccMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use ChannelUpdateAccMsg.ProtoReflect.Descriptor instead. func (*ChannelUpdateAccMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{27} + return file_wire_proto_rawDescGZIP(), []int{29} } func (x *ChannelUpdateAccMsg) GetChannelId() []byte { @@ -2000,7 +2113,7 @@ type ChannelUpdateRejMsg struct { func (x *ChannelUpdateRejMsg) Reset() { *x = ChannelUpdateRejMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[28] + mi := &file_wire_proto_msgTypes[30] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2013,7 +2126,7 @@ func (x *ChannelUpdateRejMsg) String() string { func (*ChannelUpdateRejMsg) ProtoMessage() {} func (x *ChannelUpdateRejMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[28] + mi := &file_wire_proto_msgTypes[30] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2026,7 +2139,7 @@ func (x *ChannelUpdateRejMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use ChannelUpdateRejMsg.ProtoReflect.Descriptor instead. func (*ChannelUpdateRejMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{28} + return file_wire_proto_rawDescGZIP(), []int{30} } func (x *ChannelUpdateRejMsg) GetChannelId() []byte { @@ -2063,7 +2176,7 @@ type ChannelSyncMsg struct { func (x *ChannelSyncMsg) Reset() { *x = ChannelSyncMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[29] + mi := &file_wire_proto_msgTypes[31] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2076,7 +2189,7 @@ func (x *ChannelSyncMsg) String() string { func (*ChannelSyncMsg) ProtoMessage() {} func (x *ChannelSyncMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[29] + mi := &file_wire_proto_msgTypes[31] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2089,7 +2202,7 @@ func (x *ChannelSyncMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use ChannelSyncMsg.ProtoReflect.Descriptor instead. func (*ChannelSyncMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{29} + return file_wire_proto_rawDescGZIP(), []int{31} } func (x *ChannelSyncMsg) GetPhase() uint32 { @@ -2110,327 +2223,348 @@ var File_wire_proto protoreflect.FileDescriptor var file_wire_proto_rawDesc = []byte{ 0x0a, 0x0a, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x09, 0x70, 0x65, - 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x22, 0xcd, 0x0c, 0x0a, 0x08, 0x45, 0x6e, 0x76, 0x65, - 0x6c, 0x6f, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x73, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x12, 0x1c, 0x0a, 0x09, - 0x72, 0x65, 0x63, 0x69, 0x70, 0x69, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, - 0x09, 0x72, 0x65, 0x63, 0x69, 0x70, 0x69, 0x65, 0x6e, 0x74, 0x12, 0x2f, 0x0a, 0x08, 0x70, 0x69, - 0x6e, 0x67, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, - 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x4d, 0x73, 0x67, - 0x48, 0x00, 0x52, 0x07, 0x70, 0x69, 0x6e, 0x67, 0x4d, 0x73, 0x67, 0x12, 0x2f, 0x0a, 0x08, 0x70, - 0x6f, 0x6e, 0x67, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, - 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x50, 0x6f, 0x6e, 0x67, 0x4d, 0x73, - 0x67, 0x48, 0x00, 0x52, 0x07, 0x70, 0x6f, 0x6e, 0x67, 0x4d, 0x73, 0x67, 0x12, 0x3b, 0x0a, 0x0c, - 0x73, 0x68, 0x75, 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x05, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x53, - 0x68, 0x75, 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x4d, 0x73, 0x67, 0x48, 0x00, 0x52, 0x0b, 0x73, 0x68, - 0x75, 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x4d, 0x73, 0x67, 0x12, 0x48, 0x0a, 0x11, 0x61, 0x75, 0x74, - 0x68, 0x5f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x06, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, - 0x2e, 0x41, 0x75, 0x74, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x4d, 0x73, 0x67, - 0x48, 0x00, 0x52, 0x0f, 0x61, 0x75, 0x74, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x4d, 0x73, 0x67, 0x12, 0x64, 0x0a, 0x1b, 0x6c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x5f, 0x63, 0x68, - 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x5f, 0x6d, - 0x73, 0x67, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, - 0x77, 0x69, 0x72, 0x65, 0x2e, 0x4c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x43, 0x68, 0x61, 0x6e, 0x6e, - 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x48, 0x00, 0x52, - 0x18, 0x6c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, - 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x12, 0x6e, 0x0a, 0x1f, 0x6c, 0x65, 0x64, - 0x67, 0x65, 0x72, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x70, 0x72, 0x6f, 0x70, - 0x6f, 0x73, 0x61, 0x6c, 0x5f, 0x61, 0x63, 0x63, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x08, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x4c, - 0x65, 0x64, 0x67, 0x65, 0x72, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, - 0x6f, 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x4d, 0x73, 0x67, 0x48, 0x00, 0x52, 0x1b, 0x6c, 0x65, - 0x64, 0x67, 0x65, 0x72, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, - 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x4d, 0x73, 0x67, 0x12, 0x5b, 0x0a, 0x18, 0x73, 0x75, 0x62, + 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x22, 0xf5, 0x0c, 0x0a, 0x08, 0x45, 0x6e, 0x76, 0x65, + 0x6c, 0x6f, 0x70, 0x65, 0x12, 0x2a, 0x0a, 0x06, 0x73, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, + 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x52, 0x06, 0x73, 0x65, 0x6e, 0x64, 0x65, 0x72, + 0x12, 0x30, 0x0a, 0x09, 0x72, 0x65, 0x63, 0x69, 0x70, 0x69, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, + 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x52, 0x09, 0x72, 0x65, 0x63, 0x69, 0x70, 0x69, 0x65, + 0x6e, 0x74, 0x12, 0x2f, 0x0a, 0x08, 0x70, 0x69, 0x6e, 0x67, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, + 0x2e, 0x50, 0x69, 0x6e, 0x67, 0x4d, 0x73, 0x67, 0x48, 0x00, 0x52, 0x07, 0x70, 0x69, 0x6e, 0x67, + 0x4d, 0x73, 0x67, 0x12, 0x2f, 0x0a, 0x08, 0x70, 0x6f, 0x6e, 0x67, 0x5f, 0x6d, 0x73, 0x67, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, + 0x65, 0x2e, 0x50, 0x6f, 0x6e, 0x67, 0x4d, 0x73, 0x67, 0x48, 0x00, 0x52, 0x07, 0x70, 0x6f, 0x6e, + 0x67, 0x4d, 0x73, 0x67, 0x12, 0x3b, 0x0a, 0x0c, 0x73, 0x68, 0x75, 0x74, 0x64, 0x6f, 0x77, 0x6e, + 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x70, 0x65, 0x72, + 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x53, 0x68, 0x75, 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x4d, + 0x73, 0x67, 0x48, 0x00, 0x52, 0x0b, 0x73, 0x68, 0x75, 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x4d, 0x73, + 0x67, 0x12, 0x48, 0x0a, 0x11, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x70, + 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x41, 0x75, 0x74, 0x68, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x4d, 0x73, 0x67, 0x48, 0x00, 0x52, 0x0f, 0x61, 0x75, 0x74, 0x68, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x4d, 0x73, 0x67, 0x12, 0x64, 0x0a, 0x1b, 0x6c, + 0x65, 0x64, 0x67, 0x65, 0x72, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x70, 0x72, + 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x23, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x4c, 0x65, 0x64, + 0x67, 0x65, 0x72, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, + 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x48, 0x00, 0x52, 0x18, 0x6c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x43, + 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x73, + 0x67, 0x12, 0x6e, 0x0a, 0x1f, 0x6c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x5f, 0x63, 0x68, 0x61, 0x6e, + 0x6e, 0x65, 0x6c, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x5f, 0x61, 0x63, 0x63, + 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x70, 0x65, 0x72, + 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x4c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x43, 0x68, 0x61, + 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x4d, + 0x73, 0x67, 0x48, 0x00, 0x52, 0x1b, 0x6c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x43, 0x68, 0x61, 0x6e, + 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x4d, 0x73, + 0x67, 0x12, 0x5b, 0x0a, 0x18, 0x73, 0x75, 0x62, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, + 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x09, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, + 0x53, 0x75, 0x62, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, + 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x48, 0x00, 0x52, 0x15, 0x73, 0x75, 0x62, 0x43, 0x68, 0x61, 0x6e, + 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x12, 0x65, + 0x0a, 0x1c, 0x73, 0x75, 0x62, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x70, 0x72, + 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x5f, 0x61, 0x63, 0x63, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x0a, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, + 0x2e, 0x53, 0x75, 0x62, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, + 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x4d, 0x73, 0x67, 0x48, 0x00, 0x52, 0x18, 0x73, 0x75, 0x62, + 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x41, + 0x63, 0x63, 0x4d, 0x73, 0x67, 0x12, 0x67, 0x0a, 0x1c, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, - 0x6c, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x09, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x70, 0x65, - 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x53, 0x75, 0x62, 0x43, 0x68, 0x61, 0x6e, 0x6e, - 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x48, 0x00, 0x52, - 0x15, 0x73, 0x75, 0x62, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, - 0x73, 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x12, 0x65, 0x0a, 0x1c, 0x73, 0x75, 0x62, 0x5f, 0x63, 0x68, - 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x5f, 0x61, - 0x63, 0x63, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x70, - 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x53, 0x75, 0x62, 0x43, 0x68, 0x61, 0x6e, + 0x6c, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x70, 0x65, + 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x56, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x43, + 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x73, + 0x67, 0x48, 0x00, 0x52, 0x19, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x43, 0x68, 0x61, 0x6e, + 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x12, 0x71, + 0x0a, 0x20, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, + 0x6c, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x5f, 0x61, 0x63, 0x63, 0x5f, 0x6d, + 0x73, 0x67, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, + 0x77, 0x69, 0x72, 0x65, 0x2e, 0x56, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x4d, 0x73, - 0x67, 0x48, 0x00, 0x52, 0x18, 0x73, 0x75, 0x62, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, - 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x4d, 0x73, 0x67, 0x12, 0x67, 0x0a, - 0x1c, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, - 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x0b, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, - 0x56, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, - 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x48, 0x00, 0x52, 0x19, 0x76, 0x69, 0x72, - 0x74, 0x75, 0x61, 0x6c, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, - 0x73, 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x12, 0x71, 0x0a, 0x20, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, - 0x6c, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, - 0x61, 0x6c, 0x5f, 0x61, 0x63, 0x63, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x27, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x56, 0x69, 0x72, - 0x74, 0x75, 0x61, 0x6c, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, - 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x4d, 0x73, 0x67, 0x48, 0x00, 0x52, 0x1c, 0x76, 0x69, 0x72, - 0x74, 0x75, 0x61, 0x6c, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, - 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x4d, 0x73, 0x67, 0x12, 0x5b, 0x0a, 0x18, 0x63, 0x68, 0x61, - 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x5f, 0x72, 0x65, - 0x6a, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x70, 0x65, - 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, - 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x52, 0x65, 0x6a, 0x4d, 0x73, 0x67, 0x48, 0x00, 0x52, - 0x15, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, - 0x52, 0x65, 0x6a, 0x4d, 0x73, 0x67, 0x12, 0x4b, 0x0a, 0x12, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, - 0x6c, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x0e, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x43, - 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4d, 0x73, 0x67, 0x48, - 0x00, 0x52, 0x10, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, - 0x4d, 0x73, 0x67, 0x12, 0x7d, 0x0a, 0x24, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x5f, 0x63, - 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x66, 0x75, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x5f, 0x70, - 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x0f, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x2b, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x56, 0x69, - 0x72, 0x74, 0x75, 0x61, 0x6c, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x46, 0x75, 0x6e, 0x64, - 0x69, 0x6e, 0x67, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x48, 0x00, - 0x52, 0x20, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, - 0x46, 0x75, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, - 0x73, 0x67, 0x12, 0x86, 0x01, 0x0a, 0x27, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x5f, 0x63, - 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x73, 0x65, 0x74, 0x74, 0x6c, 0x65, 0x6d, 0x65, 0x6e, - 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x10, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2e, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, - 0x2e, 0x56, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x53, - 0x65, 0x74, 0x74, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, - 0x6c, 0x4d, 0x73, 0x67, 0x48, 0x00, 0x52, 0x23, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x43, - 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x53, 0x65, 0x74, 0x74, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, - 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x12, 0x55, 0x0a, 0x16, 0x63, - 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x61, 0x63, - 0x63, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x11, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x70, 0x65, - 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, - 0x70, 0x64, 0x61, 0x74, 0x65, 0x41, 0x63, 0x63, 0x4d, 0x73, 0x67, 0x48, 0x00, 0x52, 0x13, 0x63, - 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x41, 0x63, 0x63, 0x4d, - 0x73, 0x67, 0x12, 0x55, 0x0a, 0x16, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x75, 0x70, - 0x64, 0x61, 0x74, 0x65, 0x5f, 0x72, 0x65, 0x6a, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x12, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x43, - 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x6a, 0x4d, - 0x73, 0x67, 0x48, 0x00, 0x52, 0x13, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, - 0x61, 0x74, 0x65, 0x52, 0x65, 0x6a, 0x4d, 0x73, 0x67, 0x12, 0x45, 0x0a, 0x10, 0x63, 0x68, 0x61, - 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x73, 0x79, 0x6e, 0x63, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x13, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, - 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x53, 0x79, 0x6e, 0x63, 0x4d, 0x73, 0x67, 0x48, 0x00, - 0x52, 0x0e, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x53, 0x79, 0x6e, 0x63, 0x4d, 0x73, 0x67, - 0x42, 0x05, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x22, 0x23, 0x0a, 0x07, 0x42, 0x61, 0x6c, 0x61, 0x6e, - 0x63, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, - 0x03, 0x28, 0x0c, 0x52, 0x07, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x22, 0x3a, 0x0a, 0x08, - 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x73, 0x12, 0x2e, 0x0a, 0x08, 0x62, 0x61, 0x6c, 0x61, - 0x6e, 0x63, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, 0x65, 0x72, - 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x08, - 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x73, 0x22, 0x27, 0x0a, 0x08, 0x49, 0x6e, 0x64, 0x65, - 0x78, 0x4d, 0x61, 0x70, 0x12, 0x1b, 0x0a, 0x09, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x5f, 0x6d, 0x61, - 0x70, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0d, 0x52, 0x08, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x4d, 0x61, - 0x70, 0x22, 0x74, 0x0a, 0x08, 0x53, 0x75, 0x62, 0x41, 0x6c, 0x6c, 0x6f, 0x63, 0x12, 0x0e, 0x0a, - 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x02, 0x69, 0x64, 0x12, 0x26, 0x0a, - 0x04, 0x62, 0x61, 0x6c, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, 0x65, - 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, - 0x04, 0x62, 0x61, 0x6c, 0x73, 0x12, 0x30, 0x0a, 0x09, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x5f, 0x6d, - 0x61, 0x70, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, - 0x77, 0x69, 0x72, 0x65, 0x2e, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x4d, 0x61, 0x70, 0x52, 0x08, 0x69, - 0x6e, 0x64, 0x65, 0x78, 0x4d, 0x61, 0x70, 0x22, 0x82, 0x01, 0x0a, 0x0a, 0x41, 0x6c, 0x6c, 0x6f, - 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x73, 0x73, 0x65, 0x74, 0x73, - 0x18, 0x01, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x06, 0x61, 0x73, 0x73, 0x65, 0x74, 0x73, 0x12, 0x2f, - 0x0a, 0x08, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x13, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x42, 0x61, 0x6c, - 0x61, 0x6e, 0x63, 0x65, 0x73, 0x52, 0x08, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x73, 0x12, - 0x2b, 0x0a, 0x06, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, - 0x13, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x53, 0x75, 0x62, 0x41, - 0x6c, 0x6c, 0x6f, 0x63, 0x52, 0x06, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x22, 0xab, 0x02, 0x0a, - 0x13, 0x42, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, - 0x6f, 0x73, 0x61, 0x6c, 0x12, 0x1f, 0x0a, 0x0b, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, - 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x70, 0x72, 0x6f, 0x70, 0x6f, - 0x73, 0x61, 0x6c, 0x49, 0x64, 0x12, 0x2d, 0x0a, 0x12, 0x63, 0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, - 0x67, 0x65, 0x5f, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x04, 0x52, 0x11, 0x63, 0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, 0x67, 0x65, 0x44, 0x75, 0x72, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1f, 0x0a, 0x0b, 0x6e, 0x6f, 0x6e, 0x63, 0x65, 0x5f, 0x73, 0x68, - 0x61, 0x72, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x6e, 0x6f, 0x6e, 0x63, 0x65, - 0x53, 0x68, 0x61, 0x72, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x61, 0x70, 0x70, 0x18, 0x04, 0x20, 0x01, - 0x28, 0x0c, 0x52, 0x03, 0x61, 0x70, 0x70, 0x12, 0x1b, 0x0a, 0x09, 0x69, 0x6e, 0x69, 0x74, 0x5f, - 0x64, 0x61, 0x74, 0x61, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x69, 0x6e, 0x69, 0x74, - 0x44, 0x61, 0x74, 0x61, 0x12, 0x32, 0x0a, 0x09, 0x69, 0x6e, 0x69, 0x74, 0x5f, 0x62, 0x61, 0x6c, - 0x73, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, - 0x69, 0x72, 0x65, 0x2e, 0x41, 0x6c, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x08, - 0x69, 0x6e, 0x69, 0x74, 0x42, 0x61, 0x6c, 0x73, 0x12, 0x40, 0x0a, 0x11, 0x66, 0x75, 0x6e, 0x64, - 0x69, 0x6e, 0x67, 0x5f, 0x61, 0x67, 0x72, 0x65, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x07, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, - 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x73, 0x52, 0x10, 0x66, 0x75, 0x6e, 0x64, 0x69, 0x6e, - 0x67, 0x41, 0x67, 0x72, 0x65, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x5a, 0x0a, 0x16, 0x42, 0x61, - 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, - 0x6c, 0x41, 0x63, 0x63, 0x12, 0x1f, 0x0a, 0x0b, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, - 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x70, 0x72, 0x6f, 0x70, 0x6f, - 0x73, 0x61, 0x6c, 0x49, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x6e, 0x6f, 0x6e, 0x63, 0x65, 0x5f, 0x73, - 0x68, 0x61, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x6e, 0x6f, 0x6e, 0x63, - 0x65, 0x53, 0x68, 0x61, 0x72, 0x65, 0x22, 0xd5, 0x01, 0x0a, 0x06, 0x50, 0x61, 0x72, 0x61, 0x6d, - 0x73, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x02, 0x69, - 0x64, 0x12, 0x2d, 0x0a, 0x12, 0x63, 0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, 0x67, 0x65, 0x5f, 0x64, - 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x11, 0x63, - 0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, 0x67, 0x65, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x12, 0x14, 0x0a, 0x05, 0x70, 0x61, 0x72, 0x74, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0c, 0x52, - 0x05, 0x70, 0x61, 0x72, 0x74, 0x73, 0x12, 0x10, 0x0a, 0x03, 0x61, 0x70, 0x70, 0x18, 0x04, 0x20, - 0x01, 0x28, 0x0c, 0x52, 0x03, 0x61, 0x70, 0x70, 0x12, 0x14, 0x0a, 0x05, 0x6e, 0x6f, 0x6e, 0x63, - 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x6e, 0x6f, 0x6e, 0x63, 0x65, 0x12, 0x25, - 0x0a, 0x0e, 0x6c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, - 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0d, 0x6c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x43, 0x68, - 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x12, 0x27, 0x0a, 0x0f, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, - 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0e, - 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x22, 0xa9, - 0x01, 0x0a, 0x05, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x0c, 0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, - 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, - 0x6f, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x61, 0x70, 0x70, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, - 0x03, 0x61, 0x70, 0x70, 0x12, 0x35, 0x0a, 0x0a, 0x61, 0x6c, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, - 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, + 0x67, 0x48, 0x00, 0x52, 0x1c, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x43, 0x68, 0x61, 0x6e, + 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x4d, 0x73, + 0x67, 0x12, 0x5b, 0x0a, 0x18, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x70, 0x72, 0x6f, + 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x5f, 0x72, 0x65, 0x6a, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x0d, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, + 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x52, + 0x65, 0x6a, 0x4d, 0x73, 0x67, 0x48, 0x00, 0x52, 0x15, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, + 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x52, 0x65, 0x6a, 0x4d, 0x73, 0x67, 0x12, 0x4b, + 0x0a, 0x12, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x70, 0x65, 0x72, + 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, + 0x64, 0x61, 0x74, 0x65, 0x4d, 0x73, 0x67, 0x48, 0x00, 0x52, 0x10, 0x63, 0x68, 0x61, 0x6e, 0x6e, + 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4d, 0x73, 0x67, 0x12, 0x7d, 0x0a, 0x24, 0x76, + 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x66, + 0x75, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x5f, + 0x6d, 0x73, 0x67, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2b, 0x2e, 0x70, 0x65, 0x72, 0x75, + 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x56, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x43, 0x68, 0x61, + 0x6e, 0x6e, 0x65, 0x6c, 0x46, 0x75, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x50, 0x72, 0x6f, 0x70, 0x6f, + 0x73, 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x48, 0x00, 0x52, 0x20, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, + 0x6c, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x46, 0x75, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x50, + 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x12, 0x86, 0x01, 0x0a, 0x27, 0x76, + 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x73, + 0x65, 0x74, 0x74, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, + 0x61, 0x6c, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x10, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x2e, 0x2e, 0x70, + 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x56, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, + 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x53, 0x65, 0x74, 0x74, 0x6c, 0x65, 0x6d, 0x65, 0x6e, + 0x74, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x48, 0x00, 0x52, 0x23, + 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x53, 0x65, + 0x74, 0x74, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, + 0x4d, 0x73, 0x67, 0x12, 0x55, 0x0a, 0x16, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x75, + 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x61, 0x63, 0x63, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x11, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, + 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x41, 0x63, 0x63, + 0x4d, 0x73, 0x67, 0x48, 0x00, 0x52, 0x13, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, + 0x64, 0x61, 0x74, 0x65, 0x41, 0x63, 0x63, 0x4d, 0x73, 0x67, 0x12, 0x55, 0x0a, 0x16, 0x63, 0x68, + 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x72, 0x65, 0x6a, + 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x12, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x70, 0x65, 0x72, + 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, + 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x6a, 0x4d, 0x73, 0x67, 0x48, 0x00, 0x52, 0x13, 0x63, 0x68, + 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x6a, 0x4d, 0x73, + 0x67, 0x12, 0x45, 0x0a, 0x10, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x73, 0x79, 0x6e, + 0x63, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x13, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x70, 0x65, + 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x53, + 0x79, 0x6e, 0x63, 0x4d, 0x73, 0x67, 0x48, 0x00, 0x52, 0x0e, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, + 0x6c, 0x53, 0x79, 0x6e, 0x63, 0x4d, 0x73, 0x67, 0x42, 0x05, 0x0a, 0x03, 0x6d, 0x73, 0x67, 0x22, + 0x23, 0x0a, 0x07, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x62, 0x61, + 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x07, 0x62, 0x61, 0x6c, + 0x61, 0x6e, 0x63, 0x65, 0x22, 0x3a, 0x0a, 0x08, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x73, + 0x12, 0x2e, 0x0a, 0x08, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, + 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x42, + 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x08, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x73, + 0x22, 0x3c, 0x0a, 0x0e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x4d, 0x61, 0x70, 0x70, 0x69, + 0x6e, 0x67, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, + 0x03, 0x6b, 0x65, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x22, 0x4d, + 0x0a, 0x07, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x42, 0x0a, 0x0f, 0x61, 0x64, 0x64, + 0x72, 0x65, 0x73, 0x73, 0x5f, 0x6d, 0x61, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x18, 0x01, 0x20, 0x03, + 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x41, + 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x4d, 0x61, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x52, 0x0e, 0x61, + 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x4d, 0x61, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x22, 0x27, 0x0a, + 0x08, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x4d, 0x61, 0x70, 0x12, 0x1b, 0x0a, 0x09, 0x69, 0x6e, 0x64, + 0x65, 0x78, 0x5f, 0x6d, 0x61, 0x70, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0d, 0x52, 0x08, 0x69, 0x6e, + 0x64, 0x65, 0x78, 0x4d, 0x61, 0x70, 0x22, 0x74, 0x0a, 0x08, 0x53, 0x75, 0x62, 0x41, 0x6c, 0x6c, + 0x6f, 0x63, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x02, + 0x69, 0x64, 0x12, 0x26, 0x0a, 0x04, 0x62, 0x61, 0x6c, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x12, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x42, 0x61, 0x6c, + 0x61, 0x6e, 0x63, 0x65, 0x52, 0x04, 0x62, 0x61, 0x6c, 0x73, 0x12, 0x30, 0x0a, 0x09, 0x69, 0x6e, + 0x64, 0x65, 0x78, 0x5f, 0x6d, 0x61, 0x70, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, + 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x4d, + 0x61, 0x70, 0x52, 0x08, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x4d, 0x61, 0x70, 0x22, 0x9e, 0x01, 0x0a, + 0x0a, 0x41, 0x6c, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x62, + 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x08, 0x62, + 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x73, 0x73, 0x65, 0x74, + 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x06, 0x61, 0x73, 0x73, 0x65, 0x74, 0x73, 0x12, + 0x2f, 0x0a, 0x08, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x13, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x42, 0x61, + 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x73, 0x52, 0x08, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x73, + 0x12, 0x2b, 0x0a, 0x06, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x13, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x53, 0x75, 0x62, + 0x41, 0x6c, 0x6c, 0x6f, 0x63, 0x52, 0x06, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x22, 0xab, 0x02, + 0x0a, 0x13, 0x42, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, + 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x12, 0x1f, 0x0a, 0x0b, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, + 0x6c, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x70, 0x72, 0x6f, 0x70, + 0x6f, 0x73, 0x61, 0x6c, 0x49, 0x64, 0x12, 0x2d, 0x0a, 0x12, 0x63, 0x68, 0x61, 0x6c, 0x6c, 0x65, + 0x6e, 0x67, 0x65, 0x5f, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x04, 0x52, 0x11, 0x63, 0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, 0x67, 0x65, 0x44, 0x75, 0x72, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1f, 0x0a, 0x0b, 0x6e, 0x6f, 0x6e, 0x63, 0x65, 0x5f, 0x73, + 0x68, 0x61, 0x72, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x6e, 0x6f, 0x6e, 0x63, + 0x65, 0x53, 0x68, 0x61, 0x72, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x61, 0x70, 0x70, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x03, 0x61, 0x70, 0x70, 0x12, 0x1b, 0x0a, 0x09, 0x69, 0x6e, 0x69, 0x74, + 0x5f, 0x64, 0x61, 0x74, 0x61, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x69, 0x6e, 0x69, + 0x74, 0x44, 0x61, 0x74, 0x61, 0x12, 0x32, 0x0a, 0x09, 0x69, 0x6e, 0x69, 0x74, 0x5f, 0x62, 0x61, + 0x6c, 0x73, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x41, 0x6c, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, - 0x0a, 0x61, 0x6c, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x64, - 0x61, 0x74, 0x61, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, - 0x19, 0x0a, 0x08, 0x69, 0x73, 0x5f, 0x66, 0x69, 0x6e, 0x61, 0x6c, 0x18, 0x06, 0x20, 0x01, 0x28, - 0x08, 0x52, 0x07, 0x69, 0x73, 0x46, 0x69, 0x6e, 0x61, 0x6c, 0x22, 0x49, 0x0a, 0x0b, 0x54, 0x72, - 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x26, 0x0a, 0x05, 0x73, 0x74, 0x61, - 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, - 0x77, 0x69, 0x72, 0x65, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, - 0x65, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x69, 0x67, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0c, 0x52, - 0x04, 0x73, 0x69, 0x67, 0x73, 0x22, 0x74, 0x0a, 0x0b, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x53, - 0x74, 0x61, 0x74, 0x65, 0x12, 0x29, 0x0a, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, - 0x2e, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, - 0x26, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, - 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x65, - 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x69, 0x67, 0x73, 0x18, - 0x03, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x04, 0x73, 0x69, 0x67, 0x73, 0x22, 0x54, 0x0a, 0x0d, 0x43, - 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x26, 0x0a, 0x05, - 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x70, 0x65, - 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x05, 0x73, - 0x74, 0x61, 0x74, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x5f, 0x69, 0x64, - 0x78, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x49, 0x64, - 0x78, 0x22, 0x23, 0x0a, 0x07, 0x50, 0x69, 0x6e, 0x67, 0x4d, 0x73, 0x67, 0x12, 0x18, 0x0a, 0x07, - 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x63, - 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x22, 0x23, 0x0a, 0x07, 0x50, 0x6f, 0x6e, 0x67, 0x4d, 0x73, + 0x08, 0x69, 0x6e, 0x69, 0x74, 0x42, 0x61, 0x6c, 0x73, 0x12, 0x40, 0x0a, 0x11, 0x66, 0x75, 0x6e, + 0x64, 0x69, 0x6e, 0x67, 0x5f, 0x61, 0x67, 0x72, 0x65, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x07, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, + 0x2e, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x73, 0x52, 0x10, 0x66, 0x75, 0x6e, 0x64, 0x69, + 0x6e, 0x67, 0x41, 0x67, 0x72, 0x65, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x5a, 0x0a, 0x16, 0x42, + 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, + 0x61, 0x6c, 0x41, 0x63, 0x63, 0x12, 0x1f, 0x0a, 0x0b, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, + 0x6c, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x70, 0x72, 0x6f, 0x70, + 0x6f, 0x73, 0x61, 0x6c, 0x49, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x6e, 0x6f, 0x6e, 0x63, 0x65, 0x5f, + 0x73, 0x68, 0x61, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x6e, 0x6f, 0x6e, + 0x63, 0x65, 0x53, 0x68, 0x61, 0x72, 0x65, 0x22, 0xe9, 0x01, 0x0a, 0x06, 0x50, 0x61, 0x72, 0x61, + 0x6d, 0x73, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x02, + 0x69, 0x64, 0x12, 0x2d, 0x0a, 0x12, 0x63, 0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, 0x67, 0x65, 0x5f, + 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x11, + 0x63, 0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, 0x67, 0x65, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x12, 0x28, 0x0a, 0x05, 0x70, 0x61, 0x72, 0x74, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x12, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x41, 0x64, 0x64, + 0x72, 0x65, 0x73, 0x73, 0x52, 0x05, 0x70, 0x61, 0x72, 0x74, 0x73, 0x12, 0x10, 0x0a, 0x03, 0x61, + 0x70, 0x70, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x61, 0x70, 0x70, 0x12, 0x14, 0x0a, + 0x05, 0x6e, 0x6f, 0x6e, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x6e, 0x6f, + 0x6e, 0x63, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x6c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x5f, 0x63, 0x68, + 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0d, 0x6c, 0x65, 0x64, + 0x67, 0x65, 0x72, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x12, 0x27, 0x0a, 0x0f, 0x76, 0x69, + 0x72, 0x74, 0x75, 0x61, 0x6c, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x18, 0x07, 0x20, + 0x01, 0x28, 0x08, 0x52, 0x0e, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x43, 0x68, 0x61, 0x6e, + 0x6e, 0x65, 0x6c, 0x22, 0xa9, 0x01, 0x0a, 0x05, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x0e, 0x0a, + 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, + 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x07, + 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x61, 0x70, 0x70, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x61, 0x70, 0x70, 0x12, 0x35, 0x0a, 0x0a, 0x61, 0x6c, 0x6c, + 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, + 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x41, 0x6c, 0x6c, 0x6f, 0x63, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0a, 0x61, 0x6c, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, + 0x64, 0x61, 0x74, 0x61, 0x12, 0x19, 0x0a, 0x08, 0x69, 0x73, 0x5f, 0x66, 0x69, 0x6e, 0x61, 0x6c, + 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x69, 0x73, 0x46, 0x69, 0x6e, 0x61, 0x6c, 0x22, + 0x49, 0x0a, 0x0b, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x26, + 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, + 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, + 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x69, 0x67, 0x73, 0x18, 0x02, + 0x20, 0x03, 0x28, 0x0c, 0x52, 0x04, 0x73, 0x69, 0x67, 0x73, 0x22, 0x74, 0x0a, 0x0b, 0x53, 0x69, + 0x67, 0x6e, 0x65, 0x64, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x29, 0x0a, 0x06, 0x70, 0x61, 0x72, + 0x61, 0x6d, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x70, 0x65, 0x72, 0x75, + 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x06, 0x70, 0x61, + 0x72, 0x61, 0x6d, 0x73, 0x12, 0x26, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, + 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x12, 0x12, 0x0a, 0x04, + 0x73, 0x69, 0x67, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x04, 0x73, 0x69, 0x67, 0x73, + 0x22, 0x54, 0x0a, 0x0d, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, + 0x65, 0x12, 0x26, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x10, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x53, 0x74, 0x61, + 0x74, 0x65, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x61, 0x63, 0x74, + 0x6f, 0x72, 0x5f, 0x69, 0x64, 0x78, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x61, 0x63, + 0x74, 0x6f, 0x72, 0x49, 0x64, 0x78, 0x22, 0x23, 0x0a, 0x07, 0x50, 0x69, 0x6e, 0x67, 0x4d, 0x73, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x03, 0x52, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x22, 0x25, 0x0a, 0x0b, 0x53, - 0x68, 0x75, 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x4d, 0x73, 0x67, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, - 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x61, 0x73, - 0x6f, 0x6e, 0x22, 0x2f, 0x0a, 0x0f, 0x41, 0x75, 0x74, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x4d, 0x73, 0x67, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, - 0x72, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, - 0x75, 0x72, 0x65, 0x22, 0xa6, 0x01, 0x0a, 0x18, 0x4c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x43, 0x68, - 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x73, 0x67, - 0x12, 0x52, 0x0a, 0x15, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, - 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x1e, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x42, 0x61, 0x73, 0x65, - 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x52, - 0x13, 0x62, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, - 0x6f, 0x73, 0x61, 0x6c, 0x12, 0x20, 0x0a, 0x0b, 0x70, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, - 0x61, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x70, 0x61, 0x72, 0x74, 0x69, - 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, 0x18, - 0x03, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, 0x22, 0x9d, 0x01, 0x0a, - 0x1b, 0x4c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, - 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x4d, 0x73, 0x67, 0x12, 0x5c, 0x0a, 0x19, - 0x62, 0x61, 0x73, 0x65, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x70, 0x72, 0x6f, - 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x5f, 0x61, 0x63, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x21, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x42, 0x61, 0x73, 0x65, - 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x41, - 0x63, 0x63, 0x52, 0x16, 0x62, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, - 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x12, 0x20, 0x0a, 0x0b, 0x70, 0x61, - 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, - 0x0b, 0x70, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x22, 0x83, 0x01, 0x0a, - 0x15, 0x53, 0x75, 0x62, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, - 0x73, 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x12, 0x52, 0x0a, 0x15, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x63, - 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, - 0x65, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, - 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x52, 0x13, 0x62, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, - 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x61, - 0x72, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x70, 0x61, 0x72, 0x65, - 0x6e, 0x74, 0x22, 0x78, 0x0a, 0x18, 0x53, 0x75, 0x62, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, - 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x4d, 0x73, 0x67, 0x12, 0x5c, - 0x0a, 0x19, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x70, - 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x5f, 0x61, 0x63, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x21, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x42, 0x61, - 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, - 0x6c, 0x41, 0x63, 0x63, 0x52, 0x16, 0x62, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, - 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x22, 0xef, 0x01, 0x0a, - 0x19, 0x56, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, - 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x12, 0x52, 0x0a, 0x15, 0x62, 0x61, - 0x73, 0x65, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x6f, - 0x73, 0x61, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x70, 0x65, 0x72, 0x75, - 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, - 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x52, 0x13, 0x62, 0x61, 0x73, 0x65, 0x43, - 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x12, 0x1a, - 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, - 0x52, 0x08, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x65, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x65, - 0x65, 0x72, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, - 0x12, 0x18, 0x0a, 0x07, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, - 0x0c, 0x52, 0x07, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x32, 0x0a, 0x0a, 0x69, 0x6e, - 0x64, 0x65, 0x78, 0x5f, 0x6d, 0x61, 0x70, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x13, - 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x49, 0x6e, 0x64, 0x65, 0x78, - 0x4d, 0x61, 0x70, 0x52, 0x09, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x4d, 0x61, 0x70, 0x73, 0x22, 0x9a, - 0x01, 0x0a, 0x1c, 0x56, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, + 0x28, 0x03, 0x52, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x22, 0x23, 0x0a, 0x07, 0x50, + 0x6f, 0x6e, 0x67, 0x4d, 0x73, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, + 0x22, 0x25, 0x0a, 0x0b, 0x53, 0x68, 0x75, 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x4d, 0x73, 0x67, 0x12, + 0x16, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x22, 0x2f, 0x0a, 0x0f, 0x41, 0x75, 0x74, 0x68, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x4d, 0x73, 0x67, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x69, + 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x73, + 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x22, 0xce, 0x01, 0x0a, 0x18, 0x4c, 0x65, 0x64, + 0x67, 0x65, 0x72, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, + 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x12, 0x52, 0x0a, 0x15, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x63, 0x68, + 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, + 0x2e, 0x42, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, + 0x6f, 0x73, 0x61, 0x6c, 0x52, 0x13, 0x62, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, + 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x12, 0x34, 0x0a, 0x0b, 0x70, 0x61, 0x72, + 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, + 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, + 0x73, 0x73, 0x52, 0x0b, 0x70, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x12, + 0x28, 0x0a, 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x12, + 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, + 0x73, 0x73, 0x52, 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, 0x22, 0xb1, 0x01, 0x0a, 0x1b, 0x4c, 0x65, + 0x64, 0x67, 0x65, 0x72, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, + 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x4d, 0x73, 0x67, 0x12, 0x5c, 0x0a, 0x19, 0x62, 0x61, 0x73, + 0x65, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, + 0x61, 0x6c, 0x5f, 0x61, 0x63, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x70, + 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, + 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x52, + 0x16, 0x62, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, + 0x6f, 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x12, 0x34, 0x0a, 0x0b, 0x70, 0x61, 0x72, 0x74, 0x69, + 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, + 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, + 0x52, 0x0b, 0x70, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x22, 0x83, 0x01, + 0x0a, 0x15, 0x53, 0x75, 0x62, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, + 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x12, 0x52, 0x0a, 0x15, 0x62, 0x61, 0x73, 0x65, 0x5f, + 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, + 0x72, 0x65, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, + 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x52, 0x13, 0x62, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, + 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x12, 0x16, 0x0a, 0x06, 0x70, + 0x61, 0x72, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x70, 0x61, 0x72, + 0x65, 0x6e, 0x74, 0x22, 0x78, 0x0a, 0x18, 0x53, 0x75, 0x62, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x4d, 0x73, 0x67, 0x12, 0x5c, 0x0a, 0x19, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x5f, 0x61, 0x63, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x52, 0x16, 0x62, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, - 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x12, 0x1c, 0x0a, - 0x09, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, - 0x52, 0x09, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x22, 0x50, 0x0a, 0x15, 0x43, - 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x52, 0x65, - 0x6a, 0x4d, 0x73, 0x67, 0x12, 0x1f, 0x0a, 0x0b, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, - 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x70, 0x72, 0x6f, 0x70, 0x6f, - 0x73, 0x61, 0x6c, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x22, 0x65, 0x0a, - 0x10, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4d, 0x73, - 0x67, 0x12, 0x3f, 0x0a, 0x0e, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x75, 0x70, 0x64, - 0x61, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x70, 0x65, 0x72, 0x75, + 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x22, 0x97, 0x02, + 0x0a, 0x19, 0x56, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, + 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x12, 0x52, 0x0a, 0x15, 0x62, + 0x61, 0x73, 0x65, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x70, 0x72, 0x6f, 0x70, + 0x6f, 0x73, 0x61, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x70, 0x65, 0x72, + 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, + 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x52, 0x13, 0x62, 0x61, 0x73, 0x65, + 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x12, + 0x2e, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x12, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x41, 0x64, + 0x64, 0x72, 0x65, 0x73, 0x73, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x65, 0x72, 0x12, + 0x28, 0x0a, 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x12, + 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, + 0x73, 0x73, 0x52, 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x61, 0x72, + 0x65, 0x6e, 0x74, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x07, 0x70, 0x61, 0x72, 0x65, + 0x6e, 0x74, 0x73, 0x12, 0x32, 0x0a, 0x0a, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x5f, 0x6d, 0x61, 0x70, + 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, + 0x69, 0x72, 0x65, 0x2e, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x4d, 0x61, 0x70, 0x52, 0x09, 0x69, 0x6e, + 0x64, 0x65, 0x78, 0x4d, 0x61, 0x70, 0x73, 0x22, 0xae, 0x01, 0x0a, 0x1c, 0x56, 0x69, 0x72, 0x74, + 0x75, 0x61, 0x6c, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, + 0x61, 0x6c, 0x41, 0x63, 0x63, 0x4d, 0x73, 0x67, 0x12, 0x5c, 0x0a, 0x19, 0x62, 0x61, 0x73, 0x65, + 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, + 0x6c, 0x5f, 0x61, 0x63, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x70, 0x65, + 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, + 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x52, 0x16, + 0x62, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, + 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x12, 0x30, 0x0a, 0x09, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x64, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, 0x65, 0x72, 0x75, + 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x52, 0x09, 0x72, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x22, 0x50, 0x0a, 0x15, 0x43, 0x68, 0x61, 0x6e, + 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x52, 0x65, 0x6a, 0x4d, 0x73, + 0x67, 0x12, 0x1f, 0x0a, 0x0b, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x5f, 0x69, 0x64, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, + 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x22, 0x65, 0x0a, 0x10, 0x43, 0x68, + 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4d, 0x73, 0x67, 0x12, 0x3f, + 0x0a, 0x0e, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, + 0x72, 0x65, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x52, 0x0d, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, + 0x10, 0x0a, 0x03, 0x73, 0x69, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x73, 0x69, + 0x67, 0x22, 0xd1, 0x01, 0x0a, 0x20, 0x56, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x43, 0x68, 0x61, + 0x6e, 0x6e, 0x65, 0x6c, 0x46, 0x75, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x50, 0x72, 0x6f, 0x70, 0x6f, + 0x73, 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x12, 0x49, 0x0a, 0x12, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, + 0x6c, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x43, + 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4d, 0x73, 0x67, 0x52, + 0x10, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4d, 0x73, + 0x67, 0x12, 0x30, 0x0a, 0x07, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x53, + 0x69, 0x67, 0x6e, 0x65, 0x64, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x07, 0x69, 0x6e, 0x69, 0x74, + 0x69, 0x61, 0x6c, 0x12, 0x30, 0x0a, 0x09, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x5f, 0x6d, 0x61, 0x70, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, + 0x72, 0x65, 0x2e, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x4d, 0x61, 0x70, 0x52, 0x08, 0x69, 0x6e, 0x64, + 0x65, 0x78, 0x4d, 0x61, 0x70, 0x22, 0x9e, 0x01, 0x0a, 0x23, 0x56, 0x69, 0x72, 0x74, 0x75, 0x61, + 0x6c, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x53, 0x65, 0x74, 0x74, 0x6c, 0x65, 0x6d, 0x65, + 0x6e, 0x74, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x12, 0x49, 0x0a, + 0x12, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, + 0x6d, 0x73, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, - 0x61, 0x74, 0x65, 0x52, 0x0d, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, - 0x74, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x69, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, - 0x03, 0x73, 0x69, 0x67, 0x22, 0xd1, 0x01, 0x0a, 0x20, 0x56, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, - 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x46, 0x75, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x50, 0x72, - 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x12, 0x49, 0x0a, 0x12, 0x63, 0x68, 0x61, - 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x6d, 0x73, 0x67, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, - 0x65, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4d, - 0x73, 0x67, 0x52, 0x10, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, - 0x65, 0x4d, 0x73, 0x67, 0x12, 0x30, 0x0a, 0x07, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, - 0x65, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x07, 0x69, - 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c, 0x12, 0x30, 0x0a, 0x09, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x5f, - 0x6d, 0x61, 0x70, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x70, 0x65, 0x72, 0x75, - 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x4d, 0x61, 0x70, 0x52, 0x08, - 0x69, 0x6e, 0x64, 0x65, 0x78, 0x4d, 0x61, 0x70, 0x22, 0x9e, 0x01, 0x0a, 0x23, 0x56, 0x69, 0x72, - 0x74, 0x75, 0x61, 0x6c, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x53, 0x65, 0x74, 0x74, 0x6c, - 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x73, 0x67, - 0x12, 0x49, 0x0a, 0x12, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x75, 0x70, 0x64, 0x61, - 0x74, 0x65, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x70, - 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, - 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4d, 0x73, 0x67, 0x52, 0x10, 0x63, 0x68, 0x61, 0x6e, 0x6e, - 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4d, 0x73, 0x67, 0x12, 0x2c, 0x0a, 0x05, 0x66, - 0x69, 0x6e, 0x61, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x70, 0x65, 0x72, - 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x53, 0x74, 0x61, - 0x74, 0x65, 0x52, 0x05, 0x66, 0x69, 0x6e, 0x61, 0x6c, 0x22, 0x60, 0x0a, 0x13, 0x43, 0x68, 0x61, - 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x41, 0x63, 0x63, 0x4d, 0x73, 0x67, - 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x69, 0x64, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x49, 0x64, 0x12, - 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, - 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x69, 0x67, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x73, 0x69, 0x67, 0x22, 0x66, 0x0a, 0x13, 0x43, - 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x6a, 0x4d, - 0x73, 0x67, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x69, 0x64, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x49, - 0x64, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x04, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x72, - 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x61, - 0x73, 0x6f, 0x6e, 0x22, 0x5d, 0x0a, 0x0e, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x53, 0x79, - 0x6e, 0x63, 0x4d, 0x73, 0x67, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x68, 0x61, 0x73, 0x65, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x70, 0x68, 0x61, 0x73, 0x65, 0x12, 0x35, 0x0a, 0x0a, 0x63, - 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x74, 0x78, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x16, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x6e, - 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x09, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, - 0x54, 0x78, 0x42, 0x26, 0x5a, 0x24, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x2e, 0x6e, 0x65, 0x74, 0x77, - 0x6f, 0x72, 0x6b, 0x2f, 0x67, 0x6f, 0x2d, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x2f, 0x77, 0x69, 0x72, - 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, + 0x61, 0x74, 0x65, 0x4d, 0x73, 0x67, 0x52, 0x10, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, + 0x70, 0x64, 0x61, 0x74, 0x65, 0x4d, 0x73, 0x67, 0x12, 0x2c, 0x0a, 0x05, 0x66, 0x69, 0x6e, 0x61, + 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, + 0x69, 0x72, 0x65, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, + 0x05, 0x66, 0x69, 0x6e, 0x61, 0x6c, 0x22, 0x60, 0x0a, 0x13, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, + 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x41, 0x63, 0x63, 0x4d, 0x73, 0x67, 0x12, 0x1d, 0x0a, + 0x0a, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0c, 0x52, 0x09, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, + 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x07, 0x76, + 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x69, 0x67, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x03, 0x73, 0x69, 0x67, 0x22, 0x66, 0x0a, 0x13, 0x43, 0x68, 0x61, 0x6e, + 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x6a, 0x4d, 0x73, 0x67, 0x12, + 0x1d, 0x0a, 0x0a, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x09, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x49, 0x64, 0x12, 0x18, + 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, + 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, + 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, + 0x22, 0x5d, 0x0a, 0x0e, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x53, 0x79, 0x6e, 0x63, 0x4d, + 0x73, 0x67, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x68, 0x61, 0x73, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0d, 0x52, 0x05, 0x70, 0x68, 0x61, 0x73, 0x65, 0x12, 0x35, 0x0a, 0x0a, 0x63, 0x75, 0x72, 0x72, + 0x65, 0x6e, 0x74, 0x5f, 0x74, 0x78, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x70, + 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x09, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x54, 0x78, 0x42, + 0x26, 0x5a, 0x24, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, + 0x2f, 0x67, 0x6f, 0x2d, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x2f, 0x77, 0x69, 0x72, 0x65, 0x2f, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -2445,88 +2579,100 @@ func file_wire_proto_rawDescGZIP() []byte { return file_wire_proto_rawDescData } -var file_wire_proto_msgTypes = make([]protoimpl.MessageInfo, 30) -var file_wire_proto_goTypes = []interface{}{ +var file_wire_proto_msgTypes = make([]protoimpl.MessageInfo, 32) +var file_wire_proto_goTypes = []any{ (*Envelope)(nil), // 0: perunwire.Envelope (*Balance)(nil), // 1: perunwire.Balance (*Balances)(nil), // 2: perunwire.Balances - (*IndexMap)(nil), // 3: perunwire.IndexMap - (*SubAlloc)(nil), // 4: perunwire.SubAlloc - (*Allocation)(nil), // 5: perunwire.Allocation - (*BaseChannelProposal)(nil), // 6: perunwire.BaseChannelProposal - (*BaseChannelProposalAcc)(nil), // 7: perunwire.BaseChannelProposalAcc - (*Params)(nil), // 8: perunwire.Params - (*State)(nil), // 9: perunwire.State - (*Transaction)(nil), // 10: perunwire.Transaction - (*SignedState)(nil), // 11: perunwire.SignedState - (*ChannelUpdate)(nil), // 12: perunwire.ChannelUpdate - (*PingMsg)(nil), // 13: perunwire.PingMsg - (*PongMsg)(nil), // 14: perunwire.PongMsg - (*ShutdownMsg)(nil), // 15: perunwire.ShutdownMsg - (*AuthResponseMsg)(nil), // 16: perunwire.AuthResponseMsg - (*LedgerChannelProposalMsg)(nil), // 17: perunwire.LedgerChannelProposalMsg - (*LedgerChannelProposalAccMsg)(nil), // 18: perunwire.LedgerChannelProposalAccMsg - (*SubChannelProposalMsg)(nil), // 19: perunwire.SubChannelProposalMsg - (*SubChannelProposalAccMsg)(nil), // 20: perunwire.SubChannelProposalAccMsg - (*VirtualChannelProposalMsg)(nil), // 21: perunwire.VirtualChannelProposalMsg - (*VirtualChannelProposalAccMsg)(nil), // 22: perunwire.VirtualChannelProposalAccMsg - (*ChannelProposalRejMsg)(nil), // 23: perunwire.ChannelProposalRejMsg - (*ChannelUpdateMsg)(nil), // 24: perunwire.ChannelUpdateMsg - (*VirtualChannelFundingProposalMsg)(nil), // 25: perunwire.VirtualChannelFundingProposalMsg - (*VirtualChannelSettlementProposalMsg)(nil), // 26: perunwire.VirtualChannelSettlementProposalMsg - (*ChannelUpdateAccMsg)(nil), // 27: perunwire.ChannelUpdateAccMsg - (*ChannelUpdateRejMsg)(nil), // 28: perunwire.ChannelUpdateRejMsg - (*ChannelSyncMsg)(nil), // 29: perunwire.ChannelSyncMsg + (*AddressMapping)(nil), // 3: perunwire.AddressMapping + (*Address)(nil), // 4: perunwire.Address + (*IndexMap)(nil), // 5: perunwire.IndexMap + (*SubAlloc)(nil), // 6: perunwire.SubAlloc + (*Allocation)(nil), // 7: perunwire.Allocation + (*BaseChannelProposal)(nil), // 8: perunwire.BaseChannelProposal + (*BaseChannelProposalAcc)(nil), // 9: perunwire.BaseChannelProposalAcc + (*Params)(nil), // 10: perunwire.Params + (*State)(nil), // 11: perunwire.State + (*Transaction)(nil), // 12: perunwire.Transaction + (*SignedState)(nil), // 13: perunwire.SignedState + (*ChannelUpdate)(nil), // 14: perunwire.ChannelUpdate + (*PingMsg)(nil), // 15: perunwire.PingMsg + (*PongMsg)(nil), // 16: perunwire.PongMsg + (*ShutdownMsg)(nil), // 17: perunwire.ShutdownMsg + (*AuthResponseMsg)(nil), // 18: perunwire.AuthResponseMsg + (*LedgerChannelProposalMsg)(nil), // 19: perunwire.LedgerChannelProposalMsg + (*LedgerChannelProposalAccMsg)(nil), // 20: perunwire.LedgerChannelProposalAccMsg + (*SubChannelProposalMsg)(nil), // 21: perunwire.SubChannelProposalMsg + (*SubChannelProposalAccMsg)(nil), // 22: perunwire.SubChannelProposalAccMsg + (*VirtualChannelProposalMsg)(nil), // 23: perunwire.VirtualChannelProposalMsg + (*VirtualChannelProposalAccMsg)(nil), // 24: perunwire.VirtualChannelProposalAccMsg + (*ChannelProposalRejMsg)(nil), // 25: perunwire.ChannelProposalRejMsg + (*ChannelUpdateMsg)(nil), // 26: perunwire.ChannelUpdateMsg + (*VirtualChannelFundingProposalMsg)(nil), // 27: perunwire.VirtualChannelFundingProposalMsg + (*VirtualChannelSettlementProposalMsg)(nil), // 28: perunwire.VirtualChannelSettlementProposalMsg + (*ChannelUpdateAccMsg)(nil), // 29: perunwire.ChannelUpdateAccMsg + (*ChannelUpdateRejMsg)(nil), // 30: perunwire.ChannelUpdateRejMsg + (*ChannelSyncMsg)(nil), // 31: perunwire.ChannelSyncMsg } var file_wire_proto_depIdxs = []int32{ - 13, // 0: perunwire.Envelope.ping_msg:type_name -> perunwire.PingMsg - 14, // 1: perunwire.Envelope.pong_msg:type_name -> perunwire.PongMsg - 15, // 2: perunwire.Envelope.shutdown_msg:type_name -> perunwire.ShutdownMsg - 16, // 3: perunwire.Envelope.auth_response_msg:type_name -> perunwire.AuthResponseMsg - 17, // 4: perunwire.Envelope.ledger_channel_proposal_msg:type_name -> perunwire.LedgerChannelProposalMsg - 18, // 5: perunwire.Envelope.ledger_channel_proposal_acc_msg:type_name -> perunwire.LedgerChannelProposalAccMsg - 19, // 6: perunwire.Envelope.sub_channel_proposal_msg:type_name -> perunwire.SubChannelProposalMsg - 20, // 7: perunwire.Envelope.sub_channel_proposal_acc_msg:type_name -> perunwire.SubChannelProposalAccMsg - 21, // 8: perunwire.Envelope.virtual_channel_proposal_msg:type_name -> perunwire.VirtualChannelProposalMsg - 22, // 9: perunwire.Envelope.virtual_channel_proposal_acc_msg:type_name -> perunwire.VirtualChannelProposalAccMsg - 23, // 10: perunwire.Envelope.channel_proposal_rej_msg:type_name -> perunwire.ChannelProposalRejMsg - 24, // 11: perunwire.Envelope.channel_update_msg:type_name -> perunwire.ChannelUpdateMsg - 25, // 12: perunwire.Envelope.virtual_channel_funding_proposal_msg:type_name -> perunwire.VirtualChannelFundingProposalMsg - 26, // 13: perunwire.Envelope.virtual_channel_settlement_proposal_msg:type_name -> perunwire.VirtualChannelSettlementProposalMsg - 27, // 14: perunwire.Envelope.channel_update_acc_msg:type_name -> perunwire.ChannelUpdateAccMsg - 28, // 15: perunwire.Envelope.channel_update_rej_msg:type_name -> perunwire.ChannelUpdateRejMsg - 29, // 16: perunwire.Envelope.channel_sync_msg:type_name -> perunwire.ChannelSyncMsg - 1, // 17: perunwire.Balances.balances:type_name -> perunwire.Balance - 1, // 18: perunwire.SubAlloc.bals:type_name -> perunwire.Balance - 3, // 19: perunwire.SubAlloc.index_map:type_name -> perunwire.IndexMap - 2, // 20: perunwire.Allocation.balances:type_name -> perunwire.Balances - 4, // 21: perunwire.Allocation.locked:type_name -> perunwire.SubAlloc - 5, // 22: perunwire.BaseChannelProposal.init_bals:type_name -> perunwire.Allocation - 2, // 23: perunwire.BaseChannelProposal.funding_agreement:type_name -> perunwire.Balances - 5, // 24: perunwire.State.allocation:type_name -> perunwire.Allocation - 9, // 25: perunwire.Transaction.state:type_name -> perunwire.State - 8, // 26: perunwire.SignedState.params:type_name -> perunwire.Params - 9, // 27: perunwire.SignedState.state:type_name -> perunwire.State - 9, // 28: perunwire.ChannelUpdate.state:type_name -> perunwire.State - 6, // 29: perunwire.LedgerChannelProposalMsg.base_channel_proposal:type_name -> perunwire.BaseChannelProposal - 7, // 30: perunwire.LedgerChannelProposalAccMsg.base_channel_proposal_acc:type_name -> perunwire.BaseChannelProposalAcc - 6, // 31: perunwire.SubChannelProposalMsg.base_channel_proposal:type_name -> perunwire.BaseChannelProposal - 7, // 32: perunwire.SubChannelProposalAccMsg.base_channel_proposal_acc:type_name -> perunwire.BaseChannelProposalAcc - 6, // 33: perunwire.VirtualChannelProposalMsg.base_channel_proposal:type_name -> perunwire.BaseChannelProposal - 3, // 34: perunwire.VirtualChannelProposalMsg.index_maps:type_name -> perunwire.IndexMap - 7, // 35: perunwire.VirtualChannelProposalAccMsg.base_channel_proposal_acc:type_name -> perunwire.BaseChannelProposalAcc - 12, // 36: perunwire.ChannelUpdateMsg.channel_update:type_name -> perunwire.ChannelUpdate - 24, // 37: perunwire.VirtualChannelFundingProposalMsg.channel_update_msg:type_name -> perunwire.ChannelUpdateMsg - 11, // 38: perunwire.VirtualChannelFundingProposalMsg.initial:type_name -> perunwire.SignedState - 3, // 39: perunwire.VirtualChannelFundingProposalMsg.index_map:type_name -> perunwire.IndexMap - 24, // 40: perunwire.VirtualChannelSettlementProposalMsg.channel_update_msg:type_name -> perunwire.ChannelUpdateMsg - 11, // 41: perunwire.VirtualChannelSettlementProposalMsg.final:type_name -> perunwire.SignedState - 10, // 42: perunwire.ChannelSyncMsg.current_tx:type_name -> perunwire.Transaction - 43, // [43:43] is the sub-list for method output_type - 43, // [43:43] is the sub-list for method input_type - 43, // [43:43] is the sub-list for extension type_name - 43, // [43:43] is the sub-list for extension extendee - 0, // [0:43] is the sub-list for field type_name + 4, // 0: perunwire.Envelope.sender:type_name -> perunwire.Address + 4, // 1: perunwire.Envelope.recipient:type_name -> perunwire.Address + 15, // 2: perunwire.Envelope.ping_msg:type_name -> perunwire.PingMsg + 16, // 3: perunwire.Envelope.pong_msg:type_name -> perunwire.PongMsg + 17, // 4: perunwire.Envelope.shutdown_msg:type_name -> perunwire.ShutdownMsg + 18, // 5: perunwire.Envelope.auth_response_msg:type_name -> perunwire.AuthResponseMsg + 19, // 6: perunwire.Envelope.ledger_channel_proposal_msg:type_name -> perunwire.LedgerChannelProposalMsg + 20, // 7: perunwire.Envelope.ledger_channel_proposal_acc_msg:type_name -> perunwire.LedgerChannelProposalAccMsg + 21, // 8: perunwire.Envelope.sub_channel_proposal_msg:type_name -> perunwire.SubChannelProposalMsg + 22, // 9: perunwire.Envelope.sub_channel_proposal_acc_msg:type_name -> perunwire.SubChannelProposalAccMsg + 23, // 10: perunwire.Envelope.virtual_channel_proposal_msg:type_name -> perunwire.VirtualChannelProposalMsg + 24, // 11: perunwire.Envelope.virtual_channel_proposal_acc_msg:type_name -> perunwire.VirtualChannelProposalAccMsg + 25, // 12: perunwire.Envelope.channel_proposal_rej_msg:type_name -> perunwire.ChannelProposalRejMsg + 26, // 13: perunwire.Envelope.channel_update_msg:type_name -> perunwire.ChannelUpdateMsg + 27, // 14: perunwire.Envelope.virtual_channel_funding_proposal_msg:type_name -> perunwire.VirtualChannelFundingProposalMsg + 28, // 15: perunwire.Envelope.virtual_channel_settlement_proposal_msg:type_name -> perunwire.VirtualChannelSettlementProposalMsg + 29, // 16: perunwire.Envelope.channel_update_acc_msg:type_name -> perunwire.ChannelUpdateAccMsg + 30, // 17: perunwire.Envelope.channel_update_rej_msg:type_name -> perunwire.ChannelUpdateRejMsg + 31, // 18: perunwire.Envelope.channel_sync_msg:type_name -> perunwire.ChannelSyncMsg + 1, // 19: perunwire.Balances.balances:type_name -> perunwire.Balance + 3, // 20: perunwire.Address.address_mapping:type_name -> perunwire.AddressMapping + 1, // 21: perunwire.SubAlloc.bals:type_name -> perunwire.Balance + 5, // 22: perunwire.SubAlloc.index_map:type_name -> perunwire.IndexMap + 2, // 23: perunwire.Allocation.balances:type_name -> perunwire.Balances + 6, // 24: perunwire.Allocation.locked:type_name -> perunwire.SubAlloc + 7, // 25: perunwire.BaseChannelProposal.init_bals:type_name -> perunwire.Allocation + 2, // 26: perunwire.BaseChannelProposal.funding_agreement:type_name -> perunwire.Balances + 4, // 27: perunwire.Params.parts:type_name -> perunwire.Address + 7, // 28: perunwire.State.allocation:type_name -> perunwire.Allocation + 11, // 29: perunwire.Transaction.state:type_name -> perunwire.State + 10, // 30: perunwire.SignedState.params:type_name -> perunwire.Params + 11, // 31: perunwire.SignedState.state:type_name -> perunwire.State + 11, // 32: perunwire.ChannelUpdate.state:type_name -> perunwire.State + 8, // 33: perunwire.LedgerChannelProposalMsg.base_channel_proposal:type_name -> perunwire.BaseChannelProposal + 4, // 34: perunwire.LedgerChannelProposalMsg.participant:type_name -> perunwire.Address + 4, // 35: perunwire.LedgerChannelProposalMsg.peers:type_name -> perunwire.Address + 9, // 36: perunwire.LedgerChannelProposalAccMsg.base_channel_proposal_acc:type_name -> perunwire.BaseChannelProposalAcc + 4, // 37: perunwire.LedgerChannelProposalAccMsg.participant:type_name -> perunwire.Address + 8, // 38: perunwire.SubChannelProposalMsg.base_channel_proposal:type_name -> perunwire.BaseChannelProposal + 9, // 39: perunwire.SubChannelProposalAccMsg.base_channel_proposal_acc:type_name -> perunwire.BaseChannelProposalAcc + 8, // 40: perunwire.VirtualChannelProposalMsg.base_channel_proposal:type_name -> perunwire.BaseChannelProposal + 4, // 41: perunwire.VirtualChannelProposalMsg.proposer:type_name -> perunwire.Address + 4, // 42: perunwire.VirtualChannelProposalMsg.peers:type_name -> perunwire.Address + 5, // 43: perunwire.VirtualChannelProposalMsg.index_maps:type_name -> perunwire.IndexMap + 9, // 44: perunwire.VirtualChannelProposalAccMsg.base_channel_proposal_acc:type_name -> perunwire.BaseChannelProposalAcc + 4, // 45: perunwire.VirtualChannelProposalAccMsg.responder:type_name -> perunwire.Address + 14, // 46: perunwire.ChannelUpdateMsg.channel_update:type_name -> perunwire.ChannelUpdate + 26, // 47: perunwire.VirtualChannelFundingProposalMsg.channel_update_msg:type_name -> perunwire.ChannelUpdateMsg + 13, // 48: perunwire.VirtualChannelFundingProposalMsg.initial:type_name -> perunwire.SignedState + 5, // 49: perunwire.VirtualChannelFundingProposalMsg.index_map:type_name -> perunwire.IndexMap + 26, // 50: perunwire.VirtualChannelSettlementProposalMsg.channel_update_msg:type_name -> perunwire.ChannelUpdateMsg + 13, // 51: perunwire.VirtualChannelSettlementProposalMsg.final:type_name -> perunwire.SignedState + 12, // 52: perunwire.ChannelSyncMsg.current_tx:type_name -> perunwire.Transaction + 53, // [53:53] is the sub-list for method output_type + 53, // [53:53] is the sub-list for method input_type + 53, // [53:53] is the sub-list for extension type_name + 53, // [53:53] is the sub-list for extension extendee + 0, // [0:53] is the sub-list for field type_name } func init() { file_wire_proto_init() } @@ -2535,7 +2681,7 @@ func file_wire_proto_init() { return } if !protoimpl.UnsafeEnabled { - file_wire_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[0].Exporter = func(v any, i int) any { switch v := v.(*Envelope); i { case 0: return &v.state @@ -2547,7 +2693,7 @@ func file_wire_proto_init() { return nil } } - file_wire_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[1].Exporter = func(v any, i int) any { switch v := v.(*Balance); i { case 0: return &v.state @@ -2559,7 +2705,7 @@ func file_wire_proto_init() { return nil } } - file_wire_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[2].Exporter = func(v any, i int) any { switch v := v.(*Balances); i { case 0: return &v.state @@ -2571,7 +2717,31 @@ func file_wire_proto_init() { return nil } } - file_wire_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[3].Exporter = func(v any, i int) any { + switch v := v.(*AddressMapping); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_wire_proto_msgTypes[4].Exporter = func(v any, i int) any { + switch v := v.(*Address); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_wire_proto_msgTypes[5].Exporter = func(v any, i int) any { switch v := v.(*IndexMap); i { case 0: return &v.state @@ -2583,7 +2753,7 @@ func file_wire_proto_init() { return nil } } - file_wire_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[6].Exporter = func(v any, i int) any { switch v := v.(*SubAlloc); i { case 0: return &v.state @@ -2595,7 +2765,7 @@ func file_wire_proto_init() { return nil } } - file_wire_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[7].Exporter = func(v any, i int) any { switch v := v.(*Allocation); i { case 0: return &v.state @@ -2607,7 +2777,7 @@ func file_wire_proto_init() { return nil } } - file_wire_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[8].Exporter = func(v any, i int) any { switch v := v.(*BaseChannelProposal); i { case 0: return &v.state @@ -2619,7 +2789,7 @@ func file_wire_proto_init() { return nil } } - file_wire_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[9].Exporter = func(v any, i int) any { switch v := v.(*BaseChannelProposalAcc); i { case 0: return &v.state @@ -2631,7 +2801,7 @@ func file_wire_proto_init() { return nil } } - file_wire_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[10].Exporter = func(v any, i int) any { switch v := v.(*Params); i { case 0: return &v.state @@ -2643,7 +2813,7 @@ func file_wire_proto_init() { return nil } } - file_wire_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[11].Exporter = func(v any, i int) any { switch v := v.(*State); i { case 0: return &v.state @@ -2655,7 +2825,7 @@ func file_wire_proto_init() { return nil } } - file_wire_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[12].Exporter = func(v any, i int) any { switch v := v.(*Transaction); i { case 0: return &v.state @@ -2667,7 +2837,7 @@ func file_wire_proto_init() { return nil } } - file_wire_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[13].Exporter = func(v any, i int) any { switch v := v.(*SignedState); i { case 0: return &v.state @@ -2679,7 +2849,7 @@ func file_wire_proto_init() { return nil } } - file_wire_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[14].Exporter = func(v any, i int) any { switch v := v.(*ChannelUpdate); i { case 0: return &v.state @@ -2691,7 +2861,7 @@ func file_wire_proto_init() { return nil } } - file_wire_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[15].Exporter = func(v any, i int) any { switch v := v.(*PingMsg); i { case 0: return &v.state @@ -2703,7 +2873,7 @@ func file_wire_proto_init() { return nil } } - file_wire_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[16].Exporter = func(v any, i int) any { switch v := v.(*PongMsg); i { case 0: return &v.state @@ -2715,7 +2885,7 @@ func file_wire_proto_init() { return nil } } - file_wire_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[17].Exporter = func(v any, i int) any { switch v := v.(*ShutdownMsg); i { case 0: return &v.state @@ -2727,7 +2897,7 @@ func file_wire_proto_init() { return nil } } - file_wire_proto_msgTypes[16].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[18].Exporter = func(v any, i int) any { switch v := v.(*AuthResponseMsg); i { case 0: return &v.state @@ -2739,7 +2909,7 @@ func file_wire_proto_init() { return nil } } - file_wire_proto_msgTypes[17].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[19].Exporter = func(v any, i int) any { switch v := v.(*LedgerChannelProposalMsg); i { case 0: return &v.state @@ -2751,7 +2921,7 @@ func file_wire_proto_init() { return nil } } - file_wire_proto_msgTypes[18].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[20].Exporter = func(v any, i int) any { switch v := v.(*LedgerChannelProposalAccMsg); i { case 0: return &v.state @@ -2763,7 +2933,7 @@ func file_wire_proto_init() { return nil } } - file_wire_proto_msgTypes[19].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[21].Exporter = func(v any, i int) any { switch v := v.(*SubChannelProposalMsg); i { case 0: return &v.state @@ -2775,7 +2945,7 @@ func file_wire_proto_init() { return nil } } - file_wire_proto_msgTypes[20].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[22].Exporter = func(v any, i int) any { switch v := v.(*SubChannelProposalAccMsg); i { case 0: return &v.state @@ -2787,7 +2957,7 @@ func file_wire_proto_init() { return nil } } - file_wire_proto_msgTypes[21].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[23].Exporter = func(v any, i int) any { switch v := v.(*VirtualChannelProposalMsg); i { case 0: return &v.state @@ -2799,7 +2969,7 @@ func file_wire_proto_init() { return nil } } - file_wire_proto_msgTypes[22].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[24].Exporter = func(v any, i int) any { switch v := v.(*VirtualChannelProposalAccMsg); i { case 0: return &v.state @@ -2811,7 +2981,7 @@ func file_wire_proto_init() { return nil } } - file_wire_proto_msgTypes[23].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[25].Exporter = func(v any, i int) any { switch v := v.(*ChannelProposalRejMsg); i { case 0: return &v.state @@ -2823,7 +2993,7 @@ func file_wire_proto_init() { return nil } } - file_wire_proto_msgTypes[24].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[26].Exporter = func(v any, i int) any { switch v := v.(*ChannelUpdateMsg); i { case 0: return &v.state @@ -2835,7 +3005,7 @@ func file_wire_proto_init() { return nil } } - file_wire_proto_msgTypes[25].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[27].Exporter = func(v any, i int) any { switch v := v.(*VirtualChannelFundingProposalMsg); i { case 0: return &v.state @@ -2847,7 +3017,7 @@ func file_wire_proto_init() { return nil } } - file_wire_proto_msgTypes[26].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[28].Exporter = func(v any, i int) any { switch v := v.(*VirtualChannelSettlementProposalMsg); i { case 0: return &v.state @@ -2859,7 +3029,7 @@ func file_wire_proto_init() { return nil } } - file_wire_proto_msgTypes[27].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[29].Exporter = func(v any, i int) any { switch v := v.(*ChannelUpdateAccMsg); i { case 0: return &v.state @@ -2871,7 +3041,7 @@ func file_wire_proto_init() { return nil } } - file_wire_proto_msgTypes[28].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[30].Exporter = func(v any, i int) any { switch v := v.(*ChannelUpdateRejMsg); i { case 0: return &v.state @@ -2883,7 +3053,7 @@ func file_wire_proto_init() { return nil } } - file_wire_proto_msgTypes[29].Exporter = func(v interface{}, i int) interface{} { + file_wire_proto_msgTypes[31].Exporter = func(v any, i int) any { switch v := v.(*ChannelSyncMsg); i { case 0: return &v.state @@ -2896,7 +3066,7 @@ func file_wire_proto_init() { } } } - file_wire_proto_msgTypes[0].OneofWrappers = []interface{}{ + file_wire_proto_msgTypes[0].OneofWrappers = []any{ (*Envelope_PingMsg)(nil), (*Envelope_PongMsg)(nil), (*Envelope_ShutdownMsg)(nil), @@ -2921,7 +3091,7 @@ func file_wire_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_wire_proto_rawDesc, NumEnums: 0, - NumMessages: 30, + NumMessages: 32, NumExtensions: 0, NumServices: 0, }, diff --git a/wire/protobuf/wire.proto b/wire/protobuf/wire.proto index dec4edbcb..f3f2972d0 100644 --- a/wire/protobuf/wire.proto +++ b/wire/protobuf/wire.proto @@ -24,9 +24,9 @@ option go_package = "perun.network/go-perun/wire/protobuf"; // the sender and the intended receiver. message Envelope { // sender of the message. - bytes sender = 1; + Address sender = 1; // intended recipient of the message. - bytes recipient = 2; + Address recipient = 2; // msg should contain on the valid message types. oneof msg { PingMsg ping_msg = 3; @@ -61,6 +61,17 @@ message Balances { repeated Balance balances = 1; } +// AddressMapping represents an element of a address mapping. +message AddressMapping { + bytes key = 1; + bytes address = 2; +} + +// Address represents the map of addresses for each participant in the channel. +message Address { + repeated AddressMapping address_mapping = 1; +} + // IndexMap represents the mapping of a participant indices in a sub allocation // or a virtual channel funding proposal to the corresponding indices in the // parent channel. @@ -77,9 +88,10 @@ message SubAlloc { // Allocation represents channel.Allocation. message Allocation { - repeated bytes assets = 1; - Balances balances = 2; - repeated SubAlloc locked = 3; + repeated bytes backends = 1; + repeated bytes assets = 2; + Balances balances = 3; + repeated SubAlloc locked = 4; } // BaseChannelProposal represents client.BaseChannelProposal. @@ -103,7 +115,7 @@ message BaseChannelProposalAcc { message Params { bytes id = 1; uint64 challenge_duration = 2; - repeated bytes parts = 3; + repeated Address parts = 3; bytes app = 4; bytes nonce = 5; bool ledger_channel = 6; @@ -163,14 +175,14 @@ message AuthResponseMsg { // LedgerChannelProposalMsg represents client.LedgerChannelProposalMsg. message LedgerChannelProposalMsg { BaseChannelProposal base_channel_proposal = 1; - bytes participant = 2; - repeated bytes peers = 3; + Address participant = 2; + repeated Address peers = 3; } // LedgerChannelProposalAccMsg represents client.LedgerChannelProposalAccMsg. message LedgerChannelProposalAccMsg { BaseChannelProposalAcc base_channel_proposal_acc = 1; - bytes participant = 2; + Address participant = 2; } // SubChannelProposalMsg represents client.SubChannelProposalMsg. @@ -187,8 +199,8 @@ message SubChannelProposalAccMsg { // VirtualChannelProposalMsg represents client.VirtualChannelProposalMsg. message VirtualChannelProposalMsg { BaseChannelProposal base_channel_proposal = 1; - bytes proposer = 2; - repeated bytes peers = 3; + Address proposer = 2; + repeated Address peers = 3; repeated bytes parents = 4; repeated IndexMap index_maps = 5; } @@ -196,7 +208,7 @@ message VirtualChannelProposalMsg { // VirtualChannelProposalAccMsg represents client.VirtualChannelProposalAccMsg. message VirtualChannelProposalAccMsg { BaseChannelProposalAcc base_channel_proposal_acc = 1; - bytes responder = 2; + Address responder = 2; } // ChannelProposalRejMsg represents client.ChannelProposalRejMsg. diff --git a/wire/test/bustest.go b/wire/test/bustest.go index ab8f34cb4..7d0271c99 100644 --- a/wire/test/bustest.go +++ b/wire/test/bustest.go @@ -102,7 +102,7 @@ func GenericBusTest(t *testing.T, // Only subscribe to the current sender. recv := wire.NewReceiver() err := clients[recipient].r.Subscribe(recv, func(e *wire.Envelope) bool { - return e.Sender.Equal(clients[sender].id.Address()) + return equalMaps(e.Sender, clients[sender].id.Address()) }) require.NoError(t, err) @@ -149,3 +149,15 @@ func GenericBusTest(t *testing.T, // publishing. testPublishAndReceive(t, func() {}) } + +func equalMaps(a, b map[int]wire.Address) bool { + if len(a) != len(b) { + return false + } + for k, v := range a { + if !v.Equal(b[k]) { + return false + } + } + return true +} diff --git a/wire/test/randomizer.go b/wire/test/randomizer.go index 39b3f4c88..1119a4104 100644 --- a/wire/test/randomizer.go +++ b/wire/test/randomizer.go @@ -43,8 +43,8 @@ func SetNewRandomAccount(f NewRandomAccountFunc) { } // NewRandomAddress returns a new random address. -func NewRandomAddress(rng *rand.Rand) wire.Address { - return newRandomAddress(rng) +func NewRandomAddress(rng *rand.Rand) map[int]wire.Address { + return map[int]wire.Address{0: newRandomAddress(rng)} } // NewRandomAccount returns a new random account. @@ -53,8 +53,17 @@ func NewRandomAccount(rng *rand.Rand) wire.Account { } // NewRandomAddresses returns a slice of random peer addresses. -func NewRandomAddresses(rng *rand.Rand, n int) []wire.Address { - addresses := make([]wire.Address, n) +func NewRandomAddresses(rng *rand.Rand, n int) []map[int]wire.Address { + addresses := make([]map[int]wire.Address, n) + for i := range addresses { + addresses[i] = NewRandomAddress(rng) + } + return addresses +} + +// NewRandomAddressesMap returns a slice of random peer addresses. +func NewRandomAddressesMap(rng *rand.Rand, n int) []map[int]wire.Address { + addresses := make([]map[int]wire.Address, n) for i := range addresses { addresses[i] = NewRandomAddress(rng) } From 28685ea1a4e8f4966516062b1cf24eb7a1de3287 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Wed, 28 Aug 2024 11:49:52 +0200 Subject: [PATCH 02/36] fix(multi): Add AssetIDKey struct to fix the map lookups for funders and adjudicators. fix(randomizer): Lookup backend opts to correctly initialize address maps. fix(test): Generalize tests to be used in other backends. Signed-off-by: Sophia Koehler --- channel/app.go | 5 +- channel/multi/adjudicator.go | 14 +++-- channel/multi/funder.go | 30 ++++++--- channel/test/randomizer.go | 8 ++- client/test/multiledger_happy.go | 2 +- wallet/test/wallet.go | 102 ++++++++++++++++--------------- 6 files changed, 90 insertions(+), 71 deletions(-) diff --git a/channel/app.go b/channel/app.go index 239d4ec37..e853c354d 100644 --- a/channel/app.go +++ b/channel/app.go @@ -16,9 +16,8 @@ package channel import ( "encoding" - "io" - "github.com/pkg/errors" + "io" "perun.network/go-perun/wire/perunio" ) @@ -205,7 +204,7 @@ func (d OptAppDec) Decode(r io.Reader) (err error) { *d.App = NoApp() return nil } - appDef, _ := backend[0].NewAppID() + appDef, _ := NewAppID() err = perunio.Decode(r, appDef) if err != nil { return errors.WithMessage(err, "decode app address") diff --git a/channel/multi/adjudicator.go b/channel/multi/adjudicator.go index 43a16a77e..e2f8c4c38 100644 --- a/channel/multi/adjudicator.go +++ b/channel/multi/adjudicator.go @@ -17,30 +17,31 @@ package multi import ( "context" "fmt" - "perun.network/go-perun/channel" ) // Adjudicator is a multi-ledger adjudicator. type Adjudicator struct { - adjudicators map[AssetID]channel.Adjudicator + adjudicators map[AssetIDKey]channel.Adjudicator } // NewAdjudicator creates a new adjudicator. func NewAdjudicator() *Adjudicator { return &Adjudicator{ - adjudicators: make(map[AssetID]channel.Adjudicator), + adjudicators: make(map[AssetIDKey]channel.Adjudicator), } } // RegisterAdjudicator registers an adjudicator for a given ledger. func (a *Adjudicator) RegisterAdjudicator(l AssetID, la channel.Adjudicator) { - a.adjudicators[l] = la + key := AssetIDKey{BackendID: l.BackendID, LedgerID: string(l.LedgerId.MapKey())} + a.adjudicators[key] = la } // LedgerAdjudicator returns the adjudicator for a given ledger. func (a *Adjudicator) LedgerAdjudicator(l AssetID) (channel.Adjudicator, bool) { - adj, ok := a.adjudicators[l] + key := AssetIDKey{BackendID: l.BackendID, LedgerID: string(l.LedgerId.MapKey())} + adj, ok := a.adjudicators[key] return adj, ok } @@ -96,7 +97,8 @@ func (a *Adjudicator) dispatch(assetIds []AssetID, f func(channel.Adjudicator) e for _, l := range assetIds { go func(l AssetID) { err := func() error { - adjs, ok := a.adjudicators[l] + key := AssetIDKey{BackendID: l.BackendID, LedgerID: string(l.LedgerId.MapKey())} + adjs, ok := a.adjudicators[key] if !ok { return fmt.Errorf("adjudicator not found for id %v", l) } diff --git a/channel/multi/funder.go b/channel/multi/funder.go index bf107636a..61f0b1d78 100644 --- a/channel/multi/funder.go +++ b/channel/multi/funder.go @@ -22,31 +22,39 @@ import ( "perun.network/go-perun/channel" ) +// AssetIDKey is a representation of AssetID that kan be used in map lookups. +type AssetIDKey struct { + BackendID uint32 + LedgerID string +} + // Funder is a multi-ledger funder. // funders is a map of LedgerIDs corresponding to a funder on some chain. // egoisticChains is a map of LedgerIDs corresponding to a boolean indicating whether the chain should be funded last. type Funder struct { - funders map[AssetID]channel.Funder - egoisticChains map[AssetID]bool + funders map[AssetIDKey]channel.Funder + egoisticChains map[AssetIDKey]bool } // NewFunder creates a new funder. func NewFunder() *Funder { return &Funder{ - funders: make(map[AssetID]channel.Funder), - egoisticChains: make(map[AssetID]bool), + funders: make(map[AssetIDKey]channel.Funder), + egoisticChains: make(map[AssetIDKey]bool), } } // RegisterFunder registers a funder for a given ledger. func (f *Funder) RegisterFunder(l AssetID, lf channel.Funder) { - f.funders[l] = lf - f.egoisticChains[l] = false + key := AssetIDKey{BackendID: l.BackendID, LedgerID: string(l.LedgerId.MapKey())} + f.funders[key] = lf + f.egoisticChains[key] = false } // SetEgoisticChain sets the egoistic chain flag for a given ledger. func (f *Funder) SetEgoisticChain(l AssetID, id int, egoistic bool) { - f.egoisticChains[l] = egoistic + key := AssetIDKey{BackendID: l.BackendID, LedgerID: string(l.LedgerId.MapKey())} + f.egoisticChains[key] = egoistic } // Fund funds a multi-ledger channel. It dispatches funding calls to all @@ -67,7 +75,8 @@ func (f *Funder) Fund(ctx context.Context, request channel.FundingReq) error { var nonEgoisticLedgers []AssetID for _, l := range assetIDs { - if f.egoisticChains[l] { + key := AssetIDKey{BackendID: l.BackendID, LedgerID: string(l.LedgerId.MapKey())} + if f.egoisticChains[key] { egoisticLedgers = append(egoisticLedgers, l) } else { nonEgoisticLedgers = append(nonEgoisticLedgers, l) @@ -89,7 +98,7 @@ func (f *Funder) Fund(ctx context.Context, request channel.FundingReq) error { return nil } -func fundLedgers(ctx context.Context, request channel.FundingReq, assetIDs []AssetID, funders map[AssetID]channel.Funder) error { +func fundLedgers(ctx context.Context, request channel.FundingReq, assetIDs []AssetID, funders map[AssetIDKey]channel.Funder) error { // Calculate the total number of funders n := len(assetIDs) @@ -98,8 +107,9 @@ func fundLedgers(ctx context.Context, request channel.FundingReq, assetIDs []Ass // Iterate over blockchains to get the LedgerIDs for _, assetID := range assetIDs { go func(assetID AssetID) { + key := AssetIDKey{BackendID: assetID.BackendID, LedgerID: string(assetID.LedgerId.MapKey())} // Get the Funder from the funders map - funder, ok := funders[assetID] + funder, ok := funders[key] if !ok { errs <- fmt.Errorf("funder map not found for blockchain %d and ledger %d", assetID.BackendID, assetID.LedgerId) return diff --git a/channel/test/randomizer.go b/channel/test/randomizer.go index 26c13505e..c0ae216b4 100644 --- a/channel/test/randomizer.go +++ b/channel/test/randomizer.go @@ -161,8 +161,14 @@ func NewRandomParams(rng *rand.Rand, opts ...RandomOpt) *channel.Params { var parts []map[int]wallet.Address if parts = opt.Parts(); parts == nil { parts = make([]map[int]wallet.Address, numParts) + for i := range parts { - parts[i] = map[int]wallet.Address{0: test.NewRandomAddress(rng)} + var backend int + if backend, _ = opt.Backend(); backend != 0 { + parts[i] = map[int]wallet.Address{backend: test.NewRandomAddress(rng)} + } else { + parts[i] = map[int]wallet.Address{0: test.NewRandomAddress(rng)} + } } } if firstPart := opt.FirstPart(); firstPart != nil { diff --git a/client/test/multiledger_happy.go b/client/test/multiledger_happy.go index 49bd7a8eb..be01fa7ef 100644 --- a/client/test/multiledger_happy.go +++ b/client/test/multiledger_happy.go @@ -42,7 +42,7 @@ func TestMultiLedgerHappy(ctx context.Context, t *testing.T, mlt MultiLedgerSetu // Create channel proposal. parts := []map[int]wire.Address{alice.WireAddress, bob.WireAddress} - initAlloc := channel.NewAllocation(len(parts), []int{0}, mlt.Asset1, mlt.Asset2) + initAlloc := channel.NewAllocation(len(parts), []int{int(mlt.Asset1.AssetID().BackendID), int(mlt.Asset2.AssetID().BackendID)}, mlt.Asset1, mlt.Asset2) initAlloc.Balances = initBals prop, err := client.NewLedgerChannelProposal( challengeDuration, diff --git a/wallet/test/wallet.go b/wallet/test/wallet.go index 5b764698a..b6b5e1704 100644 --- a/wallet/test/wallet.go +++ b/wallet/test/wallet.go @@ -44,61 +44,63 @@ type Setup struct { // a corresponding wallet and backend implementation. // This function should be called by every implementation of the wallet interface. func TestAccountWithWalletAndBackend(t *testing.T, s *Setup) { //nolint:revive // `test.Test...` stutters, but we accept that here. - acc, err := s.Wallet.Unlock(s.AddressInWallet) - assert.NoError(t, err) - // Check unlocked account - sig, err := acc.SignData(s.DataToSign) - assert.NoError(t, err, "Sign with unlocked account should succeed") - valid, err := s.Backend.VerifySignature(s.DataToSign, sig, acc.Address()[0]) - assert.True(t, valid, "Verification should succeed") - assert.NoError(t, err, "Verification should not produce error") + for _, address := range s.AddressInWallet { + acc, err := s.Wallet.Unlock(s.AddressInWallet) + assert.NoError(t, err) + // Check unlocked account + sig, err := acc.SignData(s.DataToSign) + assert.NoError(t, err, "Sign with unlocked account should succeed") + valid, err := s.Backend.VerifySignature(s.DataToSign, sig, address) + assert.True(t, valid, "Verification should succeed") + assert.NoError(t, err, "Verification should not produce error") - addr := s.Backend.NewAddress() - err = addr.UnmarshalBinary(s.AddressMarshalled) - assert.NoError(t, err, "Binary unmarshalling of address should work") - valid, err = s.Backend.VerifySignature(s.DataToSign, sig, addr) - assert.False(t, valid, "Verification with wrong address should fail") - assert.NoError(t, err, "Verification of valid signature should not produce error") + addr := s.Backend.NewAddress() + err = addr.UnmarshalBinary(s.AddressMarshalled) + assert.NoError(t, err, "Binary unmarshalling of address should work") + valid, err = s.Backend.VerifySignature(s.DataToSign, sig, addr) + assert.False(t, valid, "Verification with wrong address should fail") + assert.NoError(t, err, "Verification of valid signature should not produce error") - tampered := make([]byte, len(sig)) - copy(tampered, sig) - // Invalidate the signature and check for error - tampered[0] = ^sig[0] - valid, err = s.Backend.VerifySignature(s.DataToSign, tampered, acc.Address()[0]) - if valid && err == nil { - t.Error("Verification of invalid signature should produce error or return false") - } - // Truncate the signature and check for error - tampered = sig[:len(sig)-1] - valid, err = s.Backend.VerifySignature(s.DataToSign, tampered, acc.Address()[0]) - if valid && err != nil { - t.Error("Verification of invalid signature should produce error or return false") - } - // Expand the signature and check for error - //nolint:gocritic - tampered = append(sig, 0) - valid, err = s.Backend.VerifySignature(s.DataToSign, tampered, acc.Address()[0]) - if valid && err != nil { - t.Error("Verification of invalid signature should produce error or return false") - } + tampered := make([]byte, len(sig)) + copy(tampered, sig) + // Invalidate the signature and check for error + tampered[0] = ^sig[0] + valid, err = s.Backend.VerifySignature(s.DataToSign, tampered, address) + if valid && err == nil { + t.Error("Verification of invalid signature should produce error or return false") + } + // Truncate the signature and check for error + tampered = sig[:len(sig)-1] + valid, err = s.Backend.VerifySignature(s.DataToSign, tampered, address) + if valid && err != nil { + t.Error("Verification of invalid signature should produce error or return false") + } + // Expand the signature and check for error + //nolint:gocritic + tampered = append(sig, 0) + valid, err = s.Backend.VerifySignature(s.DataToSign, tampered, address) + if valid && err != nil { + t.Error("Verification of invalid signature should produce error or return false") + } - // Test DecodeSig - sig, err = acc.SignData(s.DataToSign) - require.NoError(t, err, "Sign with unlocked account should succeed") + // Test DecodeSig + sig, err = acc.SignData(s.DataToSign) + require.NoError(t, err, "Sign with unlocked account should succeed") - buff := new(bytes.Buffer) - err = perunio.Encode(buff, sig) - require.NoError(t, err, "encode sig") - sign2, err := s.Backend.DecodeSig(buff) - assert.NoError(t, err, "Decoded signature should work") - assert.Equal(t, sig, sign2, "Decoded signature should be equal to the original") + buff := new(bytes.Buffer) + err = perunio.Encode(buff, sig) + require.NoError(t, err, "encode sig") + sign2, err := s.Backend.DecodeSig(buff) + assert.NoError(t, err, "Decoded signature should work") + assert.Equal(t, sig, sign2, "Decoded signature should be equal to the original") - // Test DecodeSig on short stream - err = perunio.Encode(buff, sig) - require.NoError(t, err, "encode sig") - shortBuff := bytes.NewBuffer(buff.Bytes()[:len(buff.Bytes())-1]) // remove one byte - _, err = s.Backend.DecodeSig(shortBuff) - assert.Error(t, err, "DecodeSig on short stream should error") + // Test DecodeSig on short stream + err = perunio.Encode(buff, sig) + require.NoError(t, err, "encode sig") + shortBuff := bytes.NewBuffer(buff.Bytes()[:len(buff.Bytes())-1]) // remove one byte + _, err = s.Backend.DecodeSig(shortBuff) + assert.Error(t, err, "DecodeSig on short stream should error") + } } // GenericSignatureSizeTest tests that the size of the signatures produced by From ef11de9ee20d6587b9636198b6618633a8e35e01 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Wed, 4 Sep 2024 11:08:57 +0200 Subject: [PATCH 03/36] fix(all): Use map[int]ID instead of id for each backend. Signed-off-by: Sophia Koehler --- client/adjudicate.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/adjudicate.go b/client/adjudicate.go index beefe8522..087ce856c 100644 --- a/client/adjudicate.go +++ b/client/adjudicate.go @@ -438,7 +438,7 @@ func (c *Channel) gatherSubChannelStates() (states []channel.SignedState, err er func (c *Channel) subChannelStateMap() (states channel.StateMap, err error) { states = channel.MakeStateMap() err = c.applyToSubChannelsRecursive(func(c *Channel) error { - states[c.ID()] = c.state() + states[channel.IDKey(c.ID())] = c.state() return nil }) return From ab8e60b12c1f844ce1d395be41abcd60939c83fd Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Wed, 4 Sep 2024 11:10:32 +0200 Subject: [PATCH 04/36] fix(all): Add map of IDs Signed-off-by: Sophia Koehler --- channel/adjudicator.go | 27 +- channel/allocation.go | 19 +- channel/allocation_test.go | 19 +- channel/backend.go | 22 +- channel/errors.go | 14 +- channel/errors_internal_test.go | 8 +- channel/machine.go | 6 +- channel/machine_test.go | 6 +- channel/mock_app.go | 4 +- channel/mock_app_internal_test.go | 2 +- channel/multi/subscription.go | 2 +- channel/params.go | 111 +- channel/params_test.go | 9 +- .../persistence/keyvalue/persistedstate.go | 10 +- channel/persistence/keyvalue/persister.go | 14 +- channel/persistence/keyvalue/restorer.go | 6 +- channel/persistence/nonpersister.go | 6 +- channel/persistence/persistence.go | 12 +- channel/persistence/test/channel.go | 6 +- channel/persistence/test/peerchans.go | 12 +- .../test/peerchans_internal_test.go | 2 +- channel/persistence/test/persistrestorer.go | 30 +- .../persistence/test/persistrestorertest.go | 10 +- channel/state.go | 8 +- channel/test/randomizer.go | 62 +- channel/test/randomopts.go | 18 +- channel/transaction_test.go | 4 +- client/channel.go | 2 +- client/channelconn.go | 6 +- client/chanregistry.go | 26 +- client/client.go | 4 +- client/proposal.go | 2 +- client/proposalmsgs.go | 12 +- client/restore.go | 18 +- client/restore_internal_test.go | 26 +- client/serialize.go | 38 +- client/subchannel.go | 12 +- client/sync.go | 4 +- client/syncmsgs.go | 2 +- client/test/backend.go | 64 +- client/test/persistence.go | 2 +- client/test/role.go | 10 +- client/test/subchannel_dispute.go | 4 +- client/test/virtualchannel.go | 2 +- client/updateinterception.go | 18 +- client/updatemsgs.go | 20 +- client/virtual_channel.go | 2 +- client/virtual_channel_settlement.go | 2 +- .../internal/mocks/AdjudicatorSubscription.go | 24 +- watcher/internal/mocks/RegisterSubscriber.go | 31 +- watcher/local/registry.go | 18 +- watcher/local/watcher.go | 24 +- watcher/local/watcher_test.go | 3 +- watcher/watcher.go | 4 +- wire/protobuf/proposalmsgs.go | 64 +- wire/protobuf/updatemsgs.go | 16 +- wire/protobuf/wire.pb.go | 1004 ++++++++++------- wire/protobuf/wire.proto | 25 +- 58 files changed, 1150 insertions(+), 788 deletions(-) diff --git a/channel/adjudicator.go b/channel/adjudicator.go index ddfd1a7b0..70c1a8f42 100644 --- a/channel/adjudicator.go +++ b/channel/adjudicator.go @@ -98,7 +98,7 @@ type ( // subscription should be closed by calling Close on the subscription after // the channel is closed. EventSubscriber interface { - Subscribe(context.Context, ID) (AdjudicatorSubscription, error) + Subscribe(context.Context, map[int]ID) (AdjudicatorSubscription, error) } // An AdjudicatorReq collects all necessary information to make calls to the @@ -158,7 +158,7 @@ type ( // cause, currently either a Registered or Progressed event. // The type of the event should be checked with a type switch. AdjudicatorEvent interface { - ID() ID + ID() map[int]ID Timeout() Timeout Version() uint64 } @@ -166,9 +166,9 @@ type ( // An AdjudicatorEventBase implements the AdjudicatorEvent interface. It can // be embedded to implement an AdjudicatorEvent. AdjudicatorEventBase struct { - IDV ID // Channel ID - TimeoutV Timeout // Current phase timeout - VersionV uint64 // Registered version + IDV map[int]ID // Channel ID + TimeoutV Timeout // Current phase timeout + VersionV uint64 // Registered version } // ProgressedEvent is the abstract event that signals an on-chain progression. @@ -204,7 +204,7 @@ type ( } // StateMap represents a channel state tree. - StateMap map[ID]*State + StateMap map[string]*State ) // NewProgressReq creates a new ProgressReq object. @@ -213,7 +213,7 @@ func NewProgressReq(ar AdjudicatorReq, newState *State, sig wallet.Sig) *Progres } // NewAdjudicatorEventBase creates a new AdjudicatorEventBase object. -func NewAdjudicatorEventBase(c ID, t Timeout, v uint64) *AdjudicatorEventBase { +func NewAdjudicatorEventBase(c map[int]ID, t Timeout, v uint64) *AdjudicatorEventBase { return &AdjudicatorEventBase{ IDV: c, TimeoutV: t, @@ -222,7 +222,7 @@ func NewAdjudicatorEventBase(c ID, t Timeout, v uint64) *AdjudicatorEventBase { } // ID returns the channel ID. -func (b AdjudicatorEventBase) ID() ID { return b.IDV } +func (b AdjudicatorEventBase) ID() map[int]ID { return b.IDV } // Timeout returns the phase timeout. func (b AdjudicatorEventBase) Timeout() Timeout { return b.TimeoutV } @@ -231,7 +231,7 @@ func (b AdjudicatorEventBase) Timeout() Timeout { return b.TimeoutV } func (b AdjudicatorEventBase) Version() uint64 { return b.VersionV } // NewRegisteredEvent creates a new RegisteredEvent. -func NewRegisteredEvent(id ID, timeout Timeout, version uint64, state *State, sigs []wallet.Sig) *RegisteredEvent { +func NewRegisteredEvent(id map[int]ID, timeout Timeout, version uint64, state *State, sigs []wallet.Sig) *RegisteredEvent { return &RegisteredEvent{ AdjudicatorEventBase: AdjudicatorEventBase{ IDV: id, @@ -244,7 +244,7 @@ func NewRegisteredEvent(id ID, timeout Timeout, version uint64, state *State, si } // NewProgressedEvent creates a new ProgressedEvent. -func NewProgressedEvent(id ID, timeout Timeout, state *State, idx Index) *ProgressedEvent { +func NewProgressedEvent(id map[int]ID, timeout Timeout, state *State, idx Index) *ProgressedEvent { return &ProgressedEvent{ AdjudicatorEventBase: AdjudicatorEventBase{ IDV: id, @@ -257,7 +257,7 @@ func NewProgressedEvent(id ID, timeout Timeout, state *State, idx Index) *Progre } // NewConcludedEvent creates a new ConcludedEvent. -func NewConcludedEvent(id ID, timeout Timeout, version uint64) *ConcludedEvent { +func NewConcludedEvent(id map[int]ID, timeout Timeout, version uint64) *ConcludedEvent { return &ConcludedEvent{ AdjudicatorEventBase: AdjudicatorEventBase{ IDV: id, @@ -302,12 +302,13 @@ func (t *TimeTimeout) String() string { // MakeStateMap creates a new StateMap object. func MakeStateMap() StateMap { - return make(map[ID]*State) + return make(map[string]*State) } // Add adds the given states to the state map. func (m StateMap) Add(states ...*State) { for _, s := range states { - m[s.ID] = s + key := IDKey(s.ID) + m[key] = s } } diff --git a/channel/allocation.go b/channel/allocation.go index b299af66f..48e6b3a91 100644 --- a/channel/allocation.go +++ b/channel/allocation.go @@ -80,7 +80,7 @@ type ( // The size of the balances slice must be of the same size as the assets slice // of the channel Params. SubAlloc struct { - ID ID + ID map[int]ID Bals []Bal IndexMap []Index // Maps participant indices of the sub-channel to participant indices of the parent channel. } @@ -547,7 +547,7 @@ func (b Balances) Sum() []Bal { } // NewSubAlloc creates a new sub-allocation. -func NewSubAlloc(id ID, bals []Bal, indexMap []Index) *SubAlloc { +func NewSubAlloc(id map[int]ID, bals []Bal, indexMap []Index) *SubAlloc { if indexMap == nil { indexMap = []Index{} } @@ -556,9 +556,9 @@ func NewSubAlloc(id ID, bals []Bal, indexMap []Index) *SubAlloc { // SubAlloc tries to return the sub-allocation for the given subchannel. // The second return value indicates success. -func (a Allocation) SubAlloc(subchannel ID) (subAlloc SubAlloc, ok bool) { +func (a Allocation) SubAlloc(subchannel map[int]ID) (subAlloc SubAlloc, ok bool) { for _, subAlloc = range a.Locked { - if subAlloc.ID == subchannel { + if EqualIDs(subAlloc.ID, subchannel) { ok = true return } @@ -577,10 +577,7 @@ func (a *Allocation) RemoveSubAlloc(subAlloc SubAlloc) error { for i := range a.Locked { if subAlloc.Equal(&a.Locked[i]) == nil { // remove element at index i - b := a.Locked - copy(b[i:], b[i+1:]) - b[len(b)-1] = SubAlloc{} - a.Locked = b[:len(b)-1] + a.Locked = append(a.Locked[:i], a.Locked[i+1:]...) return nil } } @@ -644,7 +641,7 @@ func (s SubAlloc) Encode(w io.Writer) error { err, "invalid sub-allocations cannot be encoded, got %v", s) } // encode ID and dimension - if err := perunio.Encode(w, s.ID, Index(len(s.Bals))); err != nil { + if err := perunio.Encode(w, IDMap(s.ID), Index(len(s.Bals))); err != nil { return errors.WithMessagef( err, "encoding sub-allocation ID or dimension, id %v", s.ID) } @@ -673,7 +670,7 @@ func (s SubAlloc) Encode(w io.Writer) error { func (s *SubAlloc) Decode(r io.Reader) error { var numAssets Index // decode ID and dimension - if err := perunio.Decode(r, &s.ID, &numAssets); err != nil { + if err := perunio.Decode(r, (*IDMap)(&s.ID), &numAssets); err != nil { return errors.WithMessage(err, "decoding sub-allocation ID or dimension") } if numAssets > MaxNumAssets { @@ -708,7 +705,7 @@ func (s *SubAlloc) Equal(t *SubAlloc) error { if s == t { return nil } - if s.ID != t.ID { + if !EqualIDs(s.ID, t.ID) { return errors.New("different ID") } if !s.BalancesEqual(t.Bals) { diff --git a/channel/allocation_test.go b/channel/allocation_test.go index 0751fbe5f..dcafa7ac7 100644 --- a/channel/allocation_test.go +++ b/channel/allocation_test.go @@ -270,6 +270,7 @@ func TestAllocationValidLimits(t *testing.T) { for ti, x := range inputs { allocation := &channel.Allocation{ Assets: make([]channel.Asset, x.numAssets), + Backends: make([]int, x.numAssets), Balances: make(channel.Balances, x.numAssets), Locked: make([]channel.SubAlloc, x.numSuballocations), } @@ -285,12 +286,12 @@ func TestAllocationValidLimits(t *testing.T) { for i := range allocation.Locked { allocation.Locked[i] = *channel.NewSubAlloc( - channel.ID{byte(i), byte(i >> 8), byte(i >> 16), byte(i >> 24)}, + map[int]channel.ID{0: {byte(i), byte(i >> 8), byte(i >> 16), byte(i >> 24)}}, make([]channel.Bal, x.numAssets), nil, ) allocation.Locked[i] = *channel.NewSubAlloc( - channel.ID{byte(i), byte(i >> 8), byte(i >> 16), byte(i >> 24)}, + map[int]channel.ID{0: {byte(i), byte(i >> 8), byte(i >> 16), byte(i >> 24)}}, make([]channel.Bal, x.numAssets), nil, ) @@ -381,7 +382,7 @@ func TestAllocation_Sum(t *testing.T) { { "single asset/one participants/one locked", - *test.NewRandomAllocation(rng, test.WithNumAssets(1), test.WithNumParts(1), test.WithLocked(*channel.NewSubAlloc(channel.ID{}, []channel.Bal{big.NewInt(2)}, nil)), test.WithBalancesInRange(big.NewInt(1), big.NewInt(1))), + *test.NewRandomAllocation(rng, test.WithNumAssets(1), test.WithNumParts(1), test.WithLocked(*channel.NewSubAlloc(map[int]channel.ID{}, []channel.Bal{big.NewInt(2)}, nil)), test.WithBalancesInRange(big.NewInt(1), big.NewInt(1))), []channel.Bal{big.NewInt(3)}, }, @@ -494,7 +495,7 @@ func TestAllocation_Valid(t *testing.T) { {big.NewInt(64), big.NewInt(128)}, }, Locked: []channel.SubAlloc{ - *channel.NewSubAlloc(channel.Zero, []channel.Bal{big.NewInt(4)}, nil), + *channel.NewSubAlloc(map[int]channel.ID{0: channel.Zero}, []channel.Bal{big.NewInt(4)}, nil), }, }, false, @@ -510,7 +511,7 @@ func TestAllocation_Valid(t *testing.T) { {big.NewInt(64), big.NewInt(128)}, }, Locked: []channel.SubAlloc{ - *channel.NewSubAlloc(channel.Zero, []channel.Bal{big.NewInt(-1)}, nil), + *channel.NewSubAlloc(map[int]channel.ID{0: channel.Zero}, []channel.Bal{big.NewInt(-1)}, nil), }, }, false, @@ -538,7 +539,7 @@ func TestAllocation_Valid(t *testing.T) { {big.NewInt(2), big.NewInt(16)}, }, Locked: []channel.SubAlloc{ - *channel.NewSubAlloc(channel.Zero, []channel.Bal{big.NewInt(4), big.NewInt(-1)}, nil), + *channel.NewSubAlloc(map[int]channel.ID{0: channel.Zero}, []channel.Bal{big.NewInt(4), big.NewInt(-1)}, nil), }, }, false, @@ -558,9 +559,9 @@ func TestAllocation_Valid(t *testing.T) { // suballocation serialization. func TestSuballocSerialization(t *testing.T) { ss := []perunio.Serializer{ - channel.NewSubAlloc(channel.ID{2}, []channel.Bal{}, nil), - channel.NewSubAlloc(channel.ID{3}, []channel.Bal{big.NewInt(0)}, nil), - channel.NewSubAlloc(channel.ID{4}, []channel.Bal{big.NewInt(5), big.NewInt(1 << 62)}, nil), + channel.NewSubAlloc(map[int]channel.ID{0: {2}}, []channel.Bal{}, nil), + channel.NewSubAlloc(map[int]channel.ID{0: {3}}, []channel.Bal{big.NewInt(0)}, nil), + channel.NewSubAlloc(map[int]channel.ID{0: {4}}, []channel.Bal{big.NewInt(5), big.NewInt(1 << 62)}, nil), } peruniotest.GenericSerializerTest(t, ss...) diff --git a/channel/backend.go b/channel/backend.go index 68e1e8421..5af67324d 100644 --- a/channel/backend.go +++ b/channel/backend.go @@ -63,22 +63,16 @@ func SetBackend(b Backend, id int) { } // CalcID calculates the CalcID. -func CalcID(p *Params) (ID, error) { - var lastErr error - for _, b := range backend { - id, err := b.CalcID(p) - if err == nil { - return id, nil - } else { - lastErr = err +func CalcID(p *Params) (map[int]ID, error) { + id := make(map[int]ID) + var err error + for i := range p.Parts[0] { + id[i], err = backend[i].CalcID(p) + if err != nil { + return nil, err } } - - if lastErr != nil { - return ID{}, errors.Join(lastErr) - } - - return ID{}, errors.New("no valid ID found") + return id, nil } // Sign creates a signature from the account a on state s. diff --git a/channel/errors.go b/channel/errors.go index 6d6809e0e..60b31453a 100644 --- a/channel/errors.go +++ b/channel/errors.go @@ -23,18 +23,18 @@ import ( type ( // StateTransitionError happens in case of an invalid channel state transition. StateTransitionError struct { - ID ID + ID map[int]ID } // ActionError happens if an invalid action is applied to a channel state. ActionError struct { - ID ID + ID map[int]ID } // PhaseTransitionError happens in case of an invalid channel machine phase // transition. PhaseTransitionError struct { - ID ID + ID map[int]ID current Phase PhaseTransition } @@ -56,20 +56,20 @@ func (e *PhaseTransitionError) Error() string { } // NewStateTransitionError creates a new StateTransitionError. -func NewStateTransitionError(id ID, msg string) error { +func NewStateTransitionError(id map[int]ID, msg string) error { return errors.Wrap(&StateTransitionError{ ID: id, }, msg) } // NewActionError creates a new ActionError. -func NewActionError(id ID, msg string) error { +func NewActionError(id map[int]ID, msg string) error { return errors.Wrap(&ActionError{ ID: id, }, msg) } -func newPhaseTransitionError(id ID, current Phase, expected PhaseTransition, msg string) error { +func newPhaseTransitionError(id map[int]ID, current Phase, expected PhaseTransition, msg string) error { return errors.Wrap(&PhaseTransitionError{ ID: id, current: current, @@ -78,7 +78,7 @@ func newPhaseTransitionError(id ID, current Phase, expected PhaseTransition, msg } func newPhaseTransitionErrorf( - id ID, + id map[int]ID, current Phase, expected PhaseTransition, format string, diff --git a/channel/errors_internal_test.go b/channel/errors_internal_test.go index 8f3477eff..25c0835a0 100644 --- a/channel/errors_internal_test.go +++ b/channel/errors_internal_test.go @@ -23,14 +23,14 @@ import ( func TestTransitionErrors(t *testing.T) { assert.False(t, IsStateTransitionError(errors.New("No StateTransitionError"))) - assert.True(t, IsStateTransitionError(NewStateTransitionError(Zero, "A StateTransitionError"))) + assert.True(t, IsStateTransitionError(NewStateTransitionError(map[int]ID{0: Zero}, "A StateTransitionError"))) assert.False(t, IsActionError(errors.New("No ActionError"))) - assert.True(t, IsActionError(NewActionError(Zero, "An ActionError"))) + assert.True(t, IsActionError(NewActionError(map[int]ID{0: Zero}, "An ActionError"))) assert.False(t, IsPhaseTransitionError(errors.New("No PhaseTransitionError"))) assert.True(t, IsPhaseTransitionError(newPhaseTransitionError( - Zero, InitActing, PhaseTransition{InitActing, InitActing}, "A PhaseTransitionError"))) + map[int]ID{0: Zero}, InitActing, PhaseTransition{InitActing, InitActing}, "A PhaseTransitionError"))) assert.True(t, IsPhaseTransitionError(newPhaseTransitionErrorf( - Zero, InitActing, PhaseTransition{InitActing, InitActing}, "A %s", "PhaseTransitionError"))) + map[int]ID{0: Zero}, InitActing, PhaseTransition{InitActing, InitActing}, "A %s", "PhaseTransitionError"))) } diff --git a/channel/machine.go b/channel/machine.go index f9585177b..37f51c782 100644 --- a/channel/machine.go +++ b/channel/machine.go @@ -54,7 +54,7 @@ type ( // needed for persistence. The ID, Idx and Params only need to be persisted // once per channel as they stay constant during a channel's lifetime. Source interface { - ID() ID // ID is the channel ID of this source. It is the same as Params().ID(). + ID() map[int]ID // ID is the channel ID of this source. It is the same as Params().ID(). Idx() Index // Idx is the own index in the channel. Params() *Params // Params are the channel parameters. StagingTX() Transaction // StagingTX is the staged transaction (State+incomplete list of sigs). @@ -168,7 +168,7 @@ func restoreMachine(acc wallet.Account, source Source) (*machine, error) { } // ID returns the channel id. -func (m *machine) ID() ID { +func (m *machine) ID() map[int]ID { return m.params.ID() } @@ -484,7 +484,7 @@ func (m *machine) expect(tr PhaseTransition) error { // A StateMachine will additionally check the validity of the app-specific // transition whereas an ActionMachine checks each Action as being valid. func (m *machine) ValidTransition(to *State) error { - if to.ID != m.params.id { + if !EqualIDs(to.ID, m.params.id) { return errors.New("new state's ID doesn't match") } diff --git a/channel/machine_test.go b/channel/machine_test.go index f381163c2..6dcc0ff5e 100644 --- a/channel/machine_test.go +++ b/channel/machine_test.go @@ -32,9 +32,11 @@ func TestMachineClone(t *testing.T) { sm, err := channel.NewStateMachine(acc, params) require.NoError(t, err) - pkgtest.VerifyClone(t, sm) + cloneSM := sm.Clone() + require.Equal(t, sm, cloneSM) am, err := channel.NewActionMachine(acc, params) require.NoError(t, err) - pkgtest.VerifyClone(t, am) + cloneAM := am.Clone() + require.Equal(t, am, cloneAM) } diff --git a/channel/mock_app.go b/channel/mock_app.go index b8dc4f6be..5b89f41d9 100644 --- a/channel/mock_app.go +++ b/channel/mock_app.go @@ -168,9 +168,9 @@ func (a MockApp) execMockOp(op *MockOp) error { case OpErr: return errors.New("MockOp: runtime error") case OpTransitionErr: - return NewStateTransitionError(ID{}, "MockOp: state transition error") + return NewStateTransitionError(map[int]ID{}, "MockOp: state transition error") case OpActionErr: - return NewActionError(ID{}, "MockOp: action error") + return NewActionError(map[int]ID{}, "MockOp: action error") case OpPanic: panic("MockOp: panic") case OpValid: diff --git a/channel/mock_app_internal_test.go b/channel/mock_app_internal_test.go index c0f4b1c00..238ae6257 100644 --- a/channel/mock_app_internal_test.go +++ b/channel/mock_app_internal_test.go @@ -141,5 +141,5 @@ func MockActionAppTest(t *testing.T, app MockApp) { } func createState(op MockOp) *State { - return &State{ID: ID{}, Version: 0, Allocation: Allocation{}, Data: NewMockOp(op), IsFinal: false} + return &State{ID: map[int]ID{}, Version: 0, Allocation: Allocation{}, Data: NewMockOp(op), IsFinal: false} } diff --git a/channel/multi/subscription.go b/channel/multi/subscription.go index ddcca7912..93bfef673 100644 --- a/channel/multi/subscription.go +++ b/channel/multi/subscription.go @@ -21,7 +21,7 @@ import ( ) // Subscribe creates a new multi-ledger AdjudicatorSubscription. -func (a *Adjudicator) Subscribe(ctx context.Context, chID channel.ID) (channel.AdjudicatorSubscription, error) { +func (a *Adjudicator) Subscribe(ctx context.Context, chID map[int]channel.ID) (channel.AdjudicatorSubscription, error) { asub := &AdjudicatorSubscription{ events: make(chan channel.AdjudicatorEvent), errors: make(chan error), diff --git a/channel/params.go b/channel/params.go index 1079f9a83..a620f2c25 100644 --- a/channel/params.go +++ b/channel/params.go @@ -15,8 +15,11 @@ package channel import ( + "bytes" + "encoding/binary" stdio "io" "math/big" + "strings" "github.com/pkg/errors" @@ -31,6 +34,9 @@ const IDLen = 32 // ID represents a channelID. type ID = [IDLen]byte +// IDMap is a map of IDs with keys corresponding to backendIDs +type IDMap map[int]ID + // MaxNonceLen is the maximum byte count of a nonce. const MaxNonceLen = 32 @@ -51,6 +57,103 @@ func NonceFromBytes(b []byte) Nonce { // Zero is the default channelID. var Zero = ID{} +func EqualIDs(a, b map[int]ID) bool { + if len(a) != len(b) { + return false + } + + // Compare each key-value pair + for key, val1 := range a { + val2, exists := b[key] + if !exists || val1 != val2 { + return false + } + } + + return true +} + +func (ids IDMap) Encode(w stdio.Writer) error { + length := int32(len(ids)) + if err := perunio.Encode(w, length); err != nil { + return errors.WithMessage(err, "encoding map length") + } + for i, id := range ids { + if err := perunio.Encode(w, int32(i)); err != nil { + return errors.WithMessage(err, "encoding map index") + } + if err := perunio.Encode(w, id); err != nil { + return errors.WithMessagef(err, "encoding %d-th channel id map entry", i) + } + } + return nil +} + +func (ids *IDMap) Decode(r stdio.Reader) error { + var mapLen int32 + if err := perunio.Decode(r, &mapLen); err != nil { + return errors.WithMessage(err, "decoding map length") + } + *ids = make(map[int]ID, mapLen) + for i := 0; i < int(mapLen); i++ { + var idx int32 + if err := perunio.Decode(r, &idx); err != nil { + return errors.WithMessage(err, "decoding map index") + } + id := ID{} + if err := perunio.Decode(r, &id); err != nil { + return errors.WithMessagef(err, "decoding %d-th address map entry", i) + } + (*ids)[int(idx)] = id + } + return nil +} + +func IDKey(ids IDMap) string { + var buff strings.Builder + // Encode the number of elements in the map first. + length := int32(len(ids)) // Using int32 to encode the length + err := binary.Write(&buff, binary.BigEndian, length) + if err != nil { + log.Panic("could not encode map length in Key: ", err) + + } + // Iterate over the map and encode each key-value pair. + for key, id := range ids { + if err := binary.Write(&buff, binary.BigEndian, int32(key)); err != nil { + log.Panicf("could not encode map key: " + err.Error()) + } + if err := perunio.Encode(&buff, id); err != nil { + log.Panicf("could not encode map[int]ID: " + err.Error()) + } + } + return buff.String() +} + +func FromIDKey(k string) IDMap { + buff := bytes.NewBuffer([]byte(k)) + var numElements int32 + + // Manually decode the number of elements in the map. + if err := binary.Read(buff, binary.BigEndian, &numElements); err != nil { + log.Panicf("could not decode map length in FromIDKey: " + err.Error()) + } + a := make(map[int]ID, numElements) + // Decode each key-value pair and insert them into the map. + for i := 0; i < int(numElements); i++ { + var key int32 + if err := binary.Read(buff, binary.BigEndian, &key); err != nil { + log.Panicf("could not decode map key in FromIDKey: " + err.Error()) + } + id := ID{} + if err := perunio.Decode(buff, id); err != nil { + log.Panicf("could not decode map[int]ID in FromIDKey: " + err.Error()) + } + a[int(key)] = id + } + return a +} + var _ perunio.Serializer = (*Params)(nil) // Params are a channel's immutable parameters. A channel's id is the hash of @@ -59,7 +162,7 @@ var _ perunio.Serializer = (*Params)(nil) // It should only be created through NewParams(). type Params struct { // ChannelID is the channel ID as calculated by the backend - id ID + id map[int]ID // ChallengeDuration in seconds during disputes ChallengeDuration uint64 // Parts are the channel participants @@ -76,7 +179,7 @@ type Params struct { } // ID returns the channelID of this channel. -func (p *Params) ID() ID { +func (p *Params) ID() map[int]ID { return p.id } @@ -152,7 +255,7 @@ func NewParamsUnsafe(challengeDuration uint64, parts []map[int]wallet.Address, a // probably an expensive hash operation, do it only once during creation. id, err := CalcID(p) - if err != nil || id == Zero { + if err != nil || EqualIDs(id, map[int]ID{}) { log.Panicf("Could not calculate channel id: %v", err) } p.id = id @@ -187,7 +290,7 @@ func (p *Params) Encode(w stdio.Writer) error { return perunio.Encode(w, p.ChallengeDuration, - wallet.AddressMapArray{p.Parts}, + wallet.AddressMapArray{Addr: p.Parts}, OptAppEnc{App: p.App}, p.Nonce, p.LedgerChannel, diff --git a/channel/params_test.go b/channel/params_test.go index 44981b787..7aa12eebf 100644 --- a/channel/params_test.go +++ b/channel/params_test.go @@ -15,6 +15,7 @@ package channel_test import ( + "github.com/stretchr/testify/require" "testing" "perun.network/go-perun/channel" @@ -27,7 +28,13 @@ import ( func TestParams_Clone(t *testing.T) { rng := pkgtest.Prng(t) params := test.NewRandomParams(rng) - pkgtest.VerifyClone(t, params) + clone := params.Clone() + + require.Equalf(t, params.Parts, clone.Parts, "Clone() = %v, want %v", clone, params) + require.Equalf(t, params.App, clone.App, "Clone() = %v, want %v", clone, params) + require.Equalf(t, params.ChallengeDuration, clone.ChallengeDuration, "Clone() = %v, want %v", clone, params) + require.Equalf(t, params.Nonce, clone.Nonce, "Clone() = %v, want %v", clone, params) + } func TestParams_Serializer(t *testing.T) { diff --git a/channel/persistence/keyvalue/persistedstate.go b/channel/persistence/keyvalue/persistedstate.go index dd625f434..b9c9b6282 100644 --- a/channel/persistence/keyvalue/persistedstate.go +++ b/channel/persistence/keyvalue/persistedstate.go @@ -48,17 +48,17 @@ func (s *PersistedState) Decode(r io.Reader) error { type ( optChannelIDEnc struct { - ID *channel.ID + ID *map[int]channel.ID } optChannelIDDec struct { - ID **channel.ID + ID **map[int]channel.ID } ) func (id optChannelIDEnc) Encode(w io.Writer) error { if id.ID != nil { - return perunio.Encode(w, true, *id.ID) + return perunio.Encode(w, true, channel.IDMap(*id.ID)) } return perunio.Encode(w, false) } @@ -69,8 +69,8 @@ func (id optChannelIDDec) Decode(r io.Reader) error { return err } if exists { - *id.ID = new(channel.ID) - return perunio.Decode(r, *id.ID) + *id.ID = new(map[int]channel.ID) + return perunio.Decode(r, (*channel.IDMap)(*id.ID)) } *id.ID = nil return nil diff --git a/channel/persistence/keyvalue/persister.go b/channel/persistence/keyvalue/persister.go index 05fa3a111..5fa43c7c4 100644 --- a/channel/persistence/keyvalue/persister.go +++ b/channel/persistence/keyvalue/persister.go @@ -32,7 +32,7 @@ import ( ) // ChannelCreated inserts a channel into the database. -func (pr *PersistRestorer) ChannelCreated(_ context.Context, s channel.Source, peers []map[int]wire.Address, parent *channel.ID) error { +func (pr *PersistRestorer) ChannelCreated(_ context.Context, s channel.Source, peers []map[int]wire.Address, parent *map[int]channel.ID) error { db := pr.channelDB(s.ID()).NewBatch() // Write the channel data in the "Channel" table. numParts := len(s.Params().Parts) @@ -77,7 +77,7 @@ func sigKey(idx, numParts int) string { } // ChannelRemoved deletes a channel from the database. -func (pr *PersistRestorer) ChannelRemoved(ctx context.Context, id channel.ID) error { +func (pr *PersistRestorer) ChannelRemoved(ctx context.Context, id map[int]channel.ID) error { db := pr.channelDB(id).NewBatch() peerdb := sortedkv.NewTable(pr.db, prefix.PeerDB).NewBatch() // All keys a channel has. @@ -116,7 +116,7 @@ func (pr *PersistRestorer) ChannelRemoved(ctx context.Context, id channel.ID) er // paramsForChan returns the channel parameters for a given channel id from // the db. -func (pr *PersistRestorer) paramsForChan(id channel.ID) (channel.Params, error) { +func (pr *PersistRestorer) paramsForChan(id map[int]channel.ID) (channel.Params, error) { params := channel.Params{} b, err := pr.channelDB(id).GetBytes("params") if err != nil { @@ -244,19 +244,19 @@ func decodeIdxFromDBKey(key string) (int, error) { return strconv.Atoi(vals[len(vals)-1]) } -func peerChannelKey(p map[int]wire.Address, ch channel.ID) (string, error) { +func peerChannelKey(p map[int]wire.Address, ch map[int]channel.ID) (string, error) { var key bytes.Buffer if err := perunio.Encode(&key, wire.AddressDecMap(p)); err != nil { return "", errors.WithMessage(err, "encoding peer address") } key.WriteString(":channel:") - if err := perunio.Encode(&key, ch); err != nil { + if err := perunio.Encode(&key, channel.IDMap(ch)); err != nil { return "", errors.WithMessage(err, "encoding channel id") } return key.String(), nil } // channelDB creates a prefixed database for persisting a channel's data. -func (pr *PersistRestorer) channelDB(id channel.ID) sortedkv.Database { - return sortedkv.NewTable(pr.db, prefix.ChannelDB+string(id[:])+":") +func (pr *PersistRestorer) channelDB(id map[int]channel.ID) sortedkv.Database { + return sortedkv.NewTable(pr.db, prefix.ChannelDB+channel.IDKey(id)+":") } diff --git a/channel/persistence/keyvalue/restorer.go b/channel/persistence/keyvalue/restorer.go index f7f1ada8c..2fa2fb0ce 100644 --- a/channel/persistence/keyvalue/restorer.go +++ b/channel/persistence/keyvalue/restorer.go @@ -63,7 +63,7 @@ func (pr *PersistRestorer) ActivePeers(ctx context.Context) ([]map[int]wire.Addr // channelPeers returns a slice of peer addresses for a given channel id from // the db of PersistRestorer. -func (pr *PersistRestorer) channelPeers(id channel.ID) ([]map[int]wire.Address, error) { +func (pr *PersistRestorer) channelPeers(id map[int]channel.ID) ([]map[int]wire.Address, error) { var ps wire.AddressMapArray peers, err := pr.channelDB(id).Get(prefix.Peers) if err != nil { @@ -116,11 +116,11 @@ func peerChannelsKey(addr map[int]wire.Address) (string, error) { } // RestoreChannel restores a single channel. -func (pr *PersistRestorer) RestoreChannel(ctx context.Context, id channel.ID) (*persistence.Channel, error) { +func (pr *PersistRestorer) RestoreChannel(ctx context.Context, id map[int]channel.ID) (*persistence.Channel, error) { chandb := sortedkv.NewTable(pr.db, prefix.ChannelDB) it := &ChannelIterator{ restorer: pr, - its: []sortedkv.Iterator{chandb.NewIteratorWithPrefix(string(id[:]))}, + its: []sortedkv.Iterator{chandb.NewIteratorWithPrefix(channel.IDKey(id))}, } if it.Next(ctx) { diff --git a/channel/persistence/nonpersister.go b/channel/persistence/nonpersister.go index 5334718d8..9411e4181 100644 --- a/channel/persistence/nonpersister.go +++ b/channel/persistence/nonpersister.go @@ -32,10 +32,10 @@ type nonPersistRestorer struct{} // Persister implementation -func (nonPersistRestorer) ChannelCreated(context.Context, channel.Source, []map[int]wire.Address, *channel.ID) error { +func (nonPersistRestorer) ChannelCreated(context.Context, channel.Source, []map[int]wire.Address, *map[int]channel.ID) error { return nil } -func (nonPersistRestorer) ChannelRemoved(context.Context, channel.ID) error { return nil } +func (nonPersistRestorer) ChannelRemoved(context.Context, map[int]channel.ID) error { return nil } func (nonPersistRestorer) Staged(context.Context, channel.Source) error { return nil } func (nonPersistRestorer) SigAdded(context.Context, channel.Source, channel.Index) error { return nil } func (nonPersistRestorer) Enabled(context.Context, channel.Source) error { return nil } @@ -56,7 +56,7 @@ func (nonPersistRestorer) RestorePeer(map[int]wire.Address) (ChannelIterator, er return emptyChanIterator{}, nil } -func (nonPersistRestorer) RestoreChannel(context.Context, channel.ID) (*Channel, error) { +func (nonPersistRestorer) RestoreChannel(context.Context, map[int]channel.ID) (*Channel, error) { return nil, errors.New("channel not found") } diff --git a/channel/persistence/persistence.go b/channel/persistence/persistence.go index 0750cf0a4..2db31d59b 100644 --- a/channel/persistence/persistence.go +++ b/channel/persistence/persistence.go @@ -35,12 +35,12 @@ type ( // state will be empty. The passed peers are the channel network peers, // which should also be persisted. The parent field is the parent // channel's ID, or nil, if it is a ledger channel. - ChannelCreated(ctx context.Context, source channel.Source, peers []map[int]wire.Address, parent *channel.ID) error + ChannelCreated(ctx context.Context, source channel.Source, peers []map[int]wire.Address, parent *map[int]channel.ID) error // ChannelRemoved is called by the client when a channel is removed because // it has been successfully settled and its data is no longer needed. All // data associated with this channel may be discarded. - ChannelRemoved(ctx context.Context, id channel.ID) error + ChannelRemoved(ctx context.Context, id map[int]channel.ID) error // Staged is called when a new valid state got set as the new staging // state. It may already contain one valid signature, either by a remote @@ -79,7 +79,7 @@ type ( RestorePeer(map[int]wire.Address) (ChannelIterator, error) // RestoreChannel should return the channel with the requested ID. - RestoreChannel(context.Context, channel.ID) (*Channel, error) + RestoreChannel(context.Context, map[int]channel.ID) (*Channel, error) } // PersistRestorer is a Persister and Restorer on the same data source and @@ -126,7 +126,7 @@ type ( Channel struct { chSource PeersV []map[int]wire.Address - Parent *channel.ID + Parent *map[int]channel.ID } ) @@ -156,7 +156,7 @@ func NewChannel() *Channel { // FromSource creates a new Channel object from given `channel.Source`, the // channel's network peers, and the parent channel ID, if it exists. -func FromSource(s channel.Source, ps []map[int]wire.Address, parent *channel.ID) *Channel { +func FromSource(s channel.Source, ps []map[int]wire.Address, parent *map[int]channel.ID) *Channel { return &Channel{ chSource{ IdxV: s.Idx(), @@ -171,7 +171,7 @@ func FromSource(s channel.Source, ps []map[int]wire.Address, parent *channel.ID) } // ID is the channel ID of this source. It is the same as Params().ID(). -func (c *chSource) ID() channel.ID { return c.ParamsV.ID() } +func (c *chSource) ID() map[int]channel.ID { return c.ParamsV.ID() } // Idx is the own index in the channel. func (c *chSource) Idx() channel.Index { return c.IdxV } diff --git a/channel/persistence/test/channel.go b/channel/persistence/test/channel.go index bde5aed0a..abb1b5c25 100644 --- a/channel/persistence/test/channel.go +++ b/channel/persistence/test/channel.go @@ -33,7 +33,7 @@ import ( type Channel struct { accounts []wallet.Account peers []map[int]wire.Address - parent *channel.ID + parent *map[int]channel.ID *persistence.StateMachine pr persistence.PersistRestorer @@ -61,9 +61,9 @@ func NewRandomChannel( csm, err := channel.NewStateMachine(accs[0], *params) require.NoError(t, err) - var parentID *channel.ID + var parentID *map[int]channel.ID if parent != nil { - parentID = new(channel.ID) + parentID = new(map[int]channel.ID) *parentID = parent.ID() } diff --git a/channel/persistence/test/peerchans.go b/channel/persistence/test/peerchans.go index a4832edf6..04e2f8550 100644 --- a/channel/persistence/test/peerchans.go +++ b/channel/persistence/test/peerchans.go @@ -23,9 +23,9 @@ import ( "perun.network/go-perun/wire/perunio" ) -type peerChans map[string][]channel.ID +type peerChans map[string][]map[int]channel.ID -func (pc peerChans) ID(p map[int]wire.Address) []channel.ID { +func (pc peerChans) ID(p map[int]wire.Address) []map[int]channel.ID { ids, ok := pc[peerKey(p)] if !ok { return nil @@ -43,23 +43,23 @@ func (pc peerChans) Peers() []map[int]wire.Address { } // Add adds the given channel id to each peer's id list. -func (pc peerChans) Add(id channel.ID, ps ...map[int]wire.Address) { +func (pc peerChans) Add(id map[int]channel.ID, ps ...map[int]wire.Address) { for _, p := range ps { pc.add(id, p) } } // Don't use add, use Add. -func (pc peerChans) add(id channel.ID, p map[int]wire.Address) { +func (pc peerChans) add(id map[int]channel.ID, p map[int]wire.Address) { pk := peerKey(p) ids := pc[pk] // nil ok, since we append pc[pk] = append(ids, id) } -func (pc peerChans) Delete(id channel.ID) { +func (pc peerChans) Delete(id map[int]channel.ID) { for pk, ids := range pc { for i, pid := range ids { - if id == pid { + if channel.EqualIDs(id, pid) { // ch found, unsorted delete lim := len(ids) - 1 if lim == 0 { diff --git a/channel/persistence/test/peerchans_internal_test.go b/channel/persistence/test/peerchans_internal_test.go index fe68475a0..fe62e09af 100644 --- a/channel/persistence/test/peerchans_internal_test.go +++ b/channel/persistence/test/peerchans_internal_test.go @@ -29,7 +29,7 @@ import ( func TestEndpointChans(t *testing.T) { assert := assert.New(t) rng := pkgtest.Prng(t) - id := []channel.ID{ctest.NewRandomChannelID(rng), ctest.NewRandomChannelID(rng)} + id := []map[int]channel.ID{ctest.NewRandomChannelID(rng), ctest.NewRandomChannelID(rng)} ps := wiretest.NewRandomAddressesMap(rng, 3) pc := make(peerChans) diff --git a/channel/persistence/test/persistrestorer.go b/channel/persistence/test/persistrestorer.go index 0bfafda14..65f0c51a1 100644 --- a/channel/persistence/test/persistrestorer.go +++ b/channel/persistence/test/persistrestorer.go @@ -38,7 +38,7 @@ type PersistRestorer struct { t *testing.T mu sync.RWMutex // protects chans map and peerChans access - chans map[channel.ID]*persistence.Channel + chans map[string]*persistence.Channel pcs peerChans } @@ -48,7 +48,7 @@ func NewPersistRestorer(t *testing.T) *PersistRestorer { t.Helper() return &PersistRestorer{ t: t, - chans: make(map[channel.ID]*persistence.Channel), + chans: make(map[string]*persistence.Channel), pcs: make(peerChans), } } @@ -57,32 +57,32 @@ func NewPersistRestorer(t *testing.T) *PersistRestorer { // ChannelCreated fully persists all of the source's data. func (pr *PersistRestorer) ChannelCreated( - _ context.Context, source channel.Source, peers []map[int]wire.Address, parent *channel.ID, + _ context.Context, source channel.Source, peers []map[int]wire.Address, parent *map[int]channel.ID, ) error { pr.mu.Lock() defer pr.mu.Unlock() id := source.ID() - _, ok := pr.chans[id] + _, ok := pr.chans[channel.IDKey(id)] if ok { return errors.Errorf("channel already persisted: %x", id) } - pr.chans[id] = persistence.FromSource(source, peers, parent) + pr.chans[channel.IDKey(id)] = persistence.FromSource(source, peers, parent) pr.pcs.Add(id, peers...) return nil } // ChannelRemoved removes the channel from the test persister's memory. -func (pr *PersistRestorer) ChannelRemoved(_ context.Context, id channel.ID) error { +func (pr *PersistRestorer) ChannelRemoved(_ context.Context, id map[int]channel.ID) error { pr.mu.Lock() defer pr.mu.Unlock() - _, ok := pr.chans[id] + _, ok := pr.chans[channel.IDKey(id)] if !ok { return errors.Errorf("channel doesn't exist: %x", id) } - delete(pr.chans, id) + delete(pr.chans, channel.IDKey(id)) pr.pcs.Delete(id) return nil } @@ -141,7 +141,7 @@ func (pr *PersistRestorer) PhaseChanged(_ context.Context, s channel.Source) err // Close resets the persister's memory, i.e., all internally persisted channel // data is deleted. It can be reused afterwards. func (pr *PersistRestorer) Close() error { - pr.chans = make(map[channel.ID]*persistence.Channel) + pr.chans = make(map[string]*persistence.Channel) return nil } @@ -163,7 +163,7 @@ func (pr *PersistRestorer) AssertEqual(s channel.Source) { } // AssertNotExists asserts that a channel with the given ID does not exist. -func (pr *PersistRestorer) AssertNotExists(id channel.ID) { +func (pr *PersistRestorer) AssertNotExists(id map[int]channel.ID) { _, ok := pr.channel(id) assert.Falsef(pr.t, ok, "channel shouldn't exist: %x", id) } @@ -172,10 +172,10 @@ func (pr *PersistRestorer) AssertNotExists(id channel.ID) { // Since persister access is guaranteed to be single-threaded per channel, it // makes sense for the Persister implementation methods to use this getter to // channel the pointer to the channel storage. -func (pr *PersistRestorer) channel(id channel.ID) (*persistence.Channel, bool) { +func (pr *PersistRestorer) channel(id map[int]channel.ID) (*persistence.Channel, bool) { pr.mu.Lock() defer pr.mu.Unlock() - ch, ok := pr.chans[id] + ch, ok := pr.chans[channel.IDKey(id)] return ch, ok } @@ -201,17 +201,17 @@ func (pr *PersistRestorer) RestorePeer(peer map[int]wire.Address) (persistence.C idx: -1, } for i, id := range ids { - it.chans[i] = pr.chans[id] + it.chans[i] = pr.chans[channel.IDKey(id)] } return it, nil } // RestoreChannel should return the channel with the requested ID. -func (pr *PersistRestorer) RestoreChannel(_ context.Context, id channel.ID) (*persistence.Channel, error) { +func (pr *PersistRestorer) RestoreChannel(_ context.Context, id map[int]channel.ID) (*persistence.Channel, error) { pr.mu.RLock() defer pr.mu.RUnlock() - ch, ok := pr.chans[id] + ch, ok := pr.chans[channel.IDKey(id)] if !ok { return nil, errors.Errorf("channel not found: %x", id) } diff --git a/channel/persistence/test/persistrestorertest.go b/channel/persistence/test/persistrestorertest.go index c13f070fa..46560bd4d 100644 --- a/channel/persistence/test/persistrestorertest.go +++ b/channel/persistence/test/persistrestorertest.go @@ -86,7 +86,7 @@ func GenericPersistRestorerTest( ) { t.Helper() t.Run("RestoreChannel error", func(t *testing.T) { - var id channel.ID + var id map[int]channel.ID ch, err := pr.RestoreChannel(context.Background(), id) assert.Error(t, err) assert.Nil(t, ch) @@ -96,10 +96,10 @@ func GenericPersistRestorerTest( c := NewClient(ctx, t, rng, pr) peers := test.NewRandomAddressesMap(rng, numPeers) - channels := make([]map[channel.ID]*Channel, numPeers) + channels := make([]map[string]*Channel, numPeers) var prevCh *Channel for p := 0; p < numPeers; p++ { - channels[p] = make(map[channel.ID]*Channel) + channels[p] = make(map[string]*Channel) for i := 0; i < numChans; i++ { var parent *Channel // Every second channel is set to have a parent. @@ -108,7 +108,7 @@ func GenericPersistRestorerTest( } ch := c.NewChannel(t, peers[p], parent) prevCh = ch - channels[p][ch.ID()] = ch + channels[p][channel.IDKey(ch.ID())] = ch t.Logf("created channel %d for peer %d", i, p) } } @@ -173,7 +173,7 @@ func GenericPersistRestorerTest( for it.Next(ctx) { ch := it.Channel() - cached := channels[pIdx][ch.ID()] + cached := channels[pIdx][channel.IDKey(ch.ID())] cached.RequireEqual(t, ch) } } diff --git a/channel/state.go b/channel/state.go index a2f349a75..09134ed4e 100644 --- a/channel/state.go +++ b/channel/state.go @@ -32,7 +32,7 @@ type ( // during disputes. State struct { // id is the immutable id of the channel this state belongs to - ID ID + ID map[int]ID // version counter Version uint64 // App identifies the application that this channel is running. @@ -114,14 +114,14 @@ func (s *State) Clone() *State { // Encode encodes a state into an `io.Writer` or returns an `error`. func (s State) Encode(w io.Writer) error { return errors.WithMessage( - perunio.Encode(w, s.ID, s.Version, s.Allocation, s.IsFinal, OptAppAndDataEnc{s.App, s.Data}), + perunio.Encode(w, IDMap(s.ID), s.Version, s.Allocation, s.IsFinal, OptAppAndDataEnc{s.App, s.Data}), "state encode") } // Decode decodes a state from an `io.Reader` or returns an `error`. func (s *State) Decode(r io.Reader) error { return errors.WithMessage( - perunio.Decode(r, &s.ID, &s.Version, &s.Allocation, &s.IsFinal, &OptAppAndDataDec{&s.App, &s.Data}), + perunio.Decode(r, (*IDMap)(&s.ID), &s.Version, &s.Allocation, &s.IsFinal, &OptAppAndDataDec{&s.App, &s.Data}), "app decode") } @@ -131,7 +131,7 @@ func (s *State) Equal(t *State) error { if s == t { return nil } - if s.ID != t.ID { + if !EqualIDs(s.ID, t.ID) { return errors.New("different IDs") } if s.Version != t.Version { diff --git a/channel/test/randomizer.go b/channel/test/randomizer.go index c0ae216b4..d9d2f0ecc 100644 --- a/channel/test/randomizer.go +++ b/channel/test/randomizer.go @@ -17,7 +17,6 @@ package test import ( crand "crypto/rand" "fmt" - "log" "math/big" "math/rand" "time" @@ -109,17 +108,40 @@ func NewRandomLocked(rng *rand.Rand, opts ...RandomOpt) []channel.SubAlloc { // NewRandomLockedIDs generates new random `channel.ID`s used in `channel.SubAlloc`. // Options: `WithLockedIDs` and `WithNumLocked`. -func NewRandomLockedIDs(rng *rand.Rand, opts ...RandomOpt) []channel.ID { +func NewRandomLockedIDs(rng *rand.Rand, opts ...RandomOpt) []map[int]channel.ID { opt := mergeRandomOpts(opts...) if ids := opt.LockedIDs(rng); ids != nil { return ids } - numLockedIds := opt.NumLocked(rng) - ids := make([]channel.ID, numLockedIds) - for i := range ids { - rng.Read(ids[i][:]) + bIds, err := opt.BackendID() + if err == nil && bIds != nil { + ids := make([]map[int]channel.ID, numLockedIds) + for i, _ := range ids { + for j := range bIds { + ids[i] = make(map[int]channel.ID) + cId := [32]byte{} + rng.Read(cId[:]) + ids[i][j] = cId + } + } + return ids + } + b, err := opt.Backend() + ids := make([]map[int]channel.ID, numLockedIds) + for i, _ := range ids { + if err != nil { + ids[i] = make(map[int]channel.ID) + cId := [32]byte{} + rng.Read(cId[:]) + ids[i][0] = cId + } else { + ids[i] = make(map[int]channel.ID) + cId := [32]byte{} + rng.Read(cId[:]) + ids[i][b] = cId + } } return ids } @@ -216,22 +238,38 @@ func NewRandomState(rng *rand.Rand, opts ...RandomOpt) (state *channel.State) { // NewRandomChannelID generates a new random `channel.ID`. // Options: `WithID`. -func NewRandomChannelID(rng *rand.Rand, opts ...RandomOpt) (id channel.ID) { +func NewRandomChannelID(rng *rand.Rand, opts ...RandomOpt) (id map[int]channel.ID) { opt := mergeRandomOpts(opts...) if id, valid := opt.ID(); valid { return id } - - if _, err := rng.Read(id[:]); err != nil { - log.Panic("could not read from rng") + id = make(map[int]channel.ID) + bIds, err := opt.BackendID() + if bIds != nil && err == nil { + for _, b := range bIds { + cId := [32]byte{} + rng.Read(cId[:]) + id[b] = cId + } + return + } + bId, err := opt.Backend() + if err != nil { + cId := [32]byte{} + rng.Read(cId[:]) + id[0] = cId + } else { + cId := [32]byte{} + rng.Read(cId[:]) + id[bId] = cId } return } // NewRandomChannelIDs generates a list of random channel IDs. -func NewRandomChannelIDs(rng *rand.Rand, n int) (ids []channel.ID) { - ids = make([]channel.ID, n) +func NewRandomChannelIDs(rng *rand.Rand, n int) (ids []map[int]channel.ID) { + ids = make([]map[int]channel.ID, n) for i := range ids { ids[i] = NewRandomChannelID(rng) } diff --git a/channel/test/randomopts.go b/channel/test/randomopts.go index e1345888c..57f2184f5 100644 --- a/channel/test/randomopts.go +++ b/channel/test/randomopts.go @@ -127,7 +127,7 @@ func WithFirstPart(part map[int]wallet.Address) RandomOpt { } // WithID sets the channel ID that should be used. -func WithID(id channel.ID) RandomOpt { +func WithID(id map[int]channel.ID) RandomOpt { return RandomOpt{"id": id} } @@ -153,7 +153,7 @@ func WithLockedBals(bals ...channel.Bal) RandomOpt { } // WithLockedID sets the channel id that should be used when generating a single sub-allocation with `NewRandomSubAlloc`. -func WithLockedID(id channel.ID) RandomOpt { +func WithLockedID(id map[int]channel.ID) RandomOpt { return RandomOpt{"lockedId": id} } @@ -347,11 +347,11 @@ func (o RandomOpt) ChallengeDuration(rng *rand.Rand) uint64 { // ID returns the `ID` value of the `RandomOpt`. // If not present, returns `false` as second argument. -func (o RandomOpt) ID() (id channel.ID, valid bool) { +func (o RandomOpt) ID() (id map[int]channel.ID, valid bool) { if _, ok := o["id"]; !ok { - return channel.ID{}, false + return map[int]channel.ID{}, false } - return o["id"].(channel.ID), true + return o["id"].(map[int]channel.ID), true } // FirstPart returns the `FirstPart` value of the `RandomOpt`. @@ -392,20 +392,20 @@ func (o RandomOpt) LockedBals() []channel.Bal { // LockedID returns the `LockedID` value of the `RandomOpt`. // If not present, a random value is generated with `rng` as entropy source. -func (o RandomOpt) LockedID(rng *rand.Rand) channel.ID { +func (o RandomOpt) LockedID(rng *rand.Rand) map[int]channel.ID { if _, ok := o["lockedId"]; !ok { o["lockedId"] = NewRandomChannelID(rng) } - return o["lockedId"].(channel.ID) + return o["lockedId"].(map[int]channel.ID) } // LockedIDs returns the `LockedIDs` value of the `RandomOpt`. // If not present, returns nil. -func (o RandomOpt) LockedIDs(rng *rand.Rand) (ids []channel.ID) { +func (o RandomOpt) LockedIDs(rng *rand.Rand) (ids []map[int]channel.ID) { if _, ok := o["lockedIds"]; !ok { return nil } - return o["lockedIds"].([]channel.ID) + return o["lockedIds"].([]map[int]channel.ID) } // Nonce returns the `Nonce` value of the `RandomOpt`. diff --git a/channel/transaction_test.go b/channel/transaction_test.go index 4b8702594..b6a8e52a3 100644 --- a/channel/transaction_test.go +++ b/channel/transaction_test.go @@ -15,6 +15,7 @@ package channel_test import ( + "github.com/stretchr/testify/require" "testing" "perun.network/go-perun/channel" @@ -83,5 +84,6 @@ func TestTransactionClone(t *testing.T) { size := int(rng.Int31n(5)) + 2 testmask := newUniformBoolSlice(size, true) tx := *test.NewRandomTransaction(rng, testmask) - pkgtest.VerifyClone(t, tx) + clone := tx.Clone() + require.Equalf(t, tx, clone, "Clone() = %v, want %v", clone, tx) } diff --git a/client/channel.go b/client/channel.go index a9cce6035..69b88feb7 100644 --- a/client/channel.go +++ b/client/channel.go @@ -128,7 +128,7 @@ func (c *Channel) logPeer(idx channel.Index) log.Logger { } // ID returns the channel ID. -func (c *Channel) ID() channel.ID { +func (c *Channel) ID() map[int]channel.ID { return c.machine.ID() } diff --git a/client/channelconn.go b/client/channelconn.go index 8cdca55f9..2daf0ea27 100644 --- a/client/channelconn.go +++ b/client/channelconn.go @@ -41,7 +41,7 @@ type channelConn struct { // newChannelConn creates a new channel connection for the given channel ID. It // subscribes on the subscriber to all messages regarding this channel. -func newChannelConn(id channel.ID, peers []map[int]wire.Address, idx channel.Index, sub wire.Subscriber, pub wire.Publisher) (_ *channelConn, err error) { +func newChannelConn(id map[int]channel.ID, peers []map[int]wire.Address, idx channel.Index, sub wire.Subscriber, pub wire.Publisher) (_ *channelConn, err error) { // relay to receive all update responses relay := wire.NewRelay() // we cache all responses for the lifetime of the relay @@ -61,9 +61,9 @@ func newChannelConn(id channel.ID, peers []map[int]wire.Address, idx channel.Ind isUpdateRes := func(e *wire.Envelope) bool { switch msg := e.Msg.(type) { case *ChannelUpdateAccMsg: - return msg.ID() == id + return channel.EqualIDs(msg.ID(), id) case *ChannelUpdateRejMsg: - return msg.ID() == id + return channel.EqualIDs(msg.ID(), id) default: return false } diff --git a/client/chanregistry.go b/client/chanregistry.go index 8ffa4d985..e26e6d9a3 100644 --- a/client/chanregistry.go +++ b/client/chanregistry.go @@ -26,27 +26,27 @@ import ( // registry. Always initialize instances of this type with MakeChanRegistry(). type chanRegistry struct { mutex sync.RWMutex - values map[channel.ID]*Channel + values map[string]*Channel newChannelHandler func(*Channel) } // makeChanRegistry creates a new empty channel registry. func makeChanRegistry() chanRegistry { - return chanRegistry{values: make(map[channel.ID]*Channel)} + return chanRegistry{values: make(map[string]*Channel)} } // Put puts a new channel into the registry. // If an entry with the same ID already existed, this call does nothing and // returns false. Otherwise, it adds the new channel into the registry and // returns true. -func (r *chanRegistry) Put(id channel.ID, value *Channel) bool { +func (r *chanRegistry) Put(id map[int]channel.ID, value *Channel) bool { r.mutex.Lock() - if _, ok := r.values[id]; ok { + if _, ok := r.values[channel.IDKey(id)]; ok { r.mutex.Unlock() return false } - r.values[id] = value + r.values[channel.IDKey(id)] = value handler := r.newChannelHandler r.mutex.Unlock() value.OnCloseAlways(func() { r.Delete(id) }) @@ -68,34 +68,34 @@ func (r *chanRegistry) OnNewChannel(handler func(*Channel)) { } // Has checks whether a channel with the requested ID is registered. -func (r *chanRegistry) Has(id channel.ID) bool { +func (r *chanRegistry) Has(id map[int]channel.ID) bool { r.mutex.RLock() defer r.mutex.RUnlock() - _, ok := r.values[id] + _, ok := r.values[channel.IDKey(id)] return ok } // Channel retrieves a channel from the registry. // If the channel exists, returns the channel, and true. Otherwise, returns nil, // false. -func (r *chanRegistry) Channel(id channel.ID) (*Channel, bool) { +func (r *chanRegistry) Channel(id map[int]channel.ID) (*Channel, bool) { r.mutex.RLock() defer r.mutex.RUnlock() - v, ok := r.values[id] + v, ok := r.values[channel.IDKey(id)] return v, ok } // Delete deletes a channel from the registry. // If the channel did not exist, does nothing. Returns whether the channel // existed. -func (r *chanRegistry) Delete(id channel.ID) (deleted bool) { +func (r *chanRegistry) Delete(id map[int]channel.ID) (deleted bool) { r.mutex.Lock() defer r.mutex.Unlock() - if _, deleted = r.values[id]; deleted { - delete(r.values, id) + if _, deleted = r.values[channel.IDKey(id)]; deleted { + delete(r.values, channel.IDKey(id)) } return } @@ -103,7 +103,7 @@ func (r *chanRegistry) Delete(id channel.ID) (deleted bool) { func (r *chanRegistry) CloseAll() (err error) { r.mutex.Lock() values := r.values - r.values = make(map[channel.ID]*Channel) + r.values = make(map[string]*Channel) r.mutex.Unlock() for _, c := range values { diff --git a/client/client.go b/client/client.go index d4ae3484a..1146fe7ec 100644 --- a/client/client.go +++ b/client/client.go @@ -146,7 +146,7 @@ func (c *Client) EnablePersistence(pr persistence.PersistRestorer) { } // Channel queries a channel by its ID. -func (c *Client) Channel(id channel.ID) (*Channel, error) { +func (c *Client) Channel(id map[int]channel.ID) (*Channel, error) { if ch, ok := c.channels.Channel(id); ok { return ch, nil } @@ -205,7 +205,7 @@ func (c *Client) logPeer(p map[int]wire.Address) log.Logger { return c.log.WithField("peer", p) } -func (c *Client) logChan(id channel.ID) log.Logger { +func (c *Client) logChan(id map[int]channel.ID) log.Logger { return c.log.WithField("channel", id) } diff --git a/client/proposal.go b/client/proposal.go index ad000b8aa..7e1d1c34d 100644 --- a/client/proposal.go +++ b/client/proposal.go @@ -626,7 +626,7 @@ func (c *Client) completeCPP( return ch, nil } -func (c *Client) proposalParent(prop ChannelProposal, partIdx channel.Index) (parentChannelID *channel.ID, parent *Channel, err error) { +func (c *Client) proposalParent(prop ChannelProposal, partIdx channel.Index) (parentChannelID *map[int]channel.ID, parent *Channel, err error) { switch prop := prop.(type) { case *SubChannelProposalMsg: parentChannelID = &prop.Parent diff --git a/client/proposalmsgs.go b/client/proposalmsgs.go index 90d484a0e..a3117148a 100644 --- a/client/proposalmsgs.go +++ b/client/proposalmsgs.go @@ -121,7 +121,7 @@ type ( // SubChannelProposalMsg is a channel proposal for subchannels. SubChannelProposalMsg struct { BaseChannelProposal - Parent channel.ID + Parent map[int]channel.ID } ) @@ -326,7 +326,7 @@ func (p LedgerChannelProposalMsg) Valid() error { // NewSubChannelProposal creates a subchannel proposal and applies the // supplied options. For more information, see ProposalOpts. func NewSubChannelProposal( - parent channel.ID, + parent map[int]channel.ID, challengeDuration uint64, initBals *channel.Allocation, opts ...ProposalOpts, @@ -344,12 +344,12 @@ func NewSubChannelProposal( // Encode encodes the SubChannelProposal into an io.Writer. func (p SubChannelProposalMsg) Encode(w io.Writer) error { - return perunio.Encode(w, p.BaseChannelProposal, p.Parent) + return perunio.Encode(w, p.BaseChannelProposal, channel.IDMap(p.Parent)) } // Decode decodes a SubChannelProposal from an io.Reader. func (p *SubChannelProposalMsg) Decode(r io.Reader) error { - return perunio.Decode(r, &p.BaseChannelProposal, &p.Parent) + return perunio.Decode(r, &p.BaseChannelProposal, (*channel.IDMap)(&p.Parent)) } // Type returns wire.SubChannelProposal. @@ -519,7 +519,7 @@ type ( BaseChannelProposal Proposer map[int]wallet.Address // Proposer's address in the channel. Peers []map[int]wire.Address // Participants' wire addresses. - Parents []channel.ID // Parent channels for each participant. + Parents []map[int]channel.ID // Parent channels for each participant. IndexMaps [][]channel.Index // Index mapping for each participant in relation to the root channel. } @@ -537,7 +537,7 @@ func NewVirtualChannelProposal( participant map[int]wallet.Address, initBals *channel.Allocation, peers []map[int]wire.Address, - parents []channel.ID, + parents []map[int]channel.ID, indexMaps [][]channel.Index, opts ...ProposalOpts, ) (prop *VirtualChannelProposalMsg, err error) { diff --git a/client/restore.go b/client/restore.go index 95972b49e..be4d3262d 100644 --- a/client/restore.go +++ b/client/restore.go @@ -41,10 +41,10 @@ func clientChannelFromSource( func (c *Client) reconstructChannel( channelFromSource channelFromSourceSig, pch *persistence.Channel, - db map[channel.ID]*persistence.Channel, - chans map[channel.ID]*Channel, + db map[string]*persistence.Channel, + chans map[string]*Channel, ) *Channel { - if ch, ok := chans[pch.ID()]; ok { + if ch, ok := chans[channel.IDKey(pch.ID())]; ok { return ch } @@ -52,7 +52,7 @@ func (c *Client) reconstructChannel( if pch.Parent != nil { parent = c.reconstructChannel( channelFromSource, - db[*pch.Parent], + db[channel.IDKey(*pch.Parent)], db, chans) } @@ -62,7 +62,7 @@ func (c *Client) reconstructChannel( c.logChan(pch.ID()).Panicf("Reconstruct channel: %v", err) } - chans[pch.ID()] = ch + chans[channel.IDKey(pch.ID())] = ch return ch } @@ -77,13 +77,13 @@ func (c *Client) restorePeerChannels(ctx context.Context, p map[int]wire.Address } }() - db := make(map[channel.ID]*persistence.Channel) + db := make(map[string]*persistence.Channel) // Serially restore channels. We might change this to parallel restoring once // we initiate the sync protocol from here again. for it.Next(ctx) { chdata := it.Channel() - db[chdata.ID()] = chdata + db[channel.IDKey(chdata.ID())] = chdata } if err := it.Close(); err != nil { @@ -95,10 +95,10 @@ func (c *Client) restorePeerChannels(ctx context.Context, p map[int]wire.Address } func (c *Client) restoreChannelCollection( - db map[channel.ID]*persistence.Channel, + db map[string]*persistence.Channel, channelFromSource channelFromSourceSig, ) { - chs := make(map[channel.ID]*Channel) + chs := make(map[string]*Channel) for _, pch := range db { ch := c.reconstructChannel(channelFromSource, pch, db, chs) log := c.logChan(ch.ID()) diff --git a/client/restore_internal_test.go b/client/restore_internal_test.go index 4ec201578..1d1ba37f1 100644 --- a/client/restore_internal_test.go +++ b/client/restore_internal_test.go @@ -50,26 +50,26 @@ func patchChFromSource( func TestReconstructChannel(t *testing.T) { rng := pkgtest.Prng(t) - db := map[channel.ID]*persistence.Channel{} + db := map[string]*persistence.Channel{} restParent := mkRndChan(rng) - db[restParent.ID()] = restParent + db[channel.IDKey(restParent.ID())] = restParent restChild := mkRndChan(rng) parentID := restParent.ID() restChild.Parent = &parentID - db[restChild.ID()] = restChild + db[channel.IDKey(restChild.ID())] = restChild c := &Client{log: log.Default()} t.Run("parent first", func(t *testing.T) { - chans := map[channel.ID]*Channel{} + chans := map[string]*Channel{} parent := c.reconstructChannel(patchChFromSource, restParent, db, chans) child := c.reconstructChannel(patchChFromSource, restChild, db, chans) assert.Same(t, child.parent, parent) }) t.Run("child first", func(t *testing.T) { - chans := map[channel.ID]*Channel{} + chans := map[string]*Channel{} child := c.reconstructChannel(patchChFromSource, restChild, db, chans) parent := c.reconstructChannel(patchChFromSource, restParent, db, chans) assert.Same(t, child.parent, parent) @@ -80,20 +80,20 @@ func TestRestoreChannelCollection(t *testing.T) { rng := pkgtest.Prng(t) // Generate multiple trees of channels into one collection. - db := make(map[channel.ID]*persistence.Channel) + db := make(map[string]*persistence.Channel) for i := 0; i < 3; i++ { mkRndChanTree(rng, 3, 1, 3, db) } // Remember channels that have been published. - witnessedChans := make(map[channel.ID]struct{}) + witnessedChans := make(map[string]struct{}) c := &Client{log: log.Default(), channels: makeChanRegistry()} c.OnNewChannel(func(ch *Channel) { - _, ok := witnessedChans[ch.ID()] + _, ok := witnessedChans[channel.IDKey(ch.ID())] require.False(t, ok) - _, ok = db[ch.ID()] + _, ok = db[channel.IDKey(ch.ID())] require.True(t, ok) - witnessedChans[ch.ID()] = struct{}{} + witnessedChans[channel.IDKey(ch.ID())] = struct{}{} }) // Restore all channels into the client and check the published channels. @@ -130,10 +130,10 @@ func mkRndChan(rng *rand.Rand) *persistence.Channel { func mkRndChanTree( rng *rand.Rand, depth, minChildren, maxChildren int, - db map[channel.ID]*persistence.Channel, + db map[string]*persistence.Channel, ) (root *persistence.Channel) { root = mkRndChan(rng) - db[root.ID()] = root + db[channel.IDKey(root.ID())] = root if depth > 0 && maxChildren > 0 { children := minChildren + rng.Intn(maxChildren-minChildren+1) @@ -142,7 +142,7 @@ func mkRndChanTree( } for i := 0; i < children; i++ { t := mkRndChanTree(rng, depth-1, minChildren, maxChildren-1, db) - t.Parent = new(channel.ID) + t.Parent = &map[int]channel.ID{0: *new(channel.ID)} *t.Parent = root.ID() } } diff --git a/client/serialize.go b/client/serialize.go index 8a696ae01..00054836e 100644 --- a/client/serialize.go +++ b/client/serialize.go @@ -24,44 +24,38 @@ import ( type ( sliceLen = uint16 - channelIDsWithLen []channel.ID + channelIDsWithLen []map[int]channel.ID indexMapWithLen []channel.Index indexMapsWithLen [][]channel.Index ) // Encode encodes the object to the writer. func (a channelIDsWithLen) Encode(w io.Writer) (err error) { - err = perunio.Encode(w, sliceLen(len(a))) - if err != nil { - return + length := int32(len(a)) + if err := perunio.Encode(w, length); err != nil { + return errors.WithMessage(err, "encoding array length") } - - for _, id := range a { - err = perunio.Encode(w, id) - if err != nil { - return + for i, id := range a { + if err := perunio.Encode(w, (*channel.IDMap)(&id)); err != nil { + return errors.WithMessagef(err, "encoding %d-th id array entry", i) } } - return + return nil } // Decode decodes the object from the reader. func (a *channelIDsWithLen) Decode(r io.Reader) (err error) { - var l sliceLen - if err = perunio.Decode(r, &l); err != nil { - return errors.WithMessage(err, "decoding length") + var mapLen int32 + if err := perunio.Decode(r, &mapLen); err != nil { + return errors.WithMessage(err, "decoding array length") } - - *a = make(channelIDsWithLen, l) - for i := range *a { - var id channel.ID - err = perunio.Decode(r, &id) - if err != nil { - return errors.WithMessagef(err, "decoding item %d", i) + *a = make([]map[int]channel.ID, mapLen) + for i := 0; i < int(mapLen); i++ { + if err := perunio.Decode(r, (*channel.IDMap)(&(*a)[i])); err != nil { + return errors.WithMessagef(err, "decoding %d-th id map entry", i) } - (*a)[i] = id } - return + return nil } // Encode encodes the object to the writer. diff --git a/client/subchannel.go b/client/subchannel.go index 15e65f7fa..458e372a7 100644 --- a/client/subchannel.go +++ b/client/subchannel.go @@ -47,7 +47,7 @@ func (c *Channel) equalParticipants(_c *Channel) bool { return true } -func (c *Channel) fundSubChannel(ctx context.Context, id channel.ID, alloc *channel.Allocation) error { +func (c *Channel) fundSubChannel(ctx context.Context, id map[int]channel.ID, alloc *channel.Allocation) error { // We assume that the channel is locked. return c.update(ctx, func(state *channel.State) error { // equal assets and sufficient balances are already checked when validating the sub-channel proposal @@ -119,7 +119,7 @@ func (c *Channel) withdrawSubChannel(ctx context.Context, sub *Channel) error { return errors.WithMessage(err, "update parent channel") } -func (c *Channel) registerSubChannelFunding(id channel.ID, alloc []channel.Bal) { +func (c *Channel) registerSubChannelFunding(id map[int]channel.ID, alloc []channel.Bal) { filter := func(cu ChannelUpdate) bool { expected := *channel.NewSubAlloc(id, alloc, nil) _, containedBefore := c.machine.State().SubAlloc(expected.ID) @@ -130,7 +130,7 @@ func (c *Channel) registerSubChannelFunding(id channel.ID, alloc []channel.Bal) c.subChannelFundings.Register(id, ui) } -func (c *Channel) registerSubChannelSettlement(id channel.ID, bals [][]channel.Bal) { +func (c *Channel) registerSubChannelSettlement(id map[int]channel.ID, bals [][]channel.Bal) { filter := func(cu ChannelUpdate) bool { _, containedBefore := c.machine.State().SubAlloc(id) _, containedAfter := cu.State.SubAlloc(id) @@ -142,15 +142,15 @@ func (c *Channel) registerSubChannelSettlement(id channel.ID, bals [][]channel.B c.subChannelWithdrawals.Register(id, ui) } -func (c *Channel) awaitSubChannelFunding(ctx context.Context, id channel.ID) error { +func (c *Channel) awaitSubChannelFunding(ctx context.Context, id map[int]channel.ID) error { return c.awaitSubChannelUpdate(ctx, id, c.subChannelFundings) } -func (c *Channel) awaitSubChannelWithdrawal(ctx context.Context, id channel.ID) error { +func (c *Channel) awaitSubChannelWithdrawal(ctx context.Context, id map[int]channel.ID) error { return c.awaitSubChannelUpdate(ctx, id, c.subChannelWithdrawals) } -func (c *Channel) awaitSubChannelUpdate(ctx context.Context, id channel.ID, interceptors *updateInterceptors) error { +func (c *Channel) awaitSubChannelUpdate(ctx context.Context, id map[int]channel.ID, interceptors *updateInterceptors) error { ui, ok := interceptors.UpdateInterceptor(id) if !ok { diff --git a/client/sync.go b/client/sync.go index 205006a04..263358a3b 100644 --- a/client/sync.go +++ b/client/sync.go @@ -74,7 +74,7 @@ func (c *Client) syncChannel(ctx context.Context, ch *persistence.Channel, p map id := ch.ID() err = c.conn.Subscribe(recv, func(m *wire.Envelope) bool { msg, ok := m.Msg.(*ChannelSyncMsg) - return ok && msg.ID() == id + return ok && channel.EqualIDs(msg.ID(), id) }) if err != nil { return errors.WithMessage(err, "subscribing on relay") @@ -122,7 +122,7 @@ func validateMessage(ch *persistence.Channel, msg *ChannelSyncMsg) error { v := ch.CurrentTX().Version mv := msg.CurrentTX.Version - if msg.CurrentTX.ID != ch.ID() { + if channel.EqualIDs(msg.CurrentTX.ID, ch.ID()) { return errors.New("channel ID mismatch") } if mv == v { diff --git a/client/syncmsgs.go b/client/syncmsgs.go index 47f0ec142..365eee3a4 100644 --- a/client/syncmsgs.go +++ b/client/syncmsgs.go @@ -61,7 +61,7 @@ func (m *ChannelSyncMsg) Decode(r io.Reader) error { } // ID returns the channel's ID. -func (m *ChannelSyncMsg) ID() channel.ID { +func (m *ChannelSyncMsg) ID() map[int]channel.ID { return m.CurrentTX.ID } diff --git a/client/test/backend.go b/client/test/backend.go index f3a9e1c5d..08ef3f2ac 100644 --- a/client/test/backend.go +++ b/client/test/backend.go @@ -36,8 +36,8 @@ type ( rng rng mu sync.Mutex assetHolder *assetHolder - latestEvents map[channel.ID]channel.AdjudicatorEvent - eventSubs map[channel.ID][]*MockSubscription + latestEvents map[string]channel.AdjudicatorEvent + eventSubs map[string][]*MockSubscription balances map[addressMapKey]map[assetMapKey]*big.Int id multi.AssetID } @@ -67,8 +67,8 @@ func NewMockBackend(rng *rand.Rand, id string) *MockBackend { log: log.Default(), rng: newThreadSafePrng(backendRng), assetHolder: newAssetHolder(newThreadSafePrng(backendRng)), - latestEvents: make(map[channel.ID]channel.AdjudicatorEvent), - eventSubs: make(map[channel.ID][]*MockSubscription), + latestEvents: make(map[string]channel.AdjudicatorEvent), + eventSubs: make(map[string][]*MockSubscription), balances: make(map[string]map[string]*big.Int), id: multi.AssetID{0, LedgerID(id)}, } @@ -191,10 +191,10 @@ func (b *MockBackend) Register(_ context.Context, req channel.AdjudicatorReq, su return nil } -func (b *MockBackend) setLatestEvent(ch channel.ID, e channel.AdjudicatorEvent) { - b.latestEvents[ch] = e +func (b *MockBackend) setLatestEvent(ch map[int]channel.ID, e channel.AdjudicatorEvent) { + b.latestEvents[channel.IDKey(ch)] = e // Update subscriptions. - if channelSubs, ok := b.eventSubs[ch]; ok { + if channelSubs, ok := b.eventSubs[channel.IDKey(ch)]; ok { for _, sub := range channelSubs { // Remove previous latest event. select { @@ -231,7 +231,7 @@ func (b *MockBackend) Progress(_ context.Context, req channel.ProgressReq) error func outcomeRecursive(state *channel.State, subStates channel.StateMap) (outcome channel.Balances) { outcome = state.Balances.Clone() for _, subAlloc := range state.Locked { - subOutcome := outcomeRecursive(subStates[subAlloc.ID], subStates) + subOutcome := outcomeRecursive(subStates[channel.IDKey(subAlloc.ID)], subStates) for a, bals := range subOutcome { for p, bal := range bals { _p := p @@ -280,7 +280,7 @@ func (b *MockBackend) checkStates(states []*channel.State, op checkStateFunc) er } func (b *MockBackend) checkState(s *channel.State, op checkStateFunc) error { - e, ok := b.latestEvents[s.ID] + e, ok := b.latestEvents[channel.IDKey(s.ID)] if err := op(e, ok, s); err != nil { return err } @@ -313,7 +313,7 @@ func (b *MockBackend) Withdraw(_ context.Context, req channel.AdjudicatorReq, su b.log.Infof("Withdraw: %+v, %+v, %+v", req, subStates, outcome) outcomeSum := outcome.Sum() - funding := b.assetHolder.balances[ch] + funding := b.assetHolder.balances[channel.IDKey(ch)] if funding == nil { funding = channel.MakeBalances(len(req.Tx.Assets), req.Tx.NumParts()) } @@ -331,7 +331,7 @@ func (b *MockBackend) Withdraw(_ context.Context, req channel.AdjudicatorReq, su } // Payout balances. - balances := b.assetHolder.balances[ch] + balances := b.assetHolder.balances[channel.IDKey(ch)] for a, assetBalances := range balances { asset := req.Tx.Allocation.Assets[a] p := req.Idx @@ -346,8 +346,8 @@ func (b *MockBackend) Withdraw(_ context.Context, req channel.AdjudicatorReq, su return nil } -func (b *MockBackend) isConcluded(ch channel.ID) bool { - e, ok := b.latestEvents[ch] +func (b *MockBackend) isConcluded(ch map[int]channel.ID) bool { + e, ok := b.latestEvents[channel.IDKey(ch)] if !ok { return false } @@ -442,7 +442,7 @@ func (b *MockBackend) setBalance(p wallet.Address, a channel.Asset, v *big.Int) } // Subscribe creates an event subscription. -func (b *MockBackend) Subscribe(ctx context.Context, chID channel.ID) (channel.AdjudicatorSubscription, error) { +func (b *MockBackend) Subscribe(ctx context.Context, chID map[int]channel.ID) (channel.AdjudicatorSubscription, error) { b.log.Infof("SubscribeRegistered: %+v", chID) b.mu.Lock() @@ -450,23 +450,23 @@ func (b *MockBackend) Subscribe(ctx context.Context, chID channel.ID) (channel.A sub := NewMockSubscription(ctx) sub.onClose = func() { b.removeSubscription(chID, sub) } - b.eventSubs[chID] = append(b.eventSubs[chID], sub) + b.eventSubs[channel.IDKey(chID)] = append(b.eventSubs[channel.IDKey(chID)], sub) // Feed latest event if any. - if e, ok := b.latestEvents[chID]; ok { + if e, ok := b.latestEvents[channel.IDKey(chID)]; ok { sub.events <- e } return sub, nil } -func (b *MockBackend) removeSubscription(ch channel.ID, sub *MockSubscription) { +func (b *MockBackend) removeSubscription(ch map[int]channel.ID, sub *MockSubscription) { b.mu.Lock() defer b.mu.Unlock() // Find subscription index. i, ok := func() (int, bool) { - for i, s := range b.eventSubs[ch] { + for i, s := range b.eventSubs[channel.IDKey(ch)] { if sub == s { return i, true } @@ -479,24 +479,24 @@ func (b *MockBackend) removeSubscription(ch channel.ID, sub *MockSubscription) { return } - subs := b.eventSubs[ch] - b.eventSubs[ch] = append(subs[:i], subs[i+1:]...) + subs := b.eventSubs[channel.IDKey(ch)] + b.eventSubs[channel.IDKey(ch)] = append(subs[:i], subs[i+1:]...) } // assetHolder mocks an assetHolder for the MockBackend. type assetHolder struct { rng rng mtx sync.Mutex - balances map[channel.ID]channel.Balances - fundedWgs map[channel.ID]*sync.WaitGroup + balances map[string]channel.Balances + fundedWgs map[string]*sync.WaitGroup } // newAssetHolder returns a new funder. func newAssetHolder(rng rng) *assetHolder { return &assetHolder{ rng: rng, - balances: make(map[channel.ID]channel.Balances), - fundedWgs: make(map[channel.ID]*sync.WaitGroup), + balances: make(map[string]channel.Balances), + fundedWgs: make(map[string]*sync.WaitGroup), } } @@ -508,12 +508,12 @@ func (f *assetHolder) initFund(req channel.FundingReq) { f.mtx.Lock() defer f.mtx.Unlock() - if f.fundedWgs[req.Params.ID()] == nil { - f.fundedWgs[req.Params.ID()] = &sync.WaitGroup{} - f.fundedWgs[req.Params.ID()].Add(len(req.Params.Parts)) + if f.fundedWgs[channel.IDKey(req.Params.ID())] == nil { + f.fundedWgs[channel.IDKey(req.Params.ID())] = &sync.WaitGroup{} + f.fundedWgs[channel.IDKey(req.Params.ID())].Add(len(req.Params.Parts)) } - if f.balances[req.Params.ID()] == nil { - f.balances[req.Params.ID()] = channel.MakeBalances(len(req.State.Assets), req.State.NumParts()) + if f.balances[channel.IDKey(req.Params.ID())] == nil { + f.balances[channel.IDKey(req.Params.ID())] = channel.MakeBalances(len(req.State.Assets), req.State.NumParts()) } } @@ -535,12 +535,12 @@ func (f *assetHolder) Fund(req channel.FundingReq, b *MockBackend, acc wallet.Ad b.subBalance(acc, asset, bal) b.mu.Unlock() f.mtx.Lock() - fundingBal := f.balances[req.Params.ID()][i][req.Idx] + fundingBal := f.balances[channel.IDKey(req.Params.ID())][i][req.Idx] fundingBal.Add(fundingBal, bal) f.mtx.Unlock() } - f.fundedWgs[req.Params.ID()].Done() + f.fundedWgs[channel.IDKey(req.Params.ID())].Done() } // WaitForFunding waits until all participants have funded the channel. @@ -550,7 +550,7 @@ func (f *assetHolder) WaitForFunding(ctx context.Context, req channel.FundingReq defer cancel() select { - case <-f.fundedWgs[req.Params.ID()].WaitCh(): + case <-f.fundedWgs[channel.IDKey(req.Params.ID())].WaitCh(): log.Infof("Funded: %+v", req) return nil case <-fundCtx.Done(): diff --git a/client/test/persistence.go b/client/test/persistence.go index bc46c40cf..30ecf37ed 100644 --- a/client/test/persistence.go +++ b/client/test/persistence.go @@ -205,7 +205,7 @@ func (r *multiClientRole) assertPersistedPeerAndChannel(cfg ExecConfig, state *c r.RequireTrue(chIt.Next(ctx)) restoredCh := chIt.Channel() r.RequireNoError(chIt.Close()) - r.RequireTrue(restoredCh.ID() == state.ID) + r.RequireTrue(channel.EqualIDs(restoredCh.ID(), state.ID)) r.RequireNoError(restoredCh.CurrentTXV.State.Equal(state)) } diff --git a/client/test/role.go b/client/test/role.go index db570696c..435fca989 100644 --- a/client/test/role.go +++ b/client/test/role.go @@ -58,7 +58,7 @@ type ( } channelMap struct { - entries map[channel.ID]*paymentChannel + entries map[string]*paymentChannel sync.RWMutex } @@ -211,7 +211,7 @@ func (c *BaseExecConfig) App() client.ProposalOpts { func makeRole(t *testing.T, setup RoleSetup, numStages int) (r role) { t.Helper() r = role{ - chans: &channelMap{entries: make(map[channel.ID]*paymentChannel)}, + chans: &channelMap{entries: make(map[string]*paymentChannel)}, setup: setup, timeout: setup.Timeout, errs: setup.Errors, @@ -243,17 +243,17 @@ func (r *role) setClient(cl *client.Client) { r.log = log.AppendField(cl, "role", r.setup.Name) } -func (chs *channelMap) channel(ch channel.ID) (_ch *paymentChannel, ok bool) { +func (chs *channelMap) channel(ch map[int]channel.ID) (_ch *paymentChannel, ok bool) { chs.RLock() defer chs.RUnlock() - _ch, ok = chs.entries[ch] + _ch, ok = chs.entries[channel.IDKey(ch)] return } func (chs *channelMap) add(ch *paymentChannel) { chs.Lock() defer chs.Unlock() - chs.entries[ch.ID()] = ch + chs.entries[channel.IDKey(ch.ID())] = ch } func (r *role) OnNewChannel(callback func(ch *paymentChannel)) { diff --git a/client/test/subchannel_dispute.go b/client/test/subchannel_dispute.go index ea6721724..78640763a 100644 --- a/client/test/subchannel_dispute.go +++ b/client/test/subchannel_dispute.go @@ -121,7 +121,7 @@ func (r *DisputeSusie) exec(_cfg ExecConfig, ledgerChannel *paymentChannel) { type DisputeTim struct { Responder registered chan *channel.RegisteredEvent - subCh channel.ID + subCh map[int]channel.ID } // time to wait until a parent channel watcher becomes active. @@ -130,7 +130,7 @@ const channelWatcherWait = 100 * time.Millisecond // HandleAdjudicatorEvent is the callback for adjudicator event handling. func (r *DisputeTim) HandleAdjudicatorEvent(e channel.AdjudicatorEvent) { r.log.Infof("HandleAdjudicatorEvent: channelID = %x, version = %v, type = %T", e.ID(), e.Version(), e) - if e, ok := e.(*channel.RegisteredEvent); ok && e.ID() == r.subCh { + if e, ok := e.(*channel.RegisteredEvent); ok && channel.EqualIDs(e.ID(), r.subCh) { r.registered <- e } } diff --git a/client/test/virtualchannel.go b/client/test/virtualchannel.go index 121774dbc..373aa6f5f 100644 --- a/client/test/virtualchannel.go +++ b/client/test/virtualchannel.go @@ -294,7 +294,7 @@ func setupVirtualChannelTest( alice.WalletAddress, &initAllocVirtual, []map[int]wire.Address{alice.Identity.Address(), bob.Identity.Address()}, - []channel.ID{vct.chAliceIngrid.ID(), vct.chBobIngrid.ID()}, + []map[int]channel.ID{vct.chAliceIngrid.ID(), vct.chBobIngrid.ID()}, [][]channel.Index{indexMapAlice, indexMapBob}, ) require.NoError(err, "creating virtual channel proposal") diff --git a/client/updateinterception.go b/client/updateinterception.go index 3e5ea6c67..c63996625 100644 --- a/client/updateinterception.go +++ b/client/updateinterception.go @@ -36,7 +36,7 @@ type ( } updateInterceptors struct { - entries map[channel.ID]*updateInterceptor + entries map[string]*updateInterceptor sync.RWMutex } ) @@ -65,33 +65,33 @@ func (ui *updateInterceptor) Accept(ctx context.Context) error { } func newUpdateInterceptors() *updateInterceptors { - return &updateInterceptors{entries: make(map[channel.ID]*updateInterceptor)} + return &updateInterceptors{entries: make(map[string]*updateInterceptor)} } // Register assigns the given update interceptor to the given channel. -func (interceptors *updateInterceptors) Register(id channel.ID, ui *updateInterceptor) { +func (interceptors *updateInterceptors) Register(id map[int]channel.ID, ui *updateInterceptor) { interceptors.Lock() defer interceptors.Unlock() - interceptors.entries[id] = ui + interceptors.entries[channel.IDKey(id)] = ui } // UpdateInterceptor gets the update interceptor for the given channel. The second return // value indicates whether such an entry could be found. -func (interceptors *updateInterceptors) UpdateInterceptor(id channel.ID) (*updateInterceptor, bool) { +func (interceptors *updateInterceptors) UpdateInterceptor(id map[int]channel.ID) (*updateInterceptor, bool) { interceptors.RLock() defer interceptors.RUnlock() - ui, ok := interceptors.entries[id] + ui, ok := interceptors.entries[channel.IDKey(id)] return ui, ok } // Release releases the update interceptor for the given channel. -func (interceptors *updateInterceptors) Release(id channel.ID) { +func (interceptors *updateInterceptors) Release(id map[int]channel.ID) { interceptors.Lock() defer interceptors.Unlock() - if ui, ok := interceptors.entries[id]; ok { + if ui, ok := interceptors.entries[channel.IDKey(id)]; ok { close(ui.response) } - delete(interceptors.entries, id) + delete(interceptors.entries, channel.IDKey(id)) } // Filter filters for a matching update interceptor. It returns the first diff --git a/client/updatemsgs.go b/client/updatemsgs.go index 8631c8a3c..8fbf64e20 100644 --- a/client/updatemsgs.go +++ b/client/updatemsgs.go @@ -56,7 +56,7 @@ type ( // controller. ChannelMsg interface { wire.Msg - ID() channel.ID + ID() map[int]channel.ID } channelUpdateResMsg interface { @@ -85,7 +85,7 @@ type ( // signature on the accepted new state by the sender. ChannelUpdateAccMsg struct { // ChannelID is the channel ID. - ChannelID channel.ID + ChannelID map[int]channel.ID // Version of the state that is accepted. Version uint64 // Sig is the signature on the proposed new state by the sender. @@ -99,7 +99,7 @@ type ( // Reason should be a UTF-8 encodable string. ChannelUpdateRejMsg struct { // ChannelID is the channel ID. - ChannelID channel.ID + ChannelID map[int]channel.ID // Version of the state that is accepted. Version uint64 // Reason states why the sender rejectes the proposed new state. @@ -152,12 +152,12 @@ func (c *ChannelUpdateMsg) Decode(r io.Reader) (err error) { // Encode encodes the ChannelUpdateAccMsg into the io.Writer. func (c ChannelUpdateAccMsg) Encode(w io.Writer) error { - return perunio.Encode(w, c.ChannelID, c.Version, c.Sig) + return perunio.Encode(w, channel.IDMap(c.ChannelID), c.Version, c.Sig) } // Decode decodes the ChannelUpdateAccMsg from the io.Reader. func (c *ChannelUpdateAccMsg) Decode(r io.Reader) (err error) { - if err := perunio.Decode(r, &c.ChannelID, &c.Version); err != nil { + if err := perunio.Decode(r, (*channel.IDMap)(&c.ChannelID), &c.Version); err != nil { return err } c.Sig, err = wallet.DecodeSig(r) @@ -166,26 +166,26 @@ func (c *ChannelUpdateAccMsg) Decode(r io.Reader) (err error) { // Encode encodes the ChannelUpdateRejMsg into the io.Writer. func (c ChannelUpdateRejMsg) Encode(w io.Writer) error { - return perunio.Encode(w, c.ChannelID, c.Version, c.Reason) + return perunio.Encode(w, channel.IDMap(c.ChannelID), c.Version, c.Reason) } // Decode decodes the ChannelUpdateRejMsg from the io.Reader. func (c *ChannelUpdateRejMsg) Decode(r io.Reader) (err error) { - return perunio.Decode(r, &c.ChannelID, &c.Version, &c.Reason) + return perunio.Decode(r, (*channel.IDMap)(&c.ChannelID), &c.Version, &c.Reason) } // ID returns the id of the channel this update refers to. -func (c *ChannelUpdateMsg) ID() channel.ID { +func (c *ChannelUpdateMsg) ID() map[int]channel.ID { return c.State.ID } // ID returns the id of the channel this update acceptance refers to. -func (c *ChannelUpdateAccMsg) ID() channel.ID { +func (c *ChannelUpdateAccMsg) ID() map[int]channel.ID { return c.ChannelID } // ID returns the id of the channel this update rejection refers to. -func (c *ChannelUpdateRejMsg) ID() channel.ID { +func (c *ChannelUpdateRejMsg) ID() map[int]channel.ID { return c.ChannelID } diff --git a/client/virtual_channel.go b/client/virtual_channel.go index 18d19be3c..ca19002ed 100644 --- a/client/virtual_channel.go +++ b/client/virtual_channel.go @@ -239,7 +239,7 @@ func (c *Client) validateVirtualChannelFundingProposal( prop *VirtualChannelFundingProposalMsg, ) error { switch { - case prop.Initial.Params.ID() != prop.Initial.State.ID: + case !channel.EqualIDs(prop.Initial.Params.ID(), prop.Initial.State.ID): return errors.New("state does not match parameters") case !prop.Initial.Params.VirtualChannel: return errors.New("virtual channel flag not set") diff --git a/client/virtual_channel_settlement.go b/client/virtual_channel_settlement.go index 71abb0880..1e2b91035 100644 --- a/client/virtual_channel_settlement.go +++ b/client/virtual_channel_settlement.go @@ -99,7 +99,7 @@ func (c *Client) validateVirtualChannelSettlementProposal( prop *VirtualChannelSettlementProposalMsg, ) error { // Validate parameters. - if prop.Final.Params.ID() != prop.Final.State.ID { + if !channel.EqualIDs(prop.Final.Params.ID(), prop.Final.State.ID) { return errors.New("invalid parameters") } diff --git a/watcher/internal/mocks/AdjudicatorSubscription.go b/watcher/internal/mocks/AdjudicatorSubscription.go index 0de5255a4..3a1330084 100644 --- a/watcher/internal/mocks/AdjudicatorSubscription.go +++ b/watcher/internal/mocks/AdjudicatorSubscription.go @@ -1,12 +1,10 @@ -// Code generated by mockery v2.12.1. DO NOT EDIT. +// Code generated by mockery v2.45.0. DO NOT EDIT. package mocks import ( mock "github.com/stretchr/testify/mock" channel "perun.network/go-perun/channel" - - testing "testing" ) // AdjudicatorSubscription is an autogenerated mock type for the AdjudicatorSubscription type @@ -18,6 +16,10 @@ type AdjudicatorSubscription struct { func (_m *AdjudicatorSubscription) Close() error { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for Close") + } + var r0 error if rf, ok := ret.Get(0).(func() error); ok { r0 = rf() @@ -32,6 +34,10 @@ func (_m *AdjudicatorSubscription) Close() error { func (_m *AdjudicatorSubscription) Err() error { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for Err") + } + var r0 error if rf, ok := ret.Get(0).(func() error); ok { r0 = rf() @@ -46,6 +52,10 @@ func (_m *AdjudicatorSubscription) Err() error { func (_m *AdjudicatorSubscription) Next() channel.AdjudicatorEvent { ret := _m.Called() + if len(ret) == 0 { + panic("no return value specified for Next") + } + var r0 channel.AdjudicatorEvent if rf, ok := ret.Get(0).(func() channel.AdjudicatorEvent); ok { r0 = rf() @@ -58,8 +68,12 @@ func (_m *AdjudicatorSubscription) Next() channel.AdjudicatorEvent { return r0 } -// NewAdjudicatorSubscription creates a new instance of AdjudicatorSubscription. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. -func NewAdjudicatorSubscription(t testing.TB) *AdjudicatorSubscription { +// NewAdjudicatorSubscription creates a new instance of AdjudicatorSubscription. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewAdjudicatorSubscription(t interface { + mock.TestingT + Cleanup(func()) +}) *AdjudicatorSubscription { mock := &AdjudicatorSubscription{} mock.Mock.Test(t) diff --git a/watcher/internal/mocks/RegisterSubscriber.go b/watcher/internal/mocks/RegisterSubscriber.go index cd0a1b57a..06e0ec7ef 100644 --- a/watcher/internal/mocks/RegisterSubscriber.go +++ b/watcher/internal/mocks/RegisterSubscriber.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.12.1. DO NOT EDIT. +// Code generated by mockery v2.45.0. DO NOT EDIT. package mocks @@ -8,8 +8,6 @@ import ( channel "perun.network/go-perun/channel" mock "github.com/stretchr/testify/mock" - - testing "testing" ) // RegisterSubscriber is an autogenerated mock type for the RegisterSubscriber type @@ -21,6 +19,10 @@ type RegisterSubscriber struct { func (_m *RegisterSubscriber) Register(_a0 context.Context, _a1 channel.AdjudicatorReq, _a2 []channel.SignedState) error { ret := _m.Called(_a0, _a1, _a2) + if len(ret) == 0 { + panic("no return value specified for Register") + } + var r0 error if rf, ok := ret.Get(0).(func(context.Context, channel.AdjudicatorReq, []channel.SignedState) error); ok { r0 = rf(_a0, _a1, _a2) @@ -32,11 +34,19 @@ func (_m *RegisterSubscriber) Register(_a0 context.Context, _a1 channel.Adjudica } // Subscribe provides a mock function with given fields: _a0, _a1 -func (_m *RegisterSubscriber) Subscribe(_a0 context.Context, _a1 [32]byte) (channel.AdjudicatorSubscription, error) { +func (_m *RegisterSubscriber) Subscribe(_a0 context.Context, _a1 map[int][32]byte) (channel.AdjudicatorSubscription, error) { ret := _m.Called(_a0, _a1) + if len(ret) == 0 { + panic("no return value specified for Subscribe") + } + var r0 channel.AdjudicatorSubscription - if rf, ok := ret.Get(0).(func(context.Context, [32]byte) channel.AdjudicatorSubscription); ok { + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, map[int][32]byte) (channel.AdjudicatorSubscription, error)); ok { + return rf(_a0, _a1) + } + if rf, ok := ret.Get(0).(func(context.Context, map[int][32]byte) channel.AdjudicatorSubscription); ok { r0 = rf(_a0, _a1) } else { if ret.Get(0) != nil { @@ -44,8 +54,7 @@ func (_m *RegisterSubscriber) Subscribe(_a0 context.Context, _a1 [32]byte) (chan } } - var r1 error - if rf, ok := ret.Get(1).(func(context.Context, [32]byte) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, map[int][32]byte) error); ok { r1 = rf(_a0, _a1) } else { r1 = ret.Error(1) @@ -54,8 +63,12 @@ func (_m *RegisterSubscriber) Subscribe(_a0 context.Context, _a1 [32]byte) (chan return r0, r1 } -// NewRegisterSubscriber creates a new instance of RegisterSubscriber. It also registers the testing.TB interface on the mock and a cleanup function to assert the mocks expectations. -func NewRegisterSubscriber(t testing.TB) *RegisterSubscriber { +// NewRegisterSubscriber creates a new instance of RegisterSubscriber. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewRegisterSubscriber(t interface { + mock.TestingT + Cleanup(func()) +}) *RegisterSubscriber { mock := &RegisterSubscriber{} mock.Mock.Test(t) diff --git a/watcher/local/registry.go b/watcher/local/registry.go index 49d87c14c..53f19be1d 100644 --- a/watcher/local/registry.go +++ b/watcher/local/registry.go @@ -25,22 +25,22 @@ import ( type ( registry struct { mtx sync.Mutex - chs map[channel.ID]*ch + chs map[string]*ch } ) func newRegistry() *registry { return ®istry{ - chs: make(map[channel.ID]*ch), + chs: make(map[string]*ch), } } // addIfSucceeds adds the channel to the registry, if it is not already present // in the registry and if the "chInitializer" does not return an error. -func (r *registry) addIfSucceeds(id channel.ID, chInitializer chInitializer) (*ch, error) { +func (r *registry) addIfSucceeds(id map[int]channel.ID, chInitializer chInitializer) (*ch, error) { r.mtx.Lock() defer r.mtx.Unlock() - if _, ok := r.chs[id]; ok { + if _, ok := r.chs[channel.IDKey(id)]; ok { return nil, errors.New("already watching for this channel") } @@ -49,22 +49,22 @@ func (r *registry) addIfSucceeds(id channel.ID, chInitializer chInitializer) (*c return nil, err } - r.chs[ch.id] = ch + r.chs[channel.IDKey(ch.id)] = ch return ch, nil } // retrieve retrieves the channel from registry. -func (r *registry) retrieve(id channel.ID) (*ch, bool) { +func (r *registry) retrieve(id map[int]channel.ID) (*ch, bool) { r.mtx.Lock() - ch, ok := r.chs[id] + ch, ok := r.chs[channel.IDKey(id)] r.mtx.Unlock() return ch, ok } // remove removes the channel from registry, if it is present. // It does not do any validation on the channel to be removed. -func (r *registry) remove(id channel.ID) { +func (r *registry) remove(id map[int]channel.ID) { r.mtx.Lock() - delete(r.chs, id) + delete(r.chs, channel.IDKey(id)) r.mtx.Unlock() } diff --git a/watcher/local/watcher.go b/watcher/local/watcher.go index b74de505f..1460bcd0b 100644 --- a/watcher/local/watcher.go +++ b/watcher/local/watcher.go @@ -55,7 +55,7 @@ type ( } ch struct { - id channel.ID + id map[int]channel.ID params *channel.Params isClosed bool done chan struct{} @@ -66,7 +66,7 @@ type ( // registered with the watcher. // Sub-channels are added when they are registered with the watcher and // removed when they are de-registered from the watcher. - subChs map[channel.ID]struct{} + subChs map[string]struct{} // For keeping track of the last received signed states for a // sub-channel, after it is de-registered from the watcher. These @@ -74,7 +74,7 @@ type ( // required while disputing any other channel in the channel tree and // the particular sub-channel has already been de-registered from the // watcher. - archivedSubChStates map[channel.ID]channel.SignedState + archivedSubChStates map[string]channel.SignedState // For keeping track of the version registered on the blockchain for // this channel. This is used to prevent registering the same state @@ -157,7 +157,7 @@ func (w *Watcher) StartWatchingLedgerChannel( // sub-channels is supported. func (w *Watcher) StartWatchingSubChannel( ctx context.Context, - parent channel.ID, + parent map[int]channel.ID, signedState channel.SignedState, ) (watcher.StatesPub, watcher.AdjudicatorSub, error) { parentCh, ok := w.registry.retrieve(parent) @@ -173,7 +173,7 @@ func (w *Watcher) StartWatchingSubChannel( if err != nil { return nil, nil, err } - parentCh.subChs[signedState.State.ID] = struct{}{} + parentCh.subChs[channel.IDKey(signedState.State.ID)] = struct{}{} return statesPub, eventsSub, nil } @@ -212,7 +212,7 @@ func (w *Watcher) startWatching( } func newCh( - id channel.ID, + id map[int]channel.ID, parent *ch, params *channel.Params, eventsFromChainSub channel.AdjudicatorSubscription, @@ -226,8 +226,8 @@ func newCh( parent: parent, multiLedger: multiLedger, - subChs: make(map[channel.ID]struct{}), - archivedSubChStates: make(map[channel.ID]channel.SignedState), + subChs: make(map[string]struct{}), + archivedSubChStates: make(map[string]channel.SignedState), registered: false, registeredVersion: 0, @@ -423,7 +423,7 @@ func retrieveLatestSubStates(r *registry, parent *ch) (channel.Transaction, []ch subChTx := subCh.txRetriever.retrieve() subStates[i] = makeSignedState(subCh.params, subChTx) } else { - subStates[i] = parent.archivedSubChStates[parentTx.Allocation.Locked[i].ID] + subStates[i] = parent.archivedSubChStates[channel.IDKey(parentTx.Allocation.Locked[i].ID)] } } return parentTx, subStates @@ -458,7 +458,7 @@ func makeAdjudicatorReq(params *channel.Params, tx channel.Transaction) channel. // has stopped watching for some of the sub-channel). // // Context is not used, it is for implementing watcher.Watcher interface. -func (w *Watcher) StopWatching(_ context.Context, id channel.ID) error { +func (w *Watcher) StopWatching(_ context.Context, id map[int]channel.ID) error { ch, ok := w.retrieve(id) if !ok { return errors.New("channel not registered with the watcher") @@ -479,9 +479,9 @@ func (w *Watcher) StopWatching(_ context.Context, id channel.ID) error { if ch.isSubChannel() { latestParentTx := ch.parent.txRetriever.retrieve() if _, ok := latestParentTx.SubAlloc(id); ok { - parent.archivedSubChStates[id] = makeSignedState(ch.params, ch.txRetriever.retrieve()) + parent.archivedSubChStates[channel.IDKey(id)] = makeSignedState(ch.params, ch.txRetriever.retrieve()) } - delete(parent.subChs, id) + delete(parent.subChs, channel.IDKey(id)) } else if len(ch.subChs) > 0 { return errors.WithMessagef(ErrSubChannelsPresent, "cannot de-register: %d %v", len(ch.subChs), ch.id) } diff --git a/watcher/local/watcher_test.go b/watcher/local/watcher_test.go index fc6872b3f..ca5376695 100644 --- a/watcher/local/watcher_test.go +++ b/watcher/local/watcher_test.go @@ -774,6 +774,7 @@ func (t *adjEventSource) close() { // the "Subscribe" method to be called once. The adjSub and the err are set as // the return values for the call and will be returned when the method is // called. +// //nolint:unparam func setExpectationSubscribeCall(rs *mocks.RegisterSubscriber, adjSub channel.AdjudicatorSubscription, err error) { rs.On("Subscribe", testifyMock.Anything, testifyMock.Anything).Return(adjSub, err).Once() @@ -953,7 +954,7 @@ func startWatchingForSubChannel( t *testing.T, w *local.Watcher, signedState channel.SignedState, - parentID channel.ID, + parentID map[int]channel.ID, ) (watcher.StatesPub, watcher.AdjudicatorSub) { t.Helper() statesPub, eventsSub, err := w.StartWatchingSubChannel(context.TODO(), parentID, signedState) diff --git a/watcher/watcher.go b/watcher/watcher.go index ce528bae0..101d812cd 100644 --- a/watcher/watcher.go +++ b/watcher/watcher.go @@ -40,9 +40,9 @@ type ( // this. Watcher interface { StartWatchingLedgerChannel(context.Context, channel.SignedState) (StatesPub, AdjudicatorSub, error) - StartWatchingSubChannel(_ context.Context, parent channel.ID, _ channel.SignedState) ( + StartWatchingSubChannel(_ context.Context, parent map[int]channel.ID, _ channel.SignedState) ( StatesPub, AdjudicatorSub, error) - StopWatching(context.Context, channel.ID) error + StopWatching(context.Context, map[int]channel.ID) error } // StatesPub is the interface used to send newer off-chain states from the diff --git a/wire/protobuf/proposalmsgs.go b/wire/protobuf/proposalmsgs.go index cd2335e2a..99c500e94 100644 --- a/wire/protobuf/proposalmsgs.go +++ b/wire/protobuf/proposalmsgs.go @@ -52,7 +52,7 @@ func ToSubChannelProposalMsg(protoEnvMsg *Envelope_SubChannelProposalMsg) (msg * protoMsg := protoEnvMsg.SubChannelProposalMsg msg = &client.SubChannelProposalMsg{} - copy(msg.Parent[:], protoMsg.Parent) + msg.Parent, err = ToIDs(protoMsg.Parent) msg.BaseChannelProposal, err = ToBaseChannelProposal(protoMsg.BaseChannelProposal) return msg, err } @@ -71,9 +71,9 @@ func ToVirtualChannelProposalMsg(protoEnvMsg *Envelope_VirtualChannelProposalMsg if err != nil { return nil, errors.WithMessage(err, "proposer") } - msg.Parents = make([]channel.ID, len(protoMsg.Parents)) + msg.Parents = make([]map[int]channel.ID, len(protoMsg.Parents)) for i := range protoMsg.Parents { - copy(msg.Parents[i][:], protoMsg.Parents[i]) + msg.Parents[i], err = ToIDs(protoMsg.Parents[i]) } msg.IndexMaps = make([][]channel.Index, len(protoMsg.IndexMaps)) for i := range protoMsg.IndexMaps { @@ -190,6 +190,25 @@ func ToWireAddrs(protoAddrs []*Address) ([]map[int]wire.Address, error) { return addrMap, nil } +// ToIDs converts protobuf ID to a map[int]channel.ID. +func ToIDs(protoID *ID) (map[int]channel.ID, error) { + iDMap := make(map[int]channel.ID) + for i := range protoID.IdMapping { + var k int32 + if err := binary.Read(bytes.NewReader(protoID.IdMapping[i].Key), binary.BigEndian, &k); err != nil { + return nil, fmt.Errorf("failed to read key: %w", err) + } + if len(protoID.IdMapping[i].Id) != 32 { + return nil, fmt.Errorf("id has incorrect length") + } + id := channel.ID{} + copy(id[:], protoID.IdMapping[i].Id) + + iDMap[int(k)] = id + } + return iDMap, nil +} + // ToBaseChannelProposal converts a protobuf BaseChannelProposal to a client BaseChannelProposal. func ToBaseChannelProposal(protoProp *BaseChannelProposal) (prop client.BaseChannelProposal, err error) { prop.ChallengeDuration = protoProp.ChallengeDuration @@ -317,10 +336,8 @@ func ToBalance(protoBalance *Balance) (balance []channel.Bal) { func ToSubAlloc(protoSubAlloc *SubAlloc) (subAlloc channel.SubAlloc, err error) { subAlloc = channel.SubAlloc{} subAlloc.Bals = ToBalance(protoSubAlloc.Bals) - if len(protoSubAlloc.Id) != len(subAlloc.ID) { - return subAlloc, errors.New("sub alloc id has incorrect length") - } - copy(subAlloc.ID[:], protoSubAlloc.Id) + subAlloc.ID, err = ToIDs(protoSubAlloc.Id) + subAlloc.IndexMap, err = ToIndexMap(protoSubAlloc.IndexMap.IndexMap) return subAlloc, err } @@ -356,8 +373,7 @@ func FromLedgerChannelProposalMsg(msg *client.LedgerChannelProposalMsg) (_ *Enve // FromSubChannelProposalMsg converts a client SubChannelProposalMsg to a protobuf Envelope_SubChannelProposalMsg. func FromSubChannelProposalMsg(msg *client.SubChannelProposalMsg) (_ *Envelope_SubChannelProposalMsg, err error) { protoMsg := &SubChannelProposalMsg{} - protoMsg.Parent = make([]byte, len(msg.Parent)) - copy(protoMsg.Parent, msg.Parent[:]) + protoMsg.Parent, err = FromIDs(msg.Parent) protoMsg.BaseChannelProposal, err = FromBaseChannelProposal(msg.BaseChannelProposal) return &Envelope_SubChannelProposalMsg{protoMsg}, err } @@ -374,10 +390,9 @@ func FromVirtualChannelProposalMsg(msg *client.VirtualChannelProposalMsg) (_ *En if err != nil { return nil, err } - protoMsg.Parents = make([][]byte, len(msg.Parents)) + protoMsg.Parents = make([]*ID, len(msg.Parents)) for i := range msg.Parents { - protoMsg.Parents[i] = make([]byte, len(msg.Parents[i])) - copy(protoMsg.Parents[i], msg.Parents[i][:]) + protoMsg.Parents[i], err = FromIDs(msg.Parents[i]) } protoMsg.IndexMaps = make([]*IndexMap, len(msg.IndexMaps)) for i := range msg.IndexMaps { @@ -494,6 +509,28 @@ func FromWireAddrs(addrs []map[int]wire.Address) (protoAddrs []*Address, err err return protoAddrs, nil } +// FromIDs converts a map[int]channel.ID to a protobuf ID. +func FromIDs(ids map[int]channel.ID) (*ID, error) { + var idMappings []*IDMapping + + for key, id := range ids { + keyBytes := make([]byte, 4) + binary.BigEndian.PutUint32(keyBytes, uint32(key)) + + idBytes := make([]byte, 32) + copy(idBytes, id[:]) + + idMappings = append(idMappings, &IDMapping{ + Key: keyBytes, + Id: idBytes, + }) + } + + return &ID{ + IdMapping: idMappings, + }, nil +} + // FromBaseChannelProposal converts a client BaseChannelProposal to a protobuf BaseChannelProposal. func FromBaseChannelProposal(prop client.BaseChannelProposal) (protoProp *BaseChannelProposal, err error) { protoProp = &BaseChannelProposal{} @@ -610,8 +647,7 @@ func FromBalance(balance []channel.Bal) (protoBalance *Balance, err error) { // FromSubAlloc converts a channel.SubAlloc to a protobuf SubAlloc. func FromSubAlloc(subAlloc channel.SubAlloc) (protoSubAlloc *SubAlloc, err error) { protoSubAlloc = &SubAlloc{} - protoSubAlloc.Id = make([]byte, len(subAlloc.ID)) - copy(protoSubAlloc.Id, subAlloc.ID[:]) + protoSubAlloc.Id, err = FromIDs(subAlloc.ID) protoSubAlloc.IndexMap = &IndexMap{IndexMap: FromIndexMap(subAlloc.IndexMap)} protoSubAlloc.Bals, err = FromBalance(subAlloc.Bals) return protoSubAlloc, err diff --git a/wire/protobuf/updatemsgs.go b/wire/protobuf/updatemsgs.go index dc30b00ce..a14887a4c 100644 --- a/wire/protobuf/updatemsgs.go +++ b/wire/protobuf/updatemsgs.go @@ -72,7 +72,7 @@ func ToChannelUpdateAccMsg(protoEnvMsg *Envelope_ChannelUpdateAccMsg) (msg *clie protoMsg := protoEnvMsg.ChannelUpdateAccMsg msg = &client.ChannelUpdateAccMsg{} - copy(msg.ChannelID[:], protoMsg.ChannelId) + msg.ChannelID, _ = ToIDs(protoEnvMsg.ChannelUpdateAccMsg.ChannelId) msg.Version = protoMsg.Version msg.Sig = make([]byte, len(protoMsg.Sig)) copy(msg.Sig, protoMsg.Sig) @@ -84,7 +84,7 @@ func ToChannelUpdateRejMsg(protoEnvMsg *Envelope_ChannelUpdateRejMsg) (msg *clie protoMsg := protoEnvMsg.ChannelUpdateRejMsg msg = &client.ChannelUpdateRejMsg{} - copy(msg.ChannelID[:], protoMsg.ChannelId) + msg.ChannelID, _ = ToIDs(protoEnvMsg.ChannelUpdateRejMsg.ChannelId) msg.Version = protoMsg.Version msg.Reason = protoMsg.Reason return msg @@ -141,7 +141,7 @@ func ToParams(protoParams *Params) (*channel.Params, error) { // ToState converts a protobuf State to a channel.State. func ToState(protoState *State) (state *channel.State, err error) { state = &channel.State{} - copy(state.ID[:], protoState.Id) + state.ID, err = ToIDs(protoState.Id) state.Version = protoState.Version state.IsFinal = protoState.IsFinal allocation, err := ToAllocation(protoState.Allocation) @@ -196,8 +196,7 @@ func FromVirtualChannelSettlementProposalMsg(msg *client.VirtualChannelSettlemen func FromChannelUpdateAccMsg(msg *client.ChannelUpdateAccMsg) *Envelope_ChannelUpdateAccMsg { protoMsg := &ChannelUpdateAccMsg{} - protoMsg.ChannelId = make([]byte, len(msg.ChannelID)) - copy(protoMsg.ChannelId, msg.ChannelID[:]) + protoMsg.ChannelId, _ = FromIDs(msg.ChannelID) protoMsg.Sig = make([]byte, len(msg.Sig)) copy(protoMsg.Sig, msg.Sig) protoMsg.Version = msg.Version @@ -207,8 +206,7 @@ func FromChannelUpdateAccMsg(msg *client.ChannelUpdateAccMsg) *Envelope_ChannelU // FromChannelUpdateRejMsg converts a client.ChannelUpdateRejMsg to a protobuf Envelope_ChannelUpdateRejMsg. func FromChannelUpdateRejMsg(msg *client.ChannelUpdateRejMsg) *Envelope_ChannelUpdateRejMsg { protoMsg := &ChannelUpdateRejMsg{} - protoMsg.ChannelId = make([]byte, len(msg.ChannelID)) - copy(protoMsg.ChannelId, msg.ChannelID[:]) + protoMsg.ChannelId, _ = FromIDs(msg.ChannelID) protoMsg.Version = msg.Version protoMsg.Reason = msg.Reason return &Envelope_ChannelUpdateRejMsg{protoMsg} @@ -261,9 +259,7 @@ func FromParams(params *channel.Params) (protoParams *Params, err error) { // FromState converts a channel.State to a protobuf State. func FromState(state *channel.State) (protoState *State, err error) { protoState = &State{} - - protoState.Id = make([]byte, len(state.ID)) - copy(protoState.Id, state.ID[:]) + protoState.Id, _ = FromIDs(state.ID) protoState.Version = state.Version protoState.IsFinal = state.IsFinal protoState.Allocation, err = FromAllocation(state.Allocation) diff --git a/wire/protobuf/wire.pb.go b/wire/protobuf/wire.pb.go index bb4c388eb..96e208bee 100644 --- a/wire/protobuf/wire.pb.go +++ b/wire/protobuf/wire.pb.go @@ -551,6 +551,110 @@ func (x *Address) GetAddressMapping() []*AddressMapping { return nil } +// AddressMapping represents an element of a address mapping. +type IDMapping struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Id []byte `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"` +} + +func (x *IDMapping) Reset() { + *x = IDMapping{} + if protoimpl.UnsafeEnabled { + mi := &file_wire_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *IDMapping) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*IDMapping) ProtoMessage() {} + +func (x *IDMapping) ProtoReflect() protoreflect.Message { + mi := &file_wire_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use IDMapping.ProtoReflect.Descriptor instead. +func (*IDMapping) Descriptor() ([]byte, []int) { + return file_wire_proto_rawDescGZIP(), []int{5} +} + +func (x *IDMapping) GetKey() []byte { + if x != nil { + return x.Key + } + return nil +} + +func (x *IDMapping) GetId() []byte { + if x != nil { + return x.Id + } + return nil +} + +// Address represents the map of addresses for each participant in the channel. +type ID struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + IdMapping []*IDMapping `protobuf:"bytes,1,rep,name=id_mapping,json=idMapping,proto3" json:"id_mapping,omitempty"` +} + +func (x *ID) Reset() { + *x = ID{} + if protoimpl.UnsafeEnabled { + mi := &file_wire_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ID) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ID) ProtoMessage() {} + +func (x *ID) ProtoReflect() protoreflect.Message { + mi := &file_wire_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ID.ProtoReflect.Descriptor instead. +func (*ID) Descriptor() ([]byte, []int) { + return file_wire_proto_rawDescGZIP(), []int{6} +} + +func (x *ID) GetIdMapping() []*IDMapping { + if x != nil { + return x.IdMapping + } + return nil +} + // IndexMap represents the mapping of a participant indices in a sub allocation // or a virtual channel funding proposal to the corresponding indices in the // parent channel. @@ -565,7 +669,7 @@ type IndexMap struct { func (x *IndexMap) Reset() { *x = IndexMap{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[5] + mi := &file_wire_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -578,7 +682,7 @@ func (x *IndexMap) String() string { func (*IndexMap) ProtoMessage() {} func (x *IndexMap) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[5] + mi := &file_wire_proto_msgTypes[7] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -591,7 +695,7 @@ func (x *IndexMap) ProtoReflect() protoreflect.Message { // Deprecated: Use IndexMap.ProtoReflect.Descriptor instead. func (*IndexMap) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{5} + return file_wire_proto_rawDescGZIP(), []int{7} } func (x *IndexMap) GetIndexMap() []uint32 { @@ -607,7 +711,7 @@ type SubAlloc struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id []byte `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Id *ID `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` Bals *Balance `protobuf:"bytes,2,opt,name=bals,proto3" json:"bals,omitempty"` IndexMap *IndexMap `protobuf:"bytes,3,opt,name=index_map,json=indexMap,proto3" json:"index_map,omitempty"` } @@ -615,7 +719,7 @@ type SubAlloc struct { func (x *SubAlloc) Reset() { *x = SubAlloc{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[6] + mi := &file_wire_proto_msgTypes[8] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -628,7 +732,7 @@ func (x *SubAlloc) String() string { func (*SubAlloc) ProtoMessage() {} func (x *SubAlloc) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[6] + mi := &file_wire_proto_msgTypes[8] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -641,10 +745,10 @@ func (x *SubAlloc) ProtoReflect() protoreflect.Message { // Deprecated: Use SubAlloc.ProtoReflect.Descriptor instead. func (*SubAlloc) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{6} + return file_wire_proto_rawDescGZIP(), []int{8} } -func (x *SubAlloc) GetId() []byte { +func (x *SubAlloc) GetId() *ID { if x != nil { return x.Id } @@ -680,7 +784,7 @@ type Allocation struct { func (x *Allocation) Reset() { *x = Allocation{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[7] + mi := &file_wire_proto_msgTypes[9] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -693,7 +797,7 @@ func (x *Allocation) String() string { func (*Allocation) ProtoMessage() {} func (x *Allocation) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[7] + mi := &file_wire_proto_msgTypes[9] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -706,7 +810,7 @@ func (x *Allocation) ProtoReflect() protoreflect.Message { // Deprecated: Use Allocation.ProtoReflect.Descriptor instead. func (*Allocation) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{7} + return file_wire_proto_rawDescGZIP(), []int{9} } func (x *Allocation) GetBackends() [][]byte { @@ -755,7 +859,7 @@ type BaseChannelProposal struct { func (x *BaseChannelProposal) Reset() { *x = BaseChannelProposal{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[8] + mi := &file_wire_proto_msgTypes[10] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -768,7 +872,7 @@ func (x *BaseChannelProposal) String() string { func (*BaseChannelProposal) ProtoMessage() {} func (x *BaseChannelProposal) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[8] + mi := &file_wire_proto_msgTypes[10] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -781,7 +885,7 @@ func (x *BaseChannelProposal) ProtoReflect() protoreflect.Message { // Deprecated: Use BaseChannelProposal.ProtoReflect.Descriptor instead. func (*BaseChannelProposal) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{8} + return file_wire_proto_rawDescGZIP(), []int{10} } func (x *BaseChannelProposal) GetProposalId() []byte { @@ -846,7 +950,7 @@ type BaseChannelProposalAcc struct { func (x *BaseChannelProposalAcc) Reset() { *x = BaseChannelProposalAcc{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[9] + mi := &file_wire_proto_msgTypes[11] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -859,7 +963,7 @@ func (x *BaseChannelProposalAcc) String() string { func (*BaseChannelProposalAcc) ProtoMessage() {} func (x *BaseChannelProposalAcc) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[9] + mi := &file_wire_proto_msgTypes[11] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -872,7 +976,7 @@ func (x *BaseChannelProposalAcc) ProtoReflect() protoreflect.Message { // Deprecated: Use BaseChannelProposalAcc.ProtoReflect.Descriptor instead. func (*BaseChannelProposalAcc) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{9} + return file_wire_proto_rawDescGZIP(), []int{11} } func (x *BaseChannelProposalAcc) GetProposalId() []byte { @@ -895,7 +999,7 @@ type Params struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id []byte `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Id *ID `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` ChallengeDuration uint64 `protobuf:"varint,2,opt,name=challenge_duration,json=challengeDuration,proto3" json:"challenge_duration,omitempty"` Parts []*Address `protobuf:"bytes,3,rep,name=parts,proto3" json:"parts,omitempty"` App []byte `protobuf:"bytes,4,opt,name=app,proto3" json:"app,omitempty"` @@ -907,7 +1011,7 @@ type Params struct { func (x *Params) Reset() { *x = Params{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[10] + mi := &file_wire_proto_msgTypes[12] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -920,7 +1024,7 @@ func (x *Params) String() string { func (*Params) ProtoMessage() {} func (x *Params) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[10] + mi := &file_wire_proto_msgTypes[12] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -933,10 +1037,10 @@ func (x *Params) ProtoReflect() protoreflect.Message { // Deprecated: Use Params.ProtoReflect.Descriptor instead. func (*Params) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{10} + return file_wire_proto_rawDescGZIP(), []int{12} } -func (x *Params) GetId() []byte { +func (x *Params) GetId() *ID { if x != nil { return x.Id } @@ -991,7 +1095,7 @@ type State struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id []byte `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Id *ID `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` Version uint64 `protobuf:"varint,2,opt,name=version,proto3" json:"version,omitempty"` App []byte `protobuf:"bytes,3,opt,name=app,proto3" json:"app,omitempty"` Allocation *Allocation `protobuf:"bytes,4,opt,name=allocation,proto3" json:"allocation,omitempty"` @@ -1002,7 +1106,7 @@ type State struct { func (x *State) Reset() { *x = State{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[11] + mi := &file_wire_proto_msgTypes[13] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1015,7 +1119,7 @@ func (x *State) String() string { func (*State) ProtoMessage() {} func (x *State) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[11] + mi := &file_wire_proto_msgTypes[13] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1028,10 +1132,10 @@ func (x *State) ProtoReflect() protoreflect.Message { // Deprecated: Use State.ProtoReflect.Descriptor instead. func (*State) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{11} + return file_wire_proto_rawDescGZIP(), []int{13} } -func (x *State) GetId() []byte { +func (x *State) GetId() *ID { if x != nil { return x.Id } @@ -1086,7 +1190,7 @@ type Transaction struct { func (x *Transaction) Reset() { *x = Transaction{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[12] + mi := &file_wire_proto_msgTypes[14] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1099,7 +1203,7 @@ func (x *Transaction) String() string { func (*Transaction) ProtoMessage() {} func (x *Transaction) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[12] + mi := &file_wire_proto_msgTypes[14] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1112,7 +1216,7 @@ func (x *Transaction) ProtoReflect() protoreflect.Message { // Deprecated: Use Transaction.ProtoReflect.Descriptor instead. func (*Transaction) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{12} + return file_wire_proto_rawDescGZIP(), []int{14} } func (x *Transaction) GetState() *State { @@ -1143,7 +1247,7 @@ type SignedState struct { func (x *SignedState) Reset() { *x = SignedState{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[13] + mi := &file_wire_proto_msgTypes[15] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1156,7 +1260,7 @@ func (x *SignedState) String() string { func (*SignedState) ProtoMessage() {} func (x *SignedState) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[13] + mi := &file_wire_proto_msgTypes[15] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1169,7 +1273,7 @@ func (x *SignedState) ProtoReflect() protoreflect.Message { // Deprecated: Use SignedState.ProtoReflect.Descriptor instead. func (*SignedState) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{13} + return file_wire_proto_rawDescGZIP(), []int{15} } func (x *SignedState) GetParams() *Params { @@ -1206,7 +1310,7 @@ type ChannelUpdate struct { func (x *ChannelUpdate) Reset() { *x = ChannelUpdate{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[14] + mi := &file_wire_proto_msgTypes[16] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1219,7 +1323,7 @@ func (x *ChannelUpdate) String() string { func (*ChannelUpdate) ProtoMessage() {} func (x *ChannelUpdate) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[14] + mi := &file_wire_proto_msgTypes[16] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1232,7 +1336,7 @@ func (x *ChannelUpdate) ProtoReflect() protoreflect.Message { // Deprecated: Use ChannelUpdate.ProtoReflect.Descriptor instead. func (*ChannelUpdate) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{14} + return file_wire_proto_rawDescGZIP(), []int{16} } func (x *ChannelUpdate) GetState() *State { @@ -1261,7 +1365,7 @@ type PingMsg struct { func (x *PingMsg) Reset() { *x = PingMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[15] + mi := &file_wire_proto_msgTypes[17] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1274,7 +1378,7 @@ func (x *PingMsg) String() string { func (*PingMsg) ProtoMessage() {} func (x *PingMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[15] + mi := &file_wire_proto_msgTypes[17] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1287,7 +1391,7 @@ func (x *PingMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use PingMsg.ProtoReflect.Descriptor instead. func (*PingMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{15} + return file_wire_proto_rawDescGZIP(), []int{17} } func (x *PingMsg) GetCreated() int64 { @@ -1309,7 +1413,7 @@ type PongMsg struct { func (x *PongMsg) Reset() { *x = PongMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[16] + mi := &file_wire_proto_msgTypes[18] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1322,7 +1426,7 @@ func (x *PongMsg) String() string { func (*PongMsg) ProtoMessage() {} func (x *PongMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[16] + mi := &file_wire_proto_msgTypes[18] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1335,7 +1439,7 @@ func (x *PongMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use PongMsg.ProtoReflect.Descriptor instead. func (*PongMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{16} + return file_wire_proto_rawDescGZIP(), []int{18} } func (x *PongMsg) GetCreated() int64 { @@ -1357,7 +1461,7 @@ type ShutdownMsg struct { func (x *ShutdownMsg) Reset() { *x = ShutdownMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[17] + mi := &file_wire_proto_msgTypes[19] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1370,7 +1474,7 @@ func (x *ShutdownMsg) String() string { func (*ShutdownMsg) ProtoMessage() {} func (x *ShutdownMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[17] + mi := &file_wire_proto_msgTypes[19] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1383,7 +1487,7 @@ func (x *ShutdownMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use ShutdownMsg.ProtoReflect.Descriptor instead. func (*ShutdownMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{17} + return file_wire_proto_rawDescGZIP(), []int{19} } func (x *ShutdownMsg) GetReason() string { @@ -1405,7 +1509,7 @@ type AuthResponseMsg struct { func (x *AuthResponseMsg) Reset() { *x = AuthResponseMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[18] + mi := &file_wire_proto_msgTypes[20] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1418,7 +1522,7 @@ func (x *AuthResponseMsg) String() string { func (*AuthResponseMsg) ProtoMessage() {} func (x *AuthResponseMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[18] + mi := &file_wire_proto_msgTypes[20] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1431,7 +1535,7 @@ func (x *AuthResponseMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use AuthResponseMsg.ProtoReflect.Descriptor instead. func (*AuthResponseMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{18} + return file_wire_proto_rawDescGZIP(), []int{20} } func (x *AuthResponseMsg) GetSignature() []byte { @@ -1455,7 +1559,7 @@ type LedgerChannelProposalMsg struct { func (x *LedgerChannelProposalMsg) Reset() { *x = LedgerChannelProposalMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[19] + mi := &file_wire_proto_msgTypes[21] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1468,7 +1572,7 @@ func (x *LedgerChannelProposalMsg) String() string { func (*LedgerChannelProposalMsg) ProtoMessage() {} func (x *LedgerChannelProposalMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[19] + mi := &file_wire_proto_msgTypes[21] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1481,7 +1585,7 @@ func (x *LedgerChannelProposalMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use LedgerChannelProposalMsg.ProtoReflect.Descriptor instead. func (*LedgerChannelProposalMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{19} + return file_wire_proto_rawDescGZIP(), []int{21} } func (x *LedgerChannelProposalMsg) GetBaseChannelProposal() *BaseChannelProposal { @@ -1518,7 +1622,7 @@ type LedgerChannelProposalAccMsg struct { func (x *LedgerChannelProposalAccMsg) Reset() { *x = LedgerChannelProposalAccMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[20] + mi := &file_wire_proto_msgTypes[22] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1531,7 +1635,7 @@ func (x *LedgerChannelProposalAccMsg) String() string { func (*LedgerChannelProposalAccMsg) ProtoMessage() {} func (x *LedgerChannelProposalAccMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[20] + mi := &file_wire_proto_msgTypes[22] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1544,7 +1648,7 @@ func (x *LedgerChannelProposalAccMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use LedgerChannelProposalAccMsg.ProtoReflect.Descriptor instead. func (*LedgerChannelProposalAccMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{20} + return file_wire_proto_rawDescGZIP(), []int{22} } func (x *LedgerChannelProposalAccMsg) GetBaseChannelProposalAcc() *BaseChannelProposalAcc { @@ -1568,13 +1672,13 @@ type SubChannelProposalMsg struct { unknownFields protoimpl.UnknownFields BaseChannelProposal *BaseChannelProposal `protobuf:"bytes,1,opt,name=base_channel_proposal,json=baseChannelProposal,proto3" json:"base_channel_proposal,omitempty"` - Parent []byte `protobuf:"bytes,2,opt,name=parent,proto3" json:"parent,omitempty"` + Parent *ID `protobuf:"bytes,2,opt,name=parent,proto3" json:"parent,omitempty"` } func (x *SubChannelProposalMsg) Reset() { *x = SubChannelProposalMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[21] + mi := &file_wire_proto_msgTypes[23] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1587,7 +1691,7 @@ func (x *SubChannelProposalMsg) String() string { func (*SubChannelProposalMsg) ProtoMessage() {} func (x *SubChannelProposalMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[21] + mi := &file_wire_proto_msgTypes[23] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1600,7 +1704,7 @@ func (x *SubChannelProposalMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use SubChannelProposalMsg.ProtoReflect.Descriptor instead. func (*SubChannelProposalMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{21} + return file_wire_proto_rawDescGZIP(), []int{23} } func (x *SubChannelProposalMsg) GetBaseChannelProposal() *BaseChannelProposal { @@ -1610,7 +1714,7 @@ func (x *SubChannelProposalMsg) GetBaseChannelProposal() *BaseChannelProposal { return nil } -func (x *SubChannelProposalMsg) GetParent() []byte { +func (x *SubChannelProposalMsg) GetParent() *ID { if x != nil { return x.Parent } @@ -1629,7 +1733,7 @@ type SubChannelProposalAccMsg struct { func (x *SubChannelProposalAccMsg) Reset() { *x = SubChannelProposalAccMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[22] + mi := &file_wire_proto_msgTypes[24] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1642,7 +1746,7 @@ func (x *SubChannelProposalAccMsg) String() string { func (*SubChannelProposalAccMsg) ProtoMessage() {} func (x *SubChannelProposalAccMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[22] + mi := &file_wire_proto_msgTypes[24] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1655,7 +1759,7 @@ func (x *SubChannelProposalAccMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use SubChannelProposalAccMsg.ProtoReflect.Descriptor instead. func (*SubChannelProposalAccMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{22} + return file_wire_proto_rawDescGZIP(), []int{24} } func (x *SubChannelProposalAccMsg) GetBaseChannelProposalAcc() *BaseChannelProposalAcc { @@ -1674,14 +1778,14 @@ type VirtualChannelProposalMsg struct { BaseChannelProposal *BaseChannelProposal `protobuf:"bytes,1,opt,name=base_channel_proposal,json=baseChannelProposal,proto3" json:"base_channel_proposal,omitempty"` Proposer *Address `protobuf:"bytes,2,opt,name=proposer,proto3" json:"proposer,omitempty"` Peers []*Address `protobuf:"bytes,3,rep,name=peers,proto3" json:"peers,omitempty"` - Parents [][]byte `protobuf:"bytes,4,rep,name=parents,proto3" json:"parents,omitempty"` + Parents []*ID `protobuf:"bytes,4,rep,name=parents,proto3" json:"parents,omitempty"` IndexMaps []*IndexMap `protobuf:"bytes,5,rep,name=index_maps,json=indexMaps,proto3" json:"index_maps,omitempty"` } func (x *VirtualChannelProposalMsg) Reset() { *x = VirtualChannelProposalMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[23] + mi := &file_wire_proto_msgTypes[25] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1694,7 +1798,7 @@ func (x *VirtualChannelProposalMsg) String() string { func (*VirtualChannelProposalMsg) ProtoMessage() {} func (x *VirtualChannelProposalMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[23] + mi := &file_wire_proto_msgTypes[25] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1707,7 +1811,7 @@ func (x *VirtualChannelProposalMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use VirtualChannelProposalMsg.ProtoReflect.Descriptor instead. func (*VirtualChannelProposalMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{23} + return file_wire_proto_rawDescGZIP(), []int{25} } func (x *VirtualChannelProposalMsg) GetBaseChannelProposal() *BaseChannelProposal { @@ -1731,7 +1835,7 @@ func (x *VirtualChannelProposalMsg) GetPeers() []*Address { return nil } -func (x *VirtualChannelProposalMsg) GetParents() [][]byte { +func (x *VirtualChannelProposalMsg) GetParents() []*ID { if x != nil { return x.Parents } @@ -1758,7 +1862,7 @@ type VirtualChannelProposalAccMsg struct { func (x *VirtualChannelProposalAccMsg) Reset() { *x = VirtualChannelProposalAccMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[24] + mi := &file_wire_proto_msgTypes[26] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1771,7 +1875,7 @@ func (x *VirtualChannelProposalAccMsg) String() string { func (*VirtualChannelProposalAccMsg) ProtoMessage() {} func (x *VirtualChannelProposalAccMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[24] + mi := &file_wire_proto_msgTypes[26] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1784,7 +1888,7 @@ func (x *VirtualChannelProposalAccMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use VirtualChannelProposalAccMsg.ProtoReflect.Descriptor instead. func (*VirtualChannelProposalAccMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{24} + return file_wire_proto_rawDescGZIP(), []int{26} } func (x *VirtualChannelProposalAccMsg) GetBaseChannelProposalAcc() *BaseChannelProposalAcc { @@ -1814,7 +1918,7 @@ type ChannelProposalRejMsg struct { func (x *ChannelProposalRejMsg) Reset() { *x = ChannelProposalRejMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[25] + mi := &file_wire_proto_msgTypes[27] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1827,7 +1931,7 @@ func (x *ChannelProposalRejMsg) String() string { func (*ChannelProposalRejMsg) ProtoMessage() {} func (x *ChannelProposalRejMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[25] + mi := &file_wire_proto_msgTypes[27] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1840,7 +1944,7 @@ func (x *ChannelProposalRejMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use ChannelProposalRejMsg.ProtoReflect.Descriptor instead. func (*ChannelProposalRejMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{25} + return file_wire_proto_rawDescGZIP(), []int{27} } func (x *ChannelProposalRejMsg) GetProposalId() []byte { @@ -1870,7 +1974,7 @@ type ChannelUpdateMsg struct { func (x *ChannelUpdateMsg) Reset() { *x = ChannelUpdateMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[26] + mi := &file_wire_proto_msgTypes[28] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1883,7 +1987,7 @@ func (x *ChannelUpdateMsg) String() string { func (*ChannelUpdateMsg) ProtoMessage() {} func (x *ChannelUpdateMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[26] + mi := &file_wire_proto_msgTypes[28] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1896,7 +2000,7 @@ func (x *ChannelUpdateMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use ChannelUpdateMsg.ProtoReflect.Descriptor instead. func (*ChannelUpdateMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{26} + return file_wire_proto_rawDescGZIP(), []int{28} } func (x *ChannelUpdateMsg) GetChannelUpdate() *ChannelUpdate { @@ -1928,7 +2032,7 @@ type VirtualChannelFundingProposalMsg struct { func (x *VirtualChannelFundingProposalMsg) Reset() { *x = VirtualChannelFundingProposalMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[27] + mi := &file_wire_proto_msgTypes[29] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1941,7 +2045,7 @@ func (x *VirtualChannelFundingProposalMsg) String() string { func (*VirtualChannelFundingProposalMsg) ProtoMessage() {} func (x *VirtualChannelFundingProposalMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[27] + mi := &file_wire_proto_msgTypes[29] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1954,7 +2058,7 @@ func (x *VirtualChannelFundingProposalMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use VirtualChannelFundingProposalMsg.ProtoReflect.Descriptor instead. func (*VirtualChannelFundingProposalMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{27} + return file_wire_proto_rawDescGZIP(), []int{29} } func (x *VirtualChannelFundingProposalMsg) GetChannelUpdateMsg() *ChannelUpdateMsg { @@ -1992,7 +2096,7 @@ type VirtualChannelSettlementProposalMsg struct { func (x *VirtualChannelSettlementProposalMsg) Reset() { *x = VirtualChannelSettlementProposalMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[28] + mi := &file_wire_proto_msgTypes[30] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2005,7 +2109,7 @@ func (x *VirtualChannelSettlementProposalMsg) String() string { func (*VirtualChannelSettlementProposalMsg) ProtoMessage() {} func (x *VirtualChannelSettlementProposalMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[28] + mi := &file_wire_proto_msgTypes[30] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2018,7 +2122,7 @@ func (x *VirtualChannelSettlementProposalMsg) ProtoReflect() protoreflect.Messag // Deprecated: Use VirtualChannelSettlementProposalMsg.ProtoReflect.Descriptor instead. func (*VirtualChannelSettlementProposalMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{28} + return file_wire_proto_rawDescGZIP(), []int{30} } func (x *VirtualChannelSettlementProposalMsg) GetChannelUpdateMsg() *ChannelUpdateMsg { @@ -2041,7 +2145,7 @@ type ChannelUpdateAccMsg struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - ChannelId []byte `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` + ChannelId *ID `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` Version uint64 `protobuf:"varint,2,opt,name=version,proto3" json:"version,omitempty"` Sig []byte `protobuf:"bytes,3,opt,name=sig,proto3" json:"sig,omitempty"` } @@ -2049,7 +2153,7 @@ type ChannelUpdateAccMsg struct { func (x *ChannelUpdateAccMsg) Reset() { *x = ChannelUpdateAccMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[29] + mi := &file_wire_proto_msgTypes[31] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2062,7 +2166,7 @@ func (x *ChannelUpdateAccMsg) String() string { func (*ChannelUpdateAccMsg) ProtoMessage() {} func (x *ChannelUpdateAccMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[29] + mi := &file_wire_proto_msgTypes[31] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2075,10 +2179,10 @@ func (x *ChannelUpdateAccMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use ChannelUpdateAccMsg.ProtoReflect.Descriptor instead. func (*ChannelUpdateAccMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{29} + return file_wire_proto_rawDescGZIP(), []int{31} } -func (x *ChannelUpdateAccMsg) GetChannelId() []byte { +func (x *ChannelUpdateAccMsg) GetChannelId() *ID { if x != nil { return x.ChannelId } @@ -2105,7 +2209,7 @@ type ChannelUpdateRejMsg struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - ChannelId []byte `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` + ChannelId *ID `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` Version uint64 `protobuf:"varint,2,opt,name=version,proto3" json:"version,omitempty"` Reason string `protobuf:"bytes,3,opt,name=reason,proto3" json:"reason,omitempty"` } @@ -2113,7 +2217,7 @@ type ChannelUpdateRejMsg struct { func (x *ChannelUpdateRejMsg) Reset() { *x = ChannelUpdateRejMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[30] + mi := &file_wire_proto_msgTypes[32] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2126,7 +2230,7 @@ func (x *ChannelUpdateRejMsg) String() string { func (*ChannelUpdateRejMsg) ProtoMessage() {} func (x *ChannelUpdateRejMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[30] + mi := &file_wire_proto_msgTypes[32] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2139,10 +2243,10 @@ func (x *ChannelUpdateRejMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use ChannelUpdateRejMsg.ProtoReflect.Descriptor instead. func (*ChannelUpdateRejMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{30} + return file_wire_proto_rawDescGZIP(), []int{32} } -func (x *ChannelUpdateRejMsg) GetChannelId() []byte { +func (x *ChannelUpdateRejMsg) GetChannelId() *ID { if x != nil { return x.ChannelId } @@ -2176,7 +2280,7 @@ type ChannelSyncMsg struct { func (x *ChannelSyncMsg) Reset() { *x = ChannelSyncMsg{} if protoimpl.UnsafeEnabled { - mi := &file_wire_proto_msgTypes[31] + mi := &file_wire_proto_msgTypes[33] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -2189,7 +2293,7 @@ func (x *ChannelSyncMsg) String() string { func (*ChannelSyncMsg) ProtoMessage() {} func (x *ChannelSyncMsg) ProtoReflect() protoreflect.Message { - mi := &file_wire_proto_msgTypes[31] + mi := &file_wire_proto_msgTypes[33] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -2202,7 +2306,7 @@ func (x *ChannelSyncMsg) ProtoReflect() protoreflect.Message { // Deprecated: Use ChannelSyncMsg.ProtoReflect.Descriptor instead. func (*ChannelSyncMsg) Descriptor() ([]byte, []int) { - return file_wire_proto_rawDescGZIP(), []int{31} + return file_wire_proto_rawDescGZIP(), []int{33} } func (x *ChannelSyncMsg) GetPhase() uint32 { @@ -2341,230 +2445,244 @@ var file_wire_proto_rawDesc = []byte{ 0x72, 0x65, 0x73, 0x73, 0x5f, 0x6d, 0x61, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x4d, 0x61, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x52, 0x0e, 0x61, - 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x4d, 0x61, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x22, 0x27, 0x0a, - 0x08, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x4d, 0x61, 0x70, 0x12, 0x1b, 0x0a, 0x09, 0x69, 0x6e, 0x64, - 0x65, 0x78, 0x5f, 0x6d, 0x61, 0x70, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0d, 0x52, 0x08, 0x69, 0x6e, - 0x64, 0x65, 0x78, 0x4d, 0x61, 0x70, 0x22, 0x74, 0x0a, 0x08, 0x53, 0x75, 0x62, 0x41, 0x6c, 0x6c, - 0x6f, 0x63, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x02, - 0x69, 0x64, 0x12, 0x26, 0x0a, 0x04, 0x62, 0x61, 0x6c, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x12, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x42, 0x61, 0x6c, - 0x61, 0x6e, 0x63, 0x65, 0x52, 0x04, 0x62, 0x61, 0x6c, 0x73, 0x12, 0x30, 0x0a, 0x09, 0x69, 0x6e, - 0x64, 0x65, 0x78, 0x5f, 0x6d, 0x61, 0x70, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, - 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x4d, - 0x61, 0x70, 0x52, 0x08, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x4d, 0x61, 0x70, 0x22, 0x9e, 0x01, 0x0a, - 0x0a, 0x41, 0x6c, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x62, - 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x08, 0x62, - 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x73, 0x73, 0x65, 0x74, - 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x06, 0x61, 0x73, 0x73, 0x65, 0x74, 0x73, 0x12, - 0x2f, 0x0a, 0x08, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x13, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x42, 0x61, - 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x73, 0x52, 0x08, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x73, - 0x12, 0x2b, 0x0a, 0x06, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, - 0x32, 0x13, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x53, 0x75, 0x62, - 0x41, 0x6c, 0x6c, 0x6f, 0x63, 0x52, 0x06, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x22, 0xab, 0x02, - 0x0a, 0x13, 0x42, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, - 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x12, 0x1f, 0x0a, 0x0b, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, - 0x6c, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x70, 0x72, 0x6f, 0x70, - 0x6f, 0x73, 0x61, 0x6c, 0x49, 0x64, 0x12, 0x2d, 0x0a, 0x12, 0x63, 0x68, 0x61, 0x6c, 0x6c, 0x65, - 0x6e, 0x67, 0x65, 0x5f, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x04, 0x52, 0x11, 0x63, 0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, 0x67, 0x65, 0x44, 0x75, 0x72, - 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1f, 0x0a, 0x0b, 0x6e, 0x6f, 0x6e, 0x63, 0x65, 0x5f, 0x73, - 0x68, 0x61, 0x72, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x6e, 0x6f, 0x6e, 0x63, - 0x65, 0x53, 0x68, 0x61, 0x72, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x61, 0x70, 0x70, 0x18, 0x04, 0x20, - 0x01, 0x28, 0x0c, 0x52, 0x03, 0x61, 0x70, 0x70, 0x12, 0x1b, 0x0a, 0x09, 0x69, 0x6e, 0x69, 0x74, - 0x5f, 0x64, 0x61, 0x74, 0x61, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x69, 0x6e, 0x69, - 0x74, 0x44, 0x61, 0x74, 0x61, 0x12, 0x32, 0x0a, 0x09, 0x69, 0x6e, 0x69, 0x74, 0x5f, 0x62, 0x61, - 0x6c, 0x73, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, - 0x77, 0x69, 0x72, 0x65, 0x2e, 0x41, 0x6c, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, - 0x08, 0x69, 0x6e, 0x69, 0x74, 0x42, 0x61, 0x6c, 0x73, 0x12, 0x40, 0x0a, 0x11, 0x66, 0x75, 0x6e, - 0x64, 0x69, 0x6e, 0x67, 0x5f, 0x61, 0x67, 0x72, 0x65, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x07, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, - 0x2e, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x73, 0x52, 0x10, 0x66, 0x75, 0x6e, 0x64, 0x69, - 0x6e, 0x67, 0x41, 0x67, 0x72, 0x65, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x5a, 0x0a, 0x16, 0x42, - 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, - 0x61, 0x6c, 0x41, 0x63, 0x63, 0x12, 0x1f, 0x0a, 0x0b, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, - 0x6c, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x70, 0x72, 0x6f, 0x70, - 0x6f, 0x73, 0x61, 0x6c, 0x49, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x6e, 0x6f, 0x6e, 0x63, 0x65, 0x5f, - 0x73, 0x68, 0x61, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x6e, 0x6f, 0x6e, - 0x63, 0x65, 0x53, 0x68, 0x61, 0x72, 0x65, 0x22, 0xe9, 0x01, 0x0a, 0x06, 0x50, 0x61, 0x72, 0x61, - 0x6d, 0x73, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x02, - 0x69, 0x64, 0x12, 0x2d, 0x0a, 0x12, 0x63, 0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, 0x67, 0x65, 0x5f, - 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x11, - 0x63, 0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, 0x67, 0x65, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x12, 0x28, 0x0a, 0x05, 0x70, 0x61, 0x72, 0x74, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, - 0x32, 0x12, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x41, 0x64, 0x64, - 0x72, 0x65, 0x73, 0x73, 0x52, 0x05, 0x70, 0x61, 0x72, 0x74, 0x73, 0x12, 0x10, 0x0a, 0x03, 0x61, - 0x70, 0x70, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x61, 0x70, 0x70, 0x12, 0x14, 0x0a, - 0x05, 0x6e, 0x6f, 0x6e, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x6e, 0x6f, - 0x6e, 0x63, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x6c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x5f, 0x63, 0x68, - 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0d, 0x6c, 0x65, 0x64, - 0x67, 0x65, 0x72, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x12, 0x27, 0x0a, 0x0f, 0x76, 0x69, - 0x72, 0x74, 0x75, 0x61, 0x6c, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x18, 0x07, 0x20, - 0x01, 0x28, 0x08, 0x52, 0x0e, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x43, 0x68, 0x61, 0x6e, - 0x6e, 0x65, 0x6c, 0x22, 0xa9, 0x01, 0x0a, 0x05, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x0e, 0x0a, - 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, - 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x07, - 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x61, 0x70, 0x70, 0x18, 0x03, - 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x61, 0x70, 0x70, 0x12, 0x35, 0x0a, 0x0a, 0x61, 0x6c, 0x6c, - 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, - 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x41, 0x6c, 0x6c, 0x6f, 0x63, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0a, 0x61, 0x6c, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, - 0x64, 0x61, 0x74, 0x61, 0x12, 0x19, 0x0a, 0x08, 0x69, 0x73, 0x5f, 0x66, 0x69, 0x6e, 0x61, 0x6c, - 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x69, 0x73, 0x46, 0x69, 0x6e, 0x61, 0x6c, 0x22, - 0x49, 0x0a, 0x0b, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x26, - 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, - 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, - 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x69, 0x67, 0x73, 0x18, 0x02, - 0x20, 0x03, 0x28, 0x0c, 0x52, 0x04, 0x73, 0x69, 0x67, 0x73, 0x22, 0x74, 0x0a, 0x0b, 0x53, 0x69, - 0x67, 0x6e, 0x65, 0x64, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x29, 0x0a, 0x06, 0x70, 0x61, 0x72, - 0x61, 0x6d, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x70, 0x65, 0x72, 0x75, - 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x52, 0x06, 0x70, 0x61, - 0x72, 0x61, 0x6d, 0x73, 0x12, 0x26, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, - 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x12, 0x12, 0x0a, 0x04, - 0x73, 0x69, 0x67, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x04, 0x73, 0x69, 0x67, 0x73, - 0x22, 0x54, 0x0a, 0x0d, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, - 0x65, 0x12, 0x26, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x10, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x53, 0x74, 0x61, - 0x74, 0x65, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x61, 0x63, 0x74, - 0x6f, 0x72, 0x5f, 0x69, 0x64, 0x78, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x61, 0x63, - 0x74, 0x6f, 0x72, 0x49, 0x64, 0x78, 0x22, 0x23, 0x0a, 0x07, 0x50, 0x69, 0x6e, 0x67, 0x4d, 0x73, - 0x67, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x03, 0x52, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x22, 0x23, 0x0a, 0x07, 0x50, - 0x6f, 0x6e, 0x67, 0x4d, 0x73, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, - 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, - 0x22, 0x25, 0x0a, 0x0b, 0x53, 0x68, 0x75, 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x4d, 0x73, 0x67, 0x12, - 0x16, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x22, 0x2f, 0x0a, 0x0f, 0x41, 0x75, 0x74, 0x68, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x4d, 0x73, 0x67, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x69, - 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x73, - 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x22, 0xce, 0x01, 0x0a, 0x18, 0x4c, 0x65, 0x64, - 0x67, 0x65, 0x72, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, - 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x12, 0x52, 0x0a, 0x15, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x63, 0x68, - 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, - 0x2e, 0x42, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, - 0x6f, 0x73, 0x61, 0x6c, 0x52, 0x13, 0x62, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, - 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x12, 0x34, 0x0a, 0x0b, 0x70, 0x61, 0x72, - 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, - 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, - 0x73, 0x73, 0x52, 0x0b, 0x70, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x12, - 0x28, 0x0a, 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x12, - 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, - 0x73, 0x73, 0x52, 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, 0x22, 0xb1, 0x01, 0x0a, 0x1b, 0x4c, 0x65, - 0x64, 0x67, 0x65, 0x72, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, - 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x4d, 0x73, 0x67, 0x12, 0x5c, 0x0a, 0x19, 0x62, 0x61, 0x73, - 0x65, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, - 0x61, 0x6c, 0x5f, 0x61, 0x63, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x70, - 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, - 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x52, - 0x16, 0x62, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, - 0x6f, 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x12, 0x34, 0x0a, 0x0b, 0x70, 0x61, 0x72, 0x74, 0x69, - 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, - 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, - 0x52, 0x0b, 0x70, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x22, 0x83, 0x01, - 0x0a, 0x15, 0x53, 0x75, 0x62, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, - 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x12, 0x52, 0x0a, 0x15, 0x62, 0x61, 0x73, 0x65, 0x5f, - 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, - 0x72, 0x65, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, - 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x52, 0x13, 0x62, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, - 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x12, 0x16, 0x0a, 0x06, 0x70, - 0x61, 0x72, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x06, 0x70, 0x61, 0x72, - 0x65, 0x6e, 0x74, 0x22, 0x78, 0x0a, 0x18, 0x53, 0x75, 0x62, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, - 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x4d, 0x73, 0x67, 0x12, - 0x5c, 0x0a, 0x19, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, - 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x5f, 0x61, 0x63, 0x63, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x42, - 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, - 0x61, 0x6c, 0x41, 0x63, 0x63, 0x52, 0x16, 0x62, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, - 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x22, 0x97, 0x02, - 0x0a, 0x19, 0x56, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, - 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x12, 0x52, 0x0a, 0x15, 0x62, - 0x61, 0x73, 0x65, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x70, 0x72, 0x6f, 0x70, - 0x6f, 0x73, 0x61, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x70, 0x65, 0x72, - 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, - 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x52, 0x13, 0x62, 0x61, 0x73, 0x65, + 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x4d, 0x61, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x22, 0x2d, 0x0a, + 0x09, 0x49, 0x44, 0x4d, 0x61, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, + 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x0e, 0x0a, 0x02, + 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x02, 0x69, 0x64, 0x22, 0x39, 0x0a, 0x02, + 0x49, 0x44, 0x12, 0x33, 0x0a, 0x0a, 0x69, 0x64, 0x5f, 0x6d, 0x61, 0x70, 0x70, 0x69, 0x6e, 0x67, + 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, + 0x72, 0x65, 0x2e, 0x49, 0x44, 0x4d, 0x61, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x52, 0x09, 0x69, 0x64, + 0x4d, 0x61, 0x70, 0x70, 0x69, 0x6e, 0x67, 0x22, 0x27, 0x0a, 0x08, 0x49, 0x6e, 0x64, 0x65, 0x78, + 0x4d, 0x61, 0x70, 0x12, 0x1b, 0x0a, 0x09, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x5f, 0x6d, 0x61, 0x70, + 0x18, 0x01, 0x20, 0x03, 0x28, 0x0d, 0x52, 0x08, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x4d, 0x61, 0x70, + 0x22, 0x83, 0x01, 0x0a, 0x08, 0x53, 0x75, 0x62, 0x41, 0x6c, 0x6c, 0x6f, 0x63, 0x12, 0x1d, 0x0a, + 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x70, 0x65, 0x72, 0x75, + 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x49, 0x44, 0x52, 0x02, 0x69, 0x64, 0x12, 0x26, 0x0a, 0x04, + 0x62, 0x61, 0x6c, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, 0x65, 0x72, + 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x04, + 0x62, 0x61, 0x6c, 0x73, 0x12, 0x30, 0x0a, 0x09, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x5f, 0x6d, 0x61, + 0x70, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, + 0x69, 0x72, 0x65, 0x2e, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x4d, 0x61, 0x70, 0x52, 0x08, 0x69, 0x6e, + 0x64, 0x65, 0x78, 0x4d, 0x61, 0x70, 0x22, 0x9e, 0x01, 0x0a, 0x0a, 0x41, 0x6c, 0x6c, 0x6f, 0x63, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x62, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, + 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x08, 0x62, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, + 0x73, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x73, 0x73, 0x65, 0x74, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, + 0x0c, 0x52, 0x06, 0x61, 0x73, 0x73, 0x65, 0x74, 0x73, 0x12, 0x2f, 0x0a, 0x08, 0x62, 0x61, 0x6c, + 0x61, 0x6e, 0x63, 0x65, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x70, 0x65, + 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x73, + 0x52, 0x08, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x73, 0x12, 0x2b, 0x0a, 0x06, 0x6c, 0x6f, + 0x63, 0x6b, 0x65, 0x64, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x70, 0x65, 0x72, + 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x53, 0x75, 0x62, 0x41, 0x6c, 0x6c, 0x6f, 0x63, 0x52, + 0x06, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x22, 0xab, 0x02, 0x0a, 0x13, 0x42, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x12, - 0x2e, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x12, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x41, 0x64, - 0x64, 0x72, 0x65, 0x73, 0x73, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x65, 0x72, 0x12, - 0x28, 0x0a, 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x12, - 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, - 0x73, 0x73, 0x52, 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x61, 0x72, - 0x65, 0x6e, 0x74, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x07, 0x70, 0x61, 0x72, 0x65, - 0x6e, 0x74, 0x73, 0x12, 0x32, 0x0a, 0x0a, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x5f, 0x6d, 0x61, 0x70, - 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, - 0x69, 0x72, 0x65, 0x2e, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x4d, 0x61, 0x70, 0x52, 0x09, 0x69, 0x6e, - 0x64, 0x65, 0x78, 0x4d, 0x61, 0x70, 0x73, 0x22, 0xae, 0x01, 0x0a, 0x1c, 0x56, 0x69, 0x72, 0x74, - 0x75, 0x61, 0x6c, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, - 0x61, 0x6c, 0x41, 0x63, 0x63, 0x4d, 0x73, 0x67, 0x12, 0x5c, 0x0a, 0x19, 0x62, 0x61, 0x73, 0x65, - 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, - 0x6c, 0x5f, 0x61, 0x63, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x70, 0x65, - 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, - 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x52, 0x16, + 0x1f, 0x0a, 0x0b, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x5f, 0x69, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x49, 0x64, + 0x12, 0x2d, 0x0a, 0x12, 0x63, 0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, 0x67, 0x65, 0x5f, 0x64, 0x75, + 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x11, 0x63, 0x68, + 0x61, 0x6c, 0x6c, 0x65, 0x6e, 0x67, 0x65, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, + 0x1f, 0x0a, 0x0b, 0x6e, 0x6f, 0x6e, 0x63, 0x65, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x6e, 0x6f, 0x6e, 0x63, 0x65, 0x53, 0x68, 0x61, 0x72, 0x65, + 0x12, 0x10, 0x0a, 0x03, 0x61, 0x70, 0x70, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x61, + 0x70, 0x70, 0x12, 0x1b, 0x0a, 0x09, 0x69, 0x6e, 0x69, 0x74, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x18, + 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x69, 0x6e, 0x69, 0x74, 0x44, 0x61, 0x74, 0x61, 0x12, + 0x32, 0x0a, 0x09, 0x69, 0x6e, 0x69, 0x74, 0x5f, 0x62, 0x61, 0x6c, 0x73, 0x18, 0x06, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x41, + 0x6c, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x08, 0x69, 0x6e, 0x69, 0x74, 0x42, + 0x61, 0x6c, 0x73, 0x12, 0x40, 0x0a, 0x11, 0x66, 0x75, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x5f, 0x61, + 0x67, 0x72, 0x65, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, + 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x42, 0x61, 0x6c, 0x61, 0x6e, + 0x63, 0x65, 0x73, 0x52, 0x10, 0x66, 0x75, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x41, 0x67, 0x72, 0x65, + 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x5a, 0x0a, 0x16, 0x42, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, + 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x12, + 0x1f, 0x0a, 0x0b, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x5f, 0x69, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x49, 0x64, + 0x12, 0x1f, 0x0a, 0x0b, 0x6e, 0x6f, 0x6e, 0x63, 0x65, 0x5f, 0x73, 0x68, 0x61, 0x72, 0x65, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x6e, 0x6f, 0x6e, 0x63, 0x65, 0x53, 0x68, 0x61, 0x72, + 0x65, 0x22, 0xf8, 0x01, 0x0a, 0x06, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x1d, 0x0a, 0x02, + 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, + 0x77, 0x69, 0x72, 0x65, 0x2e, 0x49, 0x44, 0x52, 0x02, 0x69, 0x64, 0x12, 0x2d, 0x0a, 0x12, 0x63, + 0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, 0x67, 0x65, 0x5f, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x11, 0x63, 0x68, 0x61, 0x6c, 0x6c, 0x65, 0x6e, + 0x67, 0x65, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x28, 0x0a, 0x05, 0x70, 0x61, + 0x72, 0x74, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, 0x65, 0x72, 0x75, + 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x52, 0x05, 0x70, + 0x61, 0x72, 0x74, 0x73, 0x12, 0x10, 0x0a, 0x03, 0x61, 0x70, 0x70, 0x18, 0x04, 0x20, 0x01, 0x28, + 0x0c, 0x52, 0x03, 0x61, 0x70, 0x70, 0x12, 0x14, 0x0a, 0x05, 0x6e, 0x6f, 0x6e, 0x63, 0x65, 0x18, + 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x6e, 0x6f, 0x6e, 0x63, 0x65, 0x12, 0x25, 0x0a, 0x0e, + 0x6c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x18, 0x06, + 0x20, 0x01, 0x28, 0x08, 0x52, 0x0d, 0x6c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x43, 0x68, 0x61, 0x6e, + 0x6e, 0x65, 0x6c, 0x12, 0x27, 0x0a, 0x0f, 0x76, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x5f, 0x63, + 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0e, 0x76, 0x69, + 0x72, 0x74, 0x75, 0x61, 0x6c, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x22, 0xb8, 0x01, 0x0a, + 0x05, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x1d, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x49, + 0x44, 0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, + 0x10, 0x0a, 0x03, 0x61, 0x70, 0x70, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x61, 0x70, + 0x70, 0x12, 0x35, 0x0a, 0x0a, 0x61, 0x6c, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, + 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, + 0x65, 0x2e, 0x41, 0x6c, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0a, 0x61, 0x6c, + 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, + 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x19, 0x0a, 0x08, + 0x69, 0x73, 0x5f, 0x66, 0x69, 0x6e, 0x61, 0x6c, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, + 0x69, 0x73, 0x46, 0x69, 0x6e, 0x61, 0x6c, 0x22, 0x49, 0x0a, 0x0b, 0x54, 0x72, 0x61, 0x6e, 0x73, + 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x26, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, + 0x65, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x12, 0x12, + 0x0a, 0x04, 0x73, 0x69, 0x67, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x04, 0x73, 0x69, + 0x67, 0x73, 0x22, 0x74, 0x0a, 0x0b, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x53, 0x74, 0x61, 0x74, + 0x65, 0x12, 0x29, 0x0a, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x11, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x50, 0x61, + 0x72, 0x61, 0x6d, 0x73, 0x52, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x26, 0x0a, 0x05, + 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x70, 0x65, + 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x05, 0x73, + 0x74, 0x61, 0x74, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x69, 0x67, 0x73, 0x18, 0x03, 0x20, 0x03, + 0x28, 0x0c, 0x52, 0x04, 0x73, 0x69, 0x67, 0x73, 0x22, 0x54, 0x0a, 0x0d, 0x43, 0x68, 0x61, 0x6e, + 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x26, 0x0a, 0x05, 0x73, 0x74, 0x61, + 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, + 0x77, 0x69, 0x72, 0x65, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, + 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x5f, 0x69, 0x64, 0x78, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x49, 0x64, 0x78, 0x22, 0x23, + 0x0a, 0x07, 0x50, 0x69, 0x6e, 0x67, 0x4d, 0x73, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x72, 0x65, + 0x61, 0x74, 0x65, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x63, 0x72, 0x65, 0x61, + 0x74, 0x65, 0x64, 0x22, 0x23, 0x0a, 0x07, 0x50, 0x6f, 0x6e, 0x67, 0x4d, 0x73, 0x67, 0x12, 0x18, + 0x0a, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, + 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x22, 0x25, 0x0a, 0x0b, 0x53, 0x68, 0x75, 0x74, + 0x64, 0x6f, 0x77, 0x6e, 0x4d, 0x73, 0x67, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, + 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x22, + 0x2f, 0x0a, 0x0f, 0x41, 0x75, 0x74, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x4d, + 0x73, 0x67, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, + 0x22, 0xce, 0x01, 0x0a, 0x18, 0x4c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x43, 0x68, 0x61, 0x6e, 0x6e, + 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x12, 0x52, 0x0a, + 0x15, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x70, 0x72, + 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x70, + 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, + 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x52, 0x13, 0x62, 0x61, + 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, + 0x6c, 0x12, 0x34, 0x0a, 0x0b, 0x70, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, + 0x72, 0x65, 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x52, 0x0b, 0x70, 0x61, 0x72, 0x74, + 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x12, 0x28, 0x0a, 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, + 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, + 0x72, 0x65, 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x52, 0x05, 0x70, 0x65, 0x65, 0x72, + 0x73, 0x22, 0xb1, 0x01, 0x0a, 0x1b, 0x4c, 0x65, 0x64, 0x67, 0x65, 0x72, 0x43, 0x68, 0x61, 0x6e, + 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x4d, 0x73, + 0x67, 0x12, 0x5c, 0x0a, 0x19, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, + 0x6c, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x5f, 0x61, 0x63, 0x63, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, + 0x2e, 0x42, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, + 0x6f, 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x52, 0x16, 0x62, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, + 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x12, + 0x34, 0x0a, 0x0b, 0x70, 0x61, 0x72, 0x74, 0x69, 0x63, 0x69, 0x70, 0x61, 0x6e, 0x74, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, + 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x52, 0x0b, 0x70, 0x61, 0x72, 0x74, 0x69, 0x63, + 0x69, 0x70, 0x61, 0x6e, 0x74, 0x22, 0x92, 0x01, 0x0a, 0x15, 0x53, 0x75, 0x62, 0x43, 0x68, 0x61, + 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x12, + 0x52, 0x0a, 0x15, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, + 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, + 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x43, + 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x52, 0x13, 0x62, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, - 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x12, 0x30, 0x0a, 0x09, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x64, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, 0x65, 0x72, 0x75, - 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x52, 0x09, 0x72, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x22, 0x50, 0x0a, 0x15, 0x43, 0x68, 0x61, 0x6e, - 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x52, 0x65, 0x6a, 0x4d, 0x73, - 0x67, 0x12, 0x1f, 0x0a, 0x0b, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x5f, 0x69, 0x64, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, - 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x22, 0x65, 0x0a, 0x10, 0x43, 0x68, - 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4d, 0x73, 0x67, 0x12, 0x3f, - 0x0a, 0x0e, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, - 0x72, 0x65, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, - 0x52, 0x0d, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, - 0x10, 0x0a, 0x03, 0x73, 0x69, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x73, 0x69, - 0x67, 0x22, 0xd1, 0x01, 0x0a, 0x20, 0x56, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x43, 0x68, 0x61, - 0x6e, 0x6e, 0x65, 0x6c, 0x46, 0x75, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x50, 0x72, 0x6f, 0x70, 0x6f, - 0x73, 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x12, 0x49, 0x0a, 0x12, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, - 0x6c, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x43, - 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4d, 0x73, 0x67, 0x52, - 0x10, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4d, 0x73, - 0x67, 0x12, 0x30, 0x0a, 0x07, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x53, - 0x69, 0x67, 0x6e, 0x65, 0x64, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x07, 0x69, 0x6e, 0x69, 0x74, - 0x69, 0x61, 0x6c, 0x12, 0x30, 0x0a, 0x09, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x5f, 0x6d, 0x61, 0x70, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, - 0x72, 0x65, 0x2e, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x4d, 0x61, 0x70, 0x52, 0x08, 0x69, 0x6e, 0x64, - 0x65, 0x78, 0x4d, 0x61, 0x70, 0x22, 0x9e, 0x01, 0x0a, 0x23, 0x56, 0x69, 0x72, 0x74, 0x75, 0x61, - 0x6c, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x53, 0x65, 0x74, 0x74, 0x6c, 0x65, 0x6d, 0x65, - 0x6e, 0x74, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x12, 0x49, 0x0a, - 0x12, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, - 0x6d, 0x73, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x70, 0x65, 0x72, 0x75, - 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, - 0x61, 0x74, 0x65, 0x4d, 0x73, 0x67, 0x52, 0x10, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, - 0x70, 0x64, 0x61, 0x74, 0x65, 0x4d, 0x73, 0x67, 0x12, 0x2c, 0x0a, 0x05, 0x66, 0x69, 0x6e, 0x61, - 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, - 0x69, 0x72, 0x65, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, - 0x05, 0x66, 0x69, 0x6e, 0x61, 0x6c, 0x22, 0x60, 0x0a, 0x13, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, - 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x41, 0x63, 0x63, 0x4d, 0x73, 0x67, 0x12, 0x1d, 0x0a, - 0x0a, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x0c, 0x52, 0x09, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, - 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x07, 0x76, - 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x69, 0x67, 0x18, 0x03, 0x20, - 0x01, 0x28, 0x0c, 0x52, 0x03, 0x73, 0x69, 0x67, 0x22, 0x66, 0x0a, 0x13, 0x43, 0x68, 0x61, 0x6e, - 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x6a, 0x4d, 0x73, 0x67, 0x12, - 0x1d, 0x0a, 0x0a, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0c, 0x52, 0x09, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x49, 0x64, 0x12, 0x18, - 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, - 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, - 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, - 0x22, 0x5d, 0x0a, 0x0e, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x53, 0x79, 0x6e, 0x63, 0x4d, - 0x73, 0x67, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x68, 0x61, 0x73, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x0d, 0x52, 0x05, 0x70, 0x68, 0x61, 0x73, 0x65, 0x12, 0x35, 0x0a, 0x0a, 0x63, 0x75, 0x72, 0x72, - 0x65, 0x6e, 0x74, 0x5f, 0x74, 0x78, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x70, - 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, - 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x09, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x54, 0x78, 0x42, - 0x26, 0x5a, 0x24, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x2e, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, - 0x2f, 0x67, 0x6f, 0x2d, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x2f, 0x77, 0x69, 0x72, 0x65, 0x2f, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x73, 0x61, 0x6c, 0x12, 0x25, 0x0a, 0x06, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, + 0x49, 0x44, 0x52, 0x06, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x22, 0x78, 0x0a, 0x18, 0x53, 0x75, + 0x62, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, + 0x41, 0x63, 0x63, 0x4d, 0x73, 0x67, 0x12, 0x5c, 0x0a, 0x19, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x63, + 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x5f, + 0x61, 0x63, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x70, 0x65, 0x72, 0x75, + 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, + 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x52, 0x16, 0x62, 0x61, + 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, + 0x6c, 0x41, 0x63, 0x63, 0x22, 0xa6, 0x02, 0x0a, 0x19, 0x56, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, + 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, + 0x73, 0x67, 0x12, 0x52, 0x0a, 0x15, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, + 0x65, 0x6c, 0x5f, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x1e, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x42, 0x61, + 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, + 0x6c, 0x52, 0x13, 0x62, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, + 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x12, 0x2e, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x70, 0x6f, 0x73, + 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, + 0x77, 0x69, 0x72, 0x65, 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x52, 0x08, 0x70, 0x72, + 0x6f, 0x70, 0x6f, 0x73, 0x65, 0x72, 0x12, 0x28, 0x0a, 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, 0x18, + 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, + 0x65, 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x52, 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, + 0x12, 0x27, 0x0a, 0x07, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, + 0x0b, 0x32, 0x0d, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x49, 0x44, + 0x52, 0x07, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x32, 0x0a, 0x0a, 0x69, 0x6e, 0x64, + 0x65, 0x78, 0x5f, 0x6d, 0x61, 0x70, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x13, 0x2e, + 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x4d, + 0x61, 0x70, 0x52, 0x09, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x4d, 0x61, 0x70, 0x73, 0x22, 0xae, 0x01, + 0x0a, 0x1c, 0x56, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, + 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x4d, 0x73, 0x67, 0x12, 0x5c, + 0x0a, 0x19, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x70, + 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x5f, 0x61, 0x63, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x21, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x42, 0x61, + 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, + 0x6c, 0x41, 0x63, 0x63, 0x52, 0x16, 0x62, 0x61, 0x73, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, + 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x41, 0x63, 0x63, 0x12, 0x30, 0x0a, 0x09, + 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x12, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x41, 0x64, 0x64, 0x72, + 0x65, 0x73, 0x73, 0x52, 0x09, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x22, 0x50, + 0x0a, 0x15, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, + 0x6c, 0x52, 0x65, 0x6a, 0x4d, 0x73, 0x67, 0x12, 0x1f, 0x0a, 0x0b, 0x70, 0x72, 0x6f, 0x70, 0x6f, + 0x73, 0x61, 0x6c, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x70, 0x72, + 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, + 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, + 0x22, 0x65, 0x0a, 0x10, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, + 0x65, 0x4d, 0x73, 0x67, 0x12, 0x3f, 0x0a, 0x0e, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, + 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x70, + 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, + 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x0d, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, + 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x69, 0x67, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0c, 0x52, 0x03, 0x73, 0x69, 0x67, 0x22, 0xd1, 0x01, 0x0a, 0x20, 0x56, 0x69, 0x72, 0x74, + 0x75, 0x61, 0x6c, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x46, 0x75, 0x6e, 0x64, 0x69, 0x6e, + 0x67, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, 0x4d, 0x73, 0x67, 0x12, 0x49, 0x0a, 0x12, + 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x6d, + 0x73, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, + 0x77, 0x69, 0x72, 0x65, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, + 0x74, 0x65, 0x4d, 0x73, 0x67, 0x52, 0x10, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, + 0x64, 0x61, 0x74, 0x65, 0x4d, 0x73, 0x67, 0x12, 0x30, 0x0a, 0x07, 0x69, 0x6e, 0x69, 0x74, 0x69, + 0x61, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, + 0x77, 0x69, 0x72, 0x65, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x53, 0x74, 0x61, 0x74, 0x65, + 0x52, 0x07, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c, 0x12, 0x30, 0x0a, 0x09, 0x69, 0x6e, 0x64, + 0x65, 0x78, 0x5f, 0x6d, 0x61, 0x70, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x70, + 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x4d, 0x61, + 0x70, 0x52, 0x08, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x4d, 0x61, 0x70, 0x22, 0x9e, 0x01, 0x0a, 0x23, + 0x56, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6c, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x53, 0x65, + 0x74, 0x74, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x50, 0x72, 0x6f, 0x70, 0x6f, 0x73, 0x61, 0x6c, + 0x4d, 0x73, 0x67, 0x12, 0x49, 0x0a, 0x12, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x75, + 0x70, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x6d, 0x73, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x1b, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x43, 0x68, 0x61, 0x6e, + 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4d, 0x73, 0x67, 0x52, 0x10, 0x63, 0x68, + 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4d, 0x73, 0x67, 0x12, 0x2c, + 0x0a, 0x05, 0x66, 0x69, 0x6e, 0x61, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, + 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x65, 0x64, + 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x05, 0x66, 0x69, 0x6e, 0x61, 0x6c, 0x22, 0x6f, 0x0a, 0x13, + 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x41, 0x63, 0x63, + 0x4d, 0x73, 0x67, 0x12, 0x2c, 0x0a, 0x0a, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, 0x69, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, + 0x69, 0x72, 0x65, 0x2e, 0x49, 0x44, 0x52, 0x09, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x49, + 0x64, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x04, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x73, + 0x69, 0x67, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x73, 0x69, 0x67, 0x22, 0x75, 0x0a, + 0x13, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, + 0x6a, 0x4d, 0x73, 0x67, 0x12, 0x2c, 0x0a, 0x0a, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x5f, + 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, + 0x77, 0x69, 0x72, 0x65, 0x2e, 0x49, 0x44, 0x52, 0x09, 0x63, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, + 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x04, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x0a, 0x06, + 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, + 0x61, 0x73, 0x6f, 0x6e, 0x22, 0x5d, 0x0a, 0x0e, 0x43, 0x68, 0x61, 0x6e, 0x6e, 0x65, 0x6c, 0x53, + 0x79, 0x6e, 0x63, 0x4d, 0x73, 0x67, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x68, 0x61, 0x73, 0x65, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x70, 0x68, 0x61, 0x73, 0x65, 0x12, 0x35, 0x0a, 0x0a, + 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x74, 0x78, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x16, 0x2e, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x54, 0x72, 0x61, + 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x09, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, + 0x74, 0x54, 0x78, 0x42, 0x26, 0x5a, 0x24, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x2e, 0x6e, 0x65, 0x74, + 0x77, 0x6f, 0x72, 0x6b, 0x2f, 0x67, 0x6f, 0x2d, 0x70, 0x65, 0x72, 0x75, 0x6e, 0x2f, 0x77, 0x69, + 0x72, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var ( @@ -2579,100 +2697,110 @@ func file_wire_proto_rawDescGZIP() []byte { return file_wire_proto_rawDescData } -var file_wire_proto_msgTypes = make([]protoimpl.MessageInfo, 32) +var file_wire_proto_msgTypes = make([]protoimpl.MessageInfo, 34) var file_wire_proto_goTypes = []any{ (*Envelope)(nil), // 0: perunwire.Envelope (*Balance)(nil), // 1: perunwire.Balance (*Balances)(nil), // 2: perunwire.Balances (*AddressMapping)(nil), // 3: perunwire.AddressMapping (*Address)(nil), // 4: perunwire.Address - (*IndexMap)(nil), // 5: perunwire.IndexMap - (*SubAlloc)(nil), // 6: perunwire.SubAlloc - (*Allocation)(nil), // 7: perunwire.Allocation - (*BaseChannelProposal)(nil), // 8: perunwire.BaseChannelProposal - (*BaseChannelProposalAcc)(nil), // 9: perunwire.BaseChannelProposalAcc - (*Params)(nil), // 10: perunwire.Params - (*State)(nil), // 11: perunwire.State - (*Transaction)(nil), // 12: perunwire.Transaction - (*SignedState)(nil), // 13: perunwire.SignedState - (*ChannelUpdate)(nil), // 14: perunwire.ChannelUpdate - (*PingMsg)(nil), // 15: perunwire.PingMsg - (*PongMsg)(nil), // 16: perunwire.PongMsg - (*ShutdownMsg)(nil), // 17: perunwire.ShutdownMsg - (*AuthResponseMsg)(nil), // 18: perunwire.AuthResponseMsg - (*LedgerChannelProposalMsg)(nil), // 19: perunwire.LedgerChannelProposalMsg - (*LedgerChannelProposalAccMsg)(nil), // 20: perunwire.LedgerChannelProposalAccMsg - (*SubChannelProposalMsg)(nil), // 21: perunwire.SubChannelProposalMsg - (*SubChannelProposalAccMsg)(nil), // 22: perunwire.SubChannelProposalAccMsg - (*VirtualChannelProposalMsg)(nil), // 23: perunwire.VirtualChannelProposalMsg - (*VirtualChannelProposalAccMsg)(nil), // 24: perunwire.VirtualChannelProposalAccMsg - (*ChannelProposalRejMsg)(nil), // 25: perunwire.ChannelProposalRejMsg - (*ChannelUpdateMsg)(nil), // 26: perunwire.ChannelUpdateMsg - (*VirtualChannelFundingProposalMsg)(nil), // 27: perunwire.VirtualChannelFundingProposalMsg - (*VirtualChannelSettlementProposalMsg)(nil), // 28: perunwire.VirtualChannelSettlementProposalMsg - (*ChannelUpdateAccMsg)(nil), // 29: perunwire.ChannelUpdateAccMsg - (*ChannelUpdateRejMsg)(nil), // 30: perunwire.ChannelUpdateRejMsg - (*ChannelSyncMsg)(nil), // 31: perunwire.ChannelSyncMsg + (*IDMapping)(nil), // 5: perunwire.IDMapping + (*ID)(nil), // 6: perunwire.ID + (*IndexMap)(nil), // 7: perunwire.IndexMap + (*SubAlloc)(nil), // 8: perunwire.SubAlloc + (*Allocation)(nil), // 9: perunwire.Allocation + (*BaseChannelProposal)(nil), // 10: perunwire.BaseChannelProposal + (*BaseChannelProposalAcc)(nil), // 11: perunwire.BaseChannelProposalAcc + (*Params)(nil), // 12: perunwire.Params + (*State)(nil), // 13: perunwire.State + (*Transaction)(nil), // 14: perunwire.Transaction + (*SignedState)(nil), // 15: perunwire.SignedState + (*ChannelUpdate)(nil), // 16: perunwire.ChannelUpdate + (*PingMsg)(nil), // 17: perunwire.PingMsg + (*PongMsg)(nil), // 18: perunwire.PongMsg + (*ShutdownMsg)(nil), // 19: perunwire.ShutdownMsg + (*AuthResponseMsg)(nil), // 20: perunwire.AuthResponseMsg + (*LedgerChannelProposalMsg)(nil), // 21: perunwire.LedgerChannelProposalMsg + (*LedgerChannelProposalAccMsg)(nil), // 22: perunwire.LedgerChannelProposalAccMsg + (*SubChannelProposalMsg)(nil), // 23: perunwire.SubChannelProposalMsg + (*SubChannelProposalAccMsg)(nil), // 24: perunwire.SubChannelProposalAccMsg + (*VirtualChannelProposalMsg)(nil), // 25: perunwire.VirtualChannelProposalMsg + (*VirtualChannelProposalAccMsg)(nil), // 26: perunwire.VirtualChannelProposalAccMsg + (*ChannelProposalRejMsg)(nil), // 27: perunwire.ChannelProposalRejMsg + (*ChannelUpdateMsg)(nil), // 28: perunwire.ChannelUpdateMsg + (*VirtualChannelFundingProposalMsg)(nil), // 29: perunwire.VirtualChannelFundingProposalMsg + (*VirtualChannelSettlementProposalMsg)(nil), // 30: perunwire.VirtualChannelSettlementProposalMsg + (*ChannelUpdateAccMsg)(nil), // 31: perunwire.ChannelUpdateAccMsg + (*ChannelUpdateRejMsg)(nil), // 32: perunwire.ChannelUpdateRejMsg + (*ChannelSyncMsg)(nil), // 33: perunwire.ChannelSyncMsg } var file_wire_proto_depIdxs = []int32{ 4, // 0: perunwire.Envelope.sender:type_name -> perunwire.Address 4, // 1: perunwire.Envelope.recipient:type_name -> perunwire.Address - 15, // 2: perunwire.Envelope.ping_msg:type_name -> perunwire.PingMsg - 16, // 3: perunwire.Envelope.pong_msg:type_name -> perunwire.PongMsg - 17, // 4: perunwire.Envelope.shutdown_msg:type_name -> perunwire.ShutdownMsg - 18, // 5: perunwire.Envelope.auth_response_msg:type_name -> perunwire.AuthResponseMsg - 19, // 6: perunwire.Envelope.ledger_channel_proposal_msg:type_name -> perunwire.LedgerChannelProposalMsg - 20, // 7: perunwire.Envelope.ledger_channel_proposal_acc_msg:type_name -> perunwire.LedgerChannelProposalAccMsg - 21, // 8: perunwire.Envelope.sub_channel_proposal_msg:type_name -> perunwire.SubChannelProposalMsg - 22, // 9: perunwire.Envelope.sub_channel_proposal_acc_msg:type_name -> perunwire.SubChannelProposalAccMsg - 23, // 10: perunwire.Envelope.virtual_channel_proposal_msg:type_name -> perunwire.VirtualChannelProposalMsg - 24, // 11: perunwire.Envelope.virtual_channel_proposal_acc_msg:type_name -> perunwire.VirtualChannelProposalAccMsg - 25, // 12: perunwire.Envelope.channel_proposal_rej_msg:type_name -> perunwire.ChannelProposalRejMsg - 26, // 13: perunwire.Envelope.channel_update_msg:type_name -> perunwire.ChannelUpdateMsg - 27, // 14: perunwire.Envelope.virtual_channel_funding_proposal_msg:type_name -> perunwire.VirtualChannelFundingProposalMsg - 28, // 15: perunwire.Envelope.virtual_channel_settlement_proposal_msg:type_name -> perunwire.VirtualChannelSettlementProposalMsg - 29, // 16: perunwire.Envelope.channel_update_acc_msg:type_name -> perunwire.ChannelUpdateAccMsg - 30, // 17: perunwire.Envelope.channel_update_rej_msg:type_name -> perunwire.ChannelUpdateRejMsg - 31, // 18: perunwire.Envelope.channel_sync_msg:type_name -> perunwire.ChannelSyncMsg + 17, // 2: perunwire.Envelope.ping_msg:type_name -> perunwire.PingMsg + 18, // 3: perunwire.Envelope.pong_msg:type_name -> perunwire.PongMsg + 19, // 4: perunwire.Envelope.shutdown_msg:type_name -> perunwire.ShutdownMsg + 20, // 5: perunwire.Envelope.auth_response_msg:type_name -> perunwire.AuthResponseMsg + 21, // 6: perunwire.Envelope.ledger_channel_proposal_msg:type_name -> perunwire.LedgerChannelProposalMsg + 22, // 7: perunwire.Envelope.ledger_channel_proposal_acc_msg:type_name -> perunwire.LedgerChannelProposalAccMsg + 23, // 8: perunwire.Envelope.sub_channel_proposal_msg:type_name -> perunwire.SubChannelProposalMsg + 24, // 9: perunwire.Envelope.sub_channel_proposal_acc_msg:type_name -> perunwire.SubChannelProposalAccMsg + 25, // 10: perunwire.Envelope.virtual_channel_proposal_msg:type_name -> perunwire.VirtualChannelProposalMsg + 26, // 11: perunwire.Envelope.virtual_channel_proposal_acc_msg:type_name -> perunwire.VirtualChannelProposalAccMsg + 27, // 12: perunwire.Envelope.channel_proposal_rej_msg:type_name -> perunwire.ChannelProposalRejMsg + 28, // 13: perunwire.Envelope.channel_update_msg:type_name -> perunwire.ChannelUpdateMsg + 29, // 14: perunwire.Envelope.virtual_channel_funding_proposal_msg:type_name -> perunwire.VirtualChannelFundingProposalMsg + 30, // 15: perunwire.Envelope.virtual_channel_settlement_proposal_msg:type_name -> perunwire.VirtualChannelSettlementProposalMsg + 31, // 16: perunwire.Envelope.channel_update_acc_msg:type_name -> perunwire.ChannelUpdateAccMsg + 32, // 17: perunwire.Envelope.channel_update_rej_msg:type_name -> perunwire.ChannelUpdateRejMsg + 33, // 18: perunwire.Envelope.channel_sync_msg:type_name -> perunwire.ChannelSyncMsg 1, // 19: perunwire.Balances.balances:type_name -> perunwire.Balance 3, // 20: perunwire.Address.address_mapping:type_name -> perunwire.AddressMapping - 1, // 21: perunwire.SubAlloc.bals:type_name -> perunwire.Balance - 5, // 22: perunwire.SubAlloc.index_map:type_name -> perunwire.IndexMap - 2, // 23: perunwire.Allocation.balances:type_name -> perunwire.Balances - 6, // 24: perunwire.Allocation.locked:type_name -> perunwire.SubAlloc - 7, // 25: perunwire.BaseChannelProposal.init_bals:type_name -> perunwire.Allocation - 2, // 26: perunwire.BaseChannelProposal.funding_agreement:type_name -> perunwire.Balances - 4, // 27: perunwire.Params.parts:type_name -> perunwire.Address - 7, // 28: perunwire.State.allocation:type_name -> perunwire.Allocation - 11, // 29: perunwire.Transaction.state:type_name -> perunwire.State - 10, // 30: perunwire.SignedState.params:type_name -> perunwire.Params - 11, // 31: perunwire.SignedState.state:type_name -> perunwire.State - 11, // 32: perunwire.ChannelUpdate.state:type_name -> perunwire.State - 8, // 33: perunwire.LedgerChannelProposalMsg.base_channel_proposal:type_name -> perunwire.BaseChannelProposal - 4, // 34: perunwire.LedgerChannelProposalMsg.participant:type_name -> perunwire.Address - 4, // 35: perunwire.LedgerChannelProposalMsg.peers:type_name -> perunwire.Address - 9, // 36: perunwire.LedgerChannelProposalAccMsg.base_channel_proposal_acc:type_name -> perunwire.BaseChannelProposalAcc - 4, // 37: perunwire.LedgerChannelProposalAccMsg.participant:type_name -> perunwire.Address - 8, // 38: perunwire.SubChannelProposalMsg.base_channel_proposal:type_name -> perunwire.BaseChannelProposal - 9, // 39: perunwire.SubChannelProposalAccMsg.base_channel_proposal_acc:type_name -> perunwire.BaseChannelProposalAcc - 8, // 40: perunwire.VirtualChannelProposalMsg.base_channel_proposal:type_name -> perunwire.BaseChannelProposal - 4, // 41: perunwire.VirtualChannelProposalMsg.proposer:type_name -> perunwire.Address - 4, // 42: perunwire.VirtualChannelProposalMsg.peers:type_name -> perunwire.Address - 5, // 43: perunwire.VirtualChannelProposalMsg.index_maps:type_name -> perunwire.IndexMap - 9, // 44: perunwire.VirtualChannelProposalAccMsg.base_channel_proposal_acc:type_name -> perunwire.BaseChannelProposalAcc - 4, // 45: perunwire.VirtualChannelProposalAccMsg.responder:type_name -> perunwire.Address - 14, // 46: perunwire.ChannelUpdateMsg.channel_update:type_name -> perunwire.ChannelUpdate - 26, // 47: perunwire.VirtualChannelFundingProposalMsg.channel_update_msg:type_name -> perunwire.ChannelUpdateMsg - 13, // 48: perunwire.VirtualChannelFundingProposalMsg.initial:type_name -> perunwire.SignedState - 5, // 49: perunwire.VirtualChannelFundingProposalMsg.index_map:type_name -> perunwire.IndexMap - 26, // 50: perunwire.VirtualChannelSettlementProposalMsg.channel_update_msg:type_name -> perunwire.ChannelUpdateMsg - 13, // 51: perunwire.VirtualChannelSettlementProposalMsg.final:type_name -> perunwire.SignedState - 12, // 52: perunwire.ChannelSyncMsg.current_tx:type_name -> perunwire.Transaction - 53, // [53:53] is the sub-list for method output_type - 53, // [53:53] is the sub-list for method input_type - 53, // [53:53] is the sub-list for extension type_name - 53, // [53:53] is the sub-list for extension extendee - 0, // [0:53] is the sub-list for field type_name + 5, // 21: perunwire.ID.id_mapping:type_name -> perunwire.IDMapping + 6, // 22: perunwire.SubAlloc.id:type_name -> perunwire.ID + 1, // 23: perunwire.SubAlloc.bals:type_name -> perunwire.Balance + 7, // 24: perunwire.SubAlloc.index_map:type_name -> perunwire.IndexMap + 2, // 25: perunwire.Allocation.balances:type_name -> perunwire.Balances + 8, // 26: perunwire.Allocation.locked:type_name -> perunwire.SubAlloc + 9, // 27: perunwire.BaseChannelProposal.init_bals:type_name -> perunwire.Allocation + 2, // 28: perunwire.BaseChannelProposal.funding_agreement:type_name -> perunwire.Balances + 6, // 29: perunwire.Params.id:type_name -> perunwire.ID + 4, // 30: perunwire.Params.parts:type_name -> perunwire.Address + 6, // 31: perunwire.State.id:type_name -> perunwire.ID + 9, // 32: perunwire.State.allocation:type_name -> perunwire.Allocation + 13, // 33: perunwire.Transaction.state:type_name -> perunwire.State + 12, // 34: perunwire.SignedState.params:type_name -> perunwire.Params + 13, // 35: perunwire.SignedState.state:type_name -> perunwire.State + 13, // 36: perunwire.ChannelUpdate.state:type_name -> perunwire.State + 10, // 37: perunwire.LedgerChannelProposalMsg.base_channel_proposal:type_name -> perunwire.BaseChannelProposal + 4, // 38: perunwire.LedgerChannelProposalMsg.participant:type_name -> perunwire.Address + 4, // 39: perunwire.LedgerChannelProposalMsg.peers:type_name -> perunwire.Address + 11, // 40: perunwire.LedgerChannelProposalAccMsg.base_channel_proposal_acc:type_name -> perunwire.BaseChannelProposalAcc + 4, // 41: perunwire.LedgerChannelProposalAccMsg.participant:type_name -> perunwire.Address + 10, // 42: perunwire.SubChannelProposalMsg.base_channel_proposal:type_name -> perunwire.BaseChannelProposal + 6, // 43: perunwire.SubChannelProposalMsg.parent:type_name -> perunwire.ID + 11, // 44: perunwire.SubChannelProposalAccMsg.base_channel_proposal_acc:type_name -> perunwire.BaseChannelProposalAcc + 10, // 45: perunwire.VirtualChannelProposalMsg.base_channel_proposal:type_name -> perunwire.BaseChannelProposal + 4, // 46: perunwire.VirtualChannelProposalMsg.proposer:type_name -> perunwire.Address + 4, // 47: perunwire.VirtualChannelProposalMsg.peers:type_name -> perunwire.Address + 6, // 48: perunwire.VirtualChannelProposalMsg.parents:type_name -> perunwire.ID + 7, // 49: perunwire.VirtualChannelProposalMsg.index_maps:type_name -> perunwire.IndexMap + 11, // 50: perunwire.VirtualChannelProposalAccMsg.base_channel_proposal_acc:type_name -> perunwire.BaseChannelProposalAcc + 4, // 51: perunwire.VirtualChannelProposalAccMsg.responder:type_name -> perunwire.Address + 16, // 52: perunwire.ChannelUpdateMsg.channel_update:type_name -> perunwire.ChannelUpdate + 28, // 53: perunwire.VirtualChannelFundingProposalMsg.channel_update_msg:type_name -> perunwire.ChannelUpdateMsg + 15, // 54: perunwire.VirtualChannelFundingProposalMsg.initial:type_name -> perunwire.SignedState + 7, // 55: perunwire.VirtualChannelFundingProposalMsg.index_map:type_name -> perunwire.IndexMap + 28, // 56: perunwire.VirtualChannelSettlementProposalMsg.channel_update_msg:type_name -> perunwire.ChannelUpdateMsg + 15, // 57: perunwire.VirtualChannelSettlementProposalMsg.final:type_name -> perunwire.SignedState + 6, // 58: perunwire.ChannelUpdateAccMsg.channel_id:type_name -> perunwire.ID + 6, // 59: perunwire.ChannelUpdateRejMsg.channel_id:type_name -> perunwire.ID + 14, // 60: perunwire.ChannelSyncMsg.current_tx:type_name -> perunwire.Transaction + 61, // [61:61] is the sub-list for method output_type + 61, // [61:61] is the sub-list for method input_type + 61, // [61:61] is the sub-list for extension type_name + 61, // [61:61] is the sub-list for extension extendee + 0, // [0:61] is the sub-list for field type_name } func init() { file_wire_proto_init() } @@ -2742,7 +2870,7 @@ func file_wire_proto_init() { } } file_wire_proto_msgTypes[5].Exporter = func(v any, i int) any { - switch v := v.(*IndexMap); i { + switch v := v.(*IDMapping); i { case 0: return &v.state case 1: @@ -2754,7 +2882,7 @@ func file_wire_proto_init() { } } file_wire_proto_msgTypes[6].Exporter = func(v any, i int) any { - switch v := v.(*SubAlloc); i { + switch v := v.(*ID); i { case 0: return &v.state case 1: @@ -2766,7 +2894,7 @@ func file_wire_proto_init() { } } file_wire_proto_msgTypes[7].Exporter = func(v any, i int) any { - switch v := v.(*Allocation); i { + switch v := v.(*IndexMap); i { case 0: return &v.state case 1: @@ -2778,7 +2906,7 @@ func file_wire_proto_init() { } } file_wire_proto_msgTypes[8].Exporter = func(v any, i int) any { - switch v := v.(*BaseChannelProposal); i { + switch v := v.(*SubAlloc); i { case 0: return &v.state case 1: @@ -2790,7 +2918,7 @@ func file_wire_proto_init() { } } file_wire_proto_msgTypes[9].Exporter = func(v any, i int) any { - switch v := v.(*BaseChannelProposalAcc); i { + switch v := v.(*Allocation); i { case 0: return &v.state case 1: @@ -2802,7 +2930,7 @@ func file_wire_proto_init() { } } file_wire_proto_msgTypes[10].Exporter = func(v any, i int) any { - switch v := v.(*Params); i { + switch v := v.(*BaseChannelProposal); i { case 0: return &v.state case 1: @@ -2814,7 +2942,7 @@ func file_wire_proto_init() { } } file_wire_proto_msgTypes[11].Exporter = func(v any, i int) any { - switch v := v.(*State); i { + switch v := v.(*BaseChannelProposalAcc); i { case 0: return &v.state case 1: @@ -2826,7 +2954,7 @@ func file_wire_proto_init() { } } file_wire_proto_msgTypes[12].Exporter = func(v any, i int) any { - switch v := v.(*Transaction); i { + switch v := v.(*Params); i { case 0: return &v.state case 1: @@ -2838,7 +2966,7 @@ func file_wire_proto_init() { } } file_wire_proto_msgTypes[13].Exporter = func(v any, i int) any { - switch v := v.(*SignedState); i { + switch v := v.(*State); i { case 0: return &v.state case 1: @@ -2850,7 +2978,7 @@ func file_wire_proto_init() { } } file_wire_proto_msgTypes[14].Exporter = func(v any, i int) any { - switch v := v.(*ChannelUpdate); i { + switch v := v.(*Transaction); i { case 0: return &v.state case 1: @@ -2862,7 +2990,7 @@ func file_wire_proto_init() { } } file_wire_proto_msgTypes[15].Exporter = func(v any, i int) any { - switch v := v.(*PingMsg); i { + switch v := v.(*SignedState); i { case 0: return &v.state case 1: @@ -2874,7 +3002,7 @@ func file_wire_proto_init() { } } file_wire_proto_msgTypes[16].Exporter = func(v any, i int) any { - switch v := v.(*PongMsg); i { + switch v := v.(*ChannelUpdate); i { case 0: return &v.state case 1: @@ -2886,7 +3014,7 @@ func file_wire_proto_init() { } } file_wire_proto_msgTypes[17].Exporter = func(v any, i int) any { - switch v := v.(*ShutdownMsg); i { + switch v := v.(*PingMsg); i { case 0: return &v.state case 1: @@ -2898,7 +3026,7 @@ func file_wire_proto_init() { } } file_wire_proto_msgTypes[18].Exporter = func(v any, i int) any { - switch v := v.(*AuthResponseMsg); i { + switch v := v.(*PongMsg); i { case 0: return &v.state case 1: @@ -2910,7 +3038,7 @@ func file_wire_proto_init() { } } file_wire_proto_msgTypes[19].Exporter = func(v any, i int) any { - switch v := v.(*LedgerChannelProposalMsg); i { + switch v := v.(*ShutdownMsg); i { case 0: return &v.state case 1: @@ -2922,7 +3050,7 @@ func file_wire_proto_init() { } } file_wire_proto_msgTypes[20].Exporter = func(v any, i int) any { - switch v := v.(*LedgerChannelProposalAccMsg); i { + switch v := v.(*AuthResponseMsg); i { case 0: return &v.state case 1: @@ -2934,7 +3062,7 @@ func file_wire_proto_init() { } } file_wire_proto_msgTypes[21].Exporter = func(v any, i int) any { - switch v := v.(*SubChannelProposalMsg); i { + switch v := v.(*LedgerChannelProposalMsg); i { case 0: return &v.state case 1: @@ -2946,7 +3074,7 @@ func file_wire_proto_init() { } } file_wire_proto_msgTypes[22].Exporter = func(v any, i int) any { - switch v := v.(*SubChannelProposalAccMsg); i { + switch v := v.(*LedgerChannelProposalAccMsg); i { case 0: return &v.state case 1: @@ -2958,7 +3086,7 @@ func file_wire_proto_init() { } } file_wire_proto_msgTypes[23].Exporter = func(v any, i int) any { - switch v := v.(*VirtualChannelProposalMsg); i { + switch v := v.(*SubChannelProposalMsg); i { case 0: return &v.state case 1: @@ -2970,7 +3098,7 @@ func file_wire_proto_init() { } } file_wire_proto_msgTypes[24].Exporter = func(v any, i int) any { - switch v := v.(*VirtualChannelProposalAccMsg); i { + switch v := v.(*SubChannelProposalAccMsg); i { case 0: return &v.state case 1: @@ -2982,7 +3110,7 @@ func file_wire_proto_init() { } } file_wire_proto_msgTypes[25].Exporter = func(v any, i int) any { - switch v := v.(*ChannelProposalRejMsg); i { + switch v := v.(*VirtualChannelProposalMsg); i { case 0: return &v.state case 1: @@ -2994,7 +3122,7 @@ func file_wire_proto_init() { } } file_wire_proto_msgTypes[26].Exporter = func(v any, i int) any { - switch v := v.(*ChannelUpdateMsg); i { + switch v := v.(*VirtualChannelProposalAccMsg); i { case 0: return &v.state case 1: @@ -3006,7 +3134,7 @@ func file_wire_proto_init() { } } file_wire_proto_msgTypes[27].Exporter = func(v any, i int) any { - switch v := v.(*VirtualChannelFundingProposalMsg); i { + switch v := v.(*ChannelProposalRejMsg); i { case 0: return &v.state case 1: @@ -3018,7 +3146,7 @@ func file_wire_proto_init() { } } file_wire_proto_msgTypes[28].Exporter = func(v any, i int) any { - switch v := v.(*VirtualChannelSettlementProposalMsg); i { + switch v := v.(*ChannelUpdateMsg); i { case 0: return &v.state case 1: @@ -3030,7 +3158,7 @@ func file_wire_proto_init() { } } file_wire_proto_msgTypes[29].Exporter = func(v any, i int) any { - switch v := v.(*ChannelUpdateAccMsg); i { + switch v := v.(*VirtualChannelFundingProposalMsg); i { case 0: return &v.state case 1: @@ -3042,7 +3170,7 @@ func file_wire_proto_init() { } } file_wire_proto_msgTypes[30].Exporter = func(v any, i int) any { - switch v := v.(*ChannelUpdateRejMsg); i { + switch v := v.(*VirtualChannelSettlementProposalMsg); i { case 0: return &v.state case 1: @@ -3054,6 +3182,30 @@ func file_wire_proto_init() { } } file_wire_proto_msgTypes[31].Exporter = func(v any, i int) any { + switch v := v.(*ChannelUpdateAccMsg); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_wire_proto_msgTypes[32].Exporter = func(v any, i int) any { + switch v := v.(*ChannelUpdateRejMsg); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_wire_proto_msgTypes[33].Exporter = func(v any, i int) any { switch v := v.(*ChannelSyncMsg); i { case 0: return &v.state @@ -3091,7 +3243,7 @@ func file_wire_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_wire_proto_rawDesc, NumEnums: 0, - NumMessages: 32, + NumMessages: 34, NumExtensions: 0, NumServices: 0, }, diff --git a/wire/protobuf/wire.proto b/wire/protobuf/wire.proto index f3f2972d0..32212f781 100644 --- a/wire/protobuf/wire.proto +++ b/wire/protobuf/wire.proto @@ -72,6 +72,17 @@ message Address { repeated AddressMapping address_mapping = 1; } +// AddressMapping represents an element of a address mapping. +message IDMapping { + bytes key = 1; + bytes id = 2; +} + +// Address represents the map of addresses for each participant in the channel. +message ID { + repeated IDMapping id_mapping = 1; +} + // IndexMap represents the mapping of a participant indices in a sub allocation // or a virtual channel funding proposal to the corresponding indices in the // parent channel. @@ -81,7 +92,7 @@ message IndexMap { // SubAlloc represts a sub allocation. message SubAlloc { - bytes id = 1; + ID id = 1; Balance bals = 2; IndexMap index_map = 3; } @@ -113,7 +124,7 @@ message BaseChannelProposalAcc { // Params represents channel.Params. message Params { - bytes id = 1; + ID id = 1; uint64 challenge_duration = 2; repeated Address parts = 3; bytes app = 4; @@ -124,7 +135,7 @@ message Params { // State represents channel.State. message State { - bytes id = 1; + ID id = 1; uint64 version = 2; bytes app = 3; Allocation allocation = 4; @@ -188,7 +199,7 @@ message LedgerChannelProposalAccMsg { // SubChannelProposalMsg represents client.SubChannelProposalMsg. message SubChannelProposalMsg { BaseChannelProposal base_channel_proposal = 1; - bytes parent = 2; + ID parent = 2; } // SubChannelProposalAccMsg represents client.SubChannelProposalAccMsg. @@ -201,7 +212,7 @@ message VirtualChannelProposalMsg { BaseChannelProposal base_channel_proposal = 1; Address proposer = 2; repeated Address peers = 3; - repeated bytes parents = 4; + repeated ID parents = 4; repeated IndexMap index_maps = 5; } @@ -241,14 +252,14 @@ message VirtualChannelSettlementProposalMsg { // ChannelUpdateAccMsg represents client.ChannelUpdateAccMsg. message ChannelUpdateAccMsg { - bytes channel_id = 1; + ID channel_id = 1; uint64 version = 2; bytes sig = 3; } // ChannelUpdateRejMsg represents client.ChannelUpdateRejMsg. message ChannelUpdateRejMsg { - bytes channel_id = 1; + ID channel_id = 1; uint64 version = 2; string reason = 3; } From 13eeddfd73bba0ab18236c79cdea4945b1339e0e Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Thu, 5 Sep 2024 12:16:33 +0200 Subject: [PATCH 05/36] fix(channel/backend): Revert change in verify. fix(wallet/wallet, wallet/account): Revert changed definition. feat(client): Add wallet map to client for each backend. Signed-off-by: Sophia Koehler --- backend/sim/channel/backend.go | 2 +- backend/sim/channel/channel_internal_test.go | 2 +- backend/sim/wallet/account.go | 4 +- backend/sim/wallet/address.go | 2 +- backend/sim/wallet/wallet.go | 8 +- backend/sim/wallet/wallet_internal_test.go | 2 +- backend/sim/wallet/wallet_test.go | 6 +- backend/sim/wire/account.go | 6 +- channel/actionmachine.go | 2 +- channel/adjudicator.go | 22 ++-- channel/allocation.go | 26 ++-- channel/allocation_test.go | 24 ++-- channel/backend.go | 32 ++--- channel/errors.go | 15 +-- channel/errors_internal_test.go | 9 +- channel/machine.go | 53 ++++---- channel/machine_test.go | 9 +- channel/mock_app.go | 5 +- channel/mock_app_internal_test.go | 3 +- channel/multi/subscription.go | 3 +- channel/params.go | 28 ++--- .../persistence/keyvalue/persistedstate.go | 7 +- channel/persistence/keyvalue/persister.go | 11 +- channel/persistence/keyvalue/restorer.go | 16 +-- channel/persistence/nonpersister.go | 13 +- channel/persistence/persistence.go | 19 +-- channel/persistence/statemachine_test.go | 8 +- channel/persistence/test/channel.go | 18 +-- channel/persistence/test/peerchans.go | 21 ++-- .../test/peerchans_internal_test.go | 5 +- channel/persistence/test/persistrestorer.go | 15 +-- .../persistence/test/persistrestorertest.go | 9 +- channel/state.go | 5 +- channel/statemachine.go | 15 +-- channel/test/backend.go | 8 +- channel/test/randomizer.go | 56 +++++---- channel/test/randomopts.go | 44 +++---- channel/transaction.go | 2 +- client/adjudicate.go | 7 +- client/appchannel_test.go | 4 +- client/channel.go | 36 +++--- client/channelconn.go | 11 +- client/chanregistry.go | 9 +- client/client.go | 14 +-- client/client_role_test.go | 16 +-- client/client_test.go | 15 +-- client/clientconn.go | 7 +- client/payment_test.go | 4 +- client/proposal.go | 52 ++++---- client/proposal_internal_test.go | 5 +- client/proposalmsgs.go | 36 +++--- client/restore.go | 7 +- client/restore_internal_test.go | 12 +- client/serialize.go | 5 +- client/subchannel.go | 13 +- client/subchannel_test.go | 7 +- client/sync.go | 19 +-- client/syncmsgs.go | 3 +- client/test/backend.go | 8 +- client/test/channel.go | 4 +- client/test/fund.go | 7 +- client/test/handler.go | 2 +- client/test/multiledger.go | 28 ++--- client/test/multiledger_dispute.go | 5 +- client/test/multiledger_happy.go | 5 +- client/test/persistence.go | 11 +- client/test/randomproposal.go | 2 +- client/test/role.go | 67 ++++++---- client/test/subchannel_dispute.go | 3 +- client/test/virtualchannel.go | 14 ++- client/update.go | 4 +- client/updateinterception.go | 7 +- client/updatemsgs.go | 16 +-- client/virtual_channel.go | 36 +++--- client/virtual_channel_settlement.go | 20 +-- wallet/account.go | 2 +- wallet/address.go | 102 ++++++++-------- wallet/address_test.go | 22 +--- wallet/backend.go | 23 ++-- wallet/sig.go | 2 +- wallet/test/randomizer.go | 40 +++--- wallet/test/wallet.go | 114 +++++++++--------- wallet/test/walletbench.go | 2 +- wallet/wallet.go | 6 +- watcher/internal/mocks/RegisterSubscriber.go | 10 +- watcher/local/registry.go | 7 +- watcher/local/watcher.go | 9 +- watcher/local/watcher_test.go | 3 +- watcher/watcher.go | 5 +- wire/account.go | 12 +- wire/address.go | 25 ++-- wire/bus.go | 4 +- wire/encode.go | 5 +- wire/hybridbus.go | 3 +- wire/hybridbus_test.go | 5 +- wire/localbus.go | 5 +- wire/localbus_test.go | 3 +- wire/net/bus.go | 11 +- wire/net/bus_test.go | 5 +- wire/net/dialer.go | 3 +- wire/net/endpoint.go | 7 +- wire/net/endpoint_internal_test.go | 5 +- wire/net/endpoint_registry.go | 45 +++---- wire/net/endpoint_registry_external_test.go | 33 ++--- wire/net/endpoint_registry_internal_test.go | 51 ++++---- wire/net/exchange_addr.go | 26 ++-- wire/net/exchange_addr_internal_test.go | 12 +- wire/net/simple/account.go | 7 +- wire/net/simple/address.go | 5 +- wire/net/simple/dialer.go | 5 +- wire/net/simple/dialer_internal_test.go | 7 +- wire/net/simple/simple_exchange_addr_test.go | 12 +- wire/net/test/connhub.go | 3 +- wire/net/test/connhub_internal_test.go | 3 +- wire/net/test/dialer.go | 3 +- wire/net/test/listenermap.go | 11 +- wire/protobuf/proposalmsgs.go | 46 +++---- wire/protobuf/serializer.go | 3 +- wire/test/bustest.go | 17 +-- wire/test/msgstest.go | 2 +- wire/test/randomizer.go | 18 ++- 121 files changed, 962 insertions(+), 843 deletions(-) diff --git a/backend/sim/channel/backend.go b/backend/sim/channel/backend.go index f00289008..0f5397468 100644 --- a/backend/sim/channel/backend.go +++ b/backend/sim/channel/backend.go @@ -70,7 +70,7 @@ func (b *backend) Verify(addr wallet.Address, state *channel.State, sig []byte) if err := state.Encode(buff); err != nil { return false, errors.WithMessage(err, "pack state") } - return wallet.VerifySignature(buff.Bytes(), sig, map[int]wallet.Address{addr.BackendID(): addr}) + return wallet.VerifySignature(buff.Bytes(), sig, addr) } // NewAsset returns a variable of type Asset, which can be used diff --git a/backend/sim/channel/channel_internal_test.go b/backend/sim/channel/channel_internal_test.go index 59a8af3b0..261500ed4 100644 --- a/backend/sim/channel/channel_internal_test.go +++ b/backend/sim/channel/channel_internal_test.go @@ -41,6 +41,6 @@ func newChannelSetup(t *testing.T) *chtest.Setup { State: state, State2: state2, Account: wtest.NewRandomAccount(rng), - RandomAddress: func() map[int]wallet.Address { return wtest.NewRandomAddresses(rng) }, + RandomAddress: func() map[wallet.BackendID]wallet.Address { return wtest.NewRandomAddresses(rng) }, } } diff --git a/backend/sim/wallet/account.go b/backend/sim/wallet/account.go index ef510e187..0eb565813 100644 --- a/backend/sim/wallet/account.go +++ b/backend/sim/wallet/account.go @@ -56,8 +56,8 @@ func NewRandomAccount(rng io.Reader) *Account { } // Address returns the address of this account. -func (a *Account) Address() map[int]wallet.Address { - return map[int]wallet.Address{0: (*Address)(&a.privKey.PublicKey)} +func (a *Account) Address() wallet.Address { + return (*Address)(&a.privKey.PublicKey) } // SignData is used to sign data with this account. If the account is locked, diff --git a/backend/sim/wallet/address.go b/backend/sim/wallet/address.go index 0ca984876..91b7dcf12 100644 --- a/backend/sim/wallet/address.go +++ b/backend/sim/wallet/address.go @@ -28,7 +28,7 @@ import ( type Address ecdsa.PublicKey // BackendID returns the backend id of the address. -func (a Address) BackendID() int { +func (a Address) BackendID() wallet.BackendID { return 0 } diff --git a/backend/sim/wallet/wallet.go b/backend/sim/wallet/wallet.go index 4b17d83b5..e34f42fa4 100644 --- a/backend/sim/wallet/wallet.go +++ b/backend/sim/wallet/wallet.go @@ -61,7 +61,7 @@ type Wallet struct { // Unlock retrieves the account belonging to the supplied address, and unlocks // it. If the address does not have a corresponding account in the wallet, // returns an error. -func (w *Wallet) Unlock(a map[int]wallet.Address) (wallet.Account, error) { +func (w *Wallet) Unlock(a wallet.Address) (wallet.Account, error) { w.accMutex.RLock() defer w.accMutex.RUnlock() key := wallet.Key(a) @@ -87,7 +87,7 @@ func (w *Wallet) LockAll() { // IncrementUsage increases an account's usage count, which is used for // resource management. Panics if the wallet does not have an account that // corresponds to the supplied address. -func (w *Wallet) IncrementUsage(a map[int]wallet.Address) { +func (w *Wallet) IncrementUsage(a wallet.Address) { w.accMutex.RLock() defer w.accMutex.RUnlock() key := wallet.Key(a) @@ -103,7 +103,7 @@ func (w *Wallet) IncrementUsage(a map[int]wallet.Address) { // locks and deletes the account from the wallet. Panics if the call is not // matched to another preceding IncrementUsage call or if the supplied address // does not correspond to any of the wallet's accounts. -func (w *Wallet) DecrementUsage(a map[int]wallet.Address) { +func (w *Wallet) DecrementUsage(a wallet.Address) { w.accMutex.Lock() defer w.accMutex.Unlock() key := wallet.Key(a) @@ -126,7 +126,7 @@ func (w *Wallet) DecrementUsage(a map[int]wallet.Address) { // UsageCount retrieves an account's usage count (controlled via IncrementUsage // and DecrementUsage). Panics if the supplied address does not correspond to // any of the wallet's accounts. -func (w *Wallet) UsageCount(a map[int]wallet.Address) int { +func (w *Wallet) UsageCount(a wallet.Address) int { w.accMutex.RLock() defer w.accMutex.RUnlock() key := wallet.Key(a) diff --git a/backend/sim/wallet/wallet_internal_test.go b/backend/sim/wallet/wallet_internal_test.go index 4ac7e8f77..b6f6a4d7f 100644 --- a/backend/sim/wallet/wallet_internal_test.go +++ b/backend/sim/wallet/wallet_internal_test.go @@ -98,7 +98,7 @@ func newWalletSetup(rng *rand.Rand) *test.Setup { panic(err) } - addressNotInWallet := NewRandomAccount(rng).Address()[0] + addressNotInWallet := NewRandomAccount(rng).Address() addrMarshalled, err := addressNotInWallet.MarshalBinary() if err != nil { panic(err) diff --git a/backend/sim/wallet/wallet_test.go b/backend/sim/wallet/wallet_test.go index 2a9ee1dbd..1f1989b00 100644 --- a/backend/sim/wallet/wallet_test.go +++ b/backend/sim/wallet/wallet_test.go @@ -75,7 +75,7 @@ func TestWallet_Unlock(t *testing.T) { }) t.Run("unknown unlock", func(t *testing.T) { - acc, err := w.Unlock(wallet.NewRandomAddresses(rng)) + acc, err := w.Unlock(wallet.NewRandomAddress(rng)) assert.Error(t, err) assert.Nil(t, acc) }) @@ -123,7 +123,7 @@ func TestWallet_UsageCounting(t *testing.T) { }) t.Run("invalid address", func(t *testing.T) { - assert.Panics(t, func() { w.IncrementUsage(wallet.NewRandomAddresses(rng)) }) - assert.Panics(t, func() { w.DecrementUsage(wallet.NewRandomAddresses(rng)) }) + assert.Panics(t, func() { w.IncrementUsage(wallet.NewRandomAddress(rng)) }) + assert.Panics(t, func() { w.DecrementUsage(wallet.NewRandomAddress(rng)) }) }) } diff --git a/backend/sim/wire/account.go b/backend/sim/wire/account.go index 4f8e1704d..191cbcd17 100644 --- a/backend/sim/wire/account.go +++ b/backend/sim/wire/account.go @@ -22,11 +22,11 @@ import ( // Account is a wire account. type Account struct { - addr map[int]wire.Address + addr wire.Address } // Address returns the account's address. -func (acc *Account) Address() map[int]wire.Address { +func (acc *Account) Address() wire.Address { return acc.addr } @@ -38,6 +38,6 @@ func (acc *Account) Sign(msg []byte) ([]byte, error) { // NewRandomAccount generates a new random account. func NewRandomAccount(rng *rand.Rand) *Account { return &Account{ - addr: map[int]wire.Address{0: NewRandomAddress(rng)}, + addr: NewRandomAddress(rng), } } diff --git a/channel/actionmachine.go b/channel/actionmachine.go index 6507e5ee5..ddc07c764 100644 --- a/channel/actionmachine.go +++ b/channel/actionmachine.go @@ -33,7 +33,7 @@ type ActionMachine struct { } // NewActionMachine creates a new ActionMachine. -func NewActionMachine(acc wallet.Account, params Params) (*ActionMachine, error) { +func NewActionMachine(acc map[wallet.BackendID]wallet.Account, params Params) (*ActionMachine, error) { app, ok := params.App.(ActionApp) if !ok { return nil, errors.New("app must be ActionApp") diff --git a/channel/adjudicator.go b/channel/adjudicator.go index 70c1a8f42..2b3910186 100644 --- a/channel/adjudicator.go +++ b/channel/adjudicator.go @@ -98,7 +98,7 @@ type ( // subscription should be closed by calling Close on the subscription after // the channel is closed. EventSubscriber interface { - Subscribe(context.Context, map[int]ID) (AdjudicatorSubscription, error) + Subscribe(context.Context, map[wallet.BackendID]ID) (AdjudicatorSubscription, error) } // An AdjudicatorReq collects all necessary information to make calls to the @@ -110,7 +110,7 @@ type ( // protocol, possibly saving unnecessary double sending of transactions. AdjudicatorReq struct { Params *Params - Acc wallet.Account + Acc map[wallet.BackendID]wallet.Account Tx Transaction Idx Index // Always the own index Secondary bool // Optimized secondary call protocol @@ -158,7 +158,7 @@ type ( // cause, currently either a Registered or Progressed event. // The type of the event should be checked with a type switch. AdjudicatorEvent interface { - ID() map[int]ID + ID() map[wallet.BackendID]ID Timeout() Timeout Version() uint64 } @@ -166,9 +166,9 @@ type ( // An AdjudicatorEventBase implements the AdjudicatorEvent interface. It can // be embedded to implement an AdjudicatorEvent. AdjudicatorEventBase struct { - IDV map[int]ID // Channel ID - TimeoutV Timeout // Current phase timeout - VersionV uint64 // Registered version + IDV map[wallet.BackendID]ID // Channel ID + TimeoutV Timeout // Current phase timeout + VersionV uint64 // Registered version } // ProgressedEvent is the abstract event that signals an on-chain progression. @@ -213,7 +213,7 @@ func NewProgressReq(ar AdjudicatorReq, newState *State, sig wallet.Sig) *Progres } // NewAdjudicatorEventBase creates a new AdjudicatorEventBase object. -func NewAdjudicatorEventBase(c map[int]ID, t Timeout, v uint64) *AdjudicatorEventBase { +func NewAdjudicatorEventBase(c map[wallet.BackendID]ID, t Timeout, v uint64) *AdjudicatorEventBase { return &AdjudicatorEventBase{ IDV: c, TimeoutV: t, @@ -222,7 +222,7 @@ func NewAdjudicatorEventBase(c map[int]ID, t Timeout, v uint64) *AdjudicatorEven } // ID returns the channel ID. -func (b AdjudicatorEventBase) ID() map[int]ID { return b.IDV } +func (b AdjudicatorEventBase) ID() map[wallet.BackendID]ID { return b.IDV } // Timeout returns the phase timeout. func (b AdjudicatorEventBase) Timeout() Timeout { return b.TimeoutV } @@ -231,7 +231,7 @@ func (b AdjudicatorEventBase) Timeout() Timeout { return b.TimeoutV } func (b AdjudicatorEventBase) Version() uint64 { return b.VersionV } // NewRegisteredEvent creates a new RegisteredEvent. -func NewRegisteredEvent(id map[int]ID, timeout Timeout, version uint64, state *State, sigs []wallet.Sig) *RegisteredEvent { +func NewRegisteredEvent(id map[wallet.BackendID]ID, timeout Timeout, version uint64, state *State, sigs []wallet.Sig) *RegisteredEvent { return &RegisteredEvent{ AdjudicatorEventBase: AdjudicatorEventBase{ IDV: id, @@ -244,7 +244,7 @@ func NewRegisteredEvent(id map[int]ID, timeout Timeout, version uint64, state *S } // NewProgressedEvent creates a new ProgressedEvent. -func NewProgressedEvent(id map[int]ID, timeout Timeout, state *State, idx Index) *ProgressedEvent { +func NewProgressedEvent(id map[wallet.BackendID]ID, timeout Timeout, state *State, idx Index) *ProgressedEvent { return &ProgressedEvent{ AdjudicatorEventBase: AdjudicatorEventBase{ IDV: id, @@ -257,7 +257,7 @@ func NewProgressedEvent(id map[int]ID, timeout Timeout, state *State, idx Index) } // NewConcludedEvent creates a new ConcludedEvent. -func NewConcludedEvent(id map[int]ID, timeout Timeout, version uint64) *ConcludedEvent { +func NewConcludedEvent(id map[wallet.BackendID]ID, timeout Timeout, version uint64) *ConcludedEvent { return &ConcludedEvent{ AdjudicatorEventBase: AdjudicatorEventBase{ IDV: id, diff --git a/channel/allocation.go b/channel/allocation.go index 48e6b3a91..96067ec8b 100644 --- a/channel/allocation.go +++ b/channel/allocation.go @@ -19,6 +19,7 @@ import ( "io" "log" "math/big" + "perun.network/go-perun/wallet" "perun.network/go-perun/wire/perunio" perunbig "polycry.pt/poly-go/math/big" @@ -63,7 +64,7 @@ type ( // Locked holds the locked allocations to sub-app-channels. Allocation struct { // Backends is the indexes to which backend the assets belong to - Backends []int + Backends []wallet.BackendID // Assets are the asset types held in this channel Assets []Asset // Balances is the allocation of assets to the Params.Parts @@ -80,7 +81,7 @@ type ( // The size of the balances slice must be of the same size as the assets slice // of the channel Params. SubAlloc struct { - ID map[int]ID + ID map[wallet.BackendID]ID Bals []Bal IndexMap []Index // Maps participant indices of the sub-channel to participant indices of the parent channel. } @@ -111,7 +112,7 @@ var ( ) // NewAllocation returns a new allocation for the given number of participants and assets. -func NewAllocation(numParts int, backends []int, assets ...Asset) *Allocation { +func NewAllocation(numParts int, backends []wallet.BackendID, assets ...Asset) *Allocation { return &Allocation{ Assets: assets, Backends: backends, @@ -189,7 +190,7 @@ func (a *Allocation) NumParts() int { // If it is nil, it returns nil. func (a Allocation) Clone() (clone Allocation) { if a.Backends != nil { - clone.Backends = make([]int, len(a.Backends)) + clone.Backends = make([]wallet.BackendID, len(a.Backends)) for i, bID := range a.Backends { clone.Backends[i] = bID } @@ -329,8 +330,11 @@ func (a Allocation) Encode(w io.Writer) error { return err } // encode assets - for i, a := range a.Assets { - if err := perunio.Encode(w, a); err != nil { + for i, asset := range a.Assets { + if err := perunio.Encode(w, uint32(a.Backends[i])); err != nil { + return errors.WithMessagef(err, "encoding asset %d", i) + } + if err := perunio.Encode(w, asset); err != nil { return errors.WithMessagef(err, "encoding asset %d", i) } } @@ -361,12 +365,14 @@ func (a *Allocation) Decode(r io.Reader) error { } // decode assets a.Assets = make([]Asset, numAssets) - a.Backends = make([]int, numAssets) + a.Backends = make([]wallet.BackendID, numAssets) for i := range a.Assets { // decode backend index - if err := perunio.Decode(r); err != nil { + var id uint32 + if err := perunio.Decode(r, &id); err != nil { return errors.WithMessagef(err, "decoding backend index for asset %d", i) } + a.Backends[i] = wallet.BackendID(id) asset := NewAsset(a.Backends[i]) if err := perunio.Decode(r, asset); err != nil { return errors.WithMessagef(err, "decoding asset %d", i) @@ -547,7 +553,7 @@ func (b Balances) Sum() []Bal { } // NewSubAlloc creates a new sub-allocation. -func NewSubAlloc(id map[int]ID, bals []Bal, indexMap []Index) *SubAlloc { +func NewSubAlloc(id map[wallet.BackendID]ID, bals []Bal, indexMap []Index) *SubAlloc { if indexMap == nil { indexMap = []Index{} } @@ -556,7 +562,7 @@ func NewSubAlloc(id map[int]ID, bals []Bal, indexMap []Index) *SubAlloc { // SubAlloc tries to return the sub-allocation for the given subchannel. // The second return value indicates success. -func (a Allocation) SubAlloc(subchannel map[int]ID) (subAlloc SubAlloc, ok bool) { +func (a Allocation) SubAlloc(subchannel map[wallet.BackendID]ID) (subAlloc SubAlloc, ok bool) { for _, subAlloc = range a.Locked { if EqualIDs(subAlloc.ID, subchannel) { ok = true diff --git a/channel/allocation_test.go b/channel/allocation_test.go index dcafa7ac7..85dfc46b5 100644 --- a/channel/allocation_test.go +++ b/channel/allocation_test.go @@ -17,6 +17,7 @@ package channel_test import ( "math/big" "math/rand" + "perun.network/go-perun/wallet" "testing" "github.com/stretchr/testify/assert" @@ -270,12 +271,15 @@ func TestAllocationValidLimits(t *testing.T) { for ti, x := range inputs { allocation := &channel.Allocation{ Assets: make([]channel.Asset, x.numAssets), - Backends: make([]int, x.numAssets), + Backends: make([]wallet.BackendID, x.numAssets), Balances: make(channel.Balances, x.numAssets), Locked: make([]channel.SubAlloc, x.numSuballocations), } allocation.Assets = test.NewRandomAssets(rng, test.WithNumAssets(x.numAssets)) + for i, _ := range allocation.Assets { + allocation.Backends[i] = 0 + } for i := range allocation.Balances { for j := range allocation.Balances[i] { @@ -286,12 +290,12 @@ func TestAllocationValidLimits(t *testing.T) { for i := range allocation.Locked { allocation.Locked[i] = *channel.NewSubAlloc( - map[int]channel.ID{0: {byte(i), byte(i >> 8), byte(i >> 16), byte(i >> 24)}}, + map[wallet.BackendID]channel.ID{0: {byte(i), byte(i >> 8), byte(i >> 16), byte(i >> 24)}}, make([]channel.Bal, x.numAssets), nil, ) allocation.Locked[i] = *channel.NewSubAlloc( - map[int]channel.ID{0: {byte(i), byte(i >> 8), byte(i >> 16), byte(i >> 24)}}, + map[wallet.BackendID]channel.ID{0: {byte(i), byte(i >> 8), byte(i >> 16), byte(i >> 24)}}, make([]channel.Bal, x.numAssets), nil, ) @@ -382,7 +386,7 @@ func TestAllocation_Sum(t *testing.T) { { "single asset/one participants/one locked", - *test.NewRandomAllocation(rng, test.WithNumAssets(1), test.WithNumParts(1), test.WithLocked(*channel.NewSubAlloc(map[int]channel.ID{}, []channel.Bal{big.NewInt(2)}, nil)), test.WithBalancesInRange(big.NewInt(1), big.NewInt(1))), + *test.NewRandomAllocation(rng, test.WithNumAssets(1), test.WithNumParts(1), test.WithLocked(*channel.NewSubAlloc(map[wallet.BackendID]channel.ID{}, []channel.Bal{big.NewInt(2)}, nil)), test.WithBalancesInRange(big.NewInt(1), big.NewInt(1))), []channel.Bal{big.NewInt(3)}, }, @@ -495,7 +499,7 @@ func TestAllocation_Valid(t *testing.T) { {big.NewInt(64), big.NewInt(128)}, }, Locked: []channel.SubAlloc{ - *channel.NewSubAlloc(map[int]channel.ID{0: channel.Zero}, []channel.Bal{big.NewInt(4)}, nil), + *channel.NewSubAlloc(map[wallet.BackendID]channel.ID{0: channel.Zero}, []channel.Bal{big.NewInt(4)}, nil), }, }, false, @@ -511,7 +515,7 @@ func TestAllocation_Valid(t *testing.T) { {big.NewInt(64), big.NewInt(128)}, }, Locked: []channel.SubAlloc{ - *channel.NewSubAlloc(map[int]channel.ID{0: channel.Zero}, []channel.Bal{big.NewInt(-1)}, nil), + *channel.NewSubAlloc(map[wallet.BackendID]channel.ID{0: channel.Zero}, []channel.Bal{big.NewInt(-1)}, nil), }, }, false, @@ -539,7 +543,7 @@ func TestAllocation_Valid(t *testing.T) { {big.NewInt(2), big.NewInt(16)}, }, Locked: []channel.SubAlloc{ - *channel.NewSubAlloc(map[int]channel.ID{0: channel.Zero}, []channel.Bal{big.NewInt(4), big.NewInt(-1)}, nil), + *channel.NewSubAlloc(map[wallet.BackendID]channel.ID{0: channel.Zero}, []channel.Bal{big.NewInt(4), big.NewInt(-1)}, nil), }, }, false, @@ -559,9 +563,9 @@ func TestAllocation_Valid(t *testing.T) { // suballocation serialization. func TestSuballocSerialization(t *testing.T) { ss := []perunio.Serializer{ - channel.NewSubAlloc(map[int]channel.ID{0: {2}}, []channel.Bal{}, nil), - channel.NewSubAlloc(map[int]channel.ID{0: {3}}, []channel.Bal{big.NewInt(0)}, nil), - channel.NewSubAlloc(map[int]channel.ID{0: {4}}, []channel.Bal{big.NewInt(5), big.NewInt(1 << 62)}, nil), + channel.NewSubAlloc(map[wallet.BackendID]channel.ID{0: {2}}, []channel.Bal{}, nil), + channel.NewSubAlloc(map[wallet.BackendID]channel.ID{0: {3}}, []channel.Bal{big.NewInt(0)}, nil), + channel.NewSubAlloc(map[wallet.BackendID]channel.ID{0: {4}}, []channel.Bal{big.NewInt(5), big.NewInt(1 << 62)}, nil), } peruniotest.GenericSerializerTest(t, ss...) diff --git a/channel/backend.go b/channel/backend.go index 5af67324d..8a3e9c069 100644 --- a/channel/backend.go +++ b/channel/backend.go @@ -21,7 +21,7 @@ import ( // backend is set to the global channel backend. Must not be set directly but // through importing the needed backend. -var backend map[int]Backend +var backend map[wallet.BackendID]Backend // Backend is an interface that needs to be implemented for every blockchain. // It provides basic functionalities to the framework. @@ -54,20 +54,20 @@ type Backend interface { // through importing the needed backend. func SetBackend(b Backend, id int) { if backend == nil { - backend = make(map[int]Backend) + backend = make(map[wallet.BackendID]Backend) } - if backend[id] != nil { + if backend[wallet.BackendID(id)] != nil { panic("channel backend already set") } - backend[id] = b + backend[wallet.BackendID(id)] = b } // CalcID calculates the CalcID. -func CalcID(p *Params) (map[int]ID, error) { - id := make(map[int]ID) +func CalcID(p *Params) (map[wallet.BackendID]ID, error) { + id := make(map[wallet.BackendID]ID) var err error for i := range p.Parts[0] { - id[i], err = backend[i].CalcID(p) + id[wallet.BackendID(i)], err = backend[wallet.BackendID(i)].CalcID(p) if err != nil { return nil, err } @@ -93,25 +93,13 @@ func Sign(a wallet.Account, s *State) (wallet.Sig, error) { } // Verify verifies that a signature was a valid signature from addr on a state. -func Verify(a map[int]wallet.Address, state *State, sig wallet.Sig) (bool, error) { - errs := make([]error, len(backend)) - for i, addr := range a { - v, err := backend[i].Verify(addr, state, sig) - if v { - return true, nil - } else { - errs = append(errs, err) - } - } - if len(errs) > 0 { - return false, errors.Join(errs...) - } - return false, errors.New("could not validate signature") +func Verify(a wallet.Address, state *State, sig wallet.Sig) (bool, error) { + return backend[a.BackendID()].Verify(a, state, sig) } // NewAsset returns a variable of type Asset, which can be used // for unmarshalling an asset from its binary representation. -func NewAsset(id int) Asset { +func NewAsset(id wallet.BackendID) Asset { return backend[id].NewAsset() } diff --git a/channel/errors.go b/channel/errors.go index 60b31453a..6a7f98018 100644 --- a/channel/errors.go +++ b/channel/errors.go @@ -16,6 +16,7 @@ package channel import ( "fmt" + "perun.network/go-perun/wallet" "github.com/pkg/errors" ) @@ -23,18 +24,18 @@ import ( type ( // StateTransitionError happens in case of an invalid channel state transition. StateTransitionError struct { - ID map[int]ID + ID map[wallet.BackendID]ID } // ActionError happens if an invalid action is applied to a channel state. ActionError struct { - ID map[int]ID + ID map[wallet.BackendID]ID } // PhaseTransitionError happens in case of an invalid channel machine phase // transition. PhaseTransitionError struct { - ID map[int]ID + ID map[wallet.BackendID]ID current Phase PhaseTransition } @@ -56,20 +57,20 @@ func (e *PhaseTransitionError) Error() string { } // NewStateTransitionError creates a new StateTransitionError. -func NewStateTransitionError(id map[int]ID, msg string) error { +func NewStateTransitionError(id map[wallet.BackendID]ID, msg string) error { return errors.Wrap(&StateTransitionError{ ID: id, }, msg) } // NewActionError creates a new ActionError. -func NewActionError(id map[int]ID, msg string) error { +func NewActionError(id map[wallet.BackendID]ID, msg string) error { return errors.Wrap(&ActionError{ ID: id, }, msg) } -func newPhaseTransitionError(id map[int]ID, current Phase, expected PhaseTransition, msg string) error { +func newPhaseTransitionError(id map[wallet.BackendID]ID, current Phase, expected PhaseTransition, msg string) error { return errors.Wrap(&PhaseTransitionError{ ID: id, current: current, @@ -78,7 +79,7 @@ func newPhaseTransitionError(id map[int]ID, current Phase, expected PhaseTransit } func newPhaseTransitionErrorf( - id map[int]ID, + id map[wallet.BackendID]ID, current Phase, expected PhaseTransition, format string, diff --git a/channel/errors_internal_test.go b/channel/errors_internal_test.go index 25c0835a0..ad187d5ec 100644 --- a/channel/errors_internal_test.go +++ b/channel/errors_internal_test.go @@ -16,6 +16,7 @@ package channel import ( "errors" + "perun.network/go-perun/wallet" "testing" "github.com/stretchr/testify/assert" @@ -23,14 +24,14 @@ import ( func TestTransitionErrors(t *testing.T) { assert.False(t, IsStateTransitionError(errors.New("No StateTransitionError"))) - assert.True(t, IsStateTransitionError(NewStateTransitionError(map[int]ID{0: Zero}, "A StateTransitionError"))) + assert.True(t, IsStateTransitionError(NewStateTransitionError(map[wallet.BackendID]ID{0: Zero}, "A StateTransitionError"))) assert.False(t, IsActionError(errors.New("No ActionError"))) - assert.True(t, IsActionError(NewActionError(map[int]ID{0: Zero}, "An ActionError"))) + assert.True(t, IsActionError(NewActionError(map[wallet.BackendID]ID{0: Zero}, "An ActionError"))) assert.False(t, IsPhaseTransitionError(errors.New("No PhaseTransitionError"))) assert.True(t, IsPhaseTransitionError(newPhaseTransitionError( - map[int]ID{0: Zero}, InitActing, PhaseTransition{InitActing, InitActing}, "A PhaseTransitionError"))) + map[wallet.BackendID]ID{0: Zero}, InitActing, PhaseTransition{InitActing, InitActing}, "A PhaseTransitionError"))) assert.True(t, IsPhaseTransitionError(newPhaseTransitionErrorf( - map[int]ID{0: Zero}, InitActing, PhaseTransition{InitActing, InitActing}, "A %s", "PhaseTransitionError"))) + map[wallet.BackendID]ID{0: Zero}, InitActing, PhaseTransition{InitActing, InitActing}, "A %s", "PhaseTransitionError"))) } diff --git a/channel/machine.go b/channel/machine.go index 37f51c782..a217e172e 100644 --- a/channel/machine.go +++ b/channel/machine.go @@ -54,12 +54,12 @@ type ( // needed for persistence. The ID, Idx and Params only need to be persisted // once per channel as they stay constant during a channel's lifetime. Source interface { - ID() map[int]ID // ID is the channel ID of this source. It is the same as Params().ID(). - Idx() Index // Idx is the own index in the channel. - Params() *Params // Params are the channel parameters. - StagingTX() Transaction // StagingTX is the staged transaction (State+incomplete list of sigs). - CurrentTX() Transaction // CurrentTX is the current transaction (State+complete list of sigs). - Phase() Phase // Phase is the phase in which the channel is currently in. + ID() map[wallet.BackendID]ID // ID is the channel ID of this source. It is the same as Params().ID(). + Idx() Index // Idx is the own index in the channel. + Params() *Params // Params are the channel parameters. + StagingTX() Transaction // StagingTX is the staged transaction (State+incomplete list of sigs). + CurrentTX() Transaction // CurrentTX is the current transaction (State+complete list of sigs). + Phase() Phase // Phase is the phase in which the channel is currently in. } ) @@ -129,7 +129,7 @@ var signingPhases = []Phase{InitSigning, Signing, Progressing} // individually. type machine struct { phase Phase - acc wallet.Account `cloneable:"shallow"` + acc map[wallet.BackendID]wallet.Account `cloneable:"shallow"` idx Index params Params stagingTX Transaction @@ -141,8 +141,8 @@ type machine struct { } // newMachine returns a new uninitialized machine for the given parameters. -func newMachine(acc wallet.Account, params Params) (*machine, error) { - idx := wallet.IndexOfAddr(params.Parts, acc.Address()) +func newMachine(acc map[wallet.BackendID]wallet.Account, params Params) (*machine, error) { + idx := wallet.IndexOfAddrs(params.Parts, AddressMapfromAccountMap(acc)) if idx < 0 { return nil, errors.New("account not part of participant set") } @@ -156,7 +156,7 @@ func newMachine(acc wallet.Account, params Params) (*machine, error) { }, nil } -func restoreMachine(acc wallet.Account, source Source) (*machine, error) { +func restoreMachine(acc map[wallet.BackendID]wallet.Account, source Source) (*machine, error) { m, err := newMachine(acc, *source.Params()) if err != nil { return nil, err @@ -168,12 +168,12 @@ func restoreMachine(acc wallet.Account, source Source) (*machine, error) { } // ID returns the channel id. -func (m *machine) ID() map[int]ID { +func (m *machine) ID() map[wallet.BackendID]ID { return m.params.ID() } // Account returns the account this channel is using for signing state updates. -func (m *machine) Account() wallet.Account { +func (m *machine) Account() map[wallet.BackendID]wallet.Account { return m.acc } @@ -223,12 +223,13 @@ func (m *machine) Sig() (sig wallet.Sig, err error) { } if m.stagingTX.Sigs[m.idx] == nil { - - sig, err = Sign(m.acc, m.stagingTX.State) - if err != nil { - return + for _, acc := range m.acc { + sig, err = Sign(acc, m.stagingTX.State) + if err != nil { + return + } + m.stagingTX.Sigs[m.idx] = sig } - m.stagingTX.Sigs[m.idx] = sig } else { sig = m.stagingTX.Sigs[m.idx] } @@ -289,10 +290,12 @@ func (m *machine) AddSig(idx Index, sig wallet.Sig) error { if m.stagingTX.Sigs[idx] != nil { return errors.Errorf("signature for idx %d already present (ID: %x)", idx, m.params.id) } - if ok, err := Verify(m.params.Parts[idx], m.stagingTX.State, sig); err != nil { - return err - } else if !ok { - return errors.Errorf("invalid signature for idx %d (ID: %x)", idx, m.params.id) + for _, add := range m.params.Parts[idx] { + if ok, err := Verify(add, m.stagingTX.State, sig); err != nil { + return err + } else if !ok { + return errors.Errorf("invalid signature for idx %d (ID: %x)", idx, m.params.id) + } } m.stagingTX.Sigs[idx] = sig @@ -571,3 +574,11 @@ func (m *machine) forceState(p Phase, s *State) { m.setPhase(p) m.addTx(m.newTransaction(s)) } + +func AddressMapfromAccountMap(accs map[wallet.BackendID]wallet.Account) map[wallet.BackendID]wallet.Address { + addresses := make(map[wallet.BackendID]wallet.Address) + for id, a := range accs { + addresses[id] = a.Address() + } + return addresses +} diff --git a/channel/machine_test.go b/channel/machine_test.go index 6dcc0ff5e..efced47b7 100644 --- a/channel/machine_test.go +++ b/channel/machine_test.go @@ -15,6 +15,7 @@ package channel_test import ( + "perun.network/go-perun/wallet" "testing" "github.com/stretchr/testify/require" @@ -27,15 +28,15 @@ import ( func TestMachineClone(t *testing.T) { rng := pkgtest.Prng(t) - acc := wtest.NewRandomAccount(rng) - params := *test.NewRandomParams(rng, test.WithFirstPart(acc.Address())) + acc := wtest.NewRandomAccountMapSlice(rng, 0, 1) + params := *test.NewRandomParams(rng, test.WithFirstPart(map[wallet.BackendID]wallet.Address{0: acc[0][0].Address()})) - sm, err := channel.NewStateMachine(acc, params) + sm, err := channel.NewStateMachine(acc[0], params) require.NoError(t, err) cloneSM := sm.Clone() require.Equal(t, sm, cloneSM) - am, err := channel.NewActionMachine(acc, params) + am, err := channel.NewActionMachine(acc[0], params) require.NoError(t, err) cloneAM := am.Clone() require.Equal(t, am, cloneAM) diff --git a/channel/mock_app.go b/channel/mock_app.go index 5b89f41d9..8308bd633 100644 --- a/channel/mock_app.go +++ b/channel/mock_app.go @@ -17,6 +17,7 @@ package channel import ( "encoding/binary" "fmt" + "perun.network/go-perun/wallet" "github.com/pkg/errors" ) @@ -168,9 +169,9 @@ func (a MockApp) execMockOp(op *MockOp) error { case OpErr: return errors.New("MockOp: runtime error") case OpTransitionErr: - return NewStateTransitionError(map[int]ID{}, "MockOp: state transition error") + return NewStateTransitionError(map[wallet.BackendID]ID{}, "MockOp: state transition error") case OpActionErr: - return NewActionError(map[int]ID{}, "MockOp: action error") + return NewActionError(map[wallet.BackendID]ID{}, "MockOp: action error") case OpPanic: panic("MockOp: panic") case OpValid: diff --git a/channel/mock_app_internal_test.go b/channel/mock_app_internal_test.go index 238ae6257..a2b9e1a82 100644 --- a/channel/mock_app_internal_test.go +++ b/channel/mock_app_internal_test.go @@ -15,6 +15,7 @@ package channel import ( + "perun.network/go-perun/wallet" "testing" "github.com/stretchr/testify/assert" @@ -141,5 +142,5 @@ func MockActionAppTest(t *testing.T, app MockApp) { } func createState(op MockOp) *State { - return &State{ID: map[int]ID{}, Version: 0, Allocation: Allocation{}, Data: NewMockOp(op), IsFinal: false} + return &State{ID: map[wallet.BackendID]ID{}, Version: 0, Allocation: Allocation{}, Data: NewMockOp(op), IsFinal: false} } diff --git a/channel/multi/subscription.go b/channel/multi/subscription.go index 93bfef673..5d54ebaa1 100644 --- a/channel/multi/subscription.go +++ b/channel/multi/subscription.go @@ -16,12 +16,13 @@ package multi import ( "context" + "perun.network/go-perun/wallet" "perun.network/go-perun/channel" ) // Subscribe creates a new multi-ledger AdjudicatorSubscription. -func (a *Adjudicator) Subscribe(ctx context.Context, chID map[int]channel.ID) (channel.AdjudicatorSubscription, error) { +func (a *Adjudicator) Subscribe(ctx context.Context, chID map[wallet.BackendID]channel.ID) (channel.AdjudicatorSubscription, error) { asub := &AdjudicatorSubscription{ events: make(chan channel.AdjudicatorEvent), errors: make(chan error), diff --git a/channel/params.go b/channel/params.go index a620f2c25..cd5ceff48 100644 --- a/channel/params.go +++ b/channel/params.go @@ -35,7 +35,7 @@ const IDLen = 32 type ID = [IDLen]byte // IDMap is a map of IDs with keys corresponding to backendIDs -type IDMap map[int]ID +type IDMap map[wallet.BackendID]ID // MaxNonceLen is the maximum byte count of a nonce. const MaxNonceLen = 32 @@ -57,7 +57,7 @@ func NonceFromBytes(b []byte) Nonce { // Zero is the default channelID. var Zero = ID{} -func EqualIDs(a, b map[int]ID) bool { +func EqualIDs(a, b map[wallet.BackendID]ID) bool { if len(a) != len(b) { return false } @@ -94,7 +94,7 @@ func (ids *IDMap) Decode(r stdio.Reader) error { if err := perunio.Decode(r, &mapLen); err != nil { return errors.WithMessage(err, "decoding map length") } - *ids = make(map[int]ID, mapLen) + *ids = make(map[wallet.BackendID]ID, mapLen) for i := 0; i < int(mapLen); i++ { var idx int32 if err := perunio.Decode(r, &idx); err != nil { @@ -104,7 +104,7 @@ func (ids *IDMap) Decode(r stdio.Reader) error { if err := perunio.Decode(r, &id); err != nil { return errors.WithMessagef(err, "decoding %d-th address map entry", i) } - (*ids)[int(idx)] = id + (*ids)[wallet.BackendID(idx)] = id } return nil } @@ -138,7 +138,7 @@ func FromIDKey(k string) IDMap { if err := binary.Read(buff, binary.BigEndian, &numElements); err != nil { log.Panicf("could not decode map length in FromIDKey: " + err.Error()) } - a := make(map[int]ID, numElements) + a := make(map[wallet.BackendID]ID, numElements) // Decode each key-value pair and insert them into the map. for i := 0; i < int(numElements); i++ { var key int32 @@ -149,7 +149,7 @@ func FromIDKey(k string) IDMap { if err := perunio.Decode(buff, id); err != nil { log.Panicf("could not decode map[int]ID in FromIDKey: " + err.Error()) } - a[int(key)] = id + a[wallet.BackendID(key)] = id } return a } @@ -162,11 +162,11 @@ var _ perunio.Serializer = (*Params)(nil) // It should only be created through NewParams(). type Params struct { // ChannelID is the channel ID as calculated by the backend - id map[int]ID + id map[wallet.BackendID]ID // ChallengeDuration in seconds during disputes ChallengeDuration uint64 // Parts are the channel participants - Parts []map[int]wallet.Address + Parts []map[wallet.BackendID]wallet.Address // App identifies the application that this channel is running. It is // optional, and if nil, signifies that a channel is a payment channel. App App `cloneable:"shallow"` @@ -179,7 +179,7 @@ type Params struct { } // ID returns the channelID of this channel. -func (p *Params) ID() map[int]ID { +func (p *Params) ID() map[wallet.BackendID]ID { return p.id } @@ -187,7 +187,7 @@ func (p *Params) ID() map[int]ID { // appDef optional: if it is nil, it describes a payment channel. The channel id // is also calculated here and persisted because it probably is an expensive // hash operation. -func NewParams(challengeDuration uint64, parts []map[int]wallet.Address, app App, nonce Nonce, ledger bool, virtual bool) (*Params, error) { +func NewParams(challengeDuration uint64, parts []map[wallet.BackendID]wallet.Address, app App, nonce Nonce, ledger bool, virtual bool) (*Params, error) { if err := ValidateParameters(challengeDuration, len(parts), app, nonce); err != nil { return nil, errors.WithMessage(err, "invalid parameter for NewParams") } @@ -243,7 +243,7 @@ func ValidateParameters(challengeDuration uint64, numParts int, app App, nonce N // NewParamsUnsafe creates Params from the given data and does NOT perform // sanity checks. The channel id is also calculated here and persisted because // it probably is an expensive hash operation. -func NewParamsUnsafe(challengeDuration uint64, parts []map[int]wallet.Address, app App, nonce Nonce, ledger bool, virtual bool) *Params { +func NewParamsUnsafe(challengeDuration uint64, parts []map[wallet.BackendID]wallet.Address, app App, nonce Nonce, ledger bool, virtual bool) *Params { p := &Params{ ChallengeDuration: challengeDuration, Parts: parts, @@ -255,7 +255,7 @@ func NewParamsUnsafe(challengeDuration uint64, parts []map[int]wallet.Address, a // probably an expensive hash operation, do it only once during creation. id, err := CalcID(p) - if err != nil || EqualIDs(id, map[int]ID{}) { + if err != nil || EqualIDs(id, map[wallet.BackendID]ID{}) { log.Panicf("Could not calculate channel id: %v", err) } p.id = id @@ -264,8 +264,8 @@ func NewParamsUnsafe(challengeDuration uint64, parts []map[int]wallet.Address, a // CloneAddress returns a clone of an Address using its binary marshaling // implementation. It panics if an error occurs during binary (un)marshaling. -func CloneAddresses(as []map[int]wallet.Address) []map[int]wallet.Address { - var cloneMap []map[int]wallet.Address +func CloneAddresses(as []map[wallet.BackendID]wallet.Address) []map[wallet.BackendID]wallet.Address { + var cloneMap []map[wallet.BackendID]wallet.Address for _, a := range as { cloneMap = append(cloneMap, wallet.CloneAddressesMap(a)) } diff --git a/channel/persistence/keyvalue/persistedstate.go b/channel/persistence/keyvalue/persistedstate.go index b9c9b6282..719f3663c 100644 --- a/channel/persistence/keyvalue/persistedstate.go +++ b/channel/persistence/keyvalue/persistedstate.go @@ -16,6 +16,7 @@ package keyvalue import ( "io" + "perun.network/go-perun/wallet" "perun.network/go-perun/channel" "perun.network/go-perun/wire/perunio" @@ -48,11 +49,11 @@ func (s *PersistedState) Decode(r io.Reader) error { type ( optChannelIDEnc struct { - ID *map[int]channel.ID + ID *map[wallet.BackendID]channel.ID } optChannelIDDec struct { - ID **map[int]channel.ID + ID **map[wallet.BackendID]channel.ID } ) @@ -69,7 +70,7 @@ func (id optChannelIDDec) Decode(r io.Reader) error { return err } if exists { - *id.ID = new(map[int]channel.ID) + *id.ID = new(map[wallet.BackendID]channel.ID) return perunio.Decode(r, (*channel.IDMap)(*id.ID)) } *id.ID = nil diff --git a/channel/persistence/keyvalue/persister.go b/channel/persistence/keyvalue/persister.go index 5fa43c7c4..2de9b1ab1 100644 --- a/channel/persistence/keyvalue/persister.go +++ b/channel/persistence/keyvalue/persister.go @@ -19,6 +19,7 @@ import ( "context" "fmt" "math" + "perun.network/go-perun/wallet" "regexp" "strconv" "strings" @@ -32,7 +33,7 @@ import ( ) // ChannelCreated inserts a channel into the database. -func (pr *PersistRestorer) ChannelCreated(_ context.Context, s channel.Source, peers []map[int]wire.Address, parent *map[int]channel.ID) error { +func (pr *PersistRestorer) ChannelCreated(_ context.Context, s channel.Source, peers []map[wallet.BackendID]wire.Address, parent *map[wallet.BackendID]channel.ID) error { db := pr.channelDB(s.ID()).NewBatch() // Write the channel data in the "Channel" table. numParts := len(s.Params().Parts) @@ -77,7 +78,7 @@ func sigKey(idx, numParts int) string { } // ChannelRemoved deletes a channel from the database. -func (pr *PersistRestorer) ChannelRemoved(ctx context.Context, id map[int]channel.ID) error { +func (pr *PersistRestorer) ChannelRemoved(ctx context.Context, id map[wallet.BackendID]channel.ID) error { db := pr.channelDB(id).NewBatch() peerdb := sortedkv.NewTable(pr.db, prefix.PeerDB).NewBatch() // All keys a channel has. @@ -116,7 +117,7 @@ func (pr *PersistRestorer) ChannelRemoved(ctx context.Context, id map[int]channe // paramsForChan returns the channel parameters for a given channel id from // the db. -func (pr *PersistRestorer) paramsForChan(id map[int]channel.ID) (channel.Params, error) { +func (pr *PersistRestorer) paramsForChan(id map[wallet.BackendID]channel.ID) (channel.Params, error) { params := channel.Params{} b, err := pr.channelDB(id).GetBytes("params") if err != nil { @@ -244,7 +245,7 @@ func decodeIdxFromDBKey(key string) (int, error) { return strconv.Atoi(vals[len(vals)-1]) } -func peerChannelKey(p map[int]wire.Address, ch map[int]channel.ID) (string, error) { +func peerChannelKey(p map[wallet.BackendID]wire.Address, ch map[wallet.BackendID]channel.ID) (string, error) { var key bytes.Buffer if err := perunio.Encode(&key, wire.AddressDecMap(p)); err != nil { return "", errors.WithMessage(err, "encoding peer address") @@ -257,6 +258,6 @@ func peerChannelKey(p map[int]wire.Address, ch map[int]channel.ID) (string, erro } // channelDB creates a prefixed database for persisting a channel's data. -func (pr *PersistRestorer) channelDB(id map[int]channel.ID) sortedkv.Database { +func (pr *PersistRestorer) channelDB(id map[wallet.BackendID]channel.ID) sortedkv.Database { return sortedkv.NewTable(pr.db, prefix.ChannelDB+channel.IDKey(id)+":") } diff --git a/channel/persistence/keyvalue/restorer.go b/channel/persistence/keyvalue/restorer.go index 2fa2fb0ce..cb4ed09c0 100644 --- a/channel/persistence/keyvalue/restorer.go +++ b/channel/persistence/keyvalue/restorer.go @@ -41,12 +41,12 @@ type ChannelIterator struct { } // ActivePeers returns a list of all peers with which a channel is persisted. -func (pr *PersistRestorer) ActivePeers(ctx context.Context) ([]map[int]wire.Address, error) { +func (pr *PersistRestorer) ActivePeers(ctx context.Context) ([]map[wallet.BackendID]wire.Address, error) { it := sortedkv.NewTable(pr.db, prefix.PeerDB).NewIterator() - peermap := make(map[wire.AddrKey]map[int]wire.Address) + peermap := make(map[wire.AddrKey]map[wallet.BackendID]wire.Address) for it.Next() { - var addr map[int]wire.Address + var addr map[wallet.BackendID]wire.Address err := perunio.Decode(bytes.NewBufferString(it.Key()), (*wire.AddressDecMap)(&addr)) if err != nil { return nil, errors.WithMessagef(err, "decoding peer key (%x)", it.Key()) @@ -54,7 +54,7 @@ func (pr *PersistRestorer) ActivePeers(ctx context.Context) ([]map[int]wire.Addr peermap[wire.Keys(addr)] = addr } - peers := make([]map[int]wire.Address, 0, len(peermap)) + peers := make([]map[wallet.BackendID]wire.Address, 0, len(peermap)) for _, peer := range peermap { peers = append(peers, peer) } @@ -63,7 +63,7 @@ func (pr *PersistRestorer) ActivePeers(ctx context.Context) ([]map[int]wire.Addr // channelPeers returns a slice of peer addresses for a given channel id from // the db of PersistRestorer. -func (pr *PersistRestorer) channelPeers(id map[int]channel.ID) ([]map[int]wire.Address, error) { +func (pr *PersistRestorer) channelPeers(id map[wallet.BackendID]channel.ID) ([]map[wallet.BackendID]wire.Address, error) { var ps wire.AddressMapArray peers, err := pr.channelDB(id).Get(prefix.Peers) if err != nil { @@ -83,7 +83,7 @@ func (pr *PersistRestorer) RestoreAll() (persistence.ChannelIterator, error) { // RestorePeer should return an iterator over all persisted channels which // the given peer is a part of. -func (pr *PersistRestorer) RestorePeer(addr map[int]wire.Address) (persistence.ChannelIterator, error) { +func (pr *PersistRestorer) RestorePeer(addr map[wallet.BackendID]wire.Address) (persistence.ChannelIterator, error) { it := &ChannelIterator{restorer: pr} chandb := sortedkv.NewTable(pr.db, prefix.ChannelDB) @@ -106,7 +106,7 @@ func (pr *PersistRestorer) RestorePeer(addr map[int]wire.Address) (persistence.C } // peerChannelsKey creates a db-key-string for a given wire.Address. -func peerChannelsKey(addr map[int]wire.Address) (string, error) { +func peerChannelsKey(addr map[wallet.BackendID]wire.Address) (string, error) { var key strings.Builder if err := perunio.Encode(&key, wire.AddressDecMap(addr)); err != nil { return "", errors.WithMessage(err, "encoding peer address") @@ -116,7 +116,7 @@ func peerChannelsKey(addr map[int]wire.Address) (string, error) { } // RestoreChannel restores a single channel. -func (pr *PersistRestorer) RestoreChannel(ctx context.Context, id map[int]channel.ID) (*persistence.Channel, error) { +func (pr *PersistRestorer) RestoreChannel(ctx context.Context, id map[wallet.BackendID]channel.ID) (*persistence.Channel, error) { chandb := sortedkv.NewTable(pr.db, prefix.ChannelDB) it := &ChannelIterator{ restorer: pr, diff --git a/channel/persistence/nonpersister.go b/channel/persistence/nonpersister.go index 9411e4181..d37c6974a 100644 --- a/channel/persistence/nonpersister.go +++ b/channel/persistence/nonpersister.go @@ -16,6 +16,7 @@ package persistence import ( "context" + "perun.network/go-perun/wallet" "github.com/pkg/errors" @@ -32,10 +33,12 @@ type nonPersistRestorer struct{} // Persister implementation -func (nonPersistRestorer) ChannelCreated(context.Context, channel.Source, []map[int]wire.Address, *map[int]channel.ID) error { +func (nonPersistRestorer) ChannelCreated(context.Context, channel.Source, []map[wallet.BackendID]wire.Address, *map[wallet.BackendID]channel.ID) error { + return nil +} +func (nonPersistRestorer) ChannelRemoved(context.Context, map[wallet.BackendID]channel.ID) error { return nil } -func (nonPersistRestorer) ChannelRemoved(context.Context, map[int]channel.ID) error { return nil } func (nonPersistRestorer) Staged(context.Context, channel.Source) error { return nil } func (nonPersistRestorer) SigAdded(context.Context, channel.Source, channel.Index) error { return nil } func (nonPersistRestorer) Enabled(context.Context, channel.Source) error { return nil } @@ -44,7 +47,7 @@ func (nonPersistRestorer) Close() error // Restorer implementation -func (nonPersistRestorer) ActivePeers(context.Context) ([]map[int]wire.Address, error) { +func (nonPersistRestorer) ActivePeers(context.Context) ([]map[wallet.BackendID]wire.Address, error) { return nil, nil } @@ -52,11 +55,11 @@ func (nonPersistRestorer) RestoreAll() (ChannelIterator, error) { return emptyChanIterator{}, nil } -func (nonPersistRestorer) RestorePeer(map[int]wire.Address) (ChannelIterator, error) { +func (nonPersistRestorer) RestorePeer(map[wallet.BackendID]wire.Address) (ChannelIterator, error) { return emptyChanIterator{}, nil } -func (nonPersistRestorer) RestoreChannel(context.Context, map[int]channel.ID) (*Channel, error) { +func (nonPersistRestorer) RestoreChannel(context.Context, map[wallet.BackendID]channel.ID) (*Channel, error) { return nil, errors.New("channel not found") } diff --git a/channel/persistence/persistence.go b/channel/persistence/persistence.go index 2db31d59b..52ce930b9 100644 --- a/channel/persistence/persistence.go +++ b/channel/persistence/persistence.go @@ -17,6 +17,7 @@ package persistence import ( "context" "io" + "perun.network/go-perun/wallet" "perun.network/go-perun/channel" "perun.network/go-perun/wire" @@ -35,12 +36,12 @@ type ( // state will be empty. The passed peers are the channel network peers, // which should also be persisted. The parent field is the parent // channel's ID, or nil, if it is a ledger channel. - ChannelCreated(ctx context.Context, source channel.Source, peers []map[int]wire.Address, parent *map[int]channel.ID) error + ChannelCreated(ctx context.Context, source channel.Source, peers []map[wallet.BackendID]wire.Address, parent *map[wallet.BackendID]channel.ID) error // ChannelRemoved is called by the client when a channel is removed because // it has been successfully settled and its data is no longer needed. All // data associated with this channel may be discarded. - ChannelRemoved(ctx context.Context, id map[int]channel.ID) error + ChannelRemoved(ctx context.Context, id map[wallet.BackendID]channel.ID) error // Staged is called when a new valid state got set as the new staging // state. It may already contain one valid signature, either by a remote @@ -72,14 +73,14 @@ type ( Restorer interface { // ActivePeers should return a list of all peers with which any channel is // persisted. - ActivePeers(context.Context) ([]map[int]wire.Address, error) + ActivePeers(context.Context) ([]map[wallet.BackendID]wire.Address, error) // RestorePeer should return an iterator over all persisted channels which // the given peer is a part of. - RestorePeer(map[int]wire.Address) (ChannelIterator, error) + RestorePeer(map[wallet.BackendID]wire.Address) (ChannelIterator, error) // RestoreChannel should return the channel with the requested ID. - RestoreChannel(context.Context, map[int]channel.ID) (*Channel, error) + RestoreChannel(context.Context, map[wallet.BackendID]channel.ID) (*Channel, error) } // PersistRestorer is a Persister and Restorer on the same data source and @@ -125,8 +126,8 @@ type ( // sub-channel, also holds the parent channel's ID. Channel struct { chSource - PeersV []map[int]wire.Address - Parent *map[int]channel.ID + PeersV []map[wallet.BackendID]wire.Address + Parent *map[wallet.BackendID]channel.ID } ) @@ -156,7 +157,7 @@ func NewChannel() *Channel { // FromSource creates a new Channel object from given `channel.Source`, the // channel's network peers, and the parent channel ID, if it exists. -func FromSource(s channel.Source, ps []map[int]wire.Address, parent *map[int]channel.ID) *Channel { +func FromSource(s channel.Source, ps []map[wallet.BackendID]wire.Address, parent *map[wallet.BackendID]channel.ID) *Channel { return &Channel{ chSource{ IdxV: s.Idx(), @@ -171,7 +172,7 @@ func FromSource(s channel.Source, ps []map[int]wire.Address, parent *map[int]cha } // ID is the channel ID of this source. It is the same as Params().ID(). -func (c *chSource) ID() map[int]channel.ID { return c.ParamsV.ID() } +func (c *chSource) ID() map[wallet.BackendID]channel.ID { return c.ParamsV.ID() } // Idx is the own index in the channel. func (c *chSource) Idx() channel.Index { return c.IdxV } diff --git a/channel/persistence/statemachine_test.go b/channel/persistence/statemachine_test.go index 4cf8b1a1b..71dd0473a 100644 --- a/channel/persistence/statemachine_test.go +++ b/channel/persistence/statemachine_test.go @@ -16,6 +16,7 @@ package persistence_test import ( "context" + "perun.network/go-perun/wallet" "testing" "time" @@ -69,8 +70,11 @@ func TestStateMachine(t *testing.T) { tpr.AssertEqual(csm) // remote signers for i := 1; i < n; i++ { - sig, err := channel.Sign(accs[i], csm.StagingState()) - require.NoError(err) + var sig wallet.Sig + for _, acc := range accs[i] { + sig, err = channel.Sign(acc, csm.StagingState()) + require.NoError(err) + } err = sm.AddSig(ctx, channel.Index(i), sig) require.NoError(err) tpr.AssertEqual(csm) diff --git a/channel/persistence/test/channel.go b/channel/persistence/test/channel.go index abb1b5c25..dbbc83fb0 100644 --- a/channel/persistence/test/channel.go +++ b/channel/persistence/test/channel.go @@ -31,9 +31,9 @@ import ( // Channel is a wrapper around a persisted channel and its participants, as well // as the associated persister and restorer. type Channel struct { - accounts []wallet.Account - peers []map[int]wire.Address - parent *map[int]channel.ID + accounts []map[wallet.BackendID]wallet.Account + peers []map[wallet.BackendID]wire.Address + parent *map[wallet.BackendID]channel.ID *persistence.StateMachine pr persistence.PersistRestorer @@ -52,7 +52,7 @@ func NewRandomChannel( t require.TestingT, pr persistence.PersistRestorer, user channel.Index, - peers []map[int]wire.Address, + peers []map[wallet.BackendID]wire.Address, parent *Channel, rng *rand.Rand, ) (c *Channel) { @@ -61,9 +61,9 @@ func NewRandomChannel( csm, err := channel.NewStateMachine(accs[0], *params) require.NoError(t, err) - var parentID *map[int]channel.ID + var parentID *map[wallet.BackendID]channel.ID if parent != nil { - parentID = new(map[int]channel.ID) + parentID = new(map[wallet.BackendID]channel.ID) *parentID = parent.ID() } @@ -82,7 +82,7 @@ func NewRandomChannel( return c } -func requireEqualPeers(t require.TestingT, expected, actual []map[int]wire.Address) { +func requireEqualPeers(t require.TestingT, expected, actual []map[wallet.BackendID]wire.Address) { require.Equal(t, len(expected), len(actual)) for i, p := range expected { if !EqualWireMaps(p, actual[i]) { @@ -93,7 +93,7 @@ func requireEqualPeers(t require.TestingT, expected, actual []map[int]wire.Addre } } -func EqualWireMaps(a, b map[int]wire.Address) bool { +func EqualWireMaps(a, b map[wallet.BackendID]wire.Address) bool { if len(a) != len(b) { return false } @@ -186,7 +186,7 @@ func (c *Channel) SignAll(ctx context.Context, t require.TestingT) { c.AssertPersisted(ctx, t) // remote signers for i := range c.accounts { - sig, err := channel.Sign(c.accounts[i], c.StagingState()) + sig, err := channel.Sign(c.accounts[i][0], c.StagingState()) require.NoError(t, err) c.AddSig(ctx, channel.Index(i), sig) //nolint:errcheck c.AssertPersisted(ctx, t) diff --git a/channel/persistence/test/peerchans.go b/channel/persistence/test/peerchans.go index 04e2f8550..18c90cc34 100644 --- a/channel/persistence/test/peerchans.go +++ b/channel/persistence/test/peerchans.go @@ -17,15 +17,16 @@ package test import ( "bytes" "fmt" + "perun.network/go-perun/wallet" "perun.network/go-perun/channel" "perun.network/go-perun/wire" "perun.network/go-perun/wire/perunio" ) -type peerChans map[string][]map[int]channel.ID +type peerChans map[string][]map[wallet.BackendID]channel.ID -func (pc peerChans) ID(p map[int]wire.Address) []map[int]channel.ID { +func (pc peerChans) ID(p map[wallet.BackendID]wire.Address) []map[wallet.BackendID]channel.ID { ids, ok := pc[peerKey(p)] if !ok { return nil @@ -33,8 +34,8 @@ func (pc peerChans) ID(p map[int]wire.Address) []map[int]channel.ID { return ids } -func (pc peerChans) Peers() []map[int]wire.Address { - ps := make([]map[int]wire.Address, 0, len(pc)) +func (pc peerChans) Peers() []map[wallet.BackendID]wire.Address { + ps := make([]map[wallet.BackendID]wire.Address, 0, len(pc)) for k := range pc { pk, _ := peerFromKey(k) ps = append(ps, pk) @@ -43,20 +44,20 @@ func (pc peerChans) Peers() []map[int]wire.Address { } // Add adds the given channel id to each peer's id list. -func (pc peerChans) Add(id map[int]channel.ID, ps ...map[int]wire.Address) { +func (pc peerChans) Add(id map[wallet.BackendID]channel.ID, ps ...map[wallet.BackendID]wire.Address) { for _, p := range ps { pc.add(id, p) } } // Don't use add, use Add. -func (pc peerChans) add(id map[int]channel.ID, p map[int]wire.Address) { +func (pc peerChans) add(id map[wallet.BackendID]channel.ID, p map[wallet.BackendID]wire.Address) { pk := peerKey(p) ids := pc[pk] // nil ok, since we append pc[pk] = append(ids, id) } -func (pc peerChans) Delete(id map[int]channel.ID) { +func (pc peerChans) Delete(id map[wallet.BackendID]channel.ID) { for pk, ids := range pc { for i, pid := range ids { if channel.EqualIDs(id, pid) { @@ -76,7 +77,7 @@ func (pc peerChans) Delete(id map[int]channel.ID) { } } -func peerKey(a map[int]wire.Address) string { +func peerKey(a map[wallet.BackendID]wire.Address) string { key := new(bytes.Buffer) err := perunio.Encode(key, wire.AddressDecMap(a)) if err != nil { @@ -85,8 +86,8 @@ func peerKey(a map[int]wire.Address) string { return key.String() } -func peerFromKey(s string) (map[int]wire.Address, error) { - p := make(map[int]wire.Address) +func peerFromKey(s string) (map[wallet.BackendID]wire.Address, error) { + p := make(map[wallet.BackendID]wire.Address) decMap := wire.AddressDecMap(p) err := perunio.Decode(bytes.NewBuffer([]byte(s)), &decMap) if err != nil { diff --git a/channel/persistence/test/peerchans_internal_test.go b/channel/persistence/test/peerchans_internal_test.go index fe62e09af..f6b710032 100644 --- a/channel/persistence/test/peerchans_internal_test.go +++ b/channel/persistence/test/peerchans_internal_test.go @@ -15,6 +15,7 @@ package test import ( + "perun.network/go-perun/wallet" "testing" "github.com/stretchr/testify/assert" @@ -29,7 +30,7 @@ import ( func TestEndpointChans(t *testing.T) { assert := assert.New(t) rng := pkgtest.Prng(t) - id := []map[int]channel.ID{ctest.NewRandomChannelID(rng), ctest.NewRandomChannelID(rng)} + id := []map[wallet.BackendID]channel.ID{ctest.NewRandomChannelID(rng), ctest.NewRandomChannelID(rng)} ps := wiretest.NewRandomAddressesMap(rng, 3) pc := make(peerChans) @@ -43,7 +44,7 @@ func TestEndpointChans(t *testing.T) { pc.Delete(id[0]) // p[1] should be deleted as id[0] was their only channel assert.ElementsMatch(id[1:], pc.ID(ps[0])) assert.ElementsMatch(id[1:], pc.ID(ps[2])) - assert.ElementsMatch([]map[int]wire.Address{ps[0], ps[2]}, pc.Peers()) + assert.ElementsMatch([]map[wallet.BackendID]wire.Address{ps[0], ps[2]}, pc.Peers()) assert.Nil(pc.ID(ps[1])) pc.Delete(id[1]) // now all peers should have been deleted diff --git a/channel/persistence/test/persistrestorer.go b/channel/persistence/test/persistrestorer.go index 65f0c51a1..c7fa5e977 100644 --- a/channel/persistence/test/persistrestorer.go +++ b/channel/persistence/test/persistrestorer.go @@ -19,6 +19,7 @@ package test // import "perun.network/go-perun/channel/persistence/test" import ( "bytes" "context" + "perun.network/go-perun/wallet" "sync" "testing" @@ -57,7 +58,7 @@ func NewPersistRestorer(t *testing.T) *PersistRestorer { // ChannelCreated fully persists all of the source's data. func (pr *PersistRestorer) ChannelCreated( - _ context.Context, source channel.Source, peers []map[int]wire.Address, parent *map[int]channel.ID, + _ context.Context, source channel.Source, peers []map[wallet.BackendID]wire.Address, parent *map[wallet.BackendID]channel.ID, ) error { pr.mu.Lock() defer pr.mu.Unlock() @@ -74,7 +75,7 @@ func (pr *PersistRestorer) ChannelCreated( } // ChannelRemoved removes the channel from the test persister's memory. -func (pr *PersistRestorer) ChannelRemoved(_ context.Context, id map[int]channel.ID) error { +func (pr *PersistRestorer) ChannelRemoved(_ context.Context, id map[wallet.BackendID]channel.ID) error { pr.mu.Lock() defer pr.mu.Unlock() @@ -163,7 +164,7 @@ func (pr *PersistRestorer) AssertEqual(s channel.Source) { } // AssertNotExists asserts that a channel with the given ID does not exist. -func (pr *PersistRestorer) AssertNotExists(id map[int]channel.ID) { +func (pr *PersistRestorer) AssertNotExists(id map[wallet.BackendID]channel.ID) { _, ok := pr.channel(id) assert.Falsef(pr.t, ok, "channel shouldn't exist: %x", id) } @@ -172,7 +173,7 @@ func (pr *PersistRestorer) AssertNotExists(id map[int]channel.ID) { // Since persister access is guaranteed to be single-threaded per channel, it // makes sense for the Persister implementation methods to use this getter to // channel the pointer to the channel storage. -func (pr *PersistRestorer) channel(id map[int]channel.ID) (*persistence.Channel, bool) { +func (pr *PersistRestorer) channel(id map[wallet.BackendID]channel.ID) (*persistence.Channel, bool) { pr.mu.Lock() defer pr.mu.Unlock() ch, ok := pr.chans[channel.IDKey(id)] @@ -182,7 +183,7 @@ func (pr *PersistRestorer) channel(id map[int]channel.ID) (*persistence.Channel, // Restorer implementation // ActivePeers returns all peers that channels are persisted for. -func (pr *PersistRestorer) ActivePeers(context.Context) ([]map[int]wire.Address, error) { +func (pr *PersistRestorer) ActivePeers(context.Context) ([]map[wallet.BackendID]wire.Address, error) { pr.mu.RLock() defer pr.mu.RUnlock() @@ -191,7 +192,7 @@ func (pr *PersistRestorer) ActivePeers(context.Context) ([]map[int]wire.Address, // RestorePeer returns an iterator over all persisted channels which // the given peer is a part of. -func (pr *PersistRestorer) RestorePeer(peer map[int]wire.Address) (persistence.ChannelIterator, error) { +func (pr *PersistRestorer) RestorePeer(peer map[wallet.BackendID]wire.Address) (persistence.ChannelIterator, error) { pr.mu.RLock() defer pr.mu.RUnlock() @@ -207,7 +208,7 @@ func (pr *PersistRestorer) RestorePeer(peer map[int]wire.Address) (persistence.C } // RestoreChannel should return the channel with the requested ID. -func (pr *PersistRestorer) RestoreChannel(_ context.Context, id map[int]channel.ID) (*persistence.Channel, error) { +func (pr *PersistRestorer) RestoreChannel(_ context.Context, id map[wallet.BackendID]channel.ID) (*persistence.Channel, error) { pr.mu.RLock() defer pr.mu.RUnlock() diff --git a/channel/persistence/test/persistrestorertest.go b/channel/persistence/test/persistrestorertest.go index 46560bd4d..f372cd45b 100644 --- a/channel/persistence/test/persistrestorertest.go +++ b/channel/persistence/test/persistrestorertest.go @@ -17,6 +17,7 @@ package test import ( "context" "math/rand" + "perun.network/go-perun/wallet" "testing" "github.com/stretchr/testify/assert" @@ -32,7 +33,7 @@ import ( // Client is a mock client that can be used to create channels. type Client struct { - addr map[int]wire.Address + addr map[wallet.BackendID]wire.Address rng *rand.Rand pr persistence.PersistRestorer @@ -55,9 +56,9 @@ func NewClient(ctx context.Context, t *testing.T, rng *rand.Rand, pr persistence // NewChannel creates a new channel with the supplied peer as the other // participant. The client's participant index is randomly chosen. -func (c *Client) NewChannel(t require.TestingT, p map[int]wire.Address, parent *Channel) *Channel { +func (c *Client) NewChannel(t require.TestingT, p map[wallet.BackendID]wire.Address, parent *Channel) *Channel { idx := c.rng.Intn(channelNumPeers) - peers := make([]map[int]wire.Address, channelNumPeers) + peers := make([]map[wallet.BackendID]wire.Address, channelNumPeers) peers[idx] = c.addr peers[idx^1] = p @@ -86,7 +87,7 @@ func GenericPersistRestorerTest( ) { t.Helper() t.Run("RestoreChannel error", func(t *testing.T) { - var id map[int]channel.ID + var id map[wallet.BackendID]channel.ID ch, err := pr.RestoreChannel(context.Background(), id) assert.Error(t, err) assert.Nil(t, ch) diff --git a/channel/state.go b/channel/state.go index 09134ed4e..d13cdf3f9 100644 --- a/channel/state.go +++ b/channel/state.go @@ -17,6 +17,7 @@ package channel import ( "encoding" "io" + "perun.network/go-perun/wallet" "perun.network/go-perun/wire" "github.com/pkg/errors" @@ -32,7 +33,7 @@ type ( // during disputes. State struct { // id is the immutable id of the channel this state belongs to - ID map[int]ID + ID map[wallet.BackendID]ID // version counter Version uint64 // App identifies the application that this channel is running. @@ -160,7 +161,7 @@ func (s *State) ToSubAlloc() *SubAlloc { return NewSubAlloc(s.ID, s.Allocation.Sum(), nil) } -func EqualWireMaps(a, b map[int]wire.Address) bool { +func EqualWireMaps(a, b map[wallet.BackendID]wire.Address) bool { if len(a) != len(b) { return false } diff --git a/channel/statemachine.go b/channel/statemachine.go index 80a94c605..efe595e12 100644 --- a/channel/statemachine.go +++ b/channel/statemachine.go @@ -29,7 +29,7 @@ type StateMachine struct { } // NewStateMachine creates a new StateMachine. -func NewStateMachine(acc wallet.Account, params Params) (*StateMachine, error) { +func NewStateMachine(acc map[wallet.BackendID]wallet.Account, params Params) (*StateMachine, error) { app, ok := params.App.(StateApp) if !ok { return nil, errors.New("app must be StateApp") @@ -47,7 +47,7 @@ func NewStateMachine(acc wallet.Account, params Params) (*StateMachine, error) { } // RestoreStateMachine restores a state machine to the data given by Source. -func RestoreStateMachine(acc wallet.Account, source Source) (*StateMachine, error) { +func RestoreStateMachine(acc map[wallet.BackendID]wallet.Account, source Source) (*StateMachine, error) { app, ok := source.Params().App.(StateApp) if !ok { return nil, errors.New("app must be StateApp") @@ -115,11 +115,12 @@ func (m *StateMachine) CheckUpdate( if err := m.validTransition(state, actor); err != nil { return err } - - if ok, err := Verify(m.params.Parts[sigIdx], state, sig); err != nil { - return errors.WithMessagef(err, "verifying signature[%d]", sigIdx) - } else if !ok { - return errors.Errorf("invalid signature[%d]", sigIdx) + for _, add := range m.params.Parts[sigIdx] { + if ok, err := Verify(add, state, sig); err != nil { + return errors.WithMessagef(err, "verifying signature[%d]", sigIdx) + } else if !ok { + return errors.Errorf("invalid signature[%d]", sigIdx) + } } return nil } diff --git a/channel/test/backend.go b/channel/test/backend.go index 90b516d85..31b3dc229 100644 --- a/channel/test/backend.go +++ b/channel/test/backend.go @@ -25,7 +25,7 @@ import ( "perun.network/go-perun/wallet" ) -type addressCreator = func() map[int]wallet.Address +type addressCreator = func() map[wallet.BackendID]wallet.Address // Setup provides all objects needed for the generic channel tests. type ( @@ -135,7 +135,7 @@ func genericVerifyTest(t *testing.T, s *Setup, opts ...GenericTestOption) { // Different address and same state and params for i := 0; i < 10; i++ { - ok, err := channel.Verify(s.RandomAddress(), s.State, sig) + ok, err := channel.Verify(s.RandomAddress()[0], s.State, sig) assert.NoError(t, err, "Verify should not return an error") assert.False(t, ok, "Verify should return false") } @@ -168,7 +168,7 @@ func buildModifiedParams(p1, p2 *channel.Params, s *Setup) (ret []channel.Params // Modify Parts[0] { modParams := *p1 - modParams.Parts = make([]map[int]wallet.Address, len(p1.Parts)) + modParams.Parts = make([]map[wallet.BackendID]wallet.Address, len(p1.Parts)) copy(modParams.Parts, p1.Parts) modParams.Parts[0] = s.RandomAddress() ret = appendModParams(ret, modParams) @@ -242,6 +242,7 @@ func buildModifiedStates(s1, s2 *channel.State, _opts ...GenericTestOption) (ret { modState := s1.Clone() modState.Assets = s2.Assets + modState.Backends = s2.Backends modState = ensureConsistentBalances(modState) ret = append(ret, *modState) } @@ -249,6 +250,7 @@ func buildModifiedStates(s1, s2 *channel.State, _opts ...GenericTestOption) (ret { modState := s1.Clone() modState.Allocation.Assets[0] = s2.Allocation.Assets[0] + modState.Allocation.Backends[0] = s2.Allocation.Backends[0] ret = append(ret, *modState) } } diff --git a/channel/test/randomizer.go b/channel/test/randomizer.go index d9d2f0ecc..a1850a877 100644 --- a/channel/test/randomizer.go +++ b/channel/test/randomizer.go @@ -108,7 +108,7 @@ func NewRandomLocked(rng *rand.Rand, opts ...RandomOpt) []channel.SubAlloc { // NewRandomLockedIDs generates new random `channel.ID`s used in `channel.SubAlloc`. // Options: `WithLockedIDs` and `WithNumLocked`. -func NewRandomLockedIDs(rng *rand.Rand, opts ...RandomOpt) []map[int]channel.ID { +func NewRandomLockedIDs(rng *rand.Rand, opts ...RandomOpt) []map[wallet.BackendID]channel.ID { opt := mergeRandomOpts(opts...) if ids := opt.LockedIDs(rng); ids != nil { @@ -117,30 +117,30 @@ func NewRandomLockedIDs(rng *rand.Rand, opts ...RandomOpt) []map[int]channel.ID numLockedIds := opt.NumLocked(rng) bIds, err := opt.BackendID() if err == nil && bIds != nil { - ids := make([]map[int]channel.ID, numLockedIds) + ids := make([]map[wallet.BackendID]channel.ID, numLockedIds) for i, _ := range ids { for j := range bIds { - ids[i] = make(map[int]channel.ID) + ids[i] = make(map[wallet.BackendID]channel.ID) cId := [32]byte{} rng.Read(cId[:]) - ids[i][j] = cId + ids[i][wallet.BackendID(j)] = cId } } return ids } b, err := opt.Backend() - ids := make([]map[int]channel.ID, numLockedIds) + ids := make([]map[wallet.BackendID]channel.ID, numLockedIds) for i, _ := range ids { if err != nil { - ids[i] = make(map[int]channel.ID) + ids[i] = make(map[wallet.BackendID]channel.ID) cId := [32]byte{} rng.Read(cId[:]) ids[i][0] = cId } else { - ids[i] = make(map[int]channel.ID) + ids[i] = make(map[wallet.BackendID]channel.ID) cId := [32]byte{} rng.Read(cId[:]) - ids[i][b] = cId + ids[i][wallet.BackendID(b)] = cId } } return ids @@ -180,16 +180,16 @@ func NewRandomParams(rng *rand.Rand, opts ...RandomOpt) *channel.Params { return params } numParts := opt.NumParts(rng) - var parts []map[int]wallet.Address + var parts []map[wallet.BackendID]wallet.Address if parts = opt.Parts(); parts == nil { - parts = make([]map[int]wallet.Address, numParts) + parts = make([]map[wallet.BackendID]wallet.Address, numParts) for i := range parts { - var backend int + var backend wallet.BackendID if backend, _ = opt.Backend(); backend != 0 { - parts[i] = map[int]wallet.Address{backend: test.NewRandomAddress(rng)} + parts[i] = map[wallet.BackendID]wallet.Address{backend: test.NewRandomAddress(rng)} } else { - parts[i] = map[int]wallet.Address{0: test.NewRandomAddress(rng)} + parts[i] = map[wallet.BackendID]wallet.Address{0: test.NewRandomAddress(rng)} } } } @@ -238,19 +238,19 @@ func NewRandomState(rng *rand.Rand, opts ...RandomOpt) (state *channel.State) { // NewRandomChannelID generates a new random `channel.ID`. // Options: `WithID`. -func NewRandomChannelID(rng *rand.Rand, opts ...RandomOpt) (id map[int]channel.ID) { +func NewRandomChannelID(rng *rand.Rand, opts ...RandomOpt) (id map[wallet.BackendID]channel.ID) { opt := mergeRandomOpts(opts...) if id, valid := opt.ID(); valid { return id } - id = make(map[int]channel.ID) + id = make(map[wallet.BackendID]channel.ID) bIds, err := opt.BackendID() if bIds != nil && err == nil { for _, b := range bIds { cId := [32]byte{} rng.Read(cId[:]) - id[b] = cId + id[wallet.BackendID(b)] = cId } return } @@ -262,14 +262,14 @@ func NewRandomChannelID(rng *rand.Rand, opts ...RandomOpt) (id map[int]channel.I } else { cId := [32]byte{} rng.Read(cId[:]) - id[bId] = cId + id[wallet.BackendID(bId)] = cId } return } // NewRandomChannelIDs generates a list of random channel IDs. -func NewRandomChannelIDs(rng *rand.Rand, n int) (ids []map[int]channel.ID) { - ids = make([]map[int]channel.ID, n) +func NewRandomChannelIDs(rng *rand.Rand, n int) (ids []map[wallet.BackendID]channel.ID) { + ids = make([]map[wallet.BackendID]channel.ID, n) for i := range ids { ids[i] = NewRandomChannelID(rng) } @@ -351,8 +351,20 @@ func NewRandomBalances(rng *rand.Rand, opts ...RandomOpt) channel.Balances { // NewRandomBackends generates new random backend IDs. // Options: `WithNumAssets` and `WithBackendIDs`. -func NewRandomBackends(rng *rand.Rand, num int, opts ...RandomOpt) []int { - backends := make([]int, num) +func NewRandomBackends(rng *rand.Rand, num int, opts ...RandomOpt) []wallet.BackendID { + opt := mergeRandomOpts(opts...) + if backends, err := opt.BackendID(); err == nil { + return backends + } + if backend, err := opt.Backend(); err == nil { + backends := make([]wallet.BackendID, num) + for i := range backends { + backends[i] = backend + } + updateOpts(opts, WithBackendIDs(backends)) + return backends + } + backends := make([]wallet.BackendID, num) for i := range backends { backends[i] = 0 } @@ -379,7 +391,7 @@ func NewRandomTransaction(rng *rand.Rand, sigMask []bool, opts ...RandomOpt) *ch if !choice { sigs[i] = nil } else { - sigs[i], err = channel.Sign(accs[i], state) + sigs[i], err = channel.Sign(accs[i][0], state) } if err != nil { panic(err) diff --git a/channel/test/randomopts.go b/channel/test/randomopts.go index 57f2184f5..0ce550159 100644 --- a/channel/test/randomopts.go +++ b/channel/test/randomopts.go @@ -66,12 +66,12 @@ func WithApp(app channel.App) RandomOpt { } // WithBackend sets the `backend` that should be used. -func WithBackend(id int) RandomOpt { +func WithBackend(id wallet.BackendID) RandomOpt { return RandomOpt{"backend": id} } // WithBackendIDs sets the `backend` that should be used. -func WithBackendIDs(id []int) RandomOpt { +func WithBackendIDs(id []wallet.BackendID) RandomOpt { return RandomOpt{"backendIDs": id} } @@ -122,12 +122,12 @@ func WithChallengeDuration(d uint64) RandomOpt { } // WithFirstPart sets the first participant that should be used in randomly generated Params. Overrides `WithParts`. -func WithFirstPart(part map[int]wallet.Address) RandomOpt { +func WithFirstPart(part map[wallet.BackendID]wallet.Address) RandomOpt { return RandomOpt{"firstPart": part} } // WithID sets the channel ID that should be used. -func WithID(id map[int]channel.ID) RandomOpt { +func WithID(id map[wallet.BackendID]channel.ID) RandomOpt { return RandomOpt{"id": id} } @@ -153,7 +153,7 @@ func WithLockedBals(bals ...channel.Bal) RandomOpt { } // WithLockedID sets the channel id that should be used when generating a single sub-allocation with `NewRandomSubAlloc`. -func WithLockedID(id map[int]channel.ID) RandomOpt { +func WithLockedID(id map[wallet.BackendID]channel.ID) RandomOpt { return RandomOpt{"lockedId": id} } @@ -197,7 +197,7 @@ func WithParams(params *channel.Params) RandomOpt { // WithParts sets the `Parts` that should be used when generating Params. // Also sets `WithNumParts`. -func WithParts(parts []map[int]wallet.Address) RandomOpt { +func WithParts(parts []map[wallet.BackendID]wallet.Address) RandomOpt { return RandomOpt{"parts": parts, "numParts": len(parts)} } @@ -302,19 +302,19 @@ func (o RandomOpt) Assets() []channel.Asset { } // Backend returns the `Backend` value of the `RandomOpt`. -func (o RandomOpt) Backend() (int, error) { +func (o RandomOpt) Backend() (wallet.BackendID, error) { if _, ok := o["backend"]; !ok { return 0, fmt.Errorf("backend not set") } - return o["backend"].(int), nil + return o["backend"].(wallet.BackendID), nil } // BackendID returns the `BackendID` value from `Allocation` of the `RandomOpt`. -func (o RandomOpt) BackendID() ([]int, error) { +func (o RandomOpt) BackendID() ([]wallet.BackendID, error) { if _, ok := o["backendIDs"]; !ok { - return []int{0}, fmt.Errorf("backend not set") + return []wallet.BackendID{0}, fmt.Errorf("backend not set") } - return o["backendIDs"].([]int), nil + return o["backendIDs"].([]wallet.BackendID), nil } // Balances returns the `Balances` value of the `RandomOpt`. @@ -347,20 +347,20 @@ func (o RandomOpt) ChallengeDuration(rng *rand.Rand) uint64 { // ID returns the `ID` value of the `RandomOpt`. // If not present, returns `false` as second argument. -func (o RandomOpt) ID() (id map[int]channel.ID, valid bool) { +func (o RandomOpt) ID() (id map[wallet.BackendID]channel.ID, valid bool) { if _, ok := o["id"]; !ok { - return map[int]channel.ID{}, false + return map[wallet.BackendID]channel.ID{}, false } - return o["id"].(map[int]channel.ID), true + return o["id"].(map[wallet.BackendID]channel.ID), true } // FirstPart returns the `FirstPart` value of the `RandomOpt`. // If not present, returns nil. -func (o RandomOpt) FirstPart() map[int]wallet.Address { +func (o RandomOpt) FirstPart() map[wallet.BackendID]wallet.Address { if _, ok := o["firstPart"]; !ok { return nil } - return o["firstPart"].(map[int]wallet.Address) + return o["firstPart"].(map[wallet.BackendID]wallet.Address) } // IsFinal returns the `IsFinal` value of the `RandomOpt`. @@ -392,20 +392,20 @@ func (o RandomOpt) LockedBals() []channel.Bal { // LockedID returns the `LockedID` value of the `RandomOpt`. // If not present, a random value is generated with `rng` as entropy source. -func (o RandomOpt) LockedID(rng *rand.Rand) map[int]channel.ID { +func (o RandomOpt) LockedID(rng *rand.Rand) map[wallet.BackendID]channel.ID { if _, ok := o["lockedId"]; !ok { o["lockedId"] = NewRandomChannelID(rng) } - return o["lockedId"].(map[int]channel.ID) + return o["lockedId"].(map[wallet.BackendID]channel.ID) } // LockedIDs returns the `LockedIDs` value of the `RandomOpt`. // If not present, returns nil. -func (o RandomOpt) LockedIDs(rng *rand.Rand) (ids []map[int]channel.ID) { +func (o RandomOpt) LockedIDs(rng *rand.Rand) (ids []map[wallet.BackendID]channel.ID) { if _, ok := o["lockedIds"]; !ok { return nil } - return o["lockedIds"].([]map[int]channel.ID) + return o["lockedIds"].([]map[wallet.BackendID]channel.ID) } // Nonce returns the `Nonce` value of the `RandomOpt`. @@ -498,11 +498,11 @@ func (o RandomOpt) Params() *channel.Params { // Parts returns the `Parts` value of the `RandomOpt`. // If not present, returns nil. -func (o RandomOpt) Parts() []map[int]wallet.Address { +func (o RandomOpt) Parts() []map[wallet.BackendID]wallet.Address { if _, ok := o["parts"]; !ok { return nil } - return o["parts"].([]map[int]wallet.Address) + return o["parts"].([]map[wallet.BackendID]wallet.Address) } // Version returns the `Version` value of the `RandomOpt`. diff --git a/channel/transaction.go b/channel/transaction.go index d1314dc0e..1539d2f86 100644 --- a/channel/transaction.go +++ b/channel/transaction.go @@ -78,5 +78,5 @@ func (t *Transaction) Decode(r io.Reader) error { t.Sigs = make([]wallet.Sig, t.State.NumParts()) - return wallet.DecodeSparseSigs(r, &t.Sigs, t.State.Allocation.Backends) + return wallet.DecodeSparseSigs(r, &t.Sigs) } diff --git a/client/adjudicate.go b/client/adjudicate.go index 087ce856c..8957ad59e 100644 --- a/client/adjudicate.go +++ b/client/adjudicate.go @@ -16,6 +16,7 @@ package client import ( "context" + "perun.network/go-perun/wallet" "github.com/pkg/errors" @@ -293,7 +294,9 @@ func (c *Channel) Settle(ctx context.Context, secondary bool) (err error) { return } } - c.wallet.DecrementUsage(c.machine.Account().Address()) + for i, wall := range c.wallet { + wall.DecrementUsage(c.machine.Account()[i].Address()) + } return }); err != nil { return errors.WithMessage(err, "decrementing account usage") @@ -339,7 +342,7 @@ func (c *Channel) withdraw(ctx context.Context, secondary bool) error { } // hasParticipant returns we are participating in the channel. -func (c *Channel) hasParticipant(id map[int]wire.Address) bool { +func (c *Channel) hasParticipant(id map[wallet.BackendID]wire.Address) bool { for _, p := range c.Peers() { if channel.EqualWireMaps(id, p) { return true diff --git a/client/appchannel_test.go b/client/appchannel_test.go index adf088762..58f0af71a 100644 --- a/client/appchannel_test.go +++ b/client/appchannel_test.go @@ -17,6 +17,7 @@ package client_test import ( "context" "math/big" + "perun.network/go-perun/wallet" "testing" "perun.network/go-perun/channel" @@ -42,8 +43,9 @@ func TestProgression(t *testing.T) { execConfig := &clienttest.ProgressionExecConfig{ BaseExecConfig: clienttest.MakeBaseExecConfig( - [2]map[int]wire.Address{setups[0].Identity.Address(), setups[1].Identity.Address()}, + [2]map[wallet.BackendID]wire.Address{wire.AddressMapfromAccountMap(setups[0].Identity), wire.AddressMapfromAccountMap(setups[1].Identity)}, chtest.NewRandomAsset(rng), + 0, [2]*big.Int{big.NewInt(99), big.NewInt(1)}, client.WithApp(app, channel.NewMockOp(channel.OpValid)), ), diff --git a/client/channel.go b/client/channel.go index 69b88feb7..4f5da77d7 100644 --- a/client/channel.go +++ b/client/channel.go @@ -43,7 +43,7 @@ type Channel struct { statesPub watcher.StatesPub onUpdate func(from, to *channel.State) adjudicator channel.Adjudicator - wallet wallet.Wallet + wallet map[wallet.BackendID]wallet.Wallet parent *Channel // must be nil for ledger channel subChannelFundings *updateInterceptors // awaited subchannel funding updates @@ -53,9 +53,9 @@ type Channel struct { // newChannel is internally used by the Client to create a new channel // controller after the channel proposal protocol ran successfully. func (c *Client) newChannel( - acc wallet.Account, + acc map[wallet.BackendID]wallet.Account, parent *Channel, - peers []map[int]wire.Address, // peerIdx, BackendID -> Address + peers []map[wallet.BackendID]wire.Address, // peerIdx, BackendID -> Address params channel.Params, ) (*Channel, error) { machine, err := channel.NewStateMachine(acc, params) @@ -66,10 +66,14 @@ func (c *Client) newChannel( } // channelFromSource is used to create a channel controller from restored data. -func (c *Client) channelFromSource(s channel.Source, parent *Channel, peers []map[int]wire.Address) (*Channel, error) { - accs, err := c.wallet.Unlock(s.Params().Parts[s.Idx()]) - if err != nil { - return nil, errors.WithMessage(err, "unlocking account for channel") +func (c *Client) channelFromSource(s channel.Source, parent *Channel, peers []map[wallet.BackendID]wire.Address) (*Channel, error) { + accs := make(map[wallet.BackendID]wallet.Account) + var err error + for i, wall := range c.wallet { + accs[i], err = wall.Unlock(s.Params().Parts[s.Idx()][i]) + if err != nil { + return nil, errors.WithMessage(err, "unlocking account for channel") + } } machine, err := channel.RestoreStateMachine(accs, s) @@ -81,7 +85,7 @@ func (c *Client) channelFromSource(s channel.Source, parent *Channel, peers []ma } // channelFromMachine creates a channel controller around the passed state machine. -func (c *Client) channelFromMachine(machine *channel.StateMachine, parent *Channel, peers []map[int]wire.Address) (*Channel, error) { +func (c *Client) channelFromMachine(machine *channel.StateMachine, parent *Channel, peers []map[wallet.BackendID]wire.Address) (*Channel, error) { logger := c.logChan(machine.ID()) machine.SetLog(logger) // client logger has more fields pmachine := persistence.FromStateMachine(machine, c.pr) @@ -128,7 +132,7 @@ func (c *Channel) logPeer(idx channel.Index) log.Logger { } // ID returns the channel ID. -func (c *Channel) ID() map[int]channel.ID { +func (c *Channel) ID() map[wallet.BackendID]channel.ID { return c.machine.ID() } @@ -170,7 +174,7 @@ func (c *Channel) Phase() channel.Phase { // Peers returns the Perun network addresses of all peers, in the order // of the channel participants. -func (c *Channel) Peers() []map[int]wire.Address { +func (c *Channel) Peers() []map[wallet.BackendID]wire.Address { return c.conn.Peers() } @@ -240,15 +244,3 @@ func (c *Channel) initExchangeSigsAndEnable(ctx context.Context) error { func (c *Channel) hasLockedFunds() bool { return len(c.machine.State().Locked) > 0 } - -func sortPeers(peer map[int][]wire.Address) []map[int]wire.Address { - peerNum := 0 - for i := range peer { - peerNum = len(peer[i]) - } - peerSlice := make([]map[int]wire.Address, peerNum) - for p := 0; p < peerNum; p++ { - peerSlice[p] = GetPeerMapWire(peer, p) - } - return peerSlice -} diff --git a/client/channelconn.go b/client/channelconn.go index 2daf0ea27..27c044497 100644 --- a/client/channelconn.go +++ b/client/channelconn.go @@ -18,6 +18,7 @@ import ( "context" "github.com/pkg/errors" "golang.org/x/sync/errgroup" + "perun.network/go-perun/wallet" "perun.network/go-perun/channel" "perun.network/go-perun/log" @@ -33,7 +34,7 @@ type channelConn struct { pub wire.Publisher // outgoing message publisher r *wire.Relay // update response relay/incoming messages - peers []map[int]wire.Address + peers []map[wallet.BackendID]wire.Address idx channel.Index // our index log log.Logger @@ -41,7 +42,7 @@ type channelConn struct { // newChannelConn creates a new channel connection for the given channel ID. It // subscribes on the subscriber to all messages regarding this channel. -func newChannelConn(id map[int]channel.ID, peers []map[int]wire.Address, idx channel.Index, sub wire.Subscriber, pub wire.Publisher) (_ *channelConn, err error) { +func newChannelConn(id map[wallet.BackendID]channel.ID, peers []map[wallet.BackendID]wire.Address, idx channel.Index, sub wire.Subscriber, pub wire.Publisher) (_ *channelConn, err error) { // relay to receive all update responses relay := wire.NewRelay() // we cache all responses for the lifetime of the relay @@ -83,7 +84,7 @@ func newChannelConn(id map[int]channel.ID, peers []map[int]wire.Address, idx cha }, nil } -func (c *channelConn) sender() map[int]wire.Address { +func (c *channelConn) sender() map[wallet.BackendID]wire.Address { return c.peers[c.idx] } @@ -118,7 +119,7 @@ func (c *channelConn) Send(ctx context.Context, msg wire.Msg) error { // Peers returns the ordered list of peer addresses. Note that the own peer is // included in the list. -func (c *channelConn) Peers() []map[int]wire.Address { +func (c *channelConn) Peers() []map[wallet.BackendID]wire.Address { return c.peers } @@ -146,7 +147,7 @@ type ( // with Next(), which returns the peer's channel index and the message. channelMsgRecv struct { *wire.Receiver - peers []map[int]wire.Address + peers []map[wallet.BackendID]wire.Address log log.Logger } ) diff --git a/client/chanregistry.go b/client/chanregistry.go index e26e6d9a3..afbf04124 100644 --- a/client/chanregistry.go +++ b/client/chanregistry.go @@ -15,6 +15,7 @@ package client import ( + "perun.network/go-perun/wallet" "sync" "perun.network/go-perun/channel" @@ -39,7 +40,7 @@ func makeChanRegistry() chanRegistry { // If an entry with the same ID already existed, this call does nothing and // returns false. Otherwise, it adds the new channel into the registry and // returns true. -func (r *chanRegistry) Put(id map[int]channel.ID, value *Channel) bool { +func (r *chanRegistry) Put(id map[wallet.BackendID]channel.ID, value *Channel) bool { r.mutex.Lock() if _, ok := r.values[channel.IDKey(id)]; ok { @@ -68,7 +69,7 @@ func (r *chanRegistry) OnNewChannel(handler func(*Channel)) { } // Has checks whether a channel with the requested ID is registered. -func (r *chanRegistry) Has(id map[int]channel.ID) bool { +func (r *chanRegistry) Has(id map[wallet.BackendID]channel.ID) bool { r.mutex.RLock() defer r.mutex.RUnlock() @@ -79,7 +80,7 @@ func (r *chanRegistry) Has(id map[int]channel.ID) bool { // Channel retrieves a channel from the registry. // If the channel exists, returns the channel, and true. Otherwise, returns nil, // false. -func (r *chanRegistry) Channel(id map[int]channel.ID) (*Channel, bool) { +func (r *chanRegistry) Channel(id map[wallet.BackendID]channel.ID) (*Channel, bool) { r.mutex.RLock() defer r.mutex.RUnlock() @@ -90,7 +91,7 @@ func (r *chanRegistry) Channel(id map[int]channel.ID) (*Channel, bool) { // Delete deletes a channel from the registry. // If the channel did not exist, does nothing. Returns whether the channel // existed. -func (r *chanRegistry) Delete(id map[int]channel.ID) (deleted bool) { +func (r *chanRegistry) Delete(id map[wallet.BackendID]channel.ID) (deleted bool) { r.mutex.Lock() defer r.mutex.Unlock() diff --git a/client/client.go b/client/client.go index 1146fe7ec..adb6795b0 100644 --- a/client/client.go +++ b/client/client.go @@ -35,12 +35,12 @@ import ( // // Currently, only the two-party protocol is fully implemented. type Client struct { - address map[int]wire.Address + address map[wallet.BackendID]wire.Address conn clientConn channels chanRegistry funder channel.Funder adjudicator channel.Adjudicator - wallet wallet.Wallet + wallet map[wallet.BackendID]wallet.Wallet pr persistence.PersistRestorer log log.Logger // structured logger for this client version1Cache version1Cache @@ -68,11 +68,11 @@ type Client struct { // // If any argument is nil, New panics. func New( - address map[int]wire.Address, + address map[wallet.BackendID]wire.Address, bus wire.Bus, funder channel.Funder, adjudicator channel.Adjudicator, - wallet wallet.Wallet, + wallet map[wallet.BackendID]wallet.Wallet, watcher watcher.Watcher, ) (c *Client, err error) { if address == nil { @@ -146,7 +146,7 @@ func (c *Client) EnablePersistence(pr persistence.PersistRestorer) { } // Channel queries a channel by its ID. -func (c *Client) Channel(id map[int]channel.ID) (*Channel, error) { +func (c *Client) Channel(id map[wallet.BackendID]channel.ID) (*Channel, error) { if ch, ok := c.channels.Channel(id); ok { return ch, nil } @@ -201,11 +201,11 @@ func (c *Client) SetLog(l log.Logger) { c.log = l } -func (c *Client) logPeer(p map[int]wire.Address) log.Logger { +func (c *Client) logPeer(p map[wallet.BackendID]wire.Address) log.Logger { return c.log.WithField("peer", p) } -func (c *Client) logChan(id map[int]channel.ID) log.Logger { +func (c *Client) logChan(id map[wallet.BackendID]channel.ID) log.Logger { return c.log.WithField("channel", id) } diff --git a/client/client_role_test.go b/client/client_role_test.go index 4e4c60862..dc5ce4188 100644 --- a/client/client_role_test.go +++ b/client/client_role_test.go @@ -18,6 +18,7 @@ import ( "context" "math/big" "math/rand" + "perun.network/go-perun/wallet" "testing" "time" @@ -50,18 +51,18 @@ func NewSetups(rng *rand.Rand, names []string) []ctest.RoleSetup { if err != nil { panic("Error initializing watcher: " + err.Error()) } - w := wtest.NewWallet() - acc := w.NewRandomAccount(rng) + w := map[wallet.BackendID]wtest.Wallet{0: wtest.NewWallet()} + acc := w[0].NewRandomAccount(rng) setup[i] = ctest.RoleSetup{ Name: names[i], - Identity: wiretest.NewRandomAccount(rng), + Identity: wiretest.NewRandomAccountMap(rng), Bus: bus, - Funder: backend.NewFunder(acc.Address()[0]), - Adjudicator: backend.NewAdjudicator(acc.Address()[0]), + Funder: backend.NewFunder(acc.Address()), + Adjudicator: backend.NewAdjudicator(acc.Address()), Watcher: watcher, Wallet: w, Timeout: roleOperationTimeout, - BalanceReader: backend.NewBalanceReader(acc.Address()[0]), + BalanceReader: backend.NewBalanceReader(acc.Address()), ChallengeDuration: 60, Errors: make(chan error), } @@ -84,8 +85,9 @@ func runAliceBobTest(ctx context.Context, t *testing.T, setup func(*rand.Rand) ( cfg := &ctest.AliceBobExecConfig{ BaseExecConfig: ctest.MakeBaseExecConfig( - [2]map[int]wire.Address{setups[0].Identity.Address(), setups[1].Identity.Address()}, + [2]map[wallet.BackendID]wire.Address{wire.AddressMapfromAccountMap(setups[0].Identity), wire.AddressMapfromAccountMap(setups[1].Identity)}, chtest.NewRandomAsset(rng), + 0, [2]*big.Int{big.NewInt(100), big.NewInt(100)}, app, ), diff --git a/client/client_test.go b/client/client_test.go index 343ff73bd..7fb36f1a9 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -16,6 +16,7 @@ package client_test import ( "context" + "perun.network/go-perun/wallet" "testing" "time" @@ -43,7 +44,7 @@ func (d DummyBus) Publish(context.Context, *wire.Envelope) error { return errors.New("DummyBus.Publish called") } -func (d DummyBus) SubscribeClient(wire.Consumer, map[int]wire.Address) error { +func (d DummyBus) SubscribeClient(wire.Consumer, map[wallet.BackendID]wire.Address) error { return nil } @@ -51,7 +52,7 @@ func TestClient_New_NilArgs(t *testing.T) { rng := test.Prng(t) id := wiretest.NewRandomAddressesMap(rng, 1)[0] backend := &ctest.MockBackend{} - b, f, a, w := &DummyBus{t}, &ctest.MockFunder{}, &ctest.MockAdjudicator{}, wtest.RandomWallet() + b, f, a, w := &DummyBus{t}, &ctest.MockFunder{}, &ctest.MockAdjudicator{}, map[wallet.BackendID]wallet.Wallet{0: wtest.RandomWallet()} watcher, err := local.NewWatcher(backend) require.NoError(t, err, "initializing the watcher should not error") assert.Panics(t, func() { client.New(nil, b, f, a, w, watcher) }) //nolint:errcheck @@ -67,8 +68,8 @@ func TestClient_Handle_NilArgs(t *testing.T) { backend := &ctest.MockBackend{} watcher, err := local.NewWatcher(backend) require.NoError(t, err, "initializing the watcher should not error") - c, err := client.New(wiretest.NewRandomAddressesMap(rng, 1)[0], - &DummyBus{t}, &ctest.MockFunder{}, &ctest.MockAdjudicator{}, wtest.RandomWallet(), watcher) + c, err := client.New(wiretest.NewRandomAddress(rng), + &DummyBus{t}, &ctest.MockFunder{}, &ctest.MockAdjudicator{}, map[wallet.BackendID]wallet.Wallet{0: wtest.RandomWallet()}, watcher) require.NoError(t, err) dummyUH := client.UpdateHandlerFunc(func(*channel.State, client.ChannelUpdate, *client.UpdateResponder) {}) @@ -83,7 +84,7 @@ func TestClient_New(t *testing.T) { watcher, err := local.NewWatcher(backend) require.NoError(t, err, "initializing the watcher should not error") c, err := client.New(wiretest.NewRandomAddressesMap(rng, 1)[0], - &DummyBus{t}, &ctest.MockFunder{}, &ctest.MockAdjudicator{}, wtest.RandomWallet(), watcher) + &DummyBus{t}, &ctest.MockFunder{}, &ctest.MockAdjudicator{}, map[wallet.BackendID]wallet.Wallet{0: wtest.RandomWallet()}, watcher) assert.NoError(t, err) require.NotNil(t, c) } @@ -111,8 +112,8 @@ func TestChannelRejection(t *testing.T) { ) // Create channel proposal. - parts := []map[int]wire.Address{alice.Identity.Address(), bob.Identity.Address()} - initAlloc := channel.NewAllocation(len(parts), []int{0}, asset) + parts := []map[wallet.BackendID]wire.Address{wire.AddressMapfromAccountMap(alice.Identity), wire.AddressMapfromAccountMap(bob.Identity)} + initAlloc := channel.NewAllocation(len(parts), []wallet.BackendID{0}, asset) prop, err := client.NewLedgerChannelProposal( challengeDuration, alice.WalletAddress, diff --git a/client/clientconn.go b/client/clientconn.go index 5daae446e..272bd1974 100644 --- a/client/clientconn.go +++ b/client/clientconn.go @@ -16,6 +16,7 @@ package client import ( "context" + "perun.network/go-perun/wallet" "github.com/pkg/errors" @@ -28,11 +29,11 @@ type clientConn struct { *wire.Relay // Client relay, subscribed to the bus. Embedded for methods Subscribe and Cache. bus wire.Bus reqRecv *wire.Receiver // subscription to incoming requests - sender map[int]wire.Address + sender map[wallet.BackendID]wire.Address log.Embedding } -func makeClientConn(address map[int]wire.Address, bus wire.Bus) (c clientConn, err error) { +func makeClientConn(address map[wallet.BackendID]wire.Address, bus wire.Bus) (c clientConn, err error) { c.Embedding = log.MakeEmbedding(log.WithField("id", address)) c.sender = address c.bus = bus @@ -76,7 +77,7 @@ func (c clientConn) nextReq(ctx context.Context) (*wire.Envelope, error) { // pubMsg publishes the given message on the wire bus, setting the own client as // the sender. -func (c *clientConn) pubMsg(ctx context.Context, msg wire.Msg, rec map[int]wire.Address) error { +func (c *clientConn) pubMsg(ctx context.Context, msg wire.Msg, rec map[wallet.BackendID]wire.Address) error { c.Log().WithField("peer", rec).Debugf("Publishing message: %v: %+v", msg.Type(), msg) return c.bus.Publish(ctx, &wire.Envelope{ Sender: c.sender, diff --git a/client/payment_test.go b/client/payment_test.go index 817e61a01..37c1d31e6 100644 --- a/client/payment_test.go +++ b/client/payment_test.go @@ -18,6 +18,7 @@ import ( "context" "math/big" "math/rand" + "perun.network/go-perun/wallet" "testing" chtest "perun.network/go-perun/channel/test" @@ -55,8 +56,9 @@ func TestPaymentDispute(t *testing.T) { cfg := &ctest.MalloryCarolExecConfig{ BaseExecConfig: ctest.MakeBaseExecConfig( - [2]map[int]wire.Address{setups[mallory].Identity.Address(), setups[carol].Identity.Address()}, + [2]map[wallet.BackendID]wire.Address{wire.AddressMapfromAccountMap(setups[mallory].Identity), wire.AddressMapfromAccountMap(setups[carol].Identity)}, chtest.NewRandomAsset(rng), + 0, [2]*big.Int{big.NewInt(100), big.NewInt(1)}, client.WithoutApp(), ), diff --git a/client/proposal.go b/client/proposal.go index 7e1d1c34d..265d245ab 100644 --- a/client/proposal.go +++ b/client/proposal.go @@ -62,7 +62,7 @@ type ( // panic. ProposalResponder struct { client *Client - peer map[int]wire.Address + peer map[wallet.BackendID]wire.Address req ChannelProposal called atomic.Bool } @@ -252,7 +252,7 @@ func (c *Client) cleanupChannelOpening(prop ChannelProposal, ourIdx channel.Inde // The proposer is expected to be the first peer in the participant list. // // This handler is dispatched from the Client.Handle routine. -func (c *Client) handleChannelProposal(handler ProposalHandler, p map[int]wire.Address, req ChannelProposal) { +func (c *Client) handleChannelProposal(handler ProposalHandler, p map[wallet.BackendID]wire.Address, req ChannelProposal) { ourIdx := channel.Index(ProposeeIdx) // Prepare and cleanup, e.g., for locking and unlocking parent channel. @@ -275,7 +275,7 @@ func (c *Client) handleChannelProposal(handler ProposalHandler, p map[int]wire.A } func (c *Client) handleChannelProposalAcc( - ctx context.Context, p map[int]wire.Address, + ctx context.Context, p map[wallet.BackendID]wire.Address, prop ChannelProposal, acc ChannelProposalAccept, ) (ch *Channel, err error) { if err := c.validChannelProposalAcc(prop, acc); err != nil { @@ -301,7 +301,7 @@ func (c *Client) handleChannelProposalAcc( func (c *Client) acceptChannelProposal( ctx context.Context, prop ChannelProposal, - p map[int]wire.Address, + p map[wallet.BackendID]wire.Address, acc ChannelProposalAccept, ) (*Channel, error) { if acc == nil { @@ -324,7 +324,7 @@ func (c *Client) acceptChannelProposal( } func (c *Client) handleChannelProposalRej( - ctx context.Context, p map[int]wire.Address, + ctx context.Context, p map[wallet.BackendID]wire.Address, req ChannelProposal, reason string, ) error { msgReject := &ChannelProposalRejMsg{ @@ -405,7 +405,7 @@ func (c *Client) proposeTwoPartyChannel( func (c *Client) validTwoPartyProposal( proposal ChannelProposal, ourIdx channel.Index, - peerAddr map[int]wire.Address, + peerAddr map[wallet.BackendID]wire.Address, ) error { if err := proposal.Valid(); err != nil { return err @@ -534,8 +534,8 @@ func (c *Client) validChannelProposalAcc( return nil } -func participants(proposer, proposee map[int]wallet.Address) []map[int]wallet.Address { - parts := make([]map[int]wallet.Address, proposalNumParts) +func participants(proposer, proposee map[wallet.BackendID]wallet.Address) []map[wallet.BackendID]wallet.Address { + parts := make([]map[wallet.BackendID]wallet.Address, proposalNumParts) parts[ProposerIdx] = proposer parts[ProposeeIdx] = proposee return parts @@ -590,9 +590,13 @@ func (c *Client) completeCPP( return nil, errors.New("channel already exists") } - accounts, err := c.wallet.Unlock(params.Parts[partIdx]) - if err != nil { - return nil, errors.WithMessage(err, "unlocking account") + accounts := make(map[wallet.BackendID]wallet.Account) + var err error + for i, wall := range c.wallet { + accounts[i], err = wall.Unlock(params.Parts[partIdx][i]) + if err != nil { + return nil, errors.WithMessage(err, "unlocking account") + } } parentChannelID, parent, err := c.proposalParent(prop, partIdx) @@ -622,11 +626,13 @@ func (c *Client) completeCPP( return ch, errors.WithMessage(err, "exchanging initial sigs and enabling state") } - c.wallet.IncrementUsage(params.Parts[int(partIdx)]) + for i, wall := range c.wallet { + wall.IncrementUsage(params.Parts[partIdx][i]) + } return ch, nil } -func (c *Client) proposalParent(prop ChannelProposal, partIdx channel.Index) (parentChannelID *map[int]channel.ID, parent *Channel, err error) { +func (c *Client) proposalParent(prop ChannelProposal, partIdx channel.Index) (parentChannelID *map[wallet.BackendID]channel.ID, parent *Channel, err error) { switch prop := prop.(type) { case *SubChannelProposalMsg: parentChannelID = &prop.Parent @@ -648,7 +654,7 @@ func (c *Client) proposalParent(prop ChannelProposal, partIdx channel.Index) (pa func (c *Client) mpcppParts( prop ChannelProposal, acc ChannelProposalAccept, -) (parts []map[int]wallet.Address) { +) (parts []map[wallet.BackendID]wallet.Address) { switch p := prop.(type) { case *LedgerChannelProposalMsg: ledgerAcc, ok := acc.(*LedgerChannelProposalAccMsg) @@ -698,7 +704,9 @@ func (c *Client) completeFunding(ctx context.Context, ch *Channel) error { if !c.channels.Put(params.ID(), ch) { return errors.New("channel already exists") } - c.wallet.IncrementUsage(params.Parts[ch.machine.Idx()]) + for i, wall := range c.wallet { + wall.IncrementUsage(params.Parts[ch.machine.Idx()][i]) + } return nil } @@ -782,7 +790,7 @@ type version1Cache struct { type cachedUpdate struct { uh UpdateHandler - p map[int]wire.Address + p map[wallet.BackendID]wire.Address m ChannelUpdateProposal } @@ -803,16 +811,8 @@ func (e ChannelFundingError) Error() string { return fmt.Sprintf("channel funding failed: %v", e.Err.Error()) } -func GetPeerMap(peers map[int][]wallet.Address, index int) map[int]wallet.Address { - address := make(map[int]wallet.Address) - for i, p := range peers { - address[i] = p[index] - } - return address -} - -func GetPeerMapWire(peers map[int][]wire.Address, index int) map[int]wire.Address { - address := make(map[int]wire.Address) +func GetPeerMapWire(peers map[wallet.BackendID][]wire.Address, index int) map[wallet.BackendID]wire.Address { + address := make(map[wallet.BackendID]wire.Address) for i, p := range peers { address[i] = p[index] } diff --git a/client/proposal_internal_test.go b/client/proposal_internal_test.go index 467140fc2..1eb9a4568 100644 --- a/client/proposal_internal_test.go +++ b/client/proposal_internal_test.go @@ -16,6 +16,7 @@ package client import ( "math/rand" + "perun.network/go-perun/wallet" "testing" "github.com/pkg/errors" @@ -51,7 +52,7 @@ func TestClient_validTwoPartyProposal(t *testing.T) { tests := []struct { prop *LedgerChannelProposalMsg ourIdx channel.Index - peerAddr map[int]wire.Address + peerAddr map[wallet.BackendID]wire.Address valid bool }{ { @@ -97,7 +98,7 @@ func TestChannelProposal_assertValidNumParts(t *testing.T) { rng := pkgtest.Prng(t) c := NewRandomLedgerChannelProposal(rng) require.NoError(c.assertValidNumParts()) - c.Peers = make([]map[int]wire.Address, channel.MaxNumParts+1) + c.Peers = make([]map[wallet.BackendID]wire.Address, channel.MaxNumParts+1) require.Error(c.assertValidNumParts()) } diff --git a/client/proposalmsgs.go b/client/proposalmsgs.go index a3117148a..e7dbab419 100644 --- a/client/proposalmsgs.go +++ b/client/proposalmsgs.go @@ -114,20 +114,20 @@ type ( // LedgerChannelProposalMsg is a channel proposal for ledger channels. LedgerChannelProposalMsg struct { BaseChannelProposal - Participant map[int]wallet.Address // Proposer's address in the channel. - Peers []map[int]wire.Address // Participants' wire addresses. + Participant map[wallet.BackendID]wallet.Address // Proposer's address in the channel. + Peers []map[wallet.BackendID]wire.Address // Participants' wire addresses. } // SubChannelProposalMsg is a channel proposal for subchannels. SubChannelProposalMsg struct { BaseChannelProposal - Parent map[int]channel.ID + Parent map[wallet.BackendID]channel.ID } ) // proposalPeers returns the wire addresses of a proposed channel's // participants. -func (c *Client) proposalPeers(p ChannelProposal) (peers []map[int]wire.Address) { +func (c *Client) proposalPeers(p ChannelProposal) (peers []map[wallet.BackendID]wire.Address) { switch prop := p.(type) { case *LedgerChannelProposalMsg: peers = prop.Peers @@ -230,7 +230,7 @@ func (p *BaseChannelProposal) Valid() error { // Accept constructs an accept message that belongs to a proposal message. It // should be used instead of manually constructing an accept message. func (p LedgerChannelProposalMsg) Accept( - participant map[int]wallet.Address, + participant map[wallet.BackendID]wallet.Address, nonceShare ProposalOpts, ) *LedgerChannelProposalAccMsg { if !nonceShare.isNonce() { @@ -259,9 +259,9 @@ func (LedgerChannelProposalMsg) Matches(acc ChannelProposalAccept) bool { // For more information, see ProposalOpts. func NewLedgerChannelProposal( challengeDuration uint64, - participant map[int]wallet.Address, + participant map[wallet.BackendID]wallet.Address, initBals *channel.Allocation, - peers []map[int]wire.Address, + peers []map[wallet.BackendID]wire.Address, opts ...ProposalOpts, ) (prop *LedgerChannelProposalMsg, err error) { prop = &LedgerChannelProposalMsg{ @@ -326,7 +326,7 @@ func (p LedgerChannelProposalMsg) Valid() error { // NewSubChannelProposal creates a subchannel proposal and applies the // supplied options. For more information, see ProposalOpts. func NewSubChannelProposal( - parent map[int]channel.ID, + parent map[wallet.BackendID]channel.ID, challengeDuration uint64, initBals *channel.Allocation, opts ...ProposalOpts, @@ -404,7 +404,7 @@ type ( // each channel instantiation. LedgerChannelProposalAccMsg struct { BaseChannelProposalAcc - Participant map[int]wallet.Address // Responder's participant address. + Participant map[wallet.BackendID]wallet.Address // Responder's participant address. } // SubChannelProposalAccMsg is the accept message type corresponding to sub @@ -517,27 +517,27 @@ type ( // VirtualChannelProposalMsg is a channel proposal for virtual channels. VirtualChannelProposalMsg struct { BaseChannelProposal - Proposer map[int]wallet.Address // Proposer's address in the channel. - Peers []map[int]wire.Address // Participants' wire addresses. - Parents []map[int]channel.ID // Parent channels for each participant. - IndexMaps [][]channel.Index // Index mapping for each participant in relation to the root channel. + Proposer map[wallet.BackendID]wallet.Address // Proposer's address in the channel. + Peers []map[wallet.BackendID]wire.Address // Participants' wire addresses. + Parents []map[wallet.BackendID]channel.ID // Parent channels for each participant. + IndexMaps [][]channel.Index // Index mapping for each participant in relation to the root channel. } // VirtualChannelProposalAccMsg is the accept message type corresponding to // virtual channel proposals. VirtualChannelProposalAccMsg struct { BaseChannelProposalAcc - Responder map[int]wallet.Address // Responder's participant address. + Responder map[wallet.BackendID]wallet.Address // Responder's participant address. } ) // NewVirtualChannelProposal creates a virtual channel proposal. func NewVirtualChannelProposal( challengeDuration uint64, - participant map[int]wallet.Address, + participant map[wallet.BackendID]wallet.Address, initBals *channel.Allocation, - peers []map[int]wire.Address, - parents []map[int]channel.ID, + peers []map[wallet.BackendID]wire.Address, + parents []map[wallet.BackendID]channel.ID, indexMaps [][]channel.Index, opts ...ProposalOpts, ) (prop *VirtualChannelProposalMsg, err error) { @@ -590,7 +590,7 @@ func (VirtualChannelProposalMsg) Type() wire.Type { // Accept constructs an accept message that belongs to a proposal message. func (p VirtualChannelProposalMsg) Accept( - responder map[int]wallet.Address, + responder map[wallet.BackendID]wallet.Address, opts ...ProposalOpts, ) *VirtualChannelProposalAccMsg { _opts := union(opts...) diff --git a/client/restore.go b/client/restore.go index be4d3262d..873814039 100644 --- a/client/restore.go +++ b/client/restore.go @@ -16,6 +16,7 @@ package client import ( "context" + "perun.network/go-perun/wallet" "github.com/pkg/errors" @@ -24,7 +25,7 @@ import ( "perun.network/go-perun/wire" ) -type channelFromSourceSig = func(*Client, *persistence.Channel, *Channel, ...map[int]wire.Address) (*Channel, error) +type channelFromSourceSig = func(*Client, *persistence.Channel, *Channel, ...map[wallet.BackendID]wire.Address) (*Channel, error) // clientChannelFromSource is the production behaviour of reconstructChannel. // During testing, it is replaced by a simpler function that needs much less @@ -33,7 +34,7 @@ func clientChannelFromSource( c *Client, ch *persistence.Channel, parent *Channel, - peers ...map[int]wire.Address, + peers ...map[wallet.BackendID]wire.Address, ) (*Channel, error) { return c.channelFromSource(ch, parent, peers) } @@ -66,7 +67,7 @@ func (c *Client) reconstructChannel( return ch } -func (c *Client) restorePeerChannels(ctx context.Context, p map[int]wire.Address) (err error) { +func (c *Client) restorePeerChannels(ctx context.Context, p map[wallet.BackendID]wire.Address) (err error) { it, err := c.pr.RestorePeer(p) if err != nil { return errors.WithMessagef(err, "restoring channels for peer: %v", err) diff --git a/client/restore_internal_test.go b/client/restore_internal_test.go index 1d1ba37f1..f3f097534 100644 --- a/client/restore_internal_test.go +++ b/client/restore_internal_test.go @@ -36,10 +36,10 @@ func patchChFromSource( c *Client, ch *persistence.Channel, parent *Channel, - peers ...map[int]wire.Address, + peers ...map[wallet.BackendID]wire.Address, ) (*Channel, error) { - acc, _ := wallettest.RandomWallet().Unlock(ch.ParamsV.Parts[ch.IdxV]) - machine, _ := channel.NewStateMachine(acc, *ch.ParamsV) + acc, _ := wallettest.RandomWallet().Unlock(ch.ParamsV.Parts[ch.IdxV][0]) + machine, _ := channel.NewStateMachine(map[wallet.BackendID]wallet.Account{0: acc}, *ch.ParamsV) pmachine := persistence.FromStateMachine(machine, nil) _ch := &Channel{parent: parent, machine: pmachine, OnCloser: new(sync.Closer)} @@ -109,9 +109,9 @@ func TestRestoreChannelCollection(t *testing.T) { // mkRndChan creates a single random channel. func mkRndChan(rng *rand.Rand) *persistence.Channel { - parts := make([]map[int]wallet.Address, channel.MaxNumParts) + parts := make([]map[wallet.BackendID]wallet.Address, channel.MaxNumParts) for i := range parts { - parts[i] = wallettest.NewRandomAccount(rng).Address() + parts[i] = map[wallet.BackendID]wallet.Address{0: wallettest.NewRandomAccount(rng).Address()} } ch := persistence.NewChannel() ch.IdxV = channel.Index(rng.Intn(channel.MaxNumParts)) @@ -142,7 +142,7 @@ func mkRndChanTree( } for i := 0; i < children; i++ { t := mkRndChanTree(rng, depth-1, minChildren, maxChildren-1, db) - t.Parent = &map[int]channel.ID{0: *new(channel.ID)} + t.Parent = &map[wallet.BackendID]channel.ID{0: *new(channel.ID)} *t.Parent = root.ID() } } diff --git a/client/serialize.go b/client/serialize.go index 00054836e..6278deaa1 100644 --- a/client/serialize.go +++ b/client/serialize.go @@ -16,6 +16,7 @@ package client import ( "io" + "perun.network/go-perun/wallet" "github.com/pkg/errors" "perun.network/go-perun/channel" @@ -24,7 +25,7 @@ import ( type ( sliceLen = uint16 - channelIDsWithLen []map[int]channel.ID + channelIDsWithLen []map[wallet.BackendID]channel.ID indexMapWithLen []channel.Index indexMapsWithLen [][]channel.Index ) @@ -49,7 +50,7 @@ func (a *channelIDsWithLen) Decode(r io.Reader) (err error) { if err := perunio.Decode(r, &mapLen); err != nil { return errors.WithMessage(err, "decoding array length") } - *a = make([]map[int]channel.ID, mapLen) + *a = make([]map[wallet.BackendID]channel.ID, mapLen) for i := 0; i < int(mapLen); i++ { if err := perunio.Decode(r, (*channel.IDMap)(&(*a)[i])); err != nil { return errors.WithMessagef(err, "decoding %d-th id map entry", i) diff --git a/client/subchannel.go b/client/subchannel.go index 458e372a7..c5724409f 100644 --- a/client/subchannel.go +++ b/client/subchannel.go @@ -16,6 +16,7 @@ package client import ( "context" + "perun.network/go-perun/wallet" "github.com/pkg/errors" @@ -47,7 +48,7 @@ func (c *Channel) equalParticipants(_c *Channel) bool { return true } -func (c *Channel) fundSubChannel(ctx context.Context, id map[int]channel.ID, alloc *channel.Allocation) error { +func (c *Channel) fundSubChannel(ctx context.Context, id map[wallet.BackendID]channel.ID, alloc *channel.Allocation) error { // We assume that the channel is locked. return c.update(ctx, func(state *channel.State) error { // equal assets and sufficient balances are already checked when validating the sub-channel proposal @@ -119,7 +120,7 @@ func (c *Channel) withdrawSubChannel(ctx context.Context, sub *Channel) error { return errors.WithMessage(err, "update parent channel") } -func (c *Channel) registerSubChannelFunding(id map[int]channel.ID, alloc []channel.Bal) { +func (c *Channel) registerSubChannelFunding(id map[wallet.BackendID]channel.ID, alloc []channel.Bal) { filter := func(cu ChannelUpdate) bool { expected := *channel.NewSubAlloc(id, alloc, nil) _, containedBefore := c.machine.State().SubAlloc(expected.ID) @@ -130,7 +131,7 @@ func (c *Channel) registerSubChannelFunding(id map[int]channel.ID, alloc []chann c.subChannelFundings.Register(id, ui) } -func (c *Channel) registerSubChannelSettlement(id map[int]channel.ID, bals [][]channel.Bal) { +func (c *Channel) registerSubChannelSettlement(id map[wallet.BackendID]channel.ID, bals [][]channel.Bal) { filter := func(cu ChannelUpdate) bool { _, containedBefore := c.machine.State().SubAlloc(id) _, containedAfter := cu.State.SubAlloc(id) @@ -142,15 +143,15 @@ func (c *Channel) registerSubChannelSettlement(id map[int]channel.ID, bals [][]c c.subChannelWithdrawals.Register(id, ui) } -func (c *Channel) awaitSubChannelFunding(ctx context.Context, id map[int]channel.ID) error { +func (c *Channel) awaitSubChannelFunding(ctx context.Context, id map[wallet.BackendID]channel.ID) error { return c.awaitSubChannelUpdate(ctx, id, c.subChannelFundings) } -func (c *Channel) awaitSubChannelWithdrawal(ctx context.Context, id map[int]channel.ID) error { +func (c *Channel) awaitSubChannelWithdrawal(ctx context.Context, id map[wallet.BackendID]channel.ID) error { return c.awaitSubChannelUpdate(ctx, id, c.subChannelWithdrawals) } -func (c *Channel) awaitSubChannelUpdate(ctx context.Context, id map[int]channel.ID, interceptors *updateInterceptors) error { +func (c *Channel) awaitSubChannelUpdate(ctx context.Context, id map[wallet.BackendID]channel.ID, interceptors *updateInterceptors) error { ui, ok := interceptors.UpdateInterceptor(id) if !ok { diff --git a/client/subchannel_test.go b/client/subchannel_test.go index 93005760e..dcaef6225 100644 --- a/client/subchannel_test.go +++ b/client/subchannel_test.go @@ -17,6 +17,7 @@ package client_test import ( "context" "math/big" + "perun.network/go-perun/wallet" "testing" "perun.network/go-perun/apps/payment" @@ -38,8 +39,9 @@ func TestSubChannelHappy(t *testing.T) { cfg := ctest.NewSusieTimExecConfig( ctest.MakeBaseExecConfig( - [2]map[int]wire.Address{setups[0].Identity.Address(), setups[1].Identity.Address()}, + [2]map[wallet.BackendID]wire.Address{wire.AddressMapfromAccountMap(setups[0].Identity), wire.AddressMapfromAccountMap(setups[1].Identity)}, chtest.NewRandomAsset(rng), + 0, [2]*big.Int{big.NewInt(100), big.NewInt(100)}, client.WithoutApp(), ), @@ -75,8 +77,9 @@ func TestSubChannelDispute(t *testing.T) { } baseCfg := ctest.MakeBaseExecConfig( - [2]map[int]wire.Address{setups[0].Identity.Address(), setups[1].Identity.Address()}, + [2]map[wallet.BackendID]wire.Address{wire.AddressMapfromAccountMap(setups[0].Identity), wire.AddressMapfromAccountMap(setups[1].Identity)}, chtest.NewRandomAsset(rng), + 0, [2]*big.Int{big.NewInt(100), big.NewInt(100)}, client.WithoutApp(), ) diff --git a/client/sync.go b/client/sync.go index 263358a3b..b30dc520c 100644 --- a/client/sync.go +++ b/client/sync.go @@ -17,6 +17,7 @@ package client import ( "context" "log" + "perun.network/go-perun/wallet" "time" "github.com/pkg/errors" @@ -32,7 +33,7 @@ var syncReplyTimeout = 10 * time.Second // exists, it just sends the current channel data to the requester. If the // own channel is in the Signing phase, the ongoing update is discarded so that // the channel is reverted to the Acting phase. -func (c *Client) handleSyncMsg(peer map[int]wire.Address, msg *ChannelSyncMsg) { +func (c *Client) handleSyncMsg(peer map[wallet.BackendID]wire.Address, msg *ChannelSyncMsg) { log := c.logChan(msg.ID()).WithField("peer", peer) ch, ok := c.channels.Channel(msg.ID()) if !ok { @@ -68,7 +69,7 @@ func (c *Client) handleSyncMsg(peer map[int]wire.Address, msg *ChannelSyncMsg) { // syncChannel synchronizes the channel state with the given peer and modifies // the current state if required. // nolint:unused -func (c *Client) syncChannel(ctx context.Context, ch *persistence.Channel, p map[int]wire.Address) (err error) { +func (c *Client) syncChannel(ctx context.Context, ch *persistence.Channel, p map[wallet.BackendID]wire.Address) (err error) { recv := wire.NewReceiver() defer recv.Close() // ignore error id := ch.ID() @@ -135,12 +136,14 @@ func validateMessage(ch *persistence.Channel, msg *ChannelSyncMsg) error { return errors.New("sigs length mismatch") } for i, sig := range msg.CurrentTX.Sigs { - ok, err := channel.Verify(ch.Params().Parts[i], msg.CurrentTX.State, sig) - if err != nil { - return errors.WithMessagef(err, "validating sig %d", i) - } - if !ok { - return errors.Errorf("invalid sig %d", i) + for _, p := range ch.Params().Parts[i] { + ok, err := channel.Verify(p, msg.CurrentTX.State, sig) + if err != nil { + return errors.WithMessagef(err, "validating sig %d", i) + } + if !ok { + return errors.Errorf("invalid sig %d", i) + } } } } diff --git a/client/syncmsgs.go b/client/syncmsgs.go index 365eee3a4..b2ee38e99 100644 --- a/client/syncmsgs.go +++ b/client/syncmsgs.go @@ -16,6 +16,7 @@ package client import ( "io" + "perun.network/go-perun/wallet" "perun.network/go-perun/channel" "perun.network/go-perun/wire" @@ -61,7 +62,7 @@ func (m *ChannelSyncMsg) Decode(r io.Reader) error { } // ID returns the channel's ID. -func (m *ChannelSyncMsg) ID() map[int]channel.ID { +func (m *ChannelSyncMsg) ID() map[wallet.BackendID]channel.ID { return m.CurrentTX.ID } diff --git a/client/test/backend.go b/client/test/backend.go index 08ef3f2ac..00fd22e99 100644 --- a/client/test/backend.go +++ b/client/test/backend.go @@ -191,7 +191,7 @@ func (b *MockBackend) Register(_ context.Context, req channel.AdjudicatorReq, su return nil } -func (b *MockBackend) setLatestEvent(ch map[int]channel.ID, e channel.AdjudicatorEvent) { +func (b *MockBackend) setLatestEvent(ch map[wallet.BackendID]channel.ID, e channel.AdjudicatorEvent) { b.latestEvents[channel.IDKey(ch)] = e // Update subscriptions. if channelSubs, ok := b.eventSubs[channel.IDKey(ch)]; ok { @@ -346,7 +346,7 @@ func (b *MockBackend) Withdraw(_ context.Context, req channel.AdjudicatorReq, su return nil } -func (b *MockBackend) isConcluded(ch map[int]channel.ID) bool { +func (b *MockBackend) isConcluded(ch map[wallet.BackendID]channel.ID) bool { e, ok := b.latestEvents[channel.IDKey(ch)] if !ok { return false @@ -442,7 +442,7 @@ func (b *MockBackend) setBalance(p wallet.Address, a channel.Asset, v *big.Int) } // Subscribe creates an event subscription. -func (b *MockBackend) Subscribe(ctx context.Context, chID map[int]channel.ID) (channel.AdjudicatorSubscription, error) { +func (b *MockBackend) Subscribe(ctx context.Context, chID map[wallet.BackendID]channel.ID) (channel.AdjudicatorSubscription, error) { b.log.Infof("SubscribeRegistered: %+v", chID) b.mu.Lock() @@ -460,7 +460,7 @@ func (b *MockBackend) Subscribe(ctx context.Context, chID map[int]channel.ID) (c return sub, nil } -func (b *MockBackend) removeSubscription(ch map[int]channel.ID, sub *MockSubscription) { +func (b *MockBackend) removeSubscription(ch map[wallet.BackendID]channel.ID, sub *MockSubscription) { b.mu.Lock() defer b.mu.Unlock() diff --git a/client/test/channel.go b/client/test/channel.go index ff023626b..336f201df 100644 --- a/client/test/channel.go +++ b/client/test/channel.go @@ -19,6 +19,7 @@ import ( "errors" "io" "math/big" + "perun.network/go-perun/wallet" "time" "perun.network/go-perun/channel" @@ -67,7 +68,8 @@ func (ch *paymentChannel) openSubChannel( ) *paymentChannel { initAlloc := channel.Allocation{ Assets: []channel.Asset{cfg.Asset()}, - Balances: [][]channel.Bal{[]*big.Int{initBals[0], initBals[1]}}, + Backends: []wallet.BackendID{0}, + Balances: [][]channel.Bal{{initBals[0], initBals[1]}}, } prop := ch.r.SubChannelProposal(rng, cfg, ch.Channel, &initAlloc, app) diff --git a/client/test/fund.go b/client/test/fund.go index 788585253..a57190984 100644 --- a/client/test/fund.go +++ b/client/test/fund.go @@ -19,6 +19,7 @@ import ( "errors" "math/big" "math/rand" + "perun.network/go-perun/wallet" "testing" "github.com/stretchr/testify/assert" @@ -92,7 +93,7 @@ func runFredFridaTest( clients := NewClients(t, rng, setups[:]) frida, fred := clients[fridaIdx], clients[fredIdx] - fridaWireAddr, fredWireAddr := frida.Identity.Address(), fred.Identity.Address() + fridaWireAddr, fredWireAddr := wire.AddressMapfromAccountMap(frida.Identity), wire.AddressMapfromAccountMap(fred.Identity) fridaWalletAddr, fredWalletAddr := frida.WalletAddress, fred.WalletAddress // Store client balances before running test. @@ -113,9 +114,9 @@ func runFredFridaTest( ) // Create the proposal. - initAlloc := channel.NewAllocation(numParts, []int{0}, asset) + initAlloc := channel.NewAllocation(numParts, []wallet.BackendID{0}, asset) initAlloc.SetAssetBalances(asset, []*big.Int{fridaInitBal, fredInitBal}) - parts := []map[int]wire.Address{fridaWireAddr, fredWireAddr} + parts := []map[wallet.BackendID]wire.Address{fridaWireAddr, fredWireAddr} prop, err := client.NewLedgerChannelProposal( challengeDuration, fridaWalletAddr, diff --git a/client/test/handler.go b/client/test/handler.go index 4f25bc318..0dbe2ec99 100644 --- a/client/test/handler.go +++ b/client/test/handler.go @@ -26,7 +26,7 @@ import ( // AlwaysAcceptChannelHandler returns a channel proposal handler that accepts // all channel proposals. -func AlwaysAcceptChannelHandler(ctx context.Context, addr map[int]wallet.Address, channels chan *client.Channel, errs chan<- error) client.ProposalHandlerFunc { +func AlwaysAcceptChannelHandler(ctx context.Context, addr map[wallet.BackendID]wallet.Address, channels chan *client.Channel, errs chan<- error) client.ProposalHandlerFunc { return func(cp client.ChannelProposal, pr *client.ProposalResponder) { switch cp := cp.(type) { case *client.LedgerChannelProposalMsg: diff --git a/client/test/multiledger.go b/client/test/multiledger.go index 53833f22a..66669c23c 100644 --- a/client/test/multiledger.go +++ b/client/test/multiledger.go @@ -143,8 +143,8 @@ func (a *MultiLedgerAsset) UnmarshalBinary(data []byte) error { // MultiLedgerClient represents a test client. type MultiLedgerClient struct { *client.Client - WireAddress map[int]wire.Address - WalletAddress map[int]wallet.Address + WireAddress map[wallet.BackendID]wire.Address + WalletAddress map[wallet.BackendID]wallet.Address Events chan channel.AdjudicatorEvent Adjudicator1, Adjudicator2 channel.Adjudicator BalanceReader1, BalanceReader2 BalanceReader @@ -172,17 +172,13 @@ func setupClient( // Setup funder. funder := multi.NewFunder() - for _, add := range acc.Address() { - funder.RegisterFunder(l1.ID(), l1.NewFunder(add)) - funder.RegisterFunder(l2.ID(), l2.NewFunder(add)) - } + funder.RegisterFunder(l1.ID(), l1.NewFunder(acc.Address())) + funder.RegisterFunder(l2.ID(), l2.NewFunder(acc.Address())) // Setup adjudicator. adj := multi.NewAdjudicator() - for _, add := range acc.Address() { - adj.RegisterAdjudicator(l1.ID(), l1.NewAdjudicator(add)) - adj.RegisterAdjudicator(l2.ID(), l2.NewAdjudicator(add)) - } + adj.RegisterAdjudicator(l1.ID(), l1.NewAdjudicator(acc.Address())) + adj.RegisterAdjudicator(l2.ID(), l2.NewAdjudicator(acc.Address())) // Setup watcher. watcher, err := local.NewWatcher(adj) @@ -193,7 +189,7 @@ func setupClient( bus, funder, adj, - w, + map[wallet.BackendID]wallet.Wallet{0: w}, watcher, ) require.NoError(err) @@ -201,11 +197,11 @@ func setupClient( return MultiLedgerClient{ Client: c, WireAddress: wireAddr[0], - WalletAddress: acc.Address(), + WalletAddress: map[wallet.BackendID]wallet.Address{0: acc.Address()}, Events: make(chan channel.AdjudicatorEvent), - Adjudicator1: l1.NewAdjudicator(acc.Address()[0]), - Adjudicator2: l2.NewAdjudicator(acc.Address()[0]), - BalanceReader1: l1.NewBalanceReader(acc.Address()[0]), - BalanceReader2: l2.NewBalanceReader(acc.Address()[0]), + Adjudicator1: l1.NewAdjudicator(acc.Address()), + Adjudicator2: l2.NewAdjudicator(acc.Address()), + BalanceReader1: l1.NewBalanceReader(acc.Address()), + BalanceReader2: l2.NewBalanceReader(acc.Address()), } } diff --git a/client/test/multiledger_dispute.go b/client/test/multiledger_dispute.go index 036b69ec4..97456ba8e 100644 --- a/client/test/multiledger_dispute.go +++ b/client/test/multiledger_dispute.go @@ -17,6 +17,7 @@ package test import ( "context" "math/big" + "perun.network/go-perun/wallet" "testing" "time" @@ -61,8 +62,8 @@ func TestMultiLedgerDispute( // Establish ledger channel between Alice and Bob. // Create channel proposal. - parts := []map[int]wire.Address{alice.WireAddress, bob.WireAddress} - initAlloc := channel.NewAllocation(len(parts), []int{0}, mlt.Asset1, mlt.Asset2) + parts := []map[wallet.BackendID]wire.Address{alice.WireAddress, bob.WireAddress} + initAlloc := channel.NewAllocation(len(parts), []wallet.BackendID{0, 0}, mlt.Asset1, mlt.Asset2) initAlloc.Balances = initBals prop, err := client.NewLedgerChannelProposal( challengeDuration, diff --git a/client/test/multiledger_happy.go b/client/test/multiledger_happy.go index be01fa7ef..7539ea454 100644 --- a/client/test/multiledger_happy.go +++ b/client/test/multiledger_happy.go @@ -16,6 +16,7 @@ package test import ( "context" + "perun.network/go-perun/wallet" "testing" "github.com/stretchr/testify/require" @@ -41,8 +42,8 @@ func TestMultiLedgerHappy(ctx context.Context, t *testing.T, mlt MultiLedgerSetu // Establish ledger channel between Alice and Bob. // Create channel proposal. - parts := []map[int]wire.Address{alice.WireAddress, bob.WireAddress} - initAlloc := channel.NewAllocation(len(parts), []int{int(mlt.Asset1.AssetID().BackendID), int(mlt.Asset2.AssetID().BackendID)}, mlt.Asset1, mlt.Asset2) + parts := []map[wallet.BackendID]wire.Address{alice.WireAddress, bob.WireAddress} + initAlloc := channel.NewAllocation(len(parts), []wallet.BackendID{wallet.BackendID(mlt.Asset1.AssetID().BackendID), wallet.BackendID(mlt.Asset2.AssetID().BackendID)}, mlt.Asset1, mlt.Asset2) initAlloc.Balances = initBals prop, err := client.NewLedgerChannelProposal( challengeDuration, diff --git a/client/test/persistence.go b/client/test/persistence.go index 30ecf37ed..aadfb6d5a 100644 --- a/client/test/persistence.go +++ b/client/test/persistence.go @@ -17,6 +17,7 @@ package test import ( "context" "math/big" + "perun.network/go-perun/wallet" "testing" "time" @@ -45,7 +46,11 @@ const ( // ReplaceClient replaces the client instance of the Role. Useful for // persistence testing. func (r *multiClientRole) ReplaceClient() { - cl, err := client.New(r.setup.Identity.Address(), r.setup.Bus, r.setup.Funder, r.setup.Adjudicator, r.setup.Wallet, r.setup.Watcher) + setupWallet := make(map[wallet.BackendID]wallet.Wallet) + for i, w := range r.setup.Wallet { + setupWallet[i] = w + } + cl, err := client.New(wire.AddressMapfromAccountMap(r.setup.Identity), r.setup.Bus, r.setup.Funder, r.setup.Adjudicator, setupWallet, r.setup.Watcher) r.RequireNoErrorf(err, "recreating client") r.setClient(cl) } @@ -214,9 +219,9 @@ func (r *multiClientRole) Errors() <-chan error { return r.errs } -type addresses []map[int]wire.Address +type addresses []map[wallet.BackendID]wire.Address -func (a addresses) contains(b map[int]wire.Address) bool { +func (a addresses) contains(b map[wallet.BackendID]wire.Address) bool { for _, addr := range a { if channel.EqualWireMaps(addr, b) { return true diff --git a/client/test/randomproposal.go b/client/test/randomproposal.go index da7d198cd..a7280ac13 100644 --- a/client/test/randomproposal.go +++ b/client/test/randomproposal.go @@ -36,7 +36,7 @@ func NewRandomLedgerChannelProposal(rng *rand.Rand, opts ...client.ProposalOpts) // NewRandomLedgerChannelProposalBy creates a random channel proposal with the // supplied options and proposer. Number of participants is fixed to // randomProposalNumParts. -func NewRandomLedgerChannelProposalBy(rng *rand.Rand, proposer map[int]wallet.Address, opts ...client.ProposalOpts) *client.LedgerChannelProposalMsg { +func NewRandomLedgerChannelProposalBy(rng *rand.Rand, proposer map[wallet.BackendID]wallet.Address, opts ...client.ProposalOpts) *client.LedgerChannelProposalMsg { prop, err := client.NewLedgerChannelProposal( rng.Uint64(), proposer, diff --git a/client/test/role.go b/client/test/role.go index 435fca989..aa00d6ce8 100644 --- a/client/test/role.go +++ b/client/test/role.go @@ -70,12 +70,12 @@ type ( // RoleSetup contains the injectables for setting up the client. RoleSetup struct { Name string - Identity wire.Account + Identity map[wallet.BackendID]wire.Account Bus wire.Bus Funder channel.Funder Adjudicator channel.Adjudicator Watcher watcher.Watcher - Wallet wallettest.Wallet + Wallet map[wallet.BackendID]wallettest.Wallet PR persistence.PersistRestorer // Optional PersistRestorer Timeout time.Duration // Timeout waiting for other role, not challenge duration BalanceReader BalanceReader @@ -85,18 +85,20 @@ type ( // ExecConfig contains additional config parameters for the tests. ExecConfig interface { - Peers() [2]map[int]wire.Address // must match the RoleSetup.Identity's - Asset() channel.Asset // single Asset to use in this channel - InitBals() [2]*big.Int // channel deposit of each role - App() client.ProposalOpts // must be either WithApp or WithoutApp + Peers() [2]map[wallet.BackendID]wire.Address // must match the RoleSetup.Identity's + Asset() channel.Asset // single Asset to use in this channel + Backend() wallet.BackendID // backend corresponding to asset + InitBals() [2]*big.Int // channel deposit of each role + App() client.ProposalOpts // must be either WithApp or WithoutApp } // BaseExecConfig contains base config parameters. BaseExecConfig struct { - peers [2]map[int]wire.Address // must match the RoleSetup.Identity's - asset channel.Asset // single Asset to use in this channel - initBals [2]*big.Int // channel deposit of each role - app client.ProposalOpts // must be either WithApp or WithoutApp + peers [2]map[wallet.BackendID]wire.Address // must match the RoleSetup.Identity's + asset channel.Asset // single Asset to use in this channel + backend wallet.BackendID // backend corresponding to asset + initBals [2]*big.Int // channel deposit of each role + app client.ProposalOpts // must be either WithApp or WithoutApp } // An Executer is a Role that can execute a protocol. @@ -118,7 +120,7 @@ type ( Client struct { *client.Client RoleSetup - WalletAddress map[int]wallet.Address + WalletAddress map[wallet.BackendID]wallet.Address } ) @@ -127,12 +129,16 @@ func NewClients(t *testing.T, rng *rand.Rand, setups []RoleSetup) []*Client { t.Helper() clients := make([]*Client, len(setups)) for i, setup := range setups { - cl, err := client.New(setup.Identity.Address(), setup.Bus, setup.Funder, setup.Adjudicator, setup.Wallet, setup.Watcher) + setupWallet := make(map[wallet.BackendID]wallet.Wallet) + for i, w := range setup.Wallet { + setupWallet[i] = w + } + cl, err := client.New(wire.AddressMapfromAccountMap(setup.Identity), setup.Bus, setup.Funder, setup.Adjudicator, setupWallet, setup.Watcher) assert.NoError(t, err) clients[i] = &Client{ Client: cl, RoleSetup: setup, - WalletAddress: setup.Wallet.NewRandomAccount(rng).Address(), + WalletAddress: map[wallet.BackendID]wallet.Address{0: setup.Wallet[0].NewRandomAccount(rng).Address()}, } } return clients @@ -174,21 +180,23 @@ func ExecuteTwoPartyTest(ctx context.Context, t *testing.T, role [2]Executer, cf // MakeBaseExecConfig creates a new BaseExecConfig. func MakeBaseExecConfig( - peers [2]map[int]wire.Address, + peers [2]map[wallet.BackendID]wire.Address, asset channel.Asset, + backend wallet.BackendID, initBals [2]*big.Int, app client.ProposalOpts, ) BaseExecConfig { return BaseExecConfig{ peers: peers, asset: asset, + backend: backend, initBals: initBals, app: app, } } // Peers returns the peer addresses. -func (c *BaseExecConfig) Peers() [2]map[int]wire.Address { +func (c *BaseExecConfig) Peers() [2]map[wallet.BackendID]wire.Address { return c.peers } @@ -197,6 +205,11 @@ func (c *BaseExecConfig) Asset() channel.Asset { return c.asset } +// Asset returns the asset. +func (c *BaseExecConfig) Backend() wallet.BackendID { + return c.backend +} + // InitBals returns the initial balances. func (c *BaseExecConfig) InitBals() [2]*big.Int { return c.initBals @@ -218,8 +231,12 @@ func makeRole(t *testing.T, setup RoleSetup, numStages int) (r role) { numStages: numStages, challengeDuration: setup.ChallengeDuration, } - cl, err := client.New(r.setup.Identity.Address(), - r.setup.Bus, r.setup.Funder, r.setup.Adjudicator, r.setup.Wallet, r.setup.Watcher) + setupWallet := make(map[wallet.BackendID]wallet.Wallet) + for i, w := range r.setup.Wallet { + setupWallet[i] = w + } + cl, err := client.New(wire.AddressMapfromAccountMap(r.setup.Identity), + r.setup.Bus, r.setup.Funder, r.setup.Adjudicator, setupWallet, r.setup.Watcher) if err != nil { t.Fatal("Error creating client: ", err) } @@ -243,7 +260,7 @@ func (r *role) setClient(cl *client.Client) { r.log = log.AppendField(cl, "role", r.setup.Name) } -func (chs *channelMap) channel(ch map[int]channel.ID) (_ch *paymentChannel, ok bool) { +func (chs *channelMap) channel(ch map[wallet.BackendID]channel.ID) (_ch *paymentChannel, ok bool) { chs.RLock() defer chs.RUnlock() _ch, ok = chs.entries[channel.IDKey(ch)] @@ -297,10 +314,10 @@ func (r *role) waitStage() { // Idxs maps the passed addresses to the indices in the 2-party-channel. If the // setup's Identity is not found in peers, Idxs panics. -func (r *role) Idxs(peers [2]map[int]wire.Address) (our, their channel.Index) { - if channel.EqualWireMaps(r.setup.Identity.Address(), peers[0]) { +func (r *role) Idxs(peers [2]map[wallet.BackendID]wire.Address) (our, their channel.Index) { + if channel.EqualWireMaps(wire.AddressMapfromAccountMap(r.setup.Identity), peers[0]) { return 0, 1 - } else if channel.EqualWireMaps(r.setup.Identity.Address(), peers[1]) { + } else if channel.EqualWireMaps(wire.AddressMapfromAccountMap(r.setup.Identity), peers[1]) { return 1, 0 } panic("identity not in peers") @@ -397,12 +414,12 @@ func (r *role) LedgerChannelProposal(rng *rand.Rand, cfg ExecConfig) *client.Led } peers, asset, bals := cfg.Peers(), cfg.Asset(), cfg.InitBals() - alloc := channel.NewAllocation(len(peers), []int{0}, asset) + alloc := channel.NewAllocation(len(peers), []wallet.BackendID{0}, asset) alloc.SetAssetBalances(asset, bals[:]) prop, err := client.NewLedgerChannelProposal( r.challengeDuration, - r.setup.Wallet.NewRandomAccount(rng).Address(), + map[wallet.BackendID]wallet.Address{0: r.setup.Wallet[0].NewRandomAccount(rng).Address()}, alloc, peers[:], client.WithNonceFrom(rng), @@ -471,8 +488,8 @@ func (h *acceptNextPropHandler) Next() (*paymentChannel, error) { var acc client.ChannelProposalAccept switch p := prop.(type) { case *client.LedgerChannelProposalMsg: - part := h.r.setup.Wallet.NewRandomAccount(h.rng).Address() - acc = p.Accept(part, client.WithNonceFrom(h.rng)) + part := h.r.setup.Wallet[0].NewRandomAccount(h.rng).Address() + acc = p.Accept(map[wallet.BackendID]wallet.Address{0: part}, client.WithNonceFrom(h.rng)) h.r.log.Debugf("Accepting ledger channel proposal with participant: %v", part) case *client.SubChannelProposalMsg: diff --git a/client/test/subchannel_dispute.go b/client/test/subchannel_dispute.go index 78640763a..4ee3f6713 100644 --- a/client/test/subchannel_dispute.go +++ b/client/test/subchannel_dispute.go @@ -17,6 +17,7 @@ package test import ( "fmt" "math/big" + "perun.network/go-perun/wallet" "testing" "time" @@ -121,7 +122,7 @@ func (r *DisputeSusie) exec(_cfg ExecConfig, ledgerChannel *paymentChannel) { type DisputeTim struct { Responder registered chan *channel.RegisteredEvent - subCh map[int]channel.ID + subCh map[wallet.BackendID]channel.ID } // time to wait until a parent channel watcher becomes active. diff --git a/client/test/virtualchannel.go b/client/test/virtualchannel.go index 373aa6f5f..4234c0796 100644 --- a/client/test/virtualchannel.go +++ b/client/test/virtualchannel.go @@ -18,6 +18,7 @@ import ( "context" "math/big" "math/rand" + "perun.network/go-perun/wallet" "testing" "time" @@ -217,8 +218,8 @@ func setupVirtualChannelTest( go ingrid.Client.Handle(openingProposalHandlerIngrid, updateProposalHandlerIngrid) // Establish ledger channel between Alice and Ingrid. - peersAlice := []map[int]wire.Address{alice.Identity.Address(), ingrid.Identity.Address()} - initAllocAlice := channel.NewAllocation(len(peersAlice), []int{0}, asset) + peersAlice := []map[wallet.BackendID]wire.Address{wire.AddressMapfromAccountMap(alice.Identity), wire.AddressMapfromAccountMap(ingrid.Identity)} + initAllocAlice := channel.NewAllocation(len(peersAlice), []wallet.BackendID{0}, asset) initAllocAlice.SetAssetBalances(asset, vct.initBalsAlice) lcpAlice, err := client.NewLedgerChannelProposal( setup.ChallengeDuration, @@ -237,8 +238,8 @@ func setupVirtualChannelTest( } // Establish ledger channel between Bob and Ingrid. - peersBob := []map[int]wire.Address{bob.Identity.Address(), ingrid.Identity.Address()} - initAllocBob := channel.NewAllocation(len(peersBob), []int{0}, asset) + peersBob := []map[wallet.BackendID]wire.Address{wire.AddressMapfromAccountMap(bob.Identity), wire.AddressMapfromAccountMap(ingrid.Identity)} + initAllocBob := channel.NewAllocation(len(peersBob), []wallet.BackendID{0}, asset) initAllocBob.SetAssetBalances(asset, vct.initBalsBob) lcpBob, err := client.NewLedgerChannelProposal( setup.ChallengeDuration, @@ -286,6 +287,7 @@ func setupVirtualChannelTest( initAllocVirtual := channel.Allocation{ Assets: []channel.Asset{asset}, Balances: [][]channel.Bal{initBalsVirtual}, + Backends: []wallet.BackendID{0}, } indexMapAlice := []channel.Index{0, 1} indexMapBob := []channel.Index{1, 0} @@ -293,8 +295,8 @@ func setupVirtualChannelTest( setup.ChallengeDuration, alice.WalletAddress, &initAllocVirtual, - []map[int]wire.Address{alice.Identity.Address(), bob.Identity.Address()}, - []map[int]channel.ID{vct.chAliceIngrid.ID(), vct.chBobIngrid.ID()}, + []map[wallet.BackendID]wire.Address{wire.AddressMapfromAccountMap(alice.Identity), wire.AddressMapfromAccountMap(bob.Identity)}, + []map[wallet.BackendID]channel.ID{vct.chAliceIngrid.ID(), vct.chBobIngrid.ID()}, [][]channel.Index{indexMapAlice, indexMapBob}, ) require.NoError(err, "creating virtual channel proposal") diff --git a/client/update.go b/client/update.go index e848b5e42..a6e71a9e7 100644 --- a/client/update.go +++ b/client/update.go @@ -33,7 +33,7 @@ import ( // is unknown, an error is logged. // // This handler is dispatched from the Client.Handle routine. -func (c *Client) handleChannelUpdate(uh UpdateHandler, p map[int]wire.Address, m ChannelUpdateProposal) { +func (c *Client) handleChannelUpdate(uh UpdateHandler, p map[wallet.BackendID]wire.Address, m ChannelUpdateProposal) { ch, ok := c.channels.Channel(m.Base().ID()) if !ok { if !c.cacheVersion1Update(uh, p, m) { @@ -45,7 +45,7 @@ func (c *Client) handleChannelUpdate(uh UpdateHandler, p map[int]wire.Address, m ch.handleUpdateReq(pidx, m, uh) //nolint:contextcheck } -func (c *Client) cacheVersion1Update(uh UpdateHandler, p map[int]wire.Address, m ChannelUpdateProposal) bool { +func (c *Client) cacheVersion1Update(uh UpdateHandler, p map[wallet.BackendID]wire.Address, m ChannelUpdateProposal) bool { c.version1Cache.mu.Lock() defer c.version1Cache.mu.Unlock() diff --git a/client/updateinterception.go b/client/updateinterception.go index c63996625..8f2c51c7d 100644 --- a/client/updateinterception.go +++ b/client/updateinterception.go @@ -16,6 +16,7 @@ package client import ( "context" + "perun.network/go-perun/wallet" "sync" "perun.network/go-perun/channel" @@ -69,7 +70,7 @@ func newUpdateInterceptors() *updateInterceptors { } // Register assigns the given update interceptor to the given channel. -func (interceptors *updateInterceptors) Register(id map[int]channel.ID, ui *updateInterceptor) { +func (interceptors *updateInterceptors) Register(id map[wallet.BackendID]channel.ID, ui *updateInterceptor) { interceptors.Lock() defer interceptors.Unlock() interceptors.entries[channel.IDKey(id)] = ui @@ -77,7 +78,7 @@ func (interceptors *updateInterceptors) Register(id map[int]channel.ID, ui *upda // UpdateInterceptor gets the update interceptor for the given channel. The second return // value indicates whether such an entry could be found. -func (interceptors *updateInterceptors) UpdateInterceptor(id map[int]channel.ID) (*updateInterceptor, bool) { +func (interceptors *updateInterceptors) UpdateInterceptor(id map[wallet.BackendID]channel.ID) (*updateInterceptor, bool) { interceptors.RLock() defer interceptors.RUnlock() ui, ok := interceptors.entries[channel.IDKey(id)] @@ -85,7 +86,7 @@ func (interceptors *updateInterceptors) UpdateInterceptor(id map[int]channel.ID) } // Release releases the update interceptor for the given channel. -func (interceptors *updateInterceptors) Release(id map[int]channel.ID) { +func (interceptors *updateInterceptors) Release(id map[wallet.BackendID]channel.ID) { interceptors.Lock() defer interceptors.Unlock() if ui, ok := interceptors.entries[channel.IDKey(id)]; ok { diff --git a/client/updatemsgs.go b/client/updatemsgs.go index 8fbf64e20..9f42de0b6 100644 --- a/client/updatemsgs.go +++ b/client/updatemsgs.go @@ -56,7 +56,7 @@ type ( // controller. ChannelMsg interface { wire.Msg - ID() map[int]channel.ID + ID() map[wallet.BackendID]channel.ID } channelUpdateResMsg interface { @@ -85,7 +85,7 @@ type ( // signature on the accepted new state by the sender. ChannelUpdateAccMsg struct { // ChannelID is the channel ID. - ChannelID map[int]channel.ID + ChannelID map[wallet.BackendID]channel.ID // Version of the state that is accepted. Version uint64 // Sig is the signature on the proposed new state by the sender. @@ -99,7 +99,7 @@ type ( // Reason should be a UTF-8 encodable string. ChannelUpdateRejMsg struct { // ChannelID is the channel ID. - ChannelID map[int]channel.ID + ChannelID map[wallet.BackendID]channel.ID // Version of the state that is accepted. Version uint64 // Reason states why the sender rejectes the proposed new state. @@ -175,17 +175,17 @@ func (c *ChannelUpdateRejMsg) Decode(r io.Reader) (err error) { } // ID returns the id of the channel this update refers to. -func (c *ChannelUpdateMsg) ID() map[int]channel.ID { +func (c *ChannelUpdateMsg) ID() map[wallet.BackendID]channel.ID { return c.State.ID } // ID returns the id of the channel this update acceptance refers to. -func (c *ChannelUpdateAccMsg) ID() map[int]channel.ID { +func (c *ChannelUpdateAccMsg) ID() map[wallet.BackendID]channel.ID { return c.ChannelID } // ID returns the id of the channel this update rejection refers to. -func (c *ChannelUpdateRejMsg) ID() map[int]channel.ID { +func (c *ChannelUpdateRejMsg) ID() map[wallet.BackendID]channel.ID { return c.ChannelID } @@ -255,7 +255,7 @@ func (m *VirtualChannelFundingProposalMsg) Decode(r io.Reader) (err error) { } m.Initial.Sigs = make([]wallet.Sig, m.Initial.State.NumParts()) - return wallet.DecodeSparseSigs(r, &m.Initial.Sigs, m.Initial.State.Allocation.Backends) + return wallet.DecodeSparseSigs(r, &m.Initial.Sigs) } // Type returns the message type. @@ -293,5 +293,5 @@ func (m *VirtualChannelSettlementProposalMsg) Decode(r io.Reader) (err error) { } m.Final.Sigs = make([]wallet.Sig, m.Final.State.NumParts()) - return wallet.DecodeSparseSigs(r, &m.Final.Sigs, m.Final.State.Allocation.Backends) + return wallet.DecodeSparseSigs(r, &m.Final.Sigs) } diff --git a/client/virtual_channel.go b/client/virtual_channel.go index ca19002ed..36b6feed1 100644 --- a/client/virtual_channel.go +++ b/client/virtual_channel.go @@ -150,10 +150,10 @@ func (c *Channel) watchVirtual() error { // dummyAcount represents an address but cannot be used for signing. type dummyAccount struct { - address map[int]wallet.Address + address wallet.Address } -func (a *dummyAccount) Address() map[int]wallet.Address { +func (a *dummyAccount) Address() wallet.Address { return a.address } @@ -163,14 +163,18 @@ func (a *dummyAccount) SignData([]byte) ([]byte, error) { const hubIndex = 0 // The hub's index in a virtual channel machine. -func (c *Client) persistVirtualChannel(ctx context.Context, parent *Channel, peers []map[int]wire.Address, params channel.Params, state channel.State, sigs []wallet.Sig) (*Channel, error) { +func (c *Client) persistVirtualChannel(ctx context.Context, parent *Channel, peers []map[wallet.BackendID]wire.Address, params channel.Params, state channel.State, sigs []wallet.Sig) (*Channel, error) { cID := params.ID() if _, err := c.Channel(cID); err == nil { return nil, errors.New("channel already exists") } // We use a dummy account because we don't have the keys to the account. - ch, err := c.newChannel(&dummyAccount{params.Parts[hubIndex]}, parent, peers, params) + accs := make(map[wallet.BackendID]wallet.Account) + for i, part := range params.Parts[hubIndex] { + accs[i] = &dummyAccount{part} + } + ch, err := c.newChannel(accs, parent, peers, params) if err != nil { return nil, err } @@ -249,15 +253,17 @@ func (c *Client) validateVirtualChannelFundingProposal( // Validate signatures. for i, sig := range prop.Initial.Sigs { - ok, err := channel.Verify( - prop.Initial.Params.Parts[i], - prop.Initial.State, - sig, - ) - if err != nil { - return err - } else if !ok { - return errors.New("invalid signature") + for _, part := range prop.Initial.Params.Parts[i] { + ok, err := channel.Verify( + part, + prop.Initial.State, + sig, + ) + if err != nil { + return err + } else if !ok { + return errors.New("invalid signature") + } } } @@ -379,8 +385,8 @@ func (c *Client) gatherChannels(props ...*VirtualChannelFundingProposalMsg) ([]* return channels, nil } -func (c *Client) gatherPeers(channels ...*Channel) (peers []map[int]wire.Address) { - peers = make([]map[int]wire.Address, len(channels)) +func (c *Client) gatherPeers(channels ...*Channel) (peers []map[wallet.BackendID]wire.Address) { + peers = make([]map[wallet.BackendID]wire.Address, len(channels)) for i, ch := range channels { chPeers := ch.Peers() if len(chPeers) != gatherNumPeers { diff --git a/client/virtual_channel_settlement.go b/client/virtual_channel_settlement.go index 1e2b91035..3100b2d12 100644 --- a/client/virtual_channel_settlement.go +++ b/client/virtual_channel_settlement.go @@ -105,15 +105,17 @@ func (c *Client) validateVirtualChannelSettlementProposal( // Validate signatures. for i, sig := range prop.Final.Sigs { - ok, err := channel.Verify( - prop.Final.Params.Parts[i], - prop.Final.State, - sig, - ) - if err != nil { - return err - } else if !ok { - return errors.New("invalid signature") + for _, p := range prop.Final.Params.Parts[i] { + ok, err := channel.Verify( + p, + prop.Final.State, + sig, + ) + if err != nil { + return err + } else if !ok { + return errors.New("invalid signature") + } } } diff --git a/wallet/account.go b/wallet/account.go index d1863f57a..2785bf55d 100644 --- a/wallet/account.go +++ b/wallet/account.go @@ -17,7 +17,7 @@ package wallet // Account represents a single account. type Account interface { // Address used by this account. - Address() map[int]Address + Address() Address // SignData requests a signature from this account. // It returns the signature or an error. diff --git a/wallet/address.go b/wallet/address.go index 8beeb9ae6..e30c6648f 100644 --- a/wallet/address.go +++ b/wallet/address.go @@ -17,7 +17,6 @@ package wallet import ( "bytes" "encoding" - "encoding/binary" "fmt" stdio "io" "strings" @@ -28,6 +27,9 @@ import ( "perun.network/go-perun/wire/perunio" ) +// BackendID is a unique identifier for a backend. +type BackendID int + // Address represents a identifier used in a cryptocurrency. // It is dependent on the currency and needs to be implemented for every blockchain. type Address interface { @@ -44,12 +46,26 @@ type Address interface { // must be equivalent to checking `Address.Cmp(Address) == 0`. Equal(Address) bool // BackendID returns the id of the backend that created this address. - BackendID() int + BackendID() BackendID +} + +// IndexOfAddr returns the index of the given address in the address slice, +// or -1 if it is not part of the slice. +func IndexOfAddr(addrs []map[BackendID]Address, addr Address) int { + for i, as := range addrs { + for _, a := range as { + if a.Equal(addr) { + return i + } + } + } + + return -1 } // IndexOfAddr returns the index of the given address in the address slice, // or -1 if it is not part of the slice. -func IndexOfAddr(addrs []map[int]Address, addr map[int]Address) int { +func IndexOfAddrs(addrs []map[BackendID]Address, addr map[BackendID]Address) int { for i, as := range addrs { for j, a := range as { if a.Equal(addr[j]) { @@ -90,8 +106,8 @@ func CloneAddresses(as []Address) []Address { // CloneAddressesMap returns a clone of a map of Addresses using their binary // marshaling implementation. It panics if an error occurs during binary // (un)marshaling. -func CloneAddressesMap(as map[int]Address) map[int]Address { - clones := make(map[int]Address) +func CloneAddressesMap(as map[BackendID]Address) map[BackendID]Address { + clones := make(map[BackendID]Address) for i, a := range as { clones[i] = CloneAddress(a) } @@ -100,17 +116,15 @@ func CloneAddressesMap(as map[int]Address) map[int]Address { // AddressMapArray is a helper type for encoding and decoding arrays of address maps. type AddressMapArray struct { - Addr []map[int]Address + Addr []map[BackendID]Address } // AddressDecMap is a helper type for encoding and decoding address maps. -type AddressDecMap map[int]Address +type AddressDecMap map[BackendID]Address // AddrKey is a non-human readable representation of an `Address`. // It can be compared and therefore used as a key in a map. -type AddrKey struct { - key string -} +type AddrKey string // Encode encodes first the length of the map, // then all Addresses and their key in the map. @@ -151,17 +165,17 @@ func (a *AddressDecMap) Decode(r stdio.Reader) (err error) { if err := perunio.Decode(r, &mapLen); err != nil { return errors.WithMessage(err, "decoding map length") } - *a = make(map[int]Address, mapLen) + *a = make(map[BackendID]Address, mapLen) for i := 0; i < int(mapLen); i++ { var idx int32 if err := perunio.Decode(r, &idx); err != nil { return errors.WithMessage(err, "decoding map index") } - addr := NewAddress(int(idx)) + addr := NewAddress(BackendID(idx)) if err := perunio.Decode(r, addr); err != nil { return errors.WithMessagef(err, "decoding %d-th address map entry", i) } - (*a)[int(idx)] = addr + (*a)[BackendID(idx)] = addr } return nil } @@ -172,7 +186,7 @@ func (a *AddressMapArray) Decode(r stdio.Reader) (err error) { if err := perunio.Decode(r, &mapLen); err != nil { return errors.WithMessage(err, "decoding array length") } - a.Addr = make([]map[int]Address, mapLen) + a.Addr = make([]map[BackendID]Address, mapLen) for i := 0; i < int(mapLen); i++ { if err := perunio.Decode(r, (*AddressDecMap)(&a.Addr[i])); err != nil { return errors.WithMessagef(err, "decoding %d-th address map entry", i) @@ -181,60 +195,38 @@ func (a *AddressMapArray) Decode(r stdio.Reader) (err error) { return nil } -// Key returns the `AddrKey` corresponding to the passed `map[int]Address`. +// Key returns the `AddrKey` corresponding to the passed `Address`. // The `Address` can be retrieved with `FromKey`. -// Returns an error if the `map[int]Address` can't be encoded. -func Key(a map[int]Address) AddrKey { +// Panics when the `Address` can't be encoded. +func Key(a Address) AddrKey { var buff strings.Builder - // Encode the number of elements in the map first. - length := int32(len(a)) // Using int32 to encode the length - err := binary.Write(&buff, binary.BigEndian, length) - if err != nil { - log.Panic("could not encode map length in Key: ", err) - + if err := perunio.Encode(&buff, uint32(a.BackendID())); err != nil { + panic("Could not encode id in AddrKey: " + err.Error()) } - // Iterate over the map and encode each key-value pair. - for id, addr := range a { - if err := binary.Write(&buff, binary.BigEndian, int32(id)); err != nil { - log.Panicf("could not encode map length in AddrKey: " + err.Error()) - } - if err := perunio.Encode(&buff, addr); err != nil { - log.Panicf("could not encode map[int]Address in AddrKey: " + err.Error()) - } + if err := perunio.Encode(&buff, a); err != nil { + panic("Could not encode address in AddrKey: " + err.Error()) } - return AddrKey{buff.String()} + return AddrKey(buff.String()) } -// FromKey returns the `map[int]Address` corresponding to the passed `AddrKey` +// FromKey returns the `Address` corresponding to the passed `AddrKey` // created by `Key`. -// Returns an error if the `map[int]Address` can't be decoded. -func FromKey(k AddrKey) map[int]Address { - buff := bytes.NewBuffer([]byte(k.key)) - var numElements int32 - - // Manually decode the number of elements in the map. - if err := binary.Read(buff, binary.BigEndian, &numElements); err != nil { - log.Panicf("could not decode map length in FromKey: " + err.Error()) - } - a := make(map[int]Address, numElements) - // Decode each key-value pair and insert them into the map. - for i := 0; i < int(numElements); i++ { - var id int32 - if err := binary.Read(buff, binary.BigEndian, &id); err != nil { - log.Panicf("could not decode map length in FromKey: " + err.Error()) - } - addr := NewAddress(int(id)) - if err := perunio.Decode(buff, addr); err != nil { - log.Panicf("could not decode map[int]Address in FromKey: " + err.Error()) - } - a[int(id)] = addr +// Panics when the `Address` can't be decoded. +func FromKey(k AddrKey) Address { + buff := bytes.NewBuffer([]byte(k)) + var id uint32 + err := perunio.Decode(buff, &id) + a := NewAddress(BackendID(int(id))) + err = perunio.Decode(buff, a) + if err != nil { + panic("Could not decode address in FromKey: " + err.Error()) } return a } // Equal Returns whether the passed `Address` has the same key as the // receiving `AddrKey`. -func (k AddrKey) Equal(a map[int]Address) bool { +func (k AddrKey) Equal(a Address) bool { key := Key(a) return k == key } diff --git a/wallet/address_test.go b/wallet/address_test.go index 8e7c5aa35..4d8334006 100644 --- a/wallet/address_test.go +++ b/wallet/address_test.go @@ -60,15 +60,15 @@ func TestAddresses_Serializer(t *testing.T) { peruniotest.GenericSerializerTest(t, &testAddresses{addrs: wallet.AddressMapArray{Addr: addrs}}) addrs = wallettest.NewRandomAddressesMap(rng, 1) - peruniotest.GenericSerializerTest(t, &testAddresses{addrs: wallet.AddressMapArray{addrs}}) + peruniotest.GenericSerializerTest(t, &testAddresses{addrs: wallet.AddressMapArray{Addr: addrs}}) addrs = wallettest.NewRandomAddressesMap(rng, 5) - peruniotest.GenericSerializerTest(t, &testAddresses{addrs: wallet.AddressMapArray{addrs}}) + peruniotest.GenericSerializerTest(t, &testAddresses{addrs: wallet.AddressMapArray{Addr: addrs}}) } func TestAddrKey_Equal(t *testing.T) { rng := pkgtest.Prng(t) - addrs := wallettest.NewRandomAddressesMap(rng, 10) + addrs := wallettest.NewRandomAddressArray(rng, 10) // Test all properties of an equivalence relation. for i, a := range addrs { @@ -93,13 +93,13 @@ func TestAddrKey_Equal(t *testing.T) { func TestAddrKey(t *testing.T) { rng := pkgtest.Prng(t) - addrs := wallettest.NewRandomAddressesMap(rng, 10) + addrs := wallettest.NewRandomAddressArray(rng, 10) for _, a := range addrs { // Test that Key and FromKey are dual to each other. require.Equal(t, wallet.Key(a), wallet.Key(wallet.FromKey(wallet.Key(a)))) // Test that FromKey returns the correct Address. - require.True(t, EqualWalletMaps(a, wallet.FromKey(wallet.Key(a)))) + require.True(t, a.Equal(wallet.FromKey(wallet.Key(a)))) } } @@ -121,15 +121,3 @@ func TestCloneAddresses(t *testing.T) { require.NotSame(t, a, addrs0[i]) } } - -func EqualWalletMaps(a, b map[int]wallet.Address) bool { - if len(a) != len(b) { - return false - } - for i, addr := range a { - if !addr.Equal(b[i]) { - return false - } - } - return true -} diff --git a/wallet/backend.go b/wallet/backend.go index aaba189fe..de5eec212 100644 --- a/wallet/backend.go +++ b/wallet/backend.go @@ -21,7 +21,7 @@ import ( // backend is set to the global wallet backend. Must not be set directly but // through importing the needed backend. -var backend map[int]Backend +var backend map[BackendID]Backend // Backend provides useful methods for this blockchain. type Backend interface { @@ -43,18 +43,18 @@ type Backend interface { // through importing the needed backend. func SetBackend(b Backend, id int) { if backend == nil { - backend = make(map[int]Backend) + backend = make(map[BackendID]Backend) } - if backend[id] != nil { + if backend[BackendID(id)] != nil { panic("wallet backend already set") } - backend[id] = b + backend[BackendID(id)] = b } // NewAddress returns a variable of type Address, which can be used // for unmarshalling an address from its binary representation. -func NewAddress(id int) Address { +func NewAddress(id BackendID) Address { return backend[id].NewAddress() } @@ -79,15 +79,6 @@ func DecodeSig(r io.Reader) (Sig, error) { } // VerifySignature calls VerifySignature of the current backend. -func VerifySignature(msg []byte, sign Sig, a map[int]Address) (bool, error) { - var errs []error - for _, addr := range a { - v, err := backend[addr.BackendID()].VerifySignature(msg, sign, addr) - if err == nil && v { - return v, nil - } else { - errs = append(errs, err) - } - } - return false, errors.Join(errs...) +func VerifySignature(msg []byte, sign Sig, a Address) (bool, error) { + return backend[a.BackendID()].VerifySignature(msg, sign, a) } diff --git a/wallet/sig.go b/wallet/sig.go index 30b7859a0..ea56e0cd9 100644 --- a/wallet/sig.go +++ b/wallet/sig.go @@ -84,7 +84,7 @@ func EncodeSparseSigs(w io.Writer, sigs []Sig) error { } // DecodeSparseSigs decodes a collection of signatures in the form (mask, sig, sig, sig, ...). -func DecodeSparseSigs(r io.Reader, sigs *[]Sig, backendIDs []int) (err error) { +func DecodeSparseSigs(r io.Reader, sigs *[]Sig) (err error) { masklen := int(math.Ceil(float64(len(*sigs)) / float64(bitsPerByte))) mask := make([]uint8, masklen) diff --git a/wallet/test/randomizer.go b/wallet/test/randomizer.go index a43232856..da4c716d2 100644 --- a/wallet/test/randomizer.go +++ b/wallet/test/randomizer.go @@ -69,8 +69,8 @@ func NewRandomAddress(rng *rand.Rand) wallet.Address { // NewRandomAddressMap returns a new random address by calling the currently set // wallet randomizer. -func NewRandomAddresses(rng *rand.Rand) map[int]wallet.Address { - return map[int]wallet.Address{0: randomizer.NewRandomAddress(rng)} +func NewRandomAddresses(rng *rand.Rand) map[wallet.BackendID]wallet.Address { + return map[wallet.BackendID]wallet.Address{0: randomizer.NewRandomAddress(rng)} } // RandomWallet returns the randomizer backend's wallet. All accounts created @@ -95,28 +95,32 @@ func NewWallet() Wallet { // NewRandomAccounts returns a slice of new random accounts // by calling NewRandomAccount. -func NewRandomAccounts(rng *rand.Rand, n int) ([]wallet.Account, []map[int]wallet.Address) { - accs := make([]wallet.Account, n) - addrs := make([]map[int]wallet.Address, n) +func NewRandomAccounts(rng *rand.Rand, n int) ([]map[wallet.BackendID]wallet.Account, []map[wallet.BackendID]wallet.Address) { + accs := make([]map[wallet.BackendID]wallet.Account, n) + addrs := make([]map[wallet.BackendID]wallet.Address, n) for i := range accs { - accs[i] = NewRandomAccount(rng) - addrs[i] = accs[i].Address() + accs[i] = map[wallet.BackendID]wallet.Account{0: NewRandomAccount(rng)} + addrs[i] = map[wallet.BackendID]wallet.Address{0: accs[i][0].Address()} } return accs, addrs } -// NewRandomAccounts returns a slice of new random accounts +// NewRandomAccountMapSlice returns a slice of new random accounts map // by calling NewRandomAccount. -func NewRandomAccountsMap(rng *rand.Rand, n int) (map[int][]wallet.Account, []map[int]wallet.Address) { - accs := make([]wallet.Account, n) - mapAccs := make(map[int][]wallet.Account) - mapAddrs := make([]map[int]wallet.Address, n) +func NewRandomAccountMapSlice(rng *rand.Rand, b wallet.BackendID, n int) []map[wallet.BackendID]wallet.Account { + accs := make([]map[wallet.BackendID]wallet.Account, n) for i := range accs { - accs[i] = NewRandomAccount(rng) + accs[i] = map[wallet.BackendID]wallet.Account{b: NewRandomAccount(rng)} } - mapAccs[0] = accs - mapAddrs[0] = accs[0].Address() - return mapAccs, mapAddrs + return accs +} + +// NewRandomAccountMap returns a slice of new random accounts +// by calling NewRandomAccount. +func NewRandomAccountMap(rng *rand.Rand) map[wallet.BackendID]wallet.Account { + accs := make(map[wallet.BackendID]wallet.Account) + accs[0] = NewRandomAccount(rng) + return accs } // NewRandomAddresses returns a slice of new random addresses. @@ -129,8 +133,8 @@ func NewRandomAddressArray(rng *rand.Rand, n int) []wallet.Address { } // NewRandomAddresses returns a slice of new random addresses. -func NewRandomAddressesMap(rng *rand.Rand, n int) []map[int]wallet.Address { - addrs := make([]map[int]wallet.Address, n) +func NewRandomAddressesMap(rng *rand.Rand, n int) []map[wallet.BackendID]wallet.Address { + addrs := make([]map[wallet.BackendID]wallet.Address, n) for i := range addrs { addrs[i] = NewRandomAddresses(rng) } diff --git a/wallet/test/wallet.go b/wallet/test/wallet.go index b6b5e1704..9de843ddb 100644 --- a/wallet/test/wallet.go +++ b/wallet/test/wallet.go @@ -32,75 +32,73 @@ type UnlockedAccount func() (wallet.Account, error) // Setup provides all objects needed for the generic tests. type Setup struct { - Backend wallet.Backend // backend implementation - Wallet wallet.Wallet // the wallet instance used for testing - AddressInWallet map[int]wallet.Address // an address of an account in the test wallet - ZeroAddress wallet.Address // an address that is less or equal to any other address - DataToSign []byte // some data to sign - AddressMarshalled []byte // a valid nonzero address not in the wallet + Backend wallet.Backend // backend implementation + Wallet wallet.Wallet // the wallet instance used for testing + AddressInWallet wallet.Address // an address of an account in the test wallet + ZeroAddress wallet.Address // an address that is less or equal to any other address + DataToSign []byte // some data to sign + AddressMarshalled []byte // a valid nonzero address not in the wallet } // TestAccountWithWalletAndBackend tests an account implementation together with // a corresponding wallet and backend implementation. // This function should be called by every implementation of the wallet interface. func TestAccountWithWalletAndBackend(t *testing.T, s *Setup) { //nolint:revive // `test.Test...` stutters, but we accept that here. - for _, address := range s.AddressInWallet { - acc, err := s.Wallet.Unlock(s.AddressInWallet) - assert.NoError(t, err) - // Check unlocked account - sig, err := acc.SignData(s.DataToSign) - assert.NoError(t, err, "Sign with unlocked account should succeed") - valid, err := s.Backend.VerifySignature(s.DataToSign, sig, address) - assert.True(t, valid, "Verification should succeed") - assert.NoError(t, err, "Verification should not produce error") + acc, err := s.Wallet.Unlock(s.AddressInWallet) + assert.NoError(t, err) + // Check unlocked account + sig, err := acc.SignData(s.DataToSign) + assert.NoError(t, err, "Sign with unlocked account should succeed") + valid, err := s.Backend.VerifySignature(s.DataToSign, sig, s.AddressInWallet) + assert.True(t, valid, "Verification should succeed") + assert.NoError(t, err, "Verification should not produce error") - addr := s.Backend.NewAddress() - err = addr.UnmarshalBinary(s.AddressMarshalled) - assert.NoError(t, err, "Binary unmarshalling of address should work") - valid, err = s.Backend.VerifySignature(s.DataToSign, sig, addr) - assert.False(t, valid, "Verification with wrong address should fail") - assert.NoError(t, err, "Verification of valid signature should not produce error") + addr := s.Backend.NewAddress() + err = addr.UnmarshalBinary(s.AddressMarshalled) + assert.NoError(t, err, "Binary unmarshalling of address should work") + valid, err = s.Backend.VerifySignature(s.DataToSign, sig, addr) + assert.False(t, valid, "Verification with wrong address should fail") + assert.NoError(t, err, "Verification of valid signature should not produce error") - tampered := make([]byte, len(sig)) - copy(tampered, sig) - // Invalidate the signature and check for error - tampered[0] = ^sig[0] - valid, err = s.Backend.VerifySignature(s.DataToSign, tampered, address) - if valid && err == nil { - t.Error("Verification of invalid signature should produce error or return false") - } - // Truncate the signature and check for error - tampered = sig[:len(sig)-1] - valid, err = s.Backend.VerifySignature(s.DataToSign, tampered, address) - if valid && err != nil { - t.Error("Verification of invalid signature should produce error or return false") - } - // Expand the signature and check for error - //nolint:gocritic - tampered = append(sig, 0) - valid, err = s.Backend.VerifySignature(s.DataToSign, tampered, address) - if valid && err != nil { - t.Error("Verification of invalid signature should produce error or return false") - } + tampered := make([]byte, len(sig)) + copy(tampered, sig) + // Invalidate the signature and check for error + tampered[0] = ^sig[0] + valid, err = s.Backend.VerifySignature(s.DataToSign, tampered, s.AddressInWallet) + if valid && err == nil { + t.Error("Verification of invalid signature should produce error or return false") + } + // Truncate the signature and check for error + tampered = sig[:len(sig)-1] + valid, err = s.Backend.VerifySignature(s.DataToSign, tampered, s.AddressInWallet) + if valid && err != nil { + t.Error("Verification of invalid signature should produce error or return false") + } + // Expand the signature and check for error + //nolint:gocritic + tampered = append(sig, 0) + valid, err = s.Backend.VerifySignature(s.DataToSign, tampered, s.AddressInWallet) + if valid && err != nil { + t.Error("Verification of invalid signature should produce error or return false") + } - // Test DecodeSig - sig, err = acc.SignData(s.DataToSign) - require.NoError(t, err, "Sign with unlocked account should succeed") + // Test DecodeSig + sig, err = acc.SignData(s.DataToSign) + require.NoError(t, err, "Sign with unlocked account should succeed") - buff := new(bytes.Buffer) - err = perunio.Encode(buff, sig) - require.NoError(t, err, "encode sig") - sign2, err := s.Backend.DecodeSig(buff) - assert.NoError(t, err, "Decoded signature should work") - assert.Equal(t, sig, sign2, "Decoded signature should be equal to the original") + buff := new(bytes.Buffer) + err = perunio.Encode(buff, sig) + require.NoError(t, err, "encode sig") + sign2, err := s.Backend.DecodeSig(buff) + assert.NoError(t, err, "Decoded signature should work") + assert.Equal(t, sig, sign2, "Decoded signature should be equal to the original") - // Test DecodeSig on short stream - err = perunio.Encode(buff, sig) - require.NoError(t, err, "encode sig") - shortBuff := bytes.NewBuffer(buff.Bytes()[:len(buff.Bytes())-1]) // remove one byte - _, err = s.Backend.DecodeSig(shortBuff) - assert.Error(t, err, "DecodeSig on short stream should error") - } + // Test DecodeSig on short stream + err = perunio.Encode(buff, sig) + require.NoError(t, err, "encode sig") + shortBuff := bytes.NewBuffer(buff.Bytes()[:len(buff.Bytes())-1]) // remove one byte + _, err = s.Backend.DecodeSig(shortBuff) + assert.Error(t, err, "DecodeSig on short stream should error") } // GenericSignatureSizeTest tests that the size of the signatures produced by diff --git a/wallet/test/walletbench.go b/wallet/test/walletbench.go index 5c8c6882e..fb00b8f73 100644 --- a/wallet/test/walletbench.go +++ b/wallet/test/walletbench.go @@ -62,7 +62,7 @@ func benchBackendVerifySig(b *testing.B, s *Setup) { b.StartTimer() for n := 0; n < b.N; n++ { - ok, err := s.Backend.VerifySignature(s.DataToSign, signature, perunAcc.Address()[0]) + ok, err := s.Backend.VerifySignature(s.DataToSign, signature, perunAcc.Address()) if !ok { b.Fatal(err) diff --git a/wallet/wallet.go b/wallet/wallet.go index a630025fb..621598749 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -24,7 +24,7 @@ type Wallet interface { // LockAll has been called, or a matching count of IncrementUsage and // DecrementUsage calls on the account's address has been made. Unlock may // be called multiple times for the same Address by the Perun SDK. - Unlock(map[int]Address) (Account, error) + Unlock(Address) (Account, error) // LockAll is called by the framework when a Client shuts down. This should // release all temporary resources held by the wallet, and accesses to @@ -36,7 +36,7 @@ type Wallet interface { // The address passed to the function belongs to the Account the Client is // using to participate in the channel. Implementing this function with any // behavior is not essential. - IncrementUsage(map[int]Address) + IncrementUsage(Address) // DecrementUsage is called whenever a channel is settled. The address // passed to the function belongs to the Account the Client is using to @@ -46,5 +46,5 @@ type Wallet interface { // the wallet implementation. In that event, the affected account does not // have to be able to sign messages anymore. Implementing this function with // any behavior is not essential. - DecrementUsage(map[int]Address) + DecrementUsage(Address) } diff --git a/watcher/internal/mocks/RegisterSubscriber.go b/watcher/internal/mocks/RegisterSubscriber.go index 06e0ec7ef..2ccf1b8e7 100644 --- a/watcher/internal/mocks/RegisterSubscriber.go +++ b/watcher/internal/mocks/RegisterSubscriber.go @@ -8,6 +8,8 @@ import ( channel "perun.network/go-perun/channel" mock "github.com/stretchr/testify/mock" + + wallet "perun.network/go-perun/wallet" ) // RegisterSubscriber is an autogenerated mock type for the RegisterSubscriber type @@ -34,7 +36,7 @@ func (_m *RegisterSubscriber) Register(_a0 context.Context, _a1 channel.Adjudica } // Subscribe provides a mock function with given fields: _a0, _a1 -func (_m *RegisterSubscriber) Subscribe(_a0 context.Context, _a1 map[int][32]byte) (channel.AdjudicatorSubscription, error) { +func (_m *RegisterSubscriber) Subscribe(_a0 context.Context, _a1 map[wallet.BackendID][32]byte) (channel.AdjudicatorSubscription, error) { ret := _m.Called(_a0, _a1) if len(ret) == 0 { @@ -43,10 +45,10 @@ func (_m *RegisterSubscriber) Subscribe(_a0 context.Context, _a1 map[int][32]byt var r0 channel.AdjudicatorSubscription var r1 error - if rf, ok := ret.Get(0).(func(context.Context, map[int][32]byte) (channel.AdjudicatorSubscription, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, map[wallet.BackendID][32]byte) (channel.AdjudicatorSubscription, error)); ok { return rf(_a0, _a1) } - if rf, ok := ret.Get(0).(func(context.Context, map[int][32]byte) channel.AdjudicatorSubscription); ok { + if rf, ok := ret.Get(0).(func(context.Context, map[wallet.BackendID][32]byte) channel.AdjudicatorSubscription); ok { r0 = rf(_a0, _a1) } else { if ret.Get(0) != nil { @@ -54,7 +56,7 @@ func (_m *RegisterSubscriber) Subscribe(_a0 context.Context, _a1 map[int][32]byt } } - if rf, ok := ret.Get(1).(func(context.Context, map[int][32]byte) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, map[wallet.BackendID][32]byte) error); ok { r1 = rf(_a0, _a1) } else { r1 = ret.Error(1) diff --git a/watcher/local/registry.go b/watcher/local/registry.go index 53f19be1d..9335aed74 100644 --- a/watcher/local/registry.go +++ b/watcher/local/registry.go @@ -15,6 +15,7 @@ package local import ( + "perun.network/go-perun/wallet" "sync" "github.com/pkg/errors" @@ -37,7 +38,7 @@ func newRegistry() *registry { // addIfSucceeds adds the channel to the registry, if it is not already present // in the registry and if the "chInitializer" does not return an error. -func (r *registry) addIfSucceeds(id map[int]channel.ID, chInitializer chInitializer) (*ch, error) { +func (r *registry) addIfSucceeds(id map[wallet.BackendID]channel.ID, chInitializer chInitializer) (*ch, error) { r.mtx.Lock() defer r.mtx.Unlock() if _, ok := r.chs[channel.IDKey(id)]; ok { @@ -54,7 +55,7 @@ func (r *registry) addIfSucceeds(id map[int]channel.ID, chInitializer chInitiali } // retrieve retrieves the channel from registry. -func (r *registry) retrieve(id map[int]channel.ID) (*ch, bool) { +func (r *registry) retrieve(id map[wallet.BackendID]channel.ID) (*ch, bool) { r.mtx.Lock() ch, ok := r.chs[channel.IDKey(id)] r.mtx.Unlock() @@ -63,7 +64,7 @@ func (r *registry) retrieve(id map[int]channel.ID) (*ch, bool) { // remove removes the channel from registry, if it is present. // It does not do any validation on the channel to be removed. -func (r *registry) remove(id map[int]channel.ID) { +func (r *registry) remove(id map[wallet.BackendID]channel.ID) { r.mtx.Lock() delete(r.chs, channel.IDKey(id)) r.mtx.Unlock() diff --git a/watcher/local/watcher.go b/watcher/local/watcher.go index 1460bcd0b..898c97bda 100644 --- a/watcher/local/watcher.go +++ b/watcher/local/watcher.go @@ -17,6 +17,7 @@ package local import ( "context" stderrors "errors" + "perun.network/go-perun/wallet" "time" "github.com/pkg/errors" @@ -55,7 +56,7 @@ type ( } ch struct { - id map[int]channel.ID + id map[wallet.BackendID]channel.ID params *channel.Params isClosed bool done chan struct{} @@ -157,7 +158,7 @@ func (w *Watcher) StartWatchingLedgerChannel( // sub-channels is supported. func (w *Watcher) StartWatchingSubChannel( ctx context.Context, - parent map[int]channel.ID, + parent map[wallet.BackendID]channel.ID, signedState channel.SignedState, ) (watcher.StatesPub, watcher.AdjudicatorSub, error) { parentCh, ok := w.registry.retrieve(parent) @@ -212,7 +213,7 @@ func (w *Watcher) startWatching( } func newCh( - id map[int]channel.ID, + id map[wallet.BackendID]channel.ID, parent *ch, params *channel.Params, eventsFromChainSub channel.AdjudicatorSubscription, @@ -458,7 +459,7 @@ func makeAdjudicatorReq(params *channel.Params, tx channel.Transaction) channel. // has stopped watching for some of the sub-channel). // // Context is not used, it is for implementing watcher.Watcher interface. -func (w *Watcher) StopWatching(_ context.Context, id map[int]channel.ID) error { +func (w *Watcher) StopWatching(_ context.Context, id map[wallet.BackendID]channel.ID) error { ch, ok := w.retrieve(id) if !ok { return errors.New("channel not registered with the watcher") diff --git a/watcher/local/watcher_test.go b/watcher/local/watcher_test.go index ca5376695..cd6f41bde 100644 --- a/watcher/local/watcher_test.go +++ b/watcher/local/watcher_test.go @@ -18,6 +18,7 @@ import ( "context" "fmt" "math/rand" + "perun.network/go-perun/wallet" "sync" "testing" "time" @@ -954,7 +955,7 @@ func startWatchingForSubChannel( t *testing.T, w *local.Watcher, signedState channel.SignedState, - parentID map[int]channel.ID, + parentID map[wallet.BackendID]channel.ID, ) (watcher.StatesPub, watcher.AdjudicatorSub) { t.Helper() statesPub, eventsSub, err := w.StartWatchingSubChannel(context.TODO(), parentID, signedState) diff --git a/watcher/watcher.go b/watcher/watcher.go index 101d812cd..7a28359b5 100644 --- a/watcher/watcher.go +++ b/watcher/watcher.go @@ -16,6 +16,7 @@ package watcher import ( "context" + "perun.network/go-perun/wallet" "perun.network/go-perun/channel" ) @@ -40,9 +41,9 @@ type ( // this. Watcher interface { StartWatchingLedgerChannel(context.Context, channel.SignedState) (StatesPub, AdjudicatorSub, error) - StartWatchingSubChannel(_ context.Context, parent map[int]channel.ID, _ channel.SignedState) ( + StartWatchingSubChannel(_ context.Context, parent map[wallet.BackendID]channel.ID, _ channel.SignedState) ( StatesPub, AdjudicatorSub, error) - StopWatching(context.Context, map[int]channel.ID) error + StopWatching(context.Context, map[wallet.BackendID]channel.ID) error } // StatesPub is the interface used to send newer off-chain states from the diff --git a/wire/account.go b/wire/account.go index 98955077d..fd5202e66 100644 --- a/wire/account.go +++ b/wire/account.go @@ -18,6 +18,7 @@ import ( "encoding/binary" "fmt" "io" + "perun.network/go-perun/wallet" ) func init() { @@ -32,7 +33,7 @@ func init() { // authenticity within the Perun peer-to-peer network. type Account interface { // Address used by this account. - Address() map[int]Address + Address() Address // Sign signs the given message with this account's private key. Sign(msg []byte) ([]byte, error) @@ -80,8 +81,11 @@ func (m *AuthResponseMsg) Decode(r io.Reader) (err error) { } // NewAuthResponseMsg creates an authentication response message. -func NewAuthResponseMsg(acc Account) (Msg, error) { - addressMap := acc.Address() +func NewAuthResponseMsg(acc map[wallet.BackendID]Account) (Msg, error) { + addressMap := make(map[wallet.BackendID]Address) + for id, a := range acc { + addressMap[id] = a.Address() + } var addressBytes []byte addressBytes = append(addressBytes, byte(len(addressMap))) for _, addr := range addressMap { @@ -91,7 +95,7 @@ func NewAuthResponseMsg(acc Account) (Msg, error) { } addressBytes = append(addressBytes, addrBytes...) } - signature, err := acc.Sign(addressBytes) + signature, err := acc[0].Sign(addressBytes) if err != nil { return nil, fmt.Errorf("failed to sign address: %w", err) } diff --git a/wire/address.go b/wire/address.go index 8028ebd80..fc4315202 100644 --- a/wire/address.go +++ b/wire/address.go @@ -17,6 +17,7 @@ package wire import ( "encoding" stdio "io" + "perun.network/go-perun/wallet" "strings" "github.com/pkg/errors" @@ -47,10 +48,10 @@ type Address interface { } // AddressMapArray is a helper type for encoding and decoding address maps. -type AddressMapArray []map[int]Address +type AddressMapArray []map[wallet.BackendID]Address // AddressDecMap is a helper type for encoding and decoding arrays of address maps. -type AddressDecMap map[int]Address +type AddressDecMap map[wallet.BackendID]Address // Encode encodes first the length of the map, // then all Addresses and their key in the map. @@ -91,7 +92,7 @@ func (a *AddressDecMap) Decode(r stdio.Reader) (err error) { if err := perunio.Decode(r, &mapLen); err != nil { return errors.WithMessage(err, "decoding map length") } - *a = make(map[int]Address, mapLen) + *a = make(map[wallet.BackendID]Address, mapLen) for i := 0; i < int(mapLen); i++ { var idx int32 if err := perunio.Decode(r, &idx); err != nil { @@ -101,7 +102,7 @@ func (a *AddressDecMap) Decode(r stdio.Reader) (err error) { if err := perunio.Decode(r, addr); err != nil { return errors.WithMessagef(err, "decoding %d-th address map entry", i) } - (*a)[int(idx)] = addr + (*a)[wallet.BackendID(idx)] = addr } return nil } @@ -113,7 +114,7 @@ func (a *AddressMapArray) Decode(r stdio.Reader) (err error) { if err := perunio.Decode(r, &mapLen); err != nil { return errors.WithMessage(err, "decoding array length") } - *a = make([]map[int]Address, mapLen) + *a = make([]map[wallet.BackendID]Address, mapLen) for i := 0; i < int(mapLen); i++ { if err := perunio.Decode(r, (*AddressDecMap)(&(*a)[i])); err != nil { return errors.WithMessagef(err, "decoding %d-th address map entry", i) @@ -136,7 +137,7 @@ func IndexOfAddr(addrs []Address, addr Address) int { // IndexOfAddr returns the index of the given address in the address slice, // or -1 if it is not part of the slice. -func IndexOfAddrs(addrs []map[int]Address, addr map[int]Address) int { +func IndexOfAddrs(addrs []map[wallet.BackendID]Address, addr map[wallet.BackendID]Address) int { for i, a := range addrs { if addrEqual(a, addr) { return i @@ -146,7 +147,7 @@ func IndexOfAddrs(addrs []map[int]Address, addr map[int]Address) int { return -1 } -func addrEqual(a, b map[int]Address) bool { +func addrEqual(a, b map[wallet.BackendID]Address) bool { if len(a) != len(b) { return false } @@ -174,7 +175,7 @@ func Key(a Address) AddrKey { } // Keys returns the `AddrKey` corresponding to the passed `map[int]Address`. -func Keys(addressMap map[int]Address) AddrKey { +func Keys(addressMap map[wallet.BackendID]Address) AddrKey { var keyParts []string for _, addr := range addressMap { key := Key(addr) @@ -182,3 +183,11 @@ func Keys(addressMap map[int]Address) AddrKey { } return AddrKey(strings.Join(keyParts, "|")) } + +func AddressMapfromAccountMap(accs map[wallet.BackendID]Account) map[wallet.BackendID]Address { + addresses := make(map[wallet.BackendID]Address) + for id, a := range accs { + addresses[id] = a.Address() + } + return addresses +} diff --git a/wire/bus.go b/wire/bus.go index c4967248e..1844c9a40 100644 --- a/wire/bus.go +++ b/wire/bus.go @@ -14,6 +14,8 @@ package wire +import "perun.network/go-perun/wallet" + // A Bus is a central message bus over which all clients of a channel network // communicate. It is used as the transport layer abstraction for the // client.Client. @@ -22,5 +24,5 @@ type Bus interface { // SubscribeClient should route all messages with clientAddr as recipient to // the provided Consumer. Every address may only be subscribed to once. - SubscribeClient(c Consumer, clientAddr map[int]Address) error + SubscribeClient(c Consumer, clientAddr map[wallet.BackendID]Address) error } diff --git a/wire/encode.go b/wire/encode.go index 9327e89e9..b0a6aa9cd 100644 --- a/wire/encode.go +++ b/wire/encode.go @@ -17,6 +17,7 @@ package wire import ( "fmt" "io" + "perun.network/go-perun/wallet" "strconv" "github.com/pkg/errors" @@ -35,8 +36,8 @@ type ( // An Envelope encapsulates a message with routing information, that is, the // sender and intended recipient. Envelope struct { - Sender map[int]Address // Sender of the message. - Recipient map[int]Address // Recipient of the message. + Sender map[wallet.BackendID]Address // Sender of the message. + Recipient map[wallet.BackendID]Address // Recipient of the message. // Msg contained in this Envelope. Not embedded so Envelope doesn't implement Msg. Msg Msg } diff --git a/wire/hybridbus.go b/wire/hybridbus.go index 4c1e63687..80aa60a86 100644 --- a/wire/hybridbus.go +++ b/wire/hybridbus.go @@ -17,6 +17,7 @@ package wire import ( "context" "fmt" + "perun.network/go-perun/wallet" "polycry.pt/poly-go/errors" "polycry.pt/poly-go/sync/atomic" @@ -88,7 +89,7 @@ func (b *hybridBus) Publish(ctx context.Context, e *Envelope) error { } // SubscribeClient subscribes an envelope consumer to all sub-buses. -func (b *hybridBus) SubscribeClient(c Consumer, receiver map[int]Address) error { +func (b *hybridBus) SubscribeClient(c Consumer, receiver map[wallet.BackendID]Address) error { errg := errors.NewGatherer() for _, bus := range b.buses { errg.Add(bus.SubscribeClient(c, receiver)) diff --git a/wire/hybridbus_test.go b/wire/hybridbus_test.go index 32d7f6c77..18a0b8c7f 100644 --- a/wire/hybridbus_test.go +++ b/wire/hybridbus_test.go @@ -15,6 +15,7 @@ package wire_test import ( + "perun.network/go-perun/wallet" "testing" "github.com/stretchr/testify/require" @@ -41,7 +42,7 @@ func TestHybridBus(t *testing.T) { hybridBus := NewHybridBus(buses...) i := 0 - test.GenericBusTest(t, func(Account) (pub Bus, sub Bus) { + test.GenericBusTest(t, func(map[wallet.BackendID]Account) (pub Bus, sub Bus) { i++ // Split the clients evenly among the sub-buses, and let them publish // over the hybrid bus. @@ -51,7 +52,7 @@ func TestHybridBus(t *testing.T) { func TestHybridBus_Single(t *testing.T) { hybridBus := NewHybridBus(NewLocalBus()) - test.GenericBusTest(t, func(Account) (Bus, Bus) { + test.GenericBusTest(t, func(map[wallet.BackendID]Account) (Bus, Bus) { return hybridBus, hybridBus }, 16, 10) } diff --git a/wire/localbus.go b/wire/localbus.go index d08592fd2..2339de497 100644 --- a/wire/localbus.go +++ b/wire/localbus.go @@ -16,6 +16,7 @@ package wire import ( "context" + "perun.network/go-perun/wallet" "sync" "github.com/pkg/errors" @@ -58,7 +59,7 @@ func (h *LocalBus) Publish(ctx context.Context, e *Envelope) error { // SubscribeClient implements wire.Bus.SubscribeClient. There can only be one // subscription per receiver address. // When the Consumer closes, its subscription is removed. -func (h *LocalBus) SubscribeClient(c Consumer, receiver map[int]Address) error { +func (h *LocalBus) SubscribeClient(c Consumer, receiver map[wallet.BackendID]Address) error { recv := h.ensureRecv(receiver) recv.recv = c close(recv.exists) @@ -77,7 +78,7 @@ func (h *LocalBus) SubscribeClient(c Consumer, receiver map[int]Address) error { // ensureRecv ensures that there is an entry for a recipient address in the // bus' receiver map, and returns it. If it creates a new receiver, it is only // a placeholder until a subscription appears. -func (h *LocalBus) ensureRecv(a map[int]Address) *localBusReceiver { +func (h *LocalBus) ensureRecv(a map[wallet.BackendID]Address) *localBusReceiver { key := Keys(a) // First, we only use a read lock, hoping that the receiver already exists. h.mutex.RLock() diff --git a/wire/localbus_test.go b/wire/localbus_test.go index 971f70123..83ba3a694 100644 --- a/wire/localbus_test.go +++ b/wire/localbus_test.go @@ -15,6 +15,7 @@ package wire_test import ( + "perun.network/go-perun/wallet" "testing" . "perun.network/go-perun/wire" @@ -23,7 +24,7 @@ import ( func TestLocalBus(t *testing.T) { bus := NewLocalBus() - test.GenericBusTest(t, func(Account) (Bus, Bus) { + test.GenericBusTest(t, func(map[wallet.BackendID]Account) (Bus, Bus) { return bus, bus }, 16, 10) } diff --git a/wire/net/bus.go b/wire/net/bus.go index 015ed756d..f50c7ba73 100644 --- a/wire/net/bus.go +++ b/wire/net/bus.go @@ -16,6 +16,7 @@ package net import ( "context" + "perun.network/go-perun/wallet" "sync" "time" @@ -44,13 +45,13 @@ const ( // NewBus creates a new network bus. The dialer and listener are used to // establish new connections internally, while id is this node's identity. -func NewBus(id wire.Account, d Dialer, s wire.EnvelopeSerializer) *Bus { +func NewBus(id map[wallet.BackendID]wire.Account, d Dialer, s wire.EnvelopeSerializer) *Bus { b := &Bus{ mainRecv: wire.NewReceiver(), recvs: make(map[wire.AddrKey]wire.Consumer), } - onNewEndpoint := func(map[int]wire.Address) wire.Consumer { return b.mainRecv } + onNewEndpoint := func(map[wallet.BackendID]wire.Address) wire.Consumer { return b.mainRecv } b.reg = NewEndpointRegistry(id, onNewEndpoint, d, s) go b.dispatchMsgs() @@ -65,7 +66,7 @@ func (b *Bus) Listen(l Listener) { // SubscribeClient subscribes a new client to the bus. Duplicate subscriptions // are forbidden and will cause a panic. The supplied consumer will receive all // messages that are sent to the requested address. -func (b *Bus) SubscribeClient(c wire.Consumer, addr map[int]wire.Address) error { +func (b *Bus) SubscribeClient(c wire.Consumer, addr map[wallet.BackendID]wire.Address) error { b.addSubscriber(c, addr) c.OnCloseAlways(func() { b.removeSubscriber(addr) }) return nil @@ -114,7 +115,7 @@ func (b *Bus) Close() error { return b.reg.Close() } -func (b *Bus) addSubscriber(c wire.Consumer, addr map[int]wire.Address) { +func (b *Bus) addSubscriber(c wire.Consumer, addr map[wallet.BackendID]wire.Address) { b.mutex.Lock() defer b.mutex.Unlock() @@ -152,7 +153,7 @@ func (b *Bus) dispatchMsgs() { } } -func (b *Bus) removeSubscriber(addr map[int]wire.Address) { +func (b *Bus) removeSubscriber(addr map[wallet.BackendID]wire.Address) { b.mutex.Lock() defer b.mutex.Unlock() diff --git a/wire/net/bus_test.go b/wire/net/bus_test.go index c93973bd4..d4458c476 100644 --- a/wire/net/bus_test.go +++ b/wire/net/bus_test.go @@ -15,6 +15,7 @@ package net_test import ( + "perun.network/go-perun/wallet" "testing" "github.com/stretchr/testify/assert" @@ -32,10 +33,10 @@ func TestBus(t *testing.T) { var hub nettest.ConnHub - wiretest.GenericBusTest(t, func(acc wire.Account) (wire.Bus, wire.Bus) { + wiretest.GenericBusTest(t, func(acc map[wallet.BackendID]wire.Account) (wire.Bus, wire.Bus) { bus := net.NewBus(acc, hub.NewNetDialer(), perunio.Serializer()) hub.OnClose(func() { bus.Close() }) - go bus.Listen(hub.NewNetListener(acc.Address())) + go bus.Listen(hub.NewNetListener(wire.AddressMapfromAccountMap(acc))) return bus, bus }, numClients, numMsgs) diff --git a/wire/net/dialer.go b/wire/net/dialer.go index 0f3640e46..b18aa335e 100644 --- a/wire/net/dialer.go +++ b/wire/net/dialer.go @@ -16,6 +16,7 @@ package net import ( "context" + "perun.network/go-perun/wallet" "perun.network/go-perun/wire" ) @@ -31,7 +32,7 @@ type Dialer interface { // // Dial needs to be reentrant, and concurrent calls to Close() must abort // any ongoing Dial() calls. - Dial(ctx context.Context, addr map[int]wire.Address, ser wire.EnvelopeSerializer) (Conn, error) + Dial(ctx context.Context, addr map[wallet.BackendID]wire.Address, ser wire.EnvelopeSerializer) (Conn, error) // Close aborts any ongoing calls to Dial(). // // Close() needs to be reentrant, and repeated calls to Close() need to diff --git a/wire/net/endpoint.go b/wire/net/endpoint.go index 95034ebf6..71017448a 100644 --- a/wire/net/endpoint.go +++ b/wire/net/endpoint.go @@ -18,6 +18,7 @@ import ( "context" "fmt" "io" + "perun.network/go-perun/wallet" "github.com/pkg/errors" @@ -34,8 +35,8 @@ import ( // Sending messages to a node is done via the Send() method. To receive messages // from an Endpoint, use the Receiver helper type (by subscribing). type Endpoint struct { - Address map[int]wire.Address // The Endpoint's Perun address. - conn Conn // The Endpoint's connection. + Address map[wallet.BackendID]wire.Address // The Endpoint's Perun address. + conn Conn // The Endpoint's connection. sending sync.Mutex // Blocks multiple Send calls. } @@ -96,7 +97,7 @@ func (p *Endpoint) Close() (err error) { } // newEndpoint creates a new Endpoint from a wire Address and connection. -func newEndpoint(addr map[int]wire.Address, conn Conn) *Endpoint { +func newEndpoint(addr map[wallet.BackendID]wire.Address, conn Conn) *Endpoint { return &Endpoint{ Address: addr, conn: conn, diff --git a/wire/net/endpoint_internal_test.go b/wire/net/endpoint_internal_test.go index a1eca3514..1618af418 100644 --- a/wire/net/endpoint_internal_test.go +++ b/wire/net/endpoint_internal_test.go @@ -18,6 +18,7 @@ import ( "context" "math/rand" "perun.network/go-perun/channel" + "perun.network/go-perun/wallet" "sync" "testing" "time" @@ -54,7 +55,7 @@ func makeSetup(rng *rand.Rand) *setup { } // Dial simulates creating a connection to a. -func (s *setup) Dial(ctx context.Context, addr map[int]wire.Address, _ wire.EnvelopeSerializer) (Conn, error) { +func (s *setup) Dial(ctx context.Context, addr map[wallet.BackendID]wire.Address, _ wire.EnvelopeSerializer) (Conn, error) { s.mutex.RLock() defer s.mutex.RUnlock() @@ -98,7 +99,7 @@ type client struct { // makeClient creates a simulated test client. func makeClient(conn Conn, rng *rand.Rand, dialer Dialer) *client { receiver := wire.NewReceiver() - registry := NewEndpointRegistry(wiretest.NewRandomAccount(rng), func(map[int]wire.Address) wire.Consumer { + registry := NewEndpointRegistry(wiretest.NewRandomAccountMap(rng), func(map[wallet.BackendID]wire.Address) wire.Consumer { return receiver }, dialer, perunio.Serializer()) diff --git a/wire/net/endpoint_registry.go b/wire/net/endpoint_registry.go index 03d13d85f..ac5a85ac4 100644 --- a/wire/net/endpoint_registry.go +++ b/wire/net/endpoint_registry.go @@ -17,6 +17,7 @@ package net import ( "context" "perun.network/go-perun/channel/persistence/test" + "perun.network/go-perun/wallet" "sync" "sync/atomic" "time" @@ -32,9 +33,9 @@ import ( // dialingEndpoint is an endpoint that is being dialed, but has no connection // associated with it yet. type dialingEndpoint struct { - Address map[int]wire.Address // The Endpoint's address. - created chan struct{} // Triggered when the Endpoint is created. - createdAt *Endpoint // Contains the finished Endpoint when it exists. + Address map[wallet.BackendID]wire.Address // The Endpoint's address. + created chan struct{} // Triggered when the Endpoint is created. + createdAt *Endpoint // Contains the finished Endpoint when it exists. } // fullEndpoint describes an endpoint that is held within the registry. @@ -52,7 +53,7 @@ func newFullEndpoint(e *Endpoint) *fullEndpoint { } } -func newDialingEndpoint(addr map[int]wire.Address) *dialingEndpoint { +func newDialingEndpoint(addr map[wallet.BackendID]wire.Address) *dialingEndpoint { return &dialingEndpoint{ Address: addr, created: make(chan struct{}), @@ -64,9 +65,9 @@ func newDialingEndpoint(addr map[int]wire.Address) *dialingEndpoint { // connections. It should not be used manually, but only internally by a // wire.Bus. type EndpointRegistry struct { - id wire.Account // The identity of the node. - dialer Dialer // Used for dialing peers. - onNewEndpoint func(map[int]wire.Address) wire.Consumer // Selects Consumer for new Endpoints' receive loop. + id map[wallet.BackendID]wire.Account // The identity of the node. + dialer Dialer // Used for dialing peers. + onNewEndpoint func(map[wallet.BackendID]wire.Address) wire.Consumer // Selects Consumer for new Endpoints' receive loop. ser wire.EnvelopeSerializer endpoints map[wire.AddrKey]*fullEndpoint // The list of all of all established Endpoints. @@ -83,8 +84,8 @@ const exchangeAddrsTimeout = 10 * time.Second // The provided callback is used to set up new peer's subscriptions and it is // called before the peer starts receiving messages. func NewEndpointRegistry( - id wire.Account, - onNewEndpoint func(map[int]wire.Address) wire.Consumer, + id map[wallet.BackendID]wire.Account, + onNewEndpoint func(map[wallet.BackendID]wire.Address) wire.Consumer, dialer Dialer, ser wire.EnvelopeSerializer, ) *EndpointRegistry { @@ -97,7 +98,7 @@ func NewEndpointRegistry( endpoints: make(map[wire.AddrKey]*fullEndpoint), dialing: make(map[wire.AddrKey]*dialingEndpoint), - Embedding: log.MakeEmbedding(log.WithField("id", id.Address())), + Embedding: log.MakeEmbedding(log.WithField("id", id)), } } @@ -168,7 +169,7 @@ func (r *EndpointRegistry) setupConn(conn Conn) error { ctx, cancel := context.WithTimeout(r.Ctx(), exchangeAddrsTimeout) defer cancel() - var peerAddr map[int]wire.Address + var peerAddr map[wallet.BackendID]wire.Address var err error if peerAddr, err = ExchangeAddrsPassive(ctx, r.id, conn); err != nil { conn.Close() @@ -176,7 +177,7 @@ func (r *EndpointRegistry) setupConn(conn Conn) error { return err } - if test.EqualWireMaps(peerAddr, r.id.Address()) { + if test.EqualWireMaps(peerAddr, wire.AddressMapfromAccountMap(r.id)) { r.Log().Error("dialed by self") return errors.New("dialed by self") } @@ -188,11 +189,11 @@ func (r *EndpointRegistry) setupConn(conn Conn) error { // Endpoint looks up an Endpoint via its perun address. If the Endpoint does not // exist yet, it is dialed. Does not return until the peer is dialed or the // context is closed. -func (r *EndpointRegistry) Endpoint(ctx context.Context, addr map[int]wire.Address) (*Endpoint, error) { +func (r *EndpointRegistry) Endpoint(ctx context.Context, addr map[wallet.BackendID]wire.Address) (*Endpoint, error) { log := r.Log().WithField("peer", addr) key := wire.Keys(addr) - if test.EqualWireMaps(addr, r.id.Address()) { + if test.EqualWireMaps(addr, wire.AddressMapfromAccountMap(r.id)) { log.Panic("tried to dial self") } @@ -218,7 +219,7 @@ func (r *EndpointRegistry) Endpoint(ctx context.Context, addr map[int]wire.Addre func (r *EndpointRegistry) authenticatedDial( ctx context.Context, - addr map[int]wire.Address, + addr map[wallet.BackendID]wire.Address, de *dialingEndpoint, created bool, ) (ret *Endpoint, _ error) { @@ -262,7 +263,7 @@ func (r *EndpointRegistry) authenticatedDial( } // dialingEndpoint retrieves or creates a dialingEndpoint for the passed address. -func (r *EndpointRegistry) dialingEndpoint(a map[int]wire.Address) (_ *dialingEndpoint, created bool) { +func (r *EndpointRegistry) dialingEndpoint(a map[wallet.BackendID]wire.Address) (_ *dialingEndpoint, created bool) { key := wire.Keys(a) entry, ok := r.dialing[key] if !ok { @@ -284,7 +285,7 @@ func (r *EndpointRegistry) NumPeers() int { // Has return true if and only if there is a peer with the given address in the // registry. The function does not differentiate between regular and // placeholder peers. -func (r *EndpointRegistry) Has(addr map[int]wire.Address) bool { +func (r *EndpointRegistry) Has(addr map[wallet.BackendID]wire.Address) bool { r.mutex.Lock() defer r.mutex.Unlock() @@ -294,13 +295,13 @@ func (r *EndpointRegistry) Has(addr map[int]wire.Address) bool { } // addEndpoint adds a new peer to the registry. -func (r *EndpointRegistry) addEndpoint(addr map[int]wire.Address, conn Conn, dialer bool) *Endpoint { +func (r *EndpointRegistry) addEndpoint(addr map[wallet.BackendID]wire.Address, conn Conn, dialer bool) *Endpoint { r.Log().WithField("peer", addr).Trace("EndpointRegistry.addEndpoint") e := newEndpoint(addr, conn) fe, created := r.fullEndpoint(addr, e) if !created { - if e, closed := fe.replace(e, r.id.Address(), dialer); closed { + if e, closed := fe.replace(e, wire.AddressMapfromAccountMap(r.id), dialer); closed { return e } } @@ -318,7 +319,7 @@ func (r *EndpointRegistry) addEndpoint(addr map[int]wire.Address, conn Conn, dia } // fullEndpoint retrieves or creates a fullEndpoint for the passed address. -func (r *EndpointRegistry) fullEndpoint(addr map[int]wire.Address, e *Endpoint) (_ *fullEndpoint, created bool) { +func (r *EndpointRegistry) fullEndpoint(addr map[wallet.BackendID]wire.Address, e *Endpoint) (_ *fullEndpoint, created bool) { key := wire.Keys(addr) r.mutex.Lock() defer r.mutex.Unlock() @@ -333,7 +334,7 @@ func (r *EndpointRegistry) fullEndpoint(addr map[int]wire.Address, e *Endpoint) // replace sets a new endpoint and resolves ties when both parties dial each // other concurrently. It returns the endpoint that is selected after potential // tie resolving, and whether the supplied endpoint was closed in the process. -func (p *fullEndpoint) replace(newValue *Endpoint, self map[int]wire.Address, dialer bool) (updated *Endpoint, closed bool) { +func (p *fullEndpoint) replace(newValue *Endpoint, self map[wallet.BackendID]wire.Address, dialer bool) (updated *Endpoint, closed bool) { // If there was no previous endpoint, just set the new one. wasNil := atomic.CompareAndSwapPointer(&p.endpoint, nil, unsafe.Pointer(newValue)) if wasNil { @@ -383,7 +384,7 @@ func (p *fullEndpoint) delete(expectedOldValue *Endpoint) { atomic.CompareAndSwapPointer(&p.endpoint, unsafe.Pointer(expectedOldValue), nil) } -func (r *EndpointRegistry) find(addr map[int]wire.Address) *Endpoint { +func (r *EndpointRegistry) find(addr map[wallet.BackendID]wire.Address) *Endpoint { r.mutex.RLock() defer r.mutex.RUnlock() if e, ok := r.endpoints[wire.Keys(addr)]; ok { diff --git a/wire/net/endpoint_registry_external_test.go b/wire/net/endpoint_registry_external_test.go index 18a5ee8e6..0a087701c 100644 --- a/wire/net/endpoint_registry_external_test.go +++ b/wire/net/endpoint_registry_external_test.go @@ -17,6 +17,7 @@ package net_test import ( "context" "perun.network/go-perun/channel" + "perun.network/go-perun/wallet" "testing" "time" @@ -35,7 +36,7 @@ import ( var timeout = 100 * time.Millisecond -func nilConsumer(map[int]wire.Address) wire.Consumer { return nil } +func nilConsumer(map[wallet.BackendID]wire.Address) wire.Consumer { return nil } // Two nodes (1 dialer, 1 listener node) .Get() each other. func TestEndpointRegistry_Get_Pair(t *testing.T) { @@ -43,11 +44,11 @@ func TestEndpointRegistry_Get_Pair(t *testing.T) { assert, require := assert.New(t), require.New(t) rng := test.Prng(t) var hub nettest.ConnHub - dialerID := wiretest.NewRandomAccount(rng) - listenerID := wiretest.NewRandomAccount(rng) + dialerID := wiretest.NewRandomAccountMap(rng) + listenerID := wiretest.NewRandomAccountMap(rng) dialerReg := net.NewEndpointRegistry(dialerID, nilConsumer, hub.NewNetDialer(), perunio.Serializer()) listenerReg := net.NewEndpointRegistry(listenerID, nilConsumer, nil, perunio.Serializer()) - listener := hub.NewNetListener(listenerID.Address()) + listener := hub.NewNetListener(wire.AddressMapfromAccountMap(listenerID)) done := make(chan struct{}) go func() { @@ -57,17 +58,17 @@ func TestEndpointRegistry_Get_Pair(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 2*timeout) defer cancel() - p, err := dialerReg.Endpoint(ctx, listenerID.Address()) + p, err := dialerReg.Endpoint(ctx, wire.AddressMapfromAccountMap(listenerID)) assert.NoError(err) require.NotNil(p) - assert.True(channel.EqualWireMaps(p.Address, listenerID.Address())) + assert.True(channel.EqualWireMaps(p.Address, wire.AddressMapfromAccountMap(listenerID))) // should allow the listener routine to add the peer to its registry time.Sleep(timeout) - p, err = listenerReg.Endpoint(ctx, dialerID.Address()) + p, err = listenerReg.Endpoint(ctx, wire.AddressMapfromAccountMap(dialerID)) assert.NoError(err) require.NotNil(p) - assert.True(channel.EqualWireMaps(p.Address, dialerID.Address())) + assert.True(channel.EqualWireMaps(p.Address, wire.AddressMapfromAccountMap(dialerID))) listenerReg.Close() dialerReg.Close() @@ -83,16 +84,16 @@ func TestEndpointRegistry_Get_Multiple(t *testing.T) { assert := assert.New(t) rng := test.Prng(t) var hub nettest.ConnHub - dialerID := wiretest.NewRandomAccount(rng) - listenerID := wiretest.NewRandomAccount(rng) + dialerID := wiretest.NewRandomAccountMap(rng) + listenerID := wiretest.NewRandomAccountMap(rng) dialer := hub.NewNetDialer() - logPeer := func(addr map[int]wire.Address) wire.Consumer { + logPeer := func(addr map[wallet.BackendID]wire.Address) wire.Consumer { t.Logf("subscribing %s\n", wire.Keys(addr)) return nil } dialerReg := net.NewEndpointRegistry(dialerID, logPeer, dialer, perunio.Serializer()) listenerReg := net.NewEndpointRegistry(listenerID, logPeer, nil, perunio.Serializer()) - listener := hub.NewNetListener(listenerID.Address()) + listener := hub.NewNetListener(wire.AddressMapfromAccountMap(listenerID)) done := make(chan struct{}) go func() { @@ -107,10 +108,10 @@ func TestEndpointRegistry_Get_Multiple(t *testing.T) { peers := make(chan *net.Endpoint, N) for i := 0; i < N; i++ { go func() { - p, err := dialerReg.Endpoint(ctx, listenerID.Address()) + p, err := dialerReg.Endpoint(ctx, wire.AddressMapfromAccountMap(listenerID)) assert.NoError(err) if p != nil { - assert.True(channel.EqualWireMaps(p.Address, listenerID.Address())) + assert.True(channel.EqualWireMaps(p.Address, wire.AddressMapfromAccountMap(listenerID))) } peers <- p }() @@ -136,10 +137,10 @@ func TestEndpointRegistry_Get_Multiple(t *testing.T) { // should allow the listener routine to add the peer to its registry time.Sleep(timeout) - p, err := listenerReg.Endpoint(ctx, dialerID.Address()) + p, err := listenerReg.Endpoint(ctx, wire.AddressMapfromAccountMap(dialerID)) assert.NoError(err) assert.NotNil(p) - assert.True(channel.EqualWireMaps(p.Address, dialerID.Address())) + assert.True(channel.EqualWireMaps(p.Address, wire.AddressMapfromAccountMap(dialerID))) assert.Equal(1, listener.NumAccepted()) listenerReg.Close() diff --git a/wire/net/endpoint_registry_internal_test.go b/wire/net/endpoint_registry_internal_test.go index 66edb80f3..f10afad63 100644 --- a/wire/net/endpoint_registry_internal_test.go +++ b/wire/net/endpoint_registry_internal_test.go @@ -17,6 +17,7 @@ package net import ( "context" "net" + "perun.network/go-perun/wallet" "sync" "testing" "time" @@ -51,7 +52,7 @@ func (d *mockDialer) Close() error { return nil } -func (d *mockDialer) Dial(ctx context.Context, addr map[int]wire.Address, _ wire.EnvelopeSerializer) (Conn, error) { +func (d *mockDialer) Dial(ctx context.Context, addr map[wallet.BackendID]wire.Address, _ wire.EnvelopeSerializer) (Conn, error) { d.mutex.Lock() defer d.mutex.Unlock() @@ -104,7 +105,7 @@ func newMockListener() *mockListener { return &mockListener{dialer: mockDialer{dial: make(chan Conn)}} } -func nilConsumer(map[int]wire.Address) wire.Consumer { return nil } +func nilConsumer(map[wallet.BackendID]wire.Address) wire.Consumer { return nil } // TestRegistry_Get tests that when calling Get(), existing peers are returned, // and when unknown peers are requested, a temporary peer is create that is @@ -114,9 +115,9 @@ func nilConsumer(map[int]wire.Address) wire.Consumer { return nil } func TestRegistry_Get(t *testing.T) { t.Parallel() rng := test.Prng(t) - id := wiretest.NewRandomAccount(rng) - peerID := wiretest.NewRandomAccount(rng) - peerAddr := peerID.Address() + id := wiretest.NewRandomAccountMap(rng) + peerID := wiretest.NewRandomAccountMap(rng) + peerAddr := wire.AddressMapfromAccountMap(peerID) t.Run("peer already in progress (existing)", func(t *testing.T) { t.Parallel() @@ -179,12 +180,12 @@ func TestRegistry_Get(t *testing.T) { func TestRegistry_authenticatedDial(t *testing.T) { t.Parallel() rng := test.Prng(t) - id := wiretest.NewRandomAccount(rng) + id := wiretest.NewRandomAccountMap(rng) d := &mockDialer{dial: make(chan Conn)} r := NewEndpointRegistry(id, nilConsumer, d, perunio.Serializer()) - remoteID := wiretest.NewRandomAccount(rng) - remoteAddr := remoteID.Address() + remoteID := wiretest.NewRandomAccountMap(rng) + remoteAddr := wire.AddressMapfromAccountMap(remoteID) t.Run("dial fail", func(t *testing.T) { addr := wiretest.NewRandomAddress(rng) @@ -206,7 +207,7 @@ func TestRegistry_authenticatedDial(t *testing.T) { } err := b.Send(&wire.Envelope{ Sender: remoteAddr, - Recipient: id.Address(), + Recipient: wire.AddressMapfromAccountMap(id), Msg: wire.NewPingMsg(), }) if err != nil { @@ -228,7 +229,7 @@ func TestRegistry_authenticatedDial(t *testing.T) { a, b := newPipeConnPair() go ct.Stage("passive", func(rt test.ConcT) { d.put(a) - _, err := ExchangeAddrsPassive(ctx, wiretest.NewRandomAccount(rng), b) + _, err := ExchangeAddrsPassive(ctx, wiretest.NewRandomAccountMap(rng), b) require.True(rt, IsAuthenticationError(err)) }) de, created := r.dialingEndpoint(remoteAddr) @@ -261,8 +262,8 @@ func TestRegistry_authenticatedDial(t *testing.T) { func TestRegistry_setupConn(t *testing.T) { t.Parallel() rng := test.Prng(t) - id := wiretest.NewRandomAccount(rng) - remoteID := wiretest.NewRandomAccount(rng) + id := wiretest.NewRandomAccountMap(rng) + remoteID := wiretest.NewRandomAccountMap(rng) t.Run("ExchangeAddrs fail", func(t *testing.T) { d := &mockDialer{dial: make(chan Conn)} @@ -270,8 +271,8 @@ func TestRegistry_setupConn(t *testing.T) { a, b := newPipeConnPair() go func() { err := b.Send(&wire.Envelope{ - Sender: id.Address(), - Recipient: remoteID.Address(), + Sender: wire.AddressMapfromAccountMap(id), + Recipient: wire.AddressMapfromAccountMap(remoteID), Msg: wire.NewPingMsg(), }) if err != nil { @@ -288,13 +289,13 @@ func TestRegistry_setupConn(t *testing.T) { r := NewEndpointRegistry(id, nilConsumer, d, perunio.Serializer()) a, b := newPipeConnPair() go func() { - err := ExchangeAddrsActive(context.Background(), remoteID, id.Address(), b) + err := ExchangeAddrsActive(context.Background(), remoteID, wire.AddressMapfromAccountMap(id), b) if err != nil { panic(err) } }() - r.addEndpoint(remoteID.Address(), newMockConn(), false) + r.addEndpoint(wire.AddressMapfromAccountMap(remoteID), newMockConn(), false) ctxtest.AssertTerminates(t, timeout, func() { assert.NoError(t, r.setupConn(a)) }) @@ -305,7 +306,7 @@ func TestRegistry_setupConn(t *testing.T) { r := NewEndpointRegistry(id, nilConsumer, d, perunio.Serializer()) a, b := newPipeConnPair() go func() { - err := ExchangeAddrsActive(context.Background(), remoteID, id.Address(), b) + err := ExchangeAddrsActive(context.Background(), remoteID, wire.AddressMapfromAccountMap(id), b) if err != nil { panic(err) } @@ -323,10 +324,10 @@ func TestRegistry_Listen(t *testing.T) { rng := test.Prng(t) - id := wiretest.NewRandomAccount(rng) - addr := id.Address() - remoteID := wiretest.NewRandomAccount(rng) - remoteAddr := remoteID.Address() + id := wiretest.NewRandomAccountMap(rng) + addr := wire.AddressMapfromAccountMap(id) + remoteID := wiretest.NewRandomAccountMap(rng) + remoteAddr := wire.AddressMapfromAccountMap(remoteID) d := newMockDialer() l := newMockListener() @@ -365,8 +366,8 @@ func TestRegistry_addEndpoint_Subscribe(t *testing.T) { rng := test.Prng(t) called := false r := NewEndpointRegistry( - wiretest.NewRandomAccount(rng), - func(map[int]wire.Address) wire.Consumer { called = true; return nil }, + wiretest.NewRandomAccountMap(rng), + func(map[wallet.BackendID]wire.Address) wire.Consumer { called = true; return nil }, nil, perunio.Serializer(), ) @@ -383,7 +384,7 @@ func TestRegistry_Close(t *testing.T) { t.Run("double close error", func(t *testing.T) { r := NewEndpointRegistry( - wiretest.NewRandomAccount(rng), + wiretest.NewRandomAccountMap(rng), nilConsumer, nil, perunio.Serializer(), @@ -396,7 +397,7 @@ func TestRegistry_Close(t *testing.T) { d := &mockDialer{dial: make(chan Conn)} d.Close() r := NewEndpointRegistry( - wiretest.NewRandomAccount(rng), + wiretest.NewRandomAccountMap(rng), nilConsumer, d, perunio.Serializer(), diff --git a/wire/net/exchange_addr.go b/wire/net/exchange_addr.go index 0b382334a..262d5cdd3 100644 --- a/wire/net/exchange_addr.go +++ b/wire/net/exchange_addr.go @@ -18,6 +18,7 @@ import ( "context" "fmt" "perun.network/go-perun/channel/persistence/test" + "perun.network/go-perun/wallet" "github.com/pkg/errors" @@ -28,11 +29,11 @@ import ( // AuthenticationError describes an error which occures when the ExchangeAddrs // protcol fails because it got a different Address than expected. type AuthenticationError struct { - Sender, Receiver, Own map[int]wire.Address + Sender, Receiver, Own map[wallet.BackendID]wire.Address } // NewAuthenticationError creates a new AuthenticationError. -func NewAuthenticationError(sender, receiver, own map[int]wire.Address, msg string) error { +func NewAuthenticationError(sender, receiver, own map[wallet.BackendID]wire.Address, msg string) error { return errors.Wrap(&AuthenticationError{ Sender: sender, Receiver: receiver, @@ -57,7 +58,7 @@ func IsAuthenticationError(err error) bool { // In the future, it will be extended to become a proper authentication // protocol. The protocol will then exchange Perun addresses and establish // authenticity. -func ExchangeAddrsActive(ctx context.Context, id wire.Account, peer map[int]wire.Address, conn Conn) error { +func ExchangeAddrsActive(ctx context.Context, id map[wallet.BackendID]wire.Account, peer map[wallet.BackendID]wire.Address, conn Conn) error { var err error ok := pkg.TerminatesCtx(ctx, func() { authMsg, err2 := wire.NewAuthResponseMsg(id) @@ -66,7 +67,7 @@ func ExchangeAddrsActive(ctx context.Context, id wire.Account, peer map[int]wire return } err = conn.Send(&wire.Envelope{ - Sender: id.Address(), + Sender: wire.AddressMapfromAccountMap(id), Recipient: peer, Msg: authMsg, }) @@ -82,9 +83,9 @@ func ExchangeAddrsActive(ctx context.Context, id wire.Account, peer map[int]wire err = errors.Errorf("expected AuthResponse wire msg, got %v", e.Msg.Type()) } else if check := VerifyAddressSignature(peer, e.Msg.(*wire.AuthResponseMsg).Signature); check != nil { err = errors.WithMessage(err, "verifying peer address's signature") - } else if !test.EqualWireMaps(e.Recipient, id.Address()) && + } else if !test.EqualWireMaps(e.Recipient, wire.AddressMapfromAccountMap(id)) && !test.EqualWireMaps(e.Sender, peer) { - err = NewAuthenticationError(e.Sender, e.Recipient, id.Address(), "unmatched response sender or recipient") + err = NewAuthenticationError(e.Sender, e.Recipient, wire.AddressMapfromAccountMap(id), "unmatched response sender or recipient") } }) @@ -98,17 +99,18 @@ func ExchangeAddrsActive(ctx context.Context, id wire.Account, peer map[int]wire // ExchangeAddrsPassive executes the passive role of the address exchange // protocol. It is executed by the person that listens for incoming connections. -func ExchangeAddrsPassive(ctx context.Context, id wire.Account, conn Conn) (map[int]wire.Address, error) { - var addr map[int]wire.Address +func ExchangeAddrsPassive(ctx context.Context, id map[wallet.BackendID]wire.Account, conn Conn) (map[wallet.BackendID]wire.Address, error) { + var addr map[wallet.BackendID]wire.Address var err error + addrs := wire.AddressMapfromAccountMap(id) ok := pkg.TerminatesCtx(ctx, func() { var e *wire.Envelope if e, err = conn.Recv(); err != nil { err = errors.WithMessage(err, "receiving auth message") } else if _, ok := e.Msg.(*wire.AuthResponseMsg); !ok { err = errors.Errorf("expected AuthResponse wire msg, got %v", e.Msg.Type()) - } else if !test.EqualWireMaps(e.Recipient, id.Address()) { - err = NewAuthenticationError(e.Sender, e.Recipient, id.Address(), "unmatched response sender or recipient") + } else if !test.EqualWireMaps(e.Recipient, addrs) { + err = NewAuthenticationError(e.Sender, e.Recipient, wire.AddressMapfromAccountMap(id), "unmatched response sender or recipient") } else if err = VerifyAddressSignature(e.Sender, e.Msg.(*wire.AuthResponseMsg).Signature); err != nil { err = errors.WithMessage(err, "verifying peer address's signature") } @@ -123,7 +125,7 @@ func ExchangeAddrsPassive(ctx context.Context, id wire.Account, conn Conn) (map[ return } addr, err = e.Sender, conn.Send(&wire.Envelope{ - Sender: id.Address(), + Sender: wire.AddressMapfromAccountMap(id), Recipient: e.Sender, Msg: authMsg, }) @@ -141,7 +143,7 @@ func ExchangeAddrsPassive(ctx context.Context, id wire.Account, conn Conn) (map[ // VerifyAddressSignature verifies a signature against the hash of an address. // It relies on the MarshalBinary method of the provided wire.Address interface to generate the address hash. // In case the MarshalBinary method doesn't produce the expected hash, the verification may fail. -func VerifyAddressSignature(addrs map[int]wire.Address, sig []byte) error { +func VerifyAddressSignature(addrs map[wallet.BackendID]wire.Address, sig []byte) error { var addressBytes []byte addressBytes = append(addressBytes, byte(len(addrs))) for _, addr := range addrs { diff --git a/wire/net/exchange_addr_internal_test.go b/wire/net/exchange_addr_internal_test.go index 0b160ca60..8e0b07955 100644 --- a/wire/net/exchange_addr_internal_test.go +++ b/wire/net/exchange_addr_internal_test.go @@ -32,7 +32,7 @@ func TestExchangeAddrs_ConnFail(t *testing.T) { rng := test.Prng(t) a, _ := newPipeConnPair() a.Close() - addr, err := ExchangeAddrsPassive(context.Background(), wiretest.NewRandomAccount(rng), a) + addr, err := ExchangeAddrsPassive(context.Background(), wiretest.NewRandomAccountMap(rng), a) assert.Nil(t, addr) assert.Error(t, err) } @@ -41,7 +41,7 @@ func TestExchangeAddrs_Success(t *testing.T) { rng := test.Prng(t) conn0, conn1 := newPipeConnPair() defer conn0.Close() - account0, account1 := wiretest.NewRandomAccount(rng), wiretest.NewRandomAccount(rng) + account0, account1 := wiretest.NewRandomAccountMap(rng), wiretest.NewRandomAccountMap(rng) var wg sync.WaitGroup wg.Add(1) @@ -51,10 +51,10 @@ func TestExchangeAddrs_Success(t *testing.T) { recvAddr0, err := ExchangeAddrsPassive(context.Background(), account1, conn1) assert.NoError(t, err) - assert.True(t, channel.EqualWireMaps(recvAddr0, account0.Address())) + assert.True(t, channel.EqualWireMaps(recvAddr0, wire.AddressMapfromAccountMap(account0))) }() - err := ExchangeAddrsActive(context.Background(), account0, account1.Address(), conn0) + err := ExchangeAddrsActive(context.Background(), account0, wire.AddressMapfromAccountMap(account1), conn0) assert.NoError(t, err) wg.Wait() @@ -67,7 +67,7 @@ func TestExchangeAddrs_Timeout(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() ctxtest.AssertTerminates(t, 2*timeout, func() { - addr, err := ExchangeAddrsPassive(ctx, wiretest.NewRandomAccount(rng), a) + addr, err := ExchangeAddrsPassive(ctx, wiretest.NewRandomAccountMap(rng), a) assert.Nil(t, addr) assert.Error(t, err) }) @@ -75,7 +75,7 @@ func TestExchangeAddrs_Timeout(t *testing.T) { func TestExchangeAddrs_BogusMsg(t *testing.T) { rng := test.Prng(t) - acc := wiretest.NewRandomAccount(rng) + acc := wiretest.NewRandomAccountMap(rng) conn := newMockConn() conn.recvQueue <- wiretest.NewRandomEnvelope(rng, wire.NewPingMsg()) addr, err := ExchangeAddrsPassive(context.Background(), acc, conn) diff --git a/wire/net/simple/account.go b/wire/net/simple/account.go index 6e8e954c4..4e207851c 100644 --- a/wire/net/simple/account.go +++ b/wire/net/simple/account.go @@ -19,9 +19,8 @@ import ( crypto_rand "crypto/rand" "crypto/rsa" "crypto/sha256" - "math/rand" - "github.com/pkg/errors" + "math/rand" "perun.network/go-perun/wire" ) @@ -32,8 +31,8 @@ type Account struct { } // Address returns the account's address. -func (acc *Account) Address() map[int]wire.Address { - return map[int]wire.Address{0: acc.addr} +func (acc *Account) Address() wire.Address { + return acc.addr } // Sign signs the given message with the account's private key. diff --git a/wire/net/simple/address.go b/wire/net/simple/address.go index 9cbf8d554..88543d2ec 100644 --- a/wire/net/simple/address.go +++ b/wire/net/simple/address.go @@ -22,6 +22,7 @@ import ( "encoding/binary" "math/big" "math/rand" + "perun.network/go-perun/wallet" "perun.network/go-perun/wire" ) @@ -193,7 +194,7 @@ func NewRandomAddress(rng *rand.Rand) *Address { } // NewRandomAddress returns a new random peer address. -func NewRandomAddresses(rng *rand.Rand) map[int]wire.Address { +func NewRandomAddresses(rng *rand.Rand) map[wallet.BackendID]wire.Address { const addrLen = 32 l := rng.Intn(addrLen) d := make([]byte, l) @@ -204,7 +205,7 @@ func NewRandomAddresses(rng *rand.Rand) map[int]wire.Address { a := Address{ Name: string(d), } - return map[int]wire.Address{0: &a} + return map[wallet.BackendID]wire.Address{0: &a} } // Verify verifies a message signature. diff --git a/wire/net/simple/dialer.go b/wire/net/simple/dialer.go index 7000c37af..485342d0b 100644 --- a/wire/net/simple/dialer.go +++ b/wire/net/simple/dialer.go @@ -18,6 +18,7 @@ import ( "context" "crypto/tls" "net" + "perun.network/go-perun/wallet" "sync" "time" @@ -77,7 +78,7 @@ func (d *Dialer) host(key wire.AddrKey) (string, bool) { } // Dial implements Dialer.Dial(). -func (d *Dialer) Dial(ctx context.Context, addr map[int]wire.Address, ser wire.EnvelopeSerializer) (wirenet.Conn, error) { +func (d *Dialer) Dial(ctx context.Context, addr map[wallet.BackendID]wire.Address, ser wire.EnvelopeSerializer) (wirenet.Conn, error) { done := make(chan struct{}) defer close(done) @@ -107,7 +108,7 @@ func (d *Dialer) Dial(ctx context.Context, addr map[int]wire.Address, ser wire.E } // Register registers a network address for a peer address. -func (d *Dialer) Register(addr map[int]wire.Address, address string) { +func (d *Dialer) Register(addr map[wallet.BackendID]wire.Address, address string) { d.mutex.Lock() defer d.mutex.Unlock() diff --git a/wire/net/simple/dialer_internal_test.go b/wire/net/simple/dialer_internal_test.go index 9d0eaa410..0d800feb9 100644 --- a/wire/net/simple/dialer_internal_test.go +++ b/wire/net/simple/dialer_internal_test.go @@ -25,6 +25,7 @@ import ( "fmt" "math/big" "net" + "perun.network/go-perun/wallet" "testing" "time" @@ -66,7 +67,7 @@ func TestDialer_Register(t *testing.T) { _, ok := d.host(key) require.False(t, ok) - d.Register(map[int]wire.Address{0: addr}, "host") + d.Register(map[wallet.BackendID]wire.Address{0: addr}, "host") host, ok := d.host(key) assert.True(t, ok) @@ -77,7 +78,7 @@ func TestDialer_Dial(t *testing.T) { timeout := 100 * time.Millisecond rng := test.Prng(t) lhost := "127.0.0.1:7357" - laddr := wiretest.NewRandomAccount(rng).Address() + laddr := wire.AddressMapfromAccountMap(wiretest.NewRandomAccountMap(rng)) commonName := "127.0.0.1" sans := []string{"127.0.0.1", "localhost"} @@ -91,7 +92,7 @@ func TestDialer_Dial(t *testing.T) { ser := perunio.Serializer() d := NewTCPDialer(timeout, dConfig) d.Register(laddr, lhost) - daddr := wiretest.NewRandomAccount(rng).Address() + daddr := wire.AddressMapfromAccountMap(wiretest.NewRandomAccountMap(rng)) defer d.Close() t.Run("happy", func(t *testing.T) { diff --git a/wire/net/simple/simple_exchange_addr_test.go b/wire/net/simple/simple_exchange_addr_test.go index 4ba562640..454a42056 100644 --- a/wire/net/simple/simple_exchange_addr_test.go +++ b/wire/net/simple/simple_exchange_addr_test.go @@ -43,7 +43,7 @@ func TestExchangeAddrs_ConnFail(t *testing.T) { rng := test.Prng(t) a, _ := newPipeConnPair() a.Close() - addr, err := wirenet.ExchangeAddrsPassive(context.Background(), wiretest.NewRandomAccount(rng), a) + addr, err := wirenet.ExchangeAddrsPassive(context.Background(), wiretest.NewRandomAccountMap(rng), a) assert.Nil(t, addr) assert.Error(t, err) } @@ -52,7 +52,7 @@ func TestExchangeAddrs_Success(t *testing.T) { rng := test.Prng(t) conn0, conn1 := newPipeConnPair() defer conn0.Close() - account0, account1 := wiretest.NewRandomAccount(rng), wiretest.NewRandomAccount(rng) + account0, account1 := wiretest.NewRandomAccountMap(rng), wiretest.NewRandomAccountMap(rng) var wg sync.WaitGroup wg.Add(1) @@ -62,10 +62,10 @@ func TestExchangeAddrs_Success(t *testing.T) { recvAddr0, err := wirenet.ExchangeAddrsPassive(context.Background(), account1, conn1) assert.NoError(t, err) - assert.True(t, channel.EqualWireMaps(recvAddr0, account0.Address())) + assert.True(t, channel.EqualWireMaps(recvAddr0, wire.AddressMapfromAccountMap(account0))) }() - err := wirenet.ExchangeAddrsActive(context.Background(), account0, account1.Address(), conn0) + err := wirenet.ExchangeAddrsActive(context.Background(), account0, wire.AddressMapfromAccountMap(account1), conn0) assert.NoError(t, err) wg.Wait() @@ -78,7 +78,7 @@ func TestExchangeAddrs_Timeout(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() ctxtest.AssertTerminates(t, 20*timeout, func() { - addr, err := wirenet.ExchangeAddrsPassive(ctx, wiretest.NewRandomAccount(rng), a) + addr, err := wirenet.ExchangeAddrsPassive(ctx, wiretest.NewRandomAccountMap(rng), a) assert.Nil(t, addr) assert.Error(t, err) }) @@ -86,7 +86,7 @@ func TestExchangeAddrs_Timeout(t *testing.T) { func TestExchangeAddrs_BogusMsg(t *testing.T) { rng := test.Prng(t) - acc := wiretest.NewRandomAccount(rng) + acc := wiretest.NewRandomAccountMap(rng) conn := newMockConn() conn.recvQueue <- newRandomEnvelope(rng, wire.NewPingMsg()) addr, err := wirenet.ExchangeAddrsPassive(context.Background(), acc, conn) diff --git a/wire/net/test/connhub.go b/wire/net/test/connhub.go index e5b744b70..54c53f961 100644 --- a/wire/net/test/connhub.go +++ b/wire/net/test/connhub.go @@ -15,6 +15,7 @@ package test import ( + "perun.network/go-perun/wallet" gosync "sync" "github.com/pkg/errors" @@ -35,7 +36,7 @@ type ConnHub struct { // NewNetListener creates a new test listener for the given address. // Registers the new listener in the hub. Panics if the address was already // entered or the hub is closed. -func (h *ConnHub) NewNetListener(addr map[int]wire.Address) *Listener { +func (h *ConnHub) NewNetListener(addr map[wallet.BackendID]wire.Address) *Listener { h.mutex.RLock() defer h.mutex.RUnlock() diff --git a/wire/net/test/connhub_internal_test.go b/wire/net/test/connhub_internal_test.go index f061c765d..35f47f8be 100644 --- a/wire/net/test/connhub_internal_test.go +++ b/wire/net/test/connhub_internal_test.go @@ -16,6 +16,7 @@ package test import ( "context" + "perun.network/go-perun/wallet" "testing" "github.com/stretchr/testify/assert" @@ -121,7 +122,7 @@ func TestConnHub_Close(t *testing.T) { l := c.NewNetListener(wiretest.NewRandomAddress(rng)) l2 := NewNetListener() l2.Close() - err := c.insert(wiretest.NewRandomAccount(rng).Address(), l2) + err := c.insert(map[wallet.BackendID]wire.Address{0: wiretest.NewRandomAccount(rng).Address()}, l2) assert.NoError(err) assert.Error(c.Close()) assert.True(l.IsClosed()) diff --git a/wire/net/test/dialer.go b/wire/net/test/dialer.go index e13c6367a..86f4c5879 100644 --- a/wire/net/test/dialer.go +++ b/wire/net/test/dialer.go @@ -17,6 +17,7 @@ package test import ( "context" "net" + "perun.network/go-perun/wallet" "sync/atomic" "github.com/pkg/errors" @@ -44,7 +45,7 @@ func NewDialer(hub *ConnHub) *Dialer { } // Dial tries to connect to a wire. -func (d *Dialer) Dial(ctx context.Context, address map[int]wire.Address, ser wire.EnvelopeSerializer) (wirenet.Conn, error) { +func (d *Dialer) Dial(ctx context.Context, address map[wallet.BackendID]wire.Address, ser wire.EnvelopeSerializer) (wirenet.Conn, error) { if d.IsClosed() { return nil, errors.New("dialer closed") } diff --git a/wire/net/test/listenermap.go b/wire/net/test/listenermap.go index 05759fba8..a685d37b1 100644 --- a/wire/net/test/listenermap.go +++ b/wire/net/test/listenermap.go @@ -16,6 +16,7 @@ package test import ( "perun.network/go-perun/channel/persistence/test" + "perun.network/go-perun/wallet" "sync" "github.com/pkg/errors" @@ -24,7 +25,7 @@ import ( // listenerMapEntry is a key-value entry inside a listener map. type listenerMapEntry struct { - key map[int]wire.Address + key map[wallet.BackendID]wire.Address value *Listener } @@ -36,7 +37,7 @@ type listenerMap struct { // findEntry is not mutexed, and is only to be called from within the type's // other functions. -func (m *listenerMap) findEntry(key map[int]wire.Address) (listenerMapEntry, int, bool) { +func (m *listenerMap) findEntry(key map[wallet.BackendID]wire.Address) (listenerMapEntry, int, bool) { for i, v := range m.entries { if test.EqualWireMaps(v.key, key) { return v, i, true @@ -46,7 +47,7 @@ func (m *listenerMap) findEntry(key map[int]wire.Address) (listenerMapEntry, int return listenerMapEntry{}, -1, false } -func (m *listenerMap) find(key map[int]wire.Address) (*Listener, bool) { +func (m *listenerMap) find(key map[wallet.BackendID]wire.Address) (*Listener, bool) { m.mutex.RLock() defer m.mutex.RUnlock() @@ -56,7 +57,7 @@ func (m *listenerMap) find(key map[int]wire.Address) (*Listener, bool) { return nil, false } -func (m *listenerMap) insert(key map[int]wire.Address, value *Listener) error { +func (m *listenerMap) insert(key map[wallet.BackendID]wire.Address, value *Listener) error { m.mutex.Lock() defer m.mutex.Unlock() if _, _, ok := m.findEntry(key); ok { @@ -66,7 +67,7 @@ func (m *listenerMap) insert(key map[int]wire.Address, value *Listener) error { return nil } -func (m *listenerMap) erase(key map[int]wire.Address) error { +func (m *listenerMap) erase(key map[wallet.BackendID]wire.Address) error { m.mutex.Lock() defer m.mutex.Unlock() diff --git a/wire/protobuf/proposalmsgs.go b/wire/protobuf/proposalmsgs.go index 99c500e94..5ccc53427 100644 --- a/wire/protobuf/proposalmsgs.go +++ b/wire/protobuf/proposalmsgs.go @@ -71,7 +71,7 @@ func ToVirtualChannelProposalMsg(protoEnvMsg *Envelope_VirtualChannelProposalMsg if err != nil { return nil, errors.WithMessage(err, "proposer") } - msg.Parents = make([]map[int]channel.ID, len(protoMsg.Parents)) + msg.Parents = make([]map[wallet.BackendID]channel.ID, len(protoMsg.Parents)) for i := range protoMsg.Parents { msg.Parents[i], err = ToIDs(protoMsg.Parents[i]) } @@ -129,26 +129,26 @@ func ToChannelProposalRejMsg(protoEnvMsg *Envelope_ChannelProposalRejMsg) (msg * } // ToWalletAddr converts a protobuf wallet address to a wallet.Address. -func ToWalletAddr(protoAddr *Address) (map[int]wallet.Address, error) { - addrMap := make(map[int]wallet.Address) +func ToWalletAddr(protoAddr *Address) (map[wallet.BackendID]wallet.Address, error) { + addrMap := make(map[wallet.BackendID]wallet.Address) for i := range protoAddr.AddressMapping { var k int32 if err := binary.Read(bytes.NewReader(protoAddr.AddressMapping[i].Key), binary.BigEndian, &k); err != nil { return nil, fmt.Errorf("failed to read key: %w", err) } - addr := wallet.NewAddress(int(k)) + addr := wallet.NewAddress(wallet.BackendID(k)) if err := addr.UnmarshalBinary(protoAddr.AddressMapping[i].Address); err != nil { return nil, fmt.Errorf("failed to unmarshal address for key %d: %w", k, err) } - addrMap[int(k)] = addr + addrMap[wallet.BackendID(k)] = addr } return addrMap, nil } // ToWireAddr converts a protobuf wallet address to a wallet.Address. -func ToWireAddr(protoAddr *Address) (map[int]wire.Address, error) { - addrMap := make(map[int]wire.Address) +func ToWireAddr(protoAddr *Address) (map[wallet.BackendID]wire.Address, error) { + addrMap := make(map[wallet.BackendID]wire.Address) for i := range protoAddr.AddressMapping { var k int32 if err := binary.Read(bytes.NewReader(protoAddr.AddressMapping[i].Key), binary.BigEndian, &k); err != nil { @@ -159,14 +159,14 @@ func ToWireAddr(protoAddr *Address) (map[int]wire.Address, error) { return nil, fmt.Errorf("failed to unmarshal address for key %d: %w", k, err) } - addrMap[int(k)] = addr + addrMap[wallet.BackendID(k)] = addr } return addrMap, nil } // ToWalletAddrs converts protobuf wallet addresses to a slice of wallet.Address. -func ToWalletAddrs(protoAddrs []*Address) ([]map[int]wallet.Address, error) { - addrs := make([]map[int]wallet.Address, len(protoAddrs)) +func ToWalletAddrs(protoAddrs []*Address) ([]map[wallet.BackendID]wallet.Address, error) { + addrs := make([]map[wallet.BackendID]wallet.Address, len(protoAddrs)) for i := range protoAddrs { addrMap, err := ToWalletAddr(protoAddrs[i]) if err != nil { @@ -178,8 +178,8 @@ func ToWalletAddrs(protoAddrs []*Address) ([]map[int]wallet.Address, error) { } // ToWireAddrs converts protobuf wire addresses to a slice of wire.Address. -func ToWireAddrs(protoAddrs []*Address) ([]map[int]wire.Address, error) { - addrMap := make([]map[int]wire.Address, len(protoAddrs)) +func ToWireAddrs(protoAddrs []*Address) ([]map[wallet.BackendID]wire.Address, error) { + addrMap := make([]map[wallet.BackendID]wire.Address, len(protoAddrs)) var err error for i, addMap := range protoAddrs { addrMap[i], err = ToWireAddr(addMap) @@ -191,8 +191,8 @@ func ToWireAddrs(protoAddrs []*Address) ([]map[int]wire.Address, error) { } // ToIDs converts protobuf ID to a map[int]channel.ID. -func ToIDs(protoID *ID) (map[int]channel.ID, error) { - iDMap := make(map[int]channel.ID) +func ToIDs(protoID *ID) (map[wallet.BackendID]channel.ID, error) { + iDMap := make(map[wallet.BackendID]channel.ID) for i := range protoID.IdMapping { var k int32 if err := binary.Read(bytes.NewReader(protoID.IdMapping[i].Key), binary.BigEndian, &k); err != nil { @@ -204,7 +204,7 @@ func ToIDs(protoID *ID) (map[int]channel.ID, error) { id := channel.ID{} copy(id[:], protoID.IdMapping[i].Id) - iDMap[int(k)] = id + iDMap[wallet.BackendID(k)] = id } return iDMap, nil } @@ -266,8 +266,8 @@ func ToAppAndData(protoApp, protoData []byte) (app channel.App, data channel.Dat } // ToIntSlice converts a [][]byte field from a protobuf message to a []int. -func ToIntSlice(backends [][]byte) ([]int, error) { - ints := make([]int, len(backends)) +func ToIntSlice(backends [][]byte) ([]wallet.BackendID, error) { + ints := make([]wallet.BackendID, len(backends)) for i, backend := range backends { if len(backend) != 4 { @@ -280,7 +280,7 @@ func ToIntSlice(backends [][]byte) ([]int, error) { return nil, fmt.Errorf("failed to convert backend %d bytes to int: %w", i, err) } - ints[i] = int(value) + ints[i] = wallet.BackendID(value) } return ints, nil @@ -438,7 +438,7 @@ func FromChannelProposalRejMsg(msg *client.ChannelProposalRejMsg) (_ *Envelope_C } // FromWalletAddr converts a wallet.Address to a protobuf wallet address. -func FromWalletAddr(addr map[int]wallet.Address) (*Address, error) { +func FromWalletAddr(addr map[wallet.BackendID]wallet.Address) (*Address, error) { var addressMappings []*AddressMapping for key, address := range addr { @@ -462,7 +462,7 @@ func FromWalletAddr(addr map[int]wallet.Address) (*Address, error) { } // FromWireAddr converts a wallet.Address to a protobuf wire address. -func FromWireAddr(addr map[int]wire.Address) (*Address, error) { +func FromWireAddr(addr map[wallet.BackendID]wire.Address) (*Address, error) { var addressMappings []*AddressMapping for key, address := range addr { @@ -486,7 +486,7 @@ func FromWireAddr(addr map[int]wire.Address) (*Address, error) { } // FromWalletAddrs converts a slice of wallet.Address to protobuf wallet addresses. -func FromWalletAddrs(addrs []map[int]wallet.Address) (protoAddrs []*Address, err error) { +func FromWalletAddrs(addrs []map[wallet.BackendID]wallet.Address) (protoAddrs []*Address, err error) { protoAddrs = make([]*Address, len(addrs)) for i := range addrs { protoAddrs[i], err = FromWalletAddr(addrs[i]) @@ -498,7 +498,7 @@ func FromWalletAddrs(addrs []map[int]wallet.Address) (protoAddrs []*Address, err } // FromWireAddrs converts a slice of wire.Address to protobuf wire addresses. -func FromWireAddrs(addrs []map[int]wire.Address) (protoAddrs []*Address, err error) { +func FromWireAddrs(addrs []map[wallet.BackendID]wire.Address) (protoAddrs []*Address, err error) { protoAddrs = make([]*Address, len(addrs)) for i := range addrs { protoAddrs[i], err = FromWireAddr(addrs[i]) @@ -510,7 +510,7 @@ func FromWireAddrs(addrs []map[int]wire.Address) (protoAddrs []*Address, err err } // FromIDs converts a map[int]channel.ID to a protobuf ID. -func FromIDs(ids map[int]channel.ID) (*ID, error) { +func FromIDs(ids map[wallet.BackendID]channel.ID) (*ID, error) { var idMappings []*IDMapping for key, id := range ids { diff --git a/wire/protobuf/serializer.go b/wire/protobuf/serializer.go index f68c332fa..da8571297 100644 --- a/wire/protobuf/serializer.go +++ b/wire/protobuf/serializer.go @@ -18,6 +18,7 @@ import ( "encoding/binary" "fmt" "io" + "perun.network/go-perun/wallet" "github.com/pkg/errors" "google.golang.org/protobuf/proto" @@ -181,7 +182,7 @@ func readEnvelope(r io.Reader) (*Envelope, error) { return &protoEnv, errors.Wrap(proto.Unmarshal(data, &protoEnv), "unmarshalling envelope") } -func unmarshalSenderRecipient(protoEnv *Envelope) (map[int]wire.Address, map[int]wire.Address, error) { +func unmarshalSenderRecipient(protoEnv *Envelope) (map[wallet.BackendID]wire.Address, map[wallet.BackendID]wire.Address, error) { sender, err := ToWireAddr(protoEnv.Sender) if err != nil { return nil, nil, errors.Wrap(err, "unmarshalling sender address") diff --git a/wire/test/bustest.go b/wire/test/bustest.go index 7d0271c99..541b55fce 100644 --- a/wire/test/bustest.go +++ b/wire/test/bustest.go @@ -16,6 +16,7 @@ package test import ( "context" + "perun.network/go-perun/wallet" "testing" "time" @@ -38,7 +39,7 @@ const testNoReceiveTimeout = 10 * time.Millisecond // can either return the same bus twice, or separately select a bus to subscribe // the client to, and a bus the client should use for publishing messages. func GenericBusTest(t *testing.T, - busAssigner func(wire.Account) (pub wire.Bus, sub wire.Bus), + busAssigner func(map[wallet.BackendID]wire.Account) (pub wire.Bus, sub wire.Bus), numClients, numMsgs int, ) { t.Helper() @@ -49,13 +50,13 @@ func GenericBusTest(t *testing.T, type Client struct { r *wire.Relay pub, sub wire.Bus - id wire.Account + id map[wallet.BackendID]wire.Account } clients := make([]Client, numClients) for i := range clients { clients[i].r = wire.NewRelay() - clients[i].id = NewRandomAccount(rng) + clients[i].id = NewRandomAccountMap(rng) clients[i].pub, clients[i].sub = busAssigner(clients[i].id) } @@ -95,14 +96,14 @@ func GenericBusTest(t *testing.T, } sender, recipient := sender, recipient origEnv := &wire.Envelope{ - Sender: clients[sender].id.Address(), - Recipient: clients[recipient].id.Address(), + Sender: wire.AddressMapfromAccountMap(clients[sender].id), + Recipient: wire.AddressMapfromAccountMap(clients[recipient].id), Msg: wire.NewPingMsg(), } // Only subscribe to the current sender. recv := wire.NewReceiver() err := clients[recipient].r.Subscribe(recv, func(e *wire.Envelope) bool { - return equalMaps(e.Sender, clients[sender].id.Address()) + return equalMaps(e.Sender, wire.AddressMapfromAccountMap(clients[sender].id)) }) require.NoError(t, err) @@ -139,7 +140,7 @@ func GenericBusTest(t *testing.T, // publishing. testPublishAndReceive(t, func() { for i := range clients { - err := clients[i].sub.SubscribeClient(clients[i].r, clients[i].id.Address()) + err := clients[i].sub.SubscribeClient(clients[i].r, wire.AddressMapfromAccountMap(clients[i].id)) require.NoError(t, err) } }) @@ -150,7 +151,7 @@ func GenericBusTest(t *testing.T, testPublishAndReceive(t, func() {}) } -func equalMaps(a, b map[int]wire.Address) bool { +func equalMaps(a, b map[wallet.BackendID]wire.Address) bool { if len(a) != len(b) { return false } diff --git a/wire/test/msgstest.go b/wire/test/msgstest.go index 5d876097a..77586f7ba 100644 --- a/wire/test/msgstest.go +++ b/wire/test/msgstest.go @@ -40,7 +40,7 @@ func AuthMsgsSerializationTest(t *testing.T, serializerTest func(t *testing.T, m t.Helper() rng := pkgtest.Prng(t) - testMsg, err := wire.NewAuthResponseMsg(NewRandomAccount(rng)) + testMsg, err := wire.NewAuthResponseMsg(NewRandomAccountMap(rng)) if err != nil { t.Fatal(err) } diff --git a/wire/test/randomizer.go b/wire/test/randomizer.go index 1119a4104..58bdb7c32 100644 --- a/wire/test/randomizer.go +++ b/wire/test/randomizer.go @@ -16,6 +16,7 @@ package test import ( "math/rand" + "perun.network/go-perun/wallet" "perun.network/go-perun/wire" ) @@ -43,8 +44,8 @@ func SetNewRandomAccount(f NewRandomAccountFunc) { } // NewRandomAddress returns a new random address. -func NewRandomAddress(rng *rand.Rand) map[int]wire.Address { - return map[int]wire.Address{0: newRandomAddress(rng)} +func NewRandomAddress(rng *rand.Rand) map[wallet.BackendID]wire.Address { + return map[wallet.BackendID]wire.Address{0: newRandomAddress(rng)} } // NewRandomAccount returns a new random account. @@ -52,9 +53,14 @@ func NewRandomAccount(rng *rand.Rand) wire.Account { return newRandomAccount(rng) } +// NewRandomAccountMap returns a new random account. +func NewRandomAccountMap(rng *rand.Rand) map[wallet.BackendID]wire.Account { + return map[wallet.BackendID]wire.Account{0: newRandomAccount(rng)} +} + // NewRandomAddresses returns a slice of random peer addresses. -func NewRandomAddresses(rng *rand.Rand, n int) []map[int]wire.Address { - addresses := make([]map[int]wire.Address, n) +func NewRandomAddresses(rng *rand.Rand, n int) []map[wallet.BackendID]wire.Address { + addresses := make([]map[wallet.BackendID]wire.Address, n) for i := range addresses { addresses[i] = NewRandomAddress(rng) } @@ -62,8 +68,8 @@ func NewRandomAddresses(rng *rand.Rand, n int) []map[int]wire.Address { } // NewRandomAddressesMap returns a slice of random peer addresses. -func NewRandomAddressesMap(rng *rand.Rand, n int) []map[int]wire.Address { - addresses := make([]map[int]wire.Address, n) +func NewRandomAddressesMap(rng *rand.Rand, n int) []map[wallet.BackendID]wire.Address { + addresses := make([]map[wallet.BackendID]wire.Address, n) for i := range addresses { addresses[i] = NewRandomAddress(rng) } From 8181cb099f3396ddef0334f91ab5b8775bf41253 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Wed, 11 Sep 2024 12:57:27 +0200 Subject: [PATCH 06/36] fix(Adjudicator): Change to singular channel ID in events. Signed-off-by: Sophia Koehler --- channel/adjudicator.go | 18 +++++++++--------- channel/multi/subscription.go | 3 +-- channel/persistence/statemachine_test.go | 2 +- channel/test/backend.go | 9 ++++++--- client/test/backend.go | 6 +++--- client/test/subchannel_dispute.go | 2 +- watcher/local/watcher.go | 4 ++-- watcher/local/watcher_test.go | 6 +++--- 8 files changed, 26 insertions(+), 24 deletions(-) diff --git a/channel/adjudicator.go b/channel/adjudicator.go index 2b3910186..238b94bb3 100644 --- a/channel/adjudicator.go +++ b/channel/adjudicator.go @@ -158,7 +158,7 @@ type ( // cause, currently either a Registered or Progressed event. // The type of the event should be checked with a type switch. AdjudicatorEvent interface { - ID() map[wallet.BackendID]ID + ID() ID Timeout() Timeout Version() uint64 } @@ -166,9 +166,9 @@ type ( // An AdjudicatorEventBase implements the AdjudicatorEvent interface. It can // be embedded to implement an AdjudicatorEvent. AdjudicatorEventBase struct { - IDV map[wallet.BackendID]ID // Channel ID - TimeoutV Timeout // Current phase timeout - VersionV uint64 // Registered version + IDV ID // Channel ID + TimeoutV Timeout // Current phase timeout + VersionV uint64 // Registered version } // ProgressedEvent is the abstract event that signals an on-chain progression. @@ -213,7 +213,7 @@ func NewProgressReq(ar AdjudicatorReq, newState *State, sig wallet.Sig) *Progres } // NewAdjudicatorEventBase creates a new AdjudicatorEventBase object. -func NewAdjudicatorEventBase(c map[wallet.BackendID]ID, t Timeout, v uint64) *AdjudicatorEventBase { +func NewAdjudicatorEventBase(c ID, t Timeout, v uint64) *AdjudicatorEventBase { return &AdjudicatorEventBase{ IDV: c, TimeoutV: t, @@ -222,7 +222,7 @@ func NewAdjudicatorEventBase(c map[wallet.BackendID]ID, t Timeout, v uint64) *Ad } // ID returns the channel ID. -func (b AdjudicatorEventBase) ID() map[wallet.BackendID]ID { return b.IDV } +func (b AdjudicatorEventBase) ID() ID { return b.IDV } // Timeout returns the phase timeout. func (b AdjudicatorEventBase) Timeout() Timeout { return b.TimeoutV } @@ -231,7 +231,7 @@ func (b AdjudicatorEventBase) Timeout() Timeout { return b.TimeoutV } func (b AdjudicatorEventBase) Version() uint64 { return b.VersionV } // NewRegisteredEvent creates a new RegisteredEvent. -func NewRegisteredEvent(id map[wallet.BackendID]ID, timeout Timeout, version uint64, state *State, sigs []wallet.Sig) *RegisteredEvent { +func NewRegisteredEvent(id ID, timeout Timeout, version uint64, state *State, sigs []wallet.Sig) *RegisteredEvent { return &RegisteredEvent{ AdjudicatorEventBase: AdjudicatorEventBase{ IDV: id, @@ -244,7 +244,7 @@ func NewRegisteredEvent(id map[wallet.BackendID]ID, timeout Timeout, version uin } // NewProgressedEvent creates a new ProgressedEvent. -func NewProgressedEvent(id map[wallet.BackendID]ID, timeout Timeout, state *State, idx Index) *ProgressedEvent { +func NewProgressedEvent(id ID, timeout Timeout, state *State, idx Index) *ProgressedEvent { return &ProgressedEvent{ AdjudicatorEventBase: AdjudicatorEventBase{ IDV: id, @@ -257,7 +257,7 @@ func NewProgressedEvent(id map[wallet.BackendID]ID, timeout Timeout, state *Stat } // NewConcludedEvent creates a new ConcludedEvent. -func NewConcludedEvent(id map[wallet.BackendID]ID, timeout Timeout, version uint64) *ConcludedEvent { +func NewConcludedEvent(id ID, timeout Timeout, version uint64) *ConcludedEvent { return &ConcludedEvent{ AdjudicatorEventBase: AdjudicatorEventBase{ IDV: id, diff --git a/channel/multi/subscription.go b/channel/multi/subscription.go index 5d54ebaa1..956902b0c 100644 --- a/channel/multi/subscription.go +++ b/channel/multi/subscription.go @@ -16,9 +16,8 @@ package multi import ( "context" - "perun.network/go-perun/wallet" - "perun.network/go-perun/channel" + "perun.network/go-perun/wallet" ) // Subscribe creates a new multi-ledger AdjudicatorSubscription. diff --git a/channel/persistence/statemachine_test.go b/channel/persistence/statemachine_test.go index 71dd0473a..29150359a 100644 --- a/channel/persistence/statemachine_test.go +++ b/channel/persistence/statemachine_test.go @@ -152,7 +152,7 @@ func TestStateMachine(t *testing.T) { // Set Progressed timeout := ctest.NewRandomTimeout(rng) idx := channel.Index(rng.Intn(s.NumParts())) - e := channel.NewProgressedEvent(s.ID, timeout, s, idx) + e := channel.NewProgressedEvent(s.ID[0], timeout, s, idx) err = sm.SetProgressed(ctx, e) require.NoError(err) tpr.AssertEqual(csm) diff --git a/channel/test/backend.go b/channel/test/backend.go index 31b3dc229..4b8da65e9 100644 --- a/channel/test/backend.go +++ b/channel/test/backend.go @@ -135,9 +135,12 @@ func genericVerifyTest(t *testing.T, s *Setup, opts ...GenericTestOption) { // Different address and same state and params for i := 0; i < 10; i++ { - ok, err := channel.Verify(s.RandomAddress()[0], s.State, sig) - assert.NoError(t, err, "Verify should not return an error") - assert.False(t, ok, "Verify should return false") + add := s.RandomAddress() + for _, a := range add { + ok, err := channel.Verify(a, s.State, sig) + assert.NoError(t, err, "Verify should not return an error") + assert.False(t, ok, "Verify should return false") + } } } diff --git a/client/test/backend.go b/client/test/backend.go index 00fd22e99..c43626d7c 100644 --- a/client/test/backend.go +++ b/client/test/backend.go @@ -180,7 +180,7 @@ func (b *MockBackend) Register(_ context.Context, req channel.AdjudicatorReq, su b.setLatestEvent( ch.Params.ID(), channel.NewRegisteredEvent( - ch.Params.ID(), + ch.Params.ID()[0], &channel.TimeTimeout{Time: timeout}, ch.State.Version, ch.State, @@ -218,7 +218,7 @@ func (b *MockBackend) Progress(_ context.Context, req channel.ProgressReq) error b.setLatestEvent( req.Params.ID(), channel.NewProgressedEvent( - req.Params.ID(), + req.Params.ID()[0], &channel.TimeTimeout{Time: timeout}, req.NewState.Clone(), req.Idx, @@ -341,7 +341,7 @@ func (b *MockBackend) Withdraw(_ context.Context, req channel.AdjudicatorReq, su } if !b.isConcluded(ch) { - b.setLatestEvent(ch, channel.NewConcludedEvent(ch, &channel.ElapsedTimeout{}, req.Tx.Version)) + b.setLatestEvent(ch, channel.NewConcludedEvent(ch[0], &channel.ElapsedTimeout{}, req.Tx.Version)) } return nil } diff --git a/client/test/subchannel_dispute.go b/client/test/subchannel_dispute.go index 4ee3f6713..5ab70b0af 100644 --- a/client/test/subchannel_dispute.go +++ b/client/test/subchannel_dispute.go @@ -131,7 +131,7 @@ const channelWatcherWait = 100 * time.Millisecond // HandleAdjudicatorEvent is the callback for adjudicator event handling. func (r *DisputeTim) HandleAdjudicatorEvent(e channel.AdjudicatorEvent) { r.log.Infof("HandleAdjudicatorEvent: channelID = %x, version = %v, type = %T", e.ID(), e.Version(), e) - if e, ok := e.(*channel.RegisteredEvent); ok && channel.EqualIDs(e.ID(), r.subCh) { + if e, ok := e.(*channel.RegisteredEvent); ok && e.ID() == r.subCh[0] { r.registered <- e } } diff --git a/watcher/local/watcher.go b/watcher/local/watcher.go index 898c97bda..a5135516f 100644 --- a/watcher/local/watcher.go +++ b/watcher/local/watcher.go @@ -187,7 +187,7 @@ func (w *Watcher) startWatching( var statesPubSub *statesPubSub var eventsToClientPubSub *adjudicatorPubSub - chInitializer := func() (*ch, error) { + chInitializer1 := func() (*ch, error) { eventsFromChainSub, err := w.rs.Subscribe(ctx, id) if err != nil { return nil, errors.WithMessage(err, "subscribing to adjudicator events from blockchain") @@ -198,7 +198,7 @@ func (w *Watcher) startWatching( return newCh(id, parent, signedState.Params, eventsFromChainSub, eventsToClientPubSub, statesPubSub, multiLedger), nil } - ch, err := w.registry.addIfSucceeds(id, chInitializer) + ch, err := w.registry.addIfSucceeds(id, chInitializer1) if err != nil { return nil, nil, err } diff --git a/watcher/local/watcher_test.go b/watcher/local/watcher_test.go index cd6f41bde..897c251d7 100644 --- a/watcher/local/watcher_test.go +++ b/watcher/local/watcher_test.go @@ -897,7 +897,7 @@ func makeRegisteredEvents(txs ...channel.Transaction) []channel.AdjudicatorEvent State: tx.State, Sigs: tx.Sigs, AdjudicatorEventBase: channel.AdjudicatorEventBase{ - IDV: tx.State.ID, + IDV: tx.State.ID[0], TimeoutV: &channel.ElapsedTimeout{}, VersionV: tx.State.Version, }, @@ -913,7 +913,7 @@ func makeProgressedEvents(txs ...channel.Transaction) []channel.AdjudicatorEvent State: tx.State, Idx: channel.Index(0), AdjudicatorEventBase: channel.AdjudicatorEventBase{ - IDV: tx.State.ID, + IDV: tx.State.ID[0], TimeoutV: &channel.ElapsedTimeout{}, VersionV: tx.State.Version, }, @@ -927,7 +927,7 @@ func makeConcludedEvents(txs ...channel.Transaction) []channel.AdjudicatorEvent for i, tx := range txs { events[i] = &channel.ConcludedEvent{ AdjudicatorEventBase: channel.AdjudicatorEventBase{ - IDV: tx.State.ID, + IDV: tx.State.ID[0], TimeoutV: &channel.ElapsedTimeout{}, VersionV: tx.State.Version, }, From 794298a399ebe3de869599d0b37d69e3cd420096 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Wed, 11 Sep 2024 13:12:11 +0200 Subject: [PATCH 07/36] fix(client/test): Generalize role test. Signed-off-by: Sophia Koehler --- client/test/role.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/test/role.go b/client/test/role.go index aa00d6ce8..979809983 100644 --- a/client/test/role.go +++ b/client/test/role.go @@ -135,10 +135,14 @@ func NewClients(t *testing.T, rng *rand.Rand, setups []RoleSetup) []*Client { } cl, err := client.New(wire.AddressMapfromAccountMap(setup.Identity), setup.Bus, setup.Funder, setup.Adjudicator, setupWallet, setup.Watcher) assert.NoError(t, err) + walletAddress := make(map[wallet.BackendID]wallet.Address) + for i, w := range setup.Wallet { + walletAddress[i] = w.NewRandomAccount(rng).Address() + } clients[i] = &Client{ Client: cl, RoleSetup: setup, - WalletAddress: map[wallet.BackendID]wallet.Address{0: setup.Wallet[0].NewRandomAccount(rng).Address()}, + WalletAddress: walletAddress, } } return clients From 969c6a7cbaffb93b92765db020f394d1add8f982 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Fri, 20 Sep 2024 14:10:16 +0200 Subject: [PATCH 08/36] feat(channel): Add backend field check. feat(client/test, wire): Add backendID arguments. Signed-off-by: Sophia Koehler --- channel/allocation.go | 23 ++++++++++++++++++- channel/backend.go | 2 +- channel/params.go | 2 +- client/appchannel_test.go | 2 +- client/client_persistence_test.go | 2 +- client/client_role_test.go | 6 ++--- client/client_test.go | 9 ++++++-- client/failing_funding_test.go | 2 +- client/payment_test.go | 4 ++-- client/proposal.go | 8 +++++++ client/subchannel_test.go | 4 ++-- client/test/channel.go | 3 ++- client/test/fund.go | 8 +++++-- client/test/multiledger_dispute.go | 4 +++- client/test/role.go | 14 ++++++++---- client/test/subchannel.go | 2 +- client/test/subchannel_dispute.go | 2 +- client/test/virtualchannel.go | 10 +++++--- client/virtual_channel.go | 5 ++++ client/virtual_channel_test.go | 2 +- wallet/address.go | 4 ++++ wallet/test/randomizer.go | 4 ++-- wire/net/endpoint_internal_test.go | 2 +- wire/net/endpoint_registry_external_test.go | 8 +++---- wire/net/endpoint_registry_internal_test.go | 24 ++++++++++---------- wire/net/exchange_addr_internal_test.go | 8 +++---- wire/net/simple/dialer_internal_test.go | 4 ++-- wire/net/simple/simple_exchange_addr_test.go | 8 +++---- wire/test/bustest.go | 2 +- wire/test/msgstest.go | 2 +- wire/test/randomizer.go | 4 ++-- 31 files changed, 121 insertions(+), 63 deletions(-) diff --git a/channel/allocation.go b/channel/allocation.go index 96067ec8b..92d9ceb87 100644 --- a/channel/allocation.go +++ b/channel/allocation.go @@ -332,7 +332,7 @@ func (a Allocation) Encode(w io.Writer) error { // encode assets for i, asset := range a.Assets { if err := perunio.Encode(w, uint32(a.Backends[i])); err != nil { - return errors.WithMessagef(err, "encoding asset %d", i) + return errors.WithMessagef(err, "encoding backends %d", i) } if err := perunio.Encode(w, asset); err != nil { return errors.WithMessagef(err, "encoding asset %d", i) @@ -596,6 +596,12 @@ func (a *Allocation) Equal(b *Allocation) error { if a == b { return nil } + + // Compare Backends + if err := AssertBackendsEqual(a.Backends, b.Backends); err != nil { + return errors.WithMessage(err, "comparing backends") + } + // Compare Assets if err := AssertAssetsEqual(a.Assets, b.Assets); err != nil { return errors.WithMessage(err, "comparing assets") @@ -625,6 +631,21 @@ func AssertAssetsEqual(a []Asset, b []Asset) error { return nil } +// AssertAssetsEqual returns an error if the given assets are not equal. +func AssertBackendsEqual(a []wallet.BackendID, b []wallet.BackendID) error { + if len(a) != len(b) { + return errors.New("length mismatch") + } + + for i, bID := range a { + if !bID.Equal(b[i]) { + return errors.Errorf("value mismatch at index %d", i) + } + } + + return nil +} + var _ perunio.Serializer = new(SubAlloc) // Valid checks if this suballocation is valid. diff --git a/channel/backend.go b/channel/backend.go index 8a3e9c069..b57745aa3 100644 --- a/channel/backend.go +++ b/channel/backend.go @@ -67,7 +67,7 @@ func CalcID(p *Params) (map[wallet.BackendID]ID, error) { id := make(map[wallet.BackendID]ID) var err error for i := range p.Parts[0] { - id[wallet.BackendID(i)], err = backend[wallet.BackendID(i)].CalcID(p) + id[i], err = backend[i].CalcID(p) if err != nil { return nil, err } diff --git a/channel/params.go b/channel/params.go index cd5ceff48..a09f1eb7d 100644 --- a/channel/params.go +++ b/channel/params.go @@ -146,7 +146,7 @@ func FromIDKey(k string) IDMap { log.Panicf("could not decode map key in FromIDKey: " + err.Error()) } id := ID{} - if err := perunio.Decode(buff, id); err != nil { + if err := perunio.Decode(buff, &id); err != nil { log.Panicf("could not decode map[int]ID in FromIDKey: " + err.Error()) } a[wallet.BackendID(key)] = id diff --git a/client/appchannel_test.go b/client/appchannel_test.go index 58f0af71a..3e0136f2b 100644 --- a/client/appchannel_test.go +++ b/client/appchannel_test.go @@ -31,7 +31,7 @@ import ( func TestProgression(t *testing.T) { rng := pkgtest.Prng(t) - setups := NewSetups(rng, []string{"Paul", "Paula"}) + setups := NewSetups(rng, []string{"Paul", "Paula"}, 0) roles := [2]clienttest.Executer{ clienttest.NewPaul(t, setups[0]), clienttest.NewPaula(t, setups[1]), diff --git a/client/client_persistence_test.go b/client/client_persistence_test.go index d04bc373b..8147ce82f 100644 --- a/client/client_persistence_test.go +++ b/client/client_persistence_test.go @@ -39,7 +39,7 @@ func TestPersistencePetraRobert(t *testing.T) { func NewSetupsPersistence(t *testing.T, rng *rand.Rand, names []string) []ctest.RoleSetup { t.Helper() - setups := NewSetups(rng, names) + setups := NewSetups(rng, names, 0) for i := range names { setups[i].PR = chprtest.NewPersistRestorer(t) } diff --git a/client/client_role_test.go b/client/client_role_test.go index dc5ce4188..b5f115e42 100644 --- a/client/client_role_test.go +++ b/client/client_role_test.go @@ -38,7 +38,7 @@ const ( twoPartyTestTimeout = 20 * time.Second ) -func NewSetups(rng *rand.Rand, names []string) []ctest.RoleSetup { +func NewSetups(rng *rand.Rand, names []string, bID wallet.BackendID) []ctest.RoleSetup { var ( bus = wiretest.NewSerializingLocalBus() n = len(names) @@ -51,11 +51,11 @@ func NewSetups(rng *rand.Rand, names []string) []ctest.RoleSetup { if err != nil { panic("Error initializing watcher: " + err.Error()) } - w := map[wallet.BackendID]wtest.Wallet{0: wtest.NewWallet()} + w := map[wallet.BackendID]wtest.Wallet{bID: wtest.NewWallet()} acc := w[0].NewRandomAccount(rng) setup[i] = ctest.RoleSetup{ Name: names[i], - Identity: wiretest.NewRandomAccountMap(rng), + Identity: wiretest.NewRandomAccountMap(rng, bID), Bus: bus, Funder: backend.NewFunder(acc.Address()), Adjudicator: backend.NewAdjudicator(acc.Address()), diff --git a/client/client_test.go b/client/client_test.go index 7fb36f1a9..4f94a8439 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -94,7 +94,7 @@ func TestChannelRejection(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) defer cancel() - roles := NewSetups(rng, []string{"Alice", "Bob"}) + roles := NewSetups(rng, []string{"Alice", "Bob"}, 0) asset := chtest.NewRandomAsset(rng) clients := ctest.NewClients(t, rng, roles) require := require.New(t) @@ -113,7 +113,12 @@ func TestChannelRejection(t *testing.T) { // Create channel proposal. parts := []map[wallet.BackendID]wire.Address{wire.AddressMapfromAccountMap(alice.Identity), wire.AddressMapfromAccountMap(bob.Identity)} - initAlloc := channel.NewAllocation(len(parts), []wallet.BackendID{0}, asset) + var bID wallet.BackendID + for i := range parts[0] { + bID = i + break + } + initAlloc := channel.NewAllocation(len(parts), []wallet.BackendID{bID}, asset) prop, err := client.NewLedgerChannelProposal( challengeDuration, alice.WalletAddress, diff --git a/client/failing_funding_test.go b/client/failing_funding_test.go index 543cfd094..59a91464a 100644 --- a/client/failing_funding_test.go +++ b/client/failing_funding_test.go @@ -42,7 +42,7 @@ func TestFailingFunding(t *testing.T) { BalanceDelta: big.NewInt(0), }, func(r *rand.Rand) ([2]ctest.RoleSetup, channel.Asset) { - roles := NewSetups(rng, []string{"Frida", "Fred"}) + roles := NewSetups(rng, []string{"Frida", "Fred"}, 0) asset := chtest.NewRandomAsset(rng) return [2]ctest.RoleSetup{roles[0], roles[1]}, asset }, diff --git a/client/payment_test.go b/client/payment_test.go index 37c1d31e6..91e165508 100644 --- a/client/payment_test.go +++ b/client/payment_test.go @@ -33,7 +33,7 @@ func TestPaymentHappy(t *testing.T) { defer cancel() runAliceBobTest(ctx, t, func(rng *rand.Rand) ([]ctest.RoleSetup, [2]ctest.Executer) { - setups := NewSetups(rng, []string{"Alice", "Bob"}) + setups := NewSetups(rng, []string{"Alice", "Bob"}, 0) roles := [2]ctest.Executer{ ctest.NewAlice(t, setups[0]), ctest.NewBob(t, setups[1]), @@ -48,7 +48,7 @@ func TestPaymentDispute(t *testing.T) { defer cancel() const mallory, carol = 0, 1 // Indices of Mallory and Carol - setups := NewSetups(rng, []string{"Mallory", "Carol"}) + setups := NewSetups(rng, []string{"Mallory", "Carol"}, 0) roles := [2]ctest.Executer{ ctest.NewMallory(t, setups[0]), ctest.NewCarol(t, setups[1]), diff --git a/client/proposal.go b/client/proposal.go index 265d245ab..65ef64421 100644 --- a/client/proposal.go +++ b/client/proposal.go @@ -468,6 +468,10 @@ func (c *Client) validSubChannelProposal(proposal *SubChannelProposalMsg) error return errors.WithMessage(err, "parent channel and sub-channel assets do not match") } + if err := channel.AssertBackendsEqual(parentState.Backends, base.InitBals.Backends); err != nil { + return errors.New("parent channel and sub-channel backends do not match") + } + if err := parentState.Balances.AssertGreaterOrEqual(base.InitBals.Balances); err != nil { return errors.WithMessage(err, "insufficient funds") } @@ -493,6 +497,10 @@ func (c *Client) validVirtualChannelProposal(prop *VirtualChannelProposalMsg, ou return errors.WithMessage(err, "unequal assets") } + if err := channel.AssertBackendsEqual(parentState.Backends, prop.InitBals.Backends); err != nil { + return errors.New("unequal backends") + } + if !prop.InitBals.Balances.Equal(prop.FundingAgreement) { return errors.WithMessage(err, "unequal funding agreement") } diff --git a/client/subchannel_test.go b/client/subchannel_test.go index dcaef6225..8266ea01c 100644 --- a/client/subchannel_test.go +++ b/client/subchannel_test.go @@ -31,7 +31,7 @@ import ( func TestSubChannelHappy(t *testing.T) { rng := test.Prng(t) - setups := NewSetups(rng, []string{"Susie", "Tim"}) + setups := NewSetups(rng, []string{"Susie", "Tim"}, 0) roles := [2]ctest.Executer{ ctest.NewSusie(t, setups[0]), ctest.NewTim(t, setups[1]), @@ -70,7 +70,7 @@ func TestSubChannelHappy(t *testing.T) { func TestSubChannelDispute(t *testing.T) { rng := test.Prng(t) - setups := NewSetups(rng, []string{"DisputeSusie", "DisputeTim"}) + setups := NewSetups(rng, []string{"DisputeSusie", "DisputeTim"}, 0) roles := [2]ctest.Executer{ ctest.NewDisputeSusie(t, setups[0]), ctest.NewDisputeTim(t, setups[1]), diff --git a/client/test/channel.go b/client/test/channel.go index 336f201df..9cee1dec3 100644 --- a/client/test/channel.go +++ b/client/test/channel.go @@ -65,10 +65,11 @@ func (ch *paymentChannel) openSubChannel( cfg ExecConfig, initBals []*big.Int, app client.ProposalOpts, + bID wallet.BackendID, ) *paymentChannel { initAlloc := channel.Allocation{ Assets: []channel.Asset{cfg.Asset()}, - Backends: []wallet.BackendID{0}, + Backends: []wallet.BackendID{bID}, Balances: [][]channel.Bal{{initBals[0], initBals[1]}}, } diff --git a/client/test/fund.go b/client/test/fund.go index a57190984..975ff11c2 100644 --- a/client/test/fund.go +++ b/client/test/fund.go @@ -112,9 +112,13 @@ func runFredFridaTest( AlwaysAcceptChannelHandler(ctx, fredWalletAddr, chsFred, errsFred), AlwaysRejectUpdateHandler(ctx, errsFred), ) - + var bID wallet.BackendID + for i := range fridaWalletAddr { + bID = i + break + } // Create the proposal. - initAlloc := channel.NewAllocation(numParts, []wallet.BackendID{0}, asset) + initAlloc := channel.NewAllocation(numParts, []wallet.BackendID{bID}, asset) initAlloc.SetAssetBalances(asset, []*big.Int{fridaInitBal, fredInitBal}) parts := []map[wallet.BackendID]wire.Address{fridaWireAddr, fredWireAddr} prop, err := client.NewLedgerChannelProposal( diff --git a/client/test/multiledger_dispute.go b/client/test/multiledger_dispute.go index 97456ba8e..e74838050 100644 --- a/client/test/multiledger_dispute.go +++ b/client/test/multiledger_dispute.go @@ -61,9 +61,11 @@ func TestMultiLedgerDispute( // Establish ledger channel between Alice and Bob. + bID1 := wallet.BackendID(mlt.Asset1.AssetID().BackendID) + bID2 := wallet.BackendID(mlt.Asset2.AssetID().BackendID) // Create channel proposal. parts := []map[wallet.BackendID]wire.Address{alice.WireAddress, bob.WireAddress} - initAlloc := channel.NewAllocation(len(parts), []wallet.BackendID{0, 0}, mlt.Asset1, mlt.Asset2) + initAlloc := channel.NewAllocation(len(parts), []wallet.BackendID{bID1, bID2}, mlt.Asset1, mlt.Asset2) initAlloc.Balances = initBals prop, err := client.NewLedgerChannelProposal( challengeDuration, diff --git a/client/test/role.go b/client/test/role.go index 979809983..1dd945a40 100644 --- a/client/test/role.go +++ b/client/test/role.go @@ -418,12 +418,12 @@ func (r *role) LedgerChannelProposal(rng *rand.Rand, cfg ExecConfig) *client.Led } peers, asset, bals := cfg.Peers(), cfg.Asset(), cfg.InitBals() - alloc := channel.NewAllocation(len(peers), []wallet.BackendID{0}, asset) + alloc := channel.NewAllocation(len(peers), []wallet.BackendID{cfg.Backend()}, asset) alloc.SetAssetBalances(asset, bals[:]) prop, err := client.NewLedgerChannelProposal( r.challengeDuration, - map[wallet.BackendID]wallet.Address{0: r.setup.Wallet[0].NewRandomAccount(rng).Address()}, + map[wallet.BackendID]wallet.Address{cfg.Backend(): r.setup.Wallet[cfg.Backend()].NewRandomAccount(rng).Address()}, alloc, peers[:], client.WithNonceFrom(rng), @@ -476,7 +476,11 @@ func (h *acceptNextPropHandler) HandleProposal(prop client.ChannelProposal, res func (h *acceptNextPropHandler) Next() (*paymentChannel, error) { var prop client.ChannelProposal var res *client.ProposalResponder - + var bID wallet.BackendID + for i := range h.r.setup.Identity { + bID = i + break + } select { case pr := <-h.props: prop = pr.prop @@ -492,8 +496,8 @@ func (h *acceptNextPropHandler) Next() (*paymentChannel, error) { var acc client.ChannelProposalAccept switch p := prop.(type) { case *client.LedgerChannelProposalMsg: - part := h.r.setup.Wallet[0].NewRandomAccount(h.rng).Address() - acc = p.Accept(map[wallet.BackendID]wallet.Address{0: part}, client.WithNonceFrom(h.rng)) + part := h.r.setup.Wallet[bID].NewRandomAccount(h.rng).Address() + acc = p.Accept(map[wallet.BackendID]wallet.Address{bID: part}, client.WithNonceFrom(h.rng)) h.r.log.Debugf("Accepting ledger channel proposal with participant: %v", part) case *client.SubChannelProposalMsg: diff --git a/client/test/subchannel.go b/client/test/subchannel.go index 3480751d5..7e06d99ef 100644 --- a/client/test/subchannel.go +++ b/client/test/subchannel.go @@ -77,7 +77,7 @@ func (r *Susie) exec(_cfg ExecConfig, ledgerChannel *paymentChannel) { // stage 2 - open subchannels openSubChannel := func(parentChannel *paymentChannel, funds []*big.Int, app client.ProposalOpts) *paymentChannel { - return parentChannel.openSubChannel(rng, cfg, funds, app) + return parentChannel.openSubChannel(rng, cfg, funds, app, cfg.backend) } var subChannels []*paymentChannel diff --git a/client/test/subchannel_dispute.go b/client/test/subchannel_dispute.go index 5ab70b0af..0c86893cc 100644 --- a/client/test/subchannel_dispute.go +++ b/client/test/subchannel_dispute.go @@ -59,7 +59,7 @@ func (r *DisputeSusie) exec(_cfg ExecConfig, ledgerChannel *paymentChannel) { r.waitStage() // Stage 2 - Open sub-channel. - subChannel := ledgerChannel.openSubChannel(rng, cfg, cfg.SubChannelFunds[:], client.WithoutApp()) + subChannel := ledgerChannel.openSubChannel(rng, cfg, cfg.SubChannelFunds[:], client.WithoutApp(), _cfg.Backend()) subReq0 := client.NewTestChannel(subChannel.Channel).AdjudicatorReq() // Store AdjudicatorReq for version 0 r.waitStage() diff --git a/client/test/virtualchannel.go b/client/test/virtualchannel.go index 4234c0796..af141bbfb 100644 --- a/client/test/virtualchannel.go +++ b/client/test/virtualchannel.go @@ -219,7 +219,11 @@ func setupVirtualChannelTest( // Establish ledger channel between Alice and Ingrid. peersAlice := []map[wallet.BackendID]wire.Address{wire.AddressMapfromAccountMap(alice.Identity), wire.AddressMapfromAccountMap(ingrid.Identity)} - initAllocAlice := channel.NewAllocation(len(peersAlice), []wallet.BackendID{0}, asset) + var bID wallet.BackendID + for i := range peersAlice[0] { + bID = i + } + initAllocAlice := channel.NewAllocation(len(peersAlice), []wallet.BackendID{bID}, asset) initAllocAlice.SetAssetBalances(asset, vct.initBalsAlice) lcpAlice, err := client.NewLedgerChannelProposal( setup.ChallengeDuration, @@ -239,7 +243,7 @@ func setupVirtualChannelTest( // Establish ledger channel between Bob and Ingrid. peersBob := []map[wallet.BackendID]wire.Address{wire.AddressMapfromAccountMap(bob.Identity), wire.AddressMapfromAccountMap(ingrid.Identity)} - initAllocBob := channel.NewAllocation(len(peersBob), []wallet.BackendID{0}, asset) + initAllocBob := channel.NewAllocation(len(peersBob), []wallet.BackendID{bID}, asset) initAllocBob.SetAssetBalances(asset, vct.initBalsBob) lcpBob, err := client.NewLedgerChannelProposal( setup.ChallengeDuration, @@ -287,7 +291,7 @@ func setupVirtualChannelTest( initAllocVirtual := channel.Allocation{ Assets: []channel.Asset{asset}, Balances: [][]channel.Bal{initBalsVirtual}, - Backends: []wallet.BackendID{0}, + Backends: []wallet.BackendID{bID}, } indexMapAlice := []channel.Index{0, 1} indexMapBob := []channel.Index{1, 0} diff --git a/client/virtual_channel.go b/client/virtual_channel.go index 36b6feed1..da0421330 100644 --- a/client/virtual_channel.go +++ b/client/virtual_channel.go @@ -292,6 +292,11 @@ func (c *Client) validateVirtualChannelFundingProposal( return errors.WithMessage(err, "assets do not match") } + // Assert equal backends. + if err := channel.AssertBackendsEqual(ch.state().Backends, prop.Initial.State.Backends); err != nil { + return errors.WithMessage(err, "backends do not match") + } + // Assert sufficient funds in parent channel. virtual := transformBalances(prop.Initial.State.Balances, ch.state().NumParts(), subAlloc.IndexMap) if err := ch.state().Balances.AssertGreaterOrEqual(virtual); err != nil { diff --git a/client/virtual_channel_test.go b/client/virtual_channel_test.go index 4e8eda21e..785e37215 100644 --- a/client/virtual_channel_test.go +++ b/client/virtual_channel_test.go @@ -70,7 +70,7 @@ func makeVirtualChannelSetup(rng *rand.Rand) ctest.VirtualChannelSetup { func createVirtualChannelClients(rng *rand.Rand) [3]ctest.RoleSetup { var setupsArray [3]ctest.RoleSetup - setups := NewSetups(rng, []string{"Alice", "Bob", "Ingrid"}) + setups := NewSetups(rng, []string{"Alice", "Bob", "Ingrid"}, 0) copy(setupsArray[:], setups) return setupsArray } diff --git a/wallet/address.go b/wallet/address.go index e30c6648f..2fdce065f 100644 --- a/wallet/address.go +++ b/wallet/address.go @@ -49,6 +49,10 @@ type Address interface { BackendID() BackendID } +func (a *BackendID) Equal(b BackendID) bool { + return *a == b +} + // IndexOfAddr returns the index of the given address in the address slice, // or -1 if it is not part of the slice. func IndexOfAddr(addrs []map[BackendID]Address, addr Address) int { diff --git a/wallet/test/randomizer.go b/wallet/test/randomizer.go index da4c716d2..3f0954706 100644 --- a/wallet/test/randomizer.go +++ b/wallet/test/randomizer.go @@ -117,9 +117,9 @@ func NewRandomAccountMapSlice(rng *rand.Rand, b wallet.BackendID, n int) []map[w // NewRandomAccountMap returns a slice of new random accounts // by calling NewRandomAccount. -func NewRandomAccountMap(rng *rand.Rand) map[wallet.BackendID]wallet.Account { +func NewRandomAccountMap(rng *rand.Rand, id wallet.BackendID) map[wallet.BackendID]wallet.Account { accs := make(map[wallet.BackendID]wallet.Account) - accs[0] = NewRandomAccount(rng) + accs[id] = NewRandomAccount(rng) return accs } diff --git a/wire/net/endpoint_internal_test.go b/wire/net/endpoint_internal_test.go index 1618af418..92d0bf734 100644 --- a/wire/net/endpoint_internal_test.go +++ b/wire/net/endpoint_internal_test.go @@ -99,7 +99,7 @@ type client struct { // makeClient creates a simulated test client. func makeClient(conn Conn, rng *rand.Rand, dialer Dialer) *client { receiver := wire.NewReceiver() - registry := NewEndpointRegistry(wiretest.NewRandomAccountMap(rng), func(map[wallet.BackendID]wire.Address) wire.Consumer { + registry := NewEndpointRegistry(wiretest.NewRandomAccountMap(rng, 0), func(map[wallet.BackendID]wire.Address) wire.Consumer { return receiver }, dialer, perunio.Serializer()) diff --git a/wire/net/endpoint_registry_external_test.go b/wire/net/endpoint_registry_external_test.go index 0a087701c..2e78cfb25 100644 --- a/wire/net/endpoint_registry_external_test.go +++ b/wire/net/endpoint_registry_external_test.go @@ -44,8 +44,8 @@ func TestEndpointRegistry_Get_Pair(t *testing.T) { assert, require := assert.New(t), require.New(t) rng := test.Prng(t) var hub nettest.ConnHub - dialerID := wiretest.NewRandomAccountMap(rng) - listenerID := wiretest.NewRandomAccountMap(rng) + dialerID := wiretest.NewRandomAccountMap(rng, 0) + listenerID := wiretest.NewRandomAccountMap(rng, 0) dialerReg := net.NewEndpointRegistry(dialerID, nilConsumer, hub.NewNetDialer(), perunio.Serializer()) listenerReg := net.NewEndpointRegistry(listenerID, nilConsumer, nil, perunio.Serializer()) listener := hub.NewNetListener(wire.AddressMapfromAccountMap(listenerID)) @@ -84,8 +84,8 @@ func TestEndpointRegistry_Get_Multiple(t *testing.T) { assert := assert.New(t) rng := test.Prng(t) var hub nettest.ConnHub - dialerID := wiretest.NewRandomAccountMap(rng) - listenerID := wiretest.NewRandomAccountMap(rng) + dialerID := wiretest.NewRandomAccountMap(rng, 0) + listenerID := wiretest.NewRandomAccountMap(rng, 0) dialer := hub.NewNetDialer() logPeer := func(addr map[wallet.BackendID]wire.Address) wire.Consumer { t.Logf("subscribing %s\n", wire.Keys(addr)) diff --git a/wire/net/endpoint_registry_internal_test.go b/wire/net/endpoint_registry_internal_test.go index f10afad63..cb4edde1e 100644 --- a/wire/net/endpoint_registry_internal_test.go +++ b/wire/net/endpoint_registry_internal_test.go @@ -115,8 +115,8 @@ func nilConsumer(map[wallet.BackendID]wire.Address) wire.Consumer { return nil } func TestRegistry_Get(t *testing.T) { t.Parallel() rng := test.Prng(t) - id := wiretest.NewRandomAccountMap(rng) - peerID := wiretest.NewRandomAccountMap(rng) + id := wiretest.NewRandomAccountMap(rng, 0) + peerID := wiretest.NewRandomAccountMap(rng, 0) peerAddr := wire.AddressMapfromAccountMap(peerID) t.Run("peer already in progress (existing)", func(t *testing.T) { @@ -180,11 +180,11 @@ func TestRegistry_Get(t *testing.T) { func TestRegistry_authenticatedDial(t *testing.T) { t.Parallel() rng := test.Prng(t) - id := wiretest.NewRandomAccountMap(rng) + id := wiretest.NewRandomAccountMap(rng, 0) d := &mockDialer{dial: make(chan Conn)} r := NewEndpointRegistry(id, nilConsumer, d, perunio.Serializer()) - remoteID := wiretest.NewRandomAccountMap(rng) + remoteID := wiretest.NewRandomAccountMap(rng, 0) remoteAddr := wire.AddressMapfromAccountMap(remoteID) t.Run("dial fail", func(t *testing.T) { @@ -229,7 +229,7 @@ func TestRegistry_authenticatedDial(t *testing.T) { a, b := newPipeConnPair() go ct.Stage("passive", func(rt test.ConcT) { d.put(a) - _, err := ExchangeAddrsPassive(ctx, wiretest.NewRandomAccountMap(rng), b) + _, err := ExchangeAddrsPassive(ctx, wiretest.NewRandomAccountMap(rng, 0), b) require.True(rt, IsAuthenticationError(err)) }) de, created := r.dialingEndpoint(remoteAddr) @@ -262,8 +262,8 @@ func TestRegistry_authenticatedDial(t *testing.T) { func TestRegistry_setupConn(t *testing.T) { t.Parallel() rng := test.Prng(t) - id := wiretest.NewRandomAccountMap(rng) - remoteID := wiretest.NewRandomAccountMap(rng) + id := wiretest.NewRandomAccountMap(rng, 0) + remoteID := wiretest.NewRandomAccountMap(rng, 0) t.Run("ExchangeAddrs fail", func(t *testing.T) { d := &mockDialer{dial: make(chan Conn)} @@ -324,9 +324,9 @@ func TestRegistry_Listen(t *testing.T) { rng := test.Prng(t) - id := wiretest.NewRandomAccountMap(rng) + id := wiretest.NewRandomAccountMap(rng, 0) addr := wire.AddressMapfromAccountMap(id) - remoteID := wiretest.NewRandomAccountMap(rng) + remoteID := wiretest.NewRandomAccountMap(rng, 0) remoteAddr := wire.AddressMapfromAccountMap(remoteID) d := newMockDialer() @@ -366,7 +366,7 @@ func TestRegistry_addEndpoint_Subscribe(t *testing.T) { rng := test.Prng(t) called := false r := NewEndpointRegistry( - wiretest.NewRandomAccountMap(rng), + wiretest.NewRandomAccountMap(rng, 0), func(map[wallet.BackendID]wire.Address) wire.Consumer { called = true; return nil }, nil, perunio.Serializer(), @@ -384,7 +384,7 @@ func TestRegistry_Close(t *testing.T) { t.Run("double close error", func(t *testing.T) { r := NewEndpointRegistry( - wiretest.NewRandomAccountMap(rng), + wiretest.NewRandomAccountMap(rng, 0), nilConsumer, nil, perunio.Serializer(), @@ -397,7 +397,7 @@ func TestRegistry_Close(t *testing.T) { d := &mockDialer{dial: make(chan Conn)} d.Close() r := NewEndpointRegistry( - wiretest.NewRandomAccountMap(rng), + wiretest.NewRandomAccountMap(rng, 0), nilConsumer, d, perunio.Serializer(), diff --git a/wire/net/exchange_addr_internal_test.go b/wire/net/exchange_addr_internal_test.go index 8e0b07955..72fa82813 100644 --- a/wire/net/exchange_addr_internal_test.go +++ b/wire/net/exchange_addr_internal_test.go @@ -32,7 +32,7 @@ func TestExchangeAddrs_ConnFail(t *testing.T) { rng := test.Prng(t) a, _ := newPipeConnPair() a.Close() - addr, err := ExchangeAddrsPassive(context.Background(), wiretest.NewRandomAccountMap(rng), a) + addr, err := ExchangeAddrsPassive(context.Background(), wiretest.NewRandomAccountMap(rng, 0), a) assert.Nil(t, addr) assert.Error(t, err) } @@ -41,7 +41,7 @@ func TestExchangeAddrs_Success(t *testing.T) { rng := test.Prng(t) conn0, conn1 := newPipeConnPair() defer conn0.Close() - account0, account1 := wiretest.NewRandomAccountMap(rng), wiretest.NewRandomAccountMap(rng) + account0, account1 := wiretest.NewRandomAccountMap(rng, 0), wiretest.NewRandomAccountMap(rng, 0) var wg sync.WaitGroup wg.Add(1) @@ -67,7 +67,7 @@ func TestExchangeAddrs_Timeout(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() ctxtest.AssertTerminates(t, 2*timeout, func() { - addr, err := ExchangeAddrsPassive(ctx, wiretest.NewRandomAccountMap(rng), a) + addr, err := ExchangeAddrsPassive(ctx, wiretest.NewRandomAccountMap(rng, 0), a) assert.Nil(t, addr) assert.Error(t, err) }) @@ -75,7 +75,7 @@ func TestExchangeAddrs_Timeout(t *testing.T) { func TestExchangeAddrs_BogusMsg(t *testing.T) { rng := test.Prng(t) - acc := wiretest.NewRandomAccountMap(rng) + acc := wiretest.NewRandomAccountMap(rng, 0) conn := newMockConn() conn.recvQueue <- wiretest.NewRandomEnvelope(rng, wire.NewPingMsg()) addr, err := ExchangeAddrsPassive(context.Background(), acc, conn) diff --git a/wire/net/simple/dialer_internal_test.go b/wire/net/simple/dialer_internal_test.go index 0d800feb9..fe17b4d6f 100644 --- a/wire/net/simple/dialer_internal_test.go +++ b/wire/net/simple/dialer_internal_test.go @@ -78,7 +78,7 @@ func TestDialer_Dial(t *testing.T) { timeout := 100 * time.Millisecond rng := test.Prng(t) lhost := "127.0.0.1:7357" - laddr := wire.AddressMapfromAccountMap(wiretest.NewRandomAccountMap(rng)) + laddr := wire.AddressMapfromAccountMap(wiretest.NewRandomAccountMap(rng, 0)) commonName := "127.0.0.1" sans := []string{"127.0.0.1", "localhost"} @@ -92,7 +92,7 @@ func TestDialer_Dial(t *testing.T) { ser := perunio.Serializer() d := NewTCPDialer(timeout, dConfig) d.Register(laddr, lhost) - daddr := wire.AddressMapfromAccountMap(wiretest.NewRandomAccountMap(rng)) + daddr := wire.AddressMapfromAccountMap(wiretest.NewRandomAccountMap(rng, 0)) defer d.Close() t.Run("happy", func(t *testing.T) { diff --git a/wire/net/simple/simple_exchange_addr_test.go b/wire/net/simple/simple_exchange_addr_test.go index 454a42056..78ad37c9f 100644 --- a/wire/net/simple/simple_exchange_addr_test.go +++ b/wire/net/simple/simple_exchange_addr_test.go @@ -43,7 +43,7 @@ func TestExchangeAddrs_ConnFail(t *testing.T) { rng := test.Prng(t) a, _ := newPipeConnPair() a.Close() - addr, err := wirenet.ExchangeAddrsPassive(context.Background(), wiretest.NewRandomAccountMap(rng), a) + addr, err := wirenet.ExchangeAddrsPassive(context.Background(), wiretest.NewRandomAccountMap(rng, 0), a) assert.Nil(t, addr) assert.Error(t, err) } @@ -52,7 +52,7 @@ func TestExchangeAddrs_Success(t *testing.T) { rng := test.Prng(t) conn0, conn1 := newPipeConnPair() defer conn0.Close() - account0, account1 := wiretest.NewRandomAccountMap(rng), wiretest.NewRandomAccountMap(rng) + account0, account1 := wiretest.NewRandomAccountMap(rng, 0), wiretest.NewRandomAccountMap(rng, 0) var wg sync.WaitGroup wg.Add(1) @@ -78,7 +78,7 @@ func TestExchangeAddrs_Timeout(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() ctxtest.AssertTerminates(t, 20*timeout, func() { - addr, err := wirenet.ExchangeAddrsPassive(ctx, wiretest.NewRandomAccountMap(rng), a) + addr, err := wirenet.ExchangeAddrsPassive(ctx, wiretest.NewRandomAccountMap(rng, 0), a) assert.Nil(t, addr) assert.Error(t, err) }) @@ -86,7 +86,7 @@ func TestExchangeAddrs_Timeout(t *testing.T) { func TestExchangeAddrs_BogusMsg(t *testing.T) { rng := test.Prng(t) - acc := wiretest.NewRandomAccountMap(rng) + acc := wiretest.NewRandomAccountMap(rng, 0) conn := newMockConn() conn.recvQueue <- newRandomEnvelope(rng, wire.NewPingMsg()) addr, err := wirenet.ExchangeAddrsPassive(context.Background(), acc, conn) diff --git a/wire/test/bustest.go b/wire/test/bustest.go index 541b55fce..6e9fb319b 100644 --- a/wire/test/bustest.go +++ b/wire/test/bustest.go @@ -56,7 +56,7 @@ func GenericBusTest(t *testing.T, clients := make([]Client, numClients) for i := range clients { clients[i].r = wire.NewRelay() - clients[i].id = NewRandomAccountMap(rng) + clients[i].id = NewRandomAccountMap(rng, 0) clients[i].pub, clients[i].sub = busAssigner(clients[i].id) } diff --git a/wire/test/msgstest.go b/wire/test/msgstest.go index 77586f7ba..e86a5302a 100644 --- a/wire/test/msgstest.go +++ b/wire/test/msgstest.go @@ -40,7 +40,7 @@ func AuthMsgsSerializationTest(t *testing.T, serializerTest func(t *testing.T, m t.Helper() rng := pkgtest.Prng(t) - testMsg, err := wire.NewAuthResponseMsg(NewRandomAccountMap(rng)) + testMsg, err := wire.NewAuthResponseMsg(NewRandomAccountMap(rng, 0)) if err != nil { t.Fatal(err) } diff --git a/wire/test/randomizer.go b/wire/test/randomizer.go index 58bdb7c32..04478b50c 100644 --- a/wire/test/randomizer.go +++ b/wire/test/randomizer.go @@ -54,8 +54,8 @@ func NewRandomAccount(rng *rand.Rand) wire.Account { } // NewRandomAccountMap returns a new random account. -func NewRandomAccountMap(rng *rand.Rand) map[wallet.BackendID]wire.Account { - return map[wallet.BackendID]wire.Account{0: newRandomAccount(rng)} +func NewRandomAccountMap(rng *rand.Rand, bID wallet.BackendID) map[wallet.BackendID]wire.Account { + return map[wallet.BackendID]wire.Account{bID: newRandomAccount(rng)} } // NewRandomAddresses returns a slice of random peer addresses. From 10c9b28f4e59114020f1c5b1f04ce29d38c822e1 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Wed, 25 Sep 2024 11:03:59 +0200 Subject: [PATCH 09/36] fix(subchannel_dispute): Generalize event watcher. Signed-off-by: Sophia Koehler --- client/test/subchannel_dispute.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client/test/subchannel_dispute.go b/client/test/subchannel_dispute.go index 0c86893cc..2a10f2c5c 100644 --- a/client/test/subchannel_dispute.go +++ b/client/test/subchannel_dispute.go @@ -131,8 +131,10 @@ const channelWatcherWait = 100 * time.Millisecond // HandleAdjudicatorEvent is the callback for adjudicator event handling. func (r *DisputeTim) HandleAdjudicatorEvent(e channel.AdjudicatorEvent) { r.log.Infof("HandleAdjudicatorEvent: channelID = %x, version = %v, type = %T", e.ID(), e.Version(), e) - if e, ok := e.(*channel.RegisteredEvent); ok && e.ID() == r.subCh[0] { - r.registered <- e + for _, id := range r.subCh { + if e, ok := e.(*channel.RegisteredEvent); ok && e.ID() == id { + r.registered <- e + } } } From 3c1e2619e407c7dc47c49254f5202b9ebbac7625 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Tue, 1 Oct 2024 14:49:18 +0200 Subject: [PATCH 10/36] feat: Asset Address function to handle encoding in backends. Signed-off-by: Sophia Koehler --- backend/sim/channel/asset.go | 5 +++++ channel/allocation.go | 2 ++ client/test/multiledger.go | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/backend/sim/channel/asset.go b/backend/sim/channel/asset.go index 52913e322..0a2ec587e 100644 --- a/backend/sim/channel/asset.go +++ b/backend/sim/channel/asset.go @@ -65,3 +65,8 @@ func (a Asset) Equal(b channel.Asset) bool { } return a.ID == simAsset.ID } + +// Address returns the address of the asset. +func (a Asset) Address() string { + return fmt.Sprintf("Asset(%d)", a.ID) +} diff --git a/channel/allocation.go b/channel/allocation.go index 92d9ceb87..7fe151c51 100644 --- a/channel/allocation.go +++ b/channel/allocation.go @@ -101,6 +101,8 @@ type ( encoding.BinaryUnmarshaler // Equal returns true iff this asset is equal to the given asset. Equal(Asset) bool + // Address returns the address in string representation. + Address() string } ) diff --git a/client/test/multiledger.go b/client/test/multiledger.go index 66669c23c..5f2cd896e 100644 --- a/client/test/multiledger.go +++ b/client/test/multiledger.go @@ -118,6 +118,11 @@ func (a *MultiLedgerAsset) Equal(b channel.Asset) bool { return a.id.LedgerId.MapKey() == bm.id.LedgerId.MapKey() && a.asset.Equal(bm.asset) && a.id.BackendID == bm.id.BackendID } +// Address returns the asset's address. +func (a *MultiLedgerAsset) Address() string { + return a.asset.Address() +} + // LedgerID returns the asset's ledger ID. func (a *MultiLedgerAsset) LedgerID() multi.AssetID { return a.id From a695d14ac4c99040c55b24ed22201d9fc8ca55bc Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Tue, 15 Oct 2024 09:53:55 +0200 Subject: [PATCH 11/36] feat(apps/payment, backend/sim, channel/test, client/test, log, wallet, ): Specify backend for randomizers feat(channel/multi): Change AssetID to interface feat(channel/persistence, client/test): Generalize test for backends Signed-off-by: Sophia Koehler --- apps/payment/app_internal_test.go | 2 +- apps/payment/randomizer.go | 5 +- apps/payment/randomizer_internal_test.go | 2 +- apps/payment/resolver_internal_test.go | 2 +- backend/sim/channel/channel_internal_test.go | 4 +- backend/sim/channel/init.go | 5 +- backend/sim/wallet/init.go | 2 +- channel/multi/adjudicator.go | 6 +-- channel/multi/asset.go | 8 +-- channel/multi/funder.go | 10 ++-- channel/persistence/statemachine_test.go | 4 +- channel/persistence/test/channel.go | 8 ++- channel/test/app_randomizer.go | 23 ++++++--- channel/test/mock_app_randomizer.go | 5 +- channel/test/randomizer.go | 49 +++++++++++++----- client/appchannel_test.go | 4 +- client/client_role_test.go | 4 +- client/client_test.go | 8 +-- client/failing_funding_test.go | 2 +- client/payment_test.go | 2 +- client/proposal_internal_test.go | 6 ++- client/proposalmsgs.go | 1 + client/restore_internal_test.go | 25 +++++---- client/subchannel_test.go | 4 +- client/test/backend.go | 15 +++++- client/test/multiledger.go | 17 ++++--- client/test/multiledger_dispute.go | 4 +- client/test/multiledger_happy.go | 2 +- client/test/proposalmsgs.go | 4 +- client/test/randomproposal.go | 4 +- client/test/updatemsgs.go | 10 ++-- client/virtual_channel_test.go | 2 +- log/logrus/logrus_internal_test.go | 2 +- wallet/address_test.go | 16 +++--- wallet/test/randomizer.go | 53 +++++++++++--------- wire/net/simple/address.go | 10 ++++ 36 files changed, 204 insertions(+), 126 deletions(-) diff --git a/apps/payment/app_internal_test.go b/apps/payment/app_internal_test.go index 7834afc65..01eb8f477 100644 --- a/apps/payment/app_internal_test.go +++ b/apps/payment/app_internal_test.go @@ -27,7 +27,7 @@ import ( func TestApp_Def(t *testing.T) { rng := pkgtest.Prng(t) - def := test.NewRandomAppID(rng) + def := test.NewRandomAppID(rng, 0) app := &App{def} assert.True(t, app.Def().Equal(app.Def())) } diff --git a/apps/payment/randomizer.go b/apps/payment/randomizer.go index 52c0fb649..83245ac02 100644 --- a/apps/payment/randomizer.go +++ b/apps/payment/randomizer.go @@ -16,6 +16,7 @@ package payment import ( "math/rand" + "perun.network/go-perun/wallet" "perun.network/go-perun/channel" "perun.network/go-perun/channel/test" @@ -27,8 +28,8 @@ type Randomizer struct{} var _ test.AppRandomizer = (*Randomizer)(nil) // NewRandomApp always returns a payment app with a different address. -func (*Randomizer) NewRandomApp(rng *rand.Rand) channel.App { - return &App{test.NewRandomAppID(rng)} +func (*Randomizer) NewRandomApp(rng *rand.Rand, bID wallet.BackendID) channel.App { + return &App{test.NewRandomAppID(rng, bID)} } // NewRandomData returns NoData because a PaymentApp does not have data. diff --git a/apps/payment/randomizer_internal_test.go b/apps/payment/randomizer_internal_test.go index 9a9dea688..d6177fd1e 100644 --- a/apps/payment/randomizer_internal_test.go +++ b/apps/payment/randomizer_internal_test.go @@ -28,7 +28,7 @@ func TestRandomizer(t *testing.T) { rng := pkgtest.Prng(t) r := new(Randomizer) - app := r.NewRandomApp(rng) + app := r.NewRandomApp(rng, 0) channel.RegisterApp(app) regApp, err := channel.Resolve(app.Def()) assert.NoError(t, err) diff --git a/apps/payment/resolver_internal_test.go b/apps/payment/resolver_internal_test.go index 6c7de90b3..5a63afc79 100644 --- a/apps/payment/resolver_internal_test.go +++ b/apps/payment/resolver_internal_test.go @@ -32,7 +32,7 @@ func TestResolver(t *testing.T) { rng := pkgtest.Prng(t) assert, require := assert.New(t), require.New(t) - def := ctest.NewRandomAppID(rng) + def := ctest.NewRandomAppID(rng, 0) channel.RegisterAppResolver(def.Equal, &Resolver{}) app, err := channel.Resolve(def) diff --git a/backend/sim/channel/channel_internal_test.go b/backend/sim/channel/channel_internal_test.go index 261500ed4..97c81064a 100644 --- a/backend/sim/channel/channel_internal_test.go +++ b/backend/sim/channel/channel_internal_test.go @@ -40,7 +40,7 @@ func newChannelSetup(t *testing.T) *chtest.Setup { Params2: params2, State: state, State2: state2, - Account: wtest.NewRandomAccount(rng), - RandomAddress: func() map[wallet.BackendID]wallet.Address { return wtest.NewRandomAddresses(rng) }, + Account: wtest.NewRandomAccount(rng, 0), + RandomAddress: func() map[wallet.BackendID]wallet.Address { return wtest.NewRandomAddresses(rng, 0) }, } } diff --git a/backend/sim/channel/init.go b/backend/sim/channel/init.go index 6e2d76004..7d38b32b5 100644 --- a/backend/sim/channel/init.go +++ b/backend/sim/channel/init.go @@ -16,15 +16,14 @@ package channel import ( "math/rand" - "perun.network/go-perun/channel" "perun.network/go-perun/channel/test" ) func init() { channel.SetBackend(new(backend), 0) - test.SetRandomizer(new(randomizer)) + test.SetRandomizer(new(randomizer), 0) test.SetNewRandomAppID(func(r *rand.Rand) channel.AppID { return NewRandomAppID(r) - }) + }, 0) } diff --git a/backend/sim/wallet/init.go b/backend/sim/wallet/init.go index 587b22e08..6fbe08b51 100644 --- a/backend/sim/wallet/init.go +++ b/backend/sim/wallet/init.go @@ -21,5 +21,5 @@ import ( func init() { wallet.SetBackend(new(Backend), 0) - test.SetRandomizer(newRandomizer()) + test.SetRandomizer(newRandomizer(), 0) } diff --git a/channel/multi/adjudicator.go b/channel/multi/adjudicator.go index e2f8c4c38..87d60052a 100644 --- a/channel/multi/adjudicator.go +++ b/channel/multi/adjudicator.go @@ -34,13 +34,13 @@ func NewAdjudicator() *Adjudicator { // RegisterAdjudicator registers an adjudicator for a given ledger. func (a *Adjudicator) RegisterAdjudicator(l AssetID, la channel.Adjudicator) { - key := AssetIDKey{BackendID: l.BackendID, LedgerID: string(l.LedgerId.MapKey())} + key := AssetIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerId().MapKey())} a.adjudicators[key] = la } // LedgerAdjudicator returns the adjudicator for a given ledger. func (a *Adjudicator) LedgerAdjudicator(l AssetID) (channel.Adjudicator, bool) { - key := AssetIDKey{BackendID: l.BackendID, LedgerID: string(l.LedgerId.MapKey())} + key := AssetIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerId().MapKey())} adj, ok := a.adjudicators[key] return adj, ok } @@ -97,7 +97,7 @@ func (a *Adjudicator) dispatch(assetIds []AssetID, f func(channel.Adjudicator) e for _, l := range assetIds { go func(l AssetID) { err := func() error { - key := AssetIDKey{BackendID: l.BackendID, LedgerID: string(l.LedgerId.MapKey())} + key := AssetIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerId().MapKey())} adjs, ok := a.adjudicators[key] if !ok { return fmt.Errorf("adjudicator not found for id %v", l) diff --git a/channel/multi/asset.go b/channel/multi/asset.go index 048e7e55d..d4cdd5e5e 100644 --- a/channel/multi/asset.go +++ b/channel/multi/asset.go @@ -27,9 +27,9 @@ type ( AssetID() AssetID } - AssetID struct { - BackendID uint32 - LedgerId LedgerID + AssetID interface { + BackendID() uint32 + LedgerId() LedgerID } // LedgerIDMapKey is the map key representation of a ledger identifier. @@ -73,7 +73,7 @@ func IsMultiLedgerAssets(assets []channel.Asset) bool { case !hasMulti: hasMulti = true id = multiAsset.AssetID() - case id.LedgerId.MapKey() != multiAsset.AssetID().LedgerId.MapKey(): + case id.LedgerId().MapKey() != multiAsset.AssetID().LedgerId().MapKey(): return true } } diff --git a/channel/multi/funder.go b/channel/multi/funder.go index 61f0b1d78..f7f86e361 100644 --- a/channel/multi/funder.go +++ b/channel/multi/funder.go @@ -46,14 +46,14 @@ func NewFunder() *Funder { // RegisterFunder registers a funder for a given ledger. func (f *Funder) RegisterFunder(l AssetID, lf channel.Funder) { - key := AssetIDKey{BackendID: l.BackendID, LedgerID: string(l.LedgerId.MapKey())} + key := AssetIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerId().MapKey())} f.funders[key] = lf f.egoisticChains[key] = false } // SetEgoisticChain sets the egoistic chain flag for a given ledger. func (f *Funder) SetEgoisticChain(l AssetID, id int, egoistic bool) { - key := AssetIDKey{BackendID: l.BackendID, LedgerID: string(l.LedgerId.MapKey())} + key := AssetIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerId().MapKey())} f.egoisticChains[key] = egoistic } @@ -75,7 +75,7 @@ func (f *Funder) Fund(ctx context.Context, request channel.FundingReq) error { var nonEgoisticLedgers []AssetID for _, l := range assetIDs { - key := AssetIDKey{BackendID: l.BackendID, LedgerID: string(l.LedgerId.MapKey())} + key := AssetIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerId().MapKey())} if f.egoisticChains[key] { egoisticLedgers = append(egoisticLedgers, l) } else { @@ -107,11 +107,11 @@ func fundLedgers(ctx context.Context, request channel.FundingReq, assetIDs []Ass // Iterate over blockchains to get the LedgerIDs for _, assetID := range assetIDs { go func(assetID AssetID) { - key := AssetIDKey{BackendID: assetID.BackendID, LedgerID: string(assetID.LedgerId.MapKey())} + key := AssetIDKey{BackendID: assetID.BackendID(), LedgerID: string(assetID.LedgerId().MapKey())} // Get the Funder from the funders map funder, ok := funders[key] if !ok { - errs <- fmt.Errorf("funder map not found for blockchain %d and ledger %d", assetID.BackendID, assetID.LedgerId) + errs <- fmt.Errorf("funder map not found for blockchain %d and ledger %d", assetID.BackendID(), assetID.LedgerId()) return } diff --git a/channel/persistence/statemachine_test.go b/channel/persistence/statemachine_test.go index 29150359a..b9452e19a 100644 --- a/channel/persistence/statemachine_test.go +++ b/channel/persistence/statemachine_test.go @@ -39,8 +39,8 @@ func TestStateMachine(t *testing.T) { require := require.New(t) rng := pkgtest.Prng(t) - const n = 5 // number of participants - accs, parts := wtest.NewRandomAccounts(rng, n) // local participant idx 0 + const n = 5 // number of participants + accs, parts := wtest.NewRandomAccounts(rng, n, 0) // local participant idx 0 params := ctest.NewRandomParams(rng, ctest.WithParts(parts)) t.Log("Participants:", parts, "accs:", accs) t.Log("Params:", params) diff --git a/channel/persistence/test/channel.go b/channel/persistence/test/channel.go index dbbc83fb0..ffc98b463 100644 --- a/channel/persistence/test/channel.go +++ b/channel/persistence/test/channel.go @@ -56,7 +56,13 @@ func NewRandomChannel( parent *Channel, rng *rand.Rand, ) (c *Channel) { - accs, parts := wtest.NewRandomAccounts(rng, len(peers)) + bID := wallet.BackendID(0) + if len(peers) > 0 { + for i := range peers[0] { + bID = i + } + } + accs, parts := wtest.NewRandomAccounts(rng, len(peers), bID) params := ctest.NewRandomParams(rng, ctest.WithParts(parts)) csm, err := channel.NewStateMachine(accs[0], *params) require.NoError(t, err) diff --git a/channel/test/app_randomizer.go b/channel/test/app_randomizer.go index ae7442b20..99b651848 100644 --- a/channel/test/app_randomizer.go +++ b/channel/test/app_randomizer.go @@ -16,6 +16,7 @@ package test import ( "math/rand" + "perun.network/go-perun/wallet" "perun.network/go-perun/channel" ) @@ -23,7 +24,7 @@ import ( // The AppRandomizer interface provides functionality for creating random // data and apps which is useful for testing. type AppRandomizer interface { - NewRandomApp(*rand.Rand) channel.App + NewRandomApp(*rand.Rand, wallet.BackendID) channel.App NewRandomData(*rand.Rand) channel.Data } @@ -53,8 +54,13 @@ func NewRandomApp(rng *rand.Rand, opts ...RandomOpt) channel.App { app, _ := channel.Resolve(def) return app } + var bID wallet.BackendID + bID, err := opt.Backend() + if err != nil { + bID = wallet.BackendID(0) + } // WithAppDef does not set the app in the options - app := opt.AppRandomizer().NewRandomApp(rng) + app := opt.AppRandomizer().NewRandomApp(rng, bID) channel.RegisterApp(app) updateOpts(opts, WithApp(app)) return app @@ -82,14 +88,17 @@ func NewRandomAppAndData(rng *rand.Rand, opts ...RandomOpt) (channel.App, channe // NewRandomAppIDFunc is an app identifier randomizer function. type NewRandomAppIDFunc = func(*rand.Rand) channel.AppID -var newRandomAppID NewRandomAppIDFunc +var newRandomAppID map[wallet.BackendID]NewRandomAppIDFunc // SetNewRandomAppID sets the function generating a new app identifier. -func SetNewRandomAppID(f NewRandomAppIDFunc) { - newRandomAppID = f +func SetNewRandomAppID(f NewRandomAppIDFunc, bID wallet.BackendID) { + if newRandomAppID == nil { + newRandomAppID = make(map[wallet.BackendID]NewRandomAppIDFunc) + } + newRandomAppID[bID] = f } // NewRandomAppID creates a new random channel.AppID. -func NewRandomAppID(rng *rand.Rand) channel.AppID { - return newRandomAppID(rng) +func NewRandomAppID(rng *rand.Rand, bID wallet.BackendID) channel.AppID { + return newRandomAppID[bID](rng) } diff --git a/channel/test/mock_app_randomizer.go b/channel/test/mock_app_randomizer.go index 0e20c2493..0e3b36c67 100644 --- a/channel/test/mock_app_randomizer.go +++ b/channel/test/mock_app_randomizer.go @@ -16,6 +16,7 @@ package test import ( "math/rand" + "perun.network/go-perun/wallet" "github.com/google/uuid" "perun.network/go-perun/channel" @@ -32,8 +33,8 @@ func NewMockAppRandomizer() *MockAppRandomizer { } // NewRandomApp creates a new MockApp with a random address. -func (MockAppRandomizer) NewRandomApp(rng *rand.Rand) channel.App { - return channel.NewMockApp(NewRandomAppID(rng)) +func (MockAppRandomizer) NewRandomApp(rng *rand.Rand, bID wallet.BackendID) channel.App { + return channel.NewMockApp(NewRandomAppID(rng, bID)) } // NewRandomData creates a new MockOp with a random operation. diff --git a/channel/test/randomizer.go b/channel/test/randomizer.go index a1850a877..e766abf6a 100644 --- a/channel/test/randomizer.go +++ b/channel/test/randomizer.go @@ -32,14 +32,17 @@ type Randomizer interface { NewRandomAsset(*rand.Rand) channel.Asset } -var randomizer Randomizer +var randomizer map[wallet.BackendID]Randomizer // SetRandomizer sets the global Randomizer variable. -func SetRandomizer(r Randomizer) { - if randomizer != nil { +func SetRandomizer(r Randomizer, bID wallet.BackendID) { + if randomizer == nil { + randomizer = make(map[wallet.BackendID]Randomizer) + } + if randomizer[bID] != nil { panic("channel/test randomizer already set") } - randomizer = r + randomizer[bID] = r } // NewRandomPhase generates a random channel machine phase. @@ -48,8 +51,8 @@ func NewRandomPhase(rng *rand.Rand) channel.Phase { } // NewRandomAsset generates a new random `channel.Asset`. -func NewRandomAsset(rng *rand.Rand) channel.Asset { - return randomizer.NewRandomAsset(rng) +func NewRandomAsset(rng *rand.Rand, bID wallet.BackendID) channel.Asset { + return randomizer[bID].NewRandomAsset(rng) } // NewRandomAssets generates new random `channel.Asset`s. @@ -60,9 +63,25 @@ func NewRandomAssets(rng *rand.Rand, opts ...RandomOpt) []channel.Asset { return assets } numAssets := opt.NumAssets(rng) + if backend, err := opt.Backend(); err == nil { + assets := make([]channel.Asset, opt.NumAssets(rng)) + for i := range assets { + assets[i] = NewRandomAsset(rng, backend) + } + updateOpts(opts, WithAssets(assets...)) + return assets + } + if backends, err := opt.BackendID(); err == nil { + assets := make([]channel.Asset, numAssets) + for i := range assets { + assets[i] = NewRandomAsset(rng, backends[i]) + } + updateOpts(opts, WithAssets(assets...)) + return assets + } as := make([]channel.Asset, numAssets) for i := range as { - as[i] = NewRandomAsset(rng) + as[i] = NewRandomAsset(rng, 0) } updateOpts(opts, WithAssets(as...)) @@ -140,7 +159,7 @@ func NewRandomLockedIDs(rng *rand.Rand, opts ...RandomOpt) []map[wallet.BackendI ids[i] = make(map[wallet.BackendID]channel.ID) cId := [32]byte{} rng.Read(cId[:]) - ids[i][wallet.BackendID(b)] = cId + ids[i][b] = cId } } return ids @@ -187,9 +206,9 @@ func NewRandomParams(rng *rand.Rand, opts ...RandomOpt) *channel.Params { for i := range parts { var backend wallet.BackendID if backend, _ = opt.Backend(); backend != 0 { - parts[i] = map[wallet.BackendID]wallet.Address{backend: test.NewRandomAddress(rng)} + parts[i] = map[wallet.BackendID]wallet.Address{backend: test.NewRandomAddress(rng, backend)} } else { - parts[i] = map[wallet.BackendID]wallet.Address{0: test.NewRandomAddress(rng)} + parts[i] = map[wallet.BackendID]wallet.Address{0: test.NewRandomAddress(rng, 0)} } } } @@ -380,18 +399,22 @@ func NewRandomBackends(rng *rand.Rand, num int, opts ...RandomOpt) []wallet.Back // Options: all from `NewRandomParamsAndState`. func NewRandomTransaction(rng *rand.Rand, sigMask []bool, opts ...RandomOpt) *channel.Transaction { opt := mergeRandomOpts(opts...) + bID, err := opt.Backend() + if err != nil { + bID = 0 + } numParts := len(sigMask) - accs, addrs := test.NewRandomAccounts(rng, numParts) + accs, addrs := test.NewRandomAccounts(rng, numParts, bID) params := NewRandomParams(rng, WithParts(addrs), opt) state := NewRandomState(rng, WithID(params.ID()), WithNumParts(numParts), opt) sigs := make([]wallet.Sig, numParts) - var err error + err = nil for i, choice := range sigMask { if !choice { sigs[i] = nil } else { - sigs[i], err = channel.Sign(accs[i][0], state) + sigs[i], err = channel.Sign(accs[i][bID], state) } if err != nil { panic(err) diff --git a/client/appchannel_test.go b/client/appchannel_test.go index 3e0136f2b..427b8cad6 100644 --- a/client/appchannel_test.go +++ b/client/appchannel_test.go @@ -37,14 +37,14 @@ func TestProgression(t *testing.T) { clienttest.NewPaula(t, setups[1]), } - appAddress := chtest.NewRandomAppID(rng) + appAddress := chtest.NewRandomAppID(rng, 0) app := channel.NewMockApp(appAddress) channel.RegisterApp(app) execConfig := &clienttest.ProgressionExecConfig{ BaseExecConfig: clienttest.MakeBaseExecConfig( [2]map[wallet.BackendID]wire.Address{wire.AddressMapfromAccountMap(setups[0].Identity), wire.AddressMapfromAccountMap(setups[1].Identity)}, - chtest.NewRandomAsset(rng), + chtest.NewRandomAsset(rng, 0), 0, [2]*big.Int{big.NewInt(99), big.NewInt(1)}, client.WithApp(app, channel.NewMockOp(channel.OpValid)), diff --git a/client/client_role_test.go b/client/client_role_test.go index b5f115e42..aca1a16c9 100644 --- a/client/client_role_test.go +++ b/client/client_role_test.go @@ -51,7 +51,7 @@ func NewSetups(rng *rand.Rand, names []string, bID wallet.BackendID) []ctest.Rol if err != nil { panic("Error initializing watcher: " + err.Error()) } - w := map[wallet.BackendID]wtest.Wallet{bID: wtest.NewWallet()} + w := map[wallet.BackendID]wtest.Wallet{bID: wtest.NewWallet(bID)} acc := w[0].NewRandomAccount(rng) setup[i] = ctest.RoleSetup{ Name: names[i], @@ -86,7 +86,7 @@ func runAliceBobTest(ctx context.Context, t *testing.T, setup func(*rand.Rand) ( cfg := &ctest.AliceBobExecConfig{ BaseExecConfig: ctest.MakeBaseExecConfig( [2]map[wallet.BackendID]wire.Address{wire.AddressMapfromAccountMap(setups[0].Identity), wire.AddressMapfromAccountMap(setups[1].Identity)}, - chtest.NewRandomAsset(rng), + chtest.NewRandomAsset(rng, 0), 0, [2]*big.Int{big.NewInt(100), big.NewInt(100)}, app, diff --git a/client/client_test.go b/client/client_test.go index 4f94a8439..41a491838 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -52,7 +52,7 @@ func TestClient_New_NilArgs(t *testing.T) { rng := test.Prng(t) id := wiretest.NewRandomAddressesMap(rng, 1)[0] backend := &ctest.MockBackend{} - b, f, a, w := &DummyBus{t}, &ctest.MockFunder{}, &ctest.MockAdjudicator{}, map[wallet.BackendID]wallet.Wallet{0: wtest.RandomWallet()} + b, f, a, w := &DummyBus{t}, &ctest.MockFunder{}, &ctest.MockAdjudicator{}, map[wallet.BackendID]wallet.Wallet{0: wtest.RandomWallet(0)} watcher, err := local.NewWatcher(backend) require.NoError(t, err, "initializing the watcher should not error") assert.Panics(t, func() { client.New(nil, b, f, a, w, watcher) }) //nolint:errcheck @@ -69,7 +69,7 @@ func TestClient_Handle_NilArgs(t *testing.T) { watcher, err := local.NewWatcher(backend) require.NoError(t, err, "initializing the watcher should not error") c, err := client.New(wiretest.NewRandomAddress(rng), - &DummyBus{t}, &ctest.MockFunder{}, &ctest.MockAdjudicator{}, map[wallet.BackendID]wallet.Wallet{0: wtest.RandomWallet()}, watcher) + &DummyBus{t}, &ctest.MockFunder{}, &ctest.MockAdjudicator{}, map[wallet.BackendID]wallet.Wallet{0: wtest.RandomWallet(0)}, watcher) require.NoError(t, err) dummyUH := client.UpdateHandlerFunc(func(*channel.State, client.ChannelUpdate, *client.UpdateResponder) {}) @@ -84,7 +84,7 @@ func TestClient_New(t *testing.T) { watcher, err := local.NewWatcher(backend) require.NoError(t, err, "initializing the watcher should not error") c, err := client.New(wiretest.NewRandomAddressesMap(rng, 1)[0], - &DummyBus{t}, &ctest.MockFunder{}, &ctest.MockAdjudicator{}, map[wallet.BackendID]wallet.Wallet{0: wtest.RandomWallet()}, watcher) + &DummyBus{t}, &ctest.MockFunder{}, &ctest.MockAdjudicator{}, map[wallet.BackendID]wallet.Wallet{0: wtest.RandomWallet(0)}, watcher) assert.NoError(t, err) require.NotNil(t, c) } @@ -95,7 +95,7 @@ func TestChannelRejection(t *testing.T) { defer cancel() roles := NewSetups(rng, []string{"Alice", "Bob"}, 0) - asset := chtest.NewRandomAsset(rng) + asset := chtest.NewRandomAsset(rng, 0) clients := ctest.NewClients(t, rng, roles) require := require.New(t) alice, bob := clients[0], clients[1] diff --git a/client/failing_funding_test.go b/client/failing_funding_test.go index 59a91464a..8a62d413d 100644 --- a/client/failing_funding_test.go +++ b/client/failing_funding_test.go @@ -43,7 +43,7 @@ func TestFailingFunding(t *testing.T) { }, func(r *rand.Rand) ([2]ctest.RoleSetup, channel.Asset) { roles := NewSetups(rng, []string{"Frida", "Fred"}, 0) - asset := chtest.NewRandomAsset(rng) + asset := chtest.NewRandomAsset(rng, 0) return [2]ctest.RoleSetup{roles[0], roles[1]}, asset }, ) diff --git a/client/payment_test.go b/client/payment_test.go index 91e165508..56437fdc3 100644 --- a/client/payment_test.go +++ b/client/payment_test.go @@ -57,7 +57,7 @@ func TestPaymentDispute(t *testing.T) { cfg := &ctest.MalloryCarolExecConfig{ BaseExecConfig: ctest.MakeBaseExecConfig( [2]map[wallet.BackendID]wire.Address{wire.AddressMapfromAccountMap(setups[mallory].Identity), wire.AddressMapfromAccountMap(setups[carol].Identity)}, - chtest.NewRandomAsset(rng), + chtest.NewRandomAsset(rng, 0), 0, [2]*big.Int{big.NewInt(100), big.NewInt(1)}, client.WithoutApp(), diff --git a/client/proposal_internal_test.go b/client/proposal_internal_test.go index 1eb9a4568..59c503688 100644 --- a/client/proposal_internal_test.go +++ b/client/proposal_internal_test.go @@ -153,9 +153,13 @@ func NewRandomLedgerChannelProposal(rng *rand.Rand, opts ...channeltest.RandomOp opt := make(channeltest.RandomOpt).Append(opts...) base := NewRandomBaseChannelProposal(rng, opt) peers := wiretest.NewRandomAddressesMap(rng, base.NumPeers()) + var bID wallet.BackendID + for i := range peers[0] { + bID = i + } return &LedgerChannelProposalMsg{ BaseChannelProposal: base, - Participant: wallettest.NewRandomAddresses(rng), + Participant: wallettest.NewRandomAddresses(rng, bID), Peers: peers, } } diff --git a/client/proposalmsgs.go b/client/proposalmsgs.go index e7dbab419..885a183b6 100644 --- a/client/proposalmsgs.go +++ b/client/proposalmsgs.go @@ -233,6 +233,7 @@ func (p LedgerChannelProposalMsg) Accept( participant map[wallet.BackendID]wallet.Address, nonceShare ProposalOpts, ) *LedgerChannelProposalAccMsg { + log.Println("LedgerChannelProposalMsg.Accept") if !nonceShare.isNonce() { log.WithField("proposal", p.ProposalID). Panic("LedgerChannelProposal.Accept: nonceShare has no configured nonce") diff --git a/client/restore_internal_test.go b/client/restore_internal_test.go index f3f097534..1b155c6fe 100644 --- a/client/restore_internal_test.go +++ b/client/restore_internal_test.go @@ -38,7 +38,13 @@ func patchChFromSource( parent *Channel, peers ...map[wallet.BackendID]wire.Address, ) (*Channel, error) { - acc, _ := wallettest.RandomWallet().Unlock(ch.ParamsV.Parts[ch.IdxV][0]) + bID := wallet.BackendID(0) + if len(peers) > 0 { + for i := range peers[0] { + bID = i + } + } + acc, _ := wallettest.RandomWallet(bID).Unlock(ch.ParamsV.Parts[ch.IdxV][0]) machine, _ := channel.NewStateMachine(map[wallet.BackendID]wallet.Account{0: acc}, *ch.ParamsV) pmachine := persistence.FromStateMachine(machine, nil) @@ -52,10 +58,10 @@ func TestReconstructChannel(t *testing.T) { rng := pkgtest.Prng(t) db := map[string]*persistence.Channel{} - restParent := mkRndChan(rng) + restParent := mkRndChan(rng, 0) db[channel.IDKey(restParent.ID())] = restParent - restChild := mkRndChan(rng) + restChild := mkRndChan(rng, 0) parentID := restParent.ID() restChild.Parent = &parentID db[channel.IDKey(restChild.ID())] = restChild @@ -82,7 +88,7 @@ func TestRestoreChannelCollection(t *testing.T) { // Generate multiple trees of channels into one collection. db := make(map[string]*persistence.Channel) for i := 0; i < 3; i++ { - mkRndChanTree(rng, 3, 1, 3, db) + mkRndChanTree(rng, 3, 1, 3, db, 0) } // Remember channels that have been published. @@ -108,10 +114,10 @@ func TestRestoreChannelCollection(t *testing.T) { } // mkRndChan creates a single random channel. -func mkRndChan(rng *rand.Rand) *persistence.Channel { +func mkRndChan(rng *rand.Rand, bID wallet.BackendID) *persistence.Channel { parts := make([]map[wallet.BackendID]wallet.Address, channel.MaxNumParts) for i := range parts { - parts[i] = map[wallet.BackendID]wallet.Address{0: wallettest.NewRandomAccount(rng).Address()} + parts[i] = map[wallet.BackendID]wallet.Address{bID: wallettest.NewRandomAccount(rng, bID).Address()} } ch := persistence.NewChannel() ch.IdxV = channel.Index(rng.Intn(channel.MaxNumParts)) @@ -131,8 +137,9 @@ func mkRndChanTree( rng *rand.Rand, depth, minChildren, maxChildren int, db map[string]*persistence.Channel, + bID wallet.BackendID, ) (root *persistence.Channel) { - root = mkRndChan(rng) + root = mkRndChan(rng, bID) db[channel.IDKey(root.ID())] = root if depth > 0 && maxChildren > 0 { @@ -141,8 +148,8 @@ func mkRndChanTree( minChildren-- } for i := 0; i < children; i++ { - t := mkRndChanTree(rng, depth-1, minChildren, maxChildren-1, db) - t.Parent = &map[wallet.BackendID]channel.ID{0: *new(channel.ID)} + t := mkRndChanTree(rng, depth-1, minChildren, maxChildren-1, db, bID) + t.Parent = &map[wallet.BackendID]channel.ID{bID: *new(channel.ID)} *t.Parent = root.ID() } } diff --git a/client/subchannel_test.go b/client/subchannel_test.go index 8266ea01c..063ba9404 100644 --- a/client/subchannel_test.go +++ b/client/subchannel_test.go @@ -40,7 +40,7 @@ func TestSubChannelHappy(t *testing.T) { cfg := ctest.NewSusieTimExecConfig( ctest.MakeBaseExecConfig( [2]map[wallet.BackendID]wire.Address{wire.AddressMapfromAccountMap(setups[0].Identity), wire.AddressMapfromAccountMap(setups[1].Identity)}, - chtest.NewRandomAsset(rng), + chtest.NewRandomAsset(rng, 0), 0, [2]*big.Int{big.NewInt(100), big.NewInt(100)}, client.WithoutApp(), @@ -78,7 +78,7 @@ func TestSubChannelDispute(t *testing.T) { baseCfg := ctest.MakeBaseExecConfig( [2]map[wallet.BackendID]wire.Address{wire.AddressMapfromAccountMap(setups[0].Identity), wire.AddressMapfromAccountMap(setups[1].Identity)}, - chtest.NewRandomAsset(rng), + chtest.NewRandomAsset(rng, 0), 0, [2]*big.Int{big.NewInt(100), big.NewInt(100)}, client.WithoutApp(), diff --git a/client/test/backend.go b/client/test/backend.go index c43626d7c..4bbd62029 100644 --- a/client/test/backend.go +++ b/client/test/backend.go @@ -42,6 +42,11 @@ type ( id multi.AssetID } + AssetID struct { + backendID uint32 + ledgerID LedgerID + } + rng interface { Intn(n int) int } @@ -55,6 +60,14 @@ type ( LedgerID string ) +func (id AssetID) LedgerId() multi.LedgerID { + return id.ledgerID +} + +func (id AssetID) BackendID() uint32 { + return id.backendID +} + // maximal amount of milliseconds that the Fund method waits before returning. const fundMaxSleepMs = 100 @@ -70,7 +83,7 @@ func NewMockBackend(rng *rand.Rand, id string) *MockBackend { latestEvents: make(map[string]channel.AdjudicatorEvent), eventSubs: make(map[string][]*MockSubscription), balances: make(map[string]map[string]*big.Int), - id: multi.AssetID{0, LedgerID(id)}, + id: AssetID{0, LedgerID(id)}, } } diff --git a/client/test/multiledger.go b/client/test/multiledger.go index 5f2cd896e..841b56341 100644 --- a/client/test/multiledger.go +++ b/client/test/multiledger.go @@ -59,12 +59,12 @@ func SetupMultiLedgerTest(t *testing.T) MultiLedgerSetup { bus := wire.NewLocalBus() // Setup clients. - c1 := setupClient(t, rng, l1, l2, bus) - c2 := setupClient(t, rng, l1, l2, bus) + c1 := setupClient(t, rng, l1, l2, bus, 0) + c2 := setupClient(t, rng, l1, l2, bus, 0) // Define assets. - a1 := NewMultiLedgerAsset(l1.ID(), chtest.NewRandomAsset(rng)) - a2 := NewMultiLedgerAsset(l2.ID(), chtest.NewRandomAsset(rng)) + a1 := NewMultiLedgerAsset(l1.ID(), chtest.NewRandomAsset(rng, 0)) + a2 := NewMultiLedgerAsset(l2.ID(), chtest.NewRandomAsset(rng, 0)) return MultiLedgerSetup{ Client1: c1, @@ -115,7 +115,7 @@ func (a *MultiLedgerAsset) Equal(b channel.Asset) bool { return false } - return a.id.LedgerId.MapKey() == bm.id.LedgerId.MapKey() && a.asset.Equal(bm.asset) && a.id.BackendID == bm.id.BackendID + return a.id.LedgerId().MapKey() == bm.id.LedgerId().MapKey() && a.asset.Equal(bm.asset) && a.id.BackendID() == bm.id.BackendID() } // Address returns the asset's address. @@ -131,7 +131,7 @@ func (a *MultiLedgerAsset) LedgerID() multi.AssetID { // MarshalBinary encodes the asset to its byte representation. func (a *MultiLedgerAsset) MarshalBinary() ([]byte, error) { var buf bytes.Buffer - err := perunio.Encode(&buf, string(a.id.LedgerId.MapKey()), a.id.BackendID, a.asset) + err := perunio.Encode(&buf, string(a.id.LedgerId().MapKey()), a.id.BackendID(), a.asset) if err != nil { return nil, err } @@ -142,7 +142,7 @@ func (a *MultiLedgerAsset) MarshalBinary() ([]byte, error) { // UnmarshalBinary decodes the asset from its byte representation. func (a *MultiLedgerAsset) UnmarshalBinary(data []byte) error { buf := bytes.NewBuffer(data) - return perunio.Decode(buf, string(a.id.LedgerId.MapKey()), a.id.BackendID, a.asset) + return perunio.Decode(buf, string(a.id.LedgerId().MapKey()), a.id.BackendID(), a.asset) } // MultiLedgerClient represents a test client. @@ -164,6 +164,7 @@ func (c MultiLedgerClient) HandleAdjudicatorEvent(e channel.AdjudicatorEvent) { func setupClient( t *testing.T, rng *rand.Rand, l1, l2 *MockBackend, bus wire.Bus, + bID wallet.BackendID, ) MultiLedgerClient { t.Helper() require := require.New(t) @@ -172,7 +173,7 @@ func setupClient( wireAddr := wiretest.NewRandomAddressesMap(rng, 1) // Setup wallet and account. - w := wtest.NewWallet() + w := wtest.NewWallet(bID) acc := w.NewRandomAccount(rng) // Setup funder. diff --git a/client/test/multiledger_dispute.go b/client/test/multiledger_dispute.go index e74838050..d452c55d3 100644 --- a/client/test/multiledger_dispute.go +++ b/client/test/multiledger_dispute.go @@ -61,8 +61,8 @@ func TestMultiLedgerDispute( // Establish ledger channel between Alice and Bob. - bID1 := wallet.BackendID(mlt.Asset1.AssetID().BackendID) - bID2 := wallet.BackendID(mlt.Asset2.AssetID().BackendID) + bID1 := wallet.BackendID(mlt.Asset1.AssetID().BackendID()) + bID2 := wallet.BackendID(mlt.Asset2.AssetID().BackendID()) // Create channel proposal. parts := []map[wallet.BackendID]wire.Address{alice.WireAddress, bob.WireAddress} initAlloc := channel.NewAllocation(len(parts), []wallet.BackendID{bID1, bID2}, mlt.Asset1, mlt.Asset2) diff --git a/client/test/multiledger_happy.go b/client/test/multiledger_happy.go index 7539ea454..0e795905c 100644 --- a/client/test/multiledger_happy.go +++ b/client/test/multiledger_happy.go @@ -43,7 +43,7 @@ func TestMultiLedgerHappy(ctx context.Context, t *testing.T, mlt MultiLedgerSetu // Create channel proposal. parts := []map[wallet.BackendID]wire.Address{alice.WireAddress, bob.WireAddress} - initAlloc := channel.NewAllocation(len(parts), []wallet.BackendID{wallet.BackendID(mlt.Asset1.AssetID().BackendID), wallet.BackendID(mlt.Asset2.AssetID().BackendID)}, mlt.Asset1, mlt.Asset2) + initAlloc := channel.NewAllocation(len(parts), []wallet.BackendID{wallet.BackendID(mlt.Asset1.AssetID().BackendID()), wallet.BackendID(mlt.Asset2.AssetID().BackendID())}, mlt.Asset1, mlt.Asset2) initAlloc.Balances = initBals prop, err := client.NewLedgerChannelProposal( challengeDuration, diff --git a/client/test/proposalmsgs.go b/client/test/proposalmsgs.go index 40fe150f6..2108d666c 100644 --- a/client/test/proposalmsgs.go +++ b/client/test/proposalmsgs.go @@ -67,7 +67,7 @@ func channelProposalAccSerializationTest(t *testing.T, serializerTest func(t *te t.Run("ledger channel", func(t *testing.T) { for i := 0; i < 16; i++ { proposal := NewRandomLedgerChannelProposal(rng) - m := proposal.Accept(wallettest.NewRandomAddresses(rng), client.WithNonceFrom(rng)) + m := proposal.Accept(wallettest.NewRandomAddresses(rng, 0), client.WithNonceFrom(rng)) serializerTest(t, m) } }) @@ -85,7 +85,7 @@ func channelProposalAccSerializationTest(t *testing.T, serializerTest func(t *te var err error proposal, err := NewRandomVirtualChannelProposal(rng) require.NoError(t, err) - m := proposal.Accept(wallettest.NewRandomAddresses(rng)) + m := proposal.Accept(wallettest.NewRandomAddresses(rng, 0)) serializerTest(t, m) } }) diff --git a/client/test/randomproposal.go b/client/test/randomproposal.go index a7280ac13..1ad408fe8 100644 --- a/client/test/randomproposal.go +++ b/client/test/randomproposal.go @@ -30,7 +30,7 @@ const randomProposalNumParts = 2 // NewRandomLedgerChannelProposal creates a random channel proposal with the supplied // options. Number of participants is fixed to randomProposalNumParts. func NewRandomLedgerChannelProposal(rng *rand.Rand, opts ...client.ProposalOpts) *client.LedgerChannelProposalMsg { - return NewRandomLedgerChannelProposalBy(rng, wallettest.NewRandomAddresses(rng), opts...) + return NewRandomLedgerChannelProposalBy(rng, wallettest.NewRandomAddresses(rng, 0), opts...) } // NewRandomLedgerChannelProposalBy creates a random channel proposal with the @@ -65,7 +65,7 @@ func NewRandomVirtualChannelProposal(rng *rand.Rand, opts ...client.ProposalOpts numParts := 2 return client.NewVirtualChannelProposal( rng.Uint64(), - wallettest.NewRandomAddresses(rng), + wallettest.NewRandomAddresses(rng, 0), channeltest.NewRandomAllocation(rng, channeltest.WithNumParts(numParts)), wiretest.NewRandomAddressesMap(rng, numParts), channeltest.NewRandomChannelIDs(rng, numParts), diff --git a/client/test/updatemsgs.go b/client/test/updatemsgs.go index 676617cba..931b467a5 100644 --- a/client/test/updatemsgs.go +++ b/client/test/updatemsgs.go @@ -94,7 +94,7 @@ func channelUpdateAccSerializationTest(t *testing.T, serializerTest func(t *test t.Helper() rng := pkgtest.Prng(t) for i := 0; i < 4; i++ { - sig := newRandomSig(rng) + sig := newRandomSig(rng, 0) m := &client.ChannelUpdateAccMsg{ ChannelID: test.NewRandomChannelID(rng), Version: uint64(rng.Int63()), @@ -121,7 +121,7 @@ func channelUpdateRejSerializationTest(t *testing.T, serializerTest func(t *test func newRandomMsgChannelUpdate(rng *rand.Rand) *client.ChannelUpdateMsg { state := test.NewRandomState(rng) - sig := newRandomSig(rng) + sig := newRandomSig(rng, 0) return &client.ChannelUpdateMsg{ ChannelUpdate: client.ChannelUpdate{ State: state, @@ -133,8 +133,8 @@ func newRandomMsgChannelUpdate(rng *rand.Rand) *client.ChannelUpdateMsg { // newRandomSig generates a random account and then returns the signature on // some random data. -func newRandomSig(rng *rand.Rand) wallet.Sig { - acc := wallettest.NewRandomAccount(rng) +func newRandomSig(rng *rand.Rand, bID wallet.BackendID) wallet.Sig { + acc := wallettest.NewRandomAccount(rng, bID) maxLenOfData := 256 data := make([]byte, rng.Intn(maxLenOfData)) rng.Read(data) @@ -149,7 +149,7 @@ func newRandomSig(rng *rand.Rand) wallet.Sig { func newRandomSigs(rng *rand.Rand, n int) (a []wallet.Sig) { a = make([]wallet.Sig, n) for i := range a { - a[i] = newRandomSig(rng) + a[i] = newRandomSig(rng, 0) } return } diff --git a/client/virtual_channel_test.go b/client/virtual_channel_test.go index 785e37215..972c384ac 100644 --- a/client/virtual_channel_test.go +++ b/client/virtual_channel_test.go @@ -53,7 +53,7 @@ func makeVirtualChannelSetup(rng *rand.Rand) ctest.VirtualChannelSetup { return ctest.VirtualChannelSetup{ Clients: createVirtualChannelClients(rng), ChallengeDuration: challengeDuration, - Asset: chtest.NewRandomAsset(rng), + Asset: chtest.NewRandomAsset(rng, 0), Balances: ctest.VirtualChannelBalances{ InitBalsAliceIngrid: []*big.Int{big.NewInt(10), big.NewInt(10)}, InitBalsBobIngrid: []*big.Int{big.NewInt(10), big.NewInt(10)}, diff --git a/log/logrus/logrus_internal_test.go b/log/logrus/logrus_internal_test.go index e95884423..a62c45a8e 100644 --- a/log/logrus/logrus_internal_test.go +++ b/log/logrus/logrus_internal_test.go @@ -49,7 +49,7 @@ func testLogrusInfo(t *testing.T) { func testLogrusStringer(t *testing.T) { rng := pkgtest.Prng(t) - addr := wtest.NewRandomAddress(rng) + addr := wtest.NewRandomAddress(rng, 0) var data [32]byte rng.Read(data[:]) logger, hook := test.NewNullLogger() diff --git a/wallet/address_test.go b/wallet/address_test.go index 4d8334006..e397f89c4 100644 --- a/wallet/address_test.go +++ b/wallet/address_test.go @@ -53,22 +53,22 @@ func (t *testAddress) Decode(r io.Reader) error { func TestAddresses_Serializer(t *testing.T) { rng := pkgtest.Prng(t) - addr := wallettest.NewRandomAddressesMap(rng, 1)[0] + addr := wallettest.NewRandomAddressesMap(rng, 1, 0)[0] peruniotest.GenericSerializerTest(t, &testAddress{addrs: addr}) - addrs := wallettest.NewRandomAddressesMap(rng, 0) + addrs := wallettest.NewRandomAddressesMap(rng, 0, 0) peruniotest.GenericSerializerTest(t, &testAddresses{addrs: wallet.AddressMapArray{Addr: addrs}}) - addrs = wallettest.NewRandomAddressesMap(rng, 1) + addrs = wallettest.NewRandomAddressesMap(rng, 1, 0) peruniotest.GenericSerializerTest(t, &testAddresses{addrs: wallet.AddressMapArray{Addr: addrs}}) - addrs = wallettest.NewRandomAddressesMap(rng, 5) + addrs = wallettest.NewRandomAddressesMap(rng, 5, 0) peruniotest.GenericSerializerTest(t, &testAddresses{addrs: wallet.AddressMapArray{Addr: addrs}}) } func TestAddrKey_Equal(t *testing.T) { rng := pkgtest.Prng(t) - addrs := wallettest.NewRandomAddressArray(rng, 10) + addrs := wallettest.NewRandomAddressArray(rng, 10, 0) // Test all properties of an equivalence relation. for i, a := range addrs { @@ -93,7 +93,7 @@ func TestAddrKey_Equal(t *testing.T) { func TestAddrKey(t *testing.T) { rng := pkgtest.Prng(t) - addrs := wallettest.NewRandomAddressArray(rng, 10) + addrs := wallettest.NewRandomAddressArray(rng, 10, 0) for _, a := range addrs { // Test that Key and FromKey are dual to each other. @@ -105,7 +105,7 @@ func TestAddrKey(t *testing.T) { func TestCloneAddress(t *testing.T) { rng := pkgtest.Prng(t) - addr := wallettest.NewRandomAddress(rng) + addr := wallettest.NewRandomAddress(rng, 0) addr0 := wallet.CloneAddress(addr) require.Equal(t, addr, addr0) require.NotSame(t, addr, addr0) @@ -113,7 +113,7 @@ func TestCloneAddress(t *testing.T) { func TestCloneAddresses(t *testing.T) { rng := pkgtest.Prng(t) - addrs := wallettest.NewRandomAddressArray(rng, 3) + addrs := wallettest.NewRandomAddressArray(rng, 3, 0) addrs0 := wallet.CloneAddresses(addrs) require.Equal(t, addrs, addrs0) require.NotSame(t, addrs, addrs0) diff --git a/wallet/test/randomizer.go b/wallet/test/randomizer.go index 3f0954706..446840d8b 100644 --- a/wallet/test/randomizer.go +++ b/wallet/test/randomizer.go @@ -51,92 +51,95 @@ type ( // randomizer is the currently set wallet testing randomizer. It is initially set to // the default randomizer. -var randomizer Randomizer +var randomizer map[wallet.BackendID]Randomizer // SetRandomizer sets the wallet randomizer. It may be set multiple times. -func SetRandomizer(b Randomizer) { - if randomizer != nil { +func SetRandomizer(b Randomizer, bID wallet.BackendID) { + if randomizer == nil { + randomizer = make(map[wallet.BackendID]Randomizer) + } + if randomizer[bID] != nil { panic("wallet/test randomizer already set") } - randomizer = b + randomizer[bID] = b } // NewRandomAddress returns a new random address by calling the currently set // wallet randomizer. -func NewRandomAddress(rng *rand.Rand) wallet.Address { - return randomizer.NewRandomAddress(rng) +func NewRandomAddress(rng *rand.Rand, bID wallet.BackendID) wallet.Address { + return randomizer[bID].NewRandomAddress(rng) } // NewRandomAddressMap returns a new random address by calling the currently set // wallet randomizer. -func NewRandomAddresses(rng *rand.Rand) map[wallet.BackendID]wallet.Address { - return map[wallet.BackendID]wallet.Address{0: randomizer.NewRandomAddress(rng)} +func NewRandomAddresses(rng *rand.Rand, bID wallet.BackendID) map[wallet.BackendID]wallet.Address { + return map[wallet.BackendID]wallet.Address{bID: randomizer[bID].NewRandomAddress(rng)} } // RandomWallet returns the randomizer backend's wallet. All accounts created // with NewRandomAccount can be found in this wallet. -func RandomWallet() Wallet { - return randomizer.RandomWallet() +func RandomWallet(bID wallet.BackendID) Wallet { + return randomizer[bID].RandomWallet() } // NewRandomAccount returns a new random account by calling the currently set // wallet randomizer. The account is generated from the randomizer wallet // available via RandomWallet. It should already be unlocked. -func NewRandomAccount(rng *rand.Rand) wallet.Account { - return randomizer.RandomWallet().NewRandomAccount(rng) +func NewRandomAccount(rng *rand.Rand, bID wallet.BackendID) wallet.Account { + return randomizer[bID].RandomWallet().NewRandomAccount(rng) } // NewWallet returns a fresh, temporary Wallet for testing purposes that doesn't // hold any accounts yet. New random accounts can be generated using method // NewRandomAccount. -func NewWallet() Wallet { - return randomizer.NewWallet() +func NewWallet(bID wallet.BackendID) Wallet { + return randomizer[bID].NewWallet() } // NewRandomAccounts returns a slice of new random accounts // by calling NewRandomAccount. -func NewRandomAccounts(rng *rand.Rand, n int) ([]map[wallet.BackendID]wallet.Account, []map[wallet.BackendID]wallet.Address) { +func NewRandomAccounts(rng *rand.Rand, n int, bID wallet.BackendID) ([]map[wallet.BackendID]wallet.Account, []map[wallet.BackendID]wallet.Address) { accs := make([]map[wallet.BackendID]wallet.Account, n) addrs := make([]map[wallet.BackendID]wallet.Address, n) for i := range accs { - accs[i] = map[wallet.BackendID]wallet.Account{0: NewRandomAccount(rng)} - addrs[i] = map[wallet.BackendID]wallet.Address{0: accs[i][0].Address()} + accs[i] = map[wallet.BackendID]wallet.Account{bID: NewRandomAccount(rng, bID)} + addrs[i] = map[wallet.BackendID]wallet.Address{bID: accs[i][bID].Address()} } return accs, addrs } // NewRandomAccountMapSlice returns a slice of new random accounts map // by calling NewRandomAccount. -func NewRandomAccountMapSlice(rng *rand.Rand, b wallet.BackendID, n int) []map[wallet.BackendID]wallet.Account { +func NewRandomAccountMapSlice(rng *rand.Rand, bID wallet.BackendID, n int) []map[wallet.BackendID]wallet.Account { accs := make([]map[wallet.BackendID]wallet.Account, n) for i := range accs { - accs[i] = map[wallet.BackendID]wallet.Account{b: NewRandomAccount(rng)} + accs[i] = map[wallet.BackendID]wallet.Account{bID: NewRandomAccount(rng, bID)} } return accs } // NewRandomAccountMap returns a slice of new random accounts // by calling NewRandomAccount. -func NewRandomAccountMap(rng *rand.Rand, id wallet.BackendID) map[wallet.BackendID]wallet.Account { +func NewRandomAccountMap(rng *rand.Rand, bID wallet.BackendID) map[wallet.BackendID]wallet.Account { accs := make(map[wallet.BackendID]wallet.Account) - accs[id] = NewRandomAccount(rng) + accs[bID] = NewRandomAccount(rng, bID) return accs } // NewRandomAddresses returns a slice of new random addresses. -func NewRandomAddressArray(rng *rand.Rand, n int) []wallet.Address { +func NewRandomAddressArray(rng *rand.Rand, n int, bID wallet.BackendID) []wallet.Address { addrs := make([]wallet.Address, n) for i := range addrs { - addrs[i] = NewRandomAddress(rng) + addrs[i] = NewRandomAddress(rng, bID) } return addrs } // NewRandomAddresses returns a slice of new random addresses. -func NewRandomAddressesMap(rng *rand.Rand, n int) []map[wallet.BackendID]wallet.Address { +func NewRandomAddressesMap(rng *rand.Rand, n int, bID wallet.BackendID) []map[wallet.BackendID]wallet.Address { addrs := make([]map[wallet.BackendID]wallet.Address, n) for i := range addrs { - addrs[i] = NewRandomAddresses(rng) + addrs[i] = NewRandomAddresses(rng, bID) } return addrs } diff --git a/wire/net/simple/address.go b/wire/net/simple/address.go index 88543d2ec..2edd81af7 100644 --- a/wire/net/simple/address.go +++ b/wire/net/simple/address.go @@ -95,6 +95,16 @@ func (a *Address) UnmarshalBinary(data []byte) error { return nil } +// String returns the string representation of the address. +func (a *Address) String() string { + return a.Name +} + +// Backend returns the backend ID of the address. +func (a *Address) Backend() wallet.BackendID { + return 0 +} + // encodePublicKey encodes the public key into the buffer. func encodePublicKey(buf *bytes.Buffer, key *rsa.PublicKey) error { // Encode modulus length and modulus From 8589eb8c5b361ea9aa8b44324cbc0937ac12262e Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Tue, 29 Oct 2024 11:09:04 +0100 Subject: [PATCH 12/36] fix(asset.go, allocation.go): Adjust Address() to return byte[] instead of string. fix(params.go): Change IDKey to encode map entries sorted by keys. fix(backend.go): Use BackendID in argument to sign depending on backend. fix(address.go): Sort Addresses by keys before adding them to Keys. Signed-off-by: Sophia Koehler --- backend/sim/channel/asset.go | 5 +++-- channel/allocation.go | 2 +- channel/backend.go | 16 ++-------------- channel/machine.go | 8 ++++---- channel/params.go | 21 +++++++++++++++++++-- channel/persistence/statemachine_test.go | 4 ++-- channel/persistence/test/channel.go | 2 +- channel/test/backend.go | 4 ++-- channel/test/randomizer.go | 2 +- client/test/multiledger.go | 2 +- wire/address.go | 10 ++++++++-- 11 files changed, 44 insertions(+), 32 deletions(-) diff --git a/backend/sim/channel/asset.go b/backend/sim/channel/asset.go index 0a2ec587e..a7ae10fce 100644 --- a/backend/sim/channel/asset.go +++ b/backend/sim/channel/asset.go @@ -67,6 +67,7 @@ func (a Asset) Equal(b channel.Asset) bool { } // Address returns the address of the asset. -func (a Asset) Address() string { - return fmt.Sprintf("Asset(%d)", a.ID) +func (a Asset) Address() []byte { + data, _ := a.MarshalBinary() + return data } diff --git a/channel/allocation.go b/channel/allocation.go index 7fe151c51..0a8c7cf5c 100644 --- a/channel/allocation.go +++ b/channel/allocation.go @@ -102,7 +102,7 @@ type ( // Equal returns true iff this asset is equal to the given asset. Equal(Asset) bool // Address returns the address in string representation. - Address() string + Address() []byte } ) diff --git a/channel/backend.go b/channel/backend.go index b57745aa3..4a710d697 100644 --- a/channel/backend.go +++ b/channel/backend.go @@ -76,20 +76,8 @@ func CalcID(p *Params) (map[wallet.BackendID]ID, error) { } // Sign creates a signature from the account a on state s. -func Sign(a wallet.Account, s *State) (wallet.Sig, error) { - errs := make([]error, len(backend)) - for _, b := range backend { - sig, err := b.Sign(a, s) - if err == nil { - return sig, nil - } else { - errs = append(errs, err) - } - } - if len(errs) > 0 { - return nil, errors.Join(errs...) - } - return nil, errors.New("no valid signature found") +func Sign(a wallet.Account, s *State, b wallet.BackendID) (wallet.Sig, error) { + return backend[b].Sign(a, s) } // Verify verifies that a signature was a valid signature from addr on a state. diff --git a/channel/machine.go b/channel/machine.go index a217e172e..da17d5fe1 100644 --- a/channel/machine.go +++ b/channel/machine.go @@ -223,12 +223,12 @@ func (m *machine) Sig() (sig wallet.Sig, err error) { } if m.stagingTX.Sigs[m.idx] == nil { - for _, acc := range m.acc { - sig, err = Sign(acc, m.stagingTX.State) - if err != nil { + for b, acc := range m.acc { + sig, err = Sign(acc, m.stagingTX.State, b) + if err == nil { + m.stagingTX.Sigs[m.idx] = sig return } - m.stagingTX.Sigs[m.idx] = sig } } else { sig = m.stagingTX.Sigs[m.idx] diff --git a/channel/params.go b/channel/params.go index a09f1eb7d..a454024e4 100644 --- a/channel/params.go +++ b/channel/params.go @@ -19,6 +19,7 @@ import ( "encoding/binary" stdio "io" "math/big" + "sort" "strings" "github.com/pkg/errors" @@ -119,8 +120,9 @@ func IDKey(ids IDMap) string { } // Iterate over the map and encode each key-value pair. - for key, id := range ids { - if err := binary.Write(&buff, binary.BigEndian, int32(key)); err != nil { + sortedKeys, sortedIDs := sortIDMap(ids) + for i, id := range sortedIDs { + if err := binary.Write(&buff, binary.BigEndian, int32(sortedKeys[i])); err != nil { log.Panicf("could not encode map key: " + err.Error()) } if err := perunio.Encode(&buff, id); err != nil { @@ -130,6 +132,21 @@ func IDKey(ids IDMap) string { return buff.String() } +func sortIDMap(ids IDMap) ([]wallet.BackendID, []ID) { + var indexes []int + for i := range ids { + indexes = append(indexes, int(i)) + } + sort.Ints(indexes) + sortedIndexes := make([]wallet.BackendID, len(indexes)) + sortedIDs := make([]ID, len(indexes)) + for i, index := range indexes { + sortedIndexes[i] = wallet.BackendID(index) + sortedIDs[i] = ids[wallet.BackendID(index)] + } + return sortedIndexes, sortedIDs +} + func FromIDKey(k string) IDMap { buff := bytes.NewBuffer([]byte(k)) var numElements int32 diff --git a/channel/persistence/statemachine_test.go b/channel/persistence/statemachine_test.go index b9452e19a..648aa0afd 100644 --- a/channel/persistence/statemachine_test.go +++ b/channel/persistence/statemachine_test.go @@ -71,8 +71,8 @@ func TestStateMachine(t *testing.T) { // remote signers for i := 1; i < n; i++ { var sig wallet.Sig - for _, acc := range accs[i] { - sig, err = channel.Sign(acc, csm.StagingState()) + for b, acc := range accs[i] { + sig, err = channel.Sign(acc, csm.StagingState(), b) require.NoError(err) } err = sm.AddSig(ctx, channel.Index(i), sig) diff --git a/channel/persistence/test/channel.go b/channel/persistence/test/channel.go index ffc98b463..335c2e57a 100644 --- a/channel/persistence/test/channel.go +++ b/channel/persistence/test/channel.go @@ -192,7 +192,7 @@ func (c *Channel) SignAll(ctx context.Context, t require.TestingT) { c.AssertPersisted(ctx, t) // remote signers for i := range c.accounts { - sig, err := channel.Sign(c.accounts[i][0], c.StagingState()) + sig, err := channel.Sign(c.accounts[i][0], c.StagingState(), 0) require.NoError(t, err) c.AddSig(ctx, channel.Index(i), sig) //nolint:errcheck c.AssertPersisted(ctx, t) diff --git a/channel/test/backend.go b/channel/test/backend.go index 4b8da65e9..c816f5243 100644 --- a/channel/test/backend.go +++ b/channel/test/backend.go @@ -109,7 +109,7 @@ func genericChannelIDTest(t *testing.T, s *Setup) { func genericSignTest(t *testing.T, s *Setup) { t.Helper() - _, err := channel.Sign(s.Account, s.State) + _, err := channel.Sign(s.Account, s.State, s.State.Backends[0]) assert.NoError(t, err, "Sign should not return an error") } @@ -119,7 +119,7 @@ func genericVerifyTest(t *testing.T, s *Setup, opts ...GenericTestOption) { id, err := channel.CalcID(s.Params) require.NoError(t, err, "CalcID should not return an error") require.Equal(t, s.Params.ID(), id, "Invalid test params") - sig, err := channel.Sign(s.Account, s.State) + sig, err := channel.Sign(s.Account, s.State, s.State.Backends[0]) require.NoError(t, err, "Sign should not return an error") ok, err := channel.Verify(addr, s.State, sig) diff --git a/channel/test/randomizer.go b/channel/test/randomizer.go index e766abf6a..eed55acaa 100644 --- a/channel/test/randomizer.go +++ b/channel/test/randomizer.go @@ -414,7 +414,7 @@ func NewRandomTransaction(rng *rand.Rand, sigMask []bool, opts ...RandomOpt) *ch if !choice { sigs[i] = nil } else { - sigs[i], err = channel.Sign(accs[i][bID], state) + sigs[i], err = channel.Sign(accs[i][bID], state, bID) } if err != nil { panic(err) diff --git a/client/test/multiledger.go b/client/test/multiledger.go index 841b56341..d1537e8af 100644 --- a/client/test/multiledger.go +++ b/client/test/multiledger.go @@ -119,7 +119,7 @@ func (a *MultiLedgerAsset) Equal(b channel.Asset) bool { } // Address returns the asset's address. -func (a *MultiLedgerAsset) Address() string { +func (a *MultiLedgerAsset) Address() []byte { return a.asset.Address() } diff --git a/wire/address.go b/wire/address.go index fc4315202..f6dab62f6 100644 --- a/wire/address.go +++ b/wire/address.go @@ -18,6 +18,7 @@ import ( "encoding" stdio "io" "perun.network/go-perun/wallet" + "sort" "strings" "github.com/pkg/errors" @@ -177,8 +178,13 @@ func Key(a Address) AddrKey { // Keys returns the `AddrKey` corresponding to the passed `map[int]Address`. func Keys(addressMap map[wallet.BackendID]Address) AddrKey { var keyParts []string - for _, addr := range addressMap { - key := Key(addr) + var indexes []int + for i := range addressMap { + indexes = append(indexes, int(i)) + } + sort.Ints(indexes) + for _, index := range indexes { + key := Key(addressMap[wallet.BackendID(index)]) keyParts = append(keyParts, string(key)) // Assuming Address has a String() method. } return AddrKey(strings.Join(keyParts, "|")) From 39095c1448845653e950ef8066e91d0012891537 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Wed, 6 Nov 2024 11:12:54 +0100 Subject: [PATCH 13/36] chore: Remove unnecessary logs Signed-off-by: Sophia Koehler --- client/proposalmsgs.go | 1 - wire/protobuf/proposalmsgs.go | 6 +----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/client/proposalmsgs.go b/client/proposalmsgs.go index 885a183b6..e7dbab419 100644 --- a/client/proposalmsgs.go +++ b/client/proposalmsgs.go @@ -233,7 +233,6 @@ func (p LedgerChannelProposalMsg) Accept( participant map[wallet.BackendID]wallet.Address, nonceShare ProposalOpts, ) *LedgerChannelProposalAccMsg { - log.Println("LedgerChannelProposalMsg.Accept") if !nonceShare.isNonce() { log.WithField("proposal", p.ProposalID). Panic("LedgerChannelProposal.Accept: nonceShare has no configured nonce") diff --git a/wire/protobuf/proposalmsgs.go b/wire/protobuf/proposalmsgs.go index 5ccc53427..e226bd34f 100644 --- a/wire/protobuf/proposalmsgs.go +++ b/wire/protobuf/proposalmsgs.go @@ -18,11 +18,9 @@ import ( "bytes" "encoding/binary" "fmt" + "github.com/pkg/errors" "math" "math/big" - "perun.network/go-perun/log" - - "github.com/pkg/errors" "perun.network/go-perun/channel" "perun.network/go-perun/client" "perun.network/go-perun/wallet" @@ -293,8 +291,6 @@ func ToAllocation(protoAlloc *Allocation) (alloc *channel.Allocation, err error) if err != nil { return nil, errors.WithMessage(err, "backends") } - log.Printf("ToAllocation: alloc.Backends length: %d, protoAlloc.Assets length: %d", len(alloc.Backends), len(protoAlloc.Assets)) - log.Println("ToAllocation: ", alloc.Backends) alloc.Assets = make([]channel.Asset, len(protoAlloc.Assets)) for i := range protoAlloc.Assets { alloc.Assets[i] = channel.NewAsset(alloc.Backends[i]) From 98e11ea9571dca2d556c5b41ea710ddfc8c084e1 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Wed, 27 Nov 2024 08:59:16 +0100 Subject: [PATCH 14/36] fix: Remove repeated assetIDs in LedgerID array Signed-off-by: Sophia Koehler --- channel/multi/asset.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/channel/multi/asset.go b/channel/multi/asset.go index d4cdd5e5e..cf2e1f283 100644 --- a/channel/multi/asset.go +++ b/channel/multi/asset.go @@ -45,7 +45,7 @@ type ( // LedgerIDs returns the identifiers of the associated ledgers. func (a assets) LedgerIDs() ([]AssetID, error) { - var result []AssetID + ids := make(map[AssetIDKey]AssetID) for _, asset := range a { ma, ok := asset.(Asset) if !ok { @@ -54,11 +54,16 @@ func (a assets) LedgerIDs() ([]AssetID, error) { assetID := ma.AssetID() - // Append the pair of IDs to the result slice - result = append(result, assetID) + ids[AssetIDKey{BackendID: assetID.BackendID(), LedgerID: string(assetID.LedgerId().MapKey())}] = assetID + } + idsArray := make([]AssetID, len(ids)) + i := 0 + for _, v := range ids { + idsArray[i] = v + i++ } - return result, nil + return idsArray, nil } // IsMultiLedgerAssets returns whether the assets are from multiple ledgers. From 46de2d9eaf1a3c074953af379c630a051cf6d3a0 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Wed, 18 Dec 2024 10:27:07 +0100 Subject: [PATCH 15/36] chore: update go.sum, gofmt some files Signed-off-by: Sophia Koehler --- go.sum | 5 ----- wire/address.go | 5 ++++- wire/encode.go | 3 ++- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/go.sum b/go.sum index ba9700f3c..021d88d67 100644 --- a/go.sum +++ b/go.sum @@ -12,14 +12,12 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 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= @@ -91,7 +89,6 @@ golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912 h1:uCLL3g5wH2xjxVREVuAbP9JM5PPKjRbXKRa6IBjkzmU= golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -100,7 +97,6 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -118,7 +114,6 @@ google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/wire/address.go b/wire/address.go index f6dab62f6..87d66910c 100644 --- a/wire/address.go +++ b/wire/address.go @@ -17,10 +17,11 @@ package wire import ( "encoding" stdio "io" - "perun.network/go-perun/wallet" "sort" "strings" + "perun.network/go-perun/wallet" + "github.com/pkg/errors" "perun.network/go-perun/wire/perunio" ) @@ -126,6 +127,8 @@ func (a *AddressMapArray) Decode(r stdio.Reader) (err error) { // IndexOfAddr returns the index of the given address in the address slice, // or -1 if it is not part of the slice. +// +//nolint:unused func IndexOfAddr(addrs []Address, addr Address) int { for i, a := range addrs { if addr.Equal(a) { diff --git a/wire/encode.go b/wire/encode.go index b0a6aa9cd..2c2f39a6b 100644 --- a/wire/encode.go +++ b/wire/encode.go @@ -17,9 +17,10 @@ package wire import ( "fmt" "io" - "perun.network/go-perun/wallet" "strconv" + "perun.network/go-perun/wallet" + "github.com/pkg/errors" "perun.network/go-perun/wire/perunio" From 5e5bfb3de1fe8072c62c5bae1aded8840ccb8e98 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Thu, 19 Dec 2024 10:32:39 +0100 Subject: [PATCH 16/36] fix(wallet/backend.go): Return just one error instead of concatenation of errors chore(All): Run gofmt and sort imports Signed-off-by: Sophia Koehler --- apps/payment/randomizer.go | 1 + backend/sim/channel/init.go | 1 + channel/allocation.go | 1 + channel/allocation_test.go | 3 ++- channel/app.go | 3 ++- channel/backend.go | 1 + channel/errors.go | 1 + channel/errors_internal_test.go | 3 ++- channel/machine.go | 3 ++- channel/machine_test.go | 3 ++- channel/mock_app.go | 1 + channel/mock_app_internal_test.go | 3 ++- channel/multi/adjudicator.go | 1 + channel/multi/subscription.go | 1 + channel/params_test.go | 3 ++- channel/persistence/keyvalue/cache.go | 1 + channel/persistence/keyvalue/persistedstate.go | 1 + channel/persistence/keyvalue/persister.go | 3 ++- channel/persistence/nonpersister.go | 1 + channel/persistence/persistence.go | 1 + channel/persistence/statemachine_test.go | 3 ++- channel/persistence/test/peerchans.go | 1 + .../persistence/test/peerchans_internal_test.go | 3 ++- channel/persistence/test/persistrestorer.go | 3 ++- channel/persistence/test/persistrestorertest.go | 3 ++- channel/state.go | 1 + channel/test/app_randomizer.go | 1 + channel/test/mock_app_randomizer.go | 1 + channel/transaction_test.go | 3 ++- client/adjudicate.go | 1 + client/appchannel_test.go | 3 ++- client/channelconn.go | 1 + client/chanregistry.go | 3 ++- client/client_role_test.go | 3 ++- client/client_test.go | 3 ++- client/clientconn.go | 1 + client/payment_test.go | 3 ++- client/proposal_internal_test.go | 3 ++- client/restore.go | 1 + client/serialize.go | 1 + client/subchannel.go | 1 + client/subchannel_test.go | 3 ++- client/sync.go | 3 ++- client/syncmsgs.go | 1 + client/test/channel.go | 3 ++- client/test/fund.go | 3 ++- client/test/multiledger_dispute.go | 3 ++- client/test/multiledger_happy.go | 3 ++- client/test/persistence.go | 3 ++- client/test/subchannel_dispute.go | 3 ++- client/test/virtualchannel.go | 3 ++- client/updateinterception.go | 3 ++- wallet/backend.go | 13 +++---------- watcher/local/adjudicatorpubsub.go | 14 +++++++------- watcher/local/registry.go | 3 ++- watcher/local/statespubsub.go | 10 +++++----- watcher/local/watcher.go | 3 ++- watcher/local/watcher_test.go | 3 ++- watcher/watcher.go | 1 + wire/account.go | 1 + wire/hybridbus.go | 1 + wire/hybridbus_test.go | 3 ++- wire/localbus.go | 3 ++- wire/localbus_test.go | 3 ++- wire/net/bus.go | 3 ++- wire/net/bus_test.go | 3 ++- wire/net/dialer.go | 1 + wire/net/endpoint.go | 1 + wire/net/endpoint_internal_test.go | 5 +++-- wire/net/endpoint_registry.go | 5 +++-- wire/net/endpoint_registry_external_test.go | 5 +++-- wire/net/endpoint_registry_internal_test.go | 3 ++- wire/net/exchange_addr.go | 1 + wire/net/exchange_addr_internal_test.go | 3 ++- wire/net/simple/account.go | 3 ++- wire/net/simple/address.go | 1 + wire/net/simple/dialer.go | 3 ++- wire/net/simple/dialer_internal_test.go | 3 ++- wire/net/simple/simple_exchange_addr_test.go | 3 ++- wire/net/test/connhub.go | 3 ++- wire/net/test/connhub_internal_test.go | 3 ++- wire/net/test/dialer.go | 3 ++- wire/net/test/listenermap.go | 3 ++- wire/protobuf/proposalmsgs.go | 3 ++- wire/protobuf/serializer.go | 1 + wire/protobuf/wire.pb.go | 5 +++-- wire/test/bustest.go | 3 ++- wire/test/randomizer.go | 1 + 88 files changed, 157 insertions(+), 79 deletions(-) diff --git a/apps/payment/randomizer.go b/apps/payment/randomizer.go index 83245ac02..76bf93304 100644 --- a/apps/payment/randomizer.go +++ b/apps/payment/randomizer.go @@ -16,6 +16,7 @@ package payment import ( "math/rand" + "perun.network/go-perun/wallet" "perun.network/go-perun/channel" diff --git a/backend/sim/channel/init.go b/backend/sim/channel/init.go index 7d38b32b5..09dbbe956 100644 --- a/backend/sim/channel/init.go +++ b/backend/sim/channel/init.go @@ -16,6 +16,7 @@ package channel import ( "math/rand" + "perun.network/go-perun/channel" "perun.network/go-perun/channel/test" ) diff --git a/channel/allocation.go b/channel/allocation.go index 0a8c7cf5c..f117705b6 100644 --- a/channel/allocation.go +++ b/channel/allocation.go @@ -19,6 +19,7 @@ import ( "io" "log" "math/big" + "perun.network/go-perun/wallet" "perun.network/go-perun/wire/perunio" diff --git a/channel/allocation_test.go b/channel/allocation_test.go index 85dfc46b5..74706df81 100644 --- a/channel/allocation_test.go +++ b/channel/allocation_test.go @@ -17,9 +17,10 @@ package channel_test import ( "math/big" "math/rand" - "perun.network/go-perun/wallet" "testing" + "perun.network/go-perun/wallet" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/channel/app.go b/channel/app.go index e853c354d..66fb7c8c2 100644 --- a/channel/app.go +++ b/channel/app.go @@ -16,9 +16,10 @@ package channel import ( "encoding" - "github.com/pkg/errors" "io" + "github.com/pkg/errors" + "perun.network/go-perun/wire/perunio" ) diff --git a/channel/backend.go b/channel/backend.go index 4a710d697..5c25782ac 100644 --- a/channel/backend.go +++ b/channel/backend.go @@ -16,6 +16,7 @@ package channel import ( "errors" + "perun.network/go-perun/wallet" ) diff --git a/channel/errors.go b/channel/errors.go index 6a7f98018..5e75bb99d 100644 --- a/channel/errors.go +++ b/channel/errors.go @@ -16,6 +16,7 @@ package channel import ( "fmt" + "perun.network/go-perun/wallet" "github.com/pkg/errors" diff --git a/channel/errors_internal_test.go b/channel/errors_internal_test.go index ad187d5ec..d3cdfb3e1 100644 --- a/channel/errors_internal_test.go +++ b/channel/errors_internal_test.go @@ -16,9 +16,10 @@ package channel import ( "errors" - "perun.network/go-perun/wallet" "testing" + "perun.network/go-perun/wallet" + "github.com/stretchr/testify/assert" ) diff --git a/channel/machine.go b/channel/machine.go index da17d5fe1..e8663ea56 100644 --- a/channel/machine.go +++ b/channel/machine.go @@ -16,9 +16,10 @@ package channel import ( "fmt" - "github.com/pkg/errors" stdio "io" + "github.com/pkg/errors" + "perun.network/go-perun/log" "perun.network/go-perun/wallet" "perun.network/go-perun/wire/perunio" diff --git a/channel/machine_test.go b/channel/machine_test.go index efced47b7..86e6020b2 100644 --- a/channel/machine_test.go +++ b/channel/machine_test.go @@ -15,9 +15,10 @@ package channel_test import ( - "perun.network/go-perun/wallet" "testing" + "perun.network/go-perun/wallet" + "github.com/stretchr/testify/require" "perun.network/go-perun/channel" "perun.network/go-perun/channel/test" diff --git a/channel/mock_app.go b/channel/mock_app.go index 8308bd633..8d9b03de1 100644 --- a/channel/mock_app.go +++ b/channel/mock_app.go @@ -17,6 +17,7 @@ package channel import ( "encoding/binary" "fmt" + "perun.network/go-perun/wallet" "github.com/pkg/errors" diff --git a/channel/mock_app_internal_test.go b/channel/mock_app_internal_test.go index a2b9e1a82..98bfc3ce0 100644 --- a/channel/mock_app_internal_test.go +++ b/channel/mock_app_internal_test.go @@ -15,9 +15,10 @@ package channel import ( - "perun.network/go-perun/wallet" "testing" + "perun.network/go-perun/wallet" + "github.com/stretchr/testify/assert" wiretest "perun.network/go-perun/wire/test" diff --git a/channel/multi/adjudicator.go b/channel/multi/adjudicator.go index 87d60052a..105090362 100644 --- a/channel/multi/adjudicator.go +++ b/channel/multi/adjudicator.go @@ -17,6 +17,7 @@ package multi import ( "context" "fmt" + "perun.network/go-perun/channel" ) diff --git a/channel/multi/subscription.go b/channel/multi/subscription.go index 956902b0c..cc518bb82 100644 --- a/channel/multi/subscription.go +++ b/channel/multi/subscription.go @@ -16,6 +16,7 @@ package multi import ( "context" + "perun.network/go-perun/channel" "perun.network/go-perun/wallet" ) diff --git a/channel/params_test.go b/channel/params_test.go index 7aa12eebf..0c249c8e0 100644 --- a/channel/params_test.go +++ b/channel/params_test.go @@ -15,9 +15,10 @@ package channel_test import ( - "github.com/stretchr/testify/require" "testing" + "github.com/stretchr/testify/require" + "perun.network/go-perun/channel" "perun.network/go-perun/channel/test" "perun.network/go-perun/wire/perunio" diff --git a/channel/persistence/keyvalue/cache.go b/channel/persistence/keyvalue/cache.go index af667f4a4..6fbb875d1 100644 --- a/channel/persistence/keyvalue/cache.go +++ b/channel/persistence/keyvalue/cache.go @@ -31,6 +31,7 @@ func newChannelCache() *channelCache { } // channelCache contains all channels. +// //nolint:unused type channelCache struct { mutex stdsync.RWMutex diff --git a/channel/persistence/keyvalue/persistedstate.go b/channel/persistence/keyvalue/persistedstate.go index 719f3663c..00d670ef7 100644 --- a/channel/persistence/keyvalue/persistedstate.go +++ b/channel/persistence/keyvalue/persistedstate.go @@ -16,6 +16,7 @@ package keyvalue import ( "io" + "perun.network/go-perun/wallet" "perun.network/go-perun/channel" diff --git a/channel/persistence/keyvalue/persister.go b/channel/persistence/keyvalue/persister.go index 2de9b1ab1..e597e78dc 100644 --- a/channel/persistence/keyvalue/persister.go +++ b/channel/persistence/keyvalue/persister.go @@ -19,11 +19,12 @@ import ( "context" "fmt" "math" - "perun.network/go-perun/wallet" "regexp" "strconv" "strings" + "perun.network/go-perun/wallet" + "github.com/pkg/errors" "perun.network/go-perun/channel" diff --git a/channel/persistence/nonpersister.go b/channel/persistence/nonpersister.go index d37c6974a..2fca64124 100644 --- a/channel/persistence/nonpersister.go +++ b/channel/persistence/nonpersister.go @@ -16,6 +16,7 @@ package persistence import ( "context" + "perun.network/go-perun/wallet" "github.com/pkg/errors" diff --git a/channel/persistence/persistence.go b/channel/persistence/persistence.go index 52ce930b9..38b1f04eb 100644 --- a/channel/persistence/persistence.go +++ b/channel/persistence/persistence.go @@ -17,6 +17,7 @@ package persistence import ( "context" "io" + "perun.network/go-perun/wallet" "perun.network/go-perun/channel" diff --git a/channel/persistence/statemachine_test.go b/channel/persistence/statemachine_test.go index 648aa0afd..daf9d3d44 100644 --- a/channel/persistence/statemachine_test.go +++ b/channel/persistence/statemachine_test.go @@ -16,10 +16,11 @@ package persistence_test import ( "context" - "perun.network/go-perun/wallet" "testing" "time" + "perun.network/go-perun/wallet" + "github.com/stretchr/testify/require" "perun.network/go-perun/channel" diff --git a/channel/persistence/test/peerchans.go b/channel/persistence/test/peerchans.go index 18c90cc34..d54b8b6b8 100644 --- a/channel/persistence/test/peerchans.go +++ b/channel/persistence/test/peerchans.go @@ -17,6 +17,7 @@ package test import ( "bytes" "fmt" + "perun.network/go-perun/wallet" "perun.network/go-perun/channel" diff --git a/channel/persistence/test/peerchans_internal_test.go b/channel/persistence/test/peerchans_internal_test.go index f6b710032..d14802362 100644 --- a/channel/persistence/test/peerchans_internal_test.go +++ b/channel/persistence/test/peerchans_internal_test.go @@ -15,9 +15,10 @@ package test import ( - "perun.network/go-perun/wallet" "testing" + "perun.network/go-perun/wallet" + "github.com/stretchr/testify/assert" "perun.network/go-perun/channel" diff --git a/channel/persistence/test/persistrestorer.go b/channel/persistence/test/persistrestorer.go index c7fa5e977..77177b867 100644 --- a/channel/persistence/test/persistrestorer.go +++ b/channel/persistence/test/persistrestorer.go @@ -19,10 +19,11 @@ package test // import "perun.network/go-perun/channel/persistence/test" import ( "bytes" "context" - "perun.network/go-perun/wallet" "sync" "testing" + "perun.network/go-perun/wallet" + "github.com/pkg/errors" "github.com/stretchr/testify/assert" diff --git a/channel/persistence/test/persistrestorertest.go b/channel/persistence/test/persistrestorertest.go index f372cd45b..075728830 100644 --- a/channel/persistence/test/persistrestorertest.go +++ b/channel/persistence/test/persistrestorertest.go @@ -17,9 +17,10 @@ package test import ( "context" "math/rand" - "perun.network/go-perun/wallet" "testing" + "perun.network/go-perun/wallet" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/channel/state.go b/channel/state.go index d13cdf3f9..1a01ddbe1 100644 --- a/channel/state.go +++ b/channel/state.go @@ -17,6 +17,7 @@ package channel import ( "encoding" "io" + "perun.network/go-perun/wallet" "perun.network/go-perun/wire" diff --git a/channel/test/app_randomizer.go b/channel/test/app_randomizer.go index 99b651848..271f5ec25 100644 --- a/channel/test/app_randomizer.go +++ b/channel/test/app_randomizer.go @@ -16,6 +16,7 @@ package test import ( "math/rand" + "perun.network/go-perun/wallet" "perun.network/go-perun/channel" diff --git a/channel/test/mock_app_randomizer.go b/channel/test/mock_app_randomizer.go index 0e3b36c67..e2830acb9 100644 --- a/channel/test/mock_app_randomizer.go +++ b/channel/test/mock_app_randomizer.go @@ -16,6 +16,7 @@ package test import ( "math/rand" + "perun.network/go-perun/wallet" "github.com/google/uuid" diff --git a/channel/transaction_test.go b/channel/transaction_test.go index b6a8e52a3..6a7ccc6a0 100644 --- a/channel/transaction_test.go +++ b/channel/transaction_test.go @@ -15,9 +15,10 @@ package channel_test import ( - "github.com/stretchr/testify/require" "testing" + "github.com/stretchr/testify/require" + "perun.network/go-perun/channel" "perun.network/go-perun/channel/test" peruniotest "perun.network/go-perun/wire/perunio/test" diff --git a/client/adjudicate.go b/client/adjudicate.go index 8957ad59e..d9061165b 100644 --- a/client/adjudicate.go +++ b/client/adjudicate.go @@ -16,6 +16,7 @@ package client import ( "context" + "perun.network/go-perun/wallet" "github.com/pkg/errors" diff --git a/client/appchannel_test.go b/client/appchannel_test.go index 427b8cad6..7911b0fbf 100644 --- a/client/appchannel_test.go +++ b/client/appchannel_test.go @@ -17,9 +17,10 @@ package client_test import ( "context" "math/big" - "perun.network/go-perun/wallet" "testing" + "perun.network/go-perun/wallet" + "perun.network/go-perun/channel" chtest "perun.network/go-perun/channel/test" "perun.network/go-perun/client" diff --git a/client/channelconn.go b/client/channelconn.go index 27c044497..c10446984 100644 --- a/client/channelconn.go +++ b/client/channelconn.go @@ -16,6 +16,7 @@ package client import ( "context" + "github.com/pkg/errors" "golang.org/x/sync/errgroup" "perun.network/go-perun/wallet" diff --git a/client/chanregistry.go b/client/chanregistry.go index afbf04124..4d7db3027 100644 --- a/client/chanregistry.go +++ b/client/chanregistry.go @@ -15,9 +15,10 @@ package client import ( - "perun.network/go-perun/wallet" "sync" + "perun.network/go-perun/wallet" + "perun.network/go-perun/channel" psync "polycry.pt/poly-go/sync" ) diff --git a/client/client_role_test.go b/client/client_role_test.go index aca1a16c9..65a4520b9 100644 --- a/client/client_role_test.go +++ b/client/client_role_test.go @@ -18,10 +18,11 @@ import ( "context" "math/big" "math/rand" - "perun.network/go-perun/wallet" "testing" "time" + "perun.network/go-perun/wallet" + "perun.network/go-perun/apps/payment" chtest "perun.network/go-perun/channel/test" "perun.network/go-perun/client" diff --git a/client/client_test.go b/client/client_test.go index 41a491838..f0f9db45f 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -16,10 +16,11 @@ package client_test import ( "context" - "perun.network/go-perun/wallet" "testing" "time" + "perun.network/go-perun/wallet" + "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/client/clientconn.go b/client/clientconn.go index 272bd1974..171cee100 100644 --- a/client/clientconn.go +++ b/client/clientconn.go @@ -16,6 +16,7 @@ package client import ( "context" + "perun.network/go-perun/wallet" "github.com/pkg/errors" diff --git a/client/payment_test.go b/client/payment_test.go index 56437fdc3..1b91bc555 100644 --- a/client/payment_test.go +++ b/client/payment_test.go @@ -18,9 +18,10 @@ import ( "context" "math/big" "math/rand" - "perun.network/go-perun/wallet" "testing" + "perun.network/go-perun/wallet" + chtest "perun.network/go-perun/channel/test" "perun.network/go-perun/client" ctest "perun.network/go-perun/client/test" diff --git a/client/proposal_internal_test.go b/client/proposal_internal_test.go index 59c503688..7c50ff213 100644 --- a/client/proposal_internal_test.go +++ b/client/proposal_internal_test.go @@ -16,9 +16,10 @@ package client import ( "math/rand" - "perun.network/go-perun/wallet" "testing" + "perun.network/go-perun/wallet" + "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/client/restore.go b/client/restore.go index 873814039..1e32bc67c 100644 --- a/client/restore.go +++ b/client/restore.go @@ -16,6 +16,7 @@ package client import ( "context" + "perun.network/go-perun/wallet" "github.com/pkg/errors" diff --git a/client/serialize.go b/client/serialize.go index 6278deaa1..95e4d903c 100644 --- a/client/serialize.go +++ b/client/serialize.go @@ -16,6 +16,7 @@ package client import ( "io" + "perun.network/go-perun/wallet" "github.com/pkg/errors" diff --git a/client/subchannel.go b/client/subchannel.go index c5724409f..bfeda2a12 100644 --- a/client/subchannel.go +++ b/client/subchannel.go @@ -16,6 +16,7 @@ package client import ( "context" + "perun.network/go-perun/wallet" "github.com/pkg/errors" diff --git a/client/subchannel_test.go b/client/subchannel_test.go index 063ba9404..ac03932fc 100644 --- a/client/subchannel_test.go +++ b/client/subchannel_test.go @@ -17,9 +17,10 @@ package client_test import ( "context" "math/big" - "perun.network/go-perun/wallet" "testing" + "perun.network/go-perun/wallet" + "perun.network/go-perun/apps/payment" chtest "perun.network/go-perun/channel/test" "perun.network/go-perun/client" diff --git a/client/sync.go b/client/sync.go index b30dc520c..e137e6eea 100644 --- a/client/sync.go +++ b/client/sync.go @@ -17,9 +17,10 @@ package client import ( "context" "log" - "perun.network/go-perun/wallet" "time" + "perun.network/go-perun/wallet" + "github.com/pkg/errors" "perun.network/go-perun/channel" diff --git a/client/syncmsgs.go b/client/syncmsgs.go index b2ee38e99..ceb052a56 100644 --- a/client/syncmsgs.go +++ b/client/syncmsgs.go @@ -16,6 +16,7 @@ package client import ( "io" + "perun.network/go-perun/wallet" "perun.network/go-perun/channel" diff --git a/client/test/channel.go b/client/test/channel.go index 9cee1dec3..a812df0d5 100644 --- a/client/test/channel.go +++ b/client/test/channel.go @@ -19,9 +19,10 @@ import ( "errors" "io" "math/big" - "perun.network/go-perun/wallet" "time" + "perun.network/go-perun/wallet" + "perun.network/go-perun/channel" "perun.network/go-perun/client" "perun.network/go-perun/log" diff --git a/client/test/fund.go b/client/test/fund.go index 975ff11c2..2392894f3 100644 --- a/client/test/fund.go +++ b/client/test/fund.go @@ -19,9 +19,10 @@ import ( "errors" "math/big" "math/rand" - "perun.network/go-perun/wallet" "testing" + "perun.network/go-perun/wallet" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "perun.network/go-perun/channel" diff --git a/client/test/multiledger_dispute.go b/client/test/multiledger_dispute.go index d452c55d3..a19350d63 100644 --- a/client/test/multiledger_dispute.go +++ b/client/test/multiledger_dispute.go @@ -17,10 +17,11 @@ package test import ( "context" "math/big" - "perun.network/go-perun/wallet" "testing" "time" + "perun.network/go-perun/wallet" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/client/test/multiledger_happy.go b/client/test/multiledger_happy.go index 0e795905c..490df99c5 100644 --- a/client/test/multiledger_happy.go +++ b/client/test/multiledger_happy.go @@ -16,9 +16,10 @@ package test import ( "context" - "perun.network/go-perun/wallet" "testing" + "perun.network/go-perun/wallet" + "github.com/stretchr/testify/require" "perun.network/go-perun/channel" "perun.network/go-perun/client" diff --git a/client/test/persistence.go b/client/test/persistence.go index aadfb6d5a..80f58fdfb 100644 --- a/client/test/persistence.go +++ b/client/test/persistence.go @@ -17,10 +17,11 @@ package test import ( "context" "math/big" - "perun.network/go-perun/wallet" "testing" "time" + "perun.network/go-perun/wallet" + "perun.network/go-perun/channel" "perun.network/go-perun/client" "perun.network/go-perun/wire" diff --git a/client/test/subchannel_dispute.go b/client/test/subchannel_dispute.go index 2a10f2c5c..e0e1322f9 100644 --- a/client/test/subchannel_dispute.go +++ b/client/test/subchannel_dispute.go @@ -17,10 +17,11 @@ package test import ( "fmt" "math/big" - "perun.network/go-perun/wallet" "testing" "time" + "perun.network/go-perun/wallet" + "perun.network/go-perun/channel" "perun.network/go-perun/client" ) diff --git a/client/test/virtualchannel.go b/client/test/virtualchannel.go index af141bbfb..60eda7329 100644 --- a/client/test/virtualchannel.go +++ b/client/test/virtualchannel.go @@ -18,10 +18,11 @@ import ( "context" "math/big" "math/rand" - "perun.network/go-perun/wallet" "testing" "time" + "perun.network/go-perun/wallet" + "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/client/updateinterception.go b/client/updateinterception.go index 8f2c51c7d..2627c0413 100644 --- a/client/updateinterception.go +++ b/client/updateinterception.go @@ -16,9 +16,10 @@ package client import ( "context" - "perun.network/go-perun/wallet" "sync" + "perun.network/go-perun/wallet" + "perun.network/go-perun/channel" ) diff --git a/wallet/backend.go b/wallet/backend.go index de5eec212..3584da165 100644 --- a/wallet/backend.go +++ b/wallet/backend.go @@ -15,7 +15,7 @@ package wallet import ( - "errors" + "fmt" "io" ) @@ -60,22 +60,15 @@ func NewAddress(id BackendID) Address { // DecodeSig calls DecodeSig of all Backends and returns an error if none return a valid signature. func DecodeSig(r io.Reader) (Sig, error) { - var errs []error + var err error for _, b := range backend { sig, err := b.DecodeSig(r) if err == nil { return sig, nil - } else { - errs = append(errs, err) } } - if len(errs) > 0 { - // Join all errors into a single error message. - return nil, errors.Join(errs...) - } - - return nil, errors.New("no valid signature found") + return nil, fmt.Errorf("no valid signature found: %v", err) } // VerifySignature calls VerifySignature of the current backend. diff --git a/watcher/local/adjudicatorpubsub.go b/watcher/local/adjudicatorpubsub.go index 6f94a9571..4b7fbda90 100644 --- a/watcher/local/adjudicatorpubsub.go +++ b/watcher/local/adjudicatorpubsub.go @@ -49,13 +49,13 @@ func newAdjudicatorEventsPubSub() *adjudicatorPubSub { // // Panics if the pub-sub instance is already closed. It is implemented this // way, because -// 1. The watcher will publish on this pub-sub only when it receives an -// adjudicator event from the blockchain. -// 2. When de-registering a channel from the watcher, watcher will close the -// subscription for adjudicator events from blockchain, before closing this -// pub-sub. -// 3. This way, it can be guaranteed that, this method will never be called -// after the pub-sub instance is closed. +// 1. The watcher will publish on this pub-sub only when it receives an +// adjudicator event from the blockchain. +// 2. When de-registering a channel from the watcher, watcher will close the +// subscription for adjudicator events from blockchain, before closing this +// pub-sub. +// 3. This way, it can be guaranteed that, this method will never be called +// after the pub-sub instance is closed. func (a *adjudicatorPubSub) publish(e channel.AdjudicatorEvent) { a.pipe <- e } diff --git a/watcher/local/registry.go b/watcher/local/registry.go index 9335aed74..6faeb572a 100644 --- a/watcher/local/registry.go +++ b/watcher/local/registry.go @@ -15,9 +15,10 @@ package local import ( - "perun.network/go-perun/wallet" "sync" + "perun.network/go-perun/wallet" + "github.com/pkg/errors" "perun.network/go-perun/channel" diff --git a/watcher/local/statespubsub.go b/watcher/local/statespubsub.go index 90ef993fd..5874d121c 100644 --- a/watcher/local/statespubsub.go +++ b/watcher/local/statespubsub.go @@ -53,11 +53,11 @@ func newStatesPubSub() *statesPubSub { // // Panics if the pub-sub instance is already closed. It is implemented this // way, because -// 1. Watcher requires that, the Publish method must not be called after stop -// watching for a channel. See docs of watcher.StatesPub for more details. -// 2. Hence, by properly integrating the watcher into the client, it can be -// guaranteed that, this method will never be called after the pub-sub -// instance is closed and that, this method will never panic. +// 1. Watcher requires that, the Publish method must not be called after stop +// watching for a channel. See docs of watcher.StatesPub for more details. +// 2. Hence, by properly integrating the watcher into the client, it can be +// guaranteed that, this method will never be called after the pub-sub +// instance is closed and that, this method will never panic. func (s *statesPubSub) Publish(_ context.Context, tx channel.Transaction) error { s.pipe <- tx return nil diff --git a/watcher/local/watcher.go b/watcher/local/watcher.go index a5135516f..344ab5a58 100644 --- a/watcher/local/watcher.go +++ b/watcher/local/watcher.go @@ -17,9 +17,10 @@ package local import ( "context" stderrors "errors" - "perun.network/go-perun/wallet" "time" + "perun.network/go-perun/wallet" + "github.com/pkg/errors" "perun.network/go-perun/channel" diff --git a/watcher/local/watcher_test.go b/watcher/local/watcher_test.go index 897c251d7..dc237f333 100644 --- a/watcher/local/watcher_test.go +++ b/watcher/local/watcher_test.go @@ -18,11 +18,12 @@ import ( "context" "fmt" "math/rand" - "perun.network/go-perun/wallet" "sync" "testing" "time" + "perun.network/go-perun/wallet" + "github.com/stretchr/testify/assert" testifyMock "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" diff --git a/watcher/watcher.go b/watcher/watcher.go index 7a28359b5..1e01a3358 100644 --- a/watcher/watcher.go +++ b/watcher/watcher.go @@ -16,6 +16,7 @@ package watcher import ( "context" + "perun.network/go-perun/wallet" "perun.network/go-perun/channel" diff --git a/wire/account.go b/wire/account.go index fd5202e66..616fa230a 100644 --- a/wire/account.go +++ b/wire/account.go @@ -18,6 +18,7 @@ import ( "encoding/binary" "fmt" "io" + "perun.network/go-perun/wallet" ) diff --git a/wire/hybridbus.go b/wire/hybridbus.go index 80aa60a86..0b30b0b14 100644 --- a/wire/hybridbus.go +++ b/wire/hybridbus.go @@ -17,6 +17,7 @@ package wire import ( "context" "fmt" + "perun.network/go-perun/wallet" "polycry.pt/poly-go/errors" diff --git a/wire/hybridbus_test.go b/wire/hybridbus_test.go index 18a0b8c7f..1b5265749 100644 --- a/wire/hybridbus_test.go +++ b/wire/hybridbus_test.go @@ -15,9 +15,10 @@ package wire_test import ( - "perun.network/go-perun/wallet" "testing" + "perun.network/go-perun/wallet" + "github.com/stretchr/testify/require" . "perun.network/go-perun/wire" diff --git a/wire/localbus.go b/wire/localbus.go index 2339de497..80294a48f 100644 --- a/wire/localbus.go +++ b/wire/localbus.go @@ -16,9 +16,10 @@ package wire import ( "context" - "perun.network/go-perun/wallet" "sync" + "perun.network/go-perun/wallet" + "github.com/pkg/errors" "perun.network/go-perun/log" diff --git a/wire/localbus_test.go b/wire/localbus_test.go index 83ba3a694..2d5141822 100644 --- a/wire/localbus_test.go +++ b/wire/localbus_test.go @@ -15,9 +15,10 @@ package wire_test import ( - "perun.network/go-perun/wallet" "testing" + "perun.network/go-perun/wallet" + . "perun.network/go-perun/wire" "perun.network/go-perun/wire/test" ) diff --git a/wire/net/bus.go b/wire/net/bus.go index f50c7ba73..adfa33e59 100644 --- a/wire/net/bus.go +++ b/wire/net/bus.go @@ -16,10 +16,11 @@ package net import ( "context" - "perun.network/go-perun/wallet" "sync" "time" + "perun.network/go-perun/wallet" + "github.com/pkg/errors" "perun.network/go-perun/log" diff --git a/wire/net/bus_test.go b/wire/net/bus_test.go index d4458c476..80e5e80f6 100644 --- a/wire/net/bus_test.go +++ b/wire/net/bus_test.go @@ -15,9 +15,10 @@ package net_test import ( - "perun.network/go-perun/wallet" "testing" + "perun.network/go-perun/wallet" + "github.com/stretchr/testify/assert" "perun.network/go-perun/wire" diff --git a/wire/net/dialer.go b/wire/net/dialer.go index b18aa335e..5e0e55d17 100644 --- a/wire/net/dialer.go +++ b/wire/net/dialer.go @@ -16,6 +16,7 @@ package net import ( "context" + "perun.network/go-perun/wallet" "perun.network/go-perun/wire" diff --git a/wire/net/endpoint.go b/wire/net/endpoint.go index 71017448a..898416ce8 100644 --- a/wire/net/endpoint.go +++ b/wire/net/endpoint.go @@ -18,6 +18,7 @@ import ( "context" "fmt" "io" + "perun.network/go-perun/wallet" "github.com/pkg/errors" diff --git a/wire/net/endpoint_internal_test.go b/wire/net/endpoint_internal_test.go index 92d0bf734..063128599 100644 --- a/wire/net/endpoint_internal_test.go +++ b/wire/net/endpoint_internal_test.go @@ -17,12 +17,13 @@ package net import ( "context" "math/rand" - "perun.network/go-perun/channel" - "perun.network/go-perun/wallet" "sync" "testing" "time" + "perun.network/go-perun/channel" + "perun.network/go-perun/wallet" + "github.com/pkg/errors" "github.com/stretchr/testify/assert" diff --git a/wire/net/endpoint_registry.go b/wire/net/endpoint_registry.go index ac5a85ac4..ca09d83ec 100644 --- a/wire/net/endpoint_registry.go +++ b/wire/net/endpoint_registry.go @@ -16,13 +16,14 @@ package net import ( "context" - "perun.network/go-perun/channel/persistence/test" - "perun.network/go-perun/wallet" "sync" "sync/atomic" "time" "unsafe" + "perun.network/go-perun/channel/persistence/test" + "perun.network/go-perun/wallet" + "github.com/pkg/errors" "perun.network/go-perun/log" diff --git a/wire/net/endpoint_registry_external_test.go b/wire/net/endpoint_registry_external_test.go index 2e78cfb25..2ee3c32af 100644 --- a/wire/net/endpoint_registry_external_test.go +++ b/wire/net/endpoint_registry_external_test.go @@ -16,11 +16,12 @@ package net_test import ( "context" - "perun.network/go-perun/channel" - "perun.network/go-perun/wallet" "testing" "time" + "perun.network/go-perun/channel" + "perun.network/go-perun/wallet" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/wire/net/endpoint_registry_internal_test.go b/wire/net/endpoint_registry_internal_test.go index cb4edde1e..b10e6267b 100644 --- a/wire/net/endpoint_registry_internal_test.go +++ b/wire/net/endpoint_registry_internal_test.go @@ -17,11 +17,12 @@ package net import ( "context" "net" - "perun.network/go-perun/wallet" "sync" "testing" "time" + "perun.network/go-perun/wallet" + "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/wire/net/exchange_addr.go b/wire/net/exchange_addr.go index 262d5cdd3..066ae4ed4 100644 --- a/wire/net/exchange_addr.go +++ b/wire/net/exchange_addr.go @@ -17,6 +17,7 @@ package net import ( "context" "fmt" + "perun.network/go-perun/channel/persistence/test" "perun.network/go-perun/wallet" diff --git a/wire/net/exchange_addr_internal_test.go b/wire/net/exchange_addr_internal_test.go index 72fa82813..5ff019f45 100644 --- a/wire/net/exchange_addr_internal_test.go +++ b/wire/net/exchange_addr_internal_test.go @@ -16,10 +16,11 @@ package net import ( "context" - "perun.network/go-perun/channel" "sync" "testing" + "perun.network/go-perun/channel" + "github.com/stretchr/testify/assert" "perun.network/go-perun/wire" diff --git a/wire/net/simple/account.go b/wire/net/simple/account.go index 4e207851c..799a59ab6 100644 --- a/wire/net/simple/account.go +++ b/wire/net/simple/account.go @@ -19,8 +19,9 @@ import ( crypto_rand "crypto/rand" "crypto/rsa" "crypto/sha256" - "github.com/pkg/errors" "math/rand" + + "github.com/pkg/errors" "perun.network/go-perun/wire" ) diff --git a/wire/net/simple/address.go b/wire/net/simple/address.go index 2edd81af7..4ed79569f 100644 --- a/wire/net/simple/address.go +++ b/wire/net/simple/address.go @@ -22,6 +22,7 @@ import ( "encoding/binary" "math/big" "math/rand" + "perun.network/go-perun/wallet" "perun.network/go-perun/wire" diff --git a/wire/net/simple/dialer.go b/wire/net/simple/dialer.go index 485342d0b..a1447c21c 100644 --- a/wire/net/simple/dialer.go +++ b/wire/net/simple/dialer.go @@ -18,10 +18,11 @@ import ( "context" "crypto/tls" "net" - "perun.network/go-perun/wallet" "sync" "time" + "perun.network/go-perun/wallet" + "github.com/pkg/errors" "perun.network/go-perun/wire" wirenet "perun.network/go-perun/wire/net" diff --git a/wire/net/simple/dialer_internal_test.go b/wire/net/simple/dialer_internal_test.go index fe17b4d6f..8758db39b 100644 --- a/wire/net/simple/dialer_internal_test.go +++ b/wire/net/simple/dialer_internal_test.go @@ -25,10 +25,11 @@ import ( "fmt" "math/big" "net" - "perun.network/go-perun/wallet" "testing" "time" + "perun.network/go-perun/wallet" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/wire/net/simple/simple_exchange_addr_test.go b/wire/net/simple/simple_exchange_addr_test.go index 78ad37c9f..e1d7d5eef 100644 --- a/wire/net/simple/simple_exchange_addr_test.go +++ b/wire/net/simple/simple_exchange_addr_test.go @@ -22,11 +22,12 @@ import ( "context" "math/rand" "net" - "perun.network/go-perun/channel" "sync" "testing" "time" + "perun.network/go-perun/channel" + "github.com/stretchr/testify/assert" "perun.network/go-perun/wire" diff --git a/wire/net/test/connhub.go b/wire/net/test/connhub.go index 54c53f961..8a7c3b5ce 100644 --- a/wire/net/test/connhub.go +++ b/wire/net/test/connhub.go @@ -15,9 +15,10 @@ package test import ( - "perun.network/go-perun/wallet" gosync "sync" + "perun.network/go-perun/wallet" + "github.com/pkg/errors" "perun.network/go-perun/wire" diff --git a/wire/net/test/connhub_internal_test.go b/wire/net/test/connhub_internal_test.go index 35f47f8be..d77549529 100644 --- a/wire/net/test/connhub_internal_test.go +++ b/wire/net/test/connhub_internal_test.go @@ -16,9 +16,10 @@ package test import ( "context" - "perun.network/go-perun/wallet" "testing" + "perun.network/go-perun/wallet" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/wire/net/test/dialer.go b/wire/net/test/dialer.go index 86f4c5879..5fe5137e6 100644 --- a/wire/net/test/dialer.go +++ b/wire/net/test/dialer.go @@ -17,9 +17,10 @@ package test import ( "context" "net" - "perun.network/go-perun/wallet" "sync/atomic" + "perun.network/go-perun/wallet" + "github.com/pkg/errors" "perun.network/go-perun/wire" diff --git a/wire/net/test/listenermap.go b/wire/net/test/listenermap.go index a685d37b1..12dde418b 100644 --- a/wire/net/test/listenermap.go +++ b/wire/net/test/listenermap.go @@ -15,9 +15,10 @@ package test import ( + "sync" + "perun.network/go-perun/channel/persistence/test" "perun.network/go-perun/wallet" - "sync" "github.com/pkg/errors" "perun.network/go-perun/wire" diff --git a/wire/protobuf/proposalmsgs.go b/wire/protobuf/proposalmsgs.go index e226bd34f..0f756629e 100644 --- a/wire/protobuf/proposalmsgs.go +++ b/wire/protobuf/proposalmsgs.go @@ -18,9 +18,10 @@ import ( "bytes" "encoding/binary" "fmt" - "github.com/pkg/errors" "math" "math/big" + + "github.com/pkg/errors" "perun.network/go-perun/channel" "perun.network/go-perun/client" "perun.network/go-perun/wallet" diff --git a/wire/protobuf/serializer.go b/wire/protobuf/serializer.go index da8571297..1b4fe8140 100644 --- a/wire/protobuf/serializer.go +++ b/wire/protobuf/serializer.go @@ -18,6 +18,7 @@ import ( "encoding/binary" "fmt" "io" + "perun.network/go-perun/wallet" "github.com/pkg/errors" diff --git a/wire/protobuf/wire.pb.go b/wire/protobuf/wire.pb.go index 96e208bee..31ea66cb3 100644 --- a/wire/protobuf/wire.pb.go +++ b/wire/protobuf/wire.pb.go @@ -23,10 +23,11 @@ package protobuf import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" sync "sync" + + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" ) const ( diff --git a/wire/test/bustest.go b/wire/test/bustest.go index 6e9fb319b..4409d2550 100644 --- a/wire/test/bustest.go +++ b/wire/test/bustest.go @@ -16,10 +16,11 @@ package test import ( "context" - "perun.network/go-perun/wallet" "testing" "time" + "perun.network/go-perun/wallet" + "github.com/stretchr/testify/require" "perun.network/go-perun/wire" diff --git a/wire/test/randomizer.go b/wire/test/randomizer.go index 04478b50c..c88f8f1a9 100644 --- a/wire/test/randomizer.go +++ b/wire/test/randomizer.go @@ -16,6 +16,7 @@ package test import ( "math/rand" + "perun.network/go-perun/wallet" "perun.network/go-perun/wire" From 70036dfbaa49f7e181319c0ab53073e191d58ea9 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Thu, 19 Dec 2024 11:44:32 +0100 Subject: [PATCH 17/36] fix(golangci.yml): Exclude generated file from linter chore: Refactor for linter Signed-off-by: Sophia Koehler --- .golangci.yml | 2 ++ backend/sim/channel/asset.go | 2 +- backend/sim/channel/backend.go | 2 +- channel/allocation.go | 14 ++++------ channel/allocation_test.go | 2 +- channel/machine.go | 2 +- channel/multi/asset.go | 1 + channel/params.go | 26 ++++++++----------- channel/params_test.go | 1 - channel/persistence/nonpersister.go | 1 + channel/persistence/test/channel.go | 2 +- .../persistence/test/persistrestorertest.go | 2 +- channel/test/randomizer.go | 6 ++--- client/proposal.go | 3 ++- client/restore_internal_test.go | 2 +- client/test/backend.go | 5 ++-- client/test/role.go | 2 +- client/test/syncmsgs.go | 2 +- client/test/updatemsgs.go | 4 +-- client/virtual_channel.go | 1 + wallet/address.go | 10 ++++--- wallet/backend.go | 1 - wallet/test/randomizer.go | 6 ++--- watcher/local/watcher_test.go | 2 +- wire/account.go | 2 +- wire/address.go | 13 +++++----- wire/net/endpoint_internal_test.go | 3 +-- wire/net/simple/address.go | 2 +- wire/net/simple/listener_internal_test.go | 3 +++ wire/perunio/serializer/serializer.go | 24 ----------------- wire/protobuf/proposalmsgs.go | 5 +++- wire/protobuf/syncmsgs.go | 2 +- wire/protobuf/updatemsgs.go | 2 +- 33 files changed, 70 insertions(+), 87 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index b25ce4581..192e7bf13 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -48,6 +48,8 @@ linters-settings: template-path: ".scripts/copyright-notice" forbidigo: forbid: + - exclude-rules: + - path: ".*\\.pb\\.go$" # Exclude protobuf generated files. # Forbid functions to start with "get" or "Get". - ^[Gg]et.*$ - ^[Ee]quals$ diff --git a/backend/sim/channel/asset.go b/backend/sim/channel/asset.go index a7ae10fce..69f7c61d5 100644 --- a/backend/sim/channel/asset.go +++ b/backend/sim/channel/asset.go @@ -44,7 +44,7 @@ func NewRandomAsset(rng *rand.Rand) *Asset { // MarshalBinary marshals the address into its binary representation. func (a Asset) MarshalBinary() ([]byte, error) { data := make([]byte, assetLen) - byteOrder.PutUint64(data, uint64(a.ID)) + byteOrder.PutUint64(data, uint64(a.ID)) //nolint:gosec return data, nil } diff --git a/backend/sim/channel/backend.go b/backend/sim/channel/backend.go index 0f5397468..98a25ae08 100644 --- a/backend/sim/channel/backend.go +++ b/backend/sim/channel/backend.go @@ -37,7 +37,7 @@ func (*backend) CalcID(p *channel.Params) (id channel.ID, err error) { w := sha256.New() // Write Parts - if err := perunio.Encode(w, wallet.AddressMapArray{p.Parts}); err != nil { + if err := perunio.Encode(w, wallet.AddressMapArray{Addr: p.Parts}); err != nil { log.Panic("Could not write to sha256 hasher") } diff --git a/channel/allocation.go b/channel/allocation.go index f117705b6..7f9e25395 100644 --- a/channel/allocation.go +++ b/channel/allocation.go @@ -127,7 +127,7 @@ func NewAllocation(numParts int, backends []wallet.BackendID, assets ...Asset) * func (a *Allocation) AssetIndex(asset Asset) (Index, bool) { for idx, _asset := range a.Assets { if asset.Equal(_asset) { - return Index(idx), true + return Index(idx), true //nolint:gosec } } return 0, false @@ -194,15 +194,11 @@ func (a *Allocation) NumParts() int { func (a Allocation) Clone() (clone Allocation) { if a.Backends != nil { clone.Backends = make([]wallet.BackendID, len(a.Backends)) - for i, bID := range a.Backends { - clone.Backends[i] = bID - } + copy(clone.Backends, a.Backends) } if a.Assets != nil { clone.Assets = make([]Asset, len(a.Assets)) - for i, asset := range a.Assets { - clone.Assets[i] = asset - } + copy(clone.Assets, a.Assets) } clone.Balances = a.Balances.Clone() @@ -334,7 +330,7 @@ func (a Allocation) Encode(w io.Writer) error { } // encode assets for i, asset := range a.Assets { - if err := perunio.Encode(w, uint32(a.Backends[i])); err != nil { + if err := perunio.Encode(w, uint32(a.Backends[i])); err != nil { //nolint:gosec return errors.WithMessagef(err, "encoding backends %d", i) } if err := perunio.Encode(w, asset); err != nil { @@ -634,7 +630,7 @@ func AssertAssetsEqual(a []Asset, b []Asset) error { return nil } -// AssertAssetsEqual returns an error if the given assets are not equal. +// AssertBackendsEqual returns an error if the given assets are not equal. func AssertBackendsEqual(a []wallet.BackendID, b []wallet.BackendID) error { if len(a) != len(b) { return errors.New("length mismatch") diff --git a/channel/allocation_test.go b/channel/allocation_test.go index 74706df81..fe9f07804 100644 --- a/channel/allocation_test.go +++ b/channel/allocation_test.go @@ -278,7 +278,7 @@ func TestAllocationValidLimits(t *testing.T) { } allocation.Assets = test.NewRandomAssets(rng, test.WithNumAssets(x.numAssets)) - for i, _ := range allocation.Assets { + for i := range allocation.Assets { allocation.Backends[i] = 0 } diff --git a/channel/machine.go b/channel/machine.go index e8663ea56..78e742dff 100644 --- a/channel/machine.go +++ b/channel/machine.go @@ -228,7 +228,7 @@ func (m *machine) Sig() (sig wallet.Sig, err error) { sig, err = Sign(acc, m.stagingTX.State, b) if err == nil { m.stagingTX.Sigs[m.idx] = sig - return + return sig, nil } } } else { diff --git a/channel/multi/asset.go b/channel/multi/asset.go index cf2e1f283..6953e94e6 100644 --- a/channel/multi/asset.go +++ b/channel/multi/asset.go @@ -27,6 +27,7 @@ type ( AssetID() AssetID } + // AssetID represents an asset identifier. AssetID interface { BackendID() uint32 LedgerId() LedgerID diff --git a/channel/params.go b/channel/params.go index a454024e4..fff97d7b4 100644 --- a/channel/params.go +++ b/channel/params.go @@ -35,7 +35,7 @@ const IDLen = 32 // ID represents a channelID. type ID = [IDLen]byte -// IDMap is a map of IDs with keys corresponding to backendIDs +// IDMap is a map of IDs with keys corresponding to backendIDs. type IDMap map[wallet.BackendID]ID // MaxNonceLen is the maximum byte count of a nonce. @@ -75,12 +75,12 @@ func EqualIDs(a, b map[wallet.BackendID]ID) bool { } func (ids IDMap) Encode(w stdio.Writer) error { - length := int32(len(ids)) + length := int32(len(ids)) //nolint:gosec if err := perunio.Encode(w, length); err != nil { return errors.WithMessage(err, "encoding map length") } for i, id := range ids { - if err := perunio.Encode(w, int32(i)); err != nil { + if err := perunio.Encode(w, int32(i)); err != nil { //nolint:gosec return errors.WithMessage(err, "encoding map index") } if err := perunio.Encode(w, id); err != nil { @@ -112,14 +112,11 @@ func (ids *IDMap) Decode(r stdio.Reader) error { func IDKey(ids IDMap) string { var buff strings.Builder - // Encode the number of elements in the map first. - length := int32(len(ids)) // Using int32 to encode the length - err := binary.Write(&buff, binary.BigEndian, length) + length := int32(len(ids)) //nolint:gosec + err := binary.Write(&buff, binary.BigEndian, length) //nolint:gosec if err != nil { log.Panic("could not encode map length in Key: ", err) - } - // Iterate over the map and encode each key-value pair. sortedKeys, sortedIDs := sortIDMap(ids) for i, id := range sortedIDs { if err := binary.Write(&buff, binary.BigEndian, int32(sortedKeys[i])); err != nil { @@ -133,9 +130,9 @@ func IDKey(ids IDMap) string { } func sortIDMap(ids IDMap) ([]wallet.BackendID, []ID) { - var indexes []int + indexes := make([]int, len(ids)) for i := range ids { - indexes = append(indexes, int(i)) + indexes[i] = int(i) } sort.Ints(indexes) sortedIndexes := make([]wallet.BackendID, len(indexes)) @@ -279,12 +276,12 @@ func NewParamsUnsafe(challengeDuration uint64, parts []map[wallet.BackendID]wall return p } -// CloneAddress returns a clone of an Address using its binary marshaling +// CloneAddresses returns a clone of an Address using its binary marshaling // implementation. It panics if an error occurs during binary (un)marshaling. func CloneAddresses(as []map[wallet.BackendID]wallet.Address) []map[wallet.BackendID]wallet.Address { - var cloneMap []map[wallet.BackendID]wallet.Address - for _, a := range as { - cloneMap = append(cloneMap, wallet.CloneAddressesMap(a)) + cloneMap := make([]map[wallet.BackendID]wallet.Address, len(as)) + for i, a := range as { + cloneMap[i] = wallet.CloneAddressesMap(a) } return cloneMap } @@ -304,7 +301,6 @@ func (p *Params) Clone() *Params { // Encode uses the pkg/io module to serialize a params instance. func (p *Params) Encode(w stdio.Writer) error { - return perunio.Encode(w, p.ChallengeDuration, wallet.AddressMapArray{Addr: p.Parts}, diff --git a/channel/params_test.go b/channel/params_test.go index 0c249c8e0..fdb8b295e 100644 --- a/channel/params_test.go +++ b/channel/params_test.go @@ -35,7 +35,6 @@ func TestParams_Clone(t *testing.T) { require.Equalf(t, params.App, clone.App, "Clone() = %v, want %v", clone, params) require.Equalf(t, params.ChallengeDuration, clone.ChallengeDuration, "Clone() = %v, want %v", clone, params) require.Equalf(t, params.Nonce, clone.Nonce, "Clone() = %v, want %v", clone, params) - } func TestParams_Serializer(t *testing.T) { diff --git a/channel/persistence/nonpersister.go b/channel/persistence/nonpersister.go index 2fca64124..bc4d255c0 100644 --- a/channel/persistence/nonpersister.go +++ b/channel/persistence/nonpersister.go @@ -37,6 +37,7 @@ type nonPersistRestorer struct{} func (nonPersistRestorer) ChannelCreated(context.Context, channel.Source, []map[wallet.BackendID]wire.Address, *map[wallet.BackendID]channel.ID) error { return nil } + func (nonPersistRestorer) ChannelRemoved(context.Context, map[wallet.BackendID]channel.ID) error { return nil } diff --git a/channel/persistence/test/channel.go b/channel/persistence/test/channel.go index 335c2e57a..6684f8657 100644 --- a/channel/persistence/test/channel.go +++ b/channel/persistence/test/channel.go @@ -194,7 +194,7 @@ func (c *Channel) SignAll(ctx context.Context, t require.TestingT) { for i := range c.accounts { sig, err := channel.Sign(c.accounts[i][0], c.StagingState(), 0) require.NoError(t, err) - c.AddSig(ctx, channel.Index(i), sig) //nolint:errcheck + c.AddSig(ctx, channel.Index(i), sig) //nolint:errcheck, gosec c.AssertPersisted(ctx, t) } } diff --git a/channel/persistence/test/persistrestorertest.go b/channel/persistence/test/persistrestorertest.go index 075728830..9fdb9e738 100644 --- a/channel/persistence/test/persistrestorertest.go +++ b/channel/persistence/test/persistrestorertest.go @@ -67,7 +67,7 @@ func (c *Client) NewChannel(t require.TestingT, p map[wallet.BackendID]wire.Addr c.ctx, t, c.pr, - channel.Index(idx), + channel.Index(idx), //nolint:gosec peers, parent, c.rng) diff --git a/channel/test/randomizer.go b/channel/test/randomizer.go index eed55acaa..58d4445b6 100644 --- a/channel/test/randomizer.go +++ b/channel/test/randomizer.go @@ -47,7 +47,7 @@ func SetRandomizer(r Randomizer, bID wallet.BackendID) { // NewRandomPhase generates a random channel machine phase. func NewRandomPhase(rng *rand.Rand) channel.Phase { - return channel.Phase(rng.Intn(channel.LastPhase + 1)) + return channel.Phase(rng.Intn(channel.LastPhase + 1)) //nolint:gosec } // NewRandomAsset generates a new random `channel.Asset`. @@ -137,7 +137,7 @@ func NewRandomLockedIDs(rng *rand.Rand, opts ...RandomOpt) []map[wallet.BackendI bIds, err := opt.BackendID() if err == nil && bIds != nil { ids := make([]map[wallet.BackendID]channel.ID, numLockedIds) - for i, _ := range ids { + for i := range ids { for j := range bIds { ids[i] = make(map[wallet.BackendID]channel.ID) cId := [32]byte{} @@ -149,7 +149,7 @@ func NewRandomLockedIDs(rng *rand.Rand, opts ...RandomOpt) []map[wallet.BackendI } b, err := opt.Backend() ids := make([]map[wallet.BackendID]channel.ID, numLockedIds) - for i, _ := range ids { + for i := range ids { if err != nil { ids[i] = make(map[wallet.BackendID]channel.ID) cId := [32]byte{} diff --git a/client/proposal.go b/client/proposal.go index 65ef64421..e3b1f7480 100644 --- a/client/proposal.go +++ b/client/proposal.go @@ -819,7 +819,8 @@ func (e ChannelFundingError) Error() string { return fmt.Sprintf("channel funding failed: %v", e.Err.Error()) } -func GetPeerMapWire(peers map[wallet.BackendID][]wire.Address, index int) map[wallet.BackendID]wire.Address { +// WirePeerMap returns the map at a specific index. +func WirePeerMap(peers map[wallet.BackendID][]wire.Address, index int) map[wallet.BackendID]wire.Address { address := make(map[wallet.BackendID]wire.Address) for i, p := range peers { address[i] = p[index] diff --git a/client/restore_internal_test.go b/client/restore_internal_test.go index 1b155c6fe..e9baf8fe9 100644 --- a/client/restore_internal_test.go +++ b/client/restore_internal_test.go @@ -149,7 +149,7 @@ func mkRndChanTree( } for i := 0; i < children; i++ { t := mkRndChanTree(rng, depth-1, minChildren, maxChildren-1, db, bID) - t.Parent = &map[wallet.BackendID]channel.ID{bID: *new(channel.ID)} + t.Parent = &map[wallet.BackendID]channel.ID{bID: {}} *t.Parent = root.ID() } } diff --git a/client/test/backend.go b/client/test/backend.go index 4bbd62029..200fcc4ea 100644 --- a/client/test/backend.go +++ b/client/test/backend.go @@ -42,6 +42,7 @@ type ( id multi.AssetID } + // AssetID is the unique asset identifier. AssetID struct { backendID uint32 ledgerID LedgerID @@ -188,7 +189,7 @@ func (b *MockBackend) Register(_ context.Context, req channel.AdjudicatorReq, su }, }, subChannels...) - timeout := time.Now().Add(time.Duration(req.Params.ChallengeDuration) * time.Millisecond) + timeout := time.Now().Add(time.Duration(req.Params.ChallengeDuration) * time.Millisecond) //nolint:gosec for _, ch := range channels { b.setLatestEvent( ch.Params.ID(), @@ -558,7 +559,7 @@ func (f *assetHolder) Fund(req channel.FundingReq, b *MockBackend, acc wallet.Ad // WaitForFunding waits until all participants have funded the channel. func (f *assetHolder) WaitForFunding(ctx context.Context, req channel.FundingReq) error { - challengeDuration := time.Duration(req.Params.ChallengeDuration) * time.Second + challengeDuration := time.Duration(req.Params.ChallengeDuration) * time.Second //nolint:gosec fundCtx, cancel := context.WithTimeout(ctx, challengeDuration) defer cancel() diff --git a/client/test/role.go b/client/test/role.go index 1dd945a40..68b391ce1 100644 --- a/client/test/role.go +++ b/client/test/role.go @@ -209,7 +209,7 @@ func (c *BaseExecConfig) Asset() channel.Asset { return c.asset } -// Asset returns the asset. +// Backend returns the asset. func (c *BaseExecConfig) Backend() wallet.BackendID { return c.backend } diff --git a/client/test/syncmsgs.go b/client/test/syncmsgs.go index 4d9e87063..fe452c6e3 100644 --- a/client/test/syncmsgs.go +++ b/client/test/syncmsgs.go @@ -31,7 +31,7 @@ func ChannelSyncMsgSerializationTest(t *testing.T, serializerTest func(t *testin for i := 0; i < 4; i++ { state := test.NewRandomState(rng) m := &client.ChannelSyncMsg{ - Phase: channel.Phase(rng.Intn(channel.LastPhase)), + Phase: channel.Phase(rng.Intn(channel.LastPhase)), //nolint:gosec CurrentTX: channel.Transaction{ State: state, Sigs: newRandomSigs(rng, state.NumParts()), diff --git a/client/test/updatemsgs.go b/client/test/updatemsgs.go index 931b467a5..9f0f86ab4 100644 --- a/client/test/updatemsgs.go +++ b/client/test/updatemsgs.go @@ -97,7 +97,7 @@ func channelUpdateAccSerializationTest(t *testing.T, serializerTest func(t *test sig := newRandomSig(rng, 0) m := &client.ChannelUpdateAccMsg{ ChannelID: test.NewRandomChannelID(rng), - Version: uint64(rng.Int63()), + Version: uint64(rng.Int63()), //nolint:gosec Sig: sig, } serializerTest(t, m) @@ -112,7 +112,7 @@ func channelUpdateRejSerializationTest(t *testing.T, serializerTest func(t *test for i := 0; i < 4; i++ { m := &client.ChannelUpdateRejMsg{ ChannelID: test.NewRandomChannelID(rng), - Version: uint64(rng.Int63()), + Version: uint64(rng.Int63()), //nolint:gosec Reason: newRandomASCIIString(rng, minLen, maxLenDiff), } serializerTest(t, m) diff --git a/client/virtual_channel.go b/client/virtual_channel.go index da0421330..f4f6ca50d 100644 --- a/client/virtual_channel.go +++ b/client/virtual_channel.go @@ -238,6 +238,7 @@ func (c *Channel) pushVirtualUpdate(ctx context.Context, state *channel.State, s return err } +//nolint:funlen func (c *Client) validateVirtualChannelFundingProposal( ch *Channel, prop *VirtualChannelFundingProposalMsg, diff --git a/wallet/address.go b/wallet/address.go index 2fdce065f..3931e8f04 100644 --- a/wallet/address.go +++ b/wallet/address.go @@ -49,6 +49,7 @@ type Address interface { BackendID() BackendID } +// Equal compares two BackendIDs for equality. func (a *BackendID) Equal(b BackendID) bool { return *a == b } @@ -67,7 +68,7 @@ func IndexOfAddr(addrs []map[BackendID]Address, addr Address) int { return -1 } -// IndexOfAddr returns the index of the given address in the address slice, +// IndexOfAddrs returns the index of the given address in the address slice, // or -1 if it is not part of the slice. func IndexOfAddrs(addrs []map[BackendID]Address, addr map[BackendID]Address) int { for i, as := range addrs { @@ -204,7 +205,7 @@ func (a *AddressMapArray) Decode(r stdio.Reader) (err error) { // Panics when the `Address` can't be encoded. func Key(a Address) AddrKey { var buff strings.Builder - if err := perunio.Encode(&buff, uint32(a.BackendID())); err != nil { + if err := perunio.Encode(&buff, uint32(a.BackendID())); err != nil { //nolint:gosec panic("Could not encode id in AddrKey: " + err.Error()) } if err := perunio.Encode(&buff, a); err != nil { @@ -220,10 +221,13 @@ func FromKey(k AddrKey) Address { buff := bytes.NewBuffer([]byte(k)) var id uint32 err := perunio.Decode(buff, &id) + if err != nil { + panic("Could not decode id: " + err.Error()) + } a := NewAddress(BackendID(int(id))) err = perunio.Decode(buff, a) if err != nil { - panic("Could not decode address in FromKey: " + err.Error()) + panic("Could not decode address: " + err.Error()) } return a } diff --git a/wallet/backend.go b/wallet/backend.go index 3584da165..1f272427c 100644 --- a/wallet/backend.go +++ b/wallet/backend.go @@ -44,7 +44,6 @@ type Backend interface { func SetBackend(b Backend, id int) { if backend == nil { backend = make(map[BackendID]Backend) - } if backend[BackendID(id)] != nil { panic("wallet backend already set") diff --git a/wallet/test/randomizer.go b/wallet/test/randomizer.go index 446840d8b..b952fa028 100644 --- a/wallet/test/randomizer.go +++ b/wallet/test/randomizer.go @@ -70,7 +70,7 @@ func NewRandomAddress(rng *rand.Rand, bID wallet.BackendID) wallet.Address { return randomizer[bID].NewRandomAddress(rng) } -// NewRandomAddressMap returns a new random address by calling the currently set +// NewRandomAddresses returns a new random address by calling the currently set // wallet randomizer. func NewRandomAddresses(rng *rand.Rand, bID wallet.BackendID) map[wallet.BackendID]wallet.Address { return map[wallet.BackendID]wallet.Address{bID: randomizer[bID].NewRandomAddress(rng)} @@ -126,7 +126,7 @@ func NewRandomAccountMap(rng *rand.Rand, bID wallet.BackendID) map[wallet.Backen return accs } -// NewRandomAddresses returns a slice of new random addresses. +// NewRandomAddressArray returns a slice of new random addresses. func NewRandomAddressArray(rng *rand.Rand, n int, bID wallet.BackendID) []wallet.Address { addrs := make([]wallet.Address, n) for i := range addrs { @@ -135,7 +135,7 @@ func NewRandomAddressArray(rng *rand.Rand, n int, bID wallet.BackendID) []wallet return addrs } -// NewRandomAddresses returns a slice of new random addresses. +// NewRandomAddressesMap returns a slice of new random address maps. func NewRandomAddressesMap(rng *rand.Rand, n int, bID wallet.BackendID) []map[wallet.BackendID]wallet.Address { addrs := make([]map[wallet.BackendID]wallet.Address, n) for i := range addrs { diff --git a/watcher/local/watcher_test.go b/watcher/local/watcher_test.go index dc237f333..fd3b97d9f 100644 --- a/watcher/local/watcher_test.go +++ b/watcher/local/watcher_test.go @@ -735,7 +735,7 @@ func randomTxsForSingleCh(rng *rand.Rand, n int) (*channel.Params, []channel.Tra txs := make([]channel.Transaction, n) for i := range txs { txs[i] = channel.Transaction{State: initialState.Clone()} - txs[i].State.Version = uint64(i) + txs[i].State.Version = uint64(i) //nolint:gosec } return params, txs } diff --git a/wire/account.go b/wire/account.go index 616fa230a..7579e78d4 100644 --- a/wire/account.go +++ b/wire/account.go @@ -56,7 +56,7 @@ func (m *AuthResponseMsg) Type() Type { // It writes the signature to the writer. func (m *AuthResponseMsg) Encode(w io.Writer) error { // Write the length of the signature - err := binary.Write(w, binary.BigEndian, uint32(len(m.Signature))) + err := binary.Write(w, binary.BigEndian, uint32(len(m.Signature))) //nolint:gosec if err != nil { return fmt.Errorf("failed to write signature length: %w", err) } diff --git a/wire/address.go b/wire/address.go index 87d66910c..dfe661575 100644 --- a/wire/address.go +++ b/wire/address.go @@ -139,7 +139,7 @@ func IndexOfAddr(addrs []Address, addr Address) int { return -1 } -// IndexOfAddr returns the index of the given address in the address slice, +// IndexOfAddrs returns the index of the given address in the address slice, // or -1 if it is not part of the slice. func IndexOfAddrs(addrs []map[wallet.BackendID]Address, addr map[wallet.BackendID]Address) int { for i, a := range addrs { @@ -180,15 +180,16 @@ func Key(a Address) AddrKey { // Keys returns the `AddrKey` corresponding to the passed `map[int]Address`. func Keys(addressMap map[wallet.BackendID]Address) AddrKey { - var keyParts []string - var indexes []int + indexes := make([]int, len(addressMap)) for i := range addressMap { - indexes = append(indexes, int(i)) + indexes[i] = int(i) } sort.Ints(indexes) - for _, index := range indexes { + + keyParts := make([]string, len(indexes)) + for i, index := range indexes { key := Key(addressMap[wallet.BackendID(index)]) - keyParts = append(keyParts, string(key)) // Assuming Address has a String() method. + keyParts[i] = string(key) } return AddrKey(strings.Join(keyParts, "|")) } diff --git a/wire/net/endpoint_internal_test.go b/wire/net/endpoint_internal_test.go index 063128599..72e898eee 100644 --- a/wire/net/endpoint_internal_test.go +++ b/wire/net/endpoint_internal_test.go @@ -74,9 +74,8 @@ func (s *setup) Dial(ctx context.Context, addr map[wallet.BackendID]wire.Address } else if channel.EqualWireMaps(addr, s.bob.endpoint.Address) { // Dialing Alice? s.alice.Registry.addEndpoint(s.alice.endpoint.Address, a, true) // Alice accepts connection. return b, nil - } else { - return nil, errors.New("unknown peer") } + return nil, errors.New("unknown peer") } func (s *setup) Close() error { diff --git a/wire/net/simple/address.go b/wire/net/simple/address.go index 4ed79569f..ad7bb67e7 100644 --- a/wire/net/simple/address.go +++ b/wire/net/simple/address.go @@ -204,7 +204,7 @@ func NewRandomAddress(rng *rand.Rand) *Address { return a } -// NewRandomAddress returns a new random peer address. +// NewRandomAddresses returns a new random peer address. func NewRandomAddresses(rng *rand.Rand) map[wallet.BackendID]wire.Address { const addrLen = 32 l := rng.Intn(addrLen) diff --git a/wire/net/simple/listener_internal_test.go b/wire/net/simple/listener_internal_test.go index b5cc7258b..3151bf0e0 100644 --- a/wire/net/simple/listener_internal_test.go +++ b/wire/net/simple/listener_internal_test.go @@ -31,6 +31,8 @@ const addr = "0.0.0.0:1337" // serverKey and serverCert are generated with the following commands: // openssl ecparam -genkey -name prime256v1 -out server.key // openssl req -new -x509 -key server.key -out server.pem -days 3650. +// +//nolint:gosec const testServerKey = `-----BEGIN EC PARAMETERS----- BggqhkjOPQMBBw== -----END EC PARAMETERS----- @@ -41,6 +43,7 @@ cSqrxhPubawptX5MSr02ft32kfOlYbaF5Q== -----END EC PRIVATE KEY----- ` +//nolint:gosec const testServerCert = `-----BEGIN CERTIFICATE----- MIIB+TCCAZ+gAwIBAgIJAL05LKXo6PrrMAoGCCqGSM49BAMCMFkxCzAJBgNVBAYT AkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRn diff --git a/wire/perunio/serializer/serializer.go b/wire/perunio/serializer/serializer.go index fa8849620..3665e84a7 100644 --- a/wire/perunio/serializer/serializer.go +++ b/wire/perunio/serializer/serializer.go @@ -15,7 +15,6 @@ package serializer import ( - "encoding/binary" "io" "github.com/pkg/errors" @@ -60,26 +59,3 @@ func (serializer) Decode(r io.Reader) (env *wire.Envelope, err error) { return env, nil } - -// decodeAddressMap decodes a map[int]Address from the reader. -func decodeAddressMap(r io.Reader) (map[int]wire.Address, error) { - var numEntries int32 - if err := binary.Read(r, binary.BigEndian, &numEntries); err != nil { - return nil, errors.New("could not decode map length: " + err.Error()) - } - - addrMap := make(map[int]wire.Address, numEntries) - for i := 0; i < int(numEntries); i++ { - var idx int32 - if err := binary.Read(r, binary.BigEndian, &idx); err != nil { - return nil, errors.New("could not decode map index: " + err.Error()) - } - addrs := wire.NewAddress() - if err := perunio.Decode(r, addrs); err != nil { - return nil, errors.WithMessagef(err, "decoding %d-th address map entry", i) - } - addrMap[int(idx)] = addrs - } - - return addrMap, nil -} diff --git a/wire/protobuf/proposalmsgs.go b/wire/protobuf/proposalmsgs.go index 0f756629e..bc1298f89 100644 --- a/wire/protobuf/proposalmsgs.go +++ b/wire/protobuf/proposalmsgs.go @@ -52,6 +52,9 @@ func ToSubChannelProposalMsg(protoEnvMsg *Envelope_SubChannelProposalMsg) (msg * msg = &client.SubChannelProposalMsg{} msg.Parent, err = ToIDs(protoMsg.Parent) + if err != nil { + return nil, errors.WithMessage(err, "parent") + } msg.BaseChannelProposal, err = ToBaseChannelProposal(protoMsg.BaseChannelProposal) return msg, err } @@ -346,7 +349,7 @@ func ToIndexMap(protoIndexMap []uint32) (indexMap []channel.Index, err error) { if protoIndexMap[i] > math.MaxUint16 { return nil, fmt.Errorf("%d'th index is invalid", i) //nolint:goerr113 // We do not want to define this as constant error. } - indexMap[i] = channel.Index(uint16(protoIndexMap[i])) + indexMap[i] = channel.Index(uint16(protoIndexMap[i])) //nolint:gosec } return indexMap, nil } diff --git a/wire/protobuf/syncmsgs.go b/wire/protobuf/syncmsgs.go index fb94a5b19..1b8ff3516 100644 --- a/wire/protobuf/syncmsgs.go +++ b/wire/protobuf/syncmsgs.go @@ -23,7 +23,7 @@ func toChannelSyncMsg(protoEnvMsg *Envelope_ChannelSyncMsg) (msg *client.Channel protoMsg := protoEnvMsg.ChannelSyncMsg msg = &client.ChannelSyncMsg{} - msg.Phase = channel.Phase(protoMsg.Phase) + msg.Phase = channel.Phase(protoMsg.Phase) //nolint:gosec msg.CurrentTX.Sigs = make([][]byte, len(protoMsg.CurrentTx.Sigs)) for i := range protoMsg.CurrentTx.Sigs { msg.CurrentTX.Sigs[i] = make([]byte, len(protoMsg.CurrentTx.Sigs[i])) diff --git a/wire/protobuf/updatemsgs.go b/wire/protobuf/updatemsgs.go index a14887a4c..e6974ed6b 100644 --- a/wire/protobuf/updatemsgs.go +++ b/wire/protobuf/updatemsgs.go @@ -95,7 +95,7 @@ func ToChannelUpdate(protoUpdate *ChannelUpdateMsg) (update client.ChannelUpdate if protoUpdate.ChannelUpdate.ActorIdx > math.MaxUint16 { return update, errors.New("actor index is invalid") } - update.ActorIdx = channel.Index(protoUpdate.ChannelUpdate.ActorIdx) + update.ActorIdx = channel.Index(protoUpdate.ChannelUpdate.ActorIdx) //nolint:gosec update.Sig = make([]byte, len(protoUpdate.Sig)) copy(update.Sig, protoUpdate.Sig) update.State, err = ToState(protoUpdate.ChannelUpdate.State) From 19a792f92615aea2835ee1045e7784cd7aac98ad Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Thu, 19 Dec 2024 12:03:51 +0100 Subject: [PATCH 18/36] fix(ci): Use go1.18 for the any type in proto fix(golangci): Fix structure Signed-off-by: Sophia Koehler --- .github/workflows/ci.yml | 2 +- .golangci.yml | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e62105574..cccdaf43c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ on: release: env: - go-version: 1.17 + go-version: 1.18 jobs: check-copyright: diff --git a/.golangci.yml b/.golangci.yml index 192e7bf13..668e8353e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -48,15 +48,14 @@ linters-settings: template-path: ".scripts/copyright-notice" forbidigo: forbid: - - exclude-rules: - - path: ".*\\.pb\\.go$" # Exclude protobuf generated files. # Forbid functions to start with "get" or "Get". - ^[Gg]et.*$ - ^[Ee]quals$ # Default values: - ^print.*$ - 'fmt\.Print.*' - + exclude-rules: + - path: ".*\\.pb\\.go$" # Exclude protobuf generated files. issues: # Re-enable default excludes. include: From fd8bf8a09de5f40cb252289e40ed9f1c284f77f1 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Thu, 19 Dec 2024 12:18:03 +0100 Subject: [PATCH 19/36] fix(ci): Use glinter 1.45 which supports go1.18 Signed-off-by: Sophia Koehler --- .github/workflows/ci.yml | 2 +- channel/persistence/keyvalue/persistrestorer_internal_test.go | 4 ++-- wire/encode_test.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cccdaf43c..483c054a6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,7 +39,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: - version: v1.43 + version: v1.45 - name: Lint proto files uses: plexsystems/protolint-action@v0.6.0 diff --git a/channel/persistence/keyvalue/persistrestorer_internal_test.go b/channel/persistence/keyvalue/persistrestorer_internal_test.go index bafd808c0..3fcf9c878 100644 --- a/channel/persistence/keyvalue/persistrestorer_internal_test.go +++ b/channel/persistence/keyvalue/persistrestorer_internal_test.go @@ -16,7 +16,7 @@ package keyvalue import ( "context" - "io/ioutil" + "os" "testing" "github.com/stretchr/testify/assert" @@ -31,7 +31,7 @@ import ( ) func TestPersistRestorer_Generic(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "perun-test-kvpersistrestorer-db-*") + tmpdir, err := os.MkdirTemp("", "perun-test-kvpersistrestorer-db-*") require.NoError(t, err) lvldb, err := leveldb.LoadDatabase(tmpdir) require.NoError(t, err) diff --git a/wire/encode_test.go b/wire/encode_test.go index fc586c617..efd32e60d 100644 --- a/wire/encode_test.go +++ b/wire/encode_test.go @@ -25,7 +25,7 @@ import ( "polycry.pt/poly-go/test" ) -var nilDecoder = func(io.Reader) (wire.Msg, error) { return nil, nil } +var nilDecoder = func(io.Reader) (wire.Msg, error) { return nil, nil } //nolint:nilnil func TestType_Valid_String(t *testing.T) { test.OnlyOnce(t) From 98b900bb6c990a946720443a77c93aaedf456148 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Thu, 19 Dec 2024 13:03:35 +0100 Subject: [PATCH 20/36] chore(all): Add nolint flags for conversions Signed-off-by: Sophia Koehler --- apps/payment/app_internal_test.go | 4 +-- backend/sim/channel/asset.go | 2 +- channel/allocation.go | 8 ++--- channel/machine.go | 4 +-- channel/multi/funder.go | 2 +- channel/params.go | 6 ++-- channel/persistence/statemachine_test.go | 4 +-- channel/test/randomizer.go | 6 ++-- client/channelconn.go | 4 +-- client/restore_internal_test.go | 2 +- client/serialize.go | 6 ++-- client/sync.go | 8 +++-- client/test/backend.go | 2 +- client/test/mallory.go | 2 +- client/test/updatemsgs.go | 2 +- client/virtual_channel.go | 4 +-- client/virtual_channel_settlement.go | 2 +- wallet/address.go | 6 ++-- wire/address.go | 8 ++--- wire/net/exchange_addr.go | 12 ++++--- wire/net/simple/address.go | 6 ++-- wire/net/simple/listener_internal_test.go | 1 - wire/perunio/string.go | 2 +- wire/protobuf/proposalmsgs.go | 42 +++++++++++++++-------- wire/protobuf/serializer.go | 2 +- wire/protobuf/updatemsgs.go | 3 ++ 26 files changed, 85 insertions(+), 65 deletions(-) diff --git a/apps/payment/app_internal_test.go b/apps/payment/app_internal_test.go index 01eb8f477..710ddc08f 100644 --- a/apps/payment/app_internal_test.go +++ b/apps/payment/app_internal_test.go @@ -95,7 +95,7 @@ func TestApp_ValidTransition(t *testing.T) { numParticipants := len(tt.from[0]) for i := 0; i < numParticipants; i++ { // valid self-transition - assert.NoError(app.ValidTransition(nil, from, from, channel.Index(i))) + assert.NoError(app.ValidTransition(nil, from, from, channel.Index(i))) //nolint:gosec } for _, tto := range tt.tos { @@ -105,7 +105,7 @@ func TestApp_ValidTransition(t *testing.T) { test.WithBalances(asBalances(tto.alloc...)...), ) for i := 0; i < numParticipants; i++ { - err := app.ValidTransition(nil, from, to, channel.Index(i)) + err := app.ValidTransition(nil, from, to, channel.Index(i)) //nolint:gosec if i == tto.valid { assert.NoError(err) } else { diff --git a/backend/sim/channel/asset.go b/backend/sim/channel/asset.go index 69f7c61d5..0dd1d495a 100644 --- a/backend/sim/channel/asset.go +++ b/backend/sim/channel/asset.go @@ -53,7 +53,7 @@ func (a *Asset) UnmarshalBinary(data []byte) error { if len(data) != assetLen { return fmt.Errorf("unexpected length %d, want %d", len(data), assetLen) //nolint:goerr113 // We do not want to define this as constant error. } - a.ID = int64(byteOrder.Uint64(data)) + a.ID = int64(byteOrder.Uint64(data)) //nolint:gosec return nil } diff --git a/channel/allocation.go b/channel/allocation.go index 7f9e25395..72a31ba76 100644 --- a/channel/allocation.go +++ b/channel/allocation.go @@ -325,7 +325,7 @@ func (a Allocation) Encode(w io.Writer) error { err, "invalid allocations cannot be encoded, got %v", a) } // encode dimensions - if err := perunio.Encode(w, Index(len(a.Assets)), Index(len(a.Balances[0])), Index(len(a.Locked))); err != nil { + if err := perunio.Encode(w, Index(len(a.Assets)), Index(len(a.Balances[0])), Index(len(a.Locked))); err != nil { //nolint:gosec return err } // encode assets @@ -436,7 +436,7 @@ func (b Balances) Encode(w io.Writer) error { return errors.Errorf("expected maximum number of parts %d, got %d", MaxNumParts, numParts) } - if err := perunio.Encode(w, Index(numAssets), Index(numParts)); err != nil { + if err := perunio.Encode(w, Index(numAssets), Index(numParts)); err != nil { //nolint:gosec return errors.WithMessage(err, "encoding dimensions") } for i := range b { @@ -667,7 +667,7 @@ func (s SubAlloc) Encode(w io.Writer) error { err, "invalid sub-allocations cannot be encoded, got %v", s) } // encode ID and dimension - if err := perunio.Encode(w, IDMap(s.ID), Index(len(s.Bals))); err != nil { + if err := perunio.Encode(w, IDMap(s.ID), Index(len(s.Bals))); err != nil { //nolint:gosec return errors.WithMessagef( err, "encoding sub-allocation ID or dimension, id %v", s.ID) } @@ -679,7 +679,7 @@ func (s SubAlloc) Encode(w io.Writer) error { } } // Encode IndexMap. - if err := perunio.Encode(w, Index(len(s.IndexMap))); err != nil { + if err := perunio.Encode(w, Index(len(s.IndexMap))); err != nil { //nolint:gosec return errors.WithMessage(err, "encoding length of index map") } for i, x := range s.IndexMap { diff --git a/channel/machine.go b/channel/machine.go index 78e742dff..6198b34e9 100644 --- a/channel/machine.go +++ b/channel/machine.go @@ -151,7 +151,7 @@ func newMachine(acc map[wallet.BackendID]wallet.Account, params Params) (*machin return &machine{ phase: InitActing, acc: acc, - idx: Index(idx), + idx: Index(idx), //nolint:gosec params: params, Embedding: log.MakeEmbedding(log.WithField("ID", params.id)), }, nil @@ -190,7 +190,7 @@ func (m *machine) Params() *Params { // N returns the number of participants of the channel parameters of this machine. func (m *machine) N() Index { - return Index(len(m.params.Parts)) + return Index(len(m.params.Parts)) //nolint:gosec } // Phase returns the current phase. diff --git a/channel/multi/funder.go b/channel/multi/funder.go index f7f86e361..e42607633 100644 --- a/channel/multi/funder.go +++ b/channel/multi/funder.go @@ -62,7 +62,7 @@ func (f *Funder) SetEgoisticChain(l AssetID, id int, egoistic bool) { // channel. If any of the funder calls fails, the method returns an error. func (f *Funder) Fund(ctx context.Context, request channel.FundingReq) error { // Define funding timeout. - d := time.Duration(request.Params.ChallengeDuration) * time.Second + d := time.Duration(request.Params.ChallengeDuration) * time.Second //nolint:gosec ctx, cancel := context.WithTimeout(ctx, d) defer cancel() diff --git a/channel/params.go b/channel/params.go index fff97d7b4..d8151ae71 100644 --- a/channel/params.go +++ b/channel/params.go @@ -112,14 +112,14 @@ func (ids *IDMap) Decode(r stdio.Reader) error { func IDKey(ids IDMap) string { var buff strings.Builder - length := int32(len(ids)) //nolint:gosec - err := binary.Write(&buff, binary.BigEndian, length) //nolint:gosec + length := int32(len(ids)) //nolint:gosec + err := binary.Write(&buff, binary.BigEndian, length) if err != nil { log.Panic("could not encode map length in Key: ", err) } sortedKeys, sortedIDs := sortIDMap(ids) for i, id := range sortedIDs { - if err := binary.Write(&buff, binary.BigEndian, int32(sortedKeys[i])); err != nil { + if err := binary.Write(&buff, binary.BigEndian, int32(sortedKeys[i])); err != nil { //nolint:gosec log.Panicf("could not encode map key: " + err.Error()) } if err := perunio.Encode(&buff, id); err != nil { diff --git a/channel/persistence/statemachine_test.go b/channel/persistence/statemachine_test.go index daf9d3d44..c2dae4f68 100644 --- a/channel/persistence/statemachine_test.go +++ b/channel/persistence/statemachine_test.go @@ -76,7 +76,7 @@ func TestStateMachine(t *testing.T) { sig, err = channel.Sign(acc, csm.StagingState(), b) require.NoError(err) } - err = sm.AddSig(ctx, channel.Index(i), sig) + err = sm.AddSig(ctx, channel.Index(i), sig) //nolint:gosec require.NoError(err) tpr.AssertEqual(csm) } @@ -152,7 +152,7 @@ func TestStateMachine(t *testing.T) { // Set Progressed timeout := ctest.NewRandomTimeout(rng) - idx := channel.Index(rng.Intn(s.NumParts())) + idx := channel.Index(rng.Intn(s.NumParts())) //nolint:gosec e := channel.NewProgressedEvent(s.ID[0], timeout, s, idx) err = sm.SetProgressed(ctx, e) require.NoError(err) diff --git a/channel/test/randomizer.go b/channel/test/randomizer.go index 58d4445b6..f80e5bbce 100644 --- a/channel/test/randomizer.go +++ b/channel/test/randomizer.go @@ -269,7 +269,7 @@ func NewRandomChannelID(rng *rand.Rand, opts ...RandomOpt) (id map[wallet.Backen for _, b := range bIds { cId := [32]byte{} rng.Read(cId[:]) - id[wallet.BackendID(b)] = cId + id[b] = cId } return } @@ -281,7 +281,7 @@ func NewRandomChannelID(rng *rand.Rand, opts ...RandomOpt) (id map[wallet.Backen } else { cId := [32]byte{} rng.Read(cId[:]) - id[wallet.BackendID(bId)] = cId + id[bId] = cId } return } @@ -299,7 +299,7 @@ func NewRandomChannelIDs(rng *rand.Rand, n int) (ids []map[wallet.BackendID]chan func NewRandomIndexMap(rng *rand.Rand, numParts int, numPartsParent int) (m []channel.Index) { m = make([]channel.Index, numParts) for i := range m { - m[i] = channel.Index(rng.Intn(numPartsParent)) + m[i] = channel.Index(rng.Intn(numPartsParent)) //nolint:gosec } return } diff --git a/client/channelconn.go b/client/channelconn.go index c10446984..bd31a66b6 100644 --- a/client/channelconn.go +++ b/client/channelconn.go @@ -104,7 +104,7 @@ func (c *channelConn) Close() error { func (c *channelConn) Send(ctx context.Context, msg wire.Msg) error { var eg errgroup.Group for i, peer := range c.peers { - if channel.Index(i) == c.idx { + if channel.Index(i) == c.idx { //nolint:gosec continue // skip own peer } c.log.WithField("peer", peer).Debugf("channelConn: publishing message: %v: %+v", msg.Type(), msg) @@ -168,5 +168,5 @@ func (r *channelMsgRecv) Next(ctx context.Context) (channel.Index, ChannelMsg, e if !ok { return 0, nil, errors.Errorf("unexpected message type: expected ChannelMsg, got %T", env.Msg) } - return channel.Index(idx), msg, nil // predicate must guarantee that the conversion is safe + return channel.Index(idx), msg, nil //nolint:gosec } diff --git a/client/restore_internal_test.go b/client/restore_internal_test.go index e9baf8fe9..5bfb7d2bb 100644 --- a/client/restore_internal_test.go +++ b/client/restore_internal_test.go @@ -120,7 +120,7 @@ func mkRndChan(rng *rand.Rand, bID wallet.BackendID) *persistence.Channel { parts[i] = map[wallet.BackendID]wallet.Address{bID: wallettest.NewRandomAccount(rng, bID).Address()} } ch := persistence.NewChannel() - ch.IdxV = channel.Index(rng.Intn(channel.MaxNumParts)) + ch.IdxV = channel.Index(rng.Intn(channel.MaxNumParts)) //nolint:gosec ch.ParamsV = test.NewRandomParams(rng, test.WithParts(parts)) sigs := make([]bool, channel.MaxNumParts) opts := test.WithParams(ch.ParamsV) diff --git a/client/serialize.go b/client/serialize.go index 95e4d903c..382fefae9 100644 --- a/client/serialize.go +++ b/client/serialize.go @@ -33,7 +33,7 @@ type ( // Encode encodes the object to the writer. func (a channelIDsWithLen) Encode(w io.Writer) (err error) { - length := int32(len(a)) + length := int32(len(a)) //nolint:gosec if err := perunio.Encode(w, length); err != nil { return errors.WithMessage(err, "encoding array length") } @@ -62,7 +62,7 @@ func (a *channelIDsWithLen) Decode(r io.Reader) (err error) { // Encode encodes the object to the writer. func (a indexMapsWithLen) Encode(w io.Writer) (err error) { - err = perunio.Encode(w, sliceLen(len(a))) + err = perunio.Encode(w, sliceLen(len(a))) //nolint:gosec if err != nil { return } @@ -94,7 +94,7 @@ func (a *indexMapsWithLen) Decode(r io.Reader) (err error) { // Encode encodes the object to the writer. func (a indexMapWithLen) Encode(w io.Writer) (err error) { - err = perunio.Encode(w, sliceLen(len(a))) + err = perunio.Encode(w, sliceLen(len(a))) //nolint:gosec if err != nil { return } diff --git a/client/sync.go b/client/sync.go index e137e6eea..a6c2d1dfa 100644 --- a/client/sync.go +++ b/client/sync.go @@ -69,7 +69,8 @@ func (c *Client) handleSyncMsg(peer map[wallet.BackendID]wire.Address, msg *Chan // syncChannel synchronizes the channel state with the given peer and modifies // the current state if required. -// nolint:unused +// +//nolint:unused func (c *Client) syncChannel(ctx context.Context, ch *persistence.Channel, p map[wallet.BackendID]wire.Address) (err error) { recv := wire.NewReceiver() defer recv.Close() // ignore error @@ -119,7 +120,8 @@ func (c *Client) syncChannel(ctx context.Context, ch *persistence.Channel, p map } // validateMessage validates the remote channel sync message. -// nolint:unused, nestif +// +//nolint:unused, nestif func validateMessage(ch *persistence.Channel, msg *ChannelSyncMsg) error { v := ch.CurrentTX().Version mv := msg.CurrentTX.Version @@ -151,7 +153,7 @@ func validateMessage(ch *persistence.Channel, msg *ChannelSyncMsg) error { return nil } -// nolint:unused +//nolint:unused func revisePhase(ch *persistence.Channel) error { //nolint:gocritic if ch.PhaseV <= channel.Funding && ch.CurrentTXV.Version == 0 { diff --git a/client/test/backend.go b/client/test/backend.go index 200fcc4ea..80f9de7f6 100644 --- a/client/test/backend.go +++ b/client/test/backend.go @@ -228,7 +228,7 @@ func (b *MockBackend) Progress(_ context.Context, req channel.ProgressReq) error b.mu.Lock() defer b.mu.Unlock() - timeout := time.Now().Add(time.Duration(req.Params.ChallengeDuration) * time.Millisecond) + timeout := time.Now().Add(time.Duration(req.Params.ChallengeDuration) * time.Millisecond) //nolint:gosec b.setLatestEvent( req.Params.ID(), channel.NewProgressedEvent( diff --git a/client/test/mallory.go b/client/test/mallory.go index ef30ec27d..36aa38444 100644 --- a/client/test/mallory.go +++ b/client/test/mallory.go @@ -66,7 +66,7 @@ func (r *Mallory) exec(_cfg ExecConfig, ch *paymentChannel) { r.waitStage() // Register version 0 AdjudicatorReq - challengeDuration := time.Duration(ch.Channel.Params().ChallengeDuration) * time.Second + challengeDuration := time.Duration(ch.Channel.Params().ChallengeDuration) * time.Second //nolint:gosec regCtx, regCancel := context.WithTimeout(context.Background(), r.timeout) defer regCancel() r.log.Debug("Registering version 0 state.") diff --git a/client/test/updatemsgs.go b/client/test/updatemsgs.go index 9f0f86ab4..159da7ed4 100644 --- a/client/test/updatemsgs.go +++ b/client/test/updatemsgs.go @@ -125,7 +125,7 @@ func newRandomMsgChannelUpdate(rng *rand.Rand) *client.ChannelUpdateMsg { return &client.ChannelUpdateMsg{ ChannelUpdate: client.ChannelUpdate{ State: state, - ActorIdx: channel.Index(rng.Intn(state.NumParts())), + ActorIdx: channel.Index(rng.Intn(state.NumParts())), //nolint:gosec }, Sig: sig, } diff --git a/client/virtual_channel.go b/client/virtual_channel.go index f4f6ca50d..22be5be18 100644 --- a/client/virtual_channel.go +++ b/client/virtual_channel.go @@ -185,7 +185,7 @@ func (c *Client) persistVirtualChannel(ctx context.Context, parent *Channel, pee } for i, sig := range sigs { - err = ch.machine.AddSig(ctx, channel.Index(i), sig) + err = ch.machine.AddSig(ctx, channel.Index(i), sig) //nolint:gosec if err != nil { return nil, err } @@ -223,7 +223,7 @@ func (c *Channel) pushVirtualUpdate(ctx context.Context, state *channel.State, s } for i, sig := range sigs { - idx := channel.Index(i) + idx := channel.Index(i) //nolint:gosec if err := m.AddSig(ctx, idx, sig); err != nil { return err } diff --git a/client/virtual_channel_settlement.go b/client/virtual_channel_settlement.go index 3100b2d12..49d822d68 100644 --- a/client/virtual_channel_settlement.go +++ b/client/virtual_channel_settlement.go @@ -214,7 +214,7 @@ func (c *Channel) forceFinalState(ctx context.Context, final channel.SignedState return err } for i, sig := range final.Sigs { - if err := c.machine.AddSig(ctx, channel.Index(i), sig); err != nil { + if err := c.machine.AddSig(ctx, channel.Index(i), sig); err != nil { //nolint:gosec return err } } diff --git a/wallet/address.go b/wallet/address.go index 3931e8f04..b46909a77 100644 --- a/wallet/address.go +++ b/wallet/address.go @@ -134,12 +134,12 @@ type AddrKey string // Encode encodes first the length of the map, // then all Addresses and their key in the map. func (a AddressDecMap) Encode(w stdio.Writer) error { - length := int32(len(a)) + length := int32(len(a)) //nolint:gosec if err := perunio.Encode(w, length); err != nil { return errors.WithMessage(err, "encoding map length") } for i, addr := range a { - if err := perunio.Encode(w, int32(i)); err != nil { + if err := perunio.Encode(w, int32(i)); err != nil { //nolint:gosec return errors.WithMessage(err, "encoding map index") } if err := perunio.Encode(w, addr); err != nil { @@ -152,7 +152,7 @@ func (a AddressDecMap) Encode(w stdio.Writer) error { // Encode encodes first the length of the array, // then all AddressDecMaps in the array. func (a AddressMapArray) Encode(w stdio.Writer) error { - length := int32(len(a.Addr)) + length := int32(len(a.Addr)) //nolint:gosec if err := perunio.Encode(w, length); err != nil { return errors.WithMessage(err, "encoding array length") } diff --git a/wire/address.go b/wire/address.go index dfe661575..93b7a0353 100644 --- a/wire/address.go +++ b/wire/address.go @@ -58,12 +58,12 @@ type AddressDecMap map[wallet.BackendID]Address // Encode encodes first the length of the map, // then all Addresses and their key in the map. func (a AddressDecMap) Encode(w stdio.Writer) error { - length := int32(len(a)) // Using int32 to encode the length + length := int32(len(a)) //nolint:gosec if err := perunio.Encode(w, length); err != nil { return errors.WithMessage(err, "encoding map length") } for i, addr := range a { - if err := perunio.Encode(w, int32(i)); err != nil { + if err := perunio.Encode(w, int32(i)); err != nil { //nolint:gosec return errors.WithMessage(err, "encoding map index") } if err := perunio.Encode(w, addr); err != nil { @@ -76,7 +76,7 @@ func (a AddressDecMap) Encode(w stdio.Writer) error { // Encode encodes first the length of the array, // then all AddressDecMaps in the array. func (a AddressMapArray) Encode(w stdio.Writer) error { - length := int32(len(a)) // Using int32 to encode the length + length := int32(len(a)) //nolint:gosec if err := perunio.Encode(w, length); err != nil { return errors.WithMessage(err, "encoding array length") } @@ -127,8 +127,6 @@ func (a *AddressMapArray) Decode(r stdio.Reader) (err error) { // IndexOfAddr returns the index of the given address in the address slice, // or -1 if it is not part of the slice. -// -//nolint:unused func IndexOfAddr(addrs []Address, addr Address) int { for i, a := range addrs { if addr.Equal(a) { diff --git a/wire/net/exchange_addr.go b/wire/net/exchange_addr.go index 066ae4ed4..ca32bbca6 100644 --- a/wire/net/exchange_addr.go +++ b/wire/net/exchange_addr.go @@ -82,8 +82,10 @@ func ExchangeAddrsActive(ctx context.Context, id map[wallet.BackendID]wire.Accou err = errors.WithMessage(err, "receiving message") } else if _, ok := e.Msg.(*wire.AuthResponseMsg); !ok { err = errors.Errorf("expected AuthResponse wire msg, got %v", e.Msg.Type()) - } else if check := VerifyAddressSignature(peer, e.Msg.(*wire.AuthResponseMsg).Signature); check != nil { - err = errors.WithMessage(err, "verifying peer address's signature") + } else if msg, ok := e.Msg.(*wire.AuthResponseMsg); ok { + if check := VerifyAddressSignature(peer, msg.Signature); check != nil { + err = errors.WithMessage(check, "verifying peer address's signature") + } } else if !test.EqualWireMaps(e.Recipient, wire.AddressMapfromAccountMap(id)) && !test.EqualWireMaps(e.Sender, peer) { err = NewAuthenticationError(e.Sender, e.Recipient, wire.AddressMapfromAccountMap(id), "unmatched response sender or recipient") @@ -112,8 +114,10 @@ func ExchangeAddrsPassive(ctx context.Context, id map[wallet.BackendID]wire.Acco err = errors.Errorf("expected AuthResponse wire msg, got %v", e.Msg.Type()) } else if !test.EqualWireMaps(e.Recipient, addrs) { err = NewAuthenticationError(e.Sender, e.Recipient, wire.AddressMapfromAccountMap(id), "unmatched response sender or recipient") - } else if err = VerifyAddressSignature(e.Sender, e.Msg.(*wire.AuthResponseMsg).Signature); err != nil { - err = errors.WithMessage(err, "verifying peer address's signature") + } else if msg, ok := e.Msg.(*wire.AuthResponseMsg); ok { + if err = VerifyAddressSignature(e.Sender, msg.Signature); err != nil { + err = errors.WithMessage(err, "verifying peer address's signature") + } } if err != nil { diff --git a/wire/net/simple/address.go b/wire/net/simple/address.go index ad7bb67e7..5a177252a 100644 --- a/wire/net/simple/address.go +++ b/wire/net/simple/address.go @@ -47,7 +47,7 @@ func (a *Address) MarshalBinary() ([]byte, error) { var buf bytes.Buffer // Encode the length of the name string and the name itself - nameLen := uint16(len(a.Name)) + nameLen := uint16(len(a.Name)) //nolint:gosec if err := binary.Write(&buf, binary.BigEndian, nameLen); err != nil { return nil, err } @@ -110,7 +110,7 @@ func (a *Address) Backend() wallet.BackendID { func encodePublicKey(buf *bytes.Buffer, key *rsa.PublicKey) error { // Encode modulus length and modulus modulusBytes := key.N.Bytes() - modulusLen := uint16(len(modulusBytes)) + modulusLen := uint16(len(modulusBytes)) //nolint:gosec if err := binary.Write(buf, binary.BigEndian, modulusLen); err != nil { return err } @@ -119,7 +119,7 @@ func encodePublicKey(buf *bytes.Buffer, key *rsa.PublicKey) error { } // Encode public exponent - if err := binary.Write(buf, binary.BigEndian, int32(key.E)); err != nil { + if err := binary.Write(buf, binary.BigEndian, int32(key.E)); err != nil { //nolint:gosec return err } diff --git a/wire/net/simple/listener_internal_test.go b/wire/net/simple/listener_internal_test.go index 3151bf0e0..dfb013cf5 100644 --- a/wire/net/simple/listener_internal_test.go +++ b/wire/net/simple/listener_internal_test.go @@ -43,7 +43,6 @@ cSqrxhPubawptX5MSr02ft32kfOlYbaF5Q== -----END EC PRIVATE KEY----- ` -//nolint:gosec const testServerCert = `-----BEGIN CERTIFICATE----- MIIB+TCCAZ+gAwIBAgIJAL05LKXo6PrrMAoGCCqGSM49BAMCMFkxCzAJBgNVBAYT AkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRn diff --git a/wire/perunio/string.go b/wire/perunio/string.go index 292c0a837..88a16d9c1 100644 --- a/wire/perunio/string.go +++ b/wire/perunio/string.go @@ -23,7 +23,7 @@ import ( // encodeString writes the length as an uint16 and then the string itself to the io.Writer. func encodeString(w io.Writer, s string) error { - l := uint16(len(s)) + l := uint16(len(s)) //nolint:gosec if int(l) != len(s) { return errors.Errorf("string length exceeded: %d", len(s)) } diff --git a/wire/protobuf/proposalmsgs.go b/wire/protobuf/proposalmsgs.go index bc1298f89..1ddfe9c03 100644 --- a/wire/protobuf/proposalmsgs.go +++ b/wire/protobuf/proposalmsgs.go @@ -76,6 +76,9 @@ func ToVirtualChannelProposalMsg(protoEnvMsg *Envelope_VirtualChannelProposalMsg msg.Parents = make([]map[wallet.BackendID]channel.ID, len(protoMsg.Parents)) for i := range protoMsg.Parents { msg.Parents[i], err = ToIDs(protoMsg.Parents[i]) + if err != nil { + return nil, err + } } msg.IndexMaps = make([][]channel.Index, len(protoMsg.IndexMaps)) for i := range protoMsg.IndexMaps { @@ -200,7 +203,7 @@ func ToIDs(protoID *ID) (map[wallet.BackendID]channel.ID, error) { if err := binary.Read(bytes.NewReader(protoID.IdMapping[i].Key), binary.BigEndian, &k); err != nil { return nil, fmt.Errorf("failed to read key: %w", err) } - if len(protoID.IdMapping[i].Id) != 32 { + if len(protoID.IdMapping[i].Id) != 32 { //nolint:gomnd return nil, fmt.Errorf("id has incorrect length") } id := channel.ID{} @@ -272,7 +275,7 @@ func ToIntSlice(backends [][]byte) ([]wallet.BackendID, error) { ints := make([]wallet.BackendID, len(backends)) for i, backend := range backends { - if len(backend) != 4 { + if len(backend) != 4 { //nolint:gomnd return nil, fmt.Errorf("backend %d length is not 4 bytes", i) } @@ -337,7 +340,9 @@ func ToSubAlloc(protoSubAlloc *SubAlloc) (subAlloc channel.SubAlloc, err error) subAlloc = channel.SubAlloc{} subAlloc.Bals = ToBalance(protoSubAlloc.Bals) subAlloc.ID, err = ToIDs(protoSubAlloc.Id) - + if err != nil { + return subAlloc, err + } subAlloc.IndexMap, err = ToIndexMap(protoSubAlloc.IndexMap.IndexMap) return subAlloc, err } @@ -374,6 +379,9 @@ func FromLedgerChannelProposalMsg(msg *client.LedgerChannelProposalMsg) (_ *Enve func FromSubChannelProposalMsg(msg *client.SubChannelProposalMsg) (_ *Envelope_SubChannelProposalMsg, err error) { protoMsg := &SubChannelProposalMsg{} protoMsg.Parent, err = FromIDs(msg.Parent) + if err != nil { + return nil, err + } protoMsg.BaseChannelProposal, err = FromBaseChannelProposal(msg.BaseChannelProposal) return &Envelope_SubChannelProposalMsg{protoMsg}, err } @@ -393,6 +401,9 @@ func FromVirtualChannelProposalMsg(msg *client.VirtualChannelProposalMsg) (_ *En protoMsg.Parents = make([]*ID, len(msg.Parents)) for i := range msg.Parents { protoMsg.Parents[i], err = FromIDs(msg.Parents[i]) + if err != nil { + return nil, errors.WithMessage(err, "fromIDs") + } } protoMsg.IndexMaps = make([]*IndexMap, len(msg.IndexMaps)) for i := range msg.IndexMaps { @@ -439,11 +450,11 @@ func FromChannelProposalRejMsg(msg *client.ChannelProposalRejMsg) (_ *Envelope_C // FromWalletAddr converts a wallet.Address to a protobuf wallet address. func FromWalletAddr(addr map[wallet.BackendID]wallet.Address) (*Address, error) { - var addressMappings []*AddressMapping + var addressMappings []*AddressMapping //nolint:prealloc for key, address := range addr { - keyBytes := make([]byte, 4) - binary.BigEndian.PutUint32(keyBytes, uint32(key)) + keyBytes := make([]byte, 4) //nolint:gomnd + binary.BigEndian.PutUint32(keyBytes, uint32(key)) //nolint:gosec addressBytes, err := address.MarshalBinary() if err != nil { @@ -463,11 +474,11 @@ func FromWalletAddr(addr map[wallet.BackendID]wallet.Address) (*Address, error) // FromWireAddr converts a wallet.Address to a protobuf wire address. func FromWireAddr(addr map[wallet.BackendID]wire.Address) (*Address, error) { - var addressMappings []*AddressMapping + var addressMappings []*AddressMapping //nolint:prealloc for key, address := range addr { - keyBytes := make([]byte, 4) - binary.BigEndian.PutUint32(keyBytes, uint32(key)) + keyBytes := make([]byte, 4) //nolint:gomnd + binary.BigEndian.PutUint32(keyBytes, uint32(key)) //nolint:gosec addressBytes, err := address.MarshalBinary() if err != nil { @@ -511,13 +522,13 @@ func FromWireAddrs(addrs []map[wallet.BackendID]wire.Address) (protoAddrs []*Add // FromIDs converts a map[int]channel.ID to a protobuf ID. func FromIDs(ids map[wallet.BackendID]channel.ID) (*ID, error) { - var idMappings []*IDMapping + var idMappings []*IDMapping //nolint:prealloc for key, id := range ids { - keyBytes := make([]byte, 4) - binary.BigEndian.PutUint32(keyBytes, uint32(key)) + keyBytes := make([]byte, 4) //nolint:gomnd + binary.BigEndian.PutUint32(keyBytes, uint32(key)) //nolint:gosec - idBytes := make([]byte, 32) + idBytes := make([]byte, 32) //nolint:gomnd copy(idBytes, id[:]) idMappings = append(idMappings, &IDMapping{ @@ -593,7 +604,7 @@ func FromAllocation(alloc channel.Allocation) (protoAlloc *Allocation, err error protoAlloc.Backends = make([][]byte, len(alloc.Backends)) for i := range alloc.Backends { protoAlloc.Backends[i] = make([]byte, 4) - binary.BigEndian.PutUint32(protoAlloc.Backends[i], uint32(alloc.Backends[i])) + binary.BigEndian.PutUint32(protoAlloc.Backends[i], uint32(alloc.Backends[i])) //nolint:gosec } protoAlloc.Assets = make([][]byte, len(alloc.Assets)) for i := range alloc.Assets { @@ -648,6 +659,9 @@ func FromBalance(balance []channel.Bal) (protoBalance *Balance, err error) { func FromSubAlloc(subAlloc channel.SubAlloc) (protoSubAlloc *SubAlloc, err error) { protoSubAlloc = &SubAlloc{} protoSubAlloc.Id, err = FromIDs(subAlloc.ID) + if err != nil { + return nil, errors.WithMessage(err, "fromIDs") + } protoSubAlloc.IndexMap = &IndexMap{IndexMap: FromIndexMap(subAlloc.IndexMap)} protoSubAlloc.Bals, err = FromBalance(subAlloc.Bals) return protoSubAlloc, err diff --git a/wire/protobuf/serializer.go b/wire/protobuf/serializer.go index 1b4fe8140..79afd36fa 100644 --- a/wire/protobuf/serializer.go +++ b/wire/protobuf/serializer.go @@ -104,7 +104,7 @@ func writeEnvelope(w io.Writer, env *Envelope) error { if err != nil { return errors.Wrap(err, "marshalling envelope") } - if err := binary.Write(w, binary.BigEndian, uint16(len(data))); err != nil { + if err := binary.Write(w, binary.BigEndian, uint16(len(data))); err != nil { //nolint:gosec return errors.Wrap(err, "writing length to wire") } _, err = w.Write(data) diff --git a/wire/protobuf/updatemsgs.go b/wire/protobuf/updatemsgs.go index e6974ed6b..784cc7871 100644 --- a/wire/protobuf/updatemsgs.go +++ b/wire/protobuf/updatemsgs.go @@ -142,6 +142,9 @@ func ToParams(protoParams *Params) (*channel.Params, error) { func ToState(protoState *State) (state *channel.State, err error) { state = &channel.State{} state.ID, err = ToIDs(protoState.Id) + if err != nil { + return nil, errors.WithMessage(err, "id") + } state.Version = protoState.Version state.IsFinal = protoState.IsFinal allocation, err := ToAllocation(protoState.Allocation) From 2f24516371d66f614248ca69bae33863df8430ea Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Thu, 19 Dec 2024 13:17:06 +0100 Subject: [PATCH 21/36] chore(all): remove unnecessary flags Signed-off-by: Sophia Koehler --- channel/persistence/test/channel.go | 2 +- client/serialize.go | 3 ++- wallet/address.go | 9 +++++---- watcher/local/watcher.go | 2 +- watcher/local/watcher_test.go | 2 -- wire/encode_test.go | 2 +- wire/protobuf/proposalmsgs.go | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/channel/persistence/test/channel.go b/channel/persistence/test/channel.go index 6684f8657..335c2e57a 100644 --- a/channel/persistence/test/channel.go +++ b/channel/persistence/test/channel.go @@ -194,7 +194,7 @@ func (c *Channel) SignAll(ctx context.Context, t require.TestingT) { for i := range c.accounts { sig, err := channel.Sign(c.accounts[i][0], c.StagingState(), 0) require.NoError(t, err) - c.AddSig(ctx, channel.Index(i), sig) //nolint:errcheck, gosec + c.AddSig(ctx, channel.Index(i), sig) //nolint:errcheck c.AssertPersisted(ctx, t) } } diff --git a/client/serialize.go b/client/serialize.go index 382fefae9..e1ea51fec 100644 --- a/client/serialize.go +++ b/client/serialize.go @@ -38,7 +38,8 @@ func (a channelIDsWithLen) Encode(w io.Writer) (err error) { return errors.WithMessage(err, "encoding array length") } for i, id := range a { - if err := perunio.Encode(w, (*channel.IDMap)(&id)); err != nil { + idCopy := id + if err := perunio.Encode(w, (*channel.IDMap)(&idCopy)); err != nil { return errors.WithMessagef(err, "encoding %d-th id array entry", i) } } diff --git a/wallet/address.go b/wallet/address.go index b46909a77..1d6628b14 100644 --- a/wallet/address.go +++ b/wallet/address.go @@ -134,12 +134,12 @@ type AddrKey string // Encode encodes first the length of the map, // then all Addresses and their key in the map. func (a AddressDecMap) Encode(w stdio.Writer) error { - length := int32(len(a)) //nolint:gosec + length := int32(len(a)) if err := perunio.Encode(w, length); err != nil { return errors.WithMessage(err, "encoding map length") } for i, addr := range a { - if err := perunio.Encode(w, int32(i)); err != nil { //nolint:gosec + if err := perunio.Encode(w, int32(i)); err != nil { return errors.WithMessage(err, "encoding map index") } if err := perunio.Encode(w, addr); err != nil { @@ -152,12 +152,13 @@ func (a AddressDecMap) Encode(w stdio.Writer) error { // Encode encodes first the length of the array, // then all AddressDecMaps in the array. func (a AddressMapArray) Encode(w stdio.Writer) error { - length := int32(len(a.Addr)) //nolint:gosec + length := int32(len(a.Addr)) if err := perunio.Encode(w, length); err != nil { return errors.WithMessage(err, "encoding array length") } for i, addr := range a.Addr { - if err := perunio.Encode(w, (*AddressDecMap)(&addr)); err != nil { + addressCopy := addr + if err := perunio.Encode(w, (*AddressDecMap)(&addressCopy)); err != nil { return errors.WithMessagef(err, "encoding %d-th address array entry", i) } } diff --git a/watcher/local/watcher.go b/watcher/local/watcher.go index 344ab5a58..ee6ce65b7 100644 --- a/watcher/local/watcher.go +++ b/watcher/local/watcher.go @@ -208,7 +208,7 @@ func (w *Watcher) startWatching( Sigs: signedState.Sigs, } ch.Go(func() { ch.handleStatesFromClient(initialTx) }) - ch.Go(func() { ch.handleEventsFromChain(w.rs, w.registry) }) //nolint:contextcheck + ch.Go(func() { ch.handleEventsFromChain(w.rs, w.registry) }) return statesPubSub, eventsToClientPubSub, nil } diff --git a/watcher/local/watcher_test.go b/watcher/local/watcher_test.go index fd3b97d9f..bd6d8e891 100644 --- a/watcher/local/watcher_test.go +++ b/watcher/local/watcher_test.go @@ -776,8 +776,6 @@ func (t *adjEventSource) close() { // the "Subscribe" method to be called once. The adjSub and the err are set as // the return values for the call and will be returned when the method is // called. -// -//nolint:unparam func setExpectationSubscribeCall(rs *mocks.RegisterSubscriber, adjSub channel.AdjudicatorSubscription, err error) { rs.On("Subscribe", testifyMock.Anything, testifyMock.Anything).Return(adjSub, err).Once() } diff --git a/wire/encode_test.go b/wire/encode_test.go index efd32e60d..fc586c617 100644 --- a/wire/encode_test.go +++ b/wire/encode_test.go @@ -25,7 +25,7 @@ import ( "polycry.pt/poly-go/test" ) -var nilDecoder = func(io.Reader) (wire.Msg, error) { return nil, nil } //nolint:nilnil +var nilDecoder = func(io.Reader) (wire.Msg, error) { return nil, nil } func TestType_Valid_String(t *testing.T) { test.OnlyOnce(t) diff --git a/wire/protobuf/proposalmsgs.go b/wire/protobuf/proposalmsgs.go index 1ddfe9c03..87a2c34a4 100644 --- a/wire/protobuf/proposalmsgs.go +++ b/wire/protobuf/proposalmsgs.go @@ -603,7 +603,7 @@ func FromAllocation(alloc channel.Allocation) (protoAlloc *Allocation, err error protoAlloc = &Allocation{} protoAlloc.Backends = make([][]byte, len(alloc.Backends)) for i := range alloc.Backends { - protoAlloc.Backends[i] = make([]byte, 4) + protoAlloc.Backends[i] = make([]byte, 4) //nolint:gomnd binary.BigEndian.PutUint32(protoAlloc.Backends[i], uint32(alloc.Backends[i])) //nolint:gosec } protoAlloc.Assets = make([][]byte, len(alloc.Assets)) From 8622a49fa179ac23c3681cbd793d1b4b6db2f003 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Thu, 19 Dec 2024 13:25:15 +0100 Subject: [PATCH 22/36] chore(all): remove unnecessary flags Signed-off-by: Sophia Koehler --- channel/multi/funder.go | 2 +- channel/persistence/keyvalue/cache.go | 6 +----- client/proposal.go | 6 +++--- wallet/address.go | 2 +- wire/net/endpoint_internal_test.go | 1 - wire/perunio/string.go | 2 +- 6 files changed, 7 insertions(+), 12 deletions(-) diff --git a/channel/multi/funder.go b/channel/multi/funder.go index e42607633..f7f86e361 100644 --- a/channel/multi/funder.go +++ b/channel/multi/funder.go @@ -62,7 +62,7 @@ func (f *Funder) SetEgoisticChain(l AssetID, id int, egoistic bool) { // channel. If any of the funder calls fails, the method returns an error. func (f *Funder) Fund(ctx context.Context, request channel.FundingReq) error { // Define funding timeout. - d := time.Duration(request.Params.ChallengeDuration) * time.Second //nolint:gosec + d := time.Duration(request.Params.ChallengeDuration) * time.Second ctx, cancel := context.WithTimeout(ctx, d) defer cancel() diff --git a/channel/persistence/keyvalue/cache.go b/channel/persistence/keyvalue/cache.go index 6fbb875d1..ff463a865 100644 --- a/channel/persistence/keyvalue/cache.go +++ b/channel/persistence/keyvalue/cache.go @@ -22,7 +22,7 @@ import ( "perun.network/go-perun/wire" ) -//nolint:deadcode,unused +//nolint:deadcode func newChannelCache() *channelCache { return &channelCache{ peers: make(map[channel.ID][]wire.Address), @@ -31,15 +31,12 @@ func newChannelCache() *channelCache { } // channelCache contains all channels. -// -//nolint:unused type channelCache struct { mutex stdsync.RWMutex peers map[channel.ID][]wire.Address // Used when closing a channel. peerChannels map[string]map[channel.ID]struct{} // Address -> Set } -//nolint:unused func (c *channelCache) addPeerChannel(addr wire.Address, chID channel.ID) { c.mutex.Lock() defer c.mutex.Unlock() @@ -59,7 +56,6 @@ func (c *channelCache) addPeerChannel(addr wire.Address, chID channel.ID) { } } -//nolint:unused func (c *channelCache) deleteChannel(id channel.ID) []wire.Address { c.mutex.Lock() defer c.mutex.Unlock() diff --git a/client/proposal.go b/client/proposal.go index e3b1f7480..87f7a15dc 100644 --- a/client/proposal.go +++ b/client/proposal.go @@ -208,7 +208,7 @@ func (c *Client) ProposeChannel(ctx context.Context, prop ChannelProposal) (*Cha // cache version 1 updates until channel is opened c.enableVer1Cache() // replay cached version 1 updates - defer c.releaseVer1Cache() //nolint:contextcheck + defer c.releaseVer1Cache() ch, err := c.proposeTwoPartyChannel(ctx, prop) if err != nil { return nil, errors.WithMessage(err, "channel proposal") @@ -285,7 +285,7 @@ func (c *Client) handleChannelProposalAcc( // cache version 1 updates c.enableVer1Cache() // replay cached version 1 updates - defer c.releaseVer1Cache() //nolint:contextcheck + defer c.releaseVer1Cache() if ch, err = c.acceptChannelProposal(ctx, prop, p, acc); err != nil { return ch, errors.WithMessage(err, "accept channel proposal") @@ -785,7 +785,7 @@ func (c *Client) releaseVer1Cache() { c.version1Cache.enabled-- for _, u := range c.version1Cache.cache { - go c.handleChannelUpdate(u.uh, u.p, u.m) //nolint:contextcheck + go c.handleChannelUpdate(u.uh, u.p, u.m) } c.version1Cache.cache = nil } diff --git a/wallet/address.go b/wallet/address.go index 1d6628b14..89f189c6e 100644 --- a/wallet/address.go +++ b/wallet/address.go @@ -206,7 +206,7 @@ func (a *AddressMapArray) Decode(r stdio.Reader) (err error) { // Panics when the `Address` can't be encoded. func Key(a Address) AddrKey { var buff strings.Builder - if err := perunio.Encode(&buff, uint32(a.BackendID())); err != nil { //nolint:gosec + if err := perunio.Encode(&buff, uint32(a.BackendID())); err != nil { panic("Could not encode id in AddrKey: " + err.Error()) } if err := perunio.Encode(&buff, a); err != nil { diff --git a/wire/net/endpoint_internal_test.go b/wire/net/endpoint_internal_test.go index 72e898eee..6135039fb 100644 --- a/wire/net/endpoint_internal_test.go +++ b/wire/net/endpoint_internal_test.go @@ -67,7 +67,6 @@ func (s *setup) Dial(ctx context.Context, addr map[wallet.BackendID]wire.Address // a: Alice's end, b: Bob's end. a, b := newPipeConnPair() - //nolint:gocritic if channel.EqualWireMaps(addr, s.alice.endpoint.Address) { // Dialing Bob? s.bob.Registry.addEndpoint(s.bob.endpoint.Address, b, true) // Bob accepts connection. return a, nil diff --git a/wire/perunio/string.go b/wire/perunio/string.go index 88a16d9c1..292c0a837 100644 --- a/wire/perunio/string.go +++ b/wire/perunio/string.go @@ -23,7 +23,7 @@ import ( // encodeString writes the length as an uint16 and then the string itself to the io.Writer. func encodeString(w io.Writer, s string) error { - l := uint16(len(s)) //nolint:gosec + l := uint16(len(s)) if int(l) != len(s) { return errors.Errorf("string length exceeded: %d", len(s)) } From caa8d4c771a76a8bf798bad8193ef8b2c908cc09 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Thu, 19 Dec 2024 13:33:32 +0100 Subject: [PATCH 23/36] chore(all): remove unnecessary flags Signed-off-by: Sophia Koehler --- channel/persistence/keyvalue/cache.go | 1 - channel/test/randomizer.go | 4 ++-- client/proposal_internal_test.go | 2 +- client/sync.go | 5 +---- client/update.go | 6 +++--- client/virtual_channel.go | 8 ++++---- client/virtual_channel_settlement.go | 4 ++-- wire/account.go | 2 +- 8 files changed, 14 insertions(+), 18 deletions(-) diff --git a/channel/persistence/keyvalue/cache.go b/channel/persistence/keyvalue/cache.go index ff463a865..9a748cefd 100644 --- a/channel/persistence/keyvalue/cache.go +++ b/channel/persistence/keyvalue/cache.go @@ -78,7 +78,6 @@ func (c *channelCache) deleteChannel(id channel.ID) []wire.Address { return peers } -//nolint:unused func (c *channelCache) clear() { c.mutex.Lock() defer c.mutex.Unlock() diff --git a/channel/test/randomizer.go b/channel/test/randomizer.go index f80e5bbce..e9082badf 100644 --- a/channel/test/randomizer.go +++ b/channel/test/randomizer.go @@ -47,7 +47,7 @@ func SetRandomizer(r Randomizer, bID wallet.BackendID) { // NewRandomPhase generates a random channel machine phase. func NewRandomPhase(rng *rand.Rand) channel.Phase { - return channel.Phase(rng.Intn(channel.LastPhase + 1)) //nolint:gosec + return channel.Phase(rng.Intn(channel.LastPhase + 1)) } // NewRandomAsset generates a new random `channel.Asset`. @@ -299,7 +299,7 @@ func NewRandomChannelIDs(rng *rand.Rand, n int) (ids []map[wallet.BackendID]chan func NewRandomIndexMap(rng *rand.Rand, numParts int, numPartsParent int) (m []channel.Index) { m = make([]channel.Index, numParts) for i := range m { - m[i] = channel.Index(rng.Intn(numPartsParent)) //nolint:gosec + m[i] = channel.Index(rng.Intn(numPartsParent)) } return } diff --git a/client/proposal_internal_test.go b/client/proposal_internal_test.go index 7c50ff213..a50dbf175 100644 --- a/client/proposal_internal_test.go +++ b/client/proposal_internal_test.go @@ -105,7 +105,7 @@ func TestChannelProposal_assertValidNumParts(t *testing.T) { func TestProposalResponder_Accept_Nil(t *testing.T) { p := new(ProposalResponder) - _, err := p.Accept(nil, new(LedgerChannelProposalAccMsg)) //nolint:staticcheck + _, err := p.Accept(nil, new(LedgerChannelProposalAccMsg)) assert.Error(t, err, "context") } diff --git a/client/sync.go b/client/sync.go index a6c2d1dfa..2a0eb4c0a 100644 --- a/client/sync.go +++ b/client/sync.go @@ -69,8 +69,6 @@ func (c *Client) handleSyncMsg(peer map[wallet.BackendID]wire.Address, msg *Chan // syncChannel synchronizes the channel state with the given peer and modifies // the current state if required. -// -//nolint:unused func (c *Client) syncChannel(ctx context.Context, ch *persistence.Channel, p map[wallet.BackendID]wire.Address) (err error) { recv := wire.NewReceiver() defer recv.Close() // ignore error @@ -121,7 +119,7 @@ func (c *Client) syncChannel(ctx context.Context, ch *persistence.Channel, p map // validateMessage validates the remote channel sync message. // -//nolint:unused, nestif +//nolint:nestif func validateMessage(ch *persistence.Channel, msg *ChannelSyncMsg) error { v := ch.CurrentTX().Version mv := msg.CurrentTX.Version @@ -153,7 +151,6 @@ func validateMessage(ch *persistence.Channel, msg *ChannelSyncMsg) error { return nil } -//nolint:unused func revisePhase(ch *persistence.Channel) error { //nolint:gocritic if ch.PhaseV <= channel.Funding && ch.CurrentTXV.Version == 0 { diff --git a/client/update.go b/client/update.go index a6e71a9e7..ddec31913 100644 --- a/client/update.go +++ b/client/update.go @@ -42,7 +42,7 @@ func (c *Client) handleChannelUpdate(uh UpdateHandler, p map[wallet.BackendID]wi return } pidx := ch.Idx() ^ 1 - ch.handleUpdateReq(pidx, m, uh) //nolint:contextcheck + ch.handleUpdateReq(pidx, m, uh) } func (c *Client) cacheVersion1Update(uh UpdateHandler, p map[wallet.BackendID]wire.Address, m ChannelUpdateProposal) bool { @@ -287,10 +287,10 @@ func (c *Channel) handleUpdateReq( // Check whether we have an update related to a virtual channel. switch prop := req.(type) { case *VirtualChannelFundingProposalMsg: - client.handleVirtualChannelFundingProposal(c, prop, responder) //nolint:contextcheck + client.handleVirtualChannelFundingProposal(c, prop, responder) return case *VirtualChannelSettlementProposalMsg: - client.handleVirtualChannelSettlementProposal(c, prop, responder) //nolint:contextcheck + client.handleVirtualChannelSettlementProposal(c, prop, responder) return } diff --git a/client/virtual_channel.go b/client/virtual_channel.go index 22be5be18..0af4d033f 100644 --- a/client/virtual_channel.go +++ b/client/virtual_channel.go @@ -90,7 +90,7 @@ func (c *Client) handleVirtualChannelFundingProposal( ) { err := c.validateVirtualChannelFundingProposal(ch, prop) if err != nil { - c.rejectProposal(responder, err.Error()) //nolint:contextcheck + c.rejectProposal(responder, err.Error()) } ctx, cancel := context.WithTimeout(c.Ctx(), virtualFundingTimeout) @@ -98,10 +98,10 @@ func (c *Client) handleVirtualChannelFundingProposal( err = c.fundingWatcher.Await(ctx, prop) if err != nil { - c.rejectProposal(responder, err.Error()) //nolint:contextcheck + c.rejectProposal(responder, err.Error()) } - c.acceptProposal(responder) //nolint:contextcheck + c.acceptProposal(responder) } func (c *Channel) watchVirtual() error { @@ -361,7 +361,7 @@ func (c *Client) matchFundingProposal(ctx context.Context, a, b interface{}) boo go func() { // The context will be derived from the channel context. - err := virtual.watchVirtual() //nolint:contextcheck + err := virtual.watchVirtual() c.log.Debugf("channel %v: watcher stopped: %v", virtual.ID(), err) }() return true diff --git a/client/virtual_channel_settlement.go b/client/virtual_channel_settlement.go index 49d822d68..35947f051 100644 --- a/client/virtual_channel_settlement.go +++ b/client/virtual_channel_settlement.go @@ -79,7 +79,7 @@ func (c *Client) handleVirtualChannelSettlementProposal( ) { err := c.validateVirtualChannelSettlementProposal(parent, prop) if err != nil { - c.rejectProposal(responder, err.Error()) //nolint:contextcheck + c.rejectProposal(responder, err.Error()) } ctx, cancel := context.WithTimeout(c.Ctx(), virtualSettlementTimeout) @@ -90,7 +90,7 @@ func (c *Client) handleVirtualChannelSettlementProposal( resp: responder, }) if err != nil { - c.rejectProposal(responder, err.Error()) //nolint:contextcheck + c.rejectProposal(responder, err.Error()) } } diff --git a/wire/account.go b/wire/account.go index 7579e78d4..616fa230a 100644 --- a/wire/account.go +++ b/wire/account.go @@ -56,7 +56,7 @@ func (m *AuthResponseMsg) Type() Type { // It writes the signature to the writer. func (m *AuthResponseMsg) Encode(w io.Writer) error { // Write the length of the signature - err := binary.Write(w, binary.BigEndian, uint32(len(m.Signature))) //nolint:gosec + err := binary.Write(w, binary.BigEndian, uint32(len(m.Signature))) if err != nil { return fmt.Errorf("failed to write signature length: %w", err) } From b27256441ad8fa5196dd3a984f8799934fb32361 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Thu, 19 Dec 2024 13:36:11 +0100 Subject: [PATCH 24/36] chore(all): remove unnecessary flags Signed-off-by: Sophia Koehler --- wire/address.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wire/address.go b/wire/address.go index 93b7a0353..09ec9d72f 100644 --- a/wire/address.go +++ b/wire/address.go @@ -58,12 +58,12 @@ type AddressDecMap map[wallet.BackendID]Address // Encode encodes first the length of the map, // then all Addresses and their key in the map. func (a AddressDecMap) Encode(w stdio.Writer) error { - length := int32(len(a)) //nolint:gosec + length := int32(len(a)) if err := perunio.Encode(w, length); err != nil { return errors.WithMessage(err, "encoding map length") } for i, addr := range a { - if err := perunio.Encode(w, int32(i)); err != nil { //nolint:gosec + if err := perunio.Encode(w, int32(i)); err != nil { return errors.WithMessage(err, "encoding map index") } if err := perunio.Encode(w, addr); err != nil { @@ -76,7 +76,7 @@ func (a AddressDecMap) Encode(w stdio.Writer) error { // Encode encodes first the length of the array, // then all AddressDecMaps in the array. func (a AddressMapArray) Encode(w stdio.Writer) error { - length := int32(len(a)) //nolint:gosec + length := int32(len(a)) if err := perunio.Encode(w, length); err != nil { return errors.WithMessage(err, "encoding array length") } From 2c079f1daf17e55610a08208a328b4e1498dafd3 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Thu, 19 Dec 2024 13:47:29 +0100 Subject: [PATCH 25/36] chore(all): remove unnecessary flags Signed-off-by: Sophia Koehler --- backend/sim/channel/asset.go | 4 ++-- channel/allocation.go | 12 ++++++------ channel/machine.go | 4 ++-- channel/params.go | 8 ++++---- .../persistence/test/persistrestorertest.go | 2 +- client/channelconn.go | 4 ++-- client/serialize.go | 6 +++--- client/test/backend.go | 6 +++--- client/test/mallory.go | 2 +- client/test/syncmsgs.go | 2 +- client/test/updatemsgs.go | 6 +++--- client/virtual_channel.go | 4 ++-- client/virtual_channel_settlement.go | 2 +- wire/net/simple/address.go | 6 +++--- wire/protobuf/proposalmsgs.go | 18 +++++++++--------- wire/protobuf/serializer.go | 2 +- wire/protobuf/syncmsgs.go | 2 +- wire/protobuf/updatemsgs.go | 2 +- 18 files changed, 46 insertions(+), 46 deletions(-) diff --git a/backend/sim/channel/asset.go b/backend/sim/channel/asset.go index 0dd1d495a..a7ae10fce 100644 --- a/backend/sim/channel/asset.go +++ b/backend/sim/channel/asset.go @@ -44,7 +44,7 @@ func NewRandomAsset(rng *rand.Rand) *Asset { // MarshalBinary marshals the address into its binary representation. func (a Asset) MarshalBinary() ([]byte, error) { data := make([]byte, assetLen) - byteOrder.PutUint64(data, uint64(a.ID)) //nolint:gosec + byteOrder.PutUint64(data, uint64(a.ID)) return data, nil } @@ -53,7 +53,7 @@ func (a *Asset) UnmarshalBinary(data []byte) error { if len(data) != assetLen { return fmt.Errorf("unexpected length %d, want %d", len(data), assetLen) //nolint:goerr113 // We do not want to define this as constant error. } - a.ID = int64(byteOrder.Uint64(data)) //nolint:gosec + a.ID = int64(byteOrder.Uint64(data)) return nil } diff --git a/channel/allocation.go b/channel/allocation.go index 72a31ba76..d61316027 100644 --- a/channel/allocation.go +++ b/channel/allocation.go @@ -127,7 +127,7 @@ func NewAllocation(numParts int, backends []wallet.BackendID, assets ...Asset) * func (a *Allocation) AssetIndex(asset Asset) (Index, bool) { for idx, _asset := range a.Assets { if asset.Equal(_asset) { - return Index(idx), true //nolint:gosec + return Index(idx), true } } return 0, false @@ -325,12 +325,12 @@ func (a Allocation) Encode(w io.Writer) error { err, "invalid allocations cannot be encoded, got %v", a) } // encode dimensions - if err := perunio.Encode(w, Index(len(a.Assets)), Index(len(a.Balances[0])), Index(len(a.Locked))); err != nil { //nolint:gosec + if err := perunio.Encode(w, Index(len(a.Assets)), Index(len(a.Balances[0])), Index(len(a.Locked))); err != nil { return err } // encode assets for i, asset := range a.Assets { - if err := perunio.Encode(w, uint32(a.Backends[i])); err != nil { //nolint:gosec + if err := perunio.Encode(w, uint32(a.Backends[i])); err != nil { return errors.WithMessagef(err, "encoding backends %d", i) } if err := perunio.Encode(w, asset); err != nil { @@ -436,7 +436,7 @@ func (b Balances) Encode(w io.Writer) error { return errors.Errorf("expected maximum number of parts %d, got %d", MaxNumParts, numParts) } - if err := perunio.Encode(w, Index(numAssets), Index(numParts)); err != nil { //nolint:gosec + if err := perunio.Encode(w, Index(numAssets), Index(numParts)); err != nil { return errors.WithMessage(err, "encoding dimensions") } for i := range b { @@ -667,7 +667,7 @@ func (s SubAlloc) Encode(w io.Writer) error { err, "invalid sub-allocations cannot be encoded, got %v", s) } // encode ID and dimension - if err := perunio.Encode(w, IDMap(s.ID), Index(len(s.Bals))); err != nil { //nolint:gosec + if err := perunio.Encode(w, IDMap(s.ID), Index(len(s.Bals))); err != nil { return errors.WithMessagef( err, "encoding sub-allocation ID or dimension, id %v", s.ID) } @@ -679,7 +679,7 @@ func (s SubAlloc) Encode(w io.Writer) error { } } // Encode IndexMap. - if err := perunio.Encode(w, Index(len(s.IndexMap))); err != nil { //nolint:gosec + if err := perunio.Encode(w, Index(len(s.IndexMap))); err != nil { return errors.WithMessage(err, "encoding length of index map") } for i, x := range s.IndexMap { diff --git a/channel/machine.go b/channel/machine.go index 6198b34e9..78e742dff 100644 --- a/channel/machine.go +++ b/channel/machine.go @@ -151,7 +151,7 @@ func newMachine(acc map[wallet.BackendID]wallet.Account, params Params) (*machin return &machine{ phase: InitActing, acc: acc, - idx: Index(idx), //nolint:gosec + idx: Index(idx), params: params, Embedding: log.MakeEmbedding(log.WithField("ID", params.id)), }, nil @@ -190,7 +190,7 @@ func (m *machine) Params() *Params { // N returns the number of participants of the channel parameters of this machine. func (m *machine) N() Index { - return Index(len(m.params.Parts)) //nolint:gosec + return Index(len(m.params.Parts)) } // Phase returns the current phase. diff --git a/channel/params.go b/channel/params.go index d8151ae71..6d1ab6df3 100644 --- a/channel/params.go +++ b/channel/params.go @@ -75,12 +75,12 @@ func EqualIDs(a, b map[wallet.BackendID]ID) bool { } func (ids IDMap) Encode(w stdio.Writer) error { - length := int32(len(ids)) //nolint:gosec + length := int32(len(ids)) if err := perunio.Encode(w, length); err != nil { return errors.WithMessage(err, "encoding map length") } for i, id := range ids { - if err := perunio.Encode(w, int32(i)); err != nil { //nolint:gosec + if err := perunio.Encode(w, int32(i)); err != nil { return errors.WithMessage(err, "encoding map index") } if err := perunio.Encode(w, id); err != nil { @@ -112,14 +112,14 @@ func (ids *IDMap) Decode(r stdio.Reader) error { func IDKey(ids IDMap) string { var buff strings.Builder - length := int32(len(ids)) //nolint:gosec + length := int32(len(ids)) err := binary.Write(&buff, binary.BigEndian, length) if err != nil { log.Panic("could not encode map length in Key: ", err) } sortedKeys, sortedIDs := sortIDMap(ids) for i, id := range sortedIDs { - if err := binary.Write(&buff, binary.BigEndian, int32(sortedKeys[i])); err != nil { //nolint:gosec + if err := binary.Write(&buff, binary.BigEndian, int32(sortedKeys[i])); err != nil { log.Panicf("could not encode map key: " + err.Error()) } if err := perunio.Encode(&buff, id); err != nil { diff --git a/channel/persistence/test/persistrestorertest.go b/channel/persistence/test/persistrestorertest.go index 9fdb9e738..075728830 100644 --- a/channel/persistence/test/persistrestorertest.go +++ b/channel/persistence/test/persistrestorertest.go @@ -67,7 +67,7 @@ func (c *Client) NewChannel(t require.TestingT, p map[wallet.BackendID]wire.Addr c.ctx, t, c.pr, - channel.Index(idx), //nolint:gosec + channel.Index(idx), peers, parent, c.rng) diff --git a/client/channelconn.go b/client/channelconn.go index bd31a66b6..3c4c6e761 100644 --- a/client/channelconn.go +++ b/client/channelconn.go @@ -104,7 +104,7 @@ func (c *channelConn) Close() error { func (c *channelConn) Send(ctx context.Context, msg wire.Msg) error { var eg errgroup.Group for i, peer := range c.peers { - if channel.Index(i) == c.idx { //nolint:gosec + if channel.Index(i) == c.idx { continue // skip own peer } c.log.WithField("peer", peer).Debugf("channelConn: publishing message: %v: %+v", msg.Type(), msg) @@ -168,5 +168,5 @@ func (r *channelMsgRecv) Next(ctx context.Context) (channel.Index, ChannelMsg, e if !ok { return 0, nil, errors.Errorf("unexpected message type: expected ChannelMsg, got %T", env.Msg) } - return channel.Index(idx), msg, nil //nolint:gosec + return channel.Index(idx), msg, nil } diff --git a/client/serialize.go b/client/serialize.go index e1ea51fec..2449b4533 100644 --- a/client/serialize.go +++ b/client/serialize.go @@ -33,7 +33,7 @@ type ( // Encode encodes the object to the writer. func (a channelIDsWithLen) Encode(w io.Writer) (err error) { - length := int32(len(a)) //nolint:gosec + length := int32(len(a)) if err := perunio.Encode(w, length); err != nil { return errors.WithMessage(err, "encoding array length") } @@ -63,7 +63,7 @@ func (a *channelIDsWithLen) Decode(r io.Reader) (err error) { // Encode encodes the object to the writer. func (a indexMapsWithLen) Encode(w io.Writer) (err error) { - err = perunio.Encode(w, sliceLen(len(a))) //nolint:gosec + err = perunio.Encode(w, sliceLen(len(a))) if err != nil { return } @@ -95,7 +95,7 @@ func (a *indexMapsWithLen) Decode(r io.Reader) (err error) { // Encode encodes the object to the writer. func (a indexMapWithLen) Encode(w io.Writer) (err error) { - err = perunio.Encode(w, sliceLen(len(a))) //nolint:gosec + err = perunio.Encode(w, sliceLen(len(a))) if err != nil { return } diff --git a/client/test/backend.go b/client/test/backend.go index 80f9de7f6..f4fa401cf 100644 --- a/client/test/backend.go +++ b/client/test/backend.go @@ -189,7 +189,7 @@ func (b *MockBackend) Register(_ context.Context, req channel.AdjudicatorReq, su }, }, subChannels...) - timeout := time.Now().Add(time.Duration(req.Params.ChallengeDuration) * time.Millisecond) //nolint:gosec + timeout := time.Now().Add(time.Duration(req.Params.ChallengeDuration) * time.Millisecond) for _, ch := range channels { b.setLatestEvent( ch.Params.ID(), @@ -228,7 +228,7 @@ func (b *MockBackend) Progress(_ context.Context, req channel.ProgressReq) error b.mu.Lock() defer b.mu.Unlock() - timeout := time.Now().Add(time.Duration(req.Params.ChallengeDuration) * time.Millisecond) //nolint:gosec + timeout := time.Now().Add(time.Duration(req.Params.ChallengeDuration) * time.Millisecond) b.setLatestEvent( req.Params.ID(), channel.NewProgressedEvent( @@ -559,7 +559,7 @@ func (f *assetHolder) Fund(req channel.FundingReq, b *MockBackend, acc wallet.Ad // WaitForFunding waits until all participants have funded the channel. func (f *assetHolder) WaitForFunding(ctx context.Context, req channel.FundingReq) error { - challengeDuration := time.Duration(req.Params.ChallengeDuration) * time.Second //nolint:gosec + challengeDuration := time.Duration(req.Params.ChallengeDuration) * time.Second fundCtx, cancel := context.WithTimeout(ctx, challengeDuration) defer cancel() diff --git a/client/test/mallory.go b/client/test/mallory.go index 36aa38444..ef30ec27d 100644 --- a/client/test/mallory.go +++ b/client/test/mallory.go @@ -66,7 +66,7 @@ func (r *Mallory) exec(_cfg ExecConfig, ch *paymentChannel) { r.waitStage() // Register version 0 AdjudicatorReq - challengeDuration := time.Duration(ch.Channel.Params().ChallengeDuration) * time.Second //nolint:gosec + challengeDuration := time.Duration(ch.Channel.Params().ChallengeDuration) * time.Second regCtx, regCancel := context.WithTimeout(context.Background(), r.timeout) defer regCancel() r.log.Debug("Registering version 0 state.") diff --git a/client/test/syncmsgs.go b/client/test/syncmsgs.go index fe452c6e3..4d9e87063 100644 --- a/client/test/syncmsgs.go +++ b/client/test/syncmsgs.go @@ -31,7 +31,7 @@ func ChannelSyncMsgSerializationTest(t *testing.T, serializerTest func(t *testin for i := 0; i < 4; i++ { state := test.NewRandomState(rng) m := &client.ChannelSyncMsg{ - Phase: channel.Phase(rng.Intn(channel.LastPhase)), //nolint:gosec + Phase: channel.Phase(rng.Intn(channel.LastPhase)), CurrentTX: channel.Transaction{ State: state, Sigs: newRandomSigs(rng, state.NumParts()), diff --git a/client/test/updatemsgs.go b/client/test/updatemsgs.go index 159da7ed4..931b467a5 100644 --- a/client/test/updatemsgs.go +++ b/client/test/updatemsgs.go @@ -97,7 +97,7 @@ func channelUpdateAccSerializationTest(t *testing.T, serializerTest func(t *test sig := newRandomSig(rng, 0) m := &client.ChannelUpdateAccMsg{ ChannelID: test.NewRandomChannelID(rng), - Version: uint64(rng.Int63()), //nolint:gosec + Version: uint64(rng.Int63()), Sig: sig, } serializerTest(t, m) @@ -112,7 +112,7 @@ func channelUpdateRejSerializationTest(t *testing.T, serializerTest func(t *test for i := 0; i < 4; i++ { m := &client.ChannelUpdateRejMsg{ ChannelID: test.NewRandomChannelID(rng), - Version: uint64(rng.Int63()), //nolint:gosec + Version: uint64(rng.Int63()), Reason: newRandomASCIIString(rng, minLen, maxLenDiff), } serializerTest(t, m) @@ -125,7 +125,7 @@ func newRandomMsgChannelUpdate(rng *rand.Rand) *client.ChannelUpdateMsg { return &client.ChannelUpdateMsg{ ChannelUpdate: client.ChannelUpdate{ State: state, - ActorIdx: channel.Index(rng.Intn(state.NumParts())), //nolint:gosec + ActorIdx: channel.Index(rng.Intn(state.NumParts())), }, Sig: sig, } diff --git a/client/virtual_channel.go b/client/virtual_channel.go index 0af4d033f..596a6d359 100644 --- a/client/virtual_channel.go +++ b/client/virtual_channel.go @@ -185,7 +185,7 @@ func (c *Client) persistVirtualChannel(ctx context.Context, parent *Channel, pee } for i, sig := range sigs { - err = ch.machine.AddSig(ctx, channel.Index(i), sig) //nolint:gosec + err = ch.machine.AddSig(ctx, channel.Index(i), sig) if err != nil { return nil, err } @@ -223,7 +223,7 @@ func (c *Channel) pushVirtualUpdate(ctx context.Context, state *channel.State, s } for i, sig := range sigs { - idx := channel.Index(i) //nolint:gosec + idx := channel.Index(i) if err := m.AddSig(ctx, idx, sig); err != nil { return err } diff --git a/client/virtual_channel_settlement.go b/client/virtual_channel_settlement.go index 35947f051..532dc28b3 100644 --- a/client/virtual_channel_settlement.go +++ b/client/virtual_channel_settlement.go @@ -214,7 +214,7 @@ func (c *Channel) forceFinalState(ctx context.Context, final channel.SignedState return err } for i, sig := range final.Sigs { - if err := c.machine.AddSig(ctx, channel.Index(i), sig); err != nil { //nolint:gosec + if err := c.machine.AddSig(ctx, channel.Index(i), sig); err != nil { return err } } diff --git a/wire/net/simple/address.go b/wire/net/simple/address.go index 5a177252a..ad7bb67e7 100644 --- a/wire/net/simple/address.go +++ b/wire/net/simple/address.go @@ -47,7 +47,7 @@ func (a *Address) MarshalBinary() ([]byte, error) { var buf bytes.Buffer // Encode the length of the name string and the name itself - nameLen := uint16(len(a.Name)) //nolint:gosec + nameLen := uint16(len(a.Name)) if err := binary.Write(&buf, binary.BigEndian, nameLen); err != nil { return nil, err } @@ -110,7 +110,7 @@ func (a *Address) Backend() wallet.BackendID { func encodePublicKey(buf *bytes.Buffer, key *rsa.PublicKey) error { // Encode modulus length and modulus modulusBytes := key.N.Bytes() - modulusLen := uint16(len(modulusBytes)) //nolint:gosec + modulusLen := uint16(len(modulusBytes)) if err := binary.Write(buf, binary.BigEndian, modulusLen); err != nil { return err } @@ -119,7 +119,7 @@ func encodePublicKey(buf *bytes.Buffer, key *rsa.PublicKey) error { } // Encode public exponent - if err := binary.Write(buf, binary.BigEndian, int32(key.E)); err != nil { //nolint:gosec + if err := binary.Write(buf, binary.BigEndian, int32(key.E)); err != nil { return err } diff --git a/wire/protobuf/proposalmsgs.go b/wire/protobuf/proposalmsgs.go index 87a2c34a4..1dc048e25 100644 --- a/wire/protobuf/proposalmsgs.go +++ b/wire/protobuf/proposalmsgs.go @@ -354,7 +354,7 @@ func ToIndexMap(protoIndexMap []uint32) (indexMap []channel.Index, err error) { if protoIndexMap[i] > math.MaxUint16 { return nil, fmt.Errorf("%d'th index is invalid", i) //nolint:goerr113 // We do not want to define this as constant error. } - indexMap[i] = channel.Index(uint16(protoIndexMap[i])) //nolint:gosec + indexMap[i] = channel.Index(uint16(protoIndexMap[i])) } return indexMap, nil } @@ -453,8 +453,8 @@ func FromWalletAddr(addr map[wallet.BackendID]wallet.Address) (*Address, error) var addressMappings []*AddressMapping //nolint:prealloc for key, address := range addr { - keyBytes := make([]byte, 4) //nolint:gomnd - binary.BigEndian.PutUint32(keyBytes, uint32(key)) //nolint:gosec + keyBytes := make([]byte, 4) //nolint:gomnd + binary.BigEndian.PutUint32(keyBytes, uint32(key)) addressBytes, err := address.MarshalBinary() if err != nil { @@ -477,8 +477,8 @@ func FromWireAddr(addr map[wallet.BackendID]wire.Address) (*Address, error) { var addressMappings []*AddressMapping //nolint:prealloc for key, address := range addr { - keyBytes := make([]byte, 4) //nolint:gomnd - binary.BigEndian.PutUint32(keyBytes, uint32(key)) //nolint:gosec + keyBytes := make([]byte, 4) //nolint:gomnd + binary.BigEndian.PutUint32(keyBytes, uint32(key)) addressBytes, err := address.MarshalBinary() if err != nil { @@ -525,8 +525,8 @@ func FromIDs(ids map[wallet.BackendID]channel.ID) (*ID, error) { var idMappings []*IDMapping //nolint:prealloc for key, id := range ids { - keyBytes := make([]byte, 4) //nolint:gomnd - binary.BigEndian.PutUint32(keyBytes, uint32(key)) //nolint:gosec + keyBytes := make([]byte, 4) //nolint:gomnd + binary.BigEndian.PutUint32(keyBytes, uint32(key)) idBytes := make([]byte, 32) //nolint:gomnd copy(idBytes, id[:]) @@ -603,8 +603,8 @@ func FromAllocation(alloc channel.Allocation) (protoAlloc *Allocation, err error protoAlloc = &Allocation{} protoAlloc.Backends = make([][]byte, len(alloc.Backends)) for i := range alloc.Backends { - protoAlloc.Backends[i] = make([]byte, 4) //nolint:gomnd - binary.BigEndian.PutUint32(protoAlloc.Backends[i], uint32(alloc.Backends[i])) //nolint:gosec + protoAlloc.Backends[i] = make([]byte, 4) //nolint:gomnd + binary.BigEndian.PutUint32(protoAlloc.Backends[i], uint32(alloc.Backends[i])) } protoAlloc.Assets = make([][]byte, len(alloc.Assets)) for i := range alloc.Assets { diff --git a/wire/protobuf/serializer.go b/wire/protobuf/serializer.go index 79afd36fa..1b4fe8140 100644 --- a/wire/protobuf/serializer.go +++ b/wire/protobuf/serializer.go @@ -104,7 +104,7 @@ func writeEnvelope(w io.Writer, env *Envelope) error { if err != nil { return errors.Wrap(err, "marshalling envelope") } - if err := binary.Write(w, binary.BigEndian, uint16(len(data))); err != nil { //nolint:gosec + if err := binary.Write(w, binary.BigEndian, uint16(len(data))); err != nil { return errors.Wrap(err, "writing length to wire") } _, err = w.Write(data) diff --git a/wire/protobuf/syncmsgs.go b/wire/protobuf/syncmsgs.go index 1b8ff3516..fb94a5b19 100644 --- a/wire/protobuf/syncmsgs.go +++ b/wire/protobuf/syncmsgs.go @@ -23,7 +23,7 @@ func toChannelSyncMsg(protoEnvMsg *Envelope_ChannelSyncMsg) (msg *client.Channel protoMsg := protoEnvMsg.ChannelSyncMsg msg = &client.ChannelSyncMsg{} - msg.Phase = channel.Phase(protoMsg.Phase) //nolint:gosec + msg.Phase = channel.Phase(protoMsg.Phase) msg.CurrentTX.Sigs = make([][]byte, len(protoMsg.CurrentTx.Sigs)) for i := range protoMsg.CurrentTx.Sigs { msg.CurrentTX.Sigs[i] = make([]byte, len(protoMsg.CurrentTx.Sigs[i])) diff --git a/wire/protobuf/updatemsgs.go b/wire/protobuf/updatemsgs.go index 784cc7871..70dcf33af 100644 --- a/wire/protobuf/updatemsgs.go +++ b/wire/protobuf/updatemsgs.go @@ -95,7 +95,7 @@ func ToChannelUpdate(protoUpdate *ChannelUpdateMsg) (update client.ChannelUpdate if protoUpdate.ChannelUpdate.ActorIdx > math.MaxUint16 { return update, errors.New("actor index is invalid") } - update.ActorIdx = channel.Index(protoUpdate.ChannelUpdate.ActorIdx) //nolint:gosec + update.ActorIdx = channel.Index(protoUpdate.ChannelUpdate.ActorIdx) update.Sig = make([]byte, len(protoUpdate.Sig)) copy(update.Sig, protoUpdate.Sig) update.State, err = ToState(protoUpdate.ChannelUpdate.State) From ced8fb5dfbc87e9511c658123e49c0620f9259a7 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Thu, 19 Dec 2024 13:51:28 +0100 Subject: [PATCH 26/36] chore(all): remove unnecessary flags Signed-off-by: Sophia Koehler --- apps/payment/app_internal_test.go | 4 ++-- channel/persistence/statemachine_test.go | 4 ++-- client/restore_internal_test.go | 2 +- watcher/local/watcher_test.go | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/payment/app_internal_test.go b/apps/payment/app_internal_test.go index 710ddc08f..01eb8f477 100644 --- a/apps/payment/app_internal_test.go +++ b/apps/payment/app_internal_test.go @@ -95,7 +95,7 @@ func TestApp_ValidTransition(t *testing.T) { numParticipants := len(tt.from[0]) for i := 0; i < numParticipants; i++ { // valid self-transition - assert.NoError(app.ValidTransition(nil, from, from, channel.Index(i))) //nolint:gosec + assert.NoError(app.ValidTransition(nil, from, from, channel.Index(i))) } for _, tto := range tt.tos { @@ -105,7 +105,7 @@ func TestApp_ValidTransition(t *testing.T) { test.WithBalances(asBalances(tto.alloc...)...), ) for i := 0; i < numParticipants; i++ { - err := app.ValidTransition(nil, from, to, channel.Index(i)) //nolint:gosec + err := app.ValidTransition(nil, from, to, channel.Index(i)) if i == tto.valid { assert.NoError(err) } else { diff --git a/channel/persistence/statemachine_test.go b/channel/persistence/statemachine_test.go index c2dae4f68..daf9d3d44 100644 --- a/channel/persistence/statemachine_test.go +++ b/channel/persistence/statemachine_test.go @@ -76,7 +76,7 @@ func TestStateMachine(t *testing.T) { sig, err = channel.Sign(acc, csm.StagingState(), b) require.NoError(err) } - err = sm.AddSig(ctx, channel.Index(i), sig) //nolint:gosec + err = sm.AddSig(ctx, channel.Index(i), sig) require.NoError(err) tpr.AssertEqual(csm) } @@ -152,7 +152,7 @@ func TestStateMachine(t *testing.T) { // Set Progressed timeout := ctest.NewRandomTimeout(rng) - idx := channel.Index(rng.Intn(s.NumParts())) //nolint:gosec + idx := channel.Index(rng.Intn(s.NumParts())) e := channel.NewProgressedEvent(s.ID[0], timeout, s, idx) err = sm.SetProgressed(ctx, e) require.NoError(err) diff --git a/client/restore_internal_test.go b/client/restore_internal_test.go index 5bfb7d2bb..e9baf8fe9 100644 --- a/client/restore_internal_test.go +++ b/client/restore_internal_test.go @@ -120,7 +120,7 @@ func mkRndChan(rng *rand.Rand, bID wallet.BackendID) *persistence.Channel { parts[i] = map[wallet.BackendID]wallet.Address{bID: wallettest.NewRandomAccount(rng, bID).Address()} } ch := persistence.NewChannel() - ch.IdxV = channel.Index(rng.Intn(channel.MaxNumParts)) //nolint:gosec + ch.IdxV = channel.Index(rng.Intn(channel.MaxNumParts)) ch.ParamsV = test.NewRandomParams(rng, test.WithParts(parts)) sigs := make([]bool, channel.MaxNumParts) opts := test.WithParams(ch.ParamsV) diff --git a/watcher/local/watcher_test.go b/watcher/local/watcher_test.go index bd6d8e891..244ad5532 100644 --- a/watcher/local/watcher_test.go +++ b/watcher/local/watcher_test.go @@ -735,7 +735,7 @@ func randomTxsForSingleCh(rng *rand.Rand, n int) (*channel.Params, []channel.Tra txs := make([]channel.Transaction, n) for i := range txs { txs[i] = channel.Transaction{State: initialState.Clone()} - txs[i].State.Version = uint64(i) //nolint:gosec + txs[i].State.Version = uint64(i) } return params, txs } From 056e726384ea715b94657d0857857eaad2beab8f Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Thu, 19 Dec 2024 13:52:47 +0100 Subject: [PATCH 27/36] chore(all): remove unnecessary flags Signed-off-by: Sophia Koehler --- wire/net/simple/listener_internal_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/wire/net/simple/listener_internal_test.go b/wire/net/simple/listener_internal_test.go index dfb013cf5..b5cc7258b 100644 --- a/wire/net/simple/listener_internal_test.go +++ b/wire/net/simple/listener_internal_test.go @@ -31,8 +31,6 @@ const addr = "0.0.0.0:1337" // serverKey and serverCert are generated with the following commands: // openssl ecparam -genkey -name prime256v1 -out server.key // openssl req -new -x509 -key server.key -out server.pem -days 3650. -// -//nolint:gosec const testServerKey = `-----BEGIN EC PARAMETERS----- BggqhkjOPQMBBw== -----END EC PARAMETERS----- From d73ca03648893b86a685a6db0eb0a5f17a4dbad2 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Thu, 19 Dec 2024 14:05:46 +0100 Subject: [PATCH 28/36] chore(all): Rename and add comments to exported functions Signed-off-by: Sophia Koehler --- channel/machine.go | 1 + channel/multi/adjudicator.go | 6 ++-- channel/multi/asset.go | 6 ++-- channel/multi/funder.go | 10 +++--- channel/params.go | 5 +++ channel/persistence/test/channel.go | 14 +------- .../persistence/test/persistrestorertest.go | 2 +- channel/state.go | 1 + channel/test/randomizer.go | 36 +++++++++---------- client/test/backend.go | 4 ++- client/test/multiledger.go | 7 ++-- wire/address.go | 1 + wire/net/endpoint_registry.go | 7 ++-- wire/net/exchange_addr.go | 9 ++--- wire/net/test/listenermap.go | 5 +-- 15 files changed, 58 insertions(+), 56 deletions(-) diff --git a/channel/machine.go b/channel/machine.go index 78e742dff..08d5a7999 100644 --- a/channel/machine.go +++ b/channel/machine.go @@ -576,6 +576,7 @@ func (m *machine) forceState(p Phase, s *State) { m.addTx(m.newTransaction(s)) } +// AddressMapfromAccountMap returns a map of addresses from a map of accounts. func AddressMapfromAccountMap(accs map[wallet.BackendID]wallet.Account) map[wallet.BackendID]wallet.Address { addresses := make(map[wallet.BackendID]wallet.Address) for id, a := range accs { diff --git a/channel/multi/adjudicator.go b/channel/multi/adjudicator.go index 105090362..c1c9b1e7c 100644 --- a/channel/multi/adjudicator.go +++ b/channel/multi/adjudicator.go @@ -35,13 +35,13 @@ func NewAdjudicator() *Adjudicator { // RegisterAdjudicator registers an adjudicator for a given ledger. func (a *Adjudicator) RegisterAdjudicator(l AssetID, la channel.Adjudicator) { - key := AssetIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerId().MapKey())} + key := AssetIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} a.adjudicators[key] = la } // LedgerAdjudicator returns the adjudicator for a given ledger. func (a *Adjudicator) LedgerAdjudicator(l AssetID) (channel.Adjudicator, bool) { - key := AssetIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerId().MapKey())} + key := AssetIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} adj, ok := a.adjudicators[key] return adj, ok } @@ -98,7 +98,7 @@ func (a *Adjudicator) dispatch(assetIds []AssetID, f func(channel.Adjudicator) e for _, l := range assetIds { go func(l AssetID) { err := func() error { - key := AssetIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerId().MapKey())} + key := AssetIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} adjs, ok := a.adjudicators[key] if !ok { return fmt.Errorf("adjudicator not found for id %v", l) diff --git a/channel/multi/asset.go b/channel/multi/asset.go index 6953e94e6..fc731cbbc 100644 --- a/channel/multi/asset.go +++ b/channel/multi/asset.go @@ -30,7 +30,7 @@ type ( // AssetID represents an asset identifier. AssetID interface { BackendID() uint32 - LedgerId() LedgerID + LedgerID() LedgerID } // LedgerIDMapKey is the map key representation of a ledger identifier. @@ -55,7 +55,7 @@ func (a assets) LedgerIDs() ([]AssetID, error) { assetID := ma.AssetID() - ids[AssetIDKey{BackendID: assetID.BackendID(), LedgerID: string(assetID.LedgerId().MapKey())}] = assetID + ids[AssetIDKey{BackendID: assetID.BackendID(), LedgerID: string(assetID.LedgerID().MapKey())}] = assetID } idsArray := make([]AssetID, len(ids)) i := 0 @@ -79,7 +79,7 @@ func IsMultiLedgerAssets(assets []channel.Asset) bool { case !hasMulti: hasMulti = true id = multiAsset.AssetID() - case id.LedgerId().MapKey() != multiAsset.AssetID().LedgerId().MapKey(): + case id.LedgerID().MapKey() != multiAsset.AssetID().LedgerID().MapKey(): return true } } diff --git a/channel/multi/funder.go b/channel/multi/funder.go index f7f86e361..c54d4b9c9 100644 --- a/channel/multi/funder.go +++ b/channel/multi/funder.go @@ -46,14 +46,14 @@ func NewFunder() *Funder { // RegisterFunder registers a funder for a given ledger. func (f *Funder) RegisterFunder(l AssetID, lf channel.Funder) { - key := AssetIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerId().MapKey())} + key := AssetIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} f.funders[key] = lf f.egoisticChains[key] = false } // SetEgoisticChain sets the egoistic chain flag for a given ledger. func (f *Funder) SetEgoisticChain(l AssetID, id int, egoistic bool) { - key := AssetIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerId().MapKey())} + key := AssetIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} f.egoisticChains[key] = egoistic } @@ -75,7 +75,7 @@ func (f *Funder) Fund(ctx context.Context, request channel.FundingReq) error { var nonEgoisticLedgers []AssetID for _, l := range assetIDs { - key := AssetIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerId().MapKey())} + key := AssetIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} if f.egoisticChains[key] { egoisticLedgers = append(egoisticLedgers, l) } else { @@ -107,11 +107,11 @@ func fundLedgers(ctx context.Context, request channel.FundingReq, assetIDs []Ass // Iterate over blockchains to get the LedgerIDs for _, assetID := range assetIDs { go func(assetID AssetID) { - key := AssetIDKey{BackendID: assetID.BackendID(), LedgerID: string(assetID.LedgerId().MapKey())} + key := AssetIDKey{BackendID: assetID.BackendID(), LedgerID: string(assetID.LedgerID().MapKey())} // Get the Funder from the funders map funder, ok := funders[key] if !ok { - errs <- fmt.Errorf("funder map not found for blockchain %d and ledger %d", assetID.BackendID(), assetID.LedgerId()) + errs <- fmt.Errorf("funder map not found for blockchain %d and ledger %d", assetID.BackendID(), assetID.LedgerID()) return } diff --git a/channel/params.go b/channel/params.go index 6d1ab6df3..b04708fb7 100644 --- a/channel/params.go +++ b/channel/params.go @@ -58,6 +58,7 @@ func NonceFromBytes(b []byte) Nonce { // Zero is the default channelID. var Zero = ID{} +// EqualIDs compares two IDs for equality. func EqualIDs(a, b map[wallet.BackendID]ID) bool { if len(a) != len(b) { return false @@ -74,6 +75,7 @@ func EqualIDs(a, b map[wallet.BackendID]ID) bool { return true } +// Encode encodes the IDMap to the given writer. func (ids IDMap) Encode(w stdio.Writer) error { length := int32(len(ids)) if err := perunio.Encode(w, length); err != nil { @@ -90,6 +92,7 @@ func (ids IDMap) Encode(w stdio.Writer) error { return nil } +// Decode decodes the IDMap from the given reader. func (ids *IDMap) Decode(r stdio.Reader) error { var mapLen int32 if err := perunio.Decode(r, &mapLen); err != nil { @@ -110,6 +113,7 @@ func (ids *IDMap) Decode(r stdio.Reader) error { return nil } +// IDKey returns a string representation of the IDMap. func IDKey(ids IDMap) string { var buff strings.Builder length := int32(len(ids)) @@ -144,6 +148,7 @@ func sortIDMap(ids IDMap) ([]wallet.BackendID, []ID) { return sortedIndexes, sortedIDs } +// FromIDKey decodes an IDMap from a string representation. func FromIDKey(k string) IDMap { buff := bytes.NewBuffer([]byte(k)) var numElements int32 diff --git a/channel/persistence/test/channel.go b/channel/persistence/test/channel.go index 335c2e57a..ce45e8a70 100644 --- a/channel/persistence/test/channel.go +++ b/channel/persistence/test/channel.go @@ -91,7 +91,7 @@ func NewRandomChannel( func requireEqualPeers(t require.TestingT, expected, actual []map[wallet.BackendID]wire.Address) { require.Equal(t, len(expected), len(actual)) for i, p := range expected { - if !EqualWireMaps(p, actual[i]) { + if !channel.EqualWireMaps(p, actual[i]) { t.Errorf("restored peers for channel do not match\nexpected: %v\nactual: %v", actual, expected) t.FailNow() @@ -99,18 +99,6 @@ func requireEqualPeers(t require.TestingT, expected, actual []map[wallet.Backend } } -func EqualWireMaps(a, b map[wallet.BackendID]wire.Address) bool { - if len(a) != len(b) { - return false - } - for i, addr := range a { - if !addr.Equal(b[i]) { - return false - } - } - return true -} - // AssertPersisted reads the channel state from the restorer and compares it // to the actual channel state. If an error occurs while restoring the channel // or if the restored channel does not match the actual channel state, then the diff --git a/channel/persistence/test/persistrestorertest.go b/channel/persistence/test/persistrestorertest.go index 075728830..6f66aaf26 100644 --- a/channel/persistence/test/persistrestorertest.go +++ b/channel/persistence/test/persistrestorertest.go @@ -187,7 +187,7 @@ func GenericPersistRestorerTest( peerLoop: for idx, addr := range peers { for _, paddr := range persistedPeers { - if EqualWireMaps(addr, paddr) { + if channel.EqualWireMaps(addr, paddr) { continue peerLoop // found, next address } } diff --git a/channel/state.go b/channel/state.go index 1a01ddbe1..3d8dfeb8b 100644 --- a/channel/state.go +++ b/channel/state.go @@ -162,6 +162,7 @@ func (s *State) ToSubAlloc() *SubAlloc { return NewSubAlloc(s.ID, s.Allocation.Sum(), nil) } +// EqualWireMaps compares two wire.Address maps for equality. func EqualWireMaps(a, b map[wallet.BackendID]wire.Address) bool { if len(a) != len(b) { return false diff --git a/channel/test/randomizer.go b/channel/test/randomizer.go index e9082badf..116858d55 100644 --- a/channel/test/randomizer.go +++ b/channel/test/randomizer.go @@ -140,9 +140,9 @@ func NewRandomLockedIDs(rng *rand.Rand, opts ...RandomOpt) []map[wallet.BackendI for i := range ids { for j := range bIds { ids[i] = make(map[wallet.BackendID]channel.ID) - cId := [32]byte{} - rng.Read(cId[:]) - ids[i][wallet.BackendID(j)] = cId + cID := [32]byte{} + rng.Read(cID[:]) + ids[i][wallet.BackendID(j)] = cID } } return ids @@ -152,14 +152,14 @@ func NewRandomLockedIDs(rng *rand.Rand, opts ...RandomOpt) []map[wallet.BackendI for i := range ids { if err != nil { ids[i] = make(map[wallet.BackendID]channel.ID) - cId := [32]byte{} - rng.Read(cId[:]) - ids[i][0] = cId + cID := [32]byte{} + rng.Read(cID[:]) + ids[i][0] = cID } else { ids[i] = make(map[wallet.BackendID]channel.ID) - cId := [32]byte{} - rng.Read(cId[:]) - ids[i][b] = cId + cID := [32]byte{} + rng.Read(cID[:]) + ids[i][b] = cID } } return ids @@ -267,21 +267,21 @@ func NewRandomChannelID(rng *rand.Rand, opts ...RandomOpt) (id map[wallet.Backen bIds, err := opt.BackendID() if bIds != nil && err == nil { for _, b := range bIds { - cId := [32]byte{} - rng.Read(cId[:]) - id[b] = cId + cID := [32]byte{} + rng.Read(cID[:]) + id[b] = cID } return } bId, err := opt.Backend() if err != nil { - cId := [32]byte{} - rng.Read(cId[:]) - id[0] = cId + cID := [32]byte{} + rng.Read(cID[:]) + id[0] = cID } else { - cId := [32]byte{} - rng.Read(cId[:]) - id[bId] = cId + cID := [32]byte{} + rng.Read(cID[:]) + id[bId] = cID } return } diff --git a/client/test/backend.go b/client/test/backend.go index f4fa401cf..e2265a503 100644 --- a/client/test/backend.go +++ b/client/test/backend.go @@ -61,10 +61,12 @@ type ( LedgerID string ) -func (id AssetID) LedgerId() multi.LedgerID { +// LedgerID returns the ledger identifier. +func (id AssetID) LedgerID() multi.LedgerID { return id.ledgerID } +// BackendID returns the backend identifier. func (id AssetID) BackendID() uint32 { return id.backendID } diff --git a/client/test/multiledger.go b/client/test/multiledger.go index d1537e8af..aae3a858d 100644 --- a/client/test/multiledger.go +++ b/client/test/multiledger.go @@ -96,6 +96,7 @@ type MultiLedgerAsset struct { asset channel.Asset } +// AssetID returns the asset's ID. func (a *MultiLedgerAsset) AssetID() multi.AssetID { return a.id } @@ -115,7 +116,7 @@ func (a *MultiLedgerAsset) Equal(b channel.Asset) bool { return false } - return a.id.LedgerId().MapKey() == bm.id.LedgerId().MapKey() && a.asset.Equal(bm.asset) && a.id.BackendID() == bm.id.BackendID() + return a.id.LedgerID().MapKey() == bm.id.LedgerID().MapKey() && a.asset.Equal(bm.asset) && a.id.BackendID() == bm.id.BackendID() } // Address returns the asset's address. @@ -131,7 +132,7 @@ func (a *MultiLedgerAsset) LedgerID() multi.AssetID { // MarshalBinary encodes the asset to its byte representation. func (a *MultiLedgerAsset) MarshalBinary() ([]byte, error) { var buf bytes.Buffer - err := perunio.Encode(&buf, string(a.id.LedgerId().MapKey()), a.id.BackendID(), a.asset) + err := perunio.Encode(&buf, string(a.id.LedgerID().MapKey()), a.id.BackendID(), a.asset) if err != nil { return nil, err } @@ -142,7 +143,7 @@ func (a *MultiLedgerAsset) MarshalBinary() ([]byte, error) { // UnmarshalBinary decodes the asset from its byte representation. func (a *MultiLedgerAsset) UnmarshalBinary(data []byte) error { buf := bytes.NewBuffer(data) - return perunio.Decode(buf, string(a.id.LedgerId().MapKey()), a.id.BackendID(), a.asset) + return perunio.Decode(buf, string(a.id.LedgerID().MapKey()), a.id.BackendID(), a.asset) } // MultiLedgerClient represents a test client. diff --git a/wire/address.go b/wire/address.go index 09ec9d72f..320729643 100644 --- a/wire/address.go +++ b/wire/address.go @@ -192,6 +192,7 @@ func Keys(addressMap map[wallet.BackendID]Address) AddrKey { return AddrKey(strings.Join(keyParts, "|")) } +// AddressMapfromAccountMap converts a map of accounts to a map of addresses. func AddressMapfromAccountMap(accs map[wallet.BackendID]Account) map[wallet.BackendID]Address { addresses := make(map[wallet.BackendID]Address) for id, a := range accs { diff --git a/wire/net/endpoint_registry.go b/wire/net/endpoint_registry.go index ca09d83ec..b7bf7d8d6 100644 --- a/wire/net/endpoint_registry.go +++ b/wire/net/endpoint_registry.go @@ -21,7 +21,8 @@ import ( "time" "unsafe" - "perun.network/go-perun/channel/persistence/test" + "perun.network/go-perun/channel" + "perun.network/go-perun/wallet" "github.com/pkg/errors" @@ -178,7 +179,7 @@ func (r *EndpointRegistry) setupConn(conn Conn) error { return err } - if test.EqualWireMaps(peerAddr, wire.AddressMapfromAccountMap(r.id)) { + if channel.EqualWireMaps(peerAddr, wire.AddressMapfromAccountMap(r.id)) { r.Log().Error("dialed by self") return errors.New("dialed by self") } @@ -194,7 +195,7 @@ func (r *EndpointRegistry) Endpoint(ctx context.Context, addr map[wallet.Backend log := r.Log().WithField("peer", addr) key := wire.Keys(addr) - if test.EqualWireMaps(addr, wire.AddressMapfromAccountMap(r.id)) { + if channel.EqualWireMaps(addr, wire.AddressMapfromAccountMap(r.id)) { log.Panic("tried to dial self") } diff --git a/wire/net/exchange_addr.go b/wire/net/exchange_addr.go index ca32bbca6..54a97235f 100644 --- a/wire/net/exchange_addr.go +++ b/wire/net/exchange_addr.go @@ -18,7 +18,8 @@ import ( "context" "fmt" - "perun.network/go-perun/channel/persistence/test" + "perun.network/go-perun/channel" + "perun.network/go-perun/wallet" "github.com/pkg/errors" @@ -86,8 +87,8 @@ func ExchangeAddrsActive(ctx context.Context, id map[wallet.BackendID]wire.Accou if check := VerifyAddressSignature(peer, msg.Signature); check != nil { err = errors.WithMessage(check, "verifying peer address's signature") } - } else if !test.EqualWireMaps(e.Recipient, wire.AddressMapfromAccountMap(id)) && - !test.EqualWireMaps(e.Sender, peer) { + } else if !channel.EqualWireMaps(e.Recipient, wire.AddressMapfromAccountMap(id)) && + !channel.EqualWireMaps(e.Sender, peer) { err = NewAuthenticationError(e.Sender, e.Recipient, wire.AddressMapfromAccountMap(id), "unmatched response sender or recipient") } }) @@ -112,7 +113,7 @@ func ExchangeAddrsPassive(ctx context.Context, id map[wallet.BackendID]wire.Acco err = errors.WithMessage(err, "receiving auth message") } else if _, ok := e.Msg.(*wire.AuthResponseMsg); !ok { err = errors.Errorf("expected AuthResponse wire msg, got %v", e.Msg.Type()) - } else if !test.EqualWireMaps(e.Recipient, addrs) { + } else if !channel.EqualWireMaps(e.Recipient, addrs) { err = NewAuthenticationError(e.Sender, e.Recipient, wire.AddressMapfromAccountMap(id), "unmatched response sender or recipient") } else if msg, ok := e.Msg.(*wire.AuthResponseMsg); ok { if err = VerifyAddressSignature(e.Sender, msg.Signature); err != nil { diff --git a/wire/net/test/listenermap.go b/wire/net/test/listenermap.go index 12dde418b..19515bce3 100644 --- a/wire/net/test/listenermap.go +++ b/wire/net/test/listenermap.go @@ -17,7 +17,8 @@ package test import ( "sync" - "perun.network/go-perun/channel/persistence/test" + "perun.network/go-perun/channel" + "perun.network/go-perun/wallet" "github.com/pkg/errors" @@ -40,7 +41,7 @@ type listenerMap struct { // other functions. func (m *listenerMap) findEntry(key map[wallet.BackendID]wire.Address) (listenerMapEntry, int, bool) { for i, v := range m.entries { - if test.EqualWireMaps(v.key, key) { + if channel.EqualWireMaps(v.key, key) { return v, i, true } } From 2d9897521940c6198ebc5c6808f836e1f300121a Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Mon, 23 Dec 2024 09:15:09 +0100 Subject: [PATCH 29/36] chore: Rename variables Signed-off-by: Sophia Koehler --- channel/test/randomizer.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/channel/test/randomizer.go b/channel/test/randomizer.go index 116858d55..e34ad7ee2 100644 --- a/channel/test/randomizer.go +++ b/channel/test/randomizer.go @@ -134,11 +134,11 @@ func NewRandomLockedIDs(rng *rand.Rand, opts ...RandomOpt) []map[wallet.BackendI return ids } numLockedIds := opt.NumLocked(rng) - bIds, err := opt.BackendID() - if err == nil && bIds != nil { + bIDs, err := opt.BackendID() + if err == nil && bIDs != nil { ids := make([]map[wallet.BackendID]channel.ID, numLockedIds) for i := range ids { - for j := range bIds { + for j := range bIDs { ids[i] = make(map[wallet.BackendID]channel.ID) cID := [32]byte{} rng.Read(cID[:]) @@ -264,16 +264,16 @@ func NewRandomChannelID(rng *rand.Rand, opts ...RandomOpt) (id map[wallet.Backen return id } id = make(map[wallet.BackendID]channel.ID) - bIds, err := opt.BackendID() - if bIds != nil && err == nil { - for _, b := range bIds { + bIDs, err := opt.BackendID() + if bIDs != nil && err == nil { + for _, b := range bIDs { cID := [32]byte{} rng.Read(cID[:]) id[b] = cID } return } - bId, err := opt.Backend() + bID, err := opt.Backend() if err != nil { cID := [32]byte{} rng.Read(cID[:]) @@ -281,7 +281,7 @@ func NewRandomChannelID(rng *rand.Rand, opts ...RandomOpt) (id map[wallet.Backen } else { cID := [32]byte{} rng.Read(cID[:]) - id[bId] = cID + id[bID] = cID } return } From d463e822db12182a73d0ca478f67cb5dd3265eb4 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Mon, 23 Dec 2024 12:25:11 +0100 Subject: [PATCH 30/36] fix(params, address): Fix index allocation Signed-off-by: Sophia Koehler --- channel/params.go | 4 ++-- wire/address.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/channel/params.go b/channel/params.go index b04708fb7..39c00c763 100644 --- a/channel/params.go +++ b/channel/params.go @@ -134,9 +134,9 @@ func IDKey(ids IDMap) string { } func sortIDMap(ids IDMap) ([]wallet.BackendID, []ID) { - indexes := make([]int, len(ids)) + var indexes []int //nolint:prealloc for i := range ids { - indexes[i] = int(i) + indexes = append(indexes, int(i)) } sort.Ints(indexes) sortedIndexes := make([]wallet.BackendID, len(indexes)) diff --git a/wire/address.go b/wire/address.go index 320729643..48df14996 100644 --- a/wire/address.go +++ b/wire/address.go @@ -178,9 +178,9 @@ func Key(a Address) AddrKey { // Keys returns the `AddrKey` corresponding to the passed `map[int]Address`. func Keys(addressMap map[wallet.BackendID]Address) AddrKey { - indexes := make([]int, len(addressMap)) + var indexes []int //nolint:prealloc for i := range addressMap { - indexes[i] = int(i) + indexes = append(indexes, int(i)) } sort.Ints(indexes) From 7169c295c6fc6f41423a8378b829e6547c8d5c93 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Mon, 20 Jan 2025 08:03:13 +0100 Subject: [PATCH 31/36] refactor(/apps/payment, /sim/wallet, /channel, /client, /wallet, /wire): Name test backend ID in tests refactor(/multi, /client/test): Rename AssetID to MultiLedgerID Signed-off-by: Sophia Koehler --- apps/payment/app_internal_test.go | 2 +- apps/payment/randomizer_internal_test.go | 2 +- apps/payment/resolver_internal_test.go | 2 +- backend/sim/wallet/address.go | 4 ++- backend/sim/wallet/wallet.go | 23 +++++-------- channel/allocation_test.go | 18 +++++----- channel/backendtest.go | 7 ++-- channel/errors_internal_test.go | 8 ++--- channel/machine_test.go | 4 +-- channel/multi/adjudicator.go | 18 +++++----- channel/multi/asset.go | 26 +++++++------- channel/multi/funder.go | 36 ++++++++++---------- channel/params.go | 1 - channel/persistence/statemachine_test.go | 2 +- channel/persistence/test/channel.go | 4 +-- channel/test/app_randomizer.go | 2 +- channel/test/randomizer.go | 6 ++-- client/appchannel_test.go | 8 ++--- client/client_persistence_test.go | 4 ++- client/client_role_test.go | 6 ++-- client/client_test.go | 10 +++--- client/failing_funding_test.go | 4 +-- client/payment_test.go | 10 +++--- client/proposal.go | 4 +-- client/restore_internal_test.go | 12 +++---- client/subchannel_test.go | 14 ++++---- client/test/backend.go | 6 ++-- client/test/multiledger.go | 20 +++++------ client/test/multiledger_dispute.go | 4 +-- client/test/multiledger_happy.go | 2 +- client/virtual_channel_test.go | 8 +++-- log/logrus/logrus_internal_test.go | 5 ++- wallet/address_test.go | 19 ++++++----- wire/net/endpoint_internal_test.go | 2 +- wire/net/endpoint_registry_external_test.go | 8 ++--- wire/net/endpoint_registry_internal_test.go | 26 +++++++------- wire/net/exchange_addr_internal_test.go | 8 ++--- wire/net/simple/address.go | 5 ++- wire/net/simple/dialer_internal_test.go | 8 +++-- wire/net/simple/simple_exchange_addr_test.go | 8 ++--- wire/net/test/connhub_internal_test.go | 4 ++- wire/test/bustest.go | 7 ++-- wire/test/msgstest.go | 2 +- wire/test/randomizer.go | 2 +- 44 files changed, 204 insertions(+), 177 deletions(-) diff --git a/apps/payment/app_internal_test.go b/apps/payment/app_internal_test.go index 01eb8f477..aab9a32f3 100644 --- a/apps/payment/app_internal_test.go +++ b/apps/payment/app_internal_test.go @@ -27,7 +27,7 @@ import ( func TestApp_Def(t *testing.T) { rng := pkgtest.Prng(t) - def := test.NewRandomAppID(rng, 0) + def := test.NewRandomAppID(rng, channel.TestBackendID) app := &App{def} assert.True(t, app.Def().Equal(app.Def())) } diff --git a/apps/payment/randomizer_internal_test.go b/apps/payment/randomizer_internal_test.go index d6177fd1e..071964639 100644 --- a/apps/payment/randomizer_internal_test.go +++ b/apps/payment/randomizer_internal_test.go @@ -28,7 +28,7 @@ func TestRandomizer(t *testing.T) { rng := pkgtest.Prng(t) r := new(Randomizer) - app := r.NewRandomApp(rng, 0) + app := r.NewRandomApp(rng, channel.TestBackendID) channel.RegisterApp(app) regApp, err := channel.Resolve(app.Def()) assert.NoError(t, err) diff --git a/apps/payment/resolver_internal_test.go b/apps/payment/resolver_internal_test.go index 5a63afc79..8bc9f7c4b 100644 --- a/apps/payment/resolver_internal_test.go +++ b/apps/payment/resolver_internal_test.go @@ -32,7 +32,7 @@ func TestResolver(t *testing.T) { rng := pkgtest.Prng(t) assert, require := assert.New(t), require.New(t) - def := ctest.NewRandomAppID(rng, 0) + def := ctest.NewRandomAppID(rng, channel.TestBackendID) channel.RegisterAppResolver(def.Equal, &Resolver{}) app, err := channel.Resolve(def) diff --git a/backend/sim/wallet/address.go b/backend/sim/wallet/address.go index 91b7dcf12..8a3692456 100644 --- a/backend/sim/wallet/address.go +++ b/backend/sim/wallet/address.go @@ -20,6 +20,8 @@ import ( "io" "math/big" + "perun.network/go-perun/channel" + "perun.network/go-perun/log" "perun.network/go-perun/wallet" ) @@ -67,7 +69,7 @@ func NewRandomAddresses(rng io.Reader) map[int]wallet.Address { log.Panicf("Creation of account failed with error", err) } - return map[int]wallet.Address{0: &Address{ + return map[int]wallet.Address{channel.TestBackendID: &Address{ Curve: privateKey.Curve, X: privateKey.X, Y: privateKey.Y, diff --git a/backend/sim/wallet/wallet.go b/backend/sim/wallet/wallet.go index e34f42fa4..0cd2e9b1f 100644 --- a/backend/sim/wallet/wallet.go +++ b/backend/sim/wallet/wallet.go @@ -64,8 +64,7 @@ type Wallet struct { func (w *Wallet) Unlock(a wallet.Address) (wallet.Account, error) { w.accMutex.RLock() defer w.accMutex.RUnlock() - key := wallet.Key(a) - acc, ok := w.accs[key] + acc, ok := w.accs[wallet.Key(a)] if !ok { return nil, errors.Errorf("unlock unknown address: %v", a) } @@ -90,8 +89,7 @@ func (w *Wallet) LockAll() { func (w *Wallet) IncrementUsage(a wallet.Address) { w.accMutex.RLock() defer w.accMutex.RUnlock() - key := wallet.Key(a) - acc, ok := w.accs[key] + acc, ok := w.accs[wallet.Key(a)] if !ok { panic("invalid address") } @@ -106,8 +104,7 @@ func (w *Wallet) IncrementUsage(a wallet.Address) { func (w *Wallet) DecrementUsage(a wallet.Address) { w.accMutex.Lock() defer w.accMutex.Unlock() - key := wallet.Key(a) - acc, ok := w.accs[key] + acc, ok := w.accs[wallet.Key(a)] if !ok { panic("invalid address") } @@ -119,7 +116,7 @@ func (w *Wallet) DecrementUsage(a wallet.Address) { if newCount == 0 { acc.locked.Set() - delete(w.accs, key) + delete(w.accs, wallet.Key(a)) } } @@ -129,8 +126,7 @@ func (w *Wallet) DecrementUsage(a wallet.Address) { func (w *Wallet) UsageCount(a wallet.Address) int { w.accMutex.RLock() defer w.accMutex.RUnlock() - key := wallet.Key(a) - acc, ok := w.accs[key] + acc, ok := w.accs[wallet.Key(a)] if !ok { panic("invalid address") } @@ -153,15 +149,13 @@ func (w *Wallet) NewRandomAccount(rng *rand.Rand) wallet.Account { // account was already registered beforehand, an error is returned. Does not // lock or unlock the account. func (w *Wallet) AddAccount(acc *Account) error { - key := wallet.Key(acc.Address()) - w.accMutex.Lock() defer w.accMutex.Unlock() - if _, ok := w.accs[key]; ok { + if _, ok := w.accs[wallet.Key(acc.Address())]; ok { return errors.New("duplicate insertion") } - w.accs[key] = acc + w.accs[wallet.Key(acc.Address())] = acc return nil } @@ -171,7 +165,6 @@ func (w *Wallet) AddAccount(acc *Account) error { func (w *Wallet) HasAccount(acc *Account) bool { w.accMutex.RLock() defer w.accMutex.RUnlock() - key := wallet.Key(acc.Address()) - _, ok := w.accs[key] + _, ok := w.accs[wallet.Key(acc.Address())] return ok } diff --git a/channel/allocation_test.go b/channel/allocation_test.go index fe9f07804..2372f81f0 100644 --- a/channel/allocation_test.go +++ b/channel/allocation_test.go @@ -279,7 +279,7 @@ func TestAllocationValidLimits(t *testing.T) { allocation.Assets = test.NewRandomAssets(rng, test.WithNumAssets(x.numAssets)) for i := range allocation.Assets { - allocation.Backends[i] = 0 + allocation.Backends[i] = channel.TestBackendID } for i := range allocation.Balances { @@ -291,12 +291,12 @@ func TestAllocationValidLimits(t *testing.T) { for i := range allocation.Locked { allocation.Locked[i] = *channel.NewSubAlloc( - map[wallet.BackendID]channel.ID{0: {byte(i), byte(i >> 8), byte(i >> 16), byte(i >> 24)}}, + map[wallet.BackendID]channel.ID{channel.TestBackendID: {byte(i), byte(i >> 8), byte(i >> 16), byte(i >> 24)}}, make([]channel.Bal, x.numAssets), nil, ) allocation.Locked[i] = *channel.NewSubAlloc( - map[wallet.BackendID]channel.ID{0: {byte(i), byte(i >> 8), byte(i >> 16), byte(i >> 24)}}, + map[wallet.BackendID]channel.ID{channel.TestBackendID: {byte(i), byte(i >> 8), byte(i >> 16), byte(i >> 24)}}, make([]channel.Bal, x.numAssets), nil, ) @@ -500,7 +500,7 @@ func TestAllocation_Valid(t *testing.T) { {big.NewInt(64), big.NewInt(128)}, }, Locked: []channel.SubAlloc{ - *channel.NewSubAlloc(map[wallet.BackendID]channel.ID{0: channel.Zero}, []channel.Bal{big.NewInt(4)}, nil), + *channel.NewSubAlloc(map[wallet.BackendID]channel.ID{channel.TestBackendID: channel.Zero}, []channel.Bal{big.NewInt(4)}, nil), }, }, false, @@ -516,7 +516,7 @@ func TestAllocation_Valid(t *testing.T) { {big.NewInt(64), big.NewInt(128)}, }, Locked: []channel.SubAlloc{ - *channel.NewSubAlloc(map[wallet.BackendID]channel.ID{0: channel.Zero}, []channel.Bal{big.NewInt(-1)}, nil), + *channel.NewSubAlloc(map[wallet.BackendID]channel.ID{channel.TestBackendID: channel.Zero}, []channel.Bal{big.NewInt(-1)}, nil), }, }, false, @@ -544,7 +544,7 @@ func TestAllocation_Valid(t *testing.T) { {big.NewInt(2), big.NewInt(16)}, }, Locked: []channel.SubAlloc{ - *channel.NewSubAlloc(map[wallet.BackendID]channel.ID{0: channel.Zero}, []channel.Bal{big.NewInt(4), big.NewInt(-1)}, nil), + *channel.NewSubAlloc(map[wallet.BackendID]channel.ID{channel.TestBackendID: channel.Zero}, []channel.Bal{big.NewInt(4), big.NewInt(-1)}, nil), }, }, false, @@ -564,9 +564,9 @@ func TestAllocation_Valid(t *testing.T) { // suballocation serialization. func TestSuballocSerialization(t *testing.T) { ss := []perunio.Serializer{ - channel.NewSubAlloc(map[wallet.BackendID]channel.ID{0: {2}}, []channel.Bal{}, nil), - channel.NewSubAlloc(map[wallet.BackendID]channel.ID{0: {3}}, []channel.Bal{big.NewInt(0)}, nil), - channel.NewSubAlloc(map[wallet.BackendID]channel.ID{0: {4}}, []channel.Bal{big.NewInt(5), big.NewInt(1 << 62)}, nil), + channel.NewSubAlloc(map[wallet.BackendID]channel.ID{channel.TestBackendID: {2}}, []channel.Bal{}, nil), + channel.NewSubAlloc(map[wallet.BackendID]channel.ID{channel.TestBackendID: {3}}, []channel.Bal{big.NewInt(0)}, nil), + channel.NewSubAlloc(map[wallet.BackendID]channel.ID{channel.TestBackendID: {4}}, []channel.Bal{big.NewInt(5), big.NewInt(1 << 62)}, nil), } peruniotest.GenericSerializerTest(t, ss...) diff --git a/channel/backendtest.go b/channel/backendtest.go index 81b1a661c..a0f0570ec 100644 --- a/channel/backendtest.go +++ b/channel/backendtest.go @@ -21,10 +21,13 @@ import ( "github.com/stretchr/testify/require" ) +// TestBackendID is the identifier for the simulated Backend. +const TestBackendID = 0 + // SetBackendTest is a generic backend test. func SetBackendTest(t *testing.T) { t.Helper() - assert.Panics(t, func() { SetBackend(nil, 0) }, "nil backend set should panic") + assert.Panics(t, func() { SetBackend(nil, TestBackendID) }, "nil backend set should panic") require.NotNil(t, backend, "backend should be already set by init()") - assert.Panics(t, func() { SetBackend(backend[0], 0) }, "setting a backend twice should panic") + assert.Panics(t, func() { SetBackend(backend[TestBackendID], TestBackendID) }, "setting a backend twice should panic") } diff --git a/channel/errors_internal_test.go b/channel/errors_internal_test.go index d3cdfb3e1..45abae8b8 100644 --- a/channel/errors_internal_test.go +++ b/channel/errors_internal_test.go @@ -25,14 +25,14 @@ import ( func TestTransitionErrors(t *testing.T) { assert.False(t, IsStateTransitionError(errors.New("No StateTransitionError"))) - assert.True(t, IsStateTransitionError(NewStateTransitionError(map[wallet.BackendID]ID{0: Zero}, "A StateTransitionError"))) + assert.True(t, IsStateTransitionError(NewStateTransitionError(map[wallet.BackendID]ID{TestBackendID: Zero}, "A StateTransitionError"))) assert.False(t, IsActionError(errors.New("No ActionError"))) - assert.True(t, IsActionError(NewActionError(map[wallet.BackendID]ID{0: Zero}, "An ActionError"))) + assert.True(t, IsActionError(NewActionError(map[wallet.BackendID]ID{TestBackendID: Zero}, "An ActionError"))) assert.False(t, IsPhaseTransitionError(errors.New("No PhaseTransitionError"))) assert.True(t, IsPhaseTransitionError(newPhaseTransitionError( - map[wallet.BackendID]ID{0: Zero}, InitActing, PhaseTransition{InitActing, InitActing}, "A PhaseTransitionError"))) + map[wallet.BackendID]ID{TestBackendID: Zero}, InitActing, PhaseTransition{InitActing, InitActing}, "A PhaseTransitionError"))) assert.True(t, IsPhaseTransitionError(newPhaseTransitionErrorf( - map[wallet.BackendID]ID{0: Zero}, InitActing, PhaseTransition{InitActing, InitActing}, "A %s", "PhaseTransitionError"))) + map[wallet.BackendID]ID{TestBackendID: Zero}, InitActing, PhaseTransition{InitActing, InitActing}, "A %s", "PhaseTransitionError"))) } diff --git a/channel/machine_test.go b/channel/machine_test.go index 86e6020b2..ec7621930 100644 --- a/channel/machine_test.go +++ b/channel/machine_test.go @@ -29,8 +29,8 @@ import ( func TestMachineClone(t *testing.T) { rng := pkgtest.Prng(t) - acc := wtest.NewRandomAccountMapSlice(rng, 0, 1) - params := *test.NewRandomParams(rng, test.WithFirstPart(map[wallet.BackendID]wallet.Address{0: acc[0][0].Address()})) + acc := wtest.NewRandomAccountMapSlice(rng, channel.TestBackendID, 1) + params := *test.NewRandomParams(rng, test.WithFirstPart(map[wallet.BackendID]wallet.Address{channel.TestBackendID: acc[0][channel.TestBackendID].Address()})) sm, err := channel.NewStateMachine(acc[0], params) require.NoError(t, err) diff --git a/channel/multi/adjudicator.go b/channel/multi/adjudicator.go index c1c9b1e7c..a7b03922b 100644 --- a/channel/multi/adjudicator.go +++ b/channel/multi/adjudicator.go @@ -23,25 +23,25 @@ import ( // Adjudicator is a multi-ledger adjudicator. type Adjudicator struct { - adjudicators map[AssetIDKey]channel.Adjudicator + adjudicators map[MultiLedgerIDKey]channel.Adjudicator } // NewAdjudicator creates a new adjudicator. func NewAdjudicator() *Adjudicator { return &Adjudicator{ - adjudicators: make(map[AssetIDKey]channel.Adjudicator), + adjudicators: make(map[MultiLedgerIDKey]channel.Adjudicator), } } // RegisterAdjudicator registers an adjudicator for a given ledger. -func (a *Adjudicator) RegisterAdjudicator(l AssetID, la channel.Adjudicator) { - key := AssetIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} +func (a *Adjudicator) RegisterAdjudicator(l MultiLedgerID, la channel.Adjudicator) { + key := MultiLedgerIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} a.adjudicators[key] = la } // LedgerAdjudicator returns the adjudicator for a given ledger. -func (a *Adjudicator) LedgerAdjudicator(l AssetID) (channel.Adjudicator, bool) { - key := AssetIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} +func (a *Adjudicator) LedgerAdjudicator(l MultiLedgerID) (channel.Adjudicator, bool) { + key := MultiLedgerIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} adj, ok := a.adjudicators[key] return adj, ok } @@ -92,13 +92,13 @@ func (a *Adjudicator) Withdraw(ctx context.Context, req channel.AdjudicatorReq, } // dispatch dispatches an adjudicator call on all given ledgers. -func (a *Adjudicator) dispatch(assetIds []AssetID, f func(channel.Adjudicator) error) error { +func (a *Adjudicator) dispatch(assetIds []MultiLedgerID, f func(channel.Adjudicator) error) error { n := len(assetIds) errs := make(chan error, n) for _, l := range assetIds { - go func(l AssetID) { + go func(l MultiLedgerID) { err := func() error { - key := AssetIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} + key := MultiLedgerIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} adjs, ok := a.adjudicators[key] if !ok { return fmt.Errorf("adjudicator not found for id %v", l) diff --git a/channel/multi/asset.go b/channel/multi/asset.go index fc731cbbc..65a6dc9ec 100644 --- a/channel/multi/asset.go +++ b/channel/multi/asset.go @@ -21,14 +21,16 @@ import ( ) type ( - // Asset defines a multi-ledger asset. + // Asset defines a multi-ledger asset, extending channel.asset by a method MultiLedgerID() which returns the LedgerID and BackendID. Asset interface { channel.Asset - AssetID() AssetID + MultiLedgerID() MultiLedgerID } - // AssetID represents an asset identifier. - AssetID interface { + // MultiLedgerID represents an asset identifier. + // BackendID returns the identifier of the backend the asset belongs to. + // LedgerID returns the identifier of the ledger the asset belongs to. + MultiLedgerID interface { BackendID() uint32 LedgerID() LedgerID } @@ -45,19 +47,19 @@ type ( ) // LedgerIDs returns the identifiers of the associated ledgers. -func (a assets) LedgerIDs() ([]AssetID, error) { - ids := make(map[AssetIDKey]AssetID) +func (a assets) LedgerIDs() ([]MultiLedgerID, error) { + ids := make(map[MultiLedgerIDKey]MultiLedgerID) for _, asset := range a { ma, ok := asset.(Asset) if !ok { return nil, fmt.Errorf("wrong asset type: expected Asset, got %T", asset) } - assetID := ma.AssetID() + assetID := ma.MultiLedgerID() - ids[AssetIDKey{BackendID: assetID.BackendID(), LedgerID: string(assetID.LedgerID().MapKey())}] = assetID + ids[MultiLedgerIDKey{BackendID: assetID.BackendID(), LedgerID: string(assetID.LedgerID().MapKey())}] = assetID } - idsArray := make([]AssetID, len(ids)) + idsArray := make([]MultiLedgerID, len(ids)) i := 0 for _, v := range ids { idsArray[i] = v @@ -70,7 +72,7 @@ func (a assets) LedgerIDs() ([]AssetID, error) { // IsMultiLedgerAssets returns whether the assets are from multiple ledgers. func IsMultiLedgerAssets(assets []channel.Asset) bool { hasMulti := false - var id AssetID + var id MultiLedgerID for _, asset := range assets { multiAsset, ok := asset.(Asset) switch { @@ -78,8 +80,8 @@ func IsMultiLedgerAssets(assets []channel.Asset) bool { continue case !hasMulti: hasMulti = true - id = multiAsset.AssetID() - case id.LedgerID().MapKey() != multiAsset.AssetID().LedgerID().MapKey(): + id = multiAsset.MultiLedgerID() + case id.LedgerID().MapKey() != multiAsset.MultiLedgerID().LedgerID().MapKey(): return true } } diff --git a/channel/multi/funder.go b/channel/multi/funder.go index c54d4b9c9..b836b03b4 100644 --- a/channel/multi/funder.go +++ b/channel/multi/funder.go @@ -22,8 +22,8 @@ import ( "perun.network/go-perun/channel" ) -// AssetIDKey is a representation of AssetID that kan be used in map lookups. -type AssetIDKey struct { +// MultiLedgerIDKey is a representation of MultiLedgerID that kan be used in map lookups. +type MultiLedgerIDKey struct { BackendID uint32 LedgerID string } @@ -32,28 +32,28 @@ type AssetIDKey struct { // funders is a map of LedgerIDs corresponding to a funder on some chain. // egoisticChains is a map of LedgerIDs corresponding to a boolean indicating whether the chain should be funded last. type Funder struct { - funders map[AssetIDKey]channel.Funder - egoisticChains map[AssetIDKey]bool + funders map[MultiLedgerIDKey]channel.Funder + egoisticChains map[MultiLedgerIDKey]bool } // NewFunder creates a new funder. func NewFunder() *Funder { return &Funder{ - funders: make(map[AssetIDKey]channel.Funder), - egoisticChains: make(map[AssetIDKey]bool), + funders: make(map[MultiLedgerIDKey]channel.Funder), + egoisticChains: make(map[MultiLedgerIDKey]bool), } } // RegisterFunder registers a funder for a given ledger. -func (f *Funder) RegisterFunder(l AssetID, lf channel.Funder) { - key := AssetIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} +func (f *Funder) RegisterFunder(l MultiLedgerID, lf channel.Funder) { + key := MultiLedgerIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} f.funders[key] = lf f.egoisticChains[key] = false } // SetEgoisticChain sets the egoistic chain flag for a given ledger. -func (f *Funder) SetEgoisticChain(l AssetID, id int, egoistic bool) { - key := AssetIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} +func (f *Funder) SetEgoisticChain(l MultiLedgerID, id int, egoistic bool) { + key := MultiLedgerIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} f.egoisticChains[key] = egoistic } @@ -66,16 +66,16 @@ func (f *Funder) Fund(ctx context.Context, request channel.FundingReq) error { ctx, cancel := context.WithTimeout(ctx, d) defer cancel() - assetIDs, err := assets(request.State.Assets).LedgerIDs() + ledgerIDs, err := assets(request.State.Assets).LedgerIDs() if err != nil { return err } - var egoisticLedgers []AssetID - var nonEgoisticLedgers []AssetID + var egoisticLedgers []MultiLedgerID + var nonEgoisticLedgers []MultiLedgerID - for _, l := range assetIDs { - key := AssetIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} + for _, l := range ledgerIDs { + key := MultiLedgerIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} if f.egoisticChains[key] { egoisticLedgers = append(egoisticLedgers, l) } else { @@ -98,7 +98,7 @@ func (f *Funder) Fund(ctx context.Context, request channel.FundingReq) error { return nil } -func fundLedgers(ctx context.Context, request channel.FundingReq, assetIDs []AssetID, funders map[AssetIDKey]channel.Funder) error { +func fundLedgers(ctx context.Context, request channel.FundingReq, assetIDs []MultiLedgerID, funders map[MultiLedgerIDKey]channel.Funder) error { // Calculate the total number of funders n := len(assetIDs) @@ -106,8 +106,8 @@ func fundLedgers(ctx context.Context, request channel.FundingReq, assetIDs []Ass // Iterate over blockchains to get the LedgerIDs for _, assetID := range assetIDs { - go func(assetID AssetID) { - key := AssetIDKey{BackendID: assetID.BackendID(), LedgerID: string(assetID.LedgerID().MapKey())} + go func(assetID MultiLedgerID) { + key := MultiLedgerIDKey{BackendID: assetID.BackendID(), LedgerID: string(assetID.LedgerID().MapKey())} // Get the Funder from the funders map funder, ok := funders[key] if !ok { diff --git a/channel/params.go b/channel/params.go index 39c00c763..560fcdb0c 100644 --- a/channel/params.go +++ b/channel/params.go @@ -23,7 +23,6 @@ import ( "strings" "github.com/pkg/errors" - "perun.network/go-perun/log" "perun.network/go-perun/wallet" "perun.network/go-perun/wire/perunio" diff --git a/channel/persistence/statemachine_test.go b/channel/persistence/statemachine_test.go index daf9d3d44..3221e48d0 100644 --- a/channel/persistence/statemachine_test.go +++ b/channel/persistence/statemachine_test.go @@ -153,7 +153,7 @@ func TestStateMachine(t *testing.T) { // Set Progressed timeout := ctest.NewRandomTimeout(rng) idx := channel.Index(rng.Intn(s.NumParts())) - e := channel.NewProgressedEvent(s.ID[0], timeout, s, idx) + e := channel.NewProgressedEvent(s.ID[channel.TestBackendID], timeout, s, idx) err = sm.SetProgressed(ctx, e) require.NoError(err) tpr.AssertEqual(csm) diff --git a/channel/persistence/test/channel.go b/channel/persistence/test/channel.go index ce45e8a70..5b6f55d87 100644 --- a/channel/persistence/test/channel.go +++ b/channel/persistence/test/channel.go @@ -56,7 +56,7 @@ func NewRandomChannel( parent *Channel, rng *rand.Rand, ) (c *Channel) { - bID := wallet.BackendID(0) + bID := wallet.BackendID(channel.TestBackendID) if len(peers) > 0 { for i := range peers[0] { bID = i @@ -180,7 +180,7 @@ func (c *Channel) SignAll(ctx context.Context, t require.TestingT) { c.AssertPersisted(ctx, t) // remote signers for i := range c.accounts { - sig, err := channel.Sign(c.accounts[i][0], c.StagingState(), 0) + sig, err := channel.Sign(c.accounts[i][channel.TestBackendID], c.StagingState(), 0) require.NoError(t, err) c.AddSig(ctx, channel.Index(i), sig) //nolint:errcheck c.AssertPersisted(ctx, t) diff --git a/channel/test/app_randomizer.go b/channel/test/app_randomizer.go index 271f5ec25..563ff1921 100644 --- a/channel/test/app_randomizer.go +++ b/channel/test/app_randomizer.go @@ -58,7 +58,7 @@ func NewRandomApp(rng *rand.Rand, opts ...RandomOpt) channel.App { var bID wallet.BackendID bID, err := opt.Backend() if err != nil { - bID = wallet.BackendID(0) + bID = wallet.BackendID(channel.TestBackendID) } // WithAppDef does not set the app in the options app := opt.AppRandomizer().NewRandomApp(rng, bID) diff --git a/channel/test/randomizer.go b/channel/test/randomizer.go index e34ad7ee2..a21964ded 100644 --- a/channel/test/randomizer.go +++ b/channel/test/randomizer.go @@ -81,7 +81,7 @@ func NewRandomAssets(rng *rand.Rand, opts ...RandomOpt) []channel.Asset { } as := make([]channel.Asset, numAssets) for i := range as { - as[i] = NewRandomAsset(rng, 0) + as[i] = NewRandomAsset(rng, channel.TestBackendID) } updateOpts(opts, WithAssets(as...)) @@ -208,7 +208,7 @@ func NewRandomParams(rng *rand.Rand, opts ...RandomOpt) *channel.Params { if backend, _ = opt.Backend(); backend != 0 { parts[i] = map[wallet.BackendID]wallet.Address{backend: test.NewRandomAddress(rng, backend)} } else { - parts[i] = map[wallet.BackendID]wallet.Address{0: test.NewRandomAddress(rng, 0)} + parts[i] = map[wallet.BackendID]wallet.Address{channel.TestBackendID: test.NewRandomAddress(rng, 0)} } } } @@ -401,7 +401,7 @@ func NewRandomTransaction(rng *rand.Rand, sigMask []bool, opts ...RandomOpt) *ch opt := mergeRandomOpts(opts...) bID, err := opt.Backend() if err != nil { - bID = 0 + bID = channel.TestBackendID } numParts := len(sigMask) accs, addrs := test.NewRandomAccounts(rng, numParts, bID) diff --git a/client/appchannel_test.go b/client/appchannel_test.go index 7911b0fbf..d1a44d45a 100644 --- a/client/appchannel_test.go +++ b/client/appchannel_test.go @@ -32,21 +32,21 @@ import ( func TestProgression(t *testing.T) { rng := pkgtest.Prng(t) - setups := NewSetups(rng, []string{"Paul", "Paula"}, 0) + setups := NewSetups(rng, []string{"Paul", "Paula"}, channel.TestBackendID) roles := [2]clienttest.Executer{ clienttest.NewPaul(t, setups[0]), clienttest.NewPaula(t, setups[1]), } - appAddress := chtest.NewRandomAppID(rng, 0) + appAddress := chtest.NewRandomAppID(rng, channel.TestBackendID) app := channel.NewMockApp(appAddress) channel.RegisterApp(app) execConfig := &clienttest.ProgressionExecConfig{ BaseExecConfig: clienttest.MakeBaseExecConfig( [2]map[wallet.BackendID]wire.Address{wire.AddressMapfromAccountMap(setups[0].Identity), wire.AddressMapfromAccountMap(setups[1].Identity)}, - chtest.NewRandomAsset(rng, 0), - 0, + chtest.NewRandomAsset(rng, channel.TestBackendID), + channel.TestBackendID, [2]*big.Int{big.NewInt(99), big.NewInt(1)}, client.WithApp(app, channel.NewMockOp(channel.OpValid)), ), diff --git a/client/client_persistence_test.go b/client/client_persistence_test.go index 8147ce82f..9a3dfacac 100644 --- a/client/client_persistence_test.go +++ b/client/client_persistence_test.go @@ -19,6 +19,8 @@ import ( "math/rand" "testing" + "perun.network/go-perun/channel" + chprtest "perun.network/go-perun/channel/persistence/test" ctest "perun.network/go-perun/client/test" ) @@ -39,7 +41,7 @@ func TestPersistencePetraRobert(t *testing.T) { func NewSetupsPersistence(t *testing.T, rng *rand.Rand, names []string) []ctest.RoleSetup { t.Helper() - setups := NewSetups(rng, names, 0) + setups := NewSetups(rng, names, channel.TestBackendID) for i := range names { setups[i].PR = chprtest.NewPersistRestorer(t) } diff --git a/client/client_role_test.go b/client/client_role_test.go index 65a4520b9..9cfde977f 100644 --- a/client/client_role_test.go +++ b/client/client_role_test.go @@ -21,6 +21,8 @@ import ( "testing" "time" + "perun.network/go-perun/channel" + "perun.network/go-perun/wallet" "perun.network/go-perun/apps/payment" @@ -87,8 +89,8 @@ func runAliceBobTest(ctx context.Context, t *testing.T, setup func(*rand.Rand) ( cfg := &ctest.AliceBobExecConfig{ BaseExecConfig: ctest.MakeBaseExecConfig( [2]map[wallet.BackendID]wire.Address{wire.AddressMapfromAccountMap(setups[0].Identity), wire.AddressMapfromAccountMap(setups[1].Identity)}, - chtest.NewRandomAsset(rng, 0), - 0, + chtest.NewRandomAsset(rng, channel.TestBackendID), + channel.TestBackendID, [2]*big.Int{big.NewInt(100), big.NewInt(100)}, app, ), diff --git a/client/client_test.go b/client/client_test.go index f0f9db45f..c612dca89 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -53,7 +53,7 @@ func TestClient_New_NilArgs(t *testing.T) { rng := test.Prng(t) id := wiretest.NewRandomAddressesMap(rng, 1)[0] backend := &ctest.MockBackend{} - b, f, a, w := &DummyBus{t}, &ctest.MockFunder{}, &ctest.MockAdjudicator{}, map[wallet.BackendID]wallet.Wallet{0: wtest.RandomWallet(0)} + b, f, a, w := &DummyBus{t}, &ctest.MockFunder{}, &ctest.MockAdjudicator{}, map[wallet.BackendID]wallet.Wallet{channel.TestBackendID: wtest.RandomWallet(channel.TestBackendID)} watcher, err := local.NewWatcher(backend) require.NoError(t, err, "initializing the watcher should not error") assert.Panics(t, func() { client.New(nil, b, f, a, w, watcher) }) //nolint:errcheck @@ -70,7 +70,7 @@ func TestClient_Handle_NilArgs(t *testing.T) { watcher, err := local.NewWatcher(backend) require.NoError(t, err, "initializing the watcher should not error") c, err := client.New(wiretest.NewRandomAddress(rng), - &DummyBus{t}, &ctest.MockFunder{}, &ctest.MockAdjudicator{}, map[wallet.BackendID]wallet.Wallet{0: wtest.RandomWallet(0)}, watcher) + &DummyBus{t}, &ctest.MockFunder{}, &ctest.MockAdjudicator{}, map[wallet.BackendID]wallet.Wallet{channel.TestBackendID: wtest.RandomWallet(channel.TestBackendID)}, watcher) require.NoError(t, err) dummyUH := client.UpdateHandlerFunc(func(*channel.State, client.ChannelUpdate, *client.UpdateResponder) {}) @@ -85,7 +85,7 @@ func TestClient_New(t *testing.T) { watcher, err := local.NewWatcher(backend) require.NoError(t, err, "initializing the watcher should not error") c, err := client.New(wiretest.NewRandomAddressesMap(rng, 1)[0], - &DummyBus{t}, &ctest.MockFunder{}, &ctest.MockAdjudicator{}, map[wallet.BackendID]wallet.Wallet{0: wtest.RandomWallet(0)}, watcher) + &DummyBus{t}, &ctest.MockFunder{}, &ctest.MockAdjudicator{}, map[wallet.BackendID]wallet.Wallet{channel.TestBackendID: wtest.RandomWallet(channel.TestBackendID)}, watcher) assert.NoError(t, err) require.NotNil(t, c) } @@ -95,8 +95,8 @@ func TestChannelRejection(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) defer cancel() - roles := NewSetups(rng, []string{"Alice", "Bob"}, 0) - asset := chtest.NewRandomAsset(rng, 0) + roles := NewSetups(rng, []string{"Alice", "Bob"}, channel.TestBackendID) + asset := chtest.NewRandomAsset(rng, channel.TestBackendID) clients := ctest.NewClients(t, rng, roles) require := require.New(t) alice, bob := clients[0], clients[1] diff --git a/client/failing_funding_test.go b/client/failing_funding_test.go index 8a62d413d..123a67652 100644 --- a/client/failing_funding_test.go +++ b/client/failing_funding_test.go @@ -42,8 +42,8 @@ func TestFailingFunding(t *testing.T) { BalanceDelta: big.NewInt(0), }, func(r *rand.Rand) ([2]ctest.RoleSetup, channel.Asset) { - roles := NewSetups(rng, []string{"Frida", "Fred"}, 0) - asset := chtest.NewRandomAsset(rng, 0) + roles := NewSetups(rng, []string{"Frida", "Fred"}, channel.TestBackendID) + asset := chtest.NewRandomAsset(rng, channel.TestBackendID) return [2]ctest.RoleSetup{roles[0], roles[1]}, asset }, ) diff --git a/client/payment_test.go b/client/payment_test.go index 1b91bc555..2ac177f5d 100644 --- a/client/payment_test.go +++ b/client/payment_test.go @@ -20,6 +20,8 @@ import ( "math/rand" "testing" + "perun.network/go-perun/channel" + "perun.network/go-perun/wallet" chtest "perun.network/go-perun/channel/test" @@ -34,7 +36,7 @@ func TestPaymentHappy(t *testing.T) { defer cancel() runAliceBobTest(ctx, t, func(rng *rand.Rand) ([]ctest.RoleSetup, [2]ctest.Executer) { - setups := NewSetups(rng, []string{"Alice", "Bob"}, 0) + setups := NewSetups(rng, []string{"Alice", "Bob"}, channel.TestBackendID) roles := [2]ctest.Executer{ ctest.NewAlice(t, setups[0]), ctest.NewBob(t, setups[1]), @@ -49,7 +51,7 @@ func TestPaymentDispute(t *testing.T) { defer cancel() const mallory, carol = 0, 1 // Indices of Mallory and Carol - setups := NewSetups(rng, []string{"Mallory", "Carol"}, 0) + setups := NewSetups(rng, []string{"Mallory", "Carol"}, channel.TestBackendID) roles := [2]ctest.Executer{ ctest.NewMallory(t, setups[0]), ctest.NewCarol(t, setups[1]), @@ -58,8 +60,8 @@ func TestPaymentDispute(t *testing.T) { cfg := &ctest.MalloryCarolExecConfig{ BaseExecConfig: ctest.MakeBaseExecConfig( [2]map[wallet.BackendID]wire.Address{wire.AddressMapfromAccountMap(setups[mallory].Identity), wire.AddressMapfromAccountMap(setups[carol].Identity)}, - chtest.NewRandomAsset(rng, 0), - 0, + chtest.NewRandomAsset(rng, channel.TestBackendID), + channel.TestBackendID, [2]*big.Int{big.NewInt(100), big.NewInt(1)}, client.WithoutApp(), ), diff --git a/client/proposal.go b/client/proposal.go index 87f7a15dc..9cb8a3be4 100644 --- a/client/proposal.go +++ b/client/proposal.go @@ -128,7 +128,7 @@ func (r *ProposalResponder) Accept(ctx context.Context, acc ChannelProposalAccep } // SetEgoisticChain sets the egoistic chain flag for a given ledger. -func (r *ProposalResponder) SetEgoisticChain(egoistic multi.AssetID, id int) { +func (r *ProposalResponder) SetEgoisticChain(egoistic multi.MultiLedgerID, id int) { mf, ok := r.client.funder.(*multi.Funder) if !ok { log.Panic("unexpected type for funder") @@ -137,7 +137,7 @@ func (r *ProposalResponder) SetEgoisticChain(egoistic multi.AssetID, id int) { } // RemoveEgoisticChain removes the egoistic chain flag for a given ledger. -func (r *ProposalResponder) RemoveEgoisticChain(egoistic multi.AssetID, id int) { +func (r *ProposalResponder) RemoveEgoisticChain(egoistic multi.MultiLedgerID, id int) { mf, ok := r.client.funder.(*multi.Funder) if !ok { log.Panic("unexpected type for funder") diff --git a/client/restore_internal_test.go b/client/restore_internal_test.go index e9baf8fe9..11df2ed86 100644 --- a/client/restore_internal_test.go +++ b/client/restore_internal_test.go @@ -38,14 +38,14 @@ func patchChFromSource( parent *Channel, peers ...map[wallet.BackendID]wire.Address, ) (*Channel, error) { - bID := wallet.BackendID(0) + bID := wallet.BackendID(channel.TestBackendID) if len(peers) > 0 { for i := range peers[0] { bID = i } } - acc, _ := wallettest.RandomWallet(bID).Unlock(ch.ParamsV.Parts[ch.IdxV][0]) - machine, _ := channel.NewStateMachine(map[wallet.BackendID]wallet.Account{0: acc}, *ch.ParamsV) + acc, _ := wallettest.RandomWallet(bID).Unlock(ch.ParamsV.Parts[ch.IdxV][channel.TestBackendID]) + machine, _ := channel.NewStateMachine(map[wallet.BackendID]wallet.Account{channel.TestBackendID: acc}, *ch.ParamsV) pmachine := persistence.FromStateMachine(machine, nil) _ch := &Channel{parent: parent, machine: pmachine, OnCloser: new(sync.Closer)} @@ -58,10 +58,10 @@ func TestReconstructChannel(t *testing.T) { rng := pkgtest.Prng(t) db := map[string]*persistence.Channel{} - restParent := mkRndChan(rng, 0) + restParent := mkRndChan(rng, channel.TestBackendID) db[channel.IDKey(restParent.ID())] = restParent - restChild := mkRndChan(rng, 0) + restChild := mkRndChan(rng, channel.TestBackendID) parentID := restParent.ID() restChild.Parent = &parentID db[channel.IDKey(restChild.ID())] = restChild @@ -88,7 +88,7 @@ func TestRestoreChannelCollection(t *testing.T) { // Generate multiple trees of channels into one collection. db := make(map[string]*persistence.Channel) for i := 0; i < 3; i++ { - mkRndChanTree(rng, 3, 1, 3, db, 0) + mkRndChanTree(rng, 3, 1, 3, db, channel.TestBackendID) } // Remember channels that have been published. diff --git a/client/subchannel_test.go b/client/subchannel_test.go index ac03932fc..05eb58332 100644 --- a/client/subchannel_test.go +++ b/client/subchannel_test.go @@ -19,6 +19,8 @@ import ( "math/big" "testing" + "perun.network/go-perun/channel" + "perun.network/go-perun/wallet" "perun.network/go-perun/apps/payment" @@ -32,7 +34,7 @@ import ( func TestSubChannelHappy(t *testing.T) { rng := test.Prng(t) - setups := NewSetups(rng, []string{"Susie", "Tim"}, 0) + setups := NewSetups(rng, []string{"Susie", "Tim"}, channel.TestBackendID) roles := [2]ctest.Executer{ ctest.NewSusie(t, setups[0]), ctest.NewTim(t, setups[1]), @@ -41,8 +43,8 @@ func TestSubChannelHappy(t *testing.T) { cfg := ctest.NewSusieTimExecConfig( ctest.MakeBaseExecConfig( [2]map[wallet.BackendID]wire.Address{wire.AddressMapfromAccountMap(setups[0].Identity), wire.AddressMapfromAccountMap(setups[1].Identity)}, - chtest.NewRandomAsset(rng, 0), - 0, + chtest.NewRandomAsset(rng, channel.TestBackendID), + channel.TestBackendID, [2]*big.Int{big.NewInt(100), big.NewInt(100)}, client.WithoutApp(), ), @@ -71,7 +73,7 @@ func TestSubChannelHappy(t *testing.T) { func TestSubChannelDispute(t *testing.T) { rng := test.Prng(t) - setups := NewSetups(rng, []string{"DisputeSusie", "DisputeTim"}, 0) + setups := NewSetups(rng, []string{"DisputeSusie", "DisputeTim"}, channel.TestBackendID) roles := [2]ctest.Executer{ ctest.NewDisputeSusie(t, setups[0]), ctest.NewDisputeTim(t, setups[1]), @@ -79,8 +81,8 @@ func TestSubChannelDispute(t *testing.T) { baseCfg := ctest.MakeBaseExecConfig( [2]map[wallet.BackendID]wire.Address{wire.AddressMapfromAccountMap(setups[0].Identity), wire.AddressMapfromAccountMap(setups[1].Identity)}, - chtest.NewRandomAsset(rng, 0), - 0, + chtest.NewRandomAsset(rng, channel.TestBackendID), + channel.TestBackendID, [2]*big.Int{big.NewInt(100), big.NewInt(100)}, client.WithoutApp(), ) diff --git a/client/test/backend.go b/client/test/backend.go index e2265a503..3fe5a5d5c 100644 --- a/client/test/backend.go +++ b/client/test/backend.go @@ -39,7 +39,7 @@ type ( latestEvents map[string]channel.AdjudicatorEvent eventSubs map[string][]*MockSubscription balances map[addressMapKey]map[assetMapKey]*big.Int - id multi.AssetID + id multi.MultiLedgerID } // AssetID is the unique asset identifier. @@ -91,7 +91,7 @@ func NewMockBackend(rng *rand.Rand, id string) *MockBackend { } // ID returns the ledger's identifier. -func (b *MockBackend) ID() multi.AssetID { +func (b *MockBackend) ID() multi.MultiLedgerID { return b.id } @@ -542,7 +542,7 @@ func (f *assetHolder) Fund(req channel.FundingReq, b *MockBackend, acc wallet.Ad for i, asset := range req.State.Assets { ma, ok := asset.(*MultiLedgerAsset) - if ok && ma.AssetID() != b.ID() { + if ok && ma.MultiLedgerID() != b.ID() { continue } diff --git a/client/test/multiledger.go b/client/test/multiledger.go index aae3a858d..7f9fd2cf2 100644 --- a/client/test/multiledger.go +++ b/client/test/multiledger.go @@ -59,12 +59,12 @@ func SetupMultiLedgerTest(t *testing.T) MultiLedgerSetup { bus := wire.NewLocalBus() // Setup clients. - c1 := setupClient(t, rng, l1, l2, bus, 0) - c2 := setupClient(t, rng, l1, l2, bus, 0) + c1 := setupClient(t, rng, l1, l2, bus, channel.TestBackendID) + c2 := setupClient(t, rng, l1, l2, bus, channel.TestBackendID) // Define assets. - a1 := NewMultiLedgerAsset(l1.ID(), chtest.NewRandomAsset(rng, 0)) - a2 := NewMultiLedgerAsset(l2.ID(), chtest.NewRandomAsset(rng, 0)) + a1 := NewMultiLedgerAsset(l1.ID(), chtest.NewRandomAsset(rng, channel.TestBackendID)) + a2 := NewMultiLedgerAsset(l2.ID(), chtest.NewRandomAsset(rng, channel.TestBackendID)) return MultiLedgerSetup{ Client1: c1, @@ -92,17 +92,17 @@ func SetupMultiLedgerTest(t *testing.T) MultiLedgerSetup { // MultiLedgerAsset is a multi-ledger asset. type MultiLedgerAsset struct { - id multi.AssetID + id multi.MultiLedgerID asset channel.Asset } // AssetID returns the asset's ID. -func (a *MultiLedgerAsset) AssetID() multi.AssetID { +func (a *MultiLedgerAsset) MultiLedgerID() multi.MultiLedgerID { return a.id } // NewMultiLedgerAsset returns a new multi-ledger asset. -func NewMultiLedgerAsset(id multi.AssetID, asset channel.Asset) *MultiLedgerAsset { +func NewMultiLedgerAsset(id multi.MultiLedgerID, asset channel.Asset) *MultiLedgerAsset { return &MultiLedgerAsset{ id: id, asset: asset, @@ -125,7 +125,7 @@ func (a *MultiLedgerAsset) Address() []byte { } // LedgerID returns the asset's ledger ID. -func (a *MultiLedgerAsset) LedgerID() multi.AssetID { +func (a *MultiLedgerAsset) LedgerID() multi.MultiLedgerID { return a.id } @@ -196,7 +196,7 @@ func setupClient( bus, funder, adj, - map[wallet.BackendID]wallet.Wallet{0: w}, + map[wallet.BackendID]wallet.Wallet{channel.TestBackendID: w}, watcher, ) require.NoError(err) @@ -204,7 +204,7 @@ func setupClient( return MultiLedgerClient{ Client: c, WireAddress: wireAddr[0], - WalletAddress: map[wallet.BackendID]wallet.Address{0: acc.Address()}, + WalletAddress: map[wallet.BackendID]wallet.Address{channel.TestBackendID: acc.Address()}, Events: make(chan channel.AdjudicatorEvent), Adjudicator1: l1.NewAdjudicator(acc.Address()), Adjudicator2: l2.NewAdjudicator(acc.Address()), diff --git a/client/test/multiledger_dispute.go b/client/test/multiledger_dispute.go index a19350d63..1bba32dd6 100644 --- a/client/test/multiledger_dispute.go +++ b/client/test/multiledger_dispute.go @@ -62,8 +62,8 @@ func TestMultiLedgerDispute( // Establish ledger channel between Alice and Bob. - bID1 := wallet.BackendID(mlt.Asset1.AssetID().BackendID()) - bID2 := wallet.BackendID(mlt.Asset2.AssetID().BackendID()) + bID1 := wallet.BackendID(mlt.Asset1.MultiLedgerID().BackendID()) + bID2 := wallet.BackendID(mlt.Asset2.MultiLedgerID().BackendID()) // Create channel proposal. parts := []map[wallet.BackendID]wire.Address{alice.WireAddress, bob.WireAddress} initAlloc := channel.NewAllocation(len(parts), []wallet.BackendID{bID1, bID2}, mlt.Asset1, mlt.Asset2) diff --git a/client/test/multiledger_happy.go b/client/test/multiledger_happy.go index 490df99c5..390333c2c 100644 --- a/client/test/multiledger_happy.go +++ b/client/test/multiledger_happy.go @@ -44,7 +44,7 @@ func TestMultiLedgerHappy(ctx context.Context, t *testing.T, mlt MultiLedgerSetu // Create channel proposal. parts := []map[wallet.BackendID]wire.Address{alice.WireAddress, bob.WireAddress} - initAlloc := channel.NewAllocation(len(parts), []wallet.BackendID{wallet.BackendID(mlt.Asset1.AssetID().BackendID()), wallet.BackendID(mlt.Asset2.AssetID().BackendID())}, mlt.Asset1, mlt.Asset2) + initAlloc := channel.NewAllocation(len(parts), []wallet.BackendID{wallet.BackendID(mlt.Asset1.MultiLedgerID().BackendID()), wallet.BackendID(mlt.Asset2.MultiLedgerID().BackendID())}, mlt.Asset1, mlt.Asset2) initAlloc.Balances = initBals prop, err := client.NewLedgerChannelProposal( challengeDuration, diff --git a/client/virtual_channel_test.go b/client/virtual_channel_test.go index 972c384ac..d2c8f751b 100644 --- a/client/virtual_channel_test.go +++ b/client/virtual_channel_test.go @@ -21,13 +21,15 @@ import ( "testing" "time" + "perun.network/go-perun/channel" + chtest "perun.network/go-perun/channel/test" ctest "perun.network/go-perun/client/test" "polycry.pt/poly-go/test" ) const ( - challengeDuration = 10 + challengeDuration = 15 testDuration = 10 * time.Second ) @@ -53,7 +55,7 @@ func makeVirtualChannelSetup(rng *rand.Rand) ctest.VirtualChannelSetup { return ctest.VirtualChannelSetup{ Clients: createVirtualChannelClients(rng), ChallengeDuration: challengeDuration, - Asset: chtest.NewRandomAsset(rng, 0), + Asset: chtest.NewRandomAsset(rng, channel.TestBackendID), Balances: ctest.VirtualChannelBalances{ InitBalsAliceIngrid: []*big.Int{big.NewInt(10), big.NewInt(10)}, InitBalsBobIngrid: []*big.Int{big.NewInt(10), big.NewInt(10)}, @@ -70,7 +72,7 @@ func makeVirtualChannelSetup(rng *rand.Rand) ctest.VirtualChannelSetup { func createVirtualChannelClients(rng *rand.Rand) [3]ctest.RoleSetup { var setupsArray [3]ctest.RoleSetup - setups := NewSetups(rng, []string{"Alice", "Bob", "Ingrid"}, 0) + setups := NewSetups(rng, []string{"Alice", "Bob", "Ingrid"}, channel.TestBackendID) copy(setupsArray[:], setups) return setupsArray } diff --git a/log/logrus/logrus_internal_test.go b/log/logrus/logrus_internal_test.go index a62c45a8e..a2f606204 100644 --- a/log/logrus/logrus_internal_test.go +++ b/log/logrus/logrus_internal_test.go @@ -30,6 +30,9 @@ import ( pkgtest "polycry.pt/poly-go/test" ) +// TestBackendID is the identifier for the simulated Backend. +const TestBackendID = 0 + func TestLogrus(t *testing.T) { t.Run("Info", testLogrusInfo) t.Run("Stringer", testLogrusStringer) @@ -49,7 +52,7 @@ func testLogrusInfo(t *testing.T) { func testLogrusStringer(t *testing.T) { rng := pkgtest.Prng(t) - addr := wtest.NewRandomAddress(rng, 0) + addr := wtest.NewRandomAddress(rng, TestBackendID) var data [32]byte rng.Read(data[:]) logger, hook := test.NewNullLogger() diff --git a/wallet/address_test.go b/wallet/address_test.go index e397f89c4..fbc83917a 100644 --- a/wallet/address_test.go +++ b/wallet/address_test.go @@ -27,6 +27,9 @@ import ( pkgtest "polycry.pt/poly-go/test" ) +// TestBackendID is the identifier for the simulated Backend. +const TestBackendID = wallet.BackendID(0) + type testAddresses struct { addrs wallet.AddressMapArray } @@ -53,22 +56,22 @@ func (t *testAddress) Decode(r io.Reader) error { func TestAddresses_Serializer(t *testing.T) { rng := pkgtest.Prng(t) - addr := wallettest.NewRandomAddressesMap(rng, 1, 0)[0] + addr := wallettest.NewRandomAddressesMap(rng, 1, TestBackendID)[0] peruniotest.GenericSerializerTest(t, &testAddress{addrs: addr}) - addrs := wallettest.NewRandomAddressesMap(rng, 0, 0) + addrs := wallettest.NewRandomAddressesMap(rng, 0, TestBackendID) peruniotest.GenericSerializerTest(t, &testAddresses{addrs: wallet.AddressMapArray{Addr: addrs}}) - addrs = wallettest.NewRandomAddressesMap(rng, 1, 0) + addrs = wallettest.NewRandomAddressesMap(rng, 1, TestBackendID) peruniotest.GenericSerializerTest(t, &testAddresses{addrs: wallet.AddressMapArray{Addr: addrs}}) - addrs = wallettest.NewRandomAddressesMap(rng, 5, 0) + addrs = wallettest.NewRandomAddressesMap(rng, 5, TestBackendID) peruniotest.GenericSerializerTest(t, &testAddresses{addrs: wallet.AddressMapArray{Addr: addrs}}) } func TestAddrKey_Equal(t *testing.T) { rng := pkgtest.Prng(t) - addrs := wallettest.NewRandomAddressArray(rng, 10, 0) + addrs := wallettest.NewRandomAddressArray(rng, 10, TestBackendID) // Test all properties of an equivalence relation. for i, a := range addrs { @@ -93,7 +96,7 @@ func TestAddrKey_Equal(t *testing.T) { func TestAddrKey(t *testing.T) { rng := pkgtest.Prng(t) - addrs := wallettest.NewRandomAddressArray(rng, 10, 0) + addrs := wallettest.NewRandomAddressArray(rng, 10, TestBackendID) for _, a := range addrs { // Test that Key and FromKey are dual to each other. @@ -105,7 +108,7 @@ func TestAddrKey(t *testing.T) { func TestCloneAddress(t *testing.T) { rng := pkgtest.Prng(t) - addr := wallettest.NewRandomAddress(rng, 0) + addr := wallettest.NewRandomAddress(rng, TestBackendID) addr0 := wallet.CloneAddress(addr) require.Equal(t, addr, addr0) require.NotSame(t, addr, addr0) @@ -113,7 +116,7 @@ func TestCloneAddress(t *testing.T) { func TestCloneAddresses(t *testing.T) { rng := pkgtest.Prng(t) - addrs := wallettest.NewRandomAddressArray(rng, 3, 0) + addrs := wallettest.NewRandomAddressArray(rng, 3, TestBackendID) addrs0 := wallet.CloneAddresses(addrs) require.Equal(t, addrs, addrs0) require.NotSame(t, addrs, addrs0) diff --git a/wire/net/endpoint_internal_test.go b/wire/net/endpoint_internal_test.go index 6135039fb..6476e0672 100644 --- a/wire/net/endpoint_internal_test.go +++ b/wire/net/endpoint_internal_test.go @@ -98,7 +98,7 @@ type client struct { // makeClient creates a simulated test client. func makeClient(conn Conn, rng *rand.Rand, dialer Dialer) *client { receiver := wire.NewReceiver() - registry := NewEndpointRegistry(wiretest.NewRandomAccountMap(rng, 0), func(map[wallet.BackendID]wire.Address) wire.Consumer { + registry := NewEndpointRegistry(wiretest.NewRandomAccountMap(rng, channel.TestBackendID), func(map[wallet.BackendID]wire.Address) wire.Consumer { return receiver }, dialer, perunio.Serializer()) diff --git a/wire/net/endpoint_registry_external_test.go b/wire/net/endpoint_registry_external_test.go index 2ee3c32af..2f3179104 100644 --- a/wire/net/endpoint_registry_external_test.go +++ b/wire/net/endpoint_registry_external_test.go @@ -45,8 +45,8 @@ func TestEndpointRegistry_Get_Pair(t *testing.T) { assert, require := assert.New(t), require.New(t) rng := test.Prng(t) var hub nettest.ConnHub - dialerID := wiretest.NewRandomAccountMap(rng, 0) - listenerID := wiretest.NewRandomAccountMap(rng, 0) + dialerID := wiretest.NewRandomAccountMap(rng, channel.TestBackendID) + listenerID := wiretest.NewRandomAccountMap(rng, channel.TestBackendID) dialerReg := net.NewEndpointRegistry(dialerID, nilConsumer, hub.NewNetDialer(), perunio.Serializer()) listenerReg := net.NewEndpointRegistry(listenerID, nilConsumer, nil, perunio.Serializer()) listener := hub.NewNetListener(wire.AddressMapfromAccountMap(listenerID)) @@ -85,8 +85,8 @@ func TestEndpointRegistry_Get_Multiple(t *testing.T) { assert := assert.New(t) rng := test.Prng(t) var hub nettest.ConnHub - dialerID := wiretest.NewRandomAccountMap(rng, 0) - listenerID := wiretest.NewRandomAccountMap(rng, 0) + dialerID := wiretest.NewRandomAccountMap(rng, channel.TestBackendID) + listenerID := wiretest.NewRandomAccountMap(rng, channel.TestBackendID) dialer := hub.NewNetDialer() logPeer := func(addr map[wallet.BackendID]wire.Address) wire.Consumer { t.Logf("subscribing %s\n", wire.Keys(addr)) diff --git a/wire/net/endpoint_registry_internal_test.go b/wire/net/endpoint_registry_internal_test.go index b10e6267b..ea0471665 100644 --- a/wire/net/endpoint_registry_internal_test.go +++ b/wire/net/endpoint_registry_internal_test.go @@ -21,6 +21,8 @@ import ( "testing" "time" + "perun.network/go-perun/channel" + "perun.network/go-perun/wallet" "github.com/pkg/errors" @@ -116,8 +118,8 @@ func nilConsumer(map[wallet.BackendID]wire.Address) wire.Consumer { return nil } func TestRegistry_Get(t *testing.T) { t.Parallel() rng := test.Prng(t) - id := wiretest.NewRandomAccountMap(rng, 0) - peerID := wiretest.NewRandomAccountMap(rng, 0) + id := wiretest.NewRandomAccountMap(rng, channel.TestBackendID) + peerID := wiretest.NewRandomAccountMap(rng, channel.TestBackendID) peerAddr := wire.AddressMapfromAccountMap(peerID) t.Run("peer already in progress (existing)", func(t *testing.T) { @@ -181,11 +183,11 @@ func TestRegistry_Get(t *testing.T) { func TestRegistry_authenticatedDial(t *testing.T) { t.Parallel() rng := test.Prng(t) - id := wiretest.NewRandomAccountMap(rng, 0) + id := wiretest.NewRandomAccountMap(rng, channel.TestBackendID) d := &mockDialer{dial: make(chan Conn)} r := NewEndpointRegistry(id, nilConsumer, d, perunio.Serializer()) - remoteID := wiretest.NewRandomAccountMap(rng, 0) + remoteID := wiretest.NewRandomAccountMap(rng, channel.TestBackendID) remoteAddr := wire.AddressMapfromAccountMap(remoteID) t.Run("dial fail", func(t *testing.T) { @@ -230,7 +232,7 @@ func TestRegistry_authenticatedDial(t *testing.T) { a, b := newPipeConnPair() go ct.Stage("passive", func(rt test.ConcT) { d.put(a) - _, err := ExchangeAddrsPassive(ctx, wiretest.NewRandomAccountMap(rng, 0), b) + _, err := ExchangeAddrsPassive(ctx, wiretest.NewRandomAccountMap(rng, channel.TestBackendID), b) require.True(rt, IsAuthenticationError(err)) }) de, created := r.dialingEndpoint(remoteAddr) @@ -263,8 +265,8 @@ func TestRegistry_authenticatedDial(t *testing.T) { func TestRegistry_setupConn(t *testing.T) { t.Parallel() rng := test.Prng(t) - id := wiretest.NewRandomAccountMap(rng, 0) - remoteID := wiretest.NewRandomAccountMap(rng, 0) + id := wiretest.NewRandomAccountMap(rng, channel.TestBackendID) + remoteID := wiretest.NewRandomAccountMap(rng, channel.TestBackendID) t.Run("ExchangeAddrs fail", func(t *testing.T) { d := &mockDialer{dial: make(chan Conn)} @@ -325,9 +327,9 @@ func TestRegistry_Listen(t *testing.T) { rng := test.Prng(t) - id := wiretest.NewRandomAccountMap(rng, 0) + id := wiretest.NewRandomAccountMap(rng, channel.TestBackendID) addr := wire.AddressMapfromAccountMap(id) - remoteID := wiretest.NewRandomAccountMap(rng, 0) + remoteID := wiretest.NewRandomAccountMap(rng, channel.TestBackendID) remoteAddr := wire.AddressMapfromAccountMap(remoteID) d := newMockDialer() @@ -367,7 +369,7 @@ func TestRegistry_addEndpoint_Subscribe(t *testing.T) { rng := test.Prng(t) called := false r := NewEndpointRegistry( - wiretest.NewRandomAccountMap(rng, 0), + wiretest.NewRandomAccountMap(rng, channel.TestBackendID), func(map[wallet.BackendID]wire.Address) wire.Consumer { called = true; return nil }, nil, perunio.Serializer(), @@ -385,7 +387,7 @@ func TestRegistry_Close(t *testing.T) { t.Run("double close error", func(t *testing.T) { r := NewEndpointRegistry( - wiretest.NewRandomAccountMap(rng, 0), + wiretest.NewRandomAccountMap(rng, channel.TestBackendID), nilConsumer, nil, perunio.Serializer(), @@ -398,7 +400,7 @@ func TestRegistry_Close(t *testing.T) { d := &mockDialer{dial: make(chan Conn)} d.Close() r := NewEndpointRegistry( - wiretest.NewRandomAccountMap(rng, 0), + wiretest.NewRandomAccountMap(rng, channel.TestBackendID), nilConsumer, d, perunio.Serializer(), diff --git a/wire/net/exchange_addr_internal_test.go b/wire/net/exchange_addr_internal_test.go index 5ff019f45..6a1fc7b5b 100644 --- a/wire/net/exchange_addr_internal_test.go +++ b/wire/net/exchange_addr_internal_test.go @@ -33,7 +33,7 @@ func TestExchangeAddrs_ConnFail(t *testing.T) { rng := test.Prng(t) a, _ := newPipeConnPair() a.Close() - addr, err := ExchangeAddrsPassive(context.Background(), wiretest.NewRandomAccountMap(rng, 0), a) + addr, err := ExchangeAddrsPassive(context.Background(), wiretest.NewRandomAccountMap(rng, channel.TestBackendID), a) assert.Nil(t, addr) assert.Error(t, err) } @@ -42,7 +42,7 @@ func TestExchangeAddrs_Success(t *testing.T) { rng := test.Prng(t) conn0, conn1 := newPipeConnPair() defer conn0.Close() - account0, account1 := wiretest.NewRandomAccountMap(rng, 0), wiretest.NewRandomAccountMap(rng, 0) + account0, account1 := wiretest.NewRandomAccountMap(rng, channel.TestBackendID), wiretest.NewRandomAccountMap(rng, channel.TestBackendID) var wg sync.WaitGroup wg.Add(1) @@ -68,7 +68,7 @@ func TestExchangeAddrs_Timeout(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() ctxtest.AssertTerminates(t, 2*timeout, func() { - addr, err := ExchangeAddrsPassive(ctx, wiretest.NewRandomAccountMap(rng, 0), a) + addr, err := ExchangeAddrsPassive(ctx, wiretest.NewRandomAccountMap(rng, channel.TestBackendID), a) assert.Nil(t, addr) assert.Error(t, err) }) @@ -76,7 +76,7 @@ func TestExchangeAddrs_Timeout(t *testing.T) { func TestExchangeAddrs_BogusMsg(t *testing.T) { rng := test.Prng(t) - acc := wiretest.NewRandomAccountMap(rng, 0) + acc := wiretest.NewRandomAccountMap(rng, channel.TestBackendID) conn := newMockConn() conn.recvQueue <- wiretest.NewRandomEnvelope(rng, wire.NewPingMsg()) addr, err := ExchangeAddrsPassive(context.Background(), acc, conn) diff --git a/wire/net/simple/address.go b/wire/net/simple/address.go index ad7bb67e7..c10bc166f 100644 --- a/wire/net/simple/address.go +++ b/wire/net/simple/address.go @@ -28,6 +28,9 @@ import ( "perun.network/go-perun/wire" ) +// testBackendID is the identifier for the simulated Backend. +const testBackendID = 0 + // Address is a wire address. type Address struct { Name string @@ -216,7 +219,7 @@ func NewRandomAddresses(rng *rand.Rand) map[wallet.BackendID]wire.Address { a := Address{ Name: string(d), } - return map[wallet.BackendID]wire.Address{0: &a} + return map[wallet.BackendID]wire.Address{testBackendID: &a} } // Verify verifies a message signature. diff --git a/wire/net/simple/dialer_internal_test.go b/wire/net/simple/dialer_internal_test.go index 8758db39b..9555b1f66 100644 --- a/wire/net/simple/dialer_internal_test.go +++ b/wire/net/simple/dialer_internal_test.go @@ -28,6 +28,8 @@ import ( "testing" "time" + "perun.network/go-perun/channel" + "perun.network/go-perun/wallet" "github.com/stretchr/testify/assert" @@ -68,7 +70,7 @@ func TestDialer_Register(t *testing.T) { _, ok := d.host(key) require.False(t, ok) - d.Register(map[wallet.BackendID]wire.Address{0: addr}, "host") + d.Register(map[wallet.BackendID]wire.Address{channel.TestBackendID: addr}, "host") host, ok := d.host(key) assert.True(t, ok) @@ -79,7 +81,7 @@ func TestDialer_Dial(t *testing.T) { timeout := 100 * time.Millisecond rng := test.Prng(t) lhost := "127.0.0.1:7357" - laddr := wire.AddressMapfromAccountMap(wiretest.NewRandomAccountMap(rng, 0)) + laddr := wire.AddressMapfromAccountMap(wiretest.NewRandomAccountMap(rng, channel.TestBackendID)) commonName := "127.0.0.1" sans := []string{"127.0.0.1", "localhost"} @@ -93,7 +95,7 @@ func TestDialer_Dial(t *testing.T) { ser := perunio.Serializer() d := NewTCPDialer(timeout, dConfig) d.Register(laddr, lhost) - daddr := wire.AddressMapfromAccountMap(wiretest.NewRandomAccountMap(rng, 0)) + daddr := wire.AddressMapfromAccountMap(wiretest.NewRandomAccountMap(rng, channel.TestBackendID)) defer d.Close() t.Run("happy", func(t *testing.T) { diff --git a/wire/net/simple/simple_exchange_addr_test.go b/wire/net/simple/simple_exchange_addr_test.go index e1d7d5eef..ad6954395 100644 --- a/wire/net/simple/simple_exchange_addr_test.go +++ b/wire/net/simple/simple_exchange_addr_test.go @@ -44,7 +44,7 @@ func TestExchangeAddrs_ConnFail(t *testing.T) { rng := test.Prng(t) a, _ := newPipeConnPair() a.Close() - addr, err := wirenet.ExchangeAddrsPassive(context.Background(), wiretest.NewRandomAccountMap(rng, 0), a) + addr, err := wirenet.ExchangeAddrsPassive(context.Background(), wiretest.NewRandomAccountMap(rng, channel.TestBackendID), a) assert.Nil(t, addr) assert.Error(t, err) } @@ -53,7 +53,7 @@ func TestExchangeAddrs_Success(t *testing.T) { rng := test.Prng(t) conn0, conn1 := newPipeConnPair() defer conn0.Close() - account0, account1 := wiretest.NewRandomAccountMap(rng, 0), wiretest.NewRandomAccountMap(rng, 0) + account0, account1 := wiretest.NewRandomAccountMap(rng, channel.TestBackendID), wiretest.NewRandomAccountMap(rng, channel.TestBackendID) var wg sync.WaitGroup wg.Add(1) @@ -79,7 +79,7 @@ func TestExchangeAddrs_Timeout(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() ctxtest.AssertTerminates(t, 20*timeout, func() { - addr, err := wirenet.ExchangeAddrsPassive(ctx, wiretest.NewRandomAccountMap(rng, 0), a) + addr, err := wirenet.ExchangeAddrsPassive(ctx, wiretest.NewRandomAccountMap(rng, channel.TestBackendID), a) assert.Nil(t, addr) assert.Error(t, err) }) @@ -87,7 +87,7 @@ func TestExchangeAddrs_Timeout(t *testing.T) { func TestExchangeAddrs_BogusMsg(t *testing.T) { rng := test.Prng(t) - acc := wiretest.NewRandomAccountMap(rng, 0) + acc := wiretest.NewRandomAccountMap(rng, channel.TestBackendID) conn := newMockConn() conn.recvQueue <- newRandomEnvelope(rng, wire.NewPingMsg()) addr, err := wirenet.ExchangeAddrsPassive(context.Background(), acc, conn) diff --git a/wire/net/test/connhub_internal_test.go b/wire/net/test/connhub_internal_test.go index d77549529..4ca17d601 100644 --- a/wire/net/test/connhub_internal_test.go +++ b/wire/net/test/connhub_internal_test.go @@ -18,6 +18,8 @@ import ( "context" "testing" + "perun.network/go-perun/channel" + "perun.network/go-perun/wallet" "github.com/stretchr/testify/assert" @@ -123,7 +125,7 @@ func TestConnHub_Close(t *testing.T) { l := c.NewNetListener(wiretest.NewRandomAddress(rng)) l2 := NewNetListener() l2.Close() - err := c.insert(map[wallet.BackendID]wire.Address{0: wiretest.NewRandomAccount(rng).Address()}, l2) + err := c.insert(map[wallet.BackendID]wire.Address{channel.TestBackendID: wiretest.NewRandomAccount(rng).Address()}, l2) assert.NoError(err) assert.Error(c.Close()) assert.True(l.IsClosed()) diff --git a/wire/test/bustest.go b/wire/test/bustest.go index 4409d2550..7e474d8b7 100644 --- a/wire/test/bustest.go +++ b/wire/test/bustest.go @@ -28,7 +28,10 @@ import ( ) // timeout testNoReceive sub-test. -const testNoReceiveTimeout = 10 * time.Millisecond +const ( + testNoReceiveTimeout = 10 * time.Millisecond + TestBackendID = 0 +) // GenericBusTest tests the general functionality of a bus in the happy case: it // tests that messages sent over the bus arrive at the correct destination. The @@ -57,7 +60,7 @@ func GenericBusTest(t *testing.T, clients := make([]Client, numClients) for i := range clients { clients[i].r = wire.NewRelay() - clients[i].id = NewRandomAccountMap(rng, 0) + clients[i].id = NewRandomAccountMap(rng, TestBackendID) clients[i].pub, clients[i].sub = busAssigner(clients[i].id) } diff --git a/wire/test/msgstest.go b/wire/test/msgstest.go index e86a5302a..dc5f34c48 100644 --- a/wire/test/msgstest.go +++ b/wire/test/msgstest.go @@ -40,7 +40,7 @@ func AuthMsgsSerializationTest(t *testing.T, serializerTest func(t *testing.T, m t.Helper() rng := pkgtest.Prng(t) - testMsg, err := wire.NewAuthResponseMsg(NewRandomAccountMap(rng, 0)) + testMsg, err := wire.NewAuthResponseMsg(NewRandomAccountMap(rng, TestBackendID)) if err != nil { t.Fatal(err) } diff --git a/wire/test/randomizer.go b/wire/test/randomizer.go index c88f8f1a9..bd0e52182 100644 --- a/wire/test/randomizer.go +++ b/wire/test/randomizer.go @@ -46,7 +46,7 @@ func SetNewRandomAccount(f NewRandomAccountFunc) { // NewRandomAddress returns a new random address. func NewRandomAddress(rng *rand.Rand) map[wallet.BackendID]wire.Address { - return map[wallet.BackendID]wire.Address{0: newRandomAddress(rng)} + return map[wallet.BackendID]wire.Address{TestBackendID: newRandomAddress(rng)} } // NewRandomAccount returns a new random account. From c1fe0e237b087d0c4a59084344e2aba1f4084927 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Mon, 20 Jan 2025 09:20:50 +0100 Subject: [PATCH 32/36] refactor: Name TestBackendID, rename multiLedgerID to LedgerBackendID Signed-off-by: Sophia Koehler --- backend/sim/channel/channel_internal_test.go | 16 ++++++---- backend/sim/channel/init.go | 6 ++-- backend/sim/wallet/address.go | 2 +- backend/sim/wallet/init.go | 5 +-- channel/backend.go | 4 +-- channel/multi/adjudicator.go | 30 +++++++++--------- channel/multi/asset.go | 24 +++++++-------- channel/multi/funder.go | 32 ++++++++++---------- channel/persistence/test/channel.go | 2 +- channel/test/randomizer.go | 2 +- client/proposal.go | 4 +-- client/test/backend.go | 6 ++-- client/test/multiledger.go | 8 ++--- client/test/multiledger_dispute.go | 4 +-- client/test/multiledger_happy.go | 2 +- client/test/proposalmsgs.go | 6 ++-- client/test/randomproposal.go | 6 ++-- client/test/updatemsgs.go | 6 ++-- 18 files changed, 87 insertions(+), 78 deletions(-) diff --git a/backend/sim/channel/channel_internal_test.go b/backend/sim/channel/channel_internal_test.go index 97c81064a..7ab921578 100644 --- a/backend/sim/channel/channel_internal_test.go +++ b/backend/sim/channel/channel_internal_test.go @@ -17,6 +17,8 @@ package channel import ( "testing" + "perun.network/go-perun/channel" + chtest "perun.network/go-perun/channel/test" "perun.network/go-perun/wallet" wtest "perun.network/go-perun/wallet/test" @@ -36,11 +38,13 @@ func newChannelSetup(t *testing.T) *chtest.Setup { params2, state2 := chtest.NewRandomParamsAndState(rng, chtest.WithIsFinal(!state.IsFinal), chtest.WithNumLocked(int(rng.Int31n(4)+1))) return &chtest.Setup{ - Params: params, - Params2: params2, - State: state, - State2: state2, - Account: wtest.NewRandomAccount(rng, 0), - RandomAddress: func() map[wallet.BackendID]wallet.Address { return wtest.NewRandomAddresses(rng, 0) }, + Params: params, + Params2: params2, + State: state, + State2: state2, + Account: wtest.NewRandomAccount(rng, channel.TestBackendID), + RandomAddress: func() map[wallet.BackendID]wallet.Address { + return wtest.NewRandomAddresses(rng, channel.TestBackendID) + }, } } diff --git a/backend/sim/channel/init.go b/backend/sim/channel/init.go index 09dbbe956..633638296 100644 --- a/backend/sim/channel/init.go +++ b/backend/sim/channel/init.go @@ -22,9 +22,9 @@ import ( ) func init() { - channel.SetBackend(new(backend), 0) - test.SetRandomizer(new(randomizer), 0) + channel.SetBackend(new(backend), channel.TestBackendID) + test.SetRandomizer(new(randomizer), channel.TestBackendID) test.SetNewRandomAppID(func(r *rand.Rand) channel.AppID { return NewRandomAppID(r) - }, 0) + }, channel.TestBackendID) } diff --git a/backend/sim/wallet/address.go b/backend/sim/wallet/address.go index 8a3692456..e4c58328d 100644 --- a/backend/sim/wallet/address.go +++ b/backend/sim/wallet/address.go @@ -31,7 +31,7 @@ type Address ecdsa.PublicKey // BackendID returns the backend id of the address. func (a Address) BackendID() wallet.BackendID { - return 0 + return channel.TestBackendID } const ( diff --git a/backend/sim/wallet/init.go b/backend/sim/wallet/init.go index 6fbe08b51..1e8d2673f 100644 --- a/backend/sim/wallet/init.go +++ b/backend/sim/wallet/init.go @@ -15,11 +15,12 @@ package wallet import ( + "perun.network/go-perun/channel" "perun.network/go-perun/wallet" "perun.network/go-perun/wallet/test" ) func init() { - wallet.SetBackend(new(Backend), 0) - test.SetRandomizer(newRandomizer(), 0) + wallet.SetBackend(new(Backend), channel.TestBackendID) + test.SetRandomizer(newRandomizer(), channel.TestBackendID) } diff --git a/channel/backend.go b/channel/backend.go index 5c25782ac..5d31798f4 100644 --- a/channel/backend.go +++ b/channel/backend.go @@ -77,8 +77,8 @@ func CalcID(p *Params) (map[wallet.BackendID]ID, error) { } // Sign creates a signature from the account a on state s. -func Sign(a wallet.Account, s *State, b wallet.BackendID) (wallet.Sig, error) { - return backend[b].Sign(a, s) +func Sign(a wallet.Account, s *State, bID wallet.BackendID) (wallet.Sig, error) { + return backend[bID].Sign(a, s) } // Verify verifies that a signature was a valid signature from addr on a state. diff --git a/channel/multi/adjudicator.go b/channel/multi/adjudicator.go index a7b03922b..0e863bf8b 100644 --- a/channel/multi/adjudicator.go +++ b/channel/multi/adjudicator.go @@ -23,25 +23,25 @@ import ( // Adjudicator is a multi-ledger adjudicator. type Adjudicator struct { - adjudicators map[MultiLedgerIDKey]channel.Adjudicator + adjudicators map[LedgerBackendKey]channel.Adjudicator } // NewAdjudicator creates a new adjudicator. func NewAdjudicator() *Adjudicator { return &Adjudicator{ - adjudicators: make(map[MultiLedgerIDKey]channel.Adjudicator), + adjudicators: make(map[LedgerBackendKey]channel.Adjudicator), } } // RegisterAdjudicator registers an adjudicator for a given ledger. -func (a *Adjudicator) RegisterAdjudicator(l MultiLedgerID, la channel.Adjudicator) { - key := MultiLedgerIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} +func (a *Adjudicator) RegisterAdjudicator(l LedgerBackendID, la channel.Adjudicator) { + key := LedgerBackendKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} a.adjudicators[key] = la } // LedgerAdjudicator returns the adjudicator for a given ledger. -func (a *Adjudicator) LedgerAdjudicator(l MultiLedgerID) (channel.Adjudicator, bool) { - key := MultiLedgerIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} +func (a *Adjudicator) LedgerAdjudicator(l LedgerBackendID) (channel.Adjudicator, bool) { + key := LedgerBackendKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} adj, ok := a.adjudicators[key] return adj, ok } @@ -50,12 +50,12 @@ func (a *Adjudicator) LedgerAdjudicator(l MultiLedgerID) (channel.Adjudicator, b // all relevant adjudicators. If any of the calls fails, the method returns an // error. func (a *Adjudicator) Register(ctx context.Context, req channel.AdjudicatorReq, subStates []channel.SignedState) error { - assetIds, err := assets(req.Tx.Assets).LedgerIDs() + ledgerIDs, err := assets(req.Tx.Assets).LedgerIDs() if err != nil { return err } - err = a.dispatch(assetIds, func(la channel.Adjudicator) error { + err = a.dispatch(ledgerIDs, func(la channel.Adjudicator) error { return la.Register(ctx, req, subStates) }) return err @@ -65,12 +65,12 @@ func (a *Adjudicator) Register(ctx context.Context, req channel.AdjudicatorReq, // Progress calls to all relevant adjudicators. If any of the calls fails, the // method returns an error. func (a *Adjudicator) Progress(ctx context.Context, req channel.ProgressReq) error { - assetIds, err := assets(req.Tx.Assets).LedgerIDs() + ledgerIDs, err := assets(req.Tx.Assets).LedgerIDs() if err != nil { return err } - err = a.dispatch(assetIds, func(la channel.Adjudicator) error { + err = a.dispatch(ledgerIDs, func(la channel.Adjudicator) error { return la.Progress(ctx, req) }) return err @@ -80,25 +80,25 @@ func (a *Adjudicator) Progress(ctx context.Context, req channel.ProgressReq) err // Withdraw calls to all relevant adjudicators. If any of the calls fails, the // method returns an error. func (a *Adjudicator) Withdraw(ctx context.Context, req channel.AdjudicatorReq, subStates channel.StateMap) error { - assetIds, err := assets(req.Tx.Assets).LedgerIDs() + ledgerIDs, err := assets(req.Tx.Assets).LedgerIDs() if err != nil { return err } - err = a.dispatch(assetIds, func(la channel.Adjudicator) error { + err = a.dispatch(ledgerIDs, func(la channel.Adjudicator) error { return la.Withdraw(ctx, req, subStates) }) return err } // dispatch dispatches an adjudicator call on all given ledgers. -func (a *Adjudicator) dispatch(assetIds []MultiLedgerID, f func(channel.Adjudicator) error) error { +func (a *Adjudicator) dispatch(assetIds []LedgerBackendID, f func(channel.Adjudicator) error) error { n := len(assetIds) errs := make(chan error, n) for _, l := range assetIds { - go func(l MultiLedgerID) { + go func(l LedgerBackendID) { err := func() error { - key := MultiLedgerIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} + key := LedgerBackendKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} adjs, ok := a.adjudicators[key] if !ok { return fmt.Errorf("adjudicator not found for id %v", l) diff --git a/channel/multi/asset.go b/channel/multi/asset.go index 65a6dc9ec..98a47eeb7 100644 --- a/channel/multi/asset.go +++ b/channel/multi/asset.go @@ -21,16 +21,16 @@ import ( ) type ( - // Asset defines a multi-ledger asset, extending channel.asset by a method MultiLedgerID() which returns the LedgerID and BackendID. + // Asset defines a multi-ledger asset, extending channel.asset by a method LedgerBackendID() which returns the LedgerID and BackendID. Asset interface { channel.Asset - MultiLedgerID() MultiLedgerID + LedgerBackendID() LedgerBackendID } - // MultiLedgerID represents an asset identifier. + // LedgerBackendID represents an asset identifier. // BackendID returns the identifier of the backend the asset belongs to. // LedgerID returns the identifier of the ledger the asset belongs to. - MultiLedgerID interface { + LedgerBackendID interface { BackendID() uint32 LedgerID() LedgerID } @@ -47,19 +47,19 @@ type ( ) // LedgerIDs returns the identifiers of the associated ledgers. -func (a assets) LedgerIDs() ([]MultiLedgerID, error) { - ids := make(map[MultiLedgerIDKey]MultiLedgerID) +func (a assets) LedgerIDs() ([]LedgerBackendID, error) { + ids := make(map[LedgerBackendKey]LedgerBackendID) for _, asset := range a { ma, ok := asset.(Asset) if !ok { return nil, fmt.Errorf("wrong asset type: expected Asset, got %T", asset) } - assetID := ma.MultiLedgerID() + assetID := ma.LedgerBackendID() - ids[MultiLedgerIDKey{BackendID: assetID.BackendID(), LedgerID: string(assetID.LedgerID().MapKey())}] = assetID + ids[LedgerBackendKey{BackendID: assetID.BackendID(), LedgerID: string(assetID.LedgerID().MapKey())}] = assetID } - idsArray := make([]MultiLedgerID, len(ids)) + idsArray := make([]LedgerBackendID, len(ids)) i := 0 for _, v := range ids { idsArray[i] = v @@ -72,7 +72,7 @@ func (a assets) LedgerIDs() ([]MultiLedgerID, error) { // IsMultiLedgerAssets returns whether the assets are from multiple ledgers. func IsMultiLedgerAssets(assets []channel.Asset) bool { hasMulti := false - var id MultiLedgerID + var id LedgerBackendID for _, asset := range assets { multiAsset, ok := asset.(Asset) switch { @@ -80,8 +80,8 @@ func IsMultiLedgerAssets(assets []channel.Asset) bool { continue case !hasMulti: hasMulti = true - id = multiAsset.MultiLedgerID() - case id.LedgerID().MapKey() != multiAsset.MultiLedgerID().LedgerID().MapKey(): + id = multiAsset.LedgerBackendID() + case id.LedgerID().MapKey() != multiAsset.LedgerBackendID().LedgerID().MapKey(): return true } } diff --git a/channel/multi/funder.go b/channel/multi/funder.go index b836b03b4..7b5d9d6dc 100644 --- a/channel/multi/funder.go +++ b/channel/multi/funder.go @@ -22,8 +22,8 @@ import ( "perun.network/go-perun/channel" ) -// MultiLedgerIDKey is a representation of MultiLedgerID that kan be used in map lookups. -type MultiLedgerIDKey struct { +// LedgerBackendKey is a representation of LedgerBackendID that kan be used in map lookups. +type LedgerBackendKey struct { BackendID uint32 LedgerID string } @@ -32,28 +32,28 @@ type MultiLedgerIDKey struct { // funders is a map of LedgerIDs corresponding to a funder on some chain. // egoisticChains is a map of LedgerIDs corresponding to a boolean indicating whether the chain should be funded last. type Funder struct { - funders map[MultiLedgerIDKey]channel.Funder - egoisticChains map[MultiLedgerIDKey]bool + funders map[LedgerBackendKey]channel.Funder + egoisticChains map[LedgerBackendKey]bool } // NewFunder creates a new funder. func NewFunder() *Funder { return &Funder{ - funders: make(map[MultiLedgerIDKey]channel.Funder), - egoisticChains: make(map[MultiLedgerIDKey]bool), + funders: make(map[LedgerBackendKey]channel.Funder), + egoisticChains: make(map[LedgerBackendKey]bool), } } // RegisterFunder registers a funder for a given ledger. -func (f *Funder) RegisterFunder(l MultiLedgerID, lf channel.Funder) { - key := MultiLedgerIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} +func (f *Funder) RegisterFunder(l LedgerBackendID, lf channel.Funder) { + key := LedgerBackendKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} f.funders[key] = lf f.egoisticChains[key] = false } // SetEgoisticChain sets the egoistic chain flag for a given ledger. -func (f *Funder) SetEgoisticChain(l MultiLedgerID, id int, egoistic bool) { - key := MultiLedgerIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} +func (f *Funder) SetEgoisticChain(l LedgerBackendID, id int, egoistic bool) { + key := LedgerBackendKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} f.egoisticChains[key] = egoistic } @@ -71,11 +71,11 @@ func (f *Funder) Fund(ctx context.Context, request channel.FundingReq) error { return err } - var egoisticLedgers []MultiLedgerID - var nonEgoisticLedgers []MultiLedgerID + var egoisticLedgers []LedgerBackendID + var nonEgoisticLedgers []LedgerBackendID for _, l := range ledgerIDs { - key := MultiLedgerIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} + key := LedgerBackendKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())} if f.egoisticChains[key] { egoisticLedgers = append(egoisticLedgers, l) } else { @@ -98,7 +98,7 @@ func (f *Funder) Fund(ctx context.Context, request channel.FundingReq) error { return nil } -func fundLedgers(ctx context.Context, request channel.FundingReq, assetIDs []MultiLedgerID, funders map[MultiLedgerIDKey]channel.Funder) error { +func fundLedgers(ctx context.Context, request channel.FundingReq, assetIDs []LedgerBackendID, funders map[LedgerBackendKey]channel.Funder) error { // Calculate the total number of funders n := len(assetIDs) @@ -106,8 +106,8 @@ func fundLedgers(ctx context.Context, request channel.FundingReq, assetIDs []Mul // Iterate over blockchains to get the LedgerIDs for _, assetID := range assetIDs { - go func(assetID MultiLedgerID) { - key := MultiLedgerIDKey{BackendID: assetID.BackendID(), LedgerID: string(assetID.LedgerID().MapKey())} + go func(assetID LedgerBackendID) { + key := LedgerBackendKey{BackendID: assetID.BackendID(), LedgerID: string(assetID.LedgerID().MapKey())} // Get the Funder from the funders map funder, ok := funders[key] if !ok { diff --git a/channel/persistence/test/channel.go b/channel/persistence/test/channel.go index 5b6f55d87..37a3784f0 100644 --- a/channel/persistence/test/channel.go +++ b/channel/persistence/test/channel.go @@ -180,7 +180,7 @@ func (c *Channel) SignAll(ctx context.Context, t require.TestingT) { c.AssertPersisted(ctx, t) // remote signers for i := range c.accounts { - sig, err := channel.Sign(c.accounts[i][channel.TestBackendID], c.StagingState(), 0) + sig, err := channel.Sign(c.accounts[i][channel.TestBackendID], c.StagingState(), channel.TestBackendID) require.NoError(t, err) c.AddSig(ctx, channel.Index(i), sig) //nolint:errcheck c.AssertPersisted(ctx, t) diff --git a/channel/test/randomizer.go b/channel/test/randomizer.go index a21964ded..c0fa35f70 100644 --- a/channel/test/randomizer.go +++ b/channel/test/randomizer.go @@ -208,7 +208,7 @@ func NewRandomParams(rng *rand.Rand, opts ...RandomOpt) *channel.Params { if backend, _ = opt.Backend(); backend != 0 { parts[i] = map[wallet.BackendID]wallet.Address{backend: test.NewRandomAddress(rng, backend)} } else { - parts[i] = map[wallet.BackendID]wallet.Address{channel.TestBackendID: test.NewRandomAddress(rng, 0)} + parts[i] = map[wallet.BackendID]wallet.Address{channel.TestBackendID: test.NewRandomAddress(rng, channel.TestBackendID)} } } } diff --git a/client/proposal.go b/client/proposal.go index 9cb8a3be4..a790bd06b 100644 --- a/client/proposal.go +++ b/client/proposal.go @@ -128,7 +128,7 @@ func (r *ProposalResponder) Accept(ctx context.Context, acc ChannelProposalAccep } // SetEgoisticChain sets the egoistic chain flag for a given ledger. -func (r *ProposalResponder) SetEgoisticChain(egoistic multi.MultiLedgerID, id int) { +func (r *ProposalResponder) SetEgoisticChain(egoistic multi.LedgerBackendID, id int) { mf, ok := r.client.funder.(*multi.Funder) if !ok { log.Panic("unexpected type for funder") @@ -137,7 +137,7 @@ func (r *ProposalResponder) SetEgoisticChain(egoistic multi.MultiLedgerID, id in } // RemoveEgoisticChain removes the egoistic chain flag for a given ledger. -func (r *ProposalResponder) RemoveEgoisticChain(egoistic multi.MultiLedgerID, id int) { +func (r *ProposalResponder) RemoveEgoisticChain(egoistic multi.LedgerBackendID, id int) { mf, ok := r.client.funder.(*multi.Funder) if !ok { log.Panic("unexpected type for funder") diff --git a/client/test/backend.go b/client/test/backend.go index 3fe5a5d5c..ae038dbe8 100644 --- a/client/test/backend.go +++ b/client/test/backend.go @@ -39,7 +39,7 @@ type ( latestEvents map[string]channel.AdjudicatorEvent eventSubs map[string][]*MockSubscription balances map[addressMapKey]map[assetMapKey]*big.Int - id multi.MultiLedgerID + id multi.LedgerBackendID } // AssetID is the unique asset identifier. @@ -91,7 +91,7 @@ func NewMockBackend(rng *rand.Rand, id string) *MockBackend { } // ID returns the ledger's identifier. -func (b *MockBackend) ID() multi.MultiLedgerID { +func (b *MockBackend) ID() multi.LedgerBackendID { return b.id } @@ -542,7 +542,7 @@ func (f *assetHolder) Fund(req channel.FundingReq, b *MockBackend, acc wallet.Ad for i, asset := range req.State.Assets { ma, ok := asset.(*MultiLedgerAsset) - if ok && ma.MultiLedgerID() != b.ID() { + if ok && ma.LedgerBackendID() != b.ID() { continue } diff --git a/client/test/multiledger.go b/client/test/multiledger.go index 7f9fd2cf2..31f3433a9 100644 --- a/client/test/multiledger.go +++ b/client/test/multiledger.go @@ -92,17 +92,17 @@ func SetupMultiLedgerTest(t *testing.T) MultiLedgerSetup { // MultiLedgerAsset is a multi-ledger asset. type MultiLedgerAsset struct { - id multi.MultiLedgerID + id multi.LedgerBackendID asset channel.Asset } // AssetID returns the asset's ID. -func (a *MultiLedgerAsset) MultiLedgerID() multi.MultiLedgerID { +func (a *MultiLedgerAsset) LedgerBackendID() multi.LedgerBackendID { return a.id } // NewMultiLedgerAsset returns a new multi-ledger asset. -func NewMultiLedgerAsset(id multi.MultiLedgerID, asset channel.Asset) *MultiLedgerAsset { +func NewMultiLedgerAsset(id multi.LedgerBackendID, asset channel.Asset) *MultiLedgerAsset { return &MultiLedgerAsset{ id: id, asset: asset, @@ -125,7 +125,7 @@ func (a *MultiLedgerAsset) Address() []byte { } // LedgerID returns the asset's ledger ID. -func (a *MultiLedgerAsset) LedgerID() multi.MultiLedgerID { +func (a *MultiLedgerAsset) LedgerID() multi.LedgerBackendID { return a.id } diff --git a/client/test/multiledger_dispute.go b/client/test/multiledger_dispute.go index 1bba32dd6..2325c7445 100644 --- a/client/test/multiledger_dispute.go +++ b/client/test/multiledger_dispute.go @@ -62,8 +62,8 @@ func TestMultiLedgerDispute( // Establish ledger channel between Alice and Bob. - bID1 := wallet.BackendID(mlt.Asset1.MultiLedgerID().BackendID()) - bID2 := wallet.BackendID(mlt.Asset2.MultiLedgerID().BackendID()) + bID1 := wallet.BackendID(mlt.Asset1.LedgerBackendID().BackendID()) + bID2 := wallet.BackendID(mlt.Asset2.LedgerBackendID().BackendID()) // Create channel proposal. parts := []map[wallet.BackendID]wire.Address{alice.WireAddress, bob.WireAddress} initAlloc := channel.NewAllocation(len(parts), []wallet.BackendID{bID1, bID2}, mlt.Asset1, mlt.Asset2) diff --git a/client/test/multiledger_happy.go b/client/test/multiledger_happy.go index 390333c2c..1fd927f23 100644 --- a/client/test/multiledger_happy.go +++ b/client/test/multiledger_happy.go @@ -44,7 +44,7 @@ func TestMultiLedgerHappy(ctx context.Context, t *testing.T, mlt MultiLedgerSetu // Create channel proposal. parts := []map[wallet.BackendID]wire.Address{alice.WireAddress, bob.WireAddress} - initAlloc := channel.NewAllocation(len(parts), []wallet.BackendID{wallet.BackendID(mlt.Asset1.MultiLedgerID().BackendID()), wallet.BackendID(mlt.Asset2.MultiLedgerID().BackendID())}, mlt.Asset1, mlt.Asset2) + initAlloc := channel.NewAllocation(len(parts), []wallet.BackendID{wallet.BackendID(mlt.Asset1.LedgerBackendID().BackendID()), wallet.BackendID(mlt.Asset2.LedgerBackendID().BackendID())}, mlt.Asset1, mlt.Asset2) initAlloc.Balances = initBals prop, err := client.NewLedgerChannelProposal( challengeDuration, diff --git a/client/test/proposalmsgs.go b/client/test/proposalmsgs.go index 2108d666c..a014d518c 100644 --- a/client/test/proposalmsgs.go +++ b/client/test/proposalmsgs.go @@ -18,6 +18,8 @@ import ( "math/rand" "testing" + "perun.network/go-perun/channel" + "github.com/stretchr/testify/require" "perun.network/go-perun/channel/test" @@ -67,7 +69,7 @@ func channelProposalAccSerializationTest(t *testing.T, serializerTest func(t *te t.Run("ledger channel", func(t *testing.T) { for i := 0; i < 16; i++ { proposal := NewRandomLedgerChannelProposal(rng) - m := proposal.Accept(wallettest.NewRandomAddresses(rng, 0), client.WithNonceFrom(rng)) + m := proposal.Accept(wallettest.NewRandomAddresses(rng, channel.TestBackendID), client.WithNonceFrom(rng)) serializerTest(t, m) } }) @@ -85,7 +87,7 @@ func channelProposalAccSerializationTest(t *testing.T, serializerTest func(t *te var err error proposal, err := NewRandomVirtualChannelProposal(rng) require.NoError(t, err) - m := proposal.Accept(wallettest.NewRandomAddresses(rng, 0)) + m := proposal.Accept(wallettest.NewRandomAddresses(rng, channel.TestBackendID)) serializerTest(t, m) } }) diff --git a/client/test/randomproposal.go b/client/test/randomproposal.go index 1ad408fe8..1d916da4e 100644 --- a/client/test/randomproposal.go +++ b/client/test/randomproposal.go @@ -17,6 +17,8 @@ package test import ( "math/rand" + "perun.network/go-perun/channel" + channeltest "perun.network/go-perun/channel/test" "perun.network/go-perun/client" "perun.network/go-perun/wallet" @@ -30,7 +32,7 @@ const randomProposalNumParts = 2 // NewRandomLedgerChannelProposal creates a random channel proposal with the supplied // options. Number of participants is fixed to randomProposalNumParts. func NewRandomLedgerChannelProposal(rng *rand.Rand, opts ...client.ProposalOpts) *client.LedgerChannelProposalMsg { - return NewRandomLedgerChannelProposalBy(rng, wallettest.NewRandomAddresses(rng, 0), opts...) + return NewRandomLedgerChannelProposalBy(rng, wallettest.NewRandomAddresses(rng, channel.TestBackendID), opts...) } // NewRandomLedgerChannelProposalBy creates a random channel proposal with the @@ -65,7 +67,7 @@ func NewRandomVirtualChannelProposal(rng *rand.Rand, opts ...client.ProposalOpts numParts := 2 return client.NewVirtualChannelProposal( rng.Uint64(), - wallettest.NewRandomAddresses(rng, 0), + wallettest.NewRandomAddresses(rng, channel.TestBackendID), channeltest.NewRandomAllocation(rng, channeltest.WithNumParts(numParts)), wiretest.NewRandomAddressesMap(rng, numParts), channeltest.NewRandomChannelIDs(rng, numParts), diff --git a/client/test/updatemsgs.go b/client/test/updatemsgs.go index 931b467a5..3f6d56ee3 100644 --- a/client/test/updatemsgs.go +++ b/client/test/updatemsgs.go @@ -94,7 +94,7 @@ func channelUpdateAccSerializationTest(t *testing.T, serializerTest func(t *test t.Helper() rng := pkgtest.Prng(t) for i := 0; i < 4; i++ { - sig := newRandomSig(rng, 0) + sig := newRandomSig(rng, channel.TestBackendID) m := &client.ChannelUpdateAccMsg{ ChannelID: test.NewRandomChannelID(rng), Version: uint64(rng.Int63()), @@ -121,7 +121,7 @@ func channelUpdateRejSerializationTest(t *testing.T, serializerTest func(t *test func newRandomMsgChannelUpdate(rng *rand.Rand) *client.ChannelUpdateMsg { state := test.NewRandomState(rng) - sig := newRandomSig(rng, 0) + sig := newRandomSig(rng, channel.TestBackendID) return &client.ChannelUpdateMsg{ ChannelUpdate: client.ChannelUpdate{ State: state, @@ -149,7 +149,7 @@ func newRandomSig(rng *rand.Rand, bID wallet.BackendID) wallet.Sig { func newRandomSigs(rng *rand.Rand, n int) (a []wallet.Sig) { a = make([]wallet.Sig, n) for i := range a { - a[i] = newRandomSig(rng, 0) + a[i] = newRandomSig(rng, channel.TestBackendID) } return } From a6d4a4a8dcc4253f43e8cce0bd816d8924401271 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Mon, 20 Jan 2025 09:23:09 +0100 Subject: [PATCH 33/36] refactor: Fix comment on exported function Signed-off-by: Sophia Koehler --- client/test/multiledger.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/test/multiledger.go b/client/test/multiledger.go index 31f3433a9..eb4fcebe2 100644 --- a/client/test/multiledger.go +++ b/client/test/multiledger.go @@ -96,7 +96,7 @@ type MultiLedgerAsset struct { asset channel.Asset } -// AssetID returns the asset's ID. +// LedgerBackendID returns the asset's ID. func (a *MultiLedgerAsset) LedgerBackendID() multi.LedgerBackendID { return a.id } From 5219a0b1a5feb1af5f3c0bc57242b20feb08d72f Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Tue, 28 Jan 2025 08:46:28 +0100 Subject: [PATCH 34/36] chore(all): Update license dates Signed-off-by: Sophia Koehler --- apps/payment/app_internal_test.go | 2 +- apps/payment/randomizer.go | 2 +- apps/payment/randomizer_internal_test.go | 2 +- apps/payment/resolver_internal_test.go | 2 +- backend/sim/channel/app.go | 2 +- backend/sim/channel/asset.go | 2 +- backend/sim/channel/backend.go | 2 +- backend/sim/channel/channel_internal_test.go | 2 +- backend/sim/channel/init.go | 2 +- backend/sim/wallet/account.go | 2 +- backend/sim/wallet/address.go | 2 +- backend/sim/wallet/init.go | 2 +- backend/sim/wallet/wallet.go | 2 +- channel/actionmachine.go | 2 +- channel/adjudicator.go | 2 +- channel/allocation.go | 2 +- channel/allocation_test.go | 2 +- channel/app.go | 2 +- channel/backend.go | 2 +- channel/{backendtest.go => backend_test.go} | 2 +- channel/errors.go | 2 +- channel/errors_internal_test.go | 2 +- channel/machine.go | 2 +- channel/machine_test.go | 2 +- channel/mock_app.go | 2 +- channel/mock_app_internal_test.go | 2 +- channel/multi/adjudicator.go | 2 +- channel/multi/asset.go | 2 +- channel/multi/funder.go | 2 +- channel/multi/subscription.go | 2 +- channel/params.go | 2 +- channel/params_test.go | 2 +- channel/persistence/keyvalue/cache.go | 2 +- channel/persistence/keyvalue/persistedstate.go | 2 +- channel/persistence/keyvalue/persister.go | 2 +- channel/persistence/keyvalue/persistrestorer_internal_test.go | 2 +- channel/persistence/keyvalue/restorer.go | 2 +- channel/persistence/nonpersister.go | 2 +- channel/persistence/persistence.go | 2 +- channel/persistence/statemachine_test.go | 2 +- channel/persistence/test/channel.go | 2 +- channel/persistence/test/peerchans.go | 2 +- channel/persistence/test/peerchans_internal_test.go | 2 +- channel/persistence/test/persistrestorer.go | 2 +- channel/persistence/test/persistrestorertest.go | 2 +- channel/state.go | 2 +- channel/statemachine.go | 2 +- channel/test/app_randomizer.go | 2 +- channel/test/backend.go | 2 +- channel/test/mock_app_randomizer.go | 2 +- channel/test/randomizer.go | 2 +- channel/test/randomopts.go | 2 +- channel/transaction_test.go | 2 +- client/adjudicate.go | 2 +- client/appchannel_test.go | 2 +- client/channel.go | 2 +- client/channelconn.go | 2 +- client/chanregistry.go | 2 +- client/client.go | 2 +- client/client_internal_test.go | 2 +- client/client_persistence_test.go | 2 +- client/client_role_test.go | 2 +- client/client_test.go | 2 +- client/clientconn.go | 2 +- client/failing_funding_test.go | 2 +- client/payment_test.go | 2 +- client/proposal.go | 2 +- client/proposal_internal_test.go | 2 +- client/proposalmsgs.go | 2 +- client/restore.go | 2 +- client/restore_internal_test.go | 2 +- client/serialize.go | 2 +- client/subchannel.go | 2 +- client/subchannel_test.go | 2 +- client/sync.go | 2 +- client/syncmsgs.go | 2 +- client/test/backend.go | 2 +- client/test/channel.go | 2 +- client/test/fund.go | 2 +- client/test/handler.go | 2 +- client/test/multiledger.go | 2 +- client/test/multiledger_dispute.go | 2 +- client/test/multiledger_happy.go | 2 +- client/test/persistence.go | 2 +- client/test/proposalmsgs.go | 2 +- client/test/randomproposal.go | 2 +- client/test/role.go | 2 +- client/test/subchannel.go | 2 +- client/test/subchannel_dispute.go | 2 +- client/test/updatemsgs.go | 2 +- client/test/virtualchannel.go | 2 +- client/update.go | 2 +- client/updateinterception.go | 2 +- client/updatemsgs.go | 2 +- client/virtual_channel.go | 2 +- client/virtual_channel_settlement.go | 2 +- client/virtual_channel_test.go | 2 +- log/logrus/logrus_internal_test.go | 2 +- wallet/address.go | 2 +- wallet/address_test.go | 2 +- wallet/backend.go | 2 +- wallet/sig.go | 2 +- wallet/test/randomizer.go | 2 +- wallet/test/wallet.go | 2 +- wallet/test/walletbench.go | 2 +- watcher/local/adjudicatorpubsub.go | 2 +- watcher/local/registry.go | 2 +- watcher/local/statespubsub.go | 2 +- watcher/local/watcher.go | 2 +- watcher/local/watcher_test.go | 2 +- watcher/watcher.go | 2 +- wire/account.go | 2 +- wire/address.go | 2 +- wire/bus.go | 2 +- wire/encode.go | 2 +- wire/hybridbus.go | 2 +- wire/hybridbus_test.go | 2 +- wire/localbus.go | 2 +- wire/localbus_test.go | 2 +- wire/net/bus.go | 2 +- wire/net/bus_test.go | 2 +- wire/net/dialer.go | 2 +- wire/net/endpoint.go | 2 +- wire/net/endpoint_internal_test.go | 2 +- wire/net/endpoint_registry.go | 2 +- wire/net/endpoint_registry_external_test.go | 2 +- wire/net/endpoint_registry_internal_test.go | 2 +- wire/net/exchange_addr.go | 2 +- wire/net/exchange_addr_internal_test.go | 2 +- wire/net/simple/address.go | 2 +- wire/net/simple/dialer.go | 2 +- wire/net/simple/dialer_internal_test.go | 2 +- wire/net/simple/simple_exchange_addr_test.go | 2 +- wire/net/test/connhub.go | 2 +- wire/net/test/connhub_internal_test.go | 2 +- wire/net/test/dialer.go | 2 +- wire/net/test/listenermap.go | 2 +- wire/perunio/serializer/serializer.go | 2 +- wire/perunio/test/serializertest.go | 2 +- wire/protobuf/proposalmsgs.go | 2 +- wire/protobuf/serializer.go | 2 +- wire/protobuf/updatemsgs.go | 2 +- wire/protobuf/wire.pb.go | 2 +- wire/protobuf/wire.proto | 2 +- wire/test/bustest.go | 2 +- wire/test/msgstest.go | 2 +- wire/test/randomizer.go | 2 +- 147 files changed, 147 insertions(+), 147 deletions(-) rename channel/{backendtest.go => backend_test.go} (95%) diff --git a/apps/payment/app_internal_test.go b/apps/payment/app_internal_test.go index aab9a32f3..417e34e83 100644 --- a/apps/payment/app_internal_test.go +++ b/apps/payment/app_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/apps/payment/randomizer.go b/apps/payment/randomizer.go index 76bf93304..0e5f26268 100644 --- a/apps/payment/randomizer.go +++ b/apps/payment/randomizer.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/apps/payment/randomizer_internal_test.go b/apps/payment/randomizer_internal_test.go index 071964639..cccc1c42e 100644 --- a/apps/payment/randomizer_internal_test.go +++ b/apps/payment/randomizer_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/apps/payment/resolver_internal_test.go b/apps/payment/resolver_internal_test.go index 8bc9f7c4b..1b516d186 100644 --- a/apps/payment/resolver_internal_test.go +++ b/apps/payment/resolver_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/backend/sim/channel/app.go b/backend/sim/channel/app.go index 7bf2601fe..9efb2b298 100644 --- a/backend/sim/channel/app.go +++ b/backend/sim/channel/app.go @@ -1,4 +1,4 @@ -// Copyright 2022 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/backend/sim/channel/asset.go b/backend/sim/channel/asset.go index a7ae10fce..4cf494490 100644 --- a/backend/sim/channel/asset.go +++ b/backend/sim/channel/asset.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/backend/sim/channel/backend.go b/backend/sim/channel/backend.go index 98a25ae08..62e011c18 100644 --- a/backend/sim/channel/backend.go +++ b/backend/sim/channel/backend.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/backend/sim/channel/channel_internal_test.go b/backend/sim/channel/channel_internal_test.go index 7ab921578..bf21bf2d4 100644 --- a/backend/sim/channel/channel_internal_test.go +++ b/backend/sim/channel/channel_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/backend/sim/channel/init.go b/backend/sim/channel/init.go index 633638296..734a654bd 100644 --- a/backend/sim/channel/init.go +++ b/backend/sim/channel/init.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/backend/sim/wallet/account.go b/backend/sim/wallet/account.go index 0eb565813..3f8d01a30 100644 --- a/backend/sim/wallet/account.go +++ b/backend/sim/wallet/account.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/backend/sim/wallet/address.go b/backend/sim/wallet/address.go index e4c58328d..b31424cb8 100644 --- a/backend/sim/wallet/address.go +++ b/backend/sim/wallet/address.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/backend/sim/wallet/init.go b/backend/sim/wallet/init.go index 1e8d2673f..681b2f157 100644 --- a/backend/sim/wallet/init.go +++ b/backend/sim/wallet/init.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/backend/sim/wallet/wallet.go b/backend/sim/wallet/wallet.go index 0cd2e9b1f..f3d3cc5b4 100644 --- a/backend/sim/wallet/wallet.go +++ b/backend/sim/wallet/wallet.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/actionmachine.go b/channel/actionmachine.go index ddc07c764..dd032dba0 100644 --- a/channel/actionmachine.go +++ b/channel/actionmachine.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/adjudicator.go b/channel/adjudicator.go index 238b94bb3..5c0303d9d 100644 --- a/channel/adjudicator.go +++ b/channel/adjudicator.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/allocation.go b/channel/allocation.go index d61316027..872279e3d 100644 --- a/channel/allocation.go +++ b/channel/allocation.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/allocation_test.go b/channel/allocation_test.go index 2372f81f0..a03055dbc 100644 --- a/channel/allocation_test.go +++ b/channel/allocation_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/app.go b/channel/app.go index 66fb7c8c2..e98c282dd 100644 --- a/channel/app.go +++ b/channel/app.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/backend.go b/channel/backend.go index 5d31798f4..4b54edca6 100644 --- a/channel/backend.go +++ b/channel/backend.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/backendtest.go b/channel/backend_test.go similarity index 95% rename from channel/backendtest.go rename to channel/backend_test.go index a0f0570ec..6914fe301 100644 --- a/channel/backendtest.go +++ b/channel/backend_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/errors.go b/channel/errors.go index 5e75bb99d..0814a57e3 100644 --- a/channel/errors.go +++ b/channel/errors.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/errors_internal_test.go b/channel/errors_internal_test.go index 45abae8b8..a6e3a3593 100644 --- a/channel/errors_internal_test.go +++ b/channel/errors_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/machine.go b/channel/machine.go index 08d5a7999..9c9f8c8e2 100644 --- a/channel/machine.go +++ b/channel/machine.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/machine_test.go b/channel/machine_test.go index ec7621930..848a30aa7 100644 --- a/channel/machine_test.go +++ b/channel/machine_test.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/mock_app.go b/channel/mock_app.go index 8d9b03de1..b94a548ed 100644 --- a/channel/mock_app.go +++ b/channel/mock_app.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/mock_app_internal_test.go b/channel/mock_app_internal_test.go index 98bfc3ce0..3c9c8528e 100644 --- a/channel/mock_app_internal_test.go +++ b/channel/mock_app_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/multi/adjudicator.go b/channel/multi/adjudicator.go index 0e863bf8b..b21d22386 100644 --- a/channel/multi/adjudicator.go +++ b/channel/multi/adjudicator.go @@ -1,4 +1,4 @@ -// Copyright 2022 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/multi/asset.go b/channel/multi/asset.go index 98a47eeb7..d6df73bf0 100644 --- a/channel/multi/asset.go +++ b/channel/multi/asset.go @@ -1,4 +1,4 @@ -// Copyright 2022 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/multi/funder.go b/channel/multi/funder.go index 7b5d9d6dc..e7ed8d659 100644 --- a/channel/multi/funder.go +++ b/channel/multi/funder.go @@ -1,4 +1,4 @@ -// Copyright 2022 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/multi/subscription.go b/channel/multi/subscription.go index cc518bb82..603479e8f 100644 --- a/channel/multi/subscription.go +++ b/channel/multi/subscription.go @@ -1,4 +1,4 @@ -// Copyright 2022 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/params.go b/channel/params.go index 560fcdb0c..946f13f10 100644 --- a/channel/params.go +++ b/channel/params.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/params_test.go b/channel/params_test.go index fdb8b295e..321cfd722 100644 --- a/channel/params_test.go +++ b/channel/params_test.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/persistence/keyvalue/cache.go b/channel/persistence/keyvalue/cache.go index 9a748cefd..7b97bf49f 100644 --- a/channel/persistence/keyvalue/cache.go +++ b/channel/persistence/keyvalue/cache.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/persistence/keyvalue/persistedstate.go b/channel/persistence/keyvalue/persistedstate.go index 00d670ef7..f62efe95e 100644 --- a/channel/persistence/keyvalue/persistedstate.go +++ b/channel/persistence/keyvalue/persistedstate.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/persistence/keyvalue/persister.go b/channel/persistence/keyvalue/persister.go index e597e78dc..ff2b6cd76 100644 --- a/channel/persistence/keyvalue/persister.go +++ b/channel/persistence/keyvalue/persister.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/persistence/keyvalue/persistrestorer_internal_test.go b/channel/persistence/keyvalue/persistrestorer_internal_test.go index 3fcf9c878..36a42d69e 100644 --- a/channel/persistence/keyvalue/persistrestorer_internal_test.go +++ b/channel/persistence/keyvalue/persistrestorer_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/persistence/keyvalue/restorer.go b/channel/persistence/keyvalue/restorer.go index cb4ed09c0..f2ead9769 100644 --- a/channel/persistence/keyvalue/restorer.go +++ b/channel/persistence/keyvalue/restorer.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/persistence/nonpersister.go b/channel/persistence/nonpersister.go index bc4d255c0..568b17daf 100644 --- a/channel/persistence/nonpersister.go +++ b/channel/persistence/nonpersister.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/persistence/persistence.go b/channel/persistence/persistence.go index 38b1f04eb..98cd23ffc 100644 --- a/channel/persistence/persistence.go +++ b/channel/persistence/persistence.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/persistence/statemachine_test.go b/channel/persistence/statemachine_test.go index 3221e48d0..22d5455bf 100644 --- a/channel/persistence/statemachine_test.go +++ b/channel/persistence/statemachine_test.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/persistence/test/channel.go b/channel/persistence/test/channel.go index 37a3784f0..05611f6c4 100644 --- a/channel/persistence/test/channel.go +++ b/channel/persistence/test/channel.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/persistence/test/peerchans.go b/channel/persistence/test/peerchans.go index d54b8b6b8..7373af10d 100644 --- a/channel/persistence/test/peerchans.go +++ b/channel/persistence/test/peerchans.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/persistence/test/peerchans_internal_test.go b/channel/persistence/test/peerchans_internal_test.go index d14802362..78f8d5fea 100644 --- a/channel/persistence/test/peerchans_internal_test.go +++ b/channel/persistence/test/peerchans_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/persistence/test/persistrestorer.go b/channel/persistence/test/persistrestorer.go index 77177b867..50e205dc5 100644 --- a/channel/persistence/test/persistrestorer.go +++ b/channel/persistence/test/persistrestorer.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/persistence/test/persistrestorertest.go b/channel/persistence/test/persistrestorertest.go index 6f66aaf26..bd729f04f 100644 --- a/channel/persistence/test/persistrestorertest.go +++ b/channel/persistence/test/persistrestorertest.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/state.go b/channel/state.go index 3d8dfeb8b..fbbb26bd7 100644 --- a/channel/state.go +++ b/channel/state.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/statemachine.go b/channel/statemachine.go index efe595e12..fb0ecee35 100644 --- a/channel/statemachine.go +++ b/channel/statemachine.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/test/app_randomizer.go b/channel/test/app_randomizer.go index 563ff1921..c536684a7 100644 --- a/channel/test/app_randomizer.go +++ b/channel/test/app_randomizer.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/test/backend.go b/channel/test/backend.go index c816f5243..ff1c2a164 100644 --- a/channel/test/backend.go +++ b/channel/test/backend.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/test/mock_app_randomizer.go b/channel/test/mock_app_randomizer.go index e2830acb9..d3814eae6 100644 --- a/channel/test/mock_app_randomizer.go +++ b/channel/test/mock_app_randomizer.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/test/randomizer.go b/channel/test/randomizer.go index c0fa35f70..d53496067 100644 --- a/channel/test/randomizer.go +++ b/channel/test/randomizer.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/test/randomopts.go b/channel/test/randomopts.go index 0ce550159..190df6c89 100644 --- a/channel/test/randomopts.go +++ b/channel/test/randomopts.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/transaction_test.go b/channel/transaction_test.go index 6a7ccc6a0..a13467d55 100644 --- a/channel/transaction_test.go +++ b/channel/transaction_test.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/adjudicate.go b/client/adjudicate.go index d9061165b..c6aa136e1 100644 --- a/client/adjudicate.go +++ b/client/adjudicate.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/appchannel_test.go b/client/appchannel_test.go index d1a44d45a..47edee968 100644 --- a/client/appchannel_test.go +++ b/client/appchannel_test.go @@ -1,4 +1,4 @@ -// Copyright 2022 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/channel.go b/client/channel.go index 4f5da77d7..2b74d0f73 100644 --- a/client/channel.go +++ b/client/channel.go @@ -1,4 +1,4 @@ -// Copyright 2021 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/channelconn.go b/client/channelconn.go index 3c4c6e761..82c6c8f58 100644 --- a/client/channelconn.go +++ b/client/channelconn.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/chanregistry.go b/client/chanregistry.go index 4d7db3027..ed51acd72 100644 --- a/client/chanregistry.go +++ b/client/chanregistry.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/client.go b/client/client.go index adb6795b0..bc42ec591 100644 --- a/client/client.go +++ b/client/client.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/client_internal_test.go b/client/client_internal_test.go index 0c5a639f3..2c398baf4 100644 --- a/client/client_internal_test.go +++ b/client/client_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/client_persistence_test.go b/client/client_persistence_test.go index 9a3dfacac..9a1592d9f 100644 --- a/client/client_persistence_test.go +++ b/client/client_persistence_test.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/client_role_test.go b/client/client_role_test.go index 9cfde977f..19277af87 100644 --- a/client/client_role_test.go +++ b/client/client_role_test.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/client_test.go b/client/client_test.go index c612dca89..602706f55 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -1,4 +1,4 @@ -// Copyright 2021 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/clientconn.go b/client/clientconn.go index 171cee100..513194848 100644 --- a/client/clientconn.go +++ b/client/clientconn.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/failing_funding_test.go b/client/failing_funding_test.go index 123a67652..bebce149d 100644 --- a/client/failing_funding_test.go +++ b/client/failing_funding_test.go @@ -1,4 +1,4 @@ -// Copyright 2022 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/payment_test.go b/client/payment_test.go index 2ac177f5d..dfe892fa1 100644 --- a/client/payment_test.go +++ b/client/payment_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/proposal.go b/client/proposal.go index a790bd06b..4f7392e29 100644 --- a/client/proposal.go +++ b/client/proposal.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/proposal_internal_test.go b/client/proposal_internal_test.go index a50dbf175..cf96a4ccb 100644 --- a/client/proposal_internal_test.go +++ b/client/proposal_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/proposalmsgs.go b/client/proposalmsgs.go index e7dbab419..0469a3bcf 100644 --- a/client/proposalmsgs.go +++ b/client/proposalmsgs.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/restore.go b/client/restore.go index 1e32bc67c..764c0d66b 100644 --- a/client/restore.go +++ b/client/restore.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/restore_internal_test.go b/client/restore_internal_test.go index 11df2ed86..ac0cb0e65 100644 --- a/client/restore_internal_test.go +++ b/client/restore_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/serialize.go b/client/serialize.go index 2449b4533..4bcefe906 100644 --- a/client/serialize.go +++ b/client/serialize.go @@ -1,4 +1,4 @@ -// Copyright 2021 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/subchannel.go b/client/subchannel.go index bfeda2a12..567ab9be7 100644 --- a/client/subchannel.go +++ b/client/subchannel.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/subchannel_test.go b/client/subchannel_test.go index 05eb58332..fd3371fe1 100644 --- a/client/subchannel_test.go +++ b/client/subchannel_test.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/sync.go b/client/sync.go index 2a0eb4c0a..9b390ad4f 100644 --- a/client/sync.go +++ b/client/sync.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/syncmsgs.go b/client/syncmsgs.go index ceb052a56..bebdcd071 100644 --- a/client/syncmsgs.go +++ b/client/syncmsgs.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/test/backend.go b/client/test/backend.go index ae038dbe8..11879d2a8 100644 --- a/client/test/backend.go +++ b/client/test/backend.go @@ -1,4 +1,4 @@ -// Copyright 2021 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/test/channel.go b/client/test/channel.go index a812df0d5..982edb1b5 100644 --- a/client/test/channel.go +++ b/client/test/channel.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/test/fund.go b/client/test/fund.go index 2392894f3..6c9fbe8f3 100644 --- a/client/test/fund.go +++ b/client/test/fund.go @@ -1,4 +1,4 @@ -// Copyright 2022 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/test/handler.go b/client/test/handler.go index 0dbe2ec99..875986bcd 100644 --- a/client/test/handler.go +++ b/client/test/handler.go @@ -1,4 +1,4 @@ -// Copyright 2022 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/test/multiledger.go b/client/test/multiledger.go index eb4fcebe2..5ae9ebfec 100644 --- a/client/test/multiledger.go +++ b/client/test/multiledger.go @@ -1,4 +1,4 @@ -// Copyright 2022 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/test/multiledger_dispute.go b/client/test/multiledger_dispute.go index 2325c7445..6e06d2be2 100644 --- a/client/test/multiledger_dispute.go +++ b/client/test/multiledger_dispute.go @@ -1,4 +1,4 @@ -// Copyright 2022 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/test/multiledger_happy.go b/client/test/multiledger_happy.go index 1fd927f23..53d0810c1 100644 --- a/client/test/multiledger_happy.go +++ b/client/test/multiledger_happy.go @@ -1,4 +1,4 @@ -// Copyright 2022 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/test/persistence.go b/client/test/persistence.go index 80f58fdfb..eb095db2f 100644 --- a/client/test/persistence.go +++ b/client/test/persistence.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/test/proposalmsgs.go b/client/test/proposalmsgs.go index a014d518c..8be9a03ef 100644 --- a/client/test/proposalmsgs.go +++ b/client/test/proposalmsgs.go @@ -1,4 +1,4 @@ -// Copyright 2022 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/test/randomproposal.go b/client/test/randomproposal.go index 1d916da4e..6d4ce577b 100644 --- a/client/test/randomproposal.go +++ b/client/test/randomproposal.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/test/role.go b/client/test/role.go index 68b391ce1..354e33ef5 100644 --- a/client/test/role.go +++ b/client/test/role.go @@ -1,4 +1,4 @@ -// Copyright 2021 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/test/subchannel.go b/client/test/subchannel.go index 7e06d99ef..eeeeeeb84 100644 --- a/client/test/subchannel.go +++ b/client/test/subchannel.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/test/subchannel_dispute.go b/client/test/subchannel_dispute.go index e0e1322f9..e6e176937 100644 --- a/client/test/subchannel_dispute.go +++ b/client/test/subchannel_dispute.go @@ -1,4 +1,4 @@ -// Copyright 2021 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/test/updatemsgs.go b/client/test/updatemsgs.go index 3f6d56ee3..20bad50d9 100644 --- a/client/test/updatemsgs.go +++ b/client/test/updatemsgs.go @@ -1,4 +1,4 @@ -// Copyright 2022 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/test/virtualchannel.go b/client/test/virtualchannel.go index 60eda7329..42bd9d73c 100644 --- a/client/test/virtualchannel.go +++ b/client/test/virtualchannel.go @@ -1,4 +1,4 @@ -// Copyright 2022 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/update.go b/client/update.go index ddec31913..d0c93553d 100644 --- a/client/update.go +++ b/client/update.go @@ -1,4 +1,4 @@ -// Copyright 2021 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/updateinterception.go b/client/updateinterception.go index 2627c0413..a81fd712f 100644 --- a/client/updateinterception.go +++ b/client/updateinterception.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/updatemsgs.go b/client/updatemsgs.go index 9f42de0b6..bdecedc32 100644 --- a/client/updatemsgs.go +++ b/client/updatemsgs.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/virtual_channel.go b/client/virtual_channel.go index 596a6d359..0019fba83 100644 --- a/client/virtual_channel.go +++ b/client/virtual_channel.go @@ -1,4 +1,4 @@ -// Copyright 2021 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/virtual_channel_settlement.go b/client/virtual_channel_settlement.go index 532dc28b3..7d68d667c 100644 --- a/client/virtual_channel_settlement.go +++ b/client/virtual_channel_settlement.go @@ -1,4 +1,4 @@ -// Copyright 2021 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/virtual_channel_test.go b/client/virtual_channel_test.go index d2c8f751b..7ed87f700 100644 --- a/client/virtual_channel_test.go +++ b/client/virtual_channel_test.go @@ -1,4 +1,4 @@ -// Copyright 2021 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/log/logrus/logrus_internal_test.go b/log/logrus/logrus_internal_test.go index a2f606204..bcfc462c9 100644 --- a/log/logrus/logrus_internal_test.go +++ b/log/logrus/logrus_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wallet/address.go b/wallet/address.go index 89f189c6e..599e671f5 100644 --- a/wallet/address.go +++ b/wallet/address.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wallet/address_test.go b/wallet/address_test.go index fbc83917a..b41950989 100644 --- a/wallet/address_test.go +++ b/wallet/address_test.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wallet/backend.go b/wallet/backend.go index 1f272427c..6839a4a52 100644 --- a/wallet/backend.go +++ b/wallet/backend.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wallet/sig.go b/wallet/sig.go index ea56e0cd9..0bc435a34 100644 --- a/wallet/sig.go +++ b/wallet/sig.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wallet/test/randomizer.go b/wallet/test/randomizer.go index b952fa028..a244d6f6b 100644 --- a/wallet/test/randomizer.go +++ b/wallet/test/randomizer.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wallet/test/wallet.go b/wallet/test/wallet.go index 9de843ddb..be65912d8 100644 --- a/wallet/test/wallet.go +++ b/wallet/test/wallet.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wallet/test/walletbench.go b/wallet/test/walletbench.go index fb00b8f73..406afbbf1 100644 --- a/wallet/test/walletbench.go +++ b/wallet/test/walletbench.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/watcher/local/adjudicatorpubsub.go b/watcher/local/adjudicatorpubsub.go index 4b7fbda90..abf1e50ac 100644 --- a/watcher/local/adjudicatorpubsub.go +++ b/watcher/local/adjudicatorpubsub.go @@ -1,4 +1,4 @@ -// Copyright 2021 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/watcher/local/registry.go b/watcher/local/registry.go index 6faeb572a..67f429816 100644 --- a/watcher/local/registry.go +++ b/watcher/local/registry.go @@ -1,4 +1,4 @@ -// Copyright 2021 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/watcher/local/statespubsub.go b/watcher/local/statespubsub.go index 5874d121c..270787e75 100644 --- a/watcher/local/statespubsub.go +++ b/watcher/local/statespubsub.go @@ -1,4 +1,4 @@ -// Copyright 2021 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/watcher/local/watcher.go b/watcher/local/watcher.go index ee6ce65b7..4aed8fb5a 100644 --- a/watcher/local/watcher.go +++ b/watcher/local/watcher.go @@ -1,4 +1,4 @@ -// Copyright 2021 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/watcher/local/watcher_test.go b/watcher/local/watcher_test.go index 244ad5532..3087c6d43 100644 --- a/watcher/local/watcher_test.go +++ b/watcher/local/watcher_test.go @@ -1,4 +1,4 @@ -// Copyright 2021 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/watcher/watcher.go b/watcher/watcher.go index 1e01a3358..975c31ecf 100644 --- a/watcher/watcher.go +++ b/watcher/watcher.go @@ -1,4 +1,4 @@ -// Copyright 2021 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/account.go b/wire/account.go index 616fa230a..f458aa143 100644 --- a/wire/account.go +++ b/wire/account.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/address.go b/wire/address.go index 48df14996..5778bce45 100644 --- a/wire/address.go +++ b/wire/address.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/bus.go b/wire/bus.go index 1844c9a40..265ebfeb0 100644 --- a/wire/bus.go +++ b/wire/bus.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/encode.go b/wire/encode.go index 2c2f39a6b..11145f0cf 100644 --- a/wire/encode.go +++ b/wire/encode.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/hybridbus.go b/wire/hybridbus.go index 0b30b0b14..6ac59421a 100644 --- a/wire/hybridbus.go +++ b/wire/hybridbus.go @@ -1,4 +1,4 @@ -// Copyright 2022 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/hybridbus_test.go b/wire/hybridbus_test.go index 1b5265749..152d17065 100644 --- a/wire/hybridbus_test.go +++ b/wire/hybridbus_test.go @@ -1,4 +1,4 @@ -// Copyright 2022 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/localbus.go b/wire/localbus.go index 80294a48f..cd84ba795 100644 --- a/wire/localbus.go +++ b/wire/localbus.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/localbus_test.go b/wire/localbus_test.go index 2d5141822..cdc394a30 100644 --- a/wire/localbus_test.go +++ b/wire/localbus_test.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/bus.go b/wire/net/bus.go index adfa33e59..291ea788f 100644 --- a/wire/net/bus.go +++ b/wire/net/bus.go @@ -1,4 +1,4 @@ -// Copyright 2021 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/bus_test.go b/wire/net/bus_test.go index 80e5e80f6..825efe4fd 100644 --- a/wire/net/bus_test.go +++ b/wire/net/bus_test.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/dialer.go b/wire/net/dialer.go index 5e0e55d17..2c270aedf 100644 --- a/wire/net/dialer.go +++ b/wire/net/dialer.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/endpoint.go b/wire/net/endpoint.go index 898416ce8..4c1dc31ab 100644 --- a/wire/net/endpoint.go +++ b/wire/net/endpoint.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/endpoint_internal_test.go b/wire/net/endpoint_internal_test.go index 6476e0672..35b1fefad 100644 --- a/wire/net/endpoint_internal_test.go +++ b/wire/net/endpoint_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/endpoint_registry.go b/wire/net/endpoint_registry.go index b7bf7d8d6..9e2a614a0 100644 --- a/wire/net/endpoint_registry.go +++ b/wire/net/endpoint_registry.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/endpoint_registry_external_test.go b/wire/net/endpoint_registry_external_test.go index 2f3179104..a1593665e 100644 --- a/wire/net/endpoint_registry_external_test.go +++ b/wire/net/endpoint_registry_external_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/endpoint_registry_internal_test.go b/wire/net/endpoint_registry_internal_test.go index ea0471665..b0e55b76b 100644 --- a/wire/net/endpoint_registry_internal_test.go +++ b/wire/net/endpoint_registry_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2021 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/exchange_addr.go b/wire/net/exchange_addr.go index 54a97235f..9538a0ee4 100644 --- a/wire/net/exchange_addr.go +++ b/wire/net/exchange_addr.go @@ -1,4 +1,4 @@ -// Copyright 2021 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/exchange_addr_internal_test.go b/wire/net/exchange_addr_internal_test.go index 6a1fc7b5b..bba650b23 100644 --- a/wire/net/exchange_addr_internal_test.go +++ b/wire/net/exchange_addr_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/simple/address.go b/wire/net/simple/address.go index c10bc166f..1dcdbe1ed 100644 --- a/wire/net/simple/address.go +++ b/wire/net/simple/address.go @@ -1,4 +1,4 @@ -// Copyright 2022 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/simple/dialer.go b/wire/net/simple/dialer.go index a1447c21c..1b9f179c9 100644 --- a/wire/net/simple/dialer.go +++ b/wire/net/simple/dialer.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/simple/dialer_internal_test.go b/wire/net/simple/dialer_internal_test.go index 9555b1f66..8f8f57f91 100644 --- a/wire/net/simple/dialer_internal_test.go +++ b/wire/net/simple/dialer_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/simple/simple_exchange_addr_test.go b/wire/net/simple/simple_exchange_addr_test.go index ad6954395..b02da64af 100644 --- a/wire/net/simple/simple_exchange_addr_test.go +++ b/wire/net/simple/simple_exchange_addr_test.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/test/connhub.go b/wire/net/test/connhub.go index 8a7c3b5ce..6221e5fa7 100644 --- a/wire/net/test/connhub.go +++ b/wire/net/test/connhub.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/test/connhub_internal_test.go b/wire/net/test/connhub_internal_test.go index 4ca17d601..b0f63ce49 100644 --- a/wire/net/test/connhub_internal_test.go +++ b/wire/net/test/connhub_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/test/dialer.go b/wire/net/test/dialer.go index 5fe5137e6..b6f9a991f 100644 --- a/wire/net/test/dialer.go +++ b/wire/net/test/dialer.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/test/listenermap.go b/wire/net/test/listenermap.go index 19515bce3..1bc4c7ff6 100644 --- a/wire/net/test/listenermap.go +++ b/wire/net/test/listenermap.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/perunio/serializer/serializer.go b/wire/perunio/serializer/serializer.go index 3665e84a7..d1172542e 100644 --- a/wire/perunio/serializer/serializer.go +++ b/wire/perunio/serializer/serializer.go @@ -1,4 +1,4 @@ -// Copyright 2022 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/perunio/test/serializertest.go b/wire/perunio/test/serializertest.go index 79e39afd6..fbb793eb9 100644 --- a/wire/perunio/test/serializertest.go +++ b/wire/perunio/test/serializertest.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/protobuf/proposalmsgs.go b/wire/protobuf/proposalmsgs.go index 1dc048e25..d13bba1ba 100644 --- a/wire/protobuf/proposalmsgs.go +++ b/wire/protobuf/proposalmsgs.go @@ -1,4 +1,4 @@ -// Copyright 2022 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/protobuf/serializer.go b/wire/protobuf/serializer.go index 1b4fe8140..f2a03dc07 100644 --- a/wire/protobuf/serializer.go +++ b/wire/protobuf/serializer.go @@ -1,4 +1,4 @@ -// Copyright 2022 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/protobuf/updatemsgs.go b/wire/protobuf/updatemsgs.go index 70dcf33af..81cd72b33 100644 --- a/wire/protobuf/updatemsgs.go +++ b/wire/protobuf/updatemsgs.go @@ -1,4 +1,4 @@ -// Copyright 2022 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/protobuf/wire.pb.go b/wire/protobuf/wire.pb.go index 31ea66cb3..d7673f19e 100644 --- a/wire/protobuf/wire.pb.go +++ b/wire/protobuf/wire.pb.go @@ -1,4 +1,4 @@ -// Copyright 2022 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/protobuf/wire.proto b/wire/protobuf/wire.proto index 32212f781..7d4e65613 100644 --- a/wire/protobuf/wire.proto +++ b/wire/protobuf/wire.proto @@ -1,4 +1,4 @@ -// Copyright 2022 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/test/bustest.go b/wire/test/bustest.go index 7e474d8b7..2534f37be 100644 --- a/wire/test/bustest.go +++ b/wire/test/bustest.go @@ -1,4 +1,4 @@ -// Copyright 2020 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/test/msgstest.go b/wire/test/msgstest.go index dc5f34c48..9a64977d7 100644 --- a/wire/test/msgstest.go +++ b/wire/test/msgstest.go @@ -1,4 +1,4 @@ -// Copyright 2022 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/test/randomizer.go b/wire/test/randomizer.go index bd0e52182..60387919e 100644 --- a/wire/test/randomizer.go +++ b/wire/test/randomizer.go @@ -1,4 +1,4 @@ -// Copyright 2019 - See NOTICE file for copyright holders. +// Copyright 2024 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. From a404ea6faee5d6efdbd1ed3d85e95091ec40fa8f Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Tue, 28 Jan 2025 09:05:56 +0100 Subject: [PATCH 35/36] chore(backendtest): Rename to fix import issues Signed-off-by: Sophia Koehler --- channel/{backend_test.go => backendtest.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename channel/{backend_test.go => backendtest.go} (100%) diff --git a/channel/backend_test.go b/channel/backendtest.go similarity index 100% rename from channel/backend_test.go rename to channel/backendtest.go From 3e596db328917149a96d5464aac0686a5b7cc545 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Tue, 28 Jan 2025 15:03:22 +0100 Subject: [PATCH 36/36] chore: Update license date fix: revert increased timeouts Signed-off-by: Sophia Koehler --- apps/payment/app_internal_test.go | 2 +- apps/payment/randomizer.go | 2 +- apps/payment/randomizer_internal_test.go | 2 +- apps/payment/resolver_internal_test.go | 2 +- backend/sim/channel/app.go | 2 +- backend/sim/channel/asset.go | 2 +- backend/sim/channel/backend.go | 2 +- backend/sim/channel/channel_internal_test.go | 2 +- backend/sim/channel/init.go | 2 +- backend/sim/wallet/account.go | 2 +- backend/sim/wallet/address.go | 2 +- backend/sim/wallet/init.go | 2 +- backend/sim/wallet/wallet.go | 2 +- channel/actionmachine.go | 2 +- channel/adjudicator.go | 2 +- channel/allocation.go | 2 +- channel/allocation_test.go | 2 +- channel/app.go | 2 +- channel/backend.go | 2 +- channel/backendtest.go | 2 +- channel/errors.go | 2 +- channel/errors_internal_test.go | 2 +- channel/machine.go | 2 +- channel/machine_test.go | 2 +- channel/mock_app.go | 2 +- channel/mock_app_internal_test.go | 2 +- channel/multi/adjudicator.go | 2 +- channel/multi/asset.go | 2 +- channel/multi/funder.go | 2 +- channel/multi/subscription.go | 2 +- channel/params.go | 2 +- channel/params_test.go | 2 +- channel/persistence/keyvalue/cache.go | 2 +- channel/persistence/keyvalue/persistedstate.go | 2 +- channel/persistence/keyvalue/persister.go | 2 +- .../keyvalue/persistrestorer_internal_test.go | 2 +- channel/persistence/keyvalue/restorer.go | 2 +- channel/persistence/nonpersister.go | 2 +- channel/persistence/persistence.go | 2 +- channel/persistence/statemachine_test.go | 2 +- channel/persistence/test/channel.go | 2 +- channel/persistence/test/peerchans.go | 2 +- channel/persistence/test/peerchans_internal_test.go | 2 +- channel/persistence/test/persistrestorer.go | 2 +- channel/persistence/test/persistrestorertest.go | 2 +- channel/state.go | 2 +- channel/statemachine.go | 2 +- channel/test/app_randomizer.go | 2 +- channel/test/backend.go | 2 +- channel/test/mock_app_randomizer.go | 2 +- channel/test/randomizer.go | 2 +- channel/test/randomopts.go | 2 +- channel/transaction_test.go | 2 +- client/adjudicate.go | 2 +- client/appchannel_test.go | 2 +- client/channel.go | 2 +- client/channelconn.go | 2 +- client/chanregistry.go | 2 +- client/client.go | 2 +- client/client_internal_test.go | 4 ++-- client/client_persistence_test.go | 2 +- client/client_role_test.go | 6 +++--- client/client_test.go | 13 ++++--------- client/clientconn.go | 2 +- client/failing_funding_test.go | 2 +- client/payment_test.go | 2 +- client/proposal.go | 2 +- client/proposal_internal_test.go | 9 +++++---- client/proposalmsgs.go | 2 +- client/restore.go | 2 +- client/restore_internal_test.go | 2 +- client/serialize.go | 2 +- client/subchannel.go | 2 +- client/subchannel_test.go | 2 +- client/sync.go | 2 +- client/syncmsgs.go | 2 +- client/test/backend.go | 2 +- client/test/channel.go | 2 +- client/test/fund.go | 10 +++------- client/test/handler.go | 2 +- client/test/multiledger.go | 2 +- client/test/multiledger_dispute.go | 2 +- client/test/multiledger_happy.go | 2 +- client/test/persistence.go | 2 +- client/test/proposalmsgs.go | 2 +- client/test/randomproposal.go | 2 +- client/test/role.go | 2 +- client/test/subchannel.go | 2 +- client/test/subchannel_dispute.go | 2 +- client/test/updatemsgs.go | 2 +- client/test/virtualchannel.go | 3 ++- client/update.go | 2 +- client/updateinterception.go | 2 +- client/updatemsgs.go | 2 +- client/virtual_channel.go | 2 +- client/virtual_channel_settlement.go | 2 +- client/virtual_channel_test.go | 4 ++-- log/logrus/logrus_internal_test.go | 2 +- wallet/address.go | 2 +- wallet/address_test.go | 2 +- wallet/backend.go | 2 +- wallet/sig.go | 2 +- wallet/test/randomizer.go | 2 +- wallet/test/wallet.go | 2 +- wallet/test/walletbench.go | 2 +- watcher/local/adjudicatorpubsub.go | 2 +- watcher/local/registry.go | 2 +- watcher/local/statespubsub.go | 2 +- watcher/local/watcher.go | 2 +- watcher/local/watcher_test.go | 2 +- watcher/watcher.go | 2 +- wire/account.go | 6 ++++-- wire/address.go | 2 +- wire/bus.go | 2 +- wire/encode.go | 2 +- wire/hybridbus.go | 2 +- wire/hybridbus_test.go | 2 +- wire/localbus.go | 2 +- wire/localbus_test.go | 2 +- wire/net/bus.go | 2 +- wire/net/bus_test.go | 2 +- wire/net/dialer.go | 2 +- wire/net/endpoint.go | 2 +- wire/net/endpoint_internal_test.go | 2 +- wire/net/endpoint_registry.go | 2 +- wire/net/endpoint_registry_external_test.go | 2 +- wire/net/endpoint_registry_internal_test.go | 2 +- wire/net/exchange_addr.go | 2 +- wire/net/exchange_addr_internal_test.go | 2 +- wire/net/simple/address.go | 2 +- wire/net/simple/dialer.go | 2 +- wire/net/simple/dialer_internal_test.go | 2 +- wire/net/simple/simple_exchange_addr_test.go | 2 +- wire/net/test/connhub.go | 2 +- wire/net/test/connhub_internal_test.go | 2 +- wire/net/test/dialer.go | 2 +- wire/net/test/listenermap.go | 2 +- wire/perunio/serializer/serializer.go | 2 +- wire/perunio/test/serializertest.go | 2 +- wire/protobuf/proposalmsgs.go | 2 +- wire/protobuf/serializer.go | 2 +- wire/protobuf/updatemsgs.go | 2 +- wire/protobuf/wire.pb.go | 2 +- wire/protobuf/wire.proto | 2 +- wire/test/bustest.go | 2 +- wire/test/msgstest.go | 2 +- wire/test/randomizer.go | 11 +---------- 147 files changed, 164 insertions(+), 178 deletions(-) diff --git a/apps/payment/app_internal_test.go b/apps/payment/app_internal_test.go index 417e34e83..19c46d5e4 100644 --- a/apps/payment/app_internal_test.go +++ b/apps/payment/app_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/apps/payment/randomizer.go b/apps/payment/randomizer.go index 0e5f26268..8f4421a07 100644 --- a/apps/payment/randomizer.go +++ b/apps/payment/randomizer.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/apps/payment/randomizer_internal_test.go b/apps/payment/randomizer_internal_test.go index cccc1c42e..c178314cf 100644 --- a/apps/payment/randomizer_internal_test.go +++ b/apps/payment/randomizer_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/apps/payment/resolver_internal_test.go b/apps/payment/resolver_internal_test.go index 1b516d186..9508a0346 100644 --- a/apps/payment/resolver_internal_test.go +++ b/apps/payment/resolver_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/backend/sim/channel/app.go b/backend/sim/channel/app.go index 9efb2b298..2c32d7e7c 100644 --- a/backend/sim/channel/app.go +++ b/backend/sim/channel/app.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/backend/sim/channel/asset.go b/backend/sim/channel/asset.go index 4cf494490..2e66db169 100644 --- a/backend/sim/channel/asset.go +++ b/backend/sim/channel/asset.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/backend/sim/channel/backend.go b/backend/sim/channel/backend.go index 62e011c18..44a5bd7b8 100644 --- a/backend/sim/channel/backend.go +++ b/backend/sim/channel/backend.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/backend/sim/channel/channel_internal_test.go b/backend/sim/channel/channel_internal_test.go index bf21bf2d4..645c376ee 100644 --- a/backend/sim/channel/channel_internal_test.go +++ b/backend/sim/channel/channel_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/backend/sim/channel/init.go b/backend/sim/channel/init.go index 734a654bd..e94759ebf 100644 --- a/backend/sim/channel/init.go +++ b/backend/sim/channel/init.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/backend/sim/wallet/account.go b/backend/sim/wallet/account.go index 3f8d01a30..e89277c76 100644 --- a/backend/sim/wallet/account.go +++ b/backend/sim/wallet/account.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/backend/sim/wallet/address.go b/backend/sim/wallet/address.go index b31424cb8..22fc621a6 100644 --- a/backend/sim/wallet/address.go +++ b/backend/sim/wallet/address.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/backend/sim/wallet/init.go b/backend/sim/wallet/init.go index 681b2f157..e2060b630 100644 --- a/backend/sim/wallet/init.go +++ b/backend/sim/wallet/init.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/backend/sim/wallet/wallet.go b/backend/sim/wallet/wallet.go index f3d3cc5b4..37f431153 100644 --- a/backend/sim/wallet/wallet.go +++ b/backend/sim/wallet/wallet.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/actionmachine.go b/channel/actionmachine.go index dd032dba0..453b67a1e 100644 --- a/channel/actionmachine.go +++ b/channel/actionmachine.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/adjudicator.go b/channel/adjudicator.go index 5c0303d9d..82c77ca84 100644 --- a/channel/adjudicator.go +++ b/channel/adjudicator.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/allocation.go b/channel/allocation.go index 872279e3d..3b9e4b275 100644 --- a/channel/allocation.go +++ b/channel/allocation.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/allocation_test.go b/channel/allocation_test.go index a03055dbc..9a1ed790d 100644 --- a/channel/allocation_test.go +++ b/channel/allocation_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/app.go b/channel/app.go index e98c282dd..cd9d5305f 100644 --- a/channel/app.go +++ b/channel/app.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/backend.go b/channel/backend.go index 4b54edca6..8d5fe29e2 100644 --- a/channel/backend.go +++ b/channel/backend.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/backendtest.go b/channel/backendtest.go index 6914fe301..d7bb6f373 100644 --- a/channel/backendtest.go +++ b/channel/backendtest.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/errors.go b/channel/errors.go index 0814a57e3..556689de3 100644 --- a/channel/errors.go +++ b/channel/errors.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/errors_internal_test.go b/channel/errors_internal_test.go index a6e3a3593..923143647 100644 --- a/channel/errors_internal_test.go +++ b/channel/errors_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/machine.go b/channel/machine.go index 9c9f8c8e2..5bc3380bb 100644 --- a/channel/machine.go +++ b/channel/machine.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/machine_test.go b/channel/machine_test.go index 848a30aa7..327d222eb 100644 --- a/channel/machine_test.go +++ b/channel/machine_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/mock_app.go b/channel/mock_app.go index b94a548ed..98ace957c 100644 --- a/channel/mock_app.go +++ b/channel/mock_app.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/mock_app_internal_test.go b/channel/mock_app_internal_test.go index 3c9c8528e..a59da88fe 100644 --- a/channel/mock_app_internal_test.go +++ b/channel/mock_app_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/multi/adjudicator.go b/channel/multi/adjudicator.go index b21d22386..60fe2512f 100644 --- a/channel/multi/adjudicator.go +++ b/channel/multi/adjudicator.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/multi/asset.go b/channel/multi/asset.go index d6df73bf0..d162eb0c7 100644 --- a/channel/multi/asset.go +++ b/channel/multi/asset.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/multi/funder.go b/channel/multi/funder.go index e7ed8d659..dc8cd0b5f 100644 --- a/channel/multi/funder.go +++ b/channel/multi/funder.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/multi/subscription.go b/channel/multi/subscription.go index 603479e8f..73ef5c027 100644 --- a/channel/multi/subscription.go +++ b/channel/multi/subscription.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/params.go b/channel/params.go index 946f13f10..f10437d44 100644 --- a/channel/params.go +++ b/channel/params.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/params_test.go b/channel/params_test.go index 321cfd722..14a268329 100644 --- a/channel/params_test.go +++ b/channel/params_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/persistence/keyvalue/cache.go b/channel/persistence/keyvalue/cache.go index 7b97bf49f..5b0ad8cf1 100644 --- a/channel/persistence/keyvalue/cache.go +++ b/channel/persistence/keyvalue/cache.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/persistence/keyvalue/persistedstate.go b/channel/persistence/keyvalue/persistedstate.go index f62efe95e..77b2a0a69 100644 --- a/channel/persistence/keyvalue/persistedstate.go +++ b/channel/persistence/keyvalue/persistedstate.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/persistence/keyvalue/persister.go b/channel/persistence/keyvalue/persister.go index ff2b6cd76..77e160832 100644 --- a/channel/persistence/keyvalue/persister.go +++ b/channel/persistence/keyvalue/persister.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/persistence/keyvalue/persistrestorer_internal_test.go b/channel/persistence/keyvalue/persistrestorer_internal_test.go index 36a42d69e..de878154a 100644 --- a/channel/persistence/keyvalue/persistrestorer_internal_test.go +++ b/channel/persistence/keyvalue/persistrestorer_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/persistence/keyvalue/restorer.go b/channel/persistence/keyvalue/restorer.go index f2ead9769..77e7841db 100644 --- a/channel/persistence/keyvalue/restorer.go +++ b/channel/persistence/keyvalue/restorer.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/persistence/nonpersister.go b/channel/persistence/nonpersister.go index 568b17daf..daad0e2f3 100644 --- a/channel/persistence/nonpersister.go +++ b/channel/persistence/nonpersister.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/persistence/persistence.go b/channel/persistence/persistence.go index 98cd23ffc..a7ff234dc 100644 --- a/channel/persistence/persistence.go +++ b/channel/persistence/persistence.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/persistence/statemachine_test.go b/channel/persistence/statemachine_test.go index 22d5455bf..b9c403f5b 100644 --- a/channel/persistence/statemachine_test.go +++ b/channel/persistence/statemachine_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/persistence/test/channel.go b/channel/persistence/test/channel.go index 05611f6c4..699ae4552 100644 --- a/channel/persistence/test/channel.go +++ b/channel/persistence/test/channel.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/persistence/test/peerchans.go b/channel/persistence/test/peerchans.go index 7373af10d..7520dea72 100644 --- a/channel/persistence/test/peerchans.go +++ b/channel/persistence/test/peerchans.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/persistence/test/peerchans_internal_test.go b/channel/persistence/test/peerchans_internal_test.go index 78f8d5fea..274d943d2 100644 --- a/channel/persistence/test/peerchans_internal_test.go +++ b/channel/persistence/test/peerchans_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/persistence/test/persistrestorer.go b/channel/persistence/test/persistrestorer.go index 50e205dc5..1eb373a09 100644 --- a/channel/persistence/test/persistrestorer.go +++ b/channel/persistence/test/persistrestorer.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/persistence/test/persistrestorertest.go b/channel/persistence/test/persistrestorertest.go index bd729f04f..0702898d3 100644 --- a/channel/persistence/test/persistrestorertest.go +++ b/channel/persistence/test/persistrestorertest.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/state.go b/channel/state.go index fbbb26bd7..c41f5ac83 100644 --- a/channel/state.go +++ b/channel/state.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/statemachine.go b/channel/statemachine.go index fb0ecee35..2508b3475 100644 --- a/channel/statemachine.go +++ b/channel/statemachine.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/test/app_randomizer.go b/channel/test/app_randomizer.go index c536684a7..d1eda5330 100644 --- a/channel/test/app_randomizer.go +++ b/channel/test/app_randomizer.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/test/backend.go b/channel/test/backend.go index ff1c2a164..2138d9f2f 100644 --- a/channel/test/backend.go +++ b/channel/test/backend.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/test/mock_app_randomizer.go b/channel/test/mock_app_randomizer.go index d3814eae6..5b2788504 100644 --- a/channel/test/mock_app_randomizer.go +++ b/channel/test/mock_app_randomizer.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/test/randomizer.go b/channel/test/randomizer.go index d53496067..da57e1d75 100644 --- a/channel/test/randomizer.go +++ b/channel/test/randomizer.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/test/randomopts.go b/channel/test/randomopts.go index 190df6c89..b1a99d064 100644 --- a/channel/test/randomopts.go +++ b/channel/test/randomopts.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/transaction_test.go b/channel/transaction_test.go index a13467d55..70d2a2726 100644 --- a/channel/transaction_test.go +++ b/channel/transaction_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/adjudicate.go b/client/adjudicate.go index c6aa136e1..781b25a77 100644 --- a/client/adjudicate.go +++ b/client/adjudicate.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/appchannel_test.go b/client/appchannel_test.go index 47edee968..e21127b68 100644 --- a/client/appchannel_test.go +++ b/client/appchannel_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/channel.go b/client/channel.go index 2b74d0f73..2644baa78 100644 --- a/client/channel.go +++ b/client/channel.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/channelconn.go b/client/channelconn.go index 82c6c8f58..9d26bdaeb 100644 --- a/client/channelconn.go +++ b/client/channelconn.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/chanregistry.go b/client/chanregistry.go index ed51acd72..cf7da1138 100644 --- a/client/chanregistry.go +++ b/client/chanregistry.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/client.go b/client/client.go index bc42ec591..7ecefbb93 100644 --- a/client/client.go +++ b/client/client.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/client_internal_test.go b/client/client_internal_test.go index 2c398baf4..7ef75c15a 100644 --- a/client/client_internal_test.go +++ b/client/client_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -28,7 +28,7 @@ func TestClient_Channel(t *testing.T) { rng := test.Prng(t) // dummy client that only has an id and a registry c := &Client{ - address: wiretest.NewRandomAddressesMap(rng, 1)[0], + address: wiretest.NewRandomAddress(rng), channels: makeChanRegistry(), } diff --git a/client/client_persistence_test.go b/client/client_persistence_test.go index 9a1592d9f..1c984be78 100644 --- a/client/client_persistence_test.go +++ b/client/client_persistence_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/client_role_test.go b/client/client_role_test.go index 19277af87..09d0904d8 100644 --- a/client/client_role_test.go +++ b/client/client_role_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -38,7 +38,7 @@ import ( const ( roleOperationTimeout = 1 * time.Second - twoPartyTestTimeout = 20 * time.Second + twoPartyTestTimeout = 10 * time.Second ) func NewSetups(rng *rand.Rand, names []string, bID wallet.BackendID) []ctest.RoleSetup { @@ -55,7 +55,7 @@ func NewSetups(rng *rand.Rand, names []string, bID wallet.BackendID) []ctest.Rol panic("Error initializing watcher: " + err.Error()) } w := map[wallet.BackendID]wtest.Wallet{bID: wtest.NewWallet(bID)} - acc := w[0].NewRandomAccount(rng) + acc := w[bID].NewRandomAccount(rng) setup[i] = ctest.RoleSetup{ Name: names[i], Identity: wiretest.NewRandomAccountMap(rng, bID), diff --git a/client/client_test.go b/client/client_test.go index 602706f55..0963289e9 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -51,7 +51,7 @@ func (d DummyBus) SubscribeClient(wire.Consumer, map[wallet.BackendID]wire.Addre func TestClient_New_NilArgs(t *testing.T) { rng := test.Prng(t) - id := wiretest.NewRandomAddressesMap(rng, 1)[0] + id := wiretest.NewRandomAddress(rng) backend := &ctest.MockBackend{} b, f, a, w := &DummyBus{t}, &ctest.MockFunder{}, &ctest.MockAdjudicator{}, map[wallet.BackendID]wallet.Wallet{channel.TestBackendID: wtest.RandomWallet(channel.TestBackendID)} watcher, err := local.NewWatcher(backend) @@ -84,7 +84,7 @@ func TestClient_New(t *testing.T) { backend := &ctest.MockBackend{} watcher, err := local.NewWatcher(backend) require.NoError(t, err, "initializing the watcher should not error") - c, err := client.New(wiretest.NewRandomAddressesMap(rng, 1)[0], + c, err := client.New(wiretest.NewRandomAddress(rng), &DummyBus{t}, &ctest.MockFunder{}, &ctest.MockAdjudicator{}, map[wallet.BackendID]wallet.Wallet{channel.TestBackendID: wtest.RandomWallet(channel.TestBackendID)}, watcher) assert.NoError(t, err) require.NotNil(t, c) @@ -114,12 +114,7 @@ func TestChannelRejection(t *testing.T) { // Create channel proposal. parts := []map[wallet.BackendID]wire.Address{wire.AddressMapfromAccountMap(alice.Identity), wire.AddressMapfromAccountMap(bob.Identity)} - var bID wallet.BackendID - for i := range parts[0] { - bID = i - break - } - initAlloc := channel.NewAllocation(len(parts), []wallet.BackendID{bID}, asset) + initAlloc := channel.NewAllocation(len(parts), []wallet.BackendID{channel.TestBackendID}, asset) prop, err := client.NewLedgerChannelProposal( challengeDuration, alice.WalletAddress, diff --git a/client/clientconn.go b/client/clientconn.go index 513194848..9ba36e369 100644 --- a/client/clientconn.go +++ b/client/clientconn.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/failing_funding_test.go b/client/failing_funding_test.go index bebce149d..50fd8ec87 100644 --- a/client/failing_funding_test.go +++ b/client/failing_funding_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/payment_test.go b/client/payment_test.go index dfe892fa1..b5e7923a4 100644 --- a/client/payment_test.go +++ b/client/payment_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/proposal.go b/client/proposal.go index 4f7392e29..bfffdd709 100644 --- a/client/proposal.go +++ b/client/proposal.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/proposal_internal_test.go b/client/proposal_internal_test.go index cf96a4ccb..ed45afaf0 100644 --- a/client/proposal_internal_test.go +++ b/client/proposal_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -37,7 +37,7 @@ func TestClient_validTwoPartyProposal(t *testing.T) { // dummy client that only has an id c := &Client{ - address: wiretest.NewRandomAddressesMap(rng, 1)[0], + address: wiretest.NewRandomAddress(rng), } validProp := NewRandomLedgerChannelProposal(rng, channeltest.WithNumParts(2)) validProp.Peers[0] = c.address // set us as the proposer @@ -155,8 +155,9 @@ func NewRandomLedgerChannelProposal(rng *rand.Rand, opts ...channeltest.RandomOp base := NewRandomBaseChannelProposal(rng, opt) peers := wiretest.NewRandomAddressesMap(rng, base.NumPeers()) var bID wallet.BackendID - for i := range peers[0] { - bID = i + bID, err := opt.Backend() + if err != nil { + bID = wallet.BackendID(channel.TestBackendID) } return &LedgerChannelProposalMsg{ BaseChannelProposal: base, diff --git a/client/proposalmsgs.go b/client/proposalmsgs.go index 0469a3bcf..5f9472d97 100644 --- a/client/proposalmsgs.go +++ b/client/proposalmsgs.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/restore.go b/client/restore.go index 764c0d66b..3fb1c00b9 100644 --- a/client/restore.go +++ b/client/restore.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/restore_internal_test.go b/client/restore_internal_test.go index ac0cb0e65..8951c6619 100644 --- a/client/restore_internal_test.go +++ b/client/restore_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/serialize.go b/client/serialize.go index 4bcefe906..308b7a75e 100644 --- a/client/serialize.go +++ b/client/serialize.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/subchannel.go b/client/subchannel.go index 567ab9be7..be41efdff 100644 --- a/client/subchannel.go +++ b/client/subchannel.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/subchannel_test.go b/client/subchannel_test.go index fd3371fe1..50b4c3a1f 100644 --- a/client/subchannel_test.go +++ b/client/subchannel_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/sync.go b/client/sync.go index 9b390ad4f..cc7cfafda 100644 --- a/client/sync.go +++ b/client/sync.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/syncmsgs.go b/client/syncmsgs.go index bebdcd071..29dc8a520 100644 --- a/client/syncmsgs.go +++ b/client/syncmsgs.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/test/backend.go b/client/test/backend.go index 11879d2a8..1f9488869 100644 --- a/client/test/backend.go +++ b/client/test/backend.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/test/channel.go b/client/test/channel.go index 982edb1b5..2162d851d 100644 --- a/client/test/channel.go +++ b/client/test/channel.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/test/fund.go b/client/test/fund.go index 6c9fbe8f3..448e047a9 100644 --- a/client/test/fund.go +++ b/client/test/fund.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -113,13 +113,9 @@ func runFredFridaTest( AlwaysAcceptChannelHandler(ctx, fredWalletAddr, chsFred, errsFred), AlwaysRejectUpdateHandler(ctx, errsFred), ) - var bID wallet.BackendID - for i := range fridaWalletAddr { - bID = i - break - } + // Create the proposal. - initAlloc := channel.NewAllocation(numParts, []wallet.BackendID{bID}, asset) + initAlloc := channel.NewAllocation(numParts, []wallet.BackendID{channel.TestBackendID}, asset) initAlloc.SetAssetBalances(asset, []*big.Int{fridaInitBal, fredInitBal}) parts := []map[wallet.BackendID]wire.Address{fridaWireAddr, fredWireAddr} prop, err := client.NewLedgerChannelProposal( diff --git a/client/test/handler.go b/client/test/handler.go index 875986bcd..72c815f6c 100644 --- a/client/test/handler.go +++ b/client/test/handler.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/test/multiledger.go b/client/test/multiledger.go index 5ae9ebfec..7aa275136 100644 --- a/client/test/multiledger.go +++ b/client/test/multiledger.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/test/multiledger_dispute.go b/client/test/multiledger_dispute.go index 6e06d2be2..cabf66c90 100644 --- a/client/test/multiledger_dispute.go +++ b/client/test/multiledger_dispute.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/test/multiledger_happy.go b/client/test/multiledger_happy.go index 53d0810c1..36375428e 100644 --- a/client/test/multiledger_happy.go +++ b/client/test/multiledger_happy.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/test/persistence.go b/client/test/persistence.go index eb095db2f..0053a4813 100644 --- a/client/test/persistence.go +++ b/client/test/persistence.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/test/proposalmsgs.go b/client/test/proposalmsgs.go index 8be9a03ef..840c3d99e 100644 --- a/client/test/proposalmsgs.go +++ b/client/test/proposalmsgs.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/test/randomproposal.go b/client/test/randomproposal.go index 6d4ce577b..3cdf9f315 100644 --- a/client/test/randomproposal.go +++ b/client/test/randomproposal.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/test/role.go b/client/test/role.go index 354e33ef5..8635bf818 100644 --- a/client/test/role.go +++ b/client/test/role.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/test/subchannel.go b/client/test/subchannel.go index eeeeeeb84..061840fa6 100644 --- a/client/test/subchannel.go +++ b/client/test/subchannel.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/test/subchannel_dispute.go b/client/test/subchannel_dispute.go index e6e176937..f870efcac 100644 --- a/client/test/subchannel_dispute.go +++ b/client/test/subchannel_dispute.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/test/updatemsgs.go b/client/test/updatemsgs.go index 20bad50d9..e1a4e1332 100644 --- a/client/test/updatemsgs.go +++ b/client/test/updatemsgs.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/test/virtualchannel.go b/client/test/virtualchannel.go index 42bd9d73c..8fba0215d 100644 --- a/client/test/virtualchannel.go +++ b/client/test/virtualchannel.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -223,6 +223,7 @@ func setupVirtualChannelTest( var bID wallet.BackendID for i := range peersAlice[0] { bID = i + break } initAllocAlice := channel.NewAllocation(len(peersAlice), []wallet.BackendID{bID}, asset) initAllocAlice.SetAssetBalances(asset, vct.initBalsAlice) diff --git a/client/update.go b/client/update.go index d0c93553d..f75efa0ee 100644 --- a/client/update.go +++ b/client/update.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/updateinterception.go b/client/updateinterception.go index a81fd712f..bd78f8b0f 100644 --- a/client/updateinterception.go +++ b/client/updateinterception.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/updatemsgs.go b/client/updatemsgs.go index bdecedc32..3e9505aae 100644 --- a/client/updatemsgs.go +++ b/client/updatemsgs.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/virtual_channel.go b/client/virtual_channel.go index 0019fba83..26e6563e2 100644 --- a/client/virtual_channel.go +++ b/client/virtual_channel.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/virtual_channel_settlement.go b/client/virtual_channel_settlement.go index 7d68d667c..c38fa17da 100644 --- a/client/virtual_channel_settlement.go +++ b/client/virtual_channel_settlement.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/client/virtual_channel_test.go b/client/virtual_channel_test.go index 7ed87f700..b8e746d50 100644 --- a/client/virtual_channel_test.go +++ b/client/virtual_channel_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -29,7 +29,7 @@ import ( ) const ( - challengeDuration = 15 + challengeDuration = 10 testDuration = 10 * time.Second ) diff --git a/log/logrus/logrus_internal_test.go b/log/logrus/logrus_internal_test.go index bcfc462c9..874f313d3 100644 --- a/log/logrus/logrus_internal_test.go +++ b/log/logrus/logrus_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wallet/address.go b/wallet/address.go index 599e671f5..429983b36 100644 --- a/wallet/address.go +++ b/wallet/address.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wallet/address_test.go b/wallet/address_test.go index b41950989..ccfb65495 100644 --- a/wallet/address_test.go +++ b/wallet/address_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wallet/backend.go b/wallet/backend.go index 6839a4a52..2ef0b7b71 100644 --- a/wallet/backend.go +++ b/wallet/backend.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wallet/sig.go b/wallet/sig.go index 0bc435a34..881d2e4d1 100644 --- a/wallet/sig.go +++ b/wallet/sig.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wallet/test/randomizer.go b/wallet/test/randomizer.go index a244d6f6b..35aab64b8 100644 --- a/wallet/test/randomizer.go +++ b/wallet/test/randomizer.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wallet/test/wallet.go b/wallet/test/wallet.go index be65912d8..a520388f9 100644 --- a/wallet/test/wallet.go +++ b/wallet/test/wallet.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wallet/test/walletbench.go b/wallet/test/walletbench.go index 406afbbf1..b5cc5709f 100644 --- a/wallet/test/walletbench.go +++ b/wallet/test/walletbench.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/watcher/local/adjudicatorpubsub.go b/watcher/local/adjudicatorpubsub.go index abf1e50ac..3a7fca63d 100644 --- a/watcher/local/adjudicatorpubsub.go +++ b/watcher/local/adjudicatorpubsub.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/watcher/local/registry.go b/watcher/local/registry.go index 67f429816..9c7ed6062 100644 --- a/watcher/local/registry.go +++ b/watcher/local/registry.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/watcher/local/statespubsub.go b/watcher/local/statespubsub.go index 270787e75..9012d6d17 100644 --- a/watcher/local/statespubsub.go +++ b/watcher/local/statespubsub.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/watcher/local/watcher.go b/watcher/local/watcher.go index 4aed8fb5a..d242a86aa 100644 --- a/watcher/local/watcher.go +++ b/watcher/local/watcher.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/watcher/local/watcher_test.go b/watcher/local/watcher_test.go index 3087c6d43..cc1992bc5 100644 --- a/watcher/local/watcher_test.go +++ b/watcher/local/watcher_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/watcher/watcher.go b/watcher/watcher.go index 975c31ecf..5e6d64c13 100644 --- a/watcher/watcher.go +++ b/watcher/watcher.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/account.go b/wire/account.go index f458aa143..117b99259 100644 --- a/wire/account.go +++ b/wire/account.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -40,6 +40,8 @@ type Account interface { Sign(msg []byte) ([]byte, error) } +const testBackendID = 0 + var _ Msg = (*AuthResponseMsg)(nil) // AuthResponseMsg is the response message in the peer authentication protocol. @@ -96,7 +98,7 @@ func NewAuthResponseMsg(acc map[wallet.BackendID]Account) (Msg, error) { } addressBytes = append(addressBytes, addrBytes...) } - signature, err := acc[0].Sign(addressBytes) + signature, err := acc[testBackendID].Sign(addressBytes) if err != nil { return nil, fmt.Errorf("failed to sign address: %w", err) } diff --git a/wire/address.go b/wire/address.go index 5778bce45..2d0875dcb 100644 --- a/wire/address.go +++ b/wire/address.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/bus.go b/wire/bus.go index 265ebfeb0..6d10dce4a 100644 --- a/wire/bus.go +++ b/wire/bus.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/encode.go b/wire/encode.go index 11145f0cf..0eeff299e 100644 --- a/wire/encode.go +++ b/wire/encode.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/hybridbus.go b/wire/hybridbus.go index 6ac59421a..6015d56ec 100644 --- a/wire/hybridbus.go +++ b/wire/hybridbus.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/hybridbus_test.go b/wire/hybridbus_test.go index 152d17065..f46241ed0 100644 --- a/wire/hybridbus_test.go +++ b/wire/hybridbus_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/localbus.go b/wire/localbus.go index cd84ba795..0dda06a29 100644 --- a/wire/localbus.go +++ b/wire/localbus.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/localbus_test.go b/wire/localbus_test.go index cdc394a30..148f33b16 100644 --- a/wire/localbus_test.go +++ b/wire/localbus_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/bus.go b/wire/net/bus.go index 291ea788f..9847f868c 100644 --- a/wire/net/bus.go +++ b/wire/net/bus.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/bus_test.go b/wire/net/bus_test.go index 825efe4fd..de169d6bd 100644 --- a/wire/net/bus_test.go +++ b/wire/net/bus_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/dialer.go b/wire/net/dialer.go index 2c270aedf..4584777bf 100644 --- a/wire/net/dialer.go +++ b/wire/net/dialer.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/endpoint.go b/wire/net/endpoint.go index 4c1dc31ab..902c101ab 100644 --- a/wire/net/endpoint.go +++ b/wire/net/endpoint.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/endpoint_internal_test.go b/wire/net/endpoint_internal_test.go index 35b1fefad..0abe4734f 100644 --- a/wire/net/endpoint_internal_test.go +++ b/wire/net/endpoint_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/endpoint_registry.go b/wire/net/endpoint_registry.go index 9e2a614a0..79be8eee9 100644 --- a/wire/net/endpoint_registry.go +++ b/wire/net/endpoint_registry.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/endpoint_registry_external_test.go b/wire/net/endpoint_registry_external_test.go index a1593665e..53dd657f3 100644 --- a/wire/net/endpoint_registry_external_test.go +++ b/wire/net/endpoint_registry_external_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/endpoint_registry_internal_test.go b/wire/net/endpoint_registry_internal_test.go index b0e55b76b..85173325e 100644 --- a/wire/net/endpoint_registry_internal_test.go +++ b/wire/net/endpoint_registry_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/exchange_addr.go b/wire/net/exchange_addr.go index 9538a0ee4..caa41efbc 100644 --- a/wire/net/exchange_addr.go +++ b/wire/net/exchange_addr.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/exchange_addr_internal_test.go b/wire/net/exchange_addr_internal_test.go index bba650b23..d9ddf2c3b 100644 --- a/wire/net/exchange_addr_internal_test.go +++ b/wire/net/exchange_addr_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/simple/address.go b/wire/net/simple/address.go index 1dcdbe1ed..069d60dd8 100644 --- a/wire/net/simple/address.go +++ b/wire/net/simple/address.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/simple/dialer.go b/wire/net/simple/dialer.go index 1b9f179c9..546019d70 100644 --- a/wire/net/simple/dialer.go +++ b/wire/net/simple/dialer.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/simple/dialer_internal_test.go b/wire/net/simple/dialer_internal_test.go index 8f8f57f91..1ac60e6c3 100644 --- a/wire/net/simple/dialer_internal_test.go +++ b/wire/net/simple/dialer_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/simple/simple_exchange_addr_test.go b/wire/net/simple/simple_exchange_addr_test.go index b02da64af..885b00747 100644 --- a/wire/net/simple/simple_exchange_addr_test.go +++ b/wire/net/simple/simple_exchange_addr_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/test/connhub.go b/wire/net/test/connhub.go index 6221e5fa7..9ae13467b 100644 --- a/wire/net/test/connhub.go +++ b/wire/net/test/connhub.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/test/connhub_internal_test.go b/wire/net/test/connhub_internal_test.go index b0f63ce49..edd97b411 100644 --- a/wire/net/test/connhub_internal_test.go +++ b/wire/net/test/connhub_internal_test.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/test/dialer.go b/wire/net/test/dialer.go index b6f9a991f..c9658bc1a 100644 --- a/wire/net/test/dialer.go +++ b/wire/net/test/dialer.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/net/test/listenermap.go b/wire/net/test/listenermap.go index 1bc4c7ff6..fcdb1fadf 100644 --- a/wire/net/test/listenermap.go +++ b/wire/net/test/listenermap.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/perunio/serializer/serializer.go b/wire/perunio/serializer/serializer.go index d1172542e..6d38e1590 100644 --- a/wire/perunio/serializer/serializer.go +++ b/wire/perunio/serializer/serializer.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/perunio/test/serializertest.go b/wire/perunio/test/serializertest.go index fbb793eb9..01899d2a1 100644 --- a/wire/perunio/test/serializertest.go +++ b/wire/perunio/test/serializertest.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/protobuf/proposalmsgs.go b/wire/protobuf/proposalmsgs.go index d13bba1ba..72e305c60 100644 --- a/wire/protobuf/proposalmsgs.go +++ b/wire/protobuf/proposalmsgs.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/protobuf/serializer.go b/wire/protobuf/serializer.go index f2a03dc07..9d13d2351 100644 --- a/wire/protobuf/serializer.go +++ b/wire/protobuf/serializer.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/protobuf/updatemsgs.go b/wire/protobuf/updatemsgs.go index 81cd72b33..d539560c5 100644 --- a/wire/protobuf/updatemsgs.go +++ b/wire/protobuf/updatemsgs.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/protobuf/wire.pb.go b/wire/protobuf/wire.pb.go index d7673f19e..55404ddec 100644 --- a/wire/protobuf/wire.pb.go +++ b/wire/protobuf/wire.pb.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/protobuf/wire.proto b/wire/protobuf/wire.proto index 7d4e65613..fefd7becd 100644 --- a/wire/protobuf/wire.proto +++ b/wire/protobuf/wire.proto @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/test/bustest.go b/wire/test/bustest.go index 2534f37be..2f871d3f1 100644 --- a/wire/test/bustest.go +++ b/wire/test/bustest.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/test/msgstest.go b/wire/test/msgstest.go index 9a64977d7..29e8d3a68 100644 --- a/wire/test/msgstest.go +++ b/wire/test/msgstest.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/wire/test/randomizer.go b/wire/test/randomizer.go index 60387919e..b4a9fe013 100644 --- a/wire/test/randomizer.go +++ b/wire/test/randomizer.go @@ -1,4 +1,4 @@ -// Copyright 2024 - See NOTICE file for copyright holders. +// Copyright 2025 - See NOTICE file for copyright holders. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -59,15 +59,6 @@ func NewRandomAccountMap(rng *rand.Rand, bID wallet.BackendID) map[wallet.Backen return map[wallet.BackendID]wire.Account{bID: newRandomAccount(rng)} } -// NewRandomAddresses returns a slice of random peer addresses. -func NewRandomAddresses(rng *rand.Rand, n int) []map[wallet.BackendID]wire.Address { - addresses := make([]map[wallet.BackendID]wire.Address, n) - for i := range addresses { - addresses[i] = NewRandomAddress(rng) - } - return addresses -} - // NewRandomAddressesMap returns a slice of random peer addresses. func NewRandomAddressesMap(rng *rand.Rand, n int) []map[wallet.BackendID]wire.Address { addresses := make([]map[wallet.BackendID]wire.Address, n)