blockhashstore

package
v2.8.1-mercury-20240122 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: MIT Imports: 34 Imported by: 2

Documentation

Overview

The blockhash store package provides a service that stores blockhashes such that they are available for on-chain proofs beyond the EVM 256 block limit.

Index

Constants

This section is empty.

Variables

View Source
var EmptyAddress = utils.ZeroAddress.Hex()

Functions

func DecreasingBlockRange

func DecreasingBlockRange(start, end *big.Int) (ret []*big.Int, err error)

DecreasingBlockRange creates a contiguous block range starting with block `start` (inclusive) and ending at block `end` (inclusive).

func GetSearchWindow

func GetSearchWindow(latestBlock, waitBlocks, lookbackBlocks int) (uint64, uint64)

GetSearchWindow returns the search window (fromBlock, toBlock) given the latest block number, wait blocks and lookback blocks

func GetUnfulfilledBlocksAndRequests

func GetUnfulfilledBlocksAndRequests(
	ctx context.Context,
	lggr logger.Logger,
	coordinator Coordinator,
	fromBlock, toBlock uint64,
) (map[uint64]map[string]struct{}, error)

func LimitReqIDs

func LimitReqIDs(reqs map[string]struct{}, maxLength int) []string

LimitReqIDs converts a set of request IDs to a slice limited to maxLength.

func SendingKeys

func SendingKeys(fromAddresses []ethkey.EIP55Address) []common.Address

SendingKeys returns a list of sending keys (common.Address) given EIP55 addresses

func ValidatedSpec

func ValidatedSpec(tomlString string) (job.Job, error)

ValidatedSpec validates and converts the given toml string to a job.Job.

Types

type BHS

type BHS interface {
	// Store the hash associated with blockNum.
	Store(ctx context.Context, blockNum uint64) error

	// IsStored checks whether the hash associated with blockNum is already stored.
	IsStored(ctx context.Context, blockNum uint64) (bool, error)

	// StoreEarliest stores the earliest possible blockhash (i.e. block.number - 256)
	StoreEarliest(ctx context.Context) error

	IsTrusted() bool

	StoreTrusted(ctx context.Context, blockNums []uint64, blockhashes []common.Hash, recentBlock uint64, recentBlockhash common.Hash) error
}

BHS defines an interface for interacting with a BlockhashStore contract.

type BatchBlockhashStore

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

func NewBatchBHS

func NewBatchBHS(
	config batchBHSConfig,
	fromAddresses []ethkey.EIP55Address,
	txm txmgr.TxManager,
	batchbhs batch_blockhash_store.BatchBlockhashStoreInterface,
	chainID *big.Int,
	gethks keystore.Eth,
	lggr logger.Logger,
) (*BatchBlockhashStore, error)

func (*BatchBlockhashStore) GetBlockhashes

func (b *BatchBlockhashStore) GetBlockhashes(ctx context.Context, blockNumbers []*big.Int) ([][32]byte, error)

func (*BatchBlockhashStore) StoreVerifyHeader

func (b *BatchBlockhashStore) StoreVerifyHeader(ctx context.Context, blockNumbers []*big.Int, blockHeaders [][]byte, fromAddress common.Address) error

type BulletproofBHS

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

BulletproofBHS is an implementation of BHS that writes "store" transactions to a bulletproof transaction manager, and reads BlockhashStore state from the contract.

func NewBulletproofBHS

func NewBulletproofBHS(
	config bpBHSConfig,
	dbConfig bpBHSDatabaseConfig,
	fromAddresses []ethkey.EIP55Address,
	txm txmgr.TxManager,
	bhs blockhash_store.BlockhashStoreInterface,
	trustedBHS *trusted_blockhash_store.TrustedBlockhashStore,
	chainID *big.Int,
	gethks keystore.Eth,
) (*BulletproofBHS, error)

NewBulletproofBHS creates a new instance with the given transaction manager and blockhash store.

func (*BulletproofBHS) IsStored

func (c *BulletproofBHS) IsStored(ctx context.Context, blockNum uint64) (bool, error)

IsStored satisfies the BHS interface.

func (*BulletproofBHS) IsTrusted added in v2.5.0

func (c *BulletproofBHS) IsTrusted() bool

func (*BulletproofBHS) Store

func (c *BulletproofBHS) Store(ctx context.Context, blockNum uint64) error

Store satisfies the BHS interface.

