Skip to content

Commit 4638db2

Browse files
author
Nicolás Tallar
authored
[ETCM-426] Changed the gas limit strategy to a constant one (#820)
1 parent 8476c04 commit 4638db2

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed

src/main/resources/chains/testnet-internal-gac-genesis.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"extraData": "0x00",
33
"nonce": "0x0000000000000042",
44
"gasLimit": "0x2fefd8",
5-
"_commentAboutDifficulty": "Set to 1000000",
5+
"_commentAboutDifficulty": "Set to 1000000, a value closer to the one achieved by our current testnet with our 30 second block rate",
66
"difficulty": "0xF4240",
77
"ommersHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
8-
"_commentAboutTimestamp": "Set to 11/05/2020 @ 12:00am (UTC)",
8+
"_commentAboutTimestamp": "Set to 11/05/2020 @ 12:00am (UTC), to be closer to our release date and not affect as much the difficulty calculations",
99
"timestamp": "0x5FA34080",
1010
"coinbase": "0x0000000000000000000000000000000000000000",
1111
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",

src/main/resources/chains/testnet-internal-nomad-genesis.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
22
"extraData": "0x00",
33
"nonce": "0x0000000000000042",
4-
"gasLimit": "0x2fefd8",
5-
"_commentAboutDifficulty": "Set to 1000000",
4+
"_commentAboutGasLimit": "Set to 8 million (value used in ETC mainnet)",
5+
"gasLimit": "0x7A1200",
6+
"_commentAboutDifficulty": "Set to 1000000, a value closer to the one achieved by our current testnet with our 30 second block rate",
67
"difficulty": "0xF4240",
78
"ommersHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
8-
"_commentAboutTimestamp": "Set to 11/05/2020 @ 12:00am (UTC)",
9+
"_commentAboutTimestamp": "Set to 11/05/2020 @ 12:00am (UTC), to be closer to our release date and not affect as much the difficulty calculations",
910
"timestamp": "0x5FA34080",
1011
"coinbase": "0x0000000000000000000000000000000000000000",
1112
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",

src/main/scala/io/iohk/ethereum/consensus/blocks/BlockGeneratorSkeleton.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,13 @@ abstract class BlockGeneratorSkeleton(
163163
transactionsForBlock
164164
}
165165

166-
//returns maximal limit to be able to include as many transactions as possible
167-
protected def calculateGasLimit(parentGas: BigInt): BigInt = {
168-
val GasLimitBoundDivisor: Int = 1024
166+
/*
167+
Returns the same gas limit as the parent block
169168
170-
val gasLimitDifference = parentGas / GasLimitBoundDivisor
171-
parentGas + gasLimitDifference - 1
172-
}
169+
In Mantis only testnets (and without this changed), this means that all blocks will have the same gasLimit as
170+
the genesis block
171+
*/
172+
protected def calculateGasLimit(parentGas: BigInt): BigInt = parentGas
173173

174174
protected def buildMpt[K](entities: Seq[K], vSerializable: ByteArraySerializable[K]): ByteString = {
175175
val stateStorage = StateStorage.getReadOnlyStorage(EphemDataSource())

src/test/scala/io/iohk/ethereum/consensus/BlockGeneratorSpec.scala

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
3939
val miningTimestamp = 1508751768
4040

4141
val fullBlock = pendingBlock.block.copy(header =
42-
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp)
42+
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp, gasLimit = generatedBlockGasLimit)
4343
)
4444
validators.blockHeaderValidator.validate(
4545
fullBlock.header,
@@ -61,7 +61,7 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
6161
val miningTimestamp = 1508752265
6262

6363
val fullBlock = pendingBlock.block.copy(header =
64-
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp)
64+
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp, gasLimit = generatedBlockGasLimit)
6565
)
6666
validators.blockHeaderValidator.validate(
6767
fullBlock.header,
@@ -83,7 +83,7 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
8383
val miningTimestamp = 1508752265
8484

8585
val fullBlock = pendingBlock.block.copy(header =
86-
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp)
86+
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp, gasLimit = generatedBlockGasLimit)
8787
)
8888

8989
// Import Block, to create some existing state
@@ -132,7 +132,7 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
132132
val miningTimestamp = 1508752389
133133

134134
val fullBlock = pendingBlock.block.copy(header =
135-
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp)
135+
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp, gasLimit = generatedBlockGasLimit)
136136
)
137137
validators.blockHeaderValidator.validate(
138138
fullBlock.header,
@@ -165,7 +165,7 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
165165
val miningTimestamp = 1508752492
166166

167167
val fullBlock = pendingBlock.block.copy(header =
168-
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp)
168+
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp, gasLimit = generatedBlockGasLimit)
169169
)
170170

171171
validators.blockHeaderValidator.validate(
@@ -233,7 +233,7 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
233233

234234
val fullBlock =
235235
pendingBlock.block.copy(header =
236-
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp)
236+
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp, gasLimit = generatedBlockGasLimit)
237237
)
238238
validators.blockHeaderValidator.validate(
239239
fullBlock.header,
@@ -323,7 +323,7 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
323323

324324
val fullBlock =
325325
pendingBlock.block.copy(header =
326-
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp)
326+
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp, gasLimit = generatedBlockGasLimit)
327327
)
328328
validators.blockHeaderValidator.validate(fullBlock.header, blockchain.getBlockHeaderByHash) shouldBe Right(
329329
BlockHeaderValid
@@ -355,7 +355,7 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
355355

356356
val fullBlock =
357357
pendingBlock.block.copy(header =
358-
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp)
358+
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp, gasLimit = generatedBlockGasLimit)
359359
)
360360
validators.blockHeaderValidator.validate(fullBlock.header, blockchain.getBlockHeaderByHash) shouldBe Right(
361361
BlockHeaderValid
@@ -400,7 +400,7 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
400400
val miningTimestamp = 1499721182
401401

402402
val fullBlock = pendingBlock.block.copy(header =
403-
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp)
403+
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp, gasLimit = generatedBlockGasLimit)
404404
)
405405
validators.blockHeaderValidator.validate(fullBlock.header, blockchain.getBlockHeaderByHash) shouldBe Right(
406406
BlockHeaderValid
@@ -432,7 +432,7 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
432432
val miningTimestamp = 1508752698
433433

434434
val fullBlock = pendingBlock.block.copy(header =
435-
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp)
435+
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp, gasLimit = generatedBlockGasLimit)
436436
)
437437
validators.blockHeaderValidator.validate(fullBlock.header, blockchain.getBlockHeaderByHash) shouldBe Right(
438438
BlockHeaderValid
@@ -562,6 +562,10 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
562562
lazy val blockExecution =
563563
new BlockExecution(blockchain, blockchainConfig, consensus.blockPreparator, blockValidation)
564564

565+
// FIXME: the change in gas limit voting strategy caused the hardcoded nonce and mixHash in this file to be invalid
566+
// The gas limit of all the generated blocks has to be set to the old strategy of increasing as much as possible
567+
// the gas limit, if not PoW validations will fail
568+
val generatedBlockGasLimit = 16733003
565569
}
566570
}
567571

0 commit comments

Comments
 (0)