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

feat: Topic get info changes #15350

Merged
merged 14 commits into from
Sep 17, 2024
45 changes: 45 additions & 0 deletions hapi/hedera-protobufs/services/consensus_create_topic.proto
jsync-swirlds marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ option java_package = "com.hederahashgraph.api.proto.java";
option java_multiple_files = true;

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

/**
Expand Down Expand Up @@ -70,4 +71,48 @@ message ConsensusCreateTopicTransactionBody {
* If specified, there must be an adminKey and the autoRenewAccount must sign this transaction.
*/
AccountID autoRenewAccount = 7;

/**
* Access control for update or delete of custom fees.<br/>
* If set, subsequent consensus_update_topic transactions signed with this
* key MAY update or delete the custom fees for this topic. If not set,
* the custom fees for this topic are immutable.
* <p>
* If not set when the topic is created, this field CANNOT be set via
* update.<br/>
* If set when the topic is created, this field MAY be changed via update.
Comment on lines +76 to +83
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Access control for update or delete of custom fees.<br/>
* If set, subsequent consensus_update_topic transactions signed with this
* key MAY update or delete the custom fees for this topic. If not set,
* the custom fees for this topic are immutable.
* <p>
* If not set when the topic is created, this field CANNOT be set via
* update.<br/>
* If set when the topic is created, this field MAY be changed via update.
* Access control for update or delete of custom fees.
* <p>
* If set, subsequent `consensus_update_topic` transactions signed with this
* key MAY update or delete the custom fees for this topic. If not set,
* the custom fees for this topic are immutable.<br/>
* If not set when the topic is created, this field CANNOT be set via
* update.<br/>
* If set when the topic is created, this field MAY be changed via update.

*/
Key fee_schedule_key = 8;

/**
* A set of keys that are allowed to submit messages to the topic without
* paying the topic's custom fees.<br/>
* If a submit transaction is signed by _any_ key included in this set,
* custom fees SHALL NOT be charged for that transaction.
* <p>
Comment on lines +88 to +92
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* A set of keys that are allowed to submit messages to the topic without
* paying the topic's custom fees.<br/>
* If a submit transaction is signed by _any_ key included in this set,
* custom fees SHALL NOT be charged for that transaction.
* <p>
* A set of keys.<br/>
* Keys in this list are permitted to submit messages to this topic without
* paying custom fees associated with this topic.
* <p>
* If a submit transaction is signed by _any_ key included in this set,
* custom fees SHALL NOT be charged for that transaction.<br/>

* This field SHALL NOT contain more than
* `MAX_ENTRIES_FOR_FEE_EXEMPT_KEY_LIST` keys.<br/>
* fee_exempt_key_list SHALL NOT contain any duplicate keys.<br/>
* fee_exempt_key_list MAY contain keys for accounts that are inactive,
* deleted, or non-existent.<br/>
* If fee_exempt_key_list is unset in this transaction, there SHALL NOT be
* any fee-exempt keys. In particular, the following keys SHALL NOT be
* implicitly or automatically added to this list:
* `adminKey`, `submitKey`, `fee_schedule_key`.
*/
repeated Key fee_exempt_key_list = 9;

/**
* A set of custom fee definitions.<br/>
* These are fees to be assessed for each submit to this topic.
* <p>
* Each fee defined in this set SHALL be evaluated for
* each message submitted to this topic, and the resultant
* total assessed fees SHALL be charged.<br/>
* Custom fees defined here SHALL be assessed in addition to the base
* network and node fees.<br/>
* custom_fees list SHALL NOT contain more than
* `MAX_CUSTOM_FEE_ENTRIES_FOR_TOPICS` entries.
*/
repeated ConsensusCustomFee custom_fees = 10;
}
37 changes: 37 additions & 0 deletions hapi/hedera-protobufs/services/consensus_topic_info.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ option java_package = "com.hederahashgraph.api.proto.java";
option java_multiple_files = true;

import "basic_types.proto";
import "custom_fees.proto";
import "duration.proto";
import "timestamp.proto";

