X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Fmain.cpp;h=c36665171538c067e6c38b259b26d4b00f0879e0;hb=5b1f0a0a62474909ea2c798bbd440d2790d042c5;hp=e5668f98e5353d24c4b7020e58a75ab5d24f8cd6;hpb=77a43545b4491b9703d803765da9059d2bdd5aaa;p=novacoin.git diff --git a/src/main.cpp b/src/main.cpp index e5668f9..c366651 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -297,37 +297,54 @@ bool CTransaction::ReadFromDisk(COutPoint prevout) return ReadFromDisk(txdb, prevout, txindex); } -bool CTransaction::IsStandard() const +bool CTransaction::IsStandard(string& strReason) const { if (nVersion > CTransaction::CURRENT_VERSION) + { + strReason = "version"; return false; + } unsigned int nDataOut = 0; txnouttype whichType; BOOST_FOREACH(const CTxIn& txin, vin) { - // Biggest 'standard' txin is a 3-signature 3-of-3 CHECKMULTISIG - // pay-to-script-hash, which is 3 ~80-byte signatures, 3 - // ~65-byte public keys, plus a few script ops. - if (txin.scriptSig.size() > 500) + // Biggest 'standard' txin is a 15-of-15 P2SH multisig with compressed + // keys. (remember the 520 byte limit on redeemScript size) That works + // out to a (15*(33+1))+3=513 byte redeemScript, 513+1+15*(73+1)=1624 + // bytes of scriptSig, which we round off to 1650 bytes for some minor + // future-proofing. That's also enough to spend a 20-of-20 + // CHECKMULTISIG scriptPubKey, though such a scriptPubKey is not + // considered standard) + if (txin.scriptSig.size() > 1650) + { + strReason = "scriptsig-size"; return false; + } if (!txin.scriptSig.IsPushOnly()) + { + strReason = "scriptsig-not-pushonly"; return false; + } if (!txin.scriptSig.HasCanonicalPushes()) { + strReason = "txin-scriptsig-not-canonicalpushes"; return false; } } BOOST_FOREACH(const CTxOut& txout, vout) { if (!::IsStandard(txout.scriptPubKey, whichType)) { + strReason = "scriptpubkey"; return false; } if (whichType == TX_NULL_DATA) nDataOut++; else { if (txout.nValue == 0) { + strReason = "txout-value=0"; return false; } if (!txout.scriptPubKey.HasCanonicalPushes()) { + strReason = "txout-scriptsig-not-canonicalpushes"; return false; } } @@ -335,6 +352,7 @@ bool CTransaction::IsStandard() const // only one OP_RETURN txout is permitted if (nDataOut > 1) { + strReason = "multi-op-return"; return false; } @@ -533,13 +551,9 @@ bool CTransaction::CheckTransaction() const int64_t CTransaction::GetMinFee(unsigned int nBlockSize, bool fAllowFree, enum GetMinFee_mode mode, unsigned int nBytes) const { - // Use new fees approach if we are on test network or - // switch date has been reached - bool fNewApproach = fTestNet || nTime > FEE_SWITCH_TIME; - int64_t nMinTxFee = MIN_TX_FEE, nMinRelayTxFee = MIN_RELAY_TX_FEE; - if(!fNewApproach || IsCoinStake()) + if(IsCoinStake()) { // Enforce 0.01 as minimum fee for old approach or coinstake nMinTxFee = CENT; @@ -552,42 +566,31 @@ int64_t CTransaction::GetMinFee(unsigned int nBlockSize, bool fAllowFree, enum G unsigned int nNewBlockSize = nBlockSize + nBytes; int64_t nMinFee = (1 + (int64_t)nBytes / 1000) * nBaseFee; - if (fNewApproach) + if (fAllowFree) { - if (fAllowFree) + if (nBlockSize == 1) { - if (nBlockSize == 1) - { - // Transactions under 1K are free - if (nBytes < 1000) - nMinFee = 0; - } - else - { - // Free transaction area - if (nNewBlockSize < 27000) - nMinFee = 0; - } + // Transactions under 1K are free + if (nBytes < 1000) + nMinFee = 0; + } + else + { + // Free transaction area + if (nNewBlockSize < 27000) + nMinFee = 0; } - - // To limit dust spam, require additional MIN_TX_FEE/MIN_RELAY_TX_FEE for - // each non empty output which is less than 0.01 - // - // It's safe to ignore empty outputs here, because these inputs are allowed - // only for coinbase and coinstake transactions. - BOOST_FOREACH(const CTxOut& txout, vout) - if (txout.nValue < CENT && !txout.IsEmpty()) - nMinFee += nBaseFee; - } - else if (nMinFee < nBaseFee) - { - // To limit dust spam, require MIN_TX_FEE/MIN_RELAY_TX_FEE if - // any output is less than 0.01 - BOOST_FOREACH(const CTxOut& txout, vout) - if (txout.nValue < CENT) - nMinFee = nBaseFee; } + // To limit dust spam, require additional MIN_TX_FEE/MIN_RELAY_TX_FEE for + // each non empty output which is less than 0.01 + // + // It's safe to ignore empty outputs here, because these inputs are allowed + // only for coinbase and coinstake transactions. + BOOST_FOREACH(const CTxOut& txout, vout) + if (txout.nValue < CENT && !txout.IsEmpty()) + nMinFee += nBaseFee; + // Raise the price as the block approaches full if (nBlockSize != 1 && nNewBlockSize >= MAX_BLOCK_SIZE_GEN/2) { @@ -625,8 +628,9 @@ bool CTxMemPool::accept(CTxDB& txdb, CTransaction &tx, bool fCheckInputs, return error("CTxMemPool::accept() : not accepting nLockTime beyond 2038 yet"); // Rather not work on nonstandard transactions (unless -testnet) - if (!fTestNet && !tx.IsStandard()) - return error("CTxMemPool::accept() : nonstandard transaction type"); + string strNonStd; + if (!fTestNet && !tx.IsStandard(strNonStd)) + return error("CTxMemPool::accept() : nonstandard transaction (%s)", strNonStd.c_str()); // Do we already have it? uint256 hash = tx.GetHash(); @@ -1259,13 +1263,14 @@ bool IsInitialBlockDownload() return true; static int64_t nLastUpdate; static CBlockIndex* pindexLastBest; + int64_t nCurrentTime = GetTime(); if (pindexBest != pindexLastBest) { pindexLastBest = pindexBest; - nLastUpdate = GetTime(); + nLastUpdate = nCurrentTime; } - return (GetTime() - nLastUpdate < 10 && - pindexBest->GetBlockTime() < GetTime() - 24 * 60 * 60); + return (nCurrentTime - nLastUpdate < 10 && + pindexBest->GetBlockTime() < nCurrentTime - 24 * 60 * 60); } void static InvalidChainFound(CBlockIndex* pindexNew) @@ -2161,7 +2166,7 @@ bool CBlock::AddToBlockIndex(unsigned int nFile, unsigned int nBlockPos) pindexNew->nChainTrust = (pindexNew->pprev ? pindexNew->pprev->nChainTrust : 0) + pindexNew->GetBlockTrust(); // ppcoin: compute stake entropy bit for stake modifier - if (!pindexNew->SetStakeEntropyBit(GetStakeEntropyBit(pindexNew->nTime))) + if (!pindexNew->SetStakeEntropyBit(GetStakeEntropyBit(pindexNew->nHeight))) return error("AddToBlockIndex() : SetStakeEntropyBit() failed"); // ppcoin: record proof-of-stake hash value @@ -2209,7 +2214,9 @@ bool CBlock::AddToBlockIndex(unsigned int nFile, unsigned int nBlockPos) hashPrevBestCoinBase = vtx[0].GetHash(); } - uiInterface.NotifyBlocksChanged(); + static int8_t counter = 0; + if( (++counter & 0x0F) == 0 || !IsInitialBlockDownload()) // repaint every 16 blocks if not in initial block download + uiInterface.NotifyBlocksChanged(); return true; } @@ -2272,26 +2279,9 @@ bool CBlock::CheckBlock(bool fCheckPOW, bool fCheckMerkleRoot, bool fCheckSig) c return DoS(50, error("CheckBlock() : coinstake timestamp violation nTimeBlock=%" PRId64 " nTimeTx=%u", GetBlockTime(), vtx[1].nTime)); // NovaCoin: check proof-of-stake block signature - if (fCheckSig && !CheckBlockSignature(true)) + if (fCheckSig && !CheckBlockSignature()) return DoS(100, error("CheckBlock() : bad proof-of-stake block signature")); } - else - { - // Should we check proof-of-work block signature or not? - // - // * Always skip on TestNet - // * Perform checking for the first 9689 blocks - // * Perform checking since last checkpoint until 20 Sep 2013 (will be removed after) - - if(!fTestNet && fCheckSig) - { - bool checkEntropySig = (GetBlockTime() < ENTROPY_SWITCH_TIME); - - // NovaCoin: check proof-of-work block signature - if (checkEntropySig && !CheckBlockSignature(false)) - return DoS(100, error("CheckBlock() : bad proof-of-work block signature")); - } - } // Check transactions BOOST_FOREACH(const CTransaction& tx, vtx) @@ -2322,7 +2312,6 @@ bool CBlock::CheckBlock(bool fCheckPOW, bool fCheckMerkleRoot, bool fCheckSig) c if (fCheckMerkleRoot && hashMerkleRoot != BuildMerkleTree()) return DoS(100, error("CheckBlock() : hashMerkleRoot mismatch")); - return true; } @@ -2510,7 +2499,7 @@ bool ProcessBlock(CNode* pfrom, CBlock* pblock) return error("ProcessBlock() : duplicate proof-of-stake (%s, %d) for block %s", pblock->GetProofOfStake().first.ToString().c_str(), pblock->GetProofOfStake().second, hash.ToString().c_str()); // Preliminary checks - if (!pblock->CheckBlock()) + if (!pblock->CheckBlock(true, true, (pblock->nTime > Checkpoints::GetLastCheckpointTime()))) return error("ProcessBlock() : CheckBlock FAILED"); // ppcoin: verify hash target and signature of coinstake tx @@ -2666,55 +2655,27 @@ bool CBlock::SignBlock(CWallet& wallet) } // ppcoin: check block signature -bool CBlock::CheckBlockSignature(bool fProofOfStake) const +bool CBlock::CheckBlockSignature() const { - if (GetHash() == (!fTestNet ? hashGenesisBlock : hashGenesisBlockTestNet)) - return vchBlockSig.empty(); + if (IsProofOfWork()) + return true; vector vSolutions; txnouttype whichType; - if(fProofOfStake) - { - const CTxOut& txout = vtx[1].vout[1]; + const CTxOut& txout = vtx[1].vout[1]; - if (!Solver(txout.scriptPubKey, whichType, vSolutions)) - return false; - if (whichType == TX_PUBKEY) - { - valtype& vchPubKey = vSolutions[0]; - CKey key; - if (!key.SetPubKey(vchPubKey)) - return false; - if (vchBlockSig.empty()) - return false; - return key.Verify(GetHash(), vchBlockSig); - } - } - else + if (!Solver(txout.scriptPubKey, whichType, vSolutions)) + return false; + if (whichType == TX_PUBKEY) { - for(unsigned int i = 0; i < vtx[0].vout.size(); i++) - { - const CTxOut& txout = vtx[0].vout[i]; - - if (!Solver(txout.scriptPubKey, whichType, vSolutions)) - return false; - - if (whichType == TX_PUBKEY) - { - // Verify - valtype& vchPubKey = vSolutions[0]; - CKey key; - if (!key.SetPubKey(vchPubKey)) - continue; - if (vchBlockSig.empty()) - continue; - if(!key.Verify(GetHash(), vchBlockSig)) - continue; - - return true; - } - } + valtype& vchPubKey = vSolutions[0]; + CKey key; + if (!key.SetPubKey(vchPubKey)) + return false; + if (vchBlockSig.empty()) + return false; + return key.Verify(GetHash(), vchBlockSig); } return false; }