diff options
author | Wei-Ning Huang <w@dexon.org> | 2018-11-26 10:00:31 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2018-12-19 20:54:27 +0800 |
commit | ce9dd85433e342b9ee13848414bc694921be1100 (patch) | |
tree | 892af82873805fb2e98eb7ef7e56b6130ea0438a | |
parent | 8b0b015937c02207df440eee6e4c96eec846fae6 (diff) | |
download | dexon-ce9dd85433e342b9ee13848414bc694921be1100.tar.gz dexon-ce9dd85433e342b9ee13848414bc694921be1100.tar.zst dexon-ce9dd85433e342b9ee13848414bc694921be1100.zip |
core: various changes on tps tuning (#46)
-rw-r--r-- | cmd/monkey/monkey.go | 5 | ||||
-rw-r--r-- | core/blockchain.go | 2 | ||||
-rw-r--r-- | core/genesis.go | 4 | ||||
-rw-r--r-- | core/tx_pool.go | 2 | ||||
-rw-r--r-- | core/types/transaction_signing.go | 15 | ||||
-rw-r--r-- | dex/app.go | 9 | ||||
-rw-r--r-- | dex/handler.go | 2 | ||||
-rw-r--r-- | internal/ethapi/api.go | 1 | ||||
-rw-r--r-- | params/config.go | 4 | ||||
-rw-r--r-- | test/genesis.json | 4 |
10 files changed, 23 insertions, 25 deletions
diff --git a/cmd/monkey/monkey.go b/cmd/monkey/monkey.go index f55d195a6..b312ea473 100644 --- a/cmd/monkey/monkey.go +++ b/cmd/monkey/monkey.go @@ -128,7 +128,6 @@ func (m *Monkey) prepareTx(ctx *transferContext) *types.Transaction { func (m *Monkey) transfer(ctx *transferContext) { tx := m.prepareTx(ctx) - fmt.Println("Sending TX", "fullhash", tx.Hash().String()) err := m.client.SendTransaction(context.Background(), tx) if err != nil { panic(err) @@ -139,7 +138,6 @@ func (m *Monkey) batchTransfer(ctxs []*transferContext) { txs := make([]*types.Transaction, len(ctxs)) for i, ctx := range ctxs { txs[i] = m.prepareTx(ctx) - fmt.Println("Sending TX", "fullhash", txs[i].Hash().String()) } err := m.client.SendTransactions(context.Background(), txs) @@ -236,7 +234,6 @@ func (m *Monkey) Crazy() { fmt.Println("Performing random transfers ...") nonce := uint64(0) for { - fmt.Println("nonce", nonce) ctxs := make([]*transferContext, len(m.keys)) for i, key := range m.keys { to := crypto.PubkeyToAddress(m.keys[rand.Int()%len(m.keys)].PublicKey) @@ -256,6 +253,8 @@ func (m *Monkey) Crazy() { if *batch { m.batchTransfer(ctxs) } + fmt.Printf("Sent %d transactions, nonce = %d\n", len(m.keys), nonce) + nonce += 1 time.Sleep(time.Duration(*sleep) * time.Millisecond) } diff --git a/core/blockchain.go b/core/blockchain.go index aeec35cf0..2355e9490 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1828,6 +1828,8 @@ func (bc *BlockChain) processPendingBlock( bc.addPendingBlock(newPendingBlock, receipts) events = append(events, BlockConfirmedEvent{newPendingBlock}) + log.Debug("Inserted pending block", "height", newPendingBlock.Number(), "hash", newPendingBlock.Hash()) + // Start insert available pending blocks into db for pendingHeight := bc.CurrentBlock().NumberU64() + 1; pendingHeight <= witness.Height; pendingHeight++ { pendingIns, exist := bc.pendingBlocks[pendingHeight] diff --git a/core/genesis.go b/core/genesis.go index c0231d922..57b7c619b 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -386,7 +386,7 @@ func DefaultGenesisBlock() *Genesis { Timestamp: 1540024964, Nonce: 0x42, ExtraData: hexutil.MustDecode("0x5765692d4e696e6720536f6e696320426f6a696520323031382d31302d32302e"), - GasLimit: 80000000, + GasLimit: 40000000, Difficulty: big.NewInt(1), Alloc: decodePrealloc(mainnetAllocData), } @@ -398,7 +398,7 @@ func DefaultTestnetGenesisBlock() *Genesis { Config: params.TestnetChainConfig, Nonce: 0x42, ExtraData: hexutil.MustDecode("0x3535353535353535353535353535353535353535353535353535353535353535"), - GasLimit: 80000000, + GasLimit: 40000000, Difficulty: big.NewInt(1), Alloc: decodePrealloc(testnetAllocData), } diff --git a/core/tx_pool.go b/core/tx_pool.go index 001aee6f9..2e8211208 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -152,7 +152,7 @@ var DefaultTxPoolConfig = TxPoolConfig{ PriceLimit: 1, PriceBump: 10, - AccountSlots: 192, + AccountSlots: 512, GlobalSlots: 40960, AccountQueue: 1024, GlobalQueue: 20240, diff --git a/core/types/transaction_signing.go b/core/types/transaction_signing.go index 47c7a2f91..99e0c7896 100644 --- a/core/types/transaction_signing.go +++ b/core/types/transaction_signing.go @@ -173,9 +173,13 @@ func Sender(signer Signer, tx *Transaction) (common.Address, error) { } } - addr, err := signer.Sender(tx) - if err != nil { - return common.Address{}, err + addr, ok := GlobalSigCache.Get(tx.Hash()) + if !ok { + var err error + addr, err = signer.Sender(tx) + if err != nil { + return common.Address{}, err + } } tx.from.Store(sigCache{signer: signer, from: addr}) return addr, nil @@ -218,11 +222,6 @@ func (s EIP155Signer) Equal(s2 Signer) bool { var big8 = big.NewInt(8) func (s EIP155Signer) Sender(tx *Transaction) (common.Address, error) { - addr, ok := GlobalSigCache.Get(tx.Hash()) - if ok { - return addr, nil - } - if !tx.Protected() { return HomesteadSigner{}.Sender(tx) } diff --git a/dex/app.go b/dex/app.go index 623bb8dff..0e3f34f70 100644 --- a/dex/app.go +++ b/dex/app.go @@ -174,10 +174,9 @@ func (d *DexconApp) PreparePayload(position coreTypes.Position) (payload []byte, chainID := new(big.Int).SetUint64(uint64(position.ChainID)) chainNums := new(big.Int).SetUint64(uint64(d.gov.GetNumChains(position.Round))) - blockGasLimit := new(big.Int).SetUint64(core.CalcGasLimit(d.blockchain.CurrentBlock(), - d.config.GasFloor, d.config.GasCeil)) + blockGasLimit := new(big.Int).SetUint64(d.blockchain.CurrentBlock().GasLimit()) blockGasUsed := new(big.Int) - var allTxs types.Transactions + allTxs := make([]*types.Transaction, 0, 3000) addressMap: for address, txs := range txsMap { @@ -374,8 +373,7 @@ func (d *DexconApp) VerifyBlock(block *coreTypes.Block) coreTypes.BlockVerifySta } // Validate if balance is enough for TXs in this block. - blockGasLimit := new(big.Int).SetUint64(core.CalcGasLimit( - d.blockchain.CurrentBlock(), d.config.GasFloor, d.config.GasCeil)) + blockGasLimit := new(big.Int).SetUint64(d.blockchain.CurrentBlock().GasLimit()) blockGasUsed := new(big.Int) for _, tx := range transactions { @@ -451,7 +449,6 @@ func (d *DexconApp) BlockDelivered( } d.chainLatestRoot.Store(block.Position.ChainID, root) - log.Info("Insert pending block success", "height", result.Height) d.blockchain.RemoveConfirmedBlock(chainID, blockHash) } diff --git a/dex/handler.go b/dex/handler.go index 70c3d9806..fe48c455b 100644 --- a/dex/handler.go +++ b/dex/handler.go @@ -1117,7 +1117,7 @@ func (pm *ProtocolManager) txBroadcastLoop() { txs := make(types.Transactions, 0) for { select { - case <-time.After(500 * time.Millisecond): + case <-time.After(100 * time.Millisecond): pm.BroadcastTxs(txs) txs = txs[:0] currentSize = 0 diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 1d560b385..45a0a3e10 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1279,6 +1279,7 @@ func submitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (c // submitTransactions is a helper function that submits batch of tx to txPool and logs a message. func submitTransactions(ctx context.Context, b Backend, txs []*types.Transaction) ([]common.Hash, error) { + types.GlobalSigCache.Add(types.NewEIP155Signer(b.ChainConfig().ChainID), txs) errs := b.SendTxs(ctx, txs) var hashes []common.Hash for i, err := range errs { diff --git a/params/config.go b/params/config.go index 174aefd02..150990080 100644 --- a/params/config.go +++ b/params/config.go @@ -48,7 +48,7 @@ var ( Owner: common.HexToAddress("BF8C48A620bacc46907f9B89732D25E47A2D7Cf7"), MinStake: new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1e5)), BlockReward: big.NewInt(1e18), - BlockGasLimit: 80000000, + BlockGasLimit: 40000000, NumChains: 4, LambdaBA: 250, LambdaDKG: 2500, @@ -86,7 +86,7 @@ var ( Owner: common.HexToAddress("BF8C48A620bacc46907f9B89732D25E47A2D7Cf7"), MinStake: new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1e5)), BlockReward: big.NewInt(1e18), - BlockGasLimit: 80000000, + BlockGasLimit: 40000000, NumChains: 6, LambdaBA: 250, LambdaDKG: 2500, diff --git a/test/genesis.json b/test/genesis.json index bc3e740ea..6a48eee29 100644 --- a/test/genesis.json +++ b/test/genesis.json @@ -14,7 +14,7 @@ "owner": "0xBF8C48A620bacc46907f9B89732D25E47A2D7Cf7", "minStake": "0x152d02c7e14af6800000", "blockReward": "0xde0b6b3a7640000", - "blockGasLimit": 80000000, + "blockGasLimit": 40000000, "numChains": 6, "lambdaBA": 250, "lambdaDKG": 2500, @@ -29,7 +29,7 @@ "nonce": "0x42", "timestamp": "0x0", "extraData": "0x3535353535353535353535353535353535353535353535353535353535353535", - "gasLimit": "0x4c4b400", + "gasLimit": "0x2625a00", "difficulty": "0x1", "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "coinbase": "0x0000000000000000000000000000000000000000", |