比特幣交易所 比特幣交易所
Ctrl+D 比特幣交易所
ads
首頁 > Uniswap > Info

filecoin探索之路:復制證明(一)_COM

Author:

Time:1900/1/1 0:00:00

一、復制證明簡介

引用官方的解釋就是:“InordertoregisterasectorwiththeFilecoinnetwork,thesectorhastobesealed.Sealingisacomputation-heavyprocessthatproducesauniquerepresentationofthedataintheformofaproof,calledProof-of-ReplicationorPoRep.”簡單來說,復制證明就是在對扇區進行封裝的過程中生成的扇區唯一標識。

復制證明要用到三種特殊參數:數據本身、執行密封的礦工參與者、特定礦工密封特定數據的時間。一旦其中的一個參數發生變化,那么得到的復制證明結果將會完全不同。換句話說,如果同一個礦工稍后試圖密封相同的數據,那么這將導致不同的PoRep證明。

復制證明是一個很大的計算過程,接下來我將會分為兩部分:P1、P2,從代碼的形式給讀者介紹復制證明的工作原理。

二、P1代碼解析

在本次文章,我將主要介紹32GB封裝的P1的過程。在此階段,會發生PoRep的SDR編碼和復制。

因為是第一次,我這里提一句,扇區的不同狀態會觸發miner不同的執行方法,1.16版本可以看externstorage-sealingfsm.go文件約460行代碼內容,代碼中記錄了miner不同的狀態以及觸發方法。這里我只放P1狀態的代碼。

????????...

????????...

????????case?Packing:

????????????????return?m.handlePacking,?processed,?nil

????????case?GetTicket:

????????????????return?m.handleGetTicket,?processed,?nil

????????case?PreCommit1:

????????????????return?m.handlePreCommit1,?processed,?nil

????????case?PreCommit2:

????????????????return?m.handlePreCommit2,?processed,?nil

????????...

????????...

可以看到,PreCommit1調用的是handlePreCommit1方法,從下邊可以看出,利用SealPreCommit1方法得到P1結果。

