Duke Leto
3 years ago
2 changed files with 0 additions and 460 deletions
@ -1,341 +0,0 @@ |
|||||
#!/bin/bash |
|
||||
set -u |
|
||||
|
|
||||
|
|
||||
DATADIR=./benchmark-datadir |
|
||||
SHA256CMD="$(command -v sha256sum || echo shasum)" |
|
||||
SHA256ARGS="$(command -v sha256sum >/dev/null || echo '-a 256')" |
|
||||
|
|
||||
function zcash_rpc { |
|
||||
./src/zcash-cli -datadir="$DATADIR" -rpcuser=user -rpcpassword=password -rpcport=5983 "$@" |
|
||||
} |
|
||||
|
|
||||
function zcash_rpc_slow { |
|
||||
# Timeout of 1 hour |
|
||||
zcash_rpc -rpcclienttimeout=3600 "$@" |
|
||||
} |
|
||||
|
|
||||
function zcash_rpc_veryslow { |
|
||||
# Timeout of 2.5 hours |
|
||||
zcash_rpc -rpcclienttimeout=9000 "$@" |
|
||||
} |
|
||||
|
|
||||
function zcash_rpc_wait_for_start { |
|
||||
zcash_rpc -rpcwait getinfo > /dev/null |
|
||||
} |
|
||||
|
|
||||
function zcashd_generate { |
|
||||
zcash_rpc generate 101 > /dev/null |
|
||||
} |
|
||||
|
|
||||
function extract_benchmark_datadir { |
|
||||
if [ -f "$1.tar.xz" ]; then |
|
||||
# Check the hash of the archive: |
|
||||
"$SHA256CMD" $SHA256ARGS -c <<EOF |
|
||||
$2 $1.tar.xz |
|
||||
EOF |
|
||||
ARCHIVE_RESULT=$? |
|
||||
else |
|
||||
echo "$1.tar.xz not found." |
|
||||
ARCHIVE_RESULT=1 |
|
||||
fi |
|
||||
if [ $ARCHIVE_RESULT -ne 0 ]; then |
|
||||
zcashd_stop |
|
||||
echo |
|
||||
echo "Please download it and place it in the base directory of the repository." |
|
||||
exit 1 |
|
||||
fi |
|
||||
xzcat "$1.tar.xz" | tar x |
|
||||
} |
|
||||
|
|
||||
function use_200k_benchmark { |
|
||||
rm -rf benchmark-200k-UTXOs |
|
||||
extract_benchmark_datadir benchmark-200k-UTXOs dc8ab89eaa13730da57d9ac373c1f4e818a37181c1443f61fd11327e49fbcc5e |
|
||||
DATADIR="./benchmark-200k-UTXOs/node$1" |
|
||||
} |
|
||||
|
|
||||
function zcashd_start { |
|
||||
case "$1" in |
|
||||
sendtoaddress|loadwallet|listunspent) |
|
||||
case "$2" in |
|
||||
200k-recv) |
|
||||
use_200k_benchmark 0 |
|
||||
;; |
|
||||
200k-send) |
|
||||
use_200k_benchmark 1 |
|
||||
;; |
|
||||
*) |
|
||||
echo "Bad arguments to zcashd_start." |
|
||||
exit 1 |
|
||||
esac |
|
||||
;; |
|
||||
*) |
|
||||
rm -rf "$DATADIR" |
|
||||
mkdir -p "$DATADIR/regtest" |
|
||||
touch "$DATADIR/zcash.conf" |
|
||||
esac |
|
||||
./src/zcashd -regtest -datadir="$DATADIR" -rpcuser=user -rpcpassword=password -rpcport=5983 -showmetrics=0 & |
|
||||
ZCASHD_PID=$! |
|
||||
zcash_rpc_wait_for_start |
|
||||
} |
|
||||
|
|
||||
function zcashd_stop { |
|
||||
zcash_rpc stop > /dev/null |
|
||||
wait $ZCASHD_PID |
|
||||
} |
|
||||
|
|
||||
function zcashd_massif_start { |
|
||||
case "$1" in |
|
||||
sendtoaddress|loadwallet|listunspent) |
|
||||
case "$2" in |
|
||||
200k-recv) |
|
||||
use_200k_benchmark 0 |
|
||||
;; |
|
||||
200k-send) |
|
||||
use_200k_benchmark 1 |
|
||||
;; |
|
||||
*) |
|
||||
echo "Bad arguments to zcashd_massif_start." |
|
||||
exit 1 |
|
||||
esac |
|
||||
;; |
|
||||
*) |
|
||||
rm -rf "$DATADIR" |
|
||||
mkdir -p "$DATADIR/regtest" |
|
||||
touch "$DATADIR/zcash.conf" |
|
||||
esac |
|
||||
rm -f massif.out |
|
||||
valgrind --tool=massif --time-unit=ms --massif-out-file=massif.out ./src/zcashd -regtest -datadir="$DATADIR" -rpcuser=user -rpcpassword=password -rpcport=5983 -showmetrics=0 & |
|
||||
ZCASHD_PID=$! |
|
||||
zcash_rpc_wait_for_start |
|
||||
} |
|
||||
|
|
||||
function zcashd_massif_stop { |
|
||||
zcash_rpc stop > /dev/null |
|
||||
wait $ZCASHD_PID |
|
||||
ms_print massif.out |
|
||||
} |
|
||||
|
|
||||
function zcashd_valgrind_start { |
|
||||
rm -rf "$DATADIR" |
|
||||
mkdir -p "$DATADIR/regtest" |
|
||||
touch "$DATADIR/zcash.conf" |
|
||||
rm -f valgrind.out |
|
||||
valgrind --leak-check=yes -v --error-limit=no --log-file="valgrind.out" ./src/zcashd -regtest -datadir="$DATADIR" -rpcuser=user -rpcpassword=password -rpcport=5983 -showmetrics=0 & |
|
||||
ZCASHD_PID=$! |
|
||||
zcash_rpc_wait_for_start |
|
||||
} |
|
||||
|
|
||||
function zcashd_valgrind_stop { |
|
||||
zcash_rpc stop > /dev/null |
|
||||
wait $ZCASHD_PID |
|
||||
cat valgrind.out |
|
||||
} |
|
||||
|
|
||||
function extract_benchmark_data { |
|
||||
if [ -f "block-107134.tar.xz" ]; then |
|
||||
# Check the hash of the archive: |
|
||||
"$SHA256CMD" $SHA256ARGS -c <<EOF |
|
||||
4bd5ad1149714394e8895fa536725ed5d6c32c99812b962bfa73f03b5ffad4bb block-107134.tar.xz |
|
||||
EOF |
|
||||
ARCHIVE_RESULT=$? |
|
||||
else |
|
||||
echo "block-107134.tar.xz not found." |
|
||||
ARCHIVE_RESULT=1 |
|
||||
fi |
|
||||
if [ $ARCHIVE_RESULT -ne 0 ]; then |
|
||||
zcashd_stop |
|
||||
echo |
|
||||
echo "Please generate it using qa/zcash/create_benchmark_archive.py" |
|
||||
echo "and place it in the base directory of the repository." |
|
||||
echo "Usage details are inside the Python script." |
|
||||
exit 1 |
|
||||
fi |
|
||||
xzcat block-107134.tar.xz | tar x -C "$DATADIR/regtest" |
|
||||
} |
|
||||
|
|
||||
|
|
||||
if [ $# -lt 2 ] |
|
||||
then |
|
||||
echo "$0 : At least two arguments are required!" |
|
||||
exit 1 |
|
||||
fi |
|
||||
|
|
||||
# Precomputation |
|
||||
case "$1" in |
|
||||
*) |
|
||||
case "$2" in |
|
||||
verifyjoinsplit) |
|
||||
zcashd_start "${@:2}" |
|
||||
RAWJOINSPLIT=$(zcash_rpc zcsamplejoinsplit) |
|
||||
zcashd_stop |
|
||||
esac |
|
||||
esac |
|
||||
|
|
||||
case "$1" in |
|
||||
time) |
|
||||
zcashd_start "${@:2}" |
|
||||
case "$2" in |
|
||||
sleep) |
|
||||
zcash_rpc zcbenchmark sleep 10 |
|
||||
;; |
|
||||
parameterloading) |
|
||||
zcash_rpc zcbenchmark parameterloading 10 |
|
||||
;; |
|
||||
createjoinsplit) |
|
||||
zcash_rpc zcbenchmark createjoinsplit 10 "${@:3}" |
|
||||
;; |
|
||||
verifyjoinsplit) |
|
||||
zcash_rpc zcbenchmark verifyjoinsplit 1000 "\"$RAWJOINSPLIT\"" |
|
||||
;; |
|
||||
solveequihash) |
|
||||
zcash_rpc_slow zcbenchmark solveequihash 50 "${@:3}" |
|
||||
;; |
|
||||
verifyequihash) |
|
||||
zcash_rpc zcbenchmark verifyequihash 1000 |
|
||||
;; |
|
||||
validatelargetx) |
|
||||
zcash_rpc zcbenchmark validatelargetx 10 "${@:3}" |
|
||||
;; |
|
||||
trydecryptnotes) |
|
||||
zcash_rpc zcbenchmark trydecryptnotes 1000 "${@:3}" |
|
||||
;; |
|
||||
incnotewitnesses) |
|
||||
zcash_rpc zcbenchmark incnotewitnesses 100 "${@:3}" |
|
||||
;; |
|
||||
connectblockslow) |
|
||||
extract_benchmark_data |
|
||||
zcash_rpc zcbenchmark connectblockslow 10 |
|
||||
;; |
|
||||
sendtoaddress) |
|
||||
zcash_rpc zcbenchmark sendtoaddress 10 "${@:4}" |
|
||||
;; |
|
||||
loadwallet) |
|
||||
zcash_rpc zcbenchmark loadwallet 10 |
|
||||
;; |
|
||||
listunspent) |
|
||||
zcash_rpc zcbenchmark listunspent 10 |
|
||||
;; |
|
||||
*) |
|
||||
zcashd_stop |
|
||||
echo "Bad arguments to time." |
|
||||
exit 1 |
|
||||
esac |
|
||||
zcashd_stop |
|
||||
;; |
|
||||
memory) |
|
||||
zcashd_massif_start "${@:2}" |
|
||||
case "$2" in |
|
||||
sleep) |
|
||||
zcash_rpc zcbenchmark sleep 1 |
|
||||
;; |
|
||||
parameterloading) |
|
||||
zcash_rpc zcbenchmark parameterloading 1 |
|
||||
;; |
|
||||
createjoinsplit) |
|
||||
zcash_rpc_slow zcbenchmark createjoinsplit 1 "${@:3}" |
|
||||
;; |
|
||||
verifyjoinsplit) |
|
||||
zcash_rpc zcbenchmark verifyjoinsplit 1 "\"$RAWJOINSPLIT\"" |
|
||||
;; |
|
||||
solveequihash) |
|
||||
zcash_rpc_slow zcbenchmark solveequihash 1 "${@:3}" |
|
||||
;; |
|
||||
verifyequihash) |
|
||||
zcash_rpc zcbenchmark verifyequihash 1 |
|
||||
;; |
|
||||
validatelargetx) |
|
||||
zcash_rpc zcbenchmark validatelargetx 1 |
|
||||
;; |
|
||||
trydecryptnotes) |
|
||||
zcash_rpc zcbenchmark trydecryptnotes 1 "${@:3}" |
|
||||
;; |
|
||||
incnotewitnesses) |
|
||||
zcash_rpc zcbenchmark incnotewitnesses 1 "${@:3}" |
|
||||
;; |
|
||||
connectblockslow) |
|
||||
extract_benchmark_data |
|
||||
zcash_rpc zcbenchmark connectblockslow 1 |
|
||||
;; |
|
||||
sendtoaddress) |
|
||||
zcash_rpc zcbenchmark sendtoaddress 1 "${@:4}" |
|
||||
;; |
|
||||
loadwallet) |
|
||||
# The initial load is sufficient for measurement |
|
||||
;; |
|
||||
listunspent) |
|
||||
zcash_rpc zcbenchmark listunspent 1 |
|
||||
;; |
|
||||
*) |
|
||||
zcashd_massif_stop |
|
||||
echo "Bad arguments to memory." |
|
||||
exit 1 |
|
||||
esac |
|
||||
zcashd_massif_stop |
|
||||
rm -f massif.out |
|
||||
;; |
|
||||
valgrind) |
|
||||
zcashd_valgrind_start |
|
||||
case "$2" in |
|
||||
sleep) |
|
||||
zcash_rpc zcbenchmark sleep 1 |
|
||||
;; |
|
||||
parameterloading) |
|
||||
zcash_rpc zcbenchmark parameterloading 1 |
|
||||
;; |
|
||||
createjoinsplit) |
|
||||
zcash_rpc_veryslow zcbenchmark createjoinsplit 1 "${@:3}" |
|
||||
;; |
|
||||
verifyjoinsplit) |
|
||||
zcash_rpc zcbenchmark verifyjoinsplit 1 "\"$RAWJOINSPLIT\"" |
|
||||
;; |
|
||||
solveequihash) |
|
||||
zcash_rpc_veryslow zcbenchmark solveequihash 1 "${@:3}" |
|
||||
;; |
|
||||
verifyequihash) |
|
||||
zcash_rpc zcbenchmark verifyequihash 1 |
|
||||
;; |
|
||||
trydecryptnotes) |
|
||||
zcash_rpc zcbenchmark trydecryptnotes 1 "${@:3}" |
|
||||
;; |
|
||||
incnotewitnesses) |
|
||||
zcash_rpc zcbenchmark incnotewitnesses 1 "${@:3}" |
|
||||
;; |
|
||||
connectblockslow) |
|
||||
extract_benchmark_data |
|
||||
zcash_rpc zcbenchmark connectblockslow 1 |
|
||||
;; |
|
||||
*) |
|
||||
zcashd_valgrind_stop |
|
||||
echo "Bad arguments to valgrind." |
|
||||
exit 1 |
|
||||
esac |
|
||||
zcashd_valgrind_stop |
|
||||
rm -f valgrind.out |
|
||||
;; |
|
||||
valgrind-tests) |
|
||||
case "$2" in |
|
||||
gtest) |
|
||||
rm -f valgrind.out |
|
||||
valgrind --leak-check=yes -v --error-limit=no --log-file="valgrind.out" ./src/zcash-gtest |
|
||||
cat valgrind.out |
|
||||
rm -f valgrind.out |
|
||||
;; |
|
||||
test_bitcoin) |
|
||||
rm -f valgrind.out |
|
||||
valgrind --leak-check=yes -v --error-limit=no --log-file="valgrind.out" ./src/test/test_bitcoin |
|
||||
cat valgrind.out |
|
||||
rm -f valgrind.out |
|
||||
;; |
|
||||
*) |
|
||||
echo "Bad arguments to valgrind-tests." |
|
||||
exit 1 |
|
||||
esac |
|
||||
;; |
|
||||
*) |
|
||||
echo "Invalid benchmark type." |
|
||||
exit 1 |
|
||||
esac |
|
||||
|
|
||||
# Cleanup |
|
||||
rm -rf "$DATADIR" |
|
@ -1,119 +0,0 @@ |
|||||
// Copyright (c) 2016-2020 The Hush developers
|
|
||||
// Distributed under the GPLv3 software license, see the accompanying
|
|
||||
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
|
|
||||
/*Descriptson and examples of COptCCParams class found in:
|
|
||||
script/standard.h/cpp |
|
||||
class COptCCParams |
|
||||
|
|
||||
structure of data in vData payload attached to end of CCvout: |
|
||||
param |
|
||||
OP_1 |
|
||||
param |
|
||||
OP_2 ... etc until OP_16 |
|
||||
OP_PUSHDATA4 is the last OP code to tell things its at the end. |
|
||||
|
|
||||
taken from standard.cpp line 22: COptCCParams::COptCCParams(std::vector<unsigned char> &vch) |
|
||||
|
|
||||
EXAMPLE taken from Verus how to create scriptPubKey from COptCCParams class: |
|
||||
EXAMPLE taken from Verus how to decode scriptPubKey from COptCCParams class: |
|
||||
*/ |
|
||||
|
|
||||
bool MakeGuardedOutput(CAmount value, CPubKey &dest, CTransaction &stakeTx, CTxOut &vout) |
|
||||
{ |
|
||||
CCcontract_info *cp, C; |
|
||||
cp = CCinit(&C,EVAL_STAKEGUARD); |
|
||||
|
|
||||
CPubKey ccAddress = CPubKey(ParseHex(cp->CChexstr)); |
|
||||
|
|
||||
// return an output that is bound to the stake transaction and can be spent by presenting either a signed condition by the original
|
|
||||
// destination address or a properly signed stake transaction of the same utxo on a fork
|
|
||||
vout = MakeCC1of2vout(EVAL_STAKEGUARD, value, dest, ccAddress); |
|
||||
|
|
||||
std::vector<CPubKey> vPubKeys = std::vector<CPubKey>(); |
|
||||
vPubKeys.push_back(dest); |
|
||||
vPubKeys.push_back(ccAddress); |
|
||||
|
|
||||
std::vector<std::vector<unsigned char>> vData = std::vector<std::vector<unsigned char>>(); |
|
||||
|
|
||||
CVerusHashWriter hw = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION); |
|
||||
|
|
||||
hw << stakeTx.vin[0].prevout.hash; |
|
||||
hw << stakeTx.vin[0].prevout.n; |
|
||||
|
|
||||
uint256 utxo = hw.GetHash(); |
|
||||
vData.push_back(std::vector<unsigned char>(utxo.begin(), utxo.end())); // Can we use any data here to construct vector?
|
|
||||
|
|
||||
CStakeParams p; |
|
||||
if (GetStakeParams(stakeTx, p)) |
|
||||
{ |
|
||||
// prev block hash and height is here to make validation easy
|
|
||||
vData.push_back(std::vector<unsigned char>(p.prevHash.begin(), p.prevHash.end())); |
|
||||
std::vector<unsigned char> height = std::vector<unsigned char>(4); |
|
||||
for (int i = 0; i < 4; i++) |
|
||||
{ |
|
||||
height[i] = (p.blkHeight >> (8 * i)) & 0xff; |
|
||||
} |
|
||||
vData.push_back(height); |
|
||||
|
|
||||
COptCCParams ccp = COptCCParams(COptCCParams::VERSION, EVAL_STAKEGUARD, 1, 2, vPubKeys, vData); |
|
||||
|
|
||||
vout.scriptPubKey << ccp.AsVector() << OP_DROP; |
|
||||
return true; |
|
||||
} |
|
||||
return false; |
|
||||
} |
|
||||
|
|
||||
bool ValidateMatchingStake(const CTransaction &ccTx, uint32_t voutNum, const CTransaction &stakeTx, bool &cheating) |
|
||||
{ |
|
||||
// an invalid or non-matching stake transaction cannot cheat
|
|
||||
cheating = false; |
|
||||
|
|
||||
//printf("ValidateMatchingStake: ccTx.vin[0].prevout.hash: %s, ccTx.vin[0].prevout.n: %d\n", ccTx.vin[0].prevout.hash.GetHex().c_str(), ccTx.vin[0].prevout.n);
|
|
||||
|
|
||||
if (ccTx.IsCoinBase()) |
|
||||
{ |
|
||||
CStakeParams p; |
|
||||
if (ValidateStakeTransaction(stakeTx, p)) |
|
||||
{ |
|
||||
std::vector<std::vector<unsigned char>> vParams = std::vector<std::vector<unsigned char>>(); |
|
||||
CScript dummy; |
|
||||
|
|
||||
if (ccTx.vout[voutNum].scriptPubKey.IsPayToCryptoCondition(&dummy, vParams) && vParams.size() > 0) |
|
||||
{ |
|
||||
COptCCParams ccp = COptCCParams(vParams[0]); |
|
||||
if (ccp.IsValid() & ccp.vData.size() >= 3 && ccp.vData[2].size() <= 4) |
|
||||
{ |
|
||||
CVerusHashWriter hw = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION); |
|
||||
|
|
||||
hw << stakeTx.vin[0].prevout.hash; |
|
||||
hw << stakeTx.vin[0].prevout.n; |
|
||||
uint256 utxo = hw.GetHash(); |
|
||||
|
|
||||
uint32_t height = 0; |
|
||||
int i, dataLen = ccp.vData[2].size(); |
|
||||
for (i = dataLen - 1; i >= 0; i--) |
|
||||
{ |
|
||||
height = (height << 8) + ccp.vData[2][i]; |
|
||||
} |
|
||||
// for debugging strange issue
|
|
||||
// printf("iterator: %d, height: %d, datalen: %d\n", i, height, dataLen);
|
|
||||
|
|
||||
if (utxo == uint256(ccp.vData[0])) |
|
||||
{ |
|
||||
if (p.prevHash != uint256(ccp.vData[1]) && p.blkHeight >= height) |
|
||||
{ |
|
||||
cheating = true; |
|
||||
return true; |
|
||||
} |
|
||||
// if block height is equal and we are at the else, prevHash must have been equal
|
|
||||
else if (p.blkHeight == height) |
|
||||
{ |
|
||||
return true; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
return false; |
|
||||
} |
|
Loading…
Reference in new issue