types

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAlreadyStarted is returned if the service has already been started.
	ErrAlreadyStarted = errors.New("service is already started")

	// ErrAlreadyStopped is returned if the service has already been stopped.
	ErrAlreadyStopped = errors.New("service is already stopped")
)
View Source
var (
	// ErrThresholdExceeded is returned when the threshold of too many missed blocks in
	// a row is exceeded.
	ErrThresholdExceeded = errors.New("threshold exceeded due to too many blocks missed in a row")

	// ErrMustShutdown is returned when the current signer (rank 1) beeds to update its
	// ranks and must be shut down because rank 1 cannot be promoted anymore.
	ErrMustShutdown = errors.New("node cannot be promoted anymore, so it must be shut down")

	// ErrCounterLocked is returned when the counter for missed blocks in a row is
	// still locked due to SignCTRL not having seen a signed block from rank 1.
	ErrCounterLocked = errors.New("waiting for first commitsig from validator to unlock counter for missed blocks in a row")
)
View Source
var (
	// LogLevels defines the loglevels for SignCTRL logs.
	LogLevels = []logutils.LogLevel{"DEBUG", "INFO", "WARN", "ERR"}
)

Functions

This section is empty.

Types

type BaseService

type BaseService struct {
	Logger *SyncLogger
	// contains filtered or unexported fields
}

BaseService is a classical inheritance-style service declarations. Services can be started, and stopped. Users can override the OnStart/OnStop methods. In the absence of errors, these methods are guaranteed to be called at most once. If OnStart returns an error, service won't be marked as started, so the user can call Start again. The caller must ensure that Start and Stop are not called concurrently. It is ok to call Stop without calling Start first.

Typical usage:

type FooService struct {
	BaseService
	// private fields
}
func NewFooService() *FooService {
	fs := &FooService{
		// init
	}
	fs.BaseService = *NewBaseService(log, "FooService", fs)
	return fs
}
func (fs *FooService) OnStart() error {
	fs.BaseService.OnStart() // Always call the overridden method.
	// initialize private fields
	// start subroutines, etc.
}
func (fs *FooService) OnStop() error {
	fs.BaseService.OnStop() // Always call the overridden method.
	// close/destroy private fields
	// stop subroutines, etc.
}

func NewBaseService

func NewBaseService(logger *SyncLogger, name string, impl Service) *BaseService

NewBaseService creates a new instance of BaseService.

func (*BaseService) IsRunning

func (bs *BaseService) IsRunning() bool

IsRunning returns true or false, depending on whether the service is running or not. Implements the Service interface.

func (*BaseService) OnStart

func (bs *BaseService) OnStart() error

OnStart does nothing. This way, users don't need to call BaseService.OnStart(). Implements the Service interface.

func (*BaseService) OnStop

func (bs *BaseService) OnStop() error

OnStop does nothing. This way, users don't need to call BaseService.OnStop(). Implements the Service interface.

func (*BaseService) Quit

func (bs *BaseService) Quit() <-chan struct{}

Quit returns a quit channel. Implements the Service interface.

func (*BaseService) Start

func (bs *BaseService) Start() error

Start starts a service. An error is returned if the service is already running. Implements the Service interface.

func (*BaseService) Stop

func (bs *BaseService) Stop() error

Stop stops a service and closes the quit channel. An error is returned if the service is already stopped. Implements the Service interface.

func (*BaseService) String

func (bs *BaseService) String() string

String returns a string representation of the service. Implements the Service interface.

func (*BaseService) Wait

func (bs *BaseService) Wait()

Wait blocks until the service is stopped. Implements the Service interface.

type BaseSignCtrled

type BaseSignCtrled struct {
	Logger *SyncLogger
	// contains filtered or unexported fields
}

BaseSignCtrled is a base implementation of SignCtrled.

func NewBaseSignCtrled

func NewBaseSignCtrled(logger *SyncLogger, threshold int, rank int, impl SignCtrled) *BaseSignCtrled

NewBaseSignCtrled creates a new instance of BaseSignCtrled.

func (*BaseSignCtrled) GetCurrentHeight

func (bsc *BaseSignCtrled) GetCurrentHeight() int64

GetCurrentHeight returns the validator's current height.

func (*BaseSignCtrled) GetMissedInARow

func (bsc *BaseSignCtrled) GetMissedInARow() int

GetMissedInARow returns the number of blocks missed in a row.

func (*BaseSignCtrled) GetRank

func (bsc *BaseSignCtrled) GetRank() int

GetRank returns the validators current rank.

func (*BaseSignCtrled) GetThreshold

func (bsc *BaseSignCtrled) GetThreshold() int

GetThreshold returns the threshold of blocks missed in a row that trigger a rank update.

