-
Notifications
You must be signed in to change notification settings - Fork 75
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
[ETCM-177] Simplify ommers handling #745
Changes from all commits
c86cbd5
7428266
3bcc571
3178761
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ import io.iohk.ethereum.consensus.difficulty.DifficultyCalculator | |
import io.iohk.ethereum.consensus.ethash.validators.ValidatorsExecutor | ||
import io.iohk.ethereum.crypto.kec256 | ||
import io.iohk.ethereum.domain._ | ||
import io.iohk.ethereum.ledger.{BlockPreparationError, BlockPreparator} | ||
import io.iohk.ethereum.ledger.BlockPreparator | ||
import io.iohk.ethereum.utils.BlockchainConfig | ||
|
||
/** Internal API, used for testing (especially mocks) */ | ||
|
@@ -73,25 +73,23 @@ class EthashBlockGeneratorImpl( | |
transactions: Seq[SignedTransaction], | ||
beneficiary: Address, | ||
x: Ommers | ||
): Either[BlockPreparationError, PendingBlock] = { | ||
): PendingBlock = { | ||
val pHeader = parent.header | ||
val blockNumber = pHeader.number + 1 | ||
val parentHash = pHeader.hash | ||
|
||
val ommersV = validators.ommersValidator | ||
val ommers = validators.ommersValidator.validate(parentHash, blockNumber, x, blockchain) match { | ||
case Left(_) => emptyX | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we log this case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mmm...now i'm thinking we could log this at ommers pool level once we finally do all the validations. Btw, the amount of ommers per block is something that we measure, so we couyld produce metrics, i mean, it won't be an issue to get track of that. |
||
case Right(_) => x | ||
} | ||
|
||
val result: Either[InvalidOmmers, PendingBlockAndState] = ommersV | ||
.validate(parentHash, blockNumber, x, blockchain) | ||
.left | ||
.map(InvalidOmmers) | ||
.flatMap { _ => | ||
val prepared = prepareBlock(parent, transactions, beneficiary, blockNumber, blockPreparator, x) | ||
Right(prepared) | ||
} | ||
val prepared = prepareBlock(parent, transactions, beneficiary, blockNumber, blockPreparator, ommers) | ||
|
||
result.right.foreach(b => cache.updateAndGet((t: List[PendingBlockAndState]) => (b :: t).take(blockCacheSize))) | ||
cache.updateAndGet { t: List[PendingBlockAndState] => | ||
(prepared :: t).take(blockCacheSize) | ||
} | ||
|
||
result.map(_.pendingBlock) | ||
prepared.pendingBlock | ||
} | ||
|
||
def withBlockTimestampProvider(blockTimestampProvider: BlockTimestampProvider): EthashBlockGeneratorImpl = | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like much the middle ground of keeping the pool and ignoring any problems when using it on the miner, but only updating the pool it half of the times, should we: