Browse Source

test

pull/4/head
jl777 8 years ago
parent
commit
f2dd868d93
  1. 18
      src/komodo.h
  2. 59
      src/main.cpp
  3. 4
      src/main.h
  4. 2
      src/pow.cpp
  5. 2
      src/pow.h
  6. 2
      src/rest.cpp
  7. 2
      src/rpcblockchain.cpp
  8. 11
      src/rpcmining.cpp
  9. 2
      src/rpcrawtransaction.cpp
  10. 13
      src/txdb.cpp
  11. 6
      src/wallet/wallet.cpp

18
src/komodo.h

@ -181,6 +181,7 @@ const char *Notaries[64][2] =
int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,NOTARIZED_HEIGHT,Num_nutxos;
std::string NOTARY_PUBKEY;
uint8_t NOTARY_PUBKEY33[33];
uint256 NOTARIZED_HASH,NOTARIZED_BTCHASH;
struct nutxo_entry { uint256 txhash; uint64_t voutmask; int32_t notaryid; };
struct nutxo_entry NUTXOS[10000];
@ -205,6 +206,7 @@ int32_t komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numno
#endif
if ( fp == 0 )
{
decode_hex(NOTARY_PUBKEY33,33,NOTARY_PUBKEY.ToString().c_str());
if ( (fp= fopen(fname,"rb+")) != 0 )
{
while ( (func= fgetc(fp)) != EOF )
@ -513,7 +515,19 @@ void komodo_disconnect(CBlockIndex *pindex,CBlock& block)
komodo_stateupdate(-pindex->nHeight,0,0,0,zero,0,0);
}
int32_t komodo_blockindexcheck(CBlockIndex *pindex,uint32_t *nBitsp)
void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex)
{
}
void komodo_block2pubkey33(uint8_t *pubkey33,CBlock& block)
{
uint8_t *ptr;
ptr = block.vtx[0].vout[0].scriptPubKey.data();
memcpy(pubkey33,ptr+1,33);
}
/*int32_t komodo_blockindexcheck(CBlockIndex *pindex,uint32_t *nBitsp)
{
// 1 -> valid notary block, change nBits to KOMODO_MINDIFF_NBITS
// -1 -> invalid, ie, prior to notarized block
@ -560,6 +574,6 @@ int32_t komodo_blockhdrcheck(CBlockHeader& blockhdr,uint32_t *nBitsp)
int32_t komodo_blockcheck(CBlock& block,uint32_t *nBitsp)
{
return(komodo_blockhdrcheck(block,nBitsp));
}
}*/
#endif

59
src/main.cpp

