Skip to content

Commit 34ba879

Browse files
authored
fix: Node account ID doesn't update for ingest (#21220)
Signed-off-by: ibankov <[email protected]>
1 parent 7fd9668 commit 34ba879

File tree

11 files changed

+161
-83
lines changed

11 files changed

+161
-83
lines changed

hedera-node/hedera-app/src/main/java/com/hedera/node/app/HederaInjectionComponent.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.hedera.node.app.hints.HintsService;
2424
import com.hedera.node.app.history.HistoryService;
2525
import com.hedera.node.app.info.CurrentPlatformStatus;
26-
import com.hedera.node.app.info.InfoInjectionModule;
2726
import com.hedera.node.app.metrics.MetricsInjectionModule;
2827
import com.hedera.node.app.platform.PlatformModule;
2928
import com.hedera.node.app.records.BlockRecordInjectionModule;
@@ -86,7 +85,6 @@
8685
GrpcInjectionModule.class,
8786
MetricsInjectionModule.class,
8887
AuthorizerInjectionModule.class,
89-
InfoInjectionModule.class,
9088
BlockRecordInjectionModule.class,
9189
BlockStreamModule.class,
9290
PlatformModule.class,

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

Lines changed: 0 additions & 19 deletions
This file was deleted.

hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/TransactionChecker.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import static com.hedera.node.app.spi.workflows.PreCheckException.validateTruePreCheck;
2424
import static java.util.Objects.requireNonNull;
2525

