From 28b80e6065fb3ada78a6ea49faf2912beb59ca27 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 18 Jan 2013 12:16:39 -0500 Subject: [PATCH 1/2] Send transactions after a CMerkleBlock when asked for it in an inv. This actually simplifies some SPV code, as they can keep track of a filtered block and its txn before accepting both in one step. The previous argument was that SPV nodes should handle the txn the same as any other free txn and then mark them as connected to a block when they get the filtered block itself. However, it now appears that SPV nodes will need to put in more effort to verify loose txn than they would to verify txn in blocks, thus making it more approriate to send the txn after the filtered block. --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index a6394e0b..9fa6ebf2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3267,6 +3267,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) if (pfrom->pfilter) { CMerkleBlock merkleBlock(block, *pfrom->pfilter); + pfrom->PushMessage("merkleblock", merkleBlock); // CMerkleBlock just contains hashes, so also push any transactions in the block the client did not see // This avoids hurting performance by pointlessly requiring a round-trip // Note that there is currently no way for a node to request any single transactions we didnt send here - @@ -3277,7 +3278,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) BOOST_FOREACH(PairType& pair, merkleBlock.vMatchedTxn) if (!pfrom->setInventoryKnown.count(CInv(MSG_TX, pair.second))) pfrom->PushMessage("tx", block.vtx[pair.first]); - pfrom->PushMessage("merkleblock", merkleBlock); } // else // no response From 192cc910ec7cade1d0dce7f3b111e7fc7720e607 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 18 Jan 2013 13:55:18 -0500 Subject: [PATCH 2/2] Replace 520 constant with MAX_SCRIPT_ELEMENT_SIZE --- src/main.cpp | 2 +- src/script.cpp | 4 ++-- src/script.h | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 9fa6ebf2..4febf332 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3588,7 +3588,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) // Nodes must NEVER send a data item > 520 bytes (the max size for a script data object, // and thus, the maximum size any matched object can have) in a filteradd message - if (vData.size() > 520) + if (vData.size() > MAX_SCRIPT_ELEMENT_SIZE) { pfrom->Misbehaving(100); } else { diff --git a/src/script.cpp b/src/script.cpp index 70adf1f9..45ac8335 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -340,7 +340,7 @@ bool EvalScript(vector >& stack, const CScript& script, co // if (!script.GetOp(pc, opcode, vchPushValue)) return false; - if (vchPushValue.size() > 520) + if (vchPushValue.size() > MAX_SCRIPT_ELEMENT_SIZE) return false; if (opcode > OP_16 && ++nOpCount > 201) return false; @@ -670,7 +670,7 @@ bool EvalScript(vector >& stack, const CScript& script, co valtype& vch2 = stacktop(-1); vch1.insert(vch1.end(), vch2.begin(), vch2.end()); popstack(stack); - if (stacktop(-1).size() > 520) + if (stacktop(-1).size() > MAX_SCRIPT_ELEMENT_SIZE) return false; } break; diff --git a/src/script.h b/src/script.h index 0b481eb6..4b29f627 100644 --- a/src/script.h +++ b/src/script.h @@ -17,6 +17,8 @@ class CCoins; class CTransaction; +static const unsigned int MAX_SCRIPT_ELEMENT_SIZE = 520; // bytes + /** Signature hash types/flags */ enum {