From 357703d6433aeeca0bb48cc91759cb4f145b6aef Mon Sep 17 00:00:00 2001 From: Dennis Won Date: Fri, 9 Aug 2019 12:05:16 -0700 Subject: [PATCH] revert comparing by nano. compare max limit on tx amount with one --- cmd/client/wallet/main.go | 2 +- internal/configs/sharding/fixedschedule.go | 8 ++++---- internal/configs/sharding/localnet.go | 10 +++++----- internal/configs/sharding/mainnet.go | 10 +++++----- internal/configs/sharding/shardingconfig.go | 10 ++++++---- internal/configs/sharding/testnet.go | 10 +++++----- node/worker/worker.go | 4 ++-- 7 files changed, 28 insertions(+), 26 deletions(-) diff --git a/cmd/client/wallet/main.go b/cmd/client/wallet/main.go index 0cae37f95..3c86ffd2f 100644 --- a/cmd/client/wallet/main.go +++ b/cmd/client/wallet/main.go @@ -896,7 +896,7 @@ func submitTransaction(tx *types.Transaction, walletNode *node.Node, shardID uin fmt.Printf("Error in SubmitTransaction: %v\n", err) return err } - fmt.Printf("Transaction Id for shard %d submitted: %s\n", int(shardID), tx.Hash().Hex()) + fmt.Printf("Transaction Id for shard %d: %s\n", int(shardID), tx.Hash().Hex()) // FIXME (leo): how to we know the tx was successful sent to the network // this is a hacky way to wait for sometime time.Sleep(3 * time.Second) diff --git a/internal/configs/sharding/fixedschedule.go b/internal/configs/sharding/fixedschedule.go index 74969e0ff..f308bed67 100644 --- a/internal/configs/sharding/fixedschedule.go +++ b/internal/configs/sharding/fixedschedule.go @@ -34,9 +34,9 @@ func (s fixedSchedule) IsLastBlock(blockNum uint64) bool { return blockNum%blocks == blocks-1 } -func (s fixedSchedule) MaxTxAmountNanoLimit() *big.Int { - amountBigInt := big.NewInt(mainnetMaxTxAmountNanoLimit) - amountBigInt = amountBigInt.Mul(amountBigInt, big.NewInt(denominations.Nano)) +func (s fixedSchedule) MaxTxAmountLimit() *big.Int { + amountBigInt := big.NewInt(mainnetMaxTxAmountLimit) + amountBigInt = amountBigInt.Mul(amountBigInt, big.NewInt(denominations.One)) return amountBigInt } @@ -50,7 +50,7 @@ func (s fixedSchedule) MaxTxsPerBlockLimit() int { func (s fixedSchedule) TxsThrottleConfig() *TxsThrottleConfig { return &TxsThrottleConfig{ - MaxTxAmountNanoLimit: s.MaxTxAmountNanoLimit(), + MaxTxAmountLimit: s.MaxTxAmountLimit(), MaxNumRecentTxsPerAccountLimit: s.MaxNumRecentTxsPerAccountLimit(), MaxTxsPerBlockLimit: s.MaxTxsPerBlockLimit(), } diff --git a/internal/configs/sharding/localnet.go b/internal/configs/sharding/localnet.go index 930fec25d..b3db864ce 100644 --- a/internal/configs/sharding/localnet.go +++ b/internal/configs/sharding/localnet.go @@ -20,7 +20,7 @@ const ( localnetEpochBlock1 = 20 twoOne = 5 - localnetMaxTxAmountNanoLimit = 1e2 // unit is in One + localnetMaxTxAmountLimit = 1e2 // unit is in One localnetMaxNumRecentTxsPerAccountLimit = 2 localnetMaxTxsPerBlockLimit = 8000 ) @@ -62,9 +62,9 @@ func (ls localnetSchedule) IsLastBlock(blockNum uint64) bool { } } -func (ls localnetSchedule) MaxTxAmountNanoLimit() *big.Int { - amountBigInt := big.NewInt(localnetMaxTxAmountNanoLimit) - amountBigInt = amountBigInt.Mul(amountBigInt, big.NewInt(denominations.Nano)) +func (ls localnetSchedule) MaxTxAmountLimit() *big.Int { + amountBigInt := big.NewInt(localnetMaxTxAmountLimit) + amountBigInt = amountBigInt.Mul(amountBigInt, big.NewInt(denominations.One)) return amountBigInt } @@ -78,7 +78,7 @@ func (ls localnetSchedule) MaxTxsPerBlockLimit() int { func (ls localnetSchedule) TxsThrottleConfig() *TxsThrottleConfig { return &TxsThrottleConfig{ - MaxTxAmountNanoLimit: ls.MaxTxAmountNanoLimit(), + MaxTxAmountLimit: ls.MaxTxAmountLimit(), MaxNumRecentTxsPerAccountLimit: ls.MaxNumRecentTxsPerAccountLimit(), MaxTxsPerBlockLimit: ls.MaxTxsPerBlockLimit(), } diff --git a/internal/configs/sharding/mainnet.go b/internal/configs/sharding/mainnet.go index a4ae04da9..ff9cbf0a3 100644 --- a/internal/configs/sharding/mainnet.go +++ b/internal/configs/sharding/mainnet.go @@ -16,7 +16,7 @@ const ( mainnetV0_3Epoch = 8 mainnetV0_4Epoch = 10 - mainnetMaxTxAmountNanoLimit = 1e3 // unit is in One + mainnetMaxTxAmountLimit = 1e3 // unit is in One mainnetMaxNumRecentTxsPerAccountLimit = 10 mainnetMaxTxsPerBlockLimit = 8000 ) @@ -71,9 +71,9 @@ func (ms mainnetSchedule) IsLastBlock(blockNum uint64) bool { } } -func (ms mainnetSchedule) MaxTxAmountNanoLimit() *big.Int { - amountBigInt := big.NewInt(mainnetMaxTxAmountNanoLimit) - amountBigInt = amountBigInt.Mul(amountBigInt, big.NewInt(denominations.Nano)) +func (ms mainnetSchedule) MaxTxAmountLimit() *big.Int { + amountBigInt := big.NewInt(mainnetMaxTxAmountLimit) + amountBigInt = amountBigInt.Mul(amountBigInt, big.NewInt(denominations.One)) return amountBigInt } @@ -87,7 +87,7 @@ func (ms mainnetSchedule) MaxTxsPerBlockLimit() int { func (ms mainnetSchedule) TxsThrottleConfig() *TxsThrottleConfig { return &TxsThrottleConfig{ - MaxTxAmountNanoLimit: ms.MaxTxAmountNanoLimit(), + MaxTxAmountLimit: ms.MaxTxAmountLimit(), MaxNumRecentTxsPerAccountLimit: ms.MaxNumRecentTxsPerAccountLimit(), MaxTxsPerBlockLimit: ms.MaxTxsPerBlockLimit(), } diff --git a/internal/configs/sharding/shardingconfig.go b/internal/configs/sharding/shardingconfig.go index c361d0aea..9edbb254b 100644 --- a/internal/configs/sharding/shardingconfig.go +++ b/internal/configs/sharding/shardingconfig.go @@ -23,7 +23,7 @@ type Schedule interface { IsLastBlock(blockNum uint64) bool // Max amount limit for a valid transaction - MaxTxAmountNanoLimit() *big.Int + MaxTxAmountLimit() *big.Int // Max number of transactions of a particular account per block level MaxNumRecentTxsPerAccountLimit() uint64 @@ -60,10 +60,12 @@ type Instance interface { ReshardingEpoch() []*big.Int } -// TxThrottleFlag indicates the throttling flag for a particular transaction +// TxThrottleFlag is the throttling flag for each transaction +// Refer below enum declaration for more context. type TxThrottleFlag int -// Enum for different TxThrottleFlag +// TxThrottleFlag is determined per transaction +// during the new block proposal and pending transactions throttling const ( TxSelect TxThrottleFlag = iota TxUnselect @@ -85,7 +87,7 @@ func (result TxThrottleFlag) String() string { // TxsThrottleConfig contains configuration for throttling pending transactions per node block type TxsThrottleConfig struct { // Max amount limit for a valid transaction - MaxTxAmountNanoLimit *big.Int + MaxTxAmountLimit *big.Int // Max number of transactions of a particular account for the past hour MaxNumRecentTxsPerAccountLimit uint64 diff --git a/internal/configs/sharding/testnet.go b/internal/configs/sharding/testnet.go index 787a3febe..1e478e68f 100644 --- a/internal/configs/sharding/testnet.go +++ b/internal/configs/sharding/testnet.go @@ -20,7 +20,7 @@ const ( testnetEpochBlock1 = 78 threeOne = 111 - testnetMaxTxAmountNanoLimit = 1e3 // unit is in One + testnetMaxTxAmountLimit = 1e3 // unit is in One testnetMaxNumRecentTxsPerAccountLimit = 10 testnetMaxTxsPerBlockLimit = 8000 ) @@ -63,9 +63,9 @@ func (ts testnetSchedule) IsLastBlock(blockNum uint64) bool { } } -func (ts testnetSchedule) MaxTxAmountNanoLimit() *big.Int { - amountBigInt := big.NewInt(testnetMaxTxAmountNanoLimit) - amountBigInt = amountBigInt.Mul(amountBigInt, big.NewInt(denominations.Nano)) +func (ts testnetSchedule) MaxTxAmountLimit() *big.Int { + amountBigInt := big.NewInt(testnetMaxTxAmountLimit) + amountBigInt = amountBigInt.Mul(amountBigInt, big.NewInt(denominations.One)) return amountBigInt } @@ -79,7 +79,7 @@ func (ts testnetSchedule) MaxTxsPerBlockLimit() int { func (ts testnetSchedule) TxsThrottleConfig() *TxsThrottleConfig { return &TxsThrottleConfig{ - MaxTxAmountNanoLimit: ts.MaxTxAmountNanoLimit(), + MaxTxAmountLimit: ts.MaxTxAmountLimit(), MaxNumRecentTxsPerAccountLimit: ts.MaxNumRecentTxsPerAccountLimit(), MaxTxsPerBlockLimit: ts.MaxTxsPerBlockLimit(), } diff --git a/node/worker/worker.go b/node/worker/worker.go index 1e08da49f..220961486 100644 --- a/node/worker/worker.go +++ b/node/worker/worker.go @@ -74,10 +74,10 @@ func (w *Worker) throttleTxs(selected types.Transactions, recentTxsStats types.R } // throttle a single sender sending too many transactions in one block - if txsThrottleConfig.MaxTxAmountNanoLimit.Cmp(tx.Value()) < 0 { + if tx.Value().Cmp(txsThrottleConfig.MaxTxAmountLimit) > 0 { utils.GetLogInstance().Info("Throttling tx with max amount limit", "tx Id", tx.Hash().Hex(), - "MaxTxAmountNanoLimit", txsThrottleConfig.MaxTxAmountNanoLimit.Uint64(), + "MaxTxAmountLimit", txsThrottleConfig.MaxTxAmountLimit.Uint64(), "Tx amount", tx.Value().Uint64()) return sender, shardingconfig.TxInvalid }