Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
ff3112d
draft
Sep 18, 2019
be4aa2c
add chain synced test
Sep 18, 2019
6874941
add check queues
Sep 19, 2019
965a61c
add checks for queues and history
Sep 19, 2019
f45b0a3
move bench.Utils to EncryCore
Sep 20, 2019
699fc1c
try create right chain
Sep 20, 2019
8ab890b
fix timestamps
Sep 20, 2019
77143d8
debug prints
Sep 23, 2019
7d76dd8
add check rollback for invalid state test
Sep 23, 2019
b2be056
fix gen chain
Sep 23, 2019
5b29bc8
reafctor HistoryApplicator add locall generated block test
Sep 23, 2019
ad89035
add checkFullBlockChainIsSynced
Sep 24, 2019
80fcbbe
some refactoring
Sep 24, 2019
1613286
some refactoring
Sep 24, 2019
74355b6
Merge remote-tracking branch 'origin/EC-763' into EC-763
Sep 24, 2019
0c27d2d
draft check rollback on fat blocks test
Sep 25, 2019
ee2d6f7
add gen new chain with transQty
Sep 25, 2019
3f81a7d
adapted test for new chain
Sep 25, 2019
db12820
extract chain to ChainGenerator
Sep 25, 2019
f62f07f
some refactoring
Sep 26, 2019
c3f8aeb
cleaned up unnecessary changes
Sep 26, 2019
0628719
change test params for travis build
Sep 26, 2019
352db2e
change test params for travis build
Sep 26, 2019
eb39bef
HistoryDummy for PowScheme validate
Sep 26, 2019
e6ec35c
override settings state = LevelDB
Sep 26, 2019
57ff595
change test params for travis build
Sep 26, 2019
92281c6
replace sleep to receiveN
Sep 26, 2019
57f252e
change test params for travis build
Sep 26, 2019
6a7a59d
change test params for travis build
Sep 26, 2019
42a72b7
cleanup
Sep 26, 2019
67e0637
Merge remote-tracking branch 'origin/master' into EC-763
Sep 27, 2019
9835e90
wait condition
Sep 27, 2019
c34eb68
add sync when apply headers and payloads separately test
Sep 27, 2019
44081a5
big refactoring
Sep 30, 2019
aa0253b
fix HistoryGenerator settings
Sep 30, 2019
699131e
merge master
Sep 30, 2019
b75a0b8
refactoring benchmarks.Utils -> TransactionFactory, TestEntityGenerator
Sep 30, 2019
31111fc
refactoring it.TransactionsUtil -> TransactionFactory, TestEntityGene…
Sep 30, 2019
7abc70f
some fixes
Oct 1, 2019
2a23b87
test comment
Oct 1, 2019
7fb77db
rename
Oct 1, 2019
70ae6d6
fix "timestamp 1569926861646 less than parent's 1569926861646"
Oct 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//package benches
//
//import java.util.concurrent.TimeUnit
//import benches.Utils._
//import akka.actor.ActorSystem
//import benches.BloomFilterBenchmark.BloomFilterBenchmarkState
//import encry.modifiers.mempool.Transaction
Expand Down
42 changes: 34 additions & 8 deletions benchmarks/src/test/scala/benches/HistoryBenches.scala
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
package benches

import java.io.File
import java.util.concurrent.TimeUnit

import benches.HistoryBenches.HistoryBenchState
import benches.Utils._
import encry.utils.TestEntityGenerator.coinbaseTransaction
import encry.utils.HistoryGenerator
import encry.view.history.History
import encryBenchmark.BenchSettings
import org.encryfoundation.common.modifiers.history.Block
import org.encryfoundation.common.crypto.equihash.EquihashSolution
import org.encryfoundation.common.modifiers.history.{Block, Header, Payload}
import org.encryfoundation.common.modifiers.mempool.transaction.Transaction
import org.encryfoundation.common.utils.TaggedTypes.{Difficulty, ModifierId}
import org.openjdk.jmh.annotations._
import org.openjdk.jmh.infra.Blackhole
import org.openjdk.jmh.profile.GCProfiler
import org.openjdk.jmh.runner.{Runner, RunnerException}
import org.openjdk.jmh.runner.options.{OptionsBuilder, TimeValue, VerboseMode}
import scala.util.Random

