Skip to content

[ETCM-141] scalafmt #743

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

Merged
merged 5 commits into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 8 additions & 0 deletions .buildkite/pipeline.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,16 @@ in
];
};

scalafmt = commonAttrs // {
label = "scalafmtCheck";
command = ''
nix-shell --run '$SBT scalafmtCheck'
'';
};

compile = commonAttrs // {
label = "compile everything";
dependsOn = [ scalafmt ];
command = ''
nix-shell --run '$SBT compile-all'
'';
Expand Down
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
logLevel := sbt.Level.Warn
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2")
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.7.5")
addSbtPlugin("com.thoughtworks.sbt-api-mappings" % "sbt-api-mappings" % "3.0.0")
Expand Down
80 changes: 80 additions & 0 deletions project/repo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,22 @@
url = "https://repo1.maven.org/maven2/com/typesafe/config/1.2.0/config-1.2.0.pom";
sha256 = "057A2C5F4D6A0AEEB8B74B0A1A020F8B84B425768DEBE878CEB04E5A6CEEE522";
};
"nix-public/com/typesafe/config/1.4.0/config-1.4.0-javadoc.jar" = {
url = "https://repo1.maven.org/maven2/com/typesafe/config/1.4.0/config-1.4.0-javadoc.jar";
sha256 = "768E976B8B59A2E04FD025507222A95F032447803F6FC3E463F45F2247E9B440";
};
"nix-public/com/typesafe/config/1.4.0/config-1.4.0-sources.jar" = {
url = "https://repo1.maven.org/maven2/com/typesafe/config/1.4.0/config-1.4.0-sources.jar";
sha256 = "FFAF8892DC8C61605BD7319C6CDCEA022B6C9C28B62776915A809E8DE93D8A6E";
};
"nix-public/com/typesafe/config/1.4.0/config-1.4.0.jar" = {
url = "https://repo1.maven.org/maven2/com/typesafe/config/1.4.0/config-1.4.0.jar";
sha256 = "AADBFD5A524551BEEF10D3F891D305B83BB27D54703D9A4DE7ACA2A12D9847E2";
};
"nix-public/com/typesafe/config/1.4.0/config-1.4.0.pom" = {
url = "https://repo1.maven.org/maven2/com/typesafe/config/1.4.0/config-1.4.0.pom";
sha256 = "7DF98E93E8BDC6A8EDB86314AC8BA31F260CBD4A0E6B86F5E9AFC932512EF0C7";
};
"nix-public/com/typesafe/ssl-config-core_2.12/0.2.2/ssl-config-core_2.12-0.2.2-javadoc.jar" = {
url = "https://repo1.maven.org/maven2/com/typesafe/ssl-config-core_2.12/0.2.2/ssl-config-core_2.12-0.2.2-javadoc.jar";
sha256 = "9185CF15E1393676F00A0D130E7AA307D1C69A0D2AA2CCD568E73DD1521AFCF9";
Expand All @@ -545,6 +561,22 @@
url = "https://repo1.maven.org/maven2/com/typesafe/ssl-config-core_2.12/0.2.2/ssl-config-core_2.12-0.2.2.pom";
sha256 = "521E96B4352FF2CB3B1D4FE7BBB935E53D1BCA9412DD1BC9D2E61F7027A1938F";
};
"nix-public/io/get-coursier/interface/0.0.17/interface-0.0.17-javadoc.jar" = {
url = "https://repo1.maven.org/maven2/io/get-coursier/interface/0.0.17/interface-0.0.17-javadoc.jar";
sha256 = "DA2F22B2A34EBA8BD03038D443412158DE67D022A6B1EB042DDEF84F3A50033E";
};
"nix-public/io/get-coursier/interface/0.0.17/interface-0.0.17-sources.jar" = {
url = "https://repo1.maven.org/maven2/io/get-coursier/interface/0.0.17/interface-0.0.17-sources.jar";
sha256 = "F79C739FE81C23DC60A13A4C12877155197F32C985700CA8055BDB1DD1837729";
};
"nix-public/io/get-coursier/interface/0.0.17/interface-0.0.17.jar" = {
url = "https://repo1.maven.org/maven2/io/get-coursier/interface/0.0.17/interface-0.0.17.jar";
sha256 = "B3987E8C02441E82D88AB8727ACD64EABF3A35217FFEDBA904B125E06A722A77";
};
"nix-public/io/get-coursier/interface/0.0.17/interface-0.0.17.pom" = {
url = "https://repo1.maven.org/maven2/io/get-coursier/interface/0.0.17/interface-0.0.17.pom";
sha256 = "6E23602D09BC9EAA98AF430DB24A2A18A9DD8834FF3820B58D90CA52E561643A";
};
"nix-public/jline/jline/2.14.4/jline-2.14.4-javadoc.jar" = {
url = "https://repo1.maven.org/maven2/jline/jline/2.14.4/jline-2.14.4-javadoc.jar";
sha256 = "0A8A33DFCC39D18D5EC065FA70289182456DC96F635892F41899DA0462293BC0";
Expand Down Expand Up @@ -2121,6 +2153,54 @@
url = "https://repo1.maven.org/maven2/org/scala-sbt/zinc_2.12/1.2.5/zinc_2.12-1.2.5.pom";
sha256 = "6F9E98A5449DD7D6EB4E4EF65236B5CFFB7821B94C2CDF83C75D658309C29454";
};
"nix-public/org/scalameta/sbt-scalafmt_2.12_1.0/2.4.2/sbt-scalafmt-2.4.2-javadoc.jar" = {
url = "https://repo1.maven.org/maven2/org/scalameta/sbt-scalafmt_2.12_1.0/2.4.2/sbt-scalafmt-2.4.2-javadoc.jar";
sha256 = "C49C0BFF9FDE1B8C1374760D942A13E063F3221A6A32AC6048109B205BB9959B";
};
"nix-public/org/scalameta/sbt-scalafmt_2.12_1.0/2.4.2/sbt-scalafmt-2.4.2-sources.jar" = {
url = "https://repo1.maven.org/maven2/org/scalameta/sbt-scalafmt_2.12_1.0/2.4.2/sbt-scalafmt-2.4.2-sources.jar";
sha256 = "6C4EDBE1A02CF207AB5F3E3C50EBD16F3CA1F072FC5E711742D59765F72C43A4";
};
"nix-public/org/scalameta/sbt-scalafmt_2.12_1.0/2.4.2/sbt-scalafmt-2.4.2.jar" = {
url = "https://repo1.maven.org/maven2/org/scalameta/sbt-scalafmt_2.12_1.0/2.4.2/sbt-scalafmt-2.4.2.jar";
sha256 = "6E8F1FE4487BD75C27B0004C4CFCD3D8497872068234206477A933FB36C595B7";
};
"nix-public/org/scalameta/sbt-scalafmt_2.12_1.0/2.4.2/sbt-scalafmt-2.4.2.pom" = {
url = "https://repo1.maven.org/maven2/org/scalameta/sbt-scalafmt_2.12_1.0/2.4.2/sbt-scalafmt-2.4.2.pom";
sha256 = "8551E14FA61006C5BE413B7F92893EEBE5819F9F3EC2BDC8EA0B3CA6AFACF80E";
};
"nix-public/org/scalameta/scalafmt-dynamic_2.12/2.6.4/scalafmt-dynamic_2.12-2.6.4-javadoc.jar" = {
url = "https://repo1.maven.org/maven2/org/scalameta/scalafmt-dynamic_2.12/2.6.4/scalafmt-dynamic_2.12-2.6.4-javadoc.jar";
sha256 = "41029FC1E01E39EAE3003524E5743461EB46FDCF92220BEC16899B08763D5B9F";
};
"nix-public/org/scalameta/scalafmt-dynamic_2.12/2.6.4/scalafmt-dynamic_2.12-2.6.4-sources.jar" = {
url = "https://repo1.maven.org/maven2/org/scalameta/scalafmt-dynamic_2.12/2.6.4/scalafmt-dynamic_2.12-2.6.4-sources.jar";
sha256 = "B282E2B6F32AB1D4A1A1B2F39DCDB41867175CE793687292C64C9C88DC662CC8";
};
"nix-public/org/scalameta/scalafmt-dynamic_2.12/2.6.4/scalafmt-dynamic_2.12-2.6.4.jar" = {
url = "https://repo1.maven.org/maven2/org/scalameta/scalafmt-dynamic_2.12/2.6.4/scalafmt-dynamic_2.12-2.6.4.jar";
sha256 = "3CA0741037FE210B263A9BFD19BFCBEF44D0FCEA0D53AB099379649E6C1DD34E";
};
"nix-public/org/scalameta/scalafmt-dynamic_2.12/2.6.4/scalafmt-dynamic_2.12-2.6.4.pom" = {
url = "https://repo1.maven.org/maven2/org/scalameta/scalafmt-dynamic_2.12/2.6.4/scalafmt-dynamic_2.12-2.6.4.pom";
sha256 = "F9BB5B151A2B57E1A0D7931C40B2C12E96A317A2DBAE6C435D4EEAAD1762E764";
};
"nix-public/org/scalameta/scalafmt-interfaces/2.6.4/scalafmt-interfaces-2.6.4-javadoc.jar" = {
url = "https://repo1.maven.org/maven2/org/scalameta/scalafmt-interfaces/2.6.4/scalafmt-interfaces-2.6.4-javadoc.jar";
sha256 = "1496DB1A12504C5F7C60AB97664F6254A9BC6A7D1A78F44FDDD52F7CF86510DC";
};
"nix-public/org/scalameta/scalafmt-interfaces/2.6.4/scalafmt-interfaces-2.6.4-sources.jar" = {
url = "https://repo1.maven.org/maven2/org/scalameta/scalafmt-interfaces/2.6.4/scalafmt-interfaces-2.6.4-sources.jar";
sha256 = "B501B8C7E4FA26F53E2B2EC4EBB4710DE2F0F23B7932FFDB75EEB4F3A2EFF367";
};
"nix-public/org/scalameta/scalafmt-interfaces/2.6.4/scalafmt-interfaces-2.6.4.jar" = {
url = "https://repo1.maven.org/maven2/org/scalameta/scalafmt-interfaces/2.6.4/scalafmt-interfaces-2.6.4.jar";
sha256 = "413C8D3A2EBE0C78055A526294A4462FB9DDC80633BFB3DCDBC9B66069FA757A";
};
"nix-public/org/scalameta/scalafmt-interfaces/2.6.4/scalafmt-interfaces-2.6.4.pom" = {
url = "https://repo1.maven.org/maven2/org/scalameta/scalafmt-interfaces/2.6.4/scalafmt-interfaces-2.6.4.pom";
sha256 = "E7FBB300A5FF656DDC91FC08D5399A6234FA38AF6F7A269EBBF7336C6B514754";
};
"nix-public/org/scalariform/scalariform_2.12/0.2.0/scalariform_2.12-0.2.0-javadoc.jar" = {
url = "https://repo1.maven.org/maven2/org/scalariform/scalariform_2.12/0.2.0/scalariform_2.12-0.2.0-javadoc.jar";
sha256 = "CACC165E5BEC7DF0C36A04C3B7B1194D5E521D53E691DA698B9CE07047169137";
Expand Down
36 changes: 18 additions & 18 deletions src/main/scala/io/iohk/ethereum/App.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import io.iohk.ethereum.faucet.Faucet
import io.iohk.ethereum.mallet.main.Mallet
import io.iohk.ethereum.utils.{Config, Logger}


object App extends Logger {

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

args.headOption match {
case None => Mantis.main(args)
case Some(`launchMantis`) => Mantis.main(args.tail)
case Some(`launchKeytool`) => KeyTool.main(args.tail)
case Some(`downloadBootstrap`) => {
Config.Db.dataSource match {
case "rocksdb" => BootstrapDownload.main(args.tail :+ Config.Db.RocksDb.path)
}
args.headOption match {
case None => Mantis.main(args)
case Some(`launchMantis`) => Mantis.main(args.tail)
case Some(`launchKeytool`) => KeyTool.main(args.tail)
case Some(`downloadBootstrap`) => {
Config.Db.dataSource match {
case "rocksdb" => BootstrapDownload.main(args.tail :+ Config.Db.RocksDb.path)
}
case Some(`vmServer`) => VmServerApp.main(args.tail)
case Some(`mallet`) => Mallet.main(args.tail)
case Some(`faucet`) => Faucet.main(args.tail)
case Some(`ecKeyGen`) => EcKeyGen.main(args.tail)
case Some(unknown) =>
log.error(s"Unrecognised launcher option, " +
s"first parameter must be $launchKeytool, $downloadBootstrap, $launchMantis, " +
s"$mallet, $faucet, $vmServer or $ecKeyGen")
}

case Some(`vmServer`) => VmServerApp.main(args.tail)
case Some(`mallet`) => Mallet.main(args.tail)
case Some(`faucet`) => Faucet.main(args.tail)
case Some(`ecKeyGen`) => EcKeyGen.main(args.tail)
case Some(unknown) =>
log.error(
s"Unrecognised launcher option, " +
s"first parameter must be $launchKeytool, $downloadBootstrap, $launchMantis, " +
s"$mallet, $faucet, $vmServer or $ecKeyGen"
)
}

}
}
55 changes: 30 additions & 25 deletions src/main/scala/io/iohk/ethereum/BootstrapDownload.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.iohk.ethereum


import java.io.{File, FileInputStream, FileOutputStream}
import java.net.URL
import java.nio.file._
Expand All @@ -10,8 +9,6 @@ import java.util.zip.ZipInputStream
import io.iohk.ethereum.utils.Logger
import org.bouncycastle.util.encoders.Hex



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

private def assertAndLog(cond: Boolean, msg: String): Unit = {
if(!cond) log.info(msg)
if (!cond) log.info(msg)
assert(cond, msg)
}

def cleanOutFolder(pathToDownloadTo: Path): Unit = {
val leveldbFolder = pathToDownloadTo.toFile
assertAndLog(leveldbFolder.isDirectory, s"${pathToDownloadTo} must be a folder.")
assertAndLog(leveldbFolder.getName == leveldbFolderName, s"${pathToDownloadTo} must end in a folder named $leveldbFolderName")
assertAndLog(
leveldbFolder.getName == leveldbFolderName,
s"${pathToDownloadTo} must end in a folder named $leveldbFolderName"
)
leveldbFolder.listFiles(pathname => !pathname.getName.endsWith(".zip")).foreach(_.delete())
}

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

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

} finally {
dis.close()
Expand All @@ -74,34 +74,37 @@ object BootstrapDownload extends Logger {
try {
val buffer = new Array[Byte](bufferSize)
Stream.continually(zis.read(buffer)).takeWhile(_ != -1).foreach(out.write(buffer, 0, _))
} finally(out.close())
} finally (out.close())
}
}
} finally(zis.close())
} finally(in.close())
} finally (zis.close())
} finally (in.close())
}


