server

package
v1.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2025 License: MIT Imports: 43 Imported by: 0

Documentation

Overview

OFAC banned addresses

Request represents an incoming client request

Whitelist for smart contract functions that never need protection.

Index

Constants

View Source
const (
	OriginKeyword = "origin"
)

Variables

View Source
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.")
	ErrIncorrectOriginId                   = errors.New("Incorrect origin id, must be less then 255 char.")
	ErrIncorrectRefundQuery                = errors.New("Incorrect refund query, must be 0xaddress:percentage.")
	ErrIncorrectRefundAddressQuery         = errors.New("Incorrect refund address.")
	ErrUnsupportedRefundKeyword            = errors.New("Unsupported refund keyword (only 'origin' is supported).")
	ErrIncorrectRefundPercentageQuery      = errors.New("Incorrect refund percentage.")
	ErrIncorrectRefundTotalPercentageQuery = errors.New("Incorrect refund total percentage, must be bellow 100%.")
)
View Source
var DebugDontSendTx = os.Getenv("DEBUG_DONT_SEND_RAWTX") != ""
View Source
var ErrCustomerNotConfigured = errors.New("customer is not configured")
View Source
var Now = time.Now // used to mock time in tests
View Source
var ProtectTxApiHost = GetEnv("TX_API_HOST", "https://protect.flashbots.net")
View Source
var RedisExpiryBlockedTxHash = 24 * time.Hour // 1 day
View Source
var RedisExpiryNonceFixForAccount = 24 * time.Hour // 1 day
View Source
var RedisExpiryNonceOfTxHash = 24 * time.Hour // 1 day
View Source
var RedisExpirySenderMaxNonce = 280 * time.Second //weird time to be a little less than 5 minute default blockrange
View Source
var RedisExpirySenderOfTxHash = 24 * time.Hour // 1 day
View Source
var RedisExpiryTxHashForSenderAndNonce = 24 * time.Hour // 1 day
View Source
var RedisExpiryTxSentToRelay = 24 * time.Hour // 1 day
View Source
var RedisExpiryWhitehatBundleTransactions = 24 * time.Hour // 1 day
View Source
var RedisPrefix = "rpc-endpoint:"
View Source
var RedisPrefixBlockedTxHash = RedisPrefix + "blocked-tx-hash:"

Enable lookup of bundle txs by bundleId

View Source
var RedisPrefixNonceFixForAccount = RedisPrefix + "txsender-with-nonce-fix:"

nonce-fix of an account (with number of times sent)

View Source
var RedisPrefixNonceOfTxHash = RedisPrefix + "txnonce-of-txhash:"

Enable lookup of txNonce by txHash

View Source
var RedisPrefixSenderMaxNonce = RedisPrefix + "txsender-pending-max-nonce:"

Remember nonce of pending user tx

View Source
var RedisPrefixSenderOfTxHash = RedisPrefix + "txsender-of-txhash:"

Enable lookup of txFrom by txHash

View Source
var RedisPrefixTxHashForSenderAndNonce = RedisPrefix + "txsender-and-nonce-to-txhash:"

Enable lookup of txHash by txFrom+nonce (only if sent to relay)

View Source
var RedisPrefixTxSentToRelay = RedisPrefix + "tx-sent-to-relay:"

Enable lookup of timeSentToRelay by txHash

View Source
var RedisPrefixWhitehatBundleTransactions = RedisPrefix + "tx-for-whitehat-bundle:"

Enable lookup of bundle txs by bundleId

Functions

func AddressPtrToStr added in v1.4.4

func AddressPtrToStr(a *common.Address) string

func AuctionPreferenceErrorToJSONRPCResponse added in v1.6.0

func AuctionPreferenceErrorToJSONRPCResponse(jsonReq *types.JsonRpcRequest, err error) *types.JsonRpcResponse

func BigIntPtrToStr added in v1.4.4

func BigIntPtrToStr(i *big.Int) string

func EquivalentURLParams added in v1.11.0

func EquivalentURLParams(left URLParameters, right URLParameters) bool

func GetEnv added in v1.6.0

func GetEnv(key string, defaultValue string) string

GetEnv returns the value of the environment variable named by key, or defaultValue if the environment variable doesn't exist

func GetIP

