Skip to content

Conversation

@N-010
Copy link
Contributor

@N-010 N-010 commented Oct 23, 2025

N-010 and others added 21 commits October 9, 2025 20:44
…duling logic; update state management for draw hour and schedule
…innerCounter utility function for better clarity and maintainability
…apacity; enhance test expectations for accuracy
…g and revenue calculation to improve clarity and maintainability
@N-010 N-010 marked this pull request as ready for review October 31, 2025 06:50
@J0ET0M
Copy link
Contributor

J0ET0M commented Oct 31, 2025

it looks like you want to change the initialize() method of the contract.
this method is imho only called once after the IPO to initialize the contract. is that correct @philippwerner?
if so, it will not really work.

i can also see updates to the contract state itself. what is your change strategy from the previous state to the current?

@N-010
Copy link
Contributor Author

N-010 commented Oct 31, 2025

@J0ET0M

it looks like you want to change the initialize() method of the contract. this method is imho only called once after the IPO to initialize the contract. is that correct @philippwerner? if so, it will not really work.

That's right. I added it there just in case. All necessary new states are processed at the beginning of the epoch.

i can also see updates to the contract state itself. what is your change strategy from the previous state to the current?

What do you mean?

@Franziska-Mueller
Copy link
Collaborator

while you're at it, please remove the default values from all input/output/locals.
they are misleading because they are unused (contract_exec will initialize all structs with all 0 before running any contract call).

@N-010
Copy link
Contributor Author

N-010 commented Oct 31, 2025

@Franziska-Mueller

#586 (comment)

Done

… RL_DEFAULT_SCHEDULE for clarity and maintainability
@N-010
Copy link
Contributor Author

N-010 commented Nov 3, 2025

@philippwerner
There are new states for SC. Do I need to edit this manually somehow?

* @brief Date/time guard for draw operations.
* lastDrawDateStamp prevents more than one action per calendar day (UTC).
*/
uint8 lastDrawDay = RL_INVALID_DAY;
Copy link
Contributor

@philippwerner philippwerner Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't be initialized correctly as you intended and is misleading because this init syntax is not supported for contracts in Qubic. All of the state is initialized with 0 before INITIALIZE is invoked after the IPO. After that, the state isn't reinitialized (exception: you do it in your procedures).

Copy link
Contributor Author

@N-010 N-010 Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@philippwerner

This won't be initialized correctly as you intended and is misleading because this init syntax is not supported for contracts in Qubic.

I understand this won't be called. If it's confusing, I'll remove it now.

@philippwerner
Copy link
Contributor

@philippwerner There are new states for SC. Do I need to edit this manually somehow?

If you change the size or the binary structure of the contract state after the IPO, you need to provide a state file conversion tool that the computor operators can run (an inspect) in order to convert the old state file (used by v1 code) to the new state file (used by v2 code). The core doesn't handle changes in state size and INITIALIZE won't be called if you release v2, because the original idea of contracts is to be immutable (no v2).

Or if you plan to have a fresh restart with an "empty" state (I don't know if there is any relevant data is kept in your state across epochs), you can give instructions for the computor operators (such as generate a file of size X containing all zero bytes) and have some code in BEGIN_EPOCH that does additional initialization in the specific first epoch of v2.

Remove initialize
@N-010
Copy link
Contributor Author

N-010 commented Nov 3, 2025

@philippwerner

If you change the size or the binary structure of the contract state after the IPO, you need to provide a state file conversion tool that the computor operators can run (an inspect) in order to convert the old state file (used by v1 code) to the new state file (used by v2 code). The core doesn't handle changes in state size and INITIALIZE won't be called if you release v2, because the original idea of contracts is to be immutable (no v2).

Is there any example implementation?

Where can I find the file for v1?

@philippwerner
Copy link
Contributor

philippwerner commented Nov 3, 2025

Is there any example implementation?

Has been done for QVAULT #365 with this tool https://github.com/TakaYuPP/qubic-stateFile-migration-QVAULT-SC--tool

Where can I find the file for v1?

For the contract state of the main net, there is a new file after each epoch. For developing and testing the tool, you may download the ep185.zip file posted in the computor-operators channel by Pomm3sgab3l on Oct 29th.
Your contract state is stored in contractXXXX.YYY with XXXX being the 0-padded contract index of your contract and YYY being the epoch.

@N-010
Copy link
Contributor Author

N-010 commented Nov 3, 2025

Thanks a lot

@Franziska-Mueller
Copy link
Collaborator

@N-010 @philippwerner
We have seen issues in the past with bugs in these external tools and computors deciding to run the code without the changes.
Hence I highly recommend to implement all changes/additions to the state as follows:

  • keep current state variables as they are (same order, all at the beginning of the state)
  • add new state variables at the end of the state
  • only let computors change the size of your contract state file (extending it with 0) via a command
  • do any required initializations in your SC's BEGIN_EPOCH procedure (enclosed in an if (epoch == xxx) { ... } block)

For an example, please see MsVault 2.0: #485

@N-010
Copy link
Contributor Author

N-010 commented Nov 3, 2025

@Franziska-Mueller
Unfortunately, this method won't work because I'm changing the HashSet to an Array mid-state. HashSet stores additional data

@Franziska-Mueller Franziska-Mueller merged commit a63b33c into qubic:develop Nov 4, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants