Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blockRange feature to configure transaction max block #160

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
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
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
Loading