1
1
package io .iohk .ethereum .nodebuilder
2
2
3
3
import akka .actor .typed .ActorSystem
4
+ import akka .util .ByteString
4
5
5
6
import scala .concurrent .Await
6
7
import scala .concurrent .ExecutionContext .Implicits .global
@@ -18,6 +19,7 @@ import io.iohk.ethereum.network.discovery.PeerDiscoveryManager
18
19
import io .iohk .ethereum .nodebuilder .tooling .PeriodicConsistencyCheck
19
20
import io .iohk .ethereum .nodebuilder .tooling .StorageConsistencyChecker
20
21
import io .iohk .ethereum .utils .Config
22
+ import io .iohk .ethereum .utils .Hex
21
23
22
24
/** A standard node is everything Ethereum prescribes except the mining algorithm,
23
25
* which is plugged in dynamically.
@@ -32,6 +34,8 @@ abstract class BaseNode extends Node {
32
34
def start (): Unit = {
33
35
startMetricsClient()
34
36
37
+ fixDatabase()
38
+
35
39
loadGenesisData()
36
40
37
41
runDBConsistencyCheck()
@@ -132,6 +136,24 @@ abstract class BaseNode extends Node {
132
136
tryAndLogFailure(() => Metrics .get().close())
133
137
tryAndLogFailure(() => storagesInstance.dataSource.close())
134
138
}
139
+
140
+ def fixDatabase (): Unit = {
141
+ // FIXME this is a temporary solution to avoid an incompatibility due to the introduction of the best block hash
142
+ // We can remove this fix when we release an incompatible version.
143
+ val bestBlockInfo = storagesInstance.storages.appStateStorage.getBestBlockInfo()
144
+ if (bestBlockInfo.hash == ByteString .empty && bestBlockInfo.number > 0 ) {
145
+ log.warn(" Fixing best block hash into database for block {}" , bestBlockInfo.number)
146
+ storagesInstance.storages.blockNumberMappingStorage.get(bestBlockInfo.number) match {
147
+ case Some (hash) =>
148
+ log.warn(" Putting {} as the best block hash" , Hex .toHexString(hash.toArray))
149
+ storagesInstance.storages.appStateStorage.putBestBlockInfo(bestBlockInfo.copy(hash = hash)).commit()
150
+ case None =>
151
+ log.error(" No block found for number {} when trying to fix database" , bestBlockInfo.number)
152
+ }
153
+
154
+ }
155
+
156
+ }
135
157
}
136
158
137
159
class StdNode extends BaseNode with StdMiningBuilder
0 commit comments