Skip to content
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: 6 additions & 6 deletions server/configuration_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ func parseURLToParameters(rawURL string) (URLParameters, error) {
if err != nil {
return URLParameters{}, fmt.Errorf("failed to parse URL: %w", err)
}

params, err := ExtractParametersFromUrl(parsedURL, nil)
if err != nil {
return URLParameters{}, fmt.Errorf("failed to extract parameters: %w", err)
}

return params, nil
}

Expand All @@ -55,7 +55,7 @@ func NewConfigurationWatcher(customersConfig CustomersConfig) (*ConfigurationWat
}
parsedCustomersConfig[customerID] = allowedConfigs
}

// Parse presets for header-based override
parsedPresets := make(map[string]URLParameters)
for originID, presetURL := range customersConfig.Presets {
Expand All @@ -68,18 +68,18 @@ func NewConfigurationWatcher(customersConfig CustomersConfig) (*ConfigurationWat
parsedPresets[originID] = params
log.Info("Loaded preset configuration", "originID", originID)
}

return &ConfigurationWatcher{
ParsedCustomersConfig: parsedCustomersConfig,
ParsedPresets: parsedPresets,
ParsedPresets: parsedPresets,
}, nil
}

func ReadCustomerConfigFromFile(fileName string) (*ConfigurationWatcher, error) {
if fileName == "" {
return &ConfigurationWatcher{
ParsedCustomersConfig: make(map[string][]URLParameters),
ParsedPresets: make(map[string]URLParameters),
ParsedPresets: make(map[string]URLParameters),
}, nil
}
data, err := os.ReadFile(fileName)
Expand Down
12 changes: 6 additions & 6 deletions server/configuration_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ func TestConfigurationWatcherPresets(t *testing.T) {
"quicknode": "/fast?originId=quicknode&refund=0x1234567890123456789012345678901234567890:90",
},
}

watcher, err := NewConfigurationWatcher(config)
require.NoError(t, err)
require.NotNil(t, watcher)

// Core functionality: preset should be parsed and available
preset, exists := watcher.ParsedPresets["quicknode"]
require.True(t, exists)
Expand All @@ -40,15 +40,15 @@ func TestConfigurationWatcherInvalidPresets(t *testing.T) {
"invalid": "://invalid-url", // This should be skipped
},
}

watcher, err := NewConfigurationWatcher(config)
require.NoError(t, err) // Should not fail startup

// Valid preset loaded
_, exists := watcher.ParsedPresets["valid"]
require.True(t, exists)

// Invalid preset skipped
_, exists = watcher.ParsedPresets["invalid"]
require.False(t, exists)
}
}
2 changes: 1 addition & 1 deletion server/request_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func (r *RpcRequest) sendTxToRelay() {
sendPrivateTxArgs := types.SendPrivateTxRequestWithPreferences{}
sendPrivateTxArgs.Tx = r.rawTxHex
sendPrivateTxArgs.Preferences = &r.urlParams.pref

// Replace null addresses (origin placeholders) with sender if needed
if len(r.urlParams.pref.Validity.Refund) > 0 {
sender := common.HexToAddress(r.txFrom)
Expand Down
6 changes: 5 additions & 1 deletion server/url_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func ExtractParametersFromUrl(reqUrl *url.URL, allBuilders []string) (params URL
}

addressPart := strings.ToLower(split[0])

// Handle origin keyword
if addressPart == OriginKeyword {
addresses[i] = common.Address{}
Expand Down Expand Up @@ -188,6 +188,10 @@ func ExtractParametersFromUrl(reqUrl *url.URL, allBuilders []string) (params URL
if len(useMempoolQuery) != 0 && useMempoolQuery[0] == "true" {
params.pref.Privacy.UseMempool = true
}
protectRefundQuery := normalizedQuery["protectrefund"]
if len(protectRefundQuery) != 0 && protectRefundQuery[0] == "true" {
params.pref.Privacy.ProtectRefund = true
}
canRevertQuery := normalizedQuery["canrevert"]
if len(canRevertQuery) != 0 && canRevertQuery[0] == "true" {
params.pref.CanRevert = true
Expand Down
10 changes: 3 additions & 7 deletions tests/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,11 @@ func TestMetamaskFix(t *testing.T) {
req_getTransactionCount := types.NewJsonRpcRequest(1, "eth_getTransactionCount", []interface{}{testutils.TestTx_MM2_From, "latest"})
txCountBefore := testutils.SendRpcAndParseResponseOrFailNowString(t, req_getTransactionCount)

//first sendRawTransaction call: rawTx that triggers the error (creates MM cache entry)
// first sendRawTransaction call: rawTx that triggers the error (creates MM cache entry)
req_sendRawTransaction := types.NewJsonRpcRequest(1, "eth_sendRawTransaction", []interface{}{testutils.TestTx_MM2_RawTx})
r1 := testutils.SendRpcAndParseResponseOrFailNowAllowRpcError(t, req_sendRawTransaction)
require.NotNil(t, r1.Error, r1.Error) // tx will actually fail due to incorrect nonce but it's fine for this test, since we mark it as sent to relay
//fmt.Printf("\n\n\n\n\n")
// fmt.Printf("\n\n\n\n\n")

// call getTxReceipt to trigger query to Tx API
req_getTransactionReceipt := types.NewJsonRpcRequest(1, "eth_getTransactionReceipt", []interface{}{testutils.TestTx_MM2_Hash})
Expand Down Expand Up @@ -279,7 +279,7 @@ func TestRelayTx(t *testing.T) {

// Ensure that request was signed properly
pubkey := crypto.PubkeyToAddress(relaySigningKey.PublicKey).Hex()
require.Equal(t, pubkey+":0x06e1ea66c5fc1017787369beffc9c9acd82570b4ec4ea075c708f2351a26fdff4abbf601037884d0785ff88985b590f7b865852a4100d5670605a56b9118804900", testutils.MockBackendLastRawRequest.Header.Get("X-Flashbots-Signature"))
require.Equal(t, pubkey+":0xfa3496a32970eb2caccb7cd361c9384e21e84363501cde0f325a529c2773c0a1638abf84d4d14db65b29140e2b61d1a91d0c2621abb0fb0d2eda73f1992a58d501", testutils.MockBackendLastRawRequest.Header.Get("X-Flashbots-Signature"))

// Check result - should be the tx hash
var res string
Expand Down Expand Up @@ -451,7 +451,6 @@ func TestBatch_eth_transaction(t *testing.T) {
for _, j := range res {
assert.Equal(t, m[j.Id.(float64)], j)
}

}

// Test batch request with different eth transaction
Expand Down Expand Up @@ -494,7 +493,6 @@ func TestBatch_eth_call(t *testing.T) {
for _, j := range res {
assert.Equal(t, m[j.Id.(float64)], j)
}

}

// Test batch request with different transaction
Expand Down Expand Up @@ -727,9 +725,7 @@ func Test_StoreValidateTxs(t *testing.T) {
require.Equal(t, 10, len(entry.TxSmartContractMethod))
require.False(t, entry.Fast)
}

}

}

// Test that origin keyword in refund config is replaced with sender address
Expand Down
1 change: 1 addition & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ type TxPrivacyPreferences struct {
Hints []string `json:"hints"`
Builders []string `json:"builders"`
UseMempool bool `json:"useMempool"`
ProtectRefund bool `json:"protectRefund"`
AllowTEE bool `json:"allowTee,omitempty"`
MempoolRPC string `json:"mempoolRpc"`
AuctionTimeout uint64 `json:"auctionTimeout,omitempty"`
Expand Down