attestation

package
v0.0.0-...-91d1ffb Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: Apache-2.0, MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LOG_FILE  = "LOG_FILE"
	LOG_LEVEL = "LOG_LEVEL"

	SERVER_PORT     = "SERVER_PORT"
	SUPPORTS_SERVER = "SUPPORTS_SERVER"

	CHECKSUM_DB_DIRECTORY  = "CHECKSUM_DB_DIRECTORY"
	MSG_INDEX_DB_DIRECTORY = "MSG_INDEX_DB_DIRECTORY"

	SUPPORTS_CHECKSUMMING = "SUPPORTS_CHECKSUMMING"
	CHECKSUM_CHUNK_SIZE   = "CHECKSUM_CHUNK_SIZE"
)

Env variables

View Source
const (
	LOG_FILE_TOML  = "log.file"
	LOG_LEVEL_TOML = "log.level"

	SERVER_PORT_TOML     = "server.port"
	SUPPORTS_SERVER_TOML = "server.on"

	CHECKSUM_DB_DIRECTORY_TOML  = "database.checksumPath"
	MSG_INDEX_DB_DIRECTORY_TOML = "database.msgIndexPath"

	SUPPORTS_CHECKSUMMING_TOML = "checksum.on"
	CHECKSUM_CHUNK_SIZE_TOML   = "checksum.chunkSize"
)

TOML bindings

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	// contains filtered or unexported fields
}

API is kind of an unnecessary abstraction since this only wraps a single backing struct, but it will make it easier to extend the API in the future (add and use new backing components)

func NewAPI

func NewAPI(repo types.ChecksumRepository) *API

NewAPI returns a new API object

func (API) ChecksumExists

func (a API) ChecksumExists(hash string, res *bool) error

ChecksumExists returns true if the given checksum is published in the backing checksum repository

func (API) GetChecksum

func (a API) GetChecksum(rng types.GetChecksumRequest, res *string) error

GetChecksum returns the checksum for the given start and stop values

type CheckSummer

type CheckSummer struct {
	// contains filtered or unexported fields
}

func NewChecksummer

func NewChecksummer(srcDir string) (*CheckSummer, error)

NewChecksummer creates a new checksumming object

func (*CheckSummer) CheckRangeIsPopulated

func (cs *CheckSummer) CheckRangeIsPopulated(start, stop uint) (bool, error)

CheckRangeIsPopulated checks if the message index table is populated for the given range

func (*CheckSummer) Checksum

func (cs *CheckSummer) Checksum(start, stop uint) (string, error)

Checksum checksums a chunk defined by the start and stop epochs (inclusive) this method assumes there are no gaps, so use the FindGaps first beforehand if we can't rely on another guarantee

func (*CheckSummer) Close

func (cs *CheckSummer) Close() error

Close implements io.Closer

func (*CheckSummer) FindGaps

func (cs *CheckSummer) FindGaps(start, stop int) ([][2]uint, error)

FindGaps finds the gaps in the message index table

type Config

type Config struct {
	// support checksumming
	Checksum bool
	// support API
	Serve bool
	// Port to expose API on
	ServerPort string
	// Directory with the source msgindex.db sqlite file
	SrcDBDir string
	// Directory with/for the checksums.db sqlite file
	RepoDBDir string
	// Chunk range size for checksumming
	ChecksumChunkSize uint
	// Whether to check for gaps in the checksum repo at initialization if the repo already exists
	CheckForGaps uint
}

Config holds the configuration params for the attestation service

func NewConfig

func NewConfig() (*Config, error)

NewConfig is used to initialize a watcher config from a .toml file Separate chain watcher instances need to be ran with separate ipfs path in order to avoid lock contention on the ipfs repository lockfile

type Repo

type Repo struct {
	// contains filtered or unexported fields
}

func NewRepo

func NewRepo(repoDir string, interval uint) (*Repo, bool, error)

NewRepo creates a new checksum repository object

func (*Repo) ChecksumExists

func (r *Repo) ChecksumExists(hash string) (bool, error)

ChecksumExists checks if the given checksum hash exists in the repository

func (*Repo) Close

func (r *Repo) Close() error

Close implements io.Closer

func (*Repo) FindGaps

func (r *Repo) FindGaps(start, stop int) ([][2]uint, error)

FindGaps finds gaps in the checksums table between start and stop (inclusive)

func (*Repo) FindNextChecksum

func (r *Repo) FindNextChecksum() (uint, error)

FindNextChecksum finds the `start` epoch for the next checksum that needs to be published

func (*Repo) GetChecksum

func (r *Repo) GetChecksum(start, stop uint) (string, error)

GetChecksum gets the checksum for the given range

func (*Repo) Interval

func (r *Repo) Interval() uint

Interval returns the checksum interval used for this repo

func (*Repo) PublishChecksum

func (r *Repo) PublishChecksum(start, stop uint, hash string) error

PublishChecksum publishes the given checksum hash for the given range

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is the attestation service top-level object

func NewService

func NewService(cs types.Checksummer, repo types.ChecksumRepository, start, chunkSize uint) (*Service, error)

NewService creates a new attestation service it accepts pre-initialized checksummer and checksum repository objects useful for testing with mocks that satisfy these interfaces

func NewServiceFromConfig

func NewServiceFromConfig(c *Config) (*Service, error)

NewServiceFromConfig creates a new attestation service from a config object

func (*Service) Checksum

func (s *Service) Checksum(ctx context.Context, wg *sync.WaitGroup) (error, <-chan error)

Checksum starts the attestation service checksumming and publishing loop

func (*Service) Close

func (s *Service) Close() error

Close implements io.Closer it shuts down any active Checksum or Serve loops

func (*Service) Register

func (s *Service) Register(reg func(any) error) error

Register registers the internal API with the provided registration function (e.g. rpc.Register)

func (*Service) Serve

func (s *Service) Serve(ctx context.Context, wg *sync.WaitGroup) error

Serve starts an empty loop that waits for a quit signal used to isolate the RPC server loop from the checksum processing loop e.g. can start this with only a checksum repository to serve the RPC API, with no active background checksummer process or can use a cancel ctx passed into `Start` to stop the checksumming processes without stopping this loop TODO: wire the API into here such that 1. users can request a (missing) checksum be calculated 2. if a request to GetChecksum is made for a range that is not yet checksummed, the checksumming process can be triggered (if the range is found to be complete in local msgindex.db)

Jump to

Keyboard shortcuts

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