func?(m?*Sealing)?handlePreCommit1(ctx?statemachine.Context,?sector?SectorInfo)?error?{

????????...

????????...

????????pc1o,?err?:=?m.sealer.SealPreCommit1(sector.sealingCtx(ctx.Context()),?m.minerSector(sector.SectorType,?sector.SectorNumber),?sector.TicketValue,?sector.pieceInfos())

????????if?err?!=?nil?{

????????????????return?ctx.Send(SectorSealPreCommit1Failed{xerrors.Errorf("seal?pre?commit(1)?failed:?%w",?err。)

????????}

????????return?ctx.Send(SectorPreCommit1{

????????????????PreCommit1Out:?pc1o,

????????})

}

讓我們深入看一下SealPreCommit1方法,這里我們最終調用的是:func(sb*Sealer)SealPreCommit1(...)方法。方法中有我們常常遇到的方法:AcquireSector(...)、Unpadded()。

AcquireSector方法是根據傳入的類型與sectorID一起,組合成對應的path。

Uppadded方法是返回一個Piece的未填充大小,以字節為單位,計算公式是:s-(s/128)。有未填充大小,自然就有填充大小,填充大小的計算方法為Padded(),計算公式是:s+(s/127)

func?(sb?*Sealer)?SealPreCommit1(ctx?context.Context,?sector?storage.SectorRef,?ticket?abi.SealRandomness,?pieces?abi.PieceInfo)?(out?storage.PreCommit1Out,?err?error)?{

????????paths,?done,?err?:=?sb.sectors.AcquireSector(ctx,?sector,?storiface.FTUnsealed,?storiface.FTSealed|storiface.FTCache,?storiface.PathSealing)

????????if?err?!=?nil?{

????????????????return?nil,?xerrors.Errorf("acquiring?sector?paths:?%w",?err)

????????}

????????...

????????...

????????...

????????var?sum?abi.UnpaddedPieceSize

????????for?_,?piece?:=?range?pieces?{

????????????????sum?+=?piece.Size.Unpadded()

????????}

????????//?根據扇區證明類型獲取扇區大小

????????ssize,?err?:=?sector.ProofType.SectorSize()

PEPE市值突破15億美元 24小時交易量近17億美元:金色財經報道,CoinGecko數據顯示,PEPE市值突破15億美元,現報15.43億美元,PEPE 24小時交易量約16.95億美元。PEPE價格目前為0.00000379美元,24小時漲幅達94.1%。[2023/5/6 14:46:02]

????????if?err?!=?nil?{

????????????????return?nil,?err

????????}

????????//?這里比較一次總piece大小和要求的扇區大小是否一致

????????ussize?:=?abi.PaddedPieceSize(ssize).Unpadded()

????????if?sum?!=?ussize?{

????????????????return?nil,?xerrors.Errorf("aggregated?piece?sizes?don't?match?sector?size:?%d?!=?%d?(%d)",?sum,?ussize,?int64(ussize-sum))

????????}

????????//?TODO:?context?cancellation?respect

????????p1o,?err?:=?ffi.SealPreCommitPhase1(

????????????????sector.ProofType,

????????????????paths.Cache,

????????????????paths.Unsealed,

????????????????paths.Sealed,

????????????????sector.ID.Number,

????????????????sector.ID.Miner,

????????????????ticket,

????????????????pieces,

????????)

????????...

????????...

}

接下來,一切準備就緒,我們將要開始我們的P1遠游了,因為接下來的代碼都不屬于lotus,上面方法中我們可以看到ffi.SealPreCommitPhase1,ffi其實使用的是https://github.com/filecoin-project/filecoin-ffi庫,我們通過這個庫的如下方法,轉入rust語言去實現P1。

func?SealPreCommitPhase1(registeredProof?RegisteredSealProof,?cacheDirPath?SliceRefUint8,?stagedSectorPath?SliceRefUint8,?sealedSectorPath?SliceRefUint8,?sectorId?uint64,?proverId?*ByteArray32,?ticket?*ByteArray32,?pieces?SliceRefPublicPieceInfo)?(byte,?error)?{

????????resp?:=?C.seal_pre_commit_phase1(registeredProof,?cacheDirPath,?stagedSectorPath,?sealedSectorPath,?C.uint64_t(sectorId),?proverId,?ticket,?pieces)

????????defer?resp.destroy()

????????if?err?:=?CheckErr(resp);?err?!=?nil?{

????????????????return?nil,?err

????????}

????????return?resp.value.copy(),?nil

}

C庫其實就是ffi庫自身的rust庫,調用的方法如下所示:

fn?seal_pre_commit_phase1(

????registered_proof:?RegisteredSealProof,

????cache_dir_path:?c_slice::Ref<u8>,

????staged_sector_path:?c_slice::Ref<u8>,

????sealed_sector_path:?c_slice::Ref<u8>,

????sector_id:?u64,

????prover_id:?&,

????ticket:?&,

????pieces:?c_slice::Ref<PublicPieceInfo>,

)?->?repr_c::Box<SealPreCommitPhase1Response>?{

????catch_panic_response("seal_pre_commit_phase1",?||?{

????????let?public_pieces:?Vec<PieceInfo>?=?pieces.iter().map(Into::into).collect();

????????let?result?=?seal::seal_pre_commit_phase1(

????????????registered_proof.into(),

????????????as_path_buf(&cache_dir_path)?,

????????????as_path_buf(&staged_sector_path)?,

????????????as_path_buf(&sealed_sector_path)?,

????????????*prover_id,

????????????SectorId::from(sector_id),

????????????*ticket,

BitfinexAlpha:比特幣現貨交易量自上月達到峰值后大幅下降:4月18日消息,根據BitfinexAlpha最新報告,3月份消費者價格指數(CPI)有所改善,盡管仍居高不下。月通貨膨脹率下降主要是由于能源價格大幅下降。剔除食品和能源,核心通脹依然存在。然而,我們認為過去一年已經做了足夠的工作,可以暫停加息。雖然我們預計5月3日還會加息25個基點,但在那之后預計會進一步收緊。支持這一觀點的事實是,生產者價格指數(PPI),或批發通脹,見證了近三年來的最大跌幅。能源價格和貿易服務的大幅下跌在一定程度上夸大了該指數的跌幅,盡管本月早些時候OPEC+宣布石油減產后,能源價格可能再次飆升,但其他方面應該有足夠的下行壓力,讓美聯儲可以從經濟進一步收緊中喘息一下。[2023/4/18 14:10:20]

????????????&public_pieces,

????????)?;

????????let?result?=?serde_json::to_vec(&result)?;

????????Ok(result.into_boxed_slice().into())

????})

}

上面的seal庫是:https://github.com/filecoin-project/rust-filecoin-proofs-api。在這個方法對應的文件中,我們可以看到很多方法都對應了一個*__inner方法。實際上seal_pre_commit_phase1只是做了個中轉。我們可以直接看seal_pre_commit_phase1_inner方法

pub?fn?seal_pre_commit_phase1<R,?S,?T>(

????registered_proof:?RegisteredSealProof,

????cache_path:?R,

????in_path:?S,

????out_path:?T,

????prover_id:?ProverId,

????sector_id:?SectorId,

????ticket:?Ticket,

????piece_infos:?&,

)?->?Result<SealPreCommitPhase1Output>

where

????R:?AsRef<Path>,

????S:?AsRef<Path>,

????T:?AsRef<Path>,

{

????ensure!(

????????registered_proof.major_version()?==?1,

????????"unusupported?version"

????);

????with_shape!(

????????u64::from(registered_proof.sector_size()),

????????seal_pre_commit_phase1_inner,

????????registered_proof,

????????cache_path.as_ref(),

????????in_path.as_ref(),

????????out_path.as_ref(),

????????prover_id,

????????sector_id,

????????ticket,

????????piece_infos

????)

}

在inner方法中,filecoin_proofs_v1::seal_pre_commit_phase1,會調用證明子系統的實現部分。filecoin_proofs_v1使用的庫是:https://github.com/filecoin-project/rust-fil-proofs。

fn?seal_pre_commit_phase1_inner<Tree:?'static?+?MerkleTreeTrait>(

????registered_proof:?RegisteredSealProof,

????cache_path:?&Path,

????in_path:?&Path,

????out_path:?&Path,

????prover_id:?ProverId,

????sector_id:?SectorId,

????ticket:?Ticket,

????piece_infos:?&,

)?->?Result<SealPreCommitPhase1Output>?{

????let?config?=?registered_proof.as_v1_config();

????let?output?=?filecoin_proofs_v1::seal_pre_commit_phase1::<_,?_,?_,?Tree>(

????????config,

????????cache_path,

????????in_path,

????????out_path,

????????prover_id,

????????sector_id,

????????ticket,

????????piece_infos,

????)?;

????let?filecoin_proofs_v1::types::SealPreCommitPhase1Output::<Tree>?{

????????labels,

????????config,

A股開盤:深證區塊鏈50指數上漲0.34%:金色財經消息,A股開盤,上證指數報3248.97點,開盤上漲0.35%,深證成指報11823.8點,開盤上漲0.42%,深證區塊鏈50指數報2807.95點,開盤上漲0.34%。區塊鏈板塊開盤上漲0.22%,數字貨幣板塊開盤上漲0.26%。[2022/9/15 6:57:26]

????????comm_d,

????}?=?output;

????Ok(SealPreCommitPhase1Output?{

????????registered_proof,

????????labels:?Labels::from_raw::<Tree>(registered_proof,?&labels)?,

????????config,

????????comm_d,

????})

}

filecoin_proofs_v1::seal_pre_commit_phase1方法就是真正實現P1的地方,我將會在這里詳細講解P1,使P1將在這里一一浮出水面。

pub?fn?seal_pre_commit_phase1<R,?S,?T,?Tree:?'static?+?MerkleTreeTrait>(

????porep_config:?PoRepConfig,

????cache_path:?R,

????in_path:?S,

????out_path:?T,

????prover_id:?ProverId,

????sector_id:?SectorId,

????ticket:?Ticket,

????piece_infos:?&,

)?->?Result<SealPreCommitPhase1Output<Tree>>

