Skip to content

Commit

Permalink
fix get GasPrice bug (ontio#1361)
Browse files Browse the repository at this point in the history
* fix get GasPrice bug

* fix get GasPrice bug
  • Loading branch information
hero5512 authored Aug 9, 2021
1 parent 9be6fac commit c79fd38
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions http/base/actor/txnpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,7 @@ func GetTxnCount() []uint32 {
func GetTxnHashList() []common.Uint256 {
return txPoolService.GetTxList()
}

func GetGasPrice() uint64 {
return txPoolService.GetGasPrice()
}
3 changes: 3 additions & 0 deletions http/base/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,9 @@ func GetGasPrice() (gasPrice uint64, height uint32, err error) {
break
}
}
if gasPrice == 0 {
gasPrice = bactor.GetGasPrice()
}
return
}

Expand Down
1 change: 1 addition & 0 deletions http/ethrpc/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type TxPoolService interface {
Nonce(addr oComm.Address) uint64
PendingEIPTransactions() []*types.Transaction
PendingTransactionsByHash(target common.Hash) *types.Transaction
GetGasPrice() uint64
}

type EthereumAPI struct {
Expand Down
1 change: 1 addition & 0 deletions txnpool/common/txnpool_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ type TxPoolService interface {
GetTransactionStatus(hash common.Uint256) *TxStatus
GetTxAmount() []uint32
GetTxList() []common.Uint256
GetGasPrice() uint64
AppendTransaction(sender SenderType, txn *types.Transaction) *TxResult
AppendTransactionAsync(sender SenderType, txn *types.Transaction)
}
Expand Down
6 changes: 5 additions & 1 deletion txnpool/proc/txnpool_actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (ta *TxPoolService) handleTransaction(sender tc.SenderType, txn *tx.Transac
}

gasLimitConfig := config.DefConfig.Common.MinGasLimit
gasPriceConfig := ta.server.getGasPrice()
gasPriceConfig := ta.server.GetGasPrice()
if txn.GasLimit < gasLimitConfig || txn.GasPrice < gasPriceConfig {
log.Debugf("handleTransaction: invalid gasLimit %v, gasPrice %v", txn.GasLimit, txn.GasPrice)
replyTxResult(txResultCh, txn.Hash(), errors.ErrUnknown,
Expand Down Expand Up @@ -214,6 +214,10 @@ func (ta *TxPoolService) GetTxList() []common.Uint256 {
return ta.server.getTxHashList()
}

func (ta *TxPoolService) GetGasPrice() uint64 {
return ta.server.GetGasPrice()
}

func (ta *TxPoolService) AppendTransaction(sender tc.SenderType, txn *tx.Transaction) *tc.TxResult {
ch := make(chan *tc.TxResult, 1)
ta.handleTransaction(sender, txn, ch)
Expand Down
4 changes: 2 additions & 2 deletions txnpool/proc/txnpool_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ func (s *TXPoolServer) setHeight(height uint32) {
atomic.StoreUint32(&s.height, height)
}

// getGasPrice returns the current gas price enforced by the transaction pool
func (s *TXPoolServer) getGasPrice() uint64 {
// GetGasPrice returns the current gas price enforced by the transaction pool
func (s *TXPoolServer) GetGasPrice() uint64 {
s.mu.RLock()
defer s.mu.RUnlock()
return s.gasPrice
Expand Down

0 comments on commit c79fd38

Please sign in to comment.