Skip to content

[ETCM-426] Changed the gas limit strategy to a constant one #820

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

Merged
merged 3 commits into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/resources/chains/testnet-internal-gac-genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"extraData": "0x00",
"nonce": "0x0000000000000042",
"gasLimit": "0x2fefd8",
"_commentAboutDifficulty": "Set to 1000000",
"_commentAboutDifficulty": "Set to 1000000, a value closer to the one achieved by our current testnet with our 30 second block rate",
"difficulty": "0xF4240",
"ommersHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"_commentAboutTimestamp": "Set to 11/05/2020 @ 12:00am (UTC)",
"_commentAboutTimestamp": "Set to 11/05/2020 @ 12:00am (UTC), to be closer to our release date and not affect as much the difficulty calculations",
"timestamp": "0x5FA34080",
"coinbase": "0x0000000000000000000000000000000000000000",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
Expand Down
7 changes: 4 additions & 3 deletions src/main/resources/chains/testnet-internal-nomad-genesis.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"extraData": "0x00",
"nonce": "0x0000000000000042",
"gasLimit": "0x2fefd8",
"_commentAboutDifficulty": "Set to 1000000",
"_commentAboutGasLimit": "Set to 8 million (value used in ETC mainnet)",
"gasLimit": "0x7A1200",
"_commentAboutDifficulty": "Set to 1000000, a value closer to the one achieved by our current testnet with our 30 second block rate",
"difficulty": "0xF4240",
"ommersHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"_commentAboutTimestamp": "Set to 11/05/2020 @ 12:00am (UTC)",
"_commentAboutTimestamp": "Set to 11/05/2020 @ 12:00am (UTC), to be closer to our release date and not affect as much the difficulty calculations",
"timestamp": "0x5FA34080",
"coinbase": "0x0000000000000000000000000000000000000000",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,13 @@ abstract class BlockGeneratorSkeleton(
transactionsForBlock
}

//returns maximal limit to be able to include as many transactions as possible
protected def calculateGasLimit(parentGas: BigInt): BigInt = {
val GasLimitBoundDivisor: Int = 1024
/*
Returns the same gas limit as the parent block

val gasLimitDifference = parentGas / GasLimitBoundDivisor
parentGas + gasLimitDifference - 1
}
In Mantis only testnets (and without this changed), this means that all blocks will have the same gasLimit as
the genesis block
*/
protected def calculateGasLimit(parentGas: BigInt): BigInt = parentGas

protected def buildMpt[K](entities: Seq[K], vSerializable: ByteArraySerializable[K]): ByteString = {
val stateStorage = StateStorage.getReadOnlyStorage(EphemDataSource())
Expand Down
24 changes: 14 additions & 10 deletions src/test/scala/io/iohk/ethereum/consensus/BlockGeneratorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
val miningTimestamp = 1508751768

val fullBlock = pendingBlock.block.copy(header =
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp)
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp, gasLimit = generatedBlockGasLimit)
)
validators.blockHeaderValidator.validate(
fullBlock.header,
Expand All @@ -61,7 +61,7 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
val miningTimestamp = 1508752265

val fullBlock = pendingBlock.block.copy(header =
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp)
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp, gasLimit = generatedBlockGasLimit)
)
validators.blockHeaderValidator.validate(
fullBlock.header,
Expand All @@ -83,7 +83,7 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
val miningTimestamp = 1508752265

val fullBlock = pendingBlock.block.copy(header =
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp)
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp, gasLimit = generatedBlockGasLimit)
)

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

val fullBlock = pendingBlock.block.copy(header =
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp)
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp, gasLimit = generatedBlockGasLimit)
)
validators.blockHeaderValidator.validate(
fullBlock.header,
Expand Down Expand Up @@ -165,7 +165,7 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
val miningTimestamp = 1508752492

val fullBlock = pendingBlock.block.copy(header =
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp)
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp, gasLimit = generatedBlockGasLimit)
)

validators.blockHeaderValidator.validate(
Expand Down Expand Up @@ -233,7 +233,7 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper

val fullBlock =
pendingBlock.block.copy(header =
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp)
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp, gasLimit = generatedBlockGasLimit)
)
validators.blockHeaderValidator.validate(
fullBlock.header,
Expand Down Expand Up @@ -323,7 +323,7 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper

val fullBlock =
pendingBlock.block.copy(header =
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp)
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp, gasLimit = generatedBlockGasLimit)
)
validators.blockHeaderValidator.validate(fullBlock.header, blockchain.getBlockHeaderByHash) shouldBe Right(
BlockHeaderValid
Expand Down Expand Up @@ -355,7 +355,7 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper

val fullBlock =
pendingBlock.block.copy(header =
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp)
pendingBlock.block.header.copy(nonce = minedNonce, mixHash = minedMixHash, unixTimestamp = miningTimestamp, gasLimit = generatedBlockGasLimit)
)
validators.blockHeaderValidator.validate(fullBlock.header, blockchain.getBlockHeaderByHash) shouldBe Right(
BlockHeaderValid
Expand Down Expand Up @@ -400,7 +400,7 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper
val miningTimestamp = 1499721182

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

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

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

Expand Down