Adds randomness to price per byte per second and contract duration

This commit is contained in:
ThatBen 2025-05-02 08:49:43 +02:00
parent c68d4bb13f
commit 3fe2827080
No known key found for this signature in database
GPG Key ID: E020A7DDCD52E1AB

View File

@ -7,6 +7,7 @@ namespace AutoClient
public class CodexWrapper
{
private readonly App app;
private static readonly Random r = new Random();
public CodexWrapper(App app, ICodexNode node)
{
@ -26,11 +27,11 @@ namespace AutoClient
var result = Node.Marketplace.RequestStorage(new StoragePurchaseRequest(cid)
{
CollateralPerByte = app.Config.CollateralPerByte.TstWei(),
Duration = TimeSpan.FromMinutes(app.Config.ContractDurationMinutes),
Duration = GetDuration(),
Expiry = TimeSpan.FromMinutes(app.Config.ContractExpiryMinutes),
MinRequiredNumberOfNodes = Convert.ToUInt32(app.Config.NumHosts),
NodeFailureTolerance = Convert.ToUInt32(app.Config.HostTolerance),
PricePerBytePerSecond = app.Config.PricePerBytePerSecond.TstWei(),
PricePerBytePerSecond = GetPricePerBytePerSecond(),
ProofProbability = 15
});
return result;
@ -40,5 +41,25 @@ namespace AutoClient
{
return Node.GetPurchaseStatus(pid);
}
private TestToken GetPricePerBytePerSecond()
{
var i = app.Config.PricePerBytePerSecond;
i -= 100;
i += r.Next(0, 1000);
return i.TstWei();
}
private TimeSpan GetDuration()
{
var i = app.Config.ContractDurationMinutes;
var day = 60 * 24;
i -= day;
i -= 10; // We don't want to accidentally hit exactly 7 days because that's the limit of the storage node availabilities.
i += r.Next(0, day * 2);
return TimeSpan.FromMinutes(i);
}
}
}