]> Git Repo - VerusCoin.git/commitdiff
Move POW code around
authorjl777 <[email protected]>
Tue, 24 Apr 2018 19:31:28 +0000 (22:31 +0300)
committerjl777 <[email protected]>
Tue, 24 Apr 2018 19:31:28 +0000 (22:31 +0300)
src/komodo_bitcoind.h
src/komodo_gateway.h
src/main.cpp

index 37fc871509a2b8e9f9c8f541694bf3acf6544dfb..a7142de104639065006ec58ec53bde8039f7671c 100644 (file)
@@ -659,7 +659,7 @@ int32_t komodo_block2height(CBlock *block)
     return(height);
 }
 
-void komodo_block2pubkey33(uint8_t *pubkey33,CBlock *block)
+int32_t komodo_block2pubkey33(uint8_t *pubkey33,CBlock *block)
 {
     int32_t n;
     if ( KOMODO_LOADINGBLOCKS == 0 )
@@ -675,8 +675,12 @@ void komodo_block2pubkey33(uint8_t *pubkey33,CBlock *block)
         //komodo_init(0);
         n = block->vtx[0].vout[0].scriptPubKey.size();
         if ( n == 35 )
+        {
             memcpy(pubkey33,ptr+1,33);
+            return(1);
+        }
     }
+    return(0);
 }
 
 int32_t komodo_blockload(CBlock& block,CBlockIndex *pindex)
index 72f36a21cb33aa0e98c11eabdc65912c65bf4e65..0f3baf50f8a77fca650e4839342d6928871fb653 100644 (file)
@@ -650,153 +650,6 @@ int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max)
 
 void komodo_passport_iteration();
 
