-
Notifications
You must be signed in to change notification settings - Fork 2
Codebase and Testing
Warning - a bit dated.
The reference client can launch any one of the following servers: full node, timelord, farmer, harvester, or introducer.
The ChinillaServer
class can be used to start a listening server, or to connect to other clients.
Once running, each connection goes through an asynchronous pipeline in server.py
, where connections are mapped to messages, which are handled by the correct function, and mapped to outbound messages.
When a protocol message arrives, its function string is read, and the appropriate python function gets called. The api_request parses the function data into a python object (from CBOR/streamable format). All api functions are asynchronous generators, which means they can yield any number of responses in an asynchronous manner.
For example, a block message may trigger a block message to other peers, as well as messages to a timelord or farmer.
API functions yield OutboundMessages, which can be converted into Messages based on delivery.
class Message:
# Function to call
function: str
# Message data for that function call
data: Any
class OutboundMessage:
# Type of the peer, 'farmer', 'harvester', 'full_node', etc.
peer_type: NodeType
# Message to send
message: Message
delivery_method: Delivery
Delivery types include broadcast, response, broadcast_to_others, etc. Therefore, an api function can yield one outbound message with a broadcast type, which gets mapped into one message for each peer.
A PeerConnections
object is maintained by the server, which contains all active connections, as well as a Peers object for peers that we know of.
Periodically, the full node connects to an introducer to ask for peers, which the full node can connect to, if it does not have enough.
Furthermore, an on_connect function can be passed to start_server or start_client, which can trigger events on connection.
Full sync is the process by which a node catches up to a tip of the blockchain that is many blocks in the future. This may happen due to an accidental reorganization, a node going offline, or simply a node starting up for the first time.
The full sync process has a few steps:
- The node waits for block messages from peers, to determine the heaviest (most weight) tip it can find
- The node requests all headers up to the best tip, and finds where it diverged from its saved tips
- The node requests headers, a few at a time, from random nodes, from the fork point to the best tip
- The node requests blocks, a few at a time, from random nodes, from the fork point to the tip
- The node validates blocks as they come, and adds them to the blockchain
Full sync will take a long time for nodes just joining the system, especially since all blocks must be fully validated (including the proofs of time).
When the sync is done, our node may be behind, and therefore start another sync.
If the node is only a few blocks behind, a series of RequestBlock
messages will be send instead, to just download the missing blocks.
The reference implementation currently uses an sqlite3 database for persistence and this may change. Both the full node and the wallet have databases. The wallet database is used to store full blocks that have been validated, and blocks that are downloaded during sync. The sync blocks table is cleared after sync is done. The wallet database is used to similarly store blocks, but only stores the coins that are relevant to that wallet. Furthermore, the wallet stores puzzle hashes, transaction records, and user wallet information in the database.
The rest of the state is kept in memory by the different servers. On launch of the full node, blockchain.py is loaded with the current block database.
The Blockchain class represents the current state of where we think the blockchain is. It maintains a list of three tips, which are the connected blocks with the highest weight, along with a height_to_hash map, to easily look up blocks using the height, a reference to the database to fetch blocks, and a map of all current headers.
Blocks only get added to the persistent database after they have been fully verified as connected blocks. The wallet node similarly has the WalletStateManager, which maintains a list of header blocks, and interfaces with the user wallet.
Chinilla Network - Green money for a digital world.
- Home
- Beginners Guide
- Install instructions
- Quick Start Guide
- FAQ - Frequently Asked Questions
- Pooling FAQ
- Pooling User Guide
- Chinilla Project FAQ
- Plotting Basics
- Alternate Plotters
- Plot Sizes (k-sizes)
- CLI Commands Reference
- Windows Tips & Tricks
- How to Check if Everything is Working (or Not)
- SSD Endurance - Info on SSD's and plotting
- Reference Plotting Hardware
- Reference Farming Hardware
- Farming on Many Machines
- Good Security Practices on Many Machines
- Chinillalisp Documentation (Official)
- Chinillalisp Notes
- Timelords and Cluster Timelords
- Release Notes
- RPC Interfaces
- Resolve Sync Issues - Port 8444