Overview
Theinit command creates a new blockchain by setting up the database schema, generating cryptographic keys, and creating the genesis block. This is the first command you run when starting a new Ubu-Block instance.
Syntax
Parameters
Path to the SQL file containing initialization queries for setting up constituencies, wards, counties, and other regional data. This SQL will be executed to populate the initial database schema.
What It Does
When you run theinit command, Ubu-Block performs the following operations:
- Database Setup: Creates the main blockchain database and private database with necessary tables
- Key Generation: Generates a cryptographic key pair (private and public keys) for signing blocks
- Key Storage: Stores the public key in the main database and private key in the private database
- Schema Initialization: Executes the provided SQL file to set up regional data structures
- Genesis Block: Creates and adds the genesis block (block 0) to the blockchain
- Validation: Validates the newly created blockchain to ensure integrity
Prerequisites
Before runninginit, ensure:
-
Database files are created:
-
Configuration file exists with database paths:
- Initialization SQL file is prepared with regional data setup
Example
Initialization SQL File
The--source SQL file should contain queries to set up your regional data structure. For Kenyan elections, this typically includes:
- Counties table
- Constituencies table
- Wards table
- Polling stations table
- Candidates table
- Parties table
Genesis Block
The genesis block is special:- Height: 0
- Previous Hash: None (it’s the first block)
- Content: Hash of the initialization SQL file
- Signature: Signed by the generated key pair
- Purpose: Establishes the blockchain foundation and configuration
Key Management
Theinit command automatically generates:
- Private Key: Stored in the private database, used for signing blocks
- Public Key: Stored in the main blockchain, used for verification
- Key Hash: SHA-256 hash of the public key for identification
Post-Initialization
After successful initialization:-
Verify the blockchain:
-
Query to confirm setup:
- Backup your private database
Troubleshooting
Database Already Exists
If you runinit on an existing blockchain, you may encounter errors. To reinitialize:
SQL File Errors
If the initialization SQL fails:- Check SQL syntax
- Ensure table names match expected schema
- Verify foreign key relationships
- Test SQL file separately with SQLite
Key Generation Issues
If key generation fails:- Ensure private database is writable
- Check sufficient entropy is available on your system
- Verify database permissions
Implementation Details
The init command is implemented inapps/cli/src/init.rs:13 and:
- Uses Ed25519 signatures for cryptographic operations
- Stores keys in bincode-serialized format
- Creates SHA-256 hashes for content verification
- Implements Byzantine Fault Tolerant consensus preparation
Next Steps
Submit Results
Learn how to submit polling station results
Validate Blockchain
Verify your blockchain integrity
Query Data
Start querying your blockchain data
Configuration
Learn more about configuration options