Skip to content

Commit b9f94a3

Browse files
feat: Introduce CustomFeeLimits for ScheduledTransactions (#996)
Signed-off-by: gsstoykov <[email protected]> Signed-off-by: SimiHunjan <[email protected]> Co-authored-by: SimiHunjan <[email protected]>
1 parent 6e9fa5b commit b9f94a3

8 files changed

+429
-18
lines changed

.github/workflows/zxc-build-library.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,9 @@ jobs:
183183
uses: hiero-ledger/hiero-solo-action@97b1a5dfff3a18ae92ffb4c27f5ada95906f66bb # v0.12.0
184184
with:
185185
installMirrorNode: true
186-
hieroVersion: v0.61.4
186+
hieroVersion: v0.65.0
187+
mirrorNodeVersion: v0.136.1
188+
187189

188190
- name: Start CTest suite (Debug)
189191
run: ${{ steps.cgroup.outputs.exec }} ctest -j 6 -C Debug --test-dir build/${{ matrix.preset }}-debug --output-on-failure

src/sdk/main/include/TopicMessageSubmitTransaction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class TopicMessageSubmitTransaction : public ChunkedTransaction<TopicMessageSubm
115115
*
116116
* @return A vector containing the current custom fee limits.
117117
*/
118-
[[nodiscard]] std::vector<CustomFeeLimit> getCustomFeeLimits() const;
118+
[[nodiscard]] inline std::vector<CustomFeeLimit> getCustomFeeLimits() const { return mCustomFeeLimits; }
119119

120120
private:
121121
friend class WrappedTransaction;

src/sdk/main/src/TopicMessageSubmitTransaction.cc

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ void TopicMessageSubmitTransaction::validateChecksums(const Client& client) cons
9696
void TopicMessageSubmitTransaction::addToBody(proto::TransactionBody& body) const
9797
{
9898
body.set_allocated_consensussubmitmessage(build());
99+
100+
// Add custom fee limits to the transaction body
101+
for (const auto& fee : mCustomFeeLimits)
102+
{
103+
body.mutable_max_custom_fees()->AddAllocated(fee.toProtobuf().release());
104+
}
99105
}
100106

101107
//-----
@@ -104,10 +110,6 @@ void TopicMessageSubmitTransaction::addToChunk(uint32_t chunk, uint32_t total, p
104110
body.set_allocated_consensussubmitmessage(build(static_cast<int>(chunk)));
105111
body.mutable_consensussubmitmessage()->mutable_chunkinfo()->set_allocated_initialtransactionid(
106112
getTransactionId().toProtobuf().release());
107-
for (const auto& fee : mCustomFeeLimits)
108-
{
109-
body.mutable_max_custom_fees()->AddAllocated(fee.toProtobuf().release());
110-
}
111113
body.mutable_consensussubmitmessage()->mutable_chunkinfo()->set_number(static_cast<int32_t>(chunk + 1));
112114
body.mutable_consensussubmitmessage()->mutable_chunkinfo()->set_total(static_cast<int32_t>(total));
113115
}
@@ -128,6 +130,13 @@ void TopicMessageSubmitTransaction::initFromSourceTransactionBody()
128130
mTopicId = TopicId::fromProtobuf(body.topicid());
129131
}
130132

133+
// Read custom fee limits from the transaction body
134+
mCustomFeeLimits.clear();
135+
for (const auto& protoFeeLimit : transactionBody.max_custom_fees())
136+
{
137+
mCustomFeeLimits.push_back(CustomFeeLimit::fromProtobuf(protoFeeLimit));
138+
}
139+
131140
// Construct the data from the various Transaction protobuf objects.
132141
std::string data;
133142
bool dataStillExists = true;
@@ -151,15 +160,6 @@ void TopicMessageSubmitTransaction::initFromSourceTransactionBody()
151160
proto::TransactionBody txBody;
152161
txBody.ParseFromArray(signedTx.bodybytes().data(), static_cast<int>(signedTx.bodybytes().size()));
153162

