Skip to content

Commit

Permalink
Merge branch 'version-1.5.x' into node-2520-corrected-fail-reject-on-…
Browse files Browse the repository at this point in the history
…transfer-balance-error
  • Loading branch information
phearnot committed Nov 28, 2023
2 parents 6abfbe8 + bb322af commit 5dcc3f6
Show file tree
Hide file tree
Showing 179 changed files with 2,701 additions and 2,386 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
package com.wavesplatform.lang.v1

import java.util.concurrent.TimeUnit
import cats.Id
import com.wavesplatform.lang.Common
import com.wavesplatform.lang.directives.values.{V1, V3}
import com.wavesplatform.lang.v1.EvaluatorV2Benchmark.*
import com.wavesplatform.lang.v1.compiler.Terms.{EXPR, IF, TRUE}
import com.wavesplatform.lang.v1.compiler.TestCompiler
import com.wavesplatform.lang.v1.evaluator.EvaluatorV2
import com.wavesplatform.lang.v1.evaluator.ctx.{DisabledLogEvaluationContext, EvaluationContext}
import com.wavesplatform.lang.v1.evaluator.ctx.DisabledLogEvaluationContext
import com.wavesplatform.lang.v1.evaluator.ctx.impl.PureContext
import com.wavesplatform.lang.v1.traits.Environment
import org.openjdk.jmh.annotations.*
import org.openjdk.jmh.infra.Blackhole

import java.util.concurrent.TimeUnit
import scala.annotation.tailrec

object EvaluatorV2Benchmark {
val pureContext: CTX[Environment] = PureContext.build(V1, useNewPowPrecision = true).withEnvironment[Environment]
val pureEvalContext: EvaluationContext[Environment, Id] = pureContext.evaluationContext(Common.emptyBlockchainEnvironment())
val evaluatorV2: EvaluatorV2 = new EvaluatorV2(DisabledLogEvaluationContext(pureEvalContext), V1, true, true, false)
val pureContext = PureContext.build(V1, useNewPowPrecision = true).withEnvironment[Environment]
val pureEvalContext = pureContext.evaluationContext(Common.emptyBlockchainEnvironment())
val evaluatorV2 = new EvaluatorV2(DisabledLogEvaluationContext(pureEvalContext), V1, Int.MaxValue, true, false, true, true, true)
}

@OutputTimeUnit(TimeUnit.MILLISECONDS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ import org.openjdk.jmh.infra.Blackhole
@Measurement(iterations = 10, time = 1)
class FractionIntBenchmark {
@Benchmark
def fraction1(bh: Blackhole, s: St): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr1, LogExtraInfo(), V5, true, true, false))
def fraction1(bh: Blackhole, s: St): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr1, LogExtraInfo(), V5, true, true, false, true))

@Benchmark
def fraction2(bh: Blackhole, s: St): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr2, LogExtraInfo(), V5, true, true, false))
def fraction2(bh: Blackhole, s: St): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr2, LogExtraInfo(), V5, true, true, false, true))

@Benchmark
def fraction3(bh: Blackhole, s: St): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr3, LogExtraInfo(), V5, true, true, false))
def fraction3(bh: Blackhole, s: St): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr3, LogExtraInfo(), V5, true, true, false, true))

@Benchmark
def fraction1Round(bh: Blackhole, s: St): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr1Round, LogExtraInfo(), V5, true, true, false))
def fraction1Round(bh: Blackhole, s: St): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr1Round, LogExtraInfo(), V5, true, true, false, true))

@Benchmark
def fraction2Round(bh: Blackhole, s: St): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr2Round, LogExtraInfo(), V5, true, true, false))
def fraction2Round(bh: Blackhole, s: St): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr2Round, LogExtraInfo(), V5, true, true, false, true))

@Benchmark
def fraction3Round(bh: Blackhole, s: St): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr3Round, LogExtraInfo(), V5, true, true, false))
def fraction3Round(bh: Blackhole, s: St): Unit = bh.consume(EvaluatorV2.applyCompleted(s.ctx, s.expr3Round, LogExtraInfo(), V5, true, true, false, true))
}

