-
Notifications
You must be signed in to change notification settings - Fork 44
fix(ton): use ctf network, with unique volumes #2393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
712b945
b12fa52
6157268
120e3ae
25bfb3f
d9ef70a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,12 +3,11 @@ package blockchain | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "context" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "fmt" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "strconv" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "time" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/docker/docker/api/types/container" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/docker/go-connections/nat" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/testcontainers/testcontainers-go" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/testcontainers/testcontainers-go/network" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/testcontainers/testcontainers-go/wait" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/smartcontractkit/chainlink-testing-framework/framework" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -23,14 +22,8 @@ const ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| defaultTonHTTPServerPort = "8000" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| defaultLiteServerPort = "40000" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| defaultLiteServerPublicKey = "E7XwFSQzNkcRepUC23J2nRpASXpnsEKmyyHYV4u/FZY=" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| liteServerPortOffset = 100 // arbitrary offset for lite server port | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type portMapping struct { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| HTTPServer string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LiteServer string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func defaultTon(in *Input) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if in.Image == "" { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| in.Image = "ghcr.io/neodix42/mylocalton-docker:latest" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -43,15 +36,7 @@ func defaultTon(in *Input) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func newTon(ctx context.Context, in *Input) (*Output, error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| defaultTon(in) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| base, err := strconv.Atoi(in.Port) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return nil, fmt.Errorf("invalid base port %s: %w", in.Port, err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ports := &portMapping{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| HTTPServer: in.Port, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LiteServer: strconv.Itoa(base + liteServerPortOffset), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| containerName := framework.DefaultTCName("ton-genesis") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| baseEnv := map[string]string{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "GENESIS": "true", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -72,31 +57,20 @@ func newTon(ctx context.Context, in *Input) (*Output, error) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| n, err := network.New(ctx, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| network.WithAttachable(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| network.WithLabels(framework.DefaultTCLabels()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return nil, fmt.Errorf("failed to create network: %w", err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| networkName := n.Name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| req := testcontainers.ContainerRequest{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Image: in.Image, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AlwaysPullImage: in.PullImage, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Name: framework.DefaultTCName("ton-genesis"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Name: containerName, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ExposedPorts: []string{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fmt.Sprintf("%s:%s/tcp", ports.HTTPServer, defaultTonHTTPServerPort), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fmt.Sprintf("%s:%s/tcp", ports.LiteServer, defaultLiteServerPort), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "40003/udp", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "40002/tcp", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "40001/udp", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fmt.Sprintf("%s/tcp", defaultTonHTTPServerPort), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fmt.Sprintf("%s/tcp", defaultLiteServerPort), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Networks: []string{framework.DefaultNetworkName}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| NetworkAliases: map[string][]string{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| framework.DefaultNetworkName: {containerName}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Networks: []string{networkName}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| NetworkAliases: map[string][]string{networkName: {"genesis"}}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Labels: framework.DefaultTCLabels(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Env: finalEnv, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Labels: framework.DefaultTCLabels(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Env: finalEnv, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| WaitingFor: wait.ForExec([]string{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "/usr/local/bin/lite-client", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "-a", fmt.Sprintf("127.0.0.1:%s", defaultLiteServerPort), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -105,15 +79,29 @@ func newTon(ctx context.Context, in *Input) (*Output, error) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }).WithStartupTimeout(2 * time.Minute), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Mounts: testcontainers.ContainerMounts{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Source: testcontainers.GenericVolumeMountSource{Name: fmt.Sprintf("shared-data-%s", networkName)}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Source: testcontainers.GenericVolumeMountSource{Name: fmt.Sprintf("ton-data-%s", containerName)}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Target: "/usr/share/data", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Source: testcontainers.GenericVolumeMountSource{Name: fmt.Sprintf("ton-db-%s", networkName)}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Source: testcontainers.GenericVolumeMountSource{Name: fmt.Sprintf("ton-db-%s", containerName)}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Target: "/var/ton-work/db", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| HostConfigModifier: func(h *container.HostConfig) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| h.PortBindings = nat.PortMap{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| nat.Port(fmt.Sprintf("%s/tcp", defaultTonHTTPServerPort)): []nat.PortBinding{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| HostIP: "0.0.0.0", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| HostPort: in.Port, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| nat.Port(fmt.Sprintf("%s/tcp", defaultLiteServerPort)): []nat.PortBinding{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| HostIP: "0.0.0.0", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| HostPort: "", // Docker assigns a dynamic available port | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+91
to
+104
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| h.PortBindings = nat.PortMap{ | |
| nat.Port(fmt.Sprintf("%s/tcp", defaultTonHTTPServerPort)): []nat.PortBinding{ | |
| { | |
| HostIP: "0.0.0.0", | |
| HostPort: in.Port, | |
| }, | |
| }, | |
| nat.Port(fmt.Sprintf("%s/tcp", defaultLiteServerPort)): []nat.PortBinding{ | |
| { | |
| HostIP: "0.0.0.0", | |
| HostPort: "", // Docker assigns a dynamic available port | |
| }, | |
| }, | |
| } | |
| if h.PortBindings == nil { | |
| h.PortBindings = nat.PortMap{} | |
| } | |
| httpPort := nat.Port(fmt.Sprintf("%s/tcp", defaultTonHTTPServerPort)) | |
| lsPort := nat.Port(fmt.Sprintf("%s/tcp", defaultLiteServerPort)) | |
| h.PortBindings[httpPort] = []nat.PortBinding{ | |
| { | |
| HostIP: "0.0.0.0", | |
| HostPort: in.Port, | |
| }, | |
| } | |
| h.PortBindings[lsPort] = []nat.PortBinding{ | |
| { | |
| HostIP: "0.0.0.0", | |
| HostPort: "", // Docker assigns a dynamic available port | |
| }, | |
| } |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Output.ContainerName previously reflected the actual container name returned by Docker via c.Name(ctx). Returning the requested name (containerName) is a behavior change and can break callers that rely on the real name (including Docker's leading '/' formatting). Consider restoring name, err := c.Name(ctx) for Output.ContainerName, while still using containerName exclusively for network aliasing/internal DNS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting
HostPortto an empty string in Docker port bindings can be rejected by the Docker API (it typically expects a numeric string). To reliably request an ephemeral host port, either omit the LiteServer entry fromPortBindingsentirely (and rely onExposedPorts+MappedPort), or set the host port explicitly to "0" (equivalent to-p 0:40000).