@@ -759,15 +759,19 @@ func (api *RelayAPI) processNewSlot(headSlot uint64) {
759759 // store the head slot
760760 api .headSlot .Store (headSlot )
761761
762- // only for builder-api
762+ // for both apis
763763 if api .opts .BlockBuilderAPI || api .opts .ProposerAPI {
764764 // update proposer duties in the background
765765 go api .updateProposerDuties (headSlot )
766+ }
766767
768+ // for block builder api
769+ if api .opts .BlockBuilderAPI {
767770 // update the optimistic slot
768- go api .prepareBuildersForSlot (headSlot )
771+ go api .prepareBuildersForSlot (headSlot , prevHeadSlot )
769772 }
770773
774+ // for proposer api
771775 if api .opts .ProposerAPI {
772776 go api .datastore .RefreshKnownValidators (api .log , api .beaconClient , headSlot )
773777 }
@@ -830,13 +834,13 @@ func (api *RelayAPI) updateProposerDuties(headSlot uint64) {
830834 api .log .Infof ("proposer duties updated: %s" , strings .Join (_duties , ", " ))
831835}
832836
833- func (api * RelayAPI ) prepareBuildersForSlot (headSlot uint64 ) {
837+ func (api * RelayAPI ) prepareBuildersForSlot (headSlot uint64 , prevHeadSlot uint64 ) {
834838 // First wait for this process to finish processing optimistic blocks
835839 api .optimisticBlocksWG .Wait ()
836840
837841 // Now we release our lock and wait for all other builder processes to wrap up
838842 api .redis .EndProcessingSlot (context .Background ())
839- api .redis .WaitForSlotComplete (context .Background (), headSlot )
843+ api .redis .WaitForSlotComplete (context .Background (), prevHeadSlot + 1 )
840844
841845 // Prevent race with StopServer, make sure we don't lock up redis if the server is shutting down
842846 if api .srvShutdown .Load () {
@@ -1399,8 +1403,8 @@ func (api *RelayAPI) handleGetPayload(w http.ResponseWriter, req *http.Request)
13991403 log .WithError (err ).Error ("failed to increment builder-stats after getPayload" )
14001404 }
14011405
1402- // Wait until optimistic blocks are complete.
1403- api .optimisticBlocksWG . Wait ( )
1406+ // Wait until optimistic blocks are complete using the redis waitgroup
1407+ api .redis . WaitForSlotComplete ( context . Background (), uint64 ( slot ) )
14041408
14051409 // Check if there is a demotion for the winning block.
14061410 _ , err = api .db .GetBuilderDemotion (bidTrace )
0 commit comments