lukechilds / docker-electrumx

Run an Electrum server with one command
MIT License
109 stars 124 forks source link

standard_init_linux.go:211: exec user process caused "exec format error" #55

Closed OvoNemaSmisla closed 4 years ago

OvoNemaSmisla commented 4 years ago

Hi,

I'm running the following docker version:

Client: Docker Engine - Community
 Version:           19.03.8
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        afacb8b
 Built:             Wed Mar 11 01:26:27 2020
 OS/Arch:           linux/arm64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.8
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.17
  Git commit:       afacb8b
  Built:            Wed Mar 11 01:24:59 2020
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

The docker is running on Odroid N2 with Ubuntu 18.04.3, kernel 4.9.219-72 and aarch64 architecture. uname -m: aarch64 dpkg --print-architecture: arm64

When I try to run the container with: docker run --net=host -v ~/electrumx:/data -e DAEMON_URL="electrumx:whatever@127.0.0.1:8332" -e COIN=BitcoinSegwit -e NET=mainnet -e RPC_HOST=127.0.0.1 -e RPC_PORT=8332 -p 50002:50002 lukechilds/electrumx

I receive the following error: standard_init_linux.go:211: exec user process caused "exec format error"

lukechilds commented 4 years ago

The images on Docker Hub are currently only built for amd64 arch, so no ARM support atm.

When I get the time I'm planning to rewrite the image to be based on Debian Slim as opposed to Alpine and setup multi-arch builds for arm32v7/arm64v8/amd64.

In the meantime you can try building the image locally yourself. Just clone the repo, cd into it and run docker build -t electrumx ..

Then use electrumx instead of lukechilds/electrumx in your docker run command. I haven't tested building on ARM yet so not sure if it will work or as is or if it'll require changes.

If you try it let me know how you get on.

OvoNemaSmisla commented 4 years ago

Thanks Luke,

I've followed your instructions and here is the output of the build command:

Sending build context to Docker daemon  95.23kB
Step 1/16 : FROM python:3.7-alpine3.11
3.7-alpine3.11: Pulling from library/python
29e5d40040c1: Pull complete 
9532fd93bc56: Pull complete 
fb5af5741d69: Pull complete 
ebd3665896c4: Pull complete 
1ebec2e3d085: Pull complete 
Digest: sha256:8acbf2568aaf64337a9ef2d4f15e0813566957b93fa6954c165335d1a54ca617
Status: Downloaded newer image for python:3.7-alpine3.11
 ---> 79159c2d0ff4
Step 2/16 : LABEL maintainer="Luke Childs <lukechilds123@gmail.com>"
 ---> Running in 572368ead2f7
Removing intermediate container 572368ead2f7
 ---> 6ef64feedba1
Step 3/16 : COPY ./bin /usr/local/bin
 ---> 1f68a9f7722e
Step 4/16 : COPY ./VERSION /tmp
 ---> 432f8929a173
