From 4bacb69376633d09204aa97fd80091d4f1a633d6 Mon Sep 17 00:00:00 2001 From: TymKh Date: Mon, 9 Sep 2024 14:21:58 +0200 Subject: [PATCH] mempool configs support, reverting tx support (#154) * mempool configs support, reverting tx support * change signature in test due to body change --- server/request_processor.go | 5 +++-- server/url_params.go | 30 ++++++++++++++++++++++++++---- tests/e2e_test.go | 2 +- types/types.go | 13 ++++++++----- 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/server/request_processor.go b/server/request_processor.go index ced8d2c..97fdfb2 100644 --- a/server/request_processor.go +++ b/server/request_processor.go @@ -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 } diff --git a/server/url_params.go b/server/url_params.go index 0c4e6fb..59bb9bb 100644 --- a/server/url_params.go +++ b/server/url_params.go @@ -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.") @@ -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"] @@ -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 } @@ -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 } diff --git a/tests/e2e_test.go b/tests/e2e_test.go index 16784cb..feb2f1d 100644 --- a/tests/e2e_test.go +++ b/tests/e2e_test.go @@ -278,7 +278,7 @@ func TestRelayTx(t *testing.T) { // Ensure that request was signed properly pubkey := crypto.PubkeyToAddress(relaySigningKey.PublicKey).Hex() - require.Equal(t, pubkey+":0x04084726a086ebd58bc8eb4d4d1387aade5372e1b421ea0636ee4fcc7410b0cb650fbfdc06a7aeb1c34d0982c9bee903ac2622c51134f160dac32ad1e61331d301", testutils.MockBackendLastRawRequest.Header.Get("X-Flashbots-Signature")) + require.Equal(t, pubkey+":0x446933e9be3df94013f61764c18dfa4e521b2d822c0cc7b42063b9bbc8960f697c0dd1d9835cb22b83b0765106d7fdbb9d2257d0dfcbf3feefb0e972f872266100", testutils.MockBackendLastRawRequest.Header.Get("X-Flashbots-Signature")) // Check result - should be the tx hash var res string diff --git a/types/types.go b/types/types.go index d5503fa..e9477fa 100644 --- a/types/types.go +++ b/types/types.go @@ -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 { @@ -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"` }