revert comparing by nano. compare max limit on tx amount with one

pull/1319/head
Dennis Won 5 years ago
parent 9da6f5624c
commit e37f3ed966
  1. 2
      cmd/client/wallet/main.go
  2. 8
      internal/configs/sharding/fixedschedule.go
  3. 10
      internal/configs/sharding/localnet.go
  4. 10
      internal/configs/sharding/mainnet.go
  5. 10
      internal/configs/sharding/shardingconfig.go
  6. 10
      internal/configs/sharding/testnet.go
  7. 4
      node/worker/worker.go

@ -896,7 +896,7 @@ func submitTransaction(tx *types.Transaction, walletNode *node.Node, shardID uin
fmt.Printf("Error in SubmitTransaction: %v\n", err) fmt.Printf("Error in SubmitTransaction: %v\n", err)
return 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 // FIXME (leo): how to we know the tx was successful sent to the network
// this is a hacky way to wait for sometime // this is a hacky way to wait for sometime
time.Sleep(3 * time.Second) time.Sleep(3 * time.Second)

@ -34,9 +34,9 @@ func (s fixedSchedule) IsLastBlock(blockNum uint64) bool {
return blockNum%blocks == blocks-1 return blockNum%blocks == blocks-1
} }
func (s fixedSchedule) MaxTxAmountNanoLimit() *big.Int { func (s fixedSchedule) MaxTxAmountLimit() *big.Int {
amountBigInt := big.NewInt(mainnetMaxTxAmountNanoLimit) amountBigInt := big.NewInt(mainnetMaxTxAmountLimit)
amountBigInt = amountBigInt.Mul(amountBigInt, big.NewInt(denominations.Nano)) amountBigInt = amountBigInt.Mul(amountBigInt, big.NewInt(denominations.One))
return amountBigInt return amountBigInt
} }
@ -50,7 +50,7 @@ func (s fixedSchedule) MaxTxsPerBlockLimit() int {
func (s fixedSchedule) TxsThrottleConfig() *TxsThrottleConfig { func (s fixedSchedule) TxsThrottleConfig() *TxsThrottleConfig {
return &TxsThrottleConfig{ return &TxsThrottleConfig{
MaxTxAmountNanoLimit: s.MaxTxAmountNanoLimit(), MaxTxAmountLimit: s.MaxTxAmountLimit(),
MaxNumRecentTxsPerAccountLimit: s.MaxNumRecentTxsPerAccountLimit(), MaxNumRecentTxsPerAccountLimit: s.MaxNumRecentTxsPerAccountLimit(),
MaxTxsPerBlockLimit: s.MaxTxsPerBlockLimit(), MaxTxsPerBlockLimit: s.MaxTxsPerBlockLimit(),
} }

@ -20,7 +20,7 @@ const (
localnetEpochBlock1 = 20 localnetEpochBlock1 = 20
twoOne = 5 twoOne = 5
localnetMaxTxAmountNanoLimit = 1e2 // unit is in One localnetMaxTxAmountLimit = 1e2 // unit is in One
localnetMaxNumRecentTxsPerAccountLimit = 2 localnetMaxNumRecentTxsPerAccountLimit = 2
localnetMaxTxsPerBlockLimit = 8000 localnetMaxTxsPerBlockLimit = 8000
) )
@ -62,9 +62,9 @@ func (ls localnetSchedule) IsLastBlock(blockNum uint64) bool {
} }
} }
func (ls localnetSchedule) MaxTxAmountNanoLimit() *big.Int { func (ls localnetSchedule) MaxTxAmountLimit() *big.Int {
amountBigInt := big.NewInt(localnetMaxTxAmountNanoLimit) amountBigInt := big.NewInt(localnetMaxTxAmountLimit)
amountBigInt = amountBigInt.Mul(amountBigInt, big.NewInt(denominations.Nano)) amountBigInt = amountBigInt.Mul(amountBigInt, big.NewInt(denominations.One))
return amountBigInt return amountBigInt
} }
@ -78,7 +78,7 @@ func (ls localnetSchedule) MaxTxsPerBlockLimit() int {
func (ls localnetSchedule) TxsThrottleConfig() *TxsThrottleConfig { func (ls localnetSchedule) TxsThrottleConfig() *TxsThrottleConfig {
return &TxsThrottleConfig{ return &TxsThrottleConfig{
MaxTxAmountNanoLimit: ls.MaxTxAmountNanoLimit(), MaxTxAmountLimit: ls.MaxTxAmountLimit(),
MaxNumRecentTxsPerAccountLimit: ls.MaxNumRecentTxsPerAccountLimit(), MaxNumRecentTxsPerAccountLimit: ls.MaxNumRecentTxsPerAccountLimit(),
MaxTxsPerBlockLimit: ls.MaxTxsPerBlockLimit(), MaxTxsPerBlockLimit: ls.MaxTxsPerBlockLimit(),
} }

@ -13,7 +13,7 @@ const (
mainnetV1Epoch = 1 mainnetV1Epoch = 1
mainnetV2Epoch = 5 mainnetV2Epoch = 5
mainnetMaxTxAmountNanoLimit = 1e3 // unit is in One mainnetMaxTxAmountLimit = 1e3 // unit is in One
mainnetMaxNumRecentTxsPerAccountLimit = 10 mainnetMaxNumRecentTxsPerAccountLimit = 10
mainnetMaxTxsPerBlockLimit = 8000 mainnetMaxTxsPerBlockLimit = 8000
) )
@ -62,9 +62,9 @@ func (ms mainnetSchedule) IsLastBlock(blockNum uint64) bool {
} }
} }
func (ms mainnetSchedule) MaxTxAmountNanoLimit() *big.Int { func (ms mainnetSchedule) MaxTxAmountLimit() *big.Int {
amountBigInt := big.NewInt(mainnetMaxTxAmountNanoLimit) amountBigInt := big.NewInt(mainnetMaxTxAmountLimit)
amountBigInt = amountBigInt.Mul(amountBigInt, big.NewInt(denominations.Nano)) amountBigInt = amountBigInt.Mul(amountBigInt, big.NewInt(denominations.One))
return amountBigInt return amountBigInt
} }
@ -78,7 +78,7 @@ func (ms mainnetSchedule) MaxTxsPerBlockLimit() int {
func (ms mainnetSchedule) TxsThrottleConfig() *TxsThrottleConfig { func (ms mainnetSchedule) TxsThrottleConfig() *TxsThrottleConfig {
return &TxsThrottleConfig{ return &TxsThrottleConfig{
MaxTxAmountNanoLimit: ms.MaxTxAmountNanoLimit(), MaxTxAmountLimit: ms.MaxTxAmountLimit(),
MaxNumRecentTxsPerAccountLimit: ms.MaxNumRecentTxsPerAccountLimit(), MaxNumRecentTxsPerAccountLimit: ms.MaxNumRecentTxsPerAccountLimit(),
MaxTxsPerBlockLimit: ms.MaxTxsPerBlockLimit(), MaxTxsPerBlockLimit: ms.MaxTxsPerBlockLimit(),
} }

@ -23,7 +23,7 @@ type Schedule interface {
IsLastBlock(blockNum uint64) bool IsLastBlock(blockNum uint64) bool
// Max amount limit for a valid transaction // Max amount limit for a valid transaction
MaxTxAmountNanoLimit() *big.Int MaxTxAmountLimit() *big.Int
// Max number of transactions of a particular account per block level // Max number of transactions of a particular account per block level
MaxNumRecentTxsPerAccountLimit() uint64 MaxNumRecentTxsPerAccountLimit() uint64
@ -60,10 +60,12 @@ type Instance interface {
ReshardingEpoch() []*big.Int 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 type TxThrottleFlag int
// Enum for different TxThrottleFlag // TxThrottleFlag is determined per transaction
// during the new block proposal and pending transactions throttling
const ( const (
TxSelect TxThrottleFlag = iota TxSelect TxThrottleFlag = iota
TxUnselect TxUnselect
@ -85,7 +87,7 @@ func (result TxThrottleFlag) String() string {
// TxsThrottleConfig contains configuration for throttling pending transactions per node block // TxsThrottleConfig contains configuration for throttling pending transactions per node block
type TxsThrottleConfig struct { type TxsThrottleConfig struct {
// Max amount limit for a valid transaction // 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 // Max number of transactions of a particular account for the past hour
MaxNumRecentTxsPerAccountLimit uint64 MaxNumRecentTxsPerAccountLimit uint64

@ -20,7 +20,7 @@ const (
testnetEpochBlock1 = 78 testnetEpochBlock1 = 78
threeOne = 111 threeOne = 111
testnetMaxTxAmountNanoLimit = 1e3 // unit is in One testnetMaxTxAmountLimit = 1e3 // unit is in One
testnetMaxNumRecentTxsPerAccountLimit = 10 testnetMaxNumRecentTxsPerAccountLimit = 10
testnetMaxTxsPerBlockLimit = 8000 testnetMaxTxsPerBlockLimit = 8000
) )
@ -63,9 +63,9 @@ func (ts testnetSchedule) IsLastBlock(blockNum uint64) bool {
} }
} }
func (ts testnetSchedule) MaxTxAmountNanoLimit() *big.Int { func (ts testnetSchedule) MaxTxAmountLimit() *big.Int {
amountBigInt := big.NewInt(testnetMaxTxAmountNanoLimit) amountBigInt := big.NewInt(testnetMaxTxAmountLimit)
amountBigInt = amountBigInt.Mul(amountBigInt, big.NewInt(denominations.Nano)) amountBigInt = amountBigInt.Mul(amountBigInt, big.NewInt(denominations.One))
return amountBigInt return amountBigInt
} }
@ -79,7 +79,7 @@ func (ts testnetSchedule) MaxTxsPerBlockLimit() int {
func (ts testnetSchedule) TxsThrottleConfig() *TxsThrottleConfig { func (ts testnetSchedule) TxsThrottleConfig() *TxsThrottleConfig {
return &TxsThrottleConfig{ return &TxsThrottleConfig{
MaxTxAmountNanoLimit: ts.MaxTxAmountNanoLimit(), MaxTxAmountLimit: ts.MaxTxAmountLimit(),
MaxNumRecentTxsPerAccountLimit: ts.MaxNumRecentTxsPerAccountLimit(), MaxNumRecentTxsPerAccountLimit: ts.MaxNumRecentTxsPerAccountLimit(),
MaxTxsPerBlockLimit: ts.MaxTxsPerBlockLimit(), MaxTxsPerBlockLimit: ts.MaxTxsPerBlockLimit(),
} }

@ -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 // 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", utils.GetLogInstance().Info("Throttling tx with max amount limit",
"tx Id", tx.Hash().Hex(), "tx Id", tx.Hash().Hex(),
"MaxTxAmountNanoLimit", txsThrottleConfig.MaxTxAmountNanoLimit.Uint64(), "MaxTxAmountLimit", txsThrottleConfig.MaxTxAmountLimit.Uint64(),
"Tx amount", tx.Value().Uint64()) "Tx amount", tx.Value().Uint64())
return sender, shardingconfig.TxInvalid return sender, shardingconfig.TxInvalid
} }

Loading…
Cancel
Save