From 3b16fb98d50839918dddff8baa9e3459109f10b7 Mon Sep 17 00:00:00 2001 From: DinhLN Date: Fri, 4 Jan 2019 10:56:01 +0700 Subject: [PATCH] Fixed minimum gas used when deploy SMC. --- core/genesis.go | 2 +- core/tx_pool.go | 9 ++++++++- eth/downloader/api.go | 4 ++-- eth/handler_test.go | 8 ++++---- swarm/api/http/error.go | 2 +- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/core/genesis.go b/core/genesis.go index 9d8eb27953..c87460b908 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -366,7 +366,7 @@ func DeveloperGenesisBlock(period uint64, faucet common.Address) *Genesis { common.BytesToAddress([]byte{6}): {Balance: big.NewInt(1)}, // ECAdd common.BytesToAddress([]byte{7}): {Balance: big.NewInt(1)}, // ECScalarMul common.BytesToAddress([]byte{8}): {Balance: big.NewInt(1)}, // ECPairing - faucet: {Balance: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(9))}, + faucet: {Balance: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(9))}, }, } } diff --git a/core/tx_pool.go b/core/tx_pool.go index 63dbf3ac9e..e80c74c797 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -82,6 +82,8 @@ var ( ErrZeroGasPrice = errors.New("zero gas price") ErrDuplicateSpecialTransaction = errors.New("duplicate a special transaction") + + ErrMinDeploySMC = errors.New("smart contract creation cost is under allowance") ) var ( @@ -587,7 +589,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error { } // Drop non-local transactions under our own minimal accepted gas price local = local || pool.locals.contains(from) // account may be local even if the transaction arrived from the network - if !local && tx.To() != nil && pool.gasPrice.Cmp(tx.GasPrice()) > 0 { + if !local && pool.gasPrice.Cmp(tx.GasPrice()) > 0 { if !tx.IsSpecialTransaction() || (pool.IsMasterNode != nil && !pool.IsMasterNode(from)) { return ErrUnderpriced } @@ -621,6 +623,11 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error { } } + minGasDeploySMC := new(big.Int).Mul(new(big.Int).SetUint64(10), new(big.Int).SetUint64(params.Ether)) + if tx.To() == nil && (tx.Cost().Cmp(minGasDeploySMC) < 0 || tx.GasPrice().Cmp(new(big.Int).SetUint64(10000*params.Shannon)) < 0) { + return ErrMinDeploySMC + } + return nil } diff --git a/eth/downloader/api.go b/eth/downloader/api.go index d496fa6a4d..581e9aed24 100644 --- a/eth/downloader/api.go +++ b/eth/downloader/api.go @@ -40,8 +40,8 @@ type PublicDownloaderAPI struct { // installSyncSubscription channel. func NewPublicDownloaderAPI(d *Downloader, m *event.TypeMux) *PublicDownloaderAPI { api := &PublicDownloaderAPI{ - d: d, - mux: m, + d: d, + mux: m, installSyncSubscription: make(chan chan interface{}), uninstallSyncSubscription: make(chan *uninstallSyncSubscriptionRequest), } diff --git a/eth/handler_test.go b/eth/handler_test.go index e336dfa285..923df129a0 100644 --- a/eth/handler_test.go +++ b/eth/handler_test.go @@ -242,10 +242,10 @@ func testGetBlockBodies(t *testing.T, protocol int) { available []bool // Availability of explicitly requested blocks expected int // Total number of existing blocks to expect }{ - {1, nil, nil, 1}, // A single random block should be retrievable - {10, nil, nil, 10}, // Multiple random blocks should be retrievable - {limit, nil, nil, limit}, // The maximum possible blocks should be retrievable - {limit + 1, nil, nil, limit}, // No more than the possible block count should be returned + {1, nil, nil, 1}, // A single random block should be retrievable + {10, nil, nil, 10}, // Multiple random blocks should be retrievable + {limit, nil, nil, limit}, // The maximum possible blocks should be retrievable + {limit + 1, nil, nil, limit}, // No more than the possible block count should be returned {0, []common.Hash{pm.blockchain.Genesis().Hash()}, []bool{true}, 1}, // The genesis block should be retrievable {0, []common.Hash{pm.blockchain.CurrentBlock().Hash()}, []bool{true}, 1}, // The chains head block should be retrievable {0, []common.Hash{{}}, []bool{false}, 0}, // A non existent block should not be returned diff --git a/swarm/api/http/error.go b/swarm/api/http/error.go index 9a65412cf9..2f77f2784a 100644 --- a/swarm/api/http/error.go +++ b/swarm/api/http/error.go @@ -71,7 +71,7 @@ func initErrHandling() { multipleChoicesPage := GetMultipleChoicesErrorPage() //map the codes to the available pages tnames := map[int]string{ - 0: genErrPage, //default + 0: genErrPage, //default http.StatusBadRequest: genErrPage, http.StatusNotFound: notFoundPage, http.StatusMultipleChoices: multipleChoicesPage,