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)
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)

@ -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(),
}

@ -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(),
}

@ -13,7 +13,7 @@ const (
mainnetV1Epoch = 1
mainnetV2Epoch = 5
mainnetMaxTxAmountNanoLimit = 1e3 // unit is in One
mainnetMaxTxAmountLimit = 1e3 // unit is in One
mainnetMaxNumRecentTxsPerAccountLimit = 10
mainnetMaxTxsPerBlockLimit = 8000
)
@ -62,9 +62,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
}
@ -78,7 +78,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(),
}

@ -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

@ -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(),
}

@ -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
}

Loading…
Cancel
Save