From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1Uz2zE-0001dQ-09 for bitcoin-development@lists.sourceforge.net; Tue, 16 Jul 2013 11:00:04 +0000 Received-SPF: pass (sog-mx-2.v43.ch3.sourceforge.com: domain of gmail.com designates 209.85.219.47 as permitted sender) client-ip=209.85.219.47; envelope-from=mh.in.england@gmail.com; helo=mail-oa0-f47.google.com; Received: from mail-oa0-f47.google.com ([209.85.219.47]) by sog-mx-2.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1Uz2zC-0001tI-16 for bitcoin-development@lists.sourceforge.net; Tue, 16 Jul 2013 11:00:03 +0000 Received: by mail-oa0-f47.google.com with SMTP id m1so612496oag.6 for ; Tue, 16 Jul 2013 03:59:56 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.60.79.131 with SMTP id j3mr1143328oex.96.1373972396558; Tue, 16 Jul 2013 03:59:56 -0700 (PDT) Sender: mh.in.england@gmail.com Received: by 10.76.23.36 with HTTP; Tue, 16 Jul 2013 03:59:56 -0700 (PDT) In-Reply-To: <2A1C412D-414E-4C41-8E20-F0D21F801328@grabhive.com> References: <3E7894A0-06F3-453D-87F8-975A244EBACF@include7.ch> <2BDA0943-22BB-4405-9AF0-86FB41FD04A6@include7.ch> <2F20A509-13A9-4C84-86D7-A15C21BACD53@include7.ch> <2A1C412D-414E-4C41-8E20-F0D21F801328@grabhive.com> Date: Tue, 16 Jul 2013 12:59:56 +0200 X-Google-Sender-Auth: w8eYBxUe30J6cvkwfiTaxKJYJak Message-ID: From: Mike Hearn To: Wendell Content-Type: multipart/alternative; boundary=047d7b678126a0d23304e19ee022 X-Spam-Score: -0.5 (/) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (mh.in.england[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record 1.0 HTML_MESSAGE BODY: HTML included in message 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-Headers-End: 1Uz2zC-0001tI-16 X-Mailman-Approved-At: Sun, 21 Jul 2013 14:12:24 +0000 Cc: Bitcoin Dev , Jonas Schnelli Subject: Re: [Bitcoin-development] Introducing BitcoinKit.framework X-BeenThere: bitcoin-development@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Jul 2013 11:00:04 -0000 --047d7b678126a0d23304e19ee022 Content-Type: text/plain; charset=UTF-8 I think that's a great approach. Here is the patch Satoshi sent me back in 2010. All the code has changed since but it can be a source of inspiration. >From Satoshi: *The simplified payment verification in the paper imagined you would receive transactions directly, as with sending to IP address which nobody uses, or a node would index all transactions by public key and you could download them like downloading mail from a mail server. Instead, I think client-only nodes should receive full blocks so they can scan them for their own transactions. They don't need to store them or index them. For the initial download, they only need to download headers, since there couldn't be any payments before the first time the program was run (a header download command was added in 0.3.18). From then on, they download full blocks (but only store the headers). Code for client-only mode is mostly implemented. There's a feature branch on github with it, also I'm attaching the patch to this message. Here's some more about it: "Here's my client-mode implementation so far. Client-only mode only records block headers and doesn't use the tx index. It can't generate, but it can still send and receive transactions. It's not fully finished for use by end-users, but it doesn't matter because it's a complete no-op if fClient is not enabled. At this point it's mainly documentation showing the cut-lines for client-only re-implementers. With fClient=true, I've only tested the header-only initial download. A little background. CBlockIndex contains all the information of the block header, so to operate with headers only, I just maintain the CBlockIndex structure as usual. The nFile/nBlockPos are null, since the full block is not recorded on disk. The code to gracefully switch between client-mode on/off without deleting blk*.dat in between is not implemented yet. It would mostly be a matter of having non-client LoadBlockIndex ignore block index entries with null block pos. That would make it re-download those as full blocks. Switching back to client-mode is no problem, it doesn't mind if the full blocks are there. If the initial block download becomes too long, we'll want client mode as an option so new users can get running quickly. With graceful switch-off of client mode, they can later turn off client mode and have it download the full blocks if they want to start generating. They should rather just use a getwork miner to join a pool instead. Client-only re-implementations would not need to implement EvalScript at all, or at most just implement the five ops used by the standard transaction templates." * diff -u old\db.cpp new\db.cpp --- old\db.cpp Sat Dec 18 18:35:59 2010 +++ new\db.cpp Sun Dec 19 20:53:59 2010 @@ -464,29 +464,32 @@ ReadBestInvalidWork(bnBestInvalidWork); // Verify blocks in the best chain - CBlockIndex* pindexFork = NULL; - for (CBlockIndex* pindex = pindexBest; pindex && pindex->pprev; pindex = pindex->pprev) + if (!fClient) { - if (pindex->nHeight < nBestHeight-2500 && !mapArgs.count("-checkblocks")) - break; - CBlock block; - if (!block.ReadFromDisk(pindex)) - return error("LoadBlockIndex() : block.ReadFromDisk failed"); - if (!block.CheckBlock()) + CBlockIndex* pindexFork = NULL; + for (CBlockIndex* pindex = pindexBest; pindex && pindex->pprev; pindex = pindex->pprev) { - printf("LoadBlockIndex() : *** found bad block at %d, hash=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString().c_str()); - pindexFork = pindex->pprev; + if (pindex->nHeight < nBestHeight-2500 && !mapArgs.count("-checkblocks")) + break; + CBlock block; + if (!block.ReadFromDisk(pindex)) + return error("LoadBlockIndex() : block.ReadFromDisk failed"); + if (!block.CheckBlock()) + { + printf("LoadBlockIndex() : *** found bad block at %d, hash=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString().c_str()); + pindexFork = pindex->pprev; + } + } + if (pindexFork) + { + // Reorg back to the fork + printf("LoadBlockIndex() : *** moving best chain pointer back to block %d\n", pindexFork->nHeight); + CBlock block; + if (!block.ReadFromDisk(pindexFork)) + return error("LoadBlockIndex() : block.ReadFromDisk failed"); + CTxDB txdb; + block.SetBestChain(txdb, pindexFork); } - } - if (pindexFork) - { - // Reorg back to the fork - printf("LoadBlockIndex() : *** moving best chain pointer back to block %d\n", pindexFork->nHeight); - CBlock block; - if (!block.ReadFromDisk(pindexFork)) - return error("LoadBlockIndex() : block.ReadFromDisk failed"); - CTxDB txdb; - block.SetBestChain(txdb, pindexFork); } return true; diff -u old\main.cpp new\main.cpp --- old\main.cpp Sat Dec 18 18:35:59 2010 +++ new\main.cpp Sun Dec 19 20:53:59 2010 @@ -637,6 +637,9 @@ if (!IsStandard()) return error("AcceptToMemoryPool() : nonstandard transaction type"); + if (fClient) + return true; + // Do we already have it? uint256 hash = GetHash(); CRITICAL_BLOCK(cs_mapTransactions) @@ -1308,23 +1311,26 @@ if (!CheckBlock()) return false; - //// issue here: it doesn't know the version - unsigned int nTxPos = pindex->nBlockPos + ::GetSerializeSize(CBlock(), SER_DISK) - 1 + GetSizeOfCompactSize(vtx.size()); - - map mapUnused; - int64 nFees = 0; - foreach(CTransaction& tx, vtx) + if (!fClient) { - CDiskTxPos posThisTx(pindex->nFile, pindex->nBlockPos, nTxPos); - nTxPos += ::GetSerializeSize(tx, SER_DISK); + //// issue here: it doesn't know the version + unsigned int nTxPos = pindex->nBlockPos + ::GetSerializeSize(CBlock(), SER_DISK) - 1 + GetSizeOfCompactSize(vtx.size( )); + + map mapUnused; + int64 nFees = 0; + foreach(CTransaction& tx, vtx) + { + CDiskTxPos posThisTx(pindex->nFile, pindex->nBlockPos, nTxPos); + nTxPos += ::GetSerializeSize(tx, SER_DISK); - if (!tx.ConnectInputs(txdb, mapUnused, posThisTx, pindex, nFees, true, false)) + if (!tx.ConnectInputs(txdb, mapUnused, posThisTx, pindex, nFees, true, false)) + return false; + } + + if (vtx[0].GetValueOut() > GetBlockValue(pindex->nHeight, nFees)) return false; } - if (vtx[0].GetValueOut() > GetBlockValue(pindex->nHeight, nFees)) - return false; - // Update block index on disk without changing it in memory. // The memory index structure will be changed after the db commits. if (pindex->pprev) @@ -1378,7 +1384,7 @@ foreach(CBlockIndex* pindex, vDisconnect) { CBlock block; - if (!block.ReadFromDisk(pindex)) + if (!block.ReadFromDisk(pindex, !fClient)) return error("Reorganize() : ReadFromDisk for disconnect failed"); if (!block.DisconnectBlock(txdb, pindex)) return error("Reorganize() : DisconnectBlock failed"); @@ -1395,7 +1401,7 @@ { CBlockIndex* pindex = vConnect[i]; CBlock block; - if (!block.ReadFromDisk(pindex)) + if (!block.ReadFromDisk(pindex, !fClient)) return error("Reorganize() : ReadFromDisk for connect failed"); if (!block.ConnectBlock(txdb, pindex)) { @@ -1526,7 +1532,7 @@ txdb.Close(); - if (pindexNew == pindexBest) + if (!fClient && pindexNew == pindexBest) { // Notify UI to display prev block's coinbase if it was ours static uint256 hashPrevBestCoinBase; @@ -1547,10 +1553,6 @@ // These are checks that are independent of context // that can be verified before saving an orphan block. - // Size limits - if (vtx.empty() || vtx.size() > MAX_BLOCK_SIZE || ::GetSerializeSize(*this, SER_NETWORK) > MAX_BLOCK_SIZE) - return error("CheckBlock() : size limits failed"); - // Check proof of work matches claimed amount if (!CheckProofOfWork(GetHash(), nBits)) return error("CheckBlock() : proof of work failed"); @@ -1559,6 +1561,13 @@ if (GetBlockTime() > GetAdjustedTime() + 2 * 60 * 60) return error("CheckBlock() : block timestamp too far in the future"); + if (fClient && vtx.empty()) + return true; + + // Size limits + if (vtx.empty() || vtx.size() > MAX_BLOCK_SIZE || ::GetSerializeSize(*this, SER_NETWORK) > MAX_BLOCK_SIZE) + return error("CheckBlock() : size limits failed"); + // First transaction must be coinbase, the rest must not be if (vtx.empty() || !vtx[0].IsCoinBase()) return error("CheckBlock() : first tx is not coinbase"); @@ -1623,13 +1632,14 @@ return error("AcceptBlock() : out of disk space"); unsigned int nFile = -1; unsigned int nBlockPos = 0; - if (!WriteToDisk(nFile, nBlockPos)) - return error("AcceptBlock() : WriteToDisk failed"); + if (!fClient) + if (!WriteToDisk(nFile, nBlockPos)) + return error("AcceptBlock() : WriteToDisk failed"); if (!AddToBlockIndex(nFile, nBlockPos)) return error("AcceptBlock() : AddToBlockIndex failed"); // Relay inventory, but don't relay old inventory during initial block download - if (hashBestChain == hash) + if (!fClient && hashBestChain == hash) CRITICAL_BLOCK(cs_vNodes) foreach(CNode* pnode, vNodes) if (nBestHeight > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : 55000)) @@ -2405,6 +2415,8 @@ { if (fShutdown) return true; + if (fClient && inv.type == MSG_TX) + continue; pfrom->AddInventoryKnown(inv); bool fAlreadyHave = AlreadyHave(txdb, inv); @@ -2441,6 +2453,9 @@ if (inv.type == MSG_BLOCK) { + if (fClient) + return true; + // Send block from disk map::iterator mi = mapBlockIndex.find(inv.hash); if (mi != mapBlockIndex.end()) @@ -2486,6 +2501,8 @@ else if (strCommand == "getblocks") { + if (fClient) + return true; CBlockLocator locator; uint256 hashStop; vRecv >> locator >> hashStop; @@ -2556,6 +2573,8 @@ else if (strCommand == "tx") { + if (fClient) + return true; vector vWorkQueue; CDataStream vMsg(vRecv); CTransaction tx; @@ -2620,6 +2639,33 @@ if (ProcessBlock(pfrom, &block)) mapAlreadyAskedFor.erase(inv); + } + + + else if (strCommand == "headers") + { + if (!fClient) + return true; + vector vHeaders; + vRecv >> vHeaders; + + uint256 hashBestBefore = hashBestChain; + foreach(CBlock& block, vHeaders) + { + block.vtx.clear(); + + printf("received header %s\n", block.GetHash().ToString(). substr(0,20).c_str()); + + CInv inv(MSG_BLOCK, block.GetHash()); + pfrom->AddInventoryKnown(inv); + + if (ProcessBlock(pfrom, &block)) + mapAlreadyAskedFor.erase(inv); + } + + // Request next batch + if (hashBestChain != hashBestBefore) + pfrom->PushGetBlocks(pindexBest, uint256(0)); } On Tue, Jul 16, 2013 at 12:17 PM, Wendell wrote: > I for one would be interested in taking a look at that. > > In San Jose I was asking around about the possibility of hiring someone to > complete such a patch. Pieter Wuille introduced me to Eric Lombrozo, who > expressed interest, but has since gotten quite busy. So we haven't arrived > at a detailed estimate of what it would involve. > > Maybe it would be better to start a completely new thread for this topic, > but I would very much be interested in an open dissection of what adding > SPV support to bitcoind would take. I am willing to fund or (ideally) > co-fund this endeavor, if I can ever get my head around it. I'm super > interested in all of these possibilities (including micro-stripped-VMs and > transpilation), but would simply like to encourage the proliferation of > _options_ whenever possible. > > -wendell > > grabhive.com | twitter.com/grabhive > > On Jul 16, 2013, at 11:51 AM, Mike Hearn wrote: > > > If you wanted to implement SPV mode in bitcoind, Gavin or I could send > you Satoshi's old patch although of course it is no longer usable. It would > indicate the basic cut lines though. > > --047d7b678126a0d23304e19ee022 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I think that's a great approach. Here is the patch Sat= oshi sent me back in 2010. All the code has changed since but it can be a s= ource of inspiration.

From Satoshi:

The simplified pay= ment verification in the paper imagined you would receive transactions dire= ctly, as with sending to IP address which nobody uses, or a node would inde= x all transactions by public key and you could download them like downloadi= ng mail from a mail server.

Instead, I think client-only nod= es should receive full blocks so they can scan them for their own transacti= ons. =C2=A0They don't need to store them or index them. =C2=A0For the i= nitial download, they only need to download headers, since there couldn'= ;t be any payments before the first time the program was run (a header down= load command was added in 0.3.18). =C2=A0From then on, they download full b= locks (but only store the headers).

Code for client-only mode is mos= tly implemented. =C2=A0There's a feature branch on github with it, also= I'm attaching the patch to this message.

Here's some more about it:

"Here'= s my client-mode implementation so far. =C2=A0Client-only mode only records= block headers and doesn't use the tx index. =C2=A0It can't generat= e, but it can still send and receive transactions. =C2=A0It's not fully= finished for use by end-users, but it doesn't matter because it's = a complete no-op if fClient is not enabled. =C2=A0At this point it's ma= inly documentation showing the cut-lines for client-only re-implementers.

With fClient=3Dtrue, I've on= ly tested the header-only initial download.

A little background. =C2=A0CBloc= kIndex contains all the information of the block header, so to operate with= headers only, I just maintain the CBlockIndex structure as usual. =C2=A0Th= e nFile/nBlockPos are null, since the full block is not recorded on disk.

The code to gracefully switch be= tween client-mode on/off without deleting blk*.dat in between is not implem= ented yet. =C2=A0It would mostly be a matter of having non-client LoadBlock= Index ignore block index entries with null block pos. =C2=A0That would make= it re-download those as full blocks. =C2=A0Switching back to client-mode i= s no problem, it doesn't mind if the full blocks are there.

If the initial block download be= comes too long, we'll want client mode as an option so new users can ge= t running quickly. =C2=A0With graceful switch-off of client mode, they can = later turn off client mode and have it download the full blocks if they wan= t to start generating. =C2=A0They should rather just use a getwork miner to= join a pool instead.

Client-only re-implementations w= ould not need to implement EvalScript at all, or at most just implement the= five ops used by the standard transaction templates."
=



diff -u old\db.cpp new\= db.cpp
--- old\db.cpp = =C2=A0Sat Dec 18 18:35:59 2010
+++ new\db.cpp =C2=A0Sun Dec 19 20:53:59 2010
@@ -464,29 +464= ,32 @@
=C2=A0 =C2=A0 =C2= =A0ReadBestInvalidWork(bnBestInvalidWork);

=C2=A0 =C2=A0 =C2=A0// Verify bl= ocks in the best chain
- = =C2=A0 =C2=A0CBlockIndex* pindexFork =3D NULL;
- =C2=A0 =C2=A0= for (CBlockIndex* pindex =3D pindexBest; pindex && pindex->pprev= ; pindex =3D pindex->pprev)
+ =C2=A0 =C2=A0= if (!fClient)
=C2=A0 =C2= =A0 =C2=A0{
- =C2=A0 =C2=A0= =C2=A0 =C2=A0if (pindex->nHeight < nBestHeight-2500 && !mapA= rgs.count("-checkblocks"))
- =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0break;
- =C2=A0 =C2=A0 =C2=A0 =C2=A0CBlock block;
- =C2=A0 =C2=A0= =C2=A0 =C2=A0if (!block.ReadFromDisk(pindex))
- =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return erro= r("LoadBlockIndex() : block.ReadFromDisk failed");
- =C2=A0 =C2=A0= =C2=A0 =C2=A0if (!block.CheckBlock())
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0CBlockIndex* pindexFork =3D NULL;=
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0for (CBlockIndex* pindex =3D pindexBest; pindex && pi= ndex->pprev; pindex =3D pindex->pprev)
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0{
- = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0printf("LoadBlockIndex() : **= * found bad block at %d, hash=3D%s\n", pindex->nHeight, pindex->= GetBlockHash().ToString().c_str());
- =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0pindexFork =3D pindex->pprev;
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0if (pindex->nHeight < nBestHeight-2500 && !mapArgs.count(&= quot;-checkblocks"))
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0break;
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0CBlock bl= ock;
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!block.ReadFromDisk(pindex))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0return error("LoadBlockIndex() : block.ReadFromDisk f= ailed");
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!block.CheckBlock())
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0printf("LoadBlockIndex() : *= ** found bad block at %d, hash=3D%s\n", pindex->nHeight, pindex->= ;GetBlockHash().ToString().c_str());
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0pindexFork =3D pindex->pprev;<= /span>
+ =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0}
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0}
+ =C2=A0 = =C2=A0 =C2=A0 =C2=A0if (pindexFork)
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0{
+ =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0// Reorg back to the fork
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0printf("LoadBlockIndex() : *** moving best= chain pointer back to block %d\n", pindexFork->nHeight); + =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0CBlock block;
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!block.ReadF= romDisk(= pindexFork))
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return error("LoadBlockIndex= () : block.ReadFromDisk failed");
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0CTxDB txdb;<= br style=3D"font-family:arial,sans-serif;font-size:13px"> + =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0block.SetBestChain(txdb, pindexFork);=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0}=
- =C2=A0 =C2=A0= }
- =C2=A0 =C2=A0if (pinde= xFork)
- =C2=A0 =C2=A0= {
- =C2=A0 =C2=A0 =C2=A0 = =C2=A0// Reorg back to the fork
- =C2=A0 =C2=A0= =C2=A0 =C2=A0printf("LoadBlockIndex() : *** moving best chain pointer= back to block %d\n", pindexFork->nHeight);
- =C2=A0 =C2=A0= =C2=A0 =C2=A0CBlock block;
- =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!block.ReadFromDisk(pindexFork))
- =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0return error("LoadBlockIndex() : block.Rea= dFromDisk failed");
-= =C2=A0 =C2=A0 =C2=A0 =C2=A0CTxDB txdb;
- =C2=A0 =C2=A0= =C2=A0 =C2=A0block.SetBestChain(txdb, pindexFork);
=C2=A0 =C2=A0 =C2=A0}

