Skip to content

Commit

Permalink
Merge branch 'version-1.5.x' into node-2531-payment-validation-order
Browse files Browse the repository at this point in the history
  • Loading branch information
phearnot authored Nov 29, 2023
2 parents f483e63 + c087618 commit 2364fa8
Show file tree
Hide file tree
Showing 300 changed files with 6,254 additions and 6,754 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: 25 additions & 17 deletions grpc-server/src/main/scala/com/wavesplatform/events/events.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.wavesplatform.events
import cats.Monoid
import cats.implicits.catsSyntaxSemigroup
import com.google.protobuf.ByteString
import com.wavesplatform.account.{Address, AddressOrAlias, Alias, PublicKey}
import com.wavesplatform.account.{Address, AddressOrAlias, PublicKey}
import com.wavesplatform.block.{Block, MicroBlock}
import com.wavesplatform.common.state.ByteStr
import com.wavesplatform.common.utils.*
Expand All @@ -17,7 +17,6 @@ import com.wavesplatform.protobuf.transaction.InvokeScriptResult.Call.Argument
import com.wavesplatform.protobuf.transaction.{PBAmounts, PBTransactions, InvokeScriptResult as PBInvokeScriptResult}
import com.wavesplatform.state.*
import com.wavesplatform.state.diffs.invoke.InvokeScriptTransactionLike
import com.wavesplatform.state.reader.SnapshotBlockchain
import com.wavesplatform.transaction.Asset.IssuedAsset
import com.wavesplatform.transaction.assets.exchange.ExchangeTransaction
import com.wavesplatform.transaction.lease.LeaseTransaction
Expand Down Expand Up @@ -386,9 +385,6 @@ 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 = {
val blockchain = blockchainBeforeWithMinerReward
val blockchainAfter = SnapshotBlockchain(blockchain, snapshot)
Expand Down Expand Up @@ -426,25 +422,37 @@ object StateUpdate {
assetAfter = blockchainAfter.assetDescription(asset)
} yield AssetStateUpdate(asset.id, assetBefore, assetAfter)

val updatedLeases = snapshot.leaseStates.map { case (leaseId, newState) =>
val newLeaseUpdates = snapshot.newLeases.collect {
case (newId, staticInfo) if !snapshot.cancelledLeases.contains(newId) =>
LeaseUpdate(
newId,
LeaseStatus.Active,
staticInfo.amount.value,
staticInfo.sender,
staticInfo.recipientAddress,
staticInfo.sourceId
)
}

val cancelledLeaseUpdates = snapshot.cancelledLeases.map { case (id, _) =>
val si = snapshot.newLeases.get(id).orElse(blockchain.leaseDetails(id).map(_.static))
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
id,
LeaseStatus.Inactive,
si.fold(0L)(_.amount.value),
si.fold(PublicKey(new Array[Byte](32)))(_.sender),
si.fold(PublicKey(new Array[Byte](32)).toAddress)(_.recipientAddress),
si.fold(ByteStr.empty)(_.sourceId)
)
}.toVector
}

val updatedLeases = newLeaseUpdates ++ cancelledLeaseUpdates

val updatedScripts = snapshot.accountScriptsByAddress.map { case (address, newScript) =>
ScriptUpdate(ByteStr(address.bytes), blockchain.accountScript(address).map(_.script.bytes()), newScript.map(_.script.bytes()))
}.toVector

StateUpdate(balances.toVector, leaseBalanceUpdates, dataEntries, assets, updatedLeases, updatedScripts, Seq.empty)
StateUpdate(balances.toVector, leaseBalanceUpdates, dataEntries, assets, updatedLeases.toSeq, updatedScripts, Seq.empty)
}

private[this] def transactionsMetadata(blockchain: Blockchain, snapshot: StateSnapshot): Seq[TransactionMetadata] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,15 @@ package com.wavesplatform.api.grpc.test
import com.google.protobuf.ByteString
import com.wavesplatform.TestValues
import com.wavesplatform.account.{Address, KeyPair}
import com.wavesplatform.api.grpc.{
AccountRequest,
AccountsApiGrpcImpl,
BalanceResponse,
BalancesRequest,
DataEntryResponse,
DataRequest,
LeaseResponse
}
import com.wavesplatform.api.grpc.*
import com.wavesplatform.block.Block
import com.wavesplatform.common.state.ByteStr
import com.wavesplatform.crypto.DigestLength
import com.wavesplatform.db.WithDomain
import com.wavesplatform.db.WithState.AddrWithBalance
import com.wavesplatform.history.Domain
import com.wavesplatform.protobuf.Amount
import com.wavesplatform.protobuf.transaction.{DataTransactionData, Recipient}
import com.wavesplatform.protobuf.transaction.{DataEntry, Recipient}
import com.wavesplatform.state.{BlockRewardCalculator, EmptyDataEntry, IntegerDataEntry}
import com.wavesplatform.test.*
import com.wavesplatform.transaction.Asset.Waves
Expand Down Expand Up @@ -151,7 +143,7 @@ class AccountsApiGrpcSpec extends FreeSpec with BeforeAndAfterAll with DiffMatch
result1.runSyncUnsafe() shouldBe List(
DataEntryResponse.of(
ByteString.copyFrom(sender.toAddress.bytes),
Some(DataTransactionData.DataEntry.of("key2", DataTransactionData.DataEntry.Value.IntValue(456)))
Some(DataEntry.of("key2", DataEntry.Value.IntValue(456)))
)
)

