Skip to content

Sync architecture

Aviv Eyal edited this page Oct 1, 2019 · 18 revisions

Sync Architecture

WARNING: This doc is outdated and needs to be updated.

Package Sync

Introduction:

a node in the spacemesh network must keep its local block database synced in order to participate in the spacemesh protocol.

the sync package contains the modules needed for keeping the local block database synchronized,

sync depends on these packages in the project:

  p2p -  interface for interacting with peers.
  mesh - struct representing the local block database.  
  protobuf - message serialization

sync protocol sequence diagram

Messages

All messages are comprised of Req and Resp couples (marked by suffix)

	message FetchBlockReq {
  		   uint32 Id;
	}

	message FetchBlockResp {
		Block block;
	}

	message LayerHashReq {
		  uint32 layer;
	}

	message LayerHashResp {
		bytes hash;
	}

	message LayerIdsReq {
		  uint32 layer;
	}

	message LayerIdsResp {
	          repeated  uint32 ids;
	}

	message Block {
		uint32 Id;
		uint32 layer;
		repeated uint32 VisibleMesh;
                    ...
	}

Public API

  • Struct Syncer
       type Syncer struct {
        Peers
        logging.Logger
        mesh.Mesh
        BlockValidator
        Configuration
        *server.MessageServer
        SyncLock  uint32
        startLock uint32
        forceSync chan bool
        exit      chan struct{}
          }
    
    API
    * func NewSync(srv server.Service, layers mesh.Mesh, bv BlockValidator, conf Configuration, log logging.Logger) *Syncer
    

All of Sync's methods.

  * Start() - this starts the service basically running a go-rutine that runs the sync when needed (timer / force sync)   

  * Close() - closes all resources related to Sync

  * ForceSync() chan bool - force a new sync

  * getLayerHashes(index mesh.LayerID) (map[string]Peer, error) - gets hash of layer block ids from each peer

  * getIdsForHash(m map[string]Peer, index mesh.LayerID) (chan mesh.BlockID, error) -gets block ids for each layer hash

  * getBlockById(id string) Block - gets a block by its id

Getting Started

Dev Guides

Product Specs

Clone this wiki locally