Skip to content

Commit

Permalink
Fix matcher fee validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Nazarov committed Mar 18, 2022
1 parent b735f36 commit 2f4f525
Show file tree
Hide file tree
Showing 3 changed files with 744 additions and 384 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ case class FunctionalitySettings(
syncDAppCheckTransfersHeight: Int = 0,
estimationOverflowFixHeight: Int = 0,
estimatorSumOverflowFixHeight: Int = 0,
forbidSyncDAppNegativePaymentHeight: Int = 0
forbidSyncDAppNegativePaymentHeight: Int = 0,
forbidNegativeMatcherFee: Int = 0
) {
val allowLeasedBalanceTransferUntilHeight: Int = blockVersion3AfterHeight
val allowTemporaryNegativeUntil = lastTimeBasedForkParameter
Expand Down Expand Up @@ -126,7 +127,8 @@ object FunctionalitySettings {
syncDAppCheckTransfersHeight = 2792473,
estimationOverflowFixHeight = 2858710,
estimatorSumOverflowFixHeight = 2897510,
forbidSyncDAppNegativePaymentHeight = 2959447
forbidSyncDAppNegativePaymentHeight = 2959447,
forbidNegativeMatcherFee = 2991300
)

val TESTNET = apply(
Expand All @@ -141,7 +143,8 @@ object FunctionalitySettings {
syncDAppCheckTransfersHeight = 1727461,
estimationOverflowFixHeight = 1793770,
estimatorSumOverflowFixHeight = 1832520,
forbidSyncDAppNegativePaymentHeight = 1894600
forbidSyncDAppNegativePaymentHeight = 1894600,
forbidNegativeMatcherFee = 1926200
)

val STAGENET = apply(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.wavesplatform.state.diffs

import scala.util.{Right, Try}

import cats.instances.map._
import cats.kernel.Monoid
import cats.syntax.either._
Expand All @@ -11,7 +10,7 @@ import com.wavesplatform.lang.ValidationError
import com.wavesplatform.state._
import com.wavesplatform.transaction.{Asset, TxVersion}
import com.wavesplatform.transaction.Asset.{IssuedAsset, Waves}
import com.wavesplatform.transaction.TxValidationError.{GenericError, OrderValidationError}
import com.wavesplatform.transaction.TxValidationError.{GenericError, InsufficientFee, OrderValidationError}
import com.wavesplatform.transaction.assets.exchange.{ExchangeTransaction, Order, OrderType}

object ExchangeTransactionDiff {
Expand Down Expand Up @@ -135,6 +134,12 @@ object ExchangeTransactionDiff {
)

for {
_ <- Either.cond(
blockchain.height < blockchain.settings.functionalitySettings.forbidNegativeMatcherFee ||
tx.buyMatcherFee >= 0 && tx.sellMatcherFee >= 0,
(),
InsufficientFee("Matcher fee can not be negative")
)
_ <- Either.cond(assets.values.forall(_.isDefined), (), GenericError("Assets should be issued before they can be traded"))
amountDecimals = if (tx.version < TxVersion.V3) 8 else tx.buyOrder.assetPair.amountAsset.fold(8)(ia => assets(ia).fold(8)(_.decimals))
priceDecimals = if (tx.version < TxVersion.V3) 8 else tx.buyOrder.assetPair.priceAsset.fold(8)(ia => assets(ia).fold(8)(_.decimals))
Expand Down
Loading

0 comments on commit 2f4f525

Please sign in to comment.