diff --git a/bin/getbfa.sh b/bin/getbfa.sh deleted file mode 100644 index 151fda7324ab7f5590e6afc3b7ada8406a507267..0000000000000000000000000000000000000000 --- a/bin/getbfa.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -x - -trap "exit 1" ERR -wget https://gitlab.bfa.ar/blockchain/nucleo/raw/master/bin/installbfa.sh -chmod 755 installbfa.sh -./installbfa.sh diff --git a/bin/libbfa.js b/bin/libbfa.js index 6cdd2e99ee9e3af22086bd9b680924e0c1c65454..c4b99374fc2f010f1be5da3740e2dfc8e771c2fa 100644 --- a/bin/libbfa.js +++ b/bin/libbfa.js @@ -9,6 +9,7 @@ module.exports = class Libbfa constructor() { this.fs = require('fs'); this.Web3 = require('web3'); + var net = require('net'); // // BFAHOME if ( undefined == process.env.BFAHOME ) @@ -45,9 +46,21 @@ module.exports = class Libbfa } } // - this.netport = Number.parseInt( this.setfromfile( this.nodedir+'/netport', 30303 )); - this.rpcport = Number.parseInt( this.setfromfile( this.nodedir+'/rpcport', 8545 )); this.account = process.env.BFAACCOUNT; + this.netport = 30303; + this.rpcport = 8545; + this.sockettype = 'ipc'; + this.socketurl = 'http://127.0.0.1:' + this.rpcport; // old + this.socketurl = this.nodedir+'/geth.ipc'; // overwrite with newer ipc method + if ( this.sockettype == 'ipc' ) { + this.provider = new this.Web3.providers.IpcProvider( this.nodedir+'/geth.ipc', net ); + } else if ( this.sockettype == 'ws' ) { + this.provider = new this.Web3.providers.WebsocketProvider( this.socketurl ); + } else if ( this.sockettype == 'http') { + this.provider = new this.Web3.providers.HttpProvider( this.socketurl ); + } else { + fatal("Unknown sockettype."); + } } contract(w3, name) @@ -72,14 +85,13 @@ module.exports = class Libbfa fatal( txt ) { - console.log( txt ); + console.error( txt ); process.exit( 1 ); } newweb3() { - var provider = 'http://127.0.0.1:' + this.rpcport; - var w3 = new this.Web3( provider ); + var w3 = new this.Web3( this.provider ); w3.rpcreq = function( opname, params, callback ) { var extra = params.join(','); diff --git a/bin/libbfa.sh b/bin/libbfa.sh index c451c55b793c19605158164fc4204805baecba25..9b363b63f0ba3a0cca5cbf0ae4dcd71e6d396a26 100644 --- a/bin/libbfa.sh +++ b/bin/libbfa.sh @@ -67,10 +67,10 @@ function geth_exec function geth_rpc { - local cmd=$1 - test -n "$cmd" - local params= + local params= connectstring= cmd=$1 shift + test -n "$cmd" + rpc_counter=$(( $rpc_counter + 1 )) if [ $# -gt 0 ] then params=',"params":[' @@ -82,12 +82,18 @@ function geth_rpc # Eat the last comma and add a ] params=${params/%,/]} fi + if [ "$BFASOCKETTYPE" = "ipc" ] + then + connectstring="--unix-socket ${BFASOCKETURL}" + else + connectstring="${BFASOCKETURL}" + fi local json=$( - curl \ - -H 'Content-type: application/json' \ - -X POST \ - --data "{\"jsonrpc\":\"2.0\",\"method\":\"${cmd}\"${params},\"id\":1}" \ - http://127.0.0.1:$rpcport \ + curl \ + -H 'Content-type: application/json' \ + -X POST \ + --data "{\"jsonrpc\":\"2.0\",\"method\":\"${cmd}\"${params},\"id\":${rpc_counter}}" \ + ${connectstring} \ 2>/dev/null ) test -n "$json" @@ -104,34 +110,9 @@ function create_account geth --cache 0 --datadir ${BFANODEDIR} --password /dev/null account new } -function extradata -{ - local acct=$( - ls -1d "${BFANODEDIR}"/keystore/*--* 2>/dev/null | - head -1 | - sed 's/.*--//' - ) - if [ -n "$acct" ] - then - # something uniqueish - ## find default interface - local def_if=$( - ( ip -4 route show ; ip -6 route show ) | - expand | - sed -ne '/^default /{s/ */ /g;s/^.* dev //;s/ .*//;p;q}' - ) - local mymac=$( - ip link show ${def_if} | - sed -ne '/link\|ether/{s/^.*link.ether //;s/ .*//;s/://g;p;q}' - ) - # - echo -n "${acct:0:19}.${mymac:0:12}" - fi -} - function prereq { - err=0 + local err=0 while [ -n "$1" ] do if ! which $1 > /dev/null @@ -175,48 +156,53 @@ function contractSendTx echo "contract.${func}.sendTransaction(${args} {from: eth.accounts[0], gas: 1000000} )" } -############### -# bfainit # -test -n "${BFAHOME}" -a \ - -d "${BFAHOME}" || - fatal "\$BFAHOME in your environment must point to a directory." -# -# BFANETWORKID -test -n "${BFANETWORKID}" || BFANETWORKID=47525974938 -# -# BFANETWORKDIR -test -n "${BFANETWORKDIR}" || BFANETWORKDIR="${BFAHOME}/network" -mkdir -p "${BFANETWORKDIR}" -test -d "${BFANETWORKDIR}" || fatal "\$BFANETWORKDIR (\"${BFANETWORKDIR}\") not found." -# -# BFANODEDIR -test -n "$BFANODEDIR" || BFANODEDIR="${BFANETWORKDIR}/node" -if [ ! -d "${BFANODEDIR}" -o ! -d "${BFANODEDIR}/geth/chaindata" ] -then - echo "Node is not initialised. Initialising with genesis." - geth --cache 0 --datadir "${BFANODEDIR}" init "${BFANETWORKDIR}/genesis.json" -fi -# -# netport -netport=30303 -if [ -r "${BFANODEDIR}/netport" ] -then - netport=$( cat ${BFANODEDIR}/netport ) - test $? = 0 -fi -if [ "$netport" != "30303" ] -then - netportarg="--port ${netport}" -fi -# -# rpcport -rpcport=8545 -if [ -r "${BFANODEDIR}/rpcport" ] -then - rpcport=$( cat ${BFANODEDIR}/rpcport ) - test $? = 0 -fi -if [ "$rpcport" != "8545" ] +function bfainit +{ + rpc_counter=0 + ############### + # bfainit # + test -n "${BFAHOME}" -a \ + -d "${BFAHOME}" || + fatal "\$BFAHOME in your environment must point to a directory." + # + # BFANETWORKID + test -n "${BFANETWORKID}" || BFANETWORKID=47525974938 + # + # BFANETWORKDIR + test -n "${BFANETWORKDIR}" || BFANETWORKDIR="${BFAHOME}/network" + mkdir -p "${BFANETWORKDIR}" + test -d "${BFANETWORKDIR}" || fatal "\$BFANETWORKDIR (\"${BFANETWORKDIR}\") not found." + # + # BFANODEDIR + test -n "$BFANODEDIR" || BFANODEDIR="${BFANETWORKDIR}/node" + # + # Default to IPC connections, because we have more geth modules available. + true ${BFASOCKETTYPE:=ipc} + case "${BFASOCKETTYPE}" in + ipc) + true ${BFASOCKETURL:="ipc:${BFANODEDIR}/geth.ipc"} + ;; + http) + true ${BFASOCKETURL:="http://127.0.0.1:8545"} + ;; + ws) + true ${BFASOCKETURL:="ws://127.0.0.1:8546"} + ;; + *) + echo "Unknown socket type. Supported types are http, ws, ipc" >&2 + exit 1 + esac + # Init the blockchain with the genesis block + if [ ! -d "${BFANODEDIR}/geth/chaindata" ] + then + mkdir -p "${BFANODEDIR}" + echo "Node is not initialised. Initialising with genesis." + geth --config "${BFANETWORKDIR}/config.toml" --cache 0 init "${BFANETWORKDIR}/genesis.json" + fi +} + +if [ -z "$SOURCED_BFAINIT_SH" ] then - rpcportarg="--rpcport ${rpcport}" + export SOURCED_BFAINIT_SH=yes + bfainit fi diff --git a/bin/localstate.pl b/bin/localstate.pl index d8e1f3d6f15ecea2ddfec042fd9ffcf9287934b2..f3af0d1d20a2031c89afb18c90c6ae5c0324c3fc 100755 --- a/bin/localstate.pl +++ b/bin/localstate.pl @@ -264,7 +264,7 @@ if ( $result ) my $i = 0; if ( scalar @$result ) { - foreach my $account ( sort @$result ) + foreach my $account ( @$result ) { my $maymine = ''; $maymine = 'sealer' diff --git a/bin/mayseal.js b/bin/mayseal.js deleted file mode 100755 index 0cee239a79a0990802f9dfc6ba83142b2e8dd98a..0000000000000000000000000000000000000000 --- a/bin/mayseal.js +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/node -// vim:syntax:filetype=javascript:ai:sm -// vim:expandtab:backspace=indent,eol,start:softtabstop=4 - -"use strict" - -const Libbfa = require( process.env.BFAHOME + '/bin/libbfa.js'); - -function mayseal() -{ - var bfa = new Libbfa(); - var web3 = bfa.newweb3(); - var me = web3.eth.defaultAccount.toLowerCase(); - web3.eth.isMining().then( function(isMining){ - web3.eth.getSigners().then( function(x){ - var lcsealers = x.map( name => name.toLowerCase() ); - // console.log( "Miners are:\n\t" + lcsealers.join("\n\t") ); - var isSigner = (lcsealers.indexOf(me) > -1); - var sealerfile = bfa.nodedir + '/miner'; - var not = "not "; - if ( isSigner ) - not = ""; - console.log( "Account " + me + " is " + not + "allowed to seal." ); - if ( isSigner ) - { - if ( ! bfa.fs.existsSync( sealerfile ) ) - { - var fd = bfa.fs.openSync( sealerfile, 'a' ); - bfa.fs.close( fd ); - console.log( "Created 'sealer' file " + sealerfile ); - } - if ( ! isMining ) - { - web3.eth.minerstart(); - console.log( 'Started to seal.' ); - } - else - { - console.log( "You are already sealing. All is well." ); - } - } - else - { - if ( bfa.fs.existsSync( sealerfile ) ) - { - bfa.fs.unlinkSync( sealerfile ); - console.log( "Deleted 'sealer' file " + sealerfile ); - } - if ( isMining ) - { - web3.eth.minerstop(); - console.log( 'I was trying to seal, but am not authorized. Stopped trying.' ); - } - else - { - console.log( "I wasn't trying to seal anyway. All is well." ); - } - } - }); - },function(x){ - console.log(x); - process.exit(1); - }) -} - -mayseal(); diff --git a/bin/singlestart.sh b/bin/singlestart.sh index a00962e11aeffb5b7eba180ba9924f8afa14369c..d8fb623bf88304d2e37b56e60295157ae28a5174 100755 --- a/bin/singlestart.sh +++ b/bin/singlestart.sh @@ -88,7 +88,8 @@ PIDIDX[$!]="log.sh" exec > ${LOGPIPE} 2>&1 echo "*** Starting geth." -geth --config ${BFATOML} --gcmode archive --verbosity ${BFAVERBOSITY:-3} --allow-insecure-unlock & +# "NoPruning=true" means "--gcmode archive" +geth --config ${BFATOML} & PIDIDX[$!]="geth" # bootnode diff --git a/bin/start.sh b/bin/start.sh index 182bedb46d3c31fd4a55603b557fece2d4ecbcb3..4fc9770e1f830235080a87b1fb2eebfd0bdefb53 100755 --- a/bin/start.sh +++ b/bin/start.sh @@ -126,29 +126,12 @@ function geth_args # (re)configure parameters (you never know if they changed) flexargs="$( getsyncmode )" geth_capab - xtra=$( extradata ) - if [ -n "$xtra" ] - then - flexargs="${flexargs} --extradata $( extradata )" - fi - unset xtra # - if [ "$netport" != 30303 ] - then - flexargs="${flexargs} --port $netport" - fi - if [ "$rpcport" != 30303 ] - then - flexargs="${flexargs} --rpcport $rpcport" - fi - if [ -n "$BFAVERBOSITY" -a "$BFAVERBOSITY" != 3 ] - then - flexargs="${flexargs} --verbosity ${BFAVERBOSITY:-3}" - fi # the basic modules - rpcapis="eth,net,web3,clique" + local rpcapis="eth,net,web3,clique" if [ -e "${BFANODEDIR}/opentx" ] then + local txhostnames dummy # If you want other hostnames, put them in this file (comma separated) read txhostnames dummy < ${BFANODEDIR}/opentx if [ "${txhostnames}" = "" ] diff --git a/bin/walker.pl b/bin/walker.pl index 5dfd3f566144672157d3b4ca300e7971b283ff96..292dd77abf6cc15c388031e88676f79aa3713b4c 100755 --- a/bin/walker.pl +++ b/bin/walker.pl @@ -74,7 +74,7 @@ sub hex2string($) sub rpcreq { my ( $opname, @params ) = @_; - my $req = HTTP::Request->new( POST => 'http://127.0.0.1:' . $libbfa->{'rpcport'} ); + my $req = HTTP::Request->new( POST => 'http://127.0.0.1:8545' ); $req->content_type('application/json'); my $extra = scalar @params ? sprintf(qq(,\"params\":[%s]), join(',', @params)) diff --git a/network/config.toml b/network/config.toml index a414c48626596514c5fe46215a1753fda1fc7ecd..3c85b8b76d7e21a10f27b320aadfd3a00914b4d1 100644 --- a/network/config.toml +++ b/network/config.toml @@ -60,10 +60,10 @@ omitempty = "" IPCPath = "geth.ipc" HTTPPort = 8545 HTTPVirtualHosts = ["localhost"] -HTTPModules = ["net", "web3", "eth", "shh", "clique", "admin", "miner", "personal"] +HTTPModules = ["net", "web3", "eth", "clique"] WSHost = "127.0.0.1" WSPort = 8546 -WSModules = ["net", "web3", "eth", "shh", "clique", "admin", "miner", "personal"] +WSModules = ["net", "web3", "eth", "clique"] GraphQLPort = 8547 GraphQLVirtualHosts = ["localhost"] diff --git a/test2network/config.toml b/test2network/config.toml index e94490c8fec451628446f3767b82b9e161f0e3c7..1d776baf40a50b3019f58a2efdafe2c0551676a9 100644 --- a/test2network/config.toml +++ b/test2network/config.toml @@ -54,16 +54,16 @@ RestrictConnectionBetweenLightClients = true [Node] DataDir = "/home/bfa/bfa/test2network/node" -HTTPHost = "127.0.0.1" +HTTPHost = "0.0.0.0" HTTPCors = ["*"] omitempty = "" IPCPath = "geth.ipc" HTTPPort = 8545 HTTPVirtualHosts = ["localhost"] -HTTPModules = ["net", "web3", "eth", "shh", "clique", "admin", "miner", "personal"] -WSHost = "127.0.0.1" +HTTPModules = ["net", "web3", "eth", "clique"] +WSHost = "0.0.0.0" WSPort = 8546 -WSModules = ["net", "web3", "eth", "shh", "clique", "admin", "miner", "personal"] +WSModules = ["net", "web3", "eth", "clique"] GraphQLPort = 8547 GraphQLVirtualHosts = ["localhost"]