sync

package
v1.10.3-rc.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2023 License: BSD-3-Clause Imports: 32 Imported by: 5

README

TODOs

  • Handle errors on proof requests. Currently, any errors that occur server side are not sent back to the client.
  • Handle missing roots in change proofs by returning a range proof instead of failing

Documentation

Overview

Package sync is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAcquiringSemaphore = errors.New("error acquiring semaphore")
	ErrRequestFailed      = errors.New("request failed")
)
View Source
var (
	ErrAlreadyStarted             = errors.New("cannot start a StateSyncManager that has already been started")
	ErrAlreadyClosed              = errors.New("StateSyncManager is closed")
	ErrNoClientProvided           = errors.New("client is a required field of the sync config")
	ErrNoDatabaseProvided         = errors.New("sync database is a required field of the sync config")
	ErrNoLogProvided              = errors.New("log is a required field of the sync config")
	ErrZeroWorkLimit              = errors.New("simultaneous work limit must be greater than 0")
	ErrFinishedWithUnexpectedRoot = errors.New("finished syncing with an unexpected root")
)
View Source
var ErrMinProofSizeIsTooLarge = errors.New("cannot generate any proof within the requested limit")

Functions

This section is empty.

Types

type ChangeProofRequest

type ChangeProofRequest struct {
	StartingRoot ids.ID `serialize:"true"`
	EndingRoot   ids.ID `serialize:"true"`
	Start        []byte `serialize:"true"`
	End          []byte `serialize:"true"`
	KeyLimit     uint16 `serialize:"true"`
	BytesLimit   uint32 `serialize:"true"`
}

ChangeProofRequest is a request to receive trie leaves at specified Root within Start and End byte range Limit outlines maximum number of leaves to returns starting at Start

func (*ChangeProofRequest) Handle

func (r *ChangeProofRequest) Handle(ctx context.Context, nodeID ids.NodeID, requestID uint32, h Handler) error

func (ChangeProofRequest) String

func (r ChangeProofRequest) String() string

type Client

type Client interface {
	// GetRangeProof synchronously sends the given request, returning a parsed StateResponse or error
	// Note: this verifies the response including the range proof.
	GetRangeProof(ctx context.Context, request *syncpb.RangeProofRequest) (*merkledb.RangeProof, error)
	// GetChangeProof synchronously sends the given request, returning a parsed ChangesResponse or error
	// [verificationDB] is the local db that has all key/values in it for the proof's startroot within the proof's key range
	// Note: this verifies the response including the change proof.
	GetChangeProof(ctx context.Context, request *syncpb.ChangeProofRequest, verificationDB SyncableDB) (*merkledb.ChangeProof, error)
}

Client synchronously fetches data from the network to fulfill state sync requests. Repeatedly retries failed requests until the context is canceled.

func NewClient

func NewClient(config *ClientConfig) Client

type ClientConfig

type ClientConfig struct {
	NetworkClient       NetworkClient
	StateSyncNodeIDs    []ids.NodeID
	StateSyncMinVersion *version.Application
	Log                 logging.Logger
	Metrics             SyncMetrics
}

type Handler

type Handler interface {
	// contains filtered or unexported methods
}

type MockClient

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

MockClient is a mock of Client interface.

func NewMockClient

func NewMockClient(ctrl *gomock.Controller) *MockClient

NewMockClient creates a new mock instance.

func (*MockClient) EXPECT

func (m *MockClient) EXPECT() *MockClientMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockClient) GetChangeProof

func (m *MockClient) GetChangeProof(arg0 context.Context, arg1 *sync.ChangeProofRequest, arg2 SyncableDB) (*merkledb.ChangeProof, error)

GetChangeProof mocks base method.

func (*MockClient) GetRangeProof

func (m *MockClient) GetRangeProof(arg0 context.Context, arg1 *sync.RangeProofRequest) (*merkledb.RangeProof, error)

GetRangeProof mocks base method.

type MockClientMockRecorder

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

MockClientMockRecorder is the mock recorder for MockClient.

func (*MockClientMockRecorder) GetChangeProof

func (mr *MockClientMockRecorder) GetChangeProof(arg0, arg1, arg2 interface{}) *gomock.Call

GetChangeProof indicates an expected call of GetChangeProof.

func (*MockClientMockRecorder) GetRangeProof

func (mr *MockClientMockRecorder) GetRangeProof(arg0, arg1 interface{}) *gomock.Call

GetRangeProof indicates an expected call of GetRangeProof.

type NetworkClient

