Skip to content

Commit

Permalink
chore: Clean up HIP-423 loose ends (#16734)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
Signed-off-by: Zhivko Kelchev <zhivko.kelchev@limechain.tech>
Co-authored-by: Zhivko Kelchev <zhivko.kelchev@limechain.tech>
Co-authored-by: Joseph S. <121976561+jsync-swirlds@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 25, 2024
1 parent dac374c commit 8b58baa
Show file tree
Hide file tree
Showing 92 changed files with 3,028 additions and 1,853 deletions.
40 changes: 36 additions & 4 deletions hapi/hedera-protobufs/block/stream/output/state_changes.proto
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,10 @@ enum StateIdentifier {
STATE_ID_ROSTERS = 28;

/**
* A state identifier for scheduled transaction expiration.
* A state identifier for counts of transactions scheduled and
* processed in a second.
*/
STATE_ID_SCHEDULE_IDS_BY_EXPIRY = 29;
STATE_ID_SCHEDULED_COUNTS = 29;

/**
* A state identifier for scheduled transaction deduplication.
Expand All @@ -373,6 +374,16 @@ enum StateIdentifier {
*/
STATE_ID_TSS_VOTES = 32;

/**
* A state identifier for the ordering of scheduled transactions.
*/
STATE_ID_SCHEDULED_ORDERS = 33;

/**
* A state identifier for scheduled throttle usage snapshots.
*/
STATE_ID_SCHEDULED_USAGES = 34;

/**
* A state identifier for the round receipts queue.
*/
Expand Down Expand Up @@ -711,6 +722,21 @@ message MapChangeKey {
* A change to a virtual map keyed by pending airdrop id identifier.
*/
proto.PendingAirdropId pending_airdrop_id_key = 14;

/**
* An exact date and time, with a resolution of one second
*/
proto.TimestampSeconds timestamp_seconds_key = 15;

/**
* An ordering key mapped to a particular schedule.<br/>
* This identifies the order in which long term scheduled transactions
* that are requested to execute in the same consensus second will
* be executed. The value will be the `ScheduleID` for the schedule
* to be executed at a particular consensus second and order within
* that second.
*/
proto.ScheduledOrder scheduled_order_key = 16;
}
}

Expand Down Expand Up @@ -817,14 +843,20 @@ message MapChangeValue {
com.hedera.hapi.node.state.roster.Roster roster_value = 16;

/**
* A list of scheduled ids.
* The value of a map summarizing the counts of scheduled and processed transactions
* within a particular consensus second.
*/
proto.ScheduleIdList schedule_id_list_value = 17;
proto.ScheduledCounts scheduled_counts_value = 17;

/**
* A scheduled id value.
*/
proto.ScheduleID schedule_id_value = 18;

/**
* A change to the scheduled throttle usage snapshots.
*/
proto.ThrottleUsageSnapshots throttle_usage_snapshots_value = 19;
}
}