26-
import com.hedera.hapi.node.base.AccountID;
2726
import com.hedera.hapi.node.base.HederaFunctionality;
2827
import com.hedera.hapi.node.base.ResponseCodeEnum;
2928
import com.hedera.hapi.node.base.SignaturePair;
@@ -34,7 +33,6 @@
3433
import com.hedera.hapi.node.transaction.TransactionBody;
3534
import com.hedera.hapi.util.HapiUtils;
3635
import com.hedera.hapi.util.UnknownHederaFunctionality;
37-
import com.hedera.node.app.annotations.NodeSelfId;
3836
import com.hedera.node.app.spi.workflows.PreCheckException;
3937
import com.hedera.node.app.workflows.prehandle.DueDiligenceException;
4038
import com.hedera.node.config.ConfigProvider;
@@ -87,8 +85,6 @@ public class TransactionChecker {
8785
private final Counter deprecatedCounter;
8886
/** The {@link Counter} used to track the number of super deprecated transactions (body, sigs) received. */
8987
private final Counter superDeprecatedCounter;
90-
/** The account ID of the node running this software */
91-
private final AccountID nodeAccount;
9288

9389
private final HederaConfig hederaConfig;
9490
private final JumboTransactionsConfig jumboTransactionsConfig;
@@ -105,11 +101,7 @@ public class TransactionChecker {
105101
* @throws NullPointerException if one of the arguments is {@code null}
106102
*/
107103
@Inject
108-
public TransactionChecker(
109-
@NodeSelfId @NonNull final AccountID nodeAccount,
110-
@NonNull final ConfigProvider configProvider,
111-
@NonNull final Metrics metrics) {
112-
this.nodeAccount = requireNonNull(nodeAccount);
104+
public TransactionChecker(@NonNull final ConfigProvider configProvider, @NonNull final Metrics metrics) {
113105
this.deprecatedCounter = metrics.getOrCreate(new Counter.Config("app", COUNTER_DEPRECATED_TXNS_NAME)
114106
.withDescription(COUNTER_RECEIVED_DEPRECATED_DESC));
115107
this.superDeprecatedCounter = metrics.getOrCreate(new Counter.Config("app", COUNTER_SUPER_DEPRECATED_TXNS_NAME)
@@ -446,8 +438,8 @@ private void checkTransactionID(@NonNull final TransactionID txnId) throws PreCh
446438
// alias payer account is not allowed to submit transactions.
447439
final var accountID = txnId.accountID();
448440
final var isPlausibleAccount = accountID != null
449-
&& accountID.shardNum() == nodeAccount.shardNum()
450-
&& accountID.realmNum() == nodeAccount.realmNum()
441+
&& accountID.shardNum() == hederaConfig.shard()
442+
&& accountID.realmNum() == hederaConfig.realm()
451443
&& accountID.hasAccountNum()
452444
&& accountID.accountNumOrElse(0L) > 0;
453445

hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/ingest/IngestChecker.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import static java.util.Objects.requireNonNull;
3535
import static org.hiero.consensus.model.status.PlatformStatus.ACTIVE;
3636

37-
import com.hedera.hapi.node.base.AccountID;
3837
import com.hedera.hapi.node.base.HederaFunctionality;
3938
import com.hedera.hapi.node.base.SignaturePair;
4039
import com.hedera.hapi.node.base.TokenTransferList;
@@ -43,7 +42,6 @@
4342
import com.hedera.hapi.node.state.token.Account;
4443
import com.hedera.hapi.node.token.CryptoTransferTransactionBody;
4544
import com.hedera.hapi.node.token.TokenAirdropTransactionBody;
46-
import com.hedera.node.app.annotations.NodeSelfId;
4745
import com.hedera.node.app.blocks.BlockStreamManager;
4846
import com.hedera.node.app.fees.FeeContextImpl;
4947
import com.hedera.node.app.fees.FeeManager;
@@ -55,6 +53,7 @@
5553
import com.hedera.node.app.signature.SignatureVerifier;
5654
import com.hedera.node.app.spi.authorization.Authorizer;
5755
import com.hedera.node.app.spi.fees.FeeContext;
56+
import com.hedera.node.app.spi.info.NetworkInfo;
5857
import com.hedera.node.app.spi.signatures.SignatureVerification;
5958
import com.hedera.node.app.spi.workflows.PreCheckException;
6059
import com.hedera.node.app.state.DeduplicationCache;
@@ -119,7 +118,7 @@ public final class IngestChecker {
119118
private final DeduplicationCache deduplicationCache;
120119
private final TransactionDispatcher dispatcher;
121120
private final FeeManager feeManager;
122-
private final AccountID nodeAccount;
121+
private final NetworkInfo networkInfo;
123122
private final Authorizer authorizer;
124123
private final SynchronizedThrottleAccumulator synchronizedThrottleAccumulator;
125124
private final InstantSource instantSource;
@@ -157,7 +156,7 @@ public void setThrottleUsages(@Nullable List<ThrottleUsage> throttleUsages) {
157156
/**
158157
* Constructor of the {@code IngestChecker}
159158
*
160-
* @param nodeAccount the {@link AccountID} of the node
159+
* @param networkInfo the {@link NetworkInfo} that contains information about the network
161160
* @param currentPlatformStatus the {@link CurrentPlatformStatus} that contains the current status of the platform
162161
* @param transactionChecker the {@link TransactionChecker} that pre-processes the bytes of a transaction
163162
* @param solvencyPreCheck the {@link SolvencyPreCheck} that checks payer balance
@@ -172,7 +171,7 @@ public void setThrottleUsages(@Nullable List<ThrottleUsage> throttleUsages) {
172171
*/
173172
@Inject
174173
public IngestChecker(
175-
@NodeSelfId @NonNull final AccountID nodeAccount,
174+
@NonNull final NetworkInfo networkInfo,
176175
@NonNull final CurrentPlatformStatus currentPlatformStatus,
177176
@NonNull final BlockStreamManager blockStreamManager,
178177
@NonNull final TransactionChecker transactionChecker,
@@ -187,7 +186,7 @@ public IngestChecker(
187186
@NonNull final InstantSource instantSource,
188187
@NonNull final OpWorkflowMetrics workflowMetrics,
189188
@Nullable final AtomicBoolean systemEntitiesCreatedFlag) {
190-
this.nodeAccount = requireNonNull(nodeAccount, "nodeAccount must not be null");
189+
this.networkInfo = requireNonNull(networkInfo, "networkInfo must not be null");
191190
this.currentPlatformStatus = requireNonNull(currentPlatformStatus, "currentPlatformStatus must not be null");
192191
this.blockStreamManager = requireNonNull(blockStreamManager, "blockStreamManager must not be null");
193192
this.transactionChecker = requireNonNull(transactionChecker, "transactionChecker must not be null");
@@ -277,7 +276,8 @@ private void runAllChecks(
277276
final var functionality = txInfo.functionality();
278277

279278
// 1a. Verify the transaction has been sent to *this* node
280-
if (!nodeAccount.equals(txBody.nodeAccountID()) && innerTransaction == NO) {
279+
final var nodeAccountId = networkInfo.selfNodeInfo().accountId();
280+
if (!nodeAccountId.equals(txBody.nodeAccountID()) && innerTransaction == NO) {
281281
throw new PreCheckException(INVALID_NODE_ACCOUNT);
282282
}
283283

hedera-node/hedera-app/src/main/java/com/hedera/node/app/workflows/standalone/impl/StandaloneModule.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44
import static com.hedera.node.app.throttle.ThrottleAccumulator.ThrottleType.BACKEND_THROTTLE;
55
import static com.hedera.node.app.throttle.ThrottleAccumulator.ThrottleType.NOOP_THROTTLE;
66

7-
import com.hedera.hapi.node.base.AccountID;
87
import com.hedera.hapi.platform.state.PlatformState;
9-
import com.hedera.node.app.annotations.NodeSelfId;
108
import com.hedera.node.app.metrics.StoreMetricsServiceImpl;
11-
import com.hedera.node.app.spi.ids.EntityIdFactory;
129
import com.hedera.node.app.spi.info.NetworkInfo;
1310
import com.hedera.node.app.spi.metrics.StoreMetricsService;
1411
import com.hedera.node.app.throttle.ThrottleAccumulator;
@@ -75,14 +72,6 @@ static InstantSource provideInstantSource() {
7572
return InstantSource.system();
7673
}
7774

78-
@Provides
79-
@Singleton
80-
@NodeSelfId
81-
static AccountID provideNodeSelfId(EntityIdFactory entityIdFactory) {
82-
// This is only used to check the shard and realm of account ids
83-
return entityIdFactory.newDefaultAccountId();
84-
}
85-
8675
@Provides
8776
@Singleton
8877
static StoreMetricsService provideStoreMetricsService(Metrics metrics) {

hedera-node/hedera-app/src/test/java/com/hedera/node/app/throttle/ThrottleAccumulatorTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import com.hedera.hapi.node.base.Key;
4646
import com.hedera.hapi.node.base.ResponseCodeEnum;
4747
import com.hedera.hapi.node.base.ScheduleID;
48-
import com.hedera.hapi.node.base.SemanticVersion;
4948
import com.hedera.hapi.node.base.SignatureMap;
5049
import com.hedera.hapi.node.base.TokenID;
5150
import com.hedera.hapi.node.base.TokenTransferList;
@@ -203,7 +202,6 @@ class ThrottleAccumulatorTest {
203202
@Mock
204203
private TransactionInfo transactionInfo;
205204

206-
private SemanticVersion softwareVersionFactory = SemanticVersion.DEFAULT;
207205
private final HederaConfig hederaConfig =
208206
HederaTestConfigBuilder.create().getOrCreateConfig().getConfigData(HederaConfig.class);
209207

hedera-node/hedera-app/src/test/java/com/hedera/node/app/workflows/TransactionCheckerTest.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ void setup() {
165165
1);
166166

167167
// And create the checker itself
168-
checker = new TransactionChecker(nodeSelfAccountId, props, metrics);
168+
checker = new TransactionChecker(props, metrics);
169169
}
170170

171171
@Nested
@@ -175,12 +175,8 @@ class ConstructorTest {
175175
@SuppressWarnings("ConstantConditions")
176176
@DisplayName("Constructor throws on illegal arguments")
177177
void testConstructorWithIllegalArguments() {
178-
assertThatThrownBy(() -> new TransactionChecker(null, props, metrics))
179-
.isInstanceOf(NullPointerException.class);
180-
assertThatThrownBy(() -> new TransactionChecker(nodeSelfAccountId, null, metrics))
181-
.isInstanceOf(NullPointerException.class);
182-
assertThatThrownBy(() -> new TransactionChecker(nodeSelfAccountId, props, null))
183-
.isInstanceOf(NullPointerException.class);
178+
assertThatThrownBy(() -> new TransactionChecker(null, metrics)).isInstanceOf(NullPointerException.class);
179+
assertThatThrownBy(() -> new TransactionChecker(props, null)).isInstanceOf(NullPointerException.class);
184180
}
185181
}
186182

@@ -340,7 +336,7 @@ void doesNotPassIfMoreThenMaxJumboSizeWithEnabledJumbo() {
340336
.getOrCreateConfig(),
341337
1);
342338

343-
checker = new TransactionChecker(nodeSelfAccountId, props, metrics);
339+
checker = new TransactionChecker(props, metrics);
344340

345341
int maxJumboTxnSize = props.getConfiguration()
346342
.getConfigData(JumboTransactionsConfig.class)
@@ -361,7 +357,7 @@ void passedWithMoreThen6KbWithJumboEnabled() {
361357
.getOrCreateConfig(),
362358
1);
363359

364-
checker = new TransactionChecker(nodeSelfAccountId, props, metrics);
360+
checker = new TransactionChecker(props, metrics);
365361

366362
// assert that even if we are sending a transaction with more than 6KB,
367363
// it will not fail with TRANSACTION_OVERSIZE
@@ -385,7 +381,7 @@ void happyPath() {
385381
.getOrCreateConfig(),
386382
1);
387383

388-
checker = new TransactionChecker(nodeSelfAccountId, props, metrics);
384+
checker = new TransactionChecker(props, metrics);
389385

390386
final var maxJumboEthereumCallDataSize = props.getConfiguration()
391387
.getConfigData(JumboTransactionsConfig.class)
@@ -419,7 +415,7 @@ void withEnabledJumboSizeBiggerThenMaxTxnSizeWithNotSupportedFunctionality() {
419415
.getOrCreateConfig(),
420416
1);
421417

422-
checker = new TransactionChecker(nodeSelfAccountId, props, metrics);
418+
checker = new TransactionChecker(props, metrics);
423419

424420
TransactionInfo txInfo = mock(TransactionInfo.class);
425421
when(txInfo.signedTx())

hedera-node/hedera-app/src/test/java/com/hedera/node/app/workflows/ingest/IngestCheckerTest.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static com.hedera.node.app.spi.fixtures.workflows.ExceptionConditions.estimatedFee;
2323
import static com.hedera.node.app.spi.fixtures.workflows.ExceptionConditions.responseCode;
2424
import static com.hedera.node.app.workflows.handle.dispatch.DispatchValidator.WorkflowCheck.INGEST;
25+
import static com.swirlds.platform.system.address.AddressBookUtils.endpointFor;
2526
import static org.assertj.core.api.Assertions.assertThat;
2627
import static org.assertj.core.api.Assertions.assertThatCode;
2728
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -55,11 +56,13 @@
5556
import com.hedera.node.app.fees.FeeManager;
5657
import com.hedera.node.app.fixtures.AppTestBase;
5758
import com.hedera.node.app.info.CurrentPlatformStatus;
59+
import com.hedera.node.app.info.NodeInfoImpl;
5860
import com.hedera.node.app.signature.SignatureExpander;
5961
import com.hedera.node.app.signature.SignatureVerificationFuture;
6062
import com.hedera.node.app.signature.SignatureVerifier;
6163
import com.hedera.node.app.spi.authorization.Authorizer;
6264
import com.hedera.node.app.spi.fees.Fees;
65+
import com.hedera.node.app.spi.info.NodeInfo;
6366
import com.hedera.node.app.spi.signatures.SignatureVerification;
6467
import com.hedera.node.app.spi.workflows.InsufficientBalanceException;
6568
import com.hedera.node.app.spi.workflows.PreCheckException;
@@ -78,6 +81,7 @@
7881
import com.swirlds.config.api.Configuration;
7982
import java.time.Instant;
8083
import java.time.InstantSource;
84+
import java.util.List;
8185
import java.util.Map;
8286
import java.util.concurrent.ExecutionException;
8387
import java.util.concurrent.TimeoutException;
@@ -153,6 +157,7 @@ class IngestCheckerTest extends AppTestBase {
153157
@BeforeEach
154158
void setUp() throws PreCheckException {
155159
setupStandardStates();
160+
final var app = appBuilder().withSelfNode(selfNodeInfo).build();
156161
when(currentPlatformStatus.get()).thenReturn(PlatformStatus.ACTIVE);
157162

158163
configuration = new VersionedConfigImpl(HederaTestConfigBuilder.createConfig(), 1L);
@@ -185,7 +190,7 @@ void setUp() throws PreCheckException {
185190
.thenReturn(ThrottleResult.allowed());
186191

187192
subject = new IngestChecker(
188-
nodeSelfAccountId,
193+
app.networkInfo(),
189194
currentPlatformStatus,
190195
blockStreamManager,
191196
transactionChecker,
@@ -252,12 +257,10 @@ void testParseAndCheckWithUnknownLedgerIdFails() {
252257
@DisplayName("A wrong nodeId in transaction fails")
253258
void testWrongNodeIdFails() {
254259
// Given a transaction with an unknown node ID
255-
final var otherNodeSelfAccountId = AccountID.newBuilder()
256-
.accountNum(nodeSelfAccountId.accountNumOrElse(0L) + 1L)
257-
.build();
258-
260+
final var tempApp =
261+
appBuilder().withSelfNode(buildNodeWithAccountId(9L)).build();
259262
subject = new IngestChecker(
260-
otherNodeSelfAccountId,
263+
tempApp.networkInfo(),
261264
currentPlatformStatus,
262265
blockStreamManager,
263266
transactionChecker,
@@ -841,4 +844,22 @@ void randomException() throws Exception {
841844
verify(opWorkflowMetrics, never()).incrementThrottled(any());
842845
}
843846
}
847+
848+
private NodeInfo buildNodeWithAccountId(final long accountNum) {
849+
final AccountID nodeSelfAccountId = AccountID.newBuilder()
850+
.shardNum(0)
851+
.realmNum(0)
852+
.accountNum(accountNum)
853+
.build();
854+
855+
return new NodeInfoImpl(
856+
7,
857+
nodeSelfAccountId,
858+
10,
859+
List.of(endpointFor("127.0.0.1", 50211), endpointFor("127.0.0.1", 23456)),
860+
Bytes.wrap("cert7"),
861+
List.of(endpointFor("127.0.0.1", 50211), endpointFor("127.0.0.1", 23456)),
862+
false,
863+
null);
864+
}
844865
}

0 commit comments

Comments
 (0)