Skip to content

Commit bdb5771

Browse files
author
lemastero
committed
[ETCM-141] scalafmtAll
1 parent 34c4654 commit bdb5771

File tree

315 files changed

+6048
-4162
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

315 files changed

+6048
-4162
lines changed

src/main/scala/io/iohk/ethereum/App.scala

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import io.iohk.ethereum.faucet.Faucet
66
import io.iohk.ethereum.mallet.main.Mallet
77
import io.iohk.ethereum.utils.{Config, Logger}
88

9-
109
object App extends Logger {
1110

1211
def main(args: Array[String]): Unit = {
@@ -19,25 +18,26 @@ object App extends Logger {
1918
val faucet = "faucet"
2019
val ecKeyGen = "eckeygen"
2120

22-
args.headOption match {
23-
case None => Mantis.main(args)
24-
case Some(`launchMantis`) => Mantis.main(args.tail)
25-
case Some(`launchKeytool`) => KeyTool.main(args.tail)
26-
case Some(`downloadBootstrap`) => {
27-
Config.Db.dataSource match {
28-
case "rocksdb" => BootstrapDownload.main(args.tail :+ Config.Db.RocksDb.path)
29-
}
21+
args.headOption match {
22+
case None => Mantis.main(args)
23+
case Some(`launchMantis`) => Mantis.main(args.tail)
24+
case Some(`launchKeytool`) => KeyTool.main(args.tail)
25+
case Some(`downloadBootstrap`) => {
26+
Config.Db.dataSource match {
27+
case "rocksdb" => BootstrapDownload.main(args.tail :+ Config.Db.RocksDb.path)
3028
}
31-
case Some(`vmServer`) => VmServerApp.main(args.tail)
32-
case Some(`mallet`) => Mallet.main(args.tail)
33-
case Some(`faucet`) => Faucet.main(args.tail)
34-
case Some(`ecKeyGen`) => EcKeyGen.main(args.tail)
35-
case Some(unknown) =>
36-
log.error(s"Unrecognised launcher option, " +
37-
s"first parameter must be $launchKeytool, $downloadBootstrap, $launchMantis, " +
38-
s"$mallet, $faucet, $vmServer or $ecKeyGen")
3929
}
40-
30+
case Some(`vmServer`) => VmServerApp.main(args.tail)
31+
case Some(`mallet`) => Mallet.main(args.tail)
32+
case Some(`faucet`) => Faucet.main(args.tail)
33+
case Some(`ecKeyGen`) => EcKeyGen.main(args.tail)
34+
case Some(unknown) =>
35+
log.error(
36+
s"Unrecognised launcher option, " +
37+
s"first parameter must be $launchKeytool, $downloadBootstrap, $launchMantis, " +
38+
s"$mallet, $faucet, $vmServer or $ecKeyGen"
39+
)
40+
}
4141

4242
}
4343
}

src/main/scala/io/iohk/ethereum/BootstrapDownload.scala

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.iohk.ethereum
22

3-
43
import java.io.{File, FileInputStream, FileOutputStream}
54
import java.net.URL
65
import java.nio.file._
@@ -10,8 +9,6 @@ import java.util.zip.ZipInputStream
109
import io.iohk.ethereum.utils.Logger
1110
import org.bouncycastle.util.encoders.Hex
1211

13-
14-
1512
/**
1613
* A facility to
1714
* - check the download location for a minimum amount of free space
@@ -26,14 +23,17 @@ object BootstrapDownload extends Logger {
2623
val leveldbFolderName = "leveldb"
2724

2825
private def assertAndLog(cond: Boolean, msg: String): Unit = {
29-
if(!cond) log.info(msg)
26+
if (!cond) log.info(msg)
3027
assert(cond, msg)
3128
}
3229

3330
def cleanOutFolder(pathToDownloadTo: Path): Unit = {
3431
val leveldbFolder = pathToDownloadTo.toFile
3532
assertAndLog(leveldbFolder.isDirectory, s"${pathToDownloadTo} must be a folder.")
36-
assertAndLog(leveldbFolder.getName == leveldbFolderName, s"${pathToDownloadTo} must end in a folder named $leveldbFolderName")
33+
assertAndLog(
34+
leveldbFolder.getName == leveldbFolderName,
35+
s"${pathToDownloadTo} must end in a folder named $leveldbFolderName"
36+
)
3737
leveldbFolder.listFiles(pathname => !pathname.getName.endsWith(".zip")).foreach(_.delete())
3838
}
3939

@@ -43,12 +43,12 @@ object BootstrapDownload extends Logger {
4343
val dis = new DigestInputStream(new URL(urlToDownloadFrom).openStream(), sha512)
4444

4545
try {
46-
val out = new FileOutputStream(outFile)
47-
try {
48-
val buffer = new Array[Byte](bufferSize)
49-
Stream.continually(dis.read(buffer)).takeWhile(_ != -1).foreach(out.write(buffer, 0, _))
50-
} finally (out.close())
51-
Hex.toHexString(sha512.digest)
46+
val out = new FileOutputStream(outFile)
47+
try {
48+
val buffer = new Array[Byte](bufferSize)
49+
Stream.continually(dis.read(buffer)).takeWhile(_ != -1).foreach(out.write(buffer, 0, _))
50+
} finally (out.close())
51+
Hex.toHexString(sha512.digest)
5252

5353
} finally {
5454
dis.close()
@@ -74,34 +74,36 @@ object BootstrapDownload extends Logger {
7474
try {
7575
val buffer = new Array[Byte](bufferSize)
7676
Stream.continually(zis.read(buffer)).takeWhile(_ != -1).foreach(out.write(buffer, 0, _))
77-
} finally(out.close())
77+
} finally (out.close())
7878
}
7979
}
80-
} finally(zis.close())
81-
} finally(in.close())
80+
} finally (zis.close())
81+
} finally (in.close())
8282
}
8383

84-
8584
def deleteDownloadedFile(downloadedFile: File): Unit = {
86-
if(downloadedFile.delete()) log.info(s"Downloaded file $downloadedFile successfully deleted")
85+
if (downloadedFile.delete()) log.info(s"Downloaded file $downloadedFile successfully deleted")
8786
else log.info(s"Failed to delete downloaded file $downloadedFile")
8887
}
8988

9089
def main(args: Array[String]): Unit = {
9190
//download a zip file from a url.
9291

93-
assertAndLog(args.length == 4, "Provide the url to download from, " +
94-
" expected hash of the downloaded file, " +
95-
" the minimum required free disk space in giga bytes" +
96-
" and the path to extract the file to")
92+
assertAndLog(
93+
args.length == 4,
94+
"Provide the url to download from, " +
95+
" expected hash of the downloaded file, " +
96+
" the minimum required free disk space in giga bytes" +
97+
" and the path to extract the file to"
98+
)
9799

98100
val urlToDownloadFrom = new URL(args(0))
99101
val expectedHash = args(1)
100102
val minimumExpectedDiskSpace = args(2)
101103
val pathToDownloadTo = Paths.get(args(3))
102104

103-
val bytesInOneGigaByte = 1024l * 1024l * 1024l
104-
val minimumExpectedDiskSpaceInBytes = minimumExpectedDiskSpace.toLong * bytesInOneGigaByte
105+
val bytesInOneGigaByte = 1024L * 1024L * 1024L
106+
val minimumExpectedDiskSpaceInBytes = minimumExpectedDiskSpace.toLong * bytesInOneGigaByte
105107

106108
val urlToDownloadFromAsFile = new File(urlToDownloadFrom.getFile)
107109
val pathToDownloadToAsFile = pathToDownloadTo.toFile
@@ -112,11 +114,13 @@ object BootstrapDownload extends Logger {
112114
log.info(s"Download path is $urlToDownloadFrom")
113115
log.info(s"Path to download to is $pathToDownloadTo")
114116

115-
if(!pathToDownloadToAsFile.exists()) pathToDownloadToAsFile.mkdirs()
117+
if (!pathToDownloadToAsFile.exists()) pathToDownloadToAsFile.mkdirs()
116118

117119
assertAndLog(pathToDownloadToAsFile.isDirectory, s"$pathToDownloadToAsFile must be a folder.")
118-
assertAndLog(pathToDownloadToAsFile.getUsableSpace() >= minimumExpectedDiskSpaceInBytes,
119-
s"There is not enough free space ($minimumExpectedDiskSpace GB) to download and expand to $pathToDownloadTo ")
120+
assertAndLog(
121+
pathToDownloadToAsFile.getUsableSpace() >= minimumExpectedDiskSpaceInBytes,
122+
s"There is not enough free space ($minimumExpectedDiskSpace GB) to download and expand to $pathToDownloadTo "
123+
)
120124

121125
log.info(s"Free space check ok, starting download! (this could take some time)")
122126
val hash = downloadFile(args(0), downloadedFile)

src/main/scala/io/iohk/ethereum/KeyTool.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.iohk.ethereum
22

3-
43
object KeyTool {
54

65
def main(args: Array[String]): Unit = sun.security.tools.keytool.Main.main(args)

src/main/scala/io/iohk/ethereum/Mantis.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ object Mantis extends Logger {
99
if (Config.testmode) {
1010
log.info("Starting Mantis in test mode")
1111
new TestNode
12-
}
13-
else new StdNode
12+
} else new StdNode
1413

1514
log.info("Using network {}", Config.blockchains.network)
1615

src/main/scala/io/iohk/ethereum/blockchain/data/GenesisDataLoader.scala

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ import org.bouncycastle.util.encoders.Hex
1818
import scala.io.Source
1919
import scala.util.{Failure, Success, Try}
2020

21-
class GenesisDataLoader(
22-
blockchain: Blockchain,
23-
blockchainConfig: BlockchainConfig)
24-
extends Logger{
21+
class GenesisDataLoader(blockchain: Blockchain, blockchainConfig: BlockchainConfig) extends Logger {
2522

2623
private val bloomLength = 512
2724
private val hashLength = 64
@@ -90,13 +87,17 @@ class GenesisDataLoader(
9087
val storage = stateStorage.getReadOnlyStorage
9188
val initalRootHash = MerklePatriciaTrie.EmptyRootHash
9289

93-
val stateMptRootHash = genesisData.alloc.zipWithIndex.foldLeft(initalRootHash) { case (rootHash, (((address, AllocAccount(balance)), idx))) =>
94-
val mpt = MerklePatriciaTrie[Array[Byte], Account](rootHash, storage)
95-
val paddedAddress = address.reverse.padTo(addressLength, "0").reverse.mkString
96-
val stateRoot = mpt.put(crypto.kec256(Hex.decode(paddedAddress)),
97-
Account(blockchainConfig.accountStartNonce, UInt256(BigInt(balance)), emptyTrieRootHash, emptyEvmHash)
98-
).getRootHash
99-
stateRoot
90+
val stateMptRootHash = genesisData.alloc.zipWithIndex.foldLeft(initalRootHash) {
91+
case (rootHash, (((address, AllocAccount(balance)), idx))) =>
92+
val mpt = MerklePatriciaTrie[Array[Byte], Account](rootHash, storage)
93+
val paddedAddress = address.reverse.padTo(addressLength, "0").reverse.mkString
94+
val stateRoot = mpt
95+
.put(
96+
crypto.kec256(Hex.decode(paddedAddress)),
97+
Account(blockchainConfig.accountStartNonce, UInt256(BigInt(balance)), emptyTrieRootHash, emptyEvmHash)
98+
)
99+
.getRootHash
100+
stateRoot
100101
}
101102

102103
val header: BlockHeader = prepareHeader(genesisData, stateMptRootHash)
@@ -108,8 +109,12 @@ class GenesisDataLoader(
108109
log.debug("Genesis data already in the database")
109110
Success(())
110111
case Some(_) =>
111-
Failure(new RuntimeException("Genesis data present in the database does not match genesis block from file." +
112-
" Use different directory for running private blockchains."))
112+
Failure(
113+
new RuntimeException(
114+
"Genesis data present in the database does not match genesis block from file." +
115+
" Use different directory for running private blockchains."
116+
)
117+
)
113118
case None =>
114119
storage.persist()
115120
stateStorage.forcePersist(GenesisDataLoad)
@@ -158,12 +163,13 @@ object GenesisDataLoader {
158163
case other => throw new RuntimeException("Expected hex string, but got: " + other)
159164
}
160165

161-
object ByteStringJsonSerializer extends CustomSerializer[ByteString](formats =>
162-
(
163-
{ case jv => deserializeByteString(jv) },
164-
PartialFunction.empty
165-
)
166-
)
166+
object ByteStringJsonSerializer
167+
extends CustomSerializer[ByteString](formats =>
168+
(
169+
{ case jv => deserializeByteString(jv) },
170+
PartialFunction.empty
171+
)
172+
)
167173

168174
}
169175
}

src/main/scala/io/iohk/ethereum/blockchain/data/genesis.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ case class GenesisData(
1212
gasLimit: String,
1313
coinbase: ByteString,
1414
timestamp: String,
15-
alloc: Map[String, AllocAccount])
15+
alloc: Map[String, AllocAccount]
16+
)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ trait BlacklistSupport {
3939
def isBlacklisted(blacklistId: BlackListId): Boolean =
4040
blacklistedPeers.exists(_._1 == blacklistId)
4141

42-
def handleBlacklistMessages: Receive = {
43-
case UnblacklistPeer(ref) => undoBlacklist(ref)
42+
def handleBlacklistMessages: Receive = { case UnblacklistPeer(ref) =>
43+
undoBlacklist(ref)
4444
}
4545

4646
private def removeOldestPeer(): Unit = {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class BlockBroadcast(val etcPeerManager: ActorRef, syncConfig: SyncConfig) {
2323
*/
2424
def broadcastBlock(newBlock: NewBlock, handshakedPeers: Map[Peer, PeerInfo]): Unit = {
2525
val peersWithoutBlock = handshakedPeers.collect {
26-
case (peer, peerInfo) if shouldSendNewBlock(newBlock, peerInfo) => peer }.toSet
26+
case (peer, peerInfo) if shouldSendNewBlock(newBlock, peerInfo) => peer
27+
}.toSet
2728

2829
broadcastNewBlock(newBlock, peersWithoutBlock)
2930

@@ -47,7 +48,6 @@ class BlockBroadcast(val etcPeerManager: ActorRef, syncConfig: SyncConfig) {
4748
etcPeerManager ! EtcPeerManagerActor.SendMessage(newBlockHashMsg, peer.id)
4849
}
4950

50-
5151
/**
5252
* Obtains a random subset of peers. The returned set will verify:
5353
* subsetPeers.size == sqrt(peers.size)

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

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,22 @@ import io.iohk.ethereum.network.EtcPeerManagerActor
1717
* BlockchainHost actor is in charge of replying to the peer's requests for blockchain data, which includes both
1818
* node and block data.
1919
*/
20-
class BlockchainHostActor(blockchain: Blockchain, peerConfiguration: PeerConfiguration,
21-
peerEventBusActor: ActorRef, etcPeerManagerActor: ActorRef) extends Actor with ActorLogging {
20+
class BlockchainHostActor(
21+
blockchain: Blockchain,
22+
peerConfiguration: PeerConfiguration,
23+
peerEventBusActor: ActorRef,
24+
etcPeerManagerActor: ActorRef
25+
) extends Actor
26+
with ActorLogging {
2227

2328
private val requestMsgsCodes = Set(GetNodeData.code, GetReceipts.code, GetBlockBodies.code, GetBlockHeaders.code)
2429
peerEventBusActor ! Subscribe(MessageClassifier(requestMsgsCodes, PeerSelector.AllPeers))
2530

26-
override def receive: Receive = {
27-
case MessageFromPeer(message, peerId) =>
28-
val responseOpt = handleBlockFastDownload(message) orElse handleEvmCodeMptFastDownload(message)
29-
responseOpt.foreach{ response =>
30-
etcPeerManagerActor ! EtcPeerManagerActor.SendMessage(response, peerId)
31-
}
31+
override def receive: Receive = { case MessageFromPeer(message, peerId) =>
32+
val responseOpt = handleBlockFastDownload(message) orElse handleEvmCodeMptFastDownload(message)
33+
responseOpt.foreach { response =>
34+
etcPeerManagerActor ! EtcPeerManagerActor.SendMessage(response, peerId)
35+
}
3236
}
3337

3438
/**
@@ -40,7 +44,8 @@ class BlockchainHostActor(blockchain: Blockchain, peerConfiguration: PeerConfigu
4044
*/
4145
private def handleEvmCodeMptFastDownload(message: Message): Option[MessageSerializable] = message match {
4246
case GetNodeData(mptElementsHashes) =>
43-
val hashesRequested = mptElementsHashes.take(peerConfiguration.fastSyncHostConfiguration.maxMptComponentsPerMessage)
47+
val hashesRequested =
48+
mptElementsHashes.take(peerConfiguration.fastSyncHostConfiguration.maxMptComponentsPerMessage)
4449

4550
val nodeData: Seq[ByteString] = hashesRequested.flatMap { hash =>
4651
//Fetch mpt node by hash
@@ -63,13 +68,15 @@ class BlockchainHostActor(blockchain: Blockchain, peerConfiguration: PeerConfigu
6368
*/
6469
private def handleBlockFastDownload(message: Message): Option[MessageSerializable] = message match {
6570
case request: GetReceipts =>
66-
val receipts = request.blockHashes.take(peerConfiguration.fastSyncHostConfiguration.maxReceiptsPerMessage)
71+
val receipts = request.blockHashes
72+
.take(peerConfiguration.fastSyncHostConfiguration.maxReceiptsPerMessage)
6773
.flatMap(hash => blockchain.getReceiptsByHash(hash))
6874

6975
Some(Receipts(receipts))
7076

7177
case request: GetBlockBodies =>
72-
val blockBodies = request.hashes.take(peerConfiguration.fastSyncHostConfiguration.maxBlocksBodiesPerMessage)
78+
val blockBodies = request.hashes
79+
.take(peerConfiguration.fastSyncHostConfiguration.maxBlocksBodiesPerMessage)
7380
.flatMap(hash => blockchain.getBlockBodyByHash(hash))
7481

7582
Some(BlockBodies(blockBodies))
@@ -79,8 +86,8 @@ class BlockchainHostActor(blockchain: Blockchain, peerConfiguration: PeerConfigu
7986

8087
blockNumber match {
8188
case Some(startBlockNumber) if startBlockNumber >= 0 && request.maxHeaders >= 0 && request.skip >= 0 =>
82-
83-
val headersCount: BigInt = request.maxHeaders min peerConfiguration.fastSyncHostConfiguration.maxBlocksHeadersPerMessage
89+
val headersCount: BigInt =
90+
request.maxHeaders min peerConfiguration.fastSyncHostConfiguration.maxBlocksHeadersPerMessage
8491

8592
val range = if (request.reverse) {
8693
startBlockNumber to (startBlockNumber - (request.skip + 1) * headersCount + 1) by -(request.skip + 1)
@@ -105,8 +112,12 @@ class BlockchainHostActor(blockchain: Blockchain, peerConfiguration: PeerConfigu
105112

106113
object BlockchainHostActor {
107114

108-
def props(blockchain: Blockchain, peerConfiguration: PeerConfiguration,
109-
peerEventBusActor: ActorRef, etcPeerManagerActor: ActorRef): Props =
115+
def props(
116+
blockchain: Blockchain,
117+
peerConfiguration: PeerConfiguration,
118+
peerEventBusActor: ActorRef,
119+
etcPeerManagerActor: ActorRef
120+
): Props =
110121
Props(new BlockchainHostActor(blockchain, peerConfiguration, peerEventBusActor, etcPeerManagerActor))
111122

112123
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ trait FastSyncReceiptsValidator {
2323
*/
2424
def validateReceipts(requestedHashes: Seq[ByteString], receipts: Seq[Seq[Receipt]]): ReceiptsValidationResult = {
2525
val blockHashesWithReceipts = requestedHashes.zip(receipts)
26-
val blockHeadersWithReceipts = blockHashesWithReceipts.map{ case (hash, blockReceipts) =>
27-
blockchain.getBlockHeaderByHash(hash) -> blockReceipts }
26+
val blockHeadersWithReceipts = blockHashesWithReceipts.map { case (hash, blockReceipts) =>
27+
blockchain.getBlockHeaderByHash(hash) -> blockReceipts
28+
}
2829

2930
val receiptsValidationError = blockHeadersWithReceipts.collectFirst {
3031
case (Some(header), receipt) if validators.blockValidator.validateBlockAndReceipts(header, receipt).isLeft =>

0 commit comments

Comments
 (0)