Step 5/16 : RUN VERSION=$(cat /tmp/VERSION) &&     chmod a+x /usr/local/bin/* &&     apk add --no-cache git build-base openssl &&     apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.11/main leveldb-dev &&     apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing rocksdb-dev &&     pip install aiohttp pylru plyvel websockets python-rocksdb &&     git clone -b $VERSION https://github.com/kyuupichan/electrumx.git &&     cd electrumx &&     python setup.py install &&     apk del git build-base &&     rm -rf /tmp/*
 ---> Running in 0aff14b2d03c
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/aarch64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/aarch64/APKINDEX.tar.gz
(1/23) Installing libgcc (9.2.0-r4)
(2/23) Installing libstdc++ (9.2.0-r4)
(3/23) Installing binutils (2.33.1-r0)
(4/23) Installing libmagic (5.37-r1)
(5/23) Installing file (5.37-r1)
(6/23) Installing gmp (6.1.2-r1)
(7/23) Installing isl (0.18-r0)
(8/23) Installing libgomp (9.2.0-r4)
(9/23) Installing libatomic (9.2.0-r4)
(10/23) Installing mpfr4 (4.0.2-r1)
(11/23) Installing mpc1 (1.1.0-r1)
(12/23) Installing gcc (9.2.0-r4)
(13/23) Installing musl-dev (1.1.24-r2)
(14/23) Installing libc-dev (0.7.2-r0)
(15/23) Installing g++ (9.2.0-r4)
(16/23) Installing make (4.2.1-r2)
(17/23) Installing fortify-headers (1.1-r0)
(18/23) Installing build-base (0.5-r1)
(19/23) Installing nghttp2-libs (1.40.0-r0)
(20/23) Installing libcurl (7.67.0-r0)
(21/23) Installing pcre2 (10.34-r1)
(22/23) Installing git (2.24.3-r0)
(23/23) Installing openssl (1.1.1g-r0)
Executing busybox-1.31.1-r9.trigger
OK: 188 MiB in 57 packages
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/aarch64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/aarch64/APKINDEX.tar.gz
(1/3) Installing snappy (1.1.7-r1)
(2/3) Installing leveldb (1.22-r0)
(3/3) Installing leveldb-dev (1.22-r0)
OK: 189 MiB in 60 packages
fetch http://dl-cdn.alpinelinux.org/alpine/edge/testing/aarch64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/aarch64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/aarch64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
  rocksdb-dev (missing):
    required by: world[rocksdb-dev]
The command '/bin/sh -c VERSION=$(cat /tmp/VERSION) &&     chmod a+x /usr/local/bin/* &&     apk add --no-cache git build-base openssl &&     apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.11/main leveldb-dev &&     apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing rocksdb-dev &&     pip install aiohttp pylru plyvel websockets python-rocksdb &&     git clone -b $VERSION https://github.com/kyuupichan/electrumx.git &&     cd electrumx &&     python setup.py install &&     apk del git build-base &&     rm -rf /tmp/*' returned a non-zero code: 1

Any suggestion how to resolve the error?

lukechilds commented 4 years ago

Looks like the Alpine rocksdb-dev package either doesn't exist or exists under a different location for ARM.

You can probably just comment out that line in the Dockerfile.

We install both RocksDB and LevelDB in the image but only one of them is used at runtime. It defaults to LevelDB unless specified to RocksDB so should just work with RocksDB removed.

OvoNemaSmisla commented 4 years ago

I've commented out the 11th line in the Dockerfile:

FROM python:3.7-alpine3.11
LABEL maintainer="Luke Childs <lukechilds123@gmail.com>"

COPY ./bin /usr/local/bin
COPY ./VERSION /tmp

RUN VERSION=$(cat /tmp/VERSION) && \
    chmod a+x /usr/local/bin/* && \
    apk add --no-cache git build-base openssl && \
    apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.11/main leveldb-dev && \
    --apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing rocksdb-dev && \
    pip install aiohttp pylru plyvel websockets python-rocksdb && \
    git clone -b $VERSION https://github.com/kyuupichan/electrumx.git && \
    cd electrumx && \
    python setup.py install && \
    apk del git build-base && \
    rm -rf /tmp/*

VOLUME ["/data"]
ENV HOME /data
ENV ALLOW_ROOT 1
ENV DB_DIRECTORY /data
ENV SERVICES=tcp://:50001,ssl://:50002,wss://:50004,rpc://0.0.0.0:8000
ENV SSL_CERTFILE ${DB_DIRECTORY}/electrumx.crt
ENV SSL_KEYFILE ${DB_DIRECTORY}/electrumx.key
ENV HOST ""
WORKDIR /data

EXPOSE 50001 50002 50004 8000

CMD ["init"]

This resolved the error, but now I have another one:

Sending build context to Docker daemon  95.23kB
Step 1/16 : FROM python:3.7-alpine3.11
 ---> 79159c2d0ff4
Step 2/16 : LABEL maintainer="Luke Childs <lukechilds123@gmail.com>"
 ---> Using cache
 ---> 6ef64feedba1
Step 3/16 : COPY ./bin /usr/local/bin
 ---> Using cache
 ---> 1f68a9f7722e
Step 4/16 : COPY ./VERSION /tmp
 ---> Using cache
 ---> 432f8929a173
Step 5/16 : RUN VERSION=$(cat /tmp/VERSION) &&     chmod a+x /usr/local/bin/* &&     apk add --no-cache git build-base openssl &&     apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.11/main leveldb-dev &&     --apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing rocksdb-dev &&     pip install aiohttp pylru plyvel websockets python-rocksdb &&     git clone -b $VERSION https://github.com/kyuupichan/electrumx.git &&     cd electrumx &&     python setup.py install &&     apk del git build-base &&     rm -rf /tmp/*
 ---> Running in 612bca85a790
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/aarch64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/aarch64/APKINDEX.tar.gz
(1/23) Installing libgcc (9.2.0-r4)
(2/23) Installing libstdc++ (9.2.0-r4)
(3/23) Installing binutils (2.33.1-r0)
(4/23) Installing libmagic (5.37-r1)
(5/23) Installing file (5.37-r1)
(6/23) Installing gmp (6.1.2-r1)
(7/23) Installing isl (0.18-r0)
(8/23) Installing libgomp (9.2.0-r4)
(9/23) Installing libatomic (9.2.0-r4)
(10/23) Installing mpfr4 (4.0.2-r1)
(11/23) Installing mpc1 (1.1.0-r1)
(12/23) Installing gcc (9.2.0-r4)
(13/23) Installing musl-dev (1.1.24-r2)
(14/23) Installing libc-dev (0.7.2-r0)
(15/23) Installing g++ (9.2.0-r4)
(16/23) Installing make (4.2.1-r2)
(17/23) Installing fortify-headers (1.1-r0)
(18/23) Installing build-base (0.5-r1)
(19/23) Installing nghttp2-libs (1.40.0-r0)
(20/23) Installing libcurl (7.67.0-r0)
(21/23) Installing pcre2 (10.34-r1)
(22/23) Installing git (2.24.3-r0)
(23/23) Installing openssl (1.1.1g-r0)
Executing busybox-1.31.1-r9.trigger
OK: 188 MiB in 57 packages
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/aarch64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/aarch64/APKINDEX.tar.gz
(1/3) Installing snappy (1.1.7-r1)
(2/3) Installing leveldb (1.22-r0)
(3/3) Installing leveldb-dev (1.22-r0)
OK: 189 MiB in 60 packages
/bin/sh: --apk: not found
The command '/bin/sh -c VERSION=$(cat /tmp/VERSION) &&     chmod a+x /usr/local/bin/* &&     apk add --no-cache git build-base openssl &&     apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.11/main leveldb-dev &&     --apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing rocksdb-dev &&     pip install aiohttp pylru plyvel websockets python-rocksdb &&     git clone -b $VERSION https://github.com/kyuupichan/electrumx.git &&     cd electrumx &&     python setup.py install &&     apk del git build-base &&     rm -rf /tmp/*' returned a non-zero code: 127

It looks like it has a problem with: --apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing rocksdb-dev && pip install aiohttp pylru plyvel websockets python-rocksdb

lukechilds commented 4 years ago

You haven't commented out the line you've just added two dashes at the beginning. It's failing because the dashes mean --apk is an invalid command.

And sorry, I said comment out but should've said remove it. Just delete the entire line:

apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing rocksdb-dev
OvoNemaSmisla commented 4 years ago

I deleted the 11th and 12th line and managed to finish the build. Here is the output, it contains a few warnings.

I've tried to run the server with: docker run --net=host -v ~/electrumx:/data -e DAEMON_URL="electrumx:whatever@127.0.0.1:8332" -e COIN=BitcoinSegwit -e NET=mainnet -e RPC_HOST=127.0.0.1 -e RPC_PORT=8332 -p 50002:50002 electrumx

But it gave the following error: -bash: !h6l2Sx: event not found

lukechilds commented 4 years ago

The 12th line is needed, it installs all the python dependencies with: pip install aiohttp pylru plyvel websockets python-rocksdb

You can remove python-rocksdb if you wan't though since you won't be using it that.

OvoNemaSmisla commented 4 years ago

Ok, let me try again.

OvoNemaSmisla commented 4 years ago

Here is the docker file after the suggested modifications:

FROM python:3.7-alpine3.11
LABEL maintainer="Luke Childs <lukechilds123@gmail.com>"

COPY ./bin /usr/local/bin
COPY ./VERSION /tmp

RUN VERSION=$(cat /tmp/VERSION) && \
    chmod a+x /usr/local/bin/* && \
    apk add --no-cache git build-base openssl && \
    apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.11/main leveldb-dev && \
    pip install aiohttp pylru plyvel websockets \
    git clone -b $VERSION https://github.com/kyuupichan/electrumx.git && \
    cd electrumx && \
    python setup.py install && \
    apk del git build-base && \
    rm -rf /tmp/*

VOLUME ["/data"]
ENV HOME /data
ENV ALLOW_ROOT 1
ENV DB_DIRECTORY /data
ENV SERVICES=tcp://:50001,ssl://:50002,wss://:50004,rpc://0.0.0.0:8000
ENV SSL_CERTFILE ${DB_DIRECTORY}/electrumx.crt
ENV SSL_KEYFILE ${DB_DIRECTORY}/electrumx.key
ENV HOST ""
WORKDIR /data

EXPOSE 50001 50002 50004 8000

CMD ["init"]

Here is the output of the build:

Sending build context to Docker daemon  96.77kB
Step 1/16 : FROM python:3.7-alpine3.11
 ---> 79159c2d0ff4
Step 2/16 : LABEL maintainer="Luke Childs <lukechilds123@gmail.com>"
 ---> Using cache
 ---> 6ef64feedba1
Step 3/16 : COPY ./bin /usr/local/bin
 ---> Using cache
 ---> 1f68a9f7722e
Step 4/16 : COPY ./VERSION /tmp
 ---> Using cache
 ---> 432f8929a173
Step 5/16 : RUN VERSION=$(cat /tmp/VERSION) &&     chmod a+x /usr/local/bin/* &&     apk add --no-cache git build-base openssl &&     apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.11/main leveldb-dev &&     pip install aiohttp pylru plyvel websockets     git clone -b $VERSION https://github.com/kyuupichan/electrumx.git &&     cd electrumx &&     python setup.py install &&     apk del git build-base &&     rm -rf /tmp/*
 ---> Running in 4824ba168841
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/aarch64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/aarch64/APKINDEX.tar.gz
(1/23) Installing libgcc (9.2.0-r4)
(2/23) Installing libstdc++ (9.2.0-r4)
(3/23) Installing binutils (2.33.1-r0)
(4/23) Installing libmagic (5.37-r1)
(5/23) Installing file (5.37-r1)
(6/23) Installing gmp (6.1.2-r1)
(7/23) Installing isl (0.18-r0)
(8/23) Installing libgomp (9.2.0-r4)
(9/23) Installing libatomic (9.2.0-r4)
(10/23) Installing mpfr4 (4.0.2-r1)
(11/23) Installing mpc1 (1.1.0-r1)
(12/23) Installing gcc (9.2.0-r4)
(13/23) Installing musl-dev (1.1.24-r2)
(14/23) Installing libc-dev (0.7.2-r0)
(15/23) Installing g++ (9.2.0-r4)
(16/23) Installing make (4.2.1-r2)
(17/23) Installing fortify-headers (1.1-r0)
(18/23) Installing build-base (0.5-r1)
(19/23) Installing nghttp2-libs (1.40.0-r0)
(20/23) Installing libcurl (7.67.0-r0)
(21/23) Installing pcre2 (10.34-r1)
(22/23) Installing git (2.24.3-r0)
(23/23) Installing openssl (1.1.1g-r0)
Executing busybox-1.31.1-r9.trigger
OK: 188 MiB in 57 packages
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/aarch64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/aarch64/APKINDEX.tar.gz
(1/3) Installing snappy (1.1.7-r1)
(2/3) Installing leveldb (1.22-r0)
(3/3) Installing leveldb-dev (1.22-r0)
OK: 189 MiB in 60 packages
Collecting https://github.com/kyuupichan/electrumx.git
  Downloading https://github.com/kyuupichan/electrumx.git
  ERROR: Cannot unpack file /tmp/pip-unpack-0y3mmrg8/electrumx.git (downloaded from /tmp/pip-req-build-0lcj1jgm, content-type: text/html; charset=utf-8); cannot detect archive format
ERROR: Cannot determine archive format of /tmp/pip-req-build-0lcj1jgm
The command '/bin/sh -c VERSION=$(cat /tmp/VERSION) &&     chmod a+x /usr/local/bin/* &&     apk add --no-cache git build-base openssl &&     apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.11/main leveldb-dev &&     pip install aiohttp pylru plyvel websockets     git clone -b $VERSION https://github.com/kyuupichan/electrumx.git &&     cd electrumx &&     python setup.py install &&     apk del git build-base &&     rm -rf /tmp/*' returned a non-zero code: 1

I'm afraid I messed something up with previous attempts. Is there a way to "clean" this up and start from scratch?

lukechilds commented 4 years ago

You missed && of the pip install line.

pip install aiohttp pylru plyvel websockets \

should be:

pip install aiohttp pylru plyvel websockets && \

Complete Dockerfile with RocksDB removed:

FROM python:3.7-alpine3.11
LABEL maintainer="Luke Childs <lukechilds123@gmail.com>"

COPY ./bin /usr/local/bin
COPY ./VERSION /tmp

RUN VERSION=$(cat /tmp/VERSION) && \
    chmod a+x /usr/local/bin/* && \
    apk add --no-cache git build-base openssl && \
    apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.11/main leveldb-dev && \
    pip install aiohttp pylru plyvel websockets && \
    git clone -b $VERSION https://github.com/kyuupichan/electrumx.git && \
    cd electrumx && \
    python setup.py install && \
    apk del git build-base && \
    rm -rf /tmp/*

VOLUME ["/data"]
ENV HOME /data
ENV ALLOW_ROOT 1
ENV DB_DIRECTORY /data
ENV SERVICES=tcp://:50001,ssl://:50002,wss://:50004,rpc://0.0.0.0:8000
ENV SSL_CERTFILE ${DB_DIRECTORY}/electrumx.crt
ENV SSL_KEYFILE ${DB_DIRECTORY}/electrumx.key
ENV HOST ""
WORKDIR /data

EXPOSE 50001 50002 50004 8000

CMD ["init"]
OvoNemaSmisla commented 4 years ago

This time, the build was successful, no errors, only 2 warrnings:

Using /usr/local/lib/python3.7/site-packages
Finished processing dependencies for electrumX==1.14.0
WARNING: Ignoring APKINDEX.70f61090.tar.gz: No such file or directory
WARNING: Ignoring APKINDEX.ca2fea5b.tar.gz: No such file or directory

After running the server with: docker run --net=host -v ~/electrumx:/data -e DAEMON_URL="electrumx:whatever@127.0.0.1:8332" -e COIN=BitcoinSegwit -e NET=mainnet -e RPC_HOST=127.0.0.1 -e RPC_PORT=8332 -p 50002:50002 electrumx I get the following error: -bash: !h6l2Sx: event not found

lukechilds commented 4 years ago

Strange, I just tried this on a Pi 4 and it's working fine for me:

pi@pinode:~/docker-electrumx $ docker run -e DAEMON_URL=user:pass@127.0.0.1:8332 -e COIN=BitcoinSegwit electrumx
Generating a RSA private key
.............+++++
.....................+++++
writing new private key to '/data/electrumx.key'
-----
INFO:electrumx:ElectrumX server starting
INFO:electrumx:logging level: INFO
INFO:Controller:Python version: 3.7.7 (default, Apr 24 2020, 04:46:25)  [GCC 9.2.0]
INFO:Controller:software version: ElectrumX 1.14.0
INFO:Controller:aiorpcX version: 0.18.4
INFO:Controller:supported protocol versions: 1.4-1.4.2
INFO:Controller:event loop policy: None
INFO:Controller:reorg limit is 200 blocks
INFO:Daemon:daemon #1 at 127.0.0.1:8332/ (current)
INFO:DB:switching current directory to /data
INFO:DB:using leveldb for DB backend
ERROR:Daemon:connection problem - check your daemon is running.  Retrying occasionally...
^CWARNING:Controller:received SIGINT signal, initiating shutdown
INFO:Controller:shutting down
INFO:Controller:shutdown complete
INFO:electrumx:ElectrumX server terminated normally

I'm using tip of master and pasting in these changes: https://github.com/lukechilds/docker-electrumx/issues/55#issuecomment-622359811

What output do you see if you paste exactly this:

docker run -e DAEMON_URL=user:pass@127.0.0.1:8332 -e COIN=BitcoinSegwit electrumx
lukechilds commented 4 years ago

Also try running:

docker run -it --entrypoint sh electrumx

Does that give you an interactive shell?

OvoNemaSmisla commented 4 years ago

What output do you see if you paste exactly this:

docker run -e DAEMON_URL=user:pass@127.0.0.1:8332 -e COIN=BitcoinSegwit electrumx

No error and here is the output:

Generating a RSA private key
.............+++++
...+++++
writing new private key to '/data/electrumx.key'
-----
INFO:electrumx:ElectrumX server starting
INFO:electrumx:logging level: INFO
INFO:Controller:Python version: 3.7.7 (default, Apr 24 2020, 07:34:54)  [GCC 9.2.0]
INFO:Controller:software version: ElectrumX 1.14.0
INFO:Controller:aiorpcX version: 0.18.4
INFO:Controller:supported protocol versions: 1.4-1.4.2
INFO:Controller:event loop policy: None
INFO:Controller:reorg limit is 200 blocks
INFO:Daemon:daemon #1 at 127.0.0.1:8332/ (current)
INFO:DB:switching current directory to /data
INFO:DB:using leveldb for DB backend
ERROR:Daemon:connection problem - check your daemon is running.  Retrying occasionally...
^CWARNING:Controller:received SIGINT signal, initiating shutdown
INFO:Controller:shutting down
INFO:Controller:shutdown complete
INFO:electrumx:ElectrumX server terminated normally
OvoNemaSmisla commented 4 years ago

Also try running:

docker run -it --entrypoint sh electrumx

Does that give you an interactive shell?

It seems that I do get the shell:

user@odroid:~/docker-electrumx$ docker run -it --entrypoint sh electrumx
/data # exit
user@odroid:~/docker-electrumx$
lukechilds commented 4 years ago

That looks like everything is working normally.

Maybe there was a mistake in your original command.

Just noticed it was a bash error: -bash: !h6l2Sx: event not found. AFAIK Alpine doesn't even have bash, so this was most probably an error on your host machine, it wasn't even running Docker.

Just start with docker run -e DAEMON_URL=user:pass@127.0.0.1:8332 -e COIN=BitcoinSegwit electrumx and gradually change/add the extra params you need to connect to your node one by one.

Then see when/if it fails and it should be obvious what you're doing wrong.

OvoNemaSmisla commented 4 years ago

I'm such an idiot!

I just noticed that !h6l2Sx is a part of the password and it was causing the bash error /facepalm

I'm running a full bitcoin nod that I'm trying to connect electrumx. Here is the bitcoin.conf:

txindex=1
onlynet=onion
server=1
rpcport=8332
rpchost=127.0.0.1
rpcpassword=pass
rpcuser=electrumx

Now, when I run docker run -e DAEMON_URL=electrumx:pass@127.0.0.1:8332 -e COIN=BitcoinSegwit electrumx, I get the following:

Generating a RSA private key
............................................+++++
.................................................................+++++
writing new private key to '/data/electrumx.key'
-----
INFO:electrumx:ElectrumX server starting
INFO:electrumx:logging level: INFO
INFO:Controller:Python version: 3.7.7 (default, Apr 24 2020, 07:34:54)  [GCC 9.2.0]
INFO:Controller:software version: ElectrumX 1.14.0
INFO:Controller:aiorpcX version: 0.18.4
INFO:Controller:supported protocol versions: 1.4-1.4.2
INFO:Controller:event loop policy: None
INFO:Controller:reorg limit is 200 blocks
INFO:Daemon:daemon #1 at 127.0.0.1:8332/ (current)
INFO:DB:switching current directory to /data
INFO:DB:using leveldb for DB backend
ERROR:Daemon:connection problem - check your daemon is running.  Retrying occasionally...
ERROR:Daemon:connection problem - check your daemon is running.  Retrying occasionally...
ERROR:Daemon:connection problem - check your daemon is running.  Retrying occasionally...
ERROR:Daemon:connection problem - check your daemon is running.  Retrying occasionally...
lukechilds commented 4 years ago

127.0.0.1 is the loopback address of the Docker container, not your host machine. You can add --network host to your docker run command to tell it to use the hosts network so it can talk to bitcoind.

So the full command would be:

docker run --network host -e DAEMON_URL=electrumx:pass@127.0.0.1:8332 -e COIN=BitcoinSegwit electrumx
OvoNemaSmisla commented 4 years ago

Success finally!

Additional problem was deprecated syntax. RPC_PORT and RPC_HOST needed to be changed to rpcport and rpchost.

At the end, the correct command is: docker run --net=host -e DAEMON_URL="electrumx:pass@127.0.0.1:8332" -e COIN=BitcoinSegwit -e NET=mainnet -e rpchost=127.0.0.1 -e rpcport=8332 electrumx

with the output:

Generating a RSA private key
...................................................................................+++++
.....................................................+++++
writing new private key to '/data/electrumx.key'
-----
INFO:electrumx:ElectrumX server starting
INFO:electrumx:logging level: INFO
INFO:Controller:Python version: 3.7.7 (default, Apr 24 2020, 07:34:54)  [GCC 9.2.0]
INFO:Controller:software version: ElectrumX 1.14.0
INFO:Controller:aiorpcX version: 0.18.4
INFO:Controller:supported protocol versions: 1.4-1.4.2
INFO:Controller:event loop policy: None
INFO:Controller:reorg limit is 200 blocks
INFO:Daemon:daemon #1 at 127.0.0.1:8332/ (current)
INFO:DB:switching current directory to /data
INFO:DB:using leveldb for DB backend
INFO:DB:created new database
INFO:DB:creating metadata directory
INFO:DB:DB version: 7
INFO:DB:coin: BitcoinSegwit
INFO:DB:network: mainnet
INFO:DB:height: -1
INFO:DB:tip: 0000000000000000000000000000000000000000000000000000000000000000
INFO:DB:tx count: 0
INFO:DB:flushing DB cache at 1,200 MB
INFO:DB:sync time so far: 00s
INFO:History:history DB version: 0
INFO:History:flush count: 0
INFO:SessionManager:RPC server listening on 0.0.0.0:8000
INFO:Prefetcher:catching up to daemon height 628,428 (628,429 blocks behind)
INFO:Prefetcher:verified genesis block with hash 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
INFO:BlockProcessor:our height: 9 daemon: 628,428 UTXOs 0MB hist 0MB
INFO:BlockProcessor:our height: 4,009 daemon: 628,428 UTXOs 0MB hist 1MB
INFO:BlockProcessor:our height: 8,009 daemon: 628,428 UTXOs 1MB hist 2MB
INFO:BlockProcessor:our height: 10,009 daemon: 628,428 UTXOs 1MB hist 2MB
INFO:BlockProcessor:our height: 14,009 daemon: 628,428 UTXOs 2MB hist 3MB
INFO:BlockProcessor:our height: 18,009 daemon: 628,428 UTXOs 3MB hist 4MB
INFO:BlockProcessor:our height: 19,009 daemon: 628,428 UTXOs 3MB hist 4MB
INFO:BlockProcessor:our height: 22,009 daemon: 628,428 UTXOs 4MB hist 5MB
INFO:BlockProcessor:our height: 24,009 daemon: 628,428 UTXOs 4MB hist 6MB

Odroid that runs all of this is headless, so I'm not sure if I can disconnect from the terminal while ElectrumX server is still syncing.

Also, how can I enable ElectrumX server to start at boot (after bitcoind)? I guess there is a way to set this up in Docker?

lukechilds commented 4 years ago

Additional problem was deprecated syntax. RPC_PORT and RPC_HOST needed to be changed to rpcport and rpchost.

Are you sure? I don't think rpcport/rpchost are valid otions. Have you tried removing them? You're probably just using the defaults and those settings are getting ignored.

Documentation for ElectrumX supported environment variables is here:

https://github.com/kyuupichan/electrumx/blob/master/docs/environment.rst

Odroid that runs all of this is headless, so I'm not sure if I can disconnect from the terminal while ElectrumX server is still syncing.

Add --detach to your docker run command and it'll run it in the background. You can log out of SSH, close your terminal session etc. It'll keep running.

Also, how can I enable ElectrumX server to start at boot (after bitcoind)? I guess there is a way to set this up in Docker?

Add --restart always to your docker run command.

You can read all the documentation for the docker run command here:

https://docs.docker.com/engine/reference/commandline/run/

Both --detach and --restart are documented there.

OvoNemaSmisla commented 4 years ago

Additional problem was deprecated syntax. RPC_PORT and RPC_HOST needed to be changed to rpcport and rpchost.

Are you sure? I don't think rpcport/rpchost are valid otions. Have you tried removing them? You're probably just using the defaults and those settings are getting ignored.

Documentation for ElectrumX supported environment variables is here:

https://github.com/kyuupichan/electrumx/blob/master/docs/environment.rst

Well, when I tried running docker run --net=host -e DAEMON_URL="electrumx:pass@127.0.0.1:8332" -e COIN=BitcoinSegwit -e NET=mainnet -e RPC_HOST=127.0.0.1 -e RPC_PORT=8332 electrumx I got the following:

Generating a RSA private key
............+++++
.+++++
writing new private key to '/data/electrumx.key'
-----
INFO:electrumx:ElectrumX server starting
ERROR:electrumx:ElectrumX server terminated abnormally
Traceback (most recent call last):
File "/electrumx/electrumx_server", line 31, in main
env = Env()
File "/electrumx/electrumx/server/env.py", line 39, in __init__
"REPORT_TCP_PORT_TOR", "REPORT_SSL_PORT_TOR"])
File "/electrumx/electrumx/lib/env_base.py", line 70, in obsolete
.format(bad))
electrumx.lib.env_base.EnvBase.Error: remove obsolete environment variables ['RPC_HOST', 'RPC_PORT']

I switched to rpcport and rpchost because that's in the bitcoin.conf and it worked. Haven't tried without them, but will do so.

Really appreciate your help and advice to make this work. Is there a way I can support you and the project?

lukechilds commented 4 years ago

Yep, RPC_HOST/RPC_PORT are obsolete so it's throwing. But pretty sure rpcport/rpchost do nothing. It's just not throwing an error because it's completely ignoring them.

You don't need to pass them in manually, you're already passing in the RPC details with DAEMON_URL="electrumx:pass@127.0.0.1:8332".

Really appreciate your help and advice to make this work. Is there a way I can support you and the project?

Thanks!

If you want to support my open source work you should see a sponsor button at the top of this page. You can donate to any of my public Bitcoin open source donation addresses:

https://blockstream.info/address/1LukeQU5jwebXbMLDVydeH4vFSobRV9rkj https://blockstream.info/address/3Luke2qRn5iLj4NiFrvLBu2jaEj7JeMR6w https://blockstream.info/address/bc1qlukeyq0c69v97uss68fet26kjkcsrymd2kv6d4

My email address is on my GitHub profile if you want a private address.

You can also donate via Lightning: https://tippin.me/@lukechilds

OvoNemaSmisla commented 4 years ago

If you want to support my open source work you should see a sponsor button at the top of this page. You can donate to any of my public Bitcoin open source donation addresses:

https://blockstream.info/address/1LukeQU5jwebXbMLDVydeH4vFSobRV9rkj https://blockstream.info/address/3Luke2qRn5iLj4NiFrvLBu2jaEj7JeMR6w https://blockstream.info/address/bc1qlukeyq0c69v97uss68fet26kjkcsrymd2kv6d4

My email address is on my GitHub profile if you want a private address.

You can also donate via Lightning: https://tippin.me/@lukechilds

Great, got it.

OvoNemaSmisla commented 4 years ago

Hi Luce,

The server was running fine until it filled up my eMMC storage and almost killed my Odroid :) I forgot that sync will require much more space than 16 GB of eMMC storage.

I've read through ElectrumX Server documentation to find a way to set the data directory to external storage and found DB_DIRECTORY.

I've deployed the server again with:

docker run --net=host -e DAEMON_URL="electrumx:pass@127.0.0.1:8332" -e COIN=BitcoinSegwit -e NET=mainnet -e DB_DIRECTORY=/mnt/electrum_db --name ElectrumX_Server --detach --restart unless-stopped electrumx

But id doesn't recognize the path:

Generating a RSA private key
.........+++++
......................................................................................................+++++
writing new private key to '/data/electrumx.key'
-----
INFO:electrumx:ElectrumX server starting
INFO:electrumx:logging level: INFO
INFO:Controller:Python version: 3.7.7 (default, Apr 24 2020, 07:34:54)  [GCC 9.2.0]
INFO:Controller:software version: ElectrumX 1.14.0
INFO:Controller:aiorpcX version: 0.18.4
INFO:Controller:supported protocol versions: 1.4-1.4.2
INFO:Controller:event loop policy: None
INFO:Controller:reorg limit is 200 blocks
INFO:Daemon:daemon #1 at 127.0.0.1:8332/ (current)
INFO:DB:switching current directory to /mnt/electrum_db
INFO:Controller:shutting down
INFO:Controller:shutdown complete
ERROR:electrumx:ElectrumX server terminated abnormally
Traceback (most recent call last):
  File "/electrumx/electrumx_server", line 35, in main
    asyncio.run(controller.run())
  File "/usr/local/lib/python3.7/asyncio/runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "/usr/local/lib/python3.7/asyncio/base_events.py", line 587, in run_until_complete
    return future.result()
  File "/electrumx/electrumx/lib/server_base.py", line 125, in run
    await server_task
  File "/electrumx/electrumx/lib/server_base.py", line 98, in serve
    await self.serve(shutdown_event)
  File "/electrumx/electrumx/server/controller.py", line 101, in serve
    db = DB(env)
  File "/electrumx/electrumx/server/db.py", line 77, in __init__
    os.chdir(env.db_dir)
FileNotFoundError: [Errno 2] No such file or directory: '/mnt/electrum_db'

I suppose the container doesn't know what's /mnt/electrum_db as it can't see Odroid/Ubuntu filesystem and I don't know how to pass that variable.

I was looking at the Docker documentation and the only thing that looks it might work is to create a volume.

Can you point me to the right direction?

Thanks again!

lukechilds commented 4 years ago

That's correct.

The Docker image is setup to use /data internally as the DB_DIRECTORY:

https://github.com/lukechilds/docker-electrumx/blob/1fcf5c8fbcd031659c69413f666f45eb28935309/Dockerfile#L22

You shouldn't override this with -e DB_DIRECTORY=/mnt/electrum_db. Instead you should setup a Docker volume that mounts /mnt/electrum_db on your host to /data inside the container.

You can do that with -v /mnt/electrum_db:/data.

https://docs.docker.com/engine/reference/run/#volume-shared-filesystems

OvoNemaSmisla commented 4 years ago

I've ran the container with a volume as suggested:

docker run --net=host -e DAEMON_URL="electrumx:pass@127.0.0.1:8332" -e COIN=BitcoinSegwit -e NET=mainnet -v /mnt/electrum_db:/data --name ElectrumX_Server --detach --restart unless-stopped electrumx

And it crashes:

Generating a RSA private key
....................................................+++++
...........+++++
writing new private key to '/data/electrumx.key'
-----
INFO:electrumx:ElectrumX server starting
INFO:electrumx:logging level: INFO
INFO:Controller:Python version: 3.7.7 (default, Apr 24 2020, 07:34:54)  [GCC 9.2.0]
INFO:Controller:software version: ElectrumX 1.14.0
INFO:Controller:aiorpcX version: 0.18.4
INFO:Controller:supported protocol versions: 1.4-1.4.2
INFO:Controller:event loop policy: None
INFO:Controller:reorg limit is 200 blocks
INFO:Daemon:daemon #1 at 127.0.0.1:8332/ (current)
INFO:DB:switching current directory to /data
INFO:DB:using leveldb for DB backend
ERROR:Daemon:daemon service refused: Unauthorized.  Retrying occasionally...

In addition, I've used docker inspect ElectrumX_Server to check the volume:

"Mounts": [
            {
                "Type": "bind",
                "Source": "/mnt/clouddrive/electrum_db",
                "Destination": "/data",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            }
],

I guess the user running the container (root?) doesn't have permissions for /mnt/electrum_db directory.

If this is correct, should I use --user to make it run as the regular user that has access to /mnt/electrum_db directory?

lukechilds commented 4 years ago

It's not likely that root won't have permission but a normal user will.

Are you sure it crashed? Those logs don't show it crashing.

INFO:DB:switching current directory to /data
INFO:DB:using leveldb for DB backend

This looks like it's successfully created a DB at /data. Can you check /mnt/electrum_db on your host and see if anything exists there?

ERROR:Daemon:daemon service refused: Unauthorized.  Retrying occasionally...

And this just looks like it's not authenticating with Bitcoin Core. Are you sure the user:pass credentials are correct?

Also, is it /mnt/electrum_db or /mnt/clouddrive/electrum_db? You said /mnt/electrum_db but docker inspect is showing /mnt/clouddrive/electrum_db.

OvoNemaSmisla commented 4 years ago

You're right, it wasn't a problem with the volume.

The deamon created the crt and key files, but wasn't able to connect to the node. To my surprise, the RPC password was different to what I was using in the last few days. Different from the one used when I managed to run the container that eventually filled my eMMC storage (3 days ago). I don't remember changing the password since then, there was no need.

Anyway, I've changed the password back to the previous one and the server is up and running! :) It's currently syncing to the /mnt/electrum_db directory (I've played around with the location, that's why docker inspect showed different location).

I'll report back when it's done syncing.

OvoNemaSmisla commented 4 years ago

It's going to take a while if the ETA in log is to be believed:

INFO:DB:flushed filesystem data in 0.25s
INFO:History:flushed history in 8.5s for 1,208,766 addrs
INFO:DB:flush #83 took 8.9s.  Height 353,118 txs: 66,264,707 (+721,050)
INFO:DB:tx/sec since genesis: 1,084, since last flush: 354
INFO:DB:sync time: 16h 58m 40s  ETA: 18d 04h 12m
INFO:BlockProcessor:our height: 353,140 daemon: 629,054 UTXOs 928MB hist 11MB
INFO:BlockProcessor:our height: 353,186 daemon: 629,054 UTXOs 931MB hist 28MB
INFO:BlockProcessor:our height: 353,215 daemon: 629,054 UTXOs 931MB hist 37MB
INFO:BlockProcessor:our height: 353,241 daemon: 629,054 UTXOs 934MB hist 46MB
INFO:BlockProcessor:our height: 353,264 daemon: 629,054 UTXOs 935MB hist 54MB
INFO:BlockProcessor:our height: 353,317 daemon: 629,054 UTXOs 937MB hist 68MB
INFO:BlockProcessor:our height: 353,378 daemon: 629,054 UTXOs 943MB hist 85MB
INFO:BlockProcessor:our height: 353,422 daemon: 629,055 UTXOs 945MB hist 101MB
INFO:BlockProcessor:our height: 353,456 daemon: 629,055 UTXOs 945MB hist 112MB
INFO:BlockProcessor:our height: 353,505 daemon: 629,055 UTXOs 945MB hist 125MB
INFO:BlockProcessor:our height: 353,527 daemon: 629,055 UTXOs 945MB hist 134MB
INFO:BlockProcessor:our height: 353,565 daemon: 629,055 UTXOs 946MB hist 144MB
lukechilds commented 4 years ago

Yeah, ElectrumX is pretty slow to sync.

If this is just a local server for your personal traffic you might want to look into electrs. It does initial sync much faster than ElectrumX.

I did a comparison of the two here: https://twitter.com/lukechilds/status/1195622685377613824

OvoNemaSmisla commented 4 years ago

I started thjs with the intention to use it as a local server, but now I'm thinking to open it up for other to use as well.

I'm not in a hurry, but this is really slow and the ETA is all over the place:

2020-05-05T17:14:45.631984917Z INFO:DB:sync time: 19h 07m 47s  ETA: 80d 10h 51m
...
2020-05-05T17:52:14.551332623Z INFO:DB:sync time: 19h 45m 16s  ETA: 23d 16h 02m
...
2020-05-05T18:21:19.590143383Z INFO:DB:sync time: 20h 14m 21s  ETA: 19d 08h 39m
...
2020-05-05T18:50:31.500965084Z INFO:DB:sync time: 20h 43m 33s  ETA: 17d 20h 01m
...
2020-05-05T19:25:01.216003929Z INFO:DB:sync time: 21h 18m 03s  ETA: 21d 03h 00m
...
2020-05-05T19:47:24.273873396Z INFO:DB:sync time: 21h 40m 26s  ETA: 13d 01h 02m

Also, is it strange that the /mnt/electrum_db is not getting bigger since this morning? Its around 5.8GB for hours, although I can see in logs that it's working.

lukechilds commented 4 years ago

Yes that's strange, it should be growing. How are you measuring it's size? Are you sure you still have it mounted? You didn't restart the container and forget to mount that volume?

OvoNemaSmisla commented 4 years ago

I'm using Webmin, File Manager to browse and manipulate the filesystem. Among other features, it can calculate the directory size. Currently /mtn/electrum_db is 7.33GB, so it is growing but very slowly. Also, I don't see the eMMC free space lowering, so I think there is no problem with volume being mounted.

However, I do see that the server restarts from time to time:

docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
e6386fc8a4b6        electrumx           "init"              2 days ago          Up 7 hours                              ElectrumX_Server

And there is not much useful info in the logs (part of the docker logs ElectrumX_Server --timestamps):

2020-05-06T18:39:08.103316232Z INFO:BlockProcessor:our height: 353,722 daemon: 629,249 UTXOs 966MB hist 181MB
2020-05-06T18:41:05.564759058Z INFO:BlockProcessor:our height: 353,803 daemon: 629,250 UTXOs 972MB hist 195MB
2020-05-06T18:42:27.764078271Z INFO:BlockProcessor:our height: 353,831 daemon: 629,250 UTXOs 984MB hist 208MB
2020-05-06T18:43:40.939555294Z INFO:BlockProcessor:our height: 353,874 daemon: 629,250 UTXOs 983MB hist 218MB
2020-05-06T18:43:41.199871252Z INFO:DB:flushed filesystem data in 0.25s
2020-05-06T18:43:48.754514700Z INFO:History:flushed history in 7.6s for 1,053,237 addrs
2020-05-06T18:44:18.986732579Z INFO:electrumx:ElectrumX server starting
2020-05-06T18:44:18.989805038Z INFO:electrumx:logging level: INFO
2020-05-06T18:44:18.989969505Z INFO:Controller:Python version: 3.7.7 (default, Apr 24 2020, 07:34:54)  [GCC 9.2.0]
2020-05-06T18:44:19.001951368Z INFO:Controller:software version: ElectrumX 1.14.0
2020-05-06T18:44:19.002016121Z INFO:Controller:aiorpcX version: 0.18.4
2020-05-06T18:44:19.002030747Z INFO:Controller:supported protocol versions: 1.4-1.4.2
2020-05-06T18:44:19.002149253Z INFO:Controller:event loop policy: None
2020-05-06T18:44:19.002264593Z INFO:Controller:reorg limit is 200 blocks
2020-05-06T18:44:19.002575402Z INFO:Daemon:daemon #1 at 127.0.0.1:8332/ (current)
2020-05-06T18:44:19.003213187Z INFO:DB:switching current directory to /data
2020-05-06T18:44:19.030166200Z INFO:DB:using leveldb for DB backend
2020-05-06T18:44:19.195408095Z INFO:DB:opened UTXO DB (for sync: True)
2020-05-06T18:44:19.195691444Z INFO:DB:DB version: 7
2020-05-06T18:44:19.195745655Z INFO:DB:coin: BitcoinSegwit
2020-05-06T18:44:19.195761156Z INFO:DB:network: mainnet
2020-05-06T18:44:19.195774365Z INFO:DB:height: 343,654
2020-05-06T18:44:19.195787116Z INFO:DB:tip: 0000000000000000086de1824a1b6a83c3f9a6fd11835c76bb883b812965b383
2020-05-06T18:44:19.195816284Z INFO:DB:tx count: 59,755,097
2020-05-06T18:44:19.195829701Z INFO:DB:flushing DB cache at 1,200 MB
2020-05-06T18:44:19.196613286Z INFO:DB:sync time so far: 1d 17h 58m
2020-05-06T18:44:22.795000220Z INFO:History:history DB version: 0
2020-05-06T18:44:22.795393492Z INFO:History:flush count: 84
2020-05-06T18:44:22.795847141Z INFO:History:DB shut down uncleanly.  Scanning for excess history flushes...
2020-05-06T18:51:29.929552858Z INFO:History:deleting 12,967,542 history entries
2020-05-06T18:51:56.398615063Z INFO:History:deleted excess history entries
2020-05-06T18:51:57.155644497Z INFO:SessionManager:RPC server listening on 0.0.0.0:8000
2020-05-06T18:51:57.172261572Z INFO:Prefetcher:catching up to daemon height 629,253 (285,599 blocks behind)
2020-05-06T18:53:32.860749088Z INFO:BlockProcessor:our height: 343,664 daemon: 629,253 UTXOs 3MB hist 3MB
2020-05-06T18:54:11.257153334Z INFO:BlockProcessor:our height: 343,695 daemon: 629,253 UTXOs 13MB hist 14MB
2020-05-06T18:54:54.019806483Z INFO:BlockProcessor:our height: 343,723 daemon: 629,253 UTXOs 22MB hist 23MB
2020-05-06T18:56:32.250530248Z INFO:BlockProcessor:our height: 343,772 daemon: 629,253 UTXOs 34MB hist 38MB
2020-05-06T18:57:05.214576778Z INFO:BlockProcessor:our height: 343,798 daemon: 629,253 UTXOs 43MB hist 48MB

Something happened here:

2020-05-06T18:43:48.754514700Z INFO:History:flushed history in 7.6s for 1,053,237 addrs
2020-05-06T18:44:18.986732579Z INFO:electrumx:ElectrumX server starting

Followed by:

2020-05-06T18:44:22.795847141Z INFO:History:DB shut down uncleanly.  Scanning for excess history flushes...
2020-05-06T18:51:29.929552858Z INFO:History:deleting 12,967,542 history entries

My guess is that this is why the db size is shrinking from time to tome, but overall increasing.

lukechilds commented 4 years ago

As long as it is increasing then it's working.

Monitor your RAM usage, whenever I've seen ElectrumX restart it's normally due to that. You can set CACHE_MB to limit RAM usage if you're running on a low resource system.

What media is /mtn/electrum_db using? Is it an SD card? SD card write speeds are a lot slower than SSD/HDD and ElectrumX is only single threaded. It will take a very long time to index the entire blockchain to an SD card.

OvoNemaSmisla commented 4 years ago

Monitor your RAM usage, whenever I've seen ElectrumX restart it's normally due to that. You can set CACHE_MB to limit RAM usage if you're running on a low resource system.

The Odroid N2 has 4GB RAM and before running ElectumX, everything running on it was using around 50% of the memory. Currently it looks like this, but I've seen it at 90% also: image I've added CACHE_MB=1400, so let's see if that helps.

What media is /mtn/electrum_db using? Is it an SD card? SD card write speeds are a lot slower than SSD/HDD and ElectrumX is only single threaded. It will take a very long time to index the entire blockchain to an SD card.

It's using 2TB USB 3.0 HDD which is at 90% capacity (170GB free) if you look the screenshot above. Bitcoin node is also stored on this drive.

OvoNemaSmisla commented 4 years ago

It crashed again, even with CACHE_MB-1400:

 docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
05470597327b        electrumx           "init"              12 hours ago        Up 3 hours                              ElectrumX_Server

Same situation in the logs, it just restarts. It's probably memory, but don't know what can I do about it.

On the other side, if it requires more memory only while indexing, then I guess there won't be problems after it is finally done with it.

lukechilds commented 4 years ago

You can just set a smaller amount of memory.

-e CACHE_MB=512

This will probably increase the sync time but will try to keep memory usage below 512MB.

OvoNemaSmisla commented 4 years ago

After running for 6 hours: image HTOP: image

Now I'm not sure if this CACHE_MB actually works. According to htop, looks like electrumx server is using 41.2% of RAM which is roughly 1.6GB if you consider total amount of RAM is 4096MB. If you use the value shown by both Webmin and HTOP of 3.62GB of RAM total, then 41.2% is 1.49GB.

Anyway, it looks like it's not going above 91% memory usage.

OvoNemaSmisla commented 4 years ago

I was tired of waiting, so I installed Docker on my desktop machine and ran the server. 16 hours later, I got fully synced db which I copied to Odroid HDD.

The server is up and running for more than 24 hours! 😃

I'm looking at the logs and it's mostly populated with PeerManager information like:

2020-05-12T18:04:08.408595720Z INFO:PeerManager:accepted new peer electrum.nute.net from electrum.jochen-hoenicke.de
2020-05-12T18:04:08.408933655Z INFO:PeerManager:accepted new peer 52.1.56.181 from electrum.jochen-hoenicke.de
2020-05-12T18:04:08.416925542Z INFO:PeerManager:accepted new peer electrum.srvmin.network from fortress.qtornado.com
2020-05-12T18:04:08.417238684Z INFO:PeerManager:accepted new peer bitcoin.grey.pw from fortress.qtornado.com
2020-05-12T18:04:08.421030512Z INFO:PeerManager:accepted new peer xtrum.com from electrum.hsmiths.com
2020-05-12T18:04:08.421168644Z INFO:PeerManager:accepted new peer gall.pro from electrum.hsmiths.com
2020-05-12T18:04:08.424877843Z ERROR:PeerManager:[electrum3.hodlister.co:50002 SSL] marking bad: (not listed in own hosts list ['electrum2.hodlister.co'])
2020-05-12T18:04:08.591819714Z INFO:PeerManager:accepted new peer esx.geekhosters.com from ecdsa.net
2020-05-12T18:04:08.592115188Z INFO:PeerManager:accepted new peer 178.62.80.20 from ecdsa.net
2020-05-12T18:04:08.595208020Z INFO:PeerManager:[electrum.jochen-hoenicke.de:50005 SSL] verified in 1.0s
2020-05-12T18:04:08.595568040Z INFO:PeerManager:[electrum.hsmiths.com:50002 SSL] verified in 1.0s
2020-05-12T18:04:08.595885098Z INFO:PeerManager:[fortress.qtornado.com:443 SSL] verified in 1.0s
2020-05-12T18:04:08.616085598Z INFO:PeerManager:[xtrum.com:50002 SSL] [Errno 111] Connect call failed ('51.255.149.249', 50002)
2020-05-12T18:04:08.630069557Z INFO:PeerManager:[178.62.80.20:50002 SSL] [Errno 111] Connect call failed ('178.62.80.20', 50002)
2020-05-12T18:04:08.649938581Z INFO:PeerManager:[xtrum.com:50002 SSL] [Errno -2] Name does not resolve
2020-05-12T18:04:08.814718668Z INFO:PeerManager:[178.62.80.20:50001 TCP] [Errno 111] Connect call failed ('178.62.80.20', 50001)
2020-05-12T18:04:08.977524317Z INFO:PeerManager:[xtrum.com:50001 TCP] [Errno 111] Connect call failed ('51.255.149.249', 50001)
2020-05-12T18:04:09.067054160Z INFO:PeerManager:blacklist from https://electrum.org/blacklist.json has 641 entries
2020-05-12T18:04:09.070604559Z INFO:PeerManager:[xtrum.com:50001 TCP] [Errno -2] Name does not resolve
2020-05-12T18:04:09.072949143Z INFO:PeerManager:[ecdsa.net:110 SSL] verified in 1.5s

I've deployed the container with --net=host, so I guess the servers is listening on 50001, 50002, 50004 and 8000 ports.

Taking into account that I use UFW set to deny any incoming traffic by default and that I haven't defined rules to allow incoming traffic on these ports, how is it possible that some peers are connecting to the server?

lukechilds commented 4 years ago

Looks like those logs are just you connecting to other ElectrumX server peers hardcoded in ElectrumX:

https://github.com/kyuupichan/electrumx/blob/05c5b424895050eb9ff3aa3f372c72a581184549/electrumx/lib/coins.py#L585-L599

It's not clients connecting to you.

For example, these are the logs from my public Electrum server (which does have clients connecting to it):

INFO:ElectrumX:[14721325] attempting to crash old client with version 3.2.2
INFO:ElectrumX:[14721360] TCP 106.0.38.216:52317, 1,901 total
INFO:ElectrumX:[14721360] attempting to crash old client with version 3.2.2
INFO:ElectrumX:[14721361] TCP 113.176.163.61:52759, 1,900 total
INFO:ElectrumX:[14721362] TCP 203.223.45.46:48641, 1,901 total
INFO:ElectrumX:[14721363] TCP 42.201.195.180:9510, 1,900 total
INFO:ElectrumX:[14721364] TCP 42.114.199.86:24105, 1,901 total
INFO:ElectrumX:[14721365] TCP 105.66.131.81:56220, 1,899 total
INFO:ElectrumX:[14721365] attempting to crash old client with version 3.2.2
INFO:ElectrumX:[14721366] TCP 112.198.74.156:57199, 1,898 total
INFO:ElectrumX:[14721366] attempting to crash old client with version 3.2.2
OvoNemaSmisla commented 4 years ago

Ok, I see. I'll open up port 50002 and see if there will be clients connecting to it. Also, do I need to port forward on my router?

Looking at my logs, I can only find one entry that looks like what you got:

2020-05-13T12:19:10.552040409Z INFO:ElectrumX:[4] SSL 192.168.1.33:57413, 0 total
2020-05-13T12:19:10.570037785Z INFO:ElectrumX:[4] attempting to crash old client with version 0.0.1

And this is my attempt to connect my wallet. I've entered the ip address of the server with 50002 port, the wallet then downloaded the server certificate and when I tried to check the connection it timed out. I guess this is something I'll have to check with the wallet support.

Regarding banner file, if I want to set up one, should I put it in the DB_DIRECTORY?

I also have tor running on default port 9050 on the server machine. Is there something to be set in order for the server to use it?

lukechilds commented 4 years ago

I've entered the ip address of the server with 50002 port, the wallet then downloaded the server certificate and when I tried to check the connection it timed out. I guess this is something I'll have to check with the wallet support.

50002 is the SSL port. This Docker image generates a self signed SSL cert for you to use.

Your wallet may not allow self signed certs. If that's the case you can connect in plain text via port 50001 or Tor.

Plain text is ok if you trust your local network is safe, but Tor/SSL is better.

Regarding banner file, if I want to set up one, should I put it in the DB_DIRECTORY?

Yes, and you'll probably also need to set BANNER_FILE.

https://electrumx.readthedocs.io/en/latest/environment.html#envvar-BANNER_FILE

I also have tor running on default port 9050 on the server machine. Is there something to be set in order for the server to use it?

You need to run a Tor hidden service exposing port 50001. No need for SSL if it's tunnelled through Tor.

Basically put something like this in your torrc:

HiddenServiceDir /var/lib/tor/electrum
HiddenServicePort 50001 127.0.0.1:50001

https://2019.www.torproject.org/docs/tor-onion-service.html.en

OvoNemaSmisla commented 4 years ago

I've entered the ip address of the server with 50002 port, the wallet then downloaded the server certificate and when I tried to check the connection it timed out. I guess this is something I'll have to check with the wallet support.

50002 is the SSL port. This Docker image generates a self signed SSL cert for you to use.

Your wallet may not allow self signed certs. If that's the case you can connect in plain text via port 50001 or Tor.

Plain text is ok if you trust your local network is safe, but Tor/SSL is better.

I've just tried 50001 port, but it times out the same. Here are the log entries:

2020-05-13T16:58:34.959484421Z INFO:ElectrumX:[28] TCP 192.168.1.33:51665, 2 total
2020-05-13T16:58:34.960162165Z INFO:ElectrumX:[29] TCP 192.168.1.33:51666, 3 total
2020-05-13T16:58:34.962056515Z INFO:ElectrumX:[29] changing task concurrency from 10 to 0
2020-05-13T16:58:34.968058290Z INFO:ElectrumX:[29] disconnected whilst throttled
2020-05-13T16:59:04.965215198Z INFO:ElectrumX:[30] TCP 192.168.1.33:51692, 2 total
2020-05-13T16:59:04.966396177Z INFO:ElectrumX:[30] changing task concurrency from 10 to 0
2020-05-13T16:59:04.967744207Z INFO:ElectrumX:[30] disconnected whilst throttled

Thanks for setting me in the right direction regarding tor and banner file, I'll take a look.

Sorry to repeat the question, but is there a need to port forward 50001, 50002 and 50004 on router to the ElectrumX server machine?

jagoanpilot commented 1 year ago

docker run --net=host -e DAEMON_URL="coinuser:coinpw@127.0.0.1:17898" -e COIN=Jagoancoin -e NET=mainnet -e rpchost=127.0.0.1 -e rpcport=17898 electrumx

'`Generating a RSA private key .........+++++ .......................................................................+++++ writing new private key to '/data/electrumx.key

/usr/local/bin/init: exec: line 7: /electrumx/electrumx_server: not found`'

FROM python:3.7-alpine3.16 LABEL maintainer="Luke Childs lukechilds123@gmail.com"

COPY ./bin /usr/local/bin

RUN chmod a+x /usr/local/bin/ && \ apk add --no-cache git build-base openssl && \ apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/v3.16/main leveldb-dev && \ pip install aiohttp pylru plyvel websockets uvloop && \ git clone https://github.com/jagoanpilot/electrumx.git && \ cd electrumx && \ python setup.py build && \ python setup.py install && \ apk del git build-base && \ rm -rf /tmp/

VOLUME ["/data"] ENV HOME /data ENV ALLOW_ROOT 1 ENV EVENT_LOOP_POLICY uvloop ENV DB_DIRECTORY /data ENV SERVICES=tcp://:50001,ssl://:50002,wss://:50004,rpc://0.0.0.0:8000 ENV SSL_CERTFILE ${DB_DIRECTORY}/electrumx.crt ENV SSL_KEYFILE ${DB_DIRECTORY}/electrumx.key ENV HOST "" WORKDIR /data

EXPOSE 50001 50002 50004 8000

CMD ["init"]