diff --git a/README.md b/README.md index e3ccd343d0390618587ec358ee6b45e2db5a6a35..2f5023738240afe205561931a63ae48a9972a782 100644 --- a/README.md +++ b/README.md @@ -1,82 +1,61 @@ # Blockchain Federal Argentina -## TEST NETWORK -## Official URL: https://gitlab.bfa.ar/blockchain/nucleo +## Website: https://www.bfa.ar/ +## Repo: https://gitlab.bfa.ar/blockchain/nucleo.git 1. Install geth - For Debian read doc/compiling-geth-on-debian.txt - For Ubuntu read doc/installing-geth-on-ubuntu.txt -2. `sudo apt install jq ncurses-bin curl` -3. `git clone https://github.com/rlegene/bfa.git` +2. Install packages: + - `sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 68576280` + - `sudo apt-add-repository "deb https://deb.nodesource.com/node_7.x $(lsb_release -sc) main"` + - `sudo apt-get update` + - `sudo apt install jq ncurses-bin curl` + - `sudo apt-get install nodejs` + - `npm init -y` + - `npm install web3` +3. Install the BFA software: + - `git clone https://gitlab.bfa.ar/blockchain/nucleo.git` 4. `source ${HOME}/bfa/bin` - - You can include this line in your .bash_profile if you want. - - It is perfectly safe to source it multiple times. -5. Install this crontab: `@reboot bfa/bin/cron.sh` - - If you are running a sealer you MUST do this. -6. run `start.sh`. This will start synchronizing and probably takes at least an hour. + - You can include this line in your .bash_profile if you want. It is perfectly safe to source it multiple times. + - `echo 'source ${HOME}/bfa/bin' > ~/.bashrc` +5. Add crontab to start on system reboot (if you are running a sealer you MUST do this): + - `crontab -l 2>/dev/null | (grep -v bfa/bin/cron ; echo '@reboot bfa/bin/cron.sh') | crontab -` +6. run `start.sh`. This will start synchronizing and takes some time. This is normally done from cron on system restart. +7. Monitor the logs with `bfalog.sh`. Press CTRL-C at any time to stop the `tail -f`. 7. Change your node's settings with `syncmode.sh` - Do this before you have synced too much in the step before, as it might remove all your downloaded chain data and restart synchronizing the chain. 8. Wait for it to finish synchronizing. -9. Run `maymine.sh` to update your configuration (detects if you are allowed to seal/mine or not). -10. Get some Ether from someone. Once you have some, you can try: - - Create your contract (there is already one deployed, but you can "overwrite" it with your own) - - Type lines of text into `tsa-insert.sh` (end with ctrl-D) -11. Free things to do with the BFA: - - Verify that the checksum has been seen with `tsa-verify.sh "<yourtexthere>"` - - If the text can not be found, it is because your insert transaction still isn't in the blockchain. Wait a bit and try again. - - Try the basic `explorer.sh`. It follows "latest" by default, but you can specify a block number as argument, e.g. `explorer.sh 0` to see genesis (block 0). - - Try out `walker.pl` -12. Install node.js so you can do better scripts locally: - `sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 68576280` - `sudo apt-add-repository "deb https://deb.nodesource.com/node_7.x $(lsb_release -sc) main"` - `sudo apt-get update` - `sudo apt-get install nodejs` - `npm init -y` - `npm install web3` - -There are other "interesting" programs in the bin/ and src/ directories. +9. Run `maymine.sh` to update your configuration (detects if you are allowed to seal/mine or not). You can run this as often as you wish. If you try to mine/seal but is not allowed, your log will show errors (but no harm done). +11. Simple super basic tools (more actual proof of concepts, to inspire programmers): + - `explorer.sh` : It follows "latest" by default, but you can specify a block number as argument, e.g. `explorer.sh 0` to see genesis (block 0). + - `walker.pl` : Also takes a blocknumber to start from. Keeps waiting for new blocks. + +There are other "interesting" programs in the bin/ and src/ directories, but for developers, probably the `dev` branch is more interesting. ## start.sh -requires: **geth** -Starts a node on the 5445 BFA test net. Creates a genesis.json if you don't have one already. -One is already included in this package, which will allow you to connect to the existing BFA testnet. +Starts a node for you on the BFA Ethereum net. ## attach.sh -request: **geth** -Connects you to your running local geth. +Connects you to the CLI of your running local geth (fails if it is not already running). ## compile.and.deploy.contract -requires: **geth**, **solc**, **jq** -Compiles and deploys a contract to the blockchain. A local "node1" must already be running and synchronized. +Compiles and deploys a contract to the blockchain. A local account must already have ether to pay for the tx. Argument 1 is the filename of the contract to compile. Example: `compile.and.deploy.contract src/TimestampAuthority.sol` -## tsa-insert.sh -requires: **geth** - -Inserts the checksum of a text into the TSA. - -## tsa-verify.sh -requires: **geth** - -Returns the first blocknumber where the SHA256 checksum of a text was seen. The timestamp can then be found in the block (with `explorer.sh` for instance). - ## explorer.sh -requires: **curl**, **jq**, **tput** _(ncurses-bin)_, _(curl)_ Simple script to look at blocks -## src/TimeStampAuthority.sol - -The initial Timestamp service. - ## walker.pl -requires: **geth**, **perl**, __(libjson-perl)__ + +Shows one line per block being sealed in the network, then waits for the next block. ## rewind.sh @@ -94,3 +73,19 @@ the output from `geth` into `log.sh`, so we still can read the log. ## sendether.sh If you wish to give someone Ether, this script might be useful. + +## MasterDistiller.js + +Manages a deployed Distiller contract. It'll show registered users and their +set "allowance". + +## sealeradd.sh / sealerrem.sh + +When a sealer operator votes to promote or demote a sealer, this script +does most of the typing. Takes a single argument, being the account number +of the sealer which is being voted for. + +## monitor.sh + +This is being run every minute from `cron.sh`. It will update a file +in `network/status` showing very basic network information. diff --git a/bin/bfalog.sh b/bin/bfalog.sh index 69701e18e3be634005fd28e595aaaed6d058161c..e387b0d02c8ee73e384f0798ab983f58fd53d777 100755 --- a/bin/bfalog.sh +++ b/bin/bfalog.sh @@ -4,5 +4,4 @@ if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/env ?" >&2; exit 1; fi source ${BFAHOME}/bin/libbfa.sh || exit 1 -bfaconfig node exec tail -n 100 -F ${BFANODEDIR}/log diff --git a/bin/checkreceipt.sh b/bin/checkreceipt.sh deleted file mode 100755 index d58cdacf06b7be943da04622008631857f41ec35..0000000000000000000000000000000000000000 --- a/bin/checkreceipt.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/env ?" >&2; exit 1; fi -source ${BFAHOME}/bin/libbfa.sh || exit 1 - -geth_exec "eth.getTransactionReceipt(\"$1\");" < /dev/null diff --git a/bin/compile.and.deploy.contract b/bin/compile.and.deploy.contract index f7a36c0ff88ab9452775a3aa6278b2b18678fe59..bb1d8abe2fe0d1fd8d0485062ea8c44b117f6592 100755 --- a/bin/compile.and.deploy.contract +++ b/bin/compile.and.deploy.contract @@ -32,7 +32,7 @@ var address = rcpt.contractAddress var pubcontract = mycontract.at(address) console.log( pubcontract.address ) EOT - echo '*** Creating contract. This will take at least 16 seconds.' + echo '*** Creating contract. Be patient.' outfile=$( mktemp ) cleanup "$outfile" geth_exec_file $js > $outfile @@ -65,6 +65,5 @@ contractname=${filename%%.sol} contractname=${contractname##*/} contractname=${contractname##contract.} contractname=${contractname%.*} -bfaconfig max prereq jq solc geth create diff --git a/bin/env b/bin/env index 2139b8492cfa7cc8b1fb1db458bc2c8b657b5cc1..0e4334c442b77c5d5aa927ccc1f067f472951ebe 100644 --- a/bin/env +++ b/bin/env @@ -1,4 +1,4 @@ export BFAHOME=${HOME}/bfa -export BFANETWORKDIR="${BFAHOME}/network5445" -export BFANETWORKID=5445 +export BFANETWORKID=47525974938 +export BFANETWORKDIR="${BFAHOME}/network" PATH=${PATH}:${BFAHOME}/bin diff --git a/bin/explorer.sh b/bin/explorer.sh index 10b69ea870ada6706cd75b3d35bdbef8569bb9e8..a343b885b9713c9b3d4f907f89dc81813d87c0f4 100755 --- a/bin/explorer.sh +++ b/bin/explorer.sh @@ -4,7 +4,6 @@ if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/env ?" >&2; exit 1; fi source ${BFAHOME}/bin/libbfa.sh || exit 1 -bfaconfig max prereq tput curl cd "${BFANETWORKDIR}" width=$( tput cols ) diff --git a/bin/libbfa.js b/bin/libbfa.js index 4af1f4172993f9c9531d5fb07ae92c9591ee299f..1308def06894ad6f04c96628db3cd60be8b9ee96 100644 --- a/bin/libbfa.js +++ b/bin/libbfa.js @@ -5,117 +5,41 @@ module.exports = class Libbfa constructor() { this.fs = require('fs'); this.Web3 = require('web3'); - this._account(); - } - - fatal( txt ) - { - console.log( txt ); - process.exit( 1 ); - } - - _home() - { - if ( this.home != undefined ) - return; - if ( process.env.BFAHOME == undefined ) + // + // BFAHOME + if ( undefined == process.env.BFAHOME ) fatal( "$BFAHOME not set. Did you source bfa/bin/env ?" ); - this.home = process.env.BFAHOME; - } - - _getnetworkid() - { - if ( this.networkid != undefined ) - return; - this._home(); - if ( process.env.BFANETWORKID == undefined ) + // BFANETWORKID + if ( undefined == process.env.BFANETWORKID ) + process.env.BFANETWORKID= 47525974938; + // BFANETWORKDIR + if ( undefined == process.env.BFANETWORKDIR ) + process.env.BFANETWORKDIR = process.env.BFAHOME + '/network'; + // BFANODEDIR + if ( undefined == process.env.BFANODEDIR ) + process.env.BFANODEDIR = this.networkdir + "/node"; + // ACCOUNT + if ( undefined == process.env.BFAACCOUNT ) { - var netw = new Array(); - this.fs.readdirSync( this.home ).forEach( function(file){ - if ( file.startWith('network') ) - netw.push( 0 + file.substring(7) ); + var files = new Array(); + this.fs.readdirSync( process.env.BFANODEDIR + '/keystore' ).forEach( function(filename) { + if ( filename.includes('--') ) + files.push( filename ); }); - if ( netw.length == 0 ) - fatal( "Can't determine your network ID." ); - netw.sort(); - process.env.BFANETWORKID= - this.networkid = netw[0]; + // found none? + if ( files.length == 0 ) + fatal( "Found no accounts in your keystore." ); + files.sort(); + process.env.BFAACCOUNT = '0x' + files[0].replace( /^.*--/, '' ); } - else - this.networkid = process.env.BFANETWORKID; - } - - _networkdir() - { - if ( this.networkdir != undefined ) - return; - this._getnetworkid(); - if ( process.env.BFANETWORKDIR == undefined ) - process.env.BFANETWORKDIR = - this.networkdir = process.env.BFAHOME + '/network' + process.env.BFANETWORKID; - else - this.networkdir = process.env.BFANETWORKDIR; - } - - _nodedir() - { - if ( this.nodedir != undefined ) - return; - this._networkdir(); - if ( this.networkdir == undefined ) - return; - if ( process.env.BFANODEDIR == undefined ) - { - var dirs = new Array(); - //var fs = this.fs; - var nwdir = this.networkdir; - this.fs.readdirSync( this.networkdir ).forEach( - function findnodedirs(f1) { - var name1 = [nwdir,f1].join('/'); - var fs = require('fs'); - if ( fs.statSync( name1 ).isDirectory() ) - { - fs.readdirSync( name1 ).forEach( - function lookforkeystores(f2) { - var name2 = [nwdir,f1,f2].join('/'); - if (f2 == "keystore" && fs.statSync( name2 ).isDirectory() ) - { - dirs.push( name1 ); - } - } - ) - } - } - ); - if ( dirs.length == 0 ) - return; - dirs.sort(); - process.env.BFANODEDIR = - this.nodedir = dirs[0]; - } - else - this.nodedir = process.env.BFANODEDIR; - this.netport = Number.parseInt( this.fs.readFileSync( this.nodedir + '/netport' ) ); - this.rpcport = Number.parseInt( this.fs.readFileSync( this.nodedir + '/rpcport' ) ); - } - - _account() - { - this._nodedir(); - if ( this.acct != undefined ) - return; - if ( process.env.BFANODEDIR == undefined ) - return; - var files = new Array(); - this.fs.readdirSync( process.env.BFANODEDIR + '/keystore' ).forEach( function(filename) { - if ( filename.includes('--') ) - files.push( filename ); - }); - // found none? - if ( files.length == 0 ) - return; - files.sort(); - this.account = '0x' + files[0].replace( /^.*--/, '' ); + // + this.home = process.env.BFAHOME; + this.networkid = process.env.BFANETWORKID; + this.networkdir = process.env.BFANETWORKDIR; + this.nodedir = process.env.BFANODEDIR; + 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; } contract(w3, name) @@ -123,17 +47,23 @@ module.exports = class Libbfa this._networkdir(); var contractdir = [ this.networkdir, 'contracts', name ].join('/'); var contractaddress = this.fs.realpathSync( contractdir ).replace(/^.*\//, ''); - if ( contractaddress == undefined ) + if ( undefined == contractaddress ) return; var abi = JSON.parse( this.fs.readFileSync( contractdir + '/abi' ).toString() ); - if ( abi == undefined ) + if ( undefined == abi ) return; var c = new w3.eth.Contract( abi, contractaddress ); c.abi = abi; c.contractaddress = contractaddress; - return c; + return c; + } + + fatal( txt ) + { + console.log( txt ); + process.exit( 1 ); } newweb3() @@ -158,4 +88,11 @@ module.exports = class Libbfa isAddr(n) { return n.length == 42 && n.substring(0,2) == "0x"; } + + setfromfile( filename, defval ) + { + if ( this.fs.statSync( filename ).isFile() ) + return this.fs.readFileSync( filename ); + return defval; + } } diff --git a/bin/libbfa.sh b/bin/libbfa.sh index f949c4943e649ec41a63e825c5a2503bb790a920..22d2e4e0449106af7301b76dc5a3ec57d71acaa2 100644 --- a/bin/libbfa.sh +++ b/bin/libbfa.sh @@ -34,23 +34,12 @@ function cleanup function geth_attach { - bfaconfig node -# local cat=cat -# if echo $- | grep -q x -# then -# cat="tee /dev/tty |" -# fi -# $cat | geth --cache 0 "$@" attach ipc:${BFANODEDIR}/geth.ipc } function geth_exec_file { test -r "$1" - if echo $- | grep -q x && [ -t 1 ] - then - sed "s/^/input: /" "$1" - fi geth_attach --exec "loadScript(\"$1\")" </dev/null } @@ -62,7 +51,6 @@ function geth_exec function geth_rpc { - bfaconfig node local cmd=$1 test -n "$cmd" local params= @@ -75,7 +63,7 @@ function geth_rpc params="${params}${1}," shift done - # Eat the last command and add a ] + # Eat the last comma and add a ] params=${params/%,/]} fi local json=$( @@ -95,155 +83,21 @@ function geth_rpc echo "$json" | jq .result } -function getnetworkid -{ - test -n "${BFANETWORKID}" && - return - local dir="${BFANETWORKDIR}" - for dir in $( ls -1d "${BFAHOME}"/* | sort --version-sort ) - do - if [ -d "${dir}" ] - then - local base=$( basename "${dir}" ) - base=$( echo "${base}" | grep -E '^network[0-9]+$' ) || true - if [ -n "${base:7}" ] - then - BFANETWORKID=${base:7} - return - fi - fi - done -} - -function networkdir -{ - test -n "${BFAHOME}" -a -d "${BFAHOME}" || - fatal "\$BFAHOME in your environment must point to a directory." - # If no BFANETWORKDIR variable has been set, we will try to guess - # the network directory based on the directory we are in. - if [ -z "${BFANETWORKDIR}" ] - then - BFANETWORKDIR=$( - ls -1d "${BFAHOME}"/* | - grep -qE '/network[0-9]+$' | - sort --version-sort | - head -1 - ) - fi - test -n "${BFANETWORKDIR}" -a ! -d "${BFANETWORKDIR}" && - fatal "\$BFANETWORKDIR (\"${BFANETWORKDIR}\") not found." - if [ -z "${BFANETWORKDIR}" -o ! -d "${BFANETWORKDIR}" ] - then - local num=0 - while [ $num -lt 9876 ] - do - num=$(( $RANDOM * $RANDOM )) - done - stderr "I can not find your BFANETWORKDIR." - stderr "Consider running: mkdir ${BFAHOME}/network${num} or set BFANETWORKDIR in ${BFAHOME}/bin/env" - exit 1 - fi - getnetworkid - gen_genesis -} - -function nodedir -{ - networkdir - # set defaults - if [ -z "$BFANODEDIR" ] - then - # If there is no nodedir found, use the first node we - # find in the networkdir - BFANODEDIR=$( - ls -1d "${BFANETWORKDIR}"/*/keystore 2>/dev/null | - sort --version-sort | - head -1 - ) - if [ -z "${BFANODEDIR}" ] - then - BFANODEDIR="${BFANETWORKDIR}/node1" - echo "No node directories found. Initialising a new node." - geth --datadir ${BFANODEDIR} init ${BFAHOME}/src/genesis.json - else - # Get rid of the "keystore" label - BFANODEDIR=$( dirname $BFANODEDIR ) - fi - fi - test -n "${BFANODEDIR}" || - fatal "Unable to guess \$BFANODEDIR . Consider setting it explicitly in ${BFAHOME}/bin/env" - test -d "${BFANODEDIR}" || - fatal "$BFANODEDIR is not a directory." - test -d "${BFANODEDIR}/geth/chaindata" || - fatal "Node is not initialised. Consider running: geth --datadir $BFANODEDIR init ${BFAHOME}/src/genesis.json" - # Support migrating from "former" setups - if [ -r "${BFANODEDIR}/port" -a ! -r "${BFANODEDIR}/netport" ] - then - mv "${BFANODEDIR}/port" "${BFANODEDIR}/netport" - fi - # - test -r "${BFANODEDIR}/netport" || - echo $(( $RANDOM / 2 + 12345 )) > ${BFANODEDIR}/netport - netport=$( cat ${BFANODEDIR}/netport ) - test $? = 0 - test -r "${BFANODEDIR}/rpcport" || - echo $(( $RANDOM / 2 + 12345 )) > ${BFANODEDIR}/rpcport - rpcport=$( cat ${BFANODEDIR}/rpcport ) -} - function extradata { - account # 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}' ) + 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 "${account:0:19}.${mymac:0:12}" -} - -function account -{ - nodedir - if [ -z "$account" ] - then - test -d "${BFANODEDIR}/keystore" - account=$( - ls -1dl "${BFANODEDIR}"/keystore/*--* 2>/dev/null | - head -1 | - sed 's/.*--//' - ) - fi - if [ -z "$account" ] - then - echo "No accounts found. Creating a new one (they are free)." - geth --datadir ${BFANODEDIR} --password /dev/null account new - if [ -n "$loop_protection" ] - then - fatal "Loop detected." - fi - loop_protection=1 - account - fi - unset loop_protection -} - -function bfaconfig -{ - case "$1" in - network) - networkdir - ;; - node) - nodedir - ;; - account|max) - account - ;; - *) - fatal "Unknown bfaconfig request" - ;; - esac + echo -n "${BFAACCOUNT:0:19}.${mymac:0:12}" } function prereq @@ -261,57 +115,8 @@ function prereq test $err -eq 0 } -function gen_genesis -{ - local genesis="${BFAHOME}/src/genesis.json" - test -e "${genesis}" && - return - bfaconfig account - local zero4="0000" - local zero8="${zero4}${zero4}" - local zero16="${zero8}${zero8}" - local zero20="${zero16}${zero4}" - local zero32="${zero16}${zero16}" - local zero40="${zero20}${zero20}" - local zero60="${zero40}${zero20}" - local zero64="${zero32}${zero32}" - local zero128="${zero64}${zero64}" - local zero130="${zero128}00" - local nodes=$account - local timestamp=$( printf '0x%08x' $( date +%s ) ) - local vanity_Blockchain="426c6f636b636861696e" - local vanity_Federal="4665646572616c" - local vanity_Argentina="417267656e74696e61" - local vanity_NIC="4e4943" - local vanity="${vanity_Blockchain}20${vanity_Federal}20${vanity_Argentina}20${vanity_NIC}" - ## Make sure vanity is exactly 64 characters - vanity="${vanity}${zero64}" - vanity="${vanity:0:64}" - echo -n "$vanity" | grep -Evq '[^0-9a-fA-F]' - cat <<-EOCONF > ${genesis} - { - "config": { - "chainId": ${BFANETWORKID}, - "homesteadBlock": 0, "eip150Block": 0, "eip155Block": 0, "eip158Block": 0, "byzantiumBlock": 4, - "eip150Hash": "0x${zero64}", - "clique": { "period": 15, "epoch": 30000 } - }, - "nonce": "0x0000000000000000", - "timestamp": "${timestamp}", - "extraData": "0x${vanity}${account}${zero130}", - "gasUsed": "0x0", "gasLimit": "0xffeeddcc", "difficulty": "0x1", - "number": "0x0", - "mixHash": "0x${zero64}", - "coinbase": "0x${zero40}", - "parentHash": "0x${zero64}", - "alloc": { "${account}": { "balance": "0x200${zero60}" } } - } - EOCONF -} - function contract { - bfaconfig network local contract="${BFANETWORKDIR}/contracts/${1}" local realdir=$( realpath "${contract}" ) test -r "${realdir}" @@ -341,3 +146,60 @@ 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}" ] + then + echo "Node directory not found. Initialising a new node." + geth --datadir ${BFANODEDIR} init ${BFAHOME}/src/genesis.json + fi + if [ ! -d "${BFANODEDIR}/geth/chaindata" ] + then + echo "Node is not initialised. Initialising with BFA genesis." + geth --datadir "${BFANODEDIR}" init "${BFAHOME}/src/genesis.json" + fi + # + # netport + netport=30303 + if [ -r "${BFANODEDIR}/netport" ] + then + netport=$( cat ${BFANODEDIR}/netport ) + test $? = 0 + fi + # + # rpcport + rpcport=8545 + if [ -r "${BFANODEDIR}/rpcport" ] + then + rpcport=$( cat ${BFANODEDIR}/rpcport ) + test $? = 0 + fi + # + # BFAACCOUNT + if [ -z "$BFAACCOUNT" ] + then + if [ ! -d "${BFANODEDIR}/keystore" ] + then + echo "No accounts found. Creating a new one (they are free)." + geth --cache 0 --datadir ${BFANODEDIR} --password /dev/null account new + fi + BFAACCOUNT=$( + ls -1dl "${BFANODEDIR}"/keystore/*--* 2>/dev/null | + head -1 | + sed 's/.*--//' + ) + fi diff --git a/bin/maymine.sh b/bin/maymine.sh index 594455c6220e8b2eb7551334f33ab929fbbce830..ca5daa6d7a68bc00a5e1304dfdb3bda6c7c570bf 100755 --- a/bin/maymine.sh +++ b/bin/maymine.sh @@ -4,7 +4,6 @@ if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/env ?" >&2; exit 1; fi source ${BFAHOME}/bin/libbfa.sh || exit 1 -bfaconfig node res=$( geth_exec_file "${BFAHOME}/src/maymine.js" ) if [ "$res" = "true" ] diff --git a/bin/monitor.sh b/bin/monitor.sh index ab3f83f8221acd9c26d359ebb9690c80a3004d33..50665ca7bb6201419b13d237849f686734c54bb9 100755 --- a/bin/monitor.sh +++ b/bin/monitor.sh @@ -31,7 +31,6 @@ function json_result echo "$json" | jq -r '.result' } -bfaconfig node json_query admin_peers numpeers=$( json_result | json_arraylength ) statusfile=$( mktemp ) diff --git a/bin/numpending.sh b/bin/numpending.sh deleted file mode 100755 index cd77368f44364e85c31ad97b613c7a9abcf0616f..0000000000000000000000000000000000000000 --- a/bin/numpending.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/env ?" >&2; exit 1; fi -source ${BFAHOME}/bin/libbfa.sh || exit 1 - -echo txpool.status.pending | geth_attach | grep -Ev '^> $' | tail -1 -exit - - -function json_query -{ - cmd=$1 - params=$2 - if [ -n "$params" ] - then - params=",\"parameters\":[$2]" - fi - json=$( - curl -s -H 'Content-type: application/json' -X POST --data "{\"jsonrpc\":\"2.0\",\"method\":\"${cmd}\"${params},\"id\":1}" http://127.0.0.1:$rpcport - ) -} - -bfaconfig node -json_query web3j_txpool -echo $json | jq -exit - diff --git a/bin/start.sh b/bin/start.sh index be39a51ee53e94b046def0d93a9cea23f062c2e0..d1d9e09786847aea4adbc66d017ab4f0c5d87aa1 100755 --- a/bin/start.sh +++ b/bin/start.sh @@ -6,11 +6,9 @@ source ${BFAHOME}/bin/libbfa.sh || exit 1 bootnodeid=6c81b38551fec2f1142b58ed65137cc1b7dfdc7b35bc556ef26604c41e30fcdeb12212b3c19913584f71dc7bf87d76cd67fa523e96996c0f148390fb76fdc5f7 bootnodev6=2800:40:1:6::135 bootnodev4=200.68.65.135 -bootnodeport=5445 +bootnodeport=30301 bootnodes="enode://${bootnodeid}@[$bootnodev6]:${bootnodeport},enode://${bootnodeid}@[$bootnodev4]:${bootnodeport}" -bfaconfig max - function accountlist { local accts= @@ -65,18 +63,13 @@ function getsyncmode set -x geth \ --datadir ${BFANODEDIR} \ - --networkid $BFANETWORKID \ + --networkid ${BFANETWORKID} \ --bootnodes "${bootnodes}" \ --rpc \ --rpcport $rpcport \ --rpcapi "eth,net,web3,admin,clique,miner,personal" \ --port $netport \ --nousb \ - --txpool.nolocals \ - --txpool.accountslots 128 \ - --txpool.globalslots 32768 \ - --txpool.accountqueue 512 \ - --txpool.globalqueue 8192 \ --gcmode archive \ --cache 512 \ --verbosity 3 \ diff --git a/bin/syncmode.sh b/bin/syncmode.sh index 009d260899f968f030e86c503a46ec7bc4c8d9bf..21035d445fba75cef43c409e5d3a83abd63f9dd3 100755 --- a/bin/syncmode.sh +++ b/bin/syncmode.sh @@ -31,7 +31,6 @@ function modefilter true } -bfaconfig node mode=$( cat ${BFANODEDIR}/syncmode 2>/dev/null || true ) mode=${mode:-${defaultmode}} orgmode=$mode diff --git a/bin/transactors.pl b/bin/transactors.pl deleted file mode 100755 index d5018b0a1aa1db91e731d40400da6583f0ebc233..0000000000000000000000000000000000000000 --- a/bin/transactors.pl +++ /dev/null @@ -1,262 +0,0 @@ -#!/usr/bin/perl -w - -use strict; -use warnings; -use IO::File; -use Math::BigInt; -use Carp; -$Carp::Verbose = 1; - -die "\$BFAHOME not set. Did you source bfa/bin/env ?\n" - unless exists $ENV{BFAHOME}; -chdir "$ENV{BFAHOME}" or die $!; - -package tools; -my $rpcport; -my $ua = LWP::UserAgent->new; - -sub new -{ - my $class = shift; - return bless {@_}, ref $class || $class; -} - -sub wait -{ - my $i = ++$_[0]->{'wait'}; - printf "%s%c[D", substr('|/-\\', $i%4, 1), 27; - sleep 1; -} - -sub cat($) -{ - my ($filename) = @_; - my $fh = IO::File->new($filename) or return; - return join('', $fh->getlines); -} - -sub hex2string($) -{ - my ($msg)=@_; - my $txt = ''; - while ($msg ne '') - { - my $i=hex( substr($msg,0,2) ); - my $c='.'; - $c=chr($i) if $i >= 32 and $i <= 127; - $txt .= $c; - $msg=substr $msg, 2; - } - return $txt; -} - -sub rpcreq -{ - my ( $opname, @params ) = @_; - if ( not defined $rpcport ) - { - $rpcport = tools::cat "$ENV{BFAHOME}/network5445/node1/rpcport" or die; - } - my $req = HTTP::Request->new( POST => "http://127.0.0.1:$rpcport" ); - $req->content_type('application/json'); - my $extra = scalar @params - ? sprintf(qq(,\"params\":[%s]), join(',', @params)) - : ''; - $req->content( qq({"jsonrpc":"2.0","method":"${opname}"${extra},"id":1})); - my $res = $ua->request($req); - die $res->status_line - unless $res->is_success; - return $res->content; -} - -package balance; -use JSON; - -sub new -{ - my ($class, $acct, $at) = @_; - my $self = bless {}, ref $class || $class; - $self->get( $acct, $at ) if defined $acct; - return $self; -} - -sub acct -{ - my ($self, $acct) = @_; - if ( defined $acct ) - { - $acct = '0x'.$acct if $acct !~ /^0x/; - $self->{'_acct'} = $acct; - } - return unless exists $self->{'_acct'}; - return $self->{'_acct'}; -} - -sub at -{ - my ($self, $at) = @_; - $self->{'_at'} = $at if defined $at; - return sprintf('0x%x', $self->{'_at'}) if exists $self->{'_at'}; - return 'latest'; -} - -sub get -{ - my ($self, $acct, $at) = @_; - $self->acct($acct) if defined $acct; - $self->at($at) if defined $at; - my @params = ( sprintf(qq("%s","%s"),$self->acct,$self->at) ); - my $content = tools::rpcreq( 'eth_getBalance', @params ); - my $json; - eval { $json = decode_json( $content ) }; - my $error = error->new( $content ); - if ( $error ) - { - my $msg = ''; - return 'NOTFOUND' if $error->message =~ /^missing trie node /; - die join(' * ', @params, $content); - return; - } - die if not exists $json->{'result'}; - die if not defined $json->{'result'}; - return Math::BigInt->from_hex( $json->{'result'} ); -} - - -package error; -use JSON; - -sub new -{ - my ($class, $json_in) = @_; - my $json; - eval { $json = decode_json( $json_in ) }; - return unless defined $json; - return unless exists $json->{'error'}; - my $self = bless { - '_code' => undef, - '_message' => undef, - }, ref $class || $class; - $self->code( $json->{'error'}->{'code'} ) if exists $json->{'error'}->{'code'}; - $self->message( $json->{'error'}->{'message'} ) if exists $json->{'error'}->{'message'}; - return $self; -} - -sub code -{ - my ( $self, $val ) = @_; - $self->{'_code'} = $val if scalar @_ > 1; - return $self->{'_code'}; -} - -sub message -{ - my ( $self, $val ) = @_; - $self->{'_message'} = $val if scalar @_ > 1; - return $self->{'_message'}; -} - -package block; -use LWP; -use JSON; - -sub new -{ - my ( $class, $json_raw ) = @_; - return unless defined $json_raw; - return if $json_raw eq ''; - my $self = bless {}, ref $class || $class; - $self->{'json_raw'} = $json_raw; - eval { $self->{'json'} = decode_json( $json_raw ) }; - return if $@; - $self->error( error->new($json_raw) ); - return $self; -} - -sub error -{ - return if not exists $_[0]->{'error'}; - return $_[0]->{'error'}; -} - - -sub json -{ - return unless exists $_[0]->{'json'}; - return $_[0]->{'json'}; -} - -sub result -{ - return unless exists $_[0]->{'json'}->{'result'}; - return $_[0]->{'json'}->{'result'}; -} - -sub number -{ - return if not exists $_[0]->result->{'number'}; - return hex( $_[0]->result->{'number'} ); -} - -sub timestamp -{ - return if not exists $_[0]->result->{'timestamp'}; - return hex( $_[0]->result->{'timestamp'} ); -} - -sub miner -{ - return if not exists $_[0]->result->{'miner'}; - return $_[0]->result->{'miner'}; -} - -sub get($;$) -{ - my ($number) = @_; - $number = sprintf('0x%x', $number) if $number ne 'earliest'; - my $cachefile = "cache/block.$number"; - my $content = tools::rpcreq( 'eth_getBlockByNumber', qq("$number"), "true"); - my $block = block->new( $content ); - return if not defined $block; - return if not exists $block->{'json'}; - die $block->error->message - if $block->error; - return if not $block->result; - return $block; -} - -sub tx { - my ($self) = @_; - return $self->result->{'transactions'}; -} - -package main; - -my $number = shift || 'earliest'; -my $_rcpts; - -sub rcpt -{ - return 0 if exists $_rcpts->{$_[0]}; - $_rcpts->{$_[0]} = 1; - return 1; -} - -while ( 1 ) -{ - my $block = block::get($number); - exit 0 if not defined $block; -use Data::Dumper; print Dumper( $block->result ); -die $block->miner; - rcpt( $block->miner ); - my $txref = $block->tx; - for my $tx (@$txref) - { - my $from = $tx->{'from'}; - my $to = $tx->{'to'}; - my $value = $tx->{'value'}; - next if $value eq '0x0'; - printf "%s\n", $to if rcpt( $to ); - } - $number = $block->number + 1; -} diff --git a/bin/tsa-insert.sh b/bin/tsa-insert.sh deleted file mode 100755 index 1509e6d23d20aa04fae6bb23b086e9b15f6be112..0000000000000000000000000000000000000000 --- a/bin/tsa-insert.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash - -if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/env ?" >&2; exit 1; fi -source ${BFAHOME}/bin/libbfa.sh || exit 1 - -contract="TimeStampAuthority" -contract=${BFANETWORKDIR}/contracts/${contract} -contract=$( realpath "${contract}" ) -test -r "${contract}" -basecontract=$( basename "${contract}" ) -test -n "${basecontract}" -abi=$( cat ${BFANETWORKDIR}/contracts/${basecontract}/abi ) -test -n "${abi}" -hashes= -while read -p : -do - sum=$( echo -n "$REPLY" | sha256sum | cut -c -64 ) - echo $sum - hashes="$hashes,web3.toDecimal(\"0x$sum\")" -done -hashes="${hashes:1}" -echo $hashes -js=$( mktemp ) -cleanup "$js" -cat > $js <<EOT -var mycontract = eth.contract(${abi}) -var thecontract = mycontract.at("${basecontract}") -console.log( thecontract.put.sendTransaction( [${hashes}], {from: eth.accounts[0], gas: 1000000} ) ) -EOT -out=$( mktemp ) -cleanup "$out" -geth_exec_file "${js}" > ${out} -if [ ` wc -l < ${out} ` = 2 -a ` tail -1 < ${out} ` = "true" ] -then - trans=` head -1 < ${out} ` - echo "Sent checksum(s) in transaction ${trans}." -else - ( - cat ${js} - echo - echo ' ***' - echo - cat ${out} - ) >&2 - exit 1 -fi diff --git a/bin/tsa-verify.sh b/bin/tsa-verify.sh deleted file mode 100755 index c2a055d51e67b879f3d9b5ab781d70683ba0304d..0000000000000000000000000000000000000000 --- a/bin/tsa-verify.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash - -if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/env ?" >&2; exit 1; fi -source ${BFAHOME}/bin/libbfa.sh || exit 1 - -contract="TimeStampAuthority" -contract=${BFANETWORKDIR}/contracts/${contract} -contract=$( realpath "${contract}" ) -test -r "${contract}" -basecontract=$( basename "${contract}" ) -test -n "${basecontract}" -abi=$( cat ${BFANETWORKDIR}/contracts/${basecontract}/abi ) -test -n "${abi}" -hashes= -sum=$( echo -n "$1" | sha256sum | cut -c -64 ) -echo $sum -hashes="web3.toDecimal(\"0x$sum\")" -echo $hashes -js=$( mktemp ) -cleanup "$js" -cat > $js <<EOT -var mycontract = eth.contract(${abi}) -var thecontract = mycontract.at("${basecontract}") -console.log( thecontract.get.call( [${hashes}], {from: eth.accounts[0], gas: 1000000} ) ) -EOT -out=$( mktemp ) -cleanup "$out" -geth_exec_file "${js}" > ${out} -if [ ` wc -l < ${out} ` = 2 -a ` tail -1 < ${out} ` = "true" ] -then - block=` head -1 < $out ` - if [ "${block}" -gt "0" ] - then - echo "Checksum first seen in block ${block}" - else - echo "The checksum has not been stored in the smart contract yet." - exit 1 - fi -else - ( - cat ${js} - echo - echo ' ***' - echo - cat ${out} - ) >&2 -fi diff --git a/bin/txflood.sh b/bin/txflood.sh deleted file mode 100755 index 1d20bbde2ce66a82153c4194a86f6ca80db75979..0000000000000000000000000000000000000000 --- a/bin/txflood.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/env ?" >&2; exit 1; fi -source ${BFAHOME}/bin/libbfa.sh || exit 1 - -cd $BFAHOME - -while : -do - while num=` $BFAHOME/bin/numpending.sh `; [ $num -lt 2500 ] - do - contract=$( readlink ${BFANETWORKDIR}/contracts/TimestampDocument ) - abi=$( cat ${BFANETWORKDIR}/contracts/${contract}/abi ) - ( - echo "var mycontract = eth.contract(JSON.parse($abi));" - echo "var thecontract = mycontract.at(\"$contract\");" - n=0 - SECONDS=0 - while [ $n -lt 10000 -a $SECONDS -lt 600 ] - do - n=$(( $n + 1 )) - echo "thecontract.storeDocument.sendTransaction( \"dagenidag.${n}\", {from: eth.accounts[0], gas: 1000000});" - done - ) | - geth_attach - - done - echo `date`: $num pending. - sleep 2 -done - diff --git a/doc/whoiswho.txt b/doc/whoiswho.txt deleted file mode 100644 index 4be4a0d426ef50fc395a05a4e027e87b47ce6650..0000000000000000000000000000000000000000 --- a/doc/whoiswho.txt +++ /dev/null @@ -1,25 +0,0 @@ -NIC1 bfa@bc.duna.com.ar -Sealer 0x2fd693d1204907ae7d97b5d7d2e93ef877ef2c7d -enode://6c81b38551fec2f1142b58ed65137cc1b7dfdc7b35bc556ef26604c41e30fcdeb12212b3c19913584f71dc7bf87d76cd67fa523e96996c0f148390fb76fdc5f7@[200.68.65.135]:5445 -enode://6c81b38551fec2f1142b58ed65137cc1b7dfdc7b35bc556ef26604c41e30fcdeb12212b3c19913584f71dc7bf87d76cd67fa523e96996c0f148390fb76fdc5f7@[2800:40:1:6::135]:5445 - -CABASE1 apugawko@ -Sealer 0xf2d954738d49ff0fca43c7b3915e8499c983c5de -enode://d088f3e97e1b3d41eebe3d9596b61ed05c79a0a3d6496fe63f916a955e30b456dbd96b875ca160adea81c4341bb3049ad4c831f767d8bf948d96a48b51e97c71@[200.9.157.216]:23236 - -NIC2 robert@cloud.duna.com.ar -Sealer 0xbeebad827a9664d6be5be0f9393dd158826833c6 -enode://1a1abca46cf2f7dd1721c48df699c5b1af507c7953b8a52c353c718dbda06df43fc3e5bf43665a07dfb8be0f40f5f94c8b8224b2bd124639c89897d8774479be@[190.210.214.194]:21296 - -NIC3 Mariano Absatz -Sealer 0x95368af92200d72ae698466f44f9f4b34a7abb2f -enode://2076aec363e2429600b1629875841cf00a41c155b6fc8bfe5a525beb85cbff79712a6746b37969de74e4f6afe669e8fe512af50d0c47d40d8902647cb3f22c96@[50.116.48.41]:18844 - -DGSI -Sealer 0xa9cac6c2ef4909a05ef24a12ecadf9e541b5995f -enode://71d9972d30952db3e757954ce4e1c746a9f84b2d217e7378c1b8a1f48fb22b8960eb48e9be10a75df0968535f1916726c28869784d7ca110aa24bacd7a16c4ac@[200.108.145.9]:50310 - -RIU Luciano Minuchin -Sealer 0x737ce178ce5c97248a9a8794a78f30dce1d091ff -enode://015ab9ad905e84f3c943bb2ecded64ded00ac150ae06ff911f3fb9e76674b70fbc26ad6f9938194f7e4c607b4f8067f018d9c917250ad6e0a1e85366fea85fb8@[179.201.44.197]:28045 -enode://015ab9ad905e84f3c943bb2ecded64ded00ac150ae06ff911f3fb9e76674b70fbc26ad6f9938194f7e4c607b4f8067f018d9c917250ad6e0a1e85366fea85fb8@[2800:110:44:6120:b49a:3fff:fe74:5499]:28045 diff --git a/network5445/contracts/0x3935260bb04ee7e820fc03b7b271f1085f4365e3/abi b/network5445/contracts/0x3935260bb04ee7e820fc03b7b271f1085f4365e3/abi deleted file mode 100644 index 05cd2b3cb6985df2d60c8a7df55b4e96f023040e..0000000000000000000000000000000000000000 --- a/network5445/contracts/0x3935260bb04ee7e820fc03b7b271f1085f4365e3/abi +++ /dev/null @@ -1 +0,0 @@ -[{"constant":false,"inputs":[{"name":"hasharray","type":"uint256[]"}],"name":"put","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"hash","type":"uint256"}],"name":"get","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}] diff --git a/network5445/contracts/TimeStampAuthority b/network5445/contracts/TimeStampAuthority deleted file mode 120000 index 5ce30c7def4d672255c9641c94843f012835c521..0000000000000000000000000000000000000000 --- a/network5445/contracts/TimeStampAuthority +++ /dev/null @@ -1 +0,0 @@ -0x3935260bb04ee7e820fc03b7b271f1085f4365e3 \ No newline at end of file diff --git a/src/TimeStampAuthority.sol b/src/TimeStampAuthority.sol deleted file mode 100644 index 2282493d69c52e1bb7ed92a8548e32c2476b3d57..0000000000000000000000000000000000000000 --- a/src/TimeStampAuthority.sol +++ /dev/null @@ -1,26 +0,0 @@ -// 20180718 Robert Martin-Legene <robert@nic.ar> -// Time stamp authority - -pragma solidity ^0.4.24; - -contract TimeStampAuthority { - // This mapping is almost an "associative array" - mapping (uint256 => uint) private hashstore; - - // Stores hashes (256 bit uint) of a document in the mapping - function put( uint256[] hasharray ) public { - uint256 i = hasharray.length; - while (i>0) { - i--; - uint256 h = hasharray[i]; - if (hashstore[h] == 0) { - hashstore[h] = block.number; - } - } - } - - // Returns the block number in which the hash was first seen - function get( uint256 hash ) public view returns (uint) { - return hashstore[hash]; - } -} diff --git a/src/genesis.json b/src/genesis.json index 84812797e136ff53f9abde7ab6d68b2da207c9d9..a3488216703ffd06689743d96854f058cb49e1ea 100644 --- a/src/genesis.json +++ b/src/genesis.json @@ -1,16 +1,16 @@ { "config": { - "chainId": 5445, + "chainId": 47525974938, "homesteadBlock": 0, "eip150Block": 0, "eip155Block": 0, "eip158Block": 0, "byzantiumBlock": 4, "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "clique": { "period": 15, "epoch": 30000 } + "clique": { "period": 5, "epoch": 30000 } }, "nonce": "0x0000000000000000", - "timestamp": "0x5b293735", - "extraData": "0x426c6f636b636861696e204665646572616c20417267656e74696e61204e49432fd693d1204907ae7d97b5d7d2e93ef877ef2c7d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "gasLimit": "0xffeeddcc", "difficulty": "0x1", "number": "0x0", "gasUsed": "0x0", + "timestamp": "0x5b9f9740", + "extraData": "0x426c6f636b636861696e204665646572616c20417267656e74696e61204e4943e04c818677a6ddcda2c61a58077c5692733e48440000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "gasLimit": "0x47e7c4", "difficulty": "0x1", "number": "0x0", "gasUsed": "0x0", "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "coinbase": "0x0000000000000000000000000000000000000000", "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "alloc": { "2fd693d1204907ae7d97b5d7d2e93ef877ef2c7d": { "balance": "0x200000000000000000000000000000000000000000000000000000000000000" } } + "alloc": { "e04c818677a6ddcda2c61a58077c5692733e4844": { "balance": "0x7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" } } }