filecoin技術(shù)架構(gòu)分析之十二:filecoin源碼分析之內(nèi)部接口層plumbing&porcelain接口

本文作者:楊尉;原創(chuàng)作品茸俭,轉(zhuǎn)載請注明出處

[上一篇鏈接] filecoin技術(shù)架構(gòu)分析之十一:filecoin源碼分析之內(nèi)部接口層api包分析

[下一篇鏈接] filecoin技術(shù)架構(gòu)分析之十三:filecoin源碼分析之服務(wù)層actor及vm

目錄

  • 12.filecoin源碼分析之內(nèi)部接口層plumbing&porcelain接口
    • 12.1 說明
    • 12.2 plumbing&porcelain模式簡述
    • 12.3 plumbing底層接口
    • 12.4 porcelain高層接口

12.1 說明

  • 目前官方正在將api包解耦有梆,往plumbing报强、porcelain中遷移

    • 緣由: 原來的api包懒鉴,依賴于node包犬性,而node包應(yīng)該屬于api之上的瞻离,這導(dǎo)致代碼耦合性大
    • node作為一個(gè)上帝對象,被api包依賴乒裆,對架構(gòu)擴(kuò)展性套利,其他類型節(jié)點(diǎn)擴(kuò)展開發(fā)不利
    • 就在筆者寫這篇文章的同時(shí),官方應(yīng)該還在繼續(xù)遷移鹤耍,后面api包會逐步都遷移完
  • porcelain主要依賴于plumbing接口

  • 上一章所述的api包將會被廢除

  • 本文分析版本肉迫,go-filecoin版本:master 2c87fd59 (2019.3.7)

12.2 plumbing&porcelain模式簡述

  • 該模式是借鑒git的思路,提供兩種接口稿黄,porcelain偏高層面對用戶更加友好方便喊衫;plumbing偏底層,友好度弱于porcelain
  • porcelain是英文瓷器的意思,類似洗手盆之類杆怕;plumbing是水管裝置的意思族购,類似下水管,用戶當(dāng)然直接用洗手盆省心,不用管水管的事情
  • 用戶級更偏向用porcelain陵珍,協(xié)議級更偏向使用plumbing寝杖,

12.3 plumbing底層接口

  • 說明

    • plumbing底層接口是為實(shí)現(xiàn)協(xié)議以及面向網(wǎng)絡(luò)的必須最小實(shí)現(xiàn)
    • 更應(yīng)用級別的調(diào)用更多將會調(diào)用到porcelain高層接口
  • 提供的具體功能接口

    • 區(qū)塊狀態(tài)讀取
    • 配置信息
    • 日志
    • 消息池操作
    • 消息預(yù)覽,Gas計(jì)算
    • 消息查詢
    • 消息發(fā)送
    • 消息等待
    • 網(wǎng)絡(luò)操作
    • Chain狀態(tài)獲然ゴ俊(actor信息)
    • 錢包底層操作
  • 具體的方法如下

▼ package
    plumbing

? imports

