Implements waiting for correct sync metric of geth nodes

This commit is contained in:
benbierens 2023-04-25 07:46:09 +02:00
parent 929fdb1157
commit 72bb0132bf
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
9 changed files with 35 additions and 42 deletions

View File

@ -33,7 +33,7 @@ namespace DistTestCore
private void TransferInitialBalance(MarketplaceNetwork marketplaceNetwork, MarketplaceInitialConfig marketplaceConfig, GethCompanionNodeInfo[] companionNodes)
{
var interaction = marketplaceNetwork.StartInteraction(lifecycle.Log);
var interaction = marketplaceNetwork.StartInteraction();
var tokenAddress = marketplaceNetwork.Marketplace.TokenAddress;
foreach (var node in companionNodes)

View File

@ -34,7 +34,7 @@ namespace DistTestCore.Marketplace
var marketplaceAddress = extractor.ExtractMarketplaceAddress();
var abi = extractor.ExtractMarketplaceAbi();
var interaction = bootstrapNode.StartInteraction(lifecycle.Log);
var interaction = bootstrapNode.StartInteraction();
var tokenAddress = interaction.GetTokenAddress(marketplaceAddress);
LogEnd("Contracts deployed.");

View File

@ -1,5 +1,4 @@
using KubernetesWorkflow;
using Logging;
using NethereumWorkflow;
namespace DistTestCore.Marketplace
@ -21,14 +20,14 @@ namespace DistTestCore.Marketplace
public string PrivateKey { get; }
public Port DiscoveryPort { get; }
public NethereumInteraction StartInteraction(TestLog log)
public NethereumInteraction StartInteraction()
{
var ip = RunningContainers.RunningPod.Cluster.IP;
var port = RunningContainers.Containers[0].ServicePorts[0].Number;
var account = Account;
var privateKey = PrivateKey;
var creator = new NethereumInteractionCreator(log, ip, port, account, privateKey);
var creator = new NethereumInteractionCreator(ip, port, account, privateKey);
return creator.CreateWorkflow();
}
}

View File

@ -1,5 +1,4 @@
using KubernetesWorkflow;
using Logging;
using NethereumWorkflow;
namespace DistTestCore.Marketplace
@ -17,14 +16,14 @@ namespace DistTestCore.Marketplace
public string Account { get; }
public string PrivateKey { get; }
public NethereumInteraction StartInteraction(TestLog log)
public NethereumInteraction StartInteraction()
{
var ip = RunningContainer.Pod.Cluster.IP;
var port = RunningContainer.ServicePorts[0].Number;
var account = Account;
var privateKey = PrivateKey;
var creator = new NethereumInteractionCreator(log, ip, port, account, privateKey);
var creator = new NethereumInteractionCreator(ip, port, account, privateKey);
return creator.CreateWorkflow();
}
}

View File

@ -43,7 +43,7 @@ namespace DistTestCore.Marketplace
{
try
{
var interaction = node.StartInteraction(lifecycle.Log);
var interaction = node.StartInteraction();
interaction.EnsureSynced(marketplace.Marketplace.Address, marketplace.Marketplace.Abi);
}
catch (Exception e)

View File

@ -103,7 +103,7 @@ namespace DistTestCore.Marketplace
public TestToken GetBalance()
{
var interaction = marketplaceNetwork.StartInteraction(log);
var interaction = marketplaceNetwork.StartInteraction();
var account = companionNode.Account;
var amount = interaction.GetBalance(marketplaceNetwork.Marketplace.TokenAddress, account);
var balance = new TestToken(amount);

View File

@ -1,5 +1,4 @@
using Logging;
using NethereumWorkflow;
using NethereumWorkflow;
namespace DistTestCore.Marketplace
{
@ -14,9 +13,9 @@ namespace DistTestCore.Marketplace
public GethBootstrapNodeInfo Bootstrap { get; }
public MarketplaceInfo Marketplace { get; }
public NethereumInteraction StartInteraction(TestLog log)
public NethereumInteraction StartInteraction()
{
return Bootstrap.StartInteraction(log);
return Bootstrap.StartInteraction();
}
}
}

View File

@ -1,5 +1,4 @@
using Logging;
using Nethereum.ABI.FunctionEncoding.Attributes;
using Nethereum.ABI.FunctionEncoding.Attributes;
using Nethereum.Contracts;
using Nethereum.Hex.HexTypes;
using Nethereum.Web3;
@ -11,13 +10,11 @@ namespace NethereumWorkflow
public class NethereumInteraction
{
private readonly List<Task> openTasks = new List<Task>();
private readonly TestLog log;
private readonly Web3 web3;
private readonly string rootAccount;
internal NethereumInteraction(TestLog log, Web3 web3, string rootAccount)
internal NethereumInteraction(Web3 web3, string rootAccount)
{
this.log = log;
this.web3 = web3;
this.rootAccount = rootAccount;
}
@ -73,31 +70,30 @@ namespace NethereumWorkflow
}
public void EnsureSynced(string marketplaceAddress, string marketplaceAbi)
{
WaitUntilSynced();
WaitForContract(marketplaceAddress, marketplaceAbi);
}
private void WaitUntilSynced()
{
Time.WaitUntil(() =>
{
return !Time.Wait(web3.Eth.Syncing.SendRequestAsync()).IsSyncing;
var sync = Time.Wait(web3.Eth.Syncing.SendRequestAsync());
var number = Time.Wait(web3.Eth.Blocks.GetBlockNumber.SendRequestAsync());
var numberOfBlocks = ToDecimal(number);
return !sync.IsSyncing && numberOfBlocks > 256;
}, TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(1));
}
private void WaitForContract(string marketplaceAddress, string marketplaceAbi)
{
Time.WaitUntil(() =>
{
try
{
var contract = web3.Eth.GetContract(marketplaceAbi, marketplaceAddress);
if (contract != null)
{
var aaa = 0;
var func = contract.GetFunction("myRequests");
var input = func.CreateCallInput();
var result = Time.Wait(func.CallAsync(input));
var eeee = 0;
}
return contract != null;
}
catch
@ -105,8 +101,6 @@ namespace NethereumWorkflow
return false;
}
}, TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(1));
Thread.Sleep(TimeSpan.FromMinutes(2));
}
private HexBigInteger ToHexBig(decimal amount)
@ -121,6 +115,11 @@ namespace NethereumWorkflow
return new BigInteger(amount);
}
private decimal ToDecimal(HexBigInteger hexBigInteger)
{
return ToDecimal(hexBigInteger.Value);
}
private decimal ToDecimal(BigInteger bigInteger)
{
return (decimal)bigInteger;

View File

@ -1,19 +1,16 @@
using Logging;
using Nethereum.Web3;
using Nethereum.Web3;
namespace NethereumWorkflow
{
public class NethereumInteractionCreator
{
private readonly TestLog log;
private readonly string ip;
private readonly int port;
private readonly string rootAccount;
private readonly string privateKey;
public NethereumInteractionCreator(TestLog log, string ip, int port, string rootAccount, string privateKey)
public NethereumInteractionCreator(string ip, int port, string rootAccount, string privateKey)
{
this.log = log;
this.ip = ip;
this.port = port;
this.rootAccount = rootAccount;
@ -22,7 +19,7 @@ namespace NethereumWorkflow
public NethereumInteraction CreateWorkflow()
{
return new NethereumInteraction(log, CreateWeb3(), rootAccount);
return new NethereumInteraction(CreateWeb3(), rootAccount);
}
private Web3 CreateWeb3()