From 97ce1ec5a3887cbaea71791da6aa93a290142d40 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Tue, 13 Feb 2024 12:12:24 +0100 Subject: [PATCH 1/2] feat(funder): Add egoisticChains to funder to prioritize funding of assets. feat(proposal): Add SetEgoisticChain and RemoveEgoisticChain to change egoistic funder map, when it is known which assets need to be funded first. Refactor: Put funding loop into seperate function. Add comments. Signed-off-by: Sophia Koehler --- MAINTAINERS.md | 18 +++++++------- channel/multi/funder.go | 52 ++++++++++++++++++++++++++++++++++------- client/proposal.go | 18 ++++++++++++++ 3 files changed, 71 insertions(+), 17 deletions(-) diff --git a/MAINTAINERS.md b/MAINTAINERS.md index 7607b496..764b1e94 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -1,16 +1,16 @@ # Maintainers ## Active Maintainers -| Name | Github | [Discord][_chat_url] | -|-------------------|-----------|----------------| -| Hendrik Amler | [@tinnendo](https://github.com/tinnendo) | hendrik#5345 | -| Jan Bormet | [@janbormet](https://github.com/janbormet) | _.pants | -| Philipp-Florens Lehwalder | [@cryptphil](https://github.com/cryptphil) | cryptphil | -| Steffen Rattay | [@rmbrt](https://github.com/rmbrt) | rmbrt | -| Ilja von Hoessle | [@iljabvh](https://github.com/iljabvh) | iljabvh | +| Name | Github | [Discord][_chat_url] | +|-------------------|----------------------------------------------------|----------------| +| Hendrik Amler | [@tinnendo](https://github.com/tinnendo) | hendrik#5345 | +| Jan Bormet | [@janbormet](https://github.com/janbormet) | _.pants | +| Philipp-Florens Lehwalder | [@cryptphil](https://github.com/cryptphil) | cryptphil | +| Steffen Rattay | [@rmbrt](https://github.com/rmbrt) | rmbrt | +| Ilja von Hoessle | [@iljabvh](https://github.com/iljabvh) | iljabvh | | Jens Winkle | [@DragonDev1906](https://github.com/DragonDev1906) | jens#4601 | -| Minh Huy Tran | [@NhoxxKienn](https://github.com/NhoxxKienn) | NhoxxKienn | -| Sophia Koehler | [@sophia1ch](https://githun.com/sophia1ch) | sophia#3072 | +| Minh Huy Tran | [@NhoxxKienn](https://github.com/NhoxxKienn) | NhoxxKienn | +| Sophia Koehler | [@sophia1ch](https://github.com/sophia1ch) | sophia#3072 | ## Emeritus Maintainers diff --git a/channel/multi/funder.go b/channel/multi/funder.go index 48bdf03d..95c90459 100644 --- a/channel/multi/funder.go +++ b/channel/multi/funder.go @@ -23,20 +23,30 @@ import ( ) // 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[LedgerIDMapKey]channel.Funder + funders map[LedgerIDMapKey]channel.Funder + egoisticChains map[LedgerIDMapKey]bool } // NewFunder creates a new funder. func NewFunder() *Funder { return &Funder{ - funders: make(map[LedgerIDMapKey]channel.Funder), + funders: make(map[LedgerIDMapKey]channel.Funder), + egoisticChains: make(map[LedgerIDMapKey]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 +} + +// SetEgoisticChain sets the egoistic chain flag for a given ledger. +func (f *Funder) SetEgoisticChain(l LedgerID, egoistic bool) { + f.egoisticChains[l.MapKey()] = egoistic } // Fund funds a multi-ledger channel. It dispatches funding calls to all @@ -53,13 +63,40 @@ func (f *Funder) Fund(ctx context.Context, request channel.FundingReq) error { return err } + var egoisticLedgers []LedgerID + var nonEgoisticLedgers []LedgerID + + for _, l := range ledgers { + if f.egoisticChains[l.MapKey()] { + egoisticLedgers = append(egoisticLedgers, l) + } else { + nonEgoisticLedgers = append(nonEgoisticLedgers, l) + } + } + + // First fund with Funders that are not egoistic. + err = fundLedgers(ctx, request, nonEgoisticLedgers, f.funders) + if err != nil { + return err + } + + // Then fund with egoistic Funders. + err = fundLedgers(ctx, request, egoisticLedgers, f.funders) + if err != nil { + return err + } + + return nil +} + +func fundLedgers(ctx context.Context, request channel.FundingReq, ledgers []LedgerID, funders map[LedgerIDMapKey]channel.Funder) error { n := len(ledgers) errs := make(chan error, n) - for _, l := range ledgers { - go func(l LedgerID) { + for _, le := range ledgers { + go func(le LedgerID) { errs <- func() error { - id := l.MapKey() - lf, ok := f.funders[id] + id := le.MapKey() + lf, ok := funders[id] if !ok { return fmt.Errorf("Funder not found for ledger %v", id) } @@ -67,7 +104,7 @@ func (f *Funder) Fund(ctx context.Context, request channel.FundingReq) error { err := lf.Fund(ctx, request) return err }() - }(l) + }(le) } for i := 0; i < n; i++ { @@ -76,6 +113,5 @@ func (f *Funder) Fund(ctx context.Context, request channel.FundingReq) error { return err } } - return nil } diff --git a/client/proposal.go b/client/proposal.go index faef295a..d2762311 100644 --- a/client/proposal.go +++ b/client/proposal.go @@ -127,6 +127,24 @@ func (r *ProposalResponder) Accept(ctx context.Context, acc ChannelProposalAccep return r.client.handleChannelProposalAcc(ctx, r.peer, r.req, acc) } +// SetEgoisticChain sets the egoistic chain flag for a given ledger. +func (r *ProposalResponder) SetEgoisticChain(egoistic multi.LedgerID) { + mf, ok := r.client.funder.(*multi.Funder) + if !ok { + log.Panic("unexpected type for funder") + } + mf.SetEgoisticChain(egoistic, true) +} + +// RemoveEgoisticChain removes the egoistic chain flag for a given ledger. +func (r *ProposalResponder) RemoveEgoisticChain(egoistic multi.LedgerID) { + mf, ok := r.client.funder.(*multi.Funder) + if !ok { + log.Panic("unexpected type for funder") + } + mf.SetEgoisticChain(egoistic, false) +} + // Reject lets the user signal that they reject the channel proposal. // Returns whether the rejection message was successfully sent. Panics if the // proposal was already accepted or rejected. From 49cd2cfe1ca4538b134ec45e730a8489b2be9e79 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Thu, 7 Mar 2024 09:48:29 +0100 Subject: [PATCH 2/2] refactor: sort Maintainers alphabetically. Signed-off-by: Sophia Koehler --- MAINTAINERS.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MAINTAINERS.md b/MAINTAINERS.md index 764b1e94..39ec234d 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -5,12 +5,12 @@ |-------------------|----------------------------------------------------|----------------| | Hendrik Amler | [@tinnendo](https://github.com/tinnendo) | hendrik#5345 | | Jan Bormet | [@janbormet](https://github.com/janbormet) | _.pants | +| Ilja von Hoessle | [@iljabvh](https://github.com/iljabvh) | iljabvh | +| Sophia Koehler | [@sophia1ch](https://github.com/sophia1ch) | sophia#3072 | | Philipp-Florens Lehwalder | [@cryptphil](https://github.com/cryptphil) | cryptphil | | Steffen Rattay | [@rmbrt](https://github.com/rmbrt) | rmbrt | -| Ilja von Hoessle | [@iljabvh](https://github.com/iljabvh) | iljabvh | -| Jens Winkle | [@DragonDev1906](https://github.com/DragonDev1906) | jens#4601 | | Minh Huy Tran | [@NhoxxKienn](https://github.com/NhoxxKienn) | NhoxxKienn | -| Sophia Koehler | [@sophia1ch](https://github.com/sophia1ch) | sophia#3072 | +| Jens Winkle | [@DragonDev1906](https://github.com/DragonDev1906) | jens#4601 | ## Emeritus Maintainers