spam

package
v0.71.2 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInsufficientTokensForVoting is returned when the party has insufficient tokens for voting.
	ErrInsufficientTokensForVoting = errors.New("party has insufficient associated governance tokens in their staking account to submit votes")
	// ErrTooManyVotes is returned when the party has voted already the maximum allowed votes per proposal per epoch.
	ErrTooManyVotes = errors.New("party has already voted the maximum number of times per proposal per epoch")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Level encoding.LogLevel `long:"log-level"`
}

Config represent the configuration of the collateral engine.

func NewDefaultConfig

func NewDefaultConfig() Config

NewDefaultConfig creates an instance of the package specific configuration, given a pointer to a logger instance to be used for logging within the package.

type Engine

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

func New

func New(log *logging.Logger, config Config, epochEngine EpochEngine, accounting StakingAccounts) *Engine

New instantiates a new spam engine.

func (*Engine) EndOfBlock

func (e *Engine) EndOfBlock(blockHeight uint64, now time.Time)

EndOfBlock is called when the block is finished.

func (*Engine) GetSpamStatistics added in v0.67.0

func (e *Engine) GetSpamStatistics(partyID string) *protoapi.SpamStatistics

func (*Engine) GetState

func (e *Engine) GetState(k string) ([]byte, []types.StateProvider, error)

func (*Engine) Keys

func (e *Engine) Keys() []string

func (*Engine) LoadState

func (e *Engine) LoadState(ctx context.Context, p *types.Payload) ([]types.StateProvider, error)

func (*Engine) Namespace

func (e *Engine) Namespace() types.SnapshotNamespace

func (*Engine) OnEpochDurationChanged added in v0.65.0

func (e *Engine) OnEpochDurationChanged(_ context.Context, duration time.Duration) error

OnEpochDurationChanged updates the ban duration as a fraction of the epoch duration.

func (*Engine) OnEpochEvent

func (e *Engine) OnEpochEvent(ctx context.Context, epoch types.Epoch)

OnEpochEvent is a callback for epoch events.

func (*Engine) OnEpochRestore

func (e *Engine) OnEpochRestore(ctx context.Context, epoch types.Epoch)

OnEpochEvent is a callback for epoch events.

func (*Engine) OnMaxDelegationsChanged

func (e *Engine) OnMaxDelegationsChanged(ctx context.Context, maxDelegations int64) error

OnMaxDelegationsChanged is called when the net param for max delegations per epoch has changed.

func (*Engine) OnMaxProposalsChanged

func (e *Engine) OnMaxProposalsChanged(ctx context.Context, maxProposals int64) error

OnMaxProposalsChanged is called when the net param for max proposals per epoch has changed.

func (*Engine) OnMaxTransfersChanged

func (e *Engine) OnMaxTransfersChanged(_ context.Context, maxTransfers int64) error

OnMaxTransfersChanged is called when the net param for max transfers per epoch changes.

func (*Engine) OnMaxVotesChanged

func (e *Engine) OnMaxVotesChanged(ctx context.Context, maxVotes int64) error

OnMaxVotesChanged is called when the net param for max votes per epoch has changed.

func (*Engine) OnMinTokensForDelegationChanged

func (e *Engine) OnMinTokensForDelegationChanged(ctx context.Context, minTokens num.Decimal) error

OnMinTokensForDelegationChanged is called when the net param for min tokens requirement for voting has changed.

func (*Engine) OnMinTokensForMultisigUpdatesChanged added in v0.68.0

func (e *Engine) OnMinTokensForMultisigUpdatesChanged(ctx context.Context, minTokens num.Decimal) error

OnMinTokensForProposalChanged is called when the net param for min tokens requirement for submitting a proposal has changed.

func (*Engine) OnMinTokensForProposalChanged

func (e *Engine) OnMinTokensForProposalChanged(ctx context.Context, minTokens num.Decimal) error

OnMinTokensForProposalChanged is called when the net param for min tokens requirement for submitting a proposal has changed.

func (*Engine) OnMinTokensForVotingChanged

func (e *Engine) OnMinTokensForVotingChanged(ctx context.Context, minTokens num.Decimal) error

OnMinTokensForVotingChanged is called when the net param for min tokens requirement for voting has changed.

func (*Engine) OnMinValidatorTokensChanged

func (e *Engine) OnMinValidatorTokensChanged(_ context.Context, minTokens num.Decimal) error

OnMinValidatorTokensChanged is called when the net param for min tokens for joining validator changes.

func (*Engine) PostBlockAccept

func (e *Engine) PostBlockAccept(tx abci.Tx) (bool, error)

PostBlockAccept is called from onDeliverTx before the block is processed returns false is rejected by spam engine with a corresponding error.

func (*Engine) PreBlockAccept

func (e *Engine) PreBlockAccept(tx abci.Tx) (bool, error)

PreBlockAccept is called from onCheckTx before a tx is added to mempool returns false is rejected by spam engine with a corresponding error.

func (*Engine) ReloadConf

func (e *Engine) ReloadConf(cfg Config)

ReloadConf updates the internal configuration of the spam engine.

func (*Engine) Stopped

func (e *Engine) Stopped() bool

type EpochEngine

type EpochEngine interface {
	NotifyOnEpoch(f func(context.Context, types.Epoch), r func(context.Context, types.Epoch))
}

type Policy added in v0.55.0

type Policy interface {
	Reset(epoch types.Epoch)
	EndOfBlock(blockHeight uint64, now time.Time, banDuration time.Duration)
	PreBlockAccept(tx abci.Tx) (bool, error)
	PostBlockAccept(tx abci.Tx) (bool, error)
	UpdateUintParam(name string, value *num.Uint) error
	UpdateIntParam(name string, value int64) error
	Serialise() ([]byte, error)
	Deserialise(payload *types.Payload) error
	GetSpamStats(partyID string) *protoapi.SpamStatistic
	GetVoteSpamStats(partyID string) *protoapi.VoteSpamStatistics
}

type SimpleSpamPolicy

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

Simple spam policy supports encforcing of max allowed commands and min required tokens + banning of parties when their reject rate in the block exceeds x%.

func NewSimpleSpamPolicy

func NewSimpleSpamPolicy(policyName string, minTokensParamName string, maxAllowedParamName string, log *logging.Logger, accounts StakingAccounts) *SimpleSpamPolicy

NewSimpleSpamPolicy instantiates the simple spam policy.

func (*SimpleSpamPolicy) Deserialise

func (ssp *SimpleSpamPolicy) Deserialise(p *types.Payload) error

func (*SimpleSpamPolicy) EndOfBlock

func (ssp *SimpleSpamPolicy) EndOfBlock(blockHeight uint64, now time.Time, banDuration time.Duration)

EndOfBlock is called at the end of the processing of the block to carry over state and trigger bans if necessary.

func (*SimpleSpamPolicy) GetSpamStats added in v0.67.0

func (ssp *SimpleSpamPolicy) GetSpamStats(party string) *protoapi.SpamStatistic

func (*SimpleSpamPolicy) GetVoteSpamStats added in v0.67.0

func (ssp *SimpleSpamPolicy) GetVoteSpamStats(_ string) *protoapi.VoteSpamStatistics

func (*SimpleSpamPolicy) PostBlockAccept

func (ssp *SimpleSpamPolicy) PostBlockAccept(tx abci.Tx) (bool, error)

PostBlockAccept is called to verify a transaction from the block before passed to the application layer.

func (*SimpleSpamPolicy) PreBlockAccept

func (ssp *SimpleSpamPolicy) PreBlockAccept(tx abci.Tx) (bool, error)

PreBlockAccept checks if the commands violates spam rules based on the information we had about the number of existing commands preceding the current block.

func (*SimpleSpamPolicy) Reset

func (ssp *SimpleSpamPolicy) Reset(epoch types.Epoch)

