Skip to content

Commit

Permalink
mempool configs support, reverting tx support (#154)
Browse files Browse the repository at this point in the history
* mempool configs support, reverting tx support

* change signature in test due to body change
  • Loading branch information
TymKh authored Sep 9, 2024
1 parent 401a5eb commit 4bacb69
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 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
2 changes: 1 addition & 1 deletion tests/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 4bacb69

Please sign in to comment.