Skip to content

Commit 6823276

Browse files
committed
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>
1 parent d463e82 commit 6823276

File tree

2 files changed

+12
-31
lines changed

2 files changed

+12
-31
lines changed

channel/multi/funder.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,31 @@ type AssetIDKey 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[AssetIDKey]channel.Funder
36-
egoisticChains map[AssetIDKey]bool
36+
funders map[AssetIDKey]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[AssetIDKey]channel.Funder),
43-
egoisticChains: make(map[AssetIDKey]bool),
44+
funders: make(map[AssetIDKey]channel.Funder),
4445
}
4546
}
4647

4748
// RegisterFunder registers a funder for a given ledger.
4849
func (f *Funder) RegisterFunder(l AssetID, lf channel.Funder) {
4950
key := AssetIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())}
5051
f.funders[key] = lf
51-
f.egoisticChains[key] = false
5252
}
5353

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

6060
// Fund funds a multi-ledger channel. It dispatches funding calls to all
@@ -74,9 +74,8 @@ func (f *Funder) Fund(ctx context.Context, request channel.FundingReq) error {
7474
var egoisticLedgers []AssetID
7575
var nonEgoisticLedgers []AssetID
7676

77-
for _, l := range assetIDs {
78-
key := AssetIDKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())}
79-
if f.egoisticChains[key] {
77+
for i, l := range assetIDs {
78+
if f.egoisticIndex == i {
8079
egoisticLedgers = append(egoisticLedgers, l)
8180
} else {
8281
nonEgoisticLedgers = append(nonEgoisticLedgers, l)

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.AssetID, 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.AssetID, 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.

0 commit comments

Comments
 (0)