自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

区块链之路

all in Blockchain

  • 博客(51)
  • 收藏
  • 关注

原创 go libp2p kad record详解

go libp2p kad的value可用于存放任意数据,目前kad默认在value中存放了ipns和pk这两种数据(pk也是为ipns服务的,详情请阅读我的另一篇博文《ipns实现机制解读》)。RecordRecord proto:// Record represents a dht record that contains a value// for a key value pairtype Record struct { // The key that references this re

2021-04-07 15:33:57 328

原创 go ipfs namesys

namesysNameSystem interface// Namesys represents a cohesive name publishing and resolving system.//// Publishing a name is the process of establishing a mapping, a key-value// pair, according to naming rules and databases.//// Resolving a name is th

2021-04-07 14:57:26 257

原创 ipfs设计的BUG

理想ipfs宣称自己是一个基于内容寻址的去中心化存储网络,每个节点只需要存储部分数据,整个存储网络就可以运行起来。其中,内容寻址通过DHT实现,数据交换通过bitswap实现。现实简述1,每个block都需要DHT provide出去2,当文件很大时,会切割成很多个block3,DHT网络很慢,无法及时将所有block provide出去4,其它节点永远无法找到部分block详述1,在ipfs中,1个block最大为256KB,当文件超过256KB时,通过IPLD进行切割,构造出1颗Mer

2021-04-06 12:13:25 372 1

原创 Rust Option/Result 实用方法

