@@ -30,31 +30,32 @@ type LedgerBackendKey struct {
30
30
31
31
// Funder is a multi-ledger funder.
32
32
// 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.
34
35
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
37
39
}
38
40
39
41
// NewFunder creates a new funder.
40
42
func NewFunder () * Funder {
41
43
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 ,
44
46
}
45
47
}
46
48
47
49
// RegisterFunder registers a funder for a given ledger.
48
50
func (f * Funder ) RegisterFunder (l LedgerBackendID , lf channel.Funder ) {
49
51
key := LedgerBackendKey {BackendID : l .BackendID (), LedgerID : string (l .LedgerID ().MapKey ())}
50
52
f .funders [key ] = lf
51
- f .egoisticChains [key ] = false
52
53
}
53
54
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
58
59
}
59
60
60
61
// 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 {
74
75
var egoisticLedgers []LedgerBackendID
75
76
var nonEgoisticLedgers []LedgerBackendID
76
77
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 {
80
80
egoisticLedgers = append (egoisticLedgers , l )
81
81
} else {
82
82
nonEgoisticLedgers = append (nonEgoisticLedgers , l )
@@ -128,6 +128,5 @@ func fundLedgers(ctx context.Context, request channel.FundingReq, assetIDs []Led
128
128
return err
129
129
}
130
130
}
131
-
132
131
return nil
133
132
}
0 commit comments