server

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2024 License: MIT Imports: 39 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

This section is empty.

Variables

View Source
var (
	DefaultAuctionHint = []string{"hash", "special_logs"}

	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.")
	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 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 RedisExpirySenderMaxNonce = 2 * time.Hour
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 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 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: webextension@metamask.io

func Max added in v1.4.2

func Max(a uint64, b uint64) uint64

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 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
}

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) 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) SetSenderMaxNonce added in v1.4.2

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

func (*RedisState) SetSenderOfTxHash added in v1.4.2

func (s *RedisState) SetSenderOfTxHash(txHash string, txFrom string) error

Enable lookup of txFrom by txHash

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,
) *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,
) *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(url *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) 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