diff options
author | Wei-Ning Huang <w@dexon.org> | 2018-11-26 10:00:31 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-03-12 12:19:09 +0800 |
commit | f79bf330b4b649ea74d54faf749214c14f32af9c (patch) | |
tree | 1cf494fda8e45813c6e4062a587dfd3ecf1d5a54 | |
parent | b4f183ba63e3ab5dccc6371faaa57c77b61e967b (diff) | |
download | dexon-f79bf330b4b649ea74d54faf749214c14f32af9c.tar dexon-f79bf330b4b649ea74d54faf749214c14f32af9c.tar.gz dexon-f79bf330b4b649ea74d54faf749214c14f32af9c.tar.bz2 dexon-f79bf330b4b649ea74d54faf749214c14f32af9c.tar.lz dexon-f79bf330b4b649ea74d54faf749214c14f32af9c.tar.xz dexon-f79bf330b4b649ea74d54faf749214c14f32af9c.tar.zst dexon-f79bf330b4b649ea74d54faf749214c14f32af9c.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/tx_pool_test.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 |
11 files changed, 25 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 dfc00ffd0..b9de195dc 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1834,6 +1834,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 e7d26d4c2..e41fe9abd 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -387,7 +387,7 @@ func DefaultGenesisBlock() *Genesis { Timestamp: 1540024964, Nonce: 0x42, ExtraData: hexutil.MustDecode("0x5765692d4e696e6720536f6e696320426f6a696520323031382d31302d32302e"), - GasLimit: 80000000, + GasLimit: 40000000, Difficulty: big.NewInt(1), Alloc: decodePrealloc(mainnetAllocData), } @@ -399,7 +399,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 b7f8896fa..1d69ea506 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/tx_pool_test.go b/core/tx_pool_test.go index 4c1d78f7f..dc664eedd 100644 --- a/core/tx_pool_test.go +++ b/core/tx_pool_test.go @@ -1437,7 +1437,9 @@ func TestTransactionPoolStableUnderpricing(t *testing.T) { blockchain := &testBlockChain{statedb, 1000000, new(event.Feed), new(event.Feed)} config := testTxPoolConfig + config.AccountSlots = 16 config.GlobalSlots = 128 + config.AccountQueue = 1024 config.GlobalQueue = 0 pool := NewTxPool(config, params.TestChainConfig, blockchain, false) 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 b4499ae5a..60a5ede17 100644 --- a/dex/handler.go +++ b/dex/handler.go @@ -1112,7 +1112,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 7ea7cf2aa..43553bece 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1281,6 +1281,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 68af7143c..df5a3782d 100644 --- a/params/config.go +++ b/params/config.go @@ -49,7 +49,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, @@ -88,7 +88,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", |