- 博客(101)
- 资源 (2)
- 收藏
- 关注
原创 Substrate - Execute Extrinsic
How runtime runs for a block or extrinsicImportBlockOriginated from Consensus and invoked by NetworkWorkerClient as BlockImport::ImportBlock -> prepare_block_storage_changes -> runtime_api.execute_block_with_context--------------- Enter Runtime -
2021-11-03 09:15:41
240
原创 Substrate - ImportQueue or BlockImport Pipeline
Trait/// Blocks import queue API.////// The `import_*` methods can be called in order to send elements for the import queue to verify./// Afterwards, call `poll_actions` to determine how to respond to these elements.pub trait ImportQueue<B: BlockT
2021-11-03 09:14:04
249
原创 Substrate - Babe consensus
Babe is another slote based consensus, but unlike Aura, Babe is using VRF PRNG to randomly select a validator to produce block.Babe startupCode can be found in node_cli::service.block_import: grandpaconsensus: babeimport_queue: base BasicQueue let
2021-11-03 09:12:49
349
原创 Substrate - Aura consensus
AuraAura (Authority-round) is one of the consensus in substrate.//! Aura works by having a list of authorities A who are expected to roughly//! agree on the current time. Time is divided up into discrete slots of t//! seconds each. For each slot s, the
2021-11-03 09:12:00
297
原创 Substrate - Client DB
@TOC(Client) Database in substrateClientClient -> Backend -> DatabaseBackend/// Disk backend.////// Disk backend keeps data in a key-value store. In archive mode, trie nodes are kept from all/// blocks. Otherwise, trie nodes are kept only fro
2021-10-26 17:21:42
146
原创 Substrate - node-template startup
substrate node-template initializationentry: main()cli commandslite nodefull nodeClientClient EventClient Servicesrpcnetworkentry: main()-> cli::runcli commandscli commands can be found in substrate/client/cli::sc_cli#[derive(Debug, StructOpt)]pub
2021-10-26 17:17:10
213
原创 Rust 学习心得<6>:再谈 Send 与 Sync
Rust 学习心得<6>:再谈 Send 与 Sync基本场景异步代码:跨越 await 问题总结Send 与 Sync 可能是Rust多线程以及异步代码种最常见到的约束。在前面一篇讨论多线程的文章中介绍过这两个约束的由来。但是,真正书写比较复杂的代码时,还是会经常遇到编译器的各种不配合。这里借用我的同事遇到的一个问题再次举例谈一谈 Send 与 Sync 的故事。基本场景C/C++中不存在Send/Sync的概念,数据对象可以任意在多线程中访问,只不过需要程序员保证线程安全,也就是所谓“加锁”。而在
2020-10-14 16:31:07
1131
原创 Rust 学习心得<4>:async/await 如何工作
Rust 学习心得<4>:async/await 如何工作async现在我们来看一看async/await的实现原理。async简单滴说,async语法生成一个实现 Future trait object 的对象。如下:async fn foo() -> { ...}async 关键字,将函数的原型修改为返回一个Future trait object。然后将执行的结果包装在一个新的future中返回。大致相当于:fn foo() -> impl Future<Output
2020-08-13 22:47:34
1592
原创 Rust 学习心得<3>:无栈协程
RUST 学习心得之一:无栈协程有栈协程 vs. 无栈协程GO 有栈协程RUST 协程绿色线程 GreenThread无栈协程协程解决的问题RUST作为一门新兴语言,主打系统编程。提供了多种编写代码的模式。2019年底正式推出了 async/await语法,标志着RUST也进入了协程时代。下面让我们来看一看。RUST协程和GO协程究竟有什么不同。有栈协程 vs. 无栈协程协程的需求来自于C10K问题,这里不做更多探讨。早期解决此类问题的办法是依赖于操作系统提供的I/O复用操作,也就是 epoll/IO
2020-08-12 22:26:46
1804
原创 Rust 学习心得<2>:多线程
Rust 学习心得<2>:多线程其他语言的做法Rust 做法Send,Sync 究竟是什么异步代码,协程完美了么?死锁问题现代的CPU基本都是多核结构,为了充分利用多核的能力,多线程都是绕不开的话题。无论是同步或是异步编程,与多线程相关的问题一直都是困难并且容易出错的,本质上是因为多线程程序的复杂性,特别是竞争条件的错误,使得错误发生具备一定的随机性,而随着程序的规模越来越大,解决问题的难度也随之越来越高。其他语言的做法C/C++将同步互斥,以及线程通信的问题全部交给了程序员。关键的共享资源一般需要通
2020-08-11 21:05:34
1006
原创 Rust 学习心得<1>:开篇
近段时间在学习研究RUST。都说RUST学习曲线陡峭。本人的感觉也是如此。之前学习GO,基本上没有专门去看语法,只是在需要的时候上网查一查,再花点时间看看大型的开源软件项目,差不多自己就会写生产级别的代码了。而RUST则不然,至少我花了差不多两周的时间专门学习语法,然而去看开源的项目依然觉得很吃力,又花了一些时间才搞明白了rust的几种编码模式,特别是异步模式,又分为poll循环的方式和await协程的方式,各种坑比较多,填坑的过程还是比较吃力的。整个大约两个多月学习过程中,曾经碰到过很多的问题,在网上阅
2020-08-10 22:23:38
998
原创 rust, blocking 0.4
Blocking 可以把阻塞异步代码的执行直至完成,或者阻塞的代码转为异步的模式。本身实际上是一个简单的future的 executor,大致的原理是启用一个线程池,将阻塞的代码放到线程池中执行,通过一个channel返回执行的结果。之所以要学习这个库的原因是这里提供了异步框架 executor 实现思路。库作者在 smol 这个轻量级的异步运行库实现了完整的execute功能,而 smol 实际上就是 async-std 的基础。To convert async to blocking, block
2020-07-08 19:46:21
314
原创 rust, libp2p, preliminary
rust, libp2p, preliminaryMultiaddrProtocolMultiaddrmaddr ==> "/ip4/127.0.0.1/tcp/10000"multiaddr 本质上是一个 ’Vec<u8>,因此可以支持 PartialEq, Eq, Clone, Hash。/// Representation of a Multiaddr.#[derive(PartialEq, Eq, Clone, Hash)]pub struct Multiaddr {
2020-07-08 10:19:33
355
原创 rust, smol Async I/O
rust, smol Async I/O`Aync`read_withwrite_withdropAsyncRead/AsyncWriteAsyncReadExt/AsyncWriteExtread 实现`Async` `Async` 以及其他...smol 实现同步 I/O 包装为异步操作,从而可以与 epoll 之类的操作系统异步模型集成。值得注意的是,Async IO 仅支持网络类型的操作,也就是 TCP/UDP/Unix socket。不支持普通文件类的操作。事实上,文件操作在 smol 中是通
2020-07-07 21:44:58
503
原创 rust, smol
rust, smolDependenciesCross-platform, I/O multiplexingExecutorsWork-stealing Executorsmol::runparker.park()Wake upSmol is a lightweight async I/O runtime library, which is currently support async-std as the Executor and Reactor.Dependenciesasync-task,
2020-07-07 20:08:54
708
原创 rust, future & executor
rust, future & executor一个简单的 Executor同时执行多个future的 ExecutorFuture提供Paul的方法。每次execute来轮询future,Poll方法会返回一个 Poll<> Enum,包含两种可能:Ready 或者 Pending。一个简单的 Executor一个最简单的只能执行单一future 的 executor 代码如下所示。注意这里一般创建一对 Parker和 Waker。从性能方面考虑。这样一对数据结构可以放在线程本地存
2020-07-04 11:21:09
324
原创 rust, future & generator
rust, future, how to create a futurefuture traitfn() -> impl Futureasync fn() 以及闭包async {}await探讨future的不同写法。以及其中的差异。future trait自定义实现一个 trait 特征。需要实现 poll 方法。该方法返回一个枚举值: Poll<T>, Ready 代表完成包裹了真正的返回数据;Pending 意味着任务还未完成。pub trait Future { /
2020-07-02 19:36:51
473
原创 rust, async programming
rust, async programmingThis is a collection of rust async programming resourcesThis is a collection of rust async programming resourcesThe Future With Futuresexplains the concept of async io, and shows code examples from futures to tokiowritten in 20
2020-06-23 11:18:24
316
1
原创 rust, smart pointer
rust, smart pointerBox<>Box::newRc<>Rc.newWeak<>Cell<>Cell.newCell get/setRefCell<>RefCell borrow/borrow_mutArc<>Arc::newBox<>Like unique_ptr in C++.Internally, it contains a Unqiue<> which holds the raw p
2020-06-10 22:01:09
268
原创 rust, mem alloc/free
rust, mem alloc/freeStringVec<>vec!Box<>Rc<>StringIn rust, &str is a reference to a static string which can not be altered. Instead, it could be converted to a String by to_string(), which will eventaully allocate memory from heap:
2020-06-10 15:37:32
466
原创 CosmosSDK, BaseApp and Modules
CosmosSDK, BaseApp and ModulesBaseAppABCIbeginBlocker/endBlocker/initChainerrouterrunTxAppModuleManagerABCI Call StackBeginBlockEndBlockCommitCheckTxDeliverTxThis article is about to explain how CosmosSDK works together with ABCI. Or in other words, how t
2020-05-24 17:28:49
381
原创 CosmosSDK, first application with scaffold
CosmosSDK, first application with scaffoldscaffoldGenerated CodeAppData StructureInterfacesBaseAppAppd & AppcliInit and StartStart as a remote serverStart as a in-process serverscaffoldThis tool is used to generate skeleton code for an Application bl
2020-05-23 15:22:52
839
原创 tendermint, local & remote client
tendermint, local & remote clientclientCreatorcreateAndStartProxyAppConnsmultiAppConnLocal ClientRemote ClientTendermint supports both local and remote clients. Local client means using tendermint as a library, thus we will only hvae a single os proce
2020-05-21 17:19:47
294
原创 tendermint, consensus reactor
tendermint, consensus reactorChannelMessagesOnStartPeerStateAddPeerReceiveSwitchToConsensusThe consensus reactor is the service for consensus p2p messages.Channel StateChannel = byte(0x20) DataChannel = byte(0x21) VoteChannel = byt
2020-05-21 16:50:13
218
原创 tendermint, consensus state
tendermint, consensus stateStateEventSwitchRoundStateRoundStepTypeupdateToStateStartreceiveRoutinehandleTxsAvailableenterProposehandleMsghandleTimeoutHow it works on Single NodeStateIt is the core state machine of consensus algorithm, handling votes and
2020-05-20 21:42:45
268
原创 tendermint, PEX
tendermint, PEXReactorConfigChannels & MessagesStartcrawlPeersRoutine()ensurePeersRoutine()AddPeer & RemovePeerReceivepexRequestMessagepexAddrsMessagedialPeerAddrBookInitializationStartPEX handles peer exchange, finding more peers and building the
2020-05-20 08:47:03
318
原创 tendermint, evidence
tendermint, evidenceInitializationevidenceDB and storeevPoolevPool.PendingEvidenceevPool.UpdateevPool.AddEvidenceevidence ReactorbroadcastEvidenceRoutineReceiveInitializationIn NewNode(),evidenceReactor, evidencePool, err := createEvidenceReactor(config
2020-05-19 18:23:22
213
原创 tendermint, blockchain reactor
tendermint, blockchain reactorData StructureChannelMessagesAddPeer/RemovePeerpoolRoutineBlockPoolJudgement of CaughtUpPool.requestersPool.maxPeerHeightpool.makeRequestersRoutine()bpRequesterbpRequester.requestRoutineBlockchain reactor is used to sync up t
2020-05-18 20:48:13
285
原创 tendermint, MultiplexTransport
tendermint, MultiplexTransportInterfaceImplementationUpgradeSecretConnectionIt is a TCP based multiplexed connection manager.InterfaceAbstract of making inbound/outbound connection with peer.// Transport emits and connects to Peers. The implementation
2020-05-18 09:38:05
254
原创 tendermint, switch & reactor
tendermint, switch & reactorSwitchInitializationacceptRoutine - inboundDialPeerWithAddress - outboundaddPeerReactorConsensusBlockchainPEXMempoolEvidenceThese two parts demonstrate how tendermint handles the underlying p2p and upper layer logics.The a
2020-05-17 22:13:16
298
原创 tendermint, mempool
Tendermint, MempoolMempool interfaceThe mempool pushes txs onto the proxy app.Mempool interface// Mempool defines the mempool interface.//// Updates to the mempool need to be synchronized with committing a block so// apps can reset their transient s
2020-05-16 22:32:03
615
1
原创 burrow, events
Burrow, EventsAll eventsCallLogInput & OutputGovernanceOthersAll events// Execution event typesconst ( TypeUnknown EventType = iota TypeCall TypeLog TypeAccountInput TypeAccountOutput TypeTxExecution TypeBlockExecution TypeGovernAccount Typ
2020-05-12 20:43:09
149
原创 burrow, websocket
Burrow, WebsocketConfigStartupWebsocketHandlerCall StackwsreadRoutinewriteRoutineBurrow starts RPC info service on both http and ws.Config [RPC.Info] Enabled = true ListenHost = "0.0.0.0" ListenPort = "26658"Startupfunc InfoLauncher(kern
2020-05-11 13:46:25
175
原创 burrow, validator
Burrow, ValidatorGenesisLoading ValidatorIn TendermintValidator RingRing rotationBeginBlockEndBlockTendermint ValidatorSetExampleBurrow Update ValidatorValidators are needed by tendermint core.Tende...
2020-04-28 23:31:20
248
原创 burrow, tendermint more
Burrow, Tendermint moreNewNodeBlockchainReactorv0switchToConsensusTickerv1switchToConsensusConsensusReactorStartSome more detailed analysis about tendermint in burrow.NewNodeIt is to create a tende...
2020-04-28 20:04:35
228
原创 burrow, evm, payable
Difference between payable or non-payable fallbackSolidity code: // fallback function () ?payable? external { nnn = 100; } function testA(uint a) public payable { address payable aaa = a...
2020-04-24 21:55:46
153
原创 ethereum, evm & gas cost
Tranfer to a contract addressSolidity code is like this: tranfer to itself function testA(uint a) public payable { //s1.set(3); address payable aaa = address( uint160(address(this)) ); aaa.tra...
2020-04-24 21:19:25
489
原创 burrow, EVM precompiled contracts
Burrow, EVM precompiled contractssha256 @0x02sha256 @0x02Solidity code: function testB() public { address nnn = 0x0000000000000000000000000000000000000002; nnn.call("sha256Func"); ... ...
2020-04-21 16:12:09
386
原创 burrow, tendermint
burrow, tendermintTendermint ConfigTendermint config in BurrowMapping from Burrow config to Tendermint configSome PointsBurrow is using Tendermint Core consensus engine for blockchain and P2P underly...
2020-04-14 14:38:43
164
libp2p-multistream.pcap
2020-02-24
高性能网关类产品设计原则 (数据面应该如何实现)
2020-01-09
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人