Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: jgarzik on July 22, 2012, 05:23:00 PM



Title: [ANN] pynode: Simple bitcoin P2P node
Post by: jgarzik on July 22, 2012, 05:23:00 PM
Github URL: https://github.com/jgarzik/pynode

pynode is a simple bitcoin P2P client, originally based on ArtForz' half-a-node, which maintains a blockchain database and TX memory pool.  All bitcoin-related code is separated into a "bitcoin" module, permitting you to use core features such as CBlock or P2P message serialization, without actually using the node itself.

Therefore, pynode has two goals:

1. As a generic "python-bitcoin" library, for any project.  Update: Now a separate project, https://github.com/jgarzik/python-bitcoinlib (https://github.com/jgarzik/python-bitcoinlib)
2. As a P2P node that may be used as a base for other projects, such as a network monitoring node or P2P proxy.

At present, it is mainly for developers and not end users.  Here is what pynode does not do:
  • key management (wallet)

Here are the limited things that pynode can do at present:
  • Outgoing TCP connection to a single remote P2P node
  • Initial blockchain download
  • Maintain a transaction memory pool, with TX's removed as they are confirmed in blocks
  • Maintain an indexed blockchain database
  • Respond to JSON-RPC requests via an internal HTTP server

Over time it will become more capable, but this is an alpha quality release for developers at present.



Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: jgarzik on July 22, 2012, 05:25:14 PM
Reserved.


Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: jgarzik on August 03, 2012, 09:07:14 PM
pynode now successfully verifies all transaction scripts on mainnet.  testnet3 verification still a WIP.


Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: maaku on August 05, 2012, 06:48:59 AM
Great work @jgarzik, this is critically important stuff. Even if nobody seems to notice ;)


Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: gweedo on August 05, 2012, 06:55:48 AM
Great work @jgarzik, this is critically important stuff. Even if nobody seems to notice ;)

I noticed it! I am waiting for it to get a little more stable, cause this would make a perfect proxy, have a bitcoind, turn off the RPC and use this so even if the rpc name, and password are figured out, they can't steal any coins.


Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: weex on August 05, 2012, 07:41:55 AM
Definitely interested in this and running it now. Is it normal to see a bunch of blocks labeled as orphan at the first startup?

 Also the example lists /tmp/chaindb for the database location. Perhaps that should be .pynode/ if it will be helpful later to keep the database?


Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: jgarzik on August 05, 2012, 03:58:23 PM
Updated status:

pynode now verifies all known scripts on mainnet and testnet3, except for the OP_IF opcodes.  OP_IF is not present on mainnet right now, so this should not be a problem for testing.

pynode now includes a JSON-RPC server like bitcoind.  Only a few RPC API methods are implemented right now.  Check back in a few days, to see more RPC API calls implemented, such as parts of the raw transaction API.

pynode is not officially stable yet, as script verification is disabled (run testscript.py instead) and chain reorg is not implemented yet.

Definitely interested in this and running it now. Is it normal to see a bunch of blocks labeled as orphan at the first startup?

Possibly yes.  Chain reorganization is not yet implemented.  Small 1-2 block forks happen on mainnet every few days.  If the chain forks, pynode will not understand this, and get stuck.  Known problem, will be fixed.

The workaround is to delete your chain database, and re-download it.  If you know python, you could save download time by writing a simple script that deleted the last 100 blocks.

You may ignore orphans, as long as you see new network blocks being stored in the database, with 'height' increasing.

Quote
Also the example lists /tmp/chaindb for the database location. Perhaps that should be .pynode/ if it will be helpful later to keep the database?

I trust people can figure this one out on their own :)  They will need avoid using RPC username "XXXX" and password "YYYY" also :)


Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: jgarzik on August 05, 2012, 04:27:53 PM
Updated OP to indicate the "python-bitcoin" nature of the project.  Programmers may use some or all of pynode's library, without using the node itself.


Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: jgarzik on August 06, 2012, 11:02:45 PM
pynode's script engine now successfully verifies all scripts in the mainnet and testnet3 chains.


Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: Ferroh on August 08, 2012, 06:56:01 AM
This is awesome!