154-
// Should also set the custom fee limits but only once as every chunk would contain the limits.
155-
if (mCustomFeeLimits.empty())
156-
{
157-
for (const auto& feeLimit : txBody.max_custom_fees())
158-
{
159-
mCustomFeeLimits.push_back(CustomFeeLimit::fromProtobuf(feeLimit));
160-
}
161-
}
162-
163163
data += txBody.consensussubmitmessage().message();
164164
}
165165

src/sdk/main/src/WrappedTransaction.cc

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,12 @@ WrappedTransaction WrappedTransaction::fromProtobuf(const proto::SchedulableTran
213213
txBody.set_memo(proto.memo());
214214
txBody.set_transactionfee(proto.transactionfee());
215215

216+
// Copy custom fee limits from the schedulable transaction body
217+
if (proto.max_custom_fees_size() > 0)
218+
{
219+
*txBody.mutable_max_custom_fees() = proto.max_custom_fees();
220+
}
221+
216222
if (proto.has_cryptoapproveallowance())
217223
{
218224
*txBody.mutable_cryptoapproveallowance() = proto.cryptoapproveallowance();
@@ -1022,12 +1028,36 @@ std::unique_ptr<proto::Transaction> WrappedTransaction::toProtobufTransaction()
10221028
//-----
10231029
std::unique_ptr<proto::SchedulableTransactionBody> WrappedTransaction::toSchedulableProtobuf() const
10241030
{
1025-
proto::TransactionBody txBody = *toProtobuf();
1031+
// Use source transaction body directly to avoid rebuilding and duplicating custom fee limits
1032+
// Get the existing source transaction body without calling updateSourceTransactionBody() which
1033+
// would duplicate custom fee limits.
1034+
proto::TransactionBody txBody;
1035+
switch (getTransactionType())
1036+
{
1037+
case TOPIC_MESSAGE_SUBMIT_TRANSACTION:
1038+
{
1039+
const auto transaction = getTransaction<TopicMessageSubmitTransaction>();
1040+
txBody = transaction->getSourceTransactionBody();
1041+
break;
1042+
}
1043+
default:
1044+
{
1045+
// For other transaction types, fall back to the original behavior
1046+
txBody = *toProtobuf();
1047+
break;
1048+
}
1049+
}
10261050

10271051
auto schedulableTxBody = std::make_unique<proto::SchedulableTransactionBody>();
10281052
schedulableTxBody->set_transactionfee(txBody.transactionfee());
10291053
schedulableTxBody->set_memo(txBody.memo());
10301054

1055+
// Copy custom fee limits from the transaction body
1056+
if (txBody.max_custom_fees_size() > 0)
1057+
{
1058+
*schedulableTxBody->mutable_max_custom_fees() = txBody.max_custom_fees();
1059+
}
1060+
10311061
if (txBody.has_cryptoapproveallowance())
10321062
{
10331063
schedulableTxBody->set_allocated_cryptoapproveallowance(txBody.release_cryptoapproveallowance());

src/sdk/tests/integration/ContractNonceInfoIntegrationTests.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ TEST_F(ContractNonceInfoIntegrationTests, ContractADeploysContractBInConstructor
5656
TransactionResponse response;
5757
ASSERT_NO_THROW(response = ContractCreateTransaction()
5858
.setAdminKey(operatorKey->getPublicKey())
59-
.setGas(100000ULL)
59+
.setGas(1000000ULL)
6060
.setBytecodeFileId(fileId)
6161
.setMemo(memo)
6262
.execute(getTestClient()));

src/sdk/tests/integration/SystemDeleteTransactionIntegrationTests.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ TEST_F(SystemDeleteTransactionIntegrationTests, DeleteContract)
6969
ASSERT_NO_THROW(contractId =
7070
ContractCreateTransaction()
7171
.setAdminKey(operatorKey)
72-
.setGas(100000ULL)
72+
.setGas(1000000ULL)
7373
.setConstructorParameters(ContractFunctionParameters().addString("Hello from Hiero.").toBytes())
7474
.setBytecodeFileId(fileId)
7575
.execute(getTestClient())

0 commit comments

Comments
 (0)