Skip to content

Commit 24b9149

Browse files
authored
Blockscout multinet (#1398)
* blockscout urls and docs, run logs download in parallel and ignore local stuff * remove unused vars * blockscout docs * changelog
1 parent 2839080 commit 24b9149

File tree

17 files changed

+215
-63
lines changed

17 files changed

+215
-63
lines changed

book/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- [Mocking Services](framework/components/mocking.md)
2424
- [Copying Files](framework/copying_files.md)
2525
- [External Environment](framework/components/external.md)
26+
- [Troubleshooting](framework/components/troubleshooting.md)
2627
- [Secrets]()
2728
- [Observability Stack](framework/observability/observability_stack.md)
2829
- [Metrics](framework/observability/metrics.md)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Troubleshooting
2+
3+
## Can't run `anvil`, issue with `Rosetta`
4+
```
5+
2024/11/27 15:20:27 ⏳ Waiting for container id 79f8a68c07cc image: f4hrenh9it/foundry:latest. Waiting for: &{Port:8546 timeout:0x14000901278 PollInterval:100ms skipInternalCheck:false}
6+
2024/11/27 15:20:27 container logs (all exposed ports, [8546/tcp], were not mapped in 5s: port 8546/tcp is not mapped yet
7+
wait until ready: check target: retries: 1, port: "", last err: container exited with code 133):
8+
rosetta error: Rosetta is only intended to run on Apple Silicon with a macOS host using Virtualization.framework with Rosetta mode enabled
9+
```
10+
#### Solution
11+
12+
Update your docker to `Docker version 27.3.1, build ce12230`

book/src/framework/getting_started.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
- `Docker` [OrbStack](https://orbstack.dev/) or [Docker Desktop](https://www.docker.com/products/docker-desktop/), we recommend OrbStack (faster, smaller memory footprint)
55
- [Golang](https://go.dev/doc/install)
66

7+
Tested with
8+
```
9+
Docker version 27.3.1
10+
OrbStack Version: 1.8.2 (1080200)
11+
```
12+
713
## Test setup
814

915
To start writing tests create a directory for your project with `go.mod` and add a package

book/src/framework/observability/blockscout.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ To remove it, we also clean up all Blockscout databases to prevent stale data wh
1212
ctf bs down
1313
```
1414

15+
## Selecting Blockchain Node
16+
17+
By default, we connect to the first `anvil` node, but you can select the node explicitly
18+
```
19+
ctf bs -r http://host.docker.internal:8545 d
20+
ctf bs -r http://host.docker.internal:8555 d
21+
```
22+
1523
<div class="warning">
1624

1725
Blockscout isn’t ideal for local, ephemeral environments, as it won’t re-index blocks and transactions on test reruns. The easiest approach is to set up Blockscout first, initialize the test environment, switch to the [cache](../components/caching.md) config, and run tests without restarting RPC nodes.

framework/.changeset/v0.2.12.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Omit all local tooling container logs
2+
- Allow to connect Blockscout to any node

framework/cmd/blockscout.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ package main
33
import (
44
"fmt"
55
"github.com/smartcontractkit/chainlink-testing-framework/framework"
6+
"os"
67
"path/filepath"
78
)
89

9-
func blockscoutUp() error {
10+
func blockscoutUp(url string) error {
1011
framework.L.Info().Msg("Creating local Blockscout stack")
1112
if err := extractAllFiles("observability"); err != nil {
1213
return err
1314
}
15+
os.Setenv("BLOCKSCOUT_RPC_URL", url)
1416
err := runCommand("bash", "-c", fmt.Sprintf(`
1517
cd %s && \
1618
docker compose up -d
@@ -23,8 +25,9 @@ func blockscoutUp() error {
2325
return nil
2426
}
2527

26-
func blockscoutDown() error {
28+
func blockscoutDown(url string) error {
2729
framework.L.Info().Msg("Removing local Blockscout stack")
30+
os.Setenv("BLOCKSCOUT_RPC_URL", url)
2831
err := runCommand("bash", "-c", fmt.Sprintf(`
2932
cd %s && \
3033
docker compose down -v

framework/cmd/interactive.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ import (
1616
)
1717

1818
type nodeSetForm struct {
19-
Network string
20-
CLVersion string
21-
Nodes int
22-
Observability bool
23-
Blockscout bool
19+
Network string
20+
CLVersion string
21+
Nodes int
22+
Observability bool
23+
Blockscout bool
24+
BlockscoutRPCURL string
2425
}
2526

2627
func createComponentsFromForm(form *nodeSetForm) error {
@@ -83,7 +84,7 @@ func createComponentsFromForm(form *nodeSetForm) error {
8384
}
8485
switch form.Blockscout {
8586
case true:
86-
if err := blockscoutUp(); err != nil {
87+
if err := blockscoutUp(form.BlockscoutRPCURL); err != nil {
8788
return err
8889
}
8990
}
@@ -107,7 +108,7 @@ func cleanup(form *nodeSetForm) error {
107108
}
108109
switch form.Blockscout {
109110
case true:
110-
if err := blockscoutDown(); err != nil {
111+
if err := blockscoutDown(form.BlockscoutRPCURL); err != nil {
111112
return err
112113
}
113114
}
@@ -156,6 +157,13 @@ Docker Desktop (https://www.docker.com/products/docker-desktop/)
156157
huh.NewConfirm().
157158
Title("Do you need to spin up a Blockscout stack?").
158159
Value(&f.Blockscout),
160+
huh.NewSelect[string]().
161+
Title("To which blockchain node you want Blockscout to connect?").
162+
Options(
163+
huh.NewOption("Network 1", "http://host.docker.internal:8545"),
164+
huh.NewOption("Network 2", "http://host.docker.internal:8550"),
165+
).
166+
Value(&f.BlockscoutRPCURL),
159167
),
160168
)
161169

framework/cmd/main.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,31 +114,44 @@ func main() {
114114
Name: "blockscout",
115115
Aliases: []string{"bs"},
116116
Usage: "Controls local Blockscout stack",
117+
Flags: []cli.Flag{
118+
&cli.StringFlag{
119+
Name: "rpc",
120+
Aliases: []string{"r"},
121+
Usage: "RPC URL for blockchain node to index",
122+
Value: "http://host.docker.internal:8545",
123+
},
124+
},
117125
Subcommands: []*cli.Command{
118126
{
119127
Name: "up",
120128
Usage: "ctf bs up",
121129
Aliases: []string{"u"},
122130
Description: "Spins up Blockscout stack",
123-
Action: func(c *cli.Context) error { return blockscoutUp() },
131+
Action: func(c *cli.Context) error {
132+
return blockscoutUp(c.String("rpc"))
133+
},
124134
},
125135
{
126136
Name: "down",
127137
Usage: "ctf bs down",
128138
Aliases: []string{"d"},
129139
Description: "Removes Blockscout stack, wipes all Blockscout databases data",
130-
Action: func(c *cli.Context) error { return blockscoutDown() },
140+
Action: func(c *cli.Context) error {
141+
return blockscoutDown(c.String("rpc"))
142+
},
131143
},
132144
{
133145
Name: "reboot",
134146
Usage: "ctf bs reboot or ctf bs r",
135147
Aliases: []string{"r"},
136148
Description: "Reboots Blockscout stack",
137149
Action: func(c *cli.Context) error {
138-
if err := blockscoutDown(); err != nil {
150+
rpc := c.String("rpc")
151+
if err := blockscoutDown(rpc); err != nil {
139152
return err
140153
}
141-
return blockscoutUp()
154+
return blockscoutUp(rpc)
142155
},
143156
},
144157
},

framework/cmd/observability/blockscout/docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ services:
2828
- db:database
2929
environment:
3030
ETHEREUM_JSONRPC_VARIANT: 'geth'
31+
ETHEREUM_JSONRPC_HTTP_URL: ${BLOCKSCOUT_RPC_URL}
32+
ETHEREUM_JSONRPC_TRACE_URL: ${BLOCKSCOUT_RPC_URL}
3133

3234
visualizer:
3335
extends:

framework/components/simple_node_set/node_set.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,12 @@ func printURLs(out *Output) {
6262
if out == nil {
6363
return
6464
}
65-
httpURLs, p2pURLs, pgURLs := make([]string, 0), make([]string, 0), make([]string, 0)
65+
httpURLs, _, pgURLs := make([]string, 0), make([]string, 0), make([]string, 0)
6666
for _, n := range out.CLNodes {
6767
httpURLs = append(httpURLs, n.Node.HostURL)
6868
pgURLs = append(pgURLs, n.PostgreSQL.Url)
6969
}
7070
framework.L.Info().Any("UI", httpURLs).Send()
71-
framework.L.Debug().Any("P2P", p2pURLs).Send()
7271
framework.L.Debug().Any("DB", pgURLs).Send()
7372
}
7473

0 commit comments

Comments
 (0)