Skip to content

Commit

Permalink
merge hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm360 committed Mar 27, 2023
2 parents 8ff8608 + 5c00eb1 commit 08b65ad
Show file tree
Hide file tree
Showing 37 changed files with 760 additions and 224 deletions.
4 changes: 2 additions & 2 deletions src/BeehiveManager.Domain/BeehiveManager.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

<ItemGroup>
<PackageReference Include="Etherna.DomainEvents" Version="1.4.0" />
<PackageReference Include="MongODM.Core" Version="0.24.0-alpha.80" />
<PackageReference Include="Nethereum.Web3" Version="4.13.0" />
<PackageReference Include="MongODM.Core" Version="0.24.0-alpha.81" />
<PackageReference Include="Nethereum.Web3" Version="4.14.0" />
</ItemGroup>

</Project>
7 changes: 5 additions & 2 deletions src/BeehiveManager.Domain/Models/BeeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public BeeNode(
string connectionScheme,
int debugPort,
int gatewayPort,
string hostname)
string hostname,
bool enableBatchCreation)
{
if (debugPort is < 1 or > 65535)
throw new ArgumentOutOfRangeException(nameof(debugPort), "Debug port is not a valid port");
Expand All @@ -36,18 +37,20 @@ public BeeNode(
DebugPort = debugPort;
GatewayPort = gatewayPort;
Hostname = hostname;
IsBatchCreationEnabled = enableBatchCreation;
}
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
protected BeeNode() { }
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.

// Properties.
public virtual string ConnectionScheme { get; set; }
public virtual Uri BaseUrl => new($"{ConnectionScheme}://{Hostname}");
public virtual string ConnectionScheme { get; set; }
public virtual int DebugPort { get; set; }
public virtual Uri DebugUrl => new($"{ConnectionScheme}://{Hostname}:{DebugPort}");
public virtual int GatewayPort { get; set; }
public virtual Uri GatewayUrl => new($"{ConnectionScheme}://{Hostname}:{GatewayPort}");
public virtual string Hostname { get; set; }
public virtual bool IsBatchCreationEnabled { get; set; }
}
}
9 changes: 8 additions & 1 deletion src/BeehiveManager.Persistence/ModelMaps/BeeNodeMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ internal sealed class BeeNodeMap : IModelMapsCollector
{
public void Register(IDbContext dbContext)
{
dbContext.MapRegistry.AddModelMap<BeeNode>("6b94df32-034f-46f9-a5c1-239905ad5d07");
dbContext.MapRegistry.AddModelMap<BeeNode>("6b94df32-034f-46f9-a5c1-239905ad5d07",
mm =>
{
mm.AutoMap();

// Set default values.
mm.GetMemberMap(n => n.IsBatchCreationEnabled).SetDefaultValue(true);
});
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions src/BeehiveManager.Services/BeehiveManager.Services.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bee.Net" Version="0.2.0-alpha.156" />
<PackageReference Include="Bee.Net" Version="0.2.0-alpha.188" />
<PackageReference Include="Etherna.DomainEvents.AspNetCore" Version="1.4.0" />
<PackageReference Include="MongODM.Hangfire" Version="0.24.0-alpha.80" />
<PackageReference Include="Nethereum.JsonRpc.WebSocketClient" Version="4.13.0" />
<PackageReference Include="MongODM.Hangfire" Version="0.24.0-alpha.81" />
<PackageReference Include="Nethereum.JsonRpc.WebSocketClient" Version="4.14.0" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
</ItemGroup>

Expand Down
121 changes: 93 additions & 28 deletions src/BeehiveManager.Services/Extensions/LoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,59 +20,124 @@ namespace Etherna.BeehiveManager.Services.Extensions
{
/*
* Always group similar log delegates by type, always use incremental event ids.
* Last event id is: 4
* Last event id is: 11
*/
public static class LoggerExtensions
{
// Fields.
//*** DEBUG LOGS ***

//*** INFORMATION LOGS ***
private static readonly Action<ILogger, string, long, IEnumerable<string>, Exception> _nodeCashedOut =
LoggerMessage.Define<string, long, IEnumerable<string>>(
private static readonly Action<ILogger, string, decimal, IEnumerable<string>, Exception> _nodeCashedOut =
LoggerMessage.Define<string, decimal, IEnumerable<string>>(
LogLevel.Information,
new EventId(0, nameof(NodeCashedOut)),
"Node {BeeNodeId} cashed out {TotalCashedOut} with tx hashes {TxHashes}");
"Node {BeeNodeId} cashed out {BzzCashedOut} BZZ with tx hashes {TxHashes}");

private static readonly Action<ILogger, string, decimal, decimal, string, Exception> _succededToFundBzzOnNode =
private static readonly Action<ILogger, string, bool, Exception> _nodeConfigurationUpdated =
LoggerMessage.Define<string, bool>(
LogLevel.Information,
new EventId(7, nameof(NodeConfigurationUpdated)),
"Node {BeeNodeId} updated configuration. EnableBatchCreation: {EnableBatchCreation}");

private static readonly Action<ILogger, string, Uri, int, int, bool, Exception> _nodeRegistered =
LoggerMessage.Define<string, Uri, int, int, bool>(
LogLevel.Information,
new EventId(5, nameof(NodeRegistered)),
"Node {BeeNodeId} registered on url {NodeUrl} on gateway port {GatewayPort} and debug port {DebugPort}. Batch creation enabled: {IsBatchCreationEnabled}");

private static readonly Action<ILogger, string, Exception> _nodeRemoved =
LoggerMessage.Define<string>(
LogLevel.Information,
new EventId(6, nameof(NodeRemoved)),
"Node {BeeNodeId} has been removed");

private static readonly Action<ILogger, string, decimal, string, Exception> _succededToDepositBzzOnNodeChequeBook =
LoggerMessage.Define<string, decimal, string>(
LogLevel.Information,
new EventId(8, nameof(SuccededToDepositBzzOnNodeChequeBook)),
"Node {BeeNodeId} chequebook received deposit of {BzzAmount} BZZ with tx hash {TxHash}");

private static readonly Action<ILogger, string, decimal, decimal, string, Exception> _succededToFundBzzOnNodeAddress =
LoggerMessage.Define<string, decimal, decimal, string>(
LogLevel.Information,
new EventId(1, nameof(SuccededToFundBzzOnNode)),
"Node {BeeNodeId} funded with {BzzFunded} BZZ to total {BzzTotal} BZZ. Tx hash {TxHash}");
new EventId(1, nameof(SuccededToFundBzzOnNodeAddress)),
"Node {BeeNodeId} address funded with {BzzFunded} BZZ to total {BzzTotal} BZZ. Tx hash {TxHash}");

private static readonly Action<ILogger, string, decimal, decimal, string, Exception> _succededToFundXDaiOnNode =
private static readonly Action<ILogger, string, decimal, decimal, string, Exception> _succededToFundXDaiOnNodeAddress =
LoggerMessage.Define<string, decimal, decimal, string>(
LogLevel.Information,
new EventId(3, nameof(SuccededToFundXDaiOnNode)),
"Node {BeeNodeId} funded with {XDaiFunded} xDai to total {XDaiTotal} xDai. Tx hash {TxHash}");
new EventId(3, nameof(SuccededToFundXDaiOnNodeAddress)),
"Node {BeeNodeId} address funded with {XDaiFunded} xDai to total {XDaiTotal} xDai. Tx hash {TxHash}");

private static readonly Action<ILogger, string, decimal, string, Exception> _succededToWithdrawBzzOnNodeChequeBook =
LoggerMessage.Define<string, decimal, string>(
LogLevel.Information,
new EventId(10, nameof(SuccededToWithdrawBzzOnNodeChequeBook)),
"Node {BeeNodeId} chequebook sent withdraw of {BzzAmount} BZZ with tx hash {TxHash}");

//*** WARNING LOGS ***

//*** ERROR LOGS ***
private static readonly Action<ILogger, string, decimal, string?, Exception> _failedToFundBzzOnNode =
LoggerMessage.Define<string, decimal, string?>(LogLevel.Error,
new EventId(2, nameof(FailedToFundBzzOnNode)),
"Funding on node {BeeNodeId} failed with {BzzAmount} BZZ. Tx hash {TxHash}");
private static readonly Action<ILogger, string, decimal, Exception> _failedToDepositBzzOnNodeChequeBook =
LoggerMessage.Define<string, decimal>(
LogLevel.Error,
new EventId(9, nameof(FailedToDepositBzzOnNodeChequeBook)),
"Deposit on node {BeeNodeId} chequebook failed with {BzzAmount} BZZ");

private static readonly Action<ILogger, string, decimal, string?, Exception> _failedToFundXDaiOnNode =
LoggerMessage.Define<string, decimal, string?>(LogLevel.Error,
new EventId(2, nameof(FailedToFundXDaiOnNode)),
"Funding on node {BeeNodeId} failed with {XDaiAmount} xDai. Tx hash {TxHash}");
private static readonly Action<ILogger, string, decimal, string?, Exception> _failedToFundBzzOnNodeAddress =
LoggerMessage.Define<string, decimal, string?>(
LogLevel.Error,
new EventId(2, nameof(FailedToFundBzzOnNodeAddress)),
"Funding on node {BeeNodeId} address failed with {BzzAmount} BZZ. Tx hash {TxHash}");

private static readonly Action<ILogger, string, decimal, string?, Exception> _failedToFundXDaiOnNodeAddress =
LoggerMessage.Define<string, decimal, string?>(
LogLevel.Error,
new EventId(4, nameof(FailedToFundXDaiOnNodeAddress)),
"Funding on node {BeeNodeId} address failed with {XDaiAmount} xDai. Tx hash {TxHash}");

private static readonly Action<ILogger, string, decimal, Exception> _failedToWithdrawBzzOnNodeChequeBook =
LoggerMessage.Define<string, decimal>(
LogLevel.Error,
new EventId(11, nameof(FailedToWithdrawBzzOnNodeChequeBook)),
"Withdraw on node {BeeNodeId} chequebook failed with {BzzAmount} BZZ");

// Methods.
public static void FailedToFundBzzOnNode(this ILogger logger, string nodeId, decimal bzzFundAmount, string? txHash, Exception? exception) =>
_failedToFundBzzOnNode(logger, nodeId, bzzFundAmount, txHash, exception!);
public static void FailedToDepositBzzOnNodeChequeBook(this ILogger logger, string nodeId, decimal bzzDeposit, Exception exception) =>
_failedToDepositBzzOnNodeChequeBook(logger, nodeId, bzzDeposit, exception);

public static void FailedToFundBzzOnNodeAddress(this ILogger logger, string nodeId, decimal bzzFundAmount, string? txHash, Exception? exception) =>
_failedToFundBzzOnNodeAddress(logger, nodeId, bzzFundAmount, txHash, exception!);

public static void FailedToFundXDaiOnNodeAddress(this ILogger logger, string nodeId, decimal xDaiFundAmount, string? txHash, Exception? exception) =>
_failedToFundXDaiOnNodeAddress(logger, nodeId, xDaiFundAmount, txHash, exception!);

public static void FailedToWithdrawBzzOnNodeChequeBook(this ILogger logger, string nodeId, decimal bzzWithdraw, Exception exception) =>
_failedToWithdrawBzzOnNodeChequeBook(logger, nodeId, bzzWithdraw, exception);

public static void NodeCashedOut(this ILogger logger, string beeNodeId, decimal bzzCashedOut, IEnumerable<string> txHashes) =>
_nodeCashedOut(logger, beeNodeId, bzzCashedOut, txHashes, null!);

public static void NodeConfigurationUpdated(this ILogger logger, string beeNodeid, bool enableBatchCreation) =>
_nodeConfigurationUpdated(logger, beeNodeid, enableBatchCreation, null!);

public static void NodeRegistered(this ILogger logger, string beeNodeId, Uri nodeUrl, int gatewayPort, int debugPort, bool isBatchCreationEnabled) =>
_nodeRegistered(logger, beeNodeId, nodeUrl, gatewayPort, debugPort, isBatchCreationEnabled, null!);

public static void NodeRemoved(this ILogger logger, string beeNodeId) =>
_nodeRemoved(logger, beeNodeId, null!);

public static void FailedToFundXDaiOnNode(this ILogger logger, string nodeId, decimal xDaiFundAmount, string? txHash, Exception? exception) =>
_failedToFundXDaiOnNode(logger, nodeId, xDaiFundAmount, txHash, exception!);
public static void SuccededToDepositBzzOnNodeChequeBook(this ILogger logger, string nodeId, decimal bzzDeposit, string txHash) =>
_succededToDepositBzzOnNodeChequeBook(logger, nodeId, bzzDeposit, txHash, null!);

public static void NodeCashedOut(this ILogger logger, string beeNodeId, long totalCashedOut, IEnumerable<string> txHashes) =>
_nodeCashedOut(logger, beeNodeId, totalCashedOut, txHashes, null!);
public static void SuccededToFundBzzOnNodeAddress(this ILogger logger, string nodeId, decimal bzzFunded, decimal bzzTotal, string txHash) =>
_succededToFundBzzOnNodeAddress(logger, nodeId, bzzFunded, bzzTotal, txHash, null!);

public static void SuccededToFundBzzOnNode(this ILogger logger, string nodeId, decimal bzzFunded, decimal bzzTotal, string txHash) =>
_succededToFundBzzOnNode(logger, nodeId, bzzFunded, bzzTotal, txHash, null!);
public static void SuccededToFundXDaiOnNodeAddress(this ILogger logger, string nodeId, decimal xDaiFunded, decimal xDaiTotal, string txHash) =>
_succededToFundXDaiOnNodeAddress(logger, nodeId, xDaiFunded, xDaiTotal, txHash, null!);

public static void SuccededToFundXDaiOnNode(this ILogger logger, string nodeId, decimal xDaiFunded, decimal xDaiTotal, string txHash) =>
_succededToFundXDaiOnNode(logger, nodeId, xDaiFunded, xDaiTotal, txHash, null!);
public static void SuccededToWithdrawBzzOnNodeChequeBook(this ILogger logger, string nodeid, decimal bzzWithdraw, string txHash) =>
_succededToWithdrawBzzOnNodeChequeBook(logger, nodeid, bzzWithdraw, txHash, null!);
}
}
5 changes: 3 additions & 2 deletions src/BeehiveManager.Services/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ where t.GetInterfaces().Contains(typeof(IEventHandler))
services.AddSingleton<IBeeNodeLiveManager, BeeNodeLiveManager>();

