From e4a1e28c14fe3fc1b082366745f1b210dc0b8aab Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Nov 2016 09:47:14 -0300 Subject: [PATCH 01/28] test --- src/init.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index 1d0ffdb0b..f757beafd 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -514,7 +514,8 @@ void CleanupBlockRevFiles() remove(it->path()); } } - + path komodostate = GetDataDir() / "komodostate"; + remove(komodostate); // Remove all block files that aren't part of a contiguous set starting at // zero by walking the ordered map (keys are block file indices) by // keeping a separate counter. Once we hit a gap (or if 0 doesn't exist) From f24b36ca4c314fbc81072233cffcd545e23e6a63 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Nov 2016 11:46:27 -0300 Subject: [PATCH 02/28] test --- src/komodo_bitcoind.h | 17 +++++++++++++++++ src/komodo_globals.h | 2 +- src/main.cpp | 3 +++ src/miner.cpp | 23 +++++++++++------------ src/rpcmisc.cpp | 2 +- 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b37a4dfa7..ba994adda 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -388,6 +388,23 @@ void komodo_disconnect(CBlockIndex *pindex,CBlock& block) //komodo_stateupdate(-pindex->nHeight,0,0,0,zero,0,0,0,0,0,0,0); } +int32_t komodo_is_notarytx(const CTransaction& tx) +{ + uint8_t *ptr,crypto777[33]; +#ifdef KOMODO_ZCASH + ptr = (uint8_t *)block->vtx[0].vout[0].scriptPubKey.data(); +#else + ptr = (uint8_t *)&block->vtx[0].vout[0].scriptPubKey[0]; +#endif + decode_hex(crypto777,33,(char *)CRYPTO777_PUBSECPSTR); + if ( memcmp(ptr+1,crypto777,33) == 0 ) + { + printf("found notarytx\n"); + return(1); + } + else return(0); +} + int32_t komodo_block2height(CBlock *block) { int32_t i,n,height = 0; uint8_t *ptr; diff --git a/src/komodo_globals.h b/src/komodo_globals.h index ec5ee6127..bf9ac25ce 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -23,7 +23,7 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33) int COINBASE_MATURITY = 100; -int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,CURRENT_HEIGHT,ASSETCHAINS_SEED; +int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,CURRENT_HEIGHT,ASSETCHAINS_SEED,KOMODO_ON_DEMAND; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES; uint8_t NOTARY_PUBKEY33[33]; diff --git a/src/main.cpp b/src/main.cpp index 8c65fe825..dd1d52a92 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1044,6 +1044,7 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowFree) { + extern int32_t KOMODO_ON_DEMAND; { LOCK(mempool.cs); uint256 hash = tx.GetHash(); @@ -1268,6 +1269,8 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa } // Store transaction in memory + if ( komodo_is_notarytx(tx) == 0 ) + KOMODO_ON_DEMAND++; pool.addUnchecked(hash, entry, !IsInitialBlockDownload()); } diff --git a/src/miner.cpp b/src/miner.cpp index e90493f23..928bad008 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -99,12 +99,18 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, } #define ASSETCHAINS_MINHEIGHT 100 +#define ROUNDROBIN_DELAY 45 +extern int32_t ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,ASSETCHAINS_SHORTFLAG,KOMODO_REALTIME; +extern char ASSETCHAINS_SYMBOL[16]; +extern std::string NOTARY_PUBKEY; +extern uint8_t NOTARY_PUBKEY33[33]; +uint32_t Mining_start,Mining_height; +int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33); +int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33]); int32_t komodo_pax_opreturn(uint8_t *opret,int32_t maxsize); uint64_t komodo_paxtotal(); int32_t komodo_is_issuer(); int32_t komodo_gateway_deposits(CMutableTransaction *txNew,int32_t shortflag,char *symbol,int32_t tokomodo); -extern int32_t KOMODO_INITDONE,ASSETCHAINS_SHORTFLAG,KOMODO_REALTIME; -extern char ASSETCHAINS_SYMBOL[16]; CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) { @@ -114,11 +120,10 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if(!pblocktemplate.get()) return NULL; CBlock *pblock = &pblocktemplate->block; // pointer for convenience - //fprintf(stderr,"create new block %d\n",chainActive.Tip()->nHeight); if ( ASSETCHAINS_SYMBOL[0] != 0 && chainActive.Tip()->nHeight >= 100 ) { - fprintf(stderr,"start CreateNewBlock %s initdone.%d deposit %.8f mempool.%d RT.%u\n",ASSETCHAINS_SYMBOL,KOMODO_INITDONE,(double)komodo_paxtotal()/COIN,(int32_t)mempool.GetTotalTxSize(),KOMODO_REALTIME); - while ( mempool.GetTotalTxSize() <= 0 ) + fprintf(stderr,"start CreateNewBlock %s initdone.%d deposit %.8f mempool.%d RT.%u KOMODO_ON_DEMAND.%d\n",ASSETCHAINS_SYMBOL,KOMODO_INITDONE,(double)komodo_paxtotal()/COIN,(int32_t)mempool.GetTotalTxSize(),KOMODO_REALTIME,KOMODO_ON_DEMAND); + while ( KOMODO_ON_DEMAND == 0 )//mempool.GetTotalTxSize() <= 0 ) { deposits = komodo_paxtotal(); if ( KOMODO_INITDONE == 0 || KOMODO_REALTIME == 0 ) @@ -129,6 +134,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) break; sleep(10); } + KOMODO_ON_DEMAND = 0; if ( 0 && deposits != 0 ) printf("miner KOMODO_DEPOSIT %llu pblock->nHeight %d mempool.GetTotalTxSize(%d)\n",(long long)komodo_paxtotal(),(int32_t)chainActive.Tip()->nHeight,(int32_t)mempool.GetTotalTxSize()); } @@ -439,13 +445,6 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& // // Internal miner // -#define ROUNDROBIN_DELAY 45 -extern int32_t ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE; -extern std::string NOTARY_PUBKEY; -extern uint8_t NOTARY_PUBKEY33[33]; -uint32_t Mining_start,Mining_height; -int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33); -int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33]); CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey) { diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index c2cff8c00..4642a52db 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -85,7 +85,7 @@ Value getinfo(const Array& params, bool fHelp) obj.push_back(Pair("protocolversion", PROTOCOL_VERSION)); obj.push_back(Pair("notarized", NOTARIZED_HEIGHT)); obj.push_back(Pair("notarizedhash", NOTARIZED_HASH.ToString())); - obj.push_back(Pair("notarizedbtc", NOTARIZED_DESTTXID.ToString())); + obj.push_back(Pair("notarizedtxid", NOTARIZED_DESTTXID.ToString())); #ifdef ENABLE_WALLET if (pwalletMain) { obj.push_back(Pair("walletversion", pwalletMain->GetVersion())); From ed652d8b898eb9e8a8c225feb8a6822777b6cd1b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Nov 2016 11:47:38 -0300 Subject: [PATCH 03/28] test --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index ba994adda..1d9a8ebf8 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -392,9 +392,9 @@ int32_t komodo_is_notarytx(const CTransaction& tx) { uint8_t *ptr,crypto777[33]; #ifdef KOMODO_ZCASH - ptr = (uint8_t *)block->vtx[0].vout[0].scriptPubKey.data(); + ptr = (uint8_t *)tx.vout[0].scriptPubKey.data(); #else - ptr = (uint8_t *)&block->vtx[0].vout[0].scriptPubKey[0]; + ptr = (uint8_t *)&tx.vout[0].scriptPubKey[0]; #endif decode_hex(crypto777,33,(char *)CRYPTO777_PUBSECPSTR); if ( memcmp(ptr+1,crypto777,33) == 0 ) From 888cf827c98ca1105f8ac8a8590ef2832a06cae4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Nov 2016 16:21:48 -0300 Subject: [PATCH 04/28] test --- src/init.cpp | 2 ++ src/komodo.h | 45 ++++++++++++++++++++++++++++++++----------- src/komodo_bitcoind.h | 12 ++++++++++++ 3 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index f757beafd..fb2ae6aeb 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -516,6 +516,8 @@ void CleanupBlockRevFiles() } path komodostate = GetDataDir() / "komodostate"; remove(komodostate); + path minerids = GetDataDir() / "minerids"; + remove(minerids); // Remove all block files that aren't part of a contiguous set starting at // zero by walking the ordered map (keys are block file indices) by // keeping a separate counter. Once we hit a gap (or if 0 doesn't exist) diff --git a/src/komodo.h b/src/komodo.h index 94a204b21..d6c6c9d1e 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -17,12 +17,12 @@ #define H_KOMODO_H // Todo: +// 0. minerids file // 1. error check fiat redeem amounts // 2. net balance limiter -// 3. new RR algo -// 4. verify: interest payment, ratification, reorgs -// 5. automate notarization fee payouts -// 6. automated distribution of test REVS snapshot +// 3. verify: interest payment, ratification, reorgs +// 4. automate notarization fee payouts +// 5. automated distribution of test REVS snapshot #include #include @@ -33,6 +33,7 @@ #define GENESIS_NBITS 0x1f00ffff #define KOMODO_MINRATIFY 7 +FILE *Minerfp; int8_t Minerids[1024 * 1024 * 5]; // 5 million blocks #include "komodo_globals.h" @@ -48,14 +49,26 @@ int8_t Minerids[1024 * 1024 * 5]; // 5 million blocks void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t KMDheight,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout) { - static FILE *fp; static int32_t errs; char fname[512]; int32_t ht,func; uint8_t num,pubkeys[64][33]; -#ifdef WIN32 - sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),(char *)"komodostate"); -#else - sprintf(fname,"%s/%s",GetDataDir(false).string().c_str(),(char *)"komodostate"); -#endif + static FILE *fp; static int32_t errs; char fname[512],fname2[512]; int32_t ht,func; uint8_t num,pubkeys[64][33]; if ( fp == 0 ) { +#ifdef WIN32 + sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),(char *)"komodostate"); + sprintf(fname2,"%s\\%s",GetDataDir(false).string().c_str(),(char *)"minerids"); +#else + sprintf(fname,"%s/%s",GetDataDir(false).string().c_str(),(char *)"komodostate"); + sprintf(fname2,"%s/%s",GetDataDir(false).string().c_str(),(char *)"minerids"); +#endif + memset(Minerids,0xfe,sizeof(Minerids)); + if ( (Minerfp= fopen(fname2,"rb+")) == 0 ) + { + if ( (Minerfp= fopen(fname2,"wb")) != 0 ) + { + fwrite(Minerids,1,sizeof(Minerids),Minerfp); + fclose(Minerfp); + } + Minerfp = fopen(fname2,"rb+"); + } if ( (fp= fopen(fname,"rb+")) != 0 ) { while ( (func= fgetc(fp)) != EOF ) @@ -396,7 +409,17 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) if ( i == 0 && j == 0 && komodo_chosennotary(&nid,height,scriptbuf + 1) >= 0 ) { if ( height < sizeof(Minerids)/sizeof(*Minerids) ) - Minerids[height] = nid; + { + if ( (Minerids[height]= nid) >= -1 ) + { + if ( Minerfp != 0 ) + { + fseek(Minerfp,height,SEEK_SET); + fputc(Minerids[height],Minerfp); + fflush(Minerfp); + } + } + } } if ( 0 && i > 0 ) { diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1d9a8ebf8..e0d880bf1 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -470,11 +470,23 @@ int8_t komodo_minerid(int32_t height) int32_t notaryid; CBlockIndex *pindex; uint8_t pubkey33[33]; if ( depth < 3 && height <= CURRENT_HEIGHT )//chainActive.Tip()->nHeight ) { + if ( Minerids[height] >= -1 ) + return(Minerids[height]); if ( (pindex= chainActive[height]) != 0 ) { depth++; komodo_index2pubkey33(pubkey33,pindex,height); komodo_chosennotary(¬aryid,height,pubkey33); + if ( notaryid >= -1 ) + { + Minerids[height] = notaryid; + if ( Minerfp != 0 ) + { + fseek(Minerfp,height,SEEK_SET); + fputc(Minerids[height],Minerfp); + fflush(Minerfp); + } + } depth--; return(notaryid); } From a16343f77733b196b5de85ef0e3399e935da8be6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Nov 2016 16:29:11 -0300 Subject: [PATCH 05/28] test --- src/pow.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pow.cpp b/src/pow.cpp index 119544ec0..291bb3b75 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -132,6 +132,8 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in if ( notaryid >= 0 ) { special2 = komodo_is_special(height,pubkey33); + if ( special2 == -2 ) + printf("height.%d special2.%d special.%d\n",height,special2,special); if ( special2 == -2 || (height < 70000 && (special != 0 || special2 > 0)) || (height >= 70000 && special2 > 0) ) { From 3fccb0c5f346005f6b3f0c20b84e822020e5f590 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Nov 2016 17:00:40 -0300 Subject: [PATCH 06/28] test --- src/komodo.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo.h b/src/komodo.h index d6c6c9d1e..b8dbaa102 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -69,6 +69,8 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar } Minerfp = fopen(fname2,"rb+"); } + if ( Minerfp != 0 ) + fread(Minerids,1,sizeof(Minerids),Minerfp); if ( (fp= fopen(fname,"rb+")) != 0 ) { while ( (func= fgetc(fp)) != EOF ) From 22040314d426c1c00fdd23a175379e1c7cf935d6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Nov 2016 17:14:41 -0300 Subject: [PATCH 07/28] test --- src/komodo_bitcoind.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e0d880bf1..8995c6ef3 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -471,7 +471,10 @@ int8_t komodo_minerid(int32_t height) if ( depth < 3 && height <= CURRENT_HEIGHT )//chainActive.Tip()->nHeight ) { if ( Minerids[height] >= -1 ) + { + printf("cached[%d] -> %d\n",height,Minerids[height]); return(Minerids[height]); + } if ( (pindex= chainActive[height]) != 0 ) { depth++; From 3901c5b85bb6e40b4754c157190f8c31fe15af70 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Nov 2016 17:21:36 -0300 Subject: [PATCH 08/28] test --- src/komodo.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index b8dbaa102..cf3828867 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -69,8 +69,8 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar } Minerfp = fopen(fname2,"rb+"); } - if ( Minerfp != 0 ) - fread(Minerids,1,sizeof(Minerids),Minerfp); + if ( Minerfp != 0 && fread(Minerids,1,sizeof(Minerids),Minerfp) != sizeof(Minerids) ) + printf("read error Minerids\n"); if ( (fp= fopen(fname,"rb+")) != 0 ) { while ( (func= fgetc(fp)) != EOF ) From 63b2d35e70b8843b7d14efe522204d4f6c8c9003 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Nov 2016 17:29:34 -0300 Subject: [PATCH 09/28] test --- src/pow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index 291bb3b75..acf017442 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -132,7 +132,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in if ( notaryid >= 0 ) { special2 = komodo_is_special(height,pubkey33); - if ( special2 == -2 ) + if ( 0 && special2 == -2 ) printf("height.%d special2.%d special.%d\n",height,special2,special); if ( special2 == -2 || (height < 70000 && (special != 0 || special2 > 0)) || (height >= 70000 && special2 > 0) ) From c246f72f13121a64a39bc19a0bce1f96ee0978c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Nov 2016 08:39:41 -0300 Subject: [PATCH 10/28] test --- src/komodo.h | 2 +- src/komodo_gateway.h | 4 ++-- src/pow.cpp | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index cf3828867..25e0c515d 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -17,7 +17,7 @@ #define H_KOMODO_H // Todo: -// 0. minerids file +// 0. optimize assetchains RT loop // 1. error check fiat redeem amounts // 2. net balance limiter // 3. verify: interest payment, ratification, reorgs diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 1cda66399..6b88f8fae 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -276,7 +276,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above for (j=0; j<32; j++) printf("%02x",((uint8_t *)&hash)[j]); printf(" ht.%d blockhash couldnt find vout.[%d]\n",height,i); - // validate amount! + // validate amount! via fiat chain } } } @@ -288,7 +288,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above for (j=0; j<32; j++) printf("%02x",((uint8_t *)&txids[i-1])[j]); printf(" cant paxfind txid\n"); - // validate amount! + // validate amount! via fiat chain } else if ( opcode == 'I' ) matched++; } diff --git a/src/pow.cpp b/src/pow.cpp index acf017442..befb665bd 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -155,6 +155,8 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in } if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit)) return error("CheckProofOfWork(): nBits below minimum work"); + if ( height > 70000 ) + bnTarget /= 64; // Check proof of work matches claimed amount if ( UintToArith256(hash) > bnTarget ) { From 6dba48ec77db10a11f70ef757a2a24a4a58159e3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Nov 2016 11:43:37 -0300 Subject: [PATCH 11/28] test --- src/komodo.h | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 25e0c515d..2c8859164 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -274,7 +274,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar } } -int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp,uint64_t value) +int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp,uint64_t value) { static uint256 zero; int32_t opretlen,nid,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac ) @@ -341,7 +341,17 @@ int32_t komodo_voutupdate(int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen, //int32_t k; for (k=0; k= 32*2+4 && strcmp(ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,(char *)&scriptbuf[len+32*2+4]) == 0 ) + { + iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&kmdtxid); + if ( bits256_nonz(kmdtxid) == 0 ) + { + *isratificationp = 1; + printf("ISRATIFICATION (%s)\n",(char *)&scriptbuf[len+32*2+4]); + } + } + if ( *isratificationp == 0 ) + komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,value,&scriptbuf[len],opretlen,j); } } return(notaryid); @@ -365,7 +375,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) static int32_t hwmheight; uint64_t signedmask,voutmask; uint8_t scriptbuf[4096],pubkeys[64][33]; uint256 kmdtxid,btctxid,txhash; - int32_t i,j,k,nid,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count; + int32_t i,j,k,isratification,nid,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count; komodo_init(pindex->nHeight); if ( pindex->nHeight > hwmheight ) hwmheight = pindex->nHeight; @@ -395,7 +405,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) txhash = block.vtx[i].GetHash(); numvouts = block.vtx[i].vout.size(); notaryid = -1; - voutmask = specialtx = notarizedheight = 0; + voutmask = specialtx = notarizedheight = isratification = 0; for (j=0; j= 0 ) { if ( height < sizeof(Minerids)/sizeof(*Minerids) ) @@ -448,11 +458,11 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) if ( signedmask != 0 && (notarizedheight != 0 || specialtx != 0) ) { printf("NOTARY SIGNED.%llx numvins.%d ht.%d txi.%d notaryht.%d specialtx.%d\n",(long long)signedmask,numvins,height,i,notarizedheight,specialtx); - if ( specialtx != 0 && numvouts > 2 && komodo_ratify_threshold(height,signedmask) > 0 ) + if ( specialtx != 0 && isratification != 0 && numvouts > 2 && komodo_ratify_threshold(height,signedmask) > 0 ) { numvalid = 0; memset(pubkeys,0,sizeof(pubkeys)); - for (j=1; j= KOMODO_MINRATIFY && numvouts > 13 ) + if ( numvalid >= KOMODO_MINRATIFY ) { memset(&txhash,0,sizeof(txhash)); komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0,0,0,0,0); + printf("RATIFIED! >>>>>>>>>> new notaries.%d newheight.%d from height.%d\n",numvalid,KOMODO_PUBKEYS_HEIGHT(height),height); } - printf("new notaries.%d newheight.%d from height.%d\n",numvouts-1,KOMODO_PUBKEYS_HEIGHT(height),height); } } } From 5a286a6fef608ebba63b03673747986ea4fd72ef Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Nov 2016 11:45:26 -0300 Subject: [PATCH 12/28] test --- src/komodo.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 2c8859164..8ef1678af 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -276,7 +276,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp,uint64_t value) { - static uint256 zero; int32_t opretlen,nid,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; + static uint256 zero; int32_t opretlen,nid,k,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac ) { decode_hex(crypto777,33,(char *)CRYPTO777_PUBSECPSTR); @@ -344,7 +344,10 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr if ( opretlen >= 32*2+4 && strcmp(ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,(char *)&scriptbuf[len+32*2+4]) == 0 ) { iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&kmdtxid); - if ( bits256_nonz(kmdtxid) == 0 ) + for (k=0; k<32; k++) + if ( scriptbuf[len+k] != 0 ) + break; + if ( k == 32 ) { *isratificationp = 1; printf("ISRATIFICATION (%s)\n",(char *)&scriptbuf[len+32*2+4]); From d2a115d84165535f10c5461da385e99cf3c64a76 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Nov 2016 12:21:53 -0300 Subject: [PATCH 13/28] test --- src/komodo.h | 4 ++-- src/komodo_utils.h | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 8ef1678af..9152fe180 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -461,7 +461,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) if ( signedmask != 0 && (notarizedheight != 0 || specialtx != 0) ) { printf("NOTARY SIGNED.%llx numvins.%d ht.%d txi.%d notaryht.%d specialtx.%d\n",(long long)signedmask,numvins,height,i,notarizedheight,specialtx); - if ( specialtx != 0 && isratification != 0 && numvouts > 2 && komodo_ratify_threshold(height,signedmask) > 0 ) + if ( specialtx != 0 && isratification != 0 && numvouts > 2 ) { numvalid = 0; memset(pubkeys,0,sizeof(pubkeys)); @@ -484,7 +484,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) } } } - if ( numvalid >= KOMODO_MINRATIFY ) + if ( ((signedmask & 1) != 0 && numvalid >= KOMODO_MINRATIFY) || bitweight(signedmask) > (bp->numnotaries>>1) ) { memset(&txhash,0,sizeof(txhash)); komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0,0,0,0,0); diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 7f691dc12..ec2e2ce9d 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -807,6 +807,15 @@ int32_t komodo_is_issuer() else return(0); } +int32_t bitweight(uint64_t x) +{ + int i,wt = 0; + for (i=0; i<64; i++) + if ( (1LL << i) & x ) + wt++; + return(wt); +} + int32_t _unhex(char c) { if ( c >= '0' && c <= '9' ) From 7589f03a03ad2051791c076c2b13202e9fc3ba34 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Nov 2016 12:27:42 -0300 Subject: [PATCH 14/28] test --- src/komodo.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 9152fe180..0b8259890 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -378,8 +378,9 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) static int32_t hwmheight; uint64_t signedmask,voutmask; uint8_t scriptbuf[4096],pubkeys[64][33]; uint256 kmdtxid,btctxid,txhash; - int32_t i,j,k,isratification,nid,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count; + int32_t i,j,k,numnotaries,isratification,nid,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count; komodo_init(pindex->nHeight); + numnotaries = komodo_notaries(pubkeys,pindex->nHeight); if ( pindex->nHeight > hwmheight ) hwmheight = pindex->nHeight; else @@ -484,7 +485,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) } } } - if ( ((signedmask & 1) != 0 && numvalid >= KOMODO_MINRATIFY) || bitweight(signedmask) > (bp->numnotaries>>1) ) + if ( ((signedmask & 1) != 0 && numvalid >= KOMODO_MINRATIFY) || bitweight(signedmask) > (numnotaries>>1) ) { memset(&txhash,0,sizeof(txhash)); komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0,0,0,0,0); From 0e2acef55a562b2455a524c02df7fe761a6371c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Nov 2016 12:33:05 -0300 Subject: [PATCH 15/28] test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 8995c6ef3..af86faa76 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -399,7 +399,7 @@ int32_t komodo_is_notarytx(const CTransaction& tx) decode_hex(crypto777,33,(char *)CRYPTO777_PUBSECPSTR); if ( memcmp(ptr+1,crypto777,33) == 0 ) { - printf("found notarytx\n"); + //printf("found notarytx\n"); return(1); } else return(0); From 836e8b3c12e0608ce6e9772c4dfe1bc1a0e9302d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Nov 2016 12:43:19 -0300 Subject: [PATCH 16/28] test --- src/komodo.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 0b8259890..2d0994043 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -276,7 +276,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp,uint64_t value) { - static uint256 zero; int32_t opretlen,nid,k,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; + static uint256 zero; int32_t opretlen,nid,i,k,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac ) { decode_hex(crypto777,33,(char *)CRYPTO777_PUBSECPSTR); @@ -303,7 +303,9 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr } else if ( notaryid != nid ) { - printf("mismatch notaryid.%d k.%d\n",notaryid,nid); + for (i=0; i<33; i++) + printf("%02x",scriptbuf[i+1]); + printf(" %s mismatch notaryid.%d k.%d\n",ASSETCHAINS_SYMBOL,notaryid,nid); notaryid = 64; *voutmaskp = 0; } @@ -420,7 +422,6 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) #else memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len); #endif - // signedmask is needed here! notaryid = komodo_voutupdate(&isratification,notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].nValue); if ( i == 0 && j == 0 && komodo_chosennotary(&nid,height,scriptbuf + 1) >= 0 ) { From d01ec1158cf3743f5d13cc66247edceb247ed603 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Nov 2016 12:51:58 -0300 Subject: [PATCH 17/28] test --- src/komodo_notary.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 8b637db0a..26712645b 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -52,7 +52,7 @@ const char *Notaries_genesis[][2] = { "titomane_SH", "035f49d7a308dd9a209e894321f010d21b7793461b0c89d6d9231a3fe5f68d9960" }, }; -#define KOMODO_ELECTION_GAP 2000 +#define KOMODO_ELECTION_GAP ((ASSETCHAINS_SYMBOL[0] == 0) ? 2000 : 100) #define KOMODO_PUBKEYS_HEIGHT(height) ((int32_t)(((((height)+KOMODO_ELECTION_GAP*.5)/KOMODO_ELECTION_GAP) + 1) * KOMODO_ELECTION_GAP)) struct nutxo_entry { UT_hash_handle hh; uint256 txhash; uint64_t voutmask; int32_t notaryid,height; } *NUTXOS; @@ -94,8 +94,8 @@ int32_t komodo_ratify_threshold(int32_t height,uint64_t signedmask) int32_t htind,numnotaries,i,wt = 0; if ( ASSETCHAINS_SYMBOL[0] != 0 ) return(2); - if ( (htind= KOMODO_PUBKEYS_HEIGHT(height) / KOMODO_ELECTION_GAP) == 1 ) - htind = 0; + if ( (htind= KOMODO_PUBKEYS_HEIGHT(height) / KOMODO_ELECTION_GAP) == 0 ) + htind = 1; numnotaries = Pubkeys[htind].numnotaries; for (i=0; i= sizeof(Pubkeys)/sizeof(*Pubkeys) ) return(-1); - if ( (htind= KOMODO_PUBKEYS_HEIGHT(height) / KOMODO_ELECTION_GAP) == 1 ) - htind = 0; + if ( (htind= KOMODO_PUBKEYS_HEIGHT(height) / KOMODO_ELECTION_GAP) == 0 ) + htind = 1; pthread_mutex_lock(&komodo_mutex); HASH_FIND(hh,Pubkeys[htind].Notaries,pubkey33,33,kp); pthread_mutex_unlock(&komodo_mutex); From b7f942c8447cde54b3bc7c9a894ab88111c6ff0d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Nov 2016 12:53:06 -0300 Subject: [PATCH 18/28] test --- src/komodo.h | 8 ++++---- src/komodo_notary.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 2d0994043..0fa54ebf2 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -289,7 +289,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr if ( memcmp(crypto777,scriptbuf+1,33) == 0 ) { *specialtxp = 1; - printf(">>>>>>>> "); + //printf(">>>>>>>> "); } else if ( komodo_chosennotary(&nid,height,scriptbuf + 1) >= 0 ) { @@ -303,9 +303,9 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr } else if ( notaryid != nid ) { - for (i=0; i<33; i++) - printf("%02x",scriptbuf[i+1]); - printf(" %s mismatch notaryid.%d k.%d\n",ASSETCHAINS_SYMBOL,notaryid,nid); + //for (i=0; i<33; i++) + // printf("%02x",scriptbuf[i+1]); + //printf(" %s mismatch notaryid.%d k.%d\n",ASSETCHAINS_SYMBOL,notaryid,nid); notaryid = 64; *voutmaskp = 0; } diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 26712645b..da95e5218 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -138,7 +138,7 @@ void komodo_notarysinit(int32_t height,uint8_t pubkeys[64][33],int32_t num) memcpy(kp->pubkey,pubkeys[k],33); kp->notaryid = k; HASH_ADD_KEYPTR(hh,N.Notaries,kp->pubkey,33,kp); - //if ( height > 10000 ) + if ( height > 10000 ) { for (i=0; i<33; i++) printf("%02x",pubkeys[k][i]); From 101a1c3b5f798e42c4daa3525edcd6b86b66eda4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Nov 2016 12:53:35 -0300 Subject: [PATCH 19/28] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 0fa54ebf2..b780a417c 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -276,7 +276,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp,uint64_t value) { - static uint256 zero; int32_t opretlen,nid,i,k,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; + static uint256 zero; int32_t opretlen,nid,k,len = 0; uint256 kmdtxid,desttxid; uint8_t crypto777[33]; if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac ) { decode_hex(crypto777,33,(char *)CRYPTO777_PUBSECPSTR); From df027c81193ae5ebc71a4ae35ecdeee718c1c059 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Nov 2016 12:58:13 -0300 Subject: [PATCH 20/28] test --- src/komodo_notary.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index da95e5218..e8cd2a410 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -129,7 +129,11 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height) void komodo_notarysinit(int32_t height,uint8_t pubkeys[64][33],int32_t num) { + static int32_t hwmheight; int32_t k,i,htind; struct knotary_entry *kp; struct knotaries_entry N; + if ( height <= hwmheight ) + return; + hwmheight = height; memset(&N,0,sizeof(N)); pthread_mutex_lock(&komodo_mutex); for (k=0; kpubkey,pubkeys[k],33); kp->notaryid = k; HASH_ADD_KEYPTR(hh,N.Notaries,kp->pubkey,33,kp); - if ( height > 10000 ) + if ( height > 0 ) { for (i=0; i<33; i++) printf("%02x",pubkeys[k][i]); From 0df0f9d1c8b0723e1a1575eeea185f4925fd90a7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Nov 2016 12:59:13 -0300 Subject: [PATCH 21/28] test --- src/komodo_notary.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index e8cd2a410..1cf14a749 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -135,6 +135,8 @@ void komodo_notarysinit(int32_t height,uint8_t pubkeys[64][33],int32_t num) return; hwmheight = height; memset(&N,0,sizeof(N)); + if ( (htind= KOMODO_PUBKEYS_HEIGHT(height) / KOMODO_ELECTION_GAP) == 0 ) + htind = 1; pthread_mutex_lock(&komodo_mutex); for (k=0; k Date: Mon, 14 Nov 2016 13:09:59 -0300 Subject: [PATCH 22/28] test --- src/komodo_notary.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 1cf14a749..8afa32968 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -130,10 +130,7 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height) void komodo_notarysinit(int32_t height,uint8_t pubkeys[64][33],int32_t num) { static int32_t hwmheight; - int32_t k,i,htind; struct knotary_entry *kp; struct knotaries_entry N; - if ( height <= hwmheight ) - return; - hwmheight = height; + int32_t k,i,htind,nonz; struct knotary_entry *kp; struct knotaries_entry N; memset(&N,0,sizeof(N)); if ( (htind= KOMODO_PUBKEYS_HEIGHT(height) / KOMODO_ELECTION_GAP) == 0 ) htind = 1; @@ -148,16 +145,20 @@ void komodo_notarysinit(int32_t height,uint8_t pubkeys[64][33],int32_t num) { for (i=0; i<33; i++) printf("%02x",pubkeys[k][i]); - printf(" notarypubs.[%d] ht.%d active at %d\n",k,height,htind*KOMODO_ELECTION_GAP); + printf(" notarypubs.[%d] ht.%d active at %d\n",k,height,KOMODO_PUBKEYS_HEIGHT(height)); } } N.numnotaries = num; - for (i=htind; i hwmheight ) + hwmheight = height; } int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33) @@ -277,7 +278,7 @@ void komodo_assetchain_pubkeys(char *jsonstr) { komodo_init(-1); komodo_notarysinit(0,pubkeys,n); - printf("initialize pubkeys[%d]\n",n); + //printf("initialize pubkeys[%d]\n",n); } else fprintf(stderr,"komodo_assetchain_pubkeys i.%d vs n.%d\n",i,n); } else fprintf(stderr,"assetchain pubkeys n.%d\n",n); } From 67d135df57a039359832c7f83d4c6efedd95c489 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Nov 2016 13:13:46 -0300 Subject: [PATCH 23/28] test --- src/komodo_notary.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 8afa32968..7e5899b86 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -53,7 +53,13 @@ const char *Notaries_genesis[][2] = }; #define KOMODO_ELECTION_GAP ((ASSETCHAINS_SYMBOL[0] == 0) ? 2000 : 100) -#define KOMODO_PUBKEYS_HEIGHT(height) ((int32_t)(((((height)+KOMODO_ELECTION_GAP*.5)/KOMODO_ELECTION_GAP) + 1) * KOMODO_ELECTION_GAP)) + +int32_t KOMODO_PUBKEYS_HEIGHT(int32_t height) +{ + height += KOMODO_ELECTION_GAP/2; + height /= KOMODO_ELECTION_GAP; + return((height + 1) * KOMODO_ELECTION_GAP); +} struct nutxo_entry { UT_hash_handle hh; uint256 txhash; uint64_t voutmask; int32_t notaryid,height; } *NUTXOS; struct knotary_entry { UT_hash_handle hh; uint8_t pubkey[33],notaryid; }; From bf484c7a15274fbb84f4f6168b873e7e6d429369 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Nov 2016 13:15:43 -0300 Subject: [PATCH 24/28] test --- src/komodo_notary.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 7e5899b86..b43973b4c 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -138,8 +138,7 @@ void komodo_notarysinit(int32_t height,uint8_t pubkeys[64][33],int32_t num) static int32_t hwmheight; int32_t k,i,htind,nonz; struct knotary_entry *kp; struct knotaries_entry N; memset(&N,0,sizeof(N)); - if ( (htind= KOMODO_PUBKEYS_HEIGHT(height) / KOMODO_ELECTION_GAP) == 0 ) - htind = 1; + htind = (KOMODO_PUBKEYS_HEIGHT(height) / KOMODO_ELECTION_GAP) + 1; pthread_mutex_lock(&komodo_mutex); for (k=0; k Date: Mon, 14 Nov 2016 13:18:13 -0300 Subject: [PATCH 25/28] test --- src/komodo_notary.h | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index b43973b4c..02c702a0f 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -54,13 +54,6 @@ const char *Notaries_genesis[][2] = #define KOMODO_ELECTION_GAP ((ASSETCHAINS_SYMBOL[0] == 0) ? 2000 : 100) -int32_t KOMODO_PUBKEYS_HEIGHT(int32_t height) -{ - height += KOMODO_ELECTION_GAP/2; - height /= KOMODO_ELECTION_GAP; - return((height + 1) * KOMODO_ELECTION_GAP); -} - struct nutxo_entry { UT_hash_handle hh; uint256 txhash; uint64_t voutmask; int32_t notaryid,height; } *NUTXOS; struct knotary_entry { UT_hash_handle hh; uint8_t pubkey[33],notaryid; }; struct knotaries_entry { int32_t height,numnotaries; struct knotary_entry *Notaries; } Pubkeys[10000]; @@ -100,8 +93,7 @@ int32_t komodo_ratify_threshold(int32_t height,uint64_t signedmask) int32_t htind,numnotaries,i,wt = 0; if ( ASSETCHAINS_SYMBOL[0] != 0 ) return(2); - if ( (htind= KOMODO_PUBKEYS_HEIGHT(height) / KOMODO_ELECTION_GAP) == 0 ) - htind = 1; + htind = height / KOMODO_ELECTION_GAP; numnotaries = Pubkeys[htind].numnotaries; for (i=0; i= sizeof(Pubkeys)/sizeof(*Pubkeys) ) return(-1); - if ( (htind= KOMODO_PUBKEYS_HEIGHT(height) / KOMODO_ELECTION_GAP) == 0 ) - htind = 1; + htind = height / KOMODO_ELECTION_GAP; pthread_mutex_lock(&komodo_mutex); HASH_FIND(hh,Pubkeys[htind].Notaries,pubkey33,33,kp); pthread_mutex_unlock(&komodo_mutex); From f9d034d4c977d70073b069542c24ab073caa4026 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Nov 2016 13:20:51 -0300 Subject: [PATCH 26/28] test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index b780a417c..90900b9c5 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -490,7 +490,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) { memset(&txhash,0,sizeof(txhash)); komodo_stateupdate(height,pubkeys,numvalid,0,txhash,0,0,0,0,0,0,0,0,0); - printf("RATIFIED! >>>>>>>>>> new notaries.%d newheight.%d from height.%d\n",numvalid,KOMODO_PUBKEYS_HEIGHT(height),height); + printf("RATIFIED! >>>>>>>>>> new notaries.%d newheight.%d from height.%d\n",numvalid,(((height+KOMODO_ELECTION_GAP/2)/KOMODO_ELECTION_GAP)+1)*KOMODO_ELECTION_GAP,height); } } } From 974173549cb31986ff00d7ef6b5a9be97d0ae19b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 Nov 2016 13:25:05 -0300 Subject: [PATCH 27/28] test --- src/komodo_notary.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 02c702a0f..8cbd3bc0d 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -129,10 +129,13 @@ void komodo_notarysinit(int32_t height,uint8_t pubkeys[64][33],int32_t num) static int32_t hwmheight; int32_t k,i,htind,nonz; struct knotary_entry *kp; struct knotaries_entry N; memset(&N,0,sizeof(N)); - height += KOMODO_ELECTION_GAP/2; - height /= KOMODO_ELECTION_GAP; - height = ((height + 1) * KOMODO_ELECTION_GAP); - htind = (height / KOMODO_ELECTION_GAP); + if ( height > 0 ) + { + height += KOMODO_ELECTION_GAP/2; + height /= KOMODO_ELECTION_GAP; + height = ((height + 1) * KOMODO_ELECTION_GAP); + htind = (height / KOMODO_ELECTION_GAP); + } else htind = 0; pthread_mutex_lock(&komodo_mutex); for (k=0; k Date: Mon, 14 Nov 2016 13:39:48 -0300 Subject: [PATCH 28/28] test --- src/komodo.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo.h b/src/komodo.h index 90900b9c5..34b249f3b 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -463,6 +463,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) if ( signedmask != 0 && (notarizedheight != 0 || specialtx != 0) ) { printf("NOTARY SIGNED.%llx numvins.%d ht.%d txi.%d notaryht.%d specialtx.%d\n",(long long)signedmask,numvins,height,i,notarizedheight,specialtx); + printf("ht.%d specialtx.%d isratification.%d numvouts.%d signed.%llx numnotaries.%d\n",height,specialtx,isratification,numvouts,(long long)signedmask,numnotaries); if ( specialtx != 0 && isratification != 0 && numvouts > 2 ) { numvalid = 0;