Skip to content

Commit

Permalink
05875 query workflow improvements (#5971)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Heinrichs <netopyr@users.noreply.github.com>
  • Loading branch information
netopyr committed Apr 6, 2023
1 parent da33fc8 commit c43b5f1
Show file tree
Hide file tree
Showing 19 changed files with 505 additions and 387 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2023 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hedera.node.app.spi.info;

import com.swirlds.common.system.PlatformStatus;
import edu.umd.cs.findbugs.annotations.NonNull;

/**
* Provides the current platform status.
*/
public interface CurrentPlatformStatus {

/**
* Returns the current platform status.
*
* @return the current platform status
*/
@NonNull
PlatformStatus get();
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,21 @@
* limitations under the License.
*/

package com.hedera.node.app.spi.meta;
package com.hedera.node.app.spi.info;

import com.hedera.pbj.runtime.io.buffer.Bytes;
import edu.umd.cs.findbugs.annotations.NonNull;

/**
* Provides context for query processing.
* Provides information about the network.
*/
public interface QueryContext {
Bytes getLedgerId();
public interface NetworkInfo {

/**
* Returns the current ledger ID.
*
* @return the {@link Bytes} of the current ledger ID
*/
@NonNull
Bytes ledgerId();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2023 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hedera.node.app.spi.info;

import com.swirlds.common.system.address.AddressBook;

/**
* Summarizes useful information about the nodes in the {@link AddressBook} from the Platform. In
* the future, there may be events that require re-reading the book; but at present nodes may treat
* the initializing book as static.
*/
public interface NodeInfo {

/**
* Convenience method to check if this node is zero-stake.
*
* @return whether this node has zero stake.
*/
boolean isSelfZeroStake();
}
1 change: 1 addition & 0 deletions hedera-node/hedera-app-spi/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
exports com.hedera.node.app.spi.records;
exports com.hedera.node.app.spi.validation;
exports com.hedera.node.app.spi.accounts;
exports com.hedera.node.app.spi.info;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.hedera.node.app.components.IngestComponent;
import com.hedera.node.app.components.QueryComponent;
import com.hedera.node.app.fees.AdaptedFeeCalculatorModule;
import com.hedera.node.app.info.InfoDaggerModule;
import com.hedera.node.app.metrics.MetricsDaggerModule;
import com.hedera.node.app.service.mono.ServicesApp;
import com.hedera.node.app.service.mono.config.ConfigModule;
Expand Down Expand Up @@ -101,7 +102,8 @@
AdaptedFeeCalculatorModule.class,
HederaStateModule.class,
MetricsDaggerModule.class,
AuthorizerDaggerModule.class
AuthorizerDaggerModule.class,
InfoDaggerModule.class
})
public interface HederaApp extends ServicesApp {
/* Needed by ServicesState */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (C) 2023 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hedera.node.app.info;

import com.hedera.node.app.spi.info.CurrentPlatformStatus;
import com.hedera.node.app.spi.info.NetworkInfo;
import com.hedera.node.app.spi.info.NodeInfo;
import dagger.Module;
import dagger.Provides;
import edu.umd.cs.findbugs.annotations.NonNull;
import javax.inject.Singleton;

/** A Dagger module for facilities in the {@link com.hedera.node.app.info} package. */
@Module
public interface InfoDaggerModule {

@Provides
@Singleton
static CurrentPlatformStatus provideCurrentPlatformStatus(
@NonNull final com.hedera.node.app.service.mono.context.CurrentPlatformStatus delegate) {
return new MonoCurrentPlatformStatus(delegate);
}

@Provides
@Singleton
static NetworkInfo provideNetworkInfo(@NonNull final com.hedera.node.app.service.mono.config.NetworkInfo delegate) {
return new MonoNetworkInfo(delegate);
}

@Provides
@Singleton
static NodeInfo provideNodeInfo(@NonNull final com.hedera.node.app.service.mono.context.NodeInfo delegate) {
return new MonoNodeInfo(delegate);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2023 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hedera.node.app.info;

import static java.util.Objects.requireNonNull;

import com.hedera.node.app.spi.info.CurrentPlatformStatus;
import com.swirlds.common.system.PlatformStatus;
import edu.umd.cs.findbugs.annotations.NonNull;

/**
* Implementation of {@link CurrentPlatformStatus} that delegates to the mono-service.
*/
public class MonoCurrentPlatformStatus implements CurrentPlatformStatus {

private final com.hedera.node.app.service.mono.context.CurrentPlatformStatus delegate;

/**
* Constructs a {@link MonoCurrentPlatformStatus} with the given delegate.
*
* @param delegate the delegate
* @throws NullPointerException if {@code delegate} is {@code null}
*/
public MonoCurrentPlatformStatus(@NonNull com.hedera.node.app.service.mono.context.CurrentPlatformStatus delegate) {
this.delegate = requireNonNull(delegate);
}

@Override
@NonNull
public PlatformStatus get() {
final var status = delegate.get();
return status != null ? status : PlatformStatus.STARTING_UP;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2023 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hedera.node.app.info;

import static java.util.Objects.requireNonNull;

import com.hedera.node.app.spi.info.NetworkInfo;
import com.hedera.pbj.runtime.io.buffer.Bytes;
import edu.umd.cs.findbugs.annotations.NonNull;

/**
* Implementation of {@link NetworkInfo} that delegates to the mono-service.
*/
public class MonoNetworkInfo implements NetworkInfo {

private final com.hedera.node.app.service.mono.config.NetworkInfo delegate;

/**
* Constructs a {@link MonoNetworkInfo} with the given delegate.
*
* @param delegate the delegate
* @throws NullPointerException if {@code delegate} is {@code null}
*/
public MonoNetworkInfo(@NonNull com.hedera.node.app.service.mono.config.NetworkInfo delegate) {
this.delegate = requireNonNull(delegate);
}

@Override
@NonNull
public Bytes ledgerId() {
final var ledgerId = delegate.ledgerId();
return ledgerId != null ? Bytes.wrap(ledgerId.toByteArray()) : Bytes.EMPTY;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2023 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.hedera.node.app.info;

import static java.util.Objects.requireNonNull;

import com.hedera.node.app.spi.info.NodeInfo;
import edu.umd.cs.findbugs.annotations.NonNull;

/**
* Implementation of {@link NodeInfo} that delegates to the mono-service.
*/
public class MonoNodeInfo implements NodeInfo {

private final com.hedera.node.app.service.mono.context.NodeInfo delegate;

/**
* Constructs a {@link MonoNodeInfo} with the given delegate.
*
* @param delegate the delegate
* @throws NullPointerException if {@code delegate} is {@code null}
*/
public MonoNodeInfo(@NonNull com.hedera.node.app.service.mono.context.NodeInfo delegate) {
this.delegate = requireNonNull(delegate);
}

@Override
public boolean isSelfZeroStake() {
return delegate.isSelfZeroStake();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@

import static com.hedera.hapi.node.base.HederaFunctionality.CRYPTO_TRANSFER;
import static com.hedera.hapi.node.base.ResponseCodeEnum.INSUFFICIENT_TX_FEE;
import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_NODE_ACCOUNT;
import static com.hedera.hapi.node.base.ResponseCodeEnum.NOT_SUPPORTED;
import static com.hedera.hapi.node.base.ResponseCodeEnum.OK;
import static com.hedera.hapi.node.base.ResponseCodeEnum.PLATFORM_NOT_ACTIVE;
import static com.swirlds.common.system.PlatformStatus.ACTIVE;
import static java.util.Objects.requireNonNull;

import com.hedera.hapi.node.base.AccountID;
Expand All @@ -32,6 +35,8 @@
import com.hedera.node.app.authorization.Authorizer;
import com.hedera.node.app.service.mono.queries.validation.QueryFeeCheck;
import com.hedera.node.app.service.token.impl.handlers.CryptoTransferHandler;
import com.hedera.node.app.spi.info.CurrentPlatformStatus;
import com.hedera.node.app.spi.info.NodeInfo;
import com.hedera.node.app.spi.numbers.HederaAccountNumbers;
import com.hedera.node.app.spi.workflows.InsufficientBalanceException;
import com.hedera.node.app.spi.workflows.PreCheckException;
Expand All @@ -45,6 +50,8 @@
@Singleton
public class QueryChecker {

private final NodeInfo nodeInfo;
private final CurrentPlatformStatus currentPlatformStatus;
private final TransactionChecker transactionChecker;
private final HederaAccountNumbers accountNumbers;
private final QueryFeeCheck queryFeeCheck;
Expand All @@ -54,6 +61,8 @@ public class QueryChecker {
/**
* Constructor of {@code QueryChecker}
*
* @param nodeInfo the {@link NodeInfo} that contains information about the node
* @param currentPlatformStatus the {@link CurrentPlatformStatus} that contains the current status of the platform
* @param transactionChecker the {@link TransactionChecker} that (eventually) pre-processes the CryptoTransfer
* @param accountNumbers the {@link HederaAccountNumbers} that contains a list of special accounts
* @param queryFeeCheck the {@link QueryFeeCheck} that checks if fees can be paid
Expand All @@ -64,18 +73,37 @@ public class QueryChecker {
*/
@Inject
public QueryChecker(
@NonNull final NodeInfo nodeInfo,
@NonNull final CurrentPlatformStatus currentPlatformStatus,
@NonNull final TransactionChecker transactionChecker,
@NonNull final HederaAccountNumbers accountNumbers,
@NonNull final QueryFeeCheck queryFeeCheck,
@NonNull final Authorizer authorizer,
@NonNull final CryptoTransferHandler cryptoTransferHandler) {
this.nodeInfo = requireNonNull(nodeInfo);
this.currentPlatformStatus = requireNonNull(currentPlatformStatus);
this.transactionChecker = requireNonNull(transactionChecker);
this.accountNumbers = requireNonNull(accountNumbers);
this.queryFeeCheck = requireNonNull(queryFeeCheck);
this.authorizer = requireNonNull(authorizer);
this.cryptoTransferHandler = requireNonNull(cryptoTransferHandler);
}

/**
* Checks the general state of the node
*
* @throws PreCheckException if the node is unable to process queries
*/
public void checkNodeState() throws PreCheckException {
if (nodeInfo.isSelfZeroStake()) {
// Zero stake nodes are currently not supported
throw new PreCheckException(INVALID_NODE_ACCOUNT);
}
if (currentPlatformStatus.get() != ACTIVE) {
throw new PreCheckException(PLATFORM_NOT_ACTIVE);
}
}

/**
* Validates the {@link HederaFunctionality#CRYPTO_TRANSFER} that is contained in a query
*
Expand Down
Loading

0 comments on commit c43b5f1

Please sign in to comment.