Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the source code analysis of StateSync.go under the Downloader module of Ethernet Square?

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces how the StateSync.go source code analysis under the Downloader module of Etay Square is, and the content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

StateSync source code analysis 1. Introduction

Statesync is a synchronous state module, the most direct connection is that the stateRoot,stateRoot in block is downloaded using the statesync module.

2. Source code analysis

At the beginning of all things, first introduce the data structure of statesync itself.

/ / stateSync schedules requests for downloading a particular state trie defined// by a given state root.// stateSync dispatches the request to download the state tree type stateSync struct {d * Downloader / / Downloader instance to access and manage current peerset combined downloader module / / scheduler sched * trie.Sync / / State trie sync scheduler defining the tasks keccak hash.Hash for a specific state root / / Keccak256 hasher to verify deliveries with / / request task queue tasks map [common.Hash] * stateTask / / Set of tasks currently queued for retrieval / / Statistical bit numUncommitted int bytesUncommitted int / / Channel for processing data correlation deliver chan * stateReq / / Delivery channel multiplexing peer responses cancel chan struct {} / / Channel to signal a termination request cancelOnce Sync.Once / / Ensures cancel only ever gets called once done chan struct {} / / Channel to signal termination completion err error / / Any error hit during sync (set before completion)}

These are the main data structures of statesync, followed by the journey of source-led analysis.

/ / 1. First, take a look at how to enable state synchronization and how to trigger state synchronization / / state synchronization thread to open: / / new method / / New creates a new downloader to fetch hashes and blocks from remote peers.func New (mode SyncMode, stateDb ethdb.Database, mux * event.TypeMux, chain BlockChain, lightchain LightChain, dropPeer peerDropFn) * Downloader {under / / downloader. After entering the stateFetcher method, go dl.stateFetcher () return dl} / / starts the rotation training channel. Wait for status synchronization task to arrive / / stateFetcher manages the active state sync and accepts requests// on its behalf.func (d * Downloader) stateFetcher () {for {select {/ / read synchronization task from d.stateSyncStart channel case s: = 0 {deliverReq = finished [0] deliverReqCh = S.deliver} select {/ / if another synchronization occurs during status synchronization Then this method returns a new stateSync object and calls the runStateSync method case next: =

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report