where

????R:?AsRef<Path>,

????S:?AsRef<Path>,

????T:?AsRef<Path>,

{

????info!("seal_pre_commit_phase1:start:?{:?}",?sector_id);

????//?Sanity?check?all?input?path?types.

????ensure!(

????????metadata(in_path.as_ref())?.is_file(),

????????"in_path?must?be?a?file"

????);

????ensure!(

????????metadata(out_path.as_ref())?.is_file(),

????????"out_path?must?be?a?file"

????);

????ensure!(

????????metadata(cache_path.as_ref())?.is_dir(),

????????"cache_path?must?be?a?directory"

????);

????let?sector_bytes?=?usize::from(PaddedBytesAmount::from(porep_config));

????fs::metadata(&in_path)

????????.with_context(||?format!("could?not?read?in_path={:?})",?in_path.as_ref().display()))?;

????fs::metadata(&out_path)

????????.with_context(||?format!("could?not?read?out_path={:?}",?out_path.as_ref().display()))?;

????//?Copy?unsealed?data?to?output?location,?where?it?will?be?sealed?in?place.

????fs::copy(&in_path,?&out_path).with_context(||?{

????????format!(

????????????"could?not?copy?in_path={:?}?to?out_path={:?}",

????????????in_path.as_ref().display(),

????????????out_path.as_ref().display()

????????)

????})?;

????let?f_data?=?OpenOptions::new()

????????.read(true)

????????.write(true)

????????.open(&out_path)

????????.with_context(||?format!("could?not?open?out_path={:?}",?out_path.as_ref().display()))?;

????//?Zero-pad?the?data?to?the?requested?size?by?extending?the?underlying?file?if?needed.

????f_data.set_len(sector_bytes?as?u64)?;

????let?data?=?unsafe?{

????????//?創建由文件支持的可寫內存映射

????????MmapOptions::new()

????????????.map_mut(&f_data)

Cathie Wood:貝萊德加入BTC可能會帶來1萬億美元的增長需求:金色財經報道,Ark Invest創始人Cathie Wood稱,貝萊德加入BTC可能會帶來1萬億美元的增長需求。此外,這將增加比特幣的市值,遠遠超過1萬億的新需求,因為BTC的流動性供應非常低。[2022/8/10 12:15:44]

????????????.with_context(||?format!("could?not?mmap?out_path={:?}",?out_path.as_ref().display()))?

????};

????let?compound_setup_params?=?compound_proof::SetupParams?{

????????vanilla_params:?setup_params(

????????????PaddedBytesAmount::from(porep_config),

????????????usize::from(PoRepProofPartitions::from(porep_config)),

????????????porep_config.porep_id,

????????????porep_config.api_version,

????????)?,

????????partitions:?Some(usize::from(PoRepProofPartitions::from(porep_config))),

????????priority:?false,

????};

????//?利用param得到public_params,其vanilla_params.graph字段,就是構建出來的圖的數據結構。

????let?compound_public_params?=?<StackedCompound<Tree,?DefaultPieceHasher>?as?CompoundProof<

????????StackedDrg<'_,?Tree,?DefaultPieceHasher>,

????????_,

????>>::setup(&compound_setup_params)?;

????trace!("building?merkle?tree?for?the?original?data");

????let?(config,?comm_d)?=?measure_op(Operation::CommD,?||?->?Result<_>?{

????????let?base_tree_size?=?get_base_tree_size::<DefaultBinaryTree>(porep_config.sector_size)?;

????????let?base_tree_leafs?=?get_base_tree_leafs::<DefaultBinaryTree>(base_tree_size)?;

????????ensure!(

????????????compound_public_params.vanilla_params.graph.size()?==?base_tree_leafs,

????????????"graph?size?and?leaf?size?don't?match"

????????);

????????trace!(

????????????"seal?phase?1:?sector_size?{},?base?tree?size?{},?base?tree?leafs?{}",

????????????u64::from(porep_config.sector_size),

????????????base_tree_size,

????????????base_tree_leafs,

????????);

????????let?mut?config?=?StoreConfig::new(

????????????cache_path.as_ref(),

????????????CacheKey::CommDTree.to_string(),

????????????default_rows_to_discard(base_tree_leafs,?BINARY_ARITY),

????????);

????????let?data_tree?=?create_base_merkle_tree::<BinaryMerkleTree<DefaultPieceHasher>>(

????????????Some(config.clone()),

????????????base_tree_leafs,

????????????&data,

????????)?;

????????drop(data);

????????config.size?=?Some(data_tree.len());

????????let?comm_d_root:?Fr?=?data_tree.root().into();

????????let?comm_d?=?commitment_from_fr(comm_d_root);

????????drop(data_tree);

????????Ok((config,?comm_d))

????})?;

????trace!("verifying?pieces");

????ensure!(

????????verify_pieces(&comm_d,?piece_infos,?porep_config.into())?,

????????"pieces?and?comm_d?do?not?match"

Meta與數字時尚初創公司DressX合作推出虛擬服裝:金色財經消息,Meta正在與數字時尚初創公司DressX合作,在Meta的AvatarStore上提供新的時尚外觀。DressX服裝于7月19日開始發售,用戶可以在包括Messenger、Facebook、Instagram和頭戴VR設備Quest在內的Meta平臺上購買和穿著它們。(TheBlock)[2022/7/20 2:24:38]

????);

????let?replica_id?=?generate_replica_id::<Tree::Hasher,?_>(

????????&prover_id,

????????sector_id.into(),

????????&ticket,

????????comm_d,

????????&porep_config.porep_id,

????);

????let?labels?=?StackedDrg::<Tree,?DefaultPieceHasher>::replicate_phase1(

????????&compound_public_params.vanilla_params,

????????&replica_id,

????????config.clone(),

????)?;

????let?out?=?SealPreCommitPhase1Output?{

????????labels,

????????config,

????????comm_d,

????};

????info!("seal_pre_commit_phase1:finish:?{:?}",?sector_id);

????Ok(out)

}