class HistoryBenches {

@Benchmark
def appendBlocksToHistoryBench(benchStateHistory: HistoryBenchState, bh: Blackhole): Unit = {
bh.consume {
val history: History = generateHistory(benchStateHistory.settings, getRandomTempDir)
val history: History = HistoryGenerator.dummyHistory(benchStateHistory.settings)
benchStateHistory.blocks.foldLeft(history) { case (historyL, block) =>
historyL.append(block.header)
historyL.append(block.payload)
Expand All @@ -32,7 +36,7 @@ class HistoryBenches {
@Benchmark
def readHistoryFileBench(benchStateHistory: HistoryBenchState, bh: Blackhole): Unit = {
bh.consume {
val history: History = generateHistory(benchStateHistory.settings, benchStateHistory.tmpDir)
val history: History = HistoryGenerator.dummyHistory(benchStateHistory.settings)
history.closeStorage()
}
}
Expand Down Expand Up @@ -61,15 +65,14 @@ object HistoryBenches extends BenchSettings {
@State(Scope.Benchmark)
class HistoryBenchState extends encry.settings.Settings {

val tmpDir: File = getRandomTempDir
val initialHistory: History = generateHistory(settings, tmpDir)
val initialHistory: History = HistoryGenerator.dummyHistory(settings)

val resultedHistory: (History, Option[Block], Vector[Block]) =
(0 until benchSettings.historyBenchSettings.blocksNumber)
.foldLeft(initialHistory, Option.empty[Block], Vector.empty[Block]) {
case ((prevHistory, prevBlock, vector), _) =>
val block: Block =
generateNextBlockValidForHistory(prevHistory, 0, prevBlock, Seq(coinbaseTransaction(0)))
generateNextBlockValidForHistory(prevHistory, 0, prevBlock, Seq(coinbaseTransaction(0)), settings.constants.InitialDifficulty)
prevHistory.append(block.header)
prevHistory.append(block.payload)
(prevHistory.reportModifierIsValid(block), Some(block), vector :+ block)
Expand All @@ -78,4 +81,27 @@ object HistoryBenches extends BenchSettings {

val blocks: Vector[Block] = resultedHistory._3
}

def generateNextBlockValidForHistory(history: History,
difficultyDiff: BigInt = 0,
prevBlock: Option[Block],
txs: Seq[Transaction],
initialDifficulty: Difficulty): Block = {
val previousHeaderId: ModifierId = prevBlock.map(_.id).getOrElse(Header.GenesisParentId)
val requiredDifficulty: Difficulty = prevBlock.map(b =>
history.requiredDifficultyAfter(b.header).getOrElse(Difficulty @@ BigInt(0)))
.getOrElse(initialDifficulty)
val header = Header(
1.toByte,
previousHeaderId,
Payload.rootHash(txs.map(_.id)),
Math.abs(Random.nextLong()),
history.getBestHeaderHeight + 1,
Random.nextLong(),
Difficulty @@ (requiredDifficulty + difficultyDiff),
EquihashSolution(Seq(1, 3))
)
Block(header, Payload(header.id, txs))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package benches
import java.util.concurrent.TimeUnit

import benches.SerializedAssetTransactionBenchmark.SerializedAssetBenchState
import benches.Utils._
import encryBenchmark.{BenchSettings, Settings}
import encry.utils.TestEntityGenerator
import encryBenchmark.BenchSettings
import org.encryfoundation.common.modifiers.mempool.transaction.{Transaction, TransactionSerializer}
import org.encryfoundation.common.modifiers.state.box.AssetBox
import org.openjdk.jmh.annotations._
Expand Down Expand Up @@ -53,9 +53,9 @@ object SerializedAssetTransactionBenchmark extends BenchSettings {

@Setup
def createStateForBenchmark(): Unit = {
initialBoxes = generateInitialBoxes(benchSettings.serializedAssetBenchSettings.totalBoxesNumber)
initialBoxes = TestEntityGenerator.generateInitialBoxes(benchSettings.serializedAssetBenchSettings.totalBoxesNumber)
initialTransactions =
generateAssetTransactions(
TestEntityGenerator.generateAssetTransactions(
initialBoxes,
benchSettings.serializedAssetBenchSettings.numberOfInputs,
benchSettings.serializedAssetBenchSettings.numberOfOutputs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package benches
import java.util.concurrent.TimeUnit

import benches.SerializedDataTxBenchmark.SerializedDataBenchState
import benches.Utils._
import encry.utils.TestEntityGenerator
import encryBenchmark.{BenchSettings, Settings}
import org.encryfoundation.common.modifiers.mempool.transaction.{Transaction, TransactionSerializer}
import org.encryfoundation.common.modifiers.state.box.AssetBox
Expand Down Expand Up @@ -53,8 +53,8 @@ object SerializedDataTxBenchmark extends BenchSettings {

@Setup
def createStateForBenchmark(): Unit = {
initialBoxes = generateInitialBoxes(benchSettings.serializedDataBenchSettings.totalBoxesNumber)
initialTransactions = generateDataTransactions(
initialBoxes = TestEntityGenerator.generateInitialBoxes(benchSettings.serializedDataBenchSettings.totalBoxesNumber)
initialTransactions = TestEntityGenerator.generateDataTransactions(
initialBoxes,
benchSettings.serializedDataBenchSettings.numberOfInputs,
benchSettings.serializedDataBenchSettings.numberOfOutputs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package benches
import java.util.concurrent.TimeUnit

import benches.SerializedMonetaryTxBenchmark.SerializedMonetaryBenchState
import benches.Utils._
import encryBenchmark.{BenchSettings, Settings}
import encry.utils.TestEntityGenerator
import encryBenchmark.BenchSettings
import org.encryfoundation.common.modifiers.mempool.transaction.{Transaction, TransactionSerializer}
import org.encryfoundation.common.modifiers.state.box.AssetBox
import org.openjdk.jmh.annotations._
Expand Down Expand Up @@ -53,9 +53,9 @@ object SerializedMonetaryTxBenchmark extends BenchSettings {

@Setup
def createStateForBenchmark(): Unit = {
initialBoxes = generateInitialBoxes(benchSettings.serializedMonetaryBenchSettings.totalBoxesNumber)
initialBoxes = TestEntityGenerator.generateInitialBoxes(benchSettings.serializedMonetaryBenchSettings.totalBoxesNumber)
initialTransactions =
generatePaymentTransactions(
TestEntityGenerator.generatePaymentTransactions(
initialBoxes,
benchSettings.serializedMonetaryBenchSettings.numberOfInputs,
benchSettings.serializedMonetaryBenchSettings.numberOfOutputs
Expand Down
66 changes: 55 additions & 11 deletions benchmarks/src/test/scala/benches/StateBenches.scala
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
package benches

import java.io.File
import java.security.PublicKey
import java.util.concurrent.TimeUnit

import benches.StateBenches.StateBenchState
import org.openjdk.jmh.annotations._
import benches.Utils._
import encry.EncryApp
import encry.settings.EncryAppSettings
import encry.modifiers.mempool.TransactionFactory.paymentTransactionWithMultipleOutputs
import encry.settings.Settings
import encry.storage.VersionalStorage
import encry.storage.VersionalStorage.IODB
import encry.utils.ChainGenerator._
import encry.utils.FileHelper.getRandomTempDir
import encry.utils.{Keys, TestEntityGenerator}
import encry.utils.Utils.randomAddress
import encry.view.state.{BoxHolder, UtxoState}
import encryBenchmark.{BenchSettings, Settings}
import org.encryfoundation.common.modifiers.history.Block
import encryBenchmark.BenchSettings
import org.encryfoundation.common.crypto.equihash.EquihashSolution
import org.encryfoundation.common.modifiers.history.{Block, Header, Payload}
import org.encryfoundation.common.modifiers.mempool.transaction.Transaction
import org.encryfoundation.common.modifiers.state.box.AssetBox
import org.encryfoundation.common.utils.TaggedTypes.Difficulty
import org.openjdk.jmh.infra.Blackhole
import org.openjdk.jmh.profile.GCProfiler
import org.openjdk.jmh.runner.{Runner, RunnerException}
import org.openjdk.jmh.runner.options.{OptionsBuilder, TimeValue, VerboseMode}

import scala.util.Random

class StateBenches {

@Benchmark
def applyBlocksToTheState(stateBench: StateBenchState, bh: Blackhole): Unit = {
bh.consume {
val innerState: UtxoState =
utxoFromBoxHolder(stateBench.boxesHolder, getRandomTempDir, None, stateBench.settings, VersionalStorage.LevelDB)
utxoFromBoxHolder(stateBench.boxesHolder, getRandomTempDir, stateBench.settings, VersionalStorage.LevelDB)
stateBench.chain.foldLeft(innerState) { case (state, block) =>
state.applyModifier(block).right.get
}
Expand All @@ -37,7 +46,7 @@ class StateBenches {
def readStateFileBench(stateBench: StateBenchState, bh: Blackhole): Unit = {
bh.consume {
val localState: UtxoState =
utxoFromBoxHolder(stateBench.boxesHolder, stateBench.tmpDir, None, stateBench.settings, IODB)
utxoFromBoxHolder(stateBench.boxesHolder, stateBench.tmpDir, stateBench.settings, IODB)
localState.close()
}
}
Expand All @@ -64,16 +73,17 @@ object StateBenches extends BenchSettings {
}

@State(Scope.Benchmark)
class StateBenchState extends encry.settings.Settings {
class StateBenchState extends Settings with Keys {

val tmpDir: File = getRandomTempDir

val initialBoxes: IndexedSeq[AssetBox] = (0 until benchSettings.stateBenchSettings.totalBoxesNumber).map(nonce =>
genHardcodedBox(privKey.publicImage.address.address, nonce)
TestEntityGenerator.genHardcodedBox(publicKey.address.address, nonce)
)
val boxesHolder: BoxHolder = BoxHolder(initialBoxes)
var state: UtxoState = utxoFromBoxHolder(boxesHolder, tmpDir, None, settings, VersionalStorage.LevelDB)
val genesisBlock: Block = generateGenesisBlockValidForState(state)
var state: UtxoState = utxoFromBoxHolder(boxesHolder, tmpDir, settings, VersionalStorage.LevelDB)
val genesisBlock: Block = genGenesisBlock(publicKey, settings.constants.InitialEmissionAmount,
settings.constants.InitialDifficulty, settings.constants.GenesisHeight)

state = state.applyModifier(genesisBlock).right.get

Expand Down Expand Up @@ -104,5 +114,39 @@ object StateBenches extends BenchSettings {
val chain: Vector[Block] = genesisBlock +: stateGenerationResults._1
state = stateGenerationResults._3
state.close()

def generateNextBlockValidForState(prevBlock: Block,
state: UtxoState,
box: Seq[AssetBox],
transactionsNumberInEachBlock: Int,
numberOfInputsInOneTransaction: Int,
numberOfOutputsInOneTransaction: Int): Block = {

val transactions: Seq[Transaction] = (0 until transactionsNumberInEachBlock).foldLeft(box, Seq.empty[Transaction]) {
case ((boxes, transactionsL), _) =>
val tx: Transaction = paymentTransactionWithMultipleOutputs(
privKey,
fee = 111,
timestamp = 11L,
useBoxes = boxes.take(numberOfInputsInOneTransaction).toIndexedSeq,
recipient = randomAddress,
amount = 10000,
numOfOutputs = numberOfOutputsInOneTransaction
)
(boxes.drop(numberOfInputsInOneTransaction), transactionsL :+ tx)
}._2 ++ Seq(TestEntityGenerator.coinbaseTransaction(prevBlock.header.height + 1))
val header = Header(
1.toByte,
prevBlock.id,
Payload.rootHash(transactions.map(_.id)),
System.currentTimeMillis(),
prevBlock.header.height + 1,
Random.nextLong(),
Difficulty @@ BigInt(1),
EquihashSolution(Seq(1, 3))
)
Block(header, Payload(header.id, transactions))
}
}

}
60 changes: 51 additions & 9 deletions benchmarks/src/test/scala/benches/StateRollbackBench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,35 @@ import java.io.File
import java.util.concurrent.TimeUnit

import benches.StateRollbackBench.StateRollbackState
import benches.Utils._
import encry.modifiers.mempool.TransactionFactory.paymentTransactionWithMultipleOutputs
import encry.settings.Settings
import encry.storage.VersionalStorage
import encry.utils.CoreTaggedTypes.VersionTag
import encry.view.state.{BoxHolder, UtxoState}
import encryBenchmark.{BenchSettings, Settings}
import org.encryfoundation.common.modifiers.history.Block
import encryBenchmark.BenchSettings
import org.encryfoundation.common.modifiers.history.{Block, Header, Payload}
import org.encryfoundation.common.modifiers.state.box.AssetBox
import org.encryfoundation.common.utils.TaggedTypes.{ADKey, Difficulty}
import org.encryfoundation.common.utils.TaggedTypes.Difficulty
import org.openjdk.jmh.annotations.{Benchmark, Mode, Scope, State}
import org.openjdk.jmh.infra.Blackhole
import org.openjdk.jmh.profile.GCProfiler
import org.openjdk.jmh.runner.{Runner, RunnerException}
import org.openjdk.jmh.runner.options.{OptionsBuilder, TimeValue, VerboseMode}
import encry.utils.FileHelper.getRandomTempDir
import encry.utils.ChainGenerator.{genGenesisBlock, utxoFromBoxHolder}
import encry.utils.{Keys, TestEntityGenerator}
import org.encryfoundation.common.crypto.equihash.EquihashSolution
import org.encryfoundation.common.modifiers.mempool.transaction.Transaction

import scala.util.Random

class StateRollbackBench {

@Benchmark
def applyBlocksToTheState(stateBench: StateRollbackState, bh: Blackhole): Unit = {
bh.consume {
val innerState: UtxoState =
utxoFromBoxHolder(stateBench.boxesHolder, getRandomTempDir, None, stateBench.settings, VersionalStorage.IODB)
utxoFromBoxHolder(stateBench.boxesHolder, getRandomTempDir, stateBench.settings, VersionalStorage.IODB)
val newState = stateBench.chain.foldLeft(innerState -> List.empty[VersionTag]) { case ((state, rootHashes), block) =>
val newState = state.applyModifier(block).right.get
newState -> (rootHashes :+ newState.version)
Expand Down Expand Up @@ -57,16 +65,17 @@ object StateRollbackBench extends BenchSettings {
}

@State(Scope.Benchmark)
class StateRollbackState extends encry.settings.Settings {
class StateRollbackState extends Settings with Keys {

val tmpDir: File = getRandomTempDir

val initialBoxes: IndexedSeq[AssetBox] = (0 until benchSettings.stateBenchSettings.totalBoxesNumber).map(nonce =>
genHardcodedBox(privKey.publicImage.address.address, nonce)
TestEntityGenerator.genHardcodedBox(privKey.publicImage.address.address, nonce)
)
val boxesHolder: BoxHolder = BoxHolder(initialBoxes)
var state: UtxoState = utxoFromBoxHolder(boxesHolder, tmpDir, None, settings, VersionalStorage.LevelDB)
val genesisBlock: Block = generateGenesisBlockValidForState(state)
var state: UtxoState = utxoFromBoxHolder(boxesHolder, tmpDir, settings, VersionalStorage.LevelDB)
val genesisBlock: Block = genGenesisBlock(privKey.publicImage, settings.constants.InitialEmissionAmount,
settings.constants.InitialDifficulty, settings.constants.GenesisHeight)

state = state.applyModifier(genesisBlock).right.get

Expand Down Expand Up @@ -96,5 +105,38 @@ object StateRollbackBench extends BenchSettings {
val forkBlocks: List[Block] = genesisBlock +: stateGenerationResults._1.map(_._2)
state = stateGenerationResults._3
state.close()

def generateNextBlockForStateWithSpendingAllPreviousBoxes(prevBlock: Block,
state: UtxoState,
box: Seq[AssetBox],
splitCoef: Int = 2,
addDiff: Difficulty = Difficulty @@ BigInt(0)): Block = {

val transactions: Seq[Transaction] = box.indices.foldLeft(box, Seq.empty[Transaction]) {
case ((boxes, transactionsL), _) =>
val tx: Transaction = paymentTransactionWithMultipleOutputs(
privKey,
fee = 1,
timestamp = 11L,
useBoxes = IndexedSeq(boxes.head),
recipient = privKey.publicImage.address.address,
amount = boxes.head.amount - 1,
numOfOutputs = splitCoef
)
(boxes.tail, transactionsL :+ tx)
}._2.filter(tx => state.validate(tx).isRight) ++ Seq(TestEntityGenerator.coinbaseTransaction(prevBlock.header.height + 1))
val header = Header(
1.toByte,
prevBlock.id,
Payload.rootHash(transactions.map(_.id)),
System.currentTimeMillis(),
prevBlock.header.height + 1,
Random.nextLong(),
Difficulty @@ (BigInt(1) + addDiff),
EquihashSolution(Seq(1, 3))
)
Block(header, Payload(header.id, transactions))
}
}

}
Loading