// Tasks.
services.AddTransient<ICashoutAllNodesTask, CashoutAllNodesTask>();
services.AddTransient<IFundNodesTask, FundNodesTask>();
services.AddTransient<ICashoutAllNodesChequesTask, CashoutAllNodesChequesTask>();
services.AddTransient<INodesAddressMaintainerTask, NodesAddressMaintainerTask>();
services.AddTransient<INodesChequebookMaintainerTask, NodesChequebookMaintainerTask>();
services.AddTransient<IPinContentInNodeTask, PinContentInNodeTask>();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2021-present Etherna Sagl
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Etherna.BeehiveManager.Services.Settings
{
public class CashoutAllNodesChequesSettings
{
// Consts.
public const string ConfigPosition = "CashoutCheques";

// Properties.
public decimal BzzMaxTrigger { get; set; } = 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace Etherna.BeehiveManager.Services.Settings
{
public class FundNodesSettings
public class NodesAddressMaintainerSettings
{
// Consts.
public const string ConfigPosition = "FundNodes";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2021-present Etherna Sagl
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Etherna.BeehiveManager.Services.Settings
{
public class NodesChequebookMaintainerSettings
{
// Consts.
public const string ConfigPosition = "ChequebookLimits";

// Properties.
public decimal? BzzMaxTrigger { get; set; }
public decimal? BzzMinTrigger { get; set; }
public decimal? BzzTargetAmount { get; set; }
public bool RunDeposits => BzzTargetAmount.HasValue && BzzMinTrigger.HasValue;
public bool RunWithdraws => BzzTargetAmount.HasValue && BzzMaxTrigger.HasValue;
}
}
Loading

0 comments on commit 08b65ad

Please sign in to comment.