Created
May 5, 2017 22:58
-
-
Save luke-jr/62435b3fb80fcf9c12a4629be02c5861 to your computer and use it in GitHub Desktop.
Include segwit equivalent max size in RPC getblock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp | |
index a1cb89c..63fe757 100644 | |
--- a/src/rpc/blockchain.cpp | |
+++ b/src/rpc/blockchain.cpp | |
@@ -102,6 +102,26 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx | |
result.push_back(Pair("strippedsize", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS))); | |
result.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION))); | |
result.push_back(Pair("weight", (int)::GetBlockWeight(block))); | |
+ | |
+ { | |
+ size_t nBlockSuperStrippedSize = 0; | |
+ size_t nBlockWitnessAndSigSize = 0; | |
+ for (auto & tx : block.vtx) { | |
+ CMutableTransaction mtx(tx); | |
+ for (auto & inp : mtx.vin) { | |
+ nBlockWitnessAndSigSize += 1 + inp.scriptSig.size(); | |
+ inp.scriptSig.clear(); | |
+ } | |
+ // Doesn't work with actual witness blocks | |
+ nBlockSuperStrippedSize += ::GetSerializeSize(mtx, SER_NETWORK, PROTOCOL_VERSION); | |
+ } | |
+ const size_t nBlockMaxTxWeight = 4000000 - (4 * (80 + ::GetSerializeSize(VARINT(block.vtx.size()), SER_NETWORK, PROTOCOL_VERSION))); | |
+ const size_t nBlockSimTxWeight = ((nBlockSuperStrippedSize * 4) + nBlockWitnessAndSigSize); | |
+ const size_t nBlockTxSize = nBlockSuperStrippedSize + nBlockWitnessAndSigSize; | |
+ const int64_t nSegwitEquiv = nBlockMaxTxWeight * nBlockTxSize / nBlockSimTxWeight; | |
+ result.push_back(Pair("segwit_equiv_hack", nSegwitEquiv)); | |
+ } | |
+ | |
result.push_back(Pair("height", blockindex->nHeight)); | |
result.push_back(Pair("version", block.nVersion)); | |
result.push_back(Pair("versionHex", strprintf("%08x", block.nVersion))); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment