Skip to content
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

feat: Validate non-standard hedera.shard/hedera.realm configurations #17460

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -172,8 +172,11 @@ private Map<Long, NodeAddress> getNodeAddressMap(@NonNull final MigrationContext
}

if (readableFiles != null) {
final var nodeDetailFile = readableFiles.get(
FileID.newBuilder().fileNum(fileConfig.nodeDetails()).build());
final var nodeDetailFile = readableFiles.get(FileID.newBuilder()
.shardNum(1)
.realmNum(2)
.fileNum(fileConfig.nodeDetails())
.build());
if (nodeDetailFile != null) {
try {
final var nodeDetails = NodeAddressBook.PROTOBUF
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Hedera Hashgraph, LLC
* Copyright (C) 2023-2025 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -108,9 +108,11 @@ public class AddressBookTestBase {
final Key invalidKey = Key.newBuilder()
.ecdsaSecp256k1((Bytes.fromHex("0000000000000000000000000000000000000000")))
.build();
protected final AccountID accountId = AccountID.newBuilder().accountNum(3).build();
protected final AccountID accountId =
AccountID.newBuilder().shardNum(1).realmNum(2).accountNum(3).build();

protected final AccountID payerId = AccountID.newBuilder().accountNum(2).build();
protected final AccountID payerId =
AccountID.newBuilder().shardNum(1).realmNum(2).accountNum(2).build();
protected final byte[] grpcCertificateHash = "grpcCertificateHash".getBytes();
protected final byte[] gossipCaCertificate = "gossipCaCertificate".getBytes();
protected final long WELL_KNOWN_NODE_ID = 1L;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Hedera Hashgraph, LLC
* Copyright (C) 2023-2025 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -257,7 +257,8 @@ void preHandleWorksWhenTreasureSign() throws PreCheckException {

@Test
void preHandleWorksWhenSysAdminSign() throws PreCheckException {
final var accountID = AccountID.newBuilder().accountNum(50).build();
final var accountID =
AccountID.newBuilder().shardNum(1).realmNum(2).accountNum(50).build();
final var txn = newDeleteTxnWithPayerId(accountID);
final var context = setupPreHandlePayerKey(txn, accountID, anotherKey);
subject.preHandle(context);
Expand All @@ -268,7 +269,8 @@ void preHandleWorksWhenSysAdminSign() throws PreCheckException {

@Test
void preHandleWorksWhenAddressBookAdminSign() throws PreCheckException {
final var accountID = AccountID.newBuilder().accountNum(55).build();
final var accountID =
AccountID.newBuilder().shardNum(1).realmNum(2).accountNum(55).build();
final var txn = newDeleteTxnWithPayerId(accountID);
final var context = setupPreHandlePayerKey(txn, accountID, anotherKey);
subject.preHandle(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ private void setupMigrationContext() {
private void setupMigrationContext2() {
setupMigrationContext();
accounts.put(
AccountID.newBuilder().accountNum(55).build(),
AccountID.newBuilder().shardNum(1).realmNum(2).accountNum(55).build(),
Account.newBuilder().key(anotherKey).build());
writableStates = MapWritableStates.builder()
.state(writableAccounts)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024 Hedera Hashgraph, LLC
* Copyright (C) 2024-2025 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,7 +34,11 @@

class RecordCacheTest {
private static final TransactionID USER_TXN_ID = TransactionID.newBuilder()
.accountID(AccountID.newBuilder().accountNum(666L).build())
.accountID(AccountID.newBuilder()
.shardNum(1)
.realmNum(2)
.accountNum(666L)
.build())
.transactionValidStart(new Timestamp(1, 0))
.scheduled(true)
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Hedera Hashgraph, LLC
* Copyright (C) 2023-2025 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,27 +34,35 @@ void detectsExplicitExpiry() {
@Test
void detectsRenewPeriod() {
final var withRenewPeriod = new ExpiryMeta(NA, 1L, null);
final var withoutRenewPeriod =
new ExpiryMeta(2L, NA, AccountID.newBuilder().accountNum(1L).build());
final var withoutRenewPeriod = new ExpiryMeta(
2L,
NA,
AccountID.newBuilder().shardNum(1).realmNum(2).accountNum(1L).build());
assertTrue(withRenewPeriod.hasAutoRenewPeriod());
assertFalse(withoutRenewPeriod.hasAutoRenewPeriod());
}

@Test
void detectsRenewNum() {
final var withRenewNum =
new ExpiryMeta(NA, 1L, AccountID.newBuilder().accountNum(1L).build());
final var withRenewNum = new ExpiryMeta(
NA,
1L,
AccountID.newBuilder().shardNum(1).realmNum(2).accountNum(1L).build());
final var withoutRenewNum = new ExpiryMeta(2L, NA, null);
assertTrue(withRenewNum.hasAutoRenewAccountId());
assertFalse(withoutRenewNum.hasAutoRenewAccountId());
}

@Test
void detectsFullAutoRenewSpec() {
final var withFullSpec =
new ExpiryMeta(NA, 1L, AccountID.newBuilder().accountNum(1L).build());
final var withoutFullSpec =
new ExpiryMeta(2L, NA, AccountID.newBuilder().accountNum(1L).build());
final var withFullSpec = new ExpiryMeta(
NA,
1L,
AccountID.newBuilder().shardNum(1).realmNum(2).accountNum(1L).build());
final var withoutFullSpec = new ExpiryMeta(
2L,
NA,
AccountID.newBuilder().shardNum(1).realmNum(2).accountNum(1L).build());
assertTrue(withFullSpec.hasFullAutoRenewSpec());
assertFalse(withoutFullSpec.hasFullAutoRenewSpec());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Hedera Hashgraph, LLC
* Copyright (C) 2023-2025 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -269,7 +269,8 @@ static Key ecdsaSecp256k1(String hex) {
null)
};

final AccountID account3 = AccountID.newBuilder().accountNum(3L).build();
final AccountID account3 =
AccountID.newBuilder().shardNum(1).realmNum(2).accountNum(3L).build();
final TestNode NODE_1 = new TestNode(
0L,
account3,
Expand All @@ -280,7 +281,8 @@ static Key ecdsaSecp256k1(String hex) {
.build(),
FAKE_ECDSA_KEY_INFOS[0]);

final AccountID account4 = AccountID.newBuilder().accountNum(4L).build();
final AccountID account4 =
AccountID.newBuilder().shardNum(1).realmNum(2).accountNum(4L).build();
final TestNode NODE_2 = new TestNode(
0L,
account4,
Expand All @@ -291,15 +293,18 @@ static Key ecdsaSecp256k1(String hex) {
.build(),
FAKE_ED25519_KEY_INFOS[0]);

final AccountID account800 = AccountID.newBuilder().accountNum(800L).build();
final AccountID account800 =
AccountID.newBuilder().shardNum(1).realmNum(2).accountNum(800L).build();
final TestUser STAKING_REWARD_ACCOUNT =
new TestUser(account800, Account.newBuilder().accountId(account800).build(), null);

final AccountID account098 = AccountID.newBuilder().accountNum(98L).build();
final AccountID account098 =
AccountID.newBuilder().shardNum(1).realmNum(2).accountNum(98L).build();
final TestUser FUNDING_ACCOUNT =
new TestUser(account098, Account.newBuilder().accountId(account098).build(), null);

final AccountID account1002 = AccountID.newBuilder().accountNum(1002L).build();
final AccountID account1002 =
AccountID.newBuilder().shardNum(1).realmNum(2).accountNum(1002L).build();
final TestUser ALICE = new TestUser(
account1002,
Account.newBuilder()
Expand All @@ -309,7 +314,10 @@ static Key ecdsaSecp256k1(String hex) {
.build(),
FAKE_ECDSA_KEY_INFOS[2]);

final AccountID account1003 = AccountID.newBuilder().accountNum(1003L).build();
// AccountID.newBuilder().shardNum(1).realmNum(2).accountNum
// AccountID.newBuilder().shardNum(1).realmNum(2).accountNum
final AccountID account1003 =
AccountID.newBuilder().shardNum(1).realmNum(2).accountNum(1003L).build();
final TestUser BOB = new TestUser(
account1003,
Account.newBuilder()
Expand All @@ -318,7 +326,8 @@ static Key ecdsaSecp256k1(String hex) {
.build(),
FAKE_ED25519_KEY_INFOS[1]);

final AccountID account1004 = AccountID.newBuilder().accountNum(1004L).build();
final AccountID account1004 =
AccountID.newBuilder().shardNum(1).realmNum(2).accountNum(1004L).build();
final TestUser CAROL = new TestUser(
account1004,
Account.newBuilder()
Expand All @@ -328,7 +337,8 @@ static Key ecdsaSecp256k1(String hex) {
.build(),
FAKE_ECDSA_WITH_ALIAS_KEY_INFOS[0]);

final AccountID account1006 = AccountID.newBuilder().accountNum(1006L).build();
final AccountID account1006 =
AccountID.newBuilder().shardNum(1).realmNum(2).accountNum(1006L).build();
final TestUser ERIN = new TestUser(
account1006,
Account.newBuilder()
Expand All @@ -338,7 +348,8 @@ static Key ecdsaSecp256k1(String hex) {
.build(),
FAKE_ECDSA_KEY_INFOS[3]);

TestUser FRANK = new TestUser(AccountID.newBuilder().accountNum(2000L).build(), null, FAKE_ECDSA_KEY_INFOS[3]);
TestUser FRANK = new TestUser(
AccountID.newBuilder().shardNum(1).realmNum(2).accountNum(2000L).build(), null, FAKE_ECDSA_KEY_INFOS[3]);

default Map<AccountID, Account> defaultAccounts() {
return Map.of(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Hedera Hashgraph, LLC
* Copyright (C) 2023-2025 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,19 +38,19 @@ public class FakeNetworkInfo implements NetworkInfo {
private static final List<NodeInfo> FAKE_NODE_INFOS = List.of(
fakeInfoWith(
2L,
AccountID.newBuilder().accountNum(3).build(),
AccountID.newBuilder().shardNum(1).realmNum(2).accountNum(3).build(),
30,
List.of(endpointFor("333.333.333.333", 50233), endpointFor("127.0.0.1", 20)),
Bytes.wrap("cert1")),
fakeInfoWith(
4L,
AccountID.newBuilder().accountNum(4).build(),
AccountID.newBuilder().shardNum(1).realmNum(2).accountNum(4).build(),
40,
List.of(endpointFor("444.444.444.444", 50244), endpointFor("127.0.0.2", 21)),
Bytes.wrap("cert2")),
fakeInfoWith(
8L,
AccountID.newBuilder().accountNum(5).build(),
AccountID.newBuilder().shardNum(1).realmNum(2).accountNum(5).build(),
50,
List.of(endpointFor("555.555.555.555", 50255), endpointFor("127.0.0.3", 22)),
Bytes.wrap("cert3")));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Hedera Hashgraph, LLC
* Copyright (C) 2023-2025 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -83,7 +83,8 @@ void accountIsNotPermitted() {
1);

final var authorizer = new AuthorizerImpl(configProvider, privilegesVerifier);
accountID = AccountID.newBuilder().accountNum(1234L).build();
accountID =
AccountID.newBuilder().shardNum(1).realmNum(2).accountNum(1234L).build();

// expect:
final var authorized = authorizer.isAuthorized(accountID, hapiFunction);
Expand All @@ -101,7 +102,8 @@ void accountIsPermitted() {
1);

final var authorizer = new AuthorizerImpl(configProvider, privilegesVerifier);
accountID = AccountID.newBuilder().accountNum(1234L).build();
accountID =
AccountID.newBuilder().shardNum(1).realmNum(2).accountNum(1234L).build();

// expect:
final var authorized = authorizer.isAuthorized(accountID, hapiFunction);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024 Hedera Hashgraph, LLC
* Copyright (C) 2024-2025 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -101,31 +101,51 @@ class BlockItemsTranslatorTest {
private static final List<AssessedCustomFee> ASSESSED_CUSTOM_FEES = List.of(new AssessedCustomFee(
1L,
TokenID.newBuilder().tokenNum(123).build(),
AccountID.newBuilder().accountNum(98L).build(),
List.of(AccountID.newBuilder().accountNum(2L).build())));
AccountID.newBuilder().shardNum(1).realmNum(2).accountNum(98L).build(),
List.of(AccountID.newBuilder()
.shardNum(1)
.realmNum(2)
.accountNum(2L)
.build())));
private static final TransferList TRANSFER_LIST = TransferList.newBuilder()
.accountAmounts(
AccountAmount.newBuilder()
.amount(-1)
.accountID(AccountID.newBuilder().accountNum(2L).build())
.accountID(AccountID.newBuilder()
.shardNum(1)
.realmNum(2)
.accountNum(2L)
.build())
.build(),
AccountAmount.newBuilder()
.amount(+1)
.accountID(AccountID.newBuilder().accountNum(98L).build())
.accountID(AccountID.newBuilder()
.shardNum(1)
.realmNum(2)
.accountNum(98L)
.build())
.build())
.build();
private static final List<AccountAmount> PAID_STAKING_REWARDS = List.of(
AccountAmount.newBuilder()
.amount(-1)
.accountID(AccountID.newBuilder().accountNum(800L).build())
.accountID(AccountID.newBuilder()
.shardNum(1)
.realmNum(2)
.accountNum(800L)
.build())
.build(),
AccountAmount.newBuilder()
.amount(+1)
.accountID(AccountID.newBuilder().accountNum(2L).build())
.accountID(AccountID.newBuilder()
.shardNum(1)
.realmNum(2)
.accountNum(2L)
.build())
.build());
private static final List<TokenAssociation> AUTO_TOKEN_ASSOCIATIONS = List.of(new TokenAssociation(
TokenID.newBuilder().tokenNum(123).build(),
AccountID.newBuilder().accountNum(98L).build()));
AccountID.newBuilder().shardNum(1).realmNum(2).accountNum(98L).build()));
private static final List<PendingAirdropRecord> PENDING_AIRDROP_RECORDS = List.of(new PendingAirdropRecord(
PendingAirdropId.newBuilder()
.nonFungibleToken(
Expand All @@ -135,7 +155,11 @@ class BlockItemsTranslatorTest {
private static final List<TokenTransferList> TOKEN_TRANSFER_LISTS = List.of(new TokenTransferList(
TokenID.newBuilder().tokenNum(123).build(), TRANSFER_LIST.accountAmounts(), List.of(), 0));
private static final TransactionID TXN_ID = TransactionID.newBuilder()
.accountID(AccountID.newBuilder().accountNum(2L).build())
.accountID(AccountID.newBuilder()
.shardNum(1)
.realmNum(2)
.accountNum(2L)
.build())
.build();
private static final ExchangeRateSet RATES = ExchangeRateSet.newBuilder()
.currentRate(new ExchangeRate(1, 2, TimestampSeconds.DEFAULT))
Expand Down Expand Up @@ -176,7 +200,7 @@ class BlockItemsTranslatorTest {
private static final ContractID CONTRACT_ID =
ContractID.newBuilder().contractNum(666L).build();
private static final AccountID ACCOUNT_ID =
AccountID.newBuilder().accountNum(666L).build();
AccountID.newBuilder().shardNum(1).realmNum(2).accountNum(666L).build();
private static final TokenID TOKEN_ID = TokenID.newBuilder().tokenNum(666L).build();
private static final TopicID TOPIC_ID = TopicID.newBuilder().topicNum(666L).build();
private static final FileID FILE_ID = FileID.newBuilder().fileNum(666L).build();
Expand Down
Loading
Loading