darkfid: support both normal address and base64 encoded mining configurations as miners recipient

This commit is contained in:
skoupidi
2026-01-01 18:17:57 +02:00
parent d56580bd9e
commit 965870ab9b
11 changed files with 48 additions and 39 deletions

View File

@@ -72,11 +72,22 @@ impl MinerRewardsRecipientConfig {
Self { recipient, spend_hook, user_data }
}
pub async fn from_base64(
network: &Network,
encoded_address: &str,
) -> std::result::Result<Self, RpcError> {
let Some(address_bytes) = base64::decode(encoded_address) else {
/// Auxiliary function to convert provided string to its
/// `MinerRewardsRecipientConfig`. Supports parsing both a normal
/// `Address` and a `base64` encoded mining configuration. Also
/// verifies it corresponds to the provided `Network`.
pub async fn from_str(network: &Network, address: &str) -> std::result::Result<Self, RpcError> {
// Try to parse the string as an `Address`
if let Ok(recipient) = Address::from_str(address) {
if recipient.network() != *network {
return Err(RpcError::MinerInvalidRecipientPrefix)
}
return Ok(Self { recipient, spend_hook: None, user_data: None })
}
// Try to parse the string as a `base64` encoded mining
// configuration
let Some(address_bytes) = base64::decode(address) else {
return Err(RpcError::MinerInvalidWalletConfig)
};
let Ok((recipient, spend_hook, user_data)) =

View File

@@ -73,8 +73,8 @@ impl DarkfiNode {
// job.
//
// **Request:**
// * `login` : A base-64 encoded wallet address mining configuration
// * `pass` : Unused client password field. Expects default "x" value.
// * `login` : A wallet address or its base-64 encoded mining configuration
// * `pass` : Unused client password field
// * `agent` : Client agent description
// * `algo` : Client supported mining algorithms
//
@@ -96,7 +96,7 @@ impl DarkfiNode {
// "jsonrpc": "2.0",
// "method": "login",
// "params": {
// "login": "MINING_CONFIG",
// "login": "WALLET_ADDRESS",
// "pass": "x",
// "agent": "XMRig",
// "algo": ["rx/0"]
@@ -131,7 +131,7 @@ impl DarkfiNode {
return JsonError::new(InvalidParams, None, id).into()
};
// Parse login mining configuration
// Parse login
let Some(wallet) = params.get("login") else {
return server_error(RpcError::MinerMissingLogin, id, None)
};
@@ -139,7 +139,7 @@ impl DarkfiNode {
return server_error(RpcError::MinerInvalidLogin, id, None)
};
let config =
match MinerRewardsRecipientConfig::from_base64(&self.registry.network, wallet).await {
match MinerRewardsRecipientConfig::from_str(&self.registry.network, wallet).await {
Ok(c) => c,
Err(e) => return server_error(e, id, None),
};

View File

@@ -132,7 +132,7 @@ impl DarkfiNode {
// merge mining.
//
// **Request:**
// * `address` : A base-64 encoded wallet address mining configuration on the merge mined chain
// * `address` : A wallet address or its base-64 encoded mining configuration on the merge mined chain
// * `aux_hash`: Merge mining job that is currently being polled
// * `height` : Monero height
// * `prev_id` : Hash of the previous Monero block
@@ -189,7 +189,7 @@ impl DarkfiNode {
return JsonResponse::new(JsonValue::from(HashMap::new()), id).into()
}
// Parse address mining configuration
// Parse address
let Some(wallet) = params.get("address") else {
return server_error(RpcError::MinerMissingAddress, id, None)
};
@@ -197,7 +197,7 @@ impl DarkfiNode {
return server_error(RpcError::MinerInvalidAddress, id, None)
};
let config =
match MinerRewardsRecipientConfig::from_base64(&self.registry.network, wallet).await {
match MinerRewardsRecipientConfig::from_str(&self.registry.network, wallet).await {
Ok(c) => c,
Err(e) => return server_error(e, id, None),
};

View File

@@ -7,8 +7,8 @@ set -e
XMRIG="xmrig"
DARKFID="LOG_TARGETS='!runtime,!sled' ../../../darkfid"
# Dummy mining config wallet so mining daemons can start.
XMRIG_USER="OERjbThtVW1VMkZIYmI2RlhucUx0OXByaFRSWmVWcE5hdTROWXQ3Szg1ZDVVWnA0RGpabmFKZVZEAAA"
# Dummy mining wallet address so mining daemons can start
XMRIG_USER="DZnsGMCvZU5CEzvpuExnxbvz6SEhE2rn89sMcuHsppFE6TjL4SBTrKkf"
session=darkfid-five-nodes

View File

@@ -5,10 +5,10 @@ This will start one `darkfid` node in localnet mode,
along with an `xmrig` daemon to mine blocks.
If we want to test wallet stuff, we must generate a testing wallet and
pass its mining configuration to the `xmrig` daemon, so the wallet gets
the block rewards the node produces. We generate a wallet, set it as
the default and set its address as the `XMRIG_USER` field in
`tmux_sessions.sh`, using provided automated script:
pass its address to the `xmrig` daemon, so the wallet gets the block
rewards the node produces. We generate a wallet, set it as the default
and set its address as the `XMRIG_USER` field in `tmux_sessions.sh`,
using provided automated script:
```shell
% ./init-wallet.sh
```

View File

@@ -1,3 +1,3 @@
#!/bin/sh
rm -rf darkfid drk
sed -i -e "s|XMRIG_USER=.*|XMRIG_USER=\"OERjbThtVW1VMkZIYmI2RlhucUx0OXByaFRSWmVWcE5hdTROWXQ3Szg1ZDVVWnA0RGpabmFKZVZEAAA\"|g" tmux_sessions.sh
sed -i -e "s|XMRIG_USER=.*|XMRIG_USER=\"DZnsGMCvZU5CEzvpuExnxbvz6SEhE2rn89sMcuHsppFE6TjL4SBTrKkf\"|g" tmux_sessions.sh

View File

@@ -6,5 +6,5 @@ DRK="../../../drk -c drk.toml"
$DRK wallet initialize
$DRK wallet keygen
$DRK wallet default-address 1
wallet=$($DRK wallet mining-config 1 | tail -n 1)
sed -i -e "s|OERjbThtVW1VMkZIYmI2RlhucUx0OXByaFRSWmVWcE5hdTROWXQ3Szg1ZDVVWnA0RGpabmFKZVZEAAA|$wallet|g" tmux_sessions.sh
wallet=$($DRK wallet address)
sed -i -e "s|DZnsGMCvZU5CEzvpuExnxbvz6SEhE2rn89sMcuHsppFE6TjL4SBTrKkf|$wallet|g" tmux_sessions.sh

View File

@@ -7,7 +7,7 @@ set -e
XMRIG_BINARY_PATH="xmrig"
XMRIG_STRATUM_ENDPOINT="127.0.0.1:48241"
XMRIG_THREADS="4"
XMRIG_USER="OERjbThtVW1VMkZIYmI2RlhucUx0OXByaFRSWmVWcE5hdTROWXQ3Szg1ZDVVWnA0RGpabmFKZVZEAAA"
XMRIG_USER="DZnsGMCvZU5CEzvpuExnxbvz6SEhE2rn89sMcuHsppFE6TjL4SBTrKkf"
XMRIG_PARAMS="-u x+1 -r 1000 -R 20 -o $XMRIG_STRATUM_ENDPOINT -t $XMRIG_THREADS -u $XMRIG_USER"
XMRIG="$XMRIG_BINARY_PATH $XMRIG_PARAMS"

View File

@@ -8,8 +8,8 @@ set -e
XMRIG="xmrig"
DARKFID="LOG_TARGETS='!runtime,!sled' ../../../darkfid"
# Dummy mining config wallet so mining daemons can start.
XMRIG_USER="OERjbThtVW1VMkZIYmI2RlhucUx0OXByaFRSWmVWcE5hdTROWXQ3Szg1ZDVVWnA0RGpabmFKZVZEAAA"
# Dummy mining wallet address so mining daemons can start
XMRIG_USER="DZnsGMCvZU5CEzvpuExnxbvz6SEhE2rn89sMcuHsppFE6TjL4SBTrKkf"
session=darkfid-small

View File

@@ -174,13 +174,12 @@ Now that everything is in order, we can use `p2pool` with merge-mining
enabled in order to merge mine DarkFi. For receiving mining rewards
on DarkFi, we'll need a DarkFi wallet address so make sure you have
[initialized](node.md#wallet-initialization) your wallet and grab your
first address configuration:
default address:
```shell
drk> wallet mining-configuration 1
drk> wallet address
DarkFi mining configuration address:
{YOUR_WALLET_ADDRESS_MINING_CONFIGURATION}
{YOUR_DARKFI_WALLET_ADDRESS}
```
We will also need `darkfid` running. Make sure you enable the RPC
@@ -202,7 +201,7 @@ Stop `p2pool` if it's running, and re-run it with the merge-mining
parameters appended:
```shell
$ ./p2pool --host 127.0.0.1 --rpc-port 28081 --zmq-port 28083 --wallet {YOUR_MONERO_WALLET_ADDRESS_HERE} --stratum 127.0.0.1:3333 --data-dir ./p2pool-data --no-igd --merge-mine 127.0.0.1:8341 {YOUR_WALLET_ADDRESS_MINING_CONFIGURATION}
$ ./p2pool --host 127.0.0.1 --rpc-port 28081 --zmq-port 28083 --wallet {YOUR_MONERO_WALLET_ADDRESS_HERE} --stratum 127.0.0.1:3333 --data-dir ./p2pool-data --no-igd --merge-mine 127.0.0.1:8341 {YOUR_DARKFI_WALLET_ADDRESS}
```
Now `p2pool` should communicate with both `monerod` and `darkfid` in

View File

@@ -167,7 +167,7 @@ $ ./drk wallet keygen
Generating a new keypair
New address:
DZnsGMCvZU5CEzvpuExnxbvz6SEhE2rn89sMcuHsppFE6TjL4SBTrKkf
{YOUR_DARKFI_WALLET_ADDRESS}
```
```shell
@@ -181,7 +181,7 @@ retrieve your default address using:
```shell
$ ./drk wallet address
DZnsGMCvZU5CEzvpuExnxbvz6SEhE2rn89sMcuHsppFE6TjL4SBTrKkf
{YOUR_DARKFI_WALLET_ADDRESS}
```
### Darkfid
@@ -270,14 +270,13 @@ To mine on DarkFI we need to add a recipient to `xmrig` that specifies
where the mining rewards will be minted to. You now have to configure
`xmrig` to use your wallet address as the rewards recipient, when it
retrieves blocks from `darkfid` to mine. Make sure you have
[initialized](#wallet-initialization) your wallet and grab your first
address mining configuration:
[initialized](#wallet-initialization) your wallet and grab your default
address:
```shell
./drk wallet mining-configuration 1
./drk wallet address
DarkFi mining configuration address:
{YOUR_WALLET_ADDRESS_MINING_CONFIGURATION}
{YOUR_DARKFI_WALLET_ADDRESS}
```
Refer to [xmrig optimizations guide][2] to fully configure your system
@@ -286,14 +285,14 @@ for maximum mining performance. Start `darkfid` as usual and then start
which wallet:
```shell
$ ./xmrig -u x+1 -r 1000 -R 20 -o 127.0.0.1:8341 -t {XMRIG_THREADS} -u {YOUR_WALLET_ADDRESS_MINING_CONFIGURATION}
$ ./xmrig -u x+1 -r 1000 -R 20 -o 127.0.0.1:8341 -t {XMRIG_THREADS} -u {YOUR_DARKFI_WALLET_ADDRESS}
```
In `darkfid`, you should see a notification like this:
```shell
...
[INFO] [RPC-STRATUM] Got login from {YOUR_WALLET_ADDRESS_MINING_CONFIGURATION} ({AGENT_INFO})
[INFO] [RPC-STRATUM] Got login from {YOUR_DARKFI_WALLET_ADDRESS} ({AGENT_INFO})
...
```