diff --git a/src/komodo.h b/src/komodo.h index abc1679c9..3e6a8bb97 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -22,15 +22,16 @@ int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY; std::string NOTARY_PUBKEY; -int32_t komodo_is_notaryblock(uint8_t *pblock) +void komodo_connectblock(CBlock *block) { - /*int32_t i; - for (i=0; i<5; i++) - printf("%02x",coinbase[i]); - printf(" <- coinbase\n"); - for (i=0; i<35; i++) - printf("%02x",minerout[i]); - printf(" <- minerout\n");*/ + // update voting results and official (height, notaries[]) +} + +int32_t komodo_is_notaryblock(CBlockHeader *blockhdr) +{ + // extract height from coinbase + // extract miner's pubkey from vout[0] + // compare against elected notary pubkeys as of height return(0); } @@ -40,7 +41,22 @@ int32_t komodo_checkmsg(void *bitcoinpeer,uint8_t *data,int32_t datalen) return(0); } -int32_t komodo_blockcheck(void *block,uint32_t *nBitsp) +int32_t komodo_blockhdrcheck(CBlockHeader *blockhdr,uint32_t *nBitsp) +{ + if ( komodo_is_notaryblock(blockhdr) != 0 ) + *nBitsp = KOMODO_MINDIFF_NBITS; + //fprintf(stderr,"check block %p\n",block); + // 1 -> valid notary block, change nBits to KOMODO_MINDIFF_NBITS + // -1 -> invalid, ie, prior to notarized block + return(0); // normal PoW block +} + +int32_t komodo_blockindexcheck(CBlockIndex *pindex,uint32_t *nBitsp) +{ + +} + +int32_t komodo_blockcheck(CBlock *block,uint32_t *nBitsp) { //fprintf(stderr,"check block %p\n",block); // 1 -> valid notary block, change nBits to KOMODO_MINDIFF_NBITS diff --git a/src/main.cpp b/src/main.cpp index 32588941a..9365909b7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -41,7 +41,7 @@ using namespace std; # error "Bitcoin cannot be compiled without assertions." #endif -int32_t komodo_blockcheck(void *block,uint32_t *nBitsp); +#include "komodo.h" /** * Global state @@ -1352,7 +1352,7 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos) // Check the header nBits = block.nBits; - if ( (retval= komodo_blockcheck((void *)&block,&nBits)) == 0 ) + if ( (retval= komodo_blockcheck(&block,&nBits)) == 0 ) { if (!(CheckEquihashSolution(&block, Params()) && CheckProofOfWork(block.GetHash(), nBits, Params().GetConsensus()))) return error("ReadBlockFromDisk: Errors in block header at %s", pos.ToString()); @@ -2503,6 +2503,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * BOOST_FOREACH(const CTransaction &tx, pblock->vtx) { SyncWithWallets(tx, pblock); } + komodo_connectblock(pblock); // Update cached incremental witnesses GetMainSignals().ChainTip(pindexNew, pblock, oldTree, true); @@ -2950,7 +2951,7 @@ bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, bool f if (block.GetBlockTime() > GetAdjustedTime() + 60) return state.Invalid(error("CheckBlockHeader(): block timestamp too far in the future"),REJECT_INVALID, "time-too-new"); nBits = block.nBits; - if ( (retval= komodo_blockcheck((void *)&block,&nBits)) == 0 ) + if ( (retval= komodo_blockhdrcheck(&block,&nBits)) == 0 ) { // Check Equihash solution is valid if ( fCheckPOW && !CheckEquihashSolution(&block, Params()) ) @@ -4106,7 +4107,6 @@ string GetWarnings(string strFor) // // Messages // -#include "komodo.h" bool static AlreadyHave(const CInv& inv) diff --git a/src/pow.cpp b/src/pow.cpp index d6d4cac32..50cce6bc9 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -16,14 +16,14 @@ #include "sodium.h" -int32_t komodo_is_notaryblock(uint8_t *pblock); +int32_t komodo_is_notaryblock(const CBlockHeader *pblock); unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) { unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact(); // Genesis block - if (pindexLast == NULL || komodo_is_notaryblock((uint8_t *)pblock) != 0 ) + if (pindexLast == NULL || komodo_is_notaryblock(pblock) != 0 ) return nProofOfWorkLimit; // Find the first block in the averaging interval diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 8fbf8a2df..8521c2f6e 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -115,7 +115,7 @@ Value getgenerate(const Array& params, bool fHelp) return GetBoolArg("-gen", false); } -int32_t komodo_blockcheck(void *block,uint32_t *nBitsp); +int32_t komodo_blockcheck(CBlock *block,uint32_t *nBitsp); Value generate(const Array& params, bool fHelp) { @@ -196,7 +196,7 @@ Value generate(const Array& params, bool fHelp) int32_t retval; uint32_t nBits; pblock->nSolution = soln; nBits = pblock->nBits; - if ( (retval= komodo_blockcheck((void *)pblock,&nBits)) == 0 ) + if ( (retval= komodo_blockcheck(pblock,&nBits)) == 0 ) { return CheckProofOfWork(pblock->GetHash(), nBits, Params().GetConsensus()); } diff --git a/src/txdb.cpp b/src/txdb.cpp index ee345ac29..31bc73704 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -266,7 +266,7 @@ bool CBlockTreeDB::ReadFlag(const std::string &name, bool &fValue) { return true; } -int32_t komodo_blockcheck(void *block,uint32_t *nBitsp); +int32_t komodo_blockindexcheck(CBlockIndex *pindex,uint32_t *nBitsp); bool CBlockTreeDB::LoadBlockIndexGuts() { @@ -308,7 +308,7 @@ bool CBlockTreeDB::LoadBlockIndexGuts() int32_t retval; uint32_t nBits; nBits = pindexNew->nBits; - if ( (retval= komodo_blockcheck((void *)pindexNew,&nBits)) == 0 ) + if ( (retval= komodo_blockindexcheck(pindexNew,&nBits)) == 0 ) { if (!CheckProofOfWork(pindexNew->GetBlockHash(), nBits, Params().GetConsensus())) return error("LoadBlockIndex(): CheckProofOfWork failed: %s", pindexNew->ToString());