Benchmarks large blocks with value transfers to non-existing accounts
(b *testing.B, numTxs, numBlocks int, recipientFn func(uint64) common.Address, dataFn func(uint64) []byte)
| 905 | |
| 906 | // Benchmarks large blocks with value transfers to non-existing accounts |
| 907 | func benchmarkLargeNumberOfValueToNonexisting(b *testing.B, numTxs, numBlocks int, recipientFn func(uint64) common.Address, dataFn func(uint64) []byte) { |
| 908 | var ( |
| 909 | signer = types.HomesteadSigner{} |
| 910 | testBankKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") |
| 911 | testBankAddress = crypto.PubkeyToAddress(testBankKey.PublicKey) |
| 912 | bankFunds = big.NewInt(100000000000000000) |
| 913 | ) |
| 914 | |
| 915 | // Generate the original common chain segment and the two competing forks |
| 916 | db := database.NewMemDatabase() |
| 917 | gspec := DefaultGenesisBlock() |
| 918 | gspec.Alloc = GenesisAlloc{ |
| 919 | testBankAddress: {Balance: bankFunds}, |
| 920 | common.HexToAddress("0xc0de"): { |
| 921 | Code: []byte{0x60, 0x01, 0x50}, |
| 922 | Balance: big.NewInt(0), |
| 923 | }, // push 1, pop |
| 924 | } |
| 925 | gspec.GasLimit = 100e6 // 100 M |
| 926 | |
| 927 | engine := fakeDpor(db) |
| 928 | remoteDB := database.NewIpfsDbWithAdapter(database.NewFakeIpfsAdapter()) |
| 929 | genesis := gspec.MustCommit(db) |
| 930 | |
| 931 | blockGenerator := func(i int, block *BlockGen) { |
| 932 | block.SetCoinbase(common.Address{1}) |
| 933 | for txi := 0; txi < numTxs; txi++ { |
| 934 | uniq := uint64(i*numTxs + txi) |
| 935 | recipient := recipientFn(uniq) |
| 936 | //recipient := common.BigToAddress(big.NewInt(0).SetUint64(1337 + uniq)) |
| 937 | tx, err := types.SignTx(types.NewTransaction(uniq, recipient, big.NewInt(1), configs.TxGas, big.NewInt(1), nil), signer, testBankKey) |
| 938 | if err != nil { |
| 939 | b.Error(err) |
| 940 | } |
| 941 | block.AddTx(tx) |
| 942 | } |
| 943 | } |
| 944 | |
| 945 | shared, _ := GenerateChain(configs.TestChainConfig, genesis, engine, db, remoteDB, numBlocks, blockGenerator) |
| 946 | b.StopTimer() |
| 947 | b.ResetTimer() |
| 948 | for i := 0; i < b.N; i++ { |
| 949 | // Import the shared chain and the original canonical one |
| 950 | diskdb := database.NewMemDatabase() |
| 951 | gspec.MustCommit(diskdb) |
| 952 | remoteDB := database.NewIpfsDbWithAdapter(database.NewFakeIpfsAdapter()) |
| 953 | |
| 954 | chain, err := NewBlockChain(diskdb, nil, configs.TestChainConfig, engine, vm.Config{}, remoteDB, nil) |
| 955 | if err != nil { |
| 956 | b.Fatalf("failed to create tester chain: %v", err) |
| 957 | } |
| 958 | b.StartTimer() |
| 959 | if _, err := chain.InsertChain(shared); err != nil { |
| 960 | b.Fatalf("failed to insert shared chain: %v", err) |
| 961 | } |
| 962 | b.StopTimer() |
| 963 | if got := chain.CurrentBlock().Transactions().Len(); got != numTxs*numBlocks { |
| 964 | b.Fatalf("Transactions were not included, expected %d, got %d", (numTxs * numBlocks), got) |
no test coverage detected