hook

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IncentiveHook

type IncentiveHook interface {
	// CreateTransaction creates a new transaction for the specified node at the given cycle.
	// Returns the created transaction or nil if no transaction should be created.
	CreateTransaction(nodeID int, cycle uint64) (*transaction.Transaction, error)

	// ShouldCreateTransaction determines whether a transaction should be created
	// for the specified node at the given cycle.
	ShouldCreateTransaction(nodeID int, cycle uint64) bool
}

IncentiveHook defines the interface for creating transactions. This hook will be used by the Incentive plugin in the future.

type MockIncentiveHook

type MockIncentiveHook struct {
	// CreateEveryNCycles creates a transaction every N cycles (0 means never)
	CreateEveryNCycles uint64
	// CreateProbability creates a transaction with this probability (0.0 to 1.0)
	CreateProbability float64
	// MaxTransactionsPerNode limits the number of transactions per node (0 means unlimited)
	MaxTransactionsPerNode int
	// TransactionManager is used to create transactions
	TransactionManager *transaction.TxnManager
	// contains filtered or unexported fields
}

MockIncentiveHook is a simple implementation of IncentiveHook for testing and examples.

func NewMockIncentiveHook

func NewMockIncentiveHook(mgr *transaction.TxnManager) *MockIncentiveHook

NewMockIncentiveHook creates a new MockIncentiveHook.

func (*MockIncentiveHook) CreateTransaction

func (h *MockIncentiveHook) CreateTransaction(nodeID int, cycle uint64) (*transaction.Transaction, error)

CreateTransaction creates a new transaction if conditions are met.

func (*MockIncentiveHook) ResetNodeCounters

func (h *MockIncentiveHook) ResetNodeCounters()

ResetNodeCounters resets the transaction counters for all nodes.

func (*MockIncentiveHook) SetCreateEveryNCycles

func (h *MockIncentiveHook) SetCreateEveryNCycles(n uint64)

SetCreateEveryNCycles sets the cycle interval for transaction creation.

func (*MockIncentiveHook) SetCreateProbability

func (h *MockIncentiveHook) SetCreateProbability(prob float64)

SetCreateProbability sets the probability for transaction creation.

func (*MockIncentiveHook) SetMaxTransactionsPerNode

func (h *MockIncentiveHook) SetMaxTransactionsPerNode(max int)

SetMaxTransactionsPerNode sets the maximum number of transactions per node.

func (*MockIncentiveHook) ShouldCreateTransaction

func (h *MockIncentiveHook) ShouldCreateTransaction(nodeID int, cycle uint64) bool

ShouldCreateTransaction determines whether a transaction should be created.

Jump to

Keyboard shortcuts

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