
rust
文章平均质量分 77
Kingwel2020
这个作者很懒,什么都没留下…
展开
-
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 · 247 阅读 · 0 评论 -
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 · 254 阅读 · 0 评论 -
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 · 357 阅读 · 0 评论 -
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 · 300 阅读 · 0 评论 -
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 · 152 阅读 · 0 评论 -
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 · 217 阅读 · 0 评论 -
Rust 学习心得<6>:再谈 Send 与 Sync
Rust 学习心得<6>:再谈 Send 与 Sync基本场景异步代码:跨越 await 问题总结Send 与 Sync 可能是Rust多线程以及异步代码种最常见到的约束。在前面一篇讨论多线程的文章中介绍过这两个约束的由来。但是,真正书写比较复杂的代码时,还是会经常遇到编译器的各种不配合。这里借用我的同事遇到的一个问题再次举例谈一谈 Send 与 Sync 的故事。基本场景C/C++中不存在Send/Sync的概念,数据对象可以任意在多线程中访问,只不过需要程序员保证线程安全,也就是所谓“加锁”。而在原创 2020-10-14 16:31:07 · 1152 阅读 · 0 评论 -
Rust 学习心得<5>:异步代码的几种写法
Rust 学习心得<5>:异步代码的几种写法原创 2020-08-16 00:25:35 · 1162 阅读 · 0 评论 -
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 · 1602 阅读 · 0 评论 -
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 · 1816 阅读 · 0 评论 -
Rust 学习心得<2>:多线程
Rust 学习心得<2>:多线程其他语言的做法Rust 做法Send,Sync 究竟是什么异步代码,协程完美了么?死锁问题现代的CPU基本都是多核结构,为了充分利用多核的能力,多线程都是绕不开的话题。无论是同步或是异步编程,与多线程相关的问题一直都是困难并且容易出错的,本质上是因为多线程程序的复杂性,特别是竞争条件的错误,使得错误发生具备一定的随机性,而随着程序的规模越来越大,解决问题的难度也随之越来越高。其他语言的做法C/C++将同步互斥,以及线程通信的问题全部交给了程序员。关键的共享资源一般需要通原创 2020-08-11 21:05:34 · 1014 阅读 · 0 评论 -
Rust 学习心得<1>:开篇
近段时间在学习研究RUST。都说RUST学习曲线陡峭。本人的感觉也是如此。之前学习GO,基本上没有专门去看语法,只是在需要的时候上网查一查,再花点时间看看大型的开源软件项目,差不多自己就会写生产级别的代码了。而RUST则不然,至少我花了差不多两周的时间专门学习语法,然而去看开源的项目依然觉得很吃力,又花了一些时间才搞明白了rust的几种编码模式,特别是异步模式,又分为poll循环的方式和await协程的方式,各种坑比较多,填坑的过程还是比较吃力的。整个大约两个多月学习过程中,曾经碰到过很多的问题,在网上阅原创 2020-08-10 22:23:38 · 1010 阅读 · 0 评论 -
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 · 322 阅读 · 0 评论 -
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 · 362 阅读 · 0 评论 -
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 · 510 阅读 · 0 评论 -
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 · 718 阅读 · 0 评论 -
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 · 328 阅读 · 0 评论 -
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 · 476 阅读 · 0 评论 -
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 · 322 阅读 · 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 · 279 阅读 · 0 评论 -
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 · 469 阅读 · 0 评论