spam

package
v0.79.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: AGPL-3.0 Imports: 16 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) BeginBlock added in v0.74.0

func (e *Engine) BeginBlock(txs []abci.Tx)

func (*Engine) CheckBlockTx added in v0.74.0

func (e *Engine) CheckBlockTx(tx abci.Tx) error

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

func (*Engine) DisableSpamProtection added in v0.73.0

func (e *Engine) DisableSpamProtection()

func (*Engine) EndPrepareProposal added in v0.74.0

func (e *Engine) EndPrepareProposal()

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(_ context.Context, p *types.Payload) ([]types.StateProvider, error)

func (*Engine) Namespace

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

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) OnMaxApplyReferralCode added in v0.73.0

func (e *Engine) OnMaxApplyReferralCode(ctx context.Context, max int64) error

OnMaxApplyReferralCode is called when the net param for max update referral set per epoch has changed.

func (*Engine) OnMaxCreateReferralSet added in v0.73.0

func (e *Engine) OnMaxCreateReferralSet(ctx context.Context, max int64) error

OnCreateReferralSet is called when the net param for max create referral set per epoch has changed.

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) OnMaxMultisigUpdatesChanged added in v0.76.0

func (e *Engine) OnMaxMultisigUpdatesChanged(_ context.Context, maxUpdates int64) error

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

func (*Engine) OnMaxPartyProfile added in v0.74.0

func (e *Engine) OnMaxPartyProfile(ctx context.Context, max int64) error

OnMaxPartyProfileUpdate is called when the net param for max update party profile 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) OnMaxUpdateReferralSet added in v0.73.0

func (e *Engine) OnMaxUpdateReferralSet(ctx context.Context, max int64) error

OnMaxUpdateReferralSet is called when the net param for max update referral set per epoch has changed.

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(_ 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) OnMinTokensForReferral added in v0.73.0

func (e *Engine) OnMinTokensForReferral(ctx context.Context, minTokens *num.Uint) error

OnMinTokensForReferral is called when the net param for min staked tokens requirement for referral set create/update 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) PreBlockAccept

func (e *Engine) PreBlockAccept(tx abci.Tx) 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) ProcessProposal added in v0.74.0

func (e *Engine) ProcessProposal(txs []abci.Tx) bool

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)
	UpdateTx(tx abci.Tx)
	RollbackProposal()
	CheckBlockTx(abci.Tx) error
	PreBlockAccept(tx abci.Tx) 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) CheckBlockTx added in v0.74.0

func (ssp *SimpleSpamPolicy) CheckBlockTx(tx abci.Tx) error

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

func (*SimpleSpamPolicy) Deserialise

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

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

func (ssp *SimpleSpamPolicy) PreBlockAccept(tx abci.Tx) 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) RollbackProposal added in v0.74.0

func (ssp *SimpleSpamPolicy) RollbackProposal()

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) UpdateTx added in v0.74.0

func (ssp *SimpleSpamPolicy) UpdateTx(tx abci.Tx)

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) CheckBlockTx added in v0.74.0

func (vsp *VoteSpamPolicy) CheckBlockTx(tx abci.Tx) error

func (*VoteSpamPolicy) Deserialise

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

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

func (vsp *VoteSpamPolicy) PreBlockAccept(tx abci.Tx) 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) RollbackProposal added in v0.74.0

func (vsp *VoteSpamPolicy) RollbackProposal()

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) UpdateTx added in v0.74.0

func (vsp *VoteSpamPolicy) UpdateTx(tx abci.Tx)

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