Documentation ¶
Overview ¶
Package sync is a generated GoMock package.
Index ¶
- Constants
- Variables
- type ChangeProofRequest
- type Client
- type ClientConfig
- type Handler
- type MockClient
- func (m *MockClient) EXPECT() *MockClientMockRecorder
- func (m *MockClient) GetChangeProof(arg0 context.Context, arg1 *ChangeProofRequest, arg2 *merkledb.Database) (*merkledb.ChangeProof, error)
- func (m *MockClient) GetRangeProof(arg0 context.Context, arg1 *RangeProofRequest) (*merkledb.RangeProof, error)
- type MockClientMockRecorder
- type NetworkClient
- type NetworkServer
- func (s *NetworkServer) AppRequest(_ context.Context, nodeID ids.NodeID, requestID uint32, deadline time.Time, ...) error
- func (s *NetworkServer) HandleChangeProofRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, ...) error
- func (s *NetworkServer) HandleRangeProofRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, ...) error
- type RangeProofRequest
- type Request
- type ResponseHandler
- type StateSyncConfig
- type StateSyncManager
- type SyncMetrics
Constants ¶
const (
Version = 0 // TODO danlaine unexport this
)
Variables ¶
var ( ErrAcquiringSemaphore = errors.New("error acquiring semaphore") ErrRequestFailed = errors.New("request failed") )
var ( ErrAlreadyStarted = errors.New("cannot start a StateSyncManager that has already been started") ErrAlreadyClosed = errors.New("StateSyncManager is closed") ErrNotEnoughBytes = errors.New("less bytes read than the specified length") 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") )
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"` Limit uint16 `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) 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 *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 *ChangeProofRequest, verificationDB *merkledb.Database) (*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 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 *ChangeProofRequest, arg2 *merkledb.Database) (*merkledb.ChangeProof, error)
GetChangeProof mocks base method.
func (*MockClient) GetRangeProof ¶
func (m *MockClient) GetRangeProof(arg0 context.Context, arg1 *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 ¶
type NetworkServer ¶
type NetworkServer struct {
// contains filtered or unexported fields
}
func NewNetworkServer ¶
func (*NetworkServer) AppRequest ¶
func (s *NetworkServer) AppRequest( _ 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 *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 *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"` Limit uint16 `serialize:"true"` }
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 StateSyncManager ¶
type StateSyncManager struct {
// contains filtered or unexported fields
}
func NewStateSyncManager ¶
func NewStateSyncManager(config StateSyncConfig) (*StateSyncManager, error)
func (*StateSyncManager) Close ¶
func (m *StateSyncManager) Close()
Called when there is a fatal error or sync is complete.
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
type SyncMetrics ¶
type SyncMetrics interface { RequestFailed() RequestMade() RequestSucceeded() }
func NewMetrics ¶
func NewMetrics(namespace string, reg prometheus.Registerer) (SyncMetrics, error)