light

package
v0.0.0-...-eb06fb6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2024 License: LGPL-3.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LightProtoName protoName of Scdo service
	LightProtoName = "lightScdo"

	// LightScdoVersion version number of Scdo protocol
	LightScdoVersion uint = 1

	// MaxBlockHashRequest maximum hashes to request per message
	MaxBlockHashRequest uint64 = 1024

	// MaxBlockHeaderRequest maximum headers to request per message
	MaxBlockHeaderRequest uint64 = 256

	// MaxGapForAnnounce sends AnnounceQuery message if gap is more than this value
	MaxGapForAnnounce uint64 = 256

	// MinHashesCached minimum items cached in peer for client mode
	MinHashesCached uint64 = 256
)
View Source
const (
	// DiscHandShakeErr disconnect due to failed to shake hands in light mode
	DiscHandShakeErr = "disconnect because get error when handshaking of light mode"

	// DiscAnnounceErr disconnect due to failed to send announce message
	DiscAnnounceErr = "disconnect because send announce message err"
)

Variables

View Source
var (

	// ErrIsSynchronising indicates the synchronising  is in processing
	ErrIsSynchronising = errors.New("Is synchronising")
)

Functions

This section is empty.

Types

type AnnounceBody

type AnnounceBody struct {
	Magic           uint32
	TD              *big.Int
	CurrentBlock    common.Hash
	CurrentBlockNum uint64
	BlockNumArr     []uint64
	HeaderArr       []common.Hash
}

AnnounceBody body of AnnounceQuery response

type AnnounceQuery

type AnnounceQuery struct {
	Magic uint32
	Begin uint64
	End   uint64
}

AnnounceQuery header of AnnounceQuery request

type BlockChain

type BlockChain interface {
	GetCurrentState() (*state.Statedb, error)
	GetState(root common.Hash) (*state.Statedb, error)
	GetStateByRootAndBlockHash(root, blockHash common.Hash) (*state.Statedb, error)
	GetStore() store.BlockchainStore
	GetHeadRollbackEventManager() *event.EventManager
	CurrentHeader() *types.BlockHeader
	WriteHeader(*types.BlockHeader) error
	PutCurrentHeader(*types.BlockHeader)
	PutTd(*big.Int)
}

BlockChain define some interfaces related to underlying blockchain

type DownloadHeader

type DownloadHeader struct {
	ReqID       uint32
	HasFinished bool
	Hearders    []*types.BlockHeader
}

DownloadHeader body of DownloadHeaderQuery response

type DownloadHeaderQuery

type DownloadHeaderQuery struct {
	ReqID    uint32
	BeginNum uint64
}

DownloadHeaderQuery header of DownloadHeaderQuery request

type Downloader

type Downloader struct {
	// contains filtered or unexported fields
}

Downloader sync block chain with remote peer

func (*Downloader) Terminate

func (d *Downloader) Terminate()

Terminate close Downloader, cannot called anymore.

type HeaderHashSync

type HeaderHashSync struct {
	Magic           uint32
	TD              *big.Int
	CurrentBlock    common.Hash
	CurrentBlockNum uint64
	BeginNum        uint64
	HeaderArr       []common.Hash
}

HeaderHashSync body of HeaderHashSyncQuery response

type HeaderHashSyncQuery

type HeaderHashSyncQuery struct {
	Magic    uint32
	BeginNum uint64
}

HeaderHashSyncQuery header of HeaderHashSyncQuery request

type LightBackend

type LightBackend struct {
	// contains filtered or unexported fields
}

LightBackend represents a channel (client) that communicate with backend node service.

func NewLightBackend

func NewLightBackend(s *ServiceClient) *LightBackend

NewLightBackend creates a LightBackend

func (*LightBackend) ChainBackend

func (l *LightBackend) ChainBackend() api.Chain

ChainBackend gets instance of blockchain

func (*LightBackend) GetBlock

func (l *LightBackend) GetBlock(hash common.Hash, height int64) (*types.Block, error)

GetBlock gets a specific block through block's hash and height

func (*LightBackend) GetBlockTotalDifficulty

