Skip to content

Commit 46317e8

Browse files
authored
Merge pull request #155 from jl777/dPoW
DPoW
2 parents 5339d22 + 06f8a28 commit 46317e8

File tree

4 files changed

+52
-16
lines changed

4 files changed

+52
-16
lines changed

src/komodo_bitcoind.h

+8-3
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ int32_t komodo_electednotary(uint8_t *pubkey33,int32_t height);
616616
int8_t komodo_minerid(int32_t height,uint8_t *pubkey33)
617617
{
618618
int32_t num,i; CBlockIndex *pindex; uint8_t _pubkey33[33],pubkeys[64][33];
619-
if ( (pindex= chainActive[height]) != 0 )
619+
if ( pubkey33 == 0 && (pindex= chainActive[height]) != 0 )
620620
{
621621
if ( pubkey33 == 0 )
622622
{
@@ -633,17 +633,22 @@ int8_t komodo_minerid(int32_t height,uint8_t *pubkey33)
633633
return(komodo_electednotary(pubkey33,height));
634634
}
635635

636-
int32_t komodo_eligiblenotary(int32_t *mids,int32_t *nonzpkeysp,int32_t height)
636+
int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,int32_t *nonzpkeysp,int32_t height)
637637
{
638-
int32_t i,duplicate; CBlockIndex *pindex; uint8_t pubkey33[33];
638+
int32_t i,j,duplicate; CBlockIndex *pindex; uint8_t pubkey33[33];
639639
memset(mids,-1,sizeof(*mids)*66);
640640
for (i=duplicate=0; i<66; i++)
641641
{
642642
if ( (pindex= komodo_chainactive(height-i)) != 0 )
643643
{
644644
komodo_index2pubkey33(pubkey33,pindex,height-i);
645+
for (j=0; j<33; j++)
646+
pubkeys[i][j] = pubkey33[j];
645647
if ( (mids[i]= komodo_minerid(height-i,pubkey33)) >= 0 )
648+
{
649+
//mids[i] = *(int32_t *)pubkey33;
646650
(*nonzpkeysp)++;
651+
}
647652
if ( mids[0] >= 0 && i > 0 && mids[i] == mids[0] )
648653
duplicate++;
649654
}

src/komodo_notary.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,10 @@ int32_t komodo_electednotary(uint8_t *pubkey33,int32_t height)
132132
for (i=0; i<sizeof(Notaries_elected)/sizeof(*Notaries_elected); i++)
133133
{
134134
if ( strcmp(pubkeystr,(char *)Notaries_elected[i][1]) == 0 )
135+
{
136+
//printf("i.%d -> elected %s\n",i,(char *)Notaries_elected[i][1]);
135137
return(i);
136-
//printf("%s\n",(char *)Notaries_elected[i][1]);
138+
}
137139
}
138140
return(-1);
139141
}
@@ -154,6 +156,13 @@ int32_t komodo_ratify_threshold(int32_t height,uint64_t signedmask)
154156
int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height)
155157
{
156158
int32_t i,htind,n; uint64_t mask = 0; struct knotary_entry *kp,*tmp;
159+
if ( height >= 180000 )
160+
{
161+
n = (int32_t)(sizeof(Notaries_elected)/sizeof(*Notaries_elected));
162+
for (i=0; i<n; i++)
163+
decode_hex(pubkeys[i],33,(char *)Notaries_elected[i][1]);
164+
return(n);
165+
}
157166
htind = height / KOMODO_ELECTION_GAP;
158167
pthread_mutex_lock(&komodo_mutex);
159168
n = Pubkeys[htind].numnotaries;

src/miner.cpp

+30-8
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,8 @@ static bool ProcessBlockFound(CBlock* pblock, CWallet& wallet, CReserveKey& rese
520520
}
521521

522522
int32_t komodo_baseid(char *origbase);
523-
int32_t komodo_eligiblenotary(int32_t *mids,int32_t *nonzpkeysp,int32_t height);
523+
int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,int32_t *nonzpkeysp,int32_t height);
524+
int32_t FOUND_BLOCK;
524525

525526
void static BitcoinMiner(CWallet *pwallet)
526527
{
@@ -615,21 +616,34 @@ void static BitcoinMiner(CWallet *pwallet)
615616
//
616617
// Search
617618
//
618-
int mids[66],nonzpkeys,j; uint32_t savebits; int64_t nStart = GetTime();
619+
uint8_t pubkeys[66][33]; int mids[66],nonzpkeys,i,j; uint32_t savebits; int64_t nStart = GetTime();
619620
savebits = pblock->nBits;
620621
arith_uint256 hashTarget = arith_uint256().SetCompact(pblock->nBits);
621622
if ( ASSETCHAINS_SYMBOL[0] == 0 && notaryid >= 0 )//komodo_is_special(pindexPrev->nHeight+1,NOTARY_PUBKEY33) > 0 )
622623
{
623624
if ( (Mining_height % KOMODO_ELECTION_GAP) > 64 || (Mining_height % KOMODO_ELECTION_GAP) == 0 )
624625
{
625-
komodo_eligiblenotary(mids,&nonzpkeys,pindexPrev->nHeight);
626+
komodo_eligiblenotary(pubkeys,mids,&nonzpkeys,pindexPrev->nHeight);
626627
if ( nonzpkeys > 0 )
627628
{
628-
if ( notaryid < 2 )
629+
if ( NOTARY_PUBKEY33[0] != 0 && notaryid < 1 )
629630
{
630-
for (j=0; j<65; j++)
631-
fprintf(stderr,"%d ",mids[j]);
632-
fprintf(stderr," <- prev minerids from ht.%d notary.%d\n",pindexPrev->nHeight,notaryid);
631+
for (i=1; i<66; i++)
632+
if ( memcmp(pubkeys[i],pubkeys[0],33) == 0 )
633+
break;
634+
if ( i != 66 )
635+
{
636+
printf("VIOLATION at %d\n",i);
637+
for (i=0; i<66; i++)
638+
{
639+
for (j=0; j<33; j++)
640+
printf("%02x",pubkeys[i][j]);
641+
printf(" p%d -> %d\n",i,komodo_minerid(pindexPrev->nHeight-i,pubkeys[i]));
642+
}
643+
for (j=0; j<65; j++)
644+
fprintf(stderr,"%d ",mids[j]);
645+
fprintf(stderr," <- prev minerids from ht.%d notary.%d VIOLATION\n",pindexPrev->nHeight,notaryid);
646+
}
633647
}
634648
for (j=0; j<65; j++)
635649
if ( mids[j] == notaryid )
@@ -706,6 +720,8 @@ void static BitcoinMiner(CWallet *pwallet)
706720
ehSolverRuns.increment();
707721
throw boost::thread_interrupted();
708722
}
723+
//if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 )
724+
// sleep(1800);
709725
return true;
710726
};
711727
std::function<bool(EhSolverCancelCheck)> cancelled = [&m_cs, &cancelSolver](EhSolverCancelCheck pos) {
@@ -756,7 +772,7 @@ void static BitcoinMiner(CWallet *pwallet)
756772
for (i=0; i<32; i++)
757773
fprintf(stderr,"%02x",((uint8_t *)&hash)[i]);
758774
fprintf(stderr," <- %s Block found %d\n",ASSETCHAINS_SYMBOL,Mining_height);
759-
sleep(60); // avoid mining forks
775+
FOUND_BLOCK = 1;
760776
break;
761777
}
762778
} catch (EhSolverCancelledException&) {
@@ -769,6 +785,12 @@ void static BitcoinMiner(CWallet *pwallet)
769785
// Check for stop or if block needs to be rebuilt
770786
boost::this_thread::interruption_point();
771787
// Regtest mode doesn't require peers
788+
if ( FOUND_BLOCK != 0 )
789+
{
790+
FOUND_BLOCK = 0;
791+
fprintf(stderr,"FOUND_BLOCK!\n");
792+
sleep(2000);
793+
}
772794
if (vNodes.empty() && chainparams.MiningRequiresPeers())
773795
{
774796
if ( ASSETCHAINS_SYMBOL[0] == 0 || Mining_height > ASSETCHAINS_MINHEIGHT )

src/pow.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height)
113113
extern int32_t KOMODO_CHOSEN_ONE;
114114
#define KOMODO_ELECTION_GAP 2000
115115

116-
int32_t komodo_eligiblenotary(int32_t *mids,int32_t *nonzpkeysp,int32_t height);
116+
int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,int32_t *nonzpkeysp,int32_t height);
117117

118118

119119
extern std::string NOTARY_PUBKEY;
@@ -122,7 +122,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in
122122
{
123123
extern int32_t KOMODO_REWIND;
124124
bool fNegative,fOverflow; int32_t i,nonzpkeys=0,nonz=0,special=0,special2=0,notaryid=-1,duplicate,flag = 0, mids[66];
125-
arith_uint256 bnTarget; CBlockIndex *pindex;
125+
arith_uint256 bnTarget; CBlockIndex *pindex; uint8_t pubkeys[66][33];
126126

127127
bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
128128
if ( height == 0 )
@@ -131,7 +131,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in
131131
//for (i=0; i<33; i++)
132132
// printf("%02x",pubkey33[i]);
133133
//printf(" <- ht.%d\n",height);
134-
flag = komodo_eligiblenotary(mids,&nonzpkeys,height);
134+
flag = komodo_eligiblenotary(pubkeys,mids,&nonzpkeys,height);
135135
if ( height > 34000 ) // 0 -> non-special notary
136136
{
137137
for (i=0; i<33; i++)
@@ -185,7 +185,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in
185185
return error("CheckProofOfWork(): hash doesn't match nBits");
186186
}
187187
}
188-
if ( height > 180000 && nonzpkeys > 0 && strcmp((char *)NOTARY_PUBKEY.c_str(),"03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828") == 0 )
188+
if ( 0 && height > 180000 && nonzpkeys > 0 && strcmp((char *)NOTARY_PUBKEY.c_str(),"03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828") == 0 )
189189
{
190190
for (i=0; i<66; i++)
191191
fprintf(stderr,"%d ",mids[i]);

0 commit comments

Comments
 (0)