Skip to content

Commit

Permalink
Fix XEL payment transaction fees
Browse files Browse the repository at this point in the history
  • Loading branch information
ceedii committed Feb 10, 2025
1 parent b3bfff3 commit 9f3e675
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ cd miningcore
Then build using Docker:

```console
docker run --rm -v $(pwd):/app -w /app mcr.microsoft.com/dotnet/sdk:6.0 /bin/bash -c 'apt update && apt install cmake ninja-build build-essential libssl-dev pkg-config libboost-all-dev libsodium-dev libzmq5n libzmq3-dev golang-go libgmp-dev -y --no-install-recommends && cd src/Miningcore && dotnet publish -c Release --framework net6.0 -o /app/build/'
docker run --rm -v $(pwd):/app -w /app mcr.microsoft.com/dotnet/sdk:6.0 /bin/bash -c 'apt update && apt install cmake clang ninja-build build-essential libssl-dev pkg-config libboost-all-dev libsodium-dev libzmq5 libzmq3-dev golang-go libgmp-dev libc++-dev zlib1g-dev -y --no-install-recommends && cd src/Miningcore && dotnet publish -c Release --framework net6.0 -o /app/build/'
```
It will use a Linux container, you will build a Linux executable that will not run on Windows or macOS. You can use a runtime argument (-r) to specify the type of assets that you want to publish (if they don't match the SDK container). The following examples assume you want assets that match your host operating system, and use runtime arguments to ensure that.

For macOS:

```console
docker run --rm -v $(pwd):/app -w /app mcr.microsoft.com/dotnet/sdk:6.0 /bin/bash -c 'apt update && apt install cmake ninja-build build-essential libssl-dev pkg-config libboost-all-dev libsodium-dev libzmq5n libzmq3-dev golang-go libgmp-dev -y --no-install-recommends && cd src/Miningcore && dotnet publish -c Release --framework net6.0 -o /app/build/ -r osx-x64 --self-contained false'
docker run --rm -v $(pwd):/app -w /app mcr.microsoft.com/dotnet/sdk:6.0 /bin/bash -c 'apt update && apt install cmake clang ninja-build build-essential libssl-dev pkg-config libboost-all-dev libsodium-dev libzmq5 libzmq3-dev golang-go libgmp-dev libc++-dev zlib1g-dev -y --no-install-recommends && cd src/Miningcore && dotnet publish -c Release --framework net6.0 -o /app/build/ -r osx-x64 --self-contained false'
```

### Building and Running Miningcore from a container
Expand Down Expand Up @@ -121,7 +121,7 @@ docker run -d \
For Windows using Linux container:

```console
docker run --rm -v $(pwd):/app -w /app mcr.microsoft.com/dotnet/sdk:6.0 /bin/bash -c 'apt update && apt install cmake ninja-build build-essential libssl-dev pkg-config libboost-all-dev libsodium-dev libzmq5n libzmq3-dev golang-go libgmp-dev -y --no-install-recommends && cd src/Miningcore && dotnet publish -c Release --framework net6.0 -o /app/build/ -r win-x64 --self-contained false'
docker run --rm -v $(pwd):/app -w /app mcr.microsoft.com/dotnet/sdk:6.0 /bin/bash -c 'apt update && apt install cmake clang ninja-build build-essential libssl-dev pkg-config libboost-all-dev libsodium-dev libzmq5 libzmq3-dev golang-go libgmp-dev libc++-dev zlib1g-dev -y --no-install-recommends && cd src/Miningcore && dotnet publish -c Release --framework net6.0 -o /app/build/ -r win-x64 --self-contained false'
```

To delete used images and containers you can run after all:
Expand Down
2 changes: 1 addition & 1 deletion src/Miningcore/Blockchain/Xelis/XelisJobManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ protected override async Task EnsureDaemonsSynchedAsync(CancellationToken ct)
if(status.Error != null)
logger.Warn(() => $"'{XelisCommands.GetStatus}': {status.Error.Message} (Code {status.Error.Code})");

if(status.Response.BestTopoHeight == status.Response.TopoHeight)
if(status.Response.BestTopoHeight <= status.Response.MedianTopoHeight)
{
logger.Info(() => $"'{XelisCommands.DaemonName}' daemon synched with blockchain");
break;
Expand Down
42 changes: 22 additions & 20 deletions src/Miningcore/Blockchain/Xelis/XelisPayoutHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,23 +315,23 @@ public virtual async Task PayoutAsync(IMiningPool pool, Balance[] balances, Canc
}).ToArray()
};

var estimateFeesRequest = new EstimateFeesRequest
if(extraPoolPaymentProcessingConfig?.KeepTransactionFees == true)
{
Transfers = buildTransactionRequest.Transfers
};
var estimateFeesRequest = new EstimateFeesRequest
{
Transfers = buildTransactionRequest.Transfers
};

var estimateFeesResponse = await rpcClientWallet.ExecuteAsync<object>(logger, XelisWalletCommands.EstimateFees, ct, estimateFeesRequest);
if(estimateFeesResponse.Error != null)
{
logger.Warn(()=> $"[{LogCategory}] '{XelisWalletCommands.EstimateFees}': {estimateFeesResponse.Error.Message} (Code {estimateFeesResponse.Error.Code})");
continue;
}
var estimateFeesResponse = await rpcClientWallet.ExecuteAsync<object>(logger, XelisWalletCommands.EstimateFees, ct, estimateFeesRequest);
if(estimateFeesResponse.Error != null)
{
logger.Warn(()=> $"[{LogCategory}] '{XelisWalletCommands.EstimateFees}': {estimateFeesResponse.Error.Message} (Code {estimateFeesResponse.Error.Code})");
continue;
}

var estimatedTransactionFees = Convert.ToDecimal(estimateFeesResponse.Response) / XelisConstants.SmallestUnit;
logger.Info(() => $"[{LogCategory}] Estimated transaction fees: {FormatAmount(estimatedTransactionFees)}");
var estimatedTransactionFees = Convert.ToDecimal(estimateFeesResponse.Response) / XelisConstants.SmallestUnit;
logger.Info(() => $"[{LogCategory}] Estimated transaction fees: {FormatAmount(estimatedTransactionFees)}");

if(extraPoolPaymentProcessingConfig?.KeepTransactionFees == true)
{
logger.Debug(() => $"[{LogCategory}] Pool does not pay the transaction fee, so each address will have its payout deducted with [{FormatAmount(estimatedTransactionFees / page.Length)}]");

buildTransactionRequest = new BuildTransactionRequest
Expand All @@ -348,12 +348,12 @@ public virtual async Task PayoutAsync(IMiningPool pool, Balance[] balances, Canc
};
}).ToArray()
};
}

buildTransactionRequest.Fee = new BuildTransactionFee
{
Amount = (ulong) (estimatedTransactionFees * XelisConstants.SmallestUnit)
};
buildTransactionRequest.Fee = new BuildTransactionFee
{
Amount = (ulong) (estimatedTransactionFees * XelisConstants.SmallestUnit)
};
}

var buildTransactionResponse = await rpcClientWallet.ExecuteAsync<BuildTransactionResponse>(logger, XelisWalletCommands.BuildTransaction, ct, buildTransactionRequest);
if(buildTransactionResponse.Error != null)
Expand All @@ -371,10 +371,12 @@ public virtual async Task PayoutAsync(IMiningPool pool, Balance[] balances, Canc
else
{
// payment successful
logger.Info(() => $"[{LogCategory}] Payment transaction id: {buildTransactionResponse.Response.Hash}");
var finalTransactionFees = (decimal) buildTransactionResponse.Response.Fee / XelisConstants.SmallestUnit;

logger.Info(() => $"[{LogCategory}] Payment transaction id: {buildTransactionResponse.Response.Hash} || Payment transaction fees: {FormatAmount(finalTransactionFees)}");

await PersistPaymentsAsync(page, buildTransactionResponse.Response.Hash);
NotifyPayoutSuccess(poolConfig.Id, page, new[] { buildTransactionResponse.Response.Hash }, (decimal) (buildTransactionResponse.Response.Fee / XelisConstants.SmallestUnit));
NotifyPayoutSuccess(poolConfig.Id, page, new[] { buildTransactionResponse.Response.Hash }, finalTransactionFees);
}
}
}
Expand Down

0 comments on commit 9f3e675

Please sign in to comment.