Skip to content

Commit

Permalink
chore(relay): remove unused utility
Browse files Browse the repository at this point in the history
  • Loading branch information
thedevbirb committed Jul 26, 2024
1 parent 4e0442e commit 32f9543
Showing 1 changed file with 0 additions and 42 deletions.
42 changes: 0 additions & 42 deletions mev-boost-relay/services/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"encoding/json"
"errors"
"fmt"
"slices"
"sort"

"github.com/attestantio/go-eth2-client/spec/phase0"
gethCommon "github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -51,43 +49,3 @@ type (
Tx *types.Transaction
}
)

// ParseConstraintsDecoded receives a map of constraints and
// - creates a slice of constraints sorted by index
// - creates a slice of constraints without index sorted by nonce and hash
// Returns the concatenation of the slices
func ParseConstraintsDecoded(constraints HashToConstraintDecoded) []*ConstraintDecoded {
// Here we initialize and track the constraints left to be executed along
// with their gas requirements
constraintsOrderedByIndex := make([]*ConstraintDecoded, 0, len(constraints))
constraintsWithoutIndex := make([]*ConstraintDecoded, 0, len(constraints))

for _, constraint := range constraints {
if constraint.Index == nil {
constraintsWithoutIndex = append(constraintsWithoutIndex, constraint)
} else {
constraintsOrderedByIndex = append(constraintsOrderedByIndex, constraint)
}
}

// Sorts the constraints by index ascending
sort.Slice(constraintsOrderedByIndex, func(i, j int) bool {
// By assumption, all constraints here have a non-nil index
return *constraintsOrderedByIndex[i].Index < *constraintsOrderedByIndex[j].Index
})

// Sorts the unindexed constraints by nonce ascending and by hash
sort.Slice(constraintsWithoutIndex, func(i, j int) bool {
iNonce := constraintsWithoutIndex[i].Tx.Nonce()
jNonce := constraintsWithoutIndex[j].Tx.Nonce()
// Sort by hash
if iNonce == jNonce {
return constraintsWithoutIndex[i].Tx.Hash().Cmp(constraintsWithoutIndex[j].Tx.Hash()) < 0
}
return iNonce < jNonce
})

constraintsConcat := slices.Concat(constraintsOrderedByIndex, constraintsWithoutIndex)

return constraintsConcat
}

0 comments on commit 32f9543

Please sign in to comment.