Skip to content

Fix egoistic funding #414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 47 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
66fee75
feat(wallet, channel): Change backend to map of backends
sophia1ch Aug 21, 2024
28685ea
fix(multi): Add AssetIDKey struct to fix the map lookups for funders …
sophia1ch Aug 28, 2024
ef11de9
fix(all): Use map[int]ID instead of id for each backend.
sophia1ch Sep 4, 2024
ab8e60b
fix(all): Add map of IDs
sophia1ch Sep 4, 2024
13eeddf
fix(channel/backend): Revert change in verify.
sophia1ch Sep 5, 2024
8181cb0
fix(Adjudicator): Change to singular channel ID in events.
sophia1ch Sep 11, 2024
794298a
fix(client/test): Generalize role test.
sophia1ch Sep 11, 2024
969c6a7
feat(channel): Add backend field check.
sophia1ch Sep 20, 2024
10c9b28
fix(subchannel_dispute): Generalize event watcher.
sophia1ch Sep 25, 2024
3c1e261
feat: Asset Address function to handle encoding in backends.
sophia1ch Oct 1, 2024
a695d14
feat(apps/payment, backend/sim, channel/test, client/test, log, walle…
sophia1ch Oct 15, 2024
8589eb8
fix(asset.go, allocation.go): Adjust Address() to return byte[] inste…
sophia1ch Oct 29, 2024
39095c1
chore: Remove unnecessary logs
sophia1ch Nov 6, 2024
98e11ea
fix: Remove repeated assetIDs in LedgerID array
sophia1ch Nov 27, 2024
46de2d9
chore: update go.sum, gofmt some files
sophia1ch Dec 18, 2024
dac83b9
Merge branch 'main' into feat-mult-backends
sophia1ch Dec 18, 2024
5e5bfb3
fix(wallet/backend.go): Return just one error instead of concatenatio…
sophia1ch Dec 19, 2024
70036df
fix(golangci.yml): Exclude generated file from linter
sophia1ch Dec 19, 2024
19a792f
fix(ci): Use go1.18 for the any type in proto
sophia1ch Dec 19, 2024
fd8bf8a
fix(ci): Use glinter 1.45 which supports go1.18
sophia1ch Dec 19, 2024
98b900b
chore(all): Add nolint flags for conversions
sophia1ch Dec 19, 2024
2f24516
chore(all): remove unnecessary flags
sophia1ch Dec 19, 2024
8622a49
chore(all): remove unnecessary flags
sophia1ch Dec 19, 2024
caa8d4c
chore(all): remove unnecessary flags
sophia1ch Dec 19, 2024
b272564
chore(all): remove unnecessary flags
sophia1ch Dec 19, 2024
2c079f1
chore(all): remove unnecessary flags
sophia1ch Dec 19, 2024
ced8fb5
chore(all): remove unnecessary flags
sophia1ch Dec 19, 2024
056e726
chore(all): remove unnecessary flags
sophia1ch Dec 19, 2024
d73ca03
chore(all): Rename and add comments to exported functions
sophia1ch Dec 19, 2024
2d98975
chore: Rename variables
sophia1ch Dec 23, 2024
d463e82
fix(params, address): Fix index allocation
sophia1ch Dec 23, 2024
6823276
fix(funder, proposal): Make egoistic funding dependant on participant…
sophia1ch Jan 7, 2025
81fe219
Revert "fix(all): Add map of IDs"
sophia1ch Jan 7, 2025
3ead503
fix(backend.go): Remove unnecessary errors.join()
sophia1ch Jan 14, 2025
f46b0c5
fix: remove unnecessary else statement, add linter flag
sophia1ch Jan 14, 2025
7169c29
refactor(/apps/payment, /sim/wallet, /channel, /client, /wallet, /wir…
sophia1ch Jan 20, 2025
d899ea0
chore: Update proto binding, remove IDMap
sophia1ch Jan 20, 2025
c1fe0e2
refactor: Name TestBackendID, rename multiLedgerID to LedgerBackendID
sophia1ch Jan 20, 2025
a6d4a4a
refactor: Fix comment on exported function
sophia1ch Jan 20, 2025
091445a
fix(funder): Add egoistic check, otherwise one participant is always …
sophia1ch Jan 21, 2025
5219a0b
chore(all): Update license dates
sophia1ch Jan 28, 2025
07bf588
Merge branch 'refs/heads/feat-mult-backends' into remove-id-map
sophia1ch Jan 28, 2025
a404ea6
chore(backendtest): Rename to fix import issues
sophia1ch Jan 28, 2025
18c4a4a
Merge branch 'refs/heads/feat-mult-backends' into remove-id-map
sophia1ch Jan 28, 2025
21d0af4
fix(allocation_test): Remove channelID map from merge
sophia1ch Jan 28, 2025
8074925
Merge branch 'refs/heads/remove-id-map' into fix-egoistic-funding
sophia1ch Jan 28, 2025
66c5a88
Merge remote-tracking branch 'refs/remotes/upstream/main' into fix-eg…
sophia1ch Mar 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions channel/multi/funder.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,32 @@ type LedgerBackendKey struct {

// 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.
// egoistic controls whether the funder uses the egoisticIndex to control the funding order.
// egoisticIndex controls which participant index will fund last.
type Funder struct {
funders map[LedgerBackendKey]channel.Funder
egoisticChains map[LedgerBackendKey]bool
funders map[LedgerBackendKey]channel.Funder
egoistic bool
egoisticIndex int
}

// NewFunder creates a new funder.
func NewFunder() *Funder {
return &Funder{
funders: make(map[LedgerBackendKey]channel.Funder),
egoisticChains: make(map[LedgerBackendKey]bool),
funders: make(map[LedgerBackendKey]channel.Funder),
egoistic: false,
}
}

// RegisterFunder registers a funder for a given ledger.
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 LedgerBackendID, id int, egoistic bool) {
key := LedgerBackendKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())}
f.egoisticChains[key] = egoistic
// SetEgoisticPart sets the egoistic chain flag for a given ledger.
func (f *Funder) SetEgoisticPart(index int) {
f.egoisticIndex = index
f.egoistic = true
}

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

for _, l := range ledgerIDs {
key := LedgerBackendKey{BackendID: l.BackendID(), LedgerID: string(l.LedgerID().MapKey())}
if f.egoisticChains[key] {
for i, l := range ledgerIDs {
if f.egoistic && f.egoisticIndex == i {
egoisticLedgers = append(egoisticLedgers, l)
} else {
nonEgoisticLedgers = append(nonEgoisticLedgers, l)
Expand Down Expand Up @@ -128,6 +128,5 @@ func fundLedgers(ctx context.Context, request channel.FundingReq, assetIDs []Led
return err
}
}

return nil
}
18 changes: 0 additions & 18 deletions client/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,24 +127,6 @@ 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.LedgerBackendID, id int) {
mf, ok := r.client.funder.(*multi.Funder)
if !ok {
log.Panic("unexpected type for funder")
}
mf.SetEgoisticChain(egoistic, id, true)
}

// RemoveEgoisticChain removes the egoistic chain flag for a given ledger.
func (r *ProposalResponder) RemoveEgoisticChain(egoistic multi.LedgerBackendID, id int) {
mf, ok := r.client.funder.(*multi.Funder)
if !ok {
log.Panic("unexpected type for funder")
}
mf.SetEgoisticChain(egoistic, id, 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.
Expand Down
2 changes: 1 addition & 1 deletion wire/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func Key(a Address) AddrKey {
return AddrKey(buff.String())
}

// Keys returns the `AddrKey` corresponding to the passed `map[int]Address`.
// Keys returns the `AddrKey` corresponding to the passed `map[wallet.BackendID]Address`.
func Keys(addressMap map[wallet.BackendID]Address) AddrKey {
var indexes []int //nolint:prealloc
for i := range addressMap {
Expand Down