From 70b73d8f2547cf61f878a28f861c8e31877f4c75 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 26 Mar 2018 05:34:22 +0300 Subject: [PATCH 1/7] Test --- src/komodo_bitcoind.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9f1713584..d15082f94 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -736,13 +736,16 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) int8_t komodo_minerid(int32_t height,uint8_t *pubkey33) { int32_t num,i,numnotaries; CBlockIndex *pindex; uint32_t timestamp=0; uint8_t _pubkey33[33],pubkeys[64][33]; + if ( pubkey33 == 0 ) + { + pubkey33 = _pubkey33; + memset(pubkey33,0,33); + } if ( (pindex= chainActive[height]) != 0 ) { if ( pindex->pubkey33[0] == 0 ) { timestamp = pindex->GetBlockTime(); - if ( pubkey33 == 0 ) - pubkey33 = _pubkey33; komodo_index2pubkey33(pubkey33,pindex,height); pindex->notaryid = komodo_electednotary(&numnotaries,pindex->pubkey33,height,pindex->nTime); /*if ( (num= komodo_notaries(pubkeys,height,timestamp)) > 0 ) From bc6ba3da300e519a3c8f0c09a7ba8b76a67b970b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 26 Mar 2018 05:37:15 +0300 Subject: [PATCH 2/7] 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 d15082f94..76cb00423 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -708,7 +708,7 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) memset(pubkey33,0,33); if ( pindex != 0 ) { - if ( pindex->pubkey33[0] == 0 ) + //if ( pindex->pubkey33[0] == 0 ) { if ( komodo_blockload(block,pindex) == 0 ) { From 6402fab251f08ccdaea880f591ec40e39e366217 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 26 Mar 2018 05:45:25 +0300 Subject: [PATCH 3/7] Test --- src/komodo_notary.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 961c1e866..de93f57bd 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -236,6 +236,7 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam htind = height / KOMODO_ELECTION_GAP; if ( htind >= KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP ) htind = (KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP) - 1; + printf("Pubkeys.%p htind.%d vs max.%d\n",Pubkeys,htind,KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP); pthread_mutex_lock(&komodo_mutex); n = Pubkeys[htind].numnotaries; if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) @@ -288,7 +289,7 @@ void komodo_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num) static int32_t hwmheight; int32_t k,i,htind,height; struct knotary_entry *kp; struct knotaries_entry N; if ( Pubkeys == 0 ) - Pubkeys = (struct knotaries_entry *)calloc(KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP,sizeof(*Pubkeys)); + Pubkeys = (struct knotaries_entry *)calloc(1 + (KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP),sizeof(*Pubkeys)); memset(&N,0,sizeof(N)); if ( origheight > 0 ) { From db19b2aac5907818171dc9507ed35e5e307c59f3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 26 Mar 2018 05:49:03 +0300 Subject: [PATCH 4/7] Test --- src/komodo_notary.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index de93f57bd..1f9fce277 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -237,6 +237,11 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam if ( htind >= KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP ) htind = (KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP) - 1; printf("Pubkeys.%p htind.%d vs max.%d\n",Pubkeys,htind,KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP); + if ( Pubkeys == 0 ) + { + komodo_init(height); + printf("Pubkeys.%p htind.%d vs max.%d\n",Pubkeys,htind,KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP); + } pthread_mutex_lock(&komodo_mutex); n = Pubkeys[htind].numnotaries; if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) From bd92bdcdbdc1a7ebad1389a40edeeacdef1c8470 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 26 Mar 2018 05:50:18 +0300 Subject: [PATCH 5/7] Test --- src/komodo_notary.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 1f9fce277..4911b21d9 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -236,7 +236,6 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam htind = height / KOMODO_ELECTION_GAP; if ( htind >= KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP ) htind = (KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP) - 1; - printf("Pubkeys.%p htind.%d vs max.%d\n",Pubkeys,htind,KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP); if ( Pubkeys == 0 ) { komodo_init(height); From 7c2c1b5af180fcab593ad84242f799c45de8b047 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 26 Mar 2018 05:52:17 +0300 Subject: [PATCH 6/7] 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 76cb00423..b54844765 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -743,7 +743,7 @@ int8_t komodo_minerid(int32_t height,uint8_t *pubkey33) } if ( (pindex= chainActive[height]) != 0 ) { - if ( pindex->pubkey33[0] == 0 ) + //if ( pindex->pubkey33[0] == 0 ) { timestamp = pindex->GetBlockTime(); komodo_index2pubkey33(pubkey33,pindex,height); @@ -768,7 +768,7 @@ int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,int32_t *non { if ( (pindex= komodo_chainactive(height-i)) != 0 ) { - if ( pindex->pubkey33[0] == 0 ) + //if ( pindex->pubkey33[0] == 0 ) { komodo_index2pubkey33(pubkey33,pindex,height-i); pindex->notaryid = komodo_electednotary(&numnotaries,pindex->pubkey33,height,pindex->nTime); From 1746e25c183f5a23182a278316177906ec2df044 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 26 Mar 2018 05:57:00 +0300 Subject: [PATCH 7/7] Test --- src/komodo_bitcoind.h | 66 +++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 43 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b54844765..6ce8c5355 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -698,25 +698,15 @@ uint32_t komodo_heightstamp(int32_t height) return(0); } -int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp); -int32_t komodo_electednotary(int32_t *numnotariesp,uint8_t *pubkey33,int32_t height,uint32_t timestamp); - void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) { - CBlock block; int32_t numnotaries; + CBlock block; //komodo_init(height); memset(pubkey33,0,33); if ( pindex != 0 ) { - //if ( pindex->pubkey33[0] == 0 ) - { - if ( komodo_blockload(block,pindex) == 0 ) - { - komodo_block2pubkey33(pindex->pubkey33,block); - pindex->notaryid = komodo_electednotary(&numnotaries,pindex->pubkey33,height,pindex->nTime); - } - } - memcpy(pubkey33,pindex->pubkey33,33); + if ( komodo_blockload(block,pindex) == 0 ) + komodo_block2pubkey33(pubkey33,block); } else { @@ -732,57 +722,47 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) komodo_connectblock(pindex,block); }*/ +int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp); +int32_t komodo_electednotary(int32_t *numnotariesp,uint8_t *pubkey33,int32_t height,uint32_t timestamp); int8_t komodo_minerid(int32_t height,uint8_t *pubkey33) { int32_t num,i,numnotaries; CBlockIndex *pindex; uint32_t timestamp=0; uint8_t _pubkey33[33],pubkeys[64][33]; - if ( pubkey33 == 0 ) + if ( pubkey33 == 0 && (pindex= chainActive[height]) != 0 ) { - pubkey33 = _pubkey33; - memset(pubkey33,0,33); - } - if ( (pindex= chainActive[height]) != 0 ) - { - //if ( pindex->pubkey33[0] == 0 ) + timestamp = pindex->GetBlockTime(); + if ( pubkey33 == 0 ) { - timestamp = pindex->GetBlockTime(); + pubkey33 = _pubkey33; komodo_index2pubkey33(pubkey33,pindex,height); - pindex->notaryid = komodo_electednotary(&numnotaries,pindex->pubkey33,height,pindex->nTime); - /*if ( (num= komodo_notaries(pubkeys,height,timestamp)) > 0 ) - { - for (i=0; inotaryid); + if ( (num= komodo_notaries(pubkeys,height,timestamp)) > 0 ) + { + for (i=0; ipubkey33[0] == 0 ) + komodo_index2pubkey33(pubkey33,pindex,height-i); + //for (j=0; j<33; j++) + // pubkeys[i][j] = pubkey33[j]; + memcpy(pubkeys[i],pubkey33,33); + if ( (mids[i]= komodo_minerid(height-i,pubkey33)) >= 0 ) { - komodo_index2pubkey33(pubkey33,pindex,height-i); - pindex->notaryid = komodo_electednotary(&numnotaries,pindex->pubkey33,height,pindex->nTime); - //for (j=0; j<33; j++) - // pubkeys[i][j] = pubkey33[j]; - /*if ( (mids[i]= komodo_minerid(height-i,pubkey33)) >= 0 ) - { - //mids[i] = *(int32_t *)pubkey33; - (*nonzpkeysp)++; - }*/ - } - memcpy(pubkeys[i],pindex->pubkey33,33); - if ( (mids[i]= pindex->notaryid) >= 0 ) + //mids[i] = *(int32_t *)pubkey33; (*nonzpkeysp)++; + } if ( mids[0] >= 0 && i > 0 && mids[i] == mids[0] ) duplicate++; }