Expand Down Expand Up @@ -87,4 +88,40 @@ message ConsensusTopicInfo {
* The ledger ID the response was returned from; please see <a href="https://github.com/hashgraph/hedera-improvement-proposal/blob/master/HIP/hip-198.md">HIP-198</a> for the network-specific IDs.
*/
bytes ledger_id = 9;

/**
* Access control for update/delete of custom fees.
* <p>
* If unset, custom fees CANNOT be set for this topic.<br/>
* If not set when the topic is created, this field CANNOT be set via
* update.<br/>
* If set when the topic is created, this field MAY be changed via update.
*/
Key fee_schedule_key = 10;

/**
* A set of keys that are allowed to submit messages to the topic without
* paying the topic's custom fees.<br/>
* If a submit transaction is signed by _any_ key included in this set,
* custom fees SHALL NOT be charged for that transaction.
* <p>
Comment on lines +103 to +107
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paragraph break should not follow the requirement here.

Suggested change
* A set of keys that are allowed to submit messages to the topic without
* paying the topic's custom fees.<br/>
* If a submit transaction is signed by _any_ key included in this set,
* custom fees SHALL NOT be charged for that transaction.
* <p>
* A set of keys.<br/>
* Keys in this list are permitted to submit messages to this topic without
* paying custom fees associated with this topic.
* <p>
* If a submit transaction is signed by _any_ key included in this set,
* custom fees SHALL NOT be charged for that transaction.<br/>

* fee_exempt_key_list MAY contain keys for accounts that are inactive,
* deleted, or non-existent.<br/>
* If not set, there SHALL NOT be any fee-exempt keys. In particular, the
* following keys SHALL NOT be implicitly or automatically added to this
* list: `adminKey`, `submitKey`, `fee_schedule_key`.
*/
repeated Key fee_exempt_key_list = 11;

/**
* A set of custom fee definitions.<br/>
* These are fees to be assessed for each submit to this topic.
* <p>
* Each fee defined in this set SHALL be evaluated for
* each message submitted to this topic, and the resultant
* total assessed fees SHALL be charged.<br/>
* Custom fees defined here SHALL be assessed in addition to the base
* network and node fees.
*/
repeated ConsensusCustomFee custom_fees = 12;
}
55 changes: 55 additions & 0 deletions hapi/hedera-protobufs/services/consensus_update_topic.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ option java_multiple_files = true;

import "google/protobuf/wrappers.proto";
import "basic_types.proto";
import "custom_fees.proto";
import "duration.proto";
import "timestamp.proto";

Expand Down Expand Up @@ -87,4 +88,58 @@ message ConsensusUpdateTopicTransactionBody {
* If unspecified, no change.
*/
AccountID autoRenewAccount = 9;

/**
* Access control for update/delete of custom fees.<br/>
* <p>
* If set, subsequent consensus_update_topic transactions signed with this
* key MAY update or delete the custom fees for this topic.<br/>
* If set to a Key containing a non-empty KeyList, the previous key and new
* key MUST both sign this transaction.<br/>
Comment on lines +97 to +98
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better here to state If set to a valid Key instead of specifically a non-empty KeyList.

* If this field is set to a valid 'Key', the previous value SHALL be
* replaced.<br/>
* If set to a 'Key' containing an empty 'KeyList', the previous key and the
* admin key MUST both sign this transaction.<br/>
* If set to a 'Key' containing an empty 'KeyList', the previous value
* SHALL be cleared.<br/>
* If not set, the current key SHALL NOT change.<br/>
* If unset in state, this field MUST NOT be set in this transaction.<br/>
* If not set when the topic is created, this field CANNOT be set via
* update.<br/>
*/
Key fee_schedule_key = 10;

/**
* A set of keys<br/>
* Keys in this list are permitted to submit messages to this topic without
* paying custom fees associated with this topic.
* <p>
* If a submit transaction is signed by _any_ key included in this set,
* custom fees SHALL NOT be charged for that transaction.<br/>
* If this field is not set, the current set of keys SHALL NOT change.<br/>
* If this field is set, but contains an empty list, any existing fee-exempt
* keys SHALL be removed.<br/>
* A `fee_exempt_key_list` MUST NOT contain more than
* `MAX_ENTRIES_FOR_FEE_EXEMPT_KEY_LIST` keys.<br/>
* A `fee_exempt_key_list` MUST NOT contain any duplicate keys.<br/>
* A `fee_exempt_key_list` MAY contain keys for accounts that are inactive,
* deleted, or non-existent.
*/
FeeExemptKeyList fee_exempt_key_list = 11;

/**
* A set of custom fee definitions.<br/>
* These are fees to be assessed for each submit to this topic.
* <p>
* Each fee defined in this set SHALL be evaluated for
* each message submitted to this topic, and the resultant
* total assessed fees SHALL be charged.<br/>
* Custom fees defined here SHALL be assessed in addition to the base
* network and node fees.<br/>
* If this field is not set, the current set of custom fees
* SHALL NOT change.<br/>
* If this field is set, but contains an empty list, all current custom fees
* SHALL be removed.
*/
ConsensusCustomFeeList custom_fees = 12;
}
66 changes: 66 additions & 0 deletions hapi/hedera-protobufs/services/custom_fees.proto
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,69 @@ message AssessedCustomFee {
*/
repeated AccountID effective_payer_account_id = 4;
}

/**
* A custom fee definition for a consensus topic.
* <p>
jsync-swirlds marked this conversation as resolved.
Show resolved Hide resolved
* This fee definition is specific to an Hedera Consensus Service (HCS) topic
* and SHOULD NOT be used in any other context.<br/>
* All fields for this message are REQUIRED.<br/>
* Only "fixed" fee definitions are supported because there is no basis for
* a fractional fee on a consensus submit transaction.
*/
message ConsensusCustomFee {
Neeharika-Sompalli marked this conversation as resolved.
Show resolved Hide resolved
/**
* A fixed custom fee.
* <p>
* The amount of HBAR or other token described by this `FixedFee` SHALL
* be charged to the transction payer for each message submitted to a
* topic that assigns this consensus custom fee.
*/
FixedFee fixed_fee = 1;

/**
* A collection account identifier.
* <p>
* All amounts collected for this consensus custom fee SHALL be transferred
* to the account identified by this field.
*/
AccountID fee_collector_account_id = 2;
}

/**
* A wrapper around a consensus custom fee list.<br/>
* This wrapper exists to enable an update transaction to differentiate between
* a field that is not set and an empty list of custom fees.
* <p>
jsync-swirlds marked this conversation as resolved.
Show resolved Hide resolved
* An _unset_ field of this type SHALL NOT modify existing values.<br/>
* A _set_ field of this type with an empty `fees` list SHALL remove any
* existing values.
*/
message ConsensusCustomFeeList {
/**
* A set of custom fee definitions.<br/>
* These are fees to be assessed for each submit to a topic.
*/
repeated ConsensusCustomFee fees = 1;
}

/**
* A wrapper for fee exempt key list.<br/>
* This wrapper exists to enable an update transaction to differentiate between
* a field that is not set and an empty list of keys.
* <p>
* An _unset_ field of this type SHALL NOT modify existing values.<br/>
* A _set_ field of this type with an empty `keys` list SHALL remove any
* existing values.
*/
message FeeExemptKeyList {
/**
* A set of keys.<br/>
* The keys in this list are permitted to submit messages to the
* topic without paying the topic's custom fees.
* <p>
* If a submit transaction is signed by _any_ key included in this set,
* custom fees SHALL NOT be charged for that transaction.
*/
repeated Key keys = 1;
}
39 changes: 39 additions & 0 deletions hapi/hedera-protobufs/services/state/consensus/topic.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package proto;
*/

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

