Skip to content

Commit 886bbe4

Browse files
committed
[ETCM-177] Minor comments
1 parent d0ca47d commit 886bbe4

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

src/main/scala/io/iohk/ethereum/ommers/OmmersPool.scala

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ import io.iohk.ethereum.domain.{BlockHeader, Blockchain}
77
import io.iohk.ethereum.ommers.OmmersPool.{AddOmmers, GetOmmers, RemoveOmmers}
88
import scala.annotation.tailrec
99

10-
class OmmersPool(blockchain: Blockchain, ommersPoolSize: Int, ommerGenerationLimit: Int)
10+
class OmmersPool(blockchain: Blockchain, ommersPoolSize: Int, ommerGenerationLimit: Int, returnedOmmersSizeLimit: Int)
1111
extends Actor
1212
with ActorLogging {
1313

1414
var ommersPool: Seq[BlockHeader] = Nil
1515

16-
val ommerSizeLimit: Int = 2
17-
1816
override def receive: Receive = {
1917
case AddOmmers(ommers) =>
2018
ommersPool = (ommers ++ ommersPool).take(ommersPoolSize).distinct
@@ -32,7 +30,7 @@ class OmmersPool(blockchain: Blockchain, ommersPoolSize: Int, ommerGenerationLim
3230
val notAncestor = ancestors.find(_.hash == b.hash).isEmpty
3331
ancestors.find(_.hash == b.parentHash).isDefined && notAncestor
3432
}
35-
.take(ommerSizeLimit)
33+
.take(returnedOmmersSizeLimit)
3634
logStatus(event = s"Ommers given parent block ${Hex.toHexString(parentBlockHash.toArray)}", ommers)
3735
sender() ! OmmersPool.Ommers(ommers)
3836
}
@@ -57,9 +55,21 @@ class OmmersPool(blockchain: Blockchain, ommersPoolSize: Int, ommerGenerationLim
5755

5856
object OmmersPool {
5957

60-
// ommerGenerationLimit should be === 6 as is stated on section 11.1, eq. (143) of the YP
61-
def props(blockchain: Blockchain, ommersPoolSize: Int, ommerGenerationLimit: Int = 6): Props = Props(
62-
new OmmersPool(blockchain, ommersPoolSize, ommerGenerationLimit)
58+
/**
59+
* As is stated on section 11.1, eq. (143) of the YP
60+
*
61+
* @param ommerGenerationLimit should be === 6
62+
* @param returnedOmmersSizeLimit should be === 2
63+
*
64+
* ^ Probably not worthy but those params could be placed in consensus config.
65+
*/
66+
def props(
67+
blockchain: Blockchain,
68+
ommersPoolSize: Int,
69+
ommerGenerationLimit: Int = 6,
70+
returnedOmmersSizeLimit: Int = 2
71+
): Props = Props(
72+
new OmmersPool(blockchain, ommersPoolSize, ommerGenerationLimit, returnedOmmersSizeLimit)
6373
)
6474

6575
case class AddOmmers(ommers: List[BlockHeader])

src/test/scala/io/iohk/ethereum/ommers/OmmersPoolSpec.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,14 @@ class OmmersPoolSpec extends AnyFreeSpec with Matchers with MockFactory {
172172
// Originally it should be 6 as is stated on section 11.1, eq. (143) of the YP
173173
// Here we are using a simplification for testing purposes
174174
val ommerGenerationLimit: Int = 2
175-
176-
val ommerSizeLimit: Int = 2 // Max amount of ommers allowed per block
175+
val returnedOmmerSizeLimit: Int = 2 // Max amount of ommers allowed per block
177176

178177
/**
179178
* 00 ---> 11 --> 21 --> 31 (chain1)
180179
* \ \ \--> 33 (chain3)
181180
* \ \--> 22 --> 32 (chain2)
182181
* \--> 14 --> 24 (chain4)
183-
* \-> 15 (chain4)
182+
* \-> 15 (chain5)
184183
*/
185184
val block0 = Block3125369.header.copy(number = 0, difficulty = 0)
186185

@@ -201,6 +200,7 @@ class OmmersPoolSpec extends AnyFreeSpec with Matchers with MockFactory {
201200
val testProbe = TestProbe()
202201

203202
val blockchain = mock[BlockchainImpl]
204-
val ommersPool = system.actorOf(OmmersPool.props(blockchain, ommersPoolSize, ommerGenerationLimit))
203+
val ommersPool =
204+
system.actorOf(OmmersPool.props(blockchain, ommersPoolSize, ommerGenerationLimit, returnedOmmerSizeLimit))
205205
}
206206
}

0 commit comments

Comments
 (0)