func (l *LightBackend) GetBlockTotalDifficulty(hash common.Hash) (*big.Int, error)

GetBlockTotalDifficulty gets total difficulty by block hash

func (*LightBackend) GetDebt

func (l *LightBackend) GetDebt(debtHash common.Hash) (*types.Debt, *api.BlockIndex, error)

GetDebt returns the debt and its index for the specified debt hash.

func (*LightBackend) GetNetVersion

func (l *LightBackend) GetNetVersion() string

GetNetVersion gets the network version

func (*LightBackend) GetNetWorkID

func (l *LightBackend) GetNetWorkID() string

GetNetWorkID gets the network id

func (*LightBackend) GetP2pServer

func (l *LightBackend) GetP2pServer() *p2p.Server

GetP2pServer gets instance of p2pServer

func (*LightBackend) GetReceiptByTxHash

func (l *LightBackend) GetReceiptByTxHash(hash common.Hash) (*types.Receipt, error)

GetReceiptByTxHash gets block's receipt by tx hash

func (*LightBackend) GetTransaction

func (l *LightBackend) GetTransaction(pool api.PoolCore, bcStore store.BlockchainStore, txHash common.Hash) (*types.Transaction, *api.BlockIndex, error)

GetTransaction gets tx, block index and its debt by tx hash

func (*LightBackend) IsSyncing

func (l *LightBackend) IsSyncing() bool

func (*LightBackend) Log

func (l *LightBackend) Log() *log.ScdoLog

Log gets instance of log

func (*LightBackend) ProtocolBackend

func (l *LightBackend) ProtocolBackend() api.Protocol

ProtocolBackend gets instance of scdoProtocol

func (*LightBackend) RemoveTransaction

func (l *LightBackend) RemoveTransaction(txHash common.Hash)

RemoveTransaction removes tx of the specified tx hash from tx pool.

func (*LightBackend) TxPoolBackend

func (l *LightBackend) TxPoolBackend() api.Pool

TxPoolBackend gets the instance of tx pool

type LightChain

type LightChain struct {
	// contains filtered or unexported fields
}

LightChain represents a canonical chain that by default only handles block headers.

func (*LightChain) CurrentHeader

func (lc *LightChain) CurrentHeader() *types.BlockHeader

CurrentHeader returns the HEAD block header of the blockchain.

func (*LightChain) GetBlockByHash

func (lc *LightChain) GetBlockByHash(hash common.Hash) *types.Block

GetHeaderByHash

func (*LightChain) GetCurrentState

func (lc *LightChain) GetCurrentState() (*state.Statedb, error)

GetCurrentState get current state

func (*LightChain) GetHeadRollbackEventManager

func (lc *LightChain) GetHeadRollbackEventManager() *event.EventManager

GetHeadRollbackEventManager

func (*LightChain) GetHeaderByHash

func (lc *LightChain) GetHeaderByHash(hash common.Hash) *types.BlockHeader

GetHeaderByNumber retrieves a block header from the database by hash.

func (*LightChain) GetHeaderByHeight

func (lc *LightChain) GetHeaderByHeight(height uint64) *types.BlockHeader

GetHeader retrieves a block header from the database by height.

func (*LightChain) GetState

func (lc *LightChain) GetState(root common.Hash) (*state.Statedb, error)

GetState get statedb by root hash(not supported, just implement the interface here)

func (*LightChain) GetStateByRootAndBlockHash

func (lc *LightChain) GetStateByRootAndBlockHash(root, blockHash common.Hash) (*state.Statedb, error)

GetStateByRootAndBlockHash get the statedb by root and block hash

func (*LightChain) GetStore

func (lc *LightChain) GetStore() store.BlockchainStore

GetStore get underlying store

func (*LightChain) PutCurrentHeader

func (lc *LightChain) PutCurrentHeader(header *types.BlockHeader)

PutCurrentHeader

func (*LightChain) PutTd

func (lc *LightChain) PutTd(td *big.Int)

PutTd set light chain canonial total difficulty

func (*LightChain) WriteHeader

func (lc *LightChain) WriteHeader(header *types.BlockHeader) error