Expand All @@ -160,11 +152,11 @@ class AccountsApiGrpcSpec extends FreeSpec with BeforeAndAfterAll with DiffMatch
result2.runSyncUnsafe() shouldBe List(
DataEntryResponse.of(
ByteString.copyFrom(sender.toAddress.bytes),
Some(DataTransactionData.DataEntry.of("key2", DataTransactionData.DataEntry.Value.IntValue(456)))
Some(DataEntry.of("key2", DataEntry.Value.IntValue(456)))
),
DataEntryResponse.of(
ByteString.copyFrom(sender.toAddress.bytes),
Some(DataTransactionData.DataEntry.of("key3", DataTransactionData.DataEntry.Value.IntValue(789)))
Some(DataEntry.of("key3", DataEntry.Value.IntValue(789)))
)
)
}
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 @@ -12,10 +12,9 @@ import com.wavesplatform.events.protobuf.BlockchainUpdated.Append
import com.wavesplatform.test.NumericExt
import com.wavesplatform.transaction.Asset.Waves
import com.wavesplatform.transaction.EthTxGenerator.Arg
import com.wavesplatform.transaction.{Asset, EthTxGenerator, EthereumTransaction, TxHelpers, TxNonNegativeAmount}
import com.wavesplatform.transaction.TxHelpers.secondAddress
import com.wavesplatform.transaction.assets.IssueTransaction
import com.wavesplatform.transaction.transfer.MassTransferTransaction.ParsedTransfer
import com.wavesplatform.transaction.{Asset, EthTxGenerator, EthereumTransaction, TxHelpers}

class BlockchainUpdatesEthereumInvokeTxSpec extends BlockchainUpdatesTestBase {
val ethAddressBalanceAfterTx: Long = firstTxParticipantBalanceBefore - invokeFee
Expand Down Expand Up @@ -89,9 +88,9 @@ class BlockchainUpdatesEthereumInvokeTxSpec extends BlockchainUpdatesTestBase {
val massTx = TxHelpers.massTransfer(
assetDappAccount,
Seq(
ParsedTransfer(firstTxParticipantAddress, TxNonNegativeAmount.unsafeFrom(amount)),
ParsedTransfer(secondAddress, TxNonNegativeAmount.unsafeFrom(amount)),
ParsedTransfer(invokerDappAddress, TxNonNegativeAmount.unsafeFrom(amount))
firstTxParticipantAddress -> amount,
secondAddress -> amount,
invokerDappAddress -> amount
),
asset,
fee = 500000
Expand Down Expand Up @@ -141,23 +140,47 @@ class BlockchainUpdatesEthereumInvokeTxSpec extends BlockchainUpdatesTestBase {
doubleNestedInvokeTest(assetDappAccount, balancesSeq, issue, invoke, massTx, caller, Subscribe) { append =>
val invokeScriptMetadata = append.transactionsMetadata.head.getEthereum.getInvoke
checkEthereumBase(append, invoke, foo)
checkInvokeDoubleNestedBlockchainUpdates(append, invokeScriptMetadata, assetDappAddress, firstTxParticipantAddress, secondAddress, issue, callerBalancesMap)
checkInvokeDoubleNestedBlockchainUpdates(
append,
invokeScriptMetadata,
assetDappAddress,
firstTxParticipantAddress,
secondAddress,
issue,
callerBalancesMap
)
}
}

"BU-230. doubles nested i.caller. Invoke have to return correct data for getBlockUpdate" in {
doubleNestedInvokeTest(assetDappAccount, balancesSeq, issue, invoke, massTx, caller, GetBlockUpdate) { append =>
val invokeScriptMetadata = append.transactionsMetadata.head.getEthereum.getInvoke
checkEthereumBase(append, invoke, foo)
checkInvokeDoubleNestedBlockchainUpdates(append, invokeScriptMetadata, assetDappAddress, firstTxParticipantAddress, secondAddress, issue, callerBalancesMap)
checkInvokeDoubleNestedBlockchainUpdates(
append,
invokeScriptMetadata,
assetDappAddress,
firstTxParticipantAddress,
secondAddress,
issue,
callerBalancesMap
)
}
}

"BU-233. doubles nested i.caller. Invoke have to return correct data for getBlockUpdateRange" in {
doubleNestedInvokeTest(assetDappAccount, balancesSeq, issue, invoke, massTx, caller, GetBlockUpdateRange) { append =>
val invokeScriptMetadata = append.transactionsMetadata.head.getEthereum.getInvoke
checkEthereumBase(append, invoke, foo)
checkInvokeDoubleNestedBlockchainUpdates(append, invokeScriptMetadata, assetDappAddress, firstTxParticipantAddress, secondAddress, issue, callerBalancesMap)
checkInvokeDoubleNestedBlockchainUpdates(
append,
invokeScriptMetadata,
assetDappAddress,
firstTxParticipantAddress,
secondAddress,
issue,
callerBalancesMap
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class BlockchainUpdatesGetBlockUpdatesRangeSpec extends BlockchainUpdatesTestBas

"BU-165. Return correct data for massTransfer" in {
val massTransferFee = fee * 6
val massTransfer = TxHelpers.massTransfer(firstTxParticipant, recipients, firstToken.asset, massTransferFee)
val massTransfer = TxHelpers.massTransfer(firstTxParticipant, recipients.map(v => v.address -> v.amount.value), firstToken.asset, massTransferFee)
withGenerateGetBlockUpdateRange(
GetBlockUpdatesRangeRequest.of(1, 3),
settings = currentSettings,
Expand Down
Loading

0 comments on commit 2364fa8

Please sign in to comment.