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

fix: Skip transactions older than the software version #13527

Merged
merged 7 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -1107,6 +1107,7 @@ private void initializeDagger(
// Fully qualified so as to not confuse javadoc
daggerApp = com.hedera.node.app.DaggerHederaInjectionComponent.builder()
.initTrigger(trigger)
.softwareVersion(version)
.configProvider(configProvider)
.configProviderImpl(configProvider)
.self(SelfNodeInfoImpl.of(nodeAddress, version))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import com.swirlds.platform.listeners.StateWriteToDiskCompleteListener;
import com.swirlds.platform.system.InitTrigger;
import com.swirlds.platform.system.Platform;
import com.swirlds.platform.system.SoftwareVersion;
import dagger.BindsInstance;
import dagger.Component;
import java.nio.charset.Charset;
Expand Down Expand Up @@ -175,6 +176,9 @@ interface Builder {
@BindsInstance
Builder genesisRecordsConsensusHook(GenesisRecordsConsensusHook genesisRecordsBuilder);

@BindsInstance
Builder softwareVersion(SoftwareVersion softwareVersion);

HederaInjectionComponent build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import static com.hedera.node.app.workflows.prehandle.PreHandleResult.Status.PAYER_UNWILLING_OR_UNABLE_TO_PAY_SERVICE_FEE;
import static com.hedera.node.app.workflows.prehandle.PreHandleResult.Status.PRE_HANDLE_FAILURE;
import static com.hedera.node.app.workflows.prehandle.PreHandleResult.Status.SO_FAR_SO_GOOD;
import static com.swirlds.platform.system.InitTrigger.EVENT_STREAM_RECOVERY;
import static java.util.Collections.emptyMap;
import static java.util.Collections.emptySet;
import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -121,7 +122,9 @@
import com.hedera.pbj.runtime.io.buffer.Bytes;
import com.swirlds.config.api.Configuration;
import com.swirlds.platform.state.PlatformState;
import com.swirlds.platform.system.InitTrigger;
import com.swirlds.platform.system.Round;
import com.swirlds.platform.system.SoftwareVersion;
import com.swirlds.platform.system.events.ConsensusEvent;
import com.swirlds.platform.system.transaction.ConsensusTransaction;
import com.swirlds.state.HederaState;
Expand All @@ -134,6 +137,7 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Stream;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -173,6 +177,8 @@ public class HandleWorkflow {
private final HandleWorkflowMetrics handleWorkflowMetrics;
private final ThrottleServiceManager throttleServiceManager;
private final StoreMetricsService storeMetricsService;
private final InitTrigger initTrigger;
private final SoftwareVersion softwareVersion;

@Inject
public HandleWorkflow(
Expand Down Expand Up @@ -200,7 +206,9 @@ public HandleWorkflow(
@NonNull final CacheWarmer cacheWarmer,
@NonNull final HandleWorkflowMetrics handleWorkflowMetrics,
@NonNull final ThrottleServiceManager throttleServiceManager,
@NonNull final StoreMetricsService storeMetricsService) {
@NonNull final StoreMetricsService storeMetricsService,
@NonNull final InitTrigger initTrigger,
@NonNull final SoftwareVersion softwareVersion) {
this.networkInfo = requireNonNull(networkInfo, "networkInfo must not be null");
this.preHandleWorkflow = requireNonNull(preHandleWorkflow, "preHandleWorkflow must not be null");
this.dispatcher = requireNonNull(dispatcher, "dispatcher must not be null");
Expand Down Expand Up @@ -230,6 +238,8 @@ public HandleWorkflow(
this.handleWorkflowMetrics = requireNonNull(handleWorkflowMetrics, "handleWorkflowMetrics must not be null");
this.throttleServiceManager = requireNonNull(throttleServiceManager, "throttleServiceManager must not be null");
this.storeMetricsService = requireNonNull(storeMetricsService, "storeMetricsService must not be null");
this.initTrigger = requireNonNull(initTrigger, "initTrigger must not be null");
this.softwareVersion = requireNonNull(softwareVersion, "softwareVersion must not be null");
}

/**
Expand Down Expand Up @@ -317,7 +327,7 @@ private void handleUserTransaction(
@NonNull final ConsensusEvent platformEvent,
@NonNull final NodeInfo creator,
@NonNull final ConsensusTransaction platformTxn) {
// (FUTURE) We actually want consider exporting synthetic transactions on every
// (FUTURE) We actually want to consider exporting synthetic transactions on every
// first post-upgrade transaction, not just the first transaction after genesis.
final var consTimeOfLastHandledTxn = blockRecordManager.consTimeOfLastHandledTxn();
final var isFirstTransaction = !consTimeOfLastHandledTxn.isAfter(Instant.EPOCH);
Expand Down Expand Up @@ -413,6 +423,22 @@ private void handleUserTransaction(
.exchangeRate(exchangeRateManager.exchangeRates())
.memo(txBody.memo());

// now we have payer and record builder, check:
// Check if the transaction is submitted by a version before the deployed version.
// If so, set the status on the receipt to BUSY and return
if (this.initTrigger != EVENT_STREAM_RECOVERY
&& softwareVersion.compareTo(platformEvent.getSoftwareVersion()) > 0) {
final var record = recordBuilder.status(ResponseCodeEnum.BUSY).build();

blockRecordManager.endUserTransaction(Stream.of(record), state);
recordCache.add(creator.nodeId(), payer, List.of(record));

// We won't worry about updating the updateTransactionDuration metric here since the transaction was not
// really handled

return;
}

// Set up the verifier
final var hederaConfig = configuration.getConfigData(HederaConfig.class);
final var legacyFeeCalcNetworkVpt =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ void setUp() {
.servicesRegistry(Set::of)
.instantSource(InstantSource.system())
.genesisRecordsConsensusHook(mock(GenesisRecordsConsensusHook.class))
.softwareVersion(mock(HederaSoftwareVersion.class))
.build();

final var state = new FakeHederaState();
Expand Down
Loading
Loading