Skip to content

Commit

Permalink
blockRange feature to configure transaction max block (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
TymKh authored Oct 28, 2024
1 parent 18ee646 commit 06a42c8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
12 changes: 12 additions & 0 deletions server/request_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions server/url_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 3 additions & 2 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 06a42c8

Please sign in to comment.