Skip to content

Commit 4ec8a3b

Browse files
committed
Remove MinGasPrice calculation
1 parent 59a14ca commit 4ec8a3b

10 files changed

+13
-216
lines changed

contracts/interfaces/INodeDriver.sol

-9
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,6 @@ interface INodeDriver {
3131
uint256[] calldata originatedTxsFee
3232
) external;
3333

34-
/// Seal epoch. To be called BEFORE epoch sealing made by the client itself - currently not used.
35-
function sealEpochV1(
36-
uint256[] calldata offlineTimes,
37-
uint256[] calldata offlineBlocks,
38-
uint256[] calldata uptimes,
39-
uint256[] calldata originatedTxsFee,
40-
uint256 usedGas
41-
) external;
42-
4334
/// Seal epoch. Called AFTER epoch sealing made by the client itself.
4435
function sealEpochValidators(uint256[] calldata nextValidatorIDs) external;
4536
}

contracts/interfaces/ISFC.sol

+1-2
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ interface ISFC {
151151
uint256[] calldata offlineTime,
152152
uint256[] calldata offlineBlocks,
153153
uint256[] calldata uptimes,
154-
uint256[] calldata originatedTxsFee,
155-
uint256 epochGas
154+
uint256[] calldata originatedTxsFee
156155
) external;
157156

158157
function sealEpochValidators(uint256[] calldata nextValidatorIDs) external;

contracts/sfc/GasPriceConstants.sol

-33
This file was deleted.

contracts/sfc/Migrations.sol

-35
This file was deleted.

contracts/sfc/NodeDriver.sol

+1-12
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,7 @@ contract NodeDriver is Initializable, INodeDriver {
139139
uint256[] calldata uptimes,
140140
uint256[] calldata originatedTxsFee
141141
) external onlyNode {
142-
backend.sealEpoch(offlineTimes, offlineBlocks, uptimes, originatedTxsFee, 841669690);
143-
}
144-
145-
/// Seal epoch. To be called BEFORE epoch sealing made by the client itself - currently not used.
146-
function sealEpochV1(
147-
uint256[] calldata offlineTimes,
148-
uint256[] calldata offlineBlocks,
149-
uint256[] calldata uptimes,
150-
uint256[] calldata originatedTxsFee,
151-
uint256 usedGas
152-
) external onlyNode {
153-
backend.sealEpoch(offlineTimes, offlineBlocks, uptimes, originatedTxsFee, usedGas);
142+
backend.sealEpoch(offlineTimes, offlineBlocks, uptimes, originatedTxsFee);
154143
}
155144

156145
/// Seal epoch. Called AFTER epoch sealing made by the client itself.

contracts/sfc/NodeDriverAuth.sol

+2-9
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,6 @@ contract NodeDriverAuth is Initializable, Ownable {
114114
driver.updateNetworkRules(diff);
115115
}
116116

