# Coretime notes ![coretme](https://hackmd.io/_uploads/Bkc_Wve20.png) ## Terms ### Core virtual abstraction of computational resources provided by the relay chain to secure the blocks of a parachain. ### Coretime a time allocated for utilizing a core, measured in realy chain blocks. Coretime itself is a (perishable) resource which transforms into blockspace when utilized. The smallest quantity of coretime right now yields you a single block. ### Bulk Coretime A fixed duration of continuous coretime represented by an NFT that can be split, shared, or resold. Currently, the duration of bulk coretime is set to 28 days. ### Region an asset representing bulk coretime, 28 days. ### On-demand Coretime Pool Set of cores that are available on-demand. Cores reserved through bulk coretime could also be made available in the on-demand coretime pool, in parts or in entirety. ### Timeslice A timeslice represents the granularity the Coretime Chain schedules cores on the Relay Chain. The Coretime Chain announces a schedule for each core, comprising the next 80 relay chain blocks in advance. 5,040 timeslices corresponds to the region length of 28 days (which is the initial configuration set for bulk coretime). ### Mask An 80 bit binary string where each bit corresponds to a block. If the bit is set, the parachain gets to use a block, if not it doesn't. E.g we have a mask with only 3 bits set to 1, that means the parachain will use only 3 blocks of the timeslice for the given region (5040 timeslices). ### Lead-in Period During the proposed 7-day sale period, the price descends from a high number to a lower number (sale_price) in a linear, block-by-block basis, similar to a “dutch auction.” Currently, according to RFC-1, this is a factor of 2, so if the sale_price is 1, the start price at the beginning of the 7-day lead-in period is 2. ### Interlude period The period during which renewals are possible. ### Splitting and Interlacing **Splitting**: Dividing a region into multiple regions, each with its own start and end timeslices. **Interlacing**: Dividing a region so that different tasks are executed on different blocks within the same timeslice. The new regions will share the same start and end timeslice as the original region, but different tasks will be assigned to different blocks. #### Examples Work on the cores can be interlaced, split and shared between different parachains and different assignemnts. #### Splitting ![coreitme-splititng](https://hackmd.io/_uploads/HyCetwlnA.png) Timeslice: 0 - 5040 Mask 1: (timeslice 0-2520): `0xFFFFFFFFFFFFFFFFFFFF` Mask 2: (timeslice 2521-5040): `0xFFFFFFFFFFFFFFFFFFFF` 1. Someone buys a block and splits it into two equal parts. 2. They assign a workload to the first half with a full mask, meaning it uses all 80 blocks in each 80-block chunk. However, this workload only runs for the first 2520 timeslices. 3. They assign a different workload to the second half, also with a full mask using all 80 blocks in each 80-block chunk. This workload runs from timeslice 2521 to timeslice 5040. #### Interlacing ![coretime-interlacing](https://hackmd.io/_uploads/ry8gFwx3R.png) Timeslice: 0 - 5040 Mask 1: (timeslice 0-2520): `0xffffffffff0000000000` Mask 2: (timeslice 2521-5040): `0x0000000000ffffffffff` 1. Someone buys a region and applies interlacing masks. These masks together ensure 80 blocks are set as active. 2. They assign one workload to the first chunk, so it gets 40 blocks in every 80-block timeslice for all 5040 timeslices. 3. They assign another workload to the second chunk, so it gets the remaining 40 blocks in every 80-block timeslice for all 5040 timeslices. With the current relay implementation, the specific mask used doesn't matter because the allocation alternates between the workloads. Workload A gets a block, then workload B gets a block, and this pattern continues until the end of the region. ## Core status Task - Assigned task happening on the core Pool - Core should be used for the Instantaneous Coretime Pool. ## Regions In the initial sales period (sale 0), the Polkadot Coretime chain isn't actively driving the relay chain; it's essentially in the same state as it was prior to the transition. During the bootstrapping phase, things operate a bit differently, but after the 28-day period, the workload will align with the current state of the relay chain moving forward. ### Polkadot Coretime chain regions [Data and stats Polkadot Coretime chain](https://metabase.data.paritytech.io/dashboard/204-polkadot-coretime) | Cycle number |Sale number | Start - End (ts) |Start - End (time: 10:14AM ) | |---------------------|--------------------|------------------------------|------------------------| | 0 (deploy time) |1 | 282525 - 287565 | Sep 19 - Oct 17 2024 | | 1 |2 | 287565 - 292605 | Oct 17 - Nov 14 2024 | ### Kusama Coretime chain regions [Data and stats Kusama Coretime chain](https://metabase.data.paritytech.io/dashboard/204-polkadot-coretime) | Cycle number | Start - End (ts) |Start - End (time) | |---------------------|-------------------------|--------------------------| | 1 | 316008 - 321048 | Apr 25 - May 23 2024 | | 2 | 316008 - 321048 | May 23 - Jun 20 2024 | | 3 | 321048 - 326088 | Jun 20 - Jul 18 2024 | | 4 | 321048 - 326088 | Jul 18 - Aug 15 2024 | | 5 | 321048 - 326088 | Aug 15 - Sep 12 2024 | | 6 | 321048 - 326088 | Sep 12 - Oct 10 2024 | | 7 | 321048 - 326088 | Oct 10 - Nov 7 2024 | ## Numbers summary Bits in a mask sum up to 80 (each corresponding to a block in a timeslice) ### Relay | Header | Block | Time | Time (m) |Timeslice (ts)| |-----------|---------|--------- |------------|--------------| |`Timeslice`| 80 | 8 minutes|8 |x | | `Region` | 403200 |28 days |40320 |5040 | | `Block` | x |6000ms |0.1 |0.00125 | ### Coretime | Header | Block | Time | Time (m) |Timeslice (ts)| |-----------|---------|--------- |------------|--------------| |`Timeslice`| 40 | 8 minutes|8 |x | | `Region` | 201600 |28 days |40320 |5040 | | `Block` | x |12000ms |0.2 |0.0025 | ### Calculations #### Calculate target block number and timestamp from timeslice. - TargetTimeslice - LatestBlock - TimestampNow - BlockTime - 6000ms `TargetBlockNumber = TargetTimeslice * BlocksPerTimeslice` `BlockDifferencenMs = (TargetBlockNumber - LatestBlock) * blockTime` `EstimatedTimestamp = TimestampNow + BlockDifferencenMs` ## Purchasing Coretime ![Coretime-pricing3](https://hackmd.io/_uploads/H1_TVn5ykg.png) ## Broker Pallet ### Configuration `broker.configuration: Option<PalletBrokerConfigRecord>` https://paritytech.github.io/polkadot-sdk/master/pallet_broker/type.ConfigRecordOf.html# ```json { advanceNotice: 10 interludeLength: 50400 // in blocks on Relay chain leadinLength: 50400 // in blocks on Relay chain regionLength: 5040 // in timeslices idealBulkProportion: 100% limitCoresOffered: null renewalBump: 3% // renewal price increase each sale contributionTimeout: 5040 } ``` `regionLength` in blocks = 5040 * 80 = 403200 ### Sale Info Record This describes the sale that will start in the next cycle. The region refers to the future region that will happen when the interlude starts. `broker.saleInfo: Option<PalletBrokerSaleInfoRecord>` https://paritytech.github.io/polkadot-sdk/master/pallet_broker/type.SaleInfoRecordOf.html ```json { saleStart: 551,134 // in blocks on Relay Chain leadinLength: 100,800 // in blocks on Relay Chain endPrice: 15,110,719,424 regionBegin: 297,645 // ts regionEnd: 302,685 // ts idealCoresSold: 10 coresOffered: 10 firstCore: 52 selloutPrice: 15,110,719,424 coresSold: 10 } ``` ## Sources Timeline of work on Coretime and links to videos and other sources in [Dominique's notes](https://hackmd.io/@LwMsxe3-SFmNXxugAXOKgg/H1j0Bhn5A) [Polkadot Wiki Coretime]( https://wiki.polkadot.network/docs/learn-agile-coretime)