P1實現解釋

上邊seal_pre_commit_phase1的代碼中,我們可以看到有三個path,這三個path分別對應:in_path->unsealedpath、out_path->sealedpath、cache_path->cachepath。代碼會先去檢查這三個path,他們兩個是文件,一個是文件夾。

檢查完path后我們可以看到fs::copy方法,它將unsealed文件拷貝到了sealed文件中,完成封裝。

Copy完成后拿出sealed文件的數據,并利用.set_len()方法填充數據(或刪減),使sealed數據達到證明類型配置規定的扇區大小。

setup_params()

setup_params()方法利用證明類型配置構建啟動參數。這里傳入的參數為:扇區大小、分區數、證明類型id、證明類型版本。分區數可看https://github.com/filecoin-project/rust-filecoin-proofs-api/blob/23ae2893741829bddc29d7211e06c914bab5423c/src/registry.rs中的partitions()方法,在對應https://github.com/filecoin-project/rust-fil-proofs/blob/ec2ef88a17ffed991b64dc8d96b30c36b275eca0/filecoin-proofs/src/constants.rs得到具體值。我分析以32GB扇區為主,因此分區數為10。另外三個就不講了,跟分區數一樣,都是從這兩個文件得到的。

pub?fn?setup_params(

????sector_bytes:?PaddedBytesAmount,

????partitions:?usize,

????porep_id:?,

????api_version:?ApiVersion,

)?->?Result<stacked::SetupParams>?{

????//?得到挑戰層數和最大挑戰次數

????let?layer_challenges?=?select_challenges(

????????partitions,

????????*POREP_MINIMUM_CHALLENGES

????????????.read()

????????????.expect("POREP_MINIMUM_CHALLENGES?poisoned")

????????????.get(&u64::from(sector_bytes))

????????????.expect("unknown?sector?size")?as?usize,

????????*LAYERS

????????????.read()

????????????.expect("LAYERS?poisoned")

????????????.get(&u64::from(sector_bytes))

????????????.expect("unknown?sector?size"),

????);

????let?sector_bytes?=?u64::from(sector_bytes);

????ensure!(

????????sector_bytes?%?32?==?0,

????????"sector_bytes?({})?must?be?a?multiple?of?32",

????????sector_bytes,

????);

????let?nodes?=?(sector_bytes?/?32)?as?usize;????//?節點數,SDR共有11層,每一層的節點數量相當于1GiB的字節數量。

????let?degree?=?DRG_DEGREE;????//?用于所有?DRG?圖的基礎度數,?DRG_DEGREE=6。

????let?expansion_degree?=?EXP_DEGREE;?//大小是8,上一層中抽取的節點數量,用來計算當前層的節點數據

????Ok(stacked::SetupParams?{

????????nodes,

????????degree,

????????expansion_degree,

????????porep_id,

????????layer_challenges,

????????api_version,

????})

}