117-
/// Update MinGasPrice. Called by SFC during epoch sealing.
118-
function updateMinGasPrice(uint256 minGasPrice) external onlySFC {
119-
// prettier-ignore
120-
driver.updateNetworkRules(bytes(strConcat("{\"Economy\":{\"MinGasPrice\":", uint256ToStr(minGasPrice), "}}")));
121-
}
122-
123117
/// Update advertised network version.
124118
function updateNetworkVersion(uint256 version) external onlyOwner {
125119
driver.updateNetworkVersion(version);
@@ -166,10 +160,9 @@ contract NodeDriverAuth is Initializable, Ownable {
166160
uint256[] calldata offlineTimes,
167161
uint256[] calldata offlineBlocks,
168162
uint256[] calldata uptimes,
169-
uint256[] calldata originatedTxsFee,
170-
uint256 usedGas
163+
uint256[] calldata originatedTxsFee
171164
) external onlyDriver {
172-
sfc.sealEpoch(offlineTimes, offlineBlocks, uptimes, originatedTxsFee, usedGas);
165+
sfc.sealEpoch(offlineTimes, offlineBlocks, uptimes, originatedTxsFee);
173166
}
174167

175168
/// Seal epoch. Called AFTER epoch sealing made by the client itself.

contracts/sfc/SFC.sol

+1-31
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {Initializable} from "../common/Initializable.sol";
66
import {Decimal} from "../common/Decimal.sol";
77
import {NodeDriverAuth} from "./NodeDriverAuth.sol";
88
import {ConstantsManager} from "./ConstantsManager.sol";
9-
import {GP} from "./GasPriceConstants.sol";
109
import {Version} from "../version/Version.sol";
1110

1211
/**
@@ -98,9 +97,6 @@ contract SFC is Initializable, Ownable, Version {
9897
// validator ID -> slashing refund ratio (allows to withdraw slashed stake)
9998
mapping(uint256 validatorID => uint256 refundRatio) public slashingRefundRatio;
10099

101-
// the minimal gas price calculated for the current epoch
102-
uint256 public minGasPrice;
103-
104100
// the treasure contract (receives unlock penalties and a part of epoch fees)
105101
address public treasuryAddress;
106102

@@ -226,7 +222,6 @@ contract SFC is Initializable, Ownable, Version {
226222
node = NodeDriverAuth(nodeDriver);
227223
c = ConstantsManager(_c);
228224
totalSupply = _totalSupply;
229-
minGasPrice = GP.initialMinGasPrice();
230225
getEpochSnapshot[sealedEpoch].endTime = _now();
231226
}
232227

@@ -311,8 +306,7 @@ contract SFC is Initializable, Ownable, Version {
311306
uint256[] calldata offlineTime,
312307
uint256[] calldata offlineBlocks,
313308
uint256[] calldata uptimes,
314-
uint256[] calldata originatedTxsFee,
315-
uint256 epochGas
309+
uint256[] calldata originatedTxsFee
316310
) external onlyDriver {
317311
EpochSnapshot storage snapshot = getEpochSnapshot[currentEpoch()];
318312
uint256[] memory validatorIDs = snapshot.validatorIDs;
@@ -325,7 +319,6 @@ contract SFC is Initializable, Ownable, Version {
325319
epochDuration = _now() - prevSnapshot.endTime;
326320
}
327321
_sealEpochRewards(epochDuration, snapshot, prevSnapshot, validatorIDs, uptimes, originatedTxsFee);
328-
_sealEpochMinGasPrice(epochDuration, epochGas);
329322
}
330323

331324
currentSealedEpoch = currentEpoch();
@@ -336,7 +329,6 @@ contract SFC is Initializable, Ownable, Version {
336329
}
337330

338331
/// Finish epoch sealing - store validators of the new epoch into a snapshot.
339-
/// Apply minGasPrice calculated in the sealEpoch().
340332
/// This method is called AFTER the epoch sealing made by the client itself.
341333
function sealEpochValidators(uint256[] calldata nextValidatorIDs) external onlyDriver {
342334
EpochSnapshot storage snapshot = getEpochSnapshot[currentEpoch()];
@@ -348,7 +340,6 @@ contract SFC is Initializable, Ownable, Version {
348340
snapshot.totalStake = snapshot.totalStake + receivedStake;
349341
}
350342
snapshot.validatorIDs = nextValidatorIDs;
351-
node.updateMinGasPrice(minGasPrice);
352343
}
353344

354345
/// Set an initial validator.
@@ -941,27 +932,6 @@ contract SFC is Initializable, Ownable, Version {
941932
}
942933
}
943934

944-
/// Seal epoch - calculate min gas price for the next epoch.
945-
function _sealEpochMinGasPrice(uint256 epochDuration, uint256 epochGas) internal {
946-
// change minGasPrice proportionally to the difference between target and received epochGas
947-
uint256 targetEpochGas = epochDuration * c.targetGasPowerPerSecond() + 1;
948-
uint256 gasPriceDeltaRatio = (epochGas * Decimal.unit()) / targetEpochGas;
949-
uint256 counterweight = c.gasPriceBalancingCounterweight();
950-
// scale down the change speed (estimate gasPriceDeltaRatio ^ (epochDuration / counterweight))
951-
gasPriceDeltaRatio =
952-
(epochDuration * gasPriceDeltaRatio + counterweight * Decimal.unit()) /
953-
(epochDuration + counterweight);
954-
// limit the max/min possible delta in one epoch
955-
gasPriceDeltaRatio = GP.trimGasPriceChangeRatio(gasPriceDeltaRatio);
956-
957-
// apply the ratio
958-
uint256 newMinGasPrice = (minGasPrice * gasPriceDeltaRatio) / Decimal.unit();
959-
// limit the max/min possible minGasPrice
960-
newMinGasPrice = GP.trimMinGasPrice(newMinGasPrice);
961-
// apply new minGasPrice
962-
minGasPrice = newMinGasPrice;
963-
}
964-
965935
/// Create a new validator.
966936
function _createValidator(address auth, bytes memory pubkey) internal {
967937
uint256 validatorID = ++lastValidatorID;

test/NodeDriver.ts

-4
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,6 @@ describe('NodeDriver', () => {
155155
this.nodeDriver,
156156
'NotNode',
157157
);
158-
await expect(this.nodeDriver.sealEpochV1([0, 1], [0, 1], [0, 1], [0, 1], 0)).to.be.revertedWithCustomError(
159-
this.nodeDriver,
160-
'NotNode',
161-
);
162158
});
163159
});
164160
});

test/SFC.ts

+7-80
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe('SFC', () => {
6666
});
6767

6868
it('Should revert when sealEpoch not called by node', async function () {
69-
await expect(this.sfc.sealEpoch([1], [1], [1], [1], 0)).to.be.revertedWithCustomError(this.sfc, 'NotDriverAuth');
69+
await expect(this.sfc.sealEpoch([1], [1], [1], [1])).to.be.revertedWithCustomError(this.sfc, 'NotDriverAuth');
7070
});
7171

7272
it('Should revert when SealEpochValidators not called by node', async function () {
@@ -372,11 +372,11 @@ describe('SFC', () => {
372372
expect(await this.sfc.currentEpoch.call()).to.equal(1);
373373
expect(await this.sfc.currentSealedEpoch()).to.equal(0);
374374
await this.sfc.enableNonNodeCalls();
375-
await this.sfc.sealEpoch([100, 101, 102], [100, 101, 102], [100, 101, 102], [100, 101, 102], 0);
375+
await this.sfc.sealEpoch([100, 101, 102], [100, 101, 102], [100, 101, 102], [100, 101, 102]);
376376
expect(await this.sfc.currentEpoch.call()).to.equal(2);
377377
expect(await this.sfc.currentSealedEpoch()).to.equal(1);
378378
for (let i = 0; i < 4; i++) {
379-
await this.sfc.sealEpoch([100, 101, 102], [100, 101, 102], [100, 101, 102], [100, 101, 102], 0);
379+
await this.sfc.sealEpoch([100, 101, 102], [100, 101, 102], [100, 101, 102], [100, 101, 102]);
380380
}
381381
expect(await this.sfc.currentEpoch.call()).to.equal(6);
382382
expect(await this.sfc.currentSealedEpoch()).to.equal(5);
@@ -385,7 +385,7 @@ describe('SFC', () => {
385385
it('Should succeed and return endBlock', async function () {
386386
const epochNumber = await this.sfc.currentEpoch();
387387
await this.sfc.enableNonNodeCalls();
388-
await this.sfc.sealEpoch([100, 101, 102], [100, 101, 102], [100, 101, 102], [100, 101, 102], 0);
388+
await this.sfc.sealEpoch([100, 101, 102], [100, 101, 102], [100, 101, 102], [100, 101, 102]);
389389
const lastBlock = await ethers.provider.getBlockNumber();
390390
// endBlock is on second position
391391
expect((await this.sfc.getEpochSnapshot(epochNumber))[1]).to.equal(lastBlock);
@@ -506,79 +506,6 @@ describe('SFC', () => {
506506
expect(node.nextValidatorWeights.get(secondValidatorID)).to.equal(ethers.parseEther('0.6825'));
507507
expect(node.nextValidatorWeights.get(thirdValidatorID)).to.equal(ethers.parseEther('0.4'));
508508
});
509-
510-
it('Should succeed and balance gas price', async function () {
511-
const [validator] = await ethers.getSigners();
512-
await this.sfc.enableNonNodeCalls();
513-
514-
await this.constants.updateGasPriceBalancingCounterweight(24 * 60 * 60);
515-
await this.sfc.rebaseTime();
516-
517-
await this.sfc
518-
.connect(validator)
519-
.createValidator(ethers.Wallet.createRandom().publicKey, { value: ethers.parseEther('1') });
520-
521-
await this.constants.updateTargetGasPowerPerSecond(1000);
522-
await this.sfc.sealEpoch([1], [1], [1], [1], 1_000);
523-
await this.sfc.sealEpochValidators([1]);
524-
525-
expect(await this.sfc.minGasPrice()).to.equal(95_000_000_000);
526-
527-
await this.sfc.advanceTime(1);
528-
await this.sfc.sealEpoch([1], [1], [1], [1], 1_000);
529-
await this.sfc.sealEpochValidators([1]);
530-
expect(await this.sfc.minGasPrice()).to.equal(94_999_998_901);
531-
532-
await this.sfc.advanceTime(2);
533-
await this.sfc.sealEpoch([1], [1], [1], [1], 2_000);
534-
await this.sfc.sealEpochValidators([1]);
535-
expect(await this.sfc.minGasPrice()).to.equal(94_999_997_802);
536-
537-
await this.sfc.advanceTime(1_000);
538-
await this.sfc.sealEpoch([1], [1], [1], [1], 1_000_000);
539-
await this.sfc.sealEpochValidators([1]);
540-
expect(await this.sfc.minGasPrice()).to.equal(94_999_996_715);
541-
542-
await this.sfc.advanceTime(1_000);
543-
await this.sfc.sealEpoch([1], [1], [1], [1], 666_666);
544-
await this.sfc.sealEpochValidators([1]);
545-
expect(await this.sfc.minGasPrice()).to.equal(94_637_676_437);
546-
547-
await this.sfc.advanceTime(1_000);
548-
await this.sfc.sealEpoch([1], [1], [1], [1], 1_500_000);
549-
await this.sfc.sealEpochValidators([1]);
550-
expect(await this.sfc.minGasPrice()).to.equal(95_179_080_284);
551-
552-
await this.sfc.advanceTime(1);
553-
await this.sfc.sealEpoch([1], [1], [1], [1], 666);
554-
await this.sfc.sealEpochValidators([1]);
555-
expect(await this.sfc.minGasPrice()).to.equal(95_178_711_617);
556-
557-
await this.sfc.advanceTime(1);
558-
await this.sfc.sealEpoch([1], [1], [1], [1], 1_500);
559-
await this.sfc.sealEpochValidators([1]);
560-
expect(await this.sfc.minGasPrice()).to.equal(95_179_260_762);
561-
562-
await this.sfc.advanceTime(1_000);
563-
await this.sfc.sealEpoch([1], [1], [1], [1], 10_000_000_000);
564-
await this.sfc.sealEpochValidators([1]);
565-
expect(await this.sfc.minGasPrice()).to.equal(99_938_223_800);
566-
567-
await this.sfc.advanceTime(10_000);
568-
await this.sfc.sealEpoch([1], [1], [1], [1], 0);
569-
await this.sfc.sealEpochValidators([1]);
570-
expect(await this.sfc.minGasPrice()).to.equal(94_941_312_610);
571-
572-
await this.sfc.advanceTime(100);
573-
await this.sfc.sealEpoch([1], [1], [1], [1], 200_000);
574-
await this.sfc.sealEpochValidators([1]);
575-
expect(await this.sfc.minGasPrice()).to.equal(95_051_069_157);
576-
577-
await this.sfc.advanceTime(100);
578-
await this.sfc.sealEpoch([1], [1], [1], [1], 50_000);
579-
await this.sfc.sealEpochValidators([1]);
580-
expect(await this.sfc.minGasPrice()).to.equal(94_996_125_793);
581-
});
582509
});
583510

584511
describe('Staking / Sealed Epoch functions', () => {
@@ -741,7 +668,7 @@ describe('SFC', () => {
741668
}
742669

743670
await this.sfc.advanceTime(24 * 60 * 60);
744-
await this.sfc.sealEpoch(offlineTimes, offlineBlocks, uptimes, originatedTxsFees, 0);
671+
await this.sfc.sealEpoch(offlineTimes, offlineBlocks, uptimes, originatedTxsFees);
745672
await this.sfc.sealEpochValidators(allValidators);
746673
});
747674

@@ -772,7 +699,7 @@ describe('SFC', () => {
772699
}
773700

774701
await this.sfc.advanceTime(24 * 60 * 60);
775-
await this.sfc.sealEpoch(offlineTimes, offlineBlocks, uptimes, originatedTxsFees, 0);
702+
await this.sfc.sealEpoch(offlineTimes, offlineBlocks, uptimes, originatedTxsFees);
776703
await this.sfc.sealEpochValidators(allValidators);
777704
});
778705

@@ -844,7 +771,7 @@ describe('SFC', () => {
844771

845772
await this.sfc.advanceTime(24 * 60 * 60);
846773
await expect(
847-
this.nodeDriverAuth.sealEpoch(offlineTimes, offlineBlocks, uptimes, originatedTxsFees, 0),
774+
this.nodeDriverAuth.sealEpoch(offlineTimes, offlineBlocks, uptimes, originatedTxsFees),
848775
).to.be.revertedWithCustomError(this.nodeDriverAuth, 'NotDriver');
849776
});
850777
});

test/helpers/BlockchainNode.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class BlockchainNode {
6565
);
6666

6767
await this.sfc.advanceTime(duration);
68-
await this.handleTx(await this.sfc.sealEpoch(offlineTimes, offlineBlocks, uptimes, originatedTxsFees, 0));
68+
await this.handleTx(await this.sfc.sealEpoch(offlineTimes, offlineBlocks, uptimes, originatedTxsFees));
6969
await this.handleTx(await this.sfc.sealEpochValidators(nextValidatorIds));
7070

7171
// update validators

0 commit comments

Comments
 (0)