Expand Down
21 changes: 21 additions & 0 deletions hapi/hedera-protobufs/services/response_code.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1593,4 +1593,25 @@ enum ResponseCodeEnum {
* airdrop and whether the sender can fulfill the offer.
*/
INVALID_TOKEN_IN_PENDING_AIRDROP = 369;

/**
* A scheduled transaction configured to wait for expiry to execute was given
* an expiry time not strictly after the time at which its creation reached
* consensus.
*/
SCHEDULE_EXPIRY_MUST_BE_FUTURE = 370;

/**
* A scheduled transaction configured to wait for expiry to execute was given
* an expiry time too far in the future after the time at which its creation
* reached consensus.
*/
SCHEDULE_EXPIRY_TOO_LONG = 371;

/**
* A scheduled transaction configured to wait for expiry to execute was given
* an expiry time at which there is already too many transactions scheduled to
* expire; its creation must be retried with a different expiry.
*/
SCHEDULE_EXPIRY_IS_BUSY = 372;
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,12 @@ message BlockStreamInfo {
* at which an interval of time-dependent events were processed.
*/
proto.Timestamp last_interval_process_time = 12;

/**
* The time stamp at which the last user transaction was handled.
* <p>
* This field SHALL hold the consensus time for the last time
* at which a user transaction was handled.
*/
proto.Timestamp last_handle_time = 13;
}
30 changes: 30 additions & 0 deletions hapi/hedera-protobufs/services/state/schedule/schedule.proto
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,33 @@ message ScheduleIdList {
*/
repeated ScheduleID schedule_ids = 1;
}

/**
* The value of a map summarizing the counts of scheduled and processed transactions
* within a particular consensus second.
*/
message ScheduledCounts {
/**
* The number of transactions scheduled to expire at a consensus second.
*/
uint32 number_scheduled = 1;
/**
* The number of scheduled transactions that have been processed at a consensus second.
*/
uint32 number_processed = 2;
}

/**
* A key mapping to a particular ScheduleID that will execute at a given order number
* within a given consensus second.
*/
message ScheduledOrder {
/**
* The consensus second in which the transaction is expired.
*/
uint64 expiry_second = 1;
/*
* The ordered position within the consensus second that the transaction will be executed.
*/
uint32 order_number = 2;
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ public int scaling(int nominalOps) {
return Math.max(1, nominalOps * numerator / denominator);
}

/**
* Returns the scale factor as an approximate 1:n split of capacity, rounding up.
* @return the approximate capacity split
*/
public int asApproxCapacitySplit() {
return (denominator + numerator - 1) / numerator;
}

@Override
public int compareTo(final ScaleFactor that) {
return Integer.compare(this.numerator * that.denominator, that.numerator * this.denominator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ public AddressBookHelper() {}
/**
* Adjusts the node metadata after upgrade. This method will mark nodes as deleted if they are not present in the
* address book and add new nodes to the node store.
* <b>IMPORTANT:</b> Once DAB is enabled, should always be a no-op.
* @param networkInfo the network info
* @param config configuration
* @param nodeStore the node store
*/
@Deprecated
public void adjustPostUpgradeNodeMetadata(
@NonNull final NetworkInfo networkInfo,
@NonNull final Configuration config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.hedera.hapi.node.base.ResponseCodeEnum;
import com.hedera.hapi.node.transaction.TransactionBody;
import com.hedera.node.app.spi.signatures.SignatureVerifier;
import com.hedera.node.app.spi.throttle.Throttle;
import com.swirlds.common.crypto.Signature;
import com.swirlds.config.api.Configuration;
import com.swirlds.state.lifecycle.Service;
Expand Down Expand Up @@ -103,4 +104,10 @@ public Signature sign(final byte[] ledgerId) {
* @return the supplier
*/
Supplier<NodeInfo> selfNodeInfoSupplier();

/**
* The application's strategy for creating {@link Throttle} instances.
* @return the throttle factory
*/
Throttle.Factory throttleFactory();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (C) 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.spi.throttle;

import com.hedera.hapi.node.base.AccountID;
import com.hedera.hapi.node.base.HederaFunctionality;
import com.hedera.hapi.node.state.throttles.ThrottleUsageSnapshots;
import com.hedera.hapi.node.transaction.TransactionBody;
import com.hedera.node.app.spi.AppContext;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import java.time.Instant;

/**
* A throttle that can be used to limit the rate of transactions. Provided in the {@link AppContext} so that services
* can align to the application's strategy for throttling transactions.
*/
public interface Throttle {
/**
* A factory for creating {@link Throttle} instances.
*/
interface Factory {
/**
* Creates a new throttle based on the capacity split and usage snapshots.
* @param capacitySplit the split of the capacity
* @param initialUsageSnapshots if not null, the usage snapshots the throttle should start with
* @return the new throttle
*/
Throttle newThrottle(int capacitySplit, @Nullable ThrottleUsageSnapshots initialUsageSnapshots);
}

/**
* Tries to consume throttle capacity for the given payer, transaction, function, time, and state.
* @param payerId the account ID of the payer
* @param body the transaction body
* @param function the functionality of the transaction
* @param now the current time
* @return whether the capacity could be consumed
*/
boolean allow(
@NonNull AccountID payerId,
@NonNull TransactionBody body,
@NonNull HederaFunctionality function,
@NonNull Instant now);

/**
* Returns the usage snapshots of the throttle.
*/
ThrottleUsageSnapshots usageSnapshots();
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,11 @@ public static void main(String... args) throws Exception {
Instant::now,
fakeSignatureVerifier(),
UNAVAILABLE_GOSSIP,
() -> configProvider.getConfiguration(),
() -> DEFAULT_NODE_INFO),
configProvider::getConfiguration,
() -> DEFAULT_NODE_INFO,
(split, snapshots) -> {
throw new UnsupportedOperationException();
}),
ForkJoinPool.commonPool(),
ForkJoinPool.commonPool(),
new PlaceholderTssLibrary(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,11 @@ public class StandaloneRoundManagement {
Instant::now,
fakeSignatureVerifier(),
UNAVAILABLE_GOSSIP,
() -> configProvider.getConfiguration(),
() -> DEFAULT_NODE_INFO),
configProvider::getConfiguration,
() -> DEFAULT_NODE_INFO,
(split, snapshots) -> {
throw new UnsupportedOperationException();
}),
ForkJoinPool.commonPool(),
ForkJoinPool.commonPool(),
new PlaceholderTssLibrary(),
Expand Down
Loading

0 comments on commit 8b58baa

Please sign in to comment.