func GetIP(r *http.Request) string

func GetIPHash added in v1.5.0

func GetIPHash(r *http.Request) string

func GetSenderAddressFromTx added in v1.6.0

func GetSenderAddressFromTx(tx *ethtypes.Transaction) (common.Address, error)

func GetSenderFromRawTx

func GetSenderFromRawTx(tx *ethtypes.Transaction) (string, error)

func GetSenderFromTx

func GetSenderFromTx(tx *ethtypes.Transaction) (string, error)

func GetTx

func GetTx(rawTxHex string) (*ethtypes.Transaction, error)

func GetTxStatus added in v1.3.0

func GetTxStatus(txHash string) (*types.PrivateTxApiResponse, error)

func IsMetamask

func IsMetamask(r *http.Request) bool

CHROME_ID: nkbihfbeogaeaoehlefnkodbefgpgknn

func IsMetamaskMoz

func IsMetamaskMoz(r *http.Request) bool

FIREFOX_ID: [email protected]

func Max added in v1.4.2

func Max(a uint64, b uint64) uint64

func MetricsMiddleware added in v1.11.0

func MetricsMiddleware(next http.Handler) http.Handler

func Min added in v1.4.2

func Min(a uint64, b uint64) uint64

func NewRequestRecord added in v1.5.0

func NewRequestRecord(db database.Store) *requestRecord

func RedisKeyBlockedTxHash added in v1.5.1

func RedisKeyBlockedTxHash(txHash string) string

func RedisKeyNonceFixForAccount added in v1.4.2

func RedisKeyNonceFixForAccount(txFrom string) string

func RedisKeyNonceOfTxHash added in v1.8.3

func RedisKeyNonceOfTxHash(txHash string) string

func RedisKeySenderMaxNonce added in v1.4.2

func RedisKeySenderMaxNonce(txFrom string) string

func RedisKeySenderOfTxHash added in v1.4.2

func RedisKeySenderOfTxHash(txHash string) string

func RedisKeyTxHashForSenderAndNonce added in v1.4.2

func RedisKeyTxHashForSenderAndNonce(txFrom string, nonce uint64) string

func RedisKeyTxSentToRelay added in v1.4.2

func RedisKeyTxSentToRelay(txHash string) string

func RedisKeyWhitehatBundleTransactions added in v1.4.3

func RedisKeyWhitehatBundleTransactions(bundleId string) string

Types

type BuilderNameProvider added in v1.6.0

type BuilderNameProvider interface {
	BuilderNames() []string
}

type Configuration added in v1.6.0

type Configuration struct {
	DB                   database.Store
	DrainAddress         string
	DrainSeconds         int
	ListenAddress        string
	Logger               log.Logger
	ProxyTimeoutSeconds  int
	ProxyUrl             string
	RedisUrl             string
	RelaySigningKey      *ecdsa.PrivateKey
	RelayUrl             string
	Version              string
	BuilderInfoSource    string
	FetchInfoInterval    int
	TTLCacheSeconds      int64
	DefaultMempoolRPC    string
	ConfigurationWatcher *ConfigurationWatcher
}

type ConfigurationWatcher added in v1.11.0

type ConfigurationWatcher struct {
	// CustomersConfig represents config for each custom with allowed list of configuration parameters
	ParsedCustomersConfig map[string][]URLParameters
	// ParsedPresets contains pre-parsed preset configurations for header-based override
	ParsedPresets map[string]URLParameters
}

ConfigurationWatcher all params are normilized

func NewConfigurationWatcher added in v1.11.0

func NewConfigurationWatcher(customersConfig CustomersConfig) (*ConfigurationWatcher, error)

func ReadCustomerConfigFromFile added in v1.11.0

func ReadCustomerConfigFromFile(fileName string) (*ConfigurationWatcher, error)

func (*ConfigurationWatcher) Customers added in v1.11.0

func (watcher *ConfigurationWatcher) Customers() []string

func (*ConfigurationWatcher) IsConfigurationUpdated added in v1.11.0

func (watcher *ConfigurationWatcher) IsConfigurationUpdated(customer string, urlParams URLParameters) bool

type CustomersConfig added in v1.11.0

type CustomersConfig struct {
	URLs    map[string][]string `yaml:"urls"`
	Presets map[string]string   `yaml:"presets,omitempty"`
}