WriteHeader writes the specified block header to the blockchain.

type LightProtocol

type LightProtocol struct {
	p2p.Protocol
	// contains filtered or unexported fields
}

LightProtocol service implementation of scdo

func NewLightProtocol

func NewLightProtocol(networkID string, txPool TransactionPool, debtPool *core.DebtPool, chain BlockChain, serverMode bool, odrBackend *odrBackend,
	log *log.ScdoLog, shard uint) (s *LightProtocol, err error)

NewLightProtocol create LightProtocol

func (*LightProtocol) GetProtocolVersion

func (lp *LightProtocol) GetProtocolVersion() (uint, error)

GetProtocolVersion gets protocol version

func (*LightProtocol) SendDifferentShardTx

func (lp *LightProtocol) SendDifferentShardTx(tx *types.Transaction, shard uint)

SendDifferentShardTx send tx to another shard

func (*LightProtocol) Start

func (lp *LightProtocol) Start()

Start starts data syncer

func (*LightProtocol) Stop

func (lp *LightProtocol) Stop()

Stop stops protocol, called when scdoService quits.

type OdrItem

type OdrItem struct {
	ReqID uint32 // random request ID that generated dynamically
	Error string // response error
}

OdrItem is base struct for ODR request and response.

type OdrProvableResponse

type OdrProvableResponse struct {
	OdrItem
	BlockIndex *api.BlockIndex `rlp:"nil"`
	Proof      []proofNode
}

OdrProvableResponse represents all provable ODR response.

type PeerInfo

type PeerInfo struct {
	Version    uint     `json:"version"`    // Scdo protocol version negotiated
	Difficulty *big.Int `json:"difficulty"` // Total difficulty of the peer's blockchain
	Head       string   `json:"head"`       // SHA3 hash of the peer's best owned block
}

PeerInfo represents a short summary of a connected peer.

type ServiceClient

type ServiceClient struct {
	// contains filtered or unexported fields
}

ServiceClient implements service for light mode.

func NewServiceClient

func NewServiceClient(ctx context.Context, conf *node.Config, log *log.ScdoLog, dbFolder string, shard uint, engine consensus.Engine) (s *ServiceClient, err error)

NewServiceClient create ServiceClient

func (*ServiceClient) APIs

func (s *ServiceClient) APIs() (apis []rpc.API)

APIs implements node.Service, returning the collection of RPC services the scdo package offers.

func (*ServiceClient) Protocols

func (s *ServiceClient) Protocols() (protos []p2p.Protocol)

Protocols implements node.Service, returning all the currently configured network protocols to start.

func (*ServiceClient) Start

func (s *ServiceClient) Start(srvr *p2p.Server) error

Start implements node.Service, starting goroutines needed by ServiceClient.

func (*ServiceClient) Stop

func (s *ServiceClient) Stop() error

Stop implements node.Service, terminating all internal goroutines.

type ServiceServer

type ServiceServer struct {
	// contains filtered or unexported fields
}

ServiceServer implements light server service.

func NewServiceServer

func NewServiceServer(service *scdo.ScdoService, conf *node.Config, log *log.ScdoLog, shard uint) (*ServiceServer, error)

NewServiceServer create ServiceServer

func (*ServiceServer) APIs

func (s *ServiceServer) APIs() (apis []rpc.API)

APIs implements node.Service, returning the collection of RPC services the scdo package offers.

func (*ServiceServer) Protocols

func (s *ServiceServer) Protocols() (protos []p2p.Protocol)

Protocols implements node.Service, returning all the currently configured network protocols to start.

func (*ServiceServer) Start

func (s *ServiceServer) Start(srvr *p2p.Server) error

Start implements node.Service, starting goroutines needed by ServiceServer.

func (*ServiceServer) Stop

func (s *ServiceServer) Stop() error

Stop implements node.Service, terminating all internal goroutines.

type TransactionPool

type TransactionPool interface {
	AddTransaction(tx *types.Transaction) error
	GetTransaction(txHash common.Hash) *types.Transaction
}

TransactionPool define some interfaces related to add and get txs

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL