Skip to content

Commit 76e328b

Browse files
committed
fix(evm): stop creating a docker network the node never uses
The handler created a network, joined the besu container to it, and left it behind. Nothing needed it: the FSC nodes are host processes and forge runs on the host, so everything reaches the node over its published port on 127.0.0.1. The container joins the default bridge instead, and there is nothing left to clean up. Its name was wrong in a way worth recording. It came from the root directory, and every suite passes ./testdata, so the name was the string "testdata" for all of them. The comment claimed that kept parallel runs apart when it did the opposite: the two evm suites shared one network and one besu-testdata container, and startup force-removes a container by that name, so a second run would kill the first. The container is named after its reserved port now, which is unique by construction. Reported by adecaro on #2159. Signed-off-by: atharrva01 <atharvaborade568@gmail.com>
1 parent cccc40a commit 76e328b

3 files changed

Lines changed: 16 additions & 31 deletions

File tree

integration/nwo/token/evm/besu.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ const DefaultChainID int64 = 1337
4141
type BesuConfig struct {
4242
// Image is the container image; DefaultBesuImage when empty.
4343
Image string
44-
// NetworkID is the docker network the container joins, so FSC nodes can reach it.
45-
NetworkID string
4644
// Name is the container name.
4745
Name string
4846
// Port is the host port the JSON-RPC endpoint is published on.
@@ -134,9 +132,9 @@ func StartBesu(ctx context.Context, cfg BesuConfig) (*Besu, error) {
134132
}},
135133
},
136134
},
137-
NetworkingConfig: &network.NetworkingConfig{
138-
EndpointsConfig: map[string]*network.EndpointSettings{cfg.NetworkID: {}},
139-
},
135+
// No NetworkingConfig: the container joins docker's default bridge. Everything that talks to
136+
// this node does so over the published port on 127.0.0.1 (the FSC nodes are host processes and
137+
// forge runs on the host), so a dedicated network would be created, joined, and never used.
140138
})
141139
if err != nil {
142140
return nil, errors.Wrap(err, "evm nwo: failed to create the besu container")

integration/nwo/token/evm/besu_deploy_test.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,15 @@ func requireBesuTooling(t *testing.T) {
3838
}
3939
}
4040

41-
// startTestBesu boots a node on its own docker network and cleans both up afterwards.
41+
// startTestBesu boots a node and removes the container afterwards. There is no docker network to
42+
// create or clean up: the node is reached over its published port like everything else here.
4243
func startTestBesu(t *testing.T, name string, port int) *Besu {
4344
t.Helper()
4445
requireBesuTooling(t)
4546

46-
d, err := docker.GetInstance()
47-
require.NoError(t, err)
48-
49-
networkID := name + "-net"
50-
// A leftover network from an interrupted run would otherwise fail the create.
51-
_ = exec.Command("docker", "network", "rm", networkID).Run()
52-
require.NoError(t, d.CreateNetwork(networkID))
53-
t.Cleanup(func() { _ = exec.Command("docker", "network", "rm", networkID).Run() })
54-
5547
_ = exec.Command("docker", "rm", "-f", name).Run()
5648
node, err := StartBesu(context.Background(), BesuConfig{
57-
NetworkID: networkID, Name: name, Port: port, StartTimeout: 3 * time.Minute,
49+
Name: name, Port: port, StartTimeout: 3 * time.Minute,
5850
})
5951
require.NoError(t, err)
6052
t.Cleanup(func() { _ = node.Stop(context.Background()) })

integration/nwo/token/evm/nwo.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import (
1010
"context"
1111
"math/big"
1212
"path/filepath"
13+
"strconv"
1314
"time"
1415

1516
math3 "github.com/IBM/mathlib"
1617
api2 "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/api"
17-
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/common/docker"
1818
sfcnode "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc/node"
1919
"github.com/onsi/gomega"
2020

@@ -79,8 +79,6 @@ type NetworkHandler struct {
7979
// layer rather than the chain, so it is delegated rather than reimplemented. The backend it is
8080
// given does nothing: namespace preparation on EVM is the contract deployment below.
8181
materials *tfabric.NetworkHandler
82-
83-
networkID string
8482
}
8583

8684
// noopBackend satisfies the fabric handler's backend so the token-level generation can be reused
@@ -221,21 +219,18 @@ func (p *NetworkHandler) startNode(tms *topology2.TMS) *Besu {
221219
}
222220

223221
ctx := p.TokenPlatform.GetContext()
224-
d, err := docker.GetInstance()
225-
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "docker is required to run an EVM network")
226222

227-
// One docker network per test network, named after its root directory so parallel runs do not
228-
// collide. Creating it is idempotent from this handler's point of view: another platform may have
229-
// created it already.
230-
p.networkID = filepath.Base(ctx.RootDir())
231-
_ = d.CreateNetwork(p.networkID)
223+
// The container is named after the port it publishes rather than after the root directory. Every
224+
// suite passes "./testdata", so a name derived from it is the same string for all of them: the two
225+
// evm suites would fight over one container instead of getting one each. The reserved port is
226+
// unique by construction, which is exactly the property the name needs.
227+
port := int(ctx.ReservePort())
232228

233229
node, err := StartBesu(context.Background(), BesuConfig{
234-
Image: p.Image,
235-
NetworkID: p.networkID,
236-
Name: "besu-" + p.networkID,
237-
Port: int(ctx.ReservePort()),
238-
ChainID: p.ChainID,
230+
Image: p.Image,
231+
Name: "besu-" + strconv.Itoa(port),
232+
Port: port,
233+
ChainID: p.ChainID,
239234
})
240235
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "failed to start the EVM node")
241236

0 commit comments

Comments
 (0)