Documentation
¶
Index ¶
- Variables
- func FmtNsID(sqlTemplate, namespaceID string) string
- func NewDatabasePool(ctx context.Context, config *DatabaseConfig) (*pgxpool.Pool, error)
- func TableName(nsID string) string
- type Config
- type DatabaseConfig
- type DatabaseTestEnv
- func (env *DatabaseTestEnv) CountAlternateStatus(t *testing.T, status protoblocktx.Status) int
- func (env *DatabaseTestEnv) CountStatus(t *testing.T, status protoblocktx.Status) int
- func (env *DatabaseTestEnv) FetchKeys(t *testing.T, nsID string, keys [][]byte) map[string]*ValueVersion
- func (env *DatabaseTestEnv) StatusExistsForNonDuplicateTxID(t *testing.T, expectedStatuses map[string]*protoblocktx.StatusWithHeight)
- func (env *DatabaseTestEnv) StatusExistsWithDifferentHeightForDuplicateTxID(t *testing.T, expectedStatuses map[string]*protoblocktx.StatusWithHeight)
- type Limits
- type ResourceLimitsConfig
- type TxID
- type ValidatorAndCommitterServiceTestEnv
- type ValidatorCommitterService
- func (vc *ValidatorCommitterService) Close()
- func (vc *ValidatorCommitterService) GetConfigTransaction(ctx context.Context, _ *emptypb.Empty) (*protoblocktx.ConfigTransaction, error)
- func (vc *ValidatorCommitterService) GetLastCommittedBlockNumber(ctx context.Context, _ *emptypb.Empty) (*protoblocktx.LastCommittedBlock, error)
- func (vc *ValidatorCommitterService) GetNamespacePolicies(ctx context.Context, _ *emptypb.Empty) (*protoblocktx.NamespacePolicies, error)
- func (vc *ValidatorCommitterService) GetTransactionsStatus(ctx context.Context, query *protoblocktx.QueryStatus) (*protoblocktx.TransactionsStatus, error)
- func (vc *ValidatorCommitterService) RegisterService(server *grpc.Server)
- func (vc *ValidatorCommitterService) Run(ctx context.Context) error
- func (vc *ValidatorCommitterService) SetLastCommittedBlockNumber(ctx context.Context, lastCommittedBlock *protoblocktx.BlockInfo) (*emptypb.Empty, error)
- func (vc *ValidatorCommitterService) SetupSystemTablesAndNamespaces(ctx context.Context, _ *emptypb.Empty) (*emptypb.Empty, error)
- func (vc *ValidatorCommitterService) StartValidateAndCommitStream(...) error
- func (*ValidatorCommitterService) WaitForReady(context.Context) bool
- type ValueVersion
Constants ¶
This section is empty.
Variables ¶
var ErrMetadataEmpty = errors.New("metadata value is empty")
ErrMetadataEmpty indicates that a requested metadata value is empty or not found.
Functions ¶
func FmtNsID ¶ added in v0.1.4
FmtNsID replaces the namespace placeholder with the namespace ID in an SQL template string.
func NewDatabasePool ¶
NewDatabasePool creates a new pool from a database config.
Types ¶
type Config ¶
type Config struct {
Server *connection.ServerConfig `mapstructure:"server"`
Database *DatabaseConfig `mapstructure:"database"`
ResourceLimits *ResourceLimitsConfig `mapstructure:"resource-limits"`
Monitoring monitoring.Config `mapstructure:"monitoring"`
}
Config is the configuration for the validator-committer service.
type DatabaseConfig ¶
type DatabaseConfig struct {
Endpoints []*connection.Endpoint `mapstructure:"endpoints"`
Username string `mapstructure:"username"`
Password string `mapstructure:"password"`
Database string `mapstructure:"database"`
MaxConnections int32 `mapstructure:"max-connections"`
MinConnections int32 `mapstructure:"min-connections"`
LoadBalance bool `mapstructure:"load-balance"`
Retry *connection.RetryProfile `mapstructure:"retry"`
}
DatabaseConfig is the configuration for the database.
func (*DatabaseConfig) DataSourceName ¶
func (d *DatabaseConfig) DataSourceName() string
DataSourceName returns the data source name of the database.
func (*DatabaseConfig) EndpointsString ¶
func (d *DatabaseConfig) EndpointsString() string
EndpointsString returns the address:port as a string with comma as a separator between endpoints.
type DatabaseTestEnv ¶
type DatabaseTestEnv struct {
DB *database
DBConf *DatabaseConfig
}
DatabaseTestEnv represents a database test environment.
func NewDatabaseTestEnv ¶
func NewDatabaseTestEnv(t *testing.T) *DatabaseTestEnv
NewDatabaseTestEnv creates a new default database test environment.
func NewDatabaseTestEnvWithCluster ¶
func NewDatabaseTestEnvWithCluster(t *testing.T, dbConnections *dbtest.Connection) *DatabaseTestEnv
NewDatabaseTestEnvWithCluster creates a new db cluster test environment.
func (*DatabaseTestEnv) CountAlternateStatus ¶
func (env *DatabaseTestEnv) CountAlternateStatus(t *testing.T, status protoblocktx.Status) int
CountAlternateStatus returns the number of transactions not with a given tx status.
func (*DatabaseTestEnv) CountStatus ¶
func (env *DatabaseTestEnv) CountStatus(t *testing.T, status protoblocktx.Status) int
CountStatus returns the number of transactions with a given tx status.
func (*DatabaseTestEnv) FetchKeys ¶
func (env *DatabaseTestEnv) FetchKeys(t *testing.T, nsID string, keys [][]byte) map[string]*ValueVersion
FetchKeys fetches a list of keys.
func (*DatabaseTestEnv) StatusExistsForNonDuplicateTxID ¶
func (env *DatabaseTestEnv) StatusExistsForNonDuplicateTxID( t *testing.T, expectedStatuses map[string]*protoblocktx.StatusWithHeight, )
StatusExistsForNonDuplicateTxID ensures that the given statuses and height exist for the corresponding txIDs in the tx_status table, excluding any duplicate txID statuses.
func (*DatabaseTestEnv) StatusExistsWithDifferentHeightForDuplicateTxID ¶
func (env *DatabaseTestEnv) StatusExistsWithDifferentHeightForDuplicateTxID( t *testing.T, expectedStatuses map[string]*protoblocktx.StatusWithHeight, )
StatusExistsWithDifferentHeightForDuplicateTxID ensures that the given statuses and height do not exist for corresponding txIDs in the tx_status table for duplicate txID statuses.
type Limits ¶
type Limits struct {
MaxWorkersForPreparer int
MaxWorkersForValidator int
MaxWorkersForCommitter int
}
Limits is the struct that contains the limits of the service.
type ResourceLimitsConfig ¶
type ResourceLimitsConfig struct {
MaxWorkersForPreparer int `mapstructure:"max-workers-for-preparer"`
MaxWorkersForValidator int `mapstructure:"max-workers-for-validator"`
MaxWorkersForCommitter int `mapstructure:"max-workers-for-committer"`
MinTransactionBatchSize int `mapstructure:"min-transaction-batch-size"`
TimeoutForMinTransactionBatchSize time.Duration `mapstructure:"timeout-for-min-transaction-batch-size"`
}
ResourceLimitsConfig is the configuration for the resource limits.
type ValidatorAndCommitterServiceTestEnv ¶
type ValidatorAndCommitterServiceTestEnv struct {
VCServices []*ValidatorCommitterService
DBEnv *DatabaseTestEnv
Configs []*Config
Endpoints []*connection.Endpoint
}
ValidatorAndCommitterServiceTestEnv denotes the test environment for vcservice.
func NewValidatorAndCommitServiceTestEnv ¶
func NewValidatorAndCommitServiceTestEnv( t *testing.T, numServices int, db ...*DatabaseTestEnv, ) *ValidatorAndCommitterServiceTestEnv
NewValidatorAndCommitServiceTestEnv creates a new test environment with a vcservice and a database.
func (*ValidatorAndCommitterServiceTestEnv) GetDBEnv ¶
func (vcEnv *ValidatorAndCommitterServiceTestEnv) GetDBEnv() *DatabaseTestEnv
GetDBEnv returns the database test environment.
func (*ValidatorAndCommitterServiceTestEnv) SetupSystemTablesAndNamespaces ¶
func (vcEnv *ValidatorAndCommitterServiceTestEnv) SetupSystemTablesAndNamespaces(ctx context.Context, t *testing.T)
SetupSystemTablesAndNamespaces creates the required system tables and namespaces.
type ValidatorCommitterService ¶
type ValidatorCommitterService struct {
protovcservice.UnimplementedValidationAndCommitServiceServer
// contains filtered or unexported fields
}
ValidatorCommitterService is the service that receives transactions from the client, prepares them, validates them and commits them to the database. It is composed of a preparer, a validator and a committer. The preparer receives transactions from the client and prepares them for validation. The validator receives prepared transactions from the preparer and validates them. The committer receives validated transactions from the validator and commits them to the database. The service also sends the status of the transactions to the client. ValidatorCommitterService is a gRPC service that implements the ValidationAndCommitService interface.
func NewValidatorCommitterService ¶
func NewValidatorCommitterService( ctx context.Context, config *Config, ) (*ValidatorCommitterService, error)
NewValidatorCommitterService creates a new ValidatorCommitterService. It creates the preparer, the validator and the committer. It also creates the channels that are used to communicate between the preparer, the validator and the committer. It also creates the database connection.
func (*ValidatorCommitterService) Close ¶
func (vc *ValidatorCommitterService) Close()
Close is closing the db connection.
func (*ValidatorCommitterService) GetConfigTransaction ¶
func (vc *ValidatorCommitterService) GetConfigTransaction( ctx context.Context, _ *emptypb.Empty, ) (*protoblocktx.ConfigTransaction, error)
GetConfigTransaction retrieves the config block from the database.
func (*ValidatorCommitterService) GetLastCommittedBlockNumber ¶
func (vc *ValidatorCommitterService) GetLastCommittedBlockNumber( ctx context.Context, _ *emptypb.Empty, ) (*protoblocktx.LastCommittedBlock, error)
GetLastCommittedBlockNumber get the last committed block number in the database/ledger.
func (*ValidatorCommitterService) GetNamespacePolicies ¶
func (vc *ValidatorCommitterService) GetNamespacePolicies( ctx context.Context, _ *emptypb.Empty, ) (*protoblocktx.NamespacePolicies, error)
GetNamespacePolicies retrieves the policy data from the database.
func (*ValidatorCommitterService) GetTransactionsStatus ¶
func (vc *ValidatorCommitterService) GetTransactionsStatus( ctx context.Context, query *protoblocktx.QueryStatus, ) (*protoblocktx.TransactionsStatus, error)
GetTransactionsStatus gets the status of a given set of transaction IDs.
func (*ValidatorCommitterService) RegisterService ¶ added in v0.1.5
func (vc *ValidatorCommitterService) RegisterService(server *grpc.Server)
RegisterService registers for the validator-committer's GRPC services.
func (*ValidatorCommitterService) Run ¶
func (vc *ValidatorCommitterService) Run(ctx context.Context) error
Run starts the validator and committer service.
func (*ValidatorCommitterService) SetLastCommittedBlockNumber ¶
func (vc *ValidatorCommitterService) SetLastCommittedBlockNumber( ctx context.Context, lastCommittedBlock *protoblocktx.BlockInfo, ) (*emptypb.Empty, error)
SetLastCommittedBlockNumber set the last committed block number in the database/ledger.
func (*ValidatorCommitterService) SetupSystemTablesAndNamespaces ¶
func (vc *ValidatorCommitterService) SetupSystemTablesAndNamespaces( ctx context.Context, _ *emptypb.Empty, ) (*emptypb.Empty, error)
SetupSystemTablesAndNamespaces creates the required system tables and namespaces.
func (*ValidatorCommitterService) StartValidateAndCommitStream ¶
func (vc *ValidatorCommitterService) StartValidateAndCommitStream( stream protovcservice.ValidationAndCommitService_StartValidateAndCommitStreamServer, ) error
StartValidateAndCommitStream is the function that starts the stream between the client and the service. It receives transactions from the client, prepares them, validates them and commits them to the database. It also sends the status of the transactions to the client.
func (*ValidatorCommitterService) WaitForReady ¶
func (*ValidatorCommitterService) WaitForReady(context.Context) bool
WaitForReady wait for the service to be ready to be exposed as gRPC service. If the context ended before the service is ready, returns false.
type ValueVersion ¶
ValueVersion contains a list of values and their matching versions.