Skip to content

Commit

Permalink
harness/eth: Fix mining script.
Browse files Browse the repository at this point in the history
Immediatly stopping the miner after starting to mine was causing
transactions to not be included in blocks. Change to start once and
stop a fraction of a second before N blocks should be mined.

Update internal geth to slightly after 1.10.5 and set harness to start
at the london fork.
  • Loading branch information
JoeGruffins committed Jul 20, 2021
1 parent d0e5f31 commit 51b8c3d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 25 deletions.
2 changes: 2 additions & 0 deletions dex/testing/eth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ sandboxed environment for testing dex swap transactions.
The harness depends on [geth](https://github.com/ethereum/go-ethereum/tree/master/cmd/geth)
to run.

It also requires tmux and bc.

## Using

You must have `geth` in `PATH` to use the harness.
Expand Down
26 changes: 9 additions & 17 deletions dex/testing/eth/create-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,25 @@ chmod +x "${NODES_ROOT}/harness-ctl/${NAME}"

# Write mine script if CHAIN_ADDRESS is present.
if [ "${CHAIN_ADDRESS}" != "_" ]; then
# The mining script may end up mining more or less blocks than specified.
cat > "${NODES_ROOT}/harness-ctl/mine-${NAME}" <<EOF
#!/usr/bin/env bash
NUM=1
case \$1 in
''|*[!0-9]*) ;;
*) NUM=\$1 ;;
esac
for i in \$(seq \$NUM) ; do
"${NODES_ROOT}/harness-ctl/${NAME}" attach --preload "${MINE_JS}" --exec 'mine()'
done
echo "Mining..."
BEFORE=\$("${NODES_ROOT}/harness-ctl/${NAME}" attach --exec 'eth.blockNumber')
"${NODES_ROOT}/harness-ctl/${NAME}" attach --exec 'miner.start()' > /dev/null
sleep \$(echo "\$NUM-0.9" | bc)
"${NODES_ROOT}/harness-ctl/${NAME}" attach --exec 'miner.stop()' > /dev/null
AFTER=\$("${NODES_ROOT}/harness-ctl/${NAME}" attach --exec 'eth.blockNumber')
DIFF=\$((AFTER-BEFORE))
echo "Mined \$DIFF blocks."
EOF
chmod +x "${NODES_ROOT}/harness-ctl/mine-${NAME}"

# Write mining javascript.
# NOTE: This sometimes mines more than one block. It is a race. This returns
# the number of blocks mined within the lifespan of the function, but one more
# MAY be mined after returning.
cat > "${MINE_JS}" <<EOF
function mine() {
blkN = eth.blockNumber;
miner.start();
miner.stop();
admin.sleep(1.1);
return eth.blockNumber - blkN;
}
EOF

# Write password file to unlock accounts later.
cat > "${GROUP_DIR}/password" <<EOF
$CHAIN_PASSWORD
Expand Down
3 changes: 1 addition & 2 deletions dex/testing/eth/harness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ cat > "${NODES_ROOT}/genesis.json" <<EOF
"istanbulBlock": 0,
"muirGlacierBlock": 0,
"berlinBlock": 0,
"londonBlock": 0,
"clique": {
"period": 1,
"epoch": 30000
Expand Down Expand Up @@ -202,8 +203,6 @@ do
"${NODES_ROOT}/harness-ctl/mine-alpha" "5"
done

# Transactions can take an eternity to be mined...
# TODO: Determine why this is.
while true
do
TXSLEN=$("${NODES_ROOT}/harness-ctl/alpha" "attach --exec eth.pendingTransactions.length")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/decred/dcrd/wire v1.4.1-0.20210715032435-c9521b468f95
github.com/decred/go-socks v1.1.0
github.com/decred/slog v1.1.0
github.com/ethereum/go-ethereum v1.10.4
github.com/ethereum/go-ethereum v1.10.6-0.20210715235240-f05419f0fb8c
github.com/gcash/bchd v0.17.2-0.20201218180520-5708823e0e99
github.com/gcash/bchutil v0.0.0-20210113190856-6ea28dff4000
github.com/go-chi/chi/v5 v5.0.1
Expand Down
9 changes: 4 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/ethereum/go-ethereum v1.10.4 h1:JPZPL2MHbegfFStcaOrrggMVIcf57OQHQ0J3UhjQ+xQ=
github.com/ethereum/go-ethereum v1.10.4/go.mod h1:nEE0TP5MtxGzOMd7egIrbPJMQBnhVU3ELNxhBglIzhg=
github.com/ethereum/go-ethereum v1.10.6-0.20210715235240-f05419f0fb8c h1:9xWXqtfz8QUXO2ruCpv7HDf7SUNZ/AJE2OH3EOHa/Cw=
github.com/ethereum/go-ethereum v1.10.6-0.20210715235240-f05419f0fb8c/go.mod h1:iY/t0vHSmaAOC+xlqvAAeHdGSWNFkfSnN0OhMTDYz90=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 h1:FtmdgXiUlNeRsoNMFlKLDt+S+6hbjVMEW6RGQ7aUf7c=
github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0=
Expand Down Expand Up @@ -314,8 +314,8 @@ github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iU
github.com/holiman/uint256 v1.2.0 h1:gpSYcPLWGv4sG43I2mVLiDZCNDh/EpGjSk8tmtxitHM=
github.com/holiman/uint256 v1.2.0/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huin/goupnp v1.0.1-0.20210310174557-0ca763054c88 h1:bcAj8KroPf552TScjFPIakjH2/tdIrIH8F+cc4v4SRo=
github.com/huin/goupnp v1.0.1-0.20210310174557-0ca763054c88/go.mod h1:nNs7wvRfN1eKaMknBydLNQU6146XQim8t4h+q90biWo=
github.com/huin/goupnp v1.0.1-0.20210626160114-33cdcbb30dda h1:Vofqyy/Ysqit++X33unU0Gr08b6P35hKm3juytDrBVI=
github.com/huin/goupnp v1.0.1-0.20210626160114-33cdcbb30dda/go.mod h1:0dxJBVBHqTMjIUMkESDTNgOOx/Mw5wYIfyFmdzSamkM=
github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/improbable-eng/grpc-web v0.9.1/go.mod h1:6hRR09jOEG81ADP5wCQju1z71g6OL4eEvELdran/3cs=
Expand Down Expand Up @@ -550,7 +550,6 @@ golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73r
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down

0 comments on commit 51b8c3d

Please sign in to comment.