func (*BulletproofBHS) StoreEarliest

func (c *BulletproofBHS) StoreEarliest(ctx context.Context) error

func (*BulletproofBHS) StoreTrusted added in v2.5.0

func (c *BulletproofBHS) StoreTrusted(
	ctx context.Context,
	blockNums []uint64,
	blockhashes []common.Hash,
	recentBlock uint64,
	recentBlockhash common.Hash,
) error

type Coordinator

type Coordinator interface {
	// Requests fetches VRF requests that occurred within the specified blocks.
	Requests(ctx context.Context, fromBlock uint64, toBlock uint64) ([]Event, error)

	// Fulfillments fetches VRF fulfillments that occurred since the specified block.
	Fulfillments(ctx context.Context, fromBlock uint64) ([]Event, error)
}

Coordinator defines an interface for fetching request and fulfillment metadata from a VRF coordinator.

func NewMultiCoordinator

func NewMultiCoordinator(coordinators ...Coordinator) Coordinator

NewMultiCoordinator creates a new Coordinator that combines the results of the given coordinators.

type Delegate

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

Delegate creates BlockhashStore feeder jobs.

func NewDelegate

func NewDelegate(
	logger logger.Logger,
	legacyChains legacyevm.LegacyChainContainer,
	ks keystore.Eth,
) *Delegate

NewDelegate creates a new Delegate.

func (*Delegate) AfterJobCreated

func (d *Delegate) AfterJobCreated(spec job.Job)

AfterJobCreated satisfies the job.Delegate interface.

func (*Delegate) BeforeJobCreated

func (d *Delegate) BeforeJobCreated(spec job.Job)

AfterJobCreated satisfies the job.Delegate interface.

func (*Delegate) BeforeJobDeleted

func (d *Delegate) BeforeJobDeleted(spec job.Job)

AfterJobCreated satisfies the job.Delegate interface.

func (*Delegate) JobType

func (d *Delegate) JobType() job.Type

JobType satisfies the job.Delegate interface.

func (*Delegate) OnDeleteJob

func (d *Delegate) OnDeleteJob(spec job.Job, q pg.Queryer) error

OnDeleteJob satisfies the job.Delegate interface.

func (*Delegate) ServicesForSpec

func (d *Delegate) ServicesForSpec(jb job.Job) ([]job.ServiceCtx, error)

ServicesForSpec satisfies the job.Delegate interface.

type Event

type Event struct {
	// ID of the relevant VRF request. For a VRF V1 request, this will an encoded 32 byte array.
	// For VRF V2, it will be an integer in string form.
	ID string

	// Block that the request or fulfillment was included in.
	Block uint64
}

Event contains metadata about a VRF randomness request or fulfillment.

type Feeder

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

Feeder checks recent VRF coordinator events and stores any blockhashes for blocks within waitBlocks and lookbackBlocks that have unfulfilled requests.

func NewFeeder

func NewFeeder(
	logger logger.Logger,
	coordinator Coordinator,
	bhs BHS,
	lp logpoller.LogPoller,
	trustedBHSBatchSize int32,
	waitBlocks int,
	lookbackBlocks int,
	heartbeatPeriod time.Duration,
	latestBlock func(ctx context.Context) (uint64, error),
) *Feeder

NewFeeder creates a new Feeder instance.

func (*Feeder) Run

func (f *Feeder) Run(ctx context.Context) error

Run the feeder.

func (*Feeder) StartHeartbeats added in v2.6.0

func (f *Feeder) StartHeartbeats(ctx context.Context, timer Timer)

type MultiCoordinator

type MultiCoordinator []Coordinator

MultiCoordinator combines the data from multiple coordinators.

func (MultiCoordinator) Fulfillments

func (m MultiCoordinator) Fulfillments(ctx context.Context, fromBlock uint64) ([]Event, error)

Fulfillments satisfies the Coordinator interface.

func (MultiCoordinator) Requests

func (m MultiCoordinator) Requests(
	ctx context.Context,
	fromBlock uint64,
	toBlock uint64,
) ([]Event, error)

Requests satisfies the Coordinator interface.

type TestBHS

type TestBHS struct {
	Stored []uint64

	StoredEarliest bool

	// errorsStore defines which block numbers should return errors on Store.
	ErrorsStore []uint64

	// errorsIsStored defines which block numbers should return errors on IsStored.
	ErrorsIsStored []uint64
}

func (*TestBHS) IsStored

