Skip to content

Commit

Permalink
Merge pull request #1529 from wavesplatform/node-1207-remove-fee-calc…
Browse files Browse the repository at this point in the history
…ulator

NODE-1207: FeeCalculator removed
  • Loading branch information
ismagin authored Oct 3, 2018
2 parents 1ed59a3 + 793f337 commit c6236b4
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 210 deletions.
4 changes: 2 additions & 2 deletions it/src/main/scala/com/wavesplatform/it/Node.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.wavesplatform.account.{PrivateKeyAccount, PublicKeyAccount}
import com.wavesplatform.it.util.GlobalTimer
import com.wavesplatform.settings.WavesSettings
import com.wavesplatform.state.EitherExt2
import com.wavesplatform.transaction.FeeCalculator
import com.wavesplatform.state.diffs.CommonValidation
import com.wavesplatform.utils.{Base58, LoggerFacade}
import org.asynchttpclient.Dsl.{config => clientConfig, _}
import org.asynchttpclient._
Expand Down Expand Up @@ -45,7 +45,7 @@ object Node {

def publicKeyStr = Base58.encode(n.publicKey.publicKey)

def fee(txTypeId: Byte): Long = FeeCalculator.FeeConstants(txTypeId)
def fee(txTypeId: Byte): Long = CommonValidation.FeeConstants(txTypeId)

def blockDelay: FiniteDuration = n.settings.blockchainSettings.genesisSettings.averageBlockDelay
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/scala/com/wavesplatform/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import com.wavesplatform.network.RxExtensionLoader.RxExtensionLoaderShutdownHook
import com.wavesplatform.network._
import com.wavesplatform.settings._
import com.wavesplatform.state.appender.{BlockAppender, CheckpointAppender, ExtensionAppender, MicroblockAppender}
import com.wavesplatform.transaction._
import com.wavesplatform.utils.{NTP, ScorexLogging, SystemInformationReporter, Time, forceStopApplication}
import com.wavesplatform.utx.{MatcherUtxPool, UtxPool, UtxPoolImpl}
import com.wavesplatform.wallet.Wallet
Expand Down Expand Up @@ -98,12 +97,11 @@ class Application(val actorSystem: ActorSystem, val settings: WavesSettings, con
if (wallet.privateKeyAccounts.isEmpty)
wallet.generateNewAccounts(1)

val feeCalculator = new FeeCalculator(blockchainUpdater)
val time: Time = NTP
val establishedConnections = new ConcurrentHashMap[Channel, PeerInfo]
val allChannels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE)
val innerUtxStorage =
new UtxPoolImpl(time, blockchainUpdater, feeCalculator, settings.blockchainSettings.functionalitySettings, settings.utxSettings)
new UtxPoolImpl(time, blockchainUpdater, settings.blockchainSettings.functionalitySettings, settings.utxSettings)

matcher = if (settings.matcherSettings.enable) {
val m = new Matcher(actorSystem,
Expand Down
49 changes: 31 additions & 18 deletions src/main/scala/com/wavesplatform/state/diffs/CommonValidation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ object CommonValidation {
val MaxTimePrevBlockOverTransactionDiff: FiniteDuration = 2.hours
val ScriptExtraFee = 400000L

val FeeConstants: Map[Byte, Long] = Map(
GenesisTransaction.typeId -> 0,
PaymentTransaction.typeId -> 1,
IssueTransaction.typeId -> 1000,
ReissueTransaction.typeId -> 1000,
BurnTransaction.typeId -> 1,
TransferTransaction.typeId -> 1,
MassTransferTransaction.typeId -> 1,
LeaseTransaction.typeId -> 1,
LeaseCancelTransaction.typeId -> 1,
ExchangeTransaction.typeId -> 3,
CreateAliasTransaction.typeId -> 1,
DataTransaction.typeId -> 1,
SetScriptTransaction.typeId -> 10,
SponsorFeeTransaction.typeId -> 1000
)

def disallowSendingGreaterThanBalance[T <: Transaction](blockchain: Blockchain,
settings: FunctionalitySettings,
blockTime: Long,
Expand Down Expand Up @@ -135,24 +152,20 @@ object CommonValidation {
case _ => Right(tx)
}

private def feeInUnits(blockchain: Blockchain, height: Int, tx: Transaction): Either[ValidationError, Long] = tx match {
case _: GenesisTransaction => Right(0)
case _: PaymentTransaction => Right(1)
case _: IssueTransaction => Right(1000)
case _: ReissueTransaction => Right(1000)
case _: BurnTransaction => Right(1)
case _: TransferTransaction => Right(1)
case tx: MassTransferTransaction => Right(1 + (tx.transfers.size + 1) / 2)
case _: LeaseTransaction => Right(1)
case _: LeaseCancelTransaction => Right(1)
case _: ExchangeTransaction => Right(3)
case _: CreateAliasTransaction => Right(1)
case tx: DataTransaction =>
val base = if (blockchain.isFeatureActivated(BlockchainFeatures.SmartAccounts, height)) tx.bodyBytes() else tx.bytes()
Right(1 + (base.length - 1) / 1024)
case _: SetScriptTransaction => Right(10)
case _: SponsorFeeTransaction => Right(1000)
case _ => Left(UnsupportedTransactionType)
private def feeInUnits(blockchain: Blockchain, height: Int, tx: Transaction): Either[ValidationError, Long] = {
FeeConstants
.get(tx.builder.typeId)
.map { baseFee =>
tx match {
case tx: MassTransferTransaction =>
baseFee + (tx.transfers.size + 1) / 2
case tx: DataTransaction =>
val base = if (blockchain.isFeatureActivated(BlockchainFeatures.SmartAccounts, height)) tx.bodyBytes() else tx.bytes()
baseFee + (base.length - 1) / 1024
case _ => baseFee
}
}
.toRight(UnsupportedTransactionType)
}

def getMinFee(blockchain: Blockchain, fs: FunctionalitySettings, height: Int, tx: Transaction): Either[ValidationError, (Option[AssetId], Long)] = {
Expand Down
66 changes: 0 additions & 66 deletions src/main/scala/com/wavesplatform/transaction/FeeCalculator.scala

This file was deleted.

3 changes: 1 addition & 2 deletions src/main/scala/com/wavesplatform/utx/UtxPoolImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import scala.collection.JavaConverters._
import scala.concurrent.duration.DurationLong
import scala.util.{Left, Right}

class UtxPoolImpl(time: Time, blockchain: Blockchain, feeCalculator: FeeCalculator, fs: FunctionalitySettings, utxSettings: UtxSettings)
class UtxPoolImpl(time: Time, blockchain: Blockchain, fs: FunctionalitySettings, utxSettings: UtxSettings)
extends ScorexLogging
with Instrumented
with AutoCloseable
Expand Down Expand Up @@ -189,7 +189,6 @@ class UtxPoolImpl(time: Time, blockchain: Blockchain, feeCalculator: FeeCalculat
_ <- checkScripted(b, tx)
_ <- checkAlias(b, tx)
_ <- canReissue(b, tx)
_ <- feeCalculator.enoughFee(tx, blockchain, fs)
diff <- TransactionDiffer(fs, blockchain.lastBlockTimestamp, time.correctedTime(), blockchain.height)(b, tx)
} yield {
pessimisticPortfolios.add(tx.id(), diff)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import com.wavesplatform.{NoShrink, TransactionGen, crypto}
import org.scalacheck.Gen
import org.scalatest.prop.PropertyChecks
import org.scalatest.{Inside, Matchers, PropSpec}
import com.wavesplatform.OrderOps._

class ExchangeTransactionDiffTest extends PropSpec with PropertyChecks with Matchers with TransactionGen with Inside with NoShrink {

Expand Down Expand Up @@ -246,8 +245,7 @@ class ExchangeTransactionDiffTest extends PropSpec with PropertyChecks with Matc

forAll(allValidP) {
case (genesis, transfers, issueAndScripts, etx) =>
val smallFee = CommonValidation.ScriptExtraFee + FeeCalculator.FeeConstants(etx.builder.typeId) - 1

val smallFee = CommonValidation.ScriptExtraFee + CommonValidation.FeeConstants(ExchangeTransaction.typeId)
val exchangeWithSmallFee = ExchangeTransactionV2
.create(
MATCHER,
Expand Down

This file was deleted.

Loading

0 comments on commit c6236b4

Please sign in to comment.