Skip to content

Commit 2b1c79c

Browse files
Harmonize YML internal variables to proper case (#744)
1 parent 003929d commit 2b1c79c

File tree

7 files changed

+241
-24
lines changed

7 files changed

+241
-24
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file.
1616
- Compute alive workers metrics in `WorkerService#updateMetrics` scheduled job. (#739)
1717
- Fix Spring Security deprecations after Spring Boot 3.3.8 upgrade. (#740)
1818
- Remove code related to reopen PoCo feature in `IexecHubService` and `TaskUpdateManager`. (#743)
19+
- Harmonize YML internal variables to proper case. (#744)
1920

2021
### Breaking API changes
2122

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ You can configure the _iExec Core Scheduler_ with the following properties:
3434
| `IEXEC_WORKERS_WHITELIST` | List of worker addresses allowed to connect to the _iExec Core Scheduler_. | String | |
3535
| `IEXEC_CORE_WALLET_PATH` | Path to the wallet of the server. | String | `./src/main/resources/wallet/encrypted-wallet_scheduler.json` |
3636
| `IEXEC_CORE_WALLET_PASSWORD` | Password to unlock the wallet of the server. | String | `whatever` |
37-
| `IEXEC_PRIVATE_CHAIN_ADDRESS` | Private URL to connect to the blockchain node. | URL | `http://localhost:8545` |
37+
| `IEXEC_BLOCKCHAIN_NODE_ADDRESS` | Private URL to connect to the blockchain node. | URL | `http://localhost:8545` |
3838
| `POOL_ADDRESS` | On-chain address of the workerpool managed by the current _iExec Core Scheduler_. | String | `0x365E7BABAa85eC61Dffe5b520763062e6C29dA27` |
3939
| `IEXEC_START_BLOCK_NUMBER` | Subscribe to new deal events from a specific block number. | Positive integer | `0` |
4040
| `IEXEC_GAS_PRICE_MULTIPLIER` | Transactions will be sent with `networkGasPrice * gasPriceMultiplier`. | Float | `1.0` |

src/main/java/com/iexec/core/chain/ChainConfig.java

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2024 IEXEC BLOCKCHAIN TECH
2+
* Copyright 2020-2025 IEXEC BLOCKCHAIN TECH
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,45 +16,66 @@
1616

1717
package com.iexec.core.chain;
1818

19+
import com.iexec.commons.poco.chain.validation.ValidNonZeroEthereumAddress;
20+
import jakarta.validation.constraints.NotEmpty;
21+
import jakarta.validation.constraints.NotNull;
22+
import jakarta.validation.constraints.Positive;
23+
import jakarta.validation.constraints.PositiveOrZero;
1924
import lombok.AllArgsConstructor;
2025
import lombok.Getter;
2126
import lombok.NoArgsConstructor;
27+
import org.hibernate.validator.constraints.URL;
28+
import org.hibernate.validator.constraints.time.DurationMax;
29+
import org.hibernate.validator.constraints.time.DurationMin;
2230
import org.springframework.beans.factory.annotation.Value;
2331
import org.springframework.stereotype.Component;
32+
import org.springframework.validation.annotation.Validated;
2433

2534
import java.time.Duration;
2635

2736
@Component
2837
@Getter
2938
@AllArgsConstructor
3039
@NoArgsConstructor
40+
@Validated
3141
public class ChainConfig {
3242

3343
@Value("#{publicChainConfig.chainId}")
44+
@Positive(message = "Chain id must be greater than 0")
45+
@NotNull(message = "Chain id must not be null")
3446
private int chainId;
3547

3648
@Value("#{publicChainConfig.sidechain}")
37-
private boolean isSidechain;
49+
private boolean sidechain;
3850

3951
@Value("#{publicChainConfig.iexecHubContractAddress}")
52+
@ValidNonZeroEthereumAddress(message = "Hub address must be a valid non zero Ethereum address")
4053
private String hubAddress;
4154

4255
@Value("#{publicChainConfig.blockTime}")
56+
@DurationMin(millis = 100, message = "Block time must be greater than 100ms")
57+
@DurationMax(seconds = 20, message = "Block time must be less than 20s")
58+
@NotNull(message = "Block time must not be null")
4359
private Duration blockTime;
4460

45-
@Value("${chain.privateAddress}")
46-
private String privateChainAddress;
61+
@Value("${chain.node-address}")
62+
@URL(message = "Node address must be a valid URL")
63+
@NotEmpty(message = "Node address must not be empty")
64+
private String nodeAddress;
4765

48-
@Value("${chain.poolAddress}")
66+
@Value("${chain.pool-address}")
4967
private String poolAddress;
5068

51-
@Value("${chain.startBlockNumber}")
69+
@Value("${chain.start-block-number}")
70+
@PositiveOrZero(message = "Start Block Number must be greater or equal to 0")
5271
private long startBlockNumber;
5372

54-
@Value("${chain.gasPriceMultiplier}")
73+
@Value("${chain.gas-price-multiplier}")
74+
@Positive(message = "Gas price multiplier must be greater than 0")
5575
private float gasPriceMultiplier;
5676

57-
@Value("${chain.gasPriceCap}")
77+
@Value("${chain.gas-price-cap}")
78+
@PositiveOrZero(message = "Gas price cap must be greater or equal to 0")
5879
private long gasPriceCap;
5980

6081
}

src/main/java/com/iexec/core/chain/Web3jService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 IEXEC BLOCKCHAIN TECH
2+
* Copyright 2020-2025 IEXEC BLOCKCHAIN TECH
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,7 +25,7 @@ public class Web3jService extends Web3jAbstractService {
2525
public Web3jService(ChainConfig chainConfig) {
2626
super(
2727
chainConfig.getChainId(),
28-
chainConfig.getPrivateChainAddress(),
28+
chainConfig.getNodeAddress(),
2929
chainConfig.getBlockTime(),
3030
chainConfig.getGasPriceMultiplier(),
3131
chainConfig.getGasPriceCap(),

src/main/resources/application.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,24 @@ cron:
3838
result-upload: 30000 # 30s
3939

4040
workers:
41-
askForReplicatePeriod: ${IEXEC_ASK_REPLICATE_PERIOD:5000}
42-
requiredWorkerVersion: ${IEXEC_CORE_REQUIRED_WORKER_VERSION:} #leave empty will allow any worker version
41+
ask-for-replicate-period: ${IEXEC_ASK_REPLICATE_PERIOD:5000}
42+
required-worker-version: ${IEXEC_CORE_REQUIRED_WORKER_VERSION:} #leave empty will allow any worker version
4343
# the whitelist format should be as follow (comma separated on one or multiple lines:
4444
# whitelist: ${IEXEC_WHITELIST:address1,
4545
# address2,
4646
# address3}
4747
whitelist: ${IEXEC_WORKERS_WHITELIST:}
4848

4949
wallet:
50-
encryptedFilePath: ${IEXEC_CORE_WALLET_PATH:./src/main/resources/wallet/encrypted-wallet_scheduler.json}
50+
encrypted-file-path: ${IEXEC_CORE_WALLET_PATH:./src/main/resources/wallet/encrypted-wallet_scheduler.json}
5151
password: ${IEXEC_CORE_WALLET_PASSWORD:whatever}
5252

5353
chain:
54-
privateAddress: ${IEXEC_PRIVATE_CHAIN_ADDRESS:http://localhost:8545}
55-
poolAddress: ${POOL_ADDRESS:0x365E7BABAa85eC61Dffe5b520763062e6C29dA27}
56-
startBlockNumber: ${IEXEC_START_BLOCK_NUMBER:0}
57-
gasPriceMultiplier: ${IEXEC_GAS_PRICE_MULTIPLIER:1.0} # txs will be sent with networkGasPrice*gasPriceMultiplier, 4.0 means super fast
58-
gasPriceCap: ${IEXEC_GAS_PRICE_CAP:22000000000} #in Wei, will be used for txs if networkGasPrice*gasPriceMultiplier > gasPriceCap
54+
node-address: ${IEXEC_BLOCKCHAIN_NODE_ADDRESS:http://localhost:8545}
55+
pool-address: ${POOL_ADDRESS:0x365E7BABAa85eC61Dffe5b520763062e6C29dA27}
56+
start-block-number: ${IEXEC_START_BLOCK_NUMBER:0}
57+
gas-price-multiplier: ${IEXEC_GAS_PRICE_MULTIPLIER:1.0} # txs will be sent with networkGasPrice*gasPriceMultiplier, 4.0 means super fast
58+
gas-price-cap: ${IEXEC_GAS_PRICE_CAP:22000000000} #in Wei, will be used for txs if networkGasPrice*gasPriceMultiplier > gasPriceCap
5959

6060
blockchain-adapter:
6161
protocol: ${IEXEC_CORE_CHAIN_ADAPTER_PROTOCOL:http}
@@ -70,7 +70,7 @@ config-server:
7070
host: ${IEXEC_CONFIG_SERVER_HOST:localhost}
7171
port: ${IEXEC_CONFIG_SERVER_PORT:8888}
7272

73-
resultRepository:
73+
result-repository:
7474
protocol: ${IEXEC_RESULT_REPOSITORY_PROTOCOL:http}
7575
host: ${IEXEC_RESULT_REPOSITORY_HOST:localhost}
7676
port: ${IEXEC_RESULT_REPOSITORY_PORT:13200}
@@ -93,5 +93,5 @@ logs:
9393
availability-period-in-days: ${IEXEC_LOGS_AVAILABILITY_PERIOD_IN_DAYS:3}
9494

9595
springdoc:
96-
packagesToScan: com.iexec.core
97-
pathsToMatch: /**
96+
packages-to-scan: com.iexec.core
97+
paths-to-match: /**
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
/*
2+
* Copyright 2025 IEXEC BLOCKCHAIN TECH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.iexec.core;
18+
19+
import com.iexec.core.chain.ChainConfig;
20+
import jakarta.validation.ConstraintViolation;
21+
import jakarta.validation.Validation;
22+
import jakarta.validation.Validator;
23+
import jakarta.validation.ValidatorFactory;
24+
import org.junit.jupiter.api.BeforeEach;
25+
import org.junit.jupiter.api.Test;
26+
import java.time.Duration;
27+
import java.util.Set;
28+
import static org.assertj.core.api.Assertions.assertThat;
29+
30+
class ChainConfigTest {
31+
private static final String IEXEC_NODE_ADDRESS = "https://bellecour.iex.ec";
32+
private static final String IEXEC_HUB_ADDRESS = "0x1a69b2eb604db8eba185df03ea4f5288dcbbd248";
33+
private static final String POOL_ADDRESS = "poolAddress";
34+
35+
private Validator validator;
36+
37+
@BeforeEach
38+
void setUp() {
39+
try (final ValidatorFactory factory = Validation.buildDefaultValidatorFactory()) {
40+
validator = factory.getValidator();
41+
}
42+
}
43+
44+
@Test
45+
void chainIdMustBePositive() {
46+
final ChainConfig config = new ChainConfig(
47+
0, // invalid chainId
48+
false,
49+
IEXEC_HUB_ADDRESS,
50+
Duration.ofMillis(100),
51+
IEXEC_NODE_ADDRESS,
52+
POOL_ADDRESS,
53+
0L,
54+
1.0f,
55+
100L
56+
);
57+
final Set<ConstraintViolation<ChainConfig>> violations = validator.validate(config);
58+
assertThat(violations)
59+
.extracting(ConstraintViolation::getMessage)
60+
.containsExactly("Chain id must be greater than 0");
61+
}
62+
63+
@Test
64+
void nodeAddressMustBeValidURL() {
65+
final ChainConfig config = new ChainConfig(
66+
1,
67+
false,
68+
IEXEC_HUB_ADDRESS,
69+
Duration.ofMillis(100),
70+
"invalid-url", // invalid URL
71+
POOL_ADDRESS,
72+
0L,
73+
1.0f,
74+
100L
75+
);
76+
final Set<ConstraintViolation<ChainConfig>> violations = validator.validate(config);
77+
assertThat(violations)
78+
.extracting(ConstraintViolation::getMessage)
79+
.containsExactly("Node address must be a valid URL");
80+
}
81+
82+
@Test
83+
void nodeAddressMustNotBeEmpty() {
84+
final ChainConfig config = new ChainConfig(
85+
1,
86+
false,
87+
IEXEC_HUB_ADDRESS,
88+
Duration.ofMillis(100),
89+
"", // empty nodeAddress
90+
POOL_ADDRESS,
91+
0L,
92+
1.0f,
93+
100L
94+
);
95+
final Set<ConstraintViolation<ChainConfig>> violations = validator.validate(config);
96+
assertThat(violations)
97+
.extracting(ConstraintViolation::getMessage)
98+
.containsExactly("Node address must not be empty");
99+
}
100+
101+
@Test
102+
void blockTimeMustBeAtLeast100ms() {
103+
final ChainConfig config = new ChainConfig(
104+
1,
105+
false,
106+
IEXEC_HUB_ADDRESS,
107+
Duration.ofMillis(99), // less than 100ms
108+
IEXEC_NODE_ADDRESS,
109+
POOL_ADDRESS,
110+
0L,
111+
1.0f,
112+
100L
113+
);
114+
final Set<ConstraintViolation<ChainConfig>> violations = validator.validate(config);
115+
assertThat(violations)
116+
.extracting(ConstraintViolation::getMessage)
117+
.containsExactly("Block time must be greater than 100ms");
118+
}
119+
120+
@Test
121+
void blockTimeMustBeAtMost20Seconds() {
122+
final ChainConfig config = new ChainConfig(
123+
1,
124+
false,
125+
IEXEC_HUB_ADDRESS,
126+
Duration.ofSeconds(21), // more than 20 seconds
127+
IEXEC_NODE_ADDRESS,
128+
POOL_ADDRESS,
129+
0L,
130+
1.0f,
131+
100L
132+
);
133+
final Set<ConstraintViolation<ChainConfig>> violations = validator.validate(config);
134+
assertThat(violations)
135+
.extracting(ConstraintViolation::getMessage)
136+
.containsExactly("Block time must be less than 20s");
137+
}
138+
139+
@Test
140+
void gasPriceMultiplierMustBePositive() {
141+
final ChainConfig config = new ChainConfig(
142+
1,
143+
false,
144+
IEXEC_HUB_ADDRESS,
145+
Duration.ofMillis(100),
146+
IEXEC_NODE_ADDRESS,
147+
POOL_ADDRESS,
148+
0L,
149+
0.0f, // invalid multiplier
150+
100L
151+
);
152+
final Set<ConstraintViolation<ChainConfig>> violations = validator.validate(config);
153+
assertThat(violations)
154+
.extracting(ConstraintViolation::getMessage)
155+
.containsExactly("Gas price multiplier must be greater than 0");
156+
}
157+
158+
@Test
159+
void gasPriceCapMustBePositiveOrZero() {
160+
final ChainConfig config = new ChainConfig(
161+
1,
162+
false,
163+
IEXEC_HUB_ADDRESS,
164+
Duration.ofMillis(100),
165+
IEXEC_NODE_ADDRESS,
166+
POOL_ADDRESS,
167+
0L,
168+
1.0f,
169+
-1L // invalid gasPriceCap
170+
);
171+
Set<ConstraintViolation<ChainConfig>> violations = validator.validate(config);
172+
assertThat(violations)
173+
.extracting(ConstraintViolation::getMessage)
174+
.containsExactly("Gas price cap must be greater or equal to 0");
175+
}
176+
177+
@Test
178+
void hubAddressMustBeValidEthereumAddress() {
179+
final ChainConfig config = new ChainConfig(
180+
1,
181+
false,
182+
"0x0", // invalid address
183+
Duration.ofMillis(100),
184+
IEXEC_NODE_ADDRESS,
185+
POOL_ADDRESS,
186+
0L,
187+
1.0f,
188+
100L
189+
);
190+
final Set<ConstraintViolation<ChainConfig>> violations = validator.validate(config);
191+
assertThat(violations)
192+
.extracting(ConstraintViolation::getMessage)
193+
.containsExactly("Hub address must be a valid non zero Ethereum address");
194+
}
195+
}

src/test/java/com/iexec/core/chain/WalletConfigurationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 IEXEC BLOCKCHAIN TECH
2+
* Copyright 2024-2025 IEXEC BLOCKCHAIN TECH
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,7 +37,7 @@ class WalletConfigurationTest {
3737
void shouldCreateBeans() throws Exception {
3838
final String tempWalletName = WalletUtils.generateFullNewWalletFile("changeit", tempWalletDir);
3939
final String tempWalletPath = tempWalletDir.getAbsolutePath() + File.separator + tempWalletName;
40-
runner.withPropertyValues("chain.privateAddress=http://localhost:8545", "chain.poolAddress=0x1", "chain.startBlockNumber=0", "chain.gasPriceMultiplier=1.0", "chain.gasPriceCap=0")
40+
runner.withPropertyValues("chain.node-address=http://localhost:8545", "chain.pool-address=0x1", "chain.start-block-number=0", "chain.gas-price-multiplier=1.0", "chain.gas-price-cap=0")
4141
.withBean(IexecHubService.class)
4242
.withBean(PublicChainConfig.class, 65535, true, "http://localhost:8545", "0xC129e7917b7c7DeDfAa5Fff1FB18d5D7050fE8ca", Duration.ofSeconds(5))
4343
.withBean(WalletConfiguration.class, tempWalletPath, "changeit")

0 commit comments

Comments
 (0)