From 5ed097a3a60ca0d4a8bf5e658c7299170d0c516f Mon Sep 17 00:00:00 2001 From: kkurokawa Date: Sun, 7 Aug 2016 23:45:25 -0400 Subject: [PATCH 1/4] Return decimal values for amount in claimtrie RPC commands, instead of in dewey's --- src/rpc/claimtrie.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/rpc/claimtrie.cpp b/src/rpc/claimtrie.cpp index cd9ec1b8a..7e2edc0de 100644 --- a/src/rpc/claimtrie.cpp +++ b/src/rpc/claimtrie.cpp @@ -183,11 +183,12 @@ 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))); + ret.push_back(Pair("effective amount", ValueFromAmount(claim.nEffectiveAmount))); ret.push_back(Pair("height", claim.nHeight)); return ret; } @@ -214,7 +215,7 @@ UniValue claimsAndSupportsToJSON(claimSupportMapType::const_iterator itClaimsAnd { 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())); @@ -226,13 +227,13 @@ UniValue claimsAndSupportsToJSON(claimSupportMapType::const_iterator itClaimsAnd { 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 +252,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)); -- 2.45.3 From cbb6acd75c25fd48f8b3f83c414166beb3c828e2 Mon Sep 17 00:00:00 2001 From: Job Evers-Meltzer Date: Mon, 8 Aug 2016 10:02:46 -0500 Subject: [PATCH 2/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 3/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 09805a05b9c0ea917e99b8c41638f11799679b45 Mon Sep 17 00:00:00 2001 From: kkurokawa Date: Mon, 8 Aug 2016 18:16:27 -0400 Subject: [PATCH 4/4] add getEffectiveAmountForClaim method for claimsForNameType --- src/claimtrie.h | 26 +++++++++++++++++++++++++- src/rpc/claimtrie.cpp | 18 ++++++------------ 2 files changed, 31 insertions(+), 13 deletions(-) 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 7e2edc0de..f3d78466c 100644 --- a/src/rpc/claimtrie.cpp +++ b/src/rpc/claimtrie.cpp @@ -188,7 +188,9 @@ UniValue getvalueforname(const UniValue& params, bool fHelp) ret.push_back(Pair("txid", claim.outPoint.hash.GetHex())); ret.push_back(Pair("n", (int)claim.outPoint.n)); ret.push_back(Pair("amount", ValueFromAmount(claim.nAmount))); - ret.push_back(Pair("effective amount", ValueFromAmount(claim.nEffectiveAmount))); + 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; } @@ -197,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) { @@ -211,10 +212,6 @@ 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", ValueFromAmount(itSupports->nAmount))); supportObjs.push_back(supportObj); } @@ -223,10 +220,6 @@ 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", ValueFromAmount(claim.nAmount))); std::string sValue; if (getValueForClaim(claim.outPoint, sValue)) @@ -330,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)); -- 2.45.3