heightsync

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HeightSync

type HeightSync[Store any] struct {
	// contains filtered or unexported fields
}

HeightSync synchronizes access to a per-height tx store for mempool implementations.

At every new block height, mempools need to revalidate (recheck) their transactions against the latest chain state. This rechecking happens asynchronously — txs are validated one by one and pushed into a store as they pass. Meanwhile, block proposers may need to read from that store to build the next block.

HeightSync solves this coordination problem. It holds a Store per height that producers populate via Do (e.g. during rechecking), and that consumers read via GetStore. GetStore blocks until either all operations for the requested height are complete (EndCurrentHeight is called) or the caller's context times out, whichever comes first. This lets block builders wait for the full set of rechecked txs when time permits, while still returning partial results under time pressure rather than holding a lock on the mempool itself.

func New

func New[Store any](startHeight *big.Int, reset func(logger log.Logger) *Store, logger log.Logger) *HeightSync[Store]

New creates a new HeightSync starting at the given height.

func (*HeightSync[Store]) Do

func (hs *HeightSync[Store]) Do(fn func(store *Store))

Do executes fn with the current store. The store will be non-nil.

func (*HeightSync[Store]) EndCurrentHeight

func (hs *HeightSync[Store]) EndCurrentHeight()

EndCurrentHeight marks the current heights operations as complete. This should be called when no more operations on the value via Do will be happen for this height.

If operations are not marked as complete, callers of Get must wait for a context timeout in order to access the Store at this height.

func (*HeightSync[Store]) GetStore

func (hs *HeightSync[Store]) GetStore(ctx context.Context, height *big.Int) *Store

GetStore returns the store at the given height. If the HeightSync has not yet reached the target height, GetStore blocks until the height is reached or the context expires. If the height is reached, GetStore waits for EndCurrentHeight to be called (or for the context to expire) before returning.

func (*HeightSync[Store]) StartNewHeight

func (hs *HeightSync[Store]) StartNewHeight(height *big.Int)

StartNewHeight resets the HeightSync for a new height, overwriting the previous Store with a fresh Store via the reset fn.

Jump to

Keyboard shortcuts

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