▼+API : struct
    [fields]
   -chain : chain.ReadStore
   -config : *cfg.Config
   -logger : logging.EventLogger
   -msgPool : *core.MessagePool
   -msgPreviewer : *msg.Previewer
   -msgQueryer : *msg.Queryer
   -msgSender : *msg.Sender
   -msgWaiter : *msg.Waiter
   -network : *ntwk.Network
   -sigGetter : *mthdsig.Getter
   -wallet : *wallet.Wallet
    [methods]
   +ActorGet(ctx context.Context, addr address.Address) : *actor.Actor, error
   +ActorGetSignature(ctx context.Context, actorAddr address.Address, method string) : *exec.FunctionSignature, error
   +BlockGet(ctx context.Context, id cid.Cid) : *types.Block, error
   +ChainHead(ctx context.Context) : types.TipSet
   +ChainLs(ctx context.Context) : chan interface{}
   +ConfigGet(dottedPath string) : interface{}, error
   +ConfigSet(dottedPath string, paramJSON string) : error
   +MessagePoolGet(cid cid.Cid) : *types.SignedMessage, bool
   +MessagePoolPending() : []*types.SignedMessage
   +MessagePoolRemove(cid cid.Cid)
   +MessagePreview(ctx context.Context, from, to address.Address, method string, params ...interface{}) : types.GasUnits, error
   +MessageQuery(ctx context.Context, optFrom, to address.Address, method string, params ...interface{}) : [][]byte, *exec.FunctionSignature, error
   +MessageSend(ctx context.Context, from, to address.Address, value *types.AttoFIL, gasPrice types.AttoFIL, gasLimit types.GasUnits, method string, params ...interface{}) : cid.Cid, error
   +MessageWait(ctx context.Context, msgCid cid.Cid, cb func(*types.Block, *types.SignedMessage, *types.MessageReceipt) error) : error
   +NetworkFindProvidersAsync(ctx context.Context, key cid.Cid, count int) : chan pstore.PeerInfo
   +NetworkGetPeerID() : peer.ID
   +PubSubPublish(topic string, data []byte) : error
   +PubSubSubscribe(topic string) : pubsub.Subscription, error
   +SignBytes(data []byte, addr address.Address) : types.Signature, error
   +WalletAddresses() : []address.Address
   +WalletFind(address address.Address) : wallet.Backend, error
   +WalletNewAddress() : address.Address, error
    [functions]
   +New(deps *APIDeps) : *API

12.4 porcelain高層接口

  • 說明

    • porcelain主要依賴plumbing實(shí)現(xiàn)瑟幕。
    • 主要是面向用戶級操作
  • 提供功能

    • 獲取區(qū)塊高度
    • 建立支付通道/多支付通道
    • 獲取默認(rèn)地址
    • 消息池等待未被打包進(jìn)區(qū)塊的消息
    • 采用默認(rèn)地址發(fā)送消息
    • 獲取指定礦工報(bào)價(jià)單
    • 獲取礦工Owner地址
    • 獲取礦工節(jié)點(diǎn)ID
    • 創(chuàng)建礦工,預(yù)覽Gas消耗
    • 礦工報(bào)價(jià)留潦,預(yù)覽Gas消耗
    • 礦工報(bào)價(jià)
    • 獲取簽名支付憑證
    • 錢包余額查詢
▼ package
    porcelain

? imports

▼+API : struct
    [embedded]
   +*plumbing.API : *plumbing.API
    [methods]
   +ChainBlockHeight(ctx context.Context) : *types.BlockHeight, error
   +CreatePayments(ctx context.Context, config CreatePaymentsParams) : *CreatePaymentsReturn, error
   +GetAndMaybeSetDefaultSenderAddress() : address.Address, error
   +MessagePoolWait(ctx context.Context, messageCount uint) : []*types.SignedMessage, error
   +MessageSendWithDefaultAddress(ctx context.Context, from, to address.Address, value *types.AttoFIL, gasPrice types.AttoFIL, gasLimit types.GasUnits, method string, params ...interface{}) : cid.Cid, error
   +MinerGetAsk(ctx context.Context, minerAddr address.Address, askID uint64) : minerActor.Ask, error
   +MinerGetOwnerAddress(ctx context.Context, minerAddr address.Address) : address.Address, error
   +MinerGetPeerID(ctx context.Context, minerAddr address.Address) : peer.ID, error
   +MinerPreviewCreate(ctx context.Context, fromAddr address.Address, pledge uint64, pid peer.ID, collateral *types.AttoFIL) : types.GasUnits, error
   +MinerPreviewSetPrice(ctx context.Context, from address.Address, miner address.Address, price *types.AttoFIL, expiry *big.Int) : types.GasUnits, error
   +MinerSetPrice(ctx context.Context, from address.Address, miner address.Address, gasPrice types.AttoFIL, gasLimit types.GasUnits, price *types.AttoFIL, expiry *big.Int) : MinerSetPriceResponse, error
   +PaymentChannelLs(ctx context.Context, fromAddr address.Address, payerAddr address.Address) : map[string]*paymentbroker.PaymentChannel, error
   +PaymentChannelVoucher(ctx context.Context, fromAddr address.Address, channel *types.ChannelID, amount *types.AttoFIL, validAt *types.BlockHeight) : *paymentbroker.PaymentVoucher, error
   +WalletBalance(ctx context.Context, address address.Address) : *types.AttoFIL, error
    [functions]
   +New(plumbing *plumbing.API) : *API