type Fingerprint added in v1.7.0

type Fingerprint uint64

func FingerprintFromRequest added in v1.7.0

func FingerprintFromRequest(req *http.Request, at time.Time, seed uint64) (Fingerprint, error)

FingerprintFromRequest returns a fingerprint for the request based on the X-Forwarded-For header and a salted timestamp. The fingerprint is used to identify unique users sessions over a short period of time, and thus can be used as a key for rate limiting. The seed param is additional entropy to make the fingerprint resistant to rainbow table lookups. Without the seed a malicious rpc operator could reverse a client IP address to a fingerprint by exhausting all possible IP addresses and comparing the resulting fingerprints.

We considered adding the User-Agent header to the fingerprint, but decided against it because it would make the fingerprint gameable. Instead, we will salt the fingerprint with the current timestamp rounded to the latest hour. This will make sure fingerprints rotate every hour so we cannot reasonably track user behavior over time.

func (Fingerprint) ToIPv6 added in v1.7.0

func (f Fingerprint) ToIPv6() net.IP

type RPCProxyClient added in v1.4.4

type RPCProxyClient interface {
	ProxyRequest(body []byte) (*http.Response, error)
}

func NewRPCProxyClient added in v1.4.4

func NewRPCProxyClient(logger log.Logger, proxyURL string, timeoutSeconds int, fingerprint Fingerprint) RPCProxyClient

type RedisState added in v1.4.2

type RedisState struct {
	RedisClient *redis.Client
}
var RState *RedisState

Metamask fix helper

func NewRedisState added in v1.4.2

func NewRedisState(redisUrl string) (*RedisState, error)

func (*RedisState) AddTxToWhitehatBundle added in v1.4.3

func (s *RedisState) AddTxToWhitehatBundle(bundleId string, signedTx string) error

Enable lookup of tx bundles by bundle ID

func (*RedisState) DelNonceFixForAccount added in v1.4.2

func (s *RedisState) DelNonceFixForAccount(txFrom string) error

func (*RedisState) DelSenderMaxNonce added in v1.8.1

func (s *RedisState) DelSenderMaxNonce(txFrom string) error

func (*RedisState) DelWhitehatBundleTx added in v1.4.3

func (s *RedisState) DelWhitehatBundleTx(bundleId string) error

func (*RedisState) GetBlockedTxHash added in v1.5.1

func (s *RedisState) GetBlockedTxHash(txHash string) (returnValue string, found bool, err error)

func (*RedisState) GetNonceFixForAccount added in v1.4.2

func (s *RedisState) GetNonceFixForAccount(txFrom string) (numTimesSent uint64, found bool, err error)

func (*RedisState) GetNonceOfTxHash added in v1.8.3

func (s *RedisState) GetNonceOfTxHash(txHash string) (txNonce uint64, found bool, err error)

func (*RedisState) GetSenderMaxNonce added in v1.4.2

func (s *RedisState) GetSenderMaxNonce(txFrom string) (senderMaxNonce uint64, found bool, err error)

func (*RedisState) GetSenderOfTxHash added in v1.4.2

func (s *RedisState) GetSenderOfTxHash(txHash string) (txSender string, found bool, err error)

func (*RedisState) GetTxHashForSenderAndNonce added in v1.4.2

func (s *RedisState) GetTxHashForSenderAndNonce(txFrom string, nonce uint64) (txHash string, found bool, err error)

func (*RedisState) GetTxSentToRelay added in v1.4.2

func (s *RedisState) GetTxSentToRelay(txHash string) (timeSent time.Time, found bool, err error)

func (*RedisState) GetWhitehatBundleTx added in v1.4.3

func (s *RedisState) GetWhitehatBundleTx(bundleId string) ([]string, error)

func (*RedisState) SetBlockedTxHash added in v1.5.1

func (s *RedisState) SetBlockedTxHash(txHash string, returnValue string) error

Block transactions, with a specific return value (eg. "nonce too low")

func (*RedisState) SetNonceFixForAccount added in v1.4.2

func (s *RedisState) SetNonceFixForAccount(txFrom string, numTimesSent uint64) error

nonce-fix per account

func (*RedisState) SetSenderAndNonceOfTxHash added in v1.8.3