=C2=A0 =C2=A0 =C2=A0return true;=
diff -u old\main.cpp new\= main.cpp
--- old\main.cp= p =C2=A0 =C2=A0 =C2=A0 =C2=A0Sat Dec 18 18:35:59 2010
+++ new\main.cpp =C2=A0 =C2=A0 =C2=A0 =C2=A0Sun= Dec 19 20:53:59 2010
@@ -637,6 +637,= 9 @@
=C2=A0 =C2=A0 =C2=A0i= f (!IsStandard())
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0return error("AcceptToMemoryPool() : nonstandard t= ransaction type");

+ =C2=A0 =C2=A0= if (fClient)
+ =C2=A0 =C2= =A0 =C2=A0 =C2=A0return true;
+
=C2=A0 =C2=A0 =C2=A0// Do we already ha= ve it?
=C2=A0 =C2=A0 = =C2=A0uint256 hash =3D GetHash();
=C2=A0 =C2=A0 =C2=A0CRITICAL_BLOCK(cs_mapTransactions)
@@ -1308,23 +13= 11,26 @@
=C2=A0 =C2=A0 =C2= =A0if (!CheckBlock())

=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0return false;

- =C2=A0 = =C2=A0//// issue here: it doesn't know the version
- =C2=A0 =C2=A0= unsigned int nTxPos =3D pindex->nBlockPos + ::GetSerializeSize(CBlock(),= SER_DISK) - 1 + GetSizeOfCompactSize(vtx.size());
-
- =C2=A0 =C2=A0map<uint256, CTxIndex= > mapUnused;
- =C2=A0 =C2=A0= int64 nFees =3D 0;
- =C2= =A0 =C2=A0foreach(CTransaction& tx, vtx)
+ =C2=A0 =C2=A0= if (!fClient)
=C2=A0 =C2= =A0 =C2=A0{
- =C2=A0 =C2=A0= =C2=A0 =C2=A0CDiskTxPos posThisTx(pindex->nFile, pindex->nBlockPos, = nTxPos);
- =C2=A0 =C2=A0 = =C2=A0 =C2=A0nTxPos +=3D ::GetSerializeSize(tx, SER_DISK);

+ =C2=A0 =C2=A0= =C2=A0 =C2=A0//// issue here: it doesn't know the version
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned = int nTxPos =3D pindex->nBlockPos + ::GetSerializeSize(CBlock(), SER_DISK= ) - 1 + GetSizeOfCompactSize(vtx.size());
+
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0map<uin= t256, CTxIndex> mapUnused;
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0int64 nFees =3D 0;
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0foreach(CTransaction& tx, vtx)

+ =C2=A0 =C2=A0= =C2=A0 =C2=A0{
+ =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0CDiskTxPos posThisTx(pindex->nFile, pi= ndex->nBlockPos, nTxPos);
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0nTxPos +=3D ::GetSerializeSize(tx, SER_DISK);

- =C2=A0 =C2=A0= =C2=A0 =C2=A0if (!tx.ConnectInputs(txdb, mapUnused, posThisTx, pindex, nFe= es, true, false))
+ =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!tx.ConnectInputs(txdb, mapUnused, p= osThisTx, pindex, nFees, true, false))
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return false;
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0}
+
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0if (vtx[0]= .GetValueOut() > GetBlockValue(pindex->nHeight, nFees))
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return false;
=C2=A0 =C2=A0 =C2=A0}

