Skip to content

Commit 6de1842

Browse files
committed
merging with master
2 parents 6eaa14a + d03fbd5 commit 6de1842

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+228
-195
lines changed

build.sbt

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@
22
name := "scorex-core"
33

44
lazy val commonSettings = Seq(
5-
wartremoverErrors ++= Seq(Wart.Recursion, Wart.TraversableOps), // , Wart.Product, Wart.Var, Wart.Null
5+
wartremoverErrors ++= Seq(
6+
Wart.Recursion,
7+
Wart.TraversableOps,
8+
Wart.Null,
9+
Wart.Product,
10+
Wart.PublicInference,
11+
Wart.FinalVal,
12+
Wart.IsInstanceOf,
13+
Wart.JavaConversions,
14+
Wart.JavaSerializable,
15+
Wart.Serializable),
616
scalaVersion := "2.12.3",
717
organization := "org.scorexfoundation",
818
licenses := Seq("CC0" -> url("https://creativecommons.org/publicdomain/zero/1.0/legalcode")),

examples/src/main/scala/examples/commons/FileLogger.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import java.nio.file.{Files, Path, Paths, StandardOpenOption}
55
class FileLogger(filePath: String) {
66

77
val path: Path = Paths.get(filePath)
8-
val f = path.toFile
8+
private val f = path.toFile
99
f.getParentFile().mkdirs()
1010
f.createNewFile()
1111

examples/src/main/scala/examples/commons/PublicKey25519NoncedBox.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ case class PublicKey25519NoncedBox(override val proposition: PublicKey25519Propo
2525
}
2626

2727
object PublicKey25519NoncedBox {
28-
val BoxKeyLength = Blake2b256.DigestSize
28+
val BoxKeyLength: Int = Blake2b256.DigestSize
2929
val BoxLength: Int = Curve25519.KeyLength + 2 * 8
3030

3131
implicit val publicKey25519NoncedBoxEncoder: Encoder[PublicKey25519NoncedBox] = (pknb: PublicKey25519NoncedBox) =>

examples/src/main/scala/examples/hybrid/HybridApp.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class HybridApp(val settingsFilename: String) extends Application {
4040

4141
override val nodeViewHolderRef: ActorRef = HybridNodeViewHolderRef(settings, hybridSettings.mining, timeProvider)
4242

43-
override val apiRoutes: Seq[ApiRoute] = Seq(
43+
override val apiRoutes: Seq[ApiRoute] = Seq[ApiRoute](
4444
DebugApiRoute(settings.restApi, nodeViewHolderRef),
4545
WalletApiRoute(settings.restApi, nodeViewHolderRef),
4646
StatsApiRoute(settings.restApi, nodeViewHolderRef),
@@ -70,6 +70,6 @@ class HybridApp(val settingsFilename: String) extends Application {
7070
}
7171

7272
object HybridApp extends App {
73-
val settingsFilename = args.headOption.getOrElse("settings.conf")
73+
private val settingsFilename = args.headOption.getOrElse("settings.conf")
7474
new HybridApp(settingsFilename).run()
7575
}

examples/src/main/scala/examples/hybrid/HybridNodeViewHolder.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ object HybridNodeViewHolder extends ScorexLogging {
150150
history = history.append(powGenesis).get._1
151151
history = history.append(posGenesis).get._1
152152

153-
val gs = HBoxStoredState.genesisState(settings, Seq(posGenesis, powGenesis))
154-
val gw = HWallet.genesisWallet(settings, Seq(posGenesis, powGenesis))
153+
val gs = HBoxStoredState.genesisState(settings, Seq[HybridBlock](posGenesis, powGenesis))
154+
val gw = HWallet.genesisWallet(settings, Seq[HybridBlock](posGenesis, powGenesis))
155155
.ensuring(_.boxes().map(_.box.value.toLong).sum >= GenesisBalance || !Base58.encode(settings.wallet.seed.arr).startsWith("genesis"))
156156
.ensuring(_.boxes().forall(b => gs.closedBox(b.box.id).isDefined))
157157

examples/src/main/scala/examples/hybrid/api/http/WalletApiRoute.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import examples.hybrid.state.HBoxStoredState
99
import examples.hybrid.wallet.HWallet
1010
import io.circe.parser._
1111
import io.circe.syntax._
12-
import scorex.core.api.http.{ApiException, ApiRouteWithFullView, SuccessApiResponse}
12+
import scorex.core.api.http.{ApiException, ApiRouteWithFullView, ScorexApiResponse, SuccessApiResponse}
1313
import scorex.core.settings.RESTApiSettings
1414
import scorex.core.transaction.box.proposition.PublicKey25519Proposition
1515
import scorex.crypto.encode.Base58
@@ -25,9 +25,9 @@ case class WalletApiRoute(override val settings: RESTApiSettings, nodeViewHolder
2525
import scorex.core.NodeViewHolder.ReceivableMessages.LocallyGeneratedTransaction
2626

2727
//TODO move to settings?
28-
val DefaultFee = 100
28+
val DefaultFee: Int = 100
2929

30-
override val route = (pathPrefix("wallet") & withCors) {
30+
override val route: Route = (pathPrefix("wallet") & withCors) {
3131
balances ~ transfer
3232
}
3333

examples/src/main/scala/examples/hybrid/history/HistoryStorage.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import scorex.core.consensus.{Absent, ModifierSemanticValidity, Unknown}
99
import scorex.core.utils.ScorexLogging
1010
import scorex.crypto.hash.Sha256
1111

12-
import scala.util.Failure
12+
import scala.util.{Failure, Try}
1313

1414
//TODO: why we are using IODB if there's no rollback?
1515
class HistoryStorage(storage: LSMStore,
@@ -42,7 +42,7 @@ class HistoryStorage(storage: LSMStore,
4242
storage.get(ByteArrayWrapper(blockId)).flatMap { bw =>
4343
val bytes = bw.data
4444
val mtypeId = bytes.head
45-
val parsed = mtypeId match {
45+
val parsed: Try[HybridBlock] = mtypeId match {
4646
case t: Byte if t == PowBlock.ModifierTypeId =>
4747
PowBlockCompanion.parseBytes(bytes.tail)
4848
case t: Byte if t == PosBlock.ModifierTypeId =>

examples/src/main/scala/examples/hybrid/history/HybridHistory.scala

+7-6
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ class HybridHistory(val storage: HistoryStorage,
4747
}
4848

4949
val height: Long = storage.height
50-
val bestPosId = storage.bestPosId
51-
val bestPowId = storage.bestPowId
52-
lazy val bestPosBlock = storage.bestPosBlock
53-
lazy val bestPowBlock = storage.bestPowBlock
54-
lazy val bestBlock = if (pairCompleted) bestPosBlock else bestPowBlock
50+
val bestPosId: ModifierId = storage.bestPosId
51+
val bestPowId: ModifierId = storage.bestPowId
52+
lazy val bestPosBlock: PosBlock = storage.bestPosBlock
53+
lazy val bestPowBlock: PowBlock = storage.bestPowBlock
54+
lazy val bestBlock: HybridBlock = if (pairCompleted) bestPosBlock else bestPowBlock
5555

5656
/**
5757
* Return specified number of PoW blocks, ordered back from last one
@@ -399,6 +399,7 @@ class HybridHistory(val storage: HistoryStorage,
399399
until: HybridBlock => Boolean,
400400
limit: Int = Int.MaxValue,
401401
acc: Seq[(ModifierTypeId, ModifierId)] = Seq()): Option[Seq[(ModifierTypeId, ModifierId)]] = {
402+
@SuppressWarnings(Array("org.wartremover.warts.IsInstanceOf"))
402403
val sum: Seq[(ModifierTypeId, ModifierId)] = if (m.isInstanceOf[PosBlock]) (PosBlock.ModifierTypeId -> m.id) +: acc
403404
else (PowBlock.ModifierTypeId -> m.id) +: acc
404405

@@ -478,7 +479,7 @@ class HybridHistory(val storage: HistoryStorage,
478479

479480

480481
object HybridHistory extends ScorexLogging {
481-
val DifficultyRecalcPeriod = 20
482+
val DifficultyRecalcPeriod: Int = 20
482483

483484
def readOrGenerate(settings: ScorexSettings, minerSettings: HybridMiningSettings, timeProvider: NetworkTimeProvider): HybridHistory = {
484485
readOrGenerate(settings.dataDir, settings.logDir, minerSettings, timeProvider)

examples/src/main/scala/examples/hybrid/history/HybridSyncInfo.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ case class HybridSyncInfo(answer: Boolean,
3333
}
3434

3535
object HybridSyncInfo {
36-
val MaxLastPowBlocks = 50 //don't make it more than 127 without changing serialization!
36+
val MaxLastPowBlocks: Byte = 50 //don't make it more than 127 without changing serialization!
3737
}
3838

3939
object HybridSyncInfoSerializer extends Serializer[HybridSyncInfo] {

examples/src/main/scala/examples/hybrid/mining/PosForger.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ object PosForger extends ScorexLogging {
6161

6262
import scorex.core.NodeViewHolder.ReceivableMessages.GetDataFromCurrentView
6363

64-
val InitialDifficuly = 1500000000L
64+
val InitialDifficuly: Long = 1500000000L
6565

6666
object ReceivableMessages {
6767
case object StartForging
@@ -135,7 +135,7 @@ object PosForger extends ScorexLogging {
135135

136136
}
137137

138-
val TransactionsPerBlock = 50
138+
private val TransactionsPerBlock = 50
139139

140140
}
141141

examples/src/main/scala/examples/hybrid/mining/PowMiner.scala

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class PowMiner(viewHolderRef: ActorRef, settings: HybridMiningSettings) extends
6666
}
6767
}
6868

69+
@SuppressWarnings(Array("org.wartremover.warts.Serializable"))
6970
override def receive: Receive = {
7071
case StartMining =>
7172
if (settings.blockGenerationDelay >= 1.minute) {

examples/src/main/scala/examples/hybrid/simulations/PrivateChain.scala

+5-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import scala.concurrent.duration._
2424
*/
2525
object PrivateChain extends App with ScorexLogging {
2626

27-
val proposition = PublicKey25519Proposition(PublicKey @@ scorex.utils.Random.randomBytes(32))
27+
val proposition: PublicKey25519Proposition = PublicKey25519Proposition(PublicKey @@ scorex.utils.Random.randomBytes(32))
2828

2929
def genesisState(): (HybridHistory, HBoxStoredState, HWallet, SimpleBoxTransactionMemPool) = {
3030
HybridNodeViewHolder.generateGenesisState(settings, miningSettings, new NetworkTimeProvider(settings.ntp))
@@ -69,6 +69,8 @@ object PrivateChain extends App with ScorexLogging {
6969

7070
println("Boxes set size: " + boxes.size)
7171

72+
// TODO: review me, could `firstId` still be null at the end of the do-while loop?
73+
@SuppressWarnings(Array("org.wartremover.warts.Null"))
7274
var firstId: BlockId = null
7375

7476
do {
@@ -101,9 +103,9 @@ object PrivateChain extends App with ScorexLogging {
101103
history.bestPosBlock.timestamp - history.modifierById(firstId).get.asInstanceOf[PowBlock].timestamp
102104
}
103105

104-
val experiments = 2
106+
val experiments: Int = 2
105107

106-
val honestHashesPerSecond = 50
108+
val honestHashesPerSecond: Int = 50
107109

108110
val honestAvg = (1 to experiments).map { _ =>
109111
timeSpent(20, honestHashesPerSecond)

examples/src/main/scala/examples/hybrid/state/HBoxStoredState.scala

+1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ object HBoxStoredState {
124124
val forgerNonce = Nonce @@ Longs.fromByteArray(ps.id.take(8))
125125
val forgerBox = PublicKey25519NoncedBox(ps.generatorBox.proposition, forgerNonce, Value @@ reward)
126126

127+
@SuppressWarnings(Array("org.wartremover.warts.Product","org.wartremover.warts.Serializable"))
127128
val ops: Seq[BoxStateChangeOperation[PublicKey25519Proposition, PublicKey25519NoncedBox]] =
128129
toRemove.map(id => Removal[PublicKey25519Proposition, PublicKey25519NoncedBox](id)) ++
129130
toAdd.map(b => Insertion[PublicKey25519Proposition, PublicKey25519NoncedBox](b)) ++

examples/src/main/scala/examples/spv/Constants.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package examples.spv
33
import scorex.crypto.hash.Blake2b256
44

55
object Constants {
6-
val hashfn = Blake2b256
6+
val hashfn: Blake2b256.type = Blake2b256
77

8-
lazy val MaxTarget = BigInt(1, Array.fill(32)(Byte.MinValue))
9-
val InitialDifficulty = BigInt(1)
8+
lazy val MaxTarget: BigInt = BigInt(1, Array.fill(32)(Byte.MinValue))
9+
val InitialDifficulty: BigInt = BigInt(1)
1010
}

examples/src/main/scala/examples/spv/Header.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ object HeaderSerializer extends Serializer[Header] {
6565
Bytes.concat(bytesWithoutInterlinks(h), interlinkBytes(h.interlinks, Array[Byte]()))
6666
}
6767

68-
val BytesWithoutInterlinksLength = 108
68+
val BytesWithoutInterlinksLength: Int = 108
6969

7070
def bytesWithoutInterlinks(h: Header): Array[Byte] = {
7171
Bytes.concat(h.parentId, h.transactionsRoot, h.stateRoot, Longs.toByteArray(h.timestamp), Ints.toByteArray(h.nonce))

examples/src/main/scala/examples/spv/simulation/SPVSimulator.scala

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
package examples.spv.simulation
22

3-
import examples.spv.{SpvAlgos, Header, KMZProofSerializer}
4-
import scorex.core.transaction.state.PrivateKey25519Companion
3+
import examples.spv.{Header, KMZProofSerializer, SpvAlgos}
4+
import scorex.core.transaction.box.proposition.PublicKey25519Proposition
5+
import scorex.core.transaction.state.{PrivateKey25519, PrivateKey25519Companion}
56
import scorex.core.utils.ScorexLogging
7+
import scorex.crypto.hash
68
import scorex.crypto.hash.Blake2b256
79

810
object SPVSimulator extends App with ScorexLogging with SimulatorFuctions {
911

10-
val Height = 500000
11-
val Difficulty = BigInt(1)
12-
val stateRoot = Blake2b256("")
13-
val minerKeys = PrivateKey25519Companion.generateKeys(stateRoot)
12+
private val Height = 500000
13+
private val Difficulty = BigInt(1)
14+
private val stateRoot = Blake2b256("")
15+
private val minerKeys = PrivateKey25519Companion.generateKeys(stateRoot)
1416

15-
val genesis = genGenesisHeader(stateRoot, minerKeys._2)
16-
val st = System.currentTimeMillis()
17-
val headerChain = genChain(Height, Difficulty, stateRoot, IndexedSeq(genesis))
17+
private val genesis = genGenesisHeader(stateRoot, minerKeys._2)
18+
val st: Long = System.currentTimeMillis()
19+
private val headerChain: Seq[Header] = genChain(Height, Difficulty, stateRoot, IndexedSeq(genesis))
1820

1921
val lastBlock: Option[Header] = headerChain.lastOption
20-
var minDiff = Difficulty
22+
var minDiff: BigInt = Difficulty
2123

22-
val k = 6
24+
private val k = 6
2325

2426
println(s"Chain of length $Height, k=$k")
2527
println("m,proofLength,blockNum,uniqueBlockNum")

examples/src/main/scala/examples/trimchain/core/Algos.scala

+7-7
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,17 @@ object Algos extends App {
107107

108108
new File("/tmp/utxo").delete()
109109
new File("/tmp/utxo").mkdirs()
110-
val store = new LSMStore(new File("/tmp/utxo"))
111-
val u1 = PersistentAuthenticatedUtxo(store, 0, None, VersionTag @@ Array.fill(32)(0: Byte))
110+
private val store = new LSMStore(new File("/tmp/utxo"))
111+
private val u1 = PersistentAuthenticatedUtxo(store, 0, None, VersionTag @@ Array.fill(32)(0: Byte))
112112

113-
val pk1 = PublicKey25519Proposition(PublicKey @@ Array.fill(32)(Random.nextInt(100).toByte))
114-
val b1 = PublicKey25519NoncedBox(pk1, Nonce @@ 1L, Value @@ 10L)
115-
val b2 = PublicKey25519NoncedBox(pk1, Nonce @@ 2L, Value @@ 20L)
116-
val u2 = u1.applyChanges(BoxStateChanges(Seq(Insertion(b1), Insertion(b2))),
113+
private val pk1 = PublicKey25519Proposition(PublicKey @@ Array.fill(32)(Random.nextInt(100).toByte))
114+
private val b1 = PublicKey25519NoncedBox(pk1, Nonce @@ 1L, Value @@ 10L)
115+
private val b2 = PublicKey25519NoncedBox(pk1, Nonce @@ 2L, Value @@ 20L)
116+
private val u2 = u1.applyChanges(BoxStateChanges(Seq(Insertion(b1), Insertion(b2))),
117117
VersionTag @@ Array.fill(32)(Random.nextInt(100).toByte)).get
118118

119119

120-
val headerOpt = pow(ModifierId @@ Array.fill(32)(0: Byte),
120+
val headerOpt: Option[BlockHeader] = pow(ModifierId @@ Array.fill(32)(0: Byte),
121121
TransactionsRoot @@ Array.fill(32)(0: Byte),
122122
StateRoot @@ u2.rootHash,
123123
pk1.pubKeyBytes,

examples/src/main/scala/examples/trimchain/core/Constants.scala

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import scorex.crypto.hash.Blake2b256
44

55

66
object Constants {
7-
val n = 20
8-
val k = 1
9-
val NElementsInProof = 10
7+
val n: Int = 20
8+
val k: Int = 1
9+
val NElementsInProof: Int = 10
1010

11-
val hashfn = Blake2b256
11+
val hashfn: Blake2b256.type = Blake2b256
1212

13-
val StateRootLength = hashfn.DigestSize
13+
val StateRootLength: Int = hashfn.DigestSize
1414

15-
val TxRootLength = hashfn.DigestSize
15+
val TxRootLength: Int = hashfn.DigestSize
1616

1717

1818
lazy val MaxTarget = BigInt(1, Array.fill(32)(Byte.MinValue))

examples/src/main/scala/examples/trimchain/core/Ticket.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ object Ticket {
2626

2727
object TicketSerializer extends Serializer[Ticket] {
2828

29-
val MinerKeySize = Curve25519.KeyLength
29+
val MinerKeySize: Int = Curve25519.KeyLength
3030

3131
override def toBytes(obj: Ticket): Array[Byte] = {
3232
val proofsBytes = obj.partialProofs.map { bytes =>

examples/src/main/scala/examples/trimchain/simulation/OneMinerSimulation.scala

+11-11
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,23 @@ object OneMinerSimulation extends App with Simulators {
2424

2525
type Height = Int
2626

27-
val experimentId = Random.nextInt(500000)
28-
val NewBoxesPerBlock = 5000
27+
private val experimentId = Random.nextInt(500000)
28+
private val NewBoxesPerBlock = 5000
2929

30-
val headersChain = mutable.Map[Height, BlockHeader]()
30+
private val headersChain = mutable.Map[Height, BlockHeader]()
3131

32-
val bcDir = new File("/tmp/oms/bc" + experimentId)
32+
private val bcDir = new File("/tmp/oms/bc" + experimentId)
3333
bcDir.mkdirs()
3434

35-
val fullBlocksStore = new MemoryFullBlockStore
35+
private val fullBlocksStore = new MemoryFullBlockStore
3636
// val fullBlocksStore = new LSMStore(bcDir, keySize = 4)
3737

3838
def currentHeight: Int = Try(headersChain.keySet.max).getOrElse(0)
3939

40-
val cuDir = new File("/tmp/oms/cu" + experimentId)
40+
private val cuDir = new File("/tmp/oms/cu" + experimentId)
4141
cuDir.mkdirs()
4242

43-
val muDir = new File("/tmp/oms/mu" + experimentId)
43+
private val muDir = new File("/tmp/oms/mu" + experimentId)
4444
muDir.mkdirs()
4545

4646
def generateTransactions(richBoxes: Seq[PublicKey25519NoncedBox]): Seq[SimpleBoxTransaction] = {
@@ -65,17 +65,17 @@ object OneMinerSimulation extends App with Simulators {
6565
val genesisChanges: BoxStateChanges[PublicKey25519Proposition, PublicKey25519NoncedBox] =
6666
BoxStateChanges(genesisBoxes.map(box => Insertion[PublicKey25519Proposition, PublicKey25519NoncedBox](box)))
6767

68-
var currentUtxo = InMemoryAuthenticatedUtxo(genesisBoxes.size, None, defaultId).applyChanges(genesisChanges, defaultId).get
68+
private var currentUtxo = InMemoryAuthenticatedUtxo(genesisBoxes.size, None, defaultId).applyChanges(genesisChanges, defaultId).get
6969

70-
var miningHeight = 0
71-
var miningUtxo = InMemoryAuthenticatedUtxo(genesisBoxes.size, None, defaultId).applyChanges(genesisChanges, defaultId).get
70+
private var miningHeight = 0
71+
private var miningUtxo = InMemoryAuthenticatedUtxo(genesisBoxes.size, None, defaultId).applyChanges(genesisChanges, defaultId).get
7272
.ensuring(_.rootHash sameElements currentUtxo.rootHash)
7373

7474
var generatingBoxes: Seq[PublicKey25519NoncedBox] = genesisBoxes
7575

7676
log("Current height,Mining height,Current utxo size,Mining utxo size,Work valid,Header size,Ticket size,Proof size,Block size")
7777

78-
val blocksNum = 10000
78+
private val blocksNum = 10000
7979
(1 to blocksNum) foreach { _ =>
8080
val t0 = System.currentTimeMillis()
8181

0 commit comments

Comments
 (0)