Skip to content

Commit a5064f9

Browse files
committed
wip
1 parent c9915fe commit a5064f9

File tree

12 files changed

+205
-264
lines changed

12 files changed

+205
-264
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.wavesplatform.common
2+
3+
import com.wavesplatform.crypto.bls.BlsUtils
4+
import org.openjdk.jmh.annotations.*
5+
import org.openjdk.jmh.infra.Blackhole
6+
7+
import java.util.concurrent.TimeUnit
8+
import scala.compiletime.uninitialized
9+
10+
@OutputTimeUnit(TimeUnit.MICROSECONDS)
11+
@BenchmarkMode(Array(Mode.AverageTime))
12+
@Threads(1)
13+
@Fork(1)
14+
@Warmup(iterations = 30, time = 1)
15+
@Measurement(iterations = 30, time = 1)
16+
class BLSBenchmark {
17+
@Benchmark
18+
def verifyAgg(st: EndorsementSt, bh: Blackhole) = bh.consume(BlsUtils.verifyAgg(st.aggregatedSignature, st.message, st.publicKeys))
19+
}
20+
21+
@State(Scope.Benchmark)
22+
class EndorsementSt {
23+
@Param(Array("32", "64", "128"))
24+
var generatorCount = 0
25+
var publicKeys = Seq.empty[Array[Byte]]
26+
var aggregatedSignature: Array[Byte] = uninitialized
27+
val message: Array[Byte] = {
28+
val bs = new Array[Byte](64)
29+
bs
30+
}
31+
32+
@Setup
33+
def setup(): Unit = {
34+
val privateKeys = Seq.tabulate(generatorCount) { i =>
35+
val bs = new Array[Byte](32)
36+
bs(0) = i.toByte
37+
BlsUtils.mkBlsSecretKey(bs)
38+
}
39+
40+
publicKeys = privateKeys.map(BlsUtils.mkBlsPublicKey)
41+
aggregatedSignature = privateKeys.map(sk => BlsUtils.signBasic(sk, message)).reduceLeft(BlsUtils.aggSign)
42+
}
43+
}

docker/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ ARG CORRETTO_VERSION=2.5.0
66
ARG ROCKSDB_VERSION=10.2.1
77

88
ENV WAVES_LOG_LEVEL=INFO
9+
ENV WAVES_LOG_JAVA_OPTS=true
10+
911
ENV WAVES_HEAP_SIZE=2g
1012
ENV WAVES_NETWORK=mainnet
1113

docker/entrypoint.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ JAVA_OPTS="-XX:+ExitOnOutOfMemoryError
1313
-Dwaves.rest-api.bind-address=0.0.0.0
1414
${JAVA_OPTS}"
1515

16-
echo "JAVA_OPTS=${JAVA_OPTS}" | tee -a ${WVLOG}/waves.log
16+
if [ "$WAVES_LOG_JAVA_OPTS" = "true" ] ; then
17+
echo "JAVA_OPTS=${JAVA_OPTS}" | tee -a ${WVLOG}/waves.log
18+
fi
1719

1820
if [ -n "$WAVES_WALLET_SEED" ] ; then
1921
JAVA_OPTS="-Dwaves.wallet.seed=${WAVES_WALLET_SEED} ${JAVA_OPTS}"

