Skip to content
Open
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
11 changes: 10 additions & 1 deletion services/api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ type RelayAPI struct {
// Wait group used to monitor status of per-slot optimistic processing.
optimisticBlocksWG sync.WaitGroup
// Cache for builder statuses and collaterals.
blockBuildersCache map[string]*blockBuilderCacheEntry
blockBuildersCacheLock sync.RWMutex
blockBuildersCache map[string]*blockBuilderCacheEntry
}

// NewRelayAPI creates a new service. if builders is nil, allow any builder
Expand Down Expand Up @@ -672,7 +673,9 @@ func (api *RelayAPI) demoteBuilder(pubkey string, req *common.VersionedSubmitBlo
1,
)

api.blockBuildersCacheLock.RLock()
builderEntry, ok := api.blockBuildersCache[pubkey]
api.blockBuildersCacheLock.RUnlock()
if !ok {
api.log.Warnf("builder %v not in the builder cache", pubkey)
builderEntry = &blockBuilderCacheEntry{} //nolint:exhaustruct
Expand Down Expand Up @@ -947,7 +950,9 @@ func (api *RelayAPI) prepareBuildersForSlot(headSlot uint64) {
}
newCache[v.BuilderPubkey] = entry
}
api.blockBuildersCacheLock.Lock()
api.blockBuildersCache = newCache
api.blockBuildersCacheLock.Unlock()
}

func (api *RelayAPI) RespondError(w http.ResponseWriter, code int, message string) {
Expand Down Expand Up @@ -1306,11 +1311,13 @@ func (api *RelayAPI) handleGetHeader(w http.ResponseWriter, req *http.Request) {
if err != nil {
log.WithError(err).Info("could not get bid value")
api.RespondError(w, http.StatusBadRequest, err.Error())
return
}
blockHash, err := bid.BlockHash()
if err != nil {
log.WithError(err).Info("could not get bid block hash")
api.RespondError(w, http.StatusBadRequest, err.Error())
return
}

// Error on bid without value
Expand Down Expand Up @@ -2052,7 +2059,9 @@ func (api *RelayAPI) checkSubmissionSlotDetails(w http.ResponseWriter, log *logr
}

func (api *RelayAPI) checkBuilderEntry(w http.ResponseWriter, log *logrus.Entry, builderPubkey phase0.BLSPubKey) (*blockBuilderCacheEntry, bool) {
api.blockBuildersCacheLock.RLock()
builderEntry, ok := api.blockBuildersCache[builderPubkey.String()]
api.blockBuildersCacheLock.RUnlock()
if !ok {
log.Infof("unable to read builder: %s from the builder cache, using low-prio and no collateral", builderPubkey.String())
builderEntry = &blockBuilderCacheEntry{
Expand Down