func (s *RedisState) SetSenderAndNonceOfTxHash(txHash string, txFrom string, txNonce uint64) error

Enable lookup of txFrom and nonce by txHash

func (*RedisState) SetSenderMaxNonce added in v1.4.2

func (s *RedisState) SetSenderMaxNonce(txFrom string, nonce uint64, blockRange int) error

func (*RedisState) SetTxHashForSenderAndNonce added in v1.4.2

func (s *RedisState) SetTxHashForSenderAndNonce(txFrom string, nonce uint64, txHash string) error

Enable lookup of txHash by txFrom+nonce

func (*RedisState) SetTxSentToRelay added in v1.4.2

func (s *RedisState) SetTxSentToRelay(txHash string) error

Enable lookup of timeSentToRelay by txHash

type RpcEndPointServer

type RpcEndPointServer struct {
	// contains filtered or unexported fields
}

func NewRpcEndPointServer

func NewRpcEndPointServer(cfg Configuration) (*RpcEndPointServer, error)

func (*RpcEndPointServer) HandleBundleRequest added in v1.4.3

func (s *RpcEndPointServer) HandleBundleRequest(respw http.ResponseWriter, req *http.Request)

func (*RpcEndPointServer) HandleHttpRequest

func (s *RpcEndPointServer) HandleHttpRequest(respw http.ResponseWriter, req *http.Request)

func (*RpcEndPointServer) Start

func (s *RpcEndPointServer) Start()

type RpcRequest

type RpcRequest struct {
	// contains filtered or unexported fields
}

func NewRpcRequest

func NewRpcRequest(
	logger log.Logger,
	client RPCProxyClient,
	jsonReq *types.JsonRpcRequest,
	relaySigningKey *ecdsa.PrivateKey,
	relayUrl, origin, referer string,
	isWhitehatBundleCollection bool,
	whitehatBundleId string,
	ethSendRawTxEntry *database.EthSendRawTxEntry,
	urlParams URLParameters,
	chainID []byte,
	rpcCache *application.RpcCache,
	defaultEthClient *ethclient.Client,
) *RpcRequest

func (*RpcRequest) CheckFlashbotsSignature added in v1.8.0

func (r *RpcRequest) CheckFlashbotsSignature(signature string, body []byte) error

CheckFlashbotsSignature parses and validates the Flashbots signature if present, returning an error if the signature is invalid. If the signature is present and valid the signing address is stored in the request.

func (*RpcRequest) GetAddressNonceRange added in v1.4.2

func (r *RpcRequest) GetAddressNonceRange(address string) (minNonce, maxNonce uint64, err error)

func (*RpcRequest) ProcessRequest added in v1.4.3

func (r *RpcRequest) ProcessRequest() *types.JsonRpcResponse

func (*RpcRequest) WhitehatBalanceCheckerRewrite added in v1.4.3

func (r *RpcRequest) WhitehatBalanceCheckerRewrite()

type RpcRequestHandler added in v1.4.3

type RpcRequestHandler struct {
	// contains filtered or unexported fields
}

RPC request handler for a single/ batch JSON-RPC request

func NewRpcRequestHandler added in v1.4.3

func NewRpcRequestHandler(
	logger log.Logger,
	respw *http.ResponseWriter,
	req *http.Request,
	proxyUrl string,
	proxyTimeoutSeconds int,
	relaySigningKey *ecdsa.PrivateKey,
	relayUrl string,
	db database.Store,
	builderNames []string,
	chainID []byte,
	rpcCache *application.RpcCache,
	defaultEthClient *ethclient.Client,
	configurationWatcher *ConfigurationWatcher,
) *RpcRequestHandler

type URLParameters added in v1.6.0

type URLParameters struct {
	// contains filtered or unexported fields
}

func ExtractParametersFromUrl added in v1.6.0

func ExtractParametersFromUrl(reqUrl *url.URL, allBuilders []string) (params URLParameters, err error)

ExtractParametersFromUrl extracts the auction preference from the url query Allowed query params:

  • hint: mev share hints, can be set multiple times, default: hash, special_logs
  • originId: origin id, default: ""
  • 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)
  • auctionTimeout: auction timeout in milliseconds example: 0x123:80 - will refund 80% of the backrun profit to 0x123

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL