Skip to content

Commit a6306b5

Browse files
committed
Merge branch 'main' into thiago/loadtest-gas-oscillation
2 parents a2e8784 + 444c44a commit a6306b5

23 files changed

+608
-334
lines changed

cmd/dockerlogger/dockerlogger.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"sync"
1111
"time"
1212

13-
"github.com/docker/docker/api/types"
1413
"github.com/docker/docker/api/types/container"
14+
"github.com/docker/docker/api/types/network"
1515
"github.com/docker/docker/client"
1616
"github.com/fatih/color"
1717
"github.com/spf13/cobra"
@@ -117,23 +117,23 @@ func CreateClient() (*client.Client, error) {
117117
}
118118

119119
// InspectNetwork retrieves detailed information about a Docker network.
120-
func InspectNetwork(ctx context.Context, cli *client.Client, networkName string) (types.NetworkResource, error) {
120+
func InspectNetwork(ctx context.Context, cli *client.Client, networkName string) (network.Inspect, error) {
121121
if networkName == "" {
122-
return types.NetworkResource{}, fmt.Errorf("network name cannot be empty")
122+
return network.Inspect{}, fmt.Errorf("network name cannot be empty")
123123
}
124124

125125
if cli == nil {
126-
return types.NetworkResource{}, fmt.Errorf("docker client cannot be nil")
126+
return network.Inspect{}, fmt.Errorf("docker client cannot be nil")
127127
}
128128

129-
network, err := cli.NetworkInspect(ctx, networkName, types.NetworkInspectOptions{
129+
net, err := cli.NetworkInspect(ctx, networkName, network.InspectOptions{
130130
Verbose: true,
131131
})
132132
if err != nil {
133-
return types.NetworkResource{}, fmt.Errorf("failed to inspect network %s: %w", networkName, err)
133+
return network.Inspect{}, fmt.Errorf("failed to inspect network %s: %w", networkName, err)
134134
}
135135

136-
return network, nil
136+
return net, nil
137137
}
138138

139139
func monitorLogs(ctx context.Context, cli *client.Client, networkName string, config *LogConfig) error {
@@ -244,7 +244,7 @@ func shouldLogMessage(logLine string, config *LogConfig) bool {
244244
var allowedLevels map[string]bool
245245
if config.logLevels != "" {
246246
allowedLevels = make(map[string]bool)
247-
for _, level := range strings.Split(config.logLevels, ",") {
247+
for level := range strings.SplitSeq(config.logLevels, ",") {
248248
allowedLevels[strings.TrimSpace(strings.ToLower(level))] = true
249249
}
250250
}
@@ -267,8 +267,8 @@ func shouldLogMessage(logLine string, config *LogConfig) bool {
267267

268268
// Check custom keywords if no level match
269269
if config.customWords != "" {
270-
customKeywords := strings.Split(config.customWords, ",")
271-
for _, keyword := range customKeywords {
270+
customKeywords := strings.SplitSeq(config.customWords, ",")
271+
for keyword := range customKeywords {
272272
if strings.Contains(logLine, strings.TrimSpace(strings.ToLower(keyword))) {
273273
return true
274274
}

cmd/enr/enr.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ var ENRCmd = &cobra.Command{
3434
log.Error().Err(err).Msg("Unable to read input")
3535
return err
3636
}
37-
lines := strings.Split(string(rawData), "\n")
37+
lines := strings.SplitSeq(string(rawData), "\n")
3838

39-
for _, l := range lines {
39+
for l := range lines {
4040
var node *enode.Node
4141
var err error
4242
l = strings.TrimSpace(l)

cmd/loadtest/account.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ func (ap *AccountPool) RefreshNonce(ctx context.Context, address common.Address)
340340
return nil
341341
}
342342

343-
// NumberOfPendingTxs returns the the difference between the internal nonce
343+
// NumberOfPendingTxs returns the difference between the internal nonce
344344
// and the network pending nonce for all accounts in the pool. It uses
345345
// caching to avoid making too many requests to the network.
346346
func (ap *AccountPool) NumberOfPendingTxs(ctx context.Context) (uint64, error) {

cmd/p2p/sensor/sensor.go

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ type (
6969
DiscoveryDNS string
7070
Database string
7171
NoDiscovery bool
72-
MaxRequests int
73-
RequestsCacheTTL time.Duration
72+
RequestsCache p2p.CacheOptions
73+
ParentsCache p2p.CacheOptions
74+
BlocksCache p2p.CacheOptions
7475

7576
bootnodes []*enode.Node
7677
staticNodes []*enode.Node
@@ -192,22 +193,25 @@ var SensorCmd = &cobra.Command{
192193
}, []string{"message", "url", "name", "direction"})
193194

194195
// Create peer connection manager for broadcasting transactions
195-
conns := p2p.NewConns()
196+
// and managing the global blocks cache
197+
conns := p2p.NewConns(p2p.ConnsOptions{
198+
BlocksCache: inputSensorParams.BlocksCache,
199+
})
196200

197201
opts := p2p.EthProtocolOptions{
198-
Context: cmd.Context(),
199-
Database: db,
200-
GenesisHash: common.HexToHash(inputSensorParams.GenesisHash),
201-
RPC: inputSensorParams.RPC,
202-
SensorID: inputSensorParams.SensorID,
203-
NetworkID: inputSensorParams.NetworkID,
204-
Conns: conns,
205-
Head: &head,
206-
HeadMutex: &sync.RWMutex{},
207-
ForkID: forkid.ID{Hash: [4]byte(inputSensorParams.ForkID)},
208-
MsgCounter: msgCounter,
209-
MaxRequests: inputSensorParams.MaxRequests,
210-
RequestsCacheTTL: inputSensorParams.RequestsCacheTTL,
202+
Context: cmd.Context(),
203+
Database: db,
204+
GenesisHash: common.HexToHash(inputSensorParams.GenesisHash),
205+
RPC: inputSensorParams.RPC,
206+
SensorID: inputSensorParams.SensorID,
207+
NetworkID: inputSensorParams.NetworkID,
208+
Conns: conns,
209+
Head: &head,
210+
HeadMutex: &sync.RWMutex{},
211+
ForkID: forkid.ID{Hash: [4]byte(inputSensorParams.ForkID)},
212+
MsgCounter: msgCounter,
213+
RequestsCache: inputSensorParams.RequestsCache,
214+
ParentsCache: inputSensorParams.ParentsCache,
211215
}
212216

213217
config := ethp2p.Config{
@@ -480,6 +484,10 @@ will result in less chance of missing data but can significantly increase memory
480484
- json (output to stdout)
481485
- none (no persistence)`)
482486
f.BoolVar(&inputSensorParams.NoDiscovery, "no-discovery", false, "disable P2P peer discovery")
483-
f.IntVar(&inputSensorParams.MaxRequests, "max-requests", 2048, "maximum request IDs to track per peer (0 for no limit)")
484-
f.DurationVar(&inputSensorParams.RequestsCacheTTL, "requests-cache-ttl", 5*time.Minute, "time to live for requests cache entries (0 for no expiration)")
487+
f.IntVar(&inputSensorParams.RequestsCache.MaxSize, "max-requests", 2048, "maximum request IDs to track per peer (0 for no limit)")
488+
f.DurationVar(&inputSensorParams.RequestsCache.TTL, "requests-cache-ttl", 5*time.Minute, "time to live for requests cache entries (0 for no expiration)")
489+
f.IntVar(&inputSensorParams.ParentsCache.MaxSize, "max-parents", 1024, "maximum parent block hashes to track per peer (0 for no limit)")
490+
f.DurationVar(&inputSensorParams.ParentsCache.TTL, "parents-cache-ttl", 5*time.Minute, "time to live for parent hash cache entries (0 for no expiration)")
491+
f.IntVar(&inputSensorParams.BlocksCache.MaxSize, "max-blocks", 1024, "maximum blocks to track across all peers (0 for no limit)")
492+
f.DurationVar(&inputSensorParams.BlocksCache.TTL, "blocks-cache-ttl", 10*time.Minute, "time to live for block cache entries (0 for no expiration)")
485493
}

cmd/signer/signer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ func init() {
845845
SignerCmd.AddCommand(ListCmd)
846846
SignerCmd.AddCommand(ImportCmd)
847847

848-
f := SignerCmd.Flags()
848+
f := SignerCmd.PersistentFlags()
849849
f.StringVar(&inputSignerOpts.keystore, "keystore", "", "use keystore in given folder or file")
850850
f.StringVar(&inputSignerOpts.privateKey, "private-key", "", "use provided hex encoded private key")
851851
f.StringVar(&inputSignerOpts.kms, "kms", "", "AWS or GCP if key is stored in cloud")

cmd/ulxly/balanceTreeUsage.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ This is the response from polycli:
2121

2222
```json
2323
{
24-
"root": "0x4516ca2a793b8e20f56ec6ba8ca6033a672330670a3772f76f2ade9bc2125150"",
24+
"root": "0x4516ca2a793b8e20f56ec6ba8ca6033a672330670a3772f76f2ade9bc2125150",
25+
"balances": [{
26+
"originNetwork": 0,
27+
"originTokenAddress": "0x4348967e282138d8f377b467f7d9c2eb0f335d2a",
28+
"totalSupply": "993432432123"
29+
}]
2530
}
2631
```
2732

cmd/ulxly/ulxly.go

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -342,15 +342,55 @@ func balanceTree() error {
342342
if err != nil {
343343
return err
344344
}
345-
root, err := computeBalanceTree(client, bridgeAddress, l2RawClaimsData, l2NetworkID, l2RawDepositsData)
345+
root, balances, err := computeBalanceTree(client, bridgeAddress, l2RawClaimsData, l2NetworkID, l2RawDepositsData)
346346
if err != nil {
347347
return err
348348
}
349-
fmt.Printf(`
350-
{
351-
"root": "%s"
352-
}
353-
`, root.String())
349+
type BalanceEntry struct {
350+
OriginNetwork uint32 `json:"originNetwork"`
351+
OriginTokenAddress common.Address `json:"originTokenAddress"`
352+
TotalSupply string `json:"totalSupply"`
353+
}
354+
355+
var balanceEntries []BalanceEntry
356+
for tokenKey, balance := range balances {
357+
if balance.Cmp(big.NewInt(0)) == 0 {
358+
continue
359+
}
360+
361+
var token TokenInfo
362+
token, err = TokenInfoStringToStruct(tokenKey)
363+
if err != nil {
364+
return err
365+
}
366+
367+
if token.OriginNetwork.Uint64() == uint64(l2NetworkID) {
368+
continue
369+
}
370+
371+
balanceEntries = append(balanceEntries, BalanceEntry{
372+
OriginNetwork: uint32(token.OriginNetwork.Uint64()),
373+
OriginTokenAddress: token.OriginTokenAddress,
374+
TotalSupply: balance.String(),
375+
})
376+
}
377+
378+
// Create the response structure
379+
response := struct {
380+
Root string `json:"root"`
381+
Balances []BalanceEntry `json:"balances"`
382+
}{
383+
Root: root.String(),
384+
Balances: balanceEntries,
385+
}
386+
387+
// Marshal to JSON with proper formatting
388+
jsonOutput, err := json.MarshalIndent(response, "", " ")
389+
if err != nil {
390+
return err
391+
}
392+
393+
fmt.Println(string(jsonOutput))
354394
return nil
355395
}
356396

@@ -371,7 +411,7 @@ func nullifierTree(args []string) error {
371411
return nil
372412
}
373413

374-
func nullifierAndBalanceTree(args []string) error {
414+
func nullifierAndBalanceTree() error {
375415
l2NetworkID := balanceTreeOptions.L2NetworkID
376416
bridgeAddress := common.HexToAddress(balanceTreeOptions.BridgeAddress)
377417

@@ -401,7 +441,7 @@ func nullifierAndBalanceTree(args []string) error {
401441
return err
402442
}
403443
log.Info().Msgf("Last LER count: %d", ler_count)
404-
balanceTreeRoot, err := computeBalanceTree(client, bridgeAddress, l2RawClaimsData, l2NetworkID, l2RawDepositsData)
444+
balanceTreeRoot, _, err := computeBalanceTree(client, bridgeAddress, l2RawClaimsData, l2NetworkID, l2RawDepositsData)
405445
if err != nil {
406446
return err
407447
}
@@ -432,7 +472,7 @@ func computeNullifierTree(rawClaims []byte) (common.Hash, error) {
432472
var root common.Hash
433473
for scanner.Scan() {
434474
claim := new(ulxly.UlxlyClaimEvent)
435-
err := json.Unmarshal(scanner.Bytes(), claim)
475+
err = json.Unmarshal(scanner.Bytes(), claim)
436476
if err != nil {
437477
return common.Hash{}, err
438478
}
@@ -456,29 +496,29 @@ func computeNullifierTree(rawClaims []byte) (common.Hash, error) {
456496
return root, nil
457497
}
458498

459-
func computeBalanceTree(client *ethclient.Client, bridgeAddress common.Address, l2RawClaims []byte, l2NetworkID uint32, l2RawDeposits []byte) (common.Hash, error) {
499+
func computeBalanceTree(client *ethclient.Client, bridgeAddress common.Address, l2RawClaims []byte, l2NetworkID uint32, l2RawDeposits []byte) (common.Hash, map[string]*big.Int, error) {
460500
buf := bytes.NewBuffer(l2RawClaims)
461501
scanner := bufio.NewScanner(buf)
462502
scannerBuf := make([]byte, 0)
463503
scanner.Buffer(scannerBuf, 1024*1024)
464504
bTree, err := NewBalanceTree()
465505
if err != nil {
466-
return common.Hash{}, err
506+
return common.Hash{}, nil, err
467507
}
468508
balances := make(map[string]*big.Int)
469509
for scanner.Scan() {
470510
l2Claim := new(ulxly.UlxlyClaimEvent)
471-
err := json.Unmarshal(scanner.Bytes(), l2Claim)
511+
err = json.Unmarshal(scanner.Bytes(), l2Claim)
472512
if err != nil {
473-
return common.Hash{}, err
513+
return common.Hash{}, nil, err
474514
}
475515
token := TokenInfo{
476516
OriginNetwork: big.NewInt(0).SetUint64(uint64(l2Claim.OriginNetwork)),
477517
OriginTokenAddress: l2Claim.OriginAddress,
478518
}
479519
isMessage, err := checkClaimCalldata(client, bridgeAddress, l2Claim.Raw.TxHash)
480520
if err != nil {
481-
return common.Hash{}, err
521+
return common.Hash{}, nil, err
482522
}
483523
if isMessage {
484524
token.OriginNetwork = big.NewInt(0)
@@ -499,7 +539,7 @@ func computeBalanceTree(client *ethclient.Client, bridgeAddress common.Address,
499539
l2Deposit := new(ulxly.UlxlyBridgeEvent)
500540
err := json.Unmarshal(l2Scanner.Bytes(), l2Deposit)
501541
if err != nil {
502-
return common.Hash{}, err
542+
return common.Hash{}, nil, err
503543
}
504544
token := TokenInfo{
505545
OriginNetwork: big.NewInt(0).SetUint64(uint64(l2Deposit.OriginNetwork)),
@@ -518,20 +558,20 @@ func computeBalanceTree(client *ethclient.Client, bridgeAddress common.Address,
518558
}
519559
token, err := TokenInfoStringToStruct(t)
520560
if err != nil {
521-
return common.Hash{}, err
561+
return common.Hash{}, nil, err
522562
}
523563
if token.OriginNetwork.Uint64() == uint64(l2NetworkID) {
524564
continue
525565
}
526566
root, err = bTree.UpdateBalanceTree(token, balance)
527567
if err != nil {
528-
return common.Hash{}, err
568+
return common.Hash{}, nil, err
529569
}
530570
log.Info().Msgf("New balanceTree leaf. OriginNetwork: %s, TokenAddress: %s, Balance: %s, Root: %s", token.OriginNetwork.String(), token.OriginTokenAddress.String(), balance.String(), root.String())
531571
}
532572
log.Info().Msgf("Final balanceTree root: %s", root.String())
533573

534-
return root, nil
574+
return root, balances, nil
535575
}
536576

537577
func rollupsExitRootProof(args []string) error {
@@ -2409,7 +2449,7 @@ or if it's actually an intermediate hash.`,
24092449
Short: "Compute the balance tree and the nullifier tree given the deposits and claims.",
24102450
Long: nullifierAndBalanceTreeUsage,
24112451
RunE: func(cmd *cobra.Command, args []string) error {
2412-
return nullifierAndBalanceTree(args)
2452+
return nullifierAndBalanceTree()
24132453
},
24142454
SilenceUsage: true,
24152455
}

cmd/wallet/wallet.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var WalletCmd = &cobra.Command{
4545
var err error
4646
var mnemonic string
4747
if mode == "inspect" {
48-
// in the case of inspect, we'll partse a mnemonic and then continue
48+
// in the case of inspect, we'll parse a mnemonic and then continue
4949
mnemonic, err = getFileOrFlag(inputMnemonicFile, inputMnemonic)
5050
if err != nil {
5151
return err
@@ -102,17 +102,16 @@ var WalletCmd = &cobra.Command{
102102
}
103103

104104
func getFileOrFlag(filename string, flag string) (string, error) {
105-
if filename != "" {
106-
filedata, err := os.ReadFile(filename)
107-
if err != nil {
108-
return "", fmt.Errorf("could not open the specified file %s. Got error %s", filename, err.Error())
109-
}
110-
return string(filedata), nil
111-
}
112-
if flag != "" {
105+
if filename == "" {
113106
return flag, nil
114107
}
115-
return "", fmt.Errorf("unable to determine flat or filename")
108+
109+
filedata, err := os.ReadFile(filename)
110+
if err != nil {
111+
return "", fmt.Errorf("failed to read file %s: %w", filename, err)
112+
}
113+
114+
return string(filedata), nil
116115
}
117116

118117
func init() {

doc/polycli_p2p_sensor.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ If no nodes.json file exists, it will be created.
2424

2525
```bash
2626
--api-port uint port API server will listen on (default 8080)
27+
--blocks-cache-ttl duration time to live for block cache entries (0 for no expiration) (default 10m0s)
2728
-b, --bootnodes string comma separated nodes used for bootstrapping
2829
--database string which database to persist data to, options are:
2930
- datastore (GCP Datastore)
@@ -38,13 +39,16 @@ If no nodes.json file exists, it will be created.
3839
-h, --help help for sensor
3940
--key string hex-encoded private key (cannot be set with --key-file)
4041
-k, --key-file string private key file (cannot be set with --key)
42+
--max-blocks int maximum blocks to track across all peers (0 for no limit) (default 1024)
4143
-D, --max-db-concurrency int maximum number of concurrent database operations to perform (increasing this
4244
will result in less chance of missing data but can significantly increase memory usage) (default 10000)
45+
--max-parents int maximum parent block hashes to track per peer (0 for no limit) (default 1024)
4346
-m, --max-peers int maximum number of peers to connect to (default 2000)
4447
--max-requests int maximum request IDs to track per peer (0 for no limit) (default 2048)
4548
--nat string NAT port mapping mechanism (any|none|upnp|pmp|pmp:<IP>|extip:<IP>) (default "any")
4649
-n, --network-id uint filter discovered nodes by this network ID
4750
--no-discovery disable P2P peer discovery
51+
--parents-cache-ttl duration time to live for parent hash cache entries (0 for no expiration) (default 5m0s)
4852
--port int TCP network listening port (default 30303)
4953
--pprof run pprof server
5054
--pprof-port uint port pprof runs on (default 6060)

0 commit comments

Comments
 (0)