RSK 网络上智能合约的最大大小是多少?
What is the max size of a smart contract on the RSK network?
RSK 是否有编译智能合约的最大大小?如果是这样,可以部署的字节码的最大大小是多少?
是的,最大大小为 24567
,即 ~24KB。
这是在Constants#getMaxContractSize()
中定义的
public static int getMaxContractSize() {
return 0x6000;
}
合约部署时的具体逻辑在
TransactionExecutor#createContract()
private void createContract() {
int createdContractSize = getLength(program.getResult().getHReturn());
long returnDataGasValue = GasCost.multiply(GasCost.CREATE_DATA, createdContractSize);
if (mEndGas < returnDataGasValue) {
program.setRuntimeFailure(
Program.ExceptionHelper.notEnoughSpendingGas(
program,
"No gas to return just created contract",
returnDataGasValue));
result = program.getResult();
result.setHReturn(EMPTY_BYTE_ARRAY);
} else if (createdContractSize > Constants.getMaxContractSize()) {
program.setRuntimeFailure(
Program.ExceptionHelper.tooLargeContractSize(
program,
Constants.getMaxContractSize(),
createdContractSize));
result = program.getResult();
result.setHReturn(EMPTY_BYTE_ARRAY);
} else {
mEndGas = GasCost.subtract(mEndGas, returnDataGasValue);
program.spendGas(returnDataGasValue, "CONTRACT DATA COST");
cacheTrack.saveCode(tx.getContractAddress(), result.getHReturn());
}
}
上述函数中与您的问题相关的部分是条件
(createdContractSize > Constants.getMaxContractSize())
需要满足,否则抛出异常
RSK 是否有编译智能合约的最大大小?如果是这样,可以部署的字节码的最大大小是多少?
是的,最大大小为 24567
,即 ~24KB。
这是在Constants#getMaxContractSize()
public static int getMaxContractSize() {
return 0x6000;
}
合约部署时的具体逻辑在
TransactionExecutor#createContract()
private void createContract() {
int createdContractSize = getLength(program.getResult().getHReturn());
long returnDataGasValue = GasCost.multiply(GasCost.CREATE_DATA, createdContractSize);
if (mEndGas < returnDataGasValue) {
program.setRuntimeFailure(
Program.ExceptionHelper.notEnoughSpendingGas(
program,
"No gas to return just created contract",
returnDataGasValue));
result = program.getResult();
result.setHReturn(EMPTY_BYTE_ARRAY);
} else if (createdContractSize > Constants.getMaxContractSize()) {
program.setRuntimeFailure(
Program.ExceptionHelper.tooLargeContractSize(
program,
Constants.getMaxContractSize(),
createdContractSize));
result = program.getResult();
result.setHReturn(EMPTY_BYTE_ARRAY);
} else {
mEndGas = GasCost.subtract(mEndGas, returnDataGasValue);
program.spendGas(returnDataGasValue, "CONTRACT DATA COST");
cacheTrack.saveCode(tx.getContractAddress(), result.getHReturn());
}
}
上述函数中与您的问题相关的部分是条件
(createdContractSize > Constants.getMaxContractSize())
需要满足,否则抛出异常