everx-labs / TVM-Solidity-Compiler

Solidity compiler for TVM
GNU General Public License v3.0
125 stars 72 forks source link

Proposal: add onConstructorRetry special contract function. #122

Closed mnill closed 2 weeks ago

mnill commented 1 year ago

Hi. In Distributed programming paradigm we have a problem with gas management when we trying to redeploy an already deployed contract.

I'll try to explain it with by using tip-3 architecture. When some application transfers tokens from one wallet to another we always firstly deploy the target wallet, then we send an onAcceptTokensTransfer call with amount of tokens to transfer. If target wallet is already deployed - constructor will throw an error and gas will be bounce back to the contract which one tried to deploy the wallet. But we would like to send remain gas to the user's wallet which one started the transaction.

So we have a constructor like this:

constructor(address remainingGasTo) public
{
  require(msg.sender == root);
  tvm.rawReserve(_reserve(), 0);
  remainingGasTo.transfer({
      value: 0,
      flag: TokenMsgFlag.ALL_NOT_RESERVED + TokenMsgFlag.IGNORE_ERRORS,
      bounce: false
  });
}

If contract already deployed, message will bounce back to the msg.sender. Will be nice to to have an opportunity to declare such special function:

onConstructorRetry(address remainingGasTo) {
    require(msg.sender == root);
    tvm.rawReserve(_reserve(), 0);
    remainingGasTo.transfer({
      value: 0,
      flag: TokenMsgFlag.ALL_NOT_RESERVED + TokenMsgFlag.IGNORE_ERRORS,
      bounce: false
  });
}

Because an attempt to re-deploy is a regular situation for our application.

If you need more details I can try to draw a scheme of some real application.

cryshado commented 1 year ago

Thanks for the suggestion! We don't think that adding new built-in "magic" functions will solve the problem, and we're moving towards expanding the possibilities of the language, with which it will be possible to describe the solution to almost any situation.

IgorKoval commented 2 weeks ago

You can use Deploy the contract with no constructor https://github.com/everx-labs/TVM-Solidity-Compiler/blob/master/API.md#deploy-the-contract-with-no-constructor