Skip to content

Commit

Permalink
mempool configs support, reverting tx support
Browse files Browse the repository at this point in the history
  • Loading branch information
TymKh committed Sep 2, 2024
1 parent 401a5eb commit d681bf0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
5 changes: 3 additions & 2 deletions server/request_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,12 @@ func (r *RpcRequest) sendTxToRelay() {
if err != nil {
if errors.Is(err, flashbotsrpc.ErrRelayErrorResponse) {
r.logger.Info("[sendTxToRelay] Relay error response", "error", err, "rawTx", r.rawTxHex)
r.writeRpcError(err.Error(), types.JsonRpcInternalError)
} else {
r.logger.Error("[sendTxToRelay] Relay call failed", "error", err, "rawTx", r.rawTxHex)
r.writeRpcError(err.Error(), types.JsonRpcInternalError)
}
// todo: we need to change the way we call bundle-relay-api as it's not json-rpc compatible so we don't get proper
// error code/text
r.writeRpcError("internal error", types.JsonRpcInternalError)
return
}

Expand Down
30 changes: 26 additions & 4 deletions server/url_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
var (
DefaultAuctionHint = []string{"hash", "special_logs"}

ErrIncorrectMempoolURL = errors.New("Incorrect mempool URL.")
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 Down Expand Up @@ -49,12 +50,12 @@ func normalizeQueryParams(url *url.URL) map[string][]string {
// - builder: target builder, can be set multiple times, default: empty (only send to flashbots builders)
// - refund: refund in the form of 0xaddress:percentage, default: empty (will be set by default when backrun is produced)
// example: 0x123:80 - will refund 80% of the backrun profit to 0x123
func ExtractParametersFromUrl(url *url.URL, allBuilders []string) (params URLParameters, err error) {
if strings.HasPrefix(url.Path, "/fast") {
func ExtractParametersFromUrl(reqUrl *url.URL, allBuilders []string) (params URLParameters, err error) {
if strings.HasPrefix(reqUrl.Path, "/fast") {
params.fast = true
}
// Normalize all query parameters to lowercase keys
normalizedQuery := normalizeQueryParams(url)
normalizedQuery := normalizeQueryParams(reqUrl)

var hint []string
hintQuery, ok := normalizedQuery["hint"]
Expand Down Expand Up @@ -92,7 +93,7 @@ func ExtractParametersFromUrl(url *url.URL, allBuilders []string) (params URLPar
}
if params.fast {
params.pref.Fast = true
// set all builders no matter what's in the url
// set all builders no matter what's in the reqUrl
params.pref.Privacy.Builders = allBuilders
}

Expand Down Expand Up @@ -147,6 +148,27 @@ func ExtractParametersFromUrl(url *url.URL, allBuilders []string) (params URLPar
params.pref.Validity.Refund = refundConfig
}

useMempoolQuery := normalizedQuery["usemempool"]
if len(useMempoolQuery) != 0 && useMempoolQuery[0] == "true" {
params.pref.Privacy.UseMempool = true
}
allowRevertQuery := normalizedQuery["allowrevert"]
if len(allowRevertQuery) != 0 && allowRevertQuery[0] == "true" {
params.pref.AllowRevert = true
}
customMempoolQuery := normalizedQuery["custommempool"]
if len(customMempoolQuery) != 0 {
cm, err := url.QueryUnescape(customMempoolQuery[0])
if err != nil {
return params, ErrIncorrectMempoolURL
}
_, err = url.Parse(customMempoolQuery[0])
if err != nil {
return params, ErrIncorrectMempoolURL
}
params.pref.Privacy.CustomMempool = cm
}

return params, nil
}

Expand Down
13 changes: 8 additions & 5 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ type SendPrivateTxRequestWithPreferences struct {
}

type TxPrivacyPreferences struct {
Hints []string `json:"hints"`
Builders []string `json:"builders"`
Hints []string `json:"hints"`
Builders []string `json:"builders"`
UseMempool bool `json:"useMempool"`
CustomMempool string `json:"customMempool"`
}

type TxValidityPreferences struct {
Expand All @@ -126,7 +128,8 @@ type RefundConfig struct {
}

type PrivateTxPreferences struct {
Privacy TxPrivacyPreferences `json:"privacy"`
Validity TxValidityPreferences `json:"validity"`
Fast bool `json:"fast"`
Privacy TxPrivacyPreferences `json:"privacy"`
Validity TxValidityPreferences `json:"validity"`
Fast bool `json:"fast"`
AllowRevert bool `json:"allowRevert"`
}

0 comments on commit d681bf0

Please sign in to comment.