This repo is responsible for the PPLNS rewards mechanism for the Quarry mining pool. It works in unison with the Stratum SV2 pool and issues ERC721 tokens as shares. The final reward is in the form of SBTC on Botanix which is valued 1:1 with BTC.
Install Rust / Cargo: https://doc.rust-lang.org/book/ch01-01-installation.html (Link is also to the official rust docs)
Install Foundry / Forge: https://book.getfoundry.sh/
Installing Contract Dependencies:
cd contracts
forge install foundry-rs/forge-std --no-git
forge install OpenZeppelin/openzeppelin-foundry-upgrades --no-git
forge install OpenZeppelin/openzeppelin-contracts-upgradeable --no-git
forge install https://github.com/OpenZeppelin/openzeppelin-contracts --no-git
forge install https://github.com/bob-collective/bitcoin-spv --no-git
forge remappings > remappings.txtforge build
If you get a lot of errors saying something along the lines of
Error (6243): The "tload" instruction is only available for Cancun-compatible VMs (you are currently compiling for "paris").
then try setting the "--evm-version cancun" flag.
forge test
(Optional) If no pip3 / python env set up it may be easier to use a virtual env. From within quarry/contracts,
-
python3 -m venv env -
source env/bin/activate -
Install any deps you need to use run.py with pip3 (e.g.
pip3 install click)
Here you have 2 options:
- Download a release from Sjors' fork of Bitcoin Core from https://github.com/Sjors/bitcoin/releases. Run bitcoind:
./src/bitcoind -sv2 -sv2port=8442 -sv2interval=20 -sv2feedelta=1000 -debug=sv2 -loglevel=sv2:trace. Yourbitcoin.confshould look like:
testnet=1
server=1
rpcuser=username
rpcpassword=password
You will have to wait until testnet is finished syncing before proceeding, which may take 1-3 hours depending on internet speed. When it's up to date you should see logs stating progress = 1.0:
2024-05-14T03:44:25Z UpdateTip: new best=000000000de5a001e600ed2361b186f40d9819902f37a1dcbba653ebf2eb73c3 height=2815185 version=0x20000000 log2_work=75.779092 tx=134214885 date='2024-05-14T05:43:51Z' progress=1.000000 cache=4.7MiB(27653txo)
-
Generate bindings from smart contract:
python3 run.py -gb. -
Copy over bindings to stratum repo:
python3 run.py -cb. Note that quarry and stratum repos should be in the same root dir. -
Run
python3 run.py --allfrom quarry/contracts. This should handle compiling and deploying the contracts, copying over bindings and other configs, and running the oracle and all stratum roles.
Note: The deploy_contracts.rs script uses deployment.local to get constants and addresses to initialize the contracts with. Feel free to update settings accordingly -- an example file would look like:
{
"deployer_pkey": "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
"oracle_pkey": "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d",
"qsat": "0xa513e6e4b8f2a923d98304ec87f64353c4d5c853",
"pool": "0x2279b7a0a67db372996a5fab50d91eaa73d2ebe6",
"share": "0x8a791620dd6260079bf849dc5567adc3f2fdc318",
"peg_in_address": "0x210372c47307e5b75ce365daf835f226d246c5a7a92fe24395018d5552123354",
"ring_buffer_size": 10000,
"bond_amount": 1,
"share_difficulty_ratio": 1000000,
"eth_rpc_url": "http://localhost:8545",
"btc_rpc_url": "https://billowing-fittest-feather.btc-testnet.quiknode.pro/4613ae0ad4238d1261f99cc2cd8baa48f6b96d83/"
}
- Download CPUMiner from https://sourceforge.net/projects/cpuminer/files/. In CPUMiner dir run
./minerd -a sha256d -o stratum+tcp://localhost:34255 -q -D -P. You should see successful share submissions:
Hash: 0000000431fd1477e3e271fae14c42158f771f710f32885edf42f531964cba32
Target: 00000004fffb0000000000000000000000000000000000000000000000000000
[2024-05-13 21:40:42] > {"method": "mining.submit", "params": ["", "12", "0000000000000000", "6642cedf", "98816fa5"], "id":4}
[2024-05-13 21:40:42] < {"id":4,"error":null,"result":true}
[2024-05-13 21:40:42] accepted: 28/28 (100.00%), 60372 khash/s (yay!!!)
[2024-05-13 21:40:47] < {"method":"mining.notify","params":["16","c993c9b9e95d85b8470a701038075456b89bdf3553eb2bb3b02faf7d00000000","02000000010000000000000000000000000000000000000000000000000000000000000000ffffffff3803cef42a005374726174756d2076322053524920506f6f6c","ffffffff02d71a050300000000160014ebe1b7dcc293ccaa0ee743a86f89df8258c208fc0000000000000000266a24aa21a9ede4bfe2c266f17fa3d3863fccf38e9d908e39b84e73fb6fb755c945c59ba5723800000000",["ddd6375856de644eeaa8ca9a76cfc787925b448c76800472c7e91dc582efb19e","60b10d35520093c8c80b9eedd9717978246f9469b6577715d34846c754f351c7","df56a8c826e01a77a48b07c0195843b97c534e28eef27d2a294d0d959b036812","e5336a5346a7c841f8202c120396e71f6133b191782c6cbaae16bae68c89434c","153a9e400e67c6138ea745b06df97daf61a33da38dbcadcd5e5a482b82bb204c","10ae3c49f6a9ed43f02aeaabb58cd4b55a1b756d874a2bb3193a89bdae852d04","0860fcb21bb8b4daf0a32b65a2bb1f29a233724e9a00c789561018be89597aeb","230b07dde955c3d0dad72b8c991f494115400d96ffe06f101760dce742d80cdc","0c80451a7f31e469862a5d644359be7530fce8698f31460d5a44d2bcdf91d4b4","2c60a19b68d31aa4517577ccf66fe76f752bcc52760b23846d179288348aebdd","a2e6c498a4351fd971b04921c9daba6af15dbf6ff6cf9178006f4727398473f0","8de88aa09c8d7192858f8b83f6cba083518b310653ee180cda2f3421d90347c4"],"20000000","191881b8","6642cf2f",false]}
[2024-05-13 21:40:47] DEBUG: job_id='16' extranonce2=0000000000000000 ntime=6642cf2f
[2024-05-13 21:41:08] < {"method":"mining.set_difficulty","params":[0.5]}
[2024-05-13 21:41:08] Stratum difficulty set to 0.5
- Download a release from Sjors' fork of Bitcoin Core from https://github.com/Sjors/bitcoin/releases. Run bitcoind:
./src/bitcoind -sv2 -sv2port=8442 -sv2interval=20 -sv2feedelta=1000 -debug=sv2 -loglevel=sv2:trace. Yourbitcoin.confshould look like:
testnet=1
server=1
rpcuser=username
rpcpassword=password
You will have to wait until testnet is finished syncing before proceeding, which may take 1-3 hours depending on internet speed. When it's up to date you should see logs stating progress = 1.0:
2024-05-14T03:44:25Z UpdateTip: new best=000000000de5a001e600ed2361b186f40d9819902f37a1dcbba653ebf2eb73c3 height=2815185 version=0x20000000 log2_work=75.779092 tx=134214885 date='2024-05-14T05:43:51Z' progress=1.000000 cache=4.7MiB(27653txo)
From within quarry/contracts:
-
Copy over bindings to stratum repo:
python3 run.py -cb. Note that quarry and stratum repos should be in the same root dir. -
Compile and deploy the contracts:
python3 run.py -c -
Run oracle (
python3 run.py -o) then stratum roles separately.
From within stratum (more detailed instructions as well as logs to expect at https://stratumprotocol.org/getting-started/#ii-getting-started---running-all-roles but also provided here),
-
Terminal 1:
cd roles/pool/config-examples,cargo run -- -c pool-config-local-tp-example.toml -
Terminal 2:
cd roles/jd-server/config-examples,cargo run -- -c jds-config-local-example.toml -
Terminal 3:
cd roles/jd-client/config-examples,cargo run -- -c jdc-config-local-example.toml -
Terminal 4:
cd roles/translator/config-examples,cargo run -- -c tproxy-config-local-jdc-example.toml -
Terminal 5: Download CPUMiner from https://sourceforge.net/projects/cpuminer/files/. In CPUMiner dir run
./minerd -a sha256d -o stratum+tcp://localhost:34255 -q -D -P. You should see successful share submissions:
Hash: 0000000431fd1477e3e271fae14c42158f771f710f32885edf42f531964cba32
Target: 00000004fffb0000000000000000000000000000000000000000000000000000
[2024-05-13 21:40:42] > {"method": "mining.submit", "params": ["", "12", "0000000000000000", "6642cedf", "98816fa5"], "id":4}
[2024-05-13 21:40:42] < {"id":4,"error":null,"result":true}
[2024-05-13 21:40:42] accepted: 28/28 (100.00%), 60372 khash/s (yay!!!)
[2024-05-13 21:40:47] < {"method":"mining.notify","params":["16","c993c9b9e95d85b8470a701038075456b89bdf3553eb2bb3b02faf7d00000000","02000000010000000000000000000000000000000000000000000000000000000000000000ffffffff3803cef42a005374726174756d2076322053524920506f6f6c","ffffffff02d71a050300000000160014ebe1b7dcc293ccaa0ee743a86f89df8258c208fc0000000000000000266a24aa21a9ede4bfe2c266f17fa3d3863fccf38e9d908e39b84e73fb6fb755c945c59ba5723800000000",["ddd6375856de644eeaa8ca9a76cfc787925b448c76800472c7e91dc582efb19e","60b10d35520093c8c80b9eedd9717978246f9469b6577715d34846c754f351c7","df56a8c826e01a77a48b07c0195843b97c534e28eef27d2a294d0d959b036812","e5336a5346a7c841f8202c120396e71f6133b191782c6cbaae16bae68c89434c","153a9e400e67c6138ea745b06df97daf61a33da38dbcadcd5e5a482b82bb204c","10ae3c49f6a9ed43f02aeaabb58cd4b55a1b756d874a2bb3193a89bdae852d04","0860fcb21bb8b4daf0a32b65a2bb1f29a233724e9a00c789561018be89597aeb","230b07dde955c3d0dad72b8c991f494115400d96ffe06f101760dce742d80cdc","0c80451a7f31e469862a5d644359be7530fce8698f31460d5a44d2bcdf91d4b4","2c60a19b68d31aa4517577ccf66fe76f752bcc52760b23846d179288348aebdd","a2e6c498a4351fd971b04921c9daba6af15dbf6ff6cf9178006f4727398473f0","8de88aa09c8d7192858f8b83f6cba083518b310653ee180cda2f3421d90347c4"],"20000000","191881b8","6642cf2f",false]}
[2024-05-13 21:40:47] DEBUG: job_id='16' extranonce2=0000000000000000 ntime=6642cf2f
[2024-05-13 21:41:08] < {"method":"mining.set_difficulty","params":[0.5]}
[2024-05-13 21:41:08] Stratum difficulty set to 0.5
For both options, in the startum sv2_pool logs you should see hashes and blocks being successfully submitted (no reverts). In the pool logs you should see smart contract receipts with no reverts:
Some(TransactionReceipt { transaction_hash: 0x3bda3009fb0760a2015a7a41824d64e566c70f55a1e0641e72e9efdcd49158de, transaction_index: 0, block_hash: Some(0x635d26a212de49a19b4d85c103f7e3da3ab1320646511638128a8626bc2845ed), block_number: Some(86), from: 0x70997970c51812dc3a010c7d01b50e0d17dc79c8, to: Some(0x9fe46736679d2d9a65f0992f2272de9f3c7fa6e0), cumulative_gas_used: 45796, gas_used: Some(45796), contract_address: None, logs: [Log { address: 0x9fe46736679d2d9a65f0992f2272de9f3c7fa6e0, topics: [0x50d27fceedd14dad658ad3e394163059b4b8ce971ed48609f5469e73b6d3fa84], data: Bytes(0xdbe6ddfab6a84cca6b8f8b8747997388c92b3a327bc81e02696c51e74d7384020000000000000000000000007e5f4552091a69125d5dfcb7b8c2659029395bdf), block_hash: Some(0x635d26a212de49a19b4d85c103f7e3da3ab1320646511638128a8626bc2845ed), block_number: Some(86), transaction_hash: Some(0x3bda3009fb0760a2015a7a41824d64e566c70f55a1e0641e72e9efdcd49158de), transaction_index: Some(0), log_index: Some(0), transaction_log_index: None, log_type: None, removed: Some(false) }], status: Some(1), root: None, logs_bloom: 0x00000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000040200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000, transaction_type: Some(2), effective_gas_price: Some(3000016509), other: OtherFields { inner: {"depositNonce": Null} } })
...
python3 run.py --kill
Bitcoind is taking up too much space. It should take around ~60 GB for a testnet fullnode. If it's taking much more, make sure you're setting testnet=1 and using the right bitcoin.conf. In the bitcoind run you should see logs like:
2024-05-11T19:40:13Z Config file: /Users/konradcheng/Library/Application Support/Bitcoin/bitcoin.conf
2024-05-11T19:40:13Z Config file arg: rpcpassword=****
2024-05-11T19:40:13Z Config file arg: rpcuser=****
2024-05-11T19:40:13Z Config file arg: server="1"
2024-05-11T19:40:13Z Config file arg: testnet="1"
Stratum Pool Reverts:
- Use revertHelper.py to decode the revert.
0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000185375626d697474656420626c6f636b206973207374616c650000000000000000
"Submitted block is stale". Make sure the oracle is running successfully and you are getting chain tips set. You should see logs like:
02:48:15 [INFO] Best Hash: "00000000ba847a4029923fa91a4eb981e0e2266deec55d5c7dfb890d7f7ab86d"
02:48:15 [INFO] Best Block: ...
02:48:15 [INFO] Set chain tip: ...
in oracle/oracle.log. Also make sure the address in deployments.local in the stratum side (stratum/deployments.local) matches that in quarry/deployments.local. If it does not, something went wrong with the copying of addresses and start debugging by looking at addresses in the run.py deployment.