aboutsummaryrefslogtreecommitdiffstats
path: root/dex/app.go
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-02-25 18:27:34 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:22 +0800
commit8e92e73dc650ac03c228fbb26a3afe88a5bc237c (patch)
tree0d0c74884bddd2c29e38dfb903ccfd1459c8f279 /dex/app.go
parentf1a3f3a8f39d5490f4320591def9c2866d866bc4 (diff)
downloadgo-tangerine-8e92e73dc650ac03c228fbb26a3afe88a5bc237c.tar
go-tangerine-8e92e73dc650ac03c228fbb26a3afe88a5bc237c.tar.gz
go-tangerine-8e92e73dc650ac03c228fbb26a3afe88a5bc237c.tar.bz2
go-tangerine-8e92e73dc650ac03c228fbb26a3afe88a5bc237c.tar.lz
go-tangerine-8e92e73dc650ac03c228fbb26a3afe88a5bc237c.tar.xz
go-tangerine-8e92e73dc650ac03c228fbb26a3afe88a5bc237c.tar.zst
go-tangerine-8e92e73dc650ac03c228fbb26a3afe88a5bc237c.zip
core: Fixed gas price (#205)
* core/vm: update abi * core/vm: add MinGasPrice to gov * params: Add MinGasPrice to Config * dex: SuggestPrice from Governance * test: add minGasPrice to genesis.json * core: check underpriced tx * dex: verify with gas price
Diffstat (limited to 'dex/app.go')
-rw-r--r--dex/app.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/dex/app.go b/dex/app.go
index d2bd02f0c..ab4e80058 100644
--- a/dex/app.go
+++ b/dex/app.go
@@ -124,6 +124,18 @@ func (d *DexconApp) validateNonce(txs types.Transactions) (map[common.Address]ui
return addressFirstNonce, nil
}
+// validateGasPrice checks if no gas price is lower than minGasPrice defined in
+// governance contract.
+func (d *DexconApp) validateGasPrice(txs types.Transactions, round uint64) bool {
+ minGasPrice := d.gov.MinGasPrice(round)
+ for _, tx := range txs {
+ if minGasPrice.Cmp(tx.GasPrice()) > 0 {
+ return false
+ }
+ }
+ return true
+}
+
// PreparePayload is called when consensus core is preparing payload for block.
func (d *DexconApp) PreparePayload(position coreTypes.Position) (payload []byte, err error) {
// softLimit limits the runtime of inner call to preparePayload.
@@ -410,6 +422,10 @@ func (d *DexconApp) VerifyBlock(block *coreTypes.Block) coreTypes.BlockVerifySta
log.Error("Validate nonce failed", "error", err)
return coreTypes.VerifyInvalidBlock
}
+ if !d.validateGasPrice(transactions, block.Position.Round) {
+ log.Error("Validate gas price failed")
+ return coreTypes.VerifyInvalidBlock
+ }
// Check if nonce is strictly increasing for every address.
chainID := big.NewInt(int64(block.Position.ChainID))