Documentation ¶
Overview ¶
Package core contains everything needed to configure and run a 0x Mesh node.
Index ¶
- func NewFilteredPaginationSubprotocolV0(app *App, perPage int) ordersync.Subprotocol
- func NewFilteredPaginationSubprotocolV1(app *App, perPage int) ordersync.Subprotocol
- type App
- func (app *App) AddOrders(ctx context.Context, signedOrders []*zeroex.SignedOrder, pinned bool) (*ordervalidator.ValidationResults, error)
- func (app *App) AddOrdersRaw(ctx context.Context, signedOrdersRaw []*json.RawMessage, pinned bool) (*ordervalidator.ValidationResults, error)
- func (app *App) AddPeer(peerInfo peer.AddrInfo) error
- func (app *App) FindOrders(query *db.OrderQuery) ([]*types.OrderWithMetadata, error)
- func (app *App) GetOrder(hash common.Hash) (*types.OrderWithMetadata, error)
- func (app *App) GetOrders(perPage int, minOrderHash common.Hash) (*types.GetOrdersResponse, error)
- func (app *App) GetStats() (*types.Stats, error)
- func (app *App) HandleMessages(ctx context.Context, messages []*p2p.Message) error
- func (app *App) IsCaughtUpToLatestBlock(ctx context.Context) bool
- func (app *App) Start() error
- func (app *App) SubscribeToOrderEvents(sink chan<- []*zeroex.OrderEvent) event.Subscription
- type Config
- type ErrPerPageZero
- type FilteredPaginationRequestMetadataV0
- type FilteredPaginationRequestMetadataV1
- type FilteredPaginationResponseMetadataV0
- type FilteredPaginationResponseMetadataV1
- type FilteredPaginationSubProtocolV0
- func (p *FilteredPaginationSubProtocolV0) GenerateFirstRequestMetadata() (json.RawMessage, error)
- func (p *FilteredPaginationSubProtocolV0) HandleOrderSyncRequest(ctx context.Context, req *ordersync.Request) (*ordersync.Response, error)
- func (p *FilteredPaginationSubProtocolV0) HandleOrderSyncResponse(ctx context.Context, res *ordersync.Response) (*ordersync.Request, int, error)
- func (p *FilteredPaginationSubProtocolV0) Name() string
- func (p *FilteredPaginationSubProtocolV0) ParseRequestMetadata(metadata json.RawMessage) (interface{}, error)
- func (p *FilteredPaginationSubProtocolV0) ParseResponseMetadata(metadata json.RawMessage) (interface{}, error)
- type FilteredPaginationSubProtocolV1
- func (p *FilteredPaginationSubProtocolV1) GenerateFirstRequestMetadata() (json.RawMessage, error)
- func (p *FilteredPaginationSubProtocolV1) HandleOrderSyncRequest(ctx context.Context, req *ordersync.Request) (*ordersync.Response, error)
- func (p *FilteredPaginationSubProtocolV1) HandleOrderSyncResponse(ctx context.Context, res *ordersync.Response) (*ordersync.Request, int, error)
- func (p *FilteredPaginationSubProtocolV1) Name() string
- func (p *FilteredPaginationSubProtocolV1) ParseRequestMetadata(metadata json.RawMessage) (interface{}, error)
- func (p *FilteredPaginationSubProtocolV1) ParseResponseMetadata(metadata json.RawMessage) (interface{}, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewFilteredPaginationSubprotocolV0 ¶
func NewFilteredPaginationSubprotocolV0(app *App, perPage int) ordersync.Subprotocol
NewFilteredPaginationSubprotocolV0 creates and returns a new FilteredPaginationSubprotocolV0 which will respond with perPage orders for each individual request/response.
func NewFilteredPaginationSubprotocolV1 ¶
func NewFilteredPaginationSubprotocolV1(app *App, perPage int) ordersync.Subprotocol
NewFilteredPaginationSubprotocolV1 creates and returns a new FilteredPaginationSubprotocolV1 which will respond with perPage orders for each individual request/response.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
func (*App) AddOrders ¶
func (app *App) AddOrders(ctx context.Context, signedOrders []*zeroex.SignedOrder, pinned bool) (*ordervalidator.ValidationResults, error)
AddOrders can be used to add orders to Mesh. It validates the given orders and if they are valid, will store and broadcast the orders to peers. If pinned is true, the orders will be marked as pinned, which means they will only be removed if they become unfillable and will not be removed due to having a high expiration time or any incentive mechanisms.
func (*App) AddOrdersRaw ¶
func (app *App) AddOrdersRaw(ctx context.Context, signedOrdersRaw []*json.RawMessage, pinned bool) (*ordervalidator.ValidationResults, error)
AddOrdersRaw is like AddOrders but accepts raw JSON messages.
func (*App) FindOrders ¶
func (app *App) FindOrders(query *db.OrderQuery) ([]*types.OrderWithMetadata, error)
func (*App) GetOrders ¶
GetOrders retrieves perPage orders from the database with an order hash greater than minOrderHash (exclusive). The orders in the response are sorted by hash. In order to paginate through all orders:
- First call GetOrders with an empty minOrderHash.
- On subsequent calls, use the maximum hash of the orders from the previous response as the next minOrderHash.
- When no orders are returned, pagination is complete.
When following this process, GetOrders offers the following guarantees:
- Any order that was present before pagination started *and* was present after pagination ended will be included in a response.
- No order will be included in more than one response.
- Orders that were added or deleted during pagination may or may not be included in a response.
func (*App) HandleMessages ¶
func (*App) IsCaughtUpToLatestBlock ¶
IsCaughtUpToLatestBlock returns whether or not the latest block stored by Mesh corresponds to the latest block retrieved from it's Ethereum RPC endpoint
func (*App) SubscribeToOrderEvents ¶
func (app *App) SubscribeToOrderEvents(sink chan<- []*zeroex.OrderEvent) event.Subscription
SubscribeToOrderEvents let's one subscribe to order events emitted by the OrderWatcher
type Config ¶
type Config struct { // Verbosity is the logging verbosity: 0=panic, 1=fatal, 2=error, 3=warn, 4=info, 5=debug 6=trace Verbosity int `envvar:"VERBOSITY" default:"2"` // DataDir is the directory to use for persisting all data, including the // database and private key files. DataDir string `envvar:"DATA_DIR" default:"0x_mesh"` // P2PTCPPort is the port on which to listen for new TCP connections from // peers in the network. Set to 60558 by default. P2PTCPPort int `envvar:"P2P_TCP_PORT" default:"60558"` // P2PWebSocketsPort is the port on which to listen for new WebSockets // connections from peers in the network. Set to 60559 by default. P2PWebSocketsPort int `envvar:"P2P_WEBSOCKETS_PORT" default:"60559"` // EthereumRPCURL is the URL of an Etheruem node which supports the JSON RPC // API. EthereumRPCURL string `envvar:"ETHEREUM_RPC_URL" json:"-"` // EthereumChainID is the chain ID specifying which Ethereum chain you wish to // run your Mesh node for EthereumChainID int `envvar:"ETHEREUM_CHAIN_ID"` // UseBootstrapList is whether to bootstrap the DHT by connecting to a // specific set of peers. UseBootstrapList bool `envvar:"USE_BOOTSTRAP_LIST" default:"true"` // BootstrapList is a comma-separated list of multiaddresses to use for // bootstrapping the DHT (e.g., // "/ip4/3.214.190.67/tcp/60558/ipfs/16Uiu2HAmGx8Z6gdq5T5AQE54GMtqDhDFhizywTy1o28NJbAMMumF"). // If empty, the default bootstrap list will be used. BootstrapList string `envvar:"BOOTSTRAP_LIST" default:""` // BlockPollingInterval is the polling interval to wait before checking for a new Ethereum block // that might contain transactions that impact the fillability of orders stored by Mesh. Different // chains have different block producing intervals: POW chains are typically slower (e.g., Mainnet) // and POA chains faster (e.g., Kovan) so one should adjust the polling interval accordingly. BlockPollingInterval time.Duration `envvar:"BLOCK_POLLING_INTERVAL" default:"5s"` // EthereumRPCMaxContentLength is the maximum request Content-Length accepted by the backing Ethereum RPC // endpoint used by Mesh. Geth & Infura both limit a request's content length to 1024 * 512 Bytes. Parity // and Alchemy have much higher limits. When batch validating 0x orders, we will fit as many orders into a // request without crossing the max content length. The default value is appropriate for operators using Geth // or Infura. If using Alchemy or Parity, feel free to double the default max in order to reduce the // number of RPC calls made by Mesh. EthereumRPCMaxContentLength int `envvar:"ETHEREUM_RPC_MAX_CONTENT_LENGTH" default:"524288"` // EnableEthereumRPCRateLimiting determines whether or not Mesh should limit // the number of Ethereum RPC requests it sends. It defaults to true. // Disabling Ethereum RPC rate limiting can reduce latency for receiving order // events in some network conditions, but can also potentially lead to higher // costs or other rate limiting issues outside of Mesh, depending on your // Ethereum RPC provider. If set to false, ethereumRPCMaxRequestsPer24HrUTC // and ethereumRPCMaxRequestsPerSecond will have no effect. EnableEthereumRPCRateLimiting bool `envvar:"ENABLE_ETHEREUM_RPC_RATE_LIMITING" default:"true"` // EthereumRPCMaxRequestsPer24HrUTC caps the number of Ethereum JSON-RPC requests a Mesh node will make // per 24hr UTC time window (time window starts and ends at midnight UTC). It defaults to 200k but // can be increased well beyond this limit depending on your infrastructure or Ethereum RPC provider. EthereumRPCMaxRequestsPer24HrUTC int `envvar:"ETHEREUM_RPC_MAX_REQUESTS_PER_24_HR_UTC" default:"200000"` // EthereumRPCMaxRequestsPerSecond caps the number of Ethereum JSON-RPC requests a Mesh node will make per // second. This limits the concurrency of these requests and prevents the Mesh node from getting rate-limited. // It defaults to the recommended 30 rps for Infura's free tier, and can be increased to 100 rpc for pro users, // and potentially higher on alternative infrastructure. EthereumRPCMaxRequestsPerSecond float64 `envvar:"ETHEREUM_RPC_MAX_REQUESTS_PER_SECOND" default:"30"` // CustomContractAddresses is a JSON-encoded string representing a set of // custom addresses to use for the configured chain ID. The contract // addresses for most common chains/networks are already included by default, so this // is typically only needed for testing on custom chains/networks. The given // addresses are added to the default list of addresses for known chains/networks and // overriding any contract addresses for known chains/networks is not allowed. The // addresses for exchange, devUtils, erc20Proxy, erc721Proxy and erc1155Proxy are required // for each chain/network. For example: // // { // "exchange":"0x48bacb9266a570d521063ef5dd96e61686dbe788", // "devUtils": "0x38ef19fdf8e8415f18c307ed71967e19aac28ba1", // "erc20Proxy": "0x1dc4c1cefef38a777b15aa20260a54e584b16c48", // "erc721Proxy": "0x1d7022f5b17d2f8b695918fb48fa1089c9f85401", // "erc1155Proxy": "0x64517fa2b480ba3678a2a3c0cf08ef7fd4fad36f" // } // CustomContractAddresses string `envvar:"CUSTOM_CONTRACT_ADDRESSES" default:""` // MaxOrdersInStorage is the maximum number of orders that Mesh will keep in // storage. As the number of orders in storage grows, Mesh will begin // enforcing a limit on maximum expiration time for incoming orders and remove // any orders with an expiration time too far in the future. MaxOrdersInStorage int `envvar:"MAX_ORDERS_IN_STORAGE" default:"100000"` // CustomOrderFilter is a stringified JSON Schema which will be used for // validating incoming orders. If provided, Mesh will only receive orders from // other peers in the network with the same filter. // // Here is an example filter which will only allow orders with a specific // makerAssetData: // // { // "properties": { // "makerAssetData": { // "const": "0xf47261b0000000000000000000000000871dd7c2b4b25e1aa18728e9d5f2af4c4e431f5c" // } // } // } // // Note that you only need to include the requirements for your specific // application in the filter. The default requirements for a valid order (e.g. // all the required fields) are automatically included. For more information // on JSON Schemas, see https://json-schema.org/ CustomOrderFilter string `envvar:"CUSTOM_ORDER_FILTER" default:"{}"` // EthereumRPCClient is the client to use for all Ethereum RPC reuqests. It is only // settable in browsers and cannot be set via environment variable. If // provided, EthereumRPCURL will be ignored. EthereumRPCClient ethclient.RPCClient `envvar:"-"` // MaxBytesPerSecond is the maximum number of bytes per second that a peer is // allowed to send before failing the bandwidth check. Defaults to 5 MiB. MaxBytesPerSecond float64 `envvar:"MAX_BYTES_PER_SECOND" default:"5242880"` }
Config is a set of configuration options for 0x Mesh.
type ErrPerPageZero ¶
type ErrPerPageZero struct{}
ErrPerPageZero is the error returned when a GetOrders request specifies perPage to 0
func (ErrPerPageZero) Error ¶
func (e ErrPerPageZero) Error() string
type FilteredPaginationRequestMetadataV0 ¶
type FilteredPaginationRequestMetadataV0 struct { OrderFilter *orderfilter.Filter `json:"orderfilter"` Page int `json:"page"` SnapshotID string `json:"snapshotID"` }
FilteredPaginationRequestMetadataV0 is the request metadata for the FilteredPaginationSubProtocolV0. It keeps track of the current page and SnapshotID, which is expected to be an empty string on the first request.
type FilteredPaginationRequestMetadataV1 ¶
type FilteredPaginationRequestMetadataV1 struct { OrderFilter *orderfilter.Filter `json:"orderfilter"` MinOrderHash common.Hash `json:"minOrderHash"` }
FilteredPaginationRequestMetadataV1 is the request metadata for the FilteredPaginationSubProtocolV1. It keeps track of the current minOrderHash, which is expected to be an empty string on the first request.
type FilteredPaginationResponseMetadataV0 ¶
type FilteredPaginationResponseMetadataV0 struct { Page int `json:"page"` SnapshotID string `json:"snapshotID"` }
FilteredPaginationResponseMetadataV0 is the response metadata for the FilteredPaginationSubProtocolV0. It keeps track of the current page and SnapshotID.
type FilteredPaginationResponseMetadataV1 ¶
type FilteredPaginationResponseMetadataV1 struct {
NextMinOrderHash common.Hash `json:"nextMinOrderHash"`
}
FilteredPaginationResponseMetadataV1 is the response metadata for the FilteredPaginationSubProtocolV1. It contains the minOrderHash to use for the next request.
type FilteredPaginationSubProtocolV0 ¶
type FilteredPaginationSubProtocolV0 struct {
// contains filtered or unexported fields
}
FilteredPaginationSubProtocolV0 is an ordersync subprotocol which returns all orders by paginating through them. It involves sending multiple requests until pagination is finished and all orders have been returned. Version 0 of the subprotocol is deprecated but included for backwards-compatibility.
func (*FilteredPaginationSubProtocolV0) GenerateFirstRequestMetadata ¶
func (p *FilteredPaginationSubProtocolV0) GenerateFirstRequestMetadata() (json.RawMessage, error)
func (*FilteredPaginationSubProtocolV0) HandleOrderSyncRequest ¶
func (p *FilteredPaginationSubProtocolV0) HandleOrderSyncRequest(ctx context.Context, req *ordersync.Request) (*ordersync.Response, error)
HandleOrderSyncRequest returns the orders for one page, based on the page number and snapshotID corresponding to the given request. This is the implementation for the "provider" side of the subprotocol.
func (*FilteredPaginationSubProtocolV0) HandleOrderSyncResponse ¶
func (p *FilteredPaginationSubProtocolV0) HandleOrderSyncResponse(ctx context.Context, res *ordersync.Response) (*ordersync.Request, int, error)
HandleOrderSyncResponse handles the orders for one page by validating them, storing them in the database, and firing the appropriate events. It also returns the next request to be sent. This is the implementation for the "requester" side of the subprotocol.
func (*FilteredPaginationSubProtocolV0) Name ¶
func (p *FilteredPaginationSubProtocolV0) Name() string
Name returns the name of the FilteredPaginationSubProtocolV0
func (*FilteredPaginationSubProtocolV0) ParseRequestMetadata ¶
func (p *FilteredPaginationSubProtocolV0) ParseRequestMetadata(metadata json.RawMessage) (interface{}, error)
func (*FilteredPaginationSubProtocolV0) ParseResponseMetadata ¶
func (p *FilteredPaginationSubProtocolV0) ParseResponseMetadata(metadata json.RawMessage) (interface{}, error)
type FilteredPaginationSubProtocolV1 ¶
type FilteredPaginationSubProtocolV1 struct {
// contains filtered or unexported fields
}
FilteredPaginationSubProtocolV1 is an ordersync subprotocol which returns all orders by paginating through them. It involves sending multiple requests until pagination is finished and all orders have been returned. Version 1 was implemented in https://github.com/0xProject/0x-mesh/pull/793 after changing the database implementation from LevelDB to SQL and Dexie.js/IndexedDB.
func (*FilteredPaginationSubProtocolV1) GenerateFirstRequestMetadata ¶
func (p *FilteredPaginationSubProtocolV1) GenerateFirstRequestMetadata() (json.RawMessage, error)
func (*FilteredPaginationSubProtocolV1) HandleOrderSyncRequest ¶
func (p *FilteredPaginationSubProtocolV1) HandleOrderSyncRequest(ctx context.Context, req *ordersync.Request) (*ordersync.Response, error)
HandleOrderSyncRequest returns the orders for one page, based on the page number and snapshotID corresponding to the given request. This is the implementation for the "provider" side of the subprotocol.
func (*FilteredPaginationSubProtocolV1) HandleOrderSyncResponse ¶
func (p *FilteredPaginationSubProtocolV1) HandleOrderSyncResponse(ctx context.Context, res *ordersync.Response) (*ordersync.Request, int, error)
HandleOrderSyncResponse handles the orders for one page by validating them, storing them in the database, and firing the appropriate events. It also returns the next request to be sent. This is the implementation for the "requester" side of the subprotocol.
func (*FilteredPaginationSubProtocolV1) Name ¶
func (p *FilteredPaginationSubProtocolV1) Name() string
Name returns the name of the FilteredPaginationSubProtocolV1
func (*FilteredPaginationSubProtocolV1) ParseRequestMetadata ¶
func (p *FilteredPaginationSubProtocolV1) ParseRequestMetadata(metadata json.RawMessage) (interface{}, error)
func (*FilteredPaginationSubProtocolV1) ParseResponseMetadata ¶
func (p *FilteredPaginationSubProtocolV1) ParseResponseMetadata(metadata json.RawMessage) (interface{}, error)
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package ordersync contains the ordersync protocol, which is used for sharing existing orders between two peers, typically during initialization.
|
Package ordersync contains the ordersync protocol, which is used for sharing existing orders between two peers, typically during initialization. |