Skip to content

Commit

Permalink
chore: (0.58) support maxSignedTxnSize override in standalone Transac…
Browse files Browse the repository at this point in the history
…tionExecutor (#17204)

Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
  • Loading branch information
tinker-michaelj authored Jan 6, 2025
1 parent 358bbba commit c41751e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
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 All @@ -16,6 +16,7 @@

package com.hedera.node.app.workflows.standalone;

import com.hedera.node.app.annotations.MaxSignedTxnSize;
import com.hedera.node.app.authorization.AuthorizerInjectionModule;
import com.hedera.node.app.config.BootstrapConfigProviderImpl;
import com.hedera.node.app.config.ConfigProviderImpl;
Expand Down Expand Up @@ -86,6 +87,9 @@ interface Builder {
@BindsInstance
Builder throttleFactory(Throttle.Factory throttleFactory);

@BindsInstance
Builder maxSignedTxnSize(@MaxSignedTxnSize int maxSignedTxnSize);

ExecutorComponent build();
}

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 @@ -39,6 +39,7 @@ public interface TransactionExecutor {
* @param consensusNow the consensus time at which the transaction is to be executed
* @param operationTracers the Besu {@link OperationTracer} instances to use for contract operations
* @return one or more {@link SingleTransactionRecord}s for the executed transaction
* @throws RuntimeException if the executor cannot build a dispatch from the given transaction
*/
List<SingleTransactionRecord> execute(
@NonNull TransactionBody transactionBody,
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 All @@ -20,6 +20,7 @@
import static com.hedera.node.app.spi.AppContext.Gossip.UNAVAILABLE_GOSSIP;
import static com.hedera.node.app.workflows.standalone.impl.NoopVerificationStrategies.NOOP_VERIFICATION_STRATEGIES;

import com.hedera.node.app.Hedera;
import com.hedera.node.app.config.BootstrapConfigProviderImpl;
import com.hedera.node.app.config.ConfigProviderImpl;
import com.hedera.node.app.info.NodeInfoImpl;
Expand Down Expand Up @@ -47,6 +48,7 @@
import java.time.InstantSource;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
Expand All @@ -59,6 +61,7 @@ public enum TransactionExecutors {
TRANSACTION_EXECUTORS;

public static final NodeInfo DEFAULT_NODE_INFO = new NodeInfoImpl(0, asAccount(3L), 10, List.of(), Bytes.EMPTY);
public static final String MAX_SIGNED_TXN_SIZE_PROPERTY = "executor.maxSignedTxnSize";

/**
* A strategy to bind and retrieve {@link OperationTracer} scoped to a thread.
Expand Down Expand Up @@ -137,6 +140,9 @@ private ExecutorComponent newExecutorComponent(
.scheduleServiceImpl(scheduleService)
.metrics(NO_OP_METRICS)
.throttleFactory(appContext.throttleFactory())
.maxSignedTxnSize(Optional.ofNullable(properties.get(MAX_SIGNED_TXN_SIZE_PROPERTY))
.map(Integer::parseInt)
.orElse(Hedera.MAX_SIGNED_TXN_SIZE))
.build();
componentRef.set(component);
return component;
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 All @@ -17,8 +17,6 @@
package com.hedera.node.app.workflows.standalone.impl;

import com.hedera.hapi.node.base.AccountID;
import com.hedera.node.app.Hedera;
import com.hedera.node.app.annotations.MaxSignedTxnSize;
import com.hedera.node.app.annotations.NodeSelfId;
import com.hedera.node.app.metrics.StoreMetricsServiceImpl;
import com.hedera.node.app.spi.metrics.StoreMetricsService;
Expand Down Expand Up @@ -63,13 +61,6 @@ static InstantSource provideInstantSource() {
return InstantSource.system();
}

@Provides
@Singleton
@MaxSignedTxnSize
static int maxSignedTxnSize() {
return Hedera.MAX_SIGNED_TXN_SIZE;
}

@Provides
@Singleton
@NodeSelfId
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 All @@ -21,8 +21,10 @@
import static com.hedera.node.app.spi.key.KeyUtils.IMMUTABILITY_SENTINEL_KEY;
import static com.hedera.node.app.util.FileUtilities.createFileID;
import static com.hedera.node.app.workflows.standalone.TransactionExecutors.DEFAULT_NODE_INFO;
import static com.hedera.node.app.workflows.standalone.TransactionExecutors.MAX_SIGNED_TXN_SIZE_PROPERTY;
import static com.hedera.node.app.workflows.standalone.TransactionExecutors.TRANSACTION_EXECUTORS;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;

import com.hedera.hapi.node.base.AccountID;
import com.hedera.hapi.node.base.ContractID;
Expand Down Expand Up @@ -187,6 +189,20 @@ void executesTransactionsAsExpected() {
assertThat(stringWriter.toString()).startsWith(EXPECTED_TRACE_START);
}

@Test
void respectsOverrideMaxSignedTxnSize() {
final var overrides = Map.of(MAX_SIGNED_TXN_SIZE_PROPERTY, "42");
// Construct a full implementation of the consensus node State API with all genesis accounts and files
final var state = genesisState(overrides);

// Get a standalone executor based on this state, with an override to allow slightly longer memos
final var executor = TRANSACTION_EXECUTORS.newExecutor(state, overrides, null);

// With just 42 bytes allowed for signed transactions, the executor will not be able to construct
// a dispatch for the transaction and throw an exception
assertThrows(NullPointerException.class, () -> executor.execute(uploadMultipurposeInitcode(), Instant.EPOCH));
}

private TransactionBody contractCallMultipurposePickFunction() {
final var callData = PICK_FUNCTION.encodeCallWithArgs();
return newBodyBuilder()
Expand Down

0 comments on commit c41751e

Please sign in to comment.