It depends on the nature of the application actually suppose you have an application to upload a file and read it. Suppose the maximum file size limit you allow in your application is 500 kb then the max_transaction_cpu_usage must be greater than or equal to that limit.
I have this smart contract to upload data
#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>
class filestore_contract : public eosio::contract {
public:
filestore_contract(account_name self)
:eosio::contract(self),
files(_self, _self)
{}
// @abi action
void upload(account_name author, const uint32_t id, const std::string& hash) {
files.emplace(author, [&](auto& new_file) {
new_file.id = id;
new_file.hash = hash;
});
eosio::print("file ", id, " created with ",hash, " Size ",hash.size());
}
// @abi action
void destroy(account_name author, const uint32_t id) {
auto files_lookup = files.find(id);
files.erase(files_lookup);
eosio::print("File #", id, " destroyed");
}
// @abi action
private:
// @abi table files i64
struct file {
uint64_t id;
std::string hash;
uint64_t primary_key() const { return id; }
EOSLIB_SERIALIZE(file, (id)(hash))
};
typedef eosio::multi_index<N(files), file> filestore_table;
filestore_table files;
};
EOSIO_ABI(filestore_contract, (upload)(destroy))
This is my Javascript code
let upload = eos => {
let str = fs
.readFileSync(
"./server/controllers/files/SampleTextFile_500kb.txt",
(err, res) => {
if (!err) return res;
}
)
.toString();
eos.contract("upload").then(contract => {
contract
.upload(
{
author: "user",
id: 2324,
hash: str
},
{
authorization: ["user@active"]
}
)
.then(res => {
fs.writeFileSync("SampleTextFile_500kb.json", JSON.stringify(res), {
flag: "w"
});
})
.catch(err => {
console.log(err);
});
});
};
when i tried to upload 500 kb data it was giving me some error because the maximum transaction memory allowed was less then 500 kb so i updated
max_transaction_cpu_usage = 60000
in my config.ini file to solve my error. So it depends on the nature of the transactions you have. Please make sure you keep
max_block_cpu_usage > max_transaction_cpu_usage