-
Notifications
You must be signed in to change notification settings - Fork 23
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): store decoded constraints in the cache #68
Conversation
decodedConstraints, err := DecodeConstraint(constraint) | ||
if err != nil { | ||
log.Error("Failed to decode transaction RLP: ", err) | ||
continue | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decode the constraints from the function in utils
// Update the slot constraints | ||
b.constraintsCache.Put(constraint.Message.Slot, slotConstraints) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We put the updated slot constraints in the cache. If there are no changes to it, we put the same back
for hash := range decodedConstraints { | ||
if !seenTx[hash] { | ||
// The constraint is new, we will add this to the slot constraints | ||
slotConstraints[hash] = decodedConstraints[hash] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we iterate over the decoded constraints and see if any of the constraints present in it is different and if so we add it to the slotConstraints
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! just one nit
builder/builder/builder.go
Outdated
b.constraintsCache.Put(constraint.Message.Slot, append(slotConstraints, constraint)) | ||
|
||
// Update the slot constraints | ||
b.constraintsCache.Put(constraint.Message.Slot, slotConstraints) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (b *Builder) GetConstraintsForSlot(slot uint64) types.HashToConstraintDecoded { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can just remove this function now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, removed it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nits! Thanks for the PR
for _, constraint := range constraintsSigned { | ||
decodedConstraints, err := DecodeConstraint(constraint) | ||
if err != nil { | ||
log.Error("Failed to decode transaction RLP: ", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.Error("Failed to decode transaction RLP: ", err) | |
log.Error("Failed to decode constraint: ", err) |
// 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 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need this additional hashmap, you can just check if slotConstraint[hash] == nil
, or writing every without doing this check
@@ -712,7 +710,7 @@ func (b *Builder) runBuildingJob(slotCtx context.Context, proposerPubkey phase0. | |||
log.Debug("runBuildingJob", "slot", attrs.Slot, "parent", attrs.HeadHash, "payloadTimestamp", uint64(attrs.Timestamp)) | |||
|
|||
// fetch constraints here | |||
constraints := b.GetConstraintsForSlot(attrs.Slot) | |||
constraints, _ := b.constraintsCache.Get(attrs.Slot) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should handle the other value returned?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get returns the value and true if the value is present, otherwise it returns the default value and false.
zero value for the map's value type is returned if key is not present.
I don't think it will make a difference?
) | ||
|
||
var errHTTPErrorResponse = errors.New("HTTP error response") | ||
|
||
func DecodeConstraint(constraint *common.SignedConstraints) (types.HashToConstraintDecoded, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func DecodeConstraint(constraint *common.SignedConstraints) (types.HashToConstraintDecoded, error) { | |
func DecodeConstraints(constraints *common.SignedConstraints) (types.HashToConstraintDecoded, error) { |
This PR changes the way constraints are stored in the cache.
Before, constraints were stored in a signed form, which needed to be decoded during the building. Now it is stored in the decoded form in the first place.
fixes #51
*shardmap.FIFOMap[uint64, types.HashToConstraintDecoded]
DecodeConstraint
Implementation details in the review below