func (*BaseSignCtrled) LockCounter

func (bsc *BaseSignCtrled) LockCounter()

LockCounter locks the counter for missed blocks in a row. This lock is crucial for mitigating the risk of double-signing on startup of the validators in the set if they are started up in incorrect order, and if a reconnect takes place.

func (*BaseSignCtrled) Missed

func (bsc *BaseSignCtrled) Missed() error

Missed updates the counter for missed blocks in a row. Errors are returned if...

1) the threshold of too many blocks missed in a row is exceeded 2) the validator's promotion fails 3) the counter for missed blocks in a row is still locked

Implements the SignCtrled interface.

func (*BaseSignCtrled) OnMissedTooMany

func (bsc *BaseSignCtrled) OnMissedTooMany()

OnMissedTooMany does nothing. This way, users don't need to call BaseSignCtrled.OnMissedTooMany(). Implements the SignCtrled interface.

func (*BaseSignCtrled) OnPromote

func (bsc *BaseSignCtrled) OnPromote()

OnPromote does nothing. This way, users don't have to call BaseSignCtrled.OnPromote(). Implements the SignCtrled interface.

func (*BaseSignCtrled) Promote

func (bsc *BaseSignCtrled) Promote() error

Promote moves the validator up one rank. An error is returned if the validator cannot be promoted anymore and it has to be shut down consequently. This method is only supposed to be called from within the Missed method and never on its own. Implements the SignCtrled interface.

func (*BaseSignCtrled) Reset

func (bsc *BaseSignCtrled) Reset()

Reset resets the counter for missed blocks in a row to 0. Implements the SignCtrled interface.

func (*BaseSignCtrled) SetCurrentHeight

func (bsc *BaseSignCtrled) SetCurrentHeight(height int64)

SetCurrentHeight sets the current height to the given value.

func (*BaseSignCtrled) SetRank

func (bsc *BaseSignCtrled) SetRank(rank int)

SetRank sets the validator's rank to the given rank.

func (*BaseSignCtrled) UnlockCounter

func (bsc *BaseSignCtrled) UnlockCounter()

UnlockCounter unlocks the counter for missed blocks in a row. This lock is crucial for mitigating the risk of double-signing on startup of the validators in the set if they are started up in incorrect order, and if a reconnect takes place.

type Gauges

type Gauges struct {
	RankGauge         prometheus.Gauge
	MissedInARowGauge prometheus.Gauge
}

Gauges wraps SignCTRL's prometheus gauges.

func RegisterGauges

func RegisterGauges() Gauges

RegisterGauges registers SignCTRL's prometheus gauges and returns them.

type Service

type Service interface {
	// Start the service.
	// An error is returned if the service is already started.
	// If OnStart() returns an error, it will also be returned by Start().
	Start() error
	OnStart() error

	// Stop the service.
	// An error is returned if the service is already stopped.
	// If OnStop() returns an error, it will also be returned by Stop().
	Stop() error
	OnStop() error

	// Return true if the service is running, and false if not.
	IsRunning() bool

	// Returns a channel which is closed once the service is stopped.
	Quit() <-chan struct{}

	// Returns a string representation of the service.
	String() string
}

Service defines a servise that can be started and stopped.

type SignCtrled

type SignCtrled interface {
	Missed() error
	OnMissedTooMany()

	Reset()

	Promote() error
	OnPromote()
}

SignCtrled defines the functionality of a SignCTRL PrivValidator that monitors the blockchain for missed blocks in a row and keeps its rank up to date.

type SyncLogger

type SyncLogger struct {
	sync.Mutex
	// contains filtered or unexported fields
}

SyncLogger wraps a standard log.Logger and makes it synchronous.

func NewSyncLogger

func NewSyncLogger(out io.Writer, prefix string, flag int) *SyncLogger

NewSyncLogger creates a new synchronous logger.

func (*SyncLogger) Debug

func (sl *SyncLogger) Debug(format string, v ...interface{})

Debug calls sl.Output to print a debug message to the logger.

func (*SyncLogger) Error

func (sl *SyncLogger) Error(format string, v ...interface{})

Error calls sl.Output to print an error message to the logger.

func (*SyncLogger) Info

func (sl *SyncLogger) Info(format string, v ...interface{})

Info calls sl.Output to print an info message to the logger.

func (*SyncLogger) SetOutput

func (sl *SyncLogger) SetOutput(w io.Writer)

SetOutput sets the output destination for the standard logger.

func (*SyncLogger) Warn

func (sl *SyncLogger) Warn(format string, v ...interface{})

Warn calls sl.Output to print a warning message to the logger.

Jump to

Keyboard shortcuts

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