block

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: Apache-2.0 Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockProposal

type BlockProposal interface {
	// UpdateProposal updates the proposal with the given transactions. There are a
	// few invarients that are checked:
	//  1. The total size of the proposal must be less than the maximum number of bytes allowed.
	//  2. The total size of the partial proposal must be less than the maximum number of bytes allowed for
	//     the lane.
	UpdateProposal(lane LaneProposal, partialProposalTxs [][]byte) error

	// GetMaxTxBytes returns the maximum number of bytes that can be included in the proposal.
	GetMaxTxBytes() int64

	// GetTotalTxBytes returns the total number of bytes currently included in the proposal.
	GetTotalTxBytes() int64

	// GetTxs returns the transactions in the proposal.
	GetTxs() [][]byte

	// GetNumTxs returns the number of transactions in the proposal.
	GetNumTxs() int

	// Contains returns true if the proposal contains the given transaction.
	Contains(tx []byte) bool

	// AddVoteExtension adds a vote extension to the proposal.
	AddVoteExtension(voteExtension []byte)

	// GetVoteExtensions returns the vote extensions in the proposal.
	GetVoteExtensions() [][]byte

	// GetProposal returns all of the transactions in the proposal along with the vote extensions
	// at the top of the proposal.
	GetProposal() [][]byte
}

BlockProposal is the interface/APIs that are required for proposal creation + interacting with and updating proposals. BlockProposals are iteratively updated as each lane prepares its partial proposal. Each lane must call UpdateProposal with its partial proposal in PrepareLane. BlockProposals can also include vote extensions, which are included at the top of the proposal.

type Lane

type Lane interface {
	LaneMempool

	// PrepareLane builds a portion of the block. It inputs the maxTxBytes that can be
	// included in the proposal for the given lane, the partial proposal, and a function
	// to call the next lane in the chain. The next lane in the chain will be called with
	// the updated proposal and context.
	PrepareLane(
		ctx sdk.Context,
		proposal BlockProposal,
		maxTxBytes int64,
		next PrepareLanesHandler,
	) (BlockProposal, error)

	// CheckOrder validates that transactions belonging to this lane are not misplaced
	// in the block proposal and respect the ordering rules of the lane.
	CheckOrder(ctx sdk.Context, txs []sdk.Tx) error

	// ProcessLane verifies this lane's portion of a proposed block. It inputs the transactions
	// that may belong to this lane and a function to call the next lane in the chain. The next
	// lane in the chain will be called with the updated context and filtered down transactions.
	ProcessLane(ctx sdk.Context, proposalTxs []sdk.Tx, next ProcessLanesHandler) (sdk.Context, error)

	// GetMaxBlockSpace returns the max block space for the lane as a relative percentage.
	GetMaxBlockSpace() math.LegacyDec

	// Logger returns the lane's logger.
	Logger() log.Logger

	// Name returns the name of the lane.
	Name() string

	// SetAnteHandler sets the lane's antehandler.
	SetAnteHandler(antehander sdk.AnteHandler)

	// SetIgnoreList sets the lanes that should be ignored by this lane.
	SetIgnoreList(ignoreList []Lane)

	// Match determines if a transaction belongs to this lane.
	Match(ctx sdk.Context, tx sdk.Tx) bool
}

Lane defines an interface used for matching transactions to lanes, storing transactions, and constructing partial blocks.

type LaneMempool

type LaneMempool interface {
	sdkmempool.Mempool

	// Compare determines the relative priority of two transactions belonging in the same lane. Compare
	// will return -1 if this transaction has a lower priority than the other transaction, 0 if they have
	// the same priority, and 1 if this transaction has a higher priority than the other transaction.
	Compare(ctx sdk.Context, this, other sdk.Tx) int

	// Contains returns true if the transaction is contained in the mempool.
	Contains(tx sdk.Tx) bool
}

LaneMempool defines the interface a lane's mempool should implement. The basic API is the same as the sdk.Mempool, but it also includes a Compare function that is used to determine the relative priority of two transactions belonging in the same lane.

type LaneProposal

type LaneProposal interface {
	// Logger returns the lane's logger.
	Logger() log.Logger

	// GetMaxBlockSpace returns the maximum block space for the lane as a relative percentage.
	GetMaxBlockSpace() math.LegacyDec

	// Name returns the name of the lane.
	Name() string
}

LaneProposal defines the interface/APIs that are required for the proposal to interact with a lane.

type LanedMempool

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

LanedMempool defines the Block SDK mempool implementation. It contains a registry of lanes, which allows for customizable block proposal construction.

func NewLanedMempool

func NewLanedMempool(logger log.Logger, mutex bool, lanes ...Lane) *LanedMempool

NewLanedMempool returns a new Block SDK LanedMempool. The laned mempool is comprised of a registry of lanes. Each lane is responsible for selecting transactions according to its own selection logic. The lanes are ordered according to their priority. The first lane in the registry has the highest priority. Proposals are verified according to the order of the lanes in the registry. Each transaction should only belong in one lane but this is NOT enforced. To enforce that each transaction belong to a single lane, you must configure the ignore list of each lane to include all preceding lanes. Basic mempool API will attempt to insert, remove transactions from all lanes it belongs to. It is recommended, that mutex is set to true when creating the mempool. This will ensure that each transaction cannot be inserted into the lanes before it.

func (*LanedMempool) Contains

func (m *LanedMempool) Contains(tx sdk.Tx) (contains bool)

Contains returns true if the transaction is contained in any of the lanes.

func (*LanedMempool) CountTx

func (m *LanedMempool) CountTx() int

CountTx returns the total number of transactions in the mempool. This will be the sum of the number of transactions in each lane.

func (*LanedMempool) GetTxDistribution

func (m *LanedMempool) GetTxDistribution() map[string]int

GetTxDistribution returns the number of transactions in each lane.

func (*LanedMempool) Insert

func (m *LanedMempool) Insert(ctx context.Context, tx sdk.Tx) (err error)

Insert will insert a transaction into the mempool. It inserts the transaction into the first lane that it matches.

func (*LanedMempool) Registry

func (m *LanedMempool) Registry() []Lane

Registry returns the mempool's lane registry.

func (*LanedMempool) Remove

func (m *LanedMempool) Remove(tx sdk.Tx) (err error)

Remove removes a transaction from all of the lanes it is currently in.

func (*LanedMempool) Select

func (m *LanedMempool) Select(_ context.Context, _ [][]byte) sdkmempool.Iterator

Insert returns a nil iterator.

TODO: - Determine if it even makes sense to return an iterator. What does that even mean in the context where you have multiple lanes? - Perhaps consider implementing and returning a no-op iterator?

func (*LanedMempool) ValidateBasic

func (m *LanedMempool) ValidateBasic() error

ValidateBasic validates the mempools configuration. ValidateBasic ensures the following: - The sum of the lane max block space percentages is less than or equal to 1. - There is no unused block space.

type Mempool

type Mempool interface {
	sdkmempool.Mempool

	// Registry returns the mempool's lane registry.
	Registry() []Lane

	// Contains returns the any of the lanes currently contain the transaction.
	Contains(tx sdk.Tx) bool

	// GetTxDistribution returns the number of transactions in each lane.
	GetTxDistribution() map[string]int
}

Mempool defines the Block SDK mempool interface.

type PrepareLanesHandler

type PrepareLanesHandler func(ctx sdk.Context, proposal BlockProposal) (BlockProposal, error)

PrepareLanesHandler wraps all of the lanes' PrepareLane function into a single chained function. You can think of it like an AnteHandler, but for preparing proposals in the context of lanes instead of modules.

func NoOpPrepareLanesHandler

func NoOpPrepareLanesHandler() PrepareLanesHandler

NoOpPrepareLanesHandler returns a no-op prepare lanes handler. This should only be used for testing.

type ProcessLanesHandler

type ProcessLanesHandler func(ctx sdk.Context, txs []sdk.Tx) (sdk.Context, error)

ProcessLanesHandler wraps all of the lanes' ProcessLane functions into a single chained function. You can think of it like an AnteHandler, but for processing proposals in the context of lanes instead of modules.

func NoOpProcessLanesHandler

func NoOpProcessLanesHandler() ProcessLanesHandler

NoOpProcessLanesHandler returns a no-op process lanes handler. This should only be used for testing.

type Proposal

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

Proposal defines a block proposal type.

func NewProposal

func NewProposal(maxTxBytes int64) *Proposal

NewProposal returns a new empty proposal.

func (*Proposal) AddVoteExtension

func (p *Proposal) AddVoteExtension(voteExtension []byte)

AddVoteExtension adds a vote extension to the proposal.

func (*Proposal) Contains

func (p *Proposal) Contains(tx []byte) bool

Contains returns true if the proposal contains the given transaction.

func (*Proposal) GetMaxTxBytes

func (p *Proposal) GetMaxTxBytes() int64

GetMaxTxBytes returns the maximum number of bytes that can be included in the proposal.

func (*Proposal) GetNumTxs

func (p *Proposal) GetNumTxs() int

GetNumTxs returns the number of transactions in the proposal.

func (*Proposal) GetProposal

func (p *Proposal) GetProposal() [][]byte

GetProposal returns all of the transactions in the proposal along with the vote extensions at the top of the proposal.

func (*Proposal) GetTotalTxBytes

func (p *Proposal) GetTotalTxBytes() int64

GetTotalTxBytes returns the total number of bytes currently included in the proposal.

func (*Proposal) GetTxs

func (p *Proposal) GetTxs() [][]byte

GetTxs returns the transactions in the proposal.

func (*Proposal) GetVoteExtensions

func (p *Proposal) GetVoteExtensions() [][]byte

GetVoteExtensions returns the vote extensions in the proposal.

func (*Proposal) UpdateProposal

func (p *Proposal) UpdateProposal(lane LaneProposal, partialProposalTxs [][]byte) error

UpdateProposal updates the proposal with the given transactions and total size. There are a few invarients that are checked:

  1. The total size of the proposal must be less than the maximum number of bytes allowed.
  2. The total size of the partial proposal must be less than the maximum number of bytes allowed for the lane.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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