Skip to content

Commit 7849a81

Browse files
dzajkowskicraigem
authored andcommitted
'calculateGasLimit' set to parent value
1 parent b6a26f8 commit 7849a81

File tree

2 files changed

+70
-16
lines changed

2 files changed

+70
-16
lines changed

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: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ 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(
43+
nonce = minedNonce,
44+
mixHash = minedMixHash,
45+
unixTimestamp = miningTimestamp,
46+
gasLimit = generatedBlockGasLimit
47+
)
4348
)
4449
validators.blockHeaderValidator.validate(
4550
fullBlock.header,
@@ -61,7 +66,12 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
6166
val miningTimestamp = 1508752265
6267

6368
val fullBlock = pendingBlock.block.copy(header =
64-
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp)
69+
pendingBlock.block.header.copy(
70+
nonce = minedNonce,
71+
mixHash = minedMixHash,
72+
unixTimestamp = miningTimestamp,
73+
gasLimit = generatedBlockGasLimit
74+
)
6575
)
6676
validators.blockHeaderValidator.validate(
6777
fullBlock.header,
@@ -83,7 +93,12 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
8393
val miningTimestamp = 1508752265
8494

8595
val fullBlock = pendingBlock.block.copy(header =
86-
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp)
96+
pendingBlock.block.header.copy(
97+
nonce = minedNonce,
98+
mixHash = minedMixHash,
99+
unixTimestamp = miningTimestamp,
100+
gasLimit = generatedBlockGasLimit
101+
)
87102
)
88103

89104
// Import Block, to create some existing state
@@ -132,7 +147,12 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
132147
val miningTimestamp = 1508752389
133148

134149
val fullBlock = pendingBlock.block.copy(header =
135-
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp)
150+
pendingBlock.block.header.copy(
151+
nonce = minedNonce,
152+
mixHash = minedMixHash,
153+
unixTimestamp = miningTimestamp,
154+
gasLimit = generatedBlockGasLimit
155+
)
136156
)
137157
validators.blockHeaderValidator.validate(
138158
fullBlock.header,
@@ -165,7 +185,12 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
165185
val miningTimestamp = 1508752492
166186

167187
val fullBlock = pendingBlock.block.copy(header =
168-
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp)
188+
pendingBlock.block.header.copy(
189+
nonce = minedNonce,
190+
mixHash = minedMixHash,
191+
unixTimestamp = miningTimestamp,
192+
gasLimit = generatedBlockGasLimit
193+
)
169194
)
170195

171196
validators.blockHeaderValidator.validate(
@@ -233,7 +258,12 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
233258

234259
val fullBlock =
235260
pendingBlock.block.copy(header =
236-
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp)
261+
pendingBlock.block.header.copy(
262+
nonce = minedNonce,
263+
mixHash = minedMixHash,
264+
unixTimestamp = miningTimestamp,
265+
gasLimit = generatedBlockGasLimit
266+
)
237267
)
238268
validators.blockHeaderValidator.validate(
239269
fullBlock.header,
@@ -323,7 +353,12 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
323353

324354
val fullBlock =
325355
pendingBlock.block.copy(header =
326-
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp)
356+
pendingBlock.block.header.copy(
357+
nonce = minedNonce,
358+
mixHash = minedMixHash,
359+
unixTimestamp = miningTimestamp,
360+
gasLimit = generatedBlockGasLimit
361+
)
327362
)
328363
validators.blockHeaderValidator.validate(fullBlock.header, blockchain.getBlockHeaderByHash) shouldBe Right(
329364
BlockHeaderValid
@@ -355,7 +390,12 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
355390

356391
val fullBlock =
357392
pendingBlock.block.copy(header =
358-
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp)
393+
pendingBlock.block.header.copy(
394+
nonce = minedNonce,
395+
mixHash = minedMixHash,
396+
unixTimestamp = miningTimestamp,
397+
gasLimit = generatedBlockGasLimit
398+
)
359399
)
360400
validators.blockHeaderValidator.validate(fullBlock.header, blockchain.getBlockHeaderByHash) shouldBe Right(
361401
BlockHeaderValid
@@ -400,7 +440,12 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
400440
val miningTimestamp = 1499721182
401441

402442
val fullBlock = pendingBlock.block.copy(header =
403-
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp)
443+
pendingBlock.block.header.copy(
444+
nonce = minedNonce,
445+
mixHash = minedMixHash,
446+
unixTimestamp = miningTimestamp,
447+
gasLimit = generatedBlockGasLimit
448+
)
404449
)
405450
validators.blockHeaderValidator.validate(fullBlock.header, blockchain.getBlockHeaderByHash) shouldBe Right(
406451
BlockHeaderValid
@@ -432,7 +477,12 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
432477
val miningTimestamp = 1508752698
433478

434479
val fullBlock = pendingBlock.block.copy(header =
435-
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp)
480+
pendingBlock.block.header.copy(
481+
nonce = minedNonce,
482+
mixHash = minedMixHash,
483+
unixTimestamp = miningTimestamp,
484+
gasLimit = generatedBlockGasLimit
485+
)
436486
)
437487
validators.blockHeaderValidator.validate(fullBlock.header, blockchain.getBlockHeaderByHash) shouldBe Right(
438488
BlockHeaderValid
@@ -562,6 +612,10 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
562612
lazy val blockExecution =
563613
new BlockExecution(blockchain, blockchainConfig, consensus.blockPreparator, blockValidation)
564614

615+
// FIXME: the change in gas limit voting strategy caused the hardcoded nonce and mixHash in this file to be invalid
616+
// The gas limit of all the generated blocks has to be set to the old strategy of increasing as much as possible
617+
// the gas limit, if not PoW validations will fail
618+
val generatedBlockGasLimit = 16733003
565619
}
566620
}
567621

0 commit comments

Comments
 (0)