4

How do you efficiently tell which block number the last runtime upgrade happened on for a particular chain (without reading every block)?

A couple of people have hinted to me that the answer is in a digest somewhere? I'm assuming they were not referring to bill's :-) . Is this accessible from an rpc / state call / runtime call?

2 Answers 2

3

Usually, I go to Subscan.

At the event page, set the filter to System::CodeUpdated.

Then you can easily find which block height this event happened.


But it looks like it is hard to find it out quickly just on a node.


Haha, I wrote a tool to fetch the runtime upgrade block. See this PR.

It needs times requests.

You just need to:

subalfred get runtime-upgrade-block 9100 --uri wss://polkadot.api.onfinality.io/public-ws -lsubalfred::core::node

2022-07-24T06:40:43.855553Z TRACE subalfred::core::node: (0, 11298502) -> 30
2022-07-24T06:40:45.483503Z TRACE subalfred::core::node: (5649251, 11298502) -> 9140
2022-07-24T06:40:46.942158Z TRACE subalfred::core::node: (5649251, 8473876) -> 9090
2022-07-24T06:40:48.439329Z TRACE subalfred::core::node: (7061564, 8473876) -> 9122
2022-07-24T06:40:49.984054Z TRACE subalfred::core::node: (7061564, 7767720) -> 9110
2022-07-24T06:40:50.539368Z TRACE subalfred::core::node: (7061564, 7414642) -> 9110
2022-07-24T06:40:51.808166Z TRACE subalfred::core::node: (7061564, 7238103) -> 9090
2022-07-24T06:40:53.076860Z TRACE subalfred::core::node: (7149834, 7238103) -> 9090
2022-07-24T06:40:54.891926Z TRACE subalfred::core::node: (7193968, 7238103) -> 9090
2022-07-24T06:40:55.981484Z TRACE subalfred::core::node: (7216035, 7238103) -> 9100
2022-07-24T06:40:57.449337Z TRACE subalfred::core::node: (7216035, 7227069) -> 9100
2022-07-24T06:40:58.006499Z TRACE subalfred::core::node: (7216035, 7221552) -> 9100
2022-07-24T06:40:59.226754Z TRACE subalfred::core::node: (7216035, 7218794) -> 9090
2022-07-24T06:41:01.175041Z TRACE subalfred::core::node: (7217415, 7218794) -> 9100
2022-07-24T06:41:02.371131Z TRACE subalfred::core::node: (7217415, 7218104) -> 9090
2022-07-24T06:41:03.477414Z TRACE subalfred::core::node: (7217760, 7218104) -> 9100
2022-07-24T06:41:05.401558Z TRACE subalfred::core::node: (7217760, 7217932) -> 9090
2022-07-24T06:41:05.957115Z TRACE subalfred::core::node: (7217846, 7217932) -> 9090
2022-07-24T06:41:07.067274Z TRACE subalfred::core::node: (7217889, 7217932) -> 9100
2022-07-24T06:41:08.289674Z TRACE subalfred::core::node: (7217889, 7217910) -> 9090
2022-07-24T06:41:09.864914Z TRACE subalfred::core::node: (7217900, 7217910) -> 9090
2022-07-24T06:41:10.976319Z TRACE subalfred::core::node: (7217905, 7217910) -> 9100
2022-07-24T06:41:12.343318Z TRACE subalfred::core::node: (7217905, 7217907) -> 9090
2022-07-24T06:41:13.664283Z TRACE subalfred::core::node: (7217906, 7217907) -> 9090
7217907 0x8f10de9e6dcf190dccc90f464a8aa4448c9b080746d8e905bb0e4841fef80fdd

https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fpolkadot-rpc.dwellir.com#/explorer/query/0x8f10de9e6dcf190dccc90f464a8aa4448c9b080746d8e905bb0e4841fef80fdd

3

There is no simple way to tell you which block updated the runtime. To not require executing/looking into the state for each block, we introduced the CodeUpdated digest. This is part of the header and can be looked up. However, we don't store anywhere all the headers when this digest was present. For this you can use indexers like subscan.

Your Answer

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

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