- =C2=A0 =C2=A0if (vtx[0].GetVal= ueOut() > GetBlockValue(pindex->nHeight, nFees))
- =C2=A0 =C2=A0= =C2=A0 =C2=A0return false;
-
=C2=A0 =C2=A0 = =C2=A0// Update block index on disk without changing it in memory.=C2=A0 =C2=A0 =C2=A0// The memory = index structure will be changed after the db commits.
=C2=A0 =C2=A0 = =C2=A0if (pindex->pprev)
@@ -1378,7 +1384,7 @@
=C2=A0 =C2=A0 = =C2=A0foreach(CBlockIndex* pindex, vDisconnect)
=C2=A0 =C2=A0 =C2=A0{
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0CBlock block;
- =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!block.ReadFromDisk(pindex))
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0if (!block.ReadFromDisk(pindex, !fClient))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0return error("Reorganize() : ReadFromDisk for disconnect failed&= quot;);
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0if (!block.DisconnectBlock(txdb, pindex))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0return error("Reorganize() : DisconnectBlock failed");<= /span>
@@ -1395,7 +140= 1,7 @@
=C2=A0 =C2=A0 =C2= =A0{

=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0CBlockIndex* pindex =3D vConnect[i];
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0CBlock blo= ck;
- =C2=A0 =C2=A0= =C2=A0 =C2=A0if (!block.ReadFromDisk(pindex))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!block.ReadFromDisk(p= index, !fClient))
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return error("Reorganize() : ReadFro= mDisk for connect failed");
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!block.ConnectBlock(txdb, pind= ex))
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0{
@@ -= 1526,7 +1532,7 @@

=C2=A0 =C2=A0 =C2=A0txdb.Close()= ;

- =C2=A0 =C2=A0= if (pindexNew =3D=3D pindexBest)
+ =C2=A0 =C2=A0if (!fClient && pindexNew =3D=3D pindexBest)<= /span>
=C2=A0 =C2=A0 = =C2=A0{
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0// Notify UI to display prev block's coinbase if it wa= s ours

=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0static uint256 hashPrevBestCoinBase;
@@ -1547,10 +1553,6 @@
=C2=A0 =C2=A0 = =C2=A0// These are checks that are independent of context
=C2=A0 =C2=A0 =C2=A0// that can be verifi= ed before saving an orphan block.

- =C2=A0 =C2=A0// Size limits
- =C2=A0 =C2=A0if (vtx.emp= ty() || vtx.size() > MAX_BLOCK_SIZE || ::GetSerializeSize(*this, SER_NET= WORK) > MAX_BLOCK_SIZE)
- =C2=A0 =C2=A0= =C2=A0 =C2=A0return error("CheckBlock() : size limits failed");<= /span>
-
=C2=A0 =C2=A0 = =C2=A0// Check proof of work matches claimed amount
=C2=A0 =C2=A0 =C2=A0if (!CheckProofOfWork(GetHash= (), nBits))
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0return error("CheckBlock() : proof of work failed&= quot;);
@@ -1559,6 +1561,1= 3 @@

=C2=A0 =C2=A0 = =C2=A0if (GetBlockTime() > GetAdjustedTime() + 2 * 60 * 60)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0retu= rn error("CheckBlock() : block timestamp too far in the future");=

+ =C2=A0 =C2=A0if (fClient &= & vtx.empty())
+ =C2= =A0 =C2=A0 =C2=A0 =C2=A0return true;
+
+ =C2=A0 =C2=A0// Size limits + =C2=A0 =C2=A0= if (vtx.empty() || vtx.size() > MAX_BLOCK_SIZE || ::GetSerializeSize(*th= is, SER_NETWORK) > MAX_BLOCK_SIZE)
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0return error("CheckBlock() : size limits failed");<= /span>
+
=C2=A0 =C2=A0 = =C2=A0// First transaction must be coinbase, the rest must not be=C2=A0 =C2=A0 =C2=A0if (vtx.empty()= || !vtx[0].IsCoinBase())
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0return error("CheckBlock() : first tx is not coinb= ase");
@@ -1623,13 +1= 632,14 @@
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0return error("AcceptBlock() : out of disk space&qu= ot;);
=C2=A0 =C2=A0 =C2=A0= unsigned int nFile =3D -1;

=C2=A0 =C2=A0 = =C2=A0unsigned int nBlockPos =3D 0;
- =C2=A0 =C2=A0if (!WriteToDisk(nFile, nBlockPos))
- =C2=A0 =C2=A0= =C2=A0 =C2=A0return error("AcceptBlock() : WriteToDisk failed");=
+ =C2=A0 =C2=A0if (!fClie= nt)
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0if (!WriteToDisk(nFile, nBlockPos))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return e= rror("AcceptBlock() : WriteToDisk failed");
=C2=A0 =C2=A0 = =C2=A0if (!AddToBlockIndex(nFile, nBlockPos))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return error("Ac= ceptBlock() : AddToBlockIndex failed");

=C2=A0 =C2=A0 =C2=A0// Relay inv= entory, but don't relay old inventory during initial block download
- =C2=A0 =C2=A0= if (hashBestChain =3D=3D hash)
+ =C2=A0 =C2=A0if (!fClient && hashBestChain =3D=3D hash)
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0CRITICAL_BLOCK(cs_vNodes)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0foreach= (CNode* pnode, vNodes)
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (nBestHeight > (pnode= ->nStartingHeight !=3D -1 ? pnode->nStartingHeight - 2000 : 55000))
@@ -2405,6 +241= 5,8 @@
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0{

=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (fShutdown)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0return true;
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0if (fClient && inv.type =3D=3D MSG_TX)<= /span>
+ =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0continue;
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0pfrom->AddInventoryKnown(inv);<= br style=3D"font-family:arial,sans-serif;font-size:13px">
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0bool fAlreadyHave =3D AlreadyHave(txdb, i= nv);
@@ -2441,6 +2453,9 @@=

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0if (inv.type =3D=3D MSG_BLOCK)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (fClient)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0return true;
+
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0// Send block from disk
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0map<uint256, CBlockIndex= *>::iterator mi =3D mapBlockIndex.find(inv.hash);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0if (mi !=3D mapBlockIndex.end())
@@ -2486,6 +250= 1,8 @@

=C2=A0 =C2=A0 =C2=A0else if (strComm= and =3D=3D "getblocks")
=C2=A0 =C2=A0 = =C2=A0{
+ =C2=A0 =C2=A0 = =C2=A0 =C2=A0if (fClient)

+ =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0return true;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0CBlockLocator locator;
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0uint256 hashStop;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0vRecv >> locator >&g= t; hashStop;
@@ -2556,6 +257= 3,8 @@

=C2=A0 =C2=A0 =C2=A0else if (strComm= and =3D=3D "tx")
=C2=A0 =C2=A0 = =C2=A0{
+ =C2=A0 =C2=A0 = =C2=A0 =C2=A0if (fClient)

+ =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0return true;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0vector<uint256> vWor= kQueue;
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0CDataStream vMsg(vRecv);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0CTransaction tx;
@@ -2620,6 +263= 9,33 @@
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0i= f (ProcessBlock(pfrom, &block))
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0mapAlreadyAskedFor.erase(inv);
+ =C2=A0 =C2=A0}
+
+
+ =C2=A0 =C2=A0= else if (strCommand =3D=3D "headers")
+ =C2=A0 =C2=A0{
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0if (!fClient)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return true;
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0vector<CBlock> vHeaders;
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0vRecv >> vHeaders;
+
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0uint256 ha= shBestBefore =3D hashBestChain;
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0foreach(CBlock& block, vHeaders)
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0{
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0block.vtx.clear();
+
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0printf("received header %s\n", block.= GetHash().ToString().substr(0,20).c_str());
+
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0CInv inv(MSG_BLOCK, block.GetHash());
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0pfrom->AddInventoryKnown(inv);
+
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0if (ProcessBlock(pfrom, &block))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0mapAlreadyAskedFor.erase(inv);
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0}
+ + =C2=A0 =C2=A0= =C2=A0 =C2=A0// Request next batch
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0if (hashBestChain !=3D hashBestBefor= e)
+ =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0pfrom->PushGetBlocks(pindexBest, uint256(0));=
=C2=A0 =C2=A0 = =C2=A0}


On T= ue, Jul 16, 2013 at 12:17 PM, Wendell <w@grabhive.com> wrote:
I for one would be interested in taking a lo= ok at that.

In San Jose I was asking around about the possibility of hiring someone to = complete such a patch. Pieter Wuille introduced me to Eric Lombrozo, who ex= pressed interest, but has since gotten quite busy. So we haven't arrive= d at a detailed estimate of what it would involve.

Maybe it would be better to start a completely new thread for this topic, b= ut I would very much be interested in an open dissection of what adding SPV= support to bitcoind would take. I am willing to fund or (ideally) co-fund = this endeavor, if I can ever get my head around it. I'm super intereste= d in all of these possibilities (including micro-stripped-VMs and transpila= tion), but would simply like to encourage the proliferation of _options_ wh= enever possible.

-wendell

grabhive.com | twitter.com/grabhive

On Jul 16, 2013, at 11:51 AM, Mike Hearn wrote:

> If you wanted to implement SPV mode in bitcoind, Gavin or I could send= you Satoshi's old patch although of course it is no longer usable. It = would indicate the basic cut lines though.


--047d7b678126a0d23304e19ee022--