Skip to content

Commit 82ea7e2

Browse files
JivkoKelchevmhess-swlibankov
authored
fix: Remove default shard and realm constants (#19123)
Signed-off-by: Matt Hess <[email protected]> Signed-off-by: Zhivko Kelchev <[email protected]> Signed-off-by: ibankov <[email protected]> Co-authored-by: Matt Hess <[email protected]> Co-authored-by: ibankov <[email protected]>
1 parent 7e7f564 commit 82ea7e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+167
-221
lines changed

hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/HapiPropertySource.java

+4-13
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ public interface HapiPropertySource {
4848

4949
String ENTITY_STRING = "%d.%d.%d";
5050

51-
// Default shard and realm for static ID building and comparisons
52-
int shard = SHARD;
53-
long realm = REALM;
54-
5551
String NODE_BLOCK_STREAM_DIR = String.format("block-%d.%d.3", SHARD, REALM);
5652
String NODE_RECORD_STREAM_DIR = String.format("record%d.%d.3", SHARD, REALM);
5753

@@ -155,7 +151,7 @@ default RealmID getRealm(String property) {
155151
default long getRealm() {
156152
return Optional.ofNullable(get("hapi.spec.default.realm"))
157153
.map(Long::parseLong)
158-
.orElse(realm);
154+
.orElse(REALM);
159155
}
160156

161157
@Deprecated
@@ -166,7 +162,7 @@ default ShardID getShard(String property) {
166162
default long getShard() {
167163
return Optional.ofNullable(get("hapi.spec.default.shard"))
168164
.map(Long::parseLong)
169-
.orElse((long) shard);
165+
.orElse((long) SHARD);
170166
}
171167

172168
static long getConfigShard() {
@@ -449,8 +445,8 @@ static ContractID asContract(String v) {
449445

450446
static ContractID asContractIdWithEvmAddress(ByteString address) {
451447
return ContractID.newBuilder()
452-
.setShardNum(shard)
453-
.setRealmNum(realm)
448+
.setShardNum(getConfigShard())
449+
.setRealmNum(getConfigRealm())
454450
.setEvmAddress(address)
455451
.build();
456452
}
@@ -590,11 +586,6 @@ static String asEntityString(final long shard, final long realm, final String nu
590586
return String.format("%d.%d.%s", shard, realm, num);
591587
}
592588

593-
@Deprecated(forRemoval = true)
594-
static String asEntityString(final long num) {
595-
return asEntityString(shard, realm, num);
596-
}
597-
598589
static String asEntityString(final String shard, final String realm, final String num) {
599590
return String.format("%s.%s.%s", shard, realm, num);
600591
}

hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/HapiPropertySourceStaticInitializer.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@
77
* Initialize static properties for the HapiPropertySource.
88
*/
99
public class HapiPropertySourceStaticInitializer {
10-
public static final int SHARD;
11-
public static final long REALM;
12-
public static final String SHARD_AND_REALM;
10+
static final int SHARD;
11+
static final long REALM;
1312

1413
static {
1514
HapiPropertySource defaultSource = new JutilPropertySource("spec-default.properties");
1615
SHARD = Integer.parseInt(defaultSource.get("default.shard"));
1716
REALM = Long.parseLong(defaultSource.get("default.realm"));
18-
SHARD_AND_REALM = SHARD + "." + REALM + ".";
1917
}
2018
}

hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/HapiSpec.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,10 @@ private void buildRemoteNetwork() {
829829
"default.realm", "" + targetNetwork.realm()));
830830
} catch (Exception ignore) {
831831
targetNetwork = RemoteNetwork.newRemoteNetwork(
832-
hapiSetup.nodes(), clientsFor(hapiSetup), HapiPropertySource.shard, HapiPropertySource.realm);
832+
hapiSetup.nodes(),
833+
clientsFor(hapiSetup),
834+
HapiPropertySource.getConfigShard(),
835+
HapiPropertySource.getConfigRealm());
833836
}
834837
}
835838

hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/HapiSpecOperation.java

+9-12
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ public abstract class HapiSpecOperation implements SpecOperation {
124124
protected Optional<String> metadata = Optional.empty();
125125
protected Optional<String> payer = Optional.empty();
126126
protected Optional<Boolean> genRecord = Optional.empty();
127-
protected Optional<AccountID> node = Optional.empty();
128-
protected Optional<String> nodeNum = Optional.empty();
127+
protected Optional<String> node = Optional.empty();
129128
protected Optional<Supplier<AccountID>> nodeSupplier = Optional.empty();
130129
protected OptionalDouble usdFee = OptionalDouble.empty();
131130
protected Optional<Integer> retryLimits = Optional.empty();
@@ -170,8 +169,7 @@ public boolean requiresFinalization(final HapiSpec spec) {
170169
}
171170

172171
protected AccountID targetNodeFor(final HapiSpec spec) {
173-
fixNodeFor(spec);
174-
return node.get();
172+
return fixNodeFor(spec);
175173
}
176174

177175
protected void configureTlsFor(final HapiSpec spec) {
@@ -184,18 +182,17 @@ private void configureProtoStructureFor(final HapiSpec spec) {
184182
: spec.setup().txnProtoStructure();
185183
}
186184

187-
protected void fixNodeFor(final HapiSpec spec) {
188-
nodeNum.ifPresent(s -> node = Optional.of(asId(s, spec)));
185+
protected AccountID fixNodeFor(final HapiSpec spec) {
189186
if (node.isPresent()) {
190-
return;
187+
return asId(node.get(), spec);
191188
}
192189
if (nodeSupplier.isPresent()) {
193-
node = Optional.of(nodeSupplier.get().get());
190+
return nodeSupplier.get().get();
194191
} else {
195192
if (spec.setup().nodeSelector() == HapiSpecSetup.NodeSelection.RANDOM) {
196-
node = Optional.of(randomNodeFrom(spec));
193+
return randomNodeFrom(spec);
197194
} else {
198-
node = Optional.of(spec.setup().defaultNode());
195+
return spec.setup().defaultNode();
199196
}
200197
}
201198
}
@@ -275,7 +272,7 @@ protected Consumer<TransactionBody.Builder> bodyDef(final HapiSpec spec) {
275272
if (omitNodeAccount) {
276273
builder.clearNodeAccountID();
277274
} else {
278-
node.ifPresent(builder::setNodeAccountID);
275+
node.ifPresent((s) -> builder.setNodeAccountID(fixNodeFor(spec)));
279276
}
280277
validDurationSecs.ifPresent(s -> builder.setTransactionValidDuration(
281278
Duration.newBuilder().setSeconds(s).build()));
@@ -452,7 +449,7 @@ protected MoreObjects.ToStringHelper toStringHelper() {
452449
helper.add("sigs", FeeBuilder.getSignatureCount(txnSubmitted));
453450
}
454451
payer.ifPresent(a -> helper.add("payer", a));
455-
node.ifPresent(id -> helper.add("node", HapiPropertySource.asAccountString(id)));
452+
node.ifPresent(id -> helper.add("node", id));
456453
return helper;
457454
}
458455

hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/assertions/AccountInfoAsserts.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,12 @@ public AccountInfoAsserts accountId(String account) {
8989
}
9090

9191
public AccountInfoAsserts stakedAccountId(String acctNum) {
92+
return stakedAccountId(Long.parseLong(acctNum));
93+
}
94+
95+
public AccountInfoAsserts stakedAccountId(long acctNum) {
9296
registerProvider((spec, o) -> assertEquals(
93-
asAccount(spec.shard(), spec.realm(), Long.parseLong(acctNum)),
97+
asAccount(spec.shard(), spec.realm(), acctNum),
9498
((AccountInfo) o).getStakingInfo().getStakedAccountId(),
9599
"Bad stakedAccountId id!"));
96100
return this;

hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/props/NodeConnectInfo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public NodeConnectInfo(String inString) {
4747
.filter(TxnUtils::isIdLiteral)
4848
.map(HapiPropertySource::asAccount)
4949
.findAny()
50-
.orElse(HapiPropertySource.asAccount(asEntityString(NEXT_DEFAULT_ACCOUNT_NUM++)));
50+
.orElse(HapiPropertySource.asAccount(asEntityString(0, 0, NEXT_DEFAULT_ACCOUNT_NUM++)));
5151
host = Stream.of(aspects)
5252
.filter(aspect -> !(isIdLiteral(aspect) || isNumericLiteral(aspect)))
5353
.findAny()

hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/queries/HapiQueryOp.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ protected long costFrom(Response response) throws Throwable {
173173

174174
@Override
175175
protected boolean submitOp(HapiSpec spec) throws Throwable {
176-
fixNodeFor(spec);
177176
configureTlsFor(spec);
178177

179178
Transaction payment = Transaction.getDefaultInstance();
@@ -433,8 +432,8 @@ public T useEmptyTxnAsAnswerPayment() {
433432
return self();
434433
}
435434

436-
public T setNode(String account) {
437-
node = Optional.of(HapiPropertySource.asAccount(account));
435+
public T setNode(String accountNum) {
436+
node = Optional.of(accountNum);
438437
return self();
439438
}
440439

hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/transactions/HapiTxnOp.java

+5-10
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ public Transaction signedTxnFor(HapiSpec spec) throws Throwable {
182182

183183
@Override
184184
protected boolean submitOp(HapiSpec spec) throws Throwable {
185-
fixNodeFor(spec);
186185
configureTlsFor(spec);
187186
int retryCount = 1;
188187
while (true) {
@@ -783,13 +782,13 @@ public T txnId(String name) {
783782
return self();
784783
}
785784

786-
public T setNodeId(AccountID account) {
787-
node = Optional.of(account);
785+
public T setNode(String accountNum) {
786+
node = Optional.of(accountNum);
788787
return self();
789788
}
790789

791-
public T setNode(String accountNum) {
792-
nodeNum = Optional.of(accountNum);
790+
public T setNode(long accountNum) {
791+
node = Optional.of(Long.toString(accountNum));
793792
return self();
794793
}
795794

@@ -890,11 +889,7 @@ public T batchKey(String key) {
890889
return self();
891890
}
892891

893-
public Optional<AccountID> getNode() {
892+
public Optional<String> getNode() {
894893
return node;
895894
}
896-
897-
public Optional<String> getNodeNum() {
898-
return nodeNum;
899-
}
900895
}

hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/transactions/TxnUtils.java

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
import static com.hedera.services.bdd.spec.HapiPropertySource.asToken;
1313
import static com.hedera.services.bdd.spec.HapiPropertySource.asTokenString;
1414
import static com.hedera.services.bdd.spec.HapiPropertySource.asTopic;
15-
import static com.hedera.services.bdd.spec.HapiPropertySource.realm;
16-
import static com.hedera.services.bdd.spec.HapiPropertySource.shard;
1715
import static com.hedera.services.bdd.spec.queries.QueryVerbs.getContractInfo;
1816
import static com.hedera.services.bdd.spec.queries.QueryVerbs.getFileInfo;
1917
import static com.hedera.services.bdd.spec.transactions.contract.HapiParserUtil.encodeParametersForConstructor;

hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/transactions/contract/HapiContractCall.java

-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.hedera.services.bdd.spec.assertions.TransactionRecordAsserts;
1919
import com.hedera.services.bdd.spec.infrastructure.meta.ActionableContractCall;
2020
import com.hedera.services.bdd.spec.transactions.TxnUtils;
21-
import com.hederahashgraph.api.proto.java.AccountID;
2221
import com.hederahashgraph.api.proto.java.ContractCallTransactionBody;
2322
import com.hederahashgraph.api.proto.java.ContractID;
2423
import com.hederahashgraph.api.proto.java.HederaFunctionality;
@@ -240,10 +239,6 @@ public Optional<String> getCustomTxnId() {
240239
return customTxnId;
241240
}
242241

243-
public Optional<AccountID> getNode() {
244-
return node;
245-
}
246-
247242
public OptionalDouble getUsdFee() {
248243
return usdFee;
249244
}

hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/transactions/contract/HapiContractCreate.java

+5-13
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
package com.hedera.services.bdd.spec.transactions.contract;
33

44
import static com.hedera.services.bdd.spec.HapiPropertySource.asContractString;
5-
import static com.hedera.services.bdd.spec.HapiPropertySource.realm;
6-
import static com.hedera.services.bdd.spec.HapiPropertySource.shard;
75
import static com.hedera.services.bdd.spec.transactions.TxnUtils.asId;
86
import static com.hedera.services.bdd.spec.transactions.TxnUtils.bannerWith;
97
import static com.hedera.services.bdd.spec.transactions.TxnUtils.equivAccount;
@@ -19,7 +17,6 @@
1917
import com.hedera.services.bdd.spec.keys.KeyFactory;
2018
import com.hedera.services.bdd.spec.keys.SigControl;
2119
import com.hedera.services.bdd.spec.transactions.TxnUtils;
22-
import com.hederahashgraph.api.proto.java.AccountID;
2320
import com.hederahashgraph.api.proto.java.ContractCreateTransactionBody;
2421
import com.hederahashgraph.api.proto.java.ContractGetInfoResponse;
2522
import com.hederahashgraph.api.proto.java.ContractID;
@@ -52,10 +49,7 @@
5249

5350
public class HapiContractCreate extends HapiBaseContractCreate<HapiContractCreate> {
5451
static final Key DEPRECATED_CID_ADMIN_KEY = Key.newBuilder()
55-
.setContractID(ContractID.newBuilder()
56-
.setShardNum(shard)
57-
.setRealmNum(realm)
58-
.setContractNum(1_234L))
52+
.setContractID(ContractID.newBuilder().setShardNum(0).setRealmNum(0).setContractNum(1_234L))
5953
.build();
6054

6155
public HapiContractCreate(String contract) {
@@ -377,8 +371,10 @@ protected Consumer<TransactionBody.Builder> opBodyDef(HapiSpec spec) throws Thro
377371
}
378372
b.setDeclineReward(isDeclinedReward);
379373

380-
b.setRealmID(RealmID.newBuilder().setShardNum(shard).setRealmNum(realm));
381-
b.setShardID(ShardID.newBuilder().setShardNum(shard));
374+
b.setRealmID(RealmID.newBuilder()
375+
.setShardNum(spec.shard())
376+
.setRealmNum(spec.realm()));
377+
b.setShardID(ShardID.newBuilder().setShardNum(spec.shard()));
382378
});
383379
return b -> b.setContractCreateInstance(opBody);
384380
}
@@ -456,10 +452,6 @@ public Optional<String> getCustomTxnId() {
456452
return customTxnId;
457453
}
458454

459-
public Optional<AccountID> getNode() {
460-
return node;
461-
}
462-
463455
public OptionalDouble getUsdFee() {
464456
return usdFee;
465457
}

hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/transactions/crypto/HapiCryptoUpdate.java

+4
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ public HapiCryptoUpdate maxAutomaticAssociations(int max) {
132132
return this;
133133
}
134134

135+
public HapiCryptoUpdate newStakedAccountId(long stakee) {
136+
return newStakedAccountId(String.valueOf(stakee));
137+
}
138+
135139
public HapiCryptoUpdate newStakedAccountId(String stakee) {
136140
newStakee = Optional.of(stakee);
137141
return this;

hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/transactions/network/HapiUncheckedSubmit.java

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// SPDX-License-Identifier: Apache-2.0
22
package com.hedera.services.bdd.spec.transactions.network;
33

4-
import static com.hedera.services.bdd.spec.transactions.TxnUtils.asId;
54
import static com.hederahashgraph.api.proto.java.HederaFunctionality.UncheckedSubmit;
65

76
import com.google.common.base.MoreObjects;
@@ -39,9 +38,6 @@ public HederaFunctionality type() {
3938

4039
@Override
4140
protected Consumer<TransactionBody.Builder> opBodyDef(final HapiSpec spec) throws Throwable {
42-
if (subOp.getNodeNum().isPresent()) {
43-
subOp.setNodeId(asId(subOp.getNodeNum().get(), spec));
44-
}
4541
final var subOpBytes = subOp.serializeSignedTxnFor(spec);
4642
if (verboseLoggingOn) {
4743
log.info("Submitting unchecked: {}", CommonUtils.extractTransactionBody(Transaction.parseFrom(subOpBytes)));

hedera-node/test-clients/src/main/java/com/hedera/services/bdd/spec/transactions/util/HapiAtomicBatch.java

+4-14
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
package com.hedera.services.bdd.spec.transactions.util;
33

44
import static com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord;
5-
import static com.hedera.services.bdd.spec.transactions.TxnUtils.asId;
65
import static com.hedera.services.bdd.spec.transactions.TxnUtils.extractTxnId;
76
import static com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom;
87
import static com.hedera.services.bdd.spec.transactions.TxnUtils.txnToString;
@@ -78,8 +77,10 @@ protected Consumer<TransactionBody.Builder> opBodyDef(final HapiSpec spec) throw
7877
AtomicBatchTransactionBody.class, b -> {
7978
for (HapiTxnOp<?> op : operationsToBatch) {
8079
try {
81-
// If the node num is not set, set the ID to 0.0.0
82-
setInnerTxnNodeID(spec, op);
80+
// set node account id to 0.0.0 if not set
81+
if (op.getNode().isEmpty()) {
82+
op.setNode(DEFAULT_NODE_ACCOUNT_ID);
83+
}
8384
// create a transaction for each operation
8485
final var transaction = op.signedTxnFor(spec);
8586
if (!loggingOff) {
@@ -173,15 +174,4 @@ private void validateExecutionOrder(HapiSpec spec, List<String> transactionIds)
173174
}
174175
}
175176
}
176-
177-
private void setInnerTxnNodeID(HapiSpec spec, HapiTxnOp<?> op) {
178-
// Set node ID for inner transactions
179-
if (op.getNodeNum().isPresent()) {
180-
op.setNodeId(asId(op.getNodeNum().get(), spec));
181-
}
182-
// set node account id to 0.0.0 if not set
183-
if (op.getNode().isEmpty()) {
184-
op.setNodeId(asId(DEFAULT_NODE_ACCOUNT_ID, spec));
185-
}
186-
}
187177
}

0 commit comments

Comments
 (0)