-uint64_t komodo_commission(const CBlock &block)
-{
-    int32_t i,j,n=0,txn_count; uint64_t total = 0;
-    txn_count = block.vtx.size();
-    for (i=0; i<txn_count; i++)
-    {
-        n = block.vtx[i].vout.size();
-        for (j=0; j<n; j++)
-        {
-            //fprintf(stderr,"(%d %.8f).%d ",i,dstr(block.vtx[i].vout[j].nValue),j);
-            if ( i != 0 || j != 1 )
-            {
-                total += block.vtx[i].vout[j].nValue;
-            }
-        }
-    }
-    //fprintf(stderr,"txn.%d n.%d commission total %.8f -> %.8f\n",txn_count,n,dstr(total),dstr((total * ASSETCHAINS_COMMISSION) / COIN));
-    return((total * ASSETCHAINS_COMMISSION) / COIN);
-}
-
-uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr)
-{
-    CBlockIndex *pindex; uint8_t hashbuf[128]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t txtime,winner = 0; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN;
-    txtime = komodo_txtime(&value,txid,vout,address);
-    if ( value == 0 || txtime == 0 )
-        return(0);
-    if ( (minage= nHeight*3) > 6000 )
-        minage = 6000;
-    if ( blocktime > txtime+minage && (pindex= komodo_chainactive(nHeight>200?nHeight-200:1)) != 0 )
-    {
-        vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address));
-        segid = ((nHeight + addrhash.uints[0]) & 0x3f);
-        pasthash = pindex->GetBlockHash();
-        memcpy(hashbuf,&pasthash,sizeof(pasthash));
-        memcpy(&hashbuf[sizeof(pasthash)],&addrhash,sizeof(addrhash));
-        vcalc_sha256(0,(uint8_t *)&hash,hashbuf,(int32_t)sizeof(uint256)*2);
-        //fprintf(stderr,"(%s) vs. (%s) %s %.8f txtime.%u\n",address,destaddr,hash.ToString().c_str(),dstr(value),txtime);
-        for (iter=0; iter<3600; iter++)
-        {
-            diff = (iter + blocktime - txtime - minage);
-            if ( diff > 3600*24 )
-                break;
-            coinage = (value * diff) * ((diff >> 16) + 1);
-            hashval = arith_uint256(supply * 64) * (UintToArith256(hash) / arith_uint256(coinage+1));
-            if ( hashval <= bnTarget )
-            {
-                winner = 1;
-                if ( validateflag == 0 )
-                {
-                    blocktime += iter;
-                    blocktime += segid * 2;
-                }
-                break;
-            }
-            if ( validateflag != 0 )
-            {
-                for (i=31; i>=24; i--)
-                    fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]);
-                fprintf(stderr," vs target ");
-                for (i=31; i>=24; i--)
-                    fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]);
-                fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d gap.%d %.8f diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),dstr(value),(int32_t)diff);
-                break;
-            }
-        }
-        //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner);
-        if ( 0 )
-        {
-            for (i=31; i>=24; i--)
-                fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]);
-            fprintf(stderr," vs ");
-            for (i=31; i>=24; i--)
-                fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]);
-            fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u %.8f diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,dstr(value),(int32_t)diff);
-        }
-    }
-    if ( nHeight < 2 )
-        return(blocktime);
-    return(blocktime * winner);
-}
-
-#define KOMODO_POWMINMULT 16
-arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc)
-{
-    CBlockIndex *pindex; arith_uint256 bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,ht,percPoS,diff;
-    *percPoSp = percPoS = 0;
-    sum = arith_uint256(0);
-    ave = sum;
-    for (i=n=0; i<100; i++)
-    {
-        ht = height - 100 + i;
-        if ( (pindex= komodo_chainactive(ht)) != 0 )
-        {
-            bnTarget.SetCompact(pindex->nBits,&fNegative,&fOverflow);
-            bnTarget = (bnTarget / arith_uint256(KOMODO_POWMINMULT));
-            hashval = UintToArith256(pindex->GetBlockHash());
-            if ( hashval <= bnTarget ) // PoW is never as easy as PoS/64, some PoS will be counted as PoW
-            {
-                sum += hashval;
-                n++;
-            } else percPoS++;
-        }
-    }
-    *percPoSp = percPoS;
-    target = (target / arith_uint256(KOMODO_POWMINMULT));
-    if ( n > 0 )
-    {
-        ave = (sum / arith_uint256(n));
-        if ( ave > target )
-            ave = target;
-    } else return(target);
-    if ( percPoS < goalperc ) // increase PoW diff -> lower bnTarget
-    {
-        bnTarget = (ave * arith_uint256(goalperc)) / arith_uint256(percPoS + goalperc);
-        if ( 1 )
-        {
-            for (i=31; i>=24; i--)
-                fprintf(stderr,"%02x",((uint8_t *)&ave)[i]);
-            fprintf(stderr," increase diff -> ");
-            for (i=31; i>=24; i--)
-                fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]);
-            fprintf(stderr," floor diff ");
-            for (i=31; i>=24; i--)
-                fprintf(stderr,"%02x",((uint8_t *)&target)[i]);
-            fprintf(stderr," ht.%d percPoS.%d vs goal.%d -> diff %d\n",height,percPoS,goalperc,goalperc - percPoS);
-        }
-    }
-    else if ( percPoS > goalperc ) // decrease PoW diff -> raise bnTarget
-    {
-        bnTarget = ((ave * arith_uint256(goalperc)) + (target * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc);
-       if ( 1 )
-       {
-           for (i=31; i>=24; i--)
-               fprintf(stderr,"%02x",((uint8_t *)&ave)[i]);
-           fprintf(stderr," decrease diff -> ");
-           for (i=31; i>=24; i--)
-               fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]);
-           fprintf(stderr," floor diff ");
-           for (i=31; i>=24; i--)
-               fprintf(stderr,"%02x",((uint8_t *)&target)[i]);
-           fprintf(stderr," ht.%d percPoS.%d vs goal.%d -> diff %d\n",height,percPoS,goalperc,goalperc - percPoS);
-       }
-    }
-    else bnTarget = ave; // recent ave is perfect
-    return(bnTarget);
-}
-
 int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtime) // verify above block is valid pax pricing
 {
     static uint256 array[64]; static int32_t numbanned,indallvouts;
index a32f1d492c439a785cf00e8efbcdc74235e87cc6..b4f8ae0918d539523516a3b01562944125a8f92c 100644 (file)
@@ -55,7 +55,7 @@ CCriticalSection cs_main;
 extern uint8_t NOTARY_PUBKEY33[33];
 extern int32_t KOMODO_LOADINGBLOCKS,KOMODO_LONGESTCHAIN;
 int32_t KOMODO_NEWBLOCKS;
-void komodo_block2pubkey33(uint8_t *pubkey33,CBlock *block);
+int32_t komodo_block2pubkey33(uint8_t *pubkey33,CBlock *block);
 
 BlockMap mapBlockIndex;
 CChain chainActive;
@@ -4473,7 +4473,8 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth
         if (!ReadBlockFromDisk(block, pindex))
             return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
         // check level 1: verify block validity
-        if (nCheckLevel >= 1 && !CheckBlock(pindex->nHeight,pindex,block, state, verifier,0))
+        int32_t futureblock;
+        if (nCheckLevel >= 1 && !CheckBlock(&futureblock,pindex->nHeight,pindex,block, state, verifier,0))
             return error("VerifyDB(): *** found bad block at %d, hash=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString());
         // check level 2: verify undo validity
         if (nCheckLevel >= 2 && pindex) {
@@ -5870,9 +5871,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
                 Misbehaving(pfrom->GetId(), 20);
                 return error("non-continuous headers sequence");
             }
-            if (!AcceptBlockHeader(header, state, &pindexLast)) {
+            int32_t futureblock;
+            if (!AcceptBlockHeader(&futureblock,header, state, &pindexLast)) {
                 int nDoS;
-                if (state.IsInvalid(nDoS))
+                if (state.IsInvalid(nDoS) && futureblock == 0)
                 {
                     if (nDoS > 0)
                         Misbehaving(pfrom->GetId(), nDoS/nDoS);
This page took 0.035705 seconds and 4 git commands to generate.