From add511644318c2b885d0029303db056ea685f8d9 Mon Sep 17 00:00:00 2001 From: Sergey Nazarov Date: Mon, 30 Oct 2017 11:40:40 +0300 Subject: [PATCH] Added a setting to control transaction storage --- src/main/resources/application.conf | 1 + .../com/wavesplatform/history/StorageFactory.scala | 2 +- .../settings/BlockchainSettings.scala | 2 ++ .../com/wavesplatform/state2/StateWriter.scala | 14 +++++++++----- .../scala/com/wavesplatform/utils/package.scala | 2 -- .../com/wavesplatform/UtxPoolSpecification.scala | 2 +- .../scala/com/wavesplatform/history/package.scala | 1 + .../com/wavesplatform/state2/StateWriterSpec.scala | 2 +- .../com/wavesplatform/state2/diffs/package.scala | 5 ++--- 9 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf index efed5e8bac6..5e88a1a7eaa 100644 --- a/src/main/resources/application.conf +++ b/src/main/resources/application.conf @@ -112,6 +112,7 @@ waves { # Path to blockchain file blockchain-file = ${waves.directory}"/data/blockchain.dat" state-file = ${waves.directory}"/data/state.dat" + store-transactions-in-state = true checkpoint-file = ${waves.directory}"/data/checkpoint.dat" # Min buffer size. Fast rollback is possible up to this value. diff --git a/src/main/scala/com/wavesplatform/history/StorageFactory.scala b/src/main/scala/com/wavesplatform/history/StorageFactory.scala index d22a1b42e5c..90228203515 100644 --- a/src/main/scala/com/wavesplatform/history/StorageFactory.scala +++ b/src/main/scala/com/wavesplatform/history/StorageFactory.scala @@ -26,7 +26,7 @@ object StorageFactory { for { historyWriter <- HistoryWriterImpl(settings.blockchainSettings.blockchainFile, lock, settings.blockchainSettings.functionalitySettings, settings.featuresSettings) ss <- createStateStorage(historyWriter, settings.blockchainSettings.stateFile, settings.mvstorePageSplitSize) - stateWriter = new StateWriterImpl(ss, lock) + stateWriter = new StateWriterImpl(ss, settings.blockchainSettings.storeTransactionsInState, lock) } yield { val bcu = BlockchainUpdaterImpl(stateWriter, historyWriter, settings, settings.blockchainSettings.minimumInMemoryDiffSize, lock) val history: NgHistory with DebugNgHistory with FeatureProvider = bcu.historyReader diff --git a/src/main/scala/com/wavesplatform/settings/BlockchainSettings.scala b/src/main/scala/com/wavesplatform/settings/BlockchainSettings.scala index f08b4a0d156..c8fde1c28af 100644 --- a/src/main/scala/com/wavesplatform/settings/BlockchainSettings.scala +++ b/src/main/scala/com/wavesplatform/settings/BlockchainSettings.scala @@ -108,6 +108,7 @@ object GenesisSettings { case class BlockchainSettings(blockchainFile: Option[File], stateFile: Option[File], + storeTransactionsInState: Boolean, checkpointFile: Option[File], addressSchemeCharacter: Char, minimumInMemoryDiffSize: Int, @@ -140,6 +141,7 @@ object BlockchainSettings { BlockchainSettings( blockchainFile = config.getAs[File](s"$configPath.blockchain-file"), stateFile = config.getAs[File](s"$configPath.state-file"), + storeTransactionsInState = config.getBoolean(s"$configPath.store-transactions-in-state"), checkpointFile = config.getAs[File](s"$configPath.checkpoint-file"), addressSchemeCharacter = addressSchemeCharacter, minimumInMemoryDiffSize = config.as[Int](s"$configPath.minimum-in-memory-diff-blocks"), diff --git a/src/main/scala/com/wavesplatform/state2/StateWriter.scala b/src/main/scala/com/wavesplatform/state2/StateWriter.scala index b1740963e6b..25e6ddef316 100644 --- a/src/main/scala/com/wavesplatform/state2/StateWriter.scala +++ b/src/main/scala/com/wavesplatform/state2/StateWriter.scala @@ -6,6 +6,9 @@ import cats.Monoid import cats.implicits._ import com.wavesplatform.metrics.Instrumented import com.wavesplatform.state2.reader.StateReaderImpl +import scorex.transaction.PaymentTransaction +import scorex.transaction.assets.TransferTransaction +import scorex.transaction.assets.exchange.ExchangeTransaction import scorex.utils.ScorexLogging trait StateWriter { @@ -14,7 +17,7 @@ trait StateWriter { def clear(): Unit } -class StateWriterImpl(p: StateStorage, synchronizationToken: ReentrantReadWriteLock) +class StateWriterImpl(p: StateStorage, storeTransactions: Boolean, synchronizationToken: ReentrantReadWriteLock) extends StateReaderImpl(p, synchronizationToken) with StateWriter with AutoCloseable with ScorexLogging with Instrumented { import StateStorage._ @@ -29,8 +32,10 @@ class StateWriterImpl(p: StateStorage, synchronizationToken: ReentrantReadWriteL log.debug(s"Starting persist from $oldHeight to $newHeight") measureSizeLog("transactions")(txsDiff.transactions) { - _.par.foreach { case (id, (h, tx, _)) => - sp().transactions.put(id, (h, tx.bytes)) + _.par.foreach { + case (id, (h, tx@(_: TransferTransaction | _: ExchangeTransaction | _: PaymentTransaction), _)) => + sp().transactions.put(id, (h, if (storeTransactions) tx.bytes else Array.emptyByteArray)) + case (id, (h, tx, _)) => sp().transactions.put(id, (h, tx.bytes)) } } @@ -55,7 +60,6 @@ class StateWriterImpl(p: StateStorage, synchronizationToken: ReentrantReadWriteL } } - measureSizeLog("assets")(txsDiff.issuedAssets) { _.foreach { case (id, assetInfo) => val updated = (Option(sp().assets.get(id)) match { @@ -67,7 +71,7 @@ class StateWriterImpl(p: StateStorage, synchronizationToken: ReentrantReadWriteL } } - measureSizeLog("accountTransactionIds")(blockDiff.txsDiff.accountTransactionIds) { + if (storeTransactions) measureSizeLog("accountTransactionIds")(blockDiff.txsDiff.accountTransactionIds) { _.foreach { case (acc, txIds) => val startIdxShift = sp().accountTransactionsLengths.getOrDefault(acc.bytes, 0) txIds.reverse.foldLeft(startIdxShift) { case (shift, txId) => diff --git a/src/main/scala/com/wavesplatform/utils/package.scala b/src/main/scala/com/wavesplatform/utils/package.scala index 456421154e3..004e465c1d2 100644 --- a/src/main/scala/com/wavesplatform/utils/package.scala +++ b/src/main/scala/com/wavesplatform/utils/package.scala @@ -64,5 +64,3 @@ package object utils extends ScorexLogging { System.exit(reason.code) }, "waves-platform-shutdown-thread").start() } - - diff --git a/src/test/scala/com/wavesplatform/UtxPoolSpecification.scala b/src/test/scala/com/wavesplatform/UtxPoolSpecification.scala index fe1c8998026..d1ee3a88209 100755 --- a/src/test/scala/com/wavesplatform/UtxPoolSpecification.scala +++ b/src/test/scala/com/wavesplatform/UtxPoolSpecification.scala @@ -39,7 +39,7 @@ class UtxPoolSpecification extends FreeSpec val config = ConfigFactory.load() val genesisSettings = TestHelpers.genesisSettings(Map(senderAccount -> senderBalance)) - val settings = WavesSettings.fromConfig(config).copy(blockchainSettings = BlockchainSettings(None, None, None, 'T', 5, FunctionalitySettings.TESTNET, genesisSettings)) + val settings = WavesSettings.fromConfig(config).copy(blockchainSettings = BlockchainSettings(None, None, false, None, 'T', 5, FunctionalitySettings.TESTNET, genesisSettings)) val (history, _, _, state, bcu, _) = StorageFactory(settings).get diff --git a/src/test/scala/com/wavesplatform/history/package.scala b/src/test/scala/com/wavesplatform/history/package.scala index e4561b519f8..78518b3fc16 100644 --- a/src/test/scala/com/wavesplatform/history/package.scala +++ b/src/test/scala/com/wavesplatform/history/package.scala @@ -17,6 +17,7 @@ package object history { val DefaultBlockchainSettings = BlockchainSettings( blockchainFile = None, stateFile = None, + storeTransactionsInState = false, checkpointFile = None, addressSchemeCharacter = 'N', minimumInMemoryDiffSize = MinInMemoryDiffSize, diff --git a/src/test/scala/com/wavesplatform/state2/StateWriterSpec.scala b/src/test/scala/com/wavesplatform/state2/StateWriterSpec.scala index de717563a08..b927d851b0f 100644 --- a/src/test/scala/com/wavesplatform/state2/StateWriterSpec.scala +++ b/src/test/scala/com/wavesplatform/state2/StateWriterSpec.scala @@ -9,7 +9,7 @@ import org.scalatest.{FunSuite, Matchers} class StateWriterSpec extends FunSuite with Matchers with GeneratorDrivenPropertyChecks { test("increase height when applying block diff") { val storage = StateStorage(None, dropExisting = false).get - val writer = new StateWriterImpl(storage, new ReentrantReadWriteLock()) + val writer = new StateWriterImpl(storage, false, new ReentrantReadWriteLock()) forAll(Gen.choose(0, Int.MaxValue)) { heightDiff => val h = writer.height writer.applyBlockDiff(BlockDiff(Diff.empty, heightDiff, Map.empty)) diff --git a/src/test/scala/com/wavesplatform/state2/diffs/package.scala b/src/test/scala/com/wavesplatform/state2/diffs/package.scala index 1bda39c9e86..2849a1a3f03 100644 --- a/src/test/scala/com/wavesplatform/state2/diffs/package.scala +++ b/src/test/scala/com/wavesplatform/state2/diffs/package.scala @@ -14,7 +14,8 @@ package object diffs { private val lock = new ReentrantReadWriteLock() - def newState(): StateWriterImpl = new StateWriterImpl(StateStorage(None, dropExisting = false).get, new ReentrantReadWriteLock()) + def newState(storeTransactions: Boolean = true): StateWriterImpl = + new StateWriterImpl(StateStorage(None, dropExisting = false).get, storeTransactions, new ReentrantReadWriteLock()) def newHistory(): History with FeatureProvider = HistoryWriterImpl(None, lock, TestFunctionalitySettings.Enabled, TestFunctionalitySettings.EmptyFeaturesSettings).get @@ -38,8 +39,6 @@ package object diffs { assertion(totalDiff2) } - - def assertDiffAndState(preconditions: Seq[Block], block: Block, fs: FunctionalitySettings = TestFunctionalitySettings.Enabled)(assertion: (BlockDiff, StateReader) => Unit): Unit = { val fp = newHistory() val state = newState()