Skip to content

Commit

Permalink
ETCM-636: Fix null pointer on getBestBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
AnastasiiaL committed Feb 25, 2021
1 parent e9f0cf7 commit 3e7e223
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Expand Up @@ -823,8 +823,8 @@ class FastSync(
val bestReceivedBlock = fullBlocks.maxBy(_.number)
val lastStoredBestBlockNumber = appStateStorage.getBestBlockNumber()
if (lastStoredBestBlockNumber < bestReceivedBlock.number) {
blockchain.saveBestKnownBlocks(bestReceivedBlock.number)
appStateStorage.putBestBlockNumber(bestReceivedBlock.number).commit()
blockchain.saveBestKnownBlocks(bestReceivedBlock.number)
}
syncState = syncState.copy(lastFullBlockNumber = bestReceivedBlock.number.max(lastStoredBestBlockNumber))
}
Expand Down
Expand Up @@ -2,9 +2,9 @@ package io.iohk.ethereum.db.dataSource

import java.io.File
import java.nio.file.Files

import io.iohk.ethereum.ObjectGenerators
import io.iohk.ethereum.db.dataSource.DataSource.{Key, Namespace, Value}
import io.iohk.ethereum.db.dataSource.RocksDbDataSource.RocksDbDataSourceClosedException
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks

Expand Down Expand Up @@ -48,6 +48,15 @@ trait DataSourceTestBehavior extends ScalaCheckPropertyChecks with ObjectGenerat
}
}

it should "throw an exception if the rocksdb storage is unavailable" in {
withDir { path =>
val dataSource = createDataSource(path)
val someByteString = byteStringOfLengthNGen(KeySizeWithoutPrefix).sample.get
dataSource.destroy()
assertThrows[RocksDbDataSourceClosedException](dataSource.update(prepareUpdate(toUpsert = Seq(someByteString -> someByteString))))
}
}

it should "allow to remove keys" in {
val key1 = byteStringOfLengthNGen(KeySizeWithoutPrefix).sample.get
val key2 = byteStringOfLengthNGen(KeySizeWithoutPrefix).sample.get
Expand Down Expand Up @@ -111,5 +120,4 @@ trait DataSourceTestBehavior extends ScalaCheckPropertyChecks with ObjectGenerat
}
}
// scalastyle:on

}

0 comments on commit 3e7e223

Please sign in to comment.