Skip to content

Commit 1b1d3d6

Browse files
authored
Merge branch 'develop' into fix/ETCM-927_ChainAtoChainB_difficultyB
2 parents f9f5968 + 17e68c3 commit 1b1d3d6

36 files changed

+545
-164
lines changed

nix/overlay.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ rev: final: prev: {
33

44
mantis = final.callPackage ./mantis.nix {
55
src = ../.;
6-
depsSha256 = "sha256-US4L/xh2otnEfOa05bazb14bgYhQZpF4GfFY30sDkNY=";
6+
depsSha256 = "sha256-QXIsF46M9gKhLD8EWMsyxDRWQNzgzWv3pctRJEEHbYM=";
77
};
88

99
mantis-hash = final.mantis.override {

project/Dependencies.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ object Dependencies {
7070
)
7171

7272
val cats: Seq[ModuleID] = {
73-
val catsVersion = "2.2.0"
73+
val catsVersion = "2.6.1"
7474
Seq(
7575
"org.typelevel" %% "mouse" % "0.25",
7676
"org.typelevel" %% "cats-core" % catsVersion,
77-
"org.typelevel" %% "cats-effect" % catsVersion
77+
"org.typelevel" %% "cats-effect" % "2.5.1"
7878
)
7979
}
8080

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ abstract class CommonFakePeer(peerName: String, fakePeerCustomConfig: FakePeerCu
116116
)
117117

118118
val bl = BlockchainImpl(storagesInstance.storages)
119+
val evmCodeStorage = storagesInstance.storages.evmCodeStorage
119120

120121
val genesis = Block(
121122
Fixtures.Blocks.Genesis.header.copy(stateRoot = ByteString(MerklePatriciaTrie.EmptyRootHash)),
@@ -203,7 +204,10 @@ abstract class CommonFakePeer(peerName: String, fakePeerCustomConfig: FakePeerCu
203204
)
204205

205206
val blockchainHost: ActorRef =
206-
system.actorOf(BlockchainHostActor.props(bl, peerConf, peerEventBus, etcPeerManager), "blockchain-host")
207+
system.actorOf(
208+
BlockchainHostActor.props(bl, storagesInstance.storages.evmCodeStorage, peerConf, peerEventBus, etcPeerManager),
209+
"blockchain-host"
210+
)
207211

208212
lazy val server: ActorRef = system.actorOf(ServerActor.props(nodeStatusHolder, peerManager), "server")
209213

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ object FastSyncItSpecUtils {
2929
storagesInstance.storages.fastSyncStateStorage,
3030
storagesInstance.storages.appStateStorage,
3131
bl,
32+
storagesInstance.storages.evmCodeStorage,
33+
storagesInstance.storages.nodeStorage,
3234
validators,
3335
peerEventBus,
3436
etcPeerManager,
@@ -72,7 +74,7 @@ object FastSyncItSpecUtils {
7274
val codeHash = kec256(accountExpectedCode)
7375
val accountExpectedStorageAddresses = (i until i + 20).toList
7476
val account = bl.getAccount(accountAddress, blockNumber).get
75-
val code = bl.getEvmCodeByHash(codeHash).get
77+
val code = evmCodeStorage.get(codeHash).get
7678
val storedData = accountExpectedStorageAddresses.map { addr =>
7779
ByteUtils.toBigInt(bl.getAccountStorageAt(account.storageRoot, addr, ethCompatibleStorage = true))
7880
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,6 @@ class BlockchainMock(genesisHash: ByteString) extends Blockchain {
180180

181181
override def getChainWeightByHash(blockhash: ByteString): Option[ChainWeight] = ???
182182

183-
override def getEvmCodeByHash(hash: ByteString): Option[ByteString] = ???
184-
185183
override def getReceiptsByHash(blockhash: ByteString): Option[Seq[Receipt]] = ???
186184

187185
def getAccount(address: Address, blockNumber: BigInt): Option[Account] = ???
@@ -219,6 +217,4 @@ class BlockchainMock(genesisHash: ByteString) extends Blockchain {
219217
override def save(block: Block, receipts: Seq[Receipt], weight: ChainWeight, saveAsBestBlock: Boolean): Unit = ???
220218

221219
override def getLatestCheckpointBlockNumber(): BigInt = ???
222-
223-
override def mptStateSavedKeys(): Observable[Either[RocksDbDataSource.IterationError, NodeHash]] = ???
224220
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ object FixtureProvider {
4646
override val blockBodiesStorage: BlockBodiesStorage = new BlockBodiesStorage(dataSource)
4747
override val chainWeightStorage: ChainWeightStorage = new ChainWeightStorage(dataSource)
4848
override val transactionMappingStorage: TransactionMappingStorage = new TransactionMappingStorage(dataSource)
49-
override val nodeStorage: NodeStorage = new NodeStorage(dataSource)
50-
override val cachedNodeStorage: CachedNodeStorage = new CachedNodeStorage(nodeStorage, caches.nodeCache)
51-
override val pruningMode: PruningMode = ArchivePruning
5249
override val appStateStorage: AppStateStorage = new AppStateStorage(dataSource)
50+
val nodeStorage: NodeStorage = new NodeStorage(dataSource)
51+
val cachedNodeStorage: CachedNodeStorage = new CachedNodeStorage(nodeStorage, caches.nodeCache)
52+
val pruningMode: PruningMode = ArchivePruning
5353
override val stateStorage: StateStorage =
5454
StateStorage(
5555
pruningMode,

src/main/resources/conf/chains/etc-chain.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@
126126

127127
# List of accounts to be drained
128128
drain-list = null
129+
130+
# Tells whether this fork should be included on the fork id list used for peer validation
131+
include-on-fork-id-list = false
129132
}
130133

131134
# Starting nonce of an empty account. Some networks (like Morden) use different values.

src/main/resources/conf/chains/eth-chain.conf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@
236236
"bb9bc244d798123fde783fcc1c72d3bb8c189413",
237237
"807640a13483f8ac783c557fcdf27be11ea4ac7a"
238238
]
239+
240+
# Tells whether this fork should be included on the fork id list used for peer validation
241+
include-on-fork-id-list = true
239242
}
240243

241244
# Starting nonce of an empty account. Some networks (like Morden) use different values.
@@ -292,4 +295,3 @@
292295
"enode://979b7fa28feeb35a4741660a16076f1943202cb72b6af70d327f053e248bab9ba81760f39d0701ef1d8f89cc1fbd2cacba0710a12cd5314d5e0c9021aa3637f9@5.1.83.226:30303",
293296
]
294297
}
295-

src/main/resources/conf/chains/ropsten-chain.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@
122122

123123
# List of accounts to be drained
124124
drain-list = null
125+
126+
# Tells whether this fork should be included on the fork id list used for peer validation
127+
include-on-fork-id-list = true
125128
}
126129

127130
# Starting nonce of an empty account. Some networks (like Morden) use different values.

src/main/resources/conf/chains/test-chain.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@
119119

120120
# List of accounts to be drained
121121
drain-list = null
122+
123+
# Tells whether this fork should be included on the fork id list used for peer validation
124+
include-on-fork-id-list = true
122125
}
123126

124127
# Starting nonce of an empty account. Some networks (like Morden) use different values.

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package io.iohk.ethereum.blockchain.sync
22

33
import akka.actor.{Actor, ActorLogging, ActorRef, Props}
44
import akka.util.ByteString
5+
import io.iohk.ethereum.db.storage.EvmCodeStorage
56
import io.iohk.ethereum.domain.{BlockHeader, Blockchain}
67
import io.iohk.ethereum.network.PeerEventBusActor.PeerEvent.MessageFromPeer
78
import io.iohk.ethereum.network.PeerEventBusActor.SubscriptionClassifier.MessageClassifier
@@ -20,6 +21,7 @@ import io.iohk.ethereum.network.p2p.messages.Codes
2021
*/
2122
class BlockchainHostActor(
2223
blockchain: Blockchain,
24+
evmCodeStorage: EvmCodeStorage,
2325
peerConfiguration: PeerConfiguration,
2426
peerEventBusActor: ActorRef,
2527
etcPeerManagerActor: ActorRef
@@ -54,7 +56,7 @@ class BlockchainHostActor(
5456
val maybeMptNodeData = blockchain.getMptNodeByHash(hash).map(e => e.toBytes: ByteString)
5557

5658
//If no mpt node was found, fetch evm by hash
57-
maybeMptNodeData.orElse(blockchain.getEvmCodeByHash(hash))
59+
maybeMptNodeData.orElse(evmCodeStorage.get(hash))
5860
}
5961

6062
Some(NodeData(nodeData))
@@ -116,10 +118,13 @@ object BlockchainHostActor {
116118

117119
def props(
118120
blockchain: Blockchain,
121+
evmCodeStorage: EvmCodeStorage,
119122
peerConfiguration: PeerConfiguration,
120123
peerEventBusActor: ActorRef,
121124
etcPeerManagerActor: ActorRef
122125
): Props =
123-
Props(new BlockchainHostActor(blockchain, peerConfiguration, peerEventBusActor, etcPeerManagerActor))
126+
Props(
127+
new BlockchainHostActor(blockchain, evmCodeStorage, peerConfiguration, peerEventBusActor, etcPeerManagerActor)
128+
)
124129

125130
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ import akka.actor.{Actor, ActorLogging, ActorRef, PoisonPill, Props, Scheduler}
44
import io.iohk.ethereum.blockchain.sync.fast.FastSync
55
import io.iohk.ethereum.blockchain.sync.regular.RegularSync
66
import io.iohk.ethereum.consensus.validators.Validators
7-
import io.iohk.ethereum.db.storage.{AppStateStorage, FastSyncStateStorage}
7+
import io.iohk.ethereum.db.storage.{AppStateStorage, EvmCodeStorage, FastSyncStateStorage, NodeStorage}
88
import io.iohk.ethereum.domain.Blockchain
99
import io.iohk.ethereum.ledger.Ledger
1010
import io.iohk.ethereum.utils.Config.SyncConfig
1111

1212
class SyncController(
1313
appStateStorage: AppStateStorage,
1414
blockchain: Blockchain,
15+
evmCodeStorage: EvmCodeStorage,
16+
nodeStorage: NodeStorage,
1517
fastSyncStateStorage: FastSyncStateStorage,
1618
ledger: Ledger,
1719
validators: Validators,
@@ -77,6 +79,8 @@ class SyncController(
7779
fastSyncStateStorage,
7880
appStateStorage,
7981
blockchain,
82+
evmCodeStorage,
83+
nodeStorage,
8084
validators,
8185
peerEventBus,
8286
etcPeerManager,
@@ -120,6 +124,8 @@ object SyncController {
120124
def props(
121125
appStateStorage: AppStateStorage,
122126
blockchain: Blockchain,
127+
evmCodeStorage: EvmCodeStorage,
128+
nodeStorage: NodeStorage,
123129
syncStateStorage: FastSyncStateStorage,
124130
ledger: Ledger,
125131
validators: Validators,
@@ -134,6 +140,8 @@ object SyncController {
134140
new SyncController(
135141
appStateStorage,
136142
blockchain,
143+
evmCodeStorage,
144+
nodeStorage,
137145
syncStateStorage,
138146
ledger,
139147
validators,

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import io.iohk.ethereum.blockchain.sync.fast.SyncStateSchedulerActor.{
2020
WaitingForNewTargetBlock
2121
}
2222
import io.iohk.ethereum.consensus.validators.Validators
23-
import io.iohk.ethereum.db.storage.{AppStateStorage, FastSyncStateStorage}
23+
import io.iohk.ethereum.db.storage.{AppStateStorage, EvmCodeStorage, FastSyncStateStorage, NodeStorage}
2424
import io.iohk.ethereum.domain._
2525
import io.iohk.ethereum.mpt.MerklePatriciaTrie
2626
import io.iohk.ethereum.network.EtcPeerManagerActor.PeerInfo
@@ -48,6 +48,8 @@ class FastSync(
4848
val fastSyncStateStorage: FastSyncStateStorage,
4949
val appStateStorage: AppStateStorage,
5050
val blockchain: Blockchain,
51+
evmCodeStorage: EvmCodeStorage,
52+
nodeStorage: NodeStorage,
5153
val validators: Validators,
5254
val peerEventBus: ActorRef,
5355
val etcPeerManager: ActorRef,
@@ -153,7 +155,7 @@ class FastSync(
153155
private val syncStateScheduler = context.actorOf(
154156
SyncStateSchedulerActor
155157
.props(
156-
SyncStateScheduler(blockchain, syncConfig.stateSyncBloomFilterSize),
158+
SyncStateScheduler(blockchain, evmCodeStorage, nodeStorage, syncConfig.stateSyncBloomFilterSize),
157159
syncConfig,
158160
etcPeerManager,
159161
peerEventBus,
@@ -1134,6 +1136,8 @@ object FastSync {
11341136
fastSyncStateStorage: FastSyncStateStorage,
11351137
appStateStorage: AppStateStorage,
11361138
blockchain: Blockchain,
1139+
evmCodeStorage: EvmCodeStorage,
1140+
nodeStorage: NodeStorage,
11371141
validators: Validators,
11381142
peerEventBus: ActorRef,
11391143
etcPeerManager: ActorRef,
@@ -1146,6 +1150,8 @@ object FastSync {
11461150
fastSyncStateStorage,
11471151
appStateStorage,
11481152
blockchain,
1153+
evmCodeStorage,
1154+
nodeStorage,
11491155
validators,
11501156
peerEventBus,
11511157
etcPeerManager,

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

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
package io.iohk.ethereum.blockchain.sync.fast
22

33
import java.util.Comparator
4-
54
import akka.util.ByteString
65
import com.google.common.hash.{BloomFilter, Funnel, PrimitiveSink}
76
import io.iohk.ethereum.blockchain.sync.fast.LoadableBloomFilter.BloomFilterLoadingResult
87
import io.iohk.ethereum.blockchain.sync.fast.SyncStateScheduler._
8+
import io.iohk.ethereum.db.dataSource.RocksDbDataSource.IterationError
9+
import io.iohk.ethereum.db.storage.{EvmCodeStorage, NodeStorage}
910
import io.iohk.ethereum.domain.{Account, Blockchain}
1011
import io.iohk.ethereum.mpt.{BranchNode, ExtensionNode, HashNode, LeafNode, MerklePatriciaTrie, MptNode}
1112
import io.iohk.ethereum.network.p2p.messages.ETH63.MptNodeEncoders.MptNodeDec
1213
import io.vavr.collection.PriorityQueue
1314
import monix.eval.Task
15+
import monix.reactive.Observable
1416

1517
import scala.annotation.tailrec
1618
import scala.collection.immutable.ArraySeq
@@ -43,7 +45,11 @@ import scala.util.Try
4345
*
4446
* Important part is that nodes retrieved by getMissingNodes, must eventually be provided for scheduler to make progress
4547
*/
46-
class SyncStateScheduler(blockchain: Blockchain, bloomFilter: LoadableBloomFilter[ByteString]) {
48+
class SyncStateScheduler(
49+
blockchain: Blockchain,
50+
evmCodeStorage: EvmCodeStorage,
51+
bloomFilter: LoadableBloomFilter[ByteString]
52+
) {
4753

4854
val loadFilterFromBlockchain: Task[BloomFilterLoadingResult] = bloomFilter.loadFromSource
4955

@@ -242,9 +248,9 @@ class SyncStateScheduler(blockchain: Blockchain, bloomFilter: LoadableBloomFilte
242248

243249
private def isInDatabase(req: StateNodeRequest): Boolean = {
244250
req.requestType match {
245-
case request: CodeRequest =>
246-
blockchain.getEvmCodeByHash(req.nodeHash).isDefined
247-
case request: NodeRequest =>
251+
case _: CodeRequest =>
252+
evmCodeStorage.get(req.nodeHash).isDefined
253+
case _: NodeRequest =>
248254
blockchain.getMptNodeByHash(req.nodeHash).isDefined
249255
}
250256
}
@@ -284,12 +290,22 @@ object SyncStateScheduler {
284290
BloomFilter.create[ByteString](ByteStringFunnel, expectedFilterSize)
285291
}
286292

287-
def apply(blockchain: Blockchain, expectedBloomFilterSize: Int): SyncStateScheduler = {
293+
def apply(
294+
blockchain: Blockchain,
295+
evmCodeStorage: EvmCodeStorage,
296+
nodeStorage: NodeStorage,
297+
expectedBloomFilterSize: Int
298+
): SyncStateScheduler = {
288299
// provided source i.e mptStateSavedKeys() is guaranteed to finish on first `Left` element which means that returned
289300
// error is the reason why loading has stopped
301+
val mptStateSavedKeys: Observable[Either[IterationError, ByteString]] =
302+
(nodeStorage.storageContent.map(c => c.map(_._1)) ++ evmCodeStorage.storageContent.map(c => c.map(_._1)))
303+
.takeWhileInclusive(_.isRight)
304+
290305
new SyncStateScheduler(
291306
blockchain,
292-
LoadableBloomFilter[ByteString](expectedBloomFilterSize, blockchain.mptStateSavedKeys())
307+
evmCodeStorage,
308+
LoadableBloomFilter[ByteString](expectedBloomFilterSize, mptStateSavedKeys)
293309
)
294310
}
295311

0 commit comments

Comments
 (0)