def deleteDownloadedFile(downloadedFile: File): Unit = {
if(downloadedFile.delete()) log.info(s"Downloaded file $downloadedFile successfully deleted")
if (downloadedFile.delete()) log.info(s"Downloaded file $downloadedFile successfully deleted")
else log.info(s"Failed to delete downloaded file $downloadedFile")
}

// scalastyle:off method.length
def main(args: Array[String]): Unit = {
//download a zip file from a url.

assertAndLog(args.length == 4, "Provide the url to download from, " +
" expected hash of the downloaded file, " +
" the minimum required free disk space in giga bytes" +
" and the path to extract the file to")
assertAndLog(
args.length == 4,
"Provide the url to download from, " +
" expected hash of the downloaded file, " +
" the minimum required free disk space in giga bytes" +
" and the path to extract the file to"
)

val urlToDownloadFrom = new URL(args(0))
val expectedHash = args(1)
val minimumExpectedDiskSpace = args(2)
val pathToDownloadTo = Paths.get(args(3))

val bytesInOneGigaByte = 1024l * 1024l * 1024l
val minimumExpectedDiskSpaceInBytes = minimumExpectedDiskSpace.toLong * bytesInOneGigaByte
val bytesInOneGigaByte = 1024L * 1024L * 1024L
val minimumExpectedDiskSpaceInBytes = minimumExpectedDiskSpace.toLong * bytesInOneGigaByte

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

if(!pathToDownloadToAsFile.exists()) pathToDownloadToAsFile.mkdirs()
if (!pathToDownloadToAsFile.exists()) pathToDownloadToAsFile.mkdirs()

assertAndLog(pathToDownloadToAsFile.isDirectory, s"$pathToDownloadToAsFile must be a folder.")
assertAndLog(pathToDownloadToAsFile.getUsableSpace() >= minimumExpectedDiskSpaceInBytes,
s"There is not enough free space ($minimumExpectedDiskSpace GB) to download and expand to $pathToDownloadTo ")
assertAndLog(
pathToDownloadToAsFile.getUsableSpace() >= minimumExpectedDiskSpaceInBytes,
s"There is not enough free space ($minimumExpectedDiskSpace GB) to download and expand to $pathToDownloadTo "
)

log.info(s"Free space check ok, starting download! (this could take some time)")
val hash = downloadFile(args(0), downloadedFile)
Expand Down
1 change: 0 additions & 1 deletion src/main/scala/io/iohk/ethereum/KeyTool.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.iohk.ethereum


object KeyTool {

def main(args: Array[String]): Unit = sun.security.tools.keytool.Main.main(args)
Expand Down
3 changes: 1 addition & 2 deletions src/main/scala/io/iohk/ethereum/Mantis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ object Mantis extends Logger {
if (Config.testmode) {
log.info("Starting Mantis in test mode")
new TestNode
}
else new StdNode
} else new StdNode

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ import org.bouncycastle.util.encoders.Hex
import scala.io.Source
import scala.util.{Failure, Success, Try}

class GenesisDataLoader(
blockchain: Blockchain,
blockchainConfig: BlockchainConfig)
extends Logger{
class GenesisDataLoader(blockchain: Blockchain, blockchainConfig: BlockchainConfig) extends Logger {

private val bloomLength = 512
private val hashLength = 64
Expand Down Expand Up @@ -90,13 +87,17 @@ class GenesisDataLoader(
val storage = stateStorage.getReadOnlyStorage
val initalRootHash = MerklePatriciaTrie.EmptyRootHash

val stateMptRootHash = genesisData.alloc.zipWithIndex.foldLeft(initalRootHash) { case (rootHash, (((address, AllocAccount(balance)), idx))) =>
val mpt = MerklePatriciaTrie[Array[Byte], Account](rootHash, storage)
val paddedAddress = address.reverse.padTo(addressLength, "0").reverse.mkString
val stateRoot = mpt.put(crypto.kec256(Hex.decode(paddedAddress)),
Account(blockchainConfig.accountStartNonce, UInt256(BigInt(balance)), emptyTrieRootHash, emptyEvmHash)
).getRootHash
stateRoot
val stateMptRootHash = genesisData.alloc.zipWithIndex.foldLeft(initalRootHash) {
case (rootHash, (((address, AllocAccount(balance)), idx))) =>
val mpt = MerklePatriciaTrie[Array[Byte], Account](rootHash, storage)
val paddedAddress = address.reverse.padTo(addressLength, "0").reverse.mkString
val stateRoot = mpt
.put(
crypto.kec256(Hex.decode(paddedAddress)),
Account(blockchainConfig.accountStartNonce, UInt256(BigInt(balance)), emptyTrieRootHash, emptyEvmHash)
)
.getRootHash
stateRoot
}

val header: BlockHeader = prepareHeader(genesisData, stateMptRootHash)
Expand All @@ -108,8 +109,12 @@ class GenesisDataLoader(
log.debug("Genesis data already in the database")
Success(())
case Some(_) =>
Failure(new RuntimeException("Genesis data present in the database does not match genesis block from file." +
" Use different directory for running private blockchains."))
Failure(
new RuntimeException(
"Genesis data present in the database does not match genesis block from file." +
" Use different directory for running private blockchains."
)
)
case None =>
storage.persist()
stateStorage.forcePersist(GenesisDataLoad)
Expand Down Expand Up @@ -158,12 +163,13 @@ object GenesisDataLoader {
case other => throw new RuntimeException("Expected hex string, but got: " + other)
}

object ByteStringJsonSerializer extends CustomSerializer[ByteString](formats =>
(
{ case jv => deserializeByteString(jv) },
PartialFunction.empty
)
)
object ByteStringJsonSerializer
extends CustomSerializer[ByteString](formats =>
(
{ case jv => deserializeByteString(jv) },
PartialFunction.empty
)
)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ case class GenesisData(
gasLimit: String,
coinbase: ByteString,
timestamp: String,
alloc: Map[String, AllocAccount])
alloc: Map[String, AllocAccount]
)
Loading