The PoSt algorithm provided by Lotus has two schemes: Winning PoSt and Window PoSt. In Winning PoSt, we prove the department data that has been submitted when generating a block. The submitted department data is verified regularly to ensure that the data is saved correctly. This article will introduce the WindowPoSt logic in detail. To understand Window PoSt, we need to start with managing sectors in smart contracts. Here are the last submitted information of the smart contracts (specs-actors) used in this article: Author: Alex North<[email protected]> Date: Wed May 6 10:08:31 2020 +1000Set ConsensusMinerMinPower to 10TiB (#344) The miner's property information, mortgage information, and sector status are saved in the miner state. We select the code snippet related to WindowPoSt: ... ProvingPeriodStart abi.ChainEpoch NewSectors *abi.BitField Deadlines cid.Cid ... } ProvingPeriodStart - The start time of each proving period. NewSectors — Information about new blocks Deadline - Each challenge window is divided into multiple windows. Each window has a deadline. This is where WindowPoSt gets its name. 1.1 Verification Period The configuration specification for WindowPoSt is defined in specs-actors/actors/builtin/miner/policy.go. const SecondsInYear = 31556925 const SecondsInDay = 86400 const WPoStProvingPeriod = abi.ChainEpoch(SecondsInDay / EpochDurationSeconds) const WPoStChallengeWindow = abi.ChainEpoch(1800 / EpochDurationSeconds) // Half an hour (=48 per day) const WPoStPeriodDeadlines = uint64(WPoStProvingPeriod / WPoStChallengeWindow) const WPoStChallengeLookback = abi.ChainEpoch(20) WPoStProvingPeriod — Proving period. Proving is required once a day. WPoStChallengeWindow — ChallengeWindow is half an hour. Each validation period is divided into 47 ChallengeWindow. WPoStPeriodDeadlines — End of ChallengeWindow. WPoStChallengeLookback — Gets a random amount of data from the chain and looks back to the time of the previous block in each ChallengeWindow. In summary, the term of WindowPoSt is one day, and each WindowPoSt is divided into 48 windows. The sector information is different in different time periods of the window. Each window requires a proof provided by WindowPoSt, and the number of sectors in the window determines how many proofs are required. The detailed logic will be introduced later. 1.2 Deadline Deadlines are defined in specs-actor/actors/builtin/miner/deadlines.go: CurrentEpoch abi.ChainEpoch // Epoch at which this info was calculated. PeriodStart abi.ChainEpoch // First epoch of the proving period (<= CurrentEpoch). Index uint64 // Current deadline index, in [0..WPoStProvingPeriodDeadlines), or WPoStProvingPeriodDeadlines if period elapsed. Open abi.ChainEpoch // First epoch from which a proof may be submitted, inclusive (>= CurrentEpoch). Close abi.ChainEpoch // First epoch from which a proof may no longer be submitted, exclusive (>= Open). Challenge abi.ChainEpoch // Epoch at which to sample the chain for challenge (< Open). FaultCutoff abi.ChainEpoch // First epoch at which a fault declaration is rejected (< Open). } CurrentEpoch - The current deadline time. PeriodStart — The start freeze time for each proof. Index — Index of the cutoff date (aka window). Ranges from 0 to 47. Open - The earliest time during this window that evidence is allowed to be submitted. Close - latest time allowed in this window or submit evidence. Challenge - The range of random numbers in this window. FaultCutoff - Fault blocks can only be determined before this cutoff block time. The function ComputeProvingPeriodDeadline calculates the Deadline given the proof start time and the current block time: periodProgress := currEpoch - periodStart ... deadlineIdx := uint64(periodProgress / WPoStChallengeWindow) if periodProgress < 0 { // Period not yet started. deadlineIdx = 0 } deadlineOpen := periodStart + (abi.ChainEpoch(deadlineIdx) * WPoStChallengeWindow) return &DeadlineInfo{ CurrentEpoch: currEpoch, PeriodStart: periodStart, Index: deadlineIdx, Open: deadlineOpen, Close: deadlineOpen + WPoStChallengeWindow, Challenge: deadlineOpen - WPoStChallengeLookback, FaultCutoff: deadlineOpen - FaultDeclarationCutoff, } } We can get deadlienIdx from the current block time and start time. Using this index, it will be easier to get other variables. There are two parts in the WindowPoSt state logic: adjusting the start time of each windowPoSt proof, and updating the Sector information that needs to be proved. 2.1 Adjust the certification start time When the miner's smart contract is created, the start time of the proof is initialized. periodStart := nextProvingPeriodStart(currEpoch, AssignProvingPeriodOffset, randomly generates an offset in [0, WPoStProvingPeriod] through the function HashBlake2b. The function nextProvingPeriodStart is as follows: currModulus := currEpoch % WPoStProvingPeriod var periodProgress abi.ChainEpoch // How far ahead is currEpoch from previous offset boundary. if currModulus >= offset { periodProgress = currModulus - offset } else { periodProgress = WPoStProvingPeriod - (offset - currModulus) } periodStart := currEpoch - periodProgress + WPoStProvingPeriod Assert(periodStart>currEpoch) return periodStart } Simply put, this function finds the next proof start time with a given offset. After we know the proof start time, the minor's smart contract will check the proof status at the end of each proof period and update the proof start time. ... if deadline.PeriodStarted() { st.ProvingPeriodStart = st.ProvingPeriodStart + WPoStProvingPeriod } ... err = st.ClearPoStSubmissions() ... } 2.2 Update industry information In the miner's smart contract, NewSectors is updated through three interfaces: verifyCommitSector: Add new sector information to NewSectors while submitting PoREPommi. TerminateSector: Delete Sector information from NewSectors. handleProvingPeriod: Periodically "assigns" the NewSectors information to the deadline. In other words, this function maintains a list of all sectors that need to be proved in the miner's smart contract. It assigns sectors to different Windows at the beginning of each windowPoSt. Using the function AssignNewSectors we assign the sectors that need to be verified to different Windows (deadlines): Note that partitionSize is the number of sectors in a partition: ... case RegisteredProof_StackedDRG32GiBSeal: return 2349, nil case RegisteredProof_StackedDRG2KiBSeal: return 2, nil case RegisteredProof_StackedDRG8MiBSeal: return 2, nil case RegisteredProof_StackedDRG512MiBSeal: return 2, nil default: return 0, errors.Errorf("unsupported proof type: %v", p) ... } For 32 GB sectors, the partition size is 2349. There are 2 steps in AssignNewSectors : 1. Fill each window until the number of sectors reaches partitionSize. 2. If there are remaining sectors after step 1/, allocate them accordingly for each window according to partitionSize. To summarize the sector allocation, partitionSize is taken as a unit and is allocated to each Window. This means that there can be multiple sector partition units in a window. Pay special attention to the input variable seed. Although the function attempts to randomize sector allocation, it has not yet been implemented. The proofreading logic of WindowPoSt in the Lotus project. The following is the information from the last commit of the Lotus source code used in this article: Merge: 1d887b55 1831613f Author: Łukasz Magiera Date: Wed May 6 01:45:33 2020 +0200Merge pull request #1670 from filecoin-project/feat/update-markets-0.2.0 Update go-fil-markets The complete WindowPoSt scheduling logic flow chart is as follows: WindowPoStScheduler: Listens to the status on the chain. It tries to execute doPoSt at a new block height. doPoSt is divided into two parts: the WindowPoSt proof generated when wunPoSt is run (output from rust-fil-proofs), and submitPoSt, which pushes the proof to the chain. All proofs within a proof period will be recorded in the chain. handleProvingPeriod: At the end of each period, browse all proof status in all Windows. As a summary of what has been covered so far in this course: 1. One certification period takes one day. One period is divided into 48 windows. Each window takes 30 minutes. 2. Each window has its deadline (which is truncated for the correct submission of proof). 3. Existing partitions will be allocated based on partitionSize (2349 sectors) to fill each window. If there are remaining sectors after allocation, continue to fill Windows with partitionSize units. If the sector size is 32GB, it is 2349 sectors, that is, 73T. If each window contains one sector partition, the total storage space will be: 73T * 48 = 2.25P. That is, for 4.5P of storage space, each window will contain 2 sector partitions. The more data is stored, the more sectors there will be and the more space windows will occupy. Therefore, this leads to more time complexity for this calculation. After a basic understanding of the process logic, we finally look at how to generate proofs in WindowPoSt. These logics are implemented in rust-fil-proof or rust. From rust to rust, we will encounter many interfaces: Here, we skip the intermediate interface and directly use the interface functions in rust-fil-proofs. post_config: &PoStConfig, randomness: &ChallengeSeed, replicas: &BTreeMap<SectorId, PrivateReplicaInfo prover_id: ProverId, ) -> Result Here post_config means PoStConfig (configuration). Randomness is random information used to generate leaf data for query on sectors. Replicas are corresponding replica data of all sectors generated in WindowPoSt proof. pub fn as_v1_config(self) -> PoStConfig { Note that sector_count and challenge_count are defined in rust-fil-proofs/filecoin-proofs/src/constants.rs: [ (SECTOR_SIZE_2_KIB, 2), (SECTOR_SIZE_4_KIB, 2), (SECTOR_SIZE_16_KIB, 2), (SECTOR_SIZE_32_KIB, 2), (SECTOR_SIZE_8_MIB, 2), (SECTOR_SIZE_16_MIB, 2), (SECTOR_SIZE_512_MIB, 2), (SECTOR_SIZE_1_GIB, 2), (SECTOR_SIZE_32_GIB, 2349), // this gives 133,977,564 constraints, fitting just in a single partition (SECTOR_SIZE_64_GIB, 2300), // this gives 131,182,800 constraints, fitting just in a single partition ] .iter() .copied() .collect() ); For example, when the challenge number is 10, the partition consists of 2349 sectors, and the size of each sector is 32 GB. 5.2 Generating Challenges Each sector contains 10 challenge leaves. This is how it is calculated (function prove_all_partitions in storage-proofs/post/src/fallback/vanilla.rs): .into_par_iter() .map(|n| { let challenge_index = ((j * num_sectors_per_chunk + i) * pub_params.challenge_count + n) as u64; let challenged_leaf_start = generate_leaf_challenge( pub_params, pub_inputs.randomness, sector_id.into(), challenge_index, )?;tree.gen_cached_proof(challenged_leaf_start as usize, levels) }) .collect::<Result<Vec<_>>>()?; Challenge_index is the index of the challenge that all sectors need to prove. generate_leaf_challenge generates a leaf index based on the random information, sector index and challenge index. hasher.input(AsRef::<[u8]>::as_ref(&randomness)); hasher.input(§or_id.to_le_bytes()[..]); hasher.input(&leaf_challenge_index.to_le_bytes()[..]); let hash = hasher.result();let leaf_challenge = LittleEndian::read_u64(&hash.as_ref()[..8]);let challenged_range_index = leaf_challenge % (pub_params.sector_size / NODE_SIZE as u64); We then use a hash function on the random data, the sector ID, and the challenge leaf index. We mod the result by the total number of leaves. For a 32 GB sector, we get 16 GB of leaves. 5.3 Zero-knowledge proof circuit The circuit logic mentioned here is the same as the WinningPoSt circuit except for the different variables. It is important to note that the partition size count in WindowPoSt is not one. The calculation method is as follows: total_sector_count: usize, post_config: &PoStConfig, ) -> Option let partitions = (total_sector_count as f32 / post_config.sector_count as f32).ceil() as usize;if partitions > 1 { Some(partitions) } else { None } } In short, the number of partitions is the number of replicas divided by the number of sectors in each partition (2349). To summarize, the number of proofs (partitions) is related to the number of sectors that need to be proved, and is equal to the number of replicas divided by 2349. In the proof of each partition, 10 leaf nodes will be extracted from each sector. WindowPoSt periodically proves the existence of the submitted sector data. Each verification period takes one day. One period consists of 48 windows. Each window takes 30 minutes. All Windows require a WindowPoSt proof computation. The number of proofs is equal to the number of sectors in the window divided by the number of sectors in the partition . To prove a partition, we draw 10 leaf nodes from each sector of the partition. ——End—— |
>>: V God's speech is here! Everything you want to know about Ethereum 2.0 is here
SEC documents released on Wednesday showed that M...
A woman with a lucky face will always have her ow...
On the 15th and 16th, Bitmain's AI subsidiary...
Rage Comment : The blockchain field has always ho...
Life is never an easy thing. Everything in people...
In 44 days, Bitcoin miners will face their third ...
In physiognomy, the location of a person's mo...
What are the five small things in physiognomy? In...
Widow's Peak There are countless handsome men...
People with different facial features have differe...
The House of Migration is located between the cor...
In fact, there are many types of eye shapes. From...
Moles in different positions have different meani...
In physiognomy, if two people have high cheekbone...
Physiognomy is a folk knowledge that predicts fat...