From fb04d9a908f4a86d66411170c7a97f6ce8a94cfb Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 16 Nov 2018 02:33:16 -1100 Subject: [PATCH 1/8] Add support for EVAL_HEIR --- src/cc/CCtx.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 787c14adc..d927119d6 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -137,9 +137,9 @@ std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTran { //fprintf(stderr,"matched %s unspendable2!\n",cp->unspendableaddr2); privkey = cp->unspendablepriv2; - if ( othercond2 == 0 && cp->evalcode != EVAL_CHANNELS) + if ( othercond2 == 0 && cp->evalcode != EVAL_CHANNELS && cp->evalcode != EVAL_HEIR ) othercond2 = MakeCCcond1(cp->evalcode2,cp->unspendablepk2); - else if ( othercond2 == 0 && cp->evalcode == EVAL_CHANNELS) + else if ( othercond2 == 0 && (cp->evalcode == EVAL_CHANNELS || cp->evalcode == EVAL_HEIR) ) othercond2 = MakeCCcond1of2(cp->evalcode2,cp->unspendablepk2,cp->unspendablepk3); cond = othercond2; } From 2c85dd261a81e804682551b99bc774b76bac36c9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 16 Nov 2018 20:36:46 -1100 Subject: [PATCH 2/8] Fix -ac_script --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index a8c6e087c..d3fbf3285 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -444,7 +444,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) txNew.vout.resize(2); txNew.vout[1].nValue = commission; if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) - txNew.vout[1].scriptPubKey = CScript() << ParseHex(ASSETCHAINS_SCRIPTPUB); + txNew.vout[1].scriptPubKey = ParseHex(ASSETCHAINS_SCRIPTPUB.c_str()); //CScript() << else { txNew.vout[1].scriptPubKey.resize(35); From be0d30ee9aedf8d644a87889dabc864fc0e0c208 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 16 Nov 2018 20:38:09 -1100 Subject: [PATCH 3/8] Syntax --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index d3fbf3285..82ee8e1c4 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -444,7 +444,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) txNew.vout.resize(2); txNew.vout[1].nValue = commission; if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) - txNew.vout[1].scriptPubKey = ParseHex(ASSETCHAINS_SCRIPTPUB.c_str()); //CScript() << + txNew.vout[1].scriptPubKey = CScript() << ParseHex(ASSETCHAINS_SCRIPTPUB.c_str()); else { txNew.vout[1].scriptPubKey.resize(35); From ca2dd59830ac8d611374a83463aefe7b92165c04 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 16 Nov 2018 21:15:24 -1100 Subject: [PATCH 4/8] Fix -ac_pubkey assumptions --- src/komodo_bitcoind.h | 21 +++++++++++++++++---- src/main.cpp | 4 ++-- src/miner.cpp | 24 ++++++++++++++++++++---- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0e58e800e..bb67f9e5c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1602,13 +1602,26 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); } } - if ( failed == 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) + if ( failed == 0 && ASSETCHAINS_COMMISSION != 0 ) //ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) { if ( height == 1 ) { - script = (uint8_t *)pblock->vtx[0].vout[0].scriptPubKey.data(); - if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) - return(-1); + if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) + { + int32_t scriptlen; uint8_t scripthex[10000]; + if ( ASSETCHAINS_SCRIPTPUB.size()/2 == pblock->vtx[0].vout[0].scriptPubKey.size() && scriptlen < sizeof(scripthex) ) + { + decode_hex(scripthex,scriptlen,(char *)ASSETCHAINS_SCRIPTPUB.c_str()); + if ( memcmp(scripthex,script,scriptlen) != 0 ) + return(-1); + } else return(-1); + } + else + { + script = (uint8_t *)pblock->vtx[0].vout[0].scriptPubKey.data(); + if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) + return(-1); + } } else { diff --git a/src/main.cpp b/src/main.cpp index 4ebe7790e..9a8e97e1b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3127,12 +3127,12 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin LogPrint("bench", " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs]\n", (unsigned)block.vtx.size(), 0.001 * (nTime1 - nTimeStart), 0.001 * (nTime1 - nTimeStart) / block.vtx.size(), nInputs <= 1 ? 0 : 0.001 * (nTime1 - nTimeStart) / (nInputs-1), nTimeConnect * 0.000001); CAmount blockReward = nFees + GetBlockSubsidy(pindex->nHeight, chainparams.GetConsensus()) + sum; - if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 ) + if ( ASSETCHAINS_COMMISSION != 0 ) //ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && { uint64_t checktoshis; if ( (checktoshis= komodo_commission((CBlock *)&block,(int32_t)pindex->nHeight)) != 0 ) { - if ( block.vtx[0].vout.size() == 2 && block.vtx[0].vout[1].nValue == checktoshis ) + if ( block.vtx[0].vout.size() >= 2 && block.vtx[0].vout[1].nValue == checktoshis ) blockReward += checktoshis; else fprintf(stderr,"checktoshis %.8f numvouts %d\n",dstr(checktoshis),(int32_t)block.vtx[0].vout.size()); } diff --git a/src/miner.cpp b/src/miner.cpp index 82ee8e1c4..ba5922f45 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -444,7 +444,14 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) txNew.vout.resize(2); txNew.vout[1].nValue = commission; if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) - txNew.vout[1].scriptPubKey = CScript() << ParseHex(ASSETCHAINS_SCRIPTPUB.c_str()); + { + //txNew.vout[1].scriptPubKey = CScript() << ParseHex(); + int32_t len = strlen(ASSETCHAINS_SCRIPTPUB.c_str()); + len >>= 1; + txNew.vout[1].scriptPubKey.resize(len); + ptr = (uint8_t *)txNew.vout[1].scriptPubKey.data(); + decode_hex(ptr,len,ASSETCHAINS_SCRIPTPUB.c_str()); + } else { txNew.vout[1].scriptPubKey.resize(35); @@ -620,10 +627,19 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey,int32_t nHeight,int32_t gpucount) { - CPubKey pubkey; CScript scriptPubKey; uint8_t *script,*ptr; int32_t i; - if ( nHeight == 1 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) + CPubKey pubkey; CScript scriptPubKey; uint8_t *script,*ptr; int32_t i,len; + if ( nHeight == 1 && ASSETCHAINS_COMMISSION != 0 ) { - scriptPubKey = CScript() << ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY) << OP_CHECKSIG; + if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) + scriptPubKey = CScript() << ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY) << OP_CHECKSIG; + else + { + len = strlen(ASSETCHAINS_SCRIPTPUB.c_str()); + len >>= 1; + pubkey.resize(len); + ptr = (uint8_t *)pubkey.data(); + decode_hex(ptr,len,ASSETCHAINS_SCRIPTPUB.c_str()); + } } else if ( USE_EXTERNAL_PUBKEY != 0 ) { From 3023ca419f895b35a6ce129051c4ec58bee5f53b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 16 Nov 2018 21:18:26 -1100 Subject: [PATCH 5/8] Set scriptPubKey --- src/miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index ba5922f45..ae0c5839c 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -636,8 +636,8 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey,int32_t nHeight,in { len = strlen(ASSETCHAINS_SCRIPTPUB.c_str()); len >>= 1; - pubkey.resize(len); - ptr = (uint8_t *)pubkey.data(); + scriptPubKey.resize(len); + ptr = (uint8_t *)scriptPubKey.data(); decode_hex(ptr,len,ASSETCHAINS_SCRIPTPUB.c_str()); } } From 7c38e803e50d23ede9eebc5e912e26692e2d88ff Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 16 Nov 2018 21:19:24 -1100 Subject: [PATCH 6/8] int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); --- src/miner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/miner.cpp b/src/miner.cpp index ae0c5839c..021053cb6 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -122,6 +122,7 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ uint64_t komodo_commission(const CBlock *block,int32_t height); int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig); int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33); +int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) { From d2b51bd2c50bab9fdf26acf4fa8ab6365297fb74 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 16 Nov 2018 21:20:37 -1100 Subject: [PATCH 7/8] (Char *) --- src/miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 021053cb6..5ffbe3d95 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -451,7 +451,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) len >>= 1; txNew.vout[1].scriptPubKey.resize(len); ptr = (uint8_t *)txNew.vout[1].scriptPubKey.data(); - decode_hex(ptr,len,ASSETCHAINS_SCRIPTPUB.c_str()); + decode_hex(ptr,len,(char *)ASSETCHAINS_SCRIPTPUB.c_str()); } else { @@ -639,7 +639,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey,int32_t nHeight,in len >>= 1; scriptPubKey.resize(len); ptr = (uint8_t *)scriptPubKey.data(); - decode_hex(ptr,len,ASSETCHAINS_SCRIPTPUB.c_str()); + decode_hex(ptr,len,(char *)ASSETCHAINS_SCRIPTPUB.c_str()); } } else if ( USE_EXTERNAL_PUBKEY != 0 ) From c1cf02312a73b50a1e68888c450d7e31237d75b1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 16 Nov 2018 21:42:36 -1100 Subject: [PATCH 8/8] Require -ac_perc when -ac_pubkey --- src/komodo_utils.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 6493d51d0..d6421764f 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1594,10 +1594,18 @@ void komodo_args(char *argv0) decode_hex(ASSETCHAINS_OVERRIDE_PUBKEY33,33,(char *)ASSETCHAINS_OVERRIDE_PUBKEY.c_str()); calc_rmd160_sha256(ASSETCHAINS_OVERRIDE_PUBKEYHASH,ASSETCHAINS_OVERRIDE_PUBKEY33,33); } - if ( ASSETCHAINS_COMMISSION == 0 && ASSETCHAINS_FOUNDERS != 0 ) + if ( ASSETCHAINS_COMMISSION == 0 ) { - ASSETCHAINS_COMMISSION = 53846154; // maps to 35% - printf("ASSETCHAINS_COMMISSION defaulted to 35%% when founders reward active\n"); + if (ASSETCHAINS_FOUNDERS != 0 ) + { + ASSETCHAINS_COMMISSION = 53846154; // maps to 35% + printf("ASSETCHAINS_COMMISSION defaulted to 35%% when founders reward active\n"); + } + else + { + ASSETCHAINS_OVERRIDE_PUBKEY.clear(); + printf("-ac_perc must be set with -ac_pubkey\n"); + } } } else