Looking forward to seeing chain reorg support.


Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: jgarzik on August 18, 2012, 04:20:50 AM
Because pynode startup may take a while, here is a set of pre-indexed database files you may download:

     http://gtf.org/garzik/bitcoin/chaindb.tar.bz2  (2.3 gigabytes)
     SHA1 a8e093ce7eedb3434a3a97570be8c3b855fa7529

This was generated by pynode git HEAD (commit b93b91b1bb659b0477eeff8b0a6771bdb595f0f4).

If you wish to treat this as untrusted data, you may verify hashes and TX connectivity with the dbck.py script.  Runtime should be under 1 hour in most cases.

If you wish to verify scripts, this will take much longer, possibly 10-12 hours.  testscript.py will verify scripts in the database.





Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: jgarzik on August 20, 2012, 01:23:44 AM

Just pushed chain reorg code to github.  It seems to survive a static test... let's see how it fares on the live network.



Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: jgarzik on August 23, 2012, 02:20:09 PM
Script verification is now enabled by default.

Unfortunately it is quite slow, for an unexpected reason: Python is very slow copying data structures.  Therefore, I strongly urge users to download the chaindb.tar.bz2 archive mentioned earlier in the thread.  Otherwise the block download could take a day or two.

Plans to mitigate this include:
  • Do not verify scripts earlier than a checkpoint (reference client does this)
  • Store database of only unspent CTxOut (sipa's reference client ultraprune branch does this)
  • Swap out slow GDBM database for new pagedb database (https://github.com/jgarzik/pagedb)



Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: jgarzik on August 23, 2012, 04:04:51 PM
In addition to the fully validating node and python-bitcoin module, pynode also maintains a branch that contains a non-validating node calling a "mini-node", naturally found in the "mini-node" branch of pynode.git:

      https://github.com/jgarzik/pynode/tree/mini-node (https://github.com/jgarzik/pynode/tree/mini-node)

This is essentially ArtForz' half-a-node, with the minimum needed to work on mainnet.

Forks have already started appearing.  blkmond inside pushpoold (https://github.com/jgarzik/pushpool) existed for a long time.  And bitcoin network sniffer (https://bitcointalk.org/index.php?topic=102740.0) fork also just appeared.



Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: sebicas on August 23, 2012, 04:16:05 PM
In addition to the fully validating node and python-bitcoin module, pynode also maintains a branch that contains a non-validating node calling a "mini-node", naturally found in the "mini-node" branch of pynode.git:

      https://github.com/jgarzik/pynode/tree/mini-node (https://github.com/jgarzik/pynode/tree/mini-node)

This is essentially ArtForz' half-a-node, with the minimum needed to work on mainnet.

Forks have already started appearing.  blkmond inside pushpoold (https://github.com/jgarzik/pushpool) existed for a long time.  And bitcoin network sniffer (https://bitcointalk.org/index.php?topic=102740.0) fork also just appeared.



Thanks jgarzik for pointing this out, I haven't seen this before, so I went and create my own... :(


Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: jgarzik on September 23, 2012, 05:14:35 AM

Thanks to socrates1024, pynode got a much needed upgrade from python's asyncore to the more modern gevent. 

This opens the door to easy multi-peer operation, so expect full node status very soon.



Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: marcus_of_augustus on September 23, 2012, 07:24:23 AM
Not sure how this one slipped under my radar ...

Wondering if an Electrum client might be able to modified to talk to a pynode ... or vice versa?


Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: FactoredPrimes on September 23, 2012, 02:38:20 PM
Very nice tool. Am I correct that this could be the basis of a tool to monitor large numbers of addresses for activity?


Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: Severian on September 23, 2012, 02:43:10 PM
preserved


Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: jgarzik on September 23, 2012, 04:27:42 PM
Wondering if an Electrum client might be able to modified to talk to a pynode ... or vice versa?

What does Electrum use to talk to bitcoind?   pynode provides a JSON-RPC HTTP server interface, just like bitcoind...



Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: jgarzik on September 23, 2012, 04:28:25 PM
Very nice tool. Am I correct that this could be the basis of a tool to monitor large numbers of addresses for activity?

Sure.  It could monitor whatever metrics you need, on the bitcoin network.



Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: marcus_of_augustus on September 24, 2012, 12:01:10 AM
Wondering if an Electrum client might be able to modified to talk to a pynode ... or vice versa?

What does Electrum use to talk to bitcoind?   pynode provides a JSON-RPC HTTP server interface, just like bitcoind...



It uses the Stratum protocol ... but I don't have detailed knowledge of that, yet.


Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: wabber on September 24, 2012, 09:45:35 PM
Wondering if an Electrum client might be able to modified to talk to a pynode ... or vice versa?

What does Electrum use to talk to bitcoind?   pynode provides a JSON-RPC HTTP server interface, just like bitcoind...



It uses the Stratum protocol ... but I don't have detailed knowledge of that, yet.

there are 2 electrum applications: the electrum client and the electrum server. The electrum server talks to bitcoind using the JSON-RPC interface but stores it's own blockchain. The electrum client talks to the electrum server using the stratum protocol.


Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: jgarzik on October 01, 2012, 06:19:06 AM
Thanks (again) to socrates1024, pynode has switched to using the leveldb (http://code.google.com/p/leveldb/) database, plus a flat file format for raw blockchain data.

This database upgrade is wholly incompatible with the previous GDBM-based database.

When signature checking is disabled, the entire blockchain may be downloaded in 34 minutes.

When signature checking is enabled, the blockchain download process takes many hours (6-12), due to slowness of python.



Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: jgarzik on October 06, 2012, 02:48:06 AM

The on-disk block file format was just updated to match the network's "block" message format.

This is an incompatible change.  You will need to delete, and re-download, your block databases.



Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: jgarzik on March 07, 2013, 09:37:26 PM
pynode is very much alive and well.  It is becoming popular enough that we can branch off the internal "bitcoin" sub-directory into a proper python library, python-bitcoinlib.

Stay tuned for details.



Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: jgarzik on March 08, 2013, 03:04:42 AM
Library forked, and moved to a new home and forum thread (https://bitcointalk.org/index.php?topic=150436.0):

     https://github.com/jgarzik/python-bitcoinlib (https://github.com/jgarzik/python-bitcoinlib)

Pull requests and donations welcome, as always.



Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: tehace on March 21, 2013, 06:51:55 PM
Hello I am a bit new to programming but I would love to experiment around with pynode and python-bitcoinlib are there any guides or source code examples available or would I need to figure that stuff out myself? (I promise not to store anyone's life savings using it until I know the node and libs inside and out inside and out)


Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: jgarzik on March 21, 2013, 06:56:15 PM
Hello I am a bit new to programming but I would love to experiment around with pynode and python-bitcoinlib are there any guides or source code examples available or would I need to figure that stuff out myself? (I promise not to store anyone's life savings using it until I know the node and libs inside and out inside and out)

pynode and assorted utilities dbck.py and mkbootstrap.py are essentially source code examples for python-bitcoinlib.  Unfortunately that's it.

Contributed examples are welcome in both projects, however.



Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: tehace on March 21, 2013, 06:59:30 PM
Thanks for the quick reply. As soon as I figure stuff out I shall contribute anything useful I do back.


Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: jgarzik on August 21, 2013, 12:52:50 PM
This received several bug fixes, by way of its use of python-bitcoinlib.


Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: jgarzik on September 03, 2013, 05:29:23 PM
Merged "addnodes" support, so that additional nodes may be added via configuration file.


Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: weex on September 03, 2013, 10:39:21 PM
Nice. This is a fun project to play around with.


Title: Re: [ANN] pynode: Simple bitcoin P2P node
Post by: phelix on April 22, 2015, 12:27:14 PM
Is pynode still being updated? Or is there a follow up?