erigon-pulse/cmd/pics/state.go

540 lines
16 KiB
Go
Raw Normal View History

package main
import (
"bytes"
"context"
"encoding/binary"
"fmt"
2019-11-05 21:50:24 +00:00
"math/big"
"os"
"os/exec"
2020-09-03 06:06:32 +00:00
"path/filepath"
"strings"
2019-11-05 21:50:24 +00:00
"github.com/holiman/uint256"
"github.com/ledgerwatch/turbo-geth/accounts/abi/bind"
"github.com/ledgerwatch/turbo-geth/accounts/abi/bind/backends"
"github.com/ledgerwatch/turbo-geth/cmd/pics/contracts"
"github.com/ledgerwatch/turbo-geth/common"
"github.com/ledgerwatch/turbo-geth/common/dbutils"
"github.com/ledgerwatch/turbo-geth/consensus/ethash"
"github.com/ledgerwatch/turbo-geth/core"
"github.com/ledgerwatch/turbo-geth/core/rawdb"
"github.com/ledgerwatch/turbo-geth/core/types"
"github.com/ledgerwatch/turbo-geth/core/vm"
"github.com/ledgerwatch/turbo-geth/crypto"
"github.com/ledgerwatch/turbo-geth/eth/stagedsync"
"github.com/ledgerwatch/turbo-geth/ethdb"
"github.com/ledgerwatch/turbo-geth/params"
"github.com/ledgerwatch/turbo-geth/turbo/trie"
"github.com/ledgerwatch/turbo-geth/visual"
)
/*func statePicture(t *trie.Trie, number int, keyCompression int, codeCompressed bool, valCompressed bool,
quadTrie bool, quadColors bool, highlights [][]byte) (*trie.Trie, error) {
filename := fmt.Sprintf("state_%d.dot", number)
f, err := os.Create(filename)
if err != nil {
return nil, err
}
indexColors := visual.HexIndexColors
fontColors := visual.HexFontColors
if quadTrie {
t = trie.HexToQuad(t)
}
if quadColors {
indexColors = visual.QuadIndexColors
fontColors = visual.QuadFontColors
}
visual.StartGraph(f, false)
trie.Visual(t, f, &trie.VisualOpts{
Highlights: highlights,
IndexColors: indexColors,
FontColors: fontColors,
Values: true,
CutTerminals: keyCompression,
CodeCompressed: codeCompressed,
ValCompressed: valCompressed,
ValHex: true,
})
visual.EndGraph(f)
if err := f.Close(); err != nil {
return nil, err
}
2020-09-03 06:06:32 +00:00
//nolint:gosec
cmd := exec.Command("dot", "-Tpng:gd", "-o"+dot2png(filename), filename)
if output, err := cmd.CombinedOutput(); err != nil {
fmt.Printf("error: %v, output: %s\n", err, output)
}
return t, nil
}*/
var bucketLabels = map[string]string{
dbutils.BlockReceiptsPrefix: "Receipts",
dbutils.Log: "Event Logs",
dbutils.AccountsHistoryBucket: "History Of Accounts",
dbutils.StorageHistoryBucket: "History Of Storage",
dbutils.HeadersBucket: "Headers",
dbutils.HeaderCanonicalBucket: "Canonical headers",
dbutils.HeaderTDBucket: "Headers TD",
dbutils.BlockBodyPrefix: "Block Bodies",
dbutils.HeaderNumberBucket: "Header Numbers",
dbutils.TxLookupPrefix: "Transaction Index",
dbutils.CodeBucket: "Code Of Contracts",
dbutils.SyncStageProgress: "Sync Progress",
dbutils.PlainStateBucket: "Plain State",
dbutils.HashedAccountsBucket: "Hashed Accounts",
dbutils.HashedStorageBucket: "Hashed Storage",
dbutils.TrieOfAccountsBucket: "Intermediate Hashes Of Accounts",
dbutils.TrieOfStorageBucket: "Intermediate Hashes Of Storage",
dbutils.SyncStageUnwind: "Unwind",
dbutils.AccountChangeSetBucket: "Account Changes",
dbutils.StorageChangeSetBucket: "Storage Changes",
dbutils.IncarnationMapBucket: "Incarnations",
dbutils.Senders: "Transaction Senders",
}
/*dbutils.PlainContractCodeBucket,
dbutils.CodeBucket,
dbutils.AccountsHistoryBucket,
dbutils.StorageHistoryBucket,
dbutils.TxLookupPrefix,*/
func hexPalette() error {
filename := "hex_palette.dot"
2019-11-05 21:50:24 +00:00
f, err := os.Create(filename)
if err != nil {
return err
}
visual.StartGraph(f, true)
p := common.FromHex("0x000102030405060708090a0b0c0d0e0f")
visual.Horizontal(f, p, len(p), "p", visual.HexIndexColors, visual.HexFontColors, 0)
2019-11-05 21:50:24 +00:00
visual.EndGraph(f)
if err := f.Close(); err != nil {
return err
}
2020-09-03 06:06:32 +00:00
//nolint:gosec
cmd := exec.Command("dot", "-Tpng:gd", "-o"+dot2png(filename), filename)
2019-11-05 21:50:24 +00:00
if output, err := cmd.CombinedOutput(); err != nil {
fmt.Printf("error: %v, output: %s\n", err, output)
}
return nil
}
2021-03-30 09:53:54 +00:00
func stateDatabaseComparison(first ethdb.RwKV, second ethdb.RwKV, number int) error {
filename := fmt.Sprintf("changes_%d.dot", number)
f, err := os.Create(filename)
if err != nil {
return err
}
i := 0
visual.StartGraph(f, true)
m := make(map[string][]int)
noValues := make(map[int]struct{})
perBucketFiles := make(map[string]*os.File)
if err = second.View(context.Background(), func(readTx ethdb.Tx) error {
return first.View(context.Background(), func(firstTx ethdb.Tx) error {
2020-09-03 06:06:32 +00:00
for bucketName := range bucketLabels {
bucketName := bucketName
c, err := readTx.Cursor(bucketName)
if err != nil {
return err
}
if err2 := ethdb.ForEach(c, func(k, v []byte) (bool, error) {
if firstV, _ := firstTx.GetOne(bucketName, k); firstV != nil && bytes.Equal(v, firstV) {
// Skip the record that is the same as in the first Db
return true, nil
}
// Produce pair of nodes
keyKeyBytes := &trie.Keybytes{
Data: k,
Odd: false,
Terminating: false,
}
valKeyBytes := &trie.Keybytes{
Data: v,
Odd: false,
Terminating: false,
}
val := valKeyBytes.ToHex()
key := keyKeyBytes.ToHex()
var f1 *os.File
var ok bool
2020-08-10 23:55:32 +00:00
if f1, ok = perBucketFiles[bucketName]; !ok {
2020-09-03 06:06:32 +00:00
f1, err = os.Create(fmt.Sprintf("changes_%d_%s.dot", number, strings.ReplaceAll(bucketLabels[bucketName], " ", "")))
if err != nil {
return false, err
}
visual.StartGraph(f1, true)
var clusterLabel string
var ok bool
2020-08-10 23:55:32 +00:00
if clusterLabel, ok = bucketLabels[bucketName]; !ok {
clusterLabel = bucketName
}
visual.StartCluster(f1, 0, clusterLabel)
2020-08-10 23:55:32 +00:00
perBucketFiles[bucketName] = f1
}
visual.Horizontal(f1, key, len(key), fmt.Sprintf("k_%d", i), visual.HexIndexColors, visual.HexFontColors, 0)
if len(val) > 0 {
if len(val) > 64 {
visual.HexBox(f1, fmt.Sprintf("v_%d", i), val, 64, false /*compresses*/, true /*highlighted*/)
} else {
visual.Horizontal(f1, val, len(val), fmt.Sprintf("v_%d", i), visual.HexIndexColors, visual.HexFontColors, 0)
}
// Produce edge
fmt.Fprintf(f1, "k_%d -> v_%d;\n", i, i)
} else {
noValues[i] = struct{}{}
}
visual.Horizontal(f, key, 0, fmt.Sprintf("k_%d", i), visual.HexIndexColors, visual.HexFontColors, 0)
if len(val) > 0 {
if len(val) > 64 {
visual.HexBox(f, fmt.Sprintf("v_%d", i), val, 64, false /*compressed*/, false /*highlighted*/)
} else {
visual.Horizontal(f, val, 0, fmt.Sprintf("v_%d", i), visual.HexIndexColors, visual.HexFontColors, 0)
}
// Produce edge
fmt.Fprintf(f, "k_%d -> v_%d;\n", i, i)
} else {
noValues[i] = struct{}{}
}
2020-08-10 23:55:32 +00:00
lst := m[bucketName]
lst = append(lst, i)
2020-08-10 23:55:32 +00:00
m[bucketName] = lst
i++
return true, nil
}); err2 != nil {
return err2
}
}
return nil
})
}); err != nil {
return err
}
n := 0
for prefix, lst := range m {
var clusterLabel string
var ok bool
if clusterLabel, ok = bucketLabels[prefix]; !ok {
clusterLabel = prefix
}
if len(lst) == 0 {
continue
}
visual.StartCluster(f, n, clusterLabel)
for _, item := range lst {
if _, ok1 := noValues[item]; ok1 {
fmt.Fprintf(f, "k_%d;", item)
} else {
fmt.Fprintf(f, "k_%d;v_%d;", item, item)
}
}
fmt.Fprintf(f, "\n")
visual.EndCluster(f)
n++
}
visual.EndGraph(f)
if err := f.Close(); err != nil {
return err
}
2020-09-03 06:06:32 +00:00
//nolint:gosec
cmd := exec.Command("dot", "-Tpng:gd", "-o"+dot2png(filename), filename)
if output, err := cmd.CombinedOutput(); err != nil {
fmt.Printf("error: %v, output: %s\n", err, output)
}
for _, f1 := range perBucketFiles {
fmt.Fprintf(f1, "\n")
visual.EndCluster(f1)
visual.EndGraph(f1)
if err := f1.Close(); err != nil {
return err
}
2020-09-03 06:06:32 +00:00
//nolint:gosec
cmd := exec.Command("dot", "-Tpng:gd", "-o"+dot2png(f1.Name()), f1.Name())
if output, err := cmd.CombinedOutput(); err != nil {
fmt.Printf("error: %v, output: %s\n", err, output)
}
}
return nil
}
2020-09-03 06:06:32 +00:00
func dot2png(dotFileName string) string {
return strings.TrimSuffix(dotFileName, filepath.Ext(dotFileName)) + ".png"
}
func initialState1() error {
fmt.Printf("Initial state 1\n")
// Configure and generate a sample block chain
db := ethdb.NewMemDatabase()
defer db.Close()
var (
key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
key1, _ = crypto.HexToECDSA("49a7b37aa6f6645917e7b807e9d1c00d4fa71f18343b0d4122a4d2df64dd6fee")
key2, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a")
address = crypto.PubkeyToAddress(key.PublicKey)
address1 = crypto.PubkeyToAddress(key1.PublicKey)
address2 = crypto.PubkeyToAddress(key2.PublicKey)
theAddr = common.Address{1}
gspec = &core.Genesis{
Config: params.AllEthashProtocolChanges,
Alloc: core.GenesisAlloc{
address: {Balance: big.NewInt(9000000000000000000)},
address1: {Balance: big.NewInt(200000000000000000)},
address2: {Balance: big.NewInt(300000000000000000)},
},
}
// this code generates a log
Aleut support (Eip1559) (#1704) * Where I am at * Refactoring of transaction types * More refactoring * Use Homested signer in rpc daemon * Unified signer * Continue unified signer * A bit more * Fixes and down the rabbit hole... * More tx pool fixes * More refactoring fixes * More fixes' * more fixes * More fixes * More compile fixes * More RLP hand-writing * Finish RLP encoding/decoding of transactions * Fixes to header encoding, start on protocol packets * Transaction decoding * Use DecodeTransaction function * Decoding BlockBodyPacket * Encode and decode for pool txs * Start fixing tests * Introduce SigningHash * Fixes to SignHash * RLP encoding fixes * Fixes for encoding/decoding * More test fixes * Fix more tests * More test fixes * More test fixes * Fix core tests * More fixes for signer * Fix for tx * Fixes to string encoding/size * Fix eip2930 test * Fix rest of ./tests * More fixes * Fix compilation * More test fixes * More test fixes * Test fixes * More fixes * Reuse EncodingSize in EncodeRLP for accessList * Rearrange things in dynamic fee tx * Add MarshalBinary * More fixes * Make V,R,S non-pointers * More NPE fixes * More fixes * Receipt fixes * Fix core/types * Fix ./eth * More compile fixes for tests * More test fixes * More test fixes * Try to see lint errors better * Try to see lint errors better * Fix lint * Debugging eip1559 test * Fix TestEIP1559Transition test * Fix NewBlockPacket encoding/decoding * Fix calculation of TxHash * Fix perf problem with senders * Update aleut config values * Try adding static peers * Add staticpeers to defaul flags * Change aleut networkID * Fix test Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local> Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
2021-04-22 17:11:37 +00:00
signer = types.MakeSigner(params.AllEthashProtocolChanges, 1)
)
// Create intermediate hash bucket since it is mandatory now
_, genesisHash, err := core.SetupGenesisBlock(db, gspec, true, false)
if err != nil {
return err
}
genesis := rawdb.ReadBlockDeprecated(db, genesisHash, 0)
if err != nil {
return err
}
engine := ethash.NewFaker()
contractBackend := backends.NewSimulatedBackendWithConfig(gspec.Alloc, gspec.Config, gspec.GasLimit)
defer contractBackend.Close()
transactOpts := bind.NewKeyedTransactor(key)
transactOpts1 := bind.NewKeyedTransactor(key1)
transactOpts2 := bind.NewKeyedTransactor(key2)
var tokenContract *contracts.Token
// We generate the blocks without plainstant because it's not supported in core.GenerateChain
2021-05-20 11:49:33 +00:00
blocks, _, err := core.GenerateChain(gspec.Config, genesis, engine, db.RwKV(), 8, func(i int, block *core.BlockGen) {
var (
Aleut support (Eip1559) (#1704) * Where I am at * Refactoring of transaction types * More refactoring * Use Homested signer in rpc daemon * Unified signer * Continue unified signer * A bit more * Fixes and down the rabbit hole... * More tx pool fixes * More refactoring fixes * More fixes' * more fixes * More fixes * More compile fixes * More RLP hand-writing * Finish RLP encoding/decoding of transactions * Fixes to header encoding, start on protocol packets * Transaction decoding * Use DecodeTransaction function * Decoding BlockBodyPacket * Encode and decode for pool txs * Start fixing tests * Introduce SigningHash * Fixes to SignHash * RLP encoding fixes * Fixes for encoding/decoding * More test fixes * Fix more tests * More test fixes * More test fixes * Fix core tests * More fixes for signer * Fix for tx * Fixes to string encoding/size * Fix eip2930 test * Fix rest of ./tests * More fixes * Fix compilation * More test fixes * More test fixes * Test fixes * More fixes * Reuse EncodingSize in EncodeRLP for accessList * Rearrange things in dynamic fee tx * Add MarshalBinary * More fixes * Make V,R,S non-pointers * More NPE fixes * More fixes * Receipt fixes * Fix core/types * Fix ./eth * More compile fixes for tests * More test fixes * More test fixes * Try to see lint errors better * Try to see lint errors better * Fix lint * Debugging eip1559 test * Fix TestEIP1559Transition test * Fix NewBlockPacket encoding/decoding * Fix calculation of TxHash * Fix perf problem with senders * Update aleut config values * Try adding static peers * Add staticpeers to defaul flags * Change aleut networkID * Fix test Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local> Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
2021-04-22 17:11:37 +00:00
tx types.Transaction
txs []types.Transaction
)
Aleut support (Eip1559) (#1704) * Where I am at * Refactoring of transaction types * More refactoring * Use Homested signer in rpc daemon * Unified signer * Continue unified signer * A bit more * Fixes and down the rabbit hole... * More tx pool fixes * More refactoring fixes * More fixes' * more fixes * More fixes * More compile fixes * More RLP hand-writing * Finish RLP encoding/decoding of transactions * Fixes to header encoding, start on protocol packets * Transaction decoding * Use DecodeTransaction function * Decoding BlockBodyPacket * Encode and decode for pool txs * Start fixing tests * Introduce SigningHash * Fixes to SignHash * RLP encoding fixes * Fixes for encoding/decoding * More test fixes * Fix more tests * More test fixes * More test fixes * Fix core tests * More fixes for signer * Fix for tx * Fixes to string encoding/size * Fix eip2930 test * Fix rest of ./tests * More fixes * Fix compilation * More test fixes * More test fixes * Test fixes * More fixes * Reuse EncodingSize in EncodeRLP for accessList * Rearrange things in dynamic fee tx * Add MarshalBinary * More fixes * Make V,R,S non-pointers * More NPE fixes * More fixes * Receipt fixes * Fix core/types * Fix ./eth * More compile fixes for tests * More test fixes * More test fixes * Try to see lint errors better * Try to see lint errors better * Fix lint * Debugging eip1559 test * Fix TestEIP1559Transition test * Fix NewBlockPacket encoding/decoding * Fix calculation of TxHash * Fix perf problem with senders * Update aleut config values * Try adding static peers * Add staticpeers to defaul flags * Change aleut networkID * Fix test Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local> Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
2021-04-22 17:11:37 +00:00
ctx := gspec.Config.WithEIPsFlags(context.Background(), block.Number().Uint64())
switch i {
case 0:
Aleut support (Eip1559) (#1704) * Where I am at * Refactoring of transaction types * More refactoring * Use Homested signer in rpc daemon * Unified signer * Continue unified signer * A bit more * Fixes and down the rabbit hole... * More tx pool fixes * More refactoring fixes * More fixes' * more fixes * More fixes * More compile fixes * More RLP hand-writing * Finish RLP encoding/decoding of transactions * Fixes to header encoding, start on protocol packets * Transaction decoding * Use DecodeTransaction function * Decoding BlockBodyPacket * Encode and decode for pool txs * Start fixing tests * Introduce SigningHash * Fixes to SignHash * RLP encoding fixes * Fixes for encoding/decoding * More test fixes * Fix more tests * More test fixes * More test fixes * Fix core tests * More fixes for signer * Fix for tx * Fixes to string encoding/size * Fix eip2930 test * Fix rest of ./tests * More fixes * Fix compilation * More test fixes * More test fixes * Test fixes * More fixes * Reuse EncodingSize in EncodeRLP for accessList * Rearrange things in dynamic fee tx * Add MarshalBinary * More fixes * Make V,R,S non-pointers * More NPE fixes * More fixes * Receipt fixes * Fix core/types * Fix ./eth * More compile fixes for tests * More test fixes * More test fixes * Try to see lint errors better * Try to see lint errors better * Fix lint * Debugging eip1559 test * Fix TestEIP1559Transition test * Fix NewBlockPacket encoding/decoding * Fix calculation of TxHash * Fix perf problem with senders * Update aleut config values * Try adding static peers * Add staticpeers to defaul flags * Change aleut networkID * Fix test Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local> Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
2021-04-22 17:11:37 +00:00
tx, err = types.SignTx(types.NewTransaction(0, theAddr, uint256.NewInt().SetUint64(1000000000000000), 21000, new(uint256.Int), nil), *signer, key)
err = contractBackend.SendTransaction(ctx, tx)
if err != nil {
panic(err)
}
case 1:
Aleut support (Eip1559) (#1704) * Where I am at * Refactoring of transaction types * More refactoring * Use Homested signer in rpc daemon * Unified signer * Continue unified signer * A bit more * Fixes and down the rabbit hole... * More tx pool fixes * More refactoring fixes * More fixes' * more fixes * More fixes * More compile fixes * More RLP hand-writing * Finish RLP encoding/decoding of transactions * Fixes to header encoding, start on protocol packets * Transaction decoding * Use DecodeTransaction function * Decoding BlockBodyPacket * Encode and decode for pool txs * Start fixing tests * Introduce SigningHash * Fixes to SignHash * RLP encoding fixes * Fixes for encoding/decoding * More test fixes * Fix more tests * More test fixes * More test fixes * Fix core tests * More fixes for signer * Fix for tx * Fixes to string encoding/size * Fix eip2930 test * Fix rest of ./tests * More fixes * Fix compilation * More test fixes * More test fixes * Test fixes * More fixes * Reuse EncodingSize in EncodeRLP for accessList * Rearrange things in dynamic fee tx * Add MarshalBinary * More fixes * Make V,R,S non-pointers * More NPE fixes * More fixes * Receipt fixes * Fix core/types * Fix ./eth * More compile fixes for tests * More test fixes * More test fixes * Try to see lint errors better * Try to see lint errors better * Fix lint * Debugging eip1559 test * Fix TestEIP1559Transition test * Fix NewBlockPacket encoding/decoding * Fix calculation of TxHash * Fix perf problem with senders * Update aleut config values * Try adding static peers * Add staticpeers to defaul flags * Change aleut networkID * Fix test Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local> Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
2021-04-22 17:11:37 +00:00
tx, err = types.SignTx(types.NewTransaction(1, theAddr, uint256.NewInt().SetUint64(1000000000000000), 21000, new(uint256.Int), nil), *signer, key)
err = contractBackend.SendTransaction(ctx, tx)
if err != nil {
panic(err)
}
case 2:
_, tx, tokenContract, err = contracts.DeployToken(transactOpts, contractBackend, address1)
case 3:
tx, err = tokenContract.Mint(transactOpts1, address2, big.NewInt(10))
case 4:
tx, err = tokenContract.Transfer(transactOpts2, address, big.NewInt(3))
case 5:
// Multiple transactions sending small amounts of ether to various accounts
var j uint64
var toAddr common.Address
nonce := block.TxNonce(address)
for j = 1; j <= 32; j++ {
binary.BigEndian.PutUint64(toAddr[:], j)
Aleut support (Eip1559) (#1704) * Where I am at * Refactoring of transaction types * More refactoring * Use Homested signer in rpc daemon * Unified signer * Continue unified signer * A bit more * Fixes and down the rabbit hole... * More tx pool fixes * More refactoring fixes * More fixes' * more fixes * More fixes * More compile fixes * More RLP hand-writing * Finish RLP encoding/decoding of transactions * Fixes to header encoding, start on protocol packets * Transaction decoding * Use DecodeTransaction function * Decoding BlockBodyPacket * Encode and decode for pool txs * Start fixing tests * Introduce SigningHash * Fixes to SignHash * RLP encoding fixes * Fixes for encoding/decoding * More test fixes * Fix more tests * More test fixes * More test fixes * Fix core tests * More fixes for signer * Fix for tx * Fixes to string encoding/size * Fix eip2930 test * Fix rest of ./tests * More fixes * Fix compilation * More test fixes * More test fixes * Test fixes * More fixes * Reuse EncodingSize in EncodeRLP for accessList * Rearrange things in dynamic fee tx * Add MarshalBinary * More fixes * Make V,R,S non-pointers * More NPE fixes * More fixes * Receipt fixes * Fix core/types * Fix ./eth * More compile fixes for tests * More test fixes * More test fixes * Try to see lint errors better * Try to see lint errors better * Fix lint * Debugging eip1559 test * Fix TestEIP1559Transition test * Fix NewBlockPacket encoding/decoding * Fix calculation of TxHash * Fix perf problem with senders * Update aleut config values * Try adding static peers * Add staticpeers to defaul flags * Change aleut networkID * Fix test Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local> Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
2021-04-22 17:11:37 +00:00
tx, err = types.SignTx(types.NewTransaction(nonce, toAddr, uint256.NewInt().SetUint64(1000000000000000), 21000, new(uint256.Int), nil), *signer, key)
if err != nil {
panic(err)
}
err = contractBackend.SendTransaction(ctx, tx)
if err != nil {
panic(err)
}
txs = append(txs, tx)
nonce++
}
case 6:
_, tx, tokenContract, err = contracts.DeployToken(transactOpts, contractBackend, address1)
if err != nil {
panic(err)
}
txs = append(txs, tx)
tx, err = tokenContract.Mint(transactOpts1, address2, big.NewInt(100))
if err != nil {
panic(err)
}
txs = append(txs, tx)
// Multiple transactions sending small amounts of ether to various accounts
var j uint64
var toAddr common.Address
for j = 1; j <= 32; j++ {
binary.BigEndian.PutUint64(toAddr[:], j)
tx, err = tokenContract.Transfer(transactOpts2, toAddr, big.NewInt(1))
if err != nil {
panic(err)
}
txs = append(txs, tx)
}
case 7:
var toAddr common.Address
nonce := block.TxNonce(address)
binary.BigEndian.PutUint64(toAddr[:], 4)
Aleut support (Eip1559) (#1704) * Where I am at * Refactoring of transaction types * More refactoring * Use Homested signer in rpc daemon * Unified signer * Continue unified signer * A bit more * Fixes and down the rabbit hole... * More tx pool fixes * More refactoring fixes * More fixes' * more fixes * More fixes * More compile fixes * More RLP hand-writing * Finish RLP encoding/decoding of transactions * Fixes to header encoding, start on protocol packets * Transaction decoding * Use DecodeTransaction function * Decoding BlockBodyPacket * Encode and decode for pool txs * Start fixing tests * Introduce SigningHash * Fixes to SignHash * RLP encoding fixes * Fixes for encoding/decoding * More test fixes * Fix more tests * More test fixes * More test fixes * Fix core tests * More fixes for signer * Fix for tx * Fixes to string encoding/size * Fix eip2930 test * Fix rest of ./tests * More fixes * Fix compilation * More test fixes * More test fixes * Test fixes * More fixes * Reuse EncodingSize in EncodeRLP for accessList * Rearrange things in dynamic fee tx * Add MarshalBinary * More fixes * Make V,R,S non-pointers * More NPE fixes * More fixes * Receipt fixes * Fix core/types * Fix ./eth * More compile fixes for tests * More test fixes * More test fixes * Try to see lint errors better * Try to see lint errors better * Fix lint * Debugging eip1559 test * Fix TestEIP1559Transition test * Fix NewBlockPacket encoding/decoding * Fix calculation of TxHash * Fix perf problem with senders * Update aleut config values * Try adding static peers * Add staticpeers to defaul flags * Change aleut networkID * Fix test Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local> Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
2021-04-22 17:11:37 +00:00
tx, err = types.SignTx(types.NewTransaction(nonce, toAddr, uint256.NewInt().SetUint64(1000000000000000), 21000, new(uint256.Int), nil), *signer, key)
if err != nil {
panic(err)
}
err = contractBackend.SendTransaction(ctx, tx)
if err != nil {
panic(err)
}
txs = append(txs, tx)
binary.BigEndian.PutUint64(toAddr[:], 12)
tx, err = tokenContract.Transfer(transactOpts2, toAddr, big.NewInt(1))
if err != nil {
panic(err)
}
txs = append(txs, tx)
}
if err != nil {
panic(err)
}
if txs == nil && tx != nil {
txs = append(txs, tx)
}
for _, tx := range txs {
block.AddTx(tx)
}
contractBackend.Commit()
}, true)
if err != nil {
return err
}
db.Close()
// We reset the DB and use the generated blocks
db = ethdb.NewMemDatabase()
2021-03-30 09:53:54 +00:00
kv := db.RwKV()
snapshotDB := db.MemCopy()
_, _, err = core.SetupGenesisBlock(db, gspec, true, false)
if err != nil {
return err
}
engine = ethash.NewFaker()
if err = hexPalette(); err != nil {
return err
}
2021-03-30 09:53:54 +00:00
if err = stateDatabaseComparison(snapshotDB.RwKV(), kv, 0); err != nil {
return err
}
snapshotDB.Close()
// BLOCK 1
snapshotDB = db.MemCopy()
2019-11-05 21:50:24 +00:00
if _, err = stagedsync.InsertBlockInStages(db, gspec.Config, &vm.Config{}, engine, blocks[0], true /* rootCheck */); err != nil {
return err
}
2021-03-30 09:53:54 +00:00
if err = stateDatabaseComparison(snapshotDB.RwKV(), kv, 1); err != nil {
2019-11-05 21:50:24 +00:00
return err
}
snapshotDB.Close()
// BLOCK 2
snapshotDB = db.MemCopy()
if _, err = stagedsync.InsertBlockInStages(db, gspec.Config, &vm.Config{}, engine, blocks[1], true /* rootCheck */); err != nil {
return err
}
2021-03-30 09:53:54 +00:00
if err = stateDatabaseComparison(snapshotDB.RwKV(), kv, 2); err != nil {
2019-11-05 21:50:24 +00:00
return err
}
snapshotDB.Close()
// BLOCK 3
snapshotDB = db.MemCopy()
2019-11-05 21:50:24 +00:00
if _, err = stagedsync.InsertBlockInStages(db, gspec.Config, &vm.Config{}, engine, blocks[2], true /* rootCheck */); err != nil {
return err
}
2021-03-30 09:53:54 +00:00
if err = stateDatabaseComparison(snapshotDB.RwKV(), kv, 3); err != nil {
2019-11-05 21:50:24 +00:00
return err
}
snapshotDB.Close()
// BLOCK 4
snapshotDB = db.MemCopy()
2019-11-05 21:50:24 +00:00
if _, err = stagedsync.InsertBlockInStages(db, gspec.Config, &vm.Config{}, engine, blocks[3], true /* rootCheck */); err != nil {
return err
}
2021-03-30 09:53:54 +00:00
if err = stateDatabaseComparison(snapshotDB.RwKV(), kv, 4); err != nil {
2019-11-05 21:50:24 +00:00
return err
}
snapshotDB.Close()
// BLOCK 5
snapshotDB = db.MemCopy()
2019-11-05 21:50:24 +00:00
if _, err = stagedsync.InsertBlockInStages(db, gspec.Config, &vm.Config{}, engine, blocks[4], true /* rootCheck */); err != nil {
return err
}
2021-03-30 09:53:54 +00:00
if err = stateDatabaseComparison(snapshotDB.RwKV(), kv, 5); err != nil {
2019-11-05 21:50:24 +00:00
return err
}
snapshotDB.Close()
// BLOCK 6
snapshotDB = db.MemCopy()
2019-11-05 21:50:24 +00:00
if _, err = stagedsync.InsertBlockInStages(db, gspec.Config, &vm.Config{}, engine, blocks[5], true /* rootCheck */); err != nil {
return err
}
2021-03-30 09:53:54 +00:00
if err = stateDatabaseComparison(snapshotDB.RwKV(), kv, 6); err != nil {
2019-11-05 21:50:24 +00:00
return err
}
snapshotDB.Close()
// BLOCK 7
snapshotDB = db.MemCopy()
2019-11-05 21:50:24 +00:00
if _, err = stagedsync.InsertBlockInStages(db, gspec.Config, &vm.Config{}, engine, blocks[6], true /* rootCheck */); err != nil {
return err
}
2021-03-30 09:53:54 +00:00
if err = stateDatabaseComparison(snapshotDB.RwKV(), kv, 7); err != nil {
2019-11-05 21:50:24 +00:00
return err
}
snapshotDB.Close()
if err != nil {
return err
}
// BLOCK 8
snapshotDB = db.MemCopy()
2019-11-05 21:50:24 +00:00
if _, err = stagedsync.InsertBlockInStages(db, gspec.Config, &vm.Config{}, engine, blocks[7], true /* rootCheck */); err != nil {
return err
}
2021-03-30 09:53:54 +00:00
if err = stateDatabaseComparison(snapshotDB.RwKV(), kv, 8); err != nil {
2019-11-05 21:50:24 +00:00
return err
}
snapshotDB.Close()
2021-03-30 09:53:54 +00:00
kv2 := ethdb.NewMemDatabase().RwKV()
defer kv2.Close()
if err = stateDatabaseComparison(kv2, kv, 9); err != nil {
return err
}
return nil
2019-11-05 21:51:11 +00:00
}