You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When submitting a message to a topic using a custom transactionId and a message large enough to be split into several chunks/transactions, the operation fails with INVALID_CHUNK_TRANSACTION_ID and only the first chunk transaction is successfully registered to the topic.
The problem seems to occur because the second and following chunks do not have the same transactionId as the first one. Only the first chunk transaction has the transactionId set in the transaction creation.
This has been tested with the hedera-sdk-js and it works well as all chunk transactions are executed with the same transactionId. In the TopicMessageSubmitTransaction code there seems to be some logic to configured transactionId for all chunk transactions.
Steps to reproduce
Set a user account and client
Set a payer account and client
Create the TopicMessageSubmitTransaction instance with:
TopicId: previously created
Message: 12 (2 bytes)
Chunk size: 1 (1 byte)
TransactionId: generated with payer account
Freeze and sign transaction with the user account
Sign and execute transaction with the payer account
Get the transaction response and receipt
Notes: The message has been set to "12" and the chunk size to 1 byte to cause the message to be split into 2 chunks. So the first chunk transaction would contain message "1" and the second chunk transaction would contain message "2".
Code snippet for testing:
// main.swift
import Foundation
import Hedera
let USER_ACCOUNT_ID = ""
let USER_PRIVATE_KEY = ""
let PAYER_ACCOUNT_ID = ""
let PAYER_PRIVATE_KEY = ""
public func submitMessage() async throws {
do{
// Set user account
let userAccountId = try AccountId.fromString(USER_ACCOUNT_ID);
let userPrivateKey = try PrivateKey.fromStringDer(USER_PRIVATE_KEY);
let userClient = Client.forTestnet().setOperator(userAccountId, userPrivateKey);
// Set payer account
let payerAccountId = try AccountId.fromString(PAYER_ACCOUNT_ID);
let payerPrivateKey = try PrivateKey.fromStringDer(PAYER_PRIVATE_KEY);
let payerClient = Client.forTestnet().setOperator(payerAccountId, payerPrivateKey);
// Transaction attributes
let topicId = "0.0.7130942"; // Previously created HCS topic
let message = "12"; // 2 bytes message
let chunkSize = 1; // 1 byte chunk size
let transactionId = TransactionId.generateFrom(payerAccountId); // custom transactionId
// Transaction creation
let transaction = TopicMessageSubmitTransaction()
.topicId(try TopicId.fromString(topicId))
.message(message.data(using: .utf8)!)
.chunkSize(chunkSize)
.transactionId(transactionId);
// Transaction signature and execution
let frozenTx = try transaction.freezeWith(userClient);
let signedTx = try frozenTx.signWithOperator(userClient);
let doubleSignedTx = try signedTx.signWithOperator(payerClient);
let txResponses = try await doubleSignedTx.executeAll(payerClient)
// Transaction response
let firstTransactionId = txResponses[0].transactionId.toString();
let firstTransactionReceipt = try await txResponses[0].getReceipt(payerClient);
print(firstTransactionId, firstTransactionReceipt.status.description );
let secondTransactionId = txResponses[1].transactionId.toString();
let secondTransactionReceipt = try await txResponses[1].getReceipt(payerClient)
print(secondTransactionId, secondTransactionReceipt.status.description );
} catch let error {
print("Error: \(error)")
}
}
try await submitMessage()
Diegoescalonaro
changed the title
TopicMessageSubmit transaction with several chunks and custom transactionId results in INVALID_CHUNK_TRANSACTION_ID
TopicMessageSubmit transaction results in INVALID_CHUNK_TRANSACTION_ID
Dec 28, 2023
@Diegoescalonaro The transaction should be frozen with the payerClient, and not the userClient. Once the transactionId is set for TopicMessageSubmitTransaction, the accountId must match that in the set transactionId. Hence, there cannot be 2 payers.
I've tried what you mention by modifying the line below in the code snippet and it seems to work well. By freezing the transaction with the payerClient, the first and second chunk transactions are successfully executed in the Network.
let frozenTx = try transaction.freezeWith(payerClient);
However, this model does not work for most of the use cases where the user firstly creates and signs the transaction in the client application (which requires the transaction to be frozen with the userClient), and then payer account executes the signed transaction in the backend.
In my opinion, even if the transaction is frozen by the user or the payer, all transaction chunks should contain the same transactionId that has been specified in the moment of creation, thus designating the payer account for the the first and the following transaction chunks. That is how other SDKs like the hedera-sdk-js works.
I also tested it by utilizing the Swift SDK for creating, freezing, signing and serializing the transaction in the client, and utilizing the JavaScript SDK only for unserializing and executing the transaction in the backend server, but it also throws the same error: INVALID_CHUNK_TRANSACTION_ID. This makes me think that the problem should be related to the time of creation or freezing...
Description
When submitting a message to a topic using a custom transactionId and a message large enough to be split into several chunks/transactions, the operation fails with
INVALID_CHUNK_TRANSACTION_ID
and only the first chunk transaction is successfully registered to the topic.The problem seems to occur because the second and following chunks do not have the same
transactionId
as the first one. Only the first chunk transaction has thetransactionId
set in the transaction creation.This has been tested with the hedera-sdk-js and it works well as all chunk transactions are executed with the same
transactionId
. In the TopicMessageSubmitTransaction code there seems to be some logic to configured transactionId for all chunk transactions.Steps to reproduce
12
(2 bytes)1
(1 byte)Notes: The message has been set to "12" and the chunk size to 1 byte to cause the message to be split into 2 chunks. So the first chunk transaction would contain message "1" and the second chunk transaction would contain message "2".
Code snippet for testing:
Additional context
Results using hedera-sdk-swift:
SUCCESS
): [email protected]INVALID_CHUNK_TRANSACTION_ID
): [email protected]Results using hedera-sdk-js:
SUCCESS
): [email protected]SUCCESS
): [email protected]Hedera network
testnet
Version
v0.26.0
Operating system
macOS
The text was updated successfully, but these errors were encountered: