blockhashstore

package
v2.0.0-rc0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2023 License: MIT Imports: 26 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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
}

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,
	fromAddresses []ethkey.EIP55Address,
	txm txmgr.TxManager,
	bhs blockhash_store.BlockhashStoreInterface,
	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) 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

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,
	chains evm.ChainSet,
	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,
	waitBlocks int,
	lookbackBlocks int,
	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.

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) Store

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

func (*TestBHS) StoreEarliest

func (t *TestBHS) StoreEarliest(ctx context.Context) 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) 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 V1Coordinator

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

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

func NewV1Coordinator

func NewV1Coordinator(c v1.VRFCoordinatorInterface) *V1Coordinator

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

func NewV2Coordinator(c v2.VRFCoordinatorV2Interface) *V2Coordinator

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.

Jump to

Keyboard shortcuts

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