Skip to content

Commit 3e7e223

Browse files
committed
ETCM-636: Fix null pointer on getBestBlock
1 parent e9f0cf7 commit 3e7e223

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,8 +823,8 @@ class FastSync(
823823
val bestReceivedBlock = fullBlocks.maxBy(_.number)
824824
val lastStoredBestBlockNumber = appStateStorage.getBestBlockNumber()
825825
if (lastStoredBestBlockNumber < bestReceivedBlock.number) {
826-
blockchain.saveBestKnownBlocks(bestReceivedBlock.number)
827826
appStateStorage.putBestBlockNumber(bestReceivedBlock.number).commit()
827+
blockchain.saveBestKnownBlocks(bestReceivedBlock.number)
828828
}
829829
syncState = syncState.copy(lastFullBlockNumber = bestReceivedBlock.number.max(lastStoredBestBlockNumber))
830830
}

src/test/scala/io/iohk/ethereum/db/dataSource/DataSourceTestBehavior.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package io.iohk.ethereum.db.dataSource
22

33
import java.io.File
44
import java.nio.file.Files
5-
65
import io.iohk.ethereum.ObjectGenerators
76
import io.iohk.ethereum.db.dataSource.DataSource.{Key, Namespace, Value}
7+
import io.iohk.ethereum.db.dataSource.RocksDbDataSource.RocksDbDataSourceClosedException
88
import org.scalatest.flatspec.AnyFlatSpec
99
import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks
1010

@@ -48,6 +48,15 @@ trait DataSourceTestBehavior extends ScalaCheckPropertyChecks with ObjectGenerat
4848
}
4949
}
5050

51+
it should "throw an exception if the rocksdb storage is unavailable" in {
52+
withDir { path =>
53+
val dataSource = createDataSource(path)
54+
val someByteString = byteStringOfLengthNGen(KeySizeWithoutPrefix).sample.get
55+
dataSource.destroy()
56+
assertThrows[RocksDbDataSourceClosedException](dataSource.update(prepareUpdate(toUpsert = Seq(someByteString -> someByteString))))
57+
}
58+
}
59+
5160
it should "allow to remove keys" in {
5261
val key1 = byteStringOfLengthNGen(KeySizeWithoutPrefix).sample.get
5362
val key2 = byteStringOfLengthNGen(KeySizeWithoutPrefix).sample.get
@@ -111,5 +120,4 @@ trait DataSourceTestBehavior extends ScalaCheckPropertyChecks with ObjectGenerat
111120
}
112121
}
113122
// scalastyle:on
114-
115123
}

0 commit comments

Comments
 (0)