@ -1278,7 +1278,7 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock
if (pindexSlow) {
CBlock block;
if (ReadBlockFromDisk(block, pindexSlow,0)) {
if (ReadBlockFromDisk(block, pindexSlow)) {
BOOST_FOREACH(const CTransaction &tx, block.vtx) {
if (tx.GetHash() == hash) {
txOut = tx;
@ -1333,9 +1333,9 @@ bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos, const CMessageHeader::M
return true;
}
bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos,int32_t skipkomodo)
bool ReadBlockFromDisk(int32_t height,CBlock& block, const CDiskBlockPos& pos)
{
int32_t retval=0; uint32_t nBits;
uint8_t pubkey33[33];
block.SetNull();
// Open history file to read
@ -1350,22 +1350,16 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos,int32_t skipkomod
catch (const std::exception& e) {
return error("%s: Deserialize or I/O error - %s at %s", __func__, e.what(), pos.ToString());
}
// Check the header
nBits = block.nBits;
if ( skipkomodo != 0 || (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());
}
else if ( retval < 0 )
return(false);
komodo_block2pubkey33(pubkey33,block);
if (!(CheckEquihashSolution(&block, Params()) && CheckProofOfWork(height,pubkey33,block.GetHash(), block.nBits, Params().GetConsensus())))
return error("ReadBlockFromDisk: Errors in block header at %s", pos.ToString());
return true;
}
bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex,int32_t skipkomodo)
bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex)
{
if (!ReadBlockFromDisk(block, pindex->GetBlockPos(),skipkomodo))
if (!ReadBlockFromDisk(pindex->nHeight,block, pindex->GetBlockPos()))
return false;
if (block.GetHash() != pindex->GetBlockHash())
return error("ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() doesn't match index for %s at %s",
@ -2405,7 +2399,7 @@ bool static DisconnectTip(CValidationState &state) {
mempool.check(pcoinsTip);
// Read block from disk.
CBlock block;
if (!ReadBlockFromDisk(block, pindexDelete,0))
if (!ReadBlockFromDisk(block, pindexDelete))
return AbortNode(state, "Failed to read block");
// Apply the block atomically to the chain state.
uint256 anchorBeforeDisconnect = pcoinsTip->GetBestAnchor();
@ -2468,7 +2462,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
int64_t nTime1 = GetTimeMicros();
CBlock block;
if (!pblock) {
if (!ReadBlockFromDisk(block, pindexNew,0))
if (!ReadBlockFromDisk(block, pindexNew))
return AbortNode(state, "Failed to read block");
pblock = &block;
}
@ -2956,25 +2950,20 @@ bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, unsigne
return true;
}
bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, bool fCheckPOW)
bool CheckBlockHeader(int32_t height,const CBlockHeader& block, CValidationState& state, bool fCheckPOW)
{
int32_t retval; uint32_t nBits;
uint8_t pubkey33[33];
// Check timestamp
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_blockhdrcheck(*(CBlockHeader *)&block,&nBits)) == 0 )
{
// Check Equihash solution is valid
if ( fCheckPOW && !CheckEquihashSolution(&block, Params()) )
return state.DoS(100, error("CheckBlockHeader(): Equihash solution invalid"),REJECT_INVALID, "invalid-solution");
// Check proof of work matches claimed amount
if ( fCheckPOW && !CheckProofOfWork(block.GetHash(), nBits, Params().GetConsensus()) )
return state.DoS(50, error("CheckBlockHeader(): proof of work failed"),REJECT_INVALID, "high-hash");
}
else if ( retval < 0 ) // komodo rejects block, ie. prior to notarized blockhash
return(false);
// Check Equihash solution is valid
if ( fCheckPOW && !CheckEquihashSolution(&block, Params()) )
return state.DoS(100, error("CheckBlockHeader(): Equihash solution invalid"),REJECT_INVALID, "invalid-solution");
// Check proof of work matches claimed amount
komodo_block2pubkey33(pubkey33,block);
if ( fCheckPOW && !CheckProofOfWork(height,pubkey33,block.GetHash(), block.nBits, Params().GetConsensus()) )
return state.DoS(50, error("CheckBlockHeader(): proof of work failed"),REJECT_INVALID, "high-hash");
return true;
}
@ -3606,7 +3595,7 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth
break;
CBlock block;
// check level 0: read from disk
if (!ReadBlockFromDisk(block, pindex,0))
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(block, state))
@ -3646,7 +3635,7 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth
uiInterface.ShowProgress(_("Verifying blocks..."), std::max(1, std::min(99, 100 - (int)(((double)(chainActive.Height() - pindex->nHeight)) / (double)nCheckDepth * 50))));
pindex = chainActive.Next(pindex);
CBlock block;
if (!ReadBlockFromDisk(block, pindex,0))
if (!ReadBlockFromDisk(block, pindex))
return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
if (!ConnectBlock(block, state, pindex, coins))
return error("VerifyDB(): *** found unconnectable block at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
@ -3819,7 +3808,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
std::pair<std::multimap<uint256, CDiskBlockPos>::iterator, std::multimap<uint256, CDiskBlockPos>::iterator> range = mapBlocksUnknownParent.equal_range(head);
while (range.first != range.second) {
std::multimap<uint256, CDiskBlockPos>::iterator it = range.first;
if (ReadBlockFromDisk(block, it->second,0))
if (ReadBlockFromDisk(block, it->second))
{
LogPrintf("%s: Processing out of order child %s of %s\n", __func__, block.GetHash().ToString(),
head.ToString());
@ -4178,7 +4167,7 @@ void static ProcessGetData(CNode* pfrom)
{
// Send block from disk
CBlock block;
if (!ReadBlockFromDisk(block, (*mi).second,0))
if (!ReadBlockFromDisk(block, (*mi).second))
assert(!"cannot load block from disk");
if (inv.type == MSG_BLOCK)
pfrom->PushMessage("block", block);

4
src/main.h

@ -393,8 +393,8 @@ public:
/** Functions for disk access for blocks */
bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos, const CMessageHeader::MessageStartChars& messageStart);
bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos,int32_t skipkomodo);
bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex,int32_t skipkomodo);
bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos);
bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex);
/** Functions for validating blocks and updating the block tree */

2
src/pow.cpp

@ -106,7 +106,7 @@ bool CheckEquihashSolution(const CBlockHeader *pblock, const CChainParams& param
return true;
}
bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params& params)
bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned int nBits, const Consensus::Params& params)
{
bool fNegative;
bool fOverflow;

2
src/pow.h

@ -25,7 +25,7 @@ unsigned int CalculateNextWorkRequired(arith_uint256 bnAvg,
bool CheckEquihashSolution(const CBlockHeader *pblock, const CChainParams&);
/** Check whether a block hash satisfies the proof-of-work requirement specified by nBits */
bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params&);
bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned int nBits, const Consensus::Params&);
arith_uint256 GetBlockProof(const CBlockIndex& block);
/** Return the time it would take to redo the work difference between from and to, assuming the current hashrate corresponds to the difficulty at tip, in seconds. */

