server

package
v0.0.0-...-d1bef67 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: AGPL-3.0 Imports: 36 Imported by: 0

Documentation

Overview

Package server OFAC banned addresses

Package server Request represents an incoming client request

Package server Whitelist for smart contract functions that never need protection.

Index

Constants

This section is empty.

Variables

View Source
var (
	RedisPrefixTxSentToRelay = RedisPrefix + "tx-sent-to-relay:"
	RedisExpiryTxSentToRelay = 24 * time.Hour // 1 day
)

Enable lookup of timeSentToRelay by txHash

View Source
var (
	RedisPrefixTxHashForSenderAndNonce = RedisPrefix + "txsender-and-nonce-to-txhash:"
	RedisExpiryTxHashForSenderAndNonce = 24 * time.Hour // 1 day
)

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

View Source
var (
	RedisPrefixNonceFixForAccount = RedisPrefix + "txsender-with-nonce-fix:"
	RedisExpiryNonceFixForAccount = 24 * time.Hour // 1 day
)

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

View Source
var (
	RedisPrefixSenderOfTxHash = RedisPrefix + "txsender-of-txhash:"
	RedisExpirySenderOfTxHash = 24 * time.Hour // 1 day
)

Enable lookup of txFrom by txHash

View Source
var (
	RedisPrefixSenderMaxNonce = RedisPrefix + "txsender-pending-max-nonce:"
	RedisExpirySenderMaxNonce = 2 * time.Hour
)

Remember nonce of pending user tx

View Source
var (
	RedisPrefixWhitehatBundleTransactions = RedisPrefix + "tx-for-whitehat-bundle:"
	RedisExpiryWhitehatBundleTransactions = 24 * time.Hour // 1 day
)

Enable lookup of bundle txs by bundleID

View Source
var (
	RedisPrefixBlockedTxHash = RedisPrefix + "blocked-tx-hash:"
	RedisExpiryBlockedTxHash = 24 * time.Hour // 1 day
)

Enable lookup of bundle txs by bundleID

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 RedisPrefix = "rpc-endpoint:"

Functions

func AddressPtrToStr

func AddressPtrToStr(a *common.Address) string

func AuctionPreferenceErrorToJSONRPCResponse

func AuctionPreferenceErrorToJSONRPCResponse(jsonReq *types.JSONRPCRequest, err error) *types.JSONRPCResponse

func BigIntPtrToStr

func BigIntPtrToStr(i *big.Int) string

func GetEnv

func GetEnv(key, 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

func GetIPHash(r *http.Request) string

func GetSenderAddressFromTx

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

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

func IsMetamask

func IsMetamask(r *http.Request) bool

IsMetamask CHROME_ID: nkbihfbeogaeaoehlefnkodbefgpgknn

func IsMetamaskMoz

func IsMetamaskMoz(r *http.Request) bool

IsMetamaskMoz FIREFOX_ID: webextension@metamask.io

func Max

func Max(a, b uint64) uint64

func Min

func Min(a, b uint64) uint64

func NewRequestRecord

func NewRequestRecord(db database.Store) *requestRecord

func RedisKeyBlockedTxHash

func RedisKeyBlockedTxHash(txHash string) string

func RedisKeyNonceFixForAccount

func RedisKeyNonceFixForAccount(txFrom string) string

func RedisKeySenderMaxNonce

func RedisKeySenderMaxNonce(txFrom string) string

func RedisKeySenderOfTxHash

func RedisKeySenderOfTxHash(txHash string) string

func RedisKeyTxHashForSenderAndNonce

func RedisKeyTxHashForSenderAndNonce(txFrom string, nonce uint64) string

func RedisKeyTxSentToRelay

func RedisKeyTxSentToRelay(txHash string) string

func RedisKeyWhitehatBundleTransactions

func RedisKeyWhitehatBundleTransactions(bundleID string) string

Types

type BuilderNameProvider

type BuilderNameProvider interface {
	BuilderNames() []string
}

type Configuration

type Configuration struct {
	DB                  database.Store
	DrainAddress        string
	DrainSeconds        int
	ListenAddress       string
	Logger              *zap.Logger
	ProxyTimeoutSeconds int
	ProxyURL            string
	RedisURL            string
	RelaySigningKey     *ecdsa.PrivateKey
	RelayURL            string
	Version             string
	BuilderInfoSource   string
	FetchInfoInterval   int
}

type RPCEndPointServer

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

func NewRPCEndPointServer

func NewRPCEndPointServer(cfg Configuration) (*RPCEndPointServer, error)

func (*RPCEndPointServer) HandleBundleRequest

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 RPCProxyClient

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

func NewRPCProxyClient

func NewRPCProxyClient(logger *zap.Logger, proxyURL string, timeoutSeconds int) RPCProxyClient

type RPCRequest

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

func NewRPCRequest

func NewRPCRequest(logger *zap.Logger, client RPCProxyClient, jsonReq *types.JSONRPCRequest, relaySigningKey *ecdsa.PrivateKey, relayURL, origin, referer string, isWhitehatBundleCollection bool, proxyURL string, ethSendRawTxEntry *database.EthSendRawTxEntry, urlParams URLParameters, chainID []byte) *RPCRequest

func (*RPCRequest) GetAddressNonceRange

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

func (*RPCRequest) ProcessRequest

func (r *RPCRequest) ProcessRequest() *types.JSONRPCResponse

func (*RPCRequest) WhitehatBalanceCheckerRewrite

func (r *RPCRequest) WhitehatBalanceCheckerRewrite()

type RPCRequestHandler

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

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

func NewRPCRequestHandler

func NewRPCRequestHandler(logger *zap.Logger, respw *http.ResponseWriter, req *http.Request, proxyURL string, proxyTimeoutSeconds int, relaySigningKey *ecdsa.PrivateKey, relayURL string, db database.Store, builderNames []string, chainID []byte) *RPCRequestHandler

type RedisState

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

RState Metamask fix helper

func NewRedisState

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

func (*RedisState) AddTxToWhitehatBundle

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

AddTxToWhitehatBundle Enable lookup of tx bundles by bundle ID

func (*RedisState) DelNonceFixForAccount

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

func (*RedisState) DelWhitehatBundleTx

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

func (*RedisState) GetBlockedTxHash

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

func (*RedisState) GetNonceFixForAccount

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

func (*RedisState) GetSenderMaxNonce

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

func (*RedisState) GetSenderOfTxHash

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

func (*RedisState) GetTxHashForSenderAndNonce

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

func (*RedisState) GetTxSentToRelay

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

func (*RedisState) GetWhitehatBundleTx

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

func (*RedisState) SetBlockedTxHash

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

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

func (*RedisState) SetNonceFixForAccount

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

SetNonceFixForAccount nonce-fix per account

func (*RedisState) SetSenderMaxNonce

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

func (*RedisState) SetSenderOfTxHash

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

SetSenderOfTxHash Enable lookup of txFrom by txHash

func (*RedisState) SetTxHashForSenderAndNonce

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

SetTxHashForSenderAndNonce Enable lookup of txHash by txFrom+nonce

func (*RedisState) SetTxSentToRelay

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

SetTxSentToRelay Enable lookup of timeSentToRelay by txHash

type URLParameters

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

func ExtractParametersFromURL

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