@@ -13,7 +13,7 @@ import io.iohk.ethereum.db.components.{RocksDbDataSourceComponent, Storages}
13
13
import io .iohk .ethereum .db .dataSource .{RocksDbConfig , RocksDbDataSource }
14
14
import io .iohk .ethereum .db .storage .pruning .{ArchivePruning , PruningMode }
15
15
import io .iohk .ethereum .db .storage .{AppStateStorage , Namespaces }
16
- import io .iohk .ethereum .domain .{Block , Blockchain , BlockchainImpl }
16
+ import io .iohk .ethereum .domain .{Block , Blockchain , BlockchainImpl , ChainWeight }
17
17
import io .iohk .ethereum .ledger .InMemoryWorldStateProxy
18
18
import io .iohk .ethereum .mpt .MerklePatriciaTrie
19
19
import io .iohk .ethereum .network .EtcPeerManagerActor .PeerInfo
@@ -116,8 +116,9 @@ abstract class CommonFakePeer(peerName: String, fakePeerCustomConfig: FakePeerCu
116
116
Fixtures .Blocks .Genesis .header.copy(stateRoot = ByteString (MerklePatriciaTrie .EmptyRootHash )),
117
117
Fixtures .Blocks .Genesis .body
118
118
)
119
+ val genesisWeight = ChainWeight .zero.increase(genesis.header)
119
120
120
- bl.save(genesis, Seq (), genesis.header.difficulty , saveAsBestBlock = true )
121
+ bl.save(genesis, Seq (), genesisWeight , saveAsBestBlock = true )
121
122
122
123
lazy val nh = nodeStatusHolder
123
124
@@ -228,15 +229,15 @@ abstract class CommonFakePeer(peerName: String, fakePeerCustomConfig: FakePeerCu
228
229
)
229
230
}
230
231
231
- private def broadcastBlock (block : Block , td : BigInt ) = {
232
- broadcasterActor ! BroadcastBlock (NewBlock (block, td ))
232
+ private def broadcastBlock (block : Block , weight : ChainWeight ) = {
233
+ broadcasterActor ! BroadcastBlock (NewBlock (block, weight ))
233
234
}
234
235
235
236
def getCurrentState (): BlockchainState = {
236
237
val bestBlock = bl.getBestBlock()
237
238
val currentWorldState = getMptForBlock(bestBlock)
238
- val currentTd = bl.getTotalDifficultyByHash (bestBlock.hash).get
239
- BlockchainState (bestBlock, currentWorldState, currentTd )
239
+ val currentWeight = bl.getChainWeightByHash (bestBlock.hash).get
240
+ BlockchainState (bestBlock, currentWorldState, currentWeight )
240
241
}
241
242
242
243
def startPeer (): Task [Unit ] = {
@@ -272,16 +273,16 @@ abstract class CommonFakePeer(peerName: String, fakePeerCustomConfig: FakePeerCu
272
273
} yield ()
273
274
}
274
275
275
- private def createChildBlock (parent : Block , parentTd : BigInt , parentWorld : InMemoryWorldStateProxy )(
276
+ private def createChildBlock (parent : Block , parentWeight : ChainWeight , parentWorld : InMemoryWorldStateProxy )(
276
277
updateWorldForBlock : (BigInt , InMemoryWorldStateProxy ) => InMemoryWorldStateProxy
277
- ): (Block , BigInt , InMemoryWorldStateProxy ) = {
278
+ ): (Block , ChainWeight , InMemoryWorldStateProxy ) = {
278
279
val newBlockNumber = parent.header.number + 1
279
280
val newWorld = updateWorldForBlock(newBlockNumber, parentWorld)
280
281
val newBlock = parent.copy(header =
281
282
parent.header.copy(parentHash = parent.header.hash, number = newBlockNumber, stateRoot = newWorld.stateRootHash)
282
283
)
283
- val newTd = newBlock.header.difficulty + parentTd
284
- (newBlock, newTd , parentWorld)
284
+ val newWeight = parentWeight.increase( newBlock.header)
285
+ (newBlock, newWeight , parentWorld)
285
286
}
286
287
287
288
def importBlocksUntil (
@@ -292,12 +293,12 @@ abstract class CommonFakePeer(peerName: String, fakePeerCustomConfig: FakePeerCu
292
293
Task (())
293
294
} else {
294
295
Task {
295
- val currentTd = bl.getTotalDifficultyByHash (block.hash).get
296
+ val currentWeight = bl.getChainWeightByHash (block.hash).get
296
297
val currentWolrd = getMptForBlock(block)
297
- val (newBlock, newTd, newWorld ) = createChildBlock(block, currentTd , currentWolrd)(updateWorldForBlock)
298
- bl.save(newBlock, Seq (), newTd , saveAsBestBlock = true )
298
+ val (newBlock, newWeight, _ ) = createChildBlock(block, currentWeight , currentWolrd)(updateWorldForBlock)
299
+ bl.save(newBlock, Seq (), newWeight , saveAsBestBlock = true )
299
300
bl.persistCachedNodes()
300
- broadcastBlock(newBlock, newTd )
301
+ broadcastBlock(newBlock, newWeight )
301
302
}.flatMap(_ => importBlocksUntil(n)(updateWorldForBlock))
302
303
}
303
304
}
0 commit comments