note: Option和Result同名api的作用相似,这里只罗列出Option的api。Optionmap函数只是帮助开发者少写一些match,常用于从Option取出值,传到闭包里面执行,map的返回值是也是一个Option,包的是闭包的返回值。pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> { match self { Some(x) => Some(f(x)

2021-03-31 17:21:55 2017

原创 rust Iterator combinator

Iterator中文翻译是迭代器,顾名思义,迭代器肯定记录了当前的迭代位置。Iterator是我最喜欢的rust结构之一,因为它实现了很多方法,这些方法是可以相互组合的,大大减轻了开发者的工作量。pub trait Iterator { /// The type of the elements being iterated over. type Item; /// Advances the iterator and returns the next value. fn next(&m

2021-03-31 17:12:57 149

原创 Rust PIN思考

无栈协程有栈协程可以把任务的局部变量保存到栈上,模拟了线程的行为,用起来很自然;无栈协程需要把任务保存到线程栈或者堆里面,最好是放在堆里面。Futurepub trait Future { type Output; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>;}从Pin的定义来看,Pin的作用是获取future的可变引用,不让修改

2021-03-28 10:15:18 365

原创 go-bitswap session初步解读

在ipfs中,当你get时,blockservice首先在自己的blcokstore寻找,如果找不到,就会启动bitswap,向网络中广播wantlist,寻找block。blockServicetype blockService struct { blockstore blockstore.Blockstore exchange exchange.Interface // If checkFirst is true then first check that a block doesn't

2021-03-18 11:52:13 224

原创 libp2p-rs kad使用及调试方法

前言本文以kad-simple.rs为例,讨论如何在libp2p-rs使用kad。使用kadstep1: 创建swarm let sec = secio::Config::new(keys.clone()); let mux = yamux::Config::new(); let tu = TransportUpgrade::new(TcpConfig::default(), mux, sec); let mut swarm = Swarm::new(keys.public())

2021-01-13 17:04:52 479

原创 libp2p-rs v0.2.0发布

前言经过2个多月的开发,我们很高兴地宣布:libp2p-rs v0.2发布啦!!!v0.2主要新增Kad-DHT,这意味着现在libp2p-rs已经实现了routing host,使用者可以通过Kad-DHT查找网络中的节点,provider和value。为了更好地支持Kad-DHT,发挥libp2p-rs节点的效能,我们对swarm和tcp transport等模块进行了大量的优化。新增Kad-DHT1,引入beta值,作为迭代查询的结束条件2,迭代查询超时机制3,定时刷新路由表的机制4

2021-01-13 15:51:25 136

原创 libp2p kad 迭代查询

描述迭代查询是libp2p kad中的关键部分,kad通过迭代查询不断逼近目标,这个目标可能是peer,可能是provider,也有可能是value。过程选取K桶中距离key最近的(最多)K个节点,将这些节点的状态置为Heard;向它们发起(并行)查询(发送FIND_NODE, GET_PROVIDERS或者GET_VALUE request),得到它们K桶中距离key最近的K个节点信息,将新得到的节点状态置为Heard,并且收集起来;判断结束条件(如下),满足其中之一即可结束;否则在所有状态为

2021-01-12 17:01:59 232

原创 go ipfs provider体系

[email protected]// Provider announces blocks to the networktype Provider interface { // Run is used to begin processing the provider work Run() // Provide takes a cid and makes an attempt to announce it to the network Provide(cid.Cid

2020-12-10 19:50:01 483

原创 go libp2p kad dht

alpha: 同一时间最多只能向alpha个节点查询。现值为10beta: 迭代查询结束条件,所有非unreachable的节点按照距离排序后,前beta个节点全部都查询过即可结束。现值为3K(bucketSize): 查询开始时,从K桶中选取最多K个节点。迭代查询结束后,所有非unreachable的节点按照距离排序,向前K个节点中未查询或者正在查询的节点发起查询。现值为20...

2020-12-10 17:40:18 599

原创 在libp2p-rs上开发新协议

以floodsub为例

2020-11-13 16:07:09 213

原创 go libp2p listen

Listener interface// A Listener is a generic network listener for stream-oriented protocols.// it uses an embedded net.Listener, overriding net.Listener.Accept to// return a Conn and providing Multiaddr.type Listener interface { // Accept waits for an

2020-07-22 15:07:07 372

原创 rust future async/await

futures库是很多人学习rust异步编程的第一站,今天我将通过一个简单的hello world程序,来揭开futures的执行细节。use futures::executor;async fn hello() { println!("Hello, world!");}fn main() { let fut = hello(); executor::block_on(fut);}在hello函数打个断点,可以得出以下的调用栈:hello::hello::{{cl

2020-07-16 08:29:12 811

原创 burrow stream event

StreamEventtype StreamEvent struct { BeginBlock *BeginBlock `protobuf:"bytes,1,opt,name=BeginBlock,proto3" json:"BeginBlock,omitempty"` BeginTx *BeginTx `protobuf:

2020-06-09 15:11:41 165

原创 burrow event query

QueryMatches() is used to decide if query match tag, which we just disscuss above.type Query interface { Matches(tags Tagged) bool String() string MatchError() error}implements:EmptyEventIDPegQueryNow EventID is only used to Query For TxExecut

2020-06-09 13:32:58 150

原创 burrow event

event type// Execution event typesconst ( TypeUnknown EventType = iota TypeCall TypeLog TypeAccountInput TypeAccountOutput TypeTxExecution TypeBlockExecution TypeGovernAccount TypeBeginBlock TypeBeginTx TypeEnvelope TypeEndTx TypeEndBlock)

2020-06-09 12:19:18 215

原创 burrow event pubsub

Usage:Publish TxExecutions and blockExecution to subscriber(eg: transactor and rpcEvent) After commit state.func (exe *executor) publishBlock(blockExecution *exec.BlockExecution) { // update the numTx counter atomic.AddUint64(&exe.numBlocks, 1) f

2020-06-01 17:05:59 274

原创 cosmos sdk tx

Tx interfacecosmos-sdk/types.go/tx_msg.go// Transactions objects must fulfill the Txtype Tx interface { // Gets the all the transaction's messages. GetMsgs() []Msg // ValidateBasic does a simple and lightweight validation check that doesn't // requ

2020-05-22 17:52:08 382

原创 tendermint amino

Amino is an encoding library that can handle Interfaces. This is achieved by prefixing bytes before each “concrete type”.func Example() { defer func() { if e := recover(); e != nil { fmt.Println("Recovered:", e) } }() type Message interface{}

2020-05-21 10:47:05 249

原创 solidity智能合约简析

1,智能合约的前世今生从比特币到以太坊,从简单的脚本到图灵完备的合约,从签名,多签到合约2,simplestorage合约从simplestorage入门, 看合约layout。从remix编译和调试结果引出gas, EVM, memory, storage和calldata3,solidity和其它编程语言的不同:区块链共识的一致性特性决定了:(1)不能使用本机随机数(2)不能访问...

2020-05-07 23:01:41 1130

原创 solidity storage layout and bugs

forewordSolidity is the most populated smart contract programming languages. Storage is exclusive which differ from typical programming languages.In a typical programming language it’s not terribly ...

2020-04-29 14:43:56 280

原创 burrow consensus flow

noteburrow code version: v0.30.3Note that the blob show burrow consensus flow of single node.ABCI ApplicationBurrow use tendermint(lib) as consensus engine, which finish consensus via abci.// App...

2020-04-12 14:03:31 332

原创 burrow abi overview

This blob is focus on the generate, encode and storage of abi. If you want to know more about abi, you can refer solidity abi specabiThe chart above show the rule of abi in a process of contract in...

2020-04-09 21:59:39 230

原创 fabric2.0 orderer broadcast and deliver service

broadcastserverHandlergrpcserverStandarChannelConsensusBroadcast()Handle()loop[ wait msg ]ProcessMessage()ProcessNormalMsg() / ProcessConfigUpdateMsg()processor.WaitReady()Order() / Configure()Handle...

2020-04-02 16:13:09 700

原创 fabric2.0 cluster framework

catalog1、rpc2、commrpcOrderer will start grpc server for service and connect to gprc server of other orderer as client. That means that there are 2 connections about cluster between 2 orderers.It...

2020-04-02 11:30:53 392

原创 fabric2.0 establish a 3 raft nodes cluster that need not docker

forewordI am study orderer of fabric2.0 recently, which need at least 3 node to constitute a cluster and TLS is also mandatory.operation locationmkdir multiNodeConfigcd multiNodeConfigexport FABR...

2020-04-01 10:34:07 437

原创 fabric2.0 orderer core structure

structure chartRegistrarRegistrar is core structure of orderer, which holds all chain, consenters and ledger. It is the only entrance to operate chain.chains stores all chains;consenters store 3 ...

2020-03-27 23:02:41 230

原创 fabric2.0 raft code analyse

code version: fabric 2.0.1fabric use ectd-io/etcd as raft library, which is located in vendor, but the library only implements the Raft algorithm; both network and disk IO are left to the user. Libr...

2020-03-27 15:48:30 830

原创 run client with fabric2.0 sdk go

development envfirstmkdir -p ~/fabriccd ~/fabricexport FABRIC_CFG_PATH=$PWDcp $GOPATH/src/github.com/hyperledger/fabric/integration/chaincode $GOPATH/src/github.com/hyperledger/fabric/integratio...

2020-03-20 17:31:47 986 4

原创 让fabric 2.0 external builder在windows上跑起来

前言fabric2.0 可以使用external builder跑chaincode源码,方便chaincode调试,但是external builder编译和启动chaincode等操作使用的是4个bash脚本,而windows原生不支持bash。折腾经过一番研究(折腾),我发现只要完成以下3个步骤,即可在windows上run external chaincode。1、安装git-wi...

2020-03-20 14:14:28 543

原创 fabric2.0 chaincode handler register

code version: fabric 2.0.1registerchaincode need to register in peer before work, it start after stream is established, end with receiving REGISTERED meessage from peer. After registered, both chain...

2020-03-20 12:04:54 709

原创 How to write fabric chaincode and How it work

code version: fabric 2.0.1shim package is located in vendor/github.com/hyperledger/fabric-chaincode-go. It is a little old, we can get newer code in hyperledger/fabric-chaincode-go repo, which includ...

2020-03-18 17:16:11 185

原创 bitswap wantmanager代码解读

代码版本:[email protected]目前bitswap代码有两处用到了wantlist,一处是engine,另外一处是wantmanager。engine.ledgerMap[ID_of_other_peer].wantlist是wantlist类型,记录的是别的peer的wantlist。wantmanager.wl用于记录本节点所有session的wantli...

2020-03-09 22:34:51 338

原创 从bitswap学习使用libp2p

代码版本:[email protected]前言bitswapNetwork是bitswap的网络接口,负责bitswap的网络通信和dht调用,从bitswapNetwork可以知道bitswap是如何使用libp2p的。阅读本文,最好看过bitswap的代码以及了解libp2p中host、swarm、conn和stream的基础知识。如果没看过代码,那么看看主干,也能学到如何使用lib...

2020-03-09 18:35:23 1147

原创 fabric应用grpc解读

fabric应用grpc解读++本代码解读基于fabric v1.4.4版本++fabric proto文件主要集中在protos目录下,实现grpc服务的proto全在protos目录下,其中实现grpc服务的有:一、discovery / 服务发现discovery服务定义于discovery/protocol.proto:17,主要用于peer向cli/sdk提供查询服务,具体如下:...

2020-03-04 18:18:31 2201

原创 ipfs pubsub代码解读

Pubsub: Publish-subscribe发布订阅模式运行环境版本:[email protected] [email protected]本文运行两个节点,一个在ubuntu,另外一个在windows,下文用ipfs1代表ubuntu端的ipfs,用ipfs2代表windows端的ipfs。两个节点将彼此的地址添加到彼此的bootstrap中,形成由2个节点组成的测试网。两...

2020-03-02 10:17:26 1058

原创 ipns实现机制解读

ipns是ipfs的域名系统。

2020-03-02 10:12:15 4104

原创 go libp2p dht流程解读

运行环境版本:[email protected] [email protected]本文运行两个节点,一个在ubuntu,另外一个在windows,下文用ipfs1代表ubuntu端的ipfs,用ipfs2代表windows端的ipfs。两个节点将彼此的地址添加到彼此的bootstrap中,形成由2个节点组成的测试网。两者的peerID分别为:ipfs1: QmdvR13vcQ...

2020-03-02 09:43:34 3329 3

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除