Skip to content

Commit 74903c9

Browse files
derektrileylukelee-slvtronkovJivkoKelchevibankov
authored
feat: (cherry-pick) try using non-zero realm/shard (#18732)
Signed-off-by: Luke Lee <[email protected]> Signed-off-by: Valentin Tronkov <[email protected]> Signed-off-by: Zhivko Kelchev <[email protected]> Signed-off-by: ibankov <[email protected]> Signed-off-by: Neeharika-Sompalli <[email protected]> Signed-off-by: Derek Riley <[email protected]> Co-authored-by: lukelee-sl <[email protected]> Co-authored-by: Valentin Tronkov <[email protected]> Co-authored-by: Zhivko Kelchev <[email protected]> Co-authored-by: ibankov <[email protected]> Co-authored-by: Valentin Tronkov <[email protected]> Co-authored-by: Neeharika-Sompalli <[email protected]> Co-authored-by: Neeharika Sompalli <[email protected]>
1 parent ef8f8f6 commit 74903c9

File tree

169 files changed

+1242
-742
lines changed

Some content is hidden

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

169 files changed

+1242
-742
lines changed

hedera-node/configuration/dev/application.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ staking.fees.stakingRewardPercentage=10
1414
# Needed for Restart and Reconnect HapiTests that run many transactions of each type
1515
bootstrap.throttleDefsJson.resource=genesis/throttles-dev.json
1616
ledger.id=0x03
17+
hedera.shard=0
18+
hedera.realm=0
1719
blockStream.streamMode=BOTH
1820
nodes.enableDAB=true
1921
blockStream.blockFileDir=data/blockStreams

hedera-node/hedera-app/src/main/java/com/hedera/node/app/blocks/impl/BlockImplUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
public class BlockImplUtils {
7979
private static final int UNKNOWN_STATE_ID = -1;
8080
private static final IntFunction<String> UPGRADE_DATA_FILE_FORMAT =
81-
n -> String.format("UPGRADE_DATA\\[FileID\\[shardNum=\\d, realmNum=\\d, fileNum=%s]]", n);
81+
n -> String.format("UPGRADE_DATA\\[FileID\\[shardNum=\\d+, realmNum=\\d+, fileNum=%s]]", n);
8282

8383
/**
8484
* Prevent instantiation

hedera-node/hedera-app/src/main/java/com/hedera/node/app/info/StateNetworkInfo.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
import com.hedera.node.app.ids.schemas.V0590EntityIdSchema;
1515
import com.hedera.node.app.service.addressbook.AddressBookService;
1616
import com.hedera.node.config.ConfigProvider;
17+
import com.hedera.node.config.data.HederaConfig;
1718
import com.hedera.node.config.data.LedgerConfig;
1819
import com.hedera.node.internal.network.Network;
1920
import com.hedera.pbj.runtime.io.buffer.Bytes;
21+
import com.swirlds.config.api.Configuration;
2022
import com.swirlds.state.State;
2123
import com.swirlds.state.lifecycle.info.NetworkInfo;
2224
import com.swirlds.state.lifecycle.info.NodeInfo;
@@ -62,6 +64,8 @@ public class StateNetworkInfo implements NetworkInfo {
6264
*/
6365
private volatile Map<Long, NodeInfo> nodeInfos;
6466

67+
private final Configuration configuration;
68+
6569
/**
6670
* Constructs a new network information provider from the given state, roster, selfID, and configuration provider.
6771
*
@@ -81,6 +85,7 @@ public StateNetworkInfo(
8185
requireNonNull(configProvider);
8286
this.activeRoster = requireNonNull(roster);
8387
this.genesisNetworkSupplier = requireNonNull(genesisNetworkSupplier);
88+
this.configuration = configProvider.getConfiguration();
8489
this.ledgerId = configProvider
8590
.getConfiguration()
8691
.getConfigData(LedgerConfig.class)
@@ -155,6 +160,7 @@ private Map<Long, NodeInfo> nodeInfosFrom(@NonNull final State state) {
155160
} else {
156161
final ReadableKVState<EntityNumber, Node> nodes =
157162
state.getReadableStates(AddressBookService.NAME).get(NODES_KEY);
163+
final var hederaConfig = configuration.getConfigData(HederaConfig.class);
158164
for (final var rosterEntry : activeRoster.rosterEntries()) {
159165
// At genesis the node store is derived from the roster, hence must have info for every
160166
// node id; and from then on, the roster is derived from the node store, and hence the
@@ -171,6 +177,8 @@ private Map<Long, NodeInfo> nodeInfosFrom(@NonNull final State state) {
171177
fromRosterEntry(
172178
rosterEntry,
173179
AccountID.newBuilder()
180+
.shardNum(hederaConfig.shard())
181+
.realmNum(hederaConfig.realm())
174182
.accountNum(rosterEntry.nodeId() + 3)
175183
.build()));
176184
log.error("Roster includes a node {} that is not found in node store", rosterEntry.nodeId());

hedera-node/hedera-app/src/test/java/com/hedera/node/app/workflows/handle/steps/HollowAccountCompletionsTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.hedera.node.app.service.token.ReadableAccountStore;
3131
import com.hedera.node.app.signature.AppKeyVerifier;
3232
import com.hedera.node.app.signature.impl.SignatureVerificationImpl;
33+
import com.hedera.node.app.spi.fixtures.ids.FakeEntityIdFactoryImpl;
3334
import com.hedera.node.app.spi.signatures.SignatureVerification;
3435
import com.hedera.node.app.spi.workflows.HandleContext;
3536
import com.hedera.node.app.store.ReadableStoreFactory;
@@ -38,6 +39,7 @@
3839
import com.hedera.node.app.workflows.handle.record.RecordStreamBuilder;
3940
import com.hedera.node.app.workflows.handle.stack.SavepointStackImpl;
4041
import com.hedera.node.app.workflows.prehandle.PreHandleResult;
42+
import com.hedera.node.config.data.HederaConfig;
4143
import com.hedera.pbj.runtime.io.buffer.Bytes;
4244
import java.time.Instant;
4345
import java.util.Collections;
@@ -189,15 +191,18 @@ void skipDummyHollowAccountsFromCryptoCreateHandler() {
189191
void completeHollowAccountsWithEthereumTransaction() {
190192
when(parentTxn.functionality()).thenReturn(ETHEREUM_TRANSACTION);
191193
final var alias = Bytes.fromHex("89abcdef89abcdef89abcdef89abcdef89abcdef");
192-
final var hollowId = AccountID.newBuilder().accountNum(1234).build();
194+
final var hederaConfig = DEFAULT_CONFIG.getConfigData(HederaConfig.class);
195+
final var idFactory = new FakeEntityIdFactoryImpl(hederaConfig.shard(), hederaConfig.realm());
196+
final var hollowId = idFactory.newAccountId(1234);
193197
final var hollowAccount = Account.newBuilder()
194198
.alias(alias)
195199
.key(IMMUTABILITY_SENTINEL_KEY)
196200
.accountId(hollowId)
197201
.build();
198202
final var ethTxSigs = new EthTxSigs(Bytes.EMPTY.toByteArray(), alias.toByteArray());
199203
when(ethereumTransactionHandler.maybeEthTxSigsFor(any(), any(), any())).thenReturn(ethTxSigs);
200-
when(accountStore.getAccountIDByAlias(0, 0, alias)).thenReturn(hollowId);
204+
when(accountStore.getAccountIDByAlias(hederaConfig.shard(), hederaConfig.realm(), alias))
205+
.thenReturn(hollowId);
201206
when(accountStore.getAccountById(hollowId)).thenReturn(hollowAccount);
202207
final var txnBody = TransactionBody.newBuilder()
203208
.transactionID(TransactionID.newBuilder()

hedera-node/hedera-file-service-impl/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ testModuleInfo {
1616
requires("org.junit.jupiter.api")
1717
requires("org.mockito")
1818
requires("org.mockito.junit.jupiter")
19-
requires("com.swirlds.config.extensions.test.fixtures")
19+
runtimeOnly("com.swirlds.config.extensions.test.fixtures")
2020
}

hedera-node/hedera-file-service-impl/src/test/java/com/hedera/node/app/service/file/impl/test/FileTestBase.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.hedera.node.app.spi.ids.WritableEntityCounters;
2727
import com.hedera.node.app.spi.store.StoreFactory;
2828
import com.hedera.node.app.spi.workflows.HandleContext;
29+
import com.hedera.node.config.data.HederaConfig;
2930
import com.hedera.node.config.testfixtures.HederaTestConfigBuilder;
3031
import com.hedera.pbj.runtime.io.buffer.Bytes;
3132
import com.swirlds.config.api.Configuration;
@@ -102,10 +103,12 @@ public class FileTestBase {
102103

103104
protected final KeyList anotherKeys = B_KEY_LIST.keyList();
104105

105-
private final long SHARD = 5L;
106-
private final long REALM = 10L;
106+
protected final long SHARD =
107+
DEFAULT_CONFIG.getConfigData(HederaConfig.class).shard();
108+
protected final long REALM =
109+
DEFAULT_CONFIG.getConfigData(HederaConfig.class).realm();
107110

108-
private final EntityIdFactory idFactory = new FakeEntityIdFactoryImpl(SHARD, REALM);
111+
protected final EntityIdFactory idFactory = new FakeEntityIdFactoryImpl(SHARD, REALM);
109112

110113
protected final FileID WELL_KNOWN_FILE_ID = idFactory.newFileId(1_234L);
111114
protected final FileID WELL_KNOWN_UPGRADE_FILE_ID = idFactory.newFileId(150L);

hedera-node/hedera-file-service-impl/src/test/java/com/hedera/node/app/service/file/impl/test/WritableUpgradeFileStoreTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
@ExtendWith(MockitoExtension.class)
1818
class WritableUpgradeFileStoreTest extends FileTestBase {
1919
private File file;
20-
protected final FileID UPGRADE_FILE_ID = new FileID(5, 10, 150);
20+
protected final FileID UPGRADE_FILE_ID = new FileID(SHARD, REALM, 150);
2121

2222
@Test
2323
void throwsIfNullValuesAsArgs() {

hedera-node/hedera-file-service-impl/src/test/java/com/hedera/node/app/service/file/impl/test/handlers/FileCreateTest.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import com.hedera.node.app.service.file.impl.records.CreateFileStreamBuilder;
3737
import com.hedera.node.app.service.file.impl.test.FileTestBase;
3838
import com.hedera.node.app.service.token.ReadableAccountStore;
39-
import com.hedera.node.app.spi.fixtures.ids.FakeEntityIdFactoryImpl;
4039
import com.hedera.node.app.spi.fixtures.workflows.FakePreHandleContext;
4140
import com.hedera.node.app.spi.ids.EntityNumGenerator;
4241
import com.hedera.node.app.spi.validation.AttributeValidator;
@@ -52,7 +51,6 @@
5251
import com.hedera.node.config.types.LongPair;
5352
import com.hedera.pbj.runtime.io.buffer.Bytes;
5453
import com.swirlds.config.api.Configuration;
55-
import com.swirlds.state.lifecycle.EntityIdFactory;
5654
import org.junit.jupiter.api.BeforeEach;
5755
import org.junit.jupiter.api.DisplayName;
5856
import org.junit.jupiter.api.Test;
@@ -97,9 +95,6 @@ class FileCreateTest extends FileTestBase {
9795
private WritableFileStore fileStore;
9896
private FileCreateHandler subject;
9997

100-
private long SHARD = 5L;
101-
private long REALM = 10L;
102-
10398
private TransactionBody newCreateTxn(KeyList keys, long expirationTime) {
10499
return newCreateTxn(keys, expirationTime, ShardID.DEFAULT.shardNum(), RealmID.DEFAULT.realmNum());
105100
}
@@ -216,7 +211,6 @@ void handleWorksAsExpected() {
216211

217212
subject.handle(handleContext);
218213

219-
final EntityIdFactory idFactory = new FakeEntityIdFactoryImpl(5L, 10L);
220214
final FileID createdFileId = idFactory.newFileId(1_234L);
221215
final var createdFile = fileStore.get(createdFileId);
222216
assertTrue(createdFile.isPresent());
@@ -251,7 +245,6 @@ void handleDoesntRequireKeys() {
251245

252246
subject.handle(handleContext);
253247

254-
final EntityIdFactory idFactory = new FakeEntityIdFactoryImpl(5L, 10L);
255248
final FileID createdFileId = idFactory.newFileId(1_234L);
256249
final var createdFile = fileStore.get(createdFileId);
257250
assertTrue(createdFile.isPresent());

hedera-node/hedera-file-service-impl/src/test/java/com/hedera/node/app/service/file/impl/test/handlers/FileGetContentsHandlerTest.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,9 @@
3131
import com.hedera.node.app.service.file.impl.handlers.FileGetContentsHandler;
3232
import com.hedera.node.app.service.file.impl.schemas.V0490FileSchema;
3333
import com.hedera.node.app.service.file.impl.test.FileTestBase;
34-
import com.hedera.node.app.spi.fixtures.ids.FakeEntityIdFactoryImpl;
3534
import com.hedera.node.app.spi.workflows.QueryContext;
3635
import com.hedera.node.config.data.FilesConfig;
37-
import com.hedera.node.config.testfixtures.HederaTestConfigBuilder;
3836
import com.hedera.pbj.runtime.io.buffer.Bytes;
39-
import com.swirlds.config.api.Configuration;
4037
import org.junit.jupiter.api.BeforeEach;
4138
import org.junit.jupiter.api.Test;
4239
import org.junit.jupiter.api.extension.ExtendWith;
@@ -57,18 +54,8 @@ class FileGetContentsHandlerTest extends FileTestBase {
5754

5855
private FileGetContentsHandler subject;
5956

60-
private Configuration config;
61-
6257
@BeforeEach
6358
void setUp() {
64-
config = HederaTestConfigBuilder.create()
65-
.withValue("cryptoCreateWithAlias.enabled", true)
66-
.withValue("ledger.maxAutoAssociations", 5000)
67-
.withValue("entities.limitTokenAssociations", false)
68-
.withValue("tokens.maxPerAccount", 1000)
69-
.withValue("hedera.shard", 5L)
70-
.withValue("hedera.realm", 10L)
71-
.getOrCreateConfig();
7259
subject = new FileGetContentsHandler(usageEstimator, genesisSchema);
7360
}
7461

@@ -194,7 +181,7 @@ void getsResponseIfOkResponse() {
194181
.nodeTransactionPrecheckCode(ResponseCodeEnum.OK)
195182
.build();
196183
final var expectedContent = getExpectedContent();
197-
given(handleContext.configuration()).willReturn(config);
184+
given(context.configuration()).willReturn(DEFAULT_CONFIG);
198185
final var query = createGetFileContentQueryFromEntityId(fileId.fileNum());
199186
when(context.query()).thenReturn(query);
200187
when(context.createStore(ReadableFileStore.class)).thenReturn(readableStore);
@@ -235,7 +222,7 @@ private Query createGetFileContentQuery(final FileID fileId) {
235222
}
236223

237224
private Query createGetFileContentQuery(long fileNum) {
238-
final var fileId = FileID.newBuilder().fileNum(fileNum).build();
225+
final var fileId = idFactory.newFileId(fileNum);
239226
final var data = FileGetContentsQuery.newBuilder()
240227
.fileID(fileId)
241228
.header(QueryHeader.newBuilder().payment(Transaction.DEFAULT).build())
@@ -246,10 +233,7 @@ private Query createGetFileContentQuery(long fileNum) {
246233

247234
private Query createGetFileContentQueryFromEntityId(long fileNum) {
248235

249-
final FileID fileID = new FakeEntityIdFactoryImpl(
250-
Long.parseLong(config.getValue("hedera.shard")),
251-
Long.parseLong(config.getValue("hedera.realm")))
252-
.newFileId(fileNum);
236+
final FileID fileID = idFactory.newFileId(fileNum);
253237
final var data = FileGetContentsQuery.newBuilder()
254238
.fileID(fileID)
255239
.header(QueryHeader.newBuilder().payment(Transaction.DEFAULT).build())

hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/TransactionProcessor.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,19 @@ private InvolvedParties partiesWhenContractNotRequired(
304304
updater.setupTopLevelLazyCreate(requireNonNull(parties.receiverAddress));
305305
} else {
306306
updater.setContractNotRequired();
307-
parties =
308-
new InvolvedParties(sender, relayer, contractIDToBesuAddress(transaction.contractIdOrThrow()));
307+
parties = new InvolvedParties(
308+
sender,
309+
relayer,
310+
contractIDToBesuAddress(updater.entityIdFactory(), transaction.contractIdOrThrow()));
309311
}
310312
} else {
311313
updater.setContractNotRequired();
312314
parties = new InvolvedParties(
313315
sender,
314316
relayer,
315-
to != null ? to.getAddress() : contractIDToBesuAddress(transaction.contractIdOrThrow()));
317+
to != null
318+
? to.getAddress()
319+
: contractIDToBesuAddress(updater.entityIdFactory(), transaction.contractIdOrThrow()));
316320
}
317321
return parties;
318322
}

0 commit comments

Comments
 (0)