@@ -1649,6 +1649,50 @@ func (api *RelayAPI) checkFloorBidValue(opts bidFloorOpts) (*big.Int, *logrus.En
16491649 return floorBidValue , opts .log , true
16501650}
16511651
1652+ type redisUpdateBidOpts struct {
1653+ w http.ResponseWriter
1654+ tx redis.Pipeliner
1655+ log * logrus.Entry
1656+ cancellationsEnabled bool
1657+ receivedAt time.Time
1658+ floorBidValue * big.Int
1659+ payload * common.BuilderSubmitBlockRequest
1660+ }
1661+
1662+ func (api * RelayAPI ) updateRedisBid (opts redisUpdateBidOpts ) (* datastore.SaveBidAndUpdateTopBidResponse , * common.GetPayloadResponse , bool ) {
1663+ // Prepare the response data
1664+ getHeaderResponse , err := common .BuildGetHeaderResponse (opts .payload , api .blsSk , api .publicKey , api .opts .EthNetDetails .DomainBuilder )
1665+ if err != nil {
1666+ opts .log .WithError (err ).Error ("could not sign builder bid" )
1667+ api .RespondError (opts .w , http .StatusBadRequest , err .Error ())
1668+ return nil , nil , false
1669+ }
1670+
1671+ getPayloadResponse , err := common .BuildGetPayloadResponse (opts .payload )
1672+ if err != nil {
1673+ opts .log .WithError (err ).Error ("could not build getPayload response" )
1674+ api .RespondError (opts .w , http .StatusBadRequest , err .Error ())
1675+ return nil , nil , false
1676+ }
1677+
1678+ bidTrace := common.BidTraceV2 {
1679+ BidTrace : * opts .payload .Message (),
1680+ BlockNumber : opts .payload .BlockNumber (),
1681+ NumTx : uint64 (opts .payload .NumTx ()),
1682+ }
1683+
1684+ //
1685+ // Save to Redis
1686+ //
1687+ updateBidResult , err := api .redis .SaveBidAndUpdateTopBid (context .Background (), opts .tx , & bidTrace , opts .payload , getPayloadResponse , getHeaderResponse , opts .receivedAt , opts .cancellationsEnabled , opts .floorBidValue )
1688+ if err != nil {
1689+ opts .log .WithError (err ).Error ("could not save bid and update top bids" )
1690+ api .RespondError (opts .w , http .StatusInternalServerError , "failed saving and updating bid" )
1691+ return nil , nil , false
1692+ }
1693+ return & updateBidResult , getPayloadResponse , true
1694+ }
1695+
16521696func (api * RelayAPI ) handleSubmitNewBlock (w http.ResponseWriter , req * http.Request ) {
16531697 var pf common.Profile
16541698 var prevTime , nextTime time.Time
@@ -1953,34 +1997,17 @@ func (api *RelayAPI) handleSubmitNewBlock(w http.ResponseWriter, req *http.Reque
19531997 }
19541998 }
19551999
1956- // Prepare the response data
1957- getHeaderResponse , err := common .BuildGetHeaderResponse (payload , api .blsSk , api .publicKey , api .opts .EthNetDetails .DomainBuilder )
1958- if err != nil {
1959- log .WithError (err ).Error ("could not sign builder bid" )
1960- api .RespondError (w , http .StatusBadRequest , err .Error ())
1961- return
1962- }
1963-
1964- getPayloadResponse , err := common .BuildGetPayloadResponse (payload )
1965- if err != nil {
1966- log .WithError (err ).Error ("could not build getPayload response" )
1967- api .RespondError (w , http .StatusBadRequest , err .Error ())
1968- return
1969- }
1970-
1971- bidTrace := common.BidTraceV2 {
1972- BidTrace : * payload .Message (),
1973- BlockNumber : payload .BlockNumber (),
1974- NumTx : uint64 (payload .NumTx ()),
2000+ redisOpts := redisUpdateBidOpts {
2001+ w : w ,
2002+ tx : tx ,
2003+ log : log ,
2004+ cancellationsEnabled : isCancellationEnabled ,
2005+ receivedAt : receivedAt ,
2006+ floorBidValue : floorBidValue ,
2007+ payload : payload ,
19752008 }
1976-
1977- //
1978- // Save to Redis
1979- //
1980- updateBidResult , err := api .redis .SaveBidAndUpdateTopBid (context .Background (), tx , & bidTrace , payload , getPayloadResponse , getHeaderResponse , receivedAt , isCancellationEnabled , floorBidValue )
1981- if err != nil {
1982- log .WithError (err ).Error ("could not save bid and update top bids" )
1983- api .RespondError (w , http .StatusInternalServerError , "failed saving and updating bid" )
2009+ updateBidResult , getPayloadResponse , ok := api .updateRedisBid (redisOpts )
2010+ if ! ok {
19842011 return
19852012 }
19862013
0 commit comments