From f9913c7a5a1501fdd0aa359178d399967b5e1b06 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Mar 2019 23:33:41 -1100 Subject: [PATCH 01/29] Set max_money --- src/komodo_globals.h | 3 ++- src/komodo_utils.h | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 13de7c310..bfac8cb93 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -266,7 +266,7 @@ uint64_t komodo_current_supply(uint32_t nHeight) } #define KOMODO_MAXNVALUE (((uint64_t)1 << 63) - 1) #define KOMODO_BIT63SET(x) ((x) & ((uint64_t)1 << 63)) - + cur_money *= COIN; if ( KOMODO_BIT63SET(cur_money) != 0 ) return(KOMODO_MAXNVALUE); if ( ASSETCHAINS_COMMISSION != 0 ) @@ -278,5 +278,6 @@ uint64_t komodo_current_supply(uint32_t nHeight) return(KOMODO_MAXNVALUE); return(newval); } + fprintf(stderr,"cur_money %.8f\n",(double)cur_money/COIN); return(cur_money); } diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 65114c16b..56af296a6 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -2049,9 +2049,9 @@ void komodo_args(char *argv0) if ( ASSETCHAINS_CC >= KOMODO_FIRSTFUNGIBLEID && MAX_MONEY < 1000000LL*SATOSHIDEN ) MAX_MONEY = 1000000LL*SATOSHIDEN; - if ( MAX_MONEY <= 0 || MAX_MONEY > 10000100000LL*SATOSHIDEN ) - MAX_MONEY = 10000100000LL*SATOSHIDEN; - //fprintf(stderr,"MAX_MONEY %llu %.8f\n",(long long)MAX_MONEY,(double)MAX_MONEY/SATOSHIDEN); + if ( MAX_MONEY <= 0 || MAX_MONEY > (uint64_t)90*1000*1000*1000*SATOSHIDEN ) + MAX_MONEY = (uint64_t)90*1000*1000*1000*SATOSHIDEN; + fprintf(stderr,"MAX_MONEY %llu %.8f\n",(long long)MAX_MONEY,(double)MAX_MONEY/SATOSHIDEN); //printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,ASSETCHAINS_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); uint16_t tmpport = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); if ( GetArg("-port",0) != 0 ) From 5a39e093312551e9c4c46f22b35e98d15cd18f2b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Mar 2019 23:38:27 -1100 Subject: [PATCH 02/29] ASSETCHAINS_SUPPLY --- src/komodo_utils.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 56af296a6..e7d71e686 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1792,6 +1792,8 @@ void komodo_args(char *argv0) fprintf(stderr,"-ac_supply must be less than 90 billion\n"); exit(0); } + fprintf(stderr,"ASSETCHAINS_SUPPLY %llu\n",(long long)ASSETCHAINS_SUPPLY); + ASSETCHAINS_COMMISSION = GetArg("-ac_perc",0); ASSETCHAINS_OVERRIDE_PUBKEY = GetArg("-ac_pubkey",""); ASSETCHAINS_SCRIPTPUB = GetArg("-ac_script",""); From fe8f69b08c44ed35bc57c22e08d3ec339639d084 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Mar 2019 23:42:00 -1100 Subject: [PATCH 03/29] unmult --- src/komodo_globals.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index bfac8cb93..7370e8c70 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -142,7 +142,7 @@ uint64_t komodo_current_supply(uint32_t nHeight) cur_money = (ASSETCHAINS_SUPPLY+1) * SATOSHIDEN + (ASSETCHAINS_MAGIC & 0xffffff) + ASSETCHAINS_GENESISTXVAL; if ( ASSETCHAINS_LASTERA == 0 && ASSETCHAINS_REWARD[0] == 0 ) { - cur_money += (nHeight * 10000) / SATOSHIDEN; + cur_money += (nHeight * 10000);// / SATOSHIDEN; } else { @@ -266,7 +266,6 @@ uint64_t komodo_current_supply(uint32_t nHeight) } #define KOMODO_MAXNVALUE (((uint64_t)1 << 63) - 1) #define KOMODO_BIT63SET(x) ((x) & ((uint64_t)1 << 63)) - cur_money *= COIN; if ( KOMODO_BIT63SET(cur_money) != 0 ) return(KOMODO_MAXNVALUE); if ( ASSETCHAINS_COMMISSION != 0 ) From 0cf62abcbd5769c5c18696903ea6239ea50d616e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Mar 2019 23:47:17 -1100 Subject: [PATCH 04/29] MAX_MONEY capped at 63 bits - 1 --- src/komodo_utils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index e7d71e686..3b7d06401 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -2051,8 +2051,8 @@ void komodo_args(char *argv0) if ( ASSETCHAINS_CC >= KOMODO_FIRSTFUNGIBLEID && MAX_MONEY < 1000000LL*SATOSHIDEN ) MAX_MONEY = 1000000LL*SATOSHIDEN; - if ( MAX_MONEY <= 0 || MAX_MONEY > (uint64_t)90*1000*1000*1000*SATOSHIDEN ) - MAX_MONEY = (uint64_t)90*1000*1000*1000*SATOSHIDEN; + if ( KOMODO_BIT63SET(MAX_MONEY) != 0 ) + MAX_MONEY = KOMODO_MAXNVALUE; fprintf(stderr,"MAX_MONEY %llu %.8f\n",(long long)MAX_MONEY,(double)MAX_MONEY/SATOSHIDEN); //printf("baseid.%d MAX_MONEY.%s %.8f\n",baseid,ASSETCHAINS_SYMBOL,(double)MAX_MONEY/SATOSHIDEN); uint16_t tmpport = komodo_port(ASSETCHAINS_SYMBOL,ASSETCHAINS_SUPPLY,&ASSETCHAINS_MAGIC,extraptr,extralen); From a8ef36c29cfe8454c2e9d2d13de931c6dff14233 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Mar 2019 23:53:02 -1100 Subject: [PATCH 05/29] Test version --- src/cc/rogue/rogue.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/rogue/rogue.h b/src/cc/rogue/rogue.h index 8c1101fc6..b59ee710f 100644 --- a/src/cc/rogue/rogue.h +++ b/src/cc/rogue/rogue.h @@ -60,7 +60,7 @@ #define MAXOBJ 9 #define MAXPACK 23 #define MAXTRAPS 10 -#define AMULETLEVEL 26 +#define AMULETLEVEL 3 //26 #define NUMTHINGS 7 /* number of types of things */ #define MAXPASS 13 /* upper limit on number of passages */ #define NUMLINES 24 From 5fde22c3d897fc71fae6b2b0e8876cd73493e9e5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Mar 2019 00:33:39 -1100 Subject: [PATCH 06/29] Amulet -> level 26 --- src/cc/rogue/rogue.h | 2 +- src/utilstrencodings.cpp | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/cc/rogue/rogue.h b/src/cc/rogue/rogue.h index b59ee710f..8c1101fc6 100644 --- a/src/cc/rogue/rogue.h +++ b/src/cc/rogue/rogue.h @@ -60,7 +60,7 @@ #define MAXOBJ 9 #define MAXPACK 23 #define MAXTRAPS 10 -#define AMULETLEVEL 3 //26 +#define AMULETLEVEL 26 #define NUMTHINGS 7 /* number of types of things */ #define MAXPASS 13 /* upper limit on number of passages */ #define NUMLINES 24 diff --git a/src/utilstrencodings.cpp b/src/utilstrencodings.cpp index ece2ec73e..f1cba3f43 100644 --- a/src/utilstrencodings.cpp +++ b/src/utilstrencodings.cpp @@ -419,10 +419,26 @@ bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out) int mantissa_tzeros = 0; bool mantissa_sign = false; bool exponent_sign = false; - int ptr = 0; + int i,n,ptr = 0; char *str = val.c_str(); int end = val.size(); int point_ofs = 0; - + n = val.size(); + if ( n == 11 && (val[0] < '9' || val[1] < '3') ) + { + uint64_t val64 = 0; + for (i=0; i '9' ) + break; + val64 = (val64 * 10) + (val[i] - '0') + } + if ( i == n ) // 90000000000 + { + *amount_out = val64 * COIN; + fprintf(stderr,"special case: %s -> %.8f\n",val.c_str(),(double)val64/COIN); + return(true); + } + } if (ptr < end && val[ptr] == '-') { mantissa_sign = true; ++ptr; From a99263b97e6061250d0edab74709466d234e9478 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Mar 2019 00:35:59 -1100 Subject: [PATCH 07/29] Syntax --- src/utilstrencodings.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utilstrencodings.cpp b/src/utilstrencodings.cpp index f1cba3f43..e08993993 100644 --- a/src/utilstrencodings.cpp +++ b/src/utilstrencodings.cpp @@ -419,7 +419,7 @@ bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out) int mantissa_tzeros = 0; bool mantissa_sign = false; bool exponent_sign = false; - int i,n,ptr = 0; char *str = val.c_str(); + int i,n,ptr = 0; char *str = (char *)val.c_str(); int end = val.size(); int point_ofs = 0; n = val.size(); @@ -430,7 +430,7 @@ bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out) { if ( val[i] < '0' || val[i] > '9' ) break; - val64 = (val64 * 10) + (val[i] - '0') + val64 = (val64 * 10) + (val[i] - '0'); } if ( i == n ) // 90000000000 { From 59c289c8a2db0aaec825297a701c0528bf25ab06 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Mar 2019 00:36:33 -1100 Subject: [PATCH 08/29] 100000000 --- src/utilstrencodings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utilstrencodings.cpp b/src/utilstrencodings.cpp index e08993993..861a07b03 100644 --- a/src/utilstrencodings.cpp +++ b/src/utilstrencodings.cpp @@ -434,7 +434,7 @@ bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out) } if ( i == n ) // 90000000000 { - *amount_out = val64 * COIN; + *amount_out = val64 * 100000000; fprintf(stderr,"special case: %s -> %.8f\n",val.c_str(),(double)val64/COIN); return(true); } From ef691d5a4c1601eed87aa2e237d8c428ba6ba13b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Mar 2019 00:37:14 -1100 Subject: [PATCH 09/29] 100000000 --- src/utilstrencodings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utilstrencodings.cpp b/src/utilstrencodings.cpp index 861a07b03..10902054f 100644 --- a/src/utilstrencodings.cpp +++ b/src/utilstrencodings.cpp @@ -435,7 +435,7 @@ bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out) if ( i == n ) // 90000000000 { *amount_out = val64 * 100000000; - fprintf(stderr,"special case: %s -> %.8f\n",val.c_str(),(double)val64/COIN); + fprintf(stderr,"special case: %s -> %.8f\n",val.c_str(),(double)val64/100000000); return(true); } } From 9615ec75746118c5846c68f3ee9ec72a94d783bd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Mar 2019 00:46:51 -1100 Subject: [PATCH 10/29] Test --- src/utilstrencodings.cpp | 2 +- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utilstrencodings.cpp b/src/utilstrencodings.cpp index 10902054f..df788b2ab 100644 --- a/src/utilstrencodings.cpp +++ b/src/utilstrencodings.cpp @@ -435,7 +435,7 @@ bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out) if ( i == n ) // 90000000000 { *amount_out = val64 * 100000000; - fprintf(stderr,"special case: %s -> %.8f\n",val.c_str(),(double)val64/100000000); + fprintf(stderr,"special case: %s -> %.8f\n",val.c_str(),(double)*amount_out/100000000); return(true); } } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 46cc71958..5200677fd 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -421,7 +421,7 @@ static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtr // Check amount if (nValue <= 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid amount"); - +fprintf(stderr,"nValue %.8f vs curBalance %.8f\n",(double)nValue/COIN,(double)curBalance/COIN); if (nValue > curBalance) throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds"); From 62cea0f4e863f3861054a8e35bcccdd8bdf766bd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Mar 2019 01:18:01 -1100 Subject: [PATCH 11/29] +print --- src/main.cpp | 2 +- src/utilstrencodings.cpp | 2 +- src/wallet/rpcwallet.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c88f1520a..2aad3b9bb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2870,7 +2870,7 @@ namespace { hasher << hashBlock; hasher << blockundo; if (hashChecksum != hasher.GetHash()) - return error("%s: Checksum mismatch", __func__); + return error("%s: Checksum mismatch %s vs %s", __func__,hashChecksum.GetHex().c_str(),hasher.GetHash().GetHex().c_str()); return true; } diff --git a/src/utilstrencodings.cpp b/src/utilstrencodings.cpp index df788b2ab..d4bba72ee 100644 --- a/src/utilstrencodings.cpp +++ b/src/utilstrencodings.cpp @@ -435,7 +435,7 @@ bool ParseFixedPoint(const std::string &val, int decimals, int64_t *amount_out) if ( i == n ) // 90000000000 { *amount_out = val64 * 100000000; - fprintf(stderr,"special case: %s -> %.8f\n",val.c_str(),(double)*amount_out/100000000); + //fprintf(stderr,"special case: %s -> %.8f\n",val.c_str(),(double)*amount_out/100000000); return(true); } } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5200677fd..6cf8eeed8 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -421,7 +421,7 @@ static void SendMoney(const CTxDestination &address, CAmount nValue, bool fSubtr // Check amount if (nValue <= 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid amount"); -fprintf(stderr,"nValue %.8f vs curBalance %.8f\n",(double)nValue/COIN,(double)curBalance/COIN); +//fprintf(stderr,"nValue %.8f vs curBalance %.8f\n",(double)nValue/COIN,(double)curBalance/COIN); if (nValue > curBalance) throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds"); From 93ba595a83137d0cf75fa452abb626100a7acbe2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Mar 2019 01:51:51 -1100 Subject: [PATCH 12/29] +print --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 2aad3b9bb..e02ec515b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2845,7 +2845,7 @@ namespace { hasher << hashBlock; hasher << blockundo; fileout << hasher.GetHash(); - +fprintf(stderr,"hashBlock.%s hasher.%s\n",hashBlock.GetHex().c_str(),hasher.GetHash().GetHex().c_str()); return true; } @@ -2870,7 +2870,7 @@ namespace { hasher << hashBlock; hasher << blockundo; if (hashChecksum != hasher.GetHash()) - return error("%s: Checksum mismatch %s vs %s", __func__,hashChecksum.GetHex().c_str(),hasher.GetHash().GetHex().c_str()); + return error("%s: %s Checksum mismatch %s vs %s", __func__,hashBlock.GetHex().c_str(),hashChecksum.GetHex().c_str(),hasher.GetHash().GetHex().c_str()); return true; } @@ -3634,6 +3634,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin return true; // Write undo information to disk + fprintf(stderr,"isNull %d vs isvalid %d nStatus %x\n",pindex->GetUndoPos().IsNull(),pindex->IsValid(BLOCK_VALID_SCRIPTS),(uint32_t)pindex->nStatus); if (pindex->GetUndoPos().IsNull() || !pindex->IsValid(BLOCK_VALID_SCRIPTS)) { if (pindex->GetUndoPos().IsNull()) { @@ -3644,7 +3645,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin fprintf(stderr,"ConnectBlock: unexpected null pprev\n"); if (!UndoWriteToDisk(blockundo, pos, pindex->pprev->GetBlockHash(), chainparams.MessageStart())) return AbortNode(state, "Failed to write undo data"); - // update nUndoPos in block index pindex->nUndoPos = pos.nPos; pindex->nStatus |= BLOCK_HAVE_UNDO; From 4a8df61a7be185823547495e092ff34fa54129aa Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Mar 2019 01:54:50 -1100 Subject: [PATCH 13/29] +print --- src/main.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e02ec515b..1d7a6f8b1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3634,10 +3634,11 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin return true; // Write undo information to disk - fprintf(stderr,"isNull %d vs isvalid %d nStatus %x\n",pindex->GetUndoPos().IsNull(),pindex->IsValid(BLOCK_VALID_SCRIPTS),(uint32_t)pindex->nStatus); + fprintf(stderr,"nFile.%d isNull %d vs isvalid %d nStatus %x\n",(int32_t)pindex->nFile,pindex->GetUndoPos().IsNull(),pindex->IsValid(BLOCK_VALID_SCRIPTS),(uint32_t)pindex->nStatus); if (pindex->GetUndoPos().IsNull() || !pindex->IsValid(BLOCK_VALID_SCRIPTS)) { - if (pindex->GetUndoPos().IsNull()) { + if (pindex->GetUndoPos().IsNull()) + { CDiskBlockPos pos; if (!FindUndoPos(state, pindex->nFile, pos, ::GetSerializeSize(blockundo, SER_DISK, CLIENT_VERSION) + 40)) return error("ConnectBlock(): FindUndoPos failed"); @@ -3649,7 +3650,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin pindex->nUndoPos = pos.nPos; pindex->nStatus |= BLOCK_HAVE_UNDO; } - + // Now that all consensus rules have been validated, set nCachedBranchId. // Move this if BLOCK_VALID_CONSENSUS is ever altered. static_assert(BLOCK_VALID_CONSENSUS == BLOCK_VALID_SCRIPTS, @@ -3660,7 +3661,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin } else if (pindex->pprev) { pindex->nCachedBranchId = pindex->pprev->nCachedBranchId; } - + pindex->RaiseValidity(BLOCK_VALID_SCRIPTS); setDirtyBlockIndex.insert(pindex); } From 00b0b26fd41cdf553082d8156b7863bdaf22e684 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Mar 2019 02:25:57 -1100 Subject: [PATCH 14/29] -print --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 1d7a6f8b1..e0b2ec8bc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3634,7 +3634,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin return true; // Write undo information to disk - fprintf(stderr,"nFile.%d isNull %d vs isvalid %d nStatus %x\n",(int32_t)pindex->nFile,pindex->GetUndoPos().IsNull(),pindex->IsValid(BLOCK_VALID_SCRIPTS),(uint32_t)pindex->nStatus); + //fprintf(stderr,"nFile.%d isNull %d vs isvalid %d nStatus %x\n",(int32_t)pindex->nFile,pindex->GetUndoPos().IsNull(),pindex->IsValid(BLOCK_VALID_SCRIPTS),(uint32_t)pindex->nStatus); if (pindex->GetUndoPos().IsNull() || !pindex->IsValid(BLOCK_VALID_SCRIPTS)) { if (pindex->GetUndoPos().IsNull()) From 1d0d663b920ca6899017afcf23eb1beb80e26a00 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Mar 2019 02:33:02 -1100 Subject: [PATCH 15/29] Test --- src/main.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index e0b2ec8bc..b97f04f63 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3499,7 +3499,10 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin prevsum = voutsum; voutsum += valueout; if ( KOMODO_BIT63SET(voutsum) != 0 ) + { + fprintf(stderr,"voutsum %.8f too big\n",(double)voutsum/COIN); return state.DoS(100, error("ConnectBlock(): voutsum too big"),REJECT_INVALID,"tx valueout is too big"); + } else if ( voutsum < prevsum ) return state.DoS(100, error("ConnectBlock(): voutsum less after adding valueout"),REJECT_INVALID,"tx valueout is too big"); if (!tx.IsCoinBase()) From 0c03bfd48e491a591d62b48f6e8d2cd891ec8f8b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Mar 2019 02:40:49 -1100 Subject: [PATCH 16/29] -print --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index b97f04f63..1b88aecf7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2845,7 +2845,7 @@ namespace { hasher << hashBlock; hasher << blockundo; fileout << hasher.GetHash(); -fprintf(stderr,"hashBlock.%s hasher.%s\n",hashBlock.GetHex().c_str(),hasher.GetHash().GetHex().c_str()); +//fprintf(stderr,"hashBlock.%s hasher.%s\n",hashBlock.GetHex().c_str(),hasher.GetHash().GetHex().c_str()); return true; } From 16efbff11a7cae11be9466a506c121fc09db1356 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Mar 2019 02:55:51 -1100 Subject: [PATCH 17/29] Billion at a time --- src/komodo_globals.h | 2 ++ src/komodo_utils.h | 13 +++++++++++-- src/main.cpp | 6 +++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 7370e8c70..551a61704 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -266,6 +266,8 @@ uint64_t komodo_current_supply(uint32_t nHeight) } #define KOMODO_MAXNVALUE (((uint64_t)1 << 63) - 1) #define KOMODO_BIT63SET(x) ((x) & ((uint64_t)1 << 63)) +#define KOMODO_VALUETOOBIG(x) ((x) > (uint64_t)10000000000) + if ( KOMODO_BIT63SET(cur_money) != 0 ) return(KOMODO_MAXNVALUE); if ( ASSETCHAINS_COMMISSION != 0 ) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 3b7d06401..4086af94c 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1639,9 +1639,18 @@ uint64_t komodo_ac_block_subsidy(int nHeight) } } } - if ( nHeight == 1 ) + uint32_t magicExtra = ASSETCHAINS_STAKED ? ASSETCHAINS_MAGIC : (ASSETCHAINS_MAGIC & 0xffffff); + if ( ASSETCHAINS_SUPPLY > 1000000000 ) + { + if ( nHeight <= ASSETCHAINS_SUPPLY/1000000000 ) + { + subsidy = (uint64_t)1000000000 * COIN; + if ( nHeight == 1 ) + subsidy += magicExtra; + } + } + else if ( nHeight == 1 ) { - uint32_t magicExtra = ASSETCHAINS_STAKED ? ASSETCHAINS_MAGIC : (ASSETCHAINS_MAGIC & 0xffffff); if ( ASSETCHAINS_LASTERA == 0 ) subsidy = ASSETCHAINS_SUPPLY * SATOSHIDEN + magicExtra; else diff --git a/src/main.cpp b/src/main.cpp index 1b88aecf7..603ad054c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1808,7 +1808,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa CAmount nValueOut = tx.GetValueOut(); CAmount nFees = nValueIn-nValueOut; double dPriority = view.GetPriority(tx, chainActive.Height()); - if ( KOMODO_BIT63SET(nValueOut) != 0 ) + if ( KOMODO_VALUETOOBIG(nValueOut) != 0 ) return state.DoS(100, error("AcceptToMemoryPool: GetValueOut too big"),REJECT_INVALID,"tx valueout is too big"); // Keep track of transactions that spend a coinbase, which we re-scan @@ -3494,11 +3494,11 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin txdata.emplace_back(tx); valueout = tx.GetValueOut(); - if ( KOMODO_BIT63SET(valueout) != 0 ) + if ( KOMODO_VALUETOOBIG(valueout) != 0 ) return state.DoS(100, error("ConnectBlock(): GetValueOut too big"),REJECT_INVALID,"tx valueout is too big"); prevsum = voutsum; voutsum += valueout; - if ( KOMODO_BIT63SET(voutsum) != 0 ) + if ( KOMODO_VALUETOOBIG(voutsum) != 0 ) { fprintf(stderr,"voutsum %.8f too big\n",(double)voutsum/COIN); return state.DoS(100, error("ConnectBlock(): voutsum too big"),REJECT_INVALID,"tx valueout is too big"); From 36a8bd762f7fad8a42648a90ecfb5bfdbd8e7682 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Mar 2019 03:09:51 -1100 Subject: [PATCH 18/29] +print --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index a567e2e20..1e7d29ff1 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -621,7 +621,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 txNew.vout.resize(1); txNew.vout[0].scriptPubKey = scriptPubKeyIn; txNew.vout[0].nValue = GetBlockSubsidy(nHeight,consensusParams) + nFees; - + fprintf(stderr,"mine ht.%d with %.8f\n",(double)txNew.vout[0].nValue/COIN); txNew.nExpiryHeight = 0; txNew.nLockTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); From 685b22266364e916a9a1be318e4ddad73711287f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Mar 2019 03:11:32 -1100 Subject: [PATCH 19/29] nHeight --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 1e7d29ff1..556efb090 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -621,7 +621,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 txNew.vout.resize(1); txNew.vout[0].scriptPubKey = scriptPubKeyIn; txNew.vout[0].nValue = GetBlockSubsidy(nHeight,consensusParams) + nFees; - fprintf(stderr,"mine ht.%d with %.8f\n",(double)txNew.vout[0].nValue/COIN); + fprintf(stderr,"mine ht.%d with %.8f\n",nHeight,(double)txNew.vout[0].nValue/COIN); txNew.nExpiryHeight = 0; txNew.nLockTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); From 422b604ca59d6451b9aa8e61c5db07fc0b550a0e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Mar 2019 03:16:51 -1100 Subject: [PATCH 20/29] Test --- src/main.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 603ad054c..370e1e98b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3495,7 +3495,10 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin valueout = tx.GetValueOut(); if ( KOMODO_VALUETOOBIG(valueout) != 0 ) + { + fprintf(stderr,"valueout %.8f too big\n",(double)valueout/COIN); return state.DoS(100, error("ConnectBlock(): GetValueOut too big"),REJECT_INVALID,"tx valueout is too big"); + } prevsum = voutsum; voutsum += valueout; if ( KOMODO_VALUETOOBIG(voutsum) != 0 ) From de704db25fbbda344280b181be1ca09adb54c111 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Mar 2019 03:19:41 -1100 Subject: [PATCH 21/29] Too big --- src/komodo_globals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 551a61704..a752d0b8b 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -266,7 +266,7 @@ uint64_t komodo_current_supply(uint32_t nHeight) } #define KOMODO_MAXNVALUE (((uint64_t)1 << 63) - 1) #define KOMODO_BIT63SET(x) ((x) & ((uint64_t)1 << 63)) -#define KOMODO_VALUETOOBIG(x) ((x) > (uint64_t)10000000000) +#define KOMODO_VALUETOOBIG(x) ((x) > (uint64_t)10000000000*COIN) if ( KOMODO_BIT63SET(cur_money) != 0 ) return(KOMODO_MAXNVALUE); From e8afffb17b28bfb26878efa105b8d898e26e5ab0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Mar 2019 03:27:25 -1100 Subject: [PATCH 22/29] Prevent miner from mining too big a block in txvalue --- src/miner.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 556efb090..eb7c2d185 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -173,7 +173,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 } } else pk = _pk; - uint64_t deposits; int32_t isrealtime,kmdheight; uint32_t blocktime; const CChainParams& chainparams = Params(); + uint64_t deposits,voutsum=0; int32_t isrealtime,kmdheight; uint32_t blocktime; const CChainParams& chainparams = Params(); bool fNotarisationBlock = false; std::vector NotarisationNotaries; //fprintf(stderr,"create new block\n"); @@ -221,6 +221,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 uint256 cbHash; + voutsum = GetBlockSubsidy(nHeight,consensusParams) + nFees; CBlockIndex* pindexPrev = 0; { ENTER_CRITICAL_SECTION(cs_main); @@ -270,7 +271,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 vecPriority.reserve(mempool.mapTx.size() + 1); // now add transactions from the mem pool - int32_t Notarisations = 0; + int32_t Notarisations = 0; uint64_t txvalue; for (CTxMemPool::indexed_transaction_set::iterator mi = mempool.mapTx.begin(); mi != mempool.mapTx.end(); ++mi) { @@ -285,7 +286,12 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 //fprintf(stderr,"coinbase.%d finaltx.%d expired.%d\n",tx.IsCoinBase(),IsFinalTx(tx, nHeight, nLockTimeCutoff),IsExpiredTx(tx, nHeight)); continue; } - + txvalue = tx.GetValueOut(); + if ( KOMODO_VALUETOOBIG(txvalue) != 0 ) + continue; + if ( KOMODO_VALUETOOBIG(txvalue + voutsum) != 0 ) + continue; + voutsum += txvalue; if ( ASSETCHAINS_SYMBOL[0] == 0 && komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,0) < 0 ) { //fprintf(stderr,"CreateNewBlock: komodo_validate_interest failure nHeight.%d nTime.%u vs locktime.%u\n",nHeight,(uint32_t)pblock->nTime,(uint32_t)tx.nLockTime); @@ -621,7 +627,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 txNew.vout.resize(1); txNew.vout[0].scriptPubKey = scriptPubKeyIn; txNew.vout[0].nValue = GetBlockSubsidy(nHeight,consensusParams) + nFees; - fprintf(stderr,"mine ht.%d with %.8f\n",nHeight,(double)txNew.vout[0].nValue/COIN); + //fprintf(stderr,"mine ht.%d with %.8f\n",nHeight,(double)txNew.vout[0].nValue/COIN); txNew.nExpiryHeight = 0; txNew.nLockTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); From 1f4863694b87c1187943f1c58c3df356fc5469e8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Mar 2019 03:32:18 -1100 Subject: [PATCH 23/29] Move things --- src/komodo_defs.h | 4 ++++ src/komodo_globals.h | 6 +----- src/miner.cpp | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 2c3647b30..e1b941197 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -34,6 +34,10 @@ #define GETBIT(bits,bitoffset) (((uint8_t *)bits)[(bitoffset) >> 3] & (1 << ((bitoffset) & 7))) #define CLEARBIT(bits,bitoffset) (((uint8_t *)bits)[(bitoffset) >> 3] &= ~(1 << ((bitoffset) & 7))) +#define KOMODO_MAXNVALUE (((uint64_t)1 << 63) - 1) +#define KOMODO_BIT63SET(x) ((x) & ((uint64_t)1 << 63)) +#define KOMODO_VALUETOOBIG(x) ((x) > (uint64_t)10000000000*COIN) + extern uint8_t ASSETCHAINS_TXPOW,ASSETCHAINS_PUBLIC; int32_t MAX_BLOCK_SIZE(int32_t height); extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; diff --git a/src/komodo_globals.h b/src/komodo_globals.h index a752d0b8b..44c12bdf4 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -263,11 +263,7 @@ uint64_t komodo_current_supply(uint32_t nHeight) } } } - } -#define KOMODO_MAXNVALUE (((uint64_t)1 << 63) - 1) -#define KOMODO_BIT63SET(x) ((x) & ((uint64_t)1 << 63)) -#define KOMODO_VALUETOOBIG(x) ((x) > (uint64_t)10000000000*COIN) - + } if ( KOMODO_BIT63SET(cur_money) != 0 ) return(KOMODO_MAXNVALUE); if ( ASSETCHAINS_COMMISSION != 0 ) diff --git a/src/miner.cpp b/src/miner.cpp index eb7c2d185..2069e5a8c 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -221,7 +221,6 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 uint256 cbHash; - voutsum = GetBlockSubsidy(nHeight,consensusParams) + nFees; CBlockIndex* pindexPrev = 0; { ENTER_CRITICAL_SECTION(cs_main); @@ -234,7 +233,8 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast(); uint32_t proposedTime = GetAdjustedTime(); - + voutsum = GetBlockSubsidy(nHeight,consensusParams) + 10000*COIN; // approx fees + if (proposedTime == nMedianTimePast) { // too fast or stuck, this addresses the too fast issue, while moving From 4a77a2d625b4d9ba1e6270eab2017379caf28f31 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Mar 2019 03:35:56 -1100 Subject: [PATCH 24/29] Prevent too big tx to enter mempool --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 370e1e98b..08869080e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1808,7 +1808,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa CAmount nValueOut = tx.GetValueOut(); CAmount nFees = nValueIn-nValueOut; double dPriority = view.GetPriority(tx, chainActive.Height()); - if ( KOMODO_VALUETOOBIG(nValueOut) != 0 ) + if ( KOMODO_VALUETOOBIG(nValueOut - 777777*COIN) != 0 ) // some room for blockreward and txfees return state.DoS(100, error("AcceptToMemoryPool: GetValueOut too big"),REJECT_INVALID,"tx valueout is too big"); // Keep track of transactions that spend a coinbase, which we re-scan From 0ca3cae55691f96654c4f12cc5c0d923f544d1e5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Mar 2019 03:43:08 -1100 Subject: [PATCH 25/29] Fix ac_subsidy calls --- src/komodo_utils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 4086af94c..e8608c8bd 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1644,9 +1644,9 @@ uint64_t komodo_ac_block_subsidy(int nHeight) { if ( nHeight <= ASSETCHAINS_SUPPLY/1000000000 ) { - subsidy = (uint64_t)1000000000 * COIN; + subsidy += (uint64_t)1000000000 * COIN; if ( nHeight == 1 ) - subsidy += magicExtra; + subsidy += (ASSETCHAINS_SUPPLY % 1000000000)*COIN + magicExtra; } } else if ( nHeight == 1 ) From f442acaeb6a6971ea5af00a72368dfc26538a3a0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Mar 2019 04:15:55 -1100 Subject: [PATCH 26/29] > 10 billion exemption --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index e8608c8bd..34d1d8d4d 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1640,7 +1640,7 @@ uint64_t komodo_ac_block_subsidy(int nHeight) } } uint32_t magicExtra = ASSETCHAINS_STAKED ? ASSETCHAINS_MAGIC : (ASSETCHAINS_MAGIC & 0xffffff); - if ( ASSETCHAINS_SUPPLY > 1000000000 ) + if ( ASSETCHAINS_SUPPLY > 10000000000 ) // over 10 billion? { if ( nHeight <= ASSETCHAINS_SUPPLY/1000000000 ) { From 92f2fe7cf05c561e1bc3858c753b3fad07d87a51 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Mar 2019 04:20:03 -1100 Subject: [PATCH 27/29] Prevent > 10 billion for -ac_script/-ac_perc --- src/komodo_utils.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 34d1d8d4d..2c4a2d040 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1896,6 +1896,11 @@ void komodo_args(char *argv0) } if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 || ASSETCHAINS_SCRIPTPUB.size() > 1 ) { + if ( ASSETCHAINS_SUPPLY > 10000000000 ) + { + printf("ac_pubkey or ac_script wont work with ac_supply over 10 billion\n"); + exit(0); + } if ( ASSETCHAINS_NOTARY_PAY[0] != 0 ) { printf("Assetchains NOTARY PAY cannot be used with ac_pubkey or ac_script.\n"); From c6322f54ec85bdef50bde970872cc1adbe82a45f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Mar 2019 05:18:27 -1100 Subject: [PATCH 28/29] Test slowflag --- src/komodo_bitcoind.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b846ba9d1..53472ae63 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2125,7 +2125,8 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); else { - bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); + if ( slowflag != 0 ) + bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); if ( bhash > bnTarget ) { for (i=31; i>=16; i--) From 845ce0b543a1c4f5cb851216eeebef6146aa5452 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Mar 2019 05:30:10 -1100 Subject: [PATCH 29/29] Height 100 exception --- src/komodo_bitcoind.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 53472ae63..70a1a7c02 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2125,9 +2125,8 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); else { - if ( slowflag != 0 ) - bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); - if ( bhash > bnTarget ) + bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); + if ( bhash > bnTarget && height > 100 ) { for (i=31; i>=16; i--) fprintf(stderr,"%02x",((uint8_t *)&bhash)[i]); @@ -2136,7 +2135,8 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); fprintf(stderr," ht.%d PoW diff violation PoSperc.%d vs goalperc.%d\n",height,PoSperc,(int32_t)ASSETCHAINS_STAKED); return(-1); - } else + } + else { failed = 0; CBlockIndex *pindex;