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

fix(builder): introduce updateConstraintsCacheLock #8

Merged
merged 1 commit into from
Nov 12, 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
8 changes: 8 additions & 0 deletions builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ type Builder struct {

// constraintsCache is a map from slot to the decoded constraints made by proposers
constraintsCache *shardmap.FIFOMap[uint64, types.HashToConstraintDecoded]
// NOTE: `shardmap` already provides locks, however for handling multiple
// relay subscriptions for constraints we need a lock to protect the cache
// between the `Get` and `Put` operation
updateConstraintsCacheLock sync.Mutex

limiter *rate.Limiter
submissionOffsetFromEndOfSlot time.Duration
Expand Down Expand Up @@ -393,6 +397,9 @@ func (b *Builder) subscribeToRelayForConstraints(relayBaseEndpoint string) error
continue
}

// Take the lock to update the constraints cache: both `Get` and `Put` must be done by the same entity
b.updateConstraintsCacheLock.Lock()
// For every constraint, we need to check if it has already been seen for the associated slot
slotConstraints, _ := b.constraintsCache.Get(constraint.Message.Slot)
if len(slotConstraints) == 0 {
b.constraintsCache.Put(constraint.Message.Slot, decodedConstraints)
Expand All @@ -406,6 +413,7 @@ func (b *Builder) subscribeToRelayForConstraints(relayBaseEndpoint string) error
}

b.constraintsCache.Put(constraint.Message.Slot, slotConstraints)
b.updateConstraintsCacheLock.Unlock()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion builder/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func Register(stack *node.Node, backend *eth.Ethereum, cfg *Config) error {
return errors.New("neither local nor remote relay specified")
}

if len(cfg.SecondaryRemoteRelayEndpoints) > 0 && !(len(cfg.SecondaryRemoteRelayEndpoints) == 1 && cfg.SecondaryRemoteRelayEndpoints[0] == "") {
if len(cfg.SecondaryRemoteRelayEndpoints) > 0 && (len(cfg.SecondaryRemoteRelayEndpoints) != 1 || cfg.SecondaryRemoteRelayEndpoints[0] != "") {
secondaryRelays := make([]IRelay, len(cfg.SecondaryRemoteRelayEndpoints))
for i, endpoint := range cfg.SecondaryRemoteRelayEndpoints {
relayConfig, err := getRelayConfig(endpoint)
Expand Down
Loading