Merkletree和對應comm_d的生成

看完setup_params方法,讓我們繼續看seal_pre_commit_phase1中的compound_public_params參數,這里實際上set_up的時候,將compound_setup_params參數的值賦予進去,并增加了一個至關重要的vanilla_params.graph字段,就是構造出來的圖的數據結構

??接下來我們可以看到seal_pre_commit_phase1方法的70行,在這一段代碼用于生成markletree和comm_d

????let?(config,?comm_d)?=?measure_op(Operation::CommD,?||?->?Result<_>?{

????????let?base_tree_size?=?get_base_tree_size::<DefaultBinaryTree>(porep_config.sector_size)?;

????????let?base_tree_leafs?=?get_base_tree_leafs::<DefaultBinaryTree>(base_tree_size)?;

????????ensure!(

????????????compound_public_params.vanilla_params.graph.size()?==?base_tree_leafs,

????????????"graph?size?and?leaf?size?don't?match"

????????);

????????trace!(

????????????"seal?phase?1:?sector_size?{},?base?tree?size?{},?base?tree?leafs?{}",

????????????u64::from(porep_config.sector_size),

????????????base_tree_size,

????????????base_tree_leafs,

????????);

????????let?mut?config?=?StoreConfig::new(

????????????cache_path.as_ref(),

????????????CacheKey::CommDTree.to_string(),

????????????default_rows_to_discard(base_tree_leafs,?BINARY_ARITY),

????????);

????????//?創建默克爾樹,根據其樹根得到comm_d

????????let?data_tree?=?create_base_merkle_tree::<BinaryMerkleTree<DefaultPieceHasher>>(

????????????Some(config.clone()),

????????????base_tree_leafs,

????????????&data,

????????)?;

????????drop(data);

????????config.size?=?Some(data_tree.len());

????????let?comm_d_root:?Fr?=?data_tree.root().into();

????????let?comm_d?=?commitment_from_fr(comm_d_root);

????????drop(data_tree);

????????Ok((config,?comm_d))

????})?;

