Skip to content

Commit f9047fb

Browse files
author
Christos KK Loverdos
committed
Rename ommers
1 parent ee89251 commit f9047fb

File tree

6 files changed

+36
-50
lines changed

6 files changed

+36
-50
lines changed

src/main/scala/io/iohk/ethereum/consensus/atomixraft/AtomixRaftForger.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class AtomixRaftForger(
9898
parent = parentBlock,
9999
transactions = pendingTransactions,
100100
beneficiary = coinbase,
101-
ommers = Nil // No ommers
101+
x = Nil
102102
)
103103
errorOrPendingBlock match {
104104
case Left(error)

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,12 @@ trait BlockGenerator {
3535

3636
/**
3737
* Generates the next block.
38-
*
39-
* @param ommers We call it `ommers`, since this is the original use-case in Ethash but in general it can be anything
4038
*/
4139
def generateBlock(
4240
parent: Block,
4341
transactions: Seq[SignedTransaction],
4442
beneficiary: Address,
45-
ommers: X
43+
x: X
4644
): Either[BlockPreparationError, PendingBlock]
4745
}
4846

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,18 @@ abstract class BlockGeneratorSkeleton(
4242

4343
protected val cache: AtomicReference[List[PendingBlockAndState]] = new AtomicReference(Nil)
4444

45-
46-
protected def newBlockBody(transactions: Seq[SignedTransaction], ommers: X): BlockBody
45+
protected def newBlockBody(transactions: Seq[SignedTransaction], x: X): BlockBody
4746

4847
protected def defaultPrepareHeader(
4948
blockNumber: BigInt,
5049
parent: Block,
5150
beneficiary: Address,
5251
blockTimestamp: Long,
53-
ommers: Ommers
52+
x: Ommers
5453
): BlockHeader =
5554
BlockHeader(
5655
parentHash = parent.header.hash,
57-
ommersHash = ByteString(kec256(ommers.toBytes: Array[Byte])),
56+
ommersHash = ByteString(kec256(x.toBytes: Array[Byte])),
5857
beneficiary = beneficiary.bytes,
5958
stateRoot = ByteString.empty,
6059
//we are not able to calculate transactionsRoot here because we do not know if they will fail
@@ -74,7 +73,7 @@ abstract class BlockGeneratorSkeleton(
7473
protected def prepareHeader(
7574
blockNumber: BigInt, parent: Block,
7675
beneficiary: Address, blockTimestamp: Long,
77-
ommers: X
76+
x: X
7877
): BlockHeader
7978

8079
protected def prepareBlock(
@@ -83,13 +82,13 @@ abstract class BlockGeneratorSkeleton(
8382
beneficiary: Address,
8483
blockNumber: BigInt,
8584
blockPreparator: BlockPreparator,
86-
ommers: X
85+
x: X
8786
): PendingBlockAndState = {
8887

8988
val blockTimestamp = blockTimestampProvider.getEpochSecond
90-
val header = prepareHeader(blockNumber, parent, beneficiary, blockTimestamp, ommers)
89+
val header = prepareHeader(blockNumber, parent, beneficiary, blockTimestamp, x)
9190
val transactionsForBlock = prepareTransactions(transactions, header.gasLimit)
92-
val body = newBlockBody(transactionsForBlock, ommers)
91+
val body = newBlockBody(transactionsForBlock, x)
9392
val block = Block(header, body)
9493

9594
val prepared = blockPreparator.prepareBlock(block) match {

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@ abstract class NoOmmersBlockGenerator(
2323

2424
type X = Nil.type
2525

26-
protected def newBlockBody(transactions: Seq[SignedTransaction], ommers: Nil.type): BlockBody = {
27-
BlockBody(transactions, ommers)
28-
}
26+
protected def newBlockBody(transactions: Seq[SignedTransaction], x: Nil.type): BlockBody =
27+
BlockBody(transactions, x)
2928

3029
protected def prepareHeader(
31-
blockNumber: BigInt, parent: Block,
32-
beneficiary: Address, blockTimestamp: Long,
33-
ommers: Nil.type
30+
blockNumber: BigInt,
31+
parent: Block,
32+
beneficiary: Address,
33+
blockTimestamp: Long,
34+
x: Nil.type
3435
): BlockHeader =
35-
defaultPrepareHeader(blockNumber, parent, beneficiary, blockTimestamp, ommers)
36+
defaultPrepareHeader(blockNumber, parent, beneficiary, blockTimestamp, x)
3637

3738

3839
/** An empty `X` */
@@ -42,13 +43,13 @@ abstract class NoOmmersBlockGenerator(
4243
parent: Block,
4344
transactions: Seq[SignedTransaction],
4445
beneficiary: Address,
45-
ommers: Nil.type
46+
x: Nil.type
4647
): Either[BlockPreparationError, PendingBlock] = {
4748

4849
val pHeader = parent.header
4950
val blockNumber = pHeader.number + 1
5051

51-
val prepared = prepareBlock(parent, transactions, beneficiary, blockNumber, blockPreparator, ommers)
52+
val prepared = prepareBlock(parent, transactions, beneficiary, blockNumber, blockPreparator, x)
5253
cache.updateAndGet((t: List[PendingBlockAndState]) => (prepared :: t).take(blockCacheSize))
5354

5455
Right(prepared.pendingBlock)

src/main/scala/io/iohk/ethereum/consensus/ethash/blocks/EthashBlockGenerator.scala

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,15 @@ class EthashBlockGeneratorImpl(
3838
blockTimestampProvider
3939
) with EthashBlockGenerator {
4040

41-
protected def newBlockBody(transactions: Seq[SignedTransaction], ommers: Ommers): BlockBody = {
42-
BlockBody(transactions, ommers)
43-
}
41+
protected def newBlockBody(transactions: Seq[SignedTransaction], x: Ommers): BlockBody =
42+
BlockBody(transactions, x)
4443

4544
protected def prepareHeader(
4645
blockNumber: BigInt, parent: Block,
4746
beneficiary: Address, blockTimestamp: Long,
48-
ommers: Ommers
47+
x: Ommers
4948
): BlockHeader =
50-
defaultPrepareHeader(blockNumber, parent, beneficiary, blockTimestamp, ommers)
49+
defaultPrepareHeader(blockNumber, parent, beneficiary, blockTimestamp, x)
5150

5251

5352
/** An empty `X` */
@@ -66,7 +65,7 @@ class EthashBlockGeneratorImpl(
6665
parent: Block,
6766
transactions: Seq[SignedTransaction],
6867
beneficiary: Address,
69-
ommers: Ommers
68+
x: Ommers
7069
): Either[BlockPreparationError, PendingBlock] = {
7170
val pHeader = parent.header
7271
val blockNumber = pHeader.number + 1
@@ -75,10 +74,10 @@ class EthashBlockGeneratorImpl(
7574
val ommersV = validators.ommersValidator
7675

7776
val result: Either[InvalidOmmers, PendingBlockAndState] = ommersV
78-
.validate(parentHash, blockNumber, ommers, blockchain)
77+
.validate(parentHash, blockNumber, x, blockchain)
7978
.left.map(InvalidOmmers).flatMap { _ =>
8079

81-
val prepared = prepareBlock(parent, transactions, beneficiary, blockNumber, blockPreparator, ommers)
80+
val prepared = prepareBlock(parent, transactions, beneficiary, blockNumber, blockPreparator, x)
8281
Right(prepared)
8382
}
8483

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

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ class BlockGeneratorSpec extends FlatSpec with Matchers with PropertyChecks with
4040
}
4141

4242
it should "generate correct block with transactions" in new TestSetup {
43-
val result: Either[BlockPreparationError, PendingBlock] = blockGenerator.generateBlock(
44-
bestBlock, Seq(signedTransaction), Address(testAddress), blockGenerator.emptyX)
43+
val result: Either[BlockPreparationError, PendingBlock] = blockGenerator.generateBlock(bestBlock, Seq(signedTransaction), Address(testAddress), blockGenerator.emptyX)
4544
result shouldBe a[Right[_, Block]]
4645

4746
//mined with mantis + ethminer
@@ -58,8 +57,7 @@ class BlockGeneratorSpec extends FlatSpec with Matchers with PropertyChecks with
5857

5958

6059
it should "be possible to simulate transaction, on world returned with pending block " in new TestSetup {
61-
val result: Either[BlockPreparationError, PendingBlock] = blockGenerator.generateBlock(
62-
bestBlock, Seq(signedTransaction), Address(testAddress), blockGenerator.emptyX)
60+
val result: Either[BlockPreparationError, PendingBlock] = blockGenerator.generateBlock(bestBlock, Seq(signedTransaction), Address(testAddress), blockGenerator.emptyX)
6361
result shouldBe a[Right[_, Block]]
6462

6563
//mined with mantis + ethminer
@@ -74,8 +72,7 @@ class BlockGeneratorSpec extends FlatSpec with Matchers with PropertyChecks with
7472
val res = ledger.importBlock(fullBlock.right.get)
7573

7674
// Create new pending block, with updated stateRootHash
77-
val result1: Either[BlockPreparationError, PendingBlock] = blockGenerator.generateBlock(
78-
blockchain.getBestBlock(), Seq(signedTransaction), Address(testAddress), blockGenerator.emptyX)
75+
val result1: Either[BlockPreparationError, PendingBlock] = blockGenerator.generateBlock(blockchain.getBestBlock(), Seq(signedTransaction), Address(testAddress), blockGenerator.emptyX)
7976
result1 shouldBe a[Right[_, Block]]
8077

8178
val pendBlockAndState = blockGenerator.getPendingBlockAndState.get
@@ -93,8 +90,7 @@ class BlockGeneratorSpec extends FlatSpec with Matchers with PropertyChecks with
9390
}
9491

9592
it should "filter out failing transactions" in new TestSetup {
96-
val result: Either[BlockPreparationError, PendingBlock] = blockGenerator.generateBlock(
97-
bestBlock, Seq(signedTransaction, duplicatedSignedTransaction), Address(testAddress), blockGenerator.emptyX)
93+
val result: Either[BlockPreparationError, PendingBlock] = blockGenerator.generateBlock(bestBlock, Seq(signedTransaction, duplicatedSignedTransaction), Address(testAddress), blockGenerator.emptyX)
9894
result shouldBe a[Right[_, Block]]
9995

10096
//mined with mantis + ethminer
@@ -117,8 +113,7 @@ class BlockGeneratorSpec extends FlatSpec with Matchers with PropertyChecks with
117113
nonce = signedTransaction.tx.nonce + 1),
118114
keyPair, Some(0x3d.toByte))
119115

120-
val result: Either[BlockPreparationError, PendingBlock] = blockGenerator.generateBlock(
121-
bestBlock, Seq(txWitGasTooBigGasLimit, signedTransaction, duplicatedSignedTransaction), Address(testAddress), blockGenerator.emptyX)
116+
val result: Either[BlockPreparationError, PendingBlock] = blockGenerator.generateBlock(bestBlock, Seq(txWitGasTooBigGasLimit, signedTransaction, duplicatedSignedTransaction), Address(testAddress), blockGenerator.emptyX)
122117
result shouldBe a[Right[_, Block]]
123118

124119
//mined with mantis + ethminer
@@ -160,8 +155,7 @@ class BlockGeneratorSpec extends FlatSpec with Matchers with PropertyChecks with
160155
val generalTx = SignedTransaction.sign(transaction, keyPair, None)
161156
val specificTx = SignedTransaction.sign(transaction.copy(nonce = transaction.nonce + 1), keyPair, Some(0x3d.toByte))
162157

163-
val result: Either[BlockPreparationError, PendingBlock] = blockGenerator.generateBlock(
164-
bestBlock, Seq(generalTx, specificTx), Address(testAddress), blockGenerator.emptyX)
158+
val result: Either[BlockPreparationError, PendingBlock] = blockGenerator.generateBlock(bestBlock, Seq(generalTx, specificTx), Address(testAddress), blockGenerator.emptyX)
165159
result shouldBe a[Right[_, Block]]
166160

167161
//mined with mantis + ethminer
@@ -180,8 +174,7 @@ class BlockGeneratorSpec extends FlatSpec with Matchers with PropertyChecks with
180174
it should "generate block after eip155 and allow both chain specific and general transactions" in new TestSetup {
181175
val generalTx: SignedTransaction = SignedTransaction.sign(transaction.copy(nonce = transaction.nonce + 1), keyPair, None)
182176

183-
val result: Either[BlockPreparationError, PendingBlock] = blockGenerator.generateBlock(
184-
bestBlock, Seq(generalTx, signedTransaction), Address(testAddress), blockGenerator.emptyX)
177+
val result: Either[BlockPreparationError, PendingBlock] = blockGenerator.generateBlock(bestBlock, Seq(generalTx, signedTransaction), Address(testAddress), blockGenerator.emptyX)
185178
result shouldBe a[Right[_, Block]]
186179

187180
//mined with mantis + ethminer
@@ -200,8 +193,7 @@ class BlockGeneratorSpec extends FlatSpec with Matchers with PropertyChecks with
200193
it should "include consecutive transactions from single sender" in new TestSetup {
201194
val nextTransaction: SignedTransaction = SignedTransaction.sign(transaction.copy(nonce = signedTransaction.tx.nonce + 1), keyPair, Some(0x3d.toByte))
202195

203-
val result: Either[BlockPreparationError, PendingBlock] = blockGenerator.generateBlock(
204-
bestBlock, Seq(nextTransaction, signedTransaction), Address(testAddress), blockGenerator.emptyX)
196+
val result: Either[BlockPreparationError, PendingBlock] = blockGenerator.generateBlock(bestBlock, Seq(nextTransaction, signedTransaction), Address(testAddress), blockGenerator.emptyX)
205197
result shouldBe a[Right[_, Block]]
206198

207199
//mined with mantis + ethminer
@@ -232,9 +224,7 @@ class BlockGeneratorSpec extends FlatSpec with Matchers with PropertyChecks with
232224
val signedFailingTransaction: SignedTransaction = SignedTransaction.sign(failingTransaction,
233225
keyPairFromPrvKey(privateKeyWithNoEthere), Some(0x3d.toByte))
234226

235-
val result: Either[BlockPreparationError, PendingBlock] = blockGenerator.generateBlock(
236-
bestBlock, Seq(nextTransaction, signedFailingTransaction, signedTransaction),
237-
Address(testAddress), blockGenerator.emptyX)
227+
val result: Either[BlockPreparationError, PendingBlock] = blockGenerator.generateBlock(bestBlock, Seq(nextTransaction, signedFailingTransaction, signedTransaction), Address(testAddress), blockGenerator.emptyX)
238228
result shouldBe a[Right[_, Block]]
239229

240230
//mined with mantis + ethminer
@@ -256,8 +246,7 @@ class BlockGeneratorSpec extends FlatSpec with Matchers with PropertyChecks with
256246
keyPair,
257247
Some(0x3d.toByte))
258248

259-
val result: Either[BlockPreparationError, PendingBlock] = blockGenerator.generateBlock(
260-
bestBlock, Seq(txWitSameNonceButLowerGasPrice, signedTransaction), Address(testAddress), blockGenerator.emptyX)
249+
val result: Either[BlockPreparationError, PendingBlock] = blockGenerator.generateBlock(bestBlock, Seq(txWitSameNonceButLowerGasPrice, signedTransaction), Address(testAddress), blockGenerator.emptyX)
261250
result shouldBe a[Right[_, Block]]
262251

263252
//mined with mantis + ethminer

0 commit comments

Comments
 (0)