[上一篇鏈接] filecoin技術(shù)架構(gòu)分析之十一:filecoin源碼分析之內(nèi)部接口層api包分析

[下一篇鏈接] filecoin技術(shù)架構(gòu)分析之十三:filecoin源碼分析之服務(wù)層actor及vm

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末只盹,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子兔院,更是在濱河造成了極大的恐慌鹿霸,老刑警劉巖,帶你破解...
    沈念sama閱讀 219,188評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件秆乳,死亡現(xiàn)場離奇詭異懦鼠,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)屹堰,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,464評論 3 395
  • 文/潘曉璐 我一進(jìn)店門肛冶,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人扯键,你說我怎么就攤上這事睦袖。” “怎么了荣刑?”我有些...
    開封第一講書人閱讀 165,562評論 0 356
  • 文/不壞的土叔 我叫張陵馅笙,是天一觀的道長伦乔。 經(jīng)常有香客問我,道長董习,這世上最難降的妖魔是什么烈和? 我笑而不...
    開封第一講書人閱讀 58,893評論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮皿淋,結(jié)果婚禮上招刹,老公的妹妹穿的比我還像新娘。我一直安慰自己窝趣,他們只是感情好疯暑,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,917評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著哑舒,像睡著了一般妇拯。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上洗鸵,一...
    開封第一講書人閱讀 51,708評論 1 305
  • 那天越锈,我揣著相機(jī)與錄音,去河邊找鬼预麸。 笑死,一個(gè)胖子當(dāng)著我的面吹牛儒将,可吹牛的內(nèi)容都是我干的吏祸。 我是一名探鬼主播,決...
    沈念sama閱讀 40,430評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼钩蚊,長吁一口氣:“原來是場噩夢啊……” “哼贡翘!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起砰逻,我...
    開封第一講書人閱讀 39,342評論 0 276
  • 序言:老撾萬榮一對情侶失蹤鸣驱,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后蝠咆,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體踊东,經(jīng)...
    沈念sama閱讀 45,801評論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,976評論 3 337
  • 正文 我和宋清朗相戀三年刚操,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了闸翅。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,115評論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡菊霜,死狀恐怖坚冀,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情鉴逞,我是刑警寧澤记某,帶...
    沈念sama閱讀 35,804評論 5 346
  • 正文 年R本政府宣布司训,位于F島的核電站,受9級特大地震影響液南,放射性物質(zhì)發(fā)生泄漏壳猜。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,458評論 3 331
  • 文/蒙蒙 一贺拣、第九天 我趴在偏房一處隱蔽的房頂上張望蓖谢。 院中可真熱鬧,春花似錦譬涡、人聲如沸闪幽。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,008評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽盯腌。三九已至,卻和暖如春陨瘩,著一層夾襖步出監(jiān)牢的瞬間腕够,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,135評論 1 272
  • 我被黑心中介騙來泰國打工舌劳, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留帚湘,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,365評論 3 373
  • 正文 我出身青樓甚淡,卻偏偏與公主長得像大诸,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個(gè)殘疾皇子贯卦,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,055評論 2 355

推薦閱讀更多精彩內(nèi)容