Skip to content

fix: Remove default shard and realm constants #19123

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

Merged
merged 70 commits into from
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
206bc7c
Scope shard/realm first to target network, system properties
mhess-swl Apr 22, 2025
c684231
tiny doc update
mhess-swl Apr 22, 2025
3c06355
spotless..
mhess-swl Apr 22, 2025
bd5ffd7
Test fixes
mhess-swl Apr 23, 2025
1b0d0fd
More test fixes
mhess-swl Apr 23, 2025
882e6fe
More test fixes
mhess-swl Apr 23, 2025
4d9b6db
More test fixes
mhess-swl Apr 23, 2025
8eb8798
Fix hapiTestsToken
JivkoKelchev Apr 24, 2025
cf5c4bf
Merge branch 'refs/heads/18881-shard-realm-scope' into 18955-docouple…
JivkoKelchev Apr 24, 2025
f16de9d
fix node id
JivkoKelchev Apr 24, 2025
cbeec62
Make hapiRestart tests run with configurable per network shard and realm
ibankov Apr 24, 2025
ae00e77
spot
ibankov Apr 24, 2025
df4dc61
gradle build fix
ibankov Apr 24, 2025
8fb0cc8
setting nodes for batched transaction fix
ibankov Apr 24, 2025
b2644df
fix
ibankov Apr 25, 2025
806958c
fixing some tests
ibankov Apr 25, 2025
ae0a337
fix shard/realm for mirrorAddrWith()
JivkoKelchev Apr 25, 2025
98919b5
Merge branch 'main' into 18955-docouple-hapiTestToken
JivkoKelchev Apr 25, 2025
78d6a19
Merge branch 'refs/heads/18955-docouple-hapiTestToken' into 18957-dеc…
JivkoKelchev Apr 25, 2025
af33c47
fix shard/realm for mirrorAddrWith()
JivkoKelchev Apr 25, 2025
a8731d4
revert shard and realm config back to 0
ibankov Apr 25, 2025
8181d56
Merge branch 'refs/heads/18881-shard-realm-scope-restart' into 18955-…
JivkoKelchev Apr 25, 2025
109b5ee
revert node id changes
JivkoKelchev Apr 25, 2025
1e583cf
Merge branch 'refs/heads/18955-docouple-hapiTestToken' into 18957-dеc…
JivkoKelchev Apr 25, 2025
215159a
fix sidecarIdValidator
JivkoKelchev Apr 28, 2025
5bd467f
addressing PR comments
ibankov Apr 28, 2025
e4e013e
fix contracts
JivkoKelchev Apr 28, 2025
8df3d87
Merge branch 'refs/heads/18881-shard-realm-scope-restart' into 18955-…
JivkoKelchev Apr 28, 2025
15bc0cb
fix contracts
JivkoKelchev Apr 29, 2025
bfdc487
Merge branch 'main' into 18955-docouple-hapiTestToken
JivkoKelchev Apr 29, 2025
ed97ce6
Merge branch 'refs/heads/18955-docouple-hapiTestToken' into 18957-dеc…
JivkoKelchev Apr 29, 2025
fdbe7cc
fix contracts
JivkoKelchev Apr 30, 2025
13a7554
fix contracts
JivkoKelchev Apr 30, 2025
75edf85
fix contracts
JivkoKelchev Apr 30, 2025
ad0bfb1
Merge branch 'main' into 18955-docouple-hapiTestToken
JivkoKelchev May 7, 2025
a73a2f6
Merge branch 'refs/heads/18955-docouple-hapiTestToken' into 18957-dec…
JivkoKelchev May 7, 2025
ddfc8da
fix contracts
JivkoKelchev May 7, 2025
184b14e
fix contracts
JivkoKelchev May 7, 2025
fcd2ee8
fix contracts
JivkoKelchev May 7, 2025
a20aeb6
fix contracts
JivkoKelchev May 7, 2025
2240ccc
Merge branch 'refs/heads/main' into 18957-shard-realm-decouple-hapiTe…
JivkoKelchev May 7, 2025
40b5c61
fix contracts
JivkoKelchev May 7, 2025
e0b9b6c
fix contracts
JivkoKelchev May 7, 2025
16ed942
fixes for hapiTestMisc shard/realm usage
ibankov May 7, 2025
b97d9e1
revert unused code
ibankov May 7, 2025
25e1e68
fix
ibankov May 7, 2025
2d9de38
fix
ibankov May 7, 2025
de61cea
fix contracts
JivkoKelchev May 7, 2025
aa2f1f0
fix contracts
JivkoKelchev May 7, 2025
4a2bfa0
fix contracts
JivkoKelchev May 7, 2025
87c0305
Merge branch 'main' into 18957-shard-realm-decouple-hapiTestSmartCont…
JivkoKelchev May 7, 2025
9c6e143
Merge branch 'main' into 18957-shard-realm-decouple-hapiTestSmartCont…
mhess-swl May 7, 2025
0e4981d
Use HapiPropertySpec.asEntityString()
JivkoKelchev May 8, 2025
b31b549
Use variable name
JivkoKelchev May 8, 2025
684b1bc
Use HapiPropertySpec.asEntityString()
JivkoKelchev May 8, 2025
0a3c785
Apply suggestions from code review
JivkoKelchev May 8, 2025
1df4a24
Apply suggestions from code review
JivkoKelchev May 8, 2025
fe987bc
Merge branch 'main' into 18957-shard-realm-decouple-hapiTestSmartCont…
JivkoKelchev May 8, 2025
75f0ed2
Merge branch '18957-shard-realm-decouple-hapiTestSmartContracts' into…
ibankov May 8, 2025
4d5aff2
Merge branch 'main' into 18957-shard-realm-decouple-hapiTestSmartCont…
JivkoKelchev May 9, 2025
db2e2da
Merge branch '18957-shard-realm-decouple-hapiTestSmartContracts' into…
ibankov May 9, 2025
06751bb
Merge branch 'main' into 18957-shard-realm-decouple-hapiTestMisc
ibankov May 9, 2025
ae3cdfd
remove asEntityString(final long num)
JivkoKelchev May 9, 2025
446856d
remove all default constants shard and realm
JivkoKelchev May 9, 2025
bcc2417
Merge branch 'refs/heads/18957-shard-realm-decouple-hapiTestMisc' int…
JivkoKelchev May 9, 2025
eedba02
Fix
JivkoKelchev May 9, 2025
7a1c969
Merge branch 'main' into default-shard-realm-decouple
JivkoKelchev May 13, 2025
079339e
Fix PR comments
JivkoKelchev May 14, 2025
275c3d1
Merge branch 'main' into default-shard-realm-decouple
JivkoKelchev May 14, 2025
88f7ba3
chore: Node account id shard realm (#19192)
JivkoKelchev May 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ public interface HapiPropertySource {

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

// Default shard and realm for static ID building and comparisons
int shard = SHARD;
long realm = REALM;

String NODE_BLOCK_STREAM_DIR = String.format("block-%d.%d.3", SHARD, REALM);
String NODE_RECORD_STREAM_DIR = String.format("record%d.%d.3", SHARD, REALM);

Expand Down Expand Up @@ -155,7 +151,7 @@ default RealmID getRealm(String property) {
default long getRealm() {
return Optional.ofNullable(get("hapi.spec.default.realm"))
.map(Long::parseLong)
.orElse(realm);
.orElse(REALM);
}

@Deprecated
Expand All @@ -166,7 +162,7 @@ default ShardID getShard(String property) {
default long getShard() {
return Optional.ofNullable(get("hapi.spec.default.shard"))
.map(Long::parseLong)
.orElse((long) shard);
.orElse((long) SHARD);
}

static long getConfigShard() {
Expand Down Expand Up @@ -449,8 +445,8 @@ static ContractID asContract(String v) {

static ContractID asContractIdWithEvmAddress(ByteString address) {
return ContractID.newBuilder()
.setShardNum(shard)
.setRealmNum(realm)
.setShardNum(getConfigShard())
.setRealmNum(getConfigRealm())
.setEvmAddress(address)
.build();
}
Expand Down Expand Up @@ -590,11 +586,6 @@ static String asEntityString(final long shard, final long realm, final String nu
return String.format("%d.%d.%s", shard, realm, num);
}

@Deprecated(forRemoval = true)
static String asEntityString(final long num) {
return asEntityString(shard, realm, num);
}

static String asEntityString(final String shard, final String realm, final String num) {
return String.format("%s.%s.%s", shard, realm, num);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
* Initialize static properties for the HapiPropertySource.
*/
public class HapiPropertySourceStaticInitializer {
public static final int SHARD;
public static final long REALM;
public static final String SHARD_AND_REALM;
static final int SHARD;
static final long REALM;

static {
HapiPropertySource defaultSource = new JutilPropertySource("spec-default.properties");
SHARD = Integer.parseInt(defaultSource.get("default.shard"));
REALM = Long.parseLong(defaultSource.get("default.realm"));
SHARD_AND_REALM = SHARD + "." + REALM + ".";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,10 @@ private void buildRemoteNetwork() {
"default.realm", "" + targetNetwork.realm()));
} catch (Exception ignore) {
targetNetwork = RemoteNetwork.newRemoteNetwork(
hapiSetup.nodes(), clientsFor(hapiSetup), HapiPropertySource.shard, HapiPropertySource.realm);
hapiSetup.nodes(),
clientsFor(hapiSetup),
HapiPropertySource.getConfigShard(),
HapiPropertySource.getConfigRealm());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ public abstract class HapiSpecOperation implements SpecOperation {
protected Optional<String> metadata = Optional.empty();
protected Optional<String> payer = Optional.empty();
protected Optional<Boolean> genRecord = Optional.empty();
protected Optional<AccountID> node = Optional.empty();
protected Optional<String> nodeNum = Optional.empty();
protected Optional<String> node = Optional.empty();
protected Optional<Supplier<AccountID>> nodeSupplier = Optional.empty();
protected OptionalDouble usdFee = OptionalDouble.empty();
protected Optional<Integer> retryLimits = Optional.empty();
Expand Down Expand Up @@ -170,8 +169,7 @@ public boolean requiresFinalization(final HapiSpec spec) {
}

protected AccountID targetNodeFor(final HapiSpec spec) {
fixNodeFor(spec);
return node.get();
return fixNodeFor(spec);
}

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

protected void fixNodeFor(final HapiSpec spec) {
nodeNum.ifPresent(s -> node = Optional.of(asId(s, spec)));
protected AccountID fixNodeFor(final HapiSpec spec) {
if (node.isPresent()) {
return;
return asId(node.get(), spec);
}
if (nodeSupplier.isPresent()) {
node = Optional.of(nodeSupplier.get().get());
return nodeSupplier.get().get();
} else {
if (spec.setup().nodeSelector() == HapiSpecSetup.NodeSelection.RANDOM) {
node = Optional.of(randomNodeFrom(spec));
return randomNodeFrom(spec);
} else {
node = Optional.of(spec.setup().defaultNode());
return spec.setup().defaultNode();
}
}
}
Expand Down Expand Up @@ -275,7 +272,7 @@ protected Consumer<TransactionBody.Builder> bodyDef(final HapiSpec spec) {
if (omitNodeAccount) {
builder.clearNodeAccountID();
} else {
node.ifPresent(builder::setNodeAccountID);
node.ifPresent((s) -> builder.setNodeAccountID(fixNodeFor(spec)));
}
validDurationSecs.ifPresent(s -> builder.setTransactionValidDuration(
Duration.newBuilder().setSeconds(s).build()));
Expand Down Expand Up @@ -452,7 +449,7 @@ protected MoreObjects.ToStringHelper toStringHelper() {
helper.add("sigs", FeeBuilder.getSignatureCount(txnSubmitted));
}
payer.ifPresent(a -> helper.add("payer", a));
node.ifPresent(id -> helper.add("node", HapiPropertySource.asAccountString(id)));
node.ifPresent(id -> helper.add("node", id));
return helper;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@ public AccountInfoAsserts accountId(String account) {
}

public AccountInfoAsserts stakedAccountId(String acctNum) {
return stakedAccountId(Long.parseLong(acctNum));
}

public AccountInfoAsserts stakedAccountId(long acctNum) {
registerProvider((spec, o) -> assertEquals(
asAccount(spec.shard(), spec.realm(), Long.parseLong(acctNum)),
asAccount(spec.shard(), spec.realm(), acctNum),
((AccountInfo) o).getStakingInfo().getStakedAccountId(),
"Bad stakedAccountId id!"));
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public NodeConnectInfo(String inString) {
.filter(TxnUtils::isIdLiteral)
.map(HapiPropertySource::asAccount)
.findAny()
.orElse(HapiPropertySource.asAccount(asEntityString(NEXT_DEFAULT_ACCOUNT_NUM++)));
.orElse(HapiPropertySource.asAccount(asEntityString(0, 0, NEXT_DEFAULT_ACCOUNT_NUM++)));
host = Stream.of(aspects)
.filter(aspect -> !(isIdLiteral(aspect) || isNumericLiteral(aspect)))
.findAny()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ protected long costFrom(Response response) throws Throwable {

@Override
protected boolean submitOp(HapiSpec spec) throws Throwable {
fixNodeFor(spec);
configureTlsFor(spec);

Transaction payment = Transaction.getDefaultInstance();
Expand Down Expand Up @@ -433,8 +432,8 @@ public T useEmptyTxnAsAnswerPayment() {
return self();
}

public T setNode(String account) {
node = Optional.of(HapiPropertySource.asAccount(account));
public T setNode(String accountNum) {
node = Optional.of(accountNum);
return self();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ public Transaction signedTxnFor(HapiSpec spec) throws Throwable {

@Override
protected boolean submitOp(HapiSpec spec) throws Throwable {
fixNodeFor(spec);
configureTlsFor(spec);
int retryCount = 1;
while (true) {
Expand Down Expand Up @@ -783,13 +782,13 @@ public T txnId(String name) {
return self();
}

public T setNodeId(AccountID account) {
node = Optional.of(account);
public T setNode(String accountNum) {
node = Optional.of(accountNum);
return self();
}

public T setNode(String accountNum) {
nodeNum = Optional.of(accountNum);
public T setNode(long accountNum) {
node = Optional.of(Long.toString(accountNum));
return self();
}

Expand Down Expand Up @@ -890,11 +889,7 @@ public T batchKey(String key) {
return self();
}

public Optional<AccountID> getNode() {
public Optional<String> getNode() {
return node;
}

public Optional<String> getNodeNum() {
return nodeNum;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import static com.hedera.services.bdd.spec.HapiPropertySource.asToken;
import static com.hedera.services.bdd.spec.HapiPropertySource.asTokenString;
import static com.hedera.services.bdd.spec.HapiPropertySource.asTopic;
import static com.hedera.services.bdd.spec.HapiPropertySource.realm;
import static com.hedera.services.bdd.spec.HapiPropertySource.shard;
import static com.hedera.services.bdd.spec.queries.QueryVerbs.getContractInfo;
import static com.hedera.services.bdd.spec.queries.QueryVerbs.getFileInfo;
import static com.hedera.services.bdd.spec.transactions.contract.HapiParserUtil.encodeParametersForConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.hedera.services.bdd.spec.assertions.TransactionRecordAsserts;
import com.hedera.services.bdd.spec.infrastructure.meta.ActionableContractCall;
import com.hedera.services.bdd.spec.transactions.TxnUtils;
import com.hederahashgraph.api.proto.java.AccountID;
import com.hederahashgraph.api.proto.java.ContractCallTransactionBody;
import com.hederahashgraph.api.proto.java.ContractID;
import com.hederahashgraph.api.proto.java.HederaFunctionality;
Expand Down Expand Up @@ -240,10 +239,6 @@ public Optional<String> getCustomTxnId() {
return customTxnId;
}

public Optional<AccountID> getNode() {
return node;
}

public OptionalDouble getUsdFee() {
return usdFee;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
package com.hedera.services.bdd.spec.transactions.contract;

import static com.hedera.services.bdd.spec.HapiPropertySource.asContractString;
import static com.hedera.services.bdd.spec.HapiPropertySource.realm;
import static com.hedera.services.bdd.spec.HapiPropertySource.shard;
import static com.hedera.services.bdd.spec.transactions.TxnUtils.asId;
import static com.hedera.services.bdd.spec.transactions.TxnUtils.bannerWith;
import static com.hedera.services.bdd.spec.transactions.TxnUtils.equivAccount;
Expand All @@ -19,7 +17,6 @@
import com.hedera.services.bdd.spec.keys.KeyFactory;
import com.hedera.services.bdd.spec.keys.SigControl;
import com.hedera.services.bdd.spec.transactions.TxnUtils;
import com.hederahashgraph.api.proto.java.AccountID;
import com.hederahashgraph.api.proto.java.ContractCreateTransactionBody;
import com.hederahashgraph.api.proto.java.ContractGetInfoResponse;
import com.hederahashgraph.api.proto.java.ContractID;
Expand Down Expand Up @@ -52,10 +49,7 @@

public class HapiContractCreate extends HapiBaseContractCreate<HapiContractCreate> {
static final Key DEPRECATED_CID_ADMIN_KEY = Key.newBuilder()
.setContractID(ContractID.newBuilder()
.setShardNum(shard)
.setRealmNum(realm)
.setContractNum(1_234L))
.setContractID(ContractID.newBuilder().setShardNum(0).setRealmNum(0).setContractNum(1_234L))
.build();

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

b.setRealmID(RealmID.newBuilder().setShardNum(shard).setRealmNum(realm));
b.setShardID(ShardID.newBuilder().setShardNum(shard));
b.setRealmID(RealmID.newBuilder()
.setShardNum(spec.shard())
.setRealmNum(spec.realm()));
b.setShardID(ShardID.newBuilder().setShardNum(spec.shard()));
});
return b -> b.setContractCreateInstance(opBody);
}
Expand Down Expand Up @@ -456,10 +452,6 @@ public Optional<String> getCustomTxnId() {
return customTxnId;
}

public Optional<AccountID> getNode() {
return node;
}

public OptionalDouble getUsdFee() {
return usdFee;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ public HapiCryptoUpdate maxAutomaticAssociations(int max) {
return this;
}

public HapiCryptoUpdate newStakedAccountId(long stakee) {
return newStakedAccountId(String.valueOf(stakee));
}

public HapiCryptoUpdate newStakedAccountId(String stakee) {
newStakee = Optional.of(stakee);
return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
package com.hedera.services.bdd.spec.transactions.network;

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

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

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(final HapiSpec spec) throws Throwable {
if (subOp.getNodeNum().isPresent()) {
subOp.setNodeId(asId(subOp.getNodeNum().get(), spec));
}
final var subOpBytes = subOp.serializeSignedTxnFor(spec);
if (verboseLoggingOn) {
log.info("Submitting unchecked: {}", CommonUtils.extractTransactionBody(Transaction.parseFrom(subOpBytes)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package com.hedera.services.bdd.spec.transactions.util;

import static com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord;
import static com.hedera.services.bdd.spec.transactions.TxnUtils.asId;
import static com.hedera.services.bdd.spec.transactions.TxnUtils.extractTxnId;
import static com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom;
import static com.hedera.services.bdd.spec.transactions.TxnUtils.txnToString;
Expand Down Expand Up @@ -78,8 +77,10 @@ protected Consumer<TransactionBody.Builder> opBodyDef(final HapiSpec spec) throw
AtomicBatchTransactionBody.class, b -> {
for (HapiTxnOp<?> op : operationsToBatch) {
try {
// If the node num is not set, set the ID to 0.0.0
setInnerTxnNodeID(spec, op);
// set node account id to 0.0.0 if not set
if (op.getNode().isEmpty()) {
op.setNode(DEFAULT_NODE_ACCOUNT_ID);
}
// create a transaction for each operation
final var transaction = op.signedTxnFor(spec);
if (!loggingOff) {
Expand Down Expand Up @@ -173,15 +174,4 @@ private void validateExecutionOrder(HapiSpec spec, List<String> transactionIds)
}
}
}

private void setInnerTxnNodeID(HapiSpec spec, HapiTxnOp<?> op) {
// Set node ID for inner transactions
if (op.getNodeNum().isPresent()) {
op.setNodeId(asId(op.getNodeNum().get(), spec));
}
// set node account id to 0.0.0 if not set
if (op.getNode().isEmpty()) {
op.setNodeId(asId(DEFAULT_NODE_ACCOUNT_ID, spec));
}
}
}
Loading