-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
81 lines (73 loc) · 1.96 KB
/
init.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package environment
import (
"context"
"fmt"
"math/big"
"strconv"
"strings"
"github.com/hoaleee/go-ethereum/accounts/abi/bind"
"github.com/hoaleee/go-ethereum/crypto"
"github.com/hoaleee/go-ethereum/ethclient"
"github.com/hoaleee/zkevm-node/db"
"github.com/hoaleee/zkevm-node/pool/pgpoolstorage"
"github.com/hoaleee/zkevm-node/test/benchmarks/sequencer/common/params"
)
var (
maxConnections = 10
bitSize = 64
)
// Init sets up the environment for the benchmark
func Init() (*pgpoolstorage.PostgresPoolStorage, *ethclient.Client, *bind.TransactOpts) {
ctx := context.Background()
pl, err := pgpoolstorage.NewPostgresPoolStorage(db.Config{
Name: poolDbName,
User: poolDbUser,
Password: poolDbPass,
Host: poolDbHost,
Port: poolDbPort,
EnableLog: false,
MaxConns: maxConnections,
})
if err != nil {
panic(err)
}
l2Client, err := ethclient.Dial(L2NetworkRPCURL)
if err != nil {
panic(err)
}
// PrivateKey is the private key of the sender
privateKey, err := crypto.HexToECDSA(strings.TrimPrefix(PrivateKey, "0x"))
if err != nil {
panic(err)
}
chainId, err := strconv.ParseUint(L2ChainId, IntBase, bitSize)
if err != nil {
panic(err)
}
fmt.Printf("L2ChainId: %d\n", chainId)
// Auth is the auth of the sender
auth, err := bind.NewKeyedTransactorWithChainID(privateKey, new(big.Int).SetUint64(chainId))
if err != nil {
panic(err)
}
// Print Info before send
senderBalance, err := l2Client.BalanceAt(ctx, auth.From, nil)
if err != nil {
panic(err)
}
senderNonce, err := l2Client.PendingNonceAt(ctx, auth.From)
if err != nil {
panic(err)
}
// Print Initial Stats
fmt.Printf("Receiver Addr: %v\n", params.To.String())
fmt.Printf("Sender Addr: %v\n", auth.From.String())
fmt.Printf("Sender Balance: %v\n", senderBalance.String())
fmt.Printf("Sender Nonce: %v\n", senderNonce)
gasPrice, err := l2Client.SuggestGasPrice(ctx)
if err != nil {
panic(err)
}
auth.GasPrice = gasPrice
return pl, l2Client, auth
}