Skip to content

Commit f824816

Browse files
authored
Fix egoistic funding (#414)
* 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 <sophia@perun.network> * 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 <sophia@perun.network> * fix(all): Use map[int]ID instead of id for each backend. Signed-off-by: Sophia Koehler <sophia@perun.network> * fix(all): Add map of IDs Signed-off-by: Sophia Koehler <sophia@perun.network> * 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 <sophia@perun.network> * fix(Adjudicator): Change to singular channel ID in events. Signed-off-by: Sophia Koehler <sophia@perun.network> * fix(client/test): Generalize role test. Signed-off-by: Sophia Koehler <sophia@perun.network> * feat(channel): Add backend field check. feat(client/test, wire): Add backendID arguments. Signed-off-by: Sophia Koehler <sophia@perun.network> * fix(subchannel_dispute): Generalize event watcher. Signed-off-by: Sophia Koehler <sophia@perun.network> * feat: Asset Address function to handle encoding in backends. Signed-off-by: Sophia Koehler <sophia@perun.network> * 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 <sophia@perun.network> * 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 <sophia@perun.network> * chore: Remove unnecessary logs Signed-off-by: Sophia Koehler <sophia@perun.network> * fix: Remove repeated assetIDs in LedgerID array Signed-off-by: Sophia Koehler <sophia@perun.network> * chore: update go.sum, gofmt some files Signed-off-by: Sophia Koehler <sophia@perun.network> * 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 <sophia@perun.network> * fix(golangci.yml): Exclude generated file from linter chore: Refactor for linter Signed-off-by: Sophia Koehler <sophia@perun.network> * fix(ci): Use go1.18 for the any type in proto fix(golangci): Fix structure Signed-off-by: Sophia Koehler <sophia@perun.network> * fix(ci): Use glinter 1.45 which supports go1.18 Signed-off-by: Sophia Koehler <sophia@perun.network> * chore(all): Add nolint flags for conversions Signed-off-by: Sophia Koehler <sophia@perun.network> * chore(all): remove unnecessary flags Signed-off-by: Sophia Koehler <sophia@perun.network> * chore(all): remove unnecessary flags Signed-off-by: Sophia Koehler <sophia@perun.network> * chore(all): remove unnecessary flags Signed-off-by: Sophia Koehler <sophia@perun.network> * chore(all): remove unnecessary flags Signed-off-by: Sophia Koehler <sophia@perun.network> * chore(all): remove unnecessary flags Signed-off-by: Sophia Koehler <sophia@perun.network> * chore(all): remove unnecessary flags Signed-off-by: Sophia Koehler <sophia@perun.network> * chore(all): remove unnecessary flags Signed-off-by: Sophia Koehler <sophia@perun.network> * chore(all): Rename and add comments to exported functions Signed-off-by: Sophia Koehler <sophia@perun.network> * chore: Rename variables Signed-off-by: Sophia Koehler <sophia@perun.network> * fix(params, address): Fix index allocation Signed-off-by: Sophia Koehler <sophia@perun.network> * fix(funder, proposal): Make egoistic funding dependant on participant index instead of chain and remove unnecessary functions. Signed-off-by: Sophia Koehler <sophia@perun.network> * Revert "fix(all): Add map of IDs" Revert "fix(all): Use map[int]ID instead of id for each backend." This reverts commit ab8e60b and ef11de9 Signed-off-by: Sophia Koehler <sophia@perun.network> * fix(backend.go): Remove unnecessary errors.join() Signed-off-by: Sophia Koehler <sophia@perun.network> * fix: remove unnecessary else statement, add linter flag Signed-off-by: Sophia Koehler <sophia@perun.network> * 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 <sophia@perun.network> * chore: Update proto binding, remove IDMap Signed-off-by: Sophia Koehler <sophia@perun.network> * refactor: Name TestBackendID, rename multiLedgerID to LedgerBackendID Signed-off-by: Sophia Koehler <sophia@perun.network> * refactor: Fix comment on exported function Signed-off-by: Sophia Koehler <sophia@perun.network> * fix(funder): Add egoistic check, otherwise one participant is always egoistic Signed-off-by: Sophia Koehler <sophia@perun.network> * chore(all): Update license dates Signed-off-by: Sophia Koehler <sophia@perun.network> * chore(backendtest): Rename to fix import issues Signed-off-by: Sophia Koehler <sophia@perun.network> * fix(allocation_test): Remove channelID map from merge fix(wire.pb.go): go fmt Signed-off-by: Sophia Koehler <sophia@perun.network> --------- Signed-off-by: Sophia Koehler <sophia@perun.network>
1 parent eddc25b commit f824816

File tree

3 files changed

+14
-33
lines changed

3 files changed

+14
-33
lines changed

channel/multi/funder.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,32 @@ type LedgerBackendKey struct {
3030

3131
// Funder is a multi-ledger funder.
3232
// funders is a map of LedgerIDs corresponding to a funder on some chain.
33-
// egoisticChains is a map of LedgerIDs corresponding to a boolean indicating whether the chain should be funded last.
33+
// egoistic controls whether the funder uses the egoisticIndex to control the funding order.
34+
// egoisticIndex controls which participant index will fund last.
3435
type Funder struct {
35-
funders map[LedgerBackendKey]channel.Funder
36-
egoisticChains map[LedgerBackendKey]bool
36+
funders map[LedgerBackendKey]channel.Funder
37+
egoistic bool
38+
egoisticIndex int
3739
}
3840

3941
// NewFunder creates a new funder.
4042
func NewFunder() *Funder {
4143
return &Funder{
42-
funders: make(map[LedgerBackendKey]channel.Funder),
43-
egoisticChains: make(map[LedgerBackendKey]bool),
44+
funders: make(map[LedgerBackendKey]channel.Funder),
45+
egoistic: false,
4446
}
4547
}
4648

4749
// RegisterFunder registers a funder for a given ledger.
4850
func (f *Funder) RegisterFunder(l LedgerBackendID, lf channel.Funder) {
4951
key := LedgerBackendKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())}
5052
f.funders[key] = lf
51-
f.egoisticChains[key] = false
5253
}
5354

