aboutsummaryrefslogtreecommitdiffstats
path: root/dex/app.go
diff options
context:
space:
mode:
authorWei-Ning Huang <w@byzantine-lab.io>2019-07-25 20:41:46 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-09-17 16:57:31 +0800
commit174f6bfcdf4e2c7fea3a071653908b477ad9a3b3 (patch)
tree7990bd656bd9cc7ef3014534ad2fee5163da3790 /dex/app.go
parenta9a85fa746c727063015d6e70881426ce8b3a3fb (diff)
downloadgo-tangerine-174f6bfcdf4e2c7fea3a071653908b477ad9a3b3.tar
go-tangerine-174f6bfcdf4e2c7fea3a071653908b477ad9a3b3.tar.gz
go-tangerine-174f6bfcdf4e2c7fea3a071653908b477ad9a3b3.tar.bz2
go-tangerine-174f6bfcdf4e2c7fea3a071653908b477ad9a3b3.tar.lz
go-tangerine-174f6bfcdf4e2c7fea3a071653908b477ad9a3b3.tar.xz
go-tangerine-174f6bfcdf4e2c7fea3a071653908b477ad9a3b3.tar.zst
go-tangerine-174f6bfcdf4e2c7fea3a071653908b477ad9a3b3.zip
core: add GovUtil to unify governance state related access
Add GovUtil so we could use the same logic in everywhere that requires access to governance state, such as configuration and CRS.
Diffstat (limited to 'dex/app.go')
-rw-r--r--dex/app.go41
1 files changed, 32 insertions, 9 deletions
diff --git a/dex/app.go b/dex/app.go
index fb8ffa46d..10f977c2f 100644
--- a/dex/app.go
+++ b/dex/app.go
@@ -102,9 +102,14 @@ func (d *DexconApp) validateNonce(txs types.Transactions) (map[common.Address]ui
// 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)
+ config, err := d.gov.RawConfiguration(round)
+ if err != nil {
+ log.Error("Failed to get configuration", "err", err)
+ return false
+ }
+
for _, tx := range txs {
- if minGasPrice.Cmp(tx.GasPrice()) > 0 {
+ if config.MinGasPrice.Cmp(tx.GasPrice()) > 0 {
return false
}
}
@@ -180,8 +185,12 @@ func (d *DexconApp) preparePayload(ctx context.Context, position coreTypes.Posit
return
}
- blockGasLimit := new(big.Int).SetUint64(d.gov.DexconConfiguration(position.Round).BlockGasLimit)
- minGasPrice := d.gov.DexconConfiguration(position.Round).MinGasPrice
+ config, err := d.gov.RawConfiguration(position.Round)
+ if err != nil {
+ return
+ }
+
+ blockGasLimit := new(big.Int).SetUint64(config.BlockGasLimit)
blockGasUsed := new(big.Int)
allTxs := make([]*types.Transaction, 0, 10000)
@@ -217,8 +226,8 @@ addressMap:
// Warning: the pending tx will also affect by syncing, so startIndex maybe negative
for i := startIndex; i >= 0 && i < len(txs); i++ {
tx := txs[i]
- if minGasPrice.Cmp(tx.GasPrice()) > 0 {
- log.Error("Invalid gas price minGas(%v) > get(%v)", minGasPrice, tx.GasPrice())
+ if config.MinGasPrice.Cmp(tx.GasPrice()) > 0 {
+ log.Error("Invalid gas price minGas(%v) > get(%v)", config.MinGasPrice, tx.GasPrice())
break
}
@@ -372,8 +381,14 @@ func (d *DexconApp) VerifyBlock(block *coreTypes.Block) coreTypes.BlockVerifySta
}
}
+ config, err := d.gov.RawConfiguration(block.Position.Round)
+ if err != nil {
+ log.Error("Failed to get raw configuration", "err", err)
+ return coreTypes.VerifyRetryLater
+ }
+
// Validate if balance is enough for TXs in this block.
- blockGasLimit := new(big.Int).SetUint64(d.gov.DexconConfiguration(block.Position.Round).BlockGasLimit)
+ blockGasLimit := new(big.Int).SetUint64(config.BlockGasLimit)
blockGasUsed := new(big.Int)
for _, tx := range transactions {
@@ -436,7 +451,10 @@ func (d *DexconApp) BlockDelivered(
var owner common.Address
if !block.IsEmpty() {
- gs := d.gov.GetStateForConfigAtRound(block.Position.Round)
+ gs, err := d.gov.GetConfigState(block.Position.Round)
+ if err != nil {
+ panic(err)
+ }
node, err := gs.GetNodeByID(block.ProposerID)
if err != nil {
panic(err)
@@ -444,11 +462,16 @@ func (d *DexconApp) BlockDelivered(
owner = node.Owner
}
+ config, err := d.gov.RawConfiguration(block.Position.Round)
+ if err != nil {
+ panic(err)
+ }
+
newBlock := types.NewBlock(&types.Header{
Number: new(big.Int).SetUint64(block.Position.Height),
Time: uint64(block.Timestamp.UnixNano() / 1000000),
Coinbase: owner,
- GasLimit: d.gov.DexconConfiguration(block.Position.Round).BlockGasLimit,
+ GasLimit: config.BlockGasLimit,
Difficulty: big.NewInt(1),
Round: block.Position.Round,
DexconMeta: dexconMeta,