Skip to content

Commit 4b2beab

Browse files
author
Dmitry Voronov
committed
[ETCM-129] - starting point of migration
1 parent dacec3c commit 4b2beab

32 files changed

+131
-65
lines changed

build.sbt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def commonSettings(projectName: String): Seq[sbt.Def.Setting[_]] = Seq(
1616
version := "3.2.1",
1717
scalaVersion := "2.13.4",
1818
// Scalanet snapshots are published to Sonatype after each build.
19+
resolvers += Resolver.mavenLocal,
1920
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
2021
testOptions in Test += Tests
2122
.Argument(TestFrameworks.ScalaTest, "-l", "EthashMinerSpec"), // miner tests disabled by default,
@@ -24,10 +25,6 @@ def commonSettings(projectName: String): Seq[sbt.Def.Setting[_]] = Seq(
2425
"-deprecation",
2526
"-feature",
2627
"-Xfatal-warnings",
27-
// "-Xlint:unsound-match",
28-
// "-Ywarn-inaccessible",
29-
// "-Ywarn-unused-import",
30-
// "-Ypartial-unification",
3128
"-encoding",
3229
"utf-8"
3330
),

bytes/src/main/scala/io/iohk/ethereum/utils/ByteStringUtils.scala

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,54 @@ object ByteStringUtils {
99
// unsafe
1010
def string2hash(hash: String): ByteString =
1111
ByteString(Hex.decode(hash))
12+
13+
14+
implicit class Padding(val bs: ByteString) extends AnyVal {
15+
def padToByteString(length: Int, b: Byte): ByteString = {
16+
if (length <= bs.length) bs else {
17+
val len = Math.max(bs.length, length)
18+
val result = new Array[Byte](len)
19+
bs.copyToArray(result, 0)
20+
var i = bs.length
21+
while (i < len) {
22+
result.update(i, b)
23+
i += 1
24+
}
25+
ByteString.fromArray(result)
26+
}
27+
}
28+
}
29+
30+
31+
sealed trait ByteStringElement {
32+
def len: Int
33+
def asByteArray: Array[Byte]
34+
}
35+
36+
implicit class ByteStringSelfElement(val bs: ByteString) extends ByteStringElement {
37+
def len: Int = bs.length
38+
def asByteArray: Array[Byte] = bs.toArray
39+
}
40+
41+
implicit class ByteStringArrayElement(val ar: Array[Byte]) extends ByteStringElement {
42+
def len: Int = ar.length
43+
def asByteArray: Array[Byte] = ar
44+
}
45+
46+
implicit class ByteStringByteElement(val b: Byte) extends ByteStringElement {
47+
def len: Int = 1
48+
def asByteArray: Array[Byte] = Array(b)
49+
}
50+
51+
def concatByteStrings(bse: ByteStringElement*): ByteString = {
52+
val totalLength = bse.map(_.len).sum
53+
val result = new Array[Byte](totalLength)
54+
bse.foldLeft(0)( (i, el) => {
55+
val arr = el.asByteArray
56+
System.arraycopy(arr, 0, result, i, el.len)
57+
i + el.len
58+
})
59+
ByteString.fromArray(result)
60+
}
61+
1262
}

project/Dependencies.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ object Dependencies {
8080
)
8181

8282
val network: Seq[ModuleID] = {
83-
val scalanetVersion = "0.4.4-SNAPSHOT"
83+
val scalanetVersion = "0.5.1-SNAPSHOT"
8484
Seq(
8585
"io.iohk" %% "scalanet" % scalanetVersion,
8686
"io.iohk" %% "scalanet-discovery" % scalanetVersion

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ object BootstrapDownload extends Logger {
4646
val out = new FileOutputStream(outFile)
4747
try {
4848
val buffer = new Array[Byte](bufferSize)
49+
4950
Stream.continually(dis.read(buffer)).takeWhile(_ != -1).foreach(out.write(buffer, 0, _))
5051
} finally (out.close())
5152
Hex.toHexString(sha512.digest)

src/main/scala/io/iohk/ethereum/blockchain/sync/fast/FastSync.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class FastSync(
126126
private var requestedBlockBodies: Map[ActorRef, Seq[ByteString]] = Map.empty
127127
private var requestedReceipts: Map[ActorRef, Seq[ByteString]] = Map.empty
128128

129-
private val syncStateStorageActor = context.actorOf(Props[StateStorageActor], "state-storage")
129+
private val syncStateStorageActor = context.actorOf(Props[StateStorageActor](), "state-storage")
130130

131131
syncStateStorageActor ! fastSyncStateStorage
132132

src/main/scala/io/iohk/ethereum/db/cache/Cache.scala

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

33
import io.iohk.ethereum.common.SimpleMap
4-
import scala.collection.Seq
54

65
trait Cache[K, V] extends SimpleMap[K, V, Cache[K, V]] {
76
def getValues: Seq[(K, V)]

src/main/scala/io/iohk/ethereum/db/cache/MapCache.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import java.util.concurrent.TimeUnit
44
import java.util.concurrent.atomic.AtomicLong
55

66
import io.iohk.ethereum.utils.Config.NodeCacheConfig
7-
8-
import scala.collection.{Seq, mutable}
7+
import scala.collection.mutable
98
import scala.concurrent.duration.FiniteDuration
109

1110
//TODO EC-492 Investigate more carefully possibility of having read cache in front of db
@@ -34,7 +33,7 @@ class MapCache[K, V](val cache: mutable.Map[K, V], config: NodeCacheConfig) exte
3433
}
3534
}
3635

37-
override def clear: Unit = {
36+
override def clear(): Unit = {
3837
lastClear.getAndSet(System.nanoTime())
3938
cache.clear()
4039
}

src/main/scala/io/iohk/ethereum/db/storage/CachedKeyValueStorage.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package io.iohk.ethereum.db.storage
22

33
import io.iohk.ethereum.common.SimpleMap
44
import io.iohk.ethereum.db.cache.Cache
5-
import scala.collection._
5+
//import scala.collection._
66

77
trait CachedKeyValueStorage[K, V, T <: CachedKeyValueStorage[K, V, T]] extends SimpleMap[K, V, T] {
88
type I <: KeyValueStorage[K, V, I]

src/main/scala/io/iohk/ethereum/db/storage/StateStorage.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ trait StateStorage {
2121
def onBlockSave(bn: BigInt, currentBestSavedBlock: BigInt)(updateBestBlocksData: () => Unit): Unit
2222
def onBlockRollback(bn: BigInt, currentBestSavedBlock: BigInt)(updateBestBlocksData: () => Unit): Unit
2323

24-
def saveNode(nodeHash: NodeHash, nodeEncoded: NodeEncoded, bn: BigInt)
24+
def saveNode(nodeHash: NodeHash, nodeEncoded: NodeEncoded, bn: BigInt): Unit
2525
def getNode(nodeHash: NodeHash): Option[MptNode]
2626
def forcePersist(reason: FlushSituation): Boolean
2727
}

src/main/scala/io/iohk/ethereum/db/storage/pruning/package.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ package object pruning {
1414
* @param blockNumber BlockNumber to prune
1515
* @param nodeStorage NodeStorage
1616
*/
17-
def prune(blockNumber: BigInt, nodeStorage: NodesStorage, inMemory: Boolean)
17+
def prune(blockNumber: BigInt, nodeStorage: NodesStorage, inMemory: Boolean): Unit
1818

1919
/**
2020
* Rollbacks blocknumber changes
2121
* @param blockNumber BlockNumber to rollback
2222
* @param nodeStorage NodeStorage
2323
*/
24-
def rollback(blockNumber: BigInt, nodeStorage: NodesStorage, inMemory: Boolean)
24+
def rollback(blockNumber: BigInt, nodeStorage: NodesStorage, inMemory: Boolean): Unit
2525
}
2626
}

src/main/scala/io/iohk/ethereum/extvm/MessageHandler.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import java.math.BigInteger
44

55
import akka.stream.scaladsl.{SinkQueueWithCancel, SourceQueueWithComplete}
66
import akka.util.ByteString
7-
import com.google.protobuf.CodedInputStream
8-
import com.trueaccord.scalapb.{GeneratedMessage, GeneratedMessageCompanion, LiteParser, Message}
7+
import com.google.protobuf.{CodedInputStream, Message}
98
import org.bouncycastle.util.BigIntegers
9+
import scalapb.{GeneratedMessage, GeneratedMessageCompanion, LiteParser}
1010

1111
import scala.concurrent.duration._
1212
import scala.concurrent.Await
@@ -24,9 +24,9 @@ class MessageHandler(in: SinkQueueWithCancel[ByteString], out: SourceQueueWithCo
2424
out offer (lengthBytes ++ ByteString(bytes))
2525
}
2626

27-
def awaitMessage[M <: GeneratedMessage with Message[M]](implicit companion: GeneratedMessageCompanion[M]): M = {
27+
def awaitMessage[M <: GeneratedMessage](implicit companion: GeneratedMessageCompanion[M]): M = {
2828
val resF = in.pull() map {
29-
case Some(bytes) => LiteParser.parseFrom(companion, CodedInputStream.newInstance(bytes.toArray[Byte]))
29+
case Some(bytes) => companion.parseFrom(CodedInputStream.newInstance(bytes.toArray[Byte]))
3030
case None => throw new RuntimeException("Stream completed")
3131
}
3232

src/main/scala/io/iohk/ethereum/extvm/VMClient.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Implicits._
66
import akka.util.ByteString
77
import io.iohk.ethereum.domain._
88
import io.iohk.ethereum.utils.{BlockchainConfig, Logger, VmConfig}
9+
import scalapb.UnknownFieldSet
910

1011
import scala.annotation.tailrec
1112

@@ -46,7 +47,7 @@ class VMClient(externalVmConfig: VmConfig.ExternalConfig, messageHandler: Messag
4647
log.debug("Client received msg: CallResult")
4748
res
4849

49-
case Query.GetAccount(msg.GetAccount(address)) =>
50+
case Query.GetAccount(msg.GetAccount(address, UnknownFieldSet.empty)) =>
5051
log.debug("Client received msg: GetAccount")
5152
val accountMsg = world.getAccount(address) match {
5253
case Some(acc) =>
@@ -62,20 +63,20 @@ class VMClient(externalVmConfig: VmConfig.ExternalConfig, messageHandler: Messag
6263
messageHandler.sendMessage(accountMsg)
6364
messageLoop[W, S](world)
6465

65-
case Query.GetStorageData(msg.GetStorageData(address, offset)) =>
66+
case Query.GetStorageData(msg.GetStorageData(address, offset, UnknownFieldSet.empty)) =>
6667
log.debug("Client received msg: GetStorageData")
6768
val value = world.getStorage(address).load(offset)
6869
val storageDataMsg = msg.StorageData(data = value)
6970
messageHandler.sendMessage(storageDataMsg)
7071
messageLoop[W, S](world)
7172

72-
case Query.GetCode(msg.GetCode(address)) =>
73+
case Query.GetCode(msg.GetCode(address, UnknownFieldSet.empty)) =>
7374
log.debug("Client received msg: GetCode")
7475
val codeMsg = msg.Code(world.getCode(address))
7576
messageHandler.sendMessage(codeMsg)
7677
messageLoop[W, S](world)
7778

78-
case Query.GetBlockhash(msg.GetBlockhash(offset)) =>
79+
case Query.GetBlockhash(msg.GetBlockhash(offset, UnknownFieldSet.empty)) =>
7980
log.debug("Client received msg: GetBlockhash")
8081
val blockhashMsg = world.getBlockHash(offset) match {
8182
case Some(value) => msg.Blockhash(hash = value)

src/main/scala/io/iohk/ethereum/extvm/VMServer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import com.typesafe.config.ConfigFactory
1010
import io.iohk.ethereum.domain.{Address, BlockHeader}
1111
import io.iohk.ethereum.extvm.Implicits._
1212
import io.iohk.ethereum.utils._
13-
import io.iohk.ethereum.vm.{BlockchainConfigForEvm, ProgramResult, _}
13+
import io.iohk.ethereum.vm.{BlockchainConfigForEvm, ProgramResult, VM, ProgramContext, EvmConfig}
1414
import java.nio.ByteOrder
1515
import scala.annotation.tailrec
1616
import scala.util.{Failure, Success, Try}

src/main/scala/io/iohk/ethereum/faucet/FaucetSupervisor.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ class FaucetSupervisor(walletService: WalletService, config: FaucetConfig, shutd
3434
)
3535
.withAutoReset(autoReset)
3636
.withSupervisorStrategy(OneForOneStrategy() {
37-
case error: WalletException
37+
case error: WalletException =>
3838
log.error(s"Stop ${FaucetHandler.name}", error)
3939
shutdown()
4040
SupervisorStrategy.Stop
41-
case error
41+
case error =>
4242
log.error(s"Restart ${FaucetHandler.name}", error)
4343
SupervisorStrategy.Restart
4444
})

src/main/scala/io/iohk/ethereum/faucet/jsonrpc/FaucetBuilder.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ trait ShutdownHookBuilder {
9797

9898
def shutdown(): Unit = {
9999
Await.ready(
100-
system.terminate.map(
100+
system.terminate().map(
101101
_ ->
102102
log.info("actor system finished")
103103
)(system.dispatcher),

src/main/scala/io/iohk/ethereum/jsonrpc/EthService.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ class EthService(
649649
case Right(data) =>
650650
call(CallRequest(CallTx(tx.from, tx.to, tx.gas, tx.gasPrice, tx.value, ByteString(data)), req.block))
651651
.map(_.right.map { callResponse =>
652-
IeleCallResponse(rlp.decode[Seq[ByteString]](callResponse.returnData.toArray[Byte])(seqEncDec[ByteString]))
652+
IeleCallResponse(rlp.decode[Seq[ByteString]](callResponse.returnData.toArray[Byte])(seqEncDec[ByteString]()))
653653
})
654654
case Left(error) => Task.now(Left(error))
655655
}

src/main/scala/io/iohk/ethereum/ledger/BlockMetrics.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ case object BlockMetrics extends MetricsContainer {
3838
case Some(parentBlock) =>
3939
val timeBetweenBlocksInSeconds: Long =
4040
block.header.unixTimestamp - parentBlock.header.unixTimestamp
41-
TimeBetweenParentGauge.set(timeBetweenBlocksInSeconds)
41+
TimeBetweenParentGauge.set(timeBetweenBlocksInSeconds.toDouble)
4242
case None => ()
4343
}
4444
}

src/main/scala/io/iohk/ethereum/metrics/DeltaSpikeGauge.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class DeltaSpikeGauge(name: String, metrics: Metrics) {
2121
}
2222
}
2323

24-
private[this] final val gauge = metrics.gauge(name, () => getValue)
24+
private[this] final val gauge = metrics.gauge(name, () => getValue())
2525

2626
def trigger(): Unit = {
2727
if (isTriggeredRef.compareAndSet(false, true)) {

src/main/scala/io/iohk/ethereum/network/PeerEventBusActor.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ object PeerEventBusActor {
8282
* @param subscriber
8383
*/
8484
override def unsubscribe(subscriber: ActorRef): Unit = {
85-
messageSubscriptions = messageSubscriptions.filterKeys(_._1 != subscriber)
85+
messageSubscriptions = messageSubscriptions.filter {
86+
case ((sub, _), _) =>
87+
sub != subscriber
88+
}
8689
connectionSubscriptions = connectionSubscriptions.filterNot(_.subscriber == subscriber)
8790
}
8891

src/main/scala/io/iohk/ethereum/network/PeerStatisticsActor.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ class PeerStatisticsActor(
3939
private def handleStatsRequests: Receive = {
4040
case GetStatsForAll(window) =>
4141
val stats = maybeStats.map(_.getAll(Some(window))).getOrElse(Map.empty)
42-
sender ! StatsForAll(stats)
42+
sender() ! StatsForAll(stats)
4343

4444
case GetStatsForPeer(window, peerId) =>
4545
val stats = maybeStats.map(_.get(peerId, Some(window))).getOrElse(PeerStat.empty)
46-
sender ! StatsForPeer(peerId, stats)
46+
sender() ! StatsForPeer(peerId, stats)
4747
}
4848
}
4949

src/main/scala/io/iohk/ethereum/network/TimeSlotStats.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ class TimeSlotStats[K, V: Monoid] private (
4242
}
4343

4444
/** Forget all statistics about a given key. */
45-
def remove(key: K): TimeSlotStats[K, V] =
46-
updated(lastIdx, buffer.mapValues(_.remove(key)))
45+
def remove(key: K): TimeSlotStats[K, V] = {
46+
updated(lastIdx, buffer.map { case (k, v) => k -> v.remove(key) })
47+
}
4748

4849
/** Aggregate stats for a key in all slots that are within the duration. */
4950
def get(key: K, window: Option[Duration] = None): V =

src/main/scala/io/iohk/ethereum/network/discovery/DiscoveryServiceBuilder.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ trait DiscoveryServiceBuilder {
7272
for {
7373
reusedKnownNodes <-
7474
if (discoveryConfig.reuseKnownNodes)
75-
Task(knownNodesStorage.getKnownNodes.map(Node.fromUri))
75+
Task(knownNodesStorage.getKnownNodes().map(Node.fromUri))
7676
else
7777
Task.pure(Set.empty[Node])
7878
// Discovery is going to enroll with all the bootstrap nodes passed to it.

src/main/scala/io/iohk/ethereum/network/discovery/PeerDiscoveryManager.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ class PeerDiscoveryManager(
7979

8080
private def handleNodeInfoRequests(discovery: Option[Discovery]): Receive = {
8181
case GetDiscoveredNodesInfo =>
82-
sendDiscoveredNodesInfo(discovery.map(_._1), sender)
82+
sendDiscoveredNodesInfo(discovery.map(_._1), sender())
8383

8484
case GetRandomNodeInfo =>
85-
sendRandomNodeInfo(discovery.map(_._2), sender)
85+
sendRandomNodeInfo(discovery.map(_._2), sender())
8686
}
8787

8888
// The service hasn't been started yet, so it just serves the static known nodes.

src/main/scala/io/iohk/ethereum/network/rlpx/AuthInitiateMessage.scala

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,22 @@ case class AuthInitiateMessage(
3636
knownPeer: Boolean
3737
) extends AuthInitiateEcdsaCodec {
3838

39-
lazy val encoded: ByteString = {
40-
encodeECDSA(signature) ++
41-
ephemeralPublicHash ++
42-
//byte 0 of encoded ECC point indicates that it is uncompressed point, it is part of bouncycastle encoding
43-
publicKey.getEncoded(false).drop(1) ++
44-
nonce ++
45-
ByteString(if (knownPeer) 1.toByte else 0.toByte)
46-
}
39+
import io.iohk.ethereum.utils.ByteStringUtils._
40+
lazy val encoded: ByteString = concatByteStrings(
41+
encodeECDSA(signature),
42+
ephemeralPublicHash,
43+
publicKey.getEncoded(false).drop(1),
44+
nonce,
45+
ByteString(if (knownPeer) 1.toByte else 0.toByte)
46+
)
47+
48+
49+
// lazy val encoded: ByteString = {
50+
// encodeECDSA(signature) ++
51+
// ephemeralPublicHash ++
52+
// //byte 0 of encoded ECC point indicates that it is uncompressed point, it is part of bouncycastle encoding
53+
// publicKey.getEncoded(false).drop(1) ++
54+
// nonce ++
55+
// ByteString(if (knownPeer) 1.toByte else 0.toByte)
56+
// }
4757
}

0 commit comments

Comments
 (0)