kale-miner
is a CPU/GPU miner written in C++ for KALE on the Stellar blockchain. It supports CPU parallel processing, and GPU acceleration with CUDA or OpenCL.
Learn more about KALE:
Tested with Intel Core i9-14900K @ 3.20 GHz processor (24 cores), the miner achieved an average hash rate of 35 MH/s.
With GPU acceleration enabled on an NVIDIA GeForce RTX 4080 GPU, the miner achieved an average hash rate of 1.9 GH/s (CUDA).
GPU | Framework | Avg. Hash Rate |
---|---|---|
NVIDIA GeForce RTX 4080 | CUDA | ~1.9 GH/s |
NVIDIA GeForce RTX 4080 | OPENCL | ~1.3 GH/s |
You may want to explore more keccak implementations here keccak.team/software for potential performance improvements (note that the standalone XKCP implementation was much slower in my environment).
- C++17 or higher
- C++ Standard Library (no additional dependencies required)
- NVIDIA CUDA-Capable GPU with compute capability 3.0 or higher
- NVIDIA CUDA Toolkit
- OpenCL 3.0 or higher
- OpenCL SDK
- for NVIDIA: NVIDIA CUDA Toolkit (includes OpenCL)
- for AMD: AMD SDK (supports OpenCL)
- for Intel: Intel SDK for OpenCL
To compile the miner without GPU support, simply run:
make clean
make
To compile the miner with GPU support, run:
CUDA:
make clean
make GPU=CUDA
or OpenCL:
make clean
make GPU=OPENCL
Note: The current OpenCL implementation uses the cl_khr_int64_base_atomics
extension for atomic operations on 64-bit integers. Make sure your device supports it.
./miner <block> <hash> <nonce> <difficulty> <miner_address> [--verbose] [--max-threads <num> (default 4)] [--batch-size <size> (default 10000000)]
Parameter | Description | Default Value |
---|---|---|
<block> |
The block number. | (Required) |
<hash> |
Previous hash value (base64 encoded). | (Required) |
<nonce> |
Starting nonce value. | (Required) |
<difficulty> |
The mining difficulty level. | (Required) |
<miner_address> |
G address for reward distribution. Must have KALE trustline. |
(Required) |
[--verbose] |
Verbose mode incl. hash rate monitoring | Disabled |
[--max-threads <num>] |
Specifies the maximum number of threads (CPU) or threads per block (GPU). | 4 |
[--batch-size <size>] |
Number of hash attempts per batch. | 10000000 |
[--gpu] |
Enable GPU mining | Disabled |
[--device] |
Specify the device id | 0 |
Example:
./miner 37 AAAAAAn66y/43JP7M02rwTmONZoWOmu1OPYz/bmzJ8o= 20495217909 8 GBQHTQ7NTSKHVTSVM6EHUO3TU4P4BK2TAAII25V2TT2Q6OWXUJWEKALE --max-threads 4 --batch-size 10000000 --verbose
Should output:
{
"hash": "0000000099be0037e5a48324959cb9dd10965ae59511cfd1996f9b917aad9980",
"nonce": 20495217910
}
⚠️ IMPORTANT: When using--gpu
, the--max-threads
parameter specifies the number of threads per block (e.g. 512, 768), and --batch-size should be adjusted based on your GPU capabilities.
The homestead
folder contains a Node.js application designed to simplify the KALE farming cycle with the C++ CPU/GPU miner. It automates monitoring
new blocks, planting
, working
, and harvesting
, and can manage multiple farmer accounts to help you maximize your CPU/GPU utilization.
Open homestead/config.json
to configure your server settings.
💡PRO TIP: Add as many farmers as you like! Their tasks will run one after the other, and you can tweak individual difficulty to maximize CPU/GPU occupancy during the 5-minute block window.
💡PRO TIP: Keep only a minimal amount of XLM in your farmer accounts. These projects are experimental, network updates (e.g., reduced block time) could quickly drain your balances
{
// You can add as many farmers as you want in this array. Each farmer's work will be scheduled sequentially.
// Adjust individual difficulty and stake settings directly, or use strategy.js to implement a dynamic strategy.
"farmers": [
{
// Secret key for the farmer account.
// The harvesting process will automatically add a KALE trustline if not set.
"secret": "SECRET...KEY",
// Specify the stake, starting with 0 for new accounts.
"stake": 0,
// Optional. Adjust based on your CPU/GPU power.
"difficulty": 6,
// Optional: Defines the minimum time (in seconds) before work is submitted
// to the contract (default is 0 for immediate submission).
"minWorkTime": 0
}
],
// Tune these settings according to your system’s performance.
"miner": {
"executable": "../miner",
// Default difficulty for all farmers, unless overridden.
"difficulty": 6,
// Initial nonce.
"nonce": 0,
// Enable GPU mining (NVIDIA CUDA).
"gpu": false,
// For CPU mining, `max_threads` should be set within the range of your available CPU cores.
// For GPU mining, `max_threads` refers to the number of threads per block.
"maxThreads": 4,
// Number of hashes processed in a single batch.
"batchSize": 10000000,
// For GPU mining, specify the device ID (default 0).
"device": 0,
// Enable real-time miner output.
"verbose": true
},
"stellar": {
// Stellar RPC URL, or use the environment variable RPC_URL.
"rpc": "your-stellar-rpc-url",
// KALE contract ID.
"contract": "CDL74RF5BLYR2YBLCCI7F5FB6TPSCLKEJUBSD2RSVWZ4YHF3VMFAIGWA",
// KALE asset issuer.
"assetIssuer": "GBDVX4VELCDSQ54KQJYTNHXAHFLBCA77ZY2USQBM4CSHTTV7DME7KALE",
// KALE asset code.
"assetCode": "KALE"
// Optional. Fee settings for transactions (default 10000000).
"fees": 10000000,
// Optional. Output transaction response (default false).
"debug": false,
// Optional. If both a valid token and URL are provided,
// Launchtube credits will be used to submit contract invocation transactions.
"launchtube": {
"url": "https://launchtube.xyz",
"token": "eyJ0eX...uQQa5WlP08"
}
}
}
Then run the following commands to start the server:
cd homestead
npm install
PORT=3001 RPC_URL="https://your-rpc-url" npm start
Farming KALE most efficiently requires dynamically adjusting your farmers parameters. The strategy.js
module enables you to define the stake
, difficulty
, and minWorkTime
for each farmer based on real-time conditions.
Below is an example of a dynamic strategy that implements the following:
plant
stakes 10% of the farmer KALE balance (up to a maximum of 10 KALE).- Sets difficulty to the previous block difficulty + 1 (capped at 9 for safety).
- Ensures a minimum
work
time of 3 minutes before submission.
const config = require(process.env.CONFIG || './config.json');
const { horizon } = require('./contract');
module.exports = {
stake: async(publicKey, _blockData) => {
const asset = (await horizon.loadAccount(publicKey)).balances.find(
balance => balance.asset_code === config.stellar.assetCode && balance.asset_issuer === config.stellar.assetIssuer);
return Math.min(Math.floor(Number(asset?.balance || 0) * 1000000), 100000000);
},
difficulty: async(_publicKey, blockData) => {
return Math.min(Buffer.from(blockData.hash, 'base64').reduce(
(zeros, byte) => zeros + (byte === 0 ? 2 : (byte >> 4) === 0 ? 1 : 0), 0) + 1, 9);
},
minWorkTime: async(_publicKey, _blockData) => {
return 180;
}
};
The Homestead server provides several API endpoints to allow manual interactions with the KALE farming process, including /plant
, /work
, /harvest
, /data
, /balances
and /shader
(serving the WebGPU compute shader). Feel free to use these endpoints to experiment with individual steps in the farming cycle.
Open homestead/routes.js
for more details.
This software is experimental and provided "as-is," without warranties or guarantees of any kind. Use it at your own risk. Please ensure you understand the risks mining on Stellar mainnet before deploying this software.