Reset is called when the epoch begins to reset policy state.

func (*SimpleSpamPolicy) Serialise

func (ssp *SimpleSpamPolicy) Serialise() ([]byte, error)

func (*SimpleSpamPolicy) UpdateIntParam

func (ssp *SimpleSpamPolicy) UpdateIntParam(name string, value int64) error

UpdateIntParam is called to update int net params for the policy Specifically the number of commands a party can submit in an epoch.

func (*SimpleSpamPolicy) UpdateUintParam

func (ssp *SimpleSpamPolicy) UpdateUintParam(name string, value *num.Uint) error

UpdateUintParam is called to update Uint net params for the policy Specifically the min tokens required for executing the command for which the policy is attached.

type StakingAccounts

type StakingAccounts interface {
	GetAvailableBalance(party string) (*num.Uint, error)
}

type Statistic added in v0.67.0

type Statistic struct {
	Name        string
	Total       uint64
	Limit       uint64
	BannedUntil int64
}

type Statistics added in v0.67.0

type Statistics struct {
	Proposals         Statistic
	Delegations       Statistic
	Transfers         Statistic
	NodeAnnouncements Statistic
	Votes             []VoteStatistic
}

type VoteSpamPolicy

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

func NewVoteSpamPolicy

func NewVoteSpamPolicy(minTokensParamName string, maxAllowedParamName string, log *logging.Logger, accounts StakingAccounts) *VoteSpamPolicy

NewVoteSpamPolicy instantiates vote spam policy.

func (*VoteSpamPolicy) Deserialise

func (vsp *VoteSpamPolicy) Deserialise(p *types.Payload) error

func (*VoteSpamPolicy) EndOfBlock

func (vsp *VoteSpamPolicy) EndOfBlock(blockHeight uint64, now time.Time, banDuration time.Duration)

EndOfBlock is called at the end of the block to allow updating of the state for the next block.

func (*VoteSpamPolicy) GetSpamStats added in v0.67.0

func (vsp *VoteSpamPolicy) GetSpamStats(_ string) *protoapi.SpamStatistic

func (*VoteSpamPolicy) GetVoteSpamStats added in v0.67.0

func (vsp *VoteSpamPolicy) GetVoteSpamStats(partyID string) *protoapi.VoteSpamStatistics

func (*VoteSpamPolicy) PostBlockAccept

func (vsp *VoteSpamPolicy) PostBlockAccept(tx abci.Tx) (bool, error)

PostBlockAccept checks if votes that made it to the block should be rejected based on the number of votes preceding the block + votes seen in the block NB: this is called as part of the processing of the block.

func (*VoteSpamPolicy) PreBlockAccept

func (vsp *VoteSpamPolicy) PreBlockAccept(tx abci.Tx) (bool, error)

PreBlockAccept checks if the vote should be rejected as spam or not based on the number of votes in current epoch's preceding blocks and the number of tokens held by the party. NB: this is done at mempool before adding to block.

func (*VoteSpamPolicy) Reset

func (vsp *VoteSpamPolicy) Reset(epoch types.Epoch)

Reset is called at the beginning of an epoch to reset the settings for the epoch.

func (*VoteSpamPolicy) Serialise

func (vsp *VoteSpamPolicy) Serialise() ([]byte, error)

func (*VoteSpamPolicy) UpdateIntParam

func (vsp *VoteSpamPolicy) UpdateIntParam(name string, value int64) error

UpdateIntParam is called to update iint net params for the policy Specifically the number of votes to a proposal a party can submit in an epoch.

func (*VoteSpamPolicy) UpdateUintParam

func (vsp *VoteSpamPolicy) UpdateUintParam(name string, value *num.Uint) error

UpdateUintParam is called to update Uint net params for the policy Specifically the min tokens required for voting.

type VoteStatistic added in v0.67.0

type VoteStatistic struct {
	Proposal    string
	Total       uint64
	MaxForEpoch uint64
	BannedUntil int64
}

Jump to

Keyboard shortcuts

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