Skip to content
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

mixclient: Sort roots for slot assignment #3453

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Changes from all commits
Commits
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
13 changes: 11 additions & 2 deletions mixing/mixclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
// MinPeers is the minimum number of peers required for a mix run to proceed.
const MinPeers = 4

const pairingFlags byte = 0
const pairingVersion byte = 1

const (
timeoutDuration = 30 * time.Second
Expand Down Expand Up @@ -725,7 +725,7 @@ func (c *Client) Dicemix(ctx context.Context, cj *CoinJoin) error {
pr, err := wire.NewMsgMixPairReq(*p.id, cj.prExpiry, cj.mixValue,
string(mixing.ScriptClassP2PKHv0), cj.tx.Version,
cj.tx.LockTime, cj.mcount, cj.inputValue, cj.prUTXOs,
cj.change, prFlags, pairingFlags)
cj.change, prFlags, pairingVersion)
if err != nil {
return err
}
Expand Down Expand Up @@ -1731,6 +1731,9 @@ func (c *Client) roots(ctx context.Context, seenSRs []chainhash.Hash,
close(publishedRoots)
return nil, errTriggeredBlame
}
sort.Slice(roots, func(i, j int) bool {
return roots[i].Cmp(roots[j]) == -1
})
rootBytes := make([][]byte, len(roots))
for i, root := range roots {
rootBytes[i] = root.Bytes()
Expand Down Expand Up @@ -1802,6 +1805,12 @@ func (c *Client) roots(ctx context.Context, seenSRs []chainhash.Hash,
roots = append(roots, root)
}
}
sorted := sort.SliceIsSorted(roots, func(i, j int) bool {
return roots[i].Cmp(roots[j]) == -1
})
if !sorted {
continue
}
if len(roots) == len(a)-1 {
return roots, nil
}
Expand Down