docker/private/waves.custom.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ waves {
2121
reset-effective-balances-at-height: 1
2222
allow-leased-balance-transfer-until: 0
2323
block-version-3-after-height: 0
24+
generation-period-length = 1000
2425
pre-activated-features = {
2526
1 = 0
2627
2 = 0

node/src/main/scala/com/wavesplatform/Application.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ class Application(val actorSystem: ActorSystem, val settings: WavesSettings, con
491491
blockchainUpdater,
492492
routeTimeout
493493
),
494-
RewardApiRoute(blockchainUpdater)
494+
RewardApiRoute(blockchainUpdater),
495+
FinalityApiRoute(blockchainUpdater, settings.dbSettings.maxRollbackDepth, extensionContext.generatorsApi)
495496
)
496497

497498
val httpService = CompositeHttpService(apiRoutes, settings.restAPISettings)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.wavesplatform.api.http
2+
3+
import com.wavesplatform.api.common.CommonGeneratorsApi
4+
import com.wavesplatform.api.common.CommonGeneratorsApi.GeneratorEntry
5+
import com.wavesplatform.state.{Blockchain, GenerationPeriod, Height}
6+
import org.apache.pekko.http.scaladsl.server.Route
7+
import play.api.libs.json.*
8+
9+
case class FinalityApiRoute(blockchain: Blockchain, maxRollback: Int, generatorsApi: CommonGeneratorsApi) extends ApiRoute {
10+
import FinalityApiRoute.given
11+
12+
override def route: Route = pathPrefix("blockchain" / "finality") {
13+
(get & pathEndOrSingleSlash) {
14+
complete(finalityInfo)
15+
}
16+
}
17+
18+
private def finalityInfo: JsObject = {
19+
val currentHeight = blockchain.height
20+
val currentPeriod = blockchain.generationPeriodOf(Height(currentHeight))
21+
Json.obj(
22+
"height" -> currentHeight,
23+
"finalizedHeight" -> blockchain.finalizedHeightAtOrFallback(maxRollback, Height(currentHeight)),
24+
"currentGenerationPeriod" -> currentPeriod,
25+
"currentGenerators" -> generatorsApi.generators(Height(currentHeight)),
26+
"nextGenerationPeriod" -> currentPeriod.map(_.next),
27+
"nextGenerators" -> currentPeriod.fold(Seq.empty)(p => generatorsApi.generators(p.next.start))
28+
)
29+
}
30+
}
31+
32+
object FinalityApiRoute {
33+
given Writes[GenerationPeriod] = (gp: GenerationPeriod) =>
34+
Json.obj(
35+
"start" -> gp.start,
36+
"end" -> gp.end
37+
)
38+
39+
given Writes[GeneratorEntry] = Json.writes[GeneratorEntry]
40+
}

node/src/main/scala/com/wavesplatform/api/http/TransactionsApiRoute.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,12 @@ case class TransactionsApiRoute(
187187

188188
def sign: Route = (pathPrefix("sign") & withAuth) {
189189
pathEndOrSingleSlash(jsonPost[JsObject] { jsv =>
190-
mkTxFactory.parseRequestAndSign((jsv \ "sender").as[String], jsv)
190+
mkTxFactory.parseRequestAndSign(None, jsv)
191191
}) ~ signWithSigner
192192
}
193193

194194
def signWithSigner: Route = path(AddrSegment) { address =>
195-
jsonPost[JsObject](mkTxFactory.parseRequestAndSign(address.toString, _))
195+
jsonPost[JsObject](mkTxFactory.parseRequestAndSign(Some(address.toString), _))
196196
}
197197

198198
def signedBroadcast: Route = path("broadcast") {

node/src/main/scala/com/wavesplatform/api/http/requests/package.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,5 @@ package object requests {
8585
implicit val byteStrFormat: Format[ByteStr] = com.wavesplatform.utils.byteStrFormat
8686

8787
private[requests] def defaultVersion = TxVersion.V1
88-
private[requests] def defaultTimestamp = 0L
88+
private[requests] def defaultTimestamp = System.currentTimeMillis()
8989
}

node/src/main/scala/com/wavesplatform/settings/BlockchainSettings.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ case class FunctionalitySettings(
8282
paymentsCheckHeight: Int = 0,
8383
unitsRegistryAddress: Option[String] = None,
8484
maxValidEndorsers: Int = 5,
85-
generationPeriodLength: Int = 1001
85+
generationPeriodLength: Int = 1000
8686
) {
8787
val allowLeasedBalanceTransferUntilHeight: Int = blockVersion3AfterHeight
8888
val allowTemporaryNegativeUntil: Long = lastTimeBasedForkParameter

0 commit comments

Comments
 (0)