Skip to content

Automatic zero-padding for undersized contract state files#807

Open
fnordspace wants to merge 1 commit intoqubic:developfrom
fnordspace:feature/2026-03-25-automaticContractfilePadding
Open

Automatic zero-padding for undersized contract state files#807
fnordspace wants to merge 1 commit intoqubic:developfrom
fnordspace:feature/2026-03-25-automaticContractfilePadding

Conversation

@fnordspace
Copy link
Contributor

When a contract's state struct grows between epochs, the on-disk state file from the previous epoch is smaller than the new expected size, causing the node to fail loading.

This adds a padding mechanism that detects undersized contract files and zero-pads them: it zeros the entire buffer, then loads the smaller file into the front. New fields are automatically zero-initialized.

Padding is only applied to contracts explicitly listed in the paddableContracts whitelist to prevent masking file corruption.

@fnordspace fnordspace self-assigned this Mar 25, 2026
@fnordspace fnordspace added the enhancement New feature or request label Mar 25, 2026
@fnordspace fnordspace added this to qubic Mar 25, 2026
@fnordspace fnordspace moved this to 👀 In review in qubic Mar 25, 2026
// forceLoadFromFile: when loading node states from file, we want to make sure it load from file and ignore constructionEpoch == system.epoch case
static bool loadContractStateFiles(CHAR16* directory, bool forceLoadFromFile)
{
// Contracts whose state struct grew this epoch. Update this list each epoch as needed.
Copy link
Collaborator

Choose a reason for hiding this comment

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

could we move this to somewhere where it's easier to find? e.g. contract_def.h

Copy link
Contributor

@philippwerner philippwerner left a comment

Choose a reason for hiding this comment

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

I agree that moving the array of paddable contracts to contract_def.h would make sense. Besides that, everything looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: 👀 In review

Development

Successfully merging this pull request may close these issues.

3 participants