Documentation
¶
Index ¶
- Constants
- Variables
- func DownloadArtifacts(ctx context.Context, dataDir string) error
- func DownloadWorkerArtifacts(ctx context.Context, dataDir string) error
- type APIService
- type CensusDownloader
- func (cd *CensusDownloader) CleanUp(census *types.Census)
- func (cd *CensusDownloader) DownloadCensus(censusInfo *types.Census) (types.HexBytes, error)
- func (cd *CensusDownloader) DownloadCensusStatus(census *types.Census) (DownloadStatus, bool)
- func (cd *CensusDownloader) OnCensusDownloaded(census *types.Census, ctx context.Context, callback func(error))
- func (cd *CensusDownloader) Start(ctx context.Context) error
- func (cd *CensusDownloader) Stop()
- type CensusDownloaderConfig
- type ContractsService
- type DownloadStatus
- type MockContracts
- func (m *MockContracts) AccountAddress() common.Address
- func (m *MockContracts) BlobsByTxHash(ctx context.Context, txHash common.Hash) ([]*types.BlobSidecar, error)
- func (m *MockContracts) CreateProcess(process *types.Process) (types.ProcessID, *common.Hash, error)
- func (m *MockContracts) FetchOnchainCensusRoot(address common.Address) (types.HexBytes, error)
- func (m *MockContracts) MockStateRootChange(_ context.Context, process *types.ProcessWithChanges) error
- func (m *MockContracts) MonitorProcessChanges(ctx context.Context, interval time.Duration, retries int, ...) (<-chan *types.ProcessWithChanges, error)
- func (m *MockContracts) MonitorProcessCreation(ctx context.Context, interval time.Duration) (<-chan *types.Process, error)
- func (m *MockContracts) Process(processID types.ProcessID) (*types.Process, error)
- func (m *MockContracts) ProcessChangesFilters() []types.Web3FilterFn
- func (m *MockContracts) RegisterKnownProcess(processID types.ProcessID)
- func (m *MockContracts) SendBlobTx(blob []byte) common.Hash
- func (m *MockContracts) WaitTxByHash(hash common.Hash, timeout time.Duration, cb ...func(error)) error
- func (m *MockContracts) WaitTxByID(id []byte, timeout time.Duration, cb ...func(error)) error
- type OnchainCensusFetcher
- type ProcessMonitor
- type SequencerService
- type StateSync
Constants ¶
const (
// SequencerStatsEndpoint is the API endpoint for retrieving sequencer statistics.
SequencerStatsEndpoint = "/sequencer/stats"
)
Variables ¶
var DefaultCensusDownloaderConfig = CensusDownloaderConfig{ CleanUpInterval: time.Second * 5, OnchainCheckInterval: time.Second * 5, Attempts: 5, AttemptTimeout: 30 * time.Second, Expiration: time.Minute * 2, Cooldown: time.Second * 5, ConcurrentDownloads: 4, }
DefaultCensusDownloaderConfig provides default values for the CensusDownloaderConfig.
var StatsMonitorInterval = 60 * time.Second
StatsMonitorInterval is the interval at which process statistics are logged. This can be overridden before starting the service.
Functions ¶
func DownloadArtifacts ¶
DownloadArtifacts downloads all the circuit artifacts concurrently.
Types ¶
type APIService ¶
APIService represents a service that manages the HTTP API server.
func NewAPI ¶
func NewAPI( storage *storage.Storage, host string, port int, network string, web3Config config.DavinciWeb3Config, pinataConfig metadata.PinataMetadataProviderConfig, disableLogging bool, ) *APIService
NewAPI creates a new APIService instance.
func (*APIService) SetWorkerConfig ¶
func (as *APIService) SetWorkerConfig(seed string, tokenExpiration, timeout time.Duration, banRules *workers.WorkerBanRules)
SetWorkerConfig configures the worker settings for the API service.
type CensusDownloader ¶
type CensusDownloader struct {
// contains filtered or unexported fields
}
CensusDownloader is responsible for downloading and importing censuses asynchronously. It maintains a queue of censuses to download and tracks the status of each download attempt.
func NewCensusDownloader ¶
func NewCensusDownloader( onchainFetcher OnchainCensusFetcher, stg *storage.Storage, config CensusDownloaderConfig, ) *CensusDownloader
NewCensusDownloader creates a new CensusDownloader instance with the given ContractsService, Storage, and configuration.
func (*CensusDownloader) CleanUp ¶ added in v0.0.2
func (cd *CensusDownloader) CleanUp(census *types.Census)
CleanUp is a thread-safe wrapper around cleanUpStatusUnsafe that locks the mutex before calling the unsafe version to remove a census status from the internal tracking map based on the given census root.
func (*CensusDownloader) DownloadCensus ¶
DownloadCensus adds the specified census to the download queue for asynchronous processing. It handles on-chain dynamic Merkle Tree censuses by fetching the current root from the on-chain contract before adding it to the queue. It returns the final census root (after any necessary updates) and an error if the operation fails.
func (*CensusDownloader) DownloadCensusStatus ¶
func (cd *CensusDownloader) DownloadCensusStatus(census *types.Census) (DownloadStatus, bool)
DownloadCensusStatus retrieves the current download status of the specified census. It returns the DownloadStatus and a boolean indicating whether the census is found in the pending list.
func (*CensusDownloader) OnCensusDownloaded ¶
func (cd *CensusDownloader) OnCensusDownloaded(census *types.Census, ctx context.Context, callback func(error))
OnCensusDownloaded registers a callback function that will be called when the specified census has been downloaded and imported. The callback will be called with an error if the download or import failed, or nil if it succeeded. It allows to wait asynchronously for a census to be ready, and then execute custom logic based on the result.
func (*CensusDownloader) Start ¶
func (cd *CensusDownloader) Start(ctx context.Context) error
Start begins the CensusDownloader's processing loop. It listens for new censuses to download from the DownloadQueue channel and processes them asynchronously. If the context is canceled, the downloader stops processing.
func (*CensusDownloader) Stop ¶
func (cd *CensusDownloader) Stop()
Stop stops the CensusDownloader's processing loop by canceling its context.
type CensusDownloaderConfig ¶
type CensusDownloaderConfig struct {
CleanUpInterval time.Duration
OnchainCheckInterval time.Duration
Expiration time.Duration
Cooldown time.Duration
AttemptTimeout time.Duration
Attempts int
ConcurrentDownloads int
}
CensusDownloaderConfig holds the configuration for the CensusDownloader. It includes:
- CleanUpInterval: time duration between cleanup checks for pending censuses.
- Expiration: time duration after which a pending census is considered expired (completed or failed).
- Cooldown: time duration to wait before retrying a failed census download.
- AttemptTimeout: maximum time allowed for a single download/import attempt.
- Attempts: maximum number of attempts to download and import a census.
type ContractsService ¶
type ContractsService interface {
OnchainCensusFetcher
MonitorProcessCreation(ctx context.Context, interval time.Duration) (<-chan *types.Process, error)
ProcessChangesFilters() []types.Web3FilterFn
MonitorProcessChanges(ctx context.Context, interval time.Duration, retries int, filters ...types.Web3FilterFn) (<-chan *types.ProcessWithChanges, error)
CreateProcess(process *types.Process) (types.ProcessID, *common.Hash, error)
Process(processID types.ProcessID) (*types.Process, error)
RegisterKnownProcess(processID types.ProcessID)
AccountAddress() common.Address
WaitTxByHash(hash common.Hash, timeout time.Duration, cb ...func(error)) error
WaitTxByID(id []byte, timeout time.Duration, cb ...func(error)) error
BlobsByTxHash(ctx context.Context, txHash common.Hash) ([]*types.BlobSidecar, error)
}
ContractsService defines the interface for web3 contract operations.
type DownloadStatus ¶
type DownloadStatus struct {
Complete bool
Attempts int
LastErr error
Terminal bool
// contains filtered or unexported fields
}
DownloadStatus holds the status of a census download attempt. It is for internal use by the CensusDownloader.
type MockContracts ¶
type MockContracts struct {
// contains filtered or unexported fields
}
MockContracts implements a mock version of web3.Contracts for testing
func NewMockContracts ¶
func NewMockContracts() *MockContracts
func (*MockContracts) AccountAddress ¶
func (m *MockContracts) AccountAddress() common.Address
func (*MockContracts) BlobsByTxHash ¶
func (m *MockContracts) BlobsByTxHash(ctx context.Context, txHash common.Hash, ) ([]*types.BlobSidecar, error)
func (*MockContracts) CreateProcess ¶
func (*MockContracts) FetchOnchainCensusRoot ¶
func (*MockContracts) MockStateRootChange ¶
func (m *MockContracts) MockStateRootChange(_ context.Context, process *types.ProcessWithChanges) error
func (*MockContracts) MonitorProcessChanges ¶
func (m *MockContracts) MonitorProcessChanges( ctx context.Context, interval time.Duration, retries int, filters ...types.Web3FilterFn, ) (<-chan *types.ProcessWithChanges, error)
func (*MockContracts) MonitorProcessCreation ¶
func (*MockContracts) ProcessChangesFilters ¶
func (m *MockContracts) ProcessChangesFilters() []types.Web3FilterFn
func (*MockContracts) RegisterKnownProcess ¶
func (m *MockContracts) RegisterKnownProcess(processID types.ProcessID)
func (*MockContracts) SendBlobTx ¶
func (m *MockContracts) SendBlobTx(blob []byte) common.Hash
func (*MockContracts) WaitTxByHash ¶
func (*MockContracts) WaitTxByID ¶
type OnchainCensusFetcher ¶
type OnchainCensusFetcher interface {
FetchOnchainCensusRoot(address common.Address) (types.HexBytes, error)
}
OnchainCensusFetcher defines the interface for fetching on-chain census roots. It should be provided to the CensusImporter to handle dynamic on-chain Merkle Tree censuses.
type ProcessMonitor ¶
type ProcessMonitor struct {
// contains filtered or unexported fields
}
ProcessMonitor is a service that monitors new voting processes or process updates and update them in the local storage.
func NewProcessMonitor ¶
func NewProcessMonitor(contracts ContractsService, stg *storage.Storage, censusDownloader *CensusDownloader, stateSync *StateSync, interval time.Duration, ) *ProcessMonitor
NewProcessMonitor creates a new ProcessMonitor service. If storage is nil, it uses a memory storage.
type SequencerService ¶
type SequencerService struct {
Sequencer *sequencer.Sequencer
// contains filtered or unexported fields
}
SequencerService represents a service that handles background vote processing.
func NewSequencer ¶
func NewSequencer(stg *storage.Storage, contracts *web3.Contracts, batchTimeWindow time.Duration, api *api.API) *SequencerService
NewSequencer creates a new sequencer instance. It will verify new votes, aggregate them into batches, and update the ongoing state with the new ones. The batchTimeWindow defines how long a batch can wait until processed (either the batch becomes full of votes or the time window expires).
func (*SequencerService) Start ¶
func (ss *SequencerService) Start(ctx context.Context) error
Start begins the vote processing service. It returns an error if the service is already running.
func (*SequencerService) Stop ¶
func (ss *SequencerService) Stop()
Stop halts the vote processing service.
type StateSync ¶
type StateSync struct {
// contains filtered or unexported fields
}
StateSync is a service that synchronizes local state by fetching blobs from state transition notifications and applying them to the state tree.
func NewStateSync ¶
func NewStateSync( contracts ContractsService, stg *storage.Storage, ) *StateSync
NewStateSync creates a new StateSync service.
func (*StateSync) Notify ¶
func (ss *StateSync) Notify(process *types.ProcessWithChanges)
Notify triggers a state sync of the process. Returns immediately.