54-
// SetEgoisticChain sets the egoistic chain flag for a given ledger.
55-
func (f *Funder) SetEgoisticChain(l LedgerBackendID, id int, egoistic bool) {
56-
key := LedgerBackendKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())}
57-
f.egoisticChains[key] = egoistic
55+
// SetEgoisticPart sets the egoistic chain flag for a given ledger.
56+
func (f *Funder) SetEgoisticPart(index int) {
57+
f.egoisticIndex = index
58+
f.egoistic = true
5859
}
5960

6061
// Fund funds a multi-ledger channel. It dispatches funding calls to all
@@ -74,9 +75,8 @@ func (f *Funder) Fund(ctx context.Context, request channel.FundingReq) error {
7475
var egoisticLedgers []LedgerBackendID
7576
var nonEgoisticLedgers []LedgerBackendID
7677

77-
for _, l := range ledgerIDs {
78-
key := LedgerBackendKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())}
79-
if f.egoisticChains[key] {
78+
for i, l := range ledgerIDs {
79+
if f.egoistic && f.egoisticIndex == i {
8080
egoisticLedgers = append(egoisticLedgers, l)
8181
} else {
8282
nonEgoisticLedgers = append(nonEgoisticLedgers, l)
@@ -128,6 +128,5 @@ func fundLedgers(ctx context.Context, request channel.FundingReq, assetIDs []Led
128128
return err
129129
}
130130
}
131-
132131
return nil
133132
}

client/proposal.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -127,24 +127,6 @@ func (r *ProposalResponder) Accept(ctx context.Context, acc ChannelProposalAccep
127127
return r.client.handleChannelProposalAcc(ctx, r.peer, r.req, acc)
128128
}
129129

130-
// SetEgoisticChain sets the egoistic chain flag for a given ledger.
131-
func (r *ProposalResponder) SetEgoisticChain(egoistic multi.LedgerBackendID, id int) {
132-
mf, ok := r.client.funder.(*multi.Funder)
133-
if !ok {
134-
log.Panic("unexpected type for funder")
135-
}
136-
mf.SetEgoisticChain(egoistic, id, true)
137-
}
138-
139-
// RemoveEgoisticChain removes the egoistic chain flag for a given ledger.
140-
func (r *ProposalResponder) RemoveEgoisticChain(egoistic multi.LedgerBackendID, id int) {
141-
mf, ok := r.client.funder.(*multi.Funder)
142-
if !ok {
143-
log.Panic("unexpected type for funder")
144-
}
145-
mf.SetEgoisticChain(egoistic, id, false)
146-
}
147-
148130
// Reject lets the user signal that they reject the channel proposal.
149131
// Returns whether the rejection message was successfully sent. Panics if the
150132
// proposal was already accepted or rejected.

wire/address.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func Key(a Address) AddrKey {
176176
return AddrKey(buff.String())
177177
}
178178

179-
// Keys returns the `AddrKey` corresponding to the passed `map[int]Address`.
179+
// Keys returns the `AddrKey` corresponding to the passed `map[wallet.BackendID]Address`.
180180
func Keys(addressMap map[wallet.BackendID]Address) AddrKey {
181181
var indexes []int //nolint:prealloc
182182
for i := range addressMap {

0 commit comments

Comments
 (0)