option java_package = "com.hederahashgraph.api.proto.java";
// <<<pbj.java_package = "com.hedera.hapi.node.state.consensus">>> This comment is special code for setting PBJ Compiler java package
Expand All @@ -48,6 +49,9 @@ option java_multiple_files = true;
* 5. A memo string whose UTF-8 encoding is at most 100 bytes.
* 6. (Optional) An admin key whose signature must be active for the topic's metadata to be updated.
* 7. (Optional) A submit key whose signature must be active for the topic to receive a message.
* 8. (Optional) A fee schedule key whose signature must be active for the topic's custom fees to be updated.
* 9. (Optional) A list of keys that can submit messages without paying custom fees.
* 10. (Optional) A list of custom fees to be assessed for each message submitted to the topic.
*/
message Topic {
/**
Expand Down Expand Up @@ -94,8 +98,43 @@ message Topic {
* A topic without an admin key is immutable.
*/
Key admin_key = 9;

/**
* If present, enforces access control for message submission to the topic.
*/
Key submit_key = 10;

/**
* Access control for update/delete of custom fees.
* <p>
* If this field is unset, the current custom fees CANNOT be changed.<br/>
* If this field is set, that `Key` MUST sign any transaction to update
* the custom fee schedule for this topic.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation is off here.

Key fee_schedule_key = 11;

/**
* A list of "privileged payer" keys.
* <p>
* If a submit transaction is signed by _any_ key from this list,
* custom fees SHALL NOT be charged for that transaction.<br/>
* If fee_exempt_key_list is unset, it SHALL _implicitly_ contain
* the key `admin_key`, the key `submit_key`, and the key
* `fee_schedule_key`, if any of those keys are set.
Comment on lines +121 to +123
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct; didn't we fix this in an earlier commit?

*/
repeated Key fee_exempt_key_list = 12;

/**
* A set of custom fee definitions.<br/>
* These are fees to be assessed for each submit to this topic.
* <p>
* If this list is empty, the only fees charged for a submit to this
* topic SHALL be the network and node fees.<br/>
* If this list is not empty, each fee defined in this set SHALL
* be evaluated for each message submitted to this topic, and the
* resultant total assessed fees SHALL be charged.<br/>
* If this list is not empty, custom fees defined here SHALL be
* charged _in addition to_ the base network and node fees.
*/
repeated ConsensusCustomFee custom_fees = 13;
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ private Optional<ConsensusTopicInfo> infoForTopic(
if (!isEmpty(meta.submitKey())) info.submitKey(meta.submitKey());
info.autoRenewPeriod(Duration.newBuilder().seconds(meta.autoRenewPeriod()));
if (meta.hasAutoRenewAccountId()) info.autoRenewAccount(meta.autoRenewAccountId());
if (meta.hasFeeScheduleKey()) info.feeScheduleKey(meta.feeScheduleKey());
if (!meta.feeExemptKeyList().isEmpty()) info.feeExemptKeyList(meta.feeExemptKeyList());
if (!meta.customFees().isEmpty()) info.customFees(meta.customFees());

info.ledgerId(config.id());
return Optional.of(info.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,7 @@ public void handle(@NonNull final HandleContext handleContext) {
validateMaybeNewAttributes(handleContext, op, topic);

// Now we apply the mutations to a builder
final var builder = new Topic.Builder();
// But first copy over the immutable topic attributes to the builder
builder.topicId(topic.topicId());
builder.sequenceNumber(topic.sequenceNumber());
builder.runningHash(topic.runningHash());
builder.deleted(topic.deleted());
// And then resolve mutable attributes, and put the new topic back
final var builder = topic.copyBuilder();
resolveMutableBuilderAttributes(handleContext, op, builder, topic);
topicStore.put(builder.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ void adminKeyDoesntExist() {
Bytes.wrap(runningHash),
memo,
null,
null,
null,
null,
null);

writableTopicState = writableTopicStateWithOneKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ private ConsensusTopicInfo getExpectedInfo() {
.autoRenewAccount(topic.autoRenewAccountId())
.autoRenewPeriod(WELL_KNOWN_AUTO_RENEW_PERIOD)
.ledgerId(new BytesConverter().convert("0x03"))
.feeScheduleKey(feeScheduleKey)
.feeExemptKeyList(key, anotherKey)
.customFees(customFees)
.build();
}

Expand Down
Loading
Loading