From: CryptoManiac Date: Wed, 9 Sep 2015 20:27:15 +0000 (+0300) Subject: Fix txpos calculation issue and use out instead of ref for stake hash and target... X-Git-Url: https://git.novaco.in/?p=NovacoinLibrary.git;a=commitdiff_plain;h=fed302c65257c4124ec996f50ee228dd12acd6d3 Fix txpos calculation issue and use out instead of ref for stake hash and target values. --- diff --git a/Novacoin/CBlockStore.cs b/Novacoin/CBlockStore.cs index 1b600b9..e8981eb 100644 --- a/Novacoin/CBlockStore.cs +++ b/Novacoin/CBlockStore.cs @@ -1108,14 +1108,19 @@ namespace Novacoin /// Block reference /// Block position reference /// Result of operation - public bool GetBlockByTransactionID(uint256 TxID, ref CBlock block, ref long nBlockPos) + public bool GetBlockByTransactionID(uint256 TxID, out CBlock block, out long nBlockPos) { + block = null; + nBlockPos = -1; + var queryResult = dbConn.Query("select b.* from [BlockStorage] b left join [MerkleNodes] m on (b.[ItemID] = m.[nParentBlockID]) where m.[TransactionHash] = ?", (byte[])TxID); if (queryResult.Count == 1) { CBlockStoreItem blockCursor = queryResult[0]; + nBlockPos = blockCursor.nBlockPos; + return blockCursor.ReadFromFile(ref fStreamReadWrite, out block); } @@ -1273,7 +1278,7 @@ namespace Novacoin // TODO: proof-of-stake validation uint256 hashProofOfStake = 0, targetProofOfStake = 0; - if (!StakeModifier.CheckProofOfStake(block.vtx[1], block.header.nBits, ref hashProofOfStake, ref targetProofOfStake)) + if (!StakeModifier.CheckProofOfStake(block.vtx[1], block.header.nBits, out hashProofOfStake, out targetProofOfStake)) { return false; // do not error here as we expect this during initial block download } diff --git a/Novacoin/StakeModifier.cs b/Novacoin/StakeModifier.cs index 944fd36..788ff4e 100644 --- a/Novacoin/StakeModifier.cs +++ b/Novacoin/StakeModifier.cs @@ -338,8 +338,10 @@ namespace Novacoin return GetKernelStakeModifier(hashBlockFrom, ref nStakeModifier, ref nStakeModifierHeight, ref nStakeModifierTime); } - public static bool CheckStakeKernelHash(uint nBits, uint256 hashBlockFrom, uint nTimeBlockFrom, uint nTxPrevOffset, CTransaction txPrev, COutPoint prevout, uint nTimeTx, ref uint256 hashProofOfStake, ref uint256 targetProofOfStake) + public static bool CheckStakeKernelHash(uint nBits, uint256 hashBlockFrom, uint nTimeBlockFrom, uint nTxPrevOffset, CTransaction txPrev, COutPoint prevout, uint nTimeTx, out uint256 hashProofOfStake, out uint256 targetProofOfStake) { + hashProofOfStake = targetProofOfStake = 0; + if (nTimeTx < txPrev.nTime) { return false; // Transaction timestamp violation @@ -432,8 +434,10 @@ namespace Novacoin return (uint)hashChecksum.Low64; } - internal static bool CheckProofOfStake(CTransaction tx, uint nBits, ref uint256 hashProofOfStake, ref uint256 targetProofOfStake) + public static bool CheckProofOfStake(CTransaction tx, uint nBits, out uint256 hashProofOfStake, out uint256 targetProofOfStake) { + hashProofOfStake = targetProofOfStake = 0; + if (!tx.IsCoinStake) { return false; // called on non-coinstake @@ -444,9 +448,9 @@ namespace Novacoin // Read block header - long nBlockPos = 0; - CBlock block = null; - if (!CBlockStore.Instance.GetBlockByTransactionID(txin.prevout.hash, ref block, ref nBlockPos)) + long nBlockPos; + CBlock block; + if (!CBlockStore.Instance.GetBlockByTransactionID(txin.prevout.hash, out block, out nBlockPos)) { return false; // unable to read block of previous transaction } @@ -476,7 +480,7 @@ namespace Novacoin return false; // vin[0] signature check failed } - if (!CheckStakeKernelHash(nBits, block.header.Hash, block.header.nTime, (uint)(nTxPos - nBlockPos), txPrev, txin.prevout, tx.nTime, ref hashProofOfStake, ref targetProofOfStake)) + if (!CheckStakeKernelHash(nBits, block.header.Hash, block.header.nTime, (uint)(nTxPos - nBlockPos), txPrev, txin.prevout, tx.nTime, out hashProofOfStake, out targetProofOfStake)) { return false; // check kernel failed on coinstake }