diff --git a/README.md b/README.md index 4e8051ec03d2b184979dc2e79c4ed2e467ecaa04..030c6deba8f30b07cbc84f5f8ffb12d3a48a1745 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,11 @@ Para poder levantar todo con docker-compose primero es necesario crear las imág ```` docker build -t nodobfa nodo/ ```` +Config: +- Actualmente se [installbfa.sh](https://gitlab.bfa.ar/blockchain/nucleo/-/blob/master/bin/installbfa.sh) oficial tiene problemas con la instalacion de geth por loq ue se fixio cambiando remplazando el [installbfa.sh](https://gitlab.bfa.ar/blockchain/nucleo/-/blob/master/bin/installbfa.sh) por [fix_installbfa.sh](nodo/fix_installbfa.sh) se llevo acabo la solucion planteada en https://gitlab.bfa.ar/blockchain/nucleo/-/issues/8 +- Se puede establecer el config.toml que se precise cambiandolo en [config.toml](nodo/config.toml). Hay ejemplos en +[aca](nodo/config.example/) + **API** ```` @@ -31,6 +36,14 @@ docker-compose up -d ### Importante Al levantar los contenedores el nodo empezará a sincronizar. La API quedará expuesta en el puerto 3000. +### Registro en (registro.bfa.ar/)[https://registro.bfa.ar/accounts/list/] + + +```` +sudo docker exec -it [CONTAINER ID] geth --config /home/bfa/bfa/network/config.localhost+full+archive account new +```` + + **Comandos útiles:** ```` docker exec nodobfa bfalog.sh diff --git a/docker-compose.yml b/docker-compose.yml index 96c294258eae8a0d5b57cca7a8dd3beb79ff94f6..ff3653dab6e6091fd0be8558500d3f57177112bf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,17 +13,23 @@ services: environment: - BFAHOME=/home/bfa/bfa - PATH=${PATH}:/home/bfa/bfa/bin:/home/bfa/bin + - USERNAME=bfa + - HOME=/home/bfa + - BFANETWORKIDPROD=47525974938 + - BFANETWORKIDTEST=55555000000 + - VIRTUALIZATION=DOCKER volumes: - nodo_data:/nodo_data/ - apibfa: - container_name: apibfa - image: apibfa - tty: true - ports: - - "3000:3000" - volumes: - - nodo_data:/nodo_data/ - links: - - nodobfa + # todavia no veo esto + # apibfa: + # container_name: apibfa + # image: apibfa + # tty: true + # ports: + # - "3000:3000" + # volumes: + # - nodo_data:/nodo_data/ + # links: + # - nodobfa:nodobfa volumes: nodo_data: diff --git a/nodo/Dockerfile b/nodo/Dockerfile index 6e5021dd69c93ff7ee958f99c55abd5f585f33f3..e2313a5d642464032a0b9b849eb58a93a41a4785 100644 --- a/nodo/Dockerfile +++ b/nodo/Dockerfile @@ -1,8 +1,8 @@ -FROM ubuntu:latest +FROM ubuntu:focal-20221019 ARG DEBIAN_FRONTEND=noninteractive -RUN apt-get update && apt-get install -y software-properties-common cron wget curl locales npm git zip unzip net-tools nano +RUN apt-get update && apt-get install -y software-properties-common cron wget curl locales npm git zip unzip net-tools nano htop RUN locale-gen es_AR.UTF-8 RUN export LANG=es_AR.UTF-8 @@ -11,10 +11,18 @@ RUN git clone https://gitlab.bfa.ar/blockchain/nucleo.git /bfa RUN mkdir -p /nodo_data/ +COPY fix_installbfa.sh /bfa/bin/installbfa.sh + +RUN chmod +x /bfa/bin/installbfa.sh + +ENV NEW="/home/bfa/bfa" + RUN /bfa/bin/installbfa.sh RUN chown bfa:bfa -R /nodo_data/ +COPY config.toml /home/bfa/bfa/network/config.localhost+full+archive + RUN sed -i 's/--rpccorsdomain \\\*/--rpccorsdomain \\\* \\\n --rpcaddr 0.0.0.0\t\\\n --rpcport 8545/g' /home/bfa/bfa/bin/start.sh RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* @@ -29,4 +37,4 @@ VOLUME /nodo_data/ EXPOSE 8545 8546 30303 -ENTRYPOINT ["/bin/sh", "-c" , "/home/bfa/bfa/bin/start.sh && tail -F /dev/null"] +ENTRYPOINT ["/bin/sh", "-c" , "/home/bfa/bfa/bin/bfalog.sh"] diff --git a/nodo/config.example/config.full+archive+http.toml b/nodo/config.example/config.full+archive+http.toml new file mode 100644 index 0000000000000000000000000000000000000000..94c8bc55e35b528e4c7828a43a1f19f59ee6e70f --- /dev/null +++ b/nodo/config.example/config.full+archive+http.toml @@ -0,0 +1,22 @@ +[Eth] +NetworkId = 47525974938 +SyncMode = "full" +NoPruning = true +DatabaseCache = 4096 + +[Node.P2P] +BootstrapNodes = ["enode://7ec4dd9d5e1a2b29d6b60aa9f95677c0c3a5f9306e73d65dd3bcbfda3737a8c509b02d1eab763ce39f18cfe96423df7ee544d6c36191ec17f59ade75bc99d358@[2800:110:44:6300::aad2:2db3]:30301", "enode://7ec4dd9d5e1a2b29d6b60aa9f95677c0c3a5f9306e73d65dd3bcbfda3737a8c509b02d1eab763ce39f18cfe96423df7ee544d6c36191ec17f59ade75bc99d358@170.210.45.179:30301", "enode://82b66b13d7addcf9ffe1e4e972a105f6ccf50557161c4a0978a5d9ce595ababde609ea8a49897ae89b1d41e90551cb2e9241363238593e950ca68bd5af7c24d6@200.16.28.28:30301", "enode://ddbf37799e8d33b0c42dddbda713037b17d14696b29ecf424ca3d57bb47db78a467505e22c5f2b709a98c3d55ac8ecbf4610765385317dd51049438f498881c6@200.108.146.100:30301"] +BootstrapNodesV5 = ["enode://7ec4dd9d5e1a2b29d6b60aa9f95677c0c3a5f9306e73d65dd3bcbfda3737a8c509b02d1eab763ce39f18cfe96423df7ee544d6c36191ec17f59ade75bc99d358@[2800:110:44:6300::aad2:2db3]:30301", "enode://7ec4dd9d5e1a2b29d6b60aa9f95677c0c3a5f9306e73d65dd3bcbfda3737a8c509b02d1eab763ce39f18cfe96423df7ee544d6c36191ec17f59ade75bc99d358@170.210.45.179:30301", "enode://82b66b13d7addcf9ffe1e4e972a105f6ccf50557161c4a0978a5d9ce595ababde609ea8a49897ae89b1d41e90551cb2e9241363238593e950ca68bd5af7c24d6@200.16.28.28:30301", "enode://ddbf37799e8d33b0c42dddbda713037b17d14696b29ecf424ca3d57bb47db78a467505e22c5f2b709a98c3d55ac8ecbf4610765385317dd51049438f498881c6@200.108.146.100:30301"] + +[Node] +DataDir = "/home/bfa/bfa/network/node" +HTTPHost = "0.0.0.0" +HTTPCors = ["*"] +omitempty = "" +IPCPath = "geth.ipc" +HTTPPort = 8545 +HTTPVirtualHosts = ["*"] +HTTPModules = ["net", "web3", "eth", "clique"] +WSHost = "0.0.0.0" +WSPort = 8546 +WSModules = ["eth", "net", "web3", "clique"] diff --git a/nodo/config.example/config.full+archive+nohttp.toml b/nodo/config.example/config.full+archive+nohttp.toml new file mode 100644 index 0000000000000000000000000000000000000000..b2de2efeebdd129723bbbe8756760dcf02fcfba8 --- /dev/null +++ b/nodo/config.example/config.full+archive+nohttp.toml @@ -0,0 +1,12 @@ +[Eth] +NetworkId = 47525974938 +SyncMode = "full" +NoPruning = true +DatabaseCache = 4096 + +[Node.P2P] +BootstrapNodes = ["enode://7ec4dd9d5e1a2b29d6b60aa9f95677c0c3a5f9306e73d65dd3bcbfda3737a8c509b02d1eab763ce39f18cfe96423df7ee544d6c36191ec17f59ade75bc99d358@[2800:110:44:6300::aad2:2db3]:30301", "enode://7ec4dd9d5e1a2b29d6b60aa9f95677c0c3a5f9306e73d65dd3bcbfda3737a8c509b02d1eab763ce39f18cfe96423df7ee544d6c36191ec17f59ade75bc99d358@170.210.45.179:30301", "enode://82b66b13d7addcf9ffe1e4e972a105f6ccf50557161c4a0978a5d9ce595ababde609ea8a49897ae89b1d41e90551cb2e9241363238593e950ca68bd5af7c24d6@200.16.28.28:30301", "enode://ddbf37799e8d33b0c42dddbda713037b17d14696b29ecf424ca3d57bb47db78a467505e22c5f2b709a98c3d55ac8ecbf4610765385317dd51049438f498881c6@200.108.146.100:30301"] +BootstrapNodesV5 = ["enode://7ec4dd9d5e1a2b29d6b60aa9f95677c0c3a5f9306e73d65dd3bcbfda3737a8c509b02d1eab763ce39f18cfe96423df7ee544d6c36191ec17f59ade75bc99d358@[2800:110:44:6300::aad2:2db3]:30301", "enode://7ec4dd9d5e1a2b29d6b60aa9f95677c0c3a5f9306e73d65dd3bcbfda3737a8c509b02d1eab763ce39f18cfe96423df7ee544d6c36191ec17f59ade75bc99d358@170.210.45.179:30301", "enode://82b66b13d7addcf9ffe1e4e972a105f6ccf50557161c4a0978a5d9ce595ababde609ea8a49897ae89b1d41e90551cb2e9241363238593e950ca68bd5af7c24d6@200.16.28.28:30301", "enode://ddbf37799e8d33b0c42dddbda713037b17d14696b29ecf424ca3d57bb47db78a467505e22c5f2b709a98c3d55ac8ecbf4610765385317dd51049438f498881c6@200.108.146.100:30301"] + +[Node] +DataDir = "/home/bfa/bfa/network/node" diff --git a/nodo/config.example/docker-config.toml b/nodo/config.example/docker-config.toml new file mode 100644 index 0000000000000000000000000000000000000000..f414c8755727a134f8e906bb7a2ff821c52b1364 --- /dev/null +++ b/nodo/config.example/docker-config.toml @@ -0,0 +1,21 @@ +[Eth] +NetworkId = 47525974938 +SyncMode = "fast" +NoPruning = false +DatabaseCache = 2048 + +[Node] +DataDir = "/home/bfa/bfa/network/node" +HTTPHost = "0.0.0.0" +HTTPCors = ["*"] +IPCPath = "geth.ipc" +HTTPPort = 8545 +HTTPVirtualHosts = ["*"] +HTTPModules = ["net", "web3", "eth", "clique"] +WSHost = "0.0.0.0" +WSPort = 8546 +WSModules = ["net", "web3", "eth", "clique"] + +[Node.P2P] +BootstrapNodes = ["enode://7ec4dd9d5e1a2b29d6b60aa9f95677c0c3a5f9306e73d65dd3bcbfda3737a8c509b02d1eab763ce39f18cfe96423df7ee544d6c36191ec17f59ade75bc99d358@[2800:110:44:6300::aad2:2db3]:30301", "enode://7ec4dd9d5e1a2b29d6b60aa9f95677c0c3a5f9306e73d65dd3bcbfda3737a8c509b02d1eab763ce39f18cfe96423df7ee544d6c36191ec17f59ade75bc99d358@170.210.45.179:30301", "enode://82b66b13d7addcf9ffe1e4e972a105f6ccf50557161c4a0978a5d9ce595ababde609ea8a49897ae89b1d41e90551cb2e9241363238593e950ca68bd5af7c24d6@200.16.28.28:30301", "enode://59ae768ecdee632e0daceccb6f71b215392eba89230d626573f2fb4e9c0786c9a661027ab7343820ca63d96fe48ffd81ed1bf6e4d512f0ba50ec072c9efd9e4e@200.108.146.100:30301"] +BootstrapNodesV5 = ["enode://7ec4dd9d5e1a2b29d6b60aa9f95677c0c3a5f9306e73d65dd3bcbfda3737a8c509b02d1eab763ce39f18cfe96423df7ee544d6c36191ec17f59ade75bc99d358@[2800:110:44:6300::aad2:2db3]:30301", "enode://7ec4dd9d5e1a2b29d6b60aa9f95677c0c3a5f9306e73d65dd3bcbfda3737a8c509b02d1eab763ce39f18cfe96423df7ee544d6c36191ec17f59ade75bc99d358@170.210.45.179:30301", "enode://82b66b13d7addcf9ffe1e4e972a105f6ccf50557161c4a0978a5d9ce595ababde609ea8a49897ae89b1d41e90551cb2e9241363238593e950ca68bd5af7c24d6@200.16.28.28:30301", "enode://59ae768ecdee632e0daceccb6f71b215392eba89230d626573f2fb4e9c0786c9a661027ab7343820ca63d96fe48ffd81ed1bf6e4d512f0ba50ec072c9efd9e4e@200.108.146.100:30301"] diff --git a/nodo/config.toml b/nodo/config.toml new file mode 100644 index 0000000000000000000000000000000000000000..b2de2efeebdd129723bbbe8756760dcf02fcfba8 --- /dev/null +++ b/nodo/config.toml @@ -0,0 +1,12 @@ +[Eth] +NetworkId = 47525974938 +SyncMode = "full" +NoPruning = true +DatabaseCache = 4096 + +[Node.P2P] +BootstrapNodes = ["enode://7ec4dd9d5e1a2b29d6b60aa9f95677c0c3a5f9306e73d65dd3bcbfda3737a8c509b02d1eab763ce39f18cfe96423df7ee544d6c36191ec17f59ade75bc99d358@[2800:110:44:6300::aad2:2db3]:30301", "enode://7ec4dd9d5e1a2b29d6b60aa9f95677c0c3a5f9306e73d65dd3bcbfda3737a8c509b02d1eab763ce39f18cfe96423df7ee544d6c36191ec17f59ade75bc99d358@170.210.45.179:30301", "enode://82b66b13d7addcf9ffe1e4e972a105f6ccf50557161c4a0978a5d9ce595ababde609ea8a49897ae89b1d41e90551cb2e9241363238593e950ca68bd5af7c24d6@200.16.28.28:30301", "enode://ddbf37799e8d33b0c42dddbda713037b17d14696b29ecf424ca3d57bb47db78a467505e22c5f2b709a98c3d55ac8ecbf4610765385317dd51049438f498881c6@200.108.146.100:30301"] +BootstrapNodesV5 = ["enode://7ec4dd9d5e1a2b29d6b60aa9f95677c0c3a5f9306e73d65dd3bcbfda3737a8c509b02d1eab763ce39f18cfe96423df7ee544d6c36191ec17f59ade75bc99d358@[2800:110:44:6300::aad2:2db3]:30301", "enode://7ec4dd9d5e1a2b29d6b60aa9f95677c0c3a5f9306e73d65dd3bcbfda3737a8c509b02d1eab763ce39f18cfe96423df7ee544d6c36191ec17f59ade75bc99d358@170.210.45.179:30301", "enode://82b66b13d7addcf9ffe1e4e972a105f6ccf50557161c4a0978a5d9ce595ababde609ea8a49897ae89b1d41e90551cb2e9241363238593e950ca68bd5af7c24d6@200.16.28.28:30301", "enode://ddbf37799e8d33b0c42dddbda713037b17d14696b29ecf424ca3d57bb47db78a467505e22c5f2b709a98c3d55ac8ecbf4610765385317dd51049438f498881c6@200.108.146.100:30301"] + +[Node] +DataDir = "/home/bfa/bfa/network/node" diff --git a/nodo/fix_installbfa.sh b/nodo/fix_installbfa.sh new file mode 100644 index 0000000000000000000000000000000000000000..a58d1d971c0cefe59593c82ed9da1f85f838b1e5 --- /dev/null +++ b/nodo/fix_installbfa.sh @@ -0,0 +1,249 @@ +#!/bin/bash + +NODEJSPGP=0x68576280 + +# /root often does not have enough space, so we create a directory in /home +# for building, which we hope has more space. +NEW=/home/root/new + +trap 'echo "The installation failed." >&2 ; exit 1' ERR +set -o errtrace +# Be verbose +set -e + +if [ `id -u` -ne 0 ] +then + echo "We are not root, but we need to be. Trying sudo now." + exec sudo $0 +fi + +function info +{ + echo + echo '***' + echo "*** $@" + echo '***' +} + +# Runs as the owner of the given directory, and in the given directory +function runasownerof +{ + local where=$1 precmd= + shift 1 + pushd $where > /dev/null + if [ $( stat --format=%u . ) -ne $UID ] + then + precmd="sudo --preserve-env --shell --set-home --user=$( stat --format=%U . ) PATH=${PATH}" + fi + ${precmd} "$@" + local rv=$? + popd > /dev/null + return $rv +} + +# For getting a recent nodejs +function nodejsinstall +{ + info nodejs + # Nodejs software repository PGP key + if [ `apt-key export ${NODEJSPGP} 2>&1 | wc -l` -le 50 ] + then + info "Adding nodejs software repository PGP key" + apt-key adv --keyserver keyserver.ubuntu.com --recv ${NODEJSPGP} + fi + local file=/etc/apt/sources.list.d/nodesource.list + if [ ! -r "$file" ] + then + info "Adding nodejs repository to apt sources." + echo "deb https://deb.nodesource.com/node_10.x $(lsb_release -sc) main" > $file + info "And now updating the software package list." + apt update + fi + # nodejs also provides npm + aptinstall nodejs + info "Installing nodejs modules (will show many warnings)" + runasownerof ${BFAHOME} npm install + runasownerof ${BFAHOME} npm audit fix +} + +function gethinstall +{ + install --verbose --owner=bfa --group=bfa --directory ${NEW} + if [ -d ${NEW}/go-ethereum ] + then + info "Running git pull to ensure that the local go-ethereum repo is up-to-date." + runasownerof ${NEW}/go-ethereum git checkout master + runasownerof ${NEW}/go-ethereum git pull + else + info "Download geth source code." + runasownerof ${NEW} git clone https://github.com/ethereum/go-ethereum + fi + runasownerof ${NEW}/go-ethereum git checkout ${geth_tag} + chown -R bfa ${NEW}/go-ethereum + info "Compiling geth tagged as ${geth_tag}" + runasownerof ${NEW}/go-ethereum make all + HISBINDIR=$( echo ~bfa/bin ) + install --verbose --owner=bfa --group=bfa --directory ${HISBINDIR} + install --verbose --owner=bfa --group=bfa --target-directory=${HISBINDIR} ${NEW}/go-ethereum/build/bin/{geth,bootnode,abigen,ethkey,puppeth,rlpdump,wnode,swarm,swarm-smoke} +} + +function initgenesis +{ + ( + HOME=$( echo ~bfa ) + source ${BFAHOME}/bin/env + BFANETWORKDIR=${BFANETWORKDIR:-${BFAHOME}/network} + BFANODEDIR=${BFANODEDIR:-${BFANETWORKDIR}/node} + if [ ! -d "${BFANODEDIR}" -o ! -d "${BFANODEDIR}/geth/chaindata" ] + then + info "Node is not initialised. Initialising with genesis." + runasownerof "${BFAHOME}" geth --networkid ${BFANETWORKID} --cache 0 --datadir "${BFANODEDIR}" init "${BFANETWORKDIR}/genesis.json" + chown -R bfa:bfa ~bfa + fi + ) +} + +function aptinstall +{ + for pkg in $* + do + # consider apt install --install-suggests if you are masochist + dpkg --verify $pkg 2>/dev/null || + ( + info "Installing $pkg" + apt -y install $pkg + ) + done +} + +function usersetup +{ + if ! id bfa >/dev/null 2>&1 + then + info "Adding required user \"bfa\"" + adduser --disabled-password --gecos 'Blockchain Federal Argentina' bfa + info "Adding user \"bfa\" to group \"sudo\"" + adduser bfa sudo + fi + # If we're running inside a docker, this may already exist but + # probably owned by root. Let's make sure things are proper. + chown -R bfa:bfa ~bfa + # +} + +function userconfig +{ + if [ $( expand < ~bfa/.bashrc | grep -E "source ${BFAHOME}/bin/env" | wc -l ) -eq 0 ] + then + info "Adding to automatically source ${BFAHOME}/bin/env via .bashrc" + echo "test -r ${BFAHOME}/bin/env && source ${BFAHOME}/bin/env" >> ~bfa/.bashrc + fi + # cloning if not done already, or just update (pull) + if [ ! -d "${BFAHOME}" ] + then + # initial cloning + runasownerof ${BFAHOME%/*} git clone https://gitlab.bfa.ar/blockchain/nucleo.git $BFAHOME + else + runasownerof "${BFAHOME}" git pull + fi + if [ ! -e "${BFAHOME}/bin/env" ] + then + cp -p ${BFAHOME}/$envfile ${BFAHOME}/bin/env + fi + PATH=${PATH}:${BFAHOME}/bin + source ${BFAHOME}/lib/versions +} + +function cronit +{ + if [ $( ( crontab -u bfa -l 2>/dev/null || true ) | grep -E "${BFAHOME#~bfa/}/bin/cron.sh" | wc -l ) -eq 0 ] + then + info "Install crontab to start automatically upon reboot" + (( crontab -u bfa -l 2>/dev/null || true ) ; echo "@reboot ${BFAHOME#~bfa/}/bin/cron.sh" ) | crontab -u bfa - + fi +} + +function welcome +{ + info "(re)log in as user bfa" +} + +function setupquestions +{ + if [ -t 0 ] + then + read -p "Donde quiere instalar (sera BFAHOME) [$( echo ~bfa/bfa )]? : " -t 300 BFAHOME + fi + if [ "$BFAHOME" = "" ] + then + BFAHOME=$( echo ~bfa/bfa ) + fi + # Default to production + envfile=network/env + if [ ! -e "${BFAHOME}/bin/env" ] + then + REPLY= + if [ -t 0 ] + then + while [ "$REPLY" != "1" -a "$REPLY" != "2" ] + do + echo "Quiere conectarse a la red BFA de produccion o prueba?" + echo "1. Produccion" + echo "2. Prueba (test2)" + read -p "Red: " -t 60 -n 1 + echo + done + fi + if [ "$REPLY" = "2" ] + then + envfile=test2network/env + fi + fi +} + +function gethinstallFIXED +{ + echo "===================================================================" + echo " gethinstallFIXED - install go" + echo " URL: https://gitlab.bfa.ar/blockchain/nucleo/-/issues/8 " + echo "===================================================================" + + # Instalá la última versión de golang + wget https://golang.org/dl/go1.17.2.linux-amd64.tar.gz + rm -rf /usr/local/go + tar -C /usr/local -xzf go1.17.2.linux-amd64.tar.gz + export PATH=$PATH:/usr/local/go/bin + go version + + + echo "===================================================================" + echo " gethinstallFIXED - install geth" + echo " URL: https://gitlab.bfa.ar/blockchain/nucleo/-/issues/8 " + echo "===================================================================" + + # Instalá Go Ethereum (geth) + add-apt-repository -y ppa:ethereum/ethereum + apt-get update + apt-get -y install ethereum + geth version + +} + + +usersetup +setupquestions +# Ubuntu necesita mas repos +grep -q Ubuntu /etc/issue && apt-add-repository multiverse +# +apt update +# development tools +aptinstall dirmngr apt-transport-https curl git curl build-essential sudo software-properties-common wget +aptinstall jq libjson-perl libwww-perl libclass-accessor-perl +userconfig +nodejsinstall +# fix URL: https://gitlab.bfa.ar/blockchain/nucleo/-/issues/8 +gethinstallFIXED +#gethinstall +initgenesis +cronit +welcome