Skip to content

Commit

Permalink
Merge pull request #635 from wavesplatform/separate-transaction-storage
Browse files Browse the repository at this point in the history
Added a setting to control transaction storage
  • Loading branch information
phearnot authored Oct 30, 2017
2 parents 6713165 + add5116 commit ff72ab3
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ object GenesisSettings {

case class BlockchainSettings(blockchainFile: Option[File],
stateFile: Option[File],
storeTransactionsInState: Boolean,
checkpointFile: Option[File],
addressSchemeCharacter: Char,
minimumInMemoryDiffSize: Int,
Expand Down Expand Up @@ -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"),
Expand Down
14 changes: 9 additions & 5 deletions src/main/scala/com/wavesplatform/state2/StateWriter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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._
Expand All @@ -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))
}
}

Expand All @@ -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 {
Expand All @@ -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) =>
Expand Down
2 changes: 0 additions & 2 deletions src/main/scala/com/wavesplatform/utils/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,3 @@ package object utils extends ScorexLogging {
System.exit(reason.code)
}, "waves-platform-shutdown-thread").start()
}


Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/test/scala/com/wavesplatform/history/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package object history {
val DefaultBlockchainSettings = BlockchainSettings(
blockchainFile = None,
stateFile = None,
storeTransactionsInState = false,
checkpointFile = None,
addressSchemeCharacter = 'N',
minimumInMemoryDiffSize = MinInMemoryDiffSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 2 additions & 3 deletions src/test/scala/com/wavesplatform/state2/diffs/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand Down

0 comments on commit ff72ab3

Please sign in to comment.