這里我們會生成treestoreconfig,然后利用config、base_tree_leafs、sealed填充數據,生成一個merkletree。得到了merkletree后就可以得到merkletree的根。再利用merkletree的根,通過commitment_from_fr算出comm_d。

生成副本id(replica_id)

當我們拿到了comm_d后,會利用verify_pieces方法驗證一下comm_d,這個就不講了,感興趣的可以自己去看代碼。

讓我們看一下副本id是如何生成的

????let?replica_id?=?generate_replica_id::<Tree::Hasher,?_>(

????????&prover_id,

????????sector_id.into(),

????????&ticket,

????????comm_d,

????????&porep_config.porep_id,

????);

利用數據本身生成得到了comm_d,這里再加上礦工id、扇區id、ticket,證明類型id。就能得到replicaid值。

///?Generate?the?replica?id?as?expected?for?Stacked?DRG.

pub?fn?generate_replica_id<H:?Hasher,?T:?AsRef<>>(

????prover_id:?&,

????sector_id:?u64,

????ticket:?&,

????comm_d:?T,

????porep_seed:?&,

)?->?H::Domain?{

????//?以鏈式方式處理輸入數據。

????let?hash?=?Sha256::new()

????????.chain_update(prover_id)

????????.chain_update(&sector_id.to_be_bytes())

????????.chain_update(ticket)

????????.chain_update(&comm_d)

????????.chain_update(porep_seed)

????????.finalize();

????bytes_into_fr_repr_safe(hash.as_ref()).into()????//通過將?le_bytes?的最重要的兩位歸零,將?32?字節的切片轉換為?Fr::Repr。

}

生成labels

接下來就是P1最后的操作:生成labels。將public_params、復制id和treestoreconfig作為參數傳入。

????pub?fn?replicate_phase1(

????????pp:?&'a?PublicParams<Tree>,

????????replica_id:?&<Tree::Hasher?as?Hasher>::Domain,

????????config:?StoreConfig,

????)?->?Result<Labels<Tree>>?{

????????info!("replicate_phase1");

????????let?labels?=?measure_op(Operation::EncodeWindowTimeAll,?||?{

????????????Self::generate_labels_for_encoding(&pp.graph,?&pp.layer_challenges,?replica_id,?config)

????????})?

????????.0;

????????Ok(labels)

????}

這里可以看到,代碼提取出了public_params的.graph字段,就是構造出來的圖的數據結構,和public_params中包含挑戰層數和最大挑戰次數的layer_challenges。