2
src/rest.cpp

@ -200,7 +200,7 @@ static bool rest_block(AcceptedConnection* conn,
if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0)
throw RESTERR(HTTP_NOT_FOUND, hashStr + " not available (pruned data)");
if (!ReadBlockFromDisk(block, pblockindex,0))
if (!ReadBlockFromDisk(block, pblockindex))
throw RESTERR(HTTP_NOT_FOUND, hashStr + " not found");
}

2
src/rpcblockchain.cpp

@ -326,7 +326,7 @@ Value getblock(const Array& params, bool fHelp)
if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0)
throw JSONRPCError(RPC_INTERNAL_ERROR, "Block not available (pruned data)");
if(!ReadBlockFromDisk(block, pblockindex,0))
if(!ReadBlockFromDisk(block, pblockindex))
throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk");
if (!fVerbose)

11
src/rpcmining.cpp

@ -115,7 +115,7 @@ Value getgenerate(const Array& params, bool fHelp)
return GetBoolArg("-gen", false);
}
int32_t komodo_blockcheck(CBlock& block,uint32_t *nBitsp);
extern uint8_t NOTARY_PUBKEY33[33];
Value generate(const Array& params, bool fHelp)
{
@ -193,15 +193,8 @@ Value generate(const Array& params, bool fHelp)
std::function<bool(std::vector<unsigned char>)> validBlock =
[&pblock](std::vector<unsigned char> soln)
{
int32_t retval; uint32_t nBits;
pblock->nSolution = soln;
nBits = pblock->nBits;
if ( (retval= komodo_blockcheck(*pblock,&nBits)) == 0 )
{
return CheckProofOfWork(pblock->GetHash(), nBits, Params().GetConsensus());
} else if ( retval < 0 ) // komodo rejects, ie. prior to notarized blockhash
return(false);
return true;
return CheckProofOfWork(nHeight,NOTARY_PUBKEY33,pblock->GetHash(), pblock->nBits, Params().GetConsensus());
};
if (EhBasicSolveUncancellable(n, k, curr_state, validBlock))
goto endloop;

2
src/rpcrawtransaction.cpp

@ -303,7 +303,7 @@ Value gettxoutproof(const Array& params, bool fHelp)
}
CBlock block;
if(!ReadBlockFromDisk(block, pblockindex,0))
if(!ReadBlockFromDisk(block, pblockindex))
throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk");
unsigned int ntxFound = 0;

13
src/txdb.cpp

@ -306,15 +306,10 @@ bool CBlockTreeDB::LoadBlockIndexGuts()
pindexNew->nSolution = diskindex.nSolution;
pindexNew->nStatus = diskindex.nStatus;
pindexNew->nTx = diskindex.nTx;
int32_t retval; uint32_t nBits;
nBits = pindexNew->nBits;
if ( (retval= komodo_blockindexcheck(pindexNew,&nBits)) == 0 )
{
if (!CheckProofOfWork(pindexNew->GetBlockHash(), nBits, Params().GetConsensus()))
return error("LoadBlockIndex(): CheckProofOfWork failed: %s", pindexNew->ToString());
} else if ( retval < 0 ) // komodo rejects, ie. prior to notarized blockhash
return(false);
uint8_t pubkey33[33];
komodo_index2pubkey33(pubkey33,pindexNew);
if (!CheckProofOfWork(pindexNew->height,pubkey33,pindexNew->GetBlockHash(), pindexNew->nBits, Params().GetConsensus()))
return error("LoadBlockIndex(): CheckProofOfWork failed: %s", pindexNew->ToString());
pcursor->Next();
} else {
break; // if shutdown requested or finished loading block index

6
src/wallet/wallet.cpp

@ -668,7 +668,7 @@ void CWallet::IncrementNoteWitnesses(const CBlockIndex* pindex,
const CBlock* pblock {pblockIn};
CBlock block;
if (!pblock) {
ReadBlockFromDisk(block, pindex,0);
ReadBlockFromDisk(block, pindex);
pblock = &block;
}
@ -1651,7 +1651,7 @@ void CWallet::WitnessNoteCommitment(std::vector<uint256> commitments,
while (pindex) {
CBlock block;
ReadBlockFromDisk(block, pindex,0);
ReadBlockFromDisk(block, pindex);
BOOST_FOREACH(const CTransaction& tx, block.vtx)
{
@ -1727,7 +1727,7 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), pindex, false) - dProgressStart) / (dProgressTip - dProgressStart) * 100))));
CBlock block;
ReadBlockFromDisk(block, pindex,0);
ReadBlockFromDisk(block, pindex);
BOOST_FOREACH(CTransaction& tx, block.vtx)
{
if (AddToWalletIfInvolvingMe(tx, &block, fUpdate))

Loading…
Cancel
Save