func (t *TestBHS) IsStored(_ context.Context, blockNum uint64) (bool, error)

func (*TestBHS) IsTrusted added in v2.5.0

func (t *TestBHS) IsTrusted() bool

func (*TestBHS) Store

func (t *TestBHS) Store(_ context.Context, blockNum uint64) error

func (*TestBHS) StoreEarliest

func (t *TestBHS) StoreEarliest(ctx context.Context) error

func (*TestBHS) StoreTrusted added in v2.5.0

func (t *TestBHS) StoreTrusted(
	ctx context.Context, blockNums []uint64, blockhashes []common.Hash, recentBlock uint64, recentBlockhash common.Hash,
) error

type TestBatchBHS

type TestBatchBHS struct {
	Stored                       []uint64
	GetBlockhashesCallCounter    uint16
	StoreVerifyHeaderCallCounter uint16
	GetBlockhashesError          error
	StoreVerifyHeadersError      error
}

func (*TestBatchBHS) GetBlockhashes

func (t *TestBatchBHS) GetBlockhashes(_ context.Context, blockNumbers []*big.Int) ([][32]byte, error)

func (*TestBatchBHS) StoreVerifyHeader

func (t *TestBatchBHS) StoreVerifyHeader(ctx context.Context, blockNumbers []*big.Int, blockHeaders [][]byte, fromAddress common.Address) error

type TestBlockHeaderProvider

type TestBlockHeaderProvider struct {
}

func (*TestBlockHeaderProvider) RlpHeadersBatch

func (p *TestBlockHeaderProvider) RlpHeadersBatch(ctx context.Context, blockRange []*big.Int) ([][]byte, error)

type TestCoordinator

type TestCoordinator struct {
	RequestEvents     []Event
	FulfillmentEvents []Event
}

func (*TestCoordinator) Addresses added in v2.1.0

func (t *TestCoordinator) Addresses() []common.Address

func (*TestCoordinator) Fulfillments

func (t *TestCoordinator) Fulfillments(_ context.Context, fromBlock uint64) ([]Event, error)

func (*TestCoordinator) Requests

func (t *TestCoordinator) Requests(_ context.Context, fromBlock uint64, toBlock uint64) ([]Event, error)

type Timer added in v2.6.0

type Timer interface {
	After(d time.Duration) <-chan time.Time
}

type V1Coordinator

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

V1Coordinator fetches request and fulfillment logs from a VRF V1 coordinator contract.

func NewV1Coordinator

NewV1Coordinator creates a new V1Coordinator from the given contract.

func (*V1Coordinator) Fulfillments

func (v *V1Coordinator) Fulfillments(ctx context.Context, fromBlock uint64) ([]Event, error)

Fulfillments satisfies the Coordinator interface.

func (*V1Coordinator) Requests

func (v *V1Coordinator) Requests(
	ctx context.Context,
	fromBlock uint64,
	toBlock uint64,
) ([]Event, error)

Requests satisfies the Coordinator interface.

type V2Coordinator

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

V2Coordinator fetches request and fulfillment logs from a VRF V2 coordinator contract.

func NewV2Coordinator

NewV2Coordinator creates a new V2Coordinator from the given contract.

func (*V2Coordinator) Fulfillments

func (v *V2Coordinator) Fulfillments(ctx context.Context, fromBlock uint64) ([]Event, error)

Fulfillments satisfies the Coordinator interface.

func (*V2Coordinator) Requests

func (v *V2Coordinator) Requests(
	ctx context.Context,
	fromBlock uint64,
	toBlock uint64,
) ([]Event, error)

Requests satisfies the Coordinator interface.

type V2PlusCoordinator added in v2.4.0

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

V2PlusCoordinator fetches request and fulfillment logs from a VRF V2Plus coordinator contract.

func NewV2PlusCoordinator added in v2.4.0

NewV2Coordinator creates a new V2Coordinator from the given contract.

func (*V2PlusCoordinator) Fulfillments added in v2.4.0

func (v *V2PlusCoordinator) Fulfillments(ctx context.Context, fromBlock uint64) ([]Event, error)

Fulfillments satisfies the Coordinator interface.

func (*V2PlusCoordinator) Requests added in v2.4.0

func (v *V2PlusCoordinator) Requests(
	ctx context.Context,
	fromBlock uint64,
	toBlock uint64,
) ([]Event, error)

Requests satisfies the Coordinator interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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