debugging rewards
This commit is contained in:
parent
1bf693938c
commit
42d3c5cd2c
|
@ -18,5 +18,10 @@
|
||||||
|
|
||||||
public ulong From { get; }
|
public ulong From { get; }
|
||||||
public ulong To { get; }
|
public ulong To { get; }
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"[{From} - {To}]";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,13 +19,13 @@ namespace CodexContractsPlugin
|
||||||
TestToken GetTestTokenBalance(IHasEthAddress owner);
|
TestToken GetTestTokenBalance(IHasEthAddress owner);
|
||||||
TestToken GetTestTokenBalance(EthAddress ethAddress);
|
TestToken GetTestTokenBalance(EthAddress ethAddress);
|
||||||
|
|
||||||
Request[] GetStorageRequests(TimeRange timeRange);
|
Request[] GetStorageRequests(BlockRange blockRange);
|
||||||
EthAddress? GetSlotHost(Request storageRequest, decimal slotIndex);
|
EthAddress? GetSlotHost(Request storageRequest, decimal slotIndex);
|
||||||
RequestState GetRequestState(Request request);
|
RequestState GetRequestState(Request request);
|
||||||
RequestFulfilledEventDTO[] GetRequestFulfilledEvents(TimeRange timeRange);
|
RequestFulfilledEventDTO[] GetRequestFulfilledEvents(BlockRange blockRange);
|
||||||
RequestCancelledEventDTO[] GetRequestCancelledEvents(TimeRange timeRange);
|
RequestCancelledEventDTO[] GetRequestCancelledEvents(BlockRange blockRange);
|
||||||
SlotFilledEventDTO[] GetSlotFilledEvents(TimeRange timeRange);
|
SlotFilledEventDTO[] GetSlotFilledEvents(BlockRange blockRange);
|
||||||
SlotFreedEventDTO[] GetSlotFreedEvents(TimeRange timeRange);
|
SlotFreedEventDTO[] GetSlotFreedEvents(BlockRange blockRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum RequestState
|
public enum RequestState
|
||||||
|
@ -77,9 +77,9 @@ namespace CodexContractsPlugin
|
||||||
return balance.TestTokens();
|
return balance.TestTokens();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Request[] GetStorageRequests(TimeRange timeRange)
|
public Request[] GetStorageRequests(BlockRange blockRange)
|
||||||
{
|
{
|
||||||
var events = gethNode.GetEvents<StorageRequestedEventDTO>(Deployment.MarketplaceAddress, timeRange);
|
var events = gethNode.GetEvents<StorageRequestedEventDTO>(Deployment.MarketplaceAddress, blockRange);
|
||||||
var i = StartInteraction();
|
var i = StartInteraction();
|
||||||
return events
|
return events
|
||||||
.Select(e =>
|
.Select(e =>
|
||||||
|
@ -93,9 +93,9 @@ namespace CodexContractsPlugin
|
||||||
.ToArray();
|
.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public RequestFulfilledEventDTO[] GetRequestFulfilledEvents(TimeRange timeRange)
|
public RequestFulfilledEventDTO[] GetRequestFulfilledEvents(BlockRange blockRange)
|
||||||
{
|
{
|
||||||
var events = gethNode.GetEvents<RequestFulfilledEventDTO>(Deployment.MarketplaceAddress, timeRange);
|
var events = gethNode.GetEvents<RequestFulfilledEventDTO>(Deployment.MarketplaceAddress, blockRange);
|
||||||
return events.Select(e =>
|
return events.Select(e =>
|
||||||
{
|
{
|
||||||
var result = e.Event;
|
var result = e.Event;
|
||||||
|
@ -104,9 +104,9 @@ namespace CodexContractsPlugin
|
||||||
}).ToArray();
|
}).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public RequestCancelledEventDTO[] GetRequestCancelledEvents(TimeRange timeRange)
|
public RequestCancelledEventDTO[] GetRequestCancelledEvents(BlockRange blockRange)
|
||||||
{
|
{
|
||||||
var events = gethNode.GetEvents<RequestCancelledEventDTO>(Deployment.MarketplaceAddress, timeRange);
|
var events = gethNode.GetEvents<RequestCancelledEventDTO>(Deployment.MarketplaceAddress, blockRange);
|
||||||
return events.Select(e =>
|
return events.Select(e =>
|
||||||
{
|
{
|
||||||
var result = e.Event;
|
var result = e.Event;
|
||||||
|
@ -115,9 +115,9 @@ namespace CodexContractsPlugin
|
||||||
}).ToArray();
|
}).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SlotFilledEventDTO[] GetSlotFilledEvents(TimeRange timeRange)
|
public SlotFilledEventDTO[] GetSlotFilledEvents(BlockRange blockRange)
|
||||||
{
|
{
|
||||||
var events = gethNode.GetEvents<SlotFilledEventDTO>(Deployment.MarketplaceAddress, timeRange);
|
var events = gethNode.GetEvents<SlotFilledEventDTO>(Deployment.MarketplaceAddress, blockRange);
|
||||||
return events.Select(e =>
|
return events.Select(e =>
|
||||||
{
|
{
|
||||||
var result = e.Event;
|
var result = e.Event;
|
||||||
|
@ -127,9 +127,9 @@ namespace CodexContractsPlugin
|
||||||
}).ToArray();
|
}).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SlotFreedEventDTO[] GetSlotFreedEvents(TimeRange timeRange)
|
public SlotFreedEventDTO[] GetSlotFreedEvents(BlockRange blockRange)
|
||||||
{
|
{
|
||||||
var events = gethNode.GetEvents<SlotFreedEventDTO>(Deployment.MarketplaceAddress, timeRange);
|
var events = gethNode.GetEvents<SlotFreedEventDTO>(Deployment.MarketplaceAddress, blockRange);
|
||||||
return events.Select(e =>
|
return events.Select(e =>
|
||||||
{
|
{
|
||||||
var result = e.Event;
|
var result = e.Event;
|
||||||
|
|
|
@ -89,7 +89,9 @@ namespace CodexTests.BasicTests
|
||||||
|
|
||||||
purchaseContract.WaitForStorageContractStarted(fileSize);
|
purchaseContract.WaitForStorageContractStarted(fileSize);
|
||||||
|
|
||||||
var requests = contracts.GetStorageRequests(GetTestRunTimeRange());
|
var blockRange = geth.ConvertTimeRangeToBlockRange(GetTestRunTimeRange());
|
||||||
|
|
||||||
|
var requests = contracts.GetStorageRequests(blockRange);
|
||||||
Assert.That(requests.Length, Is.EqualTo(1));
|
Assert.That(requests.Length, Is.EqualTo(1));
|
||||||
var request = requests.Single();
|
var request = requests.Single();
|
||||||
Assert.That(contracts.GetRequestState(request), Is.EqualTo(RequestState.Started));
|
Assert.That(contracts.GetRequestState(request), Is.EqualTo(RequestState.Started));
|
||||||
|
@ -98,10 +100,10 @@ namespace CodexTests.BasicTests
|
||||||
|
|
||||||
AssertBalance(contracts, seller, Is.LessThan(sellerInitialBalance), "Collateral was not placed.");
|
AssertBalance(contracts, seller, Is.LessThan(sellerInitialBalance), "Collateral was not placed.");
|
||||||
|
|
||||||
var requestFulfilledEvents = contracts.GetRequestFulfilledEvents(GetTestRunTimeRange());
|
var requestFulfilledEvents = contracts.GetRequestFulfilledEvents(blockRange);
|
||||||
Assert.That(requestFulfilledEvents.Length, Is.EqualTo(1));
|
Assert.That(requestFulfilledEvents.Length, Is.EqualTo(1));
|
||||||
CollectionAssert.AreEqual(request.RequestId, requestFulfilledEvents[0].RequestId);
|
CollectionAssert.AreEqual(request.RequestId, requestFulfilledEvents[0].RequestId);
|
||||||
var filledSlotEvents = contracts.GetSlotFilledEvents(GetTestRunTimeRange());
|
var filledSlotEvents = contracts.GetSlotFilledEvents(blockRange);
|
||||||
Assert.That(filledSlotEvents.Length, Is.EqualTo(1));
|
Assert.That(filledSlotEvents.Length, Is.EqualTo(1));
|
||||||
var filledSlotEvent = filledSlotEvents.Single();
|
var filledSlotEvent = filledSlotEvents.Single();
|
||||||
Assert.That(filledSlotEvent.SlotIndex.IsZero);
|
Assert.That(filledSlotEvent.SlotIndex.IsZero);
|
||||||
|
@ -124,6 +126,5 @@ namespace CodexTests.BasicTests
|
||||||
|
|
||||||
//CheckLogForErrors(seller, buyer);
|
//CheckLogForErrors(seller, buyer);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
using CodexContractsPlugin;
|
using CodexContractsPlugin;
|
||||||
using CodexContractsPlugin.Marketplace;
|
using CodexContractsPlugin.Marketplace;
|
||||||
using Utils;
|
using BlockRange = Utils.BlockRange;
|
||||||
|
|
||||||
namespace TestNetRewarder
|
namespace TestNetRewarder
|
||||||
{
|
{
|
||||||
|
@ -8,18 +8,18 @@ namespace TestNetRewarder
|
||||||
{
|
{
|
||||||
private readonly HistoricState historicState;
|
private readonly HistoricState historicState;
|
||||||
|
|
||||||
public ChainState(HistoricState historicState, ICodexContracts contracts, TimeRange timeRange)
|
public ChainState(HistoricState historicState, ICodexContracts contracts, BlockRange blockRange)
|
||||||
{
|
{
|
||||||
NewRequests = contracts.GetStorageRequests(timeRange);
|
NewRequests = contracts.GetStorageRequests(blockRange);
|
||||||
historicState.ProcessNewRequests(NewRequests);
|
historicState.ProcessNewRequests(NewRequests);
|
||||||
historicState.UpdateStorageRequests(contracts);
|
historicState.UpdateStorageRequests(contracts);
|
||||||
|
|
||||||
StartedRequests = historicState.StorageRequests.Where(r => r.RecentlyStarted).ToArray();
|
StartedRequests = historicState.StorageRequests.Where(r => r.RecentlyStarted).ToArray();
|
||||||
FinishedRequests = historicState.StorageRequests.Where(r => r.RecentlyFininshed).ToArray();
|
FinishedRequests = historicState.StorageRequests.Where(r => r.RecentlyFininshed).ToArray();
|
||||||
RequestFulfilledEvents = contracts.GetRequestFulfilledEvents(timeRange);
|
RequestFulfilledEvents = contracts.GetRequestFulfilledEvents(blockRange);
|
||||||
RequestCancelledEvents = contracts.GetRequestCancelledEvents(timeRange);
|
RequestCancelledEvents = contracts.GetRequestCancelledEvents(blockRange);
|
||||||
SlotFilledEvents = contracts.GetSlotFilledEvents(timeRange);
|
SlotFilledEvents = contracts.GetSlotFilledEvents(blockRange);
|
||||||
SlotFreedEvents = contracts.GetSlotFreedEvents(timeRange);
|
SlotFreedEvents = contracts.GetSlotFreedEvents(blockRange);
|
||||||
this.historicState = historicState;
|
this.historicState = historicState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,20 +11,28 @@ namespace TestNetRewarder
|
||||||
private static readonly HistoricState historicState = new HistoricState();
|
private static readonly HistoricState historicState = new HistoricState();
|
||||||
private static readonly RewardRepo rewardRepo = new RewardRepo();
|
private static readonly RewardRepo rewardRepo = new RewardRepo();
|
||||||
private readonly ILog log;
|
private readonly ILog log;
|
||||||
|
private BlockRange? lastBlockRange;
|
||||||
|
|
||||||
public Processor(ILog log)
|
public Processor(ILog log)
|
||||||
{
|
{
|
||||||
this.log = log;
|
this.log = log;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ProcessTimeSegment(TimeRange range)
|
public async Task ProcessTimeSegment(TimeRange timeRange)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var connector = GethConnector.GethConnector.Initialize(log);
|
var connector = GethConnector.GethConnector.Initialize(log);
|
||||||
if (connector == null) return;
|
if (connector == null) return;
|
||||||
|
|
||||||
var chainState = new ChainState(historicState, connector.CodexContracts, range);
|
var blockRange = connector.GethNode.ConvertTimeRangeToBlockRange(timeRange);
|
||||||
|
if (!IsNewBlockRange(blockRange))
|
||||||
|
{
|
||||||
|
log.Log($"Block range {blockRange} was previously processed. Skipping...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var chainState = new ChainState(historicState, connector.CodexContracts, blockRange);
|
||||||
await ProcessTimeSegment(chainState);
|
await ProcessTimeSegment(chainState);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -34,6 +42,19 @@ namespace TestNetRewarder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool IsNewBlockRange(BlockRange blockRange)
|
||||||
|
{
|
||||||
|
if (lastBlockRange == null ||
|
||||||
|
lastBlockRange.From != blockRange.From ||
|
||||||
|
lastBlockRange.To != blockRange.To)
|
||||||
|
{
|
||||||
|
lastBlockRange = blockRange;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private async Task ProcessTimeSegment(ChainState chainState)
|
private async Task ProcessTimeSegment(ChainState chainState)
|
||||||
{
|
{
|
||||||
var outgoingRewards = new List<RewardUsersCommand>();
|
var outgoingRewards = new List<RewardUsersCommand>();
|
||||||
|
@ -58,13 +79,17 @@ namespace TestNetRewarder
|
||||||
Rewards = outgoingRewards.ToArray()
|
Rewards = outgoingRewards.ToArray()
|
||||||
};
|
};
|
||||||
|
|
||||||
log.Debug("Sending rewards: " + JsonConvert.SerializeObject(cmd));
|
log.Log("Sending rewards: " + JsonConvert.SerializeObject(cmd));
|
||||||
return await Program.BotClient.SendRewards(cmd);
|
return await Program.BotClient.SendRewards(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProcessReward(List<RewardUsersCommand> outgoingRewards, RewardConfig reward, ChainState chainState)
|
private void ProcessReward(List<RewardUsersCommand> outgoingRewards, RewardConfig reward, ChainState chainState)
|
||||||
{
|
{
|
||||||
var winningAddresses = PerformCheck(reward, chainState);
|
var winningAddresses = PerformCheck(reward, chainState);
|
||||||
|
foreach (var win in winningAddresses)
|
||||||
|
{
|
||||||
|
log.Log($"Address '{win.Address}' wins '{reward.Message}'");
|
||||||
|
}
|
||||||
if (winningAddresses.Any())
|
if (winningAddresses.Any())
|
||||||
{
|
{
|
||||||
outgoingRewards.Add(new RewardUsersCommand
|
outgoingRewards.Add(new RewardUsersCommand
|
||||||
|
|
|
@ -47,7 +47,7 @@ namespace TestNetRewarder
|
||||||
{
|
{
|
||||||
await EnsureBotOnline();
|
await EnsureBotOnline();
|
||||||
await segmenter.WaitForNextSegment(processor.ProcessTimeSegment);
|
await segmenter.WaitForNextSegment(processor.ProcessTimeSegment);
|
||||||
await Task.Delay(1000, CancellationToken);
|
await Task.Delay(100, CancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue