Skip to content

Commit

Permalink
Update protobufs
Browse files Browse the repository at this point in the history
Signed-off-by: Zhivko Kelchev <[email protected]>
  • Loading branch information
JivkoKelchev committed Jan 10, 2025
1 parent ad28cb8 commit 063d698
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 80 deletions.
11 changes: 0 additions & 11 deletions hapi/hedera-protobufs/services/consensus_submit_message.proto
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ option java_package = "com.hederahashgraph.api.proto.java";
option java_multiple_files = true;

import "basic_types.proto";
import "custom_fees.proto";

/**
* Consensus message "chunk" detail.<br/>
Expand Down Expand Up @@ -108,14 +107,4 @@ message ConsensusSubmitMessageTransactionBody {
* field SHOULD NOT be set.
*/
ConsensusMessageChunkInfo chunkInfo = 3;

/**
* The maximum custom fee that the user is willing to pay for the message. This field will be ignored if `accept_all_custom_fees` is set to `true`.
*/
repeated FixedFee max_custom_fees = 4;

/**
* If set to true, the transaction will accept all custom fees from the topic id
*/
bool accept_all_custom_fees = 5;
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
import com.hedera.hapi.node.base.TransactionID;
import com.hedera.hapi.node.consensus.ConsensusSubmitMessageTransactionBody;
import com.hedera.hapi.node.state.consensus.Topic;
import com.hedera.hapi.node.transaction.ConsensusCustomFee;
import com.hedera.hapi.node.transaction.FixedFee;
import com.hedera.hapi.node.transaction.CustomFeeLimit;
import com.hedera.hapi.node.transaction.FixedCustomFee;
import com.hedera.hapi.node.transaction.TransactionBody;
import com.hedera.node.app.hapi.utils.CommonPbjConverters;
import com.hedera.node.app.service.consensus.ReadableTopicStore;
Expand Down Expand Up @@ -160,8 +160,8 @@ public void handle(@NonNull final HandleContext handleContext) {
final var feesToBeCharged = extractFeesToBeCharged(topic.customFees(), handleContext);

// check payer limits or throw
if (!op.acceptAllCustomFees()) {
validateFeeLimits(feesToBeCharged, op.maxCustomFees());
if (!txn.maxCustomFees().isEmpty()) {
validateFeeLimits(handleContext.payer(), feesToBeCharged, txn.maxCustomFees());
}

// create synthetic body and dispatch crypto transfer
Expand Down Expand Up @@ -376,8 +376,9 @@ public static Predicate<Key> simpleKeyVerifierFrom(@NonNull final List<Key> sign
* @param payerCustomFeeLimits List with limits of fees that the payer is willing to pay
*/
private void validateFeeLimits(
@NonNull final List<ConsensusCustomFee> topicCustomFees,
@NonNull final List<FixedFee> payerCustomFeeLimits) {
@NonNull final AccountID payer,
@NonNull final List<FixedCustomFee> topicCustomFees,
@NonNull final List<CustomFeeLimit> payerCustomFeeLimits) {
// Validate the duplication of payer custom fee limits
validateDuplicationFeeLimits(payerCustomFeeLimits);

Expand All @@ -388,20 +389,23 @@ private void validateFeeLimits(
// Validate payer token limits
tokenFees.forEach((token, feeAmount) -> {
final boolean isValid = payerCustomFeeLimits.stream()
.filter(fee -> token.equals(fee.denominatingTokenId()))
.anyMatch(fee -> {
validateTrue(fee.amount() >= feeAmount, MAX_CUSTOM_FEE_LIMIT_EXCEEDED);
.filter(maxCustomFee ->
token.equals(maxCustomFee.amountLimit().denominatingTokenId()))
.filter(maxCustomFee -> payer.equals(maxCustomFee.accountId()))
.anyMatch(maxCustomFee -> {
validateTrue(maxCustomFee.amountLimit().amount() >= feeAmount, MAX_CUSTOM_FEE_LIMIT_EXCEEDED);
return true;
});
validateTrue(isValid, NO_VALID_MAX_CUSTOM_FEE);
});
// Validate payer HBAR limit
if (hbarFee.get() > 0) {
final var payerHbarLimit = payerCustomFeeLimits.stream()
.filter(fee -> !fee.hasDenominatingTokenId())
.filter(maxCustomFee -> !maxCustomFee.amountLimit().hasDenominatingTokenId())
.filter(maxCustomFee -> payer.equals(maxCustomFee.accountId()))
.findFirst()
.orElseThrow(() -> new HandleException(NO_VALID_MAX_CUSTOM_FEE));
validateTrue(payerHbarLimit.amount() >= hbarFee.get(), MAX_CUSTOM_FEE_LIMIT_EXCEEDED);
validateTrue(payerHbarLimit.amountLimit().amount() >= hbarFee.get(), MAX_CUSTOM_FEE_LIMIT_EXCEEDED);
}
}

Expand All @@ -413,8 +417,8 @@ private void validateFeeLimits(
* @param context The handle context
* @return List containing only the fees concerning given payer
*/
private List<ConsensusCustomFee> extractFeesToBeCharged(
@NonNull final List<ConsensusCustomFee> topicCustomFees, @NonNull final HandleContext context) {
private List<FixedCustomFee> extractFeesToBeCharged(
@NonNull final List<FixedCustomFee> topicCustomFees, @NonNull final HandleContext context) {
final var payer = context.payer();
final var tokenStore = context.storeFactory().readableStore(ReadableTokenStore.class);
return topicCustomFees.stream()
Expand All @@ -441,7 +445,7 @@ private List<ConsensusCustomFee> extractFeesToBeCharged(
* @param tokenFees Map with total amount per token.
*/
private void totalAmountToBeCharged(
@NonNull List<ConsensusCustomFee> topicCustomFees,
@NonNull List<FixedCustomFee> topicCustomFees,
AtomicReference<Long> hbarFee,
Map<TokenID, Long> tokenFees) {
for (final var fee : topicCustomFees) {
Expand All @@ -455,16 +459,16 @@ private void totalAmountToBeCharged(
}
}

private void validateDuplicationFeeLimits(@NonNull final List<FixedFee> payerCustomFeeLimits) {
private void validateDuplicationFeeLimits(@NonNull final List<CustomFeeLimit> payerCustomFeeLimits) {
final var htsCustomFeeLimits = payerCustomFeeLimits.stream()
.filter(FixedFee::hasDenominatingTokenId)
.filter(maxCustomFee -> maxCustomFee.amountLimit().hasDenominatingTokenId())
.toList();
final var hbarCustomFeeLimits = payerCustomFeeLimits.stream()
.filter(fee -> !fee.hasDenominatingTokenId())
.filter(maxCustomFee -> !maxCustomFee.amountLimit().hasDenominatingTokenId())
.toList();

final var htsLimitHasDuplicate = htsCustomFeeLimits.stream()
.map(FixedFee::denominatingTokenId)
.map(maxCustomFee -> maxCustomFee.amountLimit().denominatingTokenId())
.collect(Collectors.toSet())
.size()
!= htsCustomFeeLimits.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.hedera.hapi.node.base.TokenTransferList;
import com.hedera.hapi.node.base.TransferList;
import com.hedera.hapi.node.token.CryptoTransferTransactionBody;
import com.hedera.hapi.node.transaction.ConsensusCustomFee;
import com.hedera.hapi.node.transaction.FixedCustomFee;
import com.hedera.hapi.node.transaction.FixedFee;
import com.hedera.node.app.service.token.ReadableTokenStore;
import edu.umd.cs.findbugs.annotations.NonNull;
Expand Down Expand Up @@ -55,12 +55,12 @@ public ConsensusCustomFeeAssessor() {
* @return List of synthetic crypto transfer transaction bodies
*/
public List<CryptoTransferTransactionBody> assessCustomFee(
@NonNull final List<ConsensusCustomFee> customFees, @NonNull final AccountID payer) {
@NonNull final List<FixedCustomFee> customFees, @NonNull final AccountID payer) {
final List<CryptoTransferTransactionBody> transactionBodies = new ArrayList<>();

// build crypto transfer bodies for the first layer of custom fees,
// if there is a second or third layer it will be assessed in crypto transfer handler
for (ConsensusCustomFee fee : customFees) {
for (FixedCustomFee fee : customFees) {
final var tokenTransfers = new ArrayList<TokenTransferList>();
List<AccountAmount> hbarTransfers = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import com.hedera.hapi.node.consensus.ConsensusMessageChunkInfo;
import com.hedera.hapi.node.consensus.ConsensusSubmitMessageTransactionBody;
import com.hedera.hapi.node.state.consensus.Topic;
import com.hedera.hapi.node.transaction.CustomFeeLimit;
import com.hedera.hapi.node.transaction.FixedFee;
import com.hedera.hapi.node.transaction.TransactionBody;
import com.hedera.node.app.service.consensus.ReadableTopicStore;
import com.hedera.node.app.service.consensus.impl.ReadableTopicStoreImpl;
Expand Down Expand Up @@ -473,14 +475,27 @@ private TransactionBody newSubmitMessageTxn(final long topicEntityNum, final Str

private TransactionBody newSubmitMessageTxnWithMaxFee() {
final var txnId = TransactionID.newBuilder().accountID(payerId).build();
final var maxCustomFees = List.of(
// fungible token limit
CustomFeeLimit.newBuilder()
.accountId(payerId)
.amountLimit(FixedFee.newBuilder()
.denominatingTokenId(fungibleTokenId)
.amount(1))
.build(),
// hbar limit
CustomFeeLimit.newBuilder()
.accountId(payerId)
.amountLimit(FixedFee.newBuilder().amount(1))
.build());
final var submitMessageBuilder = ConsensusSubmitMessageTransactionBody.newBuilder()
.maxCustomFees(tokenCustomFee.fixedFee(), hbarCustomFee.fixedFee())
.topicID(TopicID.newBuilder().topicNum(topicEntityNum).build())
.message(Bytes.wrap("Message for test-" + Instant.now() + "."
+ Instant.now().getNano()));
return TransactionBody.newBuilder()
.transactionID(txnId)
.consensusSubmitMessage(submitMessageBuilder.build())
.maxCustomFees(maxCustomFees)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,18 @@ public class ConsensusTestBase {
protected final long sequenceNumber = 1L;
protected final long autoRenewSecs = 100L;
protected final Instant consensusTimestamp = Instant.ofEpochSecond(1_234_567L);
protected final ConsensusCustomFee tokenCustomFee = ConsensusCustomFee.newBuilder()
protected final FixedCustomFee tokenCustomFee = FixedCustomFee.newBuilder()
.fixedFee(FixedFee.newBuilder()
.denominatingTokenId(fungibleTokenId)
.amount(1)
.build())
.feeCollectorAccountId(anotherPayer)
.build();
protected final ConsensusCustomFee hbarCustomFee = ConsensusCustomFee.newBuilder()
protected final FixedCustomFee hbarCustomFee = FixedCustomFee.newBuilder()
.fixedFee(FixedFee.newBuilder().amount(1).build())
.feeCollectorAccountId(anotherPayer)
.build();
protected final List<ConsensusCustomFee> customFees = List.of(tokenCustomFee, hbarCustomFee);
protected final List<FixedCustomFee> customFees = List.of(tokenCustomFee, hbarCustomFee);

protected Topic topic;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import com.hedera.services.bdd.spec.HapiSpec;
import com.hedera.services.bdd.spec.fees.AdapterUtils;
import com.hedera.services.bdd.spec.transactions.HapiTxnOp;
import com.hederahashgraph.api.proto.java.ConsensusCustomFee;
import com.hederahashgraph.api.proto.java.ConsensusMessageChunkInfo;
import com.hederahashgraph.api.proto.java.ConsensusSubmitMessageTransactionBody;
import com.hederahashgraph.api.proto.java.FeeData;
Expand Down Expand Up @@ -125,16 +124,6 @@ public HapiMessageSubmit chunkInfo(
return chunkInfo(totalChunks, chunkNumber);
}

public HapiMessageSubmit maxCustomFee(Function<HapiSpec, ConsensusCustomFee> f) {
maxCustomFeeList.add(f);
return this;
}

public HapiMessageSubmit acceptAllCustomFees(boolean acceptAllFees) {
this.acceptAllCustomFees = acceptAllFees;
return this;
}

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(final HapiSpec spec) throws Throwable {
final TopicID id = resolveTopicId(spec);
Expand All @@ -146,12 +135,6 @@ protected Consumer<TransactionBody.Builder> opBodyDef(final HapiSpec spec) throw
if (clearMessage) {
b.clearMessage();
}
if (!maxCustomFeeList.isEmpty()) {
for (final var supplier : maxCustomFeeList) {
b.addMaxCustomFees(supplier.apply(spec).getFixedFee());
}
}
b.setAcceptAllCustomFees(acceptAllCustomFees);
if (totalChunks.isPresent() && chunkNumber.isPresent()) {
final ConsensusMessageChunkInfo chunkInfo = ConsensusMessageChunkInfo.newBuilder()
.setInitialTransactionID(initialTransactionID.orElse(asTransactionID(
Expand Down
Loading

0 comments on commit 063d698

Please sign in to comment.