diff --git a/reproducible_build.sh b/reproducible_build.sh index 44c4bfcd0..f47a3d88f 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 40 minutes" + echo "-o: timeout build after 45 minutes" echo "-t: turn trace on" echo "-h: show help" exit 1 @@ -31,9 +31,6 @@ 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 @@ -107,19 +104,18 @@ fi NEXT_TIME=60 -function exit_at_40() { +function exit_at_45() { if [ -f "${START_TIME_FILE}" ]; then NOW=$(date +%s) START=$(cat "${START_TIME_FILE}") - TIMEOUT_SECS=2400 # 40 * 60 + TIMEOUT_SECS=2700 # 45 * 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 40 minutes to allow the cache to populate' - OUTPUT_LOG=false + echo 'Exiting at 45 minutes to allow the cache to populate' exit 1 fi fi @@ -140,7 +136,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_40 "$2" + exit_at_45 "$2" sleep "${SLEEP}" done # restore the xtrace setting @@ -163,11 +159,11 @@ function background() { function cleanup() { rv=$? # cat the log file if it exists - if [ -f "$2" ] && [ "${OUTPUT_LOG}" = true ]; then + if [ -f "$2" ]; then echo echo "Output of log file $2" echo - tail -n 1000 "$2" + tail -c $THREE_MB "$1" echo fi # delete the build directory @@ -179,15 +175,14 @@ function cleanup() { function cat_and_exit() { rv=$? # cat the log file if it exists - if [ -f "$1" ] && [ "${OUTPUT_LOG}" = true ]; then + if [ -f "$1" ]; then echo echo "Output of log file $1" echo - # This used to be the last 3MB but outputing that - # caused problems on travis. - # Hopefully the last 1000 lines is enough + # log size is limited to 4MB on travis + # so hopefully the last 3MB is enough # to debug whatever went wrong - tail -n 1000 "$1" + tail -c $THREE_MB "$1" echo fi exit $rv diff --git a/src/claimtrie.h b/src/claimtrie.h index 6d6396ba7..e64f715ad 100644 --- a/src/claimtrie.h +++ b/src/claimtrie.h @@ -273,6 +273,30 @@ struct claimsForNameType claimsForNameType(std::vector claims, std::vector supports, int nLastTakeoverHeight) : claims(claims), supports(supports), nLastTakeoverHeight(nLastTakeoverHeight) {} + + //return effective amount form claim, retuns 0 if claim is not found + CAmount getEffectiveAmountForClaim(uint160 claimId, int currentHeight) + { + CAmount effectiveAmount = 0; + bool claim_found = false; + for (std::vector::iterator it=claims.begin(); it!=claims.end(); ++it) + { + if (it->claimId == claimId && it->nValidAtHeight < currentHeight) + effectiveAmount += it->nAmount; + claim_found = true; + break; + } + if (!claim_found) + return effectiveAmount; + + for (std::vector::iterator it=supports.begin(); it!=supports.end(); ++it) + { + if (it->supportedClaimId == claimId && it->nValidAtHeight < currentHeight) + effectiveAmount += it->nAmount; + } + return effectiveAmount; + + } }; class CClaimTrieCache; @@ -330,7 +354,7 @@ public: unsigned int getTotalNamesInTrie() const; unsigned int getTotalClaimsInTrie() const; CAmount getTotalValueOfClaimsInTrie(bool fControllingOnly) const; - + friend class CClaimTrieCache; CDBWrapper db; diff --git a/src/rpc/claimtrie.cpp b/src/rpc/claimtrie.cpp index cd9ec1b8a..f3d78466c 100644 --- a/src/rpc/claimtrie.cpp +++ b/src/rpc/claimtrie.cpp @@ -183,11 +183,14 @@ UniValue getvalueforname(const UniValue& params, bool fHelp) std::string sValue; if (!getValueForClaim(claim.outPoint, sValue)) return ret; + ret.push_back(Pair("value", sValue)); ret.push_back(Pair("txid", claim.outPoint.hash.GetHex())); ret.push_back(Pair("n", (int)claim.outPoint.n)); - ret.push_back(Pair("amount", claim.nAmount)); - ret.push_back(Pair("effective amount", claim.nEffectiveAmount)); + ret.push_back(Pair("amount", ValueFromAmount(claim.nAmount))); + claimsForNameType claimsForName = pclaimTrie->getClaimsForName(name); + CAmount effectiveAmount = claimsForName.getEffectiveAmountForClaim(claim.claimId,chainActive.Height()); + ret.push_back(Pair("effective amount", ValueFromAmount(effectiveAmount))); ret.push_back(Pair("height", claim.nHeight)); return ret; } @@ -196,12 +199,11 @@ typedef std::pair > claimAndSupportsType typedef std::map claimSupportMapType; typedef std::map > supportsWithoutClaimsMapType; -UniValue claimsAndSupportsToJSON(claimSupportMapType::const_iterator itClaimsAndSupports, int nCurrentHeight) +UniValue claimsAndSupportsToJSON(claimSupportMapType::const_iterator itClaimsAndSupports, CAmount nEffectiveAmount) { UniValue ret(UniValue::VOBJ); const CClaimValue claim = itClaimsAndSupports->second.first; const std::vector supports = itClaimsAndSupports->second.second; - CAmount nEffectiveAmount = 0; UniValue supportObjs(UniValue::VARR); for (std::vector::const_iterator itSupports = supports.begin(); itSupports != supports.end(); ++itSupports) { @@ -210,11 +212,7 @@ UniValue claimsAndSupportsToJSON(claimSupportMapType::const_iterator itClaimsAnd supportObj.push_back(Pair("n", (int)itSupports->outPoint.n)); supportObj.push_back(Pair("nHeight", itSupports->nHeight)); supportObj.push_back(Pair("nValidAtHeight", itSupports->nValidAtHeight)); - if (itSupports->nValidAtHeight < nCurrentHeight) - { - nEffectiveAmount += itSupports->nAmount; - } - supportObj.push_back(Pair("nAmount", itSupports->nAmount)); + supportObj.push_back(Pair("nAmount", ValueFromAmount(itSupports->nAmount))); supportObjs.push_back(supportObj); } ret.push_back(Pair("claimId", itClaimsAndSupports->first.GetHex())); @@ -222,17 +220,13 @@ UniValue claimsAndSupportsToJSON(claimSupportMapType::const_iterator itClaimsAnd ret.push_back(Pair("n", (int)claim.outPoint.n)); ret.push_back(Pair("nHeight", claim.nHeight)); ret.push_back(Pair("nValidAtHeight", claim.nValidAtHeight)); - if (claim.nValidAtHeight < nCurrentHeight) - { - nEffectiveAmount += claim.nAmount; - } - ret.push_back(Pair("nAmount", claim.nAmount)); + ret.push_back(Pair("nAmount", ValueFromAmount(claim.nAmount))); std::string sValue; if (getValueForClaim(claim.outPoint, sValue)) { ret.push_back(Pair("value", sValue)); } - ret.push_back(Pair("nEffectiveAmount", nEffectiveAmount)); + ret.push_back(Pair("nEffectiveAmount", ValueFromAmount(nEffectiveAmount))); ret.push_back(Pair("supports", supportObjs)); return ret; @@ -251,7 +245,7 @@ UniValue supportsWithoutClaimsToJSON(supportsWithoutClaimsMapType::const_iterato supportObj.push_back(Pair("n", (int)itSupports->outPoint.n)); supportObj.push_back(Pair("nHeight", itSupports->nHeight)); supportObj.push_back(Pair("nValidAtHeight", itSupports->nValidAtHeight)); - supportObj.push_back(Pair("nAmount", itSupports->nAmount)); + supportObj.push_back(Pair("nAmount", ValueFromAmount(itSupports->nAmount))); supportObjs.push_back(supportObj); } ret.push_back(Pair("supports", supportObjs)); @@ -329,7 +323,8 @@ UniValue getclaimsforname(const UniValue& params, bool fHelp) ret.push_back(Pair("nLastTakeoverHeight", claimsForName.nLastTakeoverHeight)); for (claimSupportMapType::const_iterator itClaimsAndSupports = claimSupportMap.begin(); itClaimsAndSupports != claimSupportMap.end(); ++itClaimsAndSupports) { - UniValue claimAndSupportsObj = claimsAndSupportsToJSON(itClaimsAndSupports, nCurrentHeight); + CAmount nEffectiveAmount = claimsForName.getEffectiveAmountForClaim(itClaimsAndSupports->second.first.claimId,nCurrentHeight); + UniValue claimAndSupportsObj = claimsAndSupportsToJSON(itClaimsAndSupports, nEffectiveAmount); claimObjs.push_back(claimAndSupportsObj); } ret.push_back(Pair("claims", claimObjs));