P2Pool code documentation: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
'''Ignore this page for the minute.''' Is just a scratch pad for documenting the p2pool code. | '''Ignore this page for the minute.''' Is just a scratch pad for documenting the p2pool code. | ||
Feel free to add or correct errors if you are familiar with code. | |||
Will tidy up once initial pass done. | Will tidy up once initial pass done. | ||
Line 232: | Line 234: | ||
==p2pool/__init__.py== | ==p2pool/__init__.py== | ||
At bottom has DEBUG flag. Change to true to get more output. (running p2pool with --debug does this) | At bottom has DEBUG flag. Change to true to get more output. (running p2pool with --debug does this) | ||
Other than that just returns version number | Other than that just returns version number from git if it can. |
Revision as of 22:38, 22 June 2012
Ignore this page for the minute. Is just a scratch pad for documenting the p2pool code. Feel free to add or correct errors if you are familiar with code.
Will tidy up once initial pass done.
Files Name | Description |
---|---|
p2pool/main.py | Main Startup and initialisation code |
p2pool/data.py | P2Pool main data structures |
p2pool/util/pack.py | Handling of over the wire data structures |
p2pool/util/variable.py | Code to allow monitoring of when variables change and triggering events |
p2pool/main.py
Makes extensive use of twisted.defer. This allows it to "yield" to allow long running network code to complete. Read up on Python Generators and this before progressing!
Contains main startup code.
Function run()
This is the initially executed function.
- Parses arguments
- Reads user/password from bitcoin config file
- Sets up log file
- Sets up logger that reports errors to http://u.forre.st/p2pool_error.cgi (If you are concerned this is a privacy issue add --no-bugreport to command line.)
Finally it adds the main function to the Twister Reactor and start the reactor. (i.e. runs the function main!).
Function main()
This does all the startup tasks.
- Tests connection to bitcoind.
- Prints hash of latest block to show bitcoind is up to date.
- Tests connection to p2pool network.
- Gets address to use for payout either from file or bitcoind.
- Validates address and checks local bitcoind owns it.
- Create a "tracker" and loads know shares from files in data/bitcoin/sharesX where X is a number.
- poll_bitcoind then gets work from bitcoind (i.e. block header to hash). Does this by calling getwork function explained below.
- The work_poller() function then polls bitcoind every 15 seconds for new work.
- Check for work from peers. This is new code to try to reduce stales. It gets new block headers from peers if they arrive before they arrive from bitcoind.
- Set up merged work for merged mining.
- Sets up combined work.
- Sets up Longpoll to trigger when current_work changes (transitions).
- Creates Node class that handles connections to other p2pool nodes (see p2p.py also).
- Read p2pool node address from addrs file else use bootstrap addresses.
- Create node object and start it connecting/sending/receiving data.
- Setup loop to save shares to disk every 60 seconds.
- Create tunnel through routers using upnp if enabled.
- Start listening for workers using WorkerBridge Class (e.g. cgminers).
- Start IRC connection for announcing blocks.
- Start Status process that output to screen data every 3 seconds.
p2pool/data.py
Contains the main data structures used in p2pool. These are:
hash_link_type
Serialized SHA256 engine state, used to prove that a coinbase transaction contains some data near the end without sending the entire transaction.
Field | Type | Description |
---|---|---|
state | String(32) | ? |
extra_data | String(0) | Comments say this is a hack |
length | VarInt | ? |
small_block_header
Bitcoin block header, excluding the merkle root. Included in shares, where the merkle root is computed implicitly from the coinbase transaction and the merkle branch.
Field | Type | Description |
---|---|---|
version | VarInt | ? |
previous_block | None or Int(256) | ? |
timestamp | Int(32) | ? |
bits | FloatingInteger(32) | ? |
nonce | Int(32) | ? |
Information contained within a share that is only relevant to P2Pool and that the client has control over (i.e. its value isn't fixed by the protocol rules).
Field | Type | Description |
---|---|---|
previous_share_hash | None or int(256) | ? |
coinbase | VarString | ? |
nonce | Int(32) | ? |
pubkey_hash | Int(160) | ? |
subsidy | Int(64) | ? |
donation | Int(16) | ? |
stale_info | String(32) | Enum (orpan, dao, unk253, unk252...??? |
desired_version | VarInt | ? |
Information contained within a share that is only relevant to P2Pool
Field | Type | Description |
---|---|---|
share_data | share_data_type (see above) | ? |
far_share_hash | none or int(256) | ? |
max_bits | Float Int | ? |
bits | Float Int | ? |
timestamp | Int(32) | ? |
x
Field | Type | Description |
---|---|---|
name | String(32) | ? |
x
Field | Type | Description |
---|---|---|
name | String(32) | ? |
x
Field | Type | Description |
---|---|---|
name | String(32) | ? |
p2pool/util/pack.py
I think this handles all the binary data types used in the bitcoin protocol to send data over the network wire. These are nasty as very low level and many big endian/little endian complications. The p2pool network protocol uses these also. Do not think you need to really understand this unless making changes at this low level.
p2pool/__init__.py
At bottom has DEBUG flag. Change to true to get more output. (running p2pool with --debug does this) Other than that just returns version number from git if it can.