Skip to content

Commit

Permalink
chore: remove unecessary sorting of covenant signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
RafilxTenfen committed Oct 14, 2024
1 parent 97466b0 commit 9617ca4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 17 deletions.
16 changes: 1 addition & 15 deletions covenant/covenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package covenant
import (
"encoding/hex"
"fmt"
"sort"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -229,7 +227,7 @@ func (ce *CovenantEmulator) AddCovenantSignatures(btcDels []*types.Delegation) (
}

// 10. submit covenant sigs
res, err := ce.cc.SubmitCovenantSigs(SortCovenantSigs(covenantSigs))
res, err := ce.cc.SubmitCovenantSigs(covenantSigs)
if err != nil {
ce.recordMetricsFailedSignDelegations(len(covenantSigs))
return nil, err
Expand Down Expand Up @@ -592,15 +590,3 @@ func (ce *CovenantEmulator) Stop() error {
})
return stopErr
}

// SortCovenantSigs helper function to sort all covenant signatures by the staking tx hash
// Usefull for test checking expected inputs
func SortCovenantSigs(covSigs []*types.CovenantSigs) []*types.CovenantSigs {
sorted := make([]*types.CovenantSigs, len(covSigs))
copy(sorted, covSigs)
sort.SliceStable(sorted, func(i, j int) bool {
return strings.Compare(sorted[i].StakingTxHash.String(), sorted[j].StakingTxHash.String()) == 1
})

return sorted
}
3 changes: 1 addition & 2 deletions covenant/covenant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,9 @@ func FuzzAddCovenantSig(f *testing.F) {
}
btcDels = append(btcDels, invalidDelegation)

sortedCovSigs := covenant.SortCovenantSigs(covSigsSet)
// check the sigs are expected
expectedTxHash := testutil.GenRandomHexStr(r, 32)
mockClientController.EXPECT().SubmitCovenantSigs(sortedCovSigs).
mockClientController.EXPECT().SubmitCovenantSigs(covSigsSet).
Return(&types.TxResponse{TxHash: expectedTxHash}, nil).AnyTimes()
res, err := ce.AddCovenantSignatures(btcDels)
require.NoError(t, err)
Expand Down

0 comments on commit 9617ca4

Please sign in to comment.