7

If I add a new field to a struct that is not stored in storage but used as a parameter to an extrinsic, will it break decoding if a node with the changed runtime is syncing (i.e. executing older blocks where the struct didn't have the extra field? Does it matter where/how I add the extra field? example:

struct exampleStruct {
  a: u32,
  b: u32
}

// Example 1 - new field added at the begining
struct exampleStruct {
  newField: u32
  a: u32,
  b: u32
}

// Example 2 - new field added at the end
struct exampleStruct {
  a: u32,
  b: u32,
  newField: u32
}

I saw this old discussion here: https://github.com/paritytech/substrate/issues/1221 but not sure how it works for structs.

Thanks.

2

1 Answer 1

2

The runtime itself is stored on-chain. This is what actually executes the extrinsics for block inclusion. This means that all clients run the exact same on-chain code at any single point in time to execute extrinsics.

Once an upgrade happens, structures can be changed and the new runtime will once again be able to execute those structures. since the spec_version is used inside the signing payload, transactions created before the upgrade become invalid, so cannot be included into blocks anymore.

4
  • Good insights! I would also encourage people to learn more form the docs and do the tutorial on runtime upgrades docs.substrate.io/tutorials/v3/forkless-upgrades
    – Nuke
    Mar 24, 2022 at 20:09
  • As well as storage migrations, required for chains with a change in format of storage on upgrades docs.substrate.io/how-to-guides/v3/storage-migrations/basics
    – Nuke
    Mar 24, 2022 at 20:10
  • Thanks @RosaryBeads, so how does it work with syncing? When a node is syncing, does it only import older blocks without executing the transactions?
    – Nahu
    Mar 25, 2022 at 10:01
  • 1
    When it syscs, it executes the block with the runtime from that point in time - so through the sync process, it changes runtimes at each timetime upgrade. Mar 25, 2022 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.