Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Commit

Permalink
Added changes related to London hard-fork, also correct calculation o…
Browse files Browse the repository at this point in the history
…f the reward minus Burnt Fees, additional eth_sendTransaction fields and settings: "gas": 21000, "maxFeePerGas": 50000000000,
  • Loading branch information
Konstantin35 committed Aug 23, 2021
1 parent 8d9e4f3 commit 7a10969
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 9 deletions.
18 changes: 10 additions & 8 deletions examples/ethereum_pool.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,16 @@
}
],
"paymentProcessing": {
"enabled": true,
"minimumPayment": 1,
"payoutScheme": "PPLNS",
"payoutSchemeConfig": {
"factor": 0.5
},
"keepUncles": false,
"keepTransactionFees": false
"enabled": true,
"minimumPayment": 1,
"payoutScheme": "PPLNS",
"payoutSchemeConfig": {
"factor": 0.5
},
"gas": 21000,
"maxFeePerGas": 50000000000,
"keepUncles": false,
"keepTransactionFees": false
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,15 @@ public class EthereumPoolPaymentProcessingConfigExtra
/// True to exempt uncle rewards from miner rewards
/// </summary>
public bool KeepUncles { get; set; }

/// <summary>
/// Gas amount for payout tx (advanced users only)
/// </summary>
public ulong Gas { get; set; }

/// <summary>
/// maximum amount you’re willing to pay
/// </summary>
public ulong MaxFeePerGas { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,17 @@ public class SendTransactionRequest
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string Data { get; set; }

/// <summary>
/// Maximum fee per gas the sender is willing to pay to miners in wei.
/// </summary>
[JsonConverter(typeof(HexToIntegralTypeJsonConverter<ulong>))]
public ulong MaxPriorityFeePerGas { get; set; }

/// <summary>
/// The maximum total fee per gas the sender is willing to pay(includes the network / base fee and miner / priority fee) in wei
/// </summary>
[JsonConverter(typeof(HexToIntegralTypeJsonConverter<ulong>))]
public ulong MaxFeePerGas { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,11 @@ public class Block
/// Array of uncle hashes.
/// </summary>
public string[] Uncles { get; set; }

/// <summary>
/// Base fee per gas.
/// </summary>
[JsonConverter(typeof(HexToIntegralTypeJsonConverter<ulong>))]
public ulong BaseFeePerGas { get; set; }
}
}
1 change: 1 addition & 0 deletions src/Miningcore/Blockchain/Ethereum/EthereumConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,6 @@ public static class EthCommands
public const string SendTx = "eth_sendTransaction";
public const string UnlockAccount = "personal_unlockAccount";
public const string Subscribe = "eth_subscribe";
public const string MaxPriorityFeePerGas = "eth_maxPriorityFeePerGas";
}
}
16 changes: 15 additions & 1 deletion src/Miningcore/Blockchain/Ethereum/EthereumPayoutHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ public async Task<Block[]> ClassifyBlocksAsync(IMiningPool pool, Block[] blocks,
var blockHashResponse = await rpcClient.ExecuteAsync<DaemonResponses.Block>(logger, EC.GetBlockByNumber, ct,
new[] { (object) block.BlockHeight.ToStringHexWithPrefix(), true });
var blockHash = blockHashResponse.Response.Hash;
var baseGas = blockHashResponse.Response.BaseFeePerGas;
var gasUsed = blockHashResponse.Response.GasUsed;

var burnedFee = (decimal) 0;
if(extraPoolConfig?.ChainTypeOverride == "Ethereum")
burnedFee = (baseGas * gasUsed / EthereumConstants.Wei);

block.Hash = blockHash;
block.Status = BlockStatus.Confirmed;
Expand All @@ -138,7 +144,7 @@ public async Task<Block[]> ClassifyBlocksAsync(IMiningPool pool, Block[] blocks,
block.Reward += blockInfo.Uncles.Length * (block.Reward / 32); // uncle rewards

if(extraConfig?.KeepTransactionFees == false && blockInfo.Transactions?.Length > 0)
block.Reward += await GetTxRewardAsync(blockInfo, ct); // tx fees
block.Reward += await GetTxRewardAsync(blockInfo, ct) - burnedFee;

logger.Info(() => $"[{LogCategory}] Unlocked block {block.BlockHeight} worth {FormatAmount(block.Reward)}");

Expand Down Expand Up @@ -396,6 +402,14 @@ private async Task<string> PayoutAsync(Balance balance, CancellationToken ct)
Value = amount.ToString("x").TrimStart('0'),
};

if(extraPoolConfig?.ChainTypeOverride == "Ethereum")
{
var maxPriorityFeePerGas = await rpcClient.ExecuteAsync<string>(logger, EC.MaxPriorityFeePerGas, ct);
request.Gas = extraConfig.Gas;
request.MaxPriorityFeePerGas = maxPriorityFeePerGas.Response.IntegralFromHex<ulong>();
request.MaxFeePerGas = extraConfig.MaxFeePerGas;
}

var response = await rpcClient.ExecuteAsync<string>(logger, EC.SendTx, ct, new[] { request });

if(response.Error != null)
Expand Down

0 comments on commit 7a10969

Please sign in to comment.