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