Skip to content

Commit e3d1594

Browse files
author
Dmitry Voronov
committed
Next step to 2.13
1 parent 2fd002a commit e3d1594

File tree

62 files changed

+232
-158
lines changed

Some content is hidden

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

62 files changed

+232
-158
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ object ByteStringUtils {
4949
}
5050

5151
def concatByteStrings(bse: ByteStringElement*): ByteString = {
52+
concatByteStrings(bse.toIterable)
53+
}
54+
55+
def concatByteStrings(bse: Iterable[ByteStringElement]): ByteString = {
5256
val totalLength = bse.map(_.len).sum
5357
val result = new Array[Byte](totalLength)
5458
bse.foldLeft(0)( (i, el) => {

src/ets/scala/io/iohk/ethereum/ets/blockchain/BlockchainSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class BlockchainSuite extends AnyFreeSpec with Matchers with BeforeAndAfterAll w
7575
runTests(testName, args)
7676
}
7777

78-
override def afterAll: Unit = {
78+
override def afterAll(): Unit = {
7979
vm match {
8080
case extVm: ExtVMInterface => extVm.close()
8181
case _ =>

src/ets/scala/io/iohk/ethereum/ets/common/ScenarioLoader.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import java.io.File
55
import io.iohk.ethereum.utils.Logger
66
import org.apache.commons.io.FileUtils
77

8-
import scala.collection.JavaConverters._
8+
import scala.jdk.CollectionConverters._
99
import scala.io.Source
1010

1111

@@ -22,7 +22,7 @@ trait ScenarioLoader[T] extends ScenarioParser[T] with Logger {
2222
None
2323
else {
2424
log.info(s"Loading test scenarios from: $file")
25-
val text = Source.fromFile(file).getLines.mkString
25+
val text = Source.fromFile(file).getLines().mkString
2626
val scenarios = parse(text)
2727
Some(ScenarioGroup(name, scenarios))
2828
}

src/it/scala/io/iohk/ethereum/sync/util/RegularSyncItSpecUtils.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ object RegularSyncItSpecUtils {
5555
system.actorOf(PeersClient.props(etcPeerManager, peerEventBus, testSyncConfig, system.scheduler), "peers-client")
5656

5757
lazy val ledger: Ledger =
58-
new LedgerImpl(bl, blockchainConfig, syncConfig, buildEthashConsensus, Scheduler.global)
58+
new LedgerImpl(bl, blockchainConfig, syncConfig, buildEthashConsensus(), Scheduler.global)
5959

6060
lazy val ommersPool: ActorRef = system.actorOf(OmmersPool.props(bl, 1), "ommers-pool")
6161

@@ -64,7 +64,7 @@ object RegularSyncItSpecUtils {
6464
"pending-transactions-manager"
6565
)
6666

67-
lazy val validators = buildEthashConsensus.validators
67+
lazy val validators = buildEthashConsensus().validators
6868

6969
lazy val regularSync = system.actorOf(
7070
RegularSync.props(

src/it/scala/io/iohk/ethereum/txExecTest/util/DumpChainActor.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ class DumpChainActor(
6464
var peers: Seq[Peer] = Nil
6565

6666
override def preStart(): Unit = {
67-
context.system.scheduler.scheduleOnce(4 seconds, () => peerManager ! GetPeers)
67+
val r: Runnable = () => peerManager ! GetPeers
68+
context.system.scheduler.scheduleOnce(4 seconds, r)
6869
}
6970

7071
//Periodically try to connect to bootstrap peer in case the connection failed before dump termination

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ object BootstrapDownload extends Logger {
4747
try {
4848
val buffer = new Array[Byte](bufferSize)
4949

50-
Stream.continually(dis.read(buffer)).takeWhile(_ != -1).foreach(out.write(buffer, 0, _))
50+
Iterator.continually(dis.read(buffer)).takeWhile(_ != -1).foreach(out.write(buffer, 0, _))
5151
} finally (out.close())
5252
Hex.toHexString(sha512.digest)
5353

@@ -62,7 +62,7 @@ object BootstrapDownload extends Logger {
6262
try {
6363
val zis = new ZipInputStream(in)
6464
try {
65-
Stream.continually(zis.getNextEntry).takeWhile(_ != null).foreach { file =>
65+
Iterator.continually(zis.getNextEntry).takeWhile(_ != null).foreach { file =>
6666
if (!file.isDirectory) {
6767
val outPath = destination.resolve(file.getName)
6868
val outPathParent = outPath.getParent
@@ -74,7 +74,7 @@ object BootstrapDownload extends Logger {
7474
val out = new FileOutputStream(outFile)
7575
try {
7676
val buffer = new Array[Byte](bufferSize)
77-
Stream.continually(zis.read(buffer)).takeWhile(_ != -1).foreach(out.write(buffer, 0, _))
77+
Iterator.continually(zis.read(buffer)).takeWhile(_ != -1).foreach(out.write(buffer, 0, _))
7878
} finally (out.close())
7979
}
8080
}

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,19 @@ trait ReceiptsValidator {
2727
blockchain.getBlockHeaderByHash(hash) -> blockReceipts
2828
}
2929

30-
val receiptsValidationError = blockHeadersWithReceipts.collectFirst {
31-
case (Some(header), receipt) if validators.blockValidator.validateBlockAndReceipts(header, receipt).isLeft =>
32-
Invalid(validators.blockValidator.validateBlockAndReceipts(header, receipt).left.get)
33-
case (None, _) => DbError
30+
val errorIterator = blockHeadersWithReceipts.iterator.map {
31+
case (Some(header), receipt) =>
32+
validators.blockValidator.validateBlockAndReceipts(header, receipt) match {
33+
case Left(err) => Some(Invalid(err))
34+
case _ => None
35+
}
36+
case (None, _) => Some(DbError)
3437
}
38+
39+
val receiptsValidationError = errorIterator.collectFirst {
40+
case Some(error) => error
41+
}
42+
3543
receiptsValidationError.getOrElse(Valid(blockHashesWithReceipts))
3644
}
3745

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import io.vavr.collection.PriorityQueue
1313
import monix.eval.Task
1414

1515
import scala.annotation.tailrec
16+
import scala.collection.immutable.ArraySeq
1617
import scala.util.Try
1718

1819
/**
@@ -209,7 +210,8 @@ class SyncStateScheduler(blockchain: Blockchain, bloomFilter: LoadableBloomFilte
209210
}
210211

211212
case n: BranchNode =>
212-
Right(n.children.collect { case HashNode(childHash) =>
213+
val children = ArraySeq.unsafeWrapArray(n.children)
214+
Right(children.collect { case HashNode(childHash) =>
213215
StateNodeRequest(
214216
ByteString.fromArrayUnsafe(childHash),
215217
None,

src/main/scala/io/iohk/ethereum/cli/CliLauncher.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ package io.iohk.ethereum.cli
22

33
import com.monovore.decline._
44

5+
import scala.collection.immutable.ArraySeq
6+
57
//scalastyle:off
68
object CliLauncher extends App {
79

8-
CliCommands.api.map(println).parse(PlatformApp.ambientArgs getOrElse args, sys.env) match {
10+
private val arguments: Seq[String] = PlatformApp.ambientArgs getOrElse ArraySeq.unsafeWrapArray(args)
11+
CliCommands.api.map(println).parse(arguments, sys.env) match {
912
case Left(help) => System.err.println(help)
1013
case Right(_) => ()
1114
}

src/main/scala/io/iohk/ethereum/consensus/ethash/EthashMiner.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class EthashMiner(
179179
// scalastyle:off magic.number
180180
val initNonce = BigInt(64, new Random())
181181

182-
(0 to numRounds).toStream
182+
(0 to numRounds).iterator
183183
.map { n =>
184184
val nonce = (initNonce + n) % MaxNonce
185185
val nonceBytes = ByteUtils.padLeft(ByteString(nonce.toUnsignedByteArray), 8)

src/main/scala/io/iohk/ethereum/consensus/validators/std/StdValidators.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,11 @@ object StdValidators {
8787
else if (header.stateRoot != stateRootHash)
8888
Left(ValidationAfterExecError(s"Block has invalid state root hash, expected ${Hex
8989
.toHexString(header.stateRoot.toArray)} but got ${Hex.toHexString(stateRootHash.toArray)}"))
90-
else if (blockAndReceiptsValidation.isLeft)
91-
Left(ValidationAfterExecError(blockAndReceiptsValidation.left.get.toString))
92-
else
93-
Right(BlockExecutionSuccess)
90+
else {
91+
blockAndReceiptsValidation match {
92+
case Left(err) => Left(ValidationAfterExecError(err.toString))
93+
case _ => Right(BlockExecutionSuccess)
94+
}
95+
}
9496
}
9597
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class LruCache[K <: AnyRef, V <: AnyRef](
3131
}
3232

3333
override def getValues: Seq[(K, V)] = {
34-
import scala.collection.JavaConverters._
34+
import scala.jdk.CollectionConverters._
3535
lruCache.asMap().asScala.toSeq
3636
}
3737

src/main/scala/io/iohk/ethereum/db/dataSource/DataSourceBatchUpdate.scala

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

3+
import scala.collection.compat.immutable.ArraySeq
4+
35
case class DataSourceBatchUpdate(dataSource: DataSource, updates: Array[DataUpdate] = Array.empty) {
46

57
def and(that: DataSourceBatchUpdate): DataSourceBatchUpdate = {
@@ -11,7 +13,7 @@ case class DataSourceBatchUpdate(dataSource: DataSource, updates: Array[DataUpda
1113
}
1214

1315
def commit(): Unit = {
14-
dataSource.update(updates)
16+
dataSource.update(ArraySeq.unsafeWrapArray(updates))
1517
}
1618

1719
}

src/main/scala/io/iohk/ethereum/db/dataSource/RocksDbDataSource.scala

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

33
import java.util.concurrent.locks.ReentrantReadWriteLock
4+
45
import io.iohk.ethereum.utils.Logger
56
import cats.effect.Resource
67
import io.iohk.ethereum.db.dataSource.DataSource._
@@ -10,6 +11,7 @@ import monix.eval.Task
1011
import monix.reactive.Observable
1112
import org.rocksdb._
1213

14+
import scala.collection.compat.immutable.ArraySeq
1315
import scala.collection.mutable
1416
import scala.util.control.NonFatal
1517

@@ -38,7 +40,8 @@ class RocksDbDataSource(
3840
dbLock.readLock().lock()
3941
try {
4042
assureNotClosed()
41-
Option(db.get(handles(namespace), readOptions, key.toArray))
43+
val byteArray = db.get(handles(namespace), readOptions, key.toArray)
44+
Option(ArraySeq.unsafeWrapArray(byteArray))
4245
} catch {
4346
case error: RocksDbDataSourceClosedException =>
4447
throw error
@@ -269,7 +272,7 @@ object RocksDbDataSource {
269272
namespaces: Seq[Namespace]
270273
): (RocksDB, mutable.Buffer[ColumnFamilyHandle], ReadOptions, DBOptions, ColumnFamilyOptions) = {
271274
import rocksDbConfig._
272-
import scala.collection.JavaConverters._
275+
import scala.jdk.CollectionConverters._
273276

274277
RocksDB.loadLibrary()
275278

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import java.math.BigInteger
55
import io.iohk.ethereum.db.dataSource.{DataSource, DataSourceBatchUpdate}
66
import io.iohk.ethereum.db.storage.AppStateStorage._
77

8+
import scala.collection.compat.immutable.ArraySeq
9+
810
/**
911
* This class is used to store app state variables
1012
* Key: see AppStateStorage.Keys
@@ -13,10 +15,10 @@ import io.iohk.ethereum.db.storage.AppStateStorage._
1315
class AppStateStorage(val dataSource: DataSource) extends TransactionalKeyValueStorage[Key, Value] {
1416

1517
val namespace: IndexedSeq[Byte] = Namespaces.AppStateNamespace
16-
def keySerializer: Key => IndexedSeq[Byte] = _.getBytes(StorageStringCharset.UTF8Charset)
18+
def keySerializer: Key => IndexedSeq[Byte] = k => ArraySeq.unsafeWrapArray(k.getBytes(StorageStringCharset.UTF8Charset))
1719

1820
def keyDeserializer: IndexedSeq[Byte] => Key = k => new String(k.toArray, StorageStringCharset.UTF8Charset)
19-
def valueSerializer: String => IndexedSeq[Byte] = _.getBytes(StorageStringCharset.UTF8Charset)
21+
def valueSerializer: String => IndexedSeq[Byte] = k => ArraySeq.unsafeWrapArray(k.getBytes(StorageStringCharset.UTF8Charset))
2022
def valueDeserializer: IndexedSeq[Byte] => String = (valueBytes: IndexedSeq[Byte]) =>
2123
new String(valueBytes.toArray, StorageStringCharset.UTF8Charset)
2224

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import akka.util.ByteString
66
import io.iohk.ethereum.db.dataSource.DataSource
77
import io.iohk.ethereum.db.storage.BlockHeadersStorage.BlockHeaderHash
88

9+
import scala.collection.immutable.ArraySeq
10+
911
class BlockNumberMappingStorage(val dataSource: DataSource)
1012
extends TransactionalKeyValueStorage[BigInt, BlockHeaderHash] {
1113
override val namespace: IndexedSeq[Byte] = Namespaces.HeightsNamespace
1214

13-
override def keySerializer: (BigInt) => IndexedSeq[Byte] = index => index.toByteArray
15+
override def keySerializer: (BigInt) => IndexedSeq[Byte] = index => ArraySeq.unsafeWrapArray( index.toByteArray )
1416

1517
override def keyDeserializer: IndexedSeq[Byte] => BigInt = bytes => new BigInt(new BigInteger(bytes.toArray))
1618

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import io.iohk.ethereum.blockchain.sync.fast.FastSync._
99
import io.iohk.ethereum.db.dataSource.DataSource
1010
import io.iohk.ethereum.utils.ByteUtils.compactPickledBytes
1111

12+
import scala.collection.compat.immutable.ArraySeq
13+
1214
object FastSyncStateStorage {
1315

1416
val syncStateKey: String = "fast-sync-state"
@@ -33,7 +35,7 @@ class FastSyncStateStorage(val dataSource: DataSource)
3335
.addConcreteType[EvmCodeHash]
3436
.addConcreteType[StorageRootHash]
3537

36-
override def keySerializer: String => IndexedSeq[Byte] = _.getBytes(StorageStringCharset.UTF8Charset)
38+
override def keySerializer: String => IndexedSeq[Byte] = k => ArraySeq.unsafeWrapArray(k.getBytes(StorageStringCharset.UTF8Charset))
3739

3840
override def keyDeserializer: IndexedSeq[Byte] => String = b =>
3941
new String(b.toArray, StorageStringCharset.UTF8Charset)

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import io.iohk.ethereum.db.dataSource.RocksDbDataSource.IterationError
55
import io.iohk.ethereum.db.dataSource.{DataSource, DataSourceUpdate}
66
import monix.reactive.Observable
77

8+
import scala.collection.immutable.ArraySeq
9+
810
trait KeyValueStorage[K, V, T <: KeyValueStorage[K, V, T]] extends SimpleMap[K, V, T] {
911

1012
val dataSource: DataSource
@@ -48,7 +50,11 @@ trait KeyValueStorage[K, V, T <: KeyValueStorage[K, V, T]] extends SimpleMap[K,
4850

4951
def storageContent: Observable[Either[IterationError, (K, V)]] = {
5052
dataSource.iterate(namespace).map { result =>
51-
result.map { case (key, value) => (keyDeserializer(key.toIndexedSeq), valueDeserializer(value)) }
53+
result.map { case (key, value) =>
54+
val kseq = keyDeserializer(ArraySeq.unsafeWrapArray(key))
55+
val vseq = valueDeserializer(ArraySeq.unsafeWrapArray(value))
56+
(kseq, vseq)
57+
}
5258
}
5359
}
5460
}

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import java.net.URI
44

55
import io.iohk.ethereum.db.dataSource.{DataSource, DataSourceBatchUpdate}
66

7+
import scala.collection.immutable.ArraySeq
8+
79
/**
810
* This class is used to store discovered nodes
911
* Value: stored nodes list
@@ -12,9 +14,19 @@ class KnownNodesStorage(val dataSource: DataSource) extends TransactionalKeyValu
1214
val key = "KnownNodes"
1315

1416
val namespace: IndexedSeq[Byte] = Namespaces.KnownNodesNamespace
15-
def keySerializer: String => IndexedSeq[Byte] = _.getBytes(StorageStringCharset.UTF8Charset)
16-
def keyDeserializer: IndexedSeq[Byte] => String = k => new String(k.toArray, StorageStringCharset.UTF8Charset)
17-
def valueSerializer: Set[String] => IndexedSeq[Byte] = _.mkString(" ").getBytes(StorageStringCharset.UTF8Charset)
17+
18+
def keySerializer: String => IndexedSeq[Byte] = k => {
19+
ArraySeq.unsafeWrapArray(k.getBytes(StorageStringCharset.UTF8Charset))
20+
}
21+
22+
def keyDeserializer: IndexedSeq[Byte] => String = k => {
23+
new String(k.toArray, StorageStringCharset.UTF8Charset)
24+
}
25+
26+
def valueSerializer: Set[String] => IndexedSeq[Byte] = k => {
27+
ArraySeq.unsafeWrapArray(k.mkString(" ").getBytes(StorageStringCharset.UTF8Charset))
28+
}
29+
1830
def valueDeserializer: IndexedSeq[Byte] => Set[String] = (valueBytes: IndexedSeq[Byte]) =>
1931
new String(valueBytes.toArray, StorageStringCharset.UTF8Charset).split(' ').toSet
2032

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import io.iohk.ethereum.db.dataSource.RocksDbDataSource.IterationError
44
import io.iohk.ethereum.db.dataSource.{DataSource, DataSourceBatchUpdate, DataSourceUpdate}
55
import monix.reactive.Observable
66

7+
import scala.collection.immutable.ArraySeq
8+
79
/**
810
* Represents transactional key value storage mapping keys of type K to values of type V
911
* Note: all methods methods that perform updates return [[io.iohk.ethereum.db.dataSource.DataSourceBatchUpdate]]
@@ -56,7 +58,10 @@ trait TransactionalKeyValueStorage[K, V] {
5658

5759
def storageContent: Observable[Either[IterationError, (K, V)]] = {
5860
dataSource.iterate(namespace).map { result =>
59-
result.map { case (key, value) => (keyDeserializer(key.toIndexedSeq), valueDeserializer(value)) }
61+
result.map { case (key, value) =>
62+
val kseq = keyDeserializer(ArraySeq.unsafeWrapArray(key))
63+
val vseq = valueDeserializer(ArraySeq.unsafeWrapArray(value))
64+
(kseq, vseq) }
6065
}
6166
}
6267
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ class VMClient(externalVmConfig: VmConfig.ExternalConfig, messageHandler: Messag
8888
case Query.Empty =>
8989
log.debug("Client received msg: Empty")
9090
messageLoop[W, S](world)
91+
92+
case _ =>
93+
log.debug("Client received unknown msg!")
94+
messageLoop[W, S](world)
9195
}
9296
}
9397

0 commit comments

Comments
 (0)