Gas price index on a 7-day cycle

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ZHU MINCHAOandClaude Opus 5.5 committed 2026-11-03 23:32:50 +08:00
1 parent dbba8b4376
commit 50c119697e
9 files changed
+32 -6

No files matched your search

+3
View File
@@ -144,6 +144,9 @@ namespace Decentralized.Domain
/// <summary>转账手续费(信用点等值,按转出的币扣):慢 / 普通 / 快;拥堵时乘以倍数。</summary>
public const double TxFeeSlow = 0.5, TxFeeNormal = 1.5, TxFeeFast = 4, TxCongestedFeeMult = 4;
/// <summary>Gas 价格指数:以 GasPeriod 天为周期正弦涨跌,振幅 GasAmp(0.5×–1.5×),每天再乘 1 ± GasNoise 的随机波动。</summary>
public const int TxGasPeriod = 7;
public const double TxGasAmp = 0.5, TxGasNoise = 0.15;
/// <summary>网络拥堵:每晚开始拥堵的概率、持续天数上限;拥堵时普通档、慢档的确认间隔倍数,慢档被挤出内存池的概率。</summary>
public const double TxCongestionChance = 0.12, TxCongestedNormalSlow = 2, TxCongestedSlowSlow = 3.5, TxSlowDrop = 0.3;
public const int TxCongestionDaysMax = 2;
+8 -2
View File
@@ -18,8 +18,14 @@ namespace Decentralized.Domain
public static class TxRules
{
/// <summary>手续费(信用点等值,按转出的币扣):档位基础价 × 拥堵倍数。</summary>
public static double FeeCredits(FeeTier t, bool congested) =>
(t == FeeTier.Slow ? Tuning.TxFeeSlow : t == FeeTier.Normal ? Tuning.TxFeeNormal : Tuning.TxFeeFast) * (congested ? Tuning.TxCongestedFeeMult : 1);
public static double FeeCredits(FeeTier t, bool congested, double gas = 1) =>
(t == FeeTier.Slow ? Tuning.TxFeeSlow : t == FeeTier.Normal ? Tuning.TxFeeNormal : Tuning.TxFeeFast) * gas * (congested ? Tuning.TxCongestedFeeMult : 1);
/// <summary>Gas 周期部分:phase 是这一局的起始相位(0..周期-1)。</summary>
public static double GasCycle(int day, int phase) => 1 + Tuning.TxGasAmp * System.Math.Sin(2 * System.Math.PI * (day + phase) / Tuning.TxGasPeriod);
/// <summary>某天的 gas 指数:周期 × (1 ± 随机波动)。</summary>
public static double Gas(int day, int phase, Rng rng) => GasCycle(day, phase) * (1 + Tuning.TxGasNoise * (rng.NextDouble() * 2 - 1));
/// <summary>需要的确认数:金额越大越多。</summary>
public static int Confirmations(double valueCredits) =>