Skip to content

Commit 08f917a

Browse files
author
Nicolas Tallar
committed
Static analysis tools fixes
1 parent e14cefd commit 08f917a

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/main/scala/io/iohk/ethereum/blockchain/sync/RegularSync.scala

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,25 +119,26 @@ trait RegularSync {
119119
blockchain.getBlockHeaderByHash(blocks.head.header.parentHash)
120120
.flatMap(b => blockchain.getTotalDifficultyByHash(b.hash)) match {
121121
case Some(blockParentTd) =>
122-
val (newBlocks, error) = processBlocks(blocks, blockParentTd)
122+
val (newBlocks, errorOpt) = processBlocks(blocks, blockParentTd)
123123

124124
if(newBlocks.nonEmpty){
125125
context.self ! BroadcastBlocks(newBlocks)
126126
log.info(s"got new blocks up till block: ${newBlocks.last.block.header.number} " +
127127
s"with hash ${Hex.toHexString(newBlocks.last.block.header.hash.toArray[Byte])}")
128128
}
129129

130-
if(error.isDefined){
131-
val numberBlockFailed = blocks.head.header.number + newBlocks.length
132-
resumeWithDifferentPeer(peer, reason = s"a block execution error: ${error.get.toString}, in block $numberBlockFailed")
133-
} else {
134-
headersQueue = headersQueue.drop(blocks.length)
135-
if (headersQueue.nonEmpty) {
136-
val hashes = headersQueue.take(blockBodiesPerRequest).map(_.hash)
137-
waitingForActor = Some(context.actorOf(SyncBlockBodiesRequestHandler.props(peer, hashes)))
138-
} else {
139-
context.self ! ResumeRegularSync
140-
}
130+
errorOpt match {
131+
case Some(error) =>
132+
val numberBlockFailed = blocks.head.header.number + newBlocks.length
133+
resumeWithDifferentPeer(peer, reason = s"a block execution error: ${error.toString}, in block $numberBlockFailed")
134+
case None =>
135+
headersQueue = headersQueue.drop(blocks.length)
136+
if (headersQueue.nonEmpty) {
137+
val hashes = headersQueue.take(blockBodiesPerRequest).map(_.hash)
138+
waitingForActor = Some(context.actorOf(SyncBlockBodiesRequestHandler.props(peer, hashes)))
139+
} else {
140+
context.self ! ResumeRegularSync
141+
}
141142
}
142143
case None =>
143144
//TODO: Investigate if we can recover from this error (EC-165)

src/main/scala/io/iohk/ethereum/validators/SignedTransactionValidator.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class SignedTransactionValidatorImpl(blockchainConfig: BlockchainConfig) extends
3434
_ <- validateSignature(stx, fromBeforeHomestead = blockHeader.number < blockchainConfig.homesteadBlockNumber)
3535
_ <- validateNonce(stx, senderAccount.nonce)
3636
_ <- validateGasLimitEnoughForIntrinsicGas(stx, blockHeader.number)
37-
_ <- validateAccountHasEnoughGasToPayUpfrontCost(stx, senderAccount.balance, upfrontGasCost)
37+
_ <- validateAccountHasEnoughGasToPayUpfrontCost(senderAccount.balance, upfrontGasCost)
3838
_ <- validateBlockHasEnoughGasLimitForTx(stx, accumGasUsed, blockHeader.gasLimit)
3939
} yield ()
4040
}
@@ -121,12 +121,11 @@ class SignedTransactionValidatorImpl(blockchainConfig: BlockchainConfig) extends
121121
/**
122122
* Validates the sender account balance contains at least the cost required in up-front payment.
123123
*
124-
* @param stx Transaction to validate
125124
* @param senderBalance Balance of the sender of the tx
126125
* @param upfrontCost Upfront cost of the transaction tx
127126
* @return Either the validated transaction or a TransactionSenderCantPayUpfrontCostError
128127
*/
129-
private def validateAccountHasEnoughGasToPayUpfrontCost(stx: SignedTransaction, senderBalance: UInt256, upfrontCost: UInt256)
128+
private def validateAccountHasEnoughGasToPayUpfrontCost(senderBalance: UInt256, upfrontCost: UInt256)
130129
: Either[SignedTransactionError, Unit] = {
131130
if (senderBalance >= upfrontCost) Right(())
132131
else Left(TransactionSenderCantPayUpfrontCostError(upfrontCost, senderBalance))

0 commit comments

Comments
 (0)