From cbb6acd75c25fd48f8b3f83c414166beb3c828e2 Mon Sep 17 00:00:00 2001 From: Job Evers-Meltzer Date: Mon, 8 Aug 2016 10:02:46 -0500 Subject: [PATCH 1/4] travis fix: only output last 1000 lines on error --- reproducible_build.sh | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/reproducible_build.sh b/reproducible_build.sh index f47a3d88f..992298a01 100755 --- a/reproducible_build.sh +++ b/reproducible_build.sh @@ -31,6 +31,9 @@ BUILD_DEPENDENCIES=true BUILD_LBRYCRD=true TIMEOUT=false THREE_MB=3145728 +# this flag gets set to False if +# the script exits due to a timeout +OUTPUT_LOG=true while getopts :crldoth:w:d: FLAG; do case $FLAG in @@ -116,6 +119,7 @@ function exit_at_45() { fi if [ "$TIMEOUT" = true ] && (( TIME > TIMEOUT_SECS )); then echo 'Exiting at 45 minutes to allow the cache to populate' + OUTPUT_LOG=false exit 1 fi fi @@ -159,11 +163,11 @@ function background() { function cleanup() { rv=$? # cat the log file if it exists - if [ -f "$2" ]; then + if [ -f "$2" ] && [ "${OUTPUT_LOG}" = true ]; then echo echo "Output of log file $2" echo - tail -c $THREE_MB "$1" + tail -n 1000 "$2" echo fi # delete the build directory @@ -175,14 +179,15 @@ function cleanup() { function cat_and_exit() { rv=$? # cat the log file if it exists - if [ -f "$1" ]; then + if [ -f "$1" ] && [ "${OUTPUT_LOG}" = true ]; then echo echo "Output of log file $1" echo - # log size is limited to 4MB on travis - # so hopefully the last 3MB is enough + # This used to be the last 3MB but outputing that + # caused problems on travis. + # Hopefully the last 1000 lines is enough # to debug whatever went wrong - tail -c $THREE_MB "$1" + tail -n 1000 "$1" echo fi exit $rv -- 2.45.3 From 083a4a1b88359a6b0ecf2162e794aa2cf0ca9388 Mon Sep 17 00:00:00 2001 From: Job Evers-Meltzer Date: Mon, 8 Aug 2016 10:58:58 -0500 Subject: [PATCH 2/4] Change build timeout to 40 minutes --- reproducible_build.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/reproducible_build.sh b/reproducible_build.sh index 992298a01..44c4bfcd0 100755 --- a/reproducible_build.sh +++ b/reproducible_build.sh @@ -19,7 +19,7 @@ function HELP { echo "-r: remove intermediate files." echo "-l: build only lbrycrd" echo "-d: build only the dependencies" - echo "-o: timeout build after 45 minutes" + echo "-o: timeout build after 40 minutes" echo "-t: turn trace on" echo "-h: show help" exit 1 @@ -107,18 +107,18 @@ fi NEXT_TIME=60 -function exit_at_45() { +function exit_at_40() { if [ -f "${START_TIME_FILE}" ]; then NOW=$(date +%s) START=$(cat "${START_TIME_FILE}") - TIMEOUT_SECS=2700 # 45 * 60 + TIMEOUT_SECS=2400 # 40 * 60 TIME=$((NOW - START)) if (( TIME > NEXT_TIME )); then echo "Build has taken $((TIME / 60)) minutes: $1" NEXT_TIME=$((TIME + 60)) fi if [ "$TIMEOUT" = true ] && (( TIME > TIMEOUT_SECS )); then - echo 'Exiting at 45 minutes to allow the cache to populate' + echo 'Exiting at 40 minutes to allow the cache to populate' OUTPUT_LOG=false exit 1 fi @@ -140,7 +140,7 @@ function wait_and_echo() { # loop until the process is no longer running # check every $SLEEP seconds, echoing a message every minute while (ps -p "${PID}" > /dev/null); do - exit_at_45 "$2" + exit_at_40 "$2" sleep "${SLEEP}" done # restore the xtrace setting -- 2.45.3 From e0089d19f2fbaf199b4b3efa4c319b32e4b5c106 Mon Sep 17 00:00:00 2001 From: kkurokawa Date: Wed, 10 Aug 2016 16:45:36 -0400 Subject: [PATCH 3/4] adding test for block with bogus claim trie hash --- src/test/claimtrie_tests.cpp | 59 ++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/test/claimtrie_tests.cpp b/src/test/claimtrie_tests.cpp index 4ee804e22..7acaa6f3f 100644 --- a/src/test/claimtrie_tests.cpp +++ b/src/test/claimtrie_tests.cpp @@ -2768,5 +2768,64 @@ BOOST_AUTO_TEST_CASE(claimtrievalue_proof) } +// Check that blocks with bogus calimtrie hash is rejected +BOOST_AUTO_TEST_CASE(bogus_claimtrie_hash) +{ + fRequireStandard = false; + BOOST_CHECK(pclaimTrie->nCurrentHeight = chainActive.Height() + 1); + LOCK(cs_main); + std::string sName("test"); + std::string sValue1("test"); + + std::vector vchName(sName.begin(), sName.end()); + std::vector vchValue1(sValue1.begin(), sValue1.end()); + + std::vector coinbases; + + BOOST_CHECK(CreateCoinbases(3, coinbases)); + + int orig_chain_height = chainActive.Height(); + + CMutableTransaction tx1 = BuildTransaction(coinbases[0]); + tx1.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName << vchValue1 << OP_2DROP << OP_DROP << OP_TRUE; + tx1.vout[0].nValue = 1; + COutPoint tx1OutPoint(tx1.GetHash(), 0); + + AddToMempool(tx1); + + CBlockTemplate *pblockTemp; + BOOST_CHECK(pblockTemp = CreateNewBlock(Params(), scriptPubKey)); + pblockTemp->block.hashPrevBlock = chainActive.Tip()->GetBlockHash(); + pblockTemp->block.nVersion = 1; + pblockTemp->block.nTime = chainActive.Tip()->GetBlockTime()+Params().GetConsensus().nPowTargetSpacing; + CMutableTransaction txCoinbase(pblockTemp->block.vtx[0]); + txCoinbase.vin[0].scriptSig = CScript() << CScriptNum(chainActive.Height()); + txCoinbase.vout[0].nValue = GetBlockSubsidy(chainActive.Height() + 1, Params().GetConsensus()); + pblockTemp->block.vtx[0] = CTransaction(txCoinbase); + pblockTemp->block.hashMerkleRoot = BlockMerkleRoot(pblockTemp->block); + //create bogus hash + + uint256 bogusHashClaimTrie; + bogusHashClaimTrie.SetHex("aaa"); + pblockTemp->block.hashClaimTrie = bogusHashClaimTrie; + + for (int i = 0; ; ++i) + { + pblockTemp->block.nNonce = i; + if (CheckProofOfWork(pblockTemp->block.GetPoWHash(), pblockTemp->block.nBits, Params().GetConsensus())) + { + break; + } + } + CValidationState state; + bool success = ProcessNewBlock(state, Params(), NULL, &pblockTemp->block, true, NULL); + // will process , but will not be connected + BOOST_CHECK(success); + BOOST_CHECK(state.IsValid()); + BOOST_CHECK(pblockTemp->block.GetHash() != chainActive.Tip()->GetBlockHash()); + BOOST_CHECK_EQUAL(orig_chain_height,chainActive.Height()); + delete pblockTemp; + +} BOOST_AUTO_TEST_SUITE_END() -- 2.45.3 From 1b80858a44487de7195cff541cb7ee374389ca3f Mon Sep 17 00:00:00 2001 From: kkurokawa Date: Wed, 10 Aug 2016 21:04:04 -0400 Subject: [PATCH 4/4] adding test to check the POW algorithm --- src/test/lbry_tests.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/test/lbry_tests.cpp b/src/test/lbry_tests.cpp index 81fe8a743..251b6551e 100644 --- a/src/test/lbry_tests.cpp +++ b/src/test/lbry_tests.cpp @@ -3,6 +3,7 @@ #include "lbry.h" #include "main.h" #include "test/test_bitcoin.h" +#include "hash.h" #include #include @@ -95,6 +96,35 @@ BOOST_AUTO_TEST_CASE(pow_limit_check) } +boost::test_tools::predicate_result +check_powhash_equals(std::string test_string,std::string expected_hash_hex) +{ + std::vector test_vect(test_string.begin(),test_string.end()); + uint256 expected; + expected.SetHex(expected_hash_hex); + uint256 hash = PoWHash(test_vect); + + //std::cout<<"hash :"<