@State(Scope.Benchmark)
Expand Down
11 changes: 10 additions & 1 deletion benchmark/src/test/scala/com/wavesplatform/lang/v1/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,14 @@ package object v1 {
expr: EXPR,
stdLibVersion: StdLibVersion = StdLibVersion.VersionDic.all.max
): (Log[Id], Int, Either[ExecutionError, Terms.EVALUATED]) =
EvaluatorV2.applyCompleted(ctx, expr, LogExtraInfo(), stdLibVersion, newMode = true, correctFunctionCallScope = true, enableExecutionLog = false)
EvaluatorV2.applyCompleted(
ctx,
expr,
LogExtraInfo(),
stdLibVersion,
newMode = true,
correctFunctionCallScope = true,
enableExecutionLog = false,
fixedThrownError = true
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ object StateSyntheticBenchmark {

val textScript = "sigVerify(tx.bodyBytes,tx.proofs[0],tx.senderPublicKey)"
val untypedScript = Parser.parseExpr(textScript).get.value
val typedScript = ExpressionCompiler(compilerContext(V1, Expression, isAssetScript = false), untypedScript).explicitGet()._1
val typedScript = ExpressionCompiler(compilerContext(V1, Expression, isAssetScript = false), V1, untypedScript).explicitGet()._1

val setScriptBlock = nextBlock(
Seq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,15 @@ class AccountsApiGrpcImpl(commonApi: CommonAccountsApi)(implicit sc: Scheduler)

override def getScript(request: AccountRequest): Future[ScriptResponse] = Future {
commonApi.script(request.address.toAddress()) match {
case Some(desc) => ScriptResponse(PBTransactions.toPBScript(Some(desc.script)), desc.script.expr.toString, desc.verifierComplexity, desc.publicKey.toByteString)
case None => ScriptResponse()
case Some(desc) =>
ScriptResponse(
PBTransactions.toPBScript(Some(desc.script)),
desc.script.expr.toString,
desc.verifierComplexity,
desc.publicKey.toByteString
)
case None =>
ScriptResponse()
}
}

Expand Down
42 changes: 26 additions & 16 deletions grpc-server/src/main/scala/com/wavesplatform/events/events.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import com.wavesplatform.transaction.assets.exchange.ExchangeTransaction
import com.wavesplatform.transaction.lease.LeaseTransaction
import com.wavesplatform.transaction.smart.InvokeScriptTransaction
import com.wavesplatform.transaction.transfer.{MassTransferTransaction, TransferTransaction}
import com.wavesplatform.transaction.{Asset, Authorized, CreateAliasTransaction, EthereumTransaction}
import com.wavesplatform.transaction.{Asset, Authorized, CreateAliasTransaction, EthereumTransaction, Transaction}

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
Expand Down Expand Up @@ -389,7 +389,11 @@ object StateUpdate {
private lazy val WavesAlias = Alias.fromString("alias:W:waves", Some('W'.toByte)).explicitGet()
private lazy val WavesAddress = Address.fromString("3PGd1eQR8EhLkSogpmu9Ne7hSH1rQ5ALihd", Some('W'.toByte)).explicitGet()

def atomic(blockchainBeforeWithMinerReward: Blockchain, snapshot: StateSnapshot): StateUpdate = {
def atomic(
blockchainBeforeWithMinerReward: Blockchain,
snapshot: StateSnapshot,
txWithLeases: Iterable[(Transaction, Map[ByteStr, LeaseSnapshot])]
): StateUpdate = {
val blockchain = blockchainBeforeWithMinerReward
val blockchainAfter = SnapshotBlockchain(blockchain, snapshot)

Expand Down Expand Up @@ -426,18 +430,20 @@ object StateUpdate {
assetAfter = blockchainAfter.assetDescription(asset)
} yield AssetStateUpdate(asset.id, assetBefore, assetAfter)

val updatedLeases = snapshot.leaseStates.map { case (leaseId, newState) =>
LeaseUpdate(
leaseId,
if (newState.isActive) LeaseStatus.Active else LeaseStatus.Inactive,
newState.amount,
newState.sender,
newState.recipient match {
case `WavesAlias` => WavesAddress
case other => blockchainAfter.resolveAlias(other).explicitGet()
},
newState.sourceId
)
val updatedLeases = txWithLeases.flatMap { case (sourceTxId, leases) =>
leases.map { case (leaseId, newState) =>
LeaseUpdate(
leaseId,
if (newState.isActive) LeaseStatus.Active else LeaseStatus.Inactive,
newState.amount,
newState.sender,
newState.recipient match {
case `WavesAlias` => WavesAddress
case other => blockchainAfter.resolveAlias(other).explicitGet()
},
newState.toDetails(blockchain, Some(sourceTxId), blockchain.leaseDetails(leaseId)).sourceId
)
}
}.toVector

val updatedScripts = snapshot.accountScriptsByAddress.map { case (address, newScript) =>
Expand Down Expand Up @@ -546,13 +552,17 @@ object StateUpdate {
val accBlockchain = SnapshotBlockchain(blockchainBeforeWithReward, accSnapshot)
(
accSnapshot |+| txInfo.snapshot,
updates :+ atomic(accBlockchain, txInfo.snapshot)
updates :+ atomic(accBlockchain, txInfo.snapshot, Seq((txInfo.transaction, txInfo.snapshot.leaseStates)))
)
}
val blockchainAfter = SnapshotBlockchain(blockchainBeforeWithReward, totalSnapshot)
val metadata = transactionsMetadata(blockchainAfter, totalSnapshot)
val refAssets = referencedAssets(blockchainAfter, txsStateUpdates)
val keyBlockUpdate = atomic(blockchainBeforeWithReward, keyBlockSnapshot)
val keyBlockUpdate = atomic(
blockchainBeforeWithReward,
keyBlockSnapshot,
keyBlockSnapshot.transactions.map { case (_, txInfo) => (txInfo.transaction, txInfo.snapshot.leaseStates) }
)
(keyBlockUpdate, txsStateUpdates, metadata, refAssets)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.wavesplatform.api.grpc.test
import com.google.protobuf.ByteString
import com.wavesplatform.account.KeyPair
import com.wavesplatform.api.grpc.{AssetInfoResponse, AssetsApiGrpcImpl, NFTRequest, NFTResponse}
import com.wavesplatform.block.Block.ProtoBlockVersion
import com.wavesplatform.db.WithDomain
import com.wavesplatform.db.WithState.AddrWithBalance
import com.wavesplatform.features.BlockchainFeatures
Expand Down Expand Up @@ -55,6 +56,49 @@ class AssetsApiGrpcSpec extends FreeSpec with BeforeAndAfterAll with DiffMatcher
}
}

"NODE-999. GetNftList limit should work properly" in withDomain(
RideV6.addFeatures(BlockchainFeatures.ReduceNFTFee),
AddrWithBalance.enoughBalances(sender)
) { d =>
val nftIssues = (1 to 5).map(idx => TxHelpers.issue(sender, 1, name = s"nft$idx", reissuable = false))
val limit = 2
val afterId = 1 // second element

d.appendBlock()
val mb1 = d.appendMicroBlock(nftIssues.take(afterId + 1)*)
d.appendMicroBlock(nftIssues.drop(afterId + 1)*)

// full liquid
d.rocksDBWriter.containsTransaction(nftIssues(afterId)) shouldBe false
d.rocksDBWriter.containsTransaction(nftIssues(afterId + 1)) shouldBe false
check()

// liquid afterId
d.appendBlock(d.createBlock(ProtoBlockVersion, nftIssues.drop(afterId + 1), Some(mb1)))
d.rocksDBWriter.containsTransaction(nftIssues(afterId)) shouldBe true
d.rocksDBWriter.containsTransaction(nftIssues(afterId + 1)) shouldBe false
check()

// full solid
d.appendBlock()
d.rocksDBWriter.containsTransaction(nftIssues(afterId)) shouldBe true
d.rocksDBWriter.containsTransaction(nftIssues(afterId + 1)) shouldBe true
check()

def check() = {
val (observer, result) = createObserver[NFTResponse]
val request = NFTRequest.of(
ByteString.copyFrom(sender.toAddress.bytes),
limit,
afterAssetId = ByteString.copyFrom(nftIssues(afterId).asset.id.arr)
)
getGrpcApi(d).getNFTList(request, observer)
val response = result.runSyncUnsafe()
response.size shouldBe limit
response.map(_.assetInfo.get.name) shouldBe nftIssues.slice(afterId + 1, afterId + limit + 1).map(_.name.toStringUtf8)
}
}

private def getGrpcApi(d: Domain) =
new AssetsApiGrpcImpl(d.assetsApi, d.accountsApi)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.wavesplatform.api.grpc.test

import scala.concurrent.{Await, Future}
import scala.concurrent.duration.Duration
import scala.concurrent.duration.*
import com.wavesplatform.account.Address
import com.wavesplatform.common.state.ByteStr
import com.wavesplatform.test.{FlatSpec, TestTime}
Expand Down Expand Up @@ -91,7 +91,7 @@ class GRPCBroadcastSpec extends FlatSpec with BeforeAndAfterAll with PathMockFac

@throws[StatusException]("on failed broadcast")
def assertBroadcast(tx: Transaction): Unit = {
Await.result(grpcTxApi.broadcast(PBTransactions.protobuf(tx)), Duration.Inf)
Await.result(grpcTxApi.broadcast(PBTransactions.protobuf(tx)), 10.seconds)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ class BlockchainUpdatesSpec extends FreeSpec with WithBUDomain with ScalaFutures
(1 to blocksCount + 1).foreach(_ => d.appendBlock())

val result = Await
.result(r.getBlockUpdatesRange(GetBlockUpdatesRangeRequest(1, blocksCount)), Duration.Inf)
.result(r.getBlockUpdatesRange(GetBlockUpdatesRangeRequest(1, blocksCount)), 1.minute)
.updates
.map(_.update.append.map(_.getBlock.vrf.toByteStr).filterNot(_.isEmpty))

Expand Down Expand Up @@ -1215,7 +1215,7 @@ class BlockchainUpdatesSpec extends FreeSpec with WithBUDomain with ScalaFutures
Await
.result(
repo.getBlockUpdate(GetBlockUpdateRequest(height)),
Duration.Inf
1.minute
)
.getUpdate
.update
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ object FastBase58 extends BaseXXEncDec {
outArray(outIndex) = longValue & 0xffffffffL
}

// called only from Try structure, see BaseXXEncDec.tryDecode(str: String)
if (base58EncMask > 0) throw new IllegalArgumentException("Output number too big (carry to the next int32)")
if ((outArray(0) & zeroMask) != 0) throw new IllegalArgumentException("Output number too big (last int32 filled too far)")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ case class CommonError(details: String, cause: Option[ValidationError] = None) e
override def toString: String = s"CommonError($message)"
override def message: String = cause.map(_.toString).getOrElse(details)
}
case class ThrownError(message: String) extends ExecutionError
case class FailOrRejectError(message: String, skipInvokeComplexity: Boolean = true) extends ExecutionError with ValidationError
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ object BaseGlobal {
def apply(n: Int): T =
if (from + n < until) arr(from + n)
else throw new ArrayIndexOutOfBoundsException(n)
// should be never thrown due to passing Random.nextInt(arr.size) at the single point of call

def partitionInPlace(p: T => Boolean): (ArrayView[T], ArrayView[T]) = {
var upper = until - 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.wavesplatform.lang.v1.compiler

import java.nio.charset.StandardCharsets

import cats.Show
import com.wavesplatform.lang.v1.ContractLimits
import com.wavesplatform.lang.v1.compiler.Types.*
import com.wavesplatform.lang.v1.evaluator.ctx.FunctionTypeSignature
import com.wavesplatform.lang.v1.parser.Expressions
import com.wavesplatform.lang.v1.parser.Expressions.{Declaration, PART}

import java.nio.charset.StandardCharsets

sealed trait CompilationError {
def start: Int
def end: Int
Expand Down Expand Up @@ -52,18 +52,11 @@ object CompilationError {
s"but ${names.map(n => s"`$n`").mkString(", ")} found"
}

final case class UnusedCaseVariables(start: Int, end: Int, names: List[String]) extends CompilationError {
val message = s"Unused case variable(s) ${names.map(n => s"`$n`").mkString(", ")}"
}

final case class AlreadyDefined(start: Int, end: Int, name: String, isFunction: Boolean) extends CompilationError {
val message =
if (isFunction) s"Value '$name' can't be defined because function with this name is already defined"
else s"Value '$name' already defined in the scope"
}
final case class NonExistingType(start: Int, end: Int, name: String, existing: List[String]) extends CompilationError {
val message = s"Value '$name' declared as non-existing type, while all possible types are $existing"
}

final case class BadFunctionSignatureSameArgNames(start: Int, end: Int, name: String) extends CompilationError {
val message = s"Function '$name' declared with duplicating argument names"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.wavesplatform.lang.v1.compiler

import com.wavesplatform.lang.v1.compiler.Types.FINAL
import com.wavesplatform.lang.v1.parser.Expressions

case class CompilationStepResultDec(
ctx: CompilerContext,
dec: Terms.DECLARATION,
t: FINAL,
parseNodeExpr: Expressions.Declaration,
errors: Iterable[CompilationError] = Iterable.empty
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.wavesplatform.lang.v1.compiler

import com.wavesplatform.lang.v1.compiler.Types.FINAL
import com.wavesplatform.lang.v1.parser.Expressions

case class CompilationStepResultExpr(
ctx: CompilerContext,
expr: Terms.EXPR,
t: FINAL,
parseNodeExpr: Expressions.EXPR,
errors: Iterable[CompilationError] = Iterable.empty
)
Loading

0 comments on commit 5dcc3f6

Please sign in to comment.