接下來看generate_labels_for_encoding。這里可以分為多核與單核進行SDR編碼,創建labels。

????pub?fn?generate_labels_for_encoding(

????????graph:?&StackedBucketGraph<Tree::Hasher>,

????????layer_challenges:?&LayerChallenges,

????????replica_id:?&<Tree::Hasher?as?Hasher>::Domain,

????????config:?StoreConfig,

????)?->?Result<(Labels<Tree>,?Vec<LayerState>)>?{

????????let?mut?parent_cache?=?graph.parent_cache()?;

????????#

????????{

????????????if?SETTINGS.use_multicore_sdr?{

????????????????info!("multi?core?replication");

????????????????create_label::multi::create_labels_for_encoding(

????????????????????graph,

????????????????????&parent_cache,

????????????????????layer_challenges.layers(),

????????????????????replica_id,

????????????????????config,

????????????????)

????????????}?else?{

????????????????info!("single?core?replication");

????????????????create_label::single::create_labels_for_encoding(

????????????????????graph,

????????????????????&mut?parent_cache,

????????????????????layer_challenges.layers(),

????????????????????replica_id,

????????????????????config,

????????????????)

????????????}

????????}

????????#

????????{

????????????info!("single?core?replication");

????????????create_label::single::create_labels_for_encoding(

????????????????graph,

????????????????&mut?parent_cache,

????????????????layer_challenges.layers(),

????????????????replica_id,

????????????????config,

????????????)

????????}

????}

我將生成label的地址放在這里,想看的可以去看一下,這里就不細講了。

多核:https://github.com/filecoin-project/rust-fil-proofs/blob/master/storage-proofs-porep/src/stacked/vanilla/create_label/multi.rs

單核:https://github.com/filecoin-project/rust-fil-proofs/blob/master/storage-proofs-porep/src/stacked/vanilla/create_label/single.rs

三、總結

其實rust語言我接觸不多,開始的時候看得有點頭痛,最后也是硬著頭皮啃下來的。

如有大佬認為文章有不對的地方,歡迎糾正。

來源:金色財經

Tags:COMTORECTATHYearn Compounding veCRV yVaultTORII幣Electroneromathwallets

Uniswap
大盤進入三角震蕩收斂末端變盤在即 反彈繼續空?_CORD

愈是害怕失去的人,愈容易失去。愈想得到,愈要放手。放手是很難,卻別無選擇。命運不是放棄,而是努力.

1900/1/1 0:00:00
Sin7y團隊解讀:關于Sinsemilla哈希函數在OlaVM中的應用_ESI

很高興,我們在2022年7月25日發布了OlaVM,一個EVM兼容的ZKVM方案。由于ZKEVM本身一直是個熱門的賽道,所以OlaVM一經發布,就很榮幸的受到了行業內大佬們的一些關注.

1900/1/1 0:00:00
小神:恭喜 昨日布局的ETH的2單多單 完美止盈獲利_ETH

盈利提示: 1.文章專欄ETH多單止盈40多點2.直播ETH多單止盈60多點,雙盈利 文章布局: 昨早ETH給出的操作建議是:建議ETH在1300-1320可以分批直接布局多單.

1900/1/1 0:00:00
金色觀察 | 排行前五的web3風投公司2022年都投了什么_OIN

本文為GlobalCoinResearch近日出品的前十大web3風險投資公司的上半部分。GlobalCoinResearch對十大web3風險投資公司和更廣泛的行業活動進行全面和最新的分析——.

1900/1/1 0:00:00
誰能成為下一個以太坊、四大投資選擇 !_FLUX

當VitalikButerin提議將區塊鏈技術用于支持去中心化應用程序而不僅僅是金融時,它標志著加密行業的一場革命。隨著以太坊作為一個平臺開始被采用,$ETH成為高價$BTC的可靠替代品.

1900/1/1 0:00:00
「可以上屏的數字藝術」 酷天下聯手文昌鏈開啟加密藝術品新形態_IDO

近日,BSN文昌鏈與酷天下數字科技有限公司正式達成合作。基于邊界智能的先進區塊鏈技術、多鏈跨鏈體系運營能力和豐富生態,以及酷天下獨有的加密數字屏技術,合作雙方將共同探索「智能硬件+數字藝術品投屏.

1900/1/1 0:00:00
ads