type NetworkClient interface {
	// RequestAny synchronously sends request to an arbitrary peer with a
	// node version greater than or equal to minVersion.
	// Returns response bytes, the ID of the chosen peer, and ErrRequestFailed if
	// the request should be retried.
	RequestAny(ctx context.Context, minVersion *version.Application, request []byte) ([]byte, ids.NodeID, error)

	// Request synchronously sends request to the selected nodeID.
	// Returns response bytes, and ErrRequestFailed if the request should be retried.
	Request(ctx context.Context, nodeID ids.NodeID, request []byte) ([]byte, error)

	// TrackBandwidth should be called for each valid response with the bandwidth
	// (length of response divided by request time), and with 0 if the response is invalid.
	TrackBandwidth(nodeID ids.NodeID, bandwidth float64)

	// The following declarations allow this interface to be embedded in the VM
	// to handle incoming responses from peers.
	AppResponse(context.Context, ids.NodeID, uint32, []byte) error
	AppRequestFailed(context.Context, ids.NodeID, uint32) error
	Connected(context.Context, ids.NodeID, *version.Application) error
	Disconnected(context.Context, ids.NodeID) error
}

NetworkClient defines ability to send request / response through the Network

func NewNetworkClient

func NewNetworkClient(
	appSender common.AppSender,
	myNodeID ids.NodeID,
	maxActiveRequests int64,
	log logging.Logger,
) NetworkClient

type NetworkServer

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

func NewNetworkServer

func NewNetworkServer(appSender common.AppSender, db SyncableDB, log logging.Logger) *NetworkServer

func (*NetworkServer) AppRequest

func (s *NetworkServer) AppRequest(
	ctx context.Context,
	nodeID ids.NodeID,
	requestID uint32,
	deadline time.Time,
	request []byte,
) error

AppRequest is called by avalanchego -> VM when there is an incoming AppRequest from a peer. Never returns errors as they are considered fatal. Sends a response back to the sender if length of response returned by the handler > 0.

func (*NetworkServer) HandleChangeProofRequest

func (s *NetworkServer) HandleChangeProofRequest(
	ctx context.Context,
	nodeID ids.NodeID,
	requestID uint32,
	req *syncpb.ChangeProofRequest,
) error

Generates a change proof and sends it to [nodeID].

func (*NetworkServer) HandleRangeProofRequest

func (s *NetworkServer) HandleRangeProofRequest(
	ctx context.Context,
	nodeID ids.NodeID,
	requestID uint32,
	req *syncpb.RangeProofRequest,
) error

Generates a range proof and sends it to [nodeID]. TODO danlaine how should we handle context cancellation?

type RangeProofRequest

type RangeProofRequest struct {
	Root       ids.ID `serialize:"true"`
	Start      []byte `serialize:"true"`
	End        []byte `serialize:"true"`
	KeyLimit   uint16 `serialize:"true"`
	BytesLimit uint32 `serialize:"true"`
}

func (*RangeProofRequest) Handle

func (r *RangeProofRequest) Handle(ctx context.Context, nodeID ids.NodeID, requestID uint32, h Handler) error

func (RangeProofRequest) String

func (r RangeProofRequest) String() string

type Request

type Request interface {
	fmt.Stringer
	Handle(ctx context.Context, nodeID ids.NodeID, requestID uint32, h Handler) error
}

A request to this node for a proof.

type ResponseHandler

type ResponseHandler interface {
	// Called when [response] is received.
	OnResponse(response []byte)
	// Called when the request failed or timed out.
	OnFailure()
}

Handles responses/failure notifications for a sent request. Exactly one of OnResponse or OnFailure is eventually called.

type StateSyncConfig

type StateSyncConfig struct {
	SyncDB                SyncableDB
	Client                Client
	SimultaneousWorkLimit int
	Log                   logging.Logger
	TargetRoot            ids.ID
}

type StateSyncManager

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

func NewStateSyncManager

func NewStateSyncManager(config StateSyncConfig) (*StateSyncManager, error)

func (*StateSyncManager) Close

func (m *StateSyncManager) Close()

Close will stop the syncing process

func (*StateSyncManager) Error

func (m *StateSyncManager) Error() error

func (*StateSyncManager) StartSyncing

func (m *StateSyncManager) StartSyncing(ctx context.Context) error

func (*StateSyncManager) UpdateSyncTarget

func (m *StateSyncManager) UpdateSyncTarget(syncTargetRoot ids.ID) error

func (*StateSyncManager) Wait

func (m *StateSyncManager) Wait(ctx context.Context) error

Wait blocks until one of the following occurs: - sync is complete. - sync fatally errored. - [ctx] is canceled. If [ctx] is canceled, returns [ctx].Err().

type SyncMetrics

type SyncMetrics interface {
	RequestFailed()
	RequestMade()
	RequestSucceeded()
}

func NewMetrics

func NewMetrics(namespace string, reg prometheus.Registerer) (SyncMetrics, error)

Jump to

Keyboard shortcuts

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