Skip to content

Commit

Permalink
Merge pull request #3 from 0bsnetwork/merge-0162
Browse files Browse the repository at this point in the history
Merge 0.16.2 (m/t)
  • Loading branch information
BlockchainJames committed Mar 8, 2019
2 parents 7265230 + eeb7602 commit 1796d5d
Show file tree
Hide file tree
Showing 254 changed files with 8,275 additions and 3,781 deletions.
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 0bsNetwork
Copyright (c) 2019 0bsNetwork

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
10 changes: 6 additions & 4 deletions README.md
@@ -1,5 +1,4 @@
# Zbs [![Build Status](https://travis-ci.org/0bsnetwork/Zbs.svg?branch=master)](https://travis-ci.org/0bsnetwork/Zbs)

# 0bsNetwork Full Node

In the master branch there is a code with functions that is under development. The latest release for each network can be found in the [Releases section](https://github.com/0bsnetwork/Zbs/releases), you can switch to the corresponding tag and build the application.

Expand Down Expand Up @@ -48,10 +47,13 @@ Mutiple features can be seperated by commas;
features = [9,10,11]
```

Note: Features < 9 have been pre-activated on this current node version.
Note: Features <= 11 have been pre-activated on the chain.

# Tests & Coverage

```
sbt -J-XX:MaxMetaspaceSize=512M -J-XX:MetaspaceSize=512M -J-Xms2048M -J-Xmx2048M -J-Xss6M -J-XX:MaxPermSize=512M ";coverage;checkPR;coverageReport"
unset _JAVA_OPTIONS
unset SBT_OPTS
export JAVA_TOOL_OPTIONS="-Xmx1548m"
sbt -J-Xms128m -J-Xmx1248m -J-XX:+UseConcMarkSweepGC -J-XX:+CMSClassUnloadingEnabled ";coverage;checkPR;coverageReport"
```
@@ -0,0 +1,75 @@
package com.zbsnetwork.serialization.protobuf

import java.util.concurrent.TimeUnit

import com.zbsnetwork.account.PublicKeyAccount
import com.zbsnetwork.common.state.ByteStr
import com.zbsnetwork.common.utils.Base58
import com.zbsnetwork.protobuf.transaction.PBTransactions
import com.zbsnetwork.transaction.Proofs
import com.zbsnetwork.transaction.transfer.MassTransferTransaction
import com.zbsnetwork.transaction.transfer.MassTransferTransaction.Transfer
import org.openjdk.jmh.annotations._
import org.openjdk.jmh.infra.Blackhole

@OutputTimeUnit(TimeUnit.NANOSECONDS)
@BenchmarkMode(Array(Mode.AverageTime))
@Threads(1)
@Fork(1)
@Warmup(iterations = 10)
@Measurement(iterations = 10)
class ProtoBufBenchmark {

@Benchmark
def serializeMassTransferPB_test(bh: Blackhole): Unit = {
val vanillaTx = {
val transfers = MassTransferTransaction
.parseTransfersList(
List(Transfer("3N5GRqzDBhjVXnCn44baHcz2GoZy5qLxtTh", 100000000L), Transfer("3N5GRqzDBhjVXnCn44baHcz2GoZy5qLxtTh", 200000000L)))
.right
.get

MassTransferTransaction
.create(
None,
PublicKeyAccount.fromBase58String("FM5ojNqW7e9cZ9zhPYGkpSP1Pcd8Z3e3MNKYVS5pGJ8Z").right.get,
transfers,
1518091313964L,
200000,
Base58.decode("59QuUcqP6p").get,
Proofs(Seq(ByteStr.decodeBase58("FXMNu3ecy5zBjn9b69VtpuYRwxjCbxdkZ3xZpLzB8ZeFDvcgTkmEDrD29wtGYRPtyLS3LPYrL2d5UM6TpFBMUGQ").get))
)
.right
.get
}

val tx = PBTransactions.protobuf(vanillaTx)
bh.consume(tx.toByteArray)
}

@Benchmark
def serializeMassTransferVanilla_test(bh: Blackhole): Unit = {
val vanillaTx = {
val transfers = MassTransferTransaction
.parseTransfersList(
List(Transfer("3N5GRqzDBhjVXnCn44baHcz2GoZy5qLxtTh", 100000000L), Transfer("3N5GRqzDBhjVXnCn44baHcz2GoZy5qLxtTh", 200000000L)))
.right
.get

MassTransferTransaction
.create(
None,
PublicKeyAccount.fromBase58String("FM5ojNqW7e9cZ9zhPYGkpSP1Pcd8Z3e3MNKYVS5pGJ8Z").right.get,
transfers,
1518091313964L,
200000,
Base58.decode("59QuUcqP6p").get,
Proofs(Seq(ByteStr.decodeBase58("FXMNu3ecy5zBjn9b69VtpuYRwxjCbxdkZ3xZpLzB8ZeFDvcgTkmEDrD29wtGYRPtyLS3LPYrL2d5UM6TpFBMUGQ").get))
)
.right
.get
}

bh.consume(vanillaTx.bytes())
}
}
Expand Up @@ -11,6 +11,7 @@ import com.zbsnetwork.database.LevelDBWriter
import com.zbsnetwork.db.LevelDBFactory
import com.zbsnetwork.settings.{ZbsSettings, loadConfig}
import com.zbsnetwork.state.LevelDBWriterBenchmark._
import com.zbsnetwork.transaction.AssetId
import com.zbsnetwork.utils.Implicits.SubjectOps
import monix.reactive.subjects.Subject
import org.iq80.leveldb.{DB, Options}
Expand Down Expand Up @@ -91,8 +92,10 @@ object LevelDBWriterBenchmark {
LevelDBFactory.factory.open(dir, new Options)
}

private val ignorePortfolioChanged: Subject[Address, Address] = Subject.empty[Address]
val db = new LevelDBWriter(rawDB, ignorePortfolioChanged, zbsSettings.blockchainSettings.functionalitySettings, 100000, 2000, 120 * 60 * 1000)
private val ignoreSpendableBalanceChanged = Subject.empty[(Address, Option[AssetId])]

val db =
new LevelDBWriter(rawDB, ignoreSpendableBalanceChanged, zbsSettings.blockchainSettings.functionalitySettings, 100000, 2000, 120 * 60 * 1000)

@TearDown
def close(): Unit = {
Expand Down
35 changes: 26 additions & 9 deletions build.sbt
Expand Up @@ -15,7 +15,7 @@ val versionSource = Def.task {
// Please, update the fallback version every major and minor releases.
// This version is used then building from sources without Git repository
// In case of not updating the version nodes build from headless sources will fail to connect to newer versions
val FallbackVersion = (0, 16, 0)
val FallbackVersion = (0, 16, 2)

val versionFile = (sourceManaged in Compile).value / "com" / "zbsnetwork" / "Version.scala"
val versionExtractor = """(\d+)\.(\d+)\.(\d+).*""".r
Expand All @@ -41,15 +41,21 @@ name := "zbs"
normalizedName := s"${name.value}${network.value.packageSuffix}"

git.useGitDescribe := true
git.uncommittedSignifier := Some("")
git.uncommittedSignifier := Some("MT")
logBuffered := false

inThisBuild(
Seq(
scalaVersion := "2.12.8",
organization := "com.zbsnetwork",
crossPaths := false,
scalacOptions ++= Seq("-feature", "-deprecation", "-language:higherKinds", "-language:implicitConversions", "-Ywarn-unused:-implicits", "-Xlint")
scalacOptions ++= Seq("-feature",
"-deprecation",
"-language:higherKinds",
"-language:implicitConversions",
"-Ywarn-unused:-implicits",
"-Xlint",
"-Ywarn-unused-import")
))

resolvers ++= Seq(
Expand All @@ -67,7 +73,7 @@ val java9Options = Seq(
fork in run := true
javaOptions in run ++= java9Options

Test / fork := true
Test / fork := false
Test / javaOptions ++= java9Options

Jmh / javaOptions ++= java9Options
Expand Down Expand Up @@ -110,7 +116,9 @@ inConfig(Compile)(
mainClass := Some("com.zbsnetwork.Application"),
publishArtifact in packageDoc := false,
publishArtifact in packageSrc := false,
sourceGenerators += versionSource
sourceGenerators += versionSource,
PB.targets += scalapb.gen(flatPackage = true) -> (sourceManaged in Compile).value,
PB.deleteTargetDirectory := false
))

inConfig(Test)(
Expand Down Expand Up @@ -213,8 +221,8 @@ def allProjects: List[ProjectReference] = ReflectUtilities.allVals[Project](this

addCommandAlias(
"checkPR",
// set scalacOptions in ThisBuild ++= Seq("-Xfatal-warnings");
""";
|set scalacOptions in ThisBuild ++= Seq("-Xfatal-warnings");
|Global / checkPRRaw;
|set scalacOptions in ThisBuild -= "-Xfatal-warnings";
""".stripMargin
Expand All @@ -233,6 +241,7 @@ checkPRRaw in Global := {

lazy val common = crossProject(JSPlatform, JVMPlatform)
.withoutSuffixFor(JVMPlatform)
.disablePlugins(ProtocPlugin)
.settings(
libraryDependencies ++= Dependencies.scalatest
)
Expand All @@ -243,6 +252,7 @@ lazy val commonJVM = common.jvm
lazy val lang =
crossProject(JSPlatform, JVMPlatform)
.withoutSuffixFor(JVMPlatform)
.disablePlugins(ProtocPlugin)
.settings(
version := "1.0.0",
coverageExcludedPackages := ".*",
Expand Down Expand Up @@ -308,7 +318,7 @@ lazy val node = project
Dependencies.http ++
Dependencies.akka ++
Dependencies.serialization ++
Dependencies.testKit.map(_ % "test") ++
Dependencies.testKit.map(_ % Test) ++
Dependencies.logging ++
Dependencies.matcher ++
Dependencies.metrics ++
Expand All @@ -317,11 +327,18 @@ lazy val node = project
Dependencies.ficus ++
Dependencies.scorex ++
Dependencies.commons_net ++
Dependencies.monix.value
Dependencies.monix.value ++
Dependencies.protobuf.value ++
Dependencies.grpc,
dependencyOverrides ++= Seq(
Dependencies.AkkaActor,
Dependencies.AkkaStream,
Dependencies.AkkaHTTP
)
)
.dependsOn(langJVM, commonJVM)

lazy val discovery = project
///lazy val discovery = project

lazy val it = project
.dependsOn(node)
Expand Down
Expand Up @@ -5,14 +5,6 @@ import com.zbsnetwork.common.utils.{Base58, Base64}
import scala.util.Try

case class ByteStr(arr: Array[Byte]) {

override def equals(a: Any): Boolean = a match {
case other: ByteStr => arr.sameElements(other.arr)
case _ => false
}

override def hashCode(): Int = java.util.Arrays.hashCode(arr)

lazy val base58: String = Base58.encode(arr)

lazy val base64: String = "base64:" + Base64.encode(arr)
Expand Down Expand Up @@ -52,23 +44,27 @@ case class ByteStr(arr: Array[Byte]) {

def dropRight(n: Long): ByteStr = take(arr.length.toLong - n.max(0))

override def equals(a: Any): Boolean = a match {
case other: ByteStr => arr.sameElements(other.arr)
case _ => false
}

override def hashCode(): Int = java.util.Arrays.hashCode(arr)
}

object ByteStr {

val empty: ByteStr = ByteStr(Array.emptyByteArray)

def fromBytes(bytes: Byte*): ByteStr = {

val buf = new Array[Byte](bytes.size)
var i = 0
implicit def fromByteArray(arr: Array[Byte]): ByteStr = {
new ByteStr(arr)
}

bytes.foreach { b =>
buf(i) = b
i += 1
}
implicit def toByteArray(bs: ByteStr): Array[Byte] = {
bs.arr
}

ByteStr(buf)
def fromBytes(bytes: Byte*): ByteStr = {
ByteStr(bytes.toArray)
}

def fromLong(l: Long): ByteStr = {
Expand Down
@@ -1,12 +1,20 @@
package com.zbsnetwork.common
import scala.util.{Failure, Success, Try}

package object utils {

implicit class EitherExt2[A, B](ei: Either[A, B]) {

def explicitGet(): B = ei match {
case Left(value) => throw new Exception(value.toString)
case Right(value) => value
}
}

def foldToTry: Try[B] = {
ei.fold(
left => Failure(new Exception(left.toString)),
right => Success(right)
)
}
}
}
Expand Up @@ -3,11 +3,11 @@ package com.zbsnetwork.dexgen
import java.util.concurrent.Executors

import cats.implicits.showInterpolator
import cats.instances.byte
import com.typesafe.config.ConfigFactory
import com.zbsnetwork.account.{AddressOrAlias, AddressScheme, PrivateKeyAccount}
import com.zbsnetwork.api.http.assets.{SignedIssueV2Request, SignedMassTransferRequest}
import com.zbsnetwork.common.state.ByteStr
import com.zbsnetwork.common.utils.EitherExt2
import com.zbsnetwork.dexgen.cli.ScoptImplicits
import com.zbsnetwork.dexgen.config.FicusImplicits
import com.zbsnetwork.dexgen.utils.{ApiRequests, GenOrderType}
Expand All @@ -19,7 +19,6 @@ import com.zbsnetwork.transaction.assets.IssueTransactionV2
import com.zbsnetwork.transaction.transfer.MassTransferTransaction
import com.zbsnetwork.transaction.transfer.MassTransferTransaction.ParsedTransfer
import com.zbsnetwork.utils.LoggerFacade
import com.zbsnetwork.common.utils.EitherExt2
import net.ceedubs.ficus.Ficus._
import net.ceedubs.ficus.readers.ArbitraryTypeReader._
import net.ceedubs.ficus.readers.{EnumerationReader, NameMapper}
Expand Down Expand Up @@ -79,6 +78,7 @@ object DexGenApp extends App with ScoptImplicits with FicusImplicits with Enumer
def issueAssets(endpoint: String, richAddressSeed: String, n: Int)(implicit tag: String): Seq[AssetId] = {
val node = api.to(endpoint)

val now = System.currentTimeMillis()
val assetsTx: Seq[IssueTransactionV2] = (1 to n).map { i =>
IssueTransactionV2
.selfSigned(
Expand All @@ -89,7 +89,7 @@ object DexGenApp extends App with ScoptImplicits with FicusImplicits with Enumer
decimals = 2,
reissuable = false,
fee = 100000000,
timestamp = System.currentTimeMillis(),
timestamp = now + i,
sender = PrivateKeyAccount.fromSeed(richAddressSeed).explicitGet(),
script = None
)
Expand Down

0 comments on commit 1796d5d

Please sign in to comment.