-
Notifications
You must be signed in to change notification settings - Fork 1k
Exec Factor with decimals #4278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 15 commits
c4cd0cc
3860b18
a3309ca
e0af41f
583f872
177cf49
cfda0b0
4b525be
14d7cd7
66d05f0
434a32f
94a03ad
05815b9
e06694b
687b612
4521159
189d839
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,7 +53,7 @@ public sealed class PolicyContract : NativeContract | |
| /// <summary> | ||
| /// The maximum execution fee factor that the committee can set. | ||
| /// </summary> | ||
| public const uint MaxExecFeeFactor = 100; | ||
| public const ulong MaxExecFeeFactor = 100; | ||
|
|
||
| /// <summary> | ||
| /// The maximum fee for attribute that the committee can set. | ||
|
|
@@ -132,6 +132,16 @@ internal override ContractTask InitializeAsync(ApplicationEngine engine, Hardfor | |
| engine.SnapshotCache.Add(_maxValidUntilBlockIncrement, new StorageItem(engine.ProtocolSettings.MaxValidUntilBlockIncrement)); | ||
| engine.SnapshotCache.Add(_maxTraceableBlocks, new StorageItem(engine.ProtocolSettings.MaxTraceableBlocks)); | ||
| } | ||
|
|
||
| // After Faun Hardfork the unit it's pico-gas, before it was datoshi | ||
|
|
||
| if (hardfork == Hardfork.HF_Faun) | ||
| { | ||
| // Add decimals to exec fee factor | ||
| var item = engine.SnapshotCache.TryGet(_execFeeFactor) ?? | ||
| throw new InvalidOperationException("Policy was not initialized"); | ||
| item.Set((uint)(BigInteger)item * ApplicationEngine.FeeFactor); | ||
| } | ||
| return ContractTask.CompletedTask; | ||
| } | ||
|
|
||
|
|
@@ -149,12 +159,34 @@ public long GetFeePerByte(IReadOnlyStore snapshot) | |
| /// <summary> | ||
| /// Gets the execution fee factor. This is a multiplier that can be adjusted by the committee to adjust the system fees for transactions. | ||
| /// </summary> | ||
| /// <param name="snapshot">The snapshot used to read data.</param> | ||
| /// <param name="engine">The execution engine.</param> | ||
| /// <returns>The execution fee factor.</returns> | ||
| [ContractMethod(CpuFee = 1 << 15, RequiredCallFlags = CallFlags.ReadStates)] | ||
| public uint GetExecFeeFactor(IReadOnlyStore snapshot) | ||
| public uint GetExecFeeFactor(ApplicationEngine engine) | ||
| { | ||
| if (engine.IsHardforkEnabled(Hardfork.HF_Faun)) | ||
| return (uint)((BigInteger)engine.SnapshotCache[_execFeeFactor] / ApplicationEngine.FeeFactor); | ||
|
|
||
| return (uint)(BigInteger)engine.SnapshotCache[_execFeeFactor]; | ||
| } | ||
|
|
||
| public long GetExecFeeFactor(ProtocolSettings settings, IReadOnlyStore snapshot, uint index) | ||
| { | ||
| if (settings.IsHardforkEnabled(Hardfork.HF_Faun, index)) | ||
| return (long)((BigInteger)snapshot[_execFeeFactor] / ApplicationEngine.FeeFactor); | ||
|
|
||
| return (long)(BigInteger)snapshot[_execFeeFactor]; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the execution fee factor. This is a multiplier that can be adjusted by the committee to adjust the system fees for transactions. | ||
| /// </summary> | ||
| /// <param name="engine">The execution engine.</param> | ||
| /// <returns>The execution fee factor in the unit of pico Gas. 1 picoGAS = 1e-12 GAS</returns> | ||
| [ContractMethod(Hardfork.HF_Faun, CpuFee = 1 << 15, RequiredCallFlags = CallFlags.ReadStates)] | ||
| public BigInteger GetExecPicoFeeFactor(ApplicationEngine engine) | ||
| { | ||
| return (uint)(BigInteger)snapshot[_execFeeFactor]; | ||
| return (BigInteger)engine.SnapshotCache[_execFeeFactor]; | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -341,12 +373,15 @@ private void SetFeePerByte(ApplicationEngine engine, long value) | |
| } | ||
|
|
||
| [ContractMethod(CpuFee = 1 << 15, RequiredCallFlags = CallFlags.States)] | ||
| private void SetExecFeeFactor(ApplicationEngine engine, uint value) | ||
| private void SetExecFeeFactor(ApplicationEngine engine, ulong value) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not we add a
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case, if there is a v2 value, we will ignore the v1 value.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems simple if we don't have an extra method, just change the factor |
||
| { | ||
| if (value == 0 || value > MaxExecFeeFactor) | ||
| throw new ArgumentOutOfRangeException(nameof(value), $"ExecFeeFactor must be between [1, {MaxExecFeeFactor}], got {value}"); | ||
| AssertCommittee(engine); | ||
| // After FAUN hardfork, the max exec fee factor is with decimals defined in ApplicationEngine.FeeFactor | ||
| var maxValue = engine.IsHardforkEnabled(Hardfork.HF_Faun) ? ApplicationEngine.FeeFactor * MaxExecFeeFactor : MaxExecFeeFactor; | ||
|
|
||
| if (value == 0 || value > maxValue) | ||
| throw new ArgumentOutOfRangeException(nameof(value), $"ExecFeeFactor must be between [1, {maxValue}], got {value}"); | ||
|
|
||
| AssertCommittee(engine); | ||
| engine.SnapshotCache.GetAndChange(_execFeeFactor)!.Set(value); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.