aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Garzik <jgarzik@exmulti.com>2012-07-31 17:42:35 -0400
committerJeff Garzik <jgarzik@redhat.com>2012-07-31 17:42:35 -0400
commit05a85b2b38d516a8701f684fcd2ab99f3e5b462d (patch)
tree6d03e0f22dd6c299e2a11e8ad0e8b1daa5d1c1f8
parent3c83387c298b6462b176fe6f335502770007f192 (diff)
Add 'mempool' P2P command, and extend 'getdata' behavior
to permit downloading of mempool transactions from the remote peer.
-rw-r--r--src/main.cpp35
-rw-r--r--src/main.h1
-rw-r--r--src/version.h5
3 files changed, 37 insertions, 4 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 0c636cdec1..293e7bca5c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -2562,7 +2562,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
{
vector<CInv> vInv;
vRecv >> vInv;
- if (vInv.size() > 50000)
+ if (vInv.size() > MAX_INV_SZ)
{
pfrom->Misbehaving(20);
return error("message inv size() = %d", vInv.size());
@@ -2613,7 +2613,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
{
vector<CInv> vInv;
vRecv >> vInv;
- if (vInv.size() > 50000)
+ if (vInv.size() > MAX_INV_SZ)
{
pfrom->Misbehaving(20);
return error("message getdata size() = %d", vInv.size());
@@ -2655,11 +2655,24 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
else if (inv.IsKnownType())
{
// Send stream from relay memory
+ bool pushed = false;
{
LOCK(cs_mapRelay);
map<CInv, CDataStream>::iterator mi = mapRelay.find(inv);
- if (mi != mapRelay.end())
+ if (mi != mapRelay.end()) {
pfrom->PushMessage(inv.GetCommand(), (*mi).second);
+ pushed = true;
+ }
+ }
+ if (!pushed && inv.type == MSG_TX) {
+ LOCK(mempool.cs);
+ if (mempool.exists(inv.hash)) {
+ CTransaction tx = mempool.lookup(inv.hash);
+ CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
+ ss.reserve(1000);
+ ss << tx;
+ pfrom->PushMessage("tx", ss);
+ }
}
}
@@ -2834,6 +2847,22 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
}
+ else if (strCommand == "mempool")
+ {
+ std::vector<uint256> vtxid;
+ mempool.queryHashes(vtxid);
+ vector<CInv> vInv;
+ for (unsigned int i = 0; i < vtxid.size(); i++) {
+ CInv inv(MSG_TX, vtxid[i]);
+ vInv.push_back(inv);
+ if (i == (MAX_INV_SZ - 1))
+ break;
+ }
+ if (vInv.size() > 0)
+ pfrom->PushMessage("inv", vInv);
+ }
+
+
else if (strCommand == "checkorder")
{
uint256 hashReply;
diff --git a/src/main.h b/src/main.h
index 301badcca9..62187e4287 100644
--- a/src/main.h
+++ b/src/main.h
@@ -27,6 +27,7 @@ static const unsigned int MAX_BLOCK_SIZE = 1000000;
static const unsigned int MAX_BLOCK_SIZE_GEN = MAX_BLOCK_SIZE/2;
static const unsigned int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50;
static const unsigned int MAX_ORPHAN_TRANSACTIONS = MAX_BLOCK_SIZE/100;
+static const unsigned int MAX_INV_SZ = 50000;
static const int64 MIN_TX_FEE = 50000;
static const int64 MIN_RELAY_TX_FEE = 10000;
static const int64 MAX_MONEY = 21000000 * COIN;
diff --git a/src/version.h b/src/version.h
index c0d53e8b91..9d2fa6bbc8 100644
--- a/src/version.h
+++ b/src/version.h
@@ -30,7 +30,7 @@ extern const std::string CLIENT_DATE;
// network protocol versioning
//
-static const int PROTOCOL_VERSION = 60001;
+static const int PROTOCOL_VERSION = 60002;
// earlier versions not supported as of Feb 2012, and are disconnected
static const int MIN_PROTO_VERSION = 209;
@@ -46,4 +46,7 @@ static const int NOBLKS_VERSION_END = 32400;
// BIP 0031, pong message, is enabled for all versions AFTER this one
static const int BIP0031_VERSION = 60000;
+// "mempool" command, enhanced "getdata" behavior starts with this version:
+static const int MEMPOOL_GD_VERSION = 60002;
+
#endif