Files
electroncash-protocol/environment.rst
T

418 lines
14 KiB
ReStructuredText
Raw Normal View History

2018-03-16 09:59:27 +08:00
.. _environment:
2017-01-03 10:24:11 +09:00
=====================
Environment Variables
=====================
ElectrumX takes no command line arguments, instead its behaviour is
controlled by environment variables. Only a few are required to be
given, the rest will have sensible defaults if not specified. Many of
the defaults around resource usage are conservative; I encourage you
to review them.
2017-09-09 21:53:03 +09:00
Note: by default the server will only serve to connections from the
same machine. To be accessible to other users across the internet you
must set **HOST** appropriately; see below.
2017-01-03 10:24:11 +09:00
Required
2018-03-26 16:48:37 +09:00
========
2017-01-03 10:24:11 +09:00
These environment variables are always required:
2018-03-26 16:48:37 +09:00
.. envvar:: COIN
2017-09-07 13:53:44 +09:00
2018-03-26 16:48:37 +09:00
Must be a :attr:`NAME` from one of the :class:`Coin` classes in
2017-09-07 13:53:44 +09:00
`lib/coins.py`_.
2018-03-26 16:48:37 +09:00
.. envvar:: DB_DIRECTORY
2017-01-03 10:24:11 +09:00
The path to the database directory. Relative paths should be
relative to the parent process working directory. This is the
directory of the `run` script if you use it.
2018-03-26 16:48:37 +09:00
.. envvar:: DAEMON_URL
2017-01-03 10:24:11 +09:00
A comma-separated list of daemon URLs. If more than one is provided
ElectrumX will initially connect to the first, and failover to
subsequent ones round-robin style if one stops working.
2018-03-26 16:48:37 +09:00
The generic form of a daemon URL is::
2017-01-03 10:24:11 +09:00
2018-03-26 16:48:37 +09:00
http://username:password@hostname:port/
2017-01-03 10:24:11 +09:00
2018-03-26 16:48:37 +09:00
The leading ``http://`` is optional, as is the trailing slash. The
``:port`` part is also optional and will default to the standard RPC
port for :envvar:`COIN` and :envvar:`NET` if omitted.
2017-01-03 10:24:11 +09:00
2018-03-26 16:48:37 +09:00
For the ``run`` script
======================
2017-01-03 10:24:11 +09:00
2018-03-26 16:48:37 +09:00
The following are required if you use the ``run`` script:
2017-01-03 10:24:11 +09:00
2018-03-26 16:48:37 +09:00
.. envvar:: ELECTRUMX
2017-01-03 10:24:11 +09:00
The path to the electrumx_server.py script. Relative paths should
2018-03-26 16:48:37 +09:00
be relative to the directory of the ``run`` script.
2017-01-03 10:24:11 +09:00
2018-03-26 16:48:37 +09:00
.. envvar:: USERNAME
2017-01-03 10:24:11 +09:00
The username the server will run as.
2017-09-09 21:53:03 +09:00
2017-01-03 10:24:11 +09:00
Miscellaneous
2018-03-26 16:48:37 +09:00
=============
2017-01-03 10:24:11 +09:00
These environment variables are optional:
2018-03-26 16:48:37 +09:00
.. envvar:: LOG_FORMAT
The Python logging `format string
<https://docs.python.org/3/library/logging.html#logrecord-attributes>`_
2018-03-26 16:48:37 +09:00
to use. Defaults to ``%(levelname)s:%(name)s:%(message)s``.
2018-03-26 16:48:37 +09:00
.. envvar:: ALLOW_ROOT
2017-09-20 01:14:06 +01:00
Set this environment variable to anything non-empty to allow running
ElectrumX as root.
2017-09-20 01:14:06 +01:00
2018-03-26 16:48:37 +09:00
.. envvar:: NET
2017-01-03 10:24:11 +09:00
2018-03-26 16:48:37 +09:00
Must be a :envvar:`NET` from one of the **Coin** classes in
`lib/coins.py`_. Defaults to ``mainnet``.
2017-01-03 10:24:11 +09:00
2018-03-26 16:48:37 +09:00
.. envvar:: DB_ENGINE
2017-01-03 10:24:11 +09:00
2017-01-04 08:18:57 +09:00
Database engine for the UTXO and history database. The default is
2018-03-26 16:48:37 +09:00
``leveldb``. The other alternative is ``rocksdb``. You will need
to install the appropriate python package for your engine. The
value is not case sensitive.
2017-01-03 10:24:11 +09:00
2018-03-26 16:48:37 +09:00
.. envvar:: HOST
2017-01-03 10:24:11 +09:00
2017-09-06 20:12:13 +09:00
The host or IP address that the TCP and SSL servers will use when
2018-03-26 16:48:37 +09:00
binding listening sockets. Defaults to ``localhost``. To listen on
2017-09-06 20:12:13 +09:00
multiple specific addresses specify a comma-separated list. Set to
an empty string to listen on all available interfaces (likely both
IPv4 and IPv6).
2017-01-03 10:24:11 +09:00
2018-03-26 16:48:37 +09:00
.. envvar:: TCP_PORT
2017-01-03 10:24:11 +09:00
2018-03-26 16:48:37 +09:00
If set ElectrumX will serve TCP clients on
:envvar:`HOST`\::envvar:`TCP_PORT`.
2017-01-03 10:24:11 +09:00
2018-03-26 16:48:37 +09:00
.. note:: ElectrumX will not serve TCP connections until it has
fully caught up with your daemon.
2018-03-26 16:48:37 +09:00
.. envvar:: SSL_PORT
2017-01-03 10:24:11 +09:00
2018-03-26 16:48:37 +09:00
If set ElectrumX will serve SSL clients on
:envvar:`HOST`\::envvar:`SSL_PORT`. If set then
:envvar:`SSL_CERTFILE` and :envvar:`SSL_KEYFILE` must be defined
environment variables with values the filesystem paths to those SSL
files.
2017-01-03 10:24:11 +09:00
2018-03-26 16:48:37 +09:00
.. note:: ElectrumX will not serve SSL connections until it has
fully caught up with your daemon.
2018-03-26 16:48:37 +09:00
.. envvar:: RPC_HOST
2017-09-09 21:53:03 +09:00
The host or IP address that the RPC server will listen on and
2018-03-26 16:48:37 +09:00
defaults to ``localhost``. To listen on multiple specific addresses
2017-09-09 21:53:03 +09:00
specify a comma-separated list. Servers with unusual networking
2018-03-26 16:48:37 +09:00
setups might want to specify e.g. ``::1`` or ``127.0.0.1``
explicitly rather than defaulting to ``localhost``.
2017-09-09 21:53:03 +09:00
An empty string (normally indicating all interfaces) is interpreted
2018-03-26 16:48:37 +09:00
as ``localhost``, because allowing access to the server's RPC
interface to arbitrary connections across the internet is not a good
idea.
2017-09-09 21:53:03 +09:00
2018-03-26 16:48:37 +09:00
.. envvar:: RPC_PORT
2017-01-03 10:24:11 +09:00
ElectrumX will listen on this port for local RPC connections.
2017-01-04 08:18:57 +09:00
ElectrumX listens for RPC connections unless this is explicitly set
2018-03-26 16:48:37 +09:00
to blank. The default depends on :envvar:`COIN` and :attr:`NET`
(e.g., 8000 for Bitcoin mainnet) if not set, as indicated in
`lib/coins.py`_.
2017-08-26 13:50:10 +09:00
2018-03-26 16:48:37 +09:00
.. envvar:: DONATION_ADDRESS
2017-01-03 10:24:11 +09:00
The server donation address reported to Electrum clients. Defaults
to empty, which Electrum interprets as meaning there is none.
2018-03-26 16:48:37 +09:00
.. envvar:: BANNER_FILE
2017-01-03 10:24:11 +09:00
2017-01-04 08:18:57 +09:00
The path to a banner file to serve to clients in Electrum's
"Console" tab. Relative file paths must be relative to
2018-03-26 16:48:37 +09:00
:envvar:`DB_DIRECTORY`. The banner file is re-read for each new
client.
2017-01-03 10:24:11 +09:00
You can place several meta-variables in your banner file, which will be
replaced before serving to a client.
2018-03-26 16:48:37 +09:00
+ ``$SERVER_VERSION`` is replaced with the ElectrumX version you are
running, such as ``1.0.10``.
+ ``$SERVER_SUBVERSION`` is replaced with the ElectrumX user agent
string. For example, ``ElectrumX 1.0.10``.
+ ``$DAEMON_VERSION`` is replaced with the daemon's version as a
dot-separated string. For example ``0.12.1``.
+ ``$DAEMON_SUBVERSION`` is replaced with the daemon's user agent
string. For example, ``/BitcoinUnlimited:0.12.1(EB16; AD4)/``.
+ ``$DONATION_ADDRESS`` is replaced with the address from the
:envvar:`DONATION_ADDRESS` environment variable.
2017-01-03 10:24:11 +09:00
2018-03-26 16:48:37 +09:00
See `here <https://github.com/shsmith/electrumx-banner-updater>`_
for a script that updates a banner file periodically with useful
statistics about fees, last block time and height, etc.
2018-03-26 16:48:37 +09:00
.. envvar:: TOR_BANNER_FILE
2017-01-27 08:22:37 +09:00
2018-03-26 16:48:37 +09:00
As for :envvar:`BANNER_FILE` (which is also the default) but shown
to incoming connections believed to be to your Tor hidden service.
2017-01-27 08:22:37 +09:00
2018-03-26 16:48:37 +09:00
.. envvar:: ANON_LOGS
2017-01-03 10:24:11 +09:00
Set to anything non-empty to replace IP addresses in logs with
2018-03-26 16:48:37 +09:00
redacted text like ``xx.xx.xx.xx:xxx``. By default IP addresses
will be written to logs.
2017-01-03 10:24:11 +09:00
2018-03-26 16:48:37 +09:00
.. envvar:: LOG_SESSIONS
2017-01-03 10:24:11 +09:00
The number of seconds between printing session statistics to the
2018-03-26 16:48:37 +09:00
log. The output is identical to the :ref:`sessions` RPC command
except that :envvar:`ANON_LOGS` is honoured. Defaults to 3600. Set
to zero to suppress this logging.
2017-01-03 10:24:11 +09:00
2018-03-26 16:48:37 +09:00
.. envvar:: REORG_LIMIT
2017-09-09 21:53:03 +09:00
The maximum number of blocks to be able to handle in a chain
reorganisation. ElectrumX retains some fairly compact undo
information for this many blocks in levelDB. The default is a
2018-03-26 16:48:37 +09:00
function of :envvar:`COIN` and :attr:`NET`; for Bitcoin mainnet it
is 200.
2017-09-09 21:53:03 +09:00
2018-03-26 16:48:37 +09:00
.. envvar:: EVENT_LOOP_POLICY
2017-09-09 21:53:03 +09:00
The name of an event loop policy to replace the default asyncio
2018-03-26 16:48:37 +09:00
policy, if any. At present only ``uvloop`` is accepted, in which
case you must have installed the `uvloop`_ Python package.
2017-09-09 21:53:03 +09:00
If you are not sure what this means leave it unset.
2017-01-03 10:24:11 +09:00
Resource Usage Limits
2018-03-26 16:48:37 +09:00
=====================
2017-01-03 10:24:11 +09:00
The following environment variables are all optional and help to limit
server resource consumption and prevent simple DoS.
Address subscriptions in ElectrumX are very cheap - they consume about
2017-02-12 08:35:47 +09:00
160 bytes of memory each and are processed efficiently. I feel the
two subscription-related defaults below are low and encourage you to
raise them.
2017-01-03 10:24:11 +09:00
2018-03-26 16:48:37 +09:00
.. envvar:: MAX_SESSIONS
2017-01-03 10:24:11 +09:00
The maximum number of incoming connections. Once reached, TCP and
SSL listening sockets are closed until the session count drops
naturally to 95% of the limit. Defaults to 1,000.
2018-03-26 16:48:37 +09:00
.. envvar:: MAX_SEND
2017-01-03 10:24:11 +09:00
The maximum size of a response message to send over the wire, in
bytes. Defaults to 1,000,000. Values smaller than 350,000 are
taken as 350,000 because standard Electrum protocol header "chunk"
requests are almost that large.
The Electrum protocol has a flaw in that address histories must be
served all at once or not at all, an obvious avenue for abuse.
2018-03-26 16:48:37 +09:00
:envvar:`MAX_SEND` is a stop-gap until the protocol is improved to
admit incremental history requests. Each history entry is
approximately 100 bytes so the default is equivalent to a history
limit of around 10,000 entries, which should be ample for most
legitimate users. If you use a higher default bear in mind one
client can request history for multiple addresses. Also note that
the largest raw transaction you will be able to serve to a client is
just under half of :envvar:`MAX_SEND`, as each raw byte becomes 2
hexadecimal ASCII characters on the wire. Very few transactions on
Bitcoin mainnet are over 500KB in size.
2017-01-03 10:24:11 +09:00
2018-03-26 16:48:37 +09:00
.. envvar:: MAX_SUBS
2017-01-03 10:24:11 +09:00
The maximum number of address subscriptions across all sessions.
Defaults to 250,000.
2018-03-26 16:48:37 +09:00
.. envvar:: MAX_SESSION_SUBS
2017-01-03 10:24:11 +09:00
The maximum number of address subscriptions permitted to a single
session. Defaults to 50,000.
2018-03-26 16:48:37 +09:00
.. envvar:: BANDWIDTH_LIMIT
2017-01-03 10:24:11 +09:00
2017-10-03 15:45:28 +02:00
Per-session periodic bandwidth usage limit in bytes. This is a soft,
2017-01-03 10:24:11 +09:00
not hard, limit. Currently the period is hard-coded to be one hour.
The default limit value is 2 million bytes.
Bandwidth usage over each period is totalled, and when this limit is
exceeded each subsequent request is stalled by sleeping before
handling it, effectively giving higher processing priority to other
2017-02-12 08:35:47 +09:00
sessions.
2017-01-03 10:24:11 +09:00
The more bandwidth usage exceeds this soft limit the longer the next
request will sleep. Sleep times are a round number of seconds with
2017-02-12 08:35:47 +09:00
a minimum of 1. Each time the delay changes the event is logged.
2017-01-03 10:24:11 +09:00
Bandwidth usage is gradually reduced over time by "refunding" a
proportional part of the limit every now and then.
2018-03-26 16:48:37 +09:00
.. envvar:: SESSION_TIMEOUT
2017-01-03 10:24:11 +09:00
An integer number of seconds defaulting to 600. Sessions with no
activity for longer than this are disconnected. Properly
functioning Electrum clients by default will send pings roughly
2017-02-12 08:35:47 +09:00
every 60 seconds.
2017-01-03 10:24:11 +09:00
2017-04-01 11:59:54 +09:00
2017-02-19 19:42:26 +09:00
Peer Discovery
2018-03-26 16:48:37 +09:00
==============
2017-01-27 08:22:37 +09:00
2018-03-26 16:48:37 +09:00
In response to the :func:`server.peers.subscribe` RPC call, ElectrumX
will only return peer servers that it has recently connected to and
2017-01-27 08:22:37 +09:00
verified basic functionality.
If you are not running a Tor proxy ElectrumX will be unable to connect
to onion server peers, in which case rather than returning no onion
peers it will fall back to a hard-coded list.
To give incoming clients a full range of onion servers you will need
to be running a Tor proxy for ElectrumX to use.
2017-02-19 14:50:13 +09:00
ElectrumX will perform peer-discovery by default and announce itself
to other peers. If your server is private you may wish to disable
some of this.
2018-03-26 16:48:37 +09:00
.. envvar:: PEER_DISCOVERY
2017-02-19 14:50:13 +09:00
2018-03-26 16:48:37 +09:00
This environment variable is case-insensitive and defaults to
``on``.
2017-10-11 13:45:37 +09:00
2018-03-26 16:48:37 +09:00
If ``on``, ElectrumX will occasionally connect to and verify its
2017-10-11 13:45:37 +09:00
network of peer servers.
2018-03-26 16:48:37 +09:00
If ``off``, peer discovery is disabled and a hard-coded default list
of servers will be read in and served. If set to ``self`` then peer
2017-10-11 13:45:37 +09:00
discovery is disabled and the server will only return itself in the
peers list.
2017-02-19 14:50:13 +09:00
2018-03-26 16:48:37 +09:00
.. envvar:: PEER_ANNOUNCE
2017-02-19 14:50:13 +09:00
2017-03-05 12:59:01 +09:00
Set this environment variable to empty to disable announcing itself.
2017-02-19 14:50:13 +09:00
If not defined, or non-empty, ElectrumX will announce itself to
peers.
If peer discovery is disabled this environment variable has no
effect, because ElectrumX only announces itself to peers when doing
peer discovery if it notices it is not present in the peer's
returned list.
2018-03-26 16:48:37 +09:00
.. envvar:: FORCE_PROXY
2017-04-02 14:59:45 +09:00
By default peer discovery happens over the clear internet. Set this
to non-empty to force peer discovery to be done via the proxy. This
might be useful if you are running a Tor service exclusively and
2017-11-27 15:05:42 +09:00
wish to keep your IP address private.
2017-04-02 14:59:45 +09:00
2018-03-26 16:48:37 +09:00
.. envvar:: TOR_PROXY_HOST
2017-01-27 08:22:37 +09:00
2018-03-26 16:48:37 +09:00
The host where your Tor proxy is running. Defaults to
``localhost``.
2017-01-27 08:22:37 +09:00
2017-02-19 14:50:13 +09:00
If you are not running a Tor proxy just leave this environment
variable undefined.
2018-03-26 16:48:37 +09:00
.. envvar:: TOR_PROXY_PORT
2017-01-27 08:22:37 +09:00
The port on which the Tor proxy is running. If not set, ElectrumX
will autodetect any proxy running on the usual ports 9050 (Tor),
9150 (Tor browser bundle) and 1080 (socks).
2017-04-01 11:59:54 +09:00
Server Advertising
2018-03-26 16:48:37 +09:00
==================
2017-04-01 11:59:54 +09:00
2017-11-27 15:05:42 +09:00
These environment variables affect how your server is advertised
by peer discovery (if enabled).
2017-04-01 11:59:54 +09:00
2018-03-26 16:48:37 +09:00
.. envvar:: REPORT_HOST
2017-04-01 11:59:54 +09:00
The clearnet host to advertise. If not set, no clearnet host is
advertised.
2018-03-26 16:48:37 +09:00
.. envvar:: REPORT_TCP_PORT
2017-04-01 11:59:54 +09:00
2018-03-26 16:48:37 +09:00
The clearnet TCP port to advertise if :envvar:`REPORT_HOST` is set.
Defaults to :envvar:`TCP_PORT`. ``0`` disables publishing a TCP
port.
2017-04-01 11:59:54 +09:00
2018-03-26 16:48:37 +09:00
.. envvar:: REPORT_SSL_PORT
2017-04-01 11:59:54 +09:00
2018-03-26 16:48:37 +09:00
The clearnet SSL port to advertise if :envvar:`REPORT_HOST` is set.
Defaults to :envvar:`SSL_PORT`. ``0`` disables publishing an SSL
port.
2017-04-01 11:59:54 +09:00
2018-03-26 16:48:37 +09:00
.. envvar:: REPORT_HOST_TOR
2017-04-01 11:59:54 +09:00
If you wish run a Tor service, this is the Tor host name to
2018-03-26 16:48:37 +09:00
advertise and must end with ``.onion``.
2017-04-01 11:59:54 +09:00
2018-03-26 16:48:37 +09:00
.. envvar:: REPORT_TCP_PORT_TOR
2017-04-01 11:59:54 +09:00
The Tor TCP port to advertise. The default is the clearnet
2018-03-26 16:48:37 +09:00
:envvar:`REPORT_TCP_PORT`, unless disabled or it is ``0``, otherwise
:envvar:`TCP_PORT`. ``0`` disables publishing a Tor TCP port.
2017-04-01 11:59:54 +09:00
2018-03-26 16:48:37 +09:00
.. envvar:: REPORT_SSL_PORT_TOR
2017-04-01 11:59:54 +09:00
The Tor SSL port to advertise. The default is the clearnet
2018-03-26 16:48:37 +09:00
:envvar:`REPORT_SSL_PORT`, unless disabled or it is ``0``, otherwise
:envvar:`SSL_PORT`. ``0`` disables publishing a Tor SSL port.
2017-04-01 11:59:54 +09:00
2018-03-26 16:48:37 +09:00
.. note:: Certificate-Authority signed certificates don't work over
Tor, so you should set :envvar:`REPORT_SSL_PORT_TOR` to
``0`` if yours is not self-signed.
2017-04-01 11:59:54 +09:00
2017-01-03 10:24:11 +09:00
Cache
2018-03-26 16:48:37 +09:00
=====
2017-01-03 10:24:11 +09:00
If synchronizing from the Genesis block your performance might change
2017-01-05 22:43:57 +09:00
by tweaking the cache size. Cache size is only checked roughly every
minute, so the cache can grow beyond the specified size. Moreover,
the Python process is often quite a bit fatter than the cache size,
because of Python overhead and also because leveldb consumes a lot of
memory when flushing. So I recommend you do not set this over 60% of
your available physical RAM:
2017-01-03 10:24:11 +09:00
2018-03-16 09:59:27 +08:00
.. _CACHE:
2018-03-26 16:48:37 +09:00
.. envvar:: CACHE_MB
2017-01-03 10:24:11 +09:00
2017-01-05 22:43:57 +09:00
The amount of cache, in MB, to use. The default is 1,200.
2017-01-03 10:24:11 +09:00
2017-01-05 22:43:57 +09:00
A portion of the cache is reserved for unflushed history, which is
written out frequently. The bulk is used to cache UTXOs.
2017-01-03 10:24:11 +09:00
2017-01-05 22:43:57 +09:00
Larger caches probably increase performance a little as there is
significant searching of the UTXO cache during indexing. However, I
don't see much benefit in my tests pushing this too high, and in
fact performance begins to fall, probably because LevelDB already
caches, and also because of Python GC.
2017-01-03 10:24:11 +09:00
2018-03-26 16:48:37 +09:00
I do not recommend raising this above 2000.
2017-01-03 10:24:11 +09:00
2018-03-26 16:48:37 +09:00
.. _lib/coins.py:
https://github.com/kyuupichan/electrumx/blob/master/lib/coins.py
2017-08-26 13:50:10 +09:00
.. _uvloop: https://pypi.python.org/pypi/uvloop