vc

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2025 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func FmtNsID(sqlTemplate, namespaceID string) string

FmtNsID replaces the namespace placeholder with the namespace ID in an SQL template string.

func NewDatabasePool

func NewDatabasePool(ctx context.Context, config *DatabaseConfig) (*pgxpool.Pool, error)

NewDatabasePool creates a new pool from a database config.

func TableName

func TableName(nsID string) string

TableName returns the table name for the given namespace.

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 TxID

type TxID string

TxID is the type defining the transaction identifier.

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

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

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

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

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

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

type ValueVersion struct {
	Value   []byte
	Version uint64
}

ValueVersion contains a list of values and their matching versions.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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