diff --git a/server/request_processor.go b/server/request_processor.go index 3b7ad6e..7eeef65 100644 --- a/server/request_processor.go +++ b/server/request_processor.go @@ -312,6 +312,18 @@ func (r *RpcRequest) sendTxToRelay() { } } + if r.urlParams.blockRange > 0 { + bn, err := r.defaultEthClient.BlockNumber(context.Background()) + if err != nil { + r.logger.Error("[sendTxToRelay] BlockNumber failed", "error", err) + r.writeRpcError(err.Error(), types.JsonRpcInternalError) + return + } + // this actually means that we use blockRange+1, to avoid problems with lagging blocks etc. + maxBlockNumber := bn + 1 + uint64(r.urlParams.blockRange) + sendPrivateTxArgs.MaxBlockNumber = maxBlockNumber + } + fbRpc := flashbotsrpc.New(r.relayUrl, func(rpc *flashbotsrpc.FlashbotsRPC) { if r.urlParams.originId != "" { rpc.Headers["X-Flashbots-Origin"] = r.urlParams.originId diff --git a/server/url_params.go b/server/url_params.go index 33822cf..521b103 100644 --- a/server/url_params.go +++ b/server/url_params.go @@ -15,6 +15,7 @@ var ( DefaultAuctionHint = []string{"hash", "special_logs"} ErrIncorrectMempoolURL = errors.New("Incorrect mempool URL.") + ErrIncorrectURLParam = errors.New("Incorrect URL parameter") ErrEmptyHintQuery = errors.New("Hint query must be non-empty if set.") ErrEmptyTargetBuilderQuery = errors.New("Target builder query must be non-empty if set.") ErrIncorrectAuctionHints = errors.New("Incorrect auction hint, must be one of: contract_address, function_selector, logs, calldata, default_logs.") @@ -30,6 +31,7 @@ type URLParameters struct { prefWasSet bool originId string fast bool + blockRange int } // normalizeQueryParams takes a URL and returns a map of query parameters with all keys normalized to lowercase. @@ -169,6 +171,14 @@ func ExtractParametersFromUrl(reqUrl *url.URL, allBuilders []string) (params URL parsedUrl.Scheme = "https" params.pref.Privacy.MempoolRPC = parsedUrl.String() } + blockRange := normalizedQuery["blockrange"] + if len(blockRange) != 0 { + brange, err := strconv.Atoi(blockRange[0]) + if err != nil { + return params, ErrIncorrectURLParam + } + params.blockRange = brange + } return params, nil } diff --git a/types/types.go b/types/types.go index 3c9f6a3..b63aa72 100644 --- a/types/types.go +++ b/types/types.go @@ -107,8 +107,9 @@ type BundleResponse struct { } type SendPrivateTxRequestWithPreferences struct { - Tx string `json:"tx"` - Preferences *PrivateTxPreferences `json:"preferences,omitempty"` + Tx string `json:"tx"` + Preferences *PrivateTxPreferences `json:"preferences,omitempty"` + MaxBlockNumber uint64 `json:"maxBlockNumber"` } type TxPrivacyPreferences struct {