From 1fb9feccef26f7fd9726effac3a127b5069f86bf Mon Sep 17 00:00:00 2001
From: Robert Martin-Legene <robert@nic.ar>
Date: Mon, 23 Jul 2018 17:51:15 -0300
Subject: [PATCH] Streamlining things a bit more.

---
 bin/attach.sh       |  3 +--
 bin/create.contract | 29 +++++++++++++++++------------
 bin/libbfa.sh       | 25 +++++++++++++------------
 bin/start.sh        |  6 ++++++
 4 files changed, 37 insertions(+), 26 deletions(-)

diff --git a/bin/attach.sh b/bin/attach.sh
index c9da22f..6abfd77 100755
--- a/bin/attach.sh
+++ b/bin/attach.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
-geth attach ipc:${BFANODEDIR}/geth.ipc
+geth_attach
diff --git a/bin/create.contract b/bin/create.contract
index cc4ebb9..d3721cf 100755
--- a/bin/create.contract
+++ b/bin/create.contract
@@ -6,31 +6,36 @@ source ${BFAHOME}/bin/libbfa.sh || exit 1
 
 function	create
 {
-    workdir=$(  bfamktemp -p . -d )
-    json=$(	solc --optimize --combined-json abi,bin $filename	); test $? eq 0
-    abi=$(	echo "$json"	| jq -rM ".contracts.${prefix}.abi"	); test $? eq 0
-    bin=$(	echo "$json"	| jq -rM ".contracts.${prefix}.bin"	); test $? eq 0
+    workdir=$(  mktemp -p . -d )
+    cleanup     "$workdir"
+    json=$(	solc --optimize --combined-json abi,bin $filename	); test $? = 0
+    prefix=$(   echo "$json"    | jq -M  '.contracts | keys | .[0]'     );
+    abi=$(	echo "$json"	| jq -rM ".contracts.${prefix}.abi"	); test $? = 0
+    bin=$(	echo "$json"	| jq -rM ".contracts.${prefix}.bin"	); test $? = 0
     # Save abi for future use
     echo $abi > ${workdir}/abi
     # We could save the bin, but we don't actually use it later, plus
     # it gets stored in the blockchain
     #echo $bin > ${workdir}/bin
-    js=$(       bfamktemp )
+    js=$(       mktemp )
+    cleanup     "$js"
     cat > $js <<EOT
-var mycontract  = eth.contract(JSON.parse($abi))
+var mycontract  = eth.contract($abi)
 var transaction = mycontract.new( { from: eth.accounts[0], data: "0x${bin}", gas: 1000000 } )
 var rcpt
 while ( !rcpt )
 {
-  admin.sleepBlocks( 1 );
-  rcpt = eth.getTransactionReceipt( transaction.transactionHash );
+  admin.sleepBlocks( 1 )
+  rcpt = eth.getTransactionReceipt( transaction.transactionHash )
 }
-var address = rcpt.contractAddress;
-var pubcontract = mycontract.at(address);
-console.log( pubcontract.address );
+var address = rcpt.contractAddress
+var pubcontract = mycontract.at(address)
+console.log( pubcontract.address )
 EOT
     echo '*** Creating contract. This will take at least 16 seconds.'
-    outfile=$(  geth_exec_js $js )
+    outfile=$(  bfamktemp )
+    cleanup "$outfile"
+    geth_exec_js $js > $outfile
     if [ ` wc -l < $outfile ` = 2 -a `tail -1 < $outfile` = "true" ]
     then
         addr=` head -1 < $outfile `
diff --git a/bin/libbfa.sh b/bin/libbfa.sh
index e004e2d..ebf15d4 100644
--- a/bin/libbfa.sh
+++ b/bin/libbfa.sh
@@ -32,25 +32,16 @@ function    cleanup
     rm  -rf $cleanup_files
 }
 
-# calls mktemp and then cleanup - makes other scripts more compact
-function    bfamktemp
-{
-    local   file=$( mktemp "$@" )
-    cleanup $file
-    echo    $file
-}
-
 function    geth_attach
 {
-    geth    "$@" attach ipc:node1/geth.ipc
+    bfaconfig node
+    geth    --cache 256 "$@" attach ipc:${BFANODEDIR}/geth.ipc
 }
 
 function    geth_exec_js
 {
     test    -r "$1"
-    local   out=$( bfamktemp )
-    geth_attach --exec "loadScript(\"$1\")" > $out
-    echo    $out
+    geth_attach --exec "loadScript(\"$1\")"
 }
 
 function    getnetworkid
@@ -126,6 +117,12 @@ function    nodedir
         fatal "$BFANODEDIR is not a directory."
     test -d "${BFANODEDIR}/geth/chaindata"  ||
         fatal "Node is not initialised. Consider running: geth --datadir $BFANODEDIR init ${BFANETWORKDIR}/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 )
@@ -133,6 +130,10 @@ function    nodedir
     test -r "${BFANODEDIR}/rpcport"         ||
         echo $(( $RANDOM / 2 + 12345 )) > ${BFANODEDIR}/rpcport
     rpcport=$(      cat ${BFANODEDIR}/rpcport )
+    # something uniqueish
+    local iphash=$( ip addr show scope global | awk '/^ *inet /{print $2}' | sed 's,/.*,,' | sha256sum )
+    BFAEXTRADATA="${USER}@${HOSTNAME} ${iphash}"
+    BFAEXTRADATA="${BFAEXTRADATA:0:32}"
 }
 
 function    account
diff --git a/bin/start.sh b/bin/start.sh
index 896f2c2..a2ba1f1 100755
--- a/bin/start.sh
+++ b/bin/start.sh
@@ -84,6 +84,12 @@ bfaconfig max
 	--syncmode full		    \
 	--nousb			    \
 	--bootnodes "${bootnodes}"  \
+        --txpool.nolocals           \
+        --txpool.accountslots 128   \
+        --txpool.globalslots 32768  \
+        --txpool.accountqueue 512   \
+        --txpool.globalqueue 8192   \
+        --extradata "${BFAEXTRADATA}"	\
 	--gcmode archive	    \
 	--cache 512		    \
 	--verbosity 3
-- 
GitLab