Skip to content

Commit e4d075d

Browse files
authored
Merge branch 'main' into tt-1741-performance-comparison-tool
2 parents 987fee9 + ed7d19c commit e4d075d

29 files changed

+465
-6
lines changed

lib/client/github.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ type GithubClient struct {
1717

1818
const WITHOUT_TOKEN = ""
1919

20+
// NewGithubClient creates a new instance of GithubClient, optionally authenticating with a personal access token.
21+
// This is useful for making authenticated requests to the GitHub API, helping to avoid rate limits.
2022
func NewGithubClient(token string) *GithubClient {
2123
// Optional: Authenticate with a personal access token if necessary
2224
// This is recommended to avoid rate limits for unauthenticated requests

lib/client/mockserver.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ func (em *MockserverClient) SetAnyValuePath(path string, v interface{}) error {
160160
return err
161161
}
162162

163+
// SetAnyValueResponse configures a mock server to return a specified value for a given path.
164+
// It ensures the path starts with a '/', sanitizes it, and logs the operation.
165+
// This function is useful for testing and simulating API responses in a controlled environment.
163166
func (em *MockserverClient) SetAnyValueResponse(path string, v interface{}) error {
164167
if !strings.HasPrefix(path, "/") {
165168
path = fmt.Sprintf("/%s", path)

lib/client/postgres.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ func NewPostgresConnector(cfg *PostgresConfig) (*PostgresConnector, error) {
5454
return &PostgresConnector{DB: db, Cfg: cfg}, nil
5555
}
5656

57+
// ConnectDB establishes a connection to a PostgreSQL database using the provided environment settings.
58+
// It returns a PostgresConnector instance or an error if the connection fails.
5759
func ConnectDB(nodeNum int, e *environment.Environment) (*PostgresConnector, error) {
5860
spl := strings.Split(e.URLs["chainlink_db"][nodeNum], ":")
5961
port := spl[len(spl)-1]

lib/client/rpc.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ func (m *RPCClient) BlockNumber() (int64, error) {
233233
return bn, nil
234234
}
235235

236+
// GethSetHead sets the Ethereum node's head to a specified block in the past.
237+
// This function is useful for testing and debugging by allowing developers to
238+
// manipulate the blockchain state to a previous block. It returns an error
239+
// if the operation fails.
236240
func (m *RPCClient) GethSetHead(blocksBack int) error {
237241
decimalLastBlock, err := m.BlockNumber()
238242
if err != nil {
@@ -274,6 +278,9 @@ type GethContainer struct {
274278
URL string
275279
}
276280

281+
// StartAnvil initializes and starts an Anvil container for Ethereum development.
282+
// It returns an AnvilContainer instance containing the container and its accessible URL.
283+
// This function is useful for developers needing a local Ethereum node for testing and development.
277284
func StartAnvil(params []string) (*AnvilContainer, error) {
278285
entryPoint := []string{"anvil", "--host", "0.0.0.0"}
279286
entryPoint = append(entryPoint, params...)

lib/docker/docker.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
const RetryAttempts = 3
1616
const defaultRyukImage = "testcontainers/ryuk:0.5.1"
1717

18+
// CreateNetwork initializes a new Docker network with a unique name.
19+
// It ensures no duplicate networks exist and returns the created network or an error if the operation fails.
1820
func CreateNetwork(l zerolog.Logger) (*tc.DockerNetwork, error) {
1921
uuidObj, _ := uuid.NewRandom()
2022
var networkName = fmt.Sprintf("network-%s", uuidObj.String())

lib/docker/test_env/besu_base.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,17 @@ type Besu struct {
4444
powSettings
4545
}
4646

47+
// WithTestInstance sets up the execution client for testing by assigning a test logger and the testing context.
48+
// This allows for better logging and error tracking during test execution.
4749
func (g *Besu) WithTestInstance(t *testing.T) ExecutionClient {
4850
g.l = logging.GetTestLogger(t)
4951
g.t = t
5052
return g
5153
}
5254

55+
// StartContainer initializes and starts a Besu container for Ethereum execution.
56+
// It configures network settings based on the Ethereum version and returns the
57+
// network configuration along with any errors encountered during the process.
5358
func (g *Besu) StartContainer() (blockchain.EVMNetwork, error) {
5459
var r *tc.ContainerRequest
5560
var err error
@@ -121,48 +126,69 @@ func (g *Besu) StartContainer() (blockchain.EVMNetwork, error) {
121126
return networkConfig, nil
122127
}
123128

129+
// GetInternalExecutionURL returns the internal execution URL for the Besu client.
130+
// It is used to retrieve the endpoint for executing transactions in Ethereum 2.0 networks,
131+
// ensuring compatibility with the Ethereum version in use.
124132
func (g *Besu) GetInternalExecutionURL() string {
125133
if g.GetEthereumVersion() == config_types.EthereumVersion_Eth1 {
126134
panic("eth1 node doesn't have an execution URL")
127135
}
128136
return g.InternalExecutionURL
129137
}
130138

139+
// GetExternalExecutionURL returns the external execution URL for the Besu instance.
140+
// It panics if the Ethereum version is Eth1, as Eth1 nodes do not support execution URLs.
131141
func (g *Besu) GetExternalExecutionURL() string {
132142
if g.GetEthereumVersion() == config_types.EthereumVersion_Eth1 {
133143
panic("eth1 node doesn't have an execution URL")
134144
}
135145
return g.ExternalExecutionURL
136146
}
137147

148+
// GetInternalHttpUrl returns the internal HTTP URL of the Besu client.
149+
// This URL is essential for establishing communication with the Besu node in a private network setup.
138150
func (g *Besu) GetInternalHttpUrl() string {
139151
return g.InternalHttpUrl
140152
}
141153

154+
// GetInternalWsUrl returns the internal WebSocket URL for the Besu client.
155+
// This URL is essential for establishing WebSocket connections to the Besu node for real-time data and event subscriptions.
142156
func (g *Besu) GetInternalWsUrl() string {
143157
return g.InternalWsUrl
144158
}
145159

160+
// GetExternalHttpUrl returns the external HTTP URL of the Besu client.
161+
// This URL is used to interact with the Besu node from external applications or services.
146162
func (g *Besu) GetExternalHttpUrl() string {
147163
return g.ExternalHttpUrl
148164
}
149165

166+
// GetExternalWsUrl returns the external WebSocket URL for the Besu client.
167+
// This URL is essential for connecting to the Besu node from external services or clients.
150168
func (g *Besu) GetExternalWsUrl() string {
151169
return g.ExternalWsUrl
152170
}
153171

172+
// GetContainerName returns the name of the container associated with the Besu instance.
173+
// This function is useful for identifying and managing the container in a Docker environment.
154174
func (g *Besu) GetContainerName() string {
155175
return g.ContainerName
156176
}
157177

178+
// GetContainer returns a pointer to the container associated with the Besu instance.
179+
// This function is useful for accessing the container's properties and methods in other operations.
158180
func (g *Besu) GetContainer() *tc.Container {
159181
return &g.Container
160182
}
161183

184+
// GetEthereumVersion returns the current Ethereum version of the Besu instance.
185+
// This information is crucial for determining the appropriate container configuration and consensus mechanism.
162186
func (g *Besu) GetEthereumVersion() config_types.EthereumVersion {
163187
return g.ethereumVersion
164188
}
165189

190+
// WaitUntilChainIsReady blocks until the Ethereum chain is ready for operations.
191+
// It is useful for ensuring that the execution client has fully synchronized with the network before proceeding with further actions.
166192
func (g *Besu) WaitUntilChainIsReady(ctx context.Context, waitTime time.Duration) error {
167193
if g.GetEthereumVersion() == config_types.EthereumVersion_Eth1 {
168194
return nil
@@ -171,7 +197,10 @@ func (g *Besu) WaitUntilChainIsReady(ctx context.Context, waitTime time.Duration
171197
return waitForFirstBlock.WaitUntilReady(ctx, *g.GetContainer())
172198
}
173199

174-
func (g *Besu) GethConsensusMechanism() ConsensusMechanism {
200+
// GetConsensusMechanism returns the consensus mechanism used by the Besu instance.
201+
// It identifies whether the Ethereum version is Eth1 or not, returning either Proof of Authority (PoA)
202+
// or Proof of Stake (PoS) accordingly. This is useful for understanding the network's validation method.
203+
func (g *Besu) GetConsensusMechanism() ConsensusMechanism {
175204
if g.GetEthereumVersion() == config_types.EthereumVersion_Eth1 {
176205
return ConsensusMechanism_PoA
177206
}

lib/docker/test_env/env_component.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ type EnvComponent struct {
3333

3434
type EnvComponentOption = func(c *EnvComponent)
3535

36+
// WithContainerName sets the container name for an EnvComponent.
37+
// It allows customization of the container's identity, enhancing clarity
38+
// and organization in containerized environments.
3639
func WithContainerName(name string) EnvComponentOption {
3740
return func(c *EnvComponent) {
3841
if name != "" {
@@ -41,6 +44,9 @@ func WithContainerName(name string) EnvComponentOption {
4144
}
4245
}
4346

47+
// WithStartupTimeout sets a custom startup timeout for an EnvComponent.
48+
// This option allows users to specify how long to wait for the component to start
49+
// before timing out, enhancing control over component initialization.
4450
func WithStartupTimeout(timeout time.Duration) EnvComponentOption {
4551
return func(c *EnvComponent) {
4652
if timeout != 0 {
@@ -49,6 +55,9 @@ func WithStartupTimeout(timeout time.Duration) EnvComponentOption {
4955
}
5056
}
5157

58+
// WithContainerImageWithVersion sets the container image and version for an EnvComponent.
59+
// It splits the provided image string by ':' and assigns the values accordingly.
60+
// This function is useful for configuring specific container images in a deployment.
5261
func WithContainerImageWithVersion(imageWithVersion string) EnvComponentOption {
5362
return func(c *EnvComponent) {
5463
split := strings.Split(imageWithVersion, ":")
@@ -59,6 +68,8 @@ func WithContainerImageWithVersion(imageWithVersion string) EnvComponentOption {
5968
}
6069
}
6170

71+
// WithLogLevel sets the logging level for an environment component.
72+
// It allows customization of log verbosity, enhancing debugging and monitoring capabilities.
6273
func WithLogLevel(logLevel string) EnvComponentOption {
6374
return func(c *EnvComponent) {
6475
if logLevel != "" {
@@ -67,28 +78,38 @@ func WithLogLevel(logLevel string) EnvComponentOption {
6778
}
6879
}
6980

81+
// WithPostStartsHooks sets the PostStarts hooks for an EnvComponent.
82+
// This allows users to define custom actions that should occur after the component starts.
7083
func WithPostStartsHooks(hooks ...tc.ContainerHook) EnvComponentOption {
7184
return func(c *EnvComponent) {
7285
c.PostStartsHooks = hooks
7386
}
7487
}
7588

89+
// WithPostStopsHooks sets the PostStops hooks for an EnvComponent.
90+
// This allows users to define custom actions that should occur after the component stops.
7691
func WithPostStopsHooks(hooks ...tc.ContainerHook) EnvComponentOption {
7792
return func(c *EnvComponent) {
7893
c.PostStopsHooks = hooks
7994
}
8095
}
8196

97+
// WithPreTerminatesHooks sets the pre-termination hooks for an EnvComponent.
98+
// This allows users to define custom behavior that should occur before the component is terminated.
8299
func WithPreTerminatesHooks(hooks ...tc.ContainerHook) EnvComponentOption {
83100
return func(c *EnvComponent) {
84101
c.PreTerminatesHooks = hooks
85102
}
86103
}
87104

105+
// SetDefaultHooks initializes the default hooks for the environment component.
106+
// This function is useful for ensuring that the component has a consistent starting state before further configuration.
88107
func (ec *EnvComponent) SetDefaultHooks() {
89108
// no default hooks
90109
}
91110

111+
// GetImageWithVersion returns the container image name combined with its version.
112+
// This function is useful for generating a complete image identifier needed for container requests.
92113
func (ec *EnvComponent) GetImageWithVersion() string {
93114
return fmt.Sprintf("%s:%s", ec.ContainerImage, ec.ContainerVersion)
94115
}

lib/docker/test_env/erigon_base.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,17 @@ type Erigon struct {
3636
posContainerSettings
3737
}
3838

39+
// WithTestInstance sets up the execution client with a test logger and test context.
40+
// This is useful for running tests that require a specific logging setup and context.
3941
func (g *Erigon) WithTestInstance(t *testing.T) ExecutionClient {
4042
g.l = logging.GetTestLogger(t)
4143
g.t = t
4244
return g
4345
}
4446

47+
// StartContainer initializes and starts an Erigon container for Ethereum execution.
48+
// It configures network settings based on the Ethereum version and returns the
49+
// blockchain network configuration along with any errors encountered during the process.
4550
func (g *Erigon) StartContainer() (blockchain.EVMNetwork, error) {
4651
var r *tc.ContainerRequest
4752
var err error
@@ -105,48 +110,69 @@ func (g *Erigon) StartContainer() (blockchain.EVMNetwork, error) {
105110
return networkConfig, nil
106111
}
107112

113+
// GetInternalExecutionURL returns the internal execution URL for the Erigon client.
114+
// It is used to retrieve the execution layer's endpoint, essential for connecting to the Ethereum network.
115+
// If the Ethereum version is Eth1, it panics as Eth1 nodes do not support execution URLs.
108116
func (g *Erigon) GetInternalExecutionURL() string {
109117
if g.GetEthereumVersion() == config_types.EthereumVersion_Eth1 {
110118
panic("eth1 node doesn't have an execution URL")
111119
}
112120
return g.InternalExecutionURL
113121
}
114122

123+
// GetExternalExecutionURL returns the external execution URL for the Erigon instance.
124+
// It panics if the Ethereum version is Eth1, as Eth1 nodes do not support execution URLs.
115125
func (g *Erigon) GetExternalExecutionURL() string {
116126
if g.GetEthereumVersion() == config_types.EthereumVersion_Eth1 {
117127
panic("eth1 node doesn't have an execution URL")
118128
}
119129
return g.ExternalExecutionURL
120130
}
121131

132+
// GetInternalHttpUrl returns the internal HTTP URL of the Erigon client.
133+
// This URL is used to connect to the Erigon execution layer for internal communications.
122134
func (g *Erigon) GetInternalHttpUrl() string {
123135
return g.InternalHttpUrl
124136
}
125137

138+
// GetInternalWsUrl returns the internal WebSocket URL for the Erigon client.
139+
// This URL is used to establish a WebSocket connection for real-time communication with the Erigon node.
126140
func (g *Erigon) GetInternalWsUrl() string {
127141
return g.InternalWsUrl
128142
}
129143

144+
// GetExternalHttpUrl returns the external HTTP URL for the Erigon client.
145+
// This URL is used to interact with the Erigon execution layer over HTTP.
130146
func (g *Erigon) GetExternalHttpUrl() string {
131147
return g.ExternalHttpUrl
132148
}
133149

150+
// GetExternalWsUrl returns the external WebSocket URL for the Erigon client.
151+
// This URL is essential for connecting to the Erigon node for real-time data and event subscriptions.
134152
func (g *Erigon) GetExternalWsUrl() string {
135153
return g.ExternalWsUrl
136154
}
137155

156+
// GetContainerName returns the name of the container associated with the Erigon instance.
157+
// This function is useful for identifying and managing the container in a Docker environment.
138158
func (g *Erigon) GetContainerName() string {
139159
return g.ContainerName
140160
}
141161

162+
// GetContainer returns a pointer to the Container associated with the Erigon instance.
163+
// This function is useful for accessing the container's properties and methods in a structured manner.
142164
func (g *Erigon) GetContainer() *tc.Container {
143165
return &g.Container
144166
}
145167

168+
// GetEthereumVersion returns the current Ethereum version of the Erigon instance.
169+
// This information is essential for determining the appropriate execution URLs and consensus mechanisms.
146170
func (g *Erigon) GetEthereumVersion() config_types.EthereumVersion {
147171
return g.ethereumVersion
148172
}
149173

174+
// WaitUntilChainIsReady blocks until the Ethereum chain is ready for use, waiting for the first block to be built.
175+
// It returns an error if the chain does not become ready within the specified wait time.
150176
func (g *Erigon) WaitUntilChainIsReady(ctx context.Context, waitTime time.Duration) error {
151177
if g.GetEthereumVersion() == config_types.EthereumVersion_Eth1 {
152178
return nil
@@ -155,7 +181,9 @@ func (g *Erigon) WaitUntilChainIsReady(ctx context.Context, waitTime time.Durati
155181
return waitForFirstBlock.WaitUntilReady(ctx, *g.GetContainer())
156182
}
157183

158-
func (g *Erigon) GethConsensusMechanism() ConsensusMechanism {
184+
// GetConsensusMechanism returns the consensus mechanism used by the Erigon instance.
185+
// It identifies whether the Ethereum version is Eth1 (Proof of Work) or a later version (Proof of Stake).
186+
func (g *Erigon) GetConsensusMechanism() ConsensusMechanism {
159187
if g.GetEthereumVersion() == config_types.EthereumVersion_Eth1 {
160188
return ConsensusMechanism_PoW
161189
}

lib/docker/test_env/eth2_init_helpers.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ type AfterGenesisHelper struct {
2929
posContainerSettings
3030
}
3131

32+
// NewInitHelper initializes a new AfterGenesisHelper instance with the provided chain configuration and directory paths.
33+
// It sets up necessary environment components and options, facilitating the management of post-genesis operations in a blockchain network.
3234
func NewInitHelper(chainConfig config.EthereumChainConfig, generatedDataHostDir, generatedDataContainerDir string, opts ...EnvComponentOption) *AfterGenesisHelper {
3335
g := &AfterGenesisHelper{
3436
EnvComponent: EnvComponent{
@@ -47,12 +49,16 @@ func NewInitHelper(chainConfig config.EthereumChainConfig, generatedDataHostDir,
4749
return g
4850
}
4951

52+
// WithTestInstance sets up the AfterGenesisHelper for testing by assigning a logger and test context.
53+
// This allows for better logging and error tracking during test execution.
5054
func (g *AfterGenesisHelper) WithTestInstance(t *testing.T) *AfterGenesisHelper {
5155
g.l = logging.GetTestLogger(t)
5256
g.t = t
5357
return g
5458
}
5559

60+
// StartContainer initializes and starts the After Genesis Helper container.
61+
// It handles container requests and logs the startup process, ensuring the container is ready for use.
5662
func (g *AfterGenesisHelper) StartContainer() error {
5763
r, err := g.getContainerRequest(g.Networks)
5864
if err != nil {

lib/docker/test_env/eth_common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type ExecutionClient interface {
4242
GetExternalHttpUrl() string
4343
GetExternalWsUrl() string
4444
GetEthereumVersion() config_types.EthereumVersion
45-
GethConsensusMechanism() ConsensusMechanism
45+
GetConsensusMechanism() ConsensusMechanism
4646
WaitUntilChainIsReady(ctx context.Context, waitTime time.Duration) error
4747
WithTestInstance(t *testing.T) ExecutionClient
4848
}

0 commit comments

Comments
 (0)