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

chore(builder): decoded constraint cache #74

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
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
18 changes: 5 additions & 13 deletions builder/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ func (b *Builder) subscribeToRelayForConstraints(relayBaseEndpoint, authHeader s
}

for _, constraint := range constraintsSigned {
decodedConstraints, err := DecodeConstraint(constraint)
decodedConstraints, err := DecodeConstraints(constraint)
if err != nil {
log.Error("Failed to decode transaction RLP: ", err)
log.Error("Failed to decode constraint: ", err)
continue
}

Expand All @@ -378,20 +378,12 @@ func (b *Builder) subscribeToRelayForConstraints(relayBaseEndpoint, authHeader s
continue
}

// Temporary map to keep track of the constraints that are already in the slot
seenTx := make(map[common.Hash]bool)
for hash := range slotConstraints {
seenTx[hash] = true
}

for hash := range decodedConstraints {
if !seenTx[hash] {
// The constraint is new, we will add this to the slot constraints
slotConstraints[hash] = decodedConstraints[hash]
}
// Update the slot constraints
slotConstraints[hash] = decodedConstraints[hash]
}

// Update the slot constraints
// Update the slot constraints in the cache
b.constraintsCache.Put(constraint.Message.Slot, slotConstraints)
}
}
Expand Down
2 changes: 1 addition & 1 deletion builder/builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ func TestSubscribeProposerConstraints(t *testing.T) {
require.Equal(t, true, ok)

expectedConstraint := generateMockConstraintsForSlot(slot)[0]
decodedConstraint, err := DecodeConstraint(expectedConstraint)
decodedConstraint, err := DecodeConstraints(expectedConstraint)
require.NoError(t, err)

// Compare the keys of the cachedConstraints and decodedConstraint maps
Expand Down
4 changes: 2 additions & 2 deletions builder/builder/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (

var errHTTPErrorResponse = errors.New("HTTP error response")

func DecodeConstraint(constraint *common.SignedConstraints) (types.HashToConstraintDecoded, error) {
func DecodeConstraints(constraints *common.SignedConstraints) (types.HashToConstraintDecoded, error) {
decodedConstraints := make(types.HashToConstraintDecoded)
for _, tx := range constraint.Message.Constraints {
for _, tx := range constraints.Message.Constraints {
decoded := new(types.Transaction)
if err := decoded.UnmarshalBinary(tx.Tx); err != nil {
return nil, err
Expand Down