Skip to content

Commit

Permalink
Merge upstream
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Tinker <[email protected]>
  • Loading branch information
tinker-michaelj committed Nov 16, 2024
2 parents f315e9a + 80100a3 commit 218cfb8
Show file tree
Hide file tree
Showing 67 changed files with 4,437 additions and 4,004 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,14 @@ val maven =
url = "https://www.hashgraph.com/"
inceptionYear = "2016"

// this field must be present. Default to empty string.
description =
providers
.fileContents(layout.projectDirectory.file("../description.txt"))
.asText
.orElse(provider { project.description })
.orElse(provider(project::getDescription))
.map { it.replace("\n", " ").trim() }
.orNull
.orElse("")

organization {
name = "Hedera Hashgraph, LLC"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
import static com.hedera.node.app.util.HederaAsciiArt.HEDERA;
import static com.hedera.node.config.types.StreamMode.BLOCKS;
import static com.hedera.node.config.types.StreamMode.RECORDS;
import static com.swirlds.platform.roster.RosterRetriever.buildRoster;
import static com.swirlds.platform.state.service.PlatformStateService.PLATFORM_STATE_SERVICE;
import static com.swirlds.platform.state.service.schemas.V0540PlatformStateSchema.PLATFORM_STATE_KEY;
import static com.swirlds.platform.system.InitTrigger.EVENT_STREAM_RECOVERY;
import static com.swirlds.platform.system.InitTrigger.GENESIS;
import static com.swirlds.platform.system.InitTrigger.RECONNECT;
import static com.swirlds.platform.system.address.AddressBookUtils.createRoster;
import static com.swirlds.platform.system.status.PlatformStatus.ACTIVE;
import static com.swirlds.platform.system.status.PlatformStatus.STARTING_UP;
import static java.nio.charset.StandardCharsets.UTF_8;
Expand Down Expand Up @@ -624,7 +624,7 @@ private void migrateSchemas(
if (trigger == GENESIS) {
final var config = configProvider.getConfiguration();
final var ledgerConfig = config.getConfigData(LedgerConfig.class);
final var genesisRoster = buildRoster(requireNonNull(genesisAddressBook));
final var genesisRoster = createRoster(requireNonNull(genesisAddressBook));
genesisNetworkInfo = new GenesisNetworkInfo(genesisRoster, ledgerConfig.id());
}
blockStreamService.resetMigratedLastBlockHash();
Expand Down Expand Up @@ -963,7 +963,7 @@ private void initializeDagger(@NonNull final State state, @NonNull final InitTri
serviceMigrator,
version,
configProvider.getConfiguration(),
buildRoster(platform.getAddressBook()));
createRoster(platform.getAddressBook()));
final var networkInfo =
new StateNetworkInfo(state, activeRoster, platform.getSelfId().id(), configProvider);
// Fully qualified so as to not confuse javadoc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
import static com.swirlds.platform.builder.internal.StaticPlatformBuilder.setupGlobalMetrics;
import static com.swirlds.platform.config.internal.PlatformConfigUtils.checkConfiguration;
import static com.swirlds.platform.crypto.CryptoStatic.initNodeSecurity;
import static com.swirlds.platform.roster.RosterRetriever.buildRoster;
import static com.swirlds.platform.state.signed.StartupStateUtils.getInitialState;
import static com.swirlds.platform.system.SystemExitCode.CONFIGURATION_ERROR;
import static com.swirlds.platform.system.SystemExitCode.NODE_ADDRESS_MISMATCH;
import static com.swirlds.platform.system.SystemExitUtils.exitSystem;
import static com.swirlds.platform.system.address.AddressBookUtils.createRoster;
import static com.swirlds.platform.system.address.AddressBookUtils.initializeAddressBook;
import static com.swirlds.platform.util.BootstrapUtils.checkNodesToRun;
import static com.swirlds.platform.util.BootstrapUtils.getNodesToRun;
Expand Down Expand Up @@ -276,7 +276,7 @@ public static void main(final String... args) throws Exception {
final var addressBook = initializeAddressBook(selfId, version, initialState, diskAddressBook, platformContext);

// Follow the Inversion of Control pattern by injecting all needed dependencies into the PlatformBuilder.
final var roster = buildRoster(addressBook);
final var roster = createRoster(addressBook);
final var platformBuilder = PlatformBuilder.create(
Hedera.APP_NAME,
Hedera.SWIRLD_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.hedera.node.app.fixtures;

import static com.swirlds.platform.roster.RosterRetriever.buildRoster;
import static com.swirlds.platform.system.address.AddressBookUtils.createRoster;
import static com.swirlds.platform.system.address.AddressBookUtils.endpointFor;
import static com.swirlds.platform.test.fixtures.state.TestSchema.CURRENT_VERSION;
import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -340,7 +340,7 @@ public App build() {
final var addressBook = new AddressBook(addresses);
final var platform = new FakePlatform(realSelfNodeInfo.nodeId(), addressBook);
final var initialState = new FakeState();
final var genesisRoster = buildRoster(addressBook);
final var genesisRoster = createRoster(addressBook);
final var networkInfo = new GenesisNetworkInfo(genesisRoster, Bytes.fromHex("03"));
final var startupNetworks = new FakeStartupNetworks(Network.newBuilder()
.nodeMetadata(genesisRoster.rosterEntries().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public record ContractsConfig(
boolean precompileHrcFacadeAssociateEnabled,
@ConfigProperty(value = "systemContract.accountService.enabled", defaultValue = "true") @NetworkProperty
boolean systemContractAccountServiceEnabled,
@ConfigProperty(value = "systemContract.scheduleService.enabled", defaultValue = "false") @NetworkProperty
boolean systemContractScheduleServiceEnabled,
@ConfigProperty(value = "systemContract.accountService.isAuthorizedRawEnabled", defaultValue = "true")
@NetworkProperty
boolean systemContractAccountServiceIsAuthorizedRawEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.hedera.hapi.node.token.CryptoTransferTransactionBody;
import com.hedera.hapi.node.transaction.TransactionBody;
import com.hedera.node.app.service.contract.impl.annotations.TransactionScope;
import com.hedera.node.app.service.schedule.ReadableScheduleStore;
import com.hedera.node.app.service.token.ReadableAccountStore;
import com.hedera.node.app.service.token.ReadableNftStore;
import com.hedera.node.app.service.token.ReadableTokenRelationStore;
Expand Down Expand Up @@ -90,6 +91,14 @@ public HandleHederaNativeOperations(@NonNull final HandleContext context, @Nulla
return context.storeFactory().readableStore(ReadableAccountStore.class);
}

/**
* {@inheritDoc}
*/
@Override
public @NonNull ReadableScheduleStore readableScheduleStore() {
return context.storeFactory().readableStore(ReadableScheduleStore.class);
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@
import com.hedera.hapi.node.base.Key;
import com.hedera.hapi.node.base.NftID;
import com.hedera.hapi.node.base.ResponseCodeEnum;
import com.hedera.hapi.node.base.ScheduleID;
import com.hedera.hapi.node.base.TokenID;
import com.hedera.hapi.node.state.schedule.Schedule;
import com.hedera.hapi.node.state.token.Account;
import com.hedera.hapi.node.state.token.Nft;
import com.hedera.hapi.node.state.token.Token;
import com.hedera.hapi.node.state.token.TokenRelation;
import com.hedera.hapi.node.token.CryptoTransferTransactionBody;
import com.hedera.node.app.service.contract.impl.state.DispatchingEvmFrameState;
import com.hedera.node.app.service.schedule.ReadableScheduleStore;
import com.hedera.node.app.service.token.ReadableAccountStore;
import com.hedera.node.app.service.token.ReadableNftStore;
import com.hedera.node.app.service.token.ReadableTokenRelationStore;
Expand Down Expand Up @@ -79,6 +82,14 @@ public interface HederaNativeOperations {
@NonNull
ReadableAccountStore readableAccountStore();

/**
* Returns the {@link ReadableScheduleStore} for this {@link HederaNativeOperations}.
*
* @return the {@link ReadableScheduleStore}
*/
@NonNull
ReadableScheduleStore readableScheduleStore();

/**
* Returns the {@link Account} with the given number.
*
Expand Down Expand Up @@ -166,6 +177,18 @@ default Nft getNft(final long tokenNumber, final long serialNo) {
.build());
}

/**
* Returns the {@link Schedule} with the given number.
*
* @param number the schedule number
* @return the schedule transaction, or {@code null} if no such schedule transactionexists
*/
@Nullable
default Schedule getSchedule(final long number) {
return readableScheduleStore()
.get(ScheduleID.newBuilder().scheduleNum(number).build());
}

/**
* Given an EVM address, resolves to the account or contract number (if any) that this address
* is an alias for.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.hedera.hapi.node.base.ResponseCodeEnum;
import com.hedera.hapi.node.token.CryptoTransferTransactionBody;
import com.hedera.node.app.service.contract.impl.annotations.QueryScope;
import com.hedera.node.app.service.schedule.ReadableScheduleStore;
import com.hedera.node.app.service.token.ReadableAccountStore;
import com.hedera.node.app.service.token.ReadableNftStore;
import com.hedera.node.app.service.token.ReadableTokenRelationStore;
Expand Down Expand Up @@ -80,6 +81,14 @@ public QueryHederaNativeOperations(@NonNull final QueryContext context) {
return context.createStore(ReadableAccountStore.class);
}

/**
* {@inheritDoc}
*/
@Override
public @NonNull ReadableScheduleStore readableScheduleStore() {
return context.createStore(ReadableScheduleStore.class);
}

/**
* Refuses to set the nonce of a contract.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractNativeSystemContract;
import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.HasCallFactory;
import com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils;
import com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils.EntityType;
import edu.umd.cs.findbugs.annotations.NonNull;
import javax.inject.Inject;
import javax.inject.Singleton;
Expand All @@ -47,7 +48,7 @@ public HasSystemContract(@NonNull final GasCalculator gasCalculator, @NonNull fi

@Override
protected FrameUtils.CallType callTypeOf(@NonNull MessageFrame frame) {
return FrameUtils.callTypeForAccountOf(frame);
return FrameUtils.callTypeOf(frame, EntityType.REGULAR_ACCOUNT);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (C) 2023-2024 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.service.contract.impl.exec.systemcontracts;

import static com.hedera.node.app.service.contract.impl.exec.failure.CustomExceptionalHaltReason.NOT_SUPPORTED;
import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.FullResult.haltResult;
import static com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils.contractsConfigOf;
import static com.hedera.node.app.service.contract.impl.utils.ConversionUtils.asNumberedContractId;
import static java.util.Objects.requireNonNull;

import com.hedera.hapi.node.base.ContractID;
import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractNativeSystemContract;
import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.HasCallFactory;
import com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils;
import com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils.EntityType;
import edu.umd.cs.findbugs.annotations.NonNull;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.apache.tuweni.bytes.Bytes;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.evm.frame.MessageFrame;
import org.hyperledger.besu.evm.gascalculator.GasCalculator;

/**
* System contract for the Hedera Schedule Service (HSS) system contract.
*/
@Singleton
public class HssSystemContract extends AbstractNativeSystemContract implements HederaSystemContract {
public static final String HSS_SYSTEM_CONTRACT_NAME = "HSS";
public static final String HSS_EVM_ADDRESS = "0x16b";
public static final ContractID HSS_CONTRACT_ID = asNumberedContractId(Address.fromHexString(HSS_EVM_ADDRESS));

@Inject
public HssSystemContract(@NonNull final GasCalculator gasCalculator, @NonNull final HasCallFactory callFactory) {
super(HSS_SYSTEM_CONTRACT_NAME, callFactory, HSS_CONTRACT_ID, gasCalculator);
}

@Override
protected FrameUtils.CallType callTypeOf(@NonNull MessageFrame frame) {
return FrameUtils.callTypeOf(frame, EntityType.SCHEDULE_TXN);
}

@Override
public FullResult computeFully(@NonNull final Bytes input, @NonNull final MessageFrame frame) {
requireNonNull(input);
requireNonNull(frame);

// Check if calls to hedera schedule service is enabled
if (!contractsConfigOf(frame).systemContractScheduleServiceEnabled()) {
return haltResult(NOT_SUPPORTED, frame.getRemainingGas());
}

return super.computeFully(input, frame);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.hedera.node.app.service.contract.impl.exec.systemcontracts.common.AbstractNativeSystemContract;
import com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.HtsCallFactory;
import com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils;
import com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils.EntityType;
import edu.umd.cs.findbugs.annotations.NonNull;
import javax.inject.Inject;
import javax.inject.Singleton;
Expand All @@ -42,6 +43,6 @@ public HtsSystemContract(@NonNull final GasCalculator gasCalculator, @NonNull fi

@Override
protected FrameUtils.CallType callTypeOf(@NonNull MessageFrame frame) {
return FrameUtils.callTypeOf(frame);
return FrameUtils.callTypeOf(frame, EntityType.TOKEN);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public class HasCallAttempt extends AbstractCallAttempt<HasCallAttempt> {
public HasCallAttempt(
@NonNull final Bytes input,
@NonNull final Address senderAddress,
@NonNull final Address authorizingAddress,
final boolean onlyDelegatableContractKeysActive,
@NonNull final HederaWorldUpdater.Enhancement enhancement,
@NonNull final Configuration configuration,
Expand All @@ -73,7 +72,7 @@ public HasCallAttempt(
super(
input,
senderAddress,
authorizingAddress,
senderAddress,
onlyDelegatableContractKeysActive,
enhancement,
configuration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public HasCallFactory(
return new HasCallAttempt(
input,
frame.getSenderAddress(),
frame.getSenderAddress(),
addressChecks.hasParentDelegateCall(frame),
enhancement,
configOf(frame),
Expand Down
Loading

0 comments on commit 218cfb8

Please sign in to comment.