Documentation ¶
Index ¶
- Variables
- type Config
- type Engine
- func (e *Engine) EndOfBlock(blockHeight uint64)
- func (e *Engine) GetState(k string) ([]byte, []types.StateProvider, error)
- func (e *Engine) HasChanged(k string) bool
- func (e *Engine) Keys() []string
- func (e *Engine) LoadState(ctx context.Context, p *types.Payload) ([]types.StateProvider, error)
- func (e *Engine) Namespace() types.SnapshotNamespace
- func (e *Engine) OnEpochEvent(ctx context.Context, epoch types.Epoch)
- func (e *Engine) OnEpochRestore(ctx context.Context, epoch types.Epoch)
- func (e *Engine) OnMaxDelegationsChanged(ctx context.Context, maxDelegations int64) error
- func (e *Engine) OnMaxProposalsChanged(ctx context.Context, maxProposals int64) error
- func (e *Engine) OnMaxTransfersChanged(_ context.Context, maxTransfers int64) error
- func (e *Engine) OnMaxVotesChanged(ctx context.Context, maxVotes int64) error
- func (e *Engine) OnMinTokensForDelegationChanged(ctx context.Context, minTokens num.Decimal) error
- func (e *Engine) OnMinTokensForProposalChanged(ctx context.Context, minTokens num.Decimal) error
- func (e *Engine) OnMinTokensForVotingChanged(ctx context.Context, minTokens num.Decimal) error
- func (e *Engine) OnMinValidatorTokensChanged(_ context.Context, minTokens num.Decimal) error
- func (e *Engine) PostBlockAccept(tx abci.Tx) (bool, error)
- func (e *Engine) PreBlockAccept(tx abci.Tx) (bool, error)
- func (e *Engine) ReloadConf(cfg Config)
- func (e *Engine) Stopped() bool
- type EpochEngine
- type Policy
- type SimpleSpamPolicy
- func (ssp *SimpleSpamPolicy) Deserialise(p *types.Payload) error
- func (ssp *SimpleSpamPolicy) EndOfBlock(blockHeight uint64)
- func (ssp *SimpleSpamPolicy) PostBlockAccept(tx abci.Tx) (bool, error)
- func (ssp *SimpleSpamPolicy) PreBlockAccept(tx abci.Tx) (bool, error)
- func (ssp *SimpleSpamPolicy) Reset(epoch types.Epoch)
- func (ssp *SimpleSpamPolicy) Serialise() ([]byte, error)
- func (ssp *SimpleSpamPolicy) UpdateIntParam(name string, value int64) error
- func (ssp *SimpleSpamPolicy) UpdateUintParam(name string, value *num.Uint) error
- type StakingAccounts
- type VoteSpamPolicy
- func (vsp *VoteSpamPolicy) Deserialise(p *types.Payload) error
- func (vsp *VoteSpamPolicy) EndOfBlock(blockHeight uint64)
- func (vsp *VoteSpamPolicy) PostBlockAccept(tx abci.Tx) (bool, error)
- func (vsp *VoteSpamPolicy) PreBlockAccept(tx abci.Tx) (bool, error)
- func (vsp *VoteSpamPolicy) Reset(epoch types.Epoch)
- func (vsp *VoteSpamPolicy) Serialise() ([]byte, error)
- func (vsp *VoteSpamPolicy) UpdateIntParam(name string, value int64) error
- func (vsp *VoteSpamPolicy) UpdateUintParam(name string, value *num.Uint) error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrPartyIsBannedFromVoting is returned when the party is banned from voting. ErrPartyIsBannedFromVoting = errors.New("party is banned from submitting votes in the current epoch") // 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 ¶
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 ¶
EndOfBlock is called when the block is finished.
func (*Engine) HasChanged ¶
func (*Engine) Namespace ¶
func (e *Engine) Namespace() types.SnapshotNamespace
func (*Engine) OnEpochEvent ¶
OnEpochEvent is a callback for epoch events.
func (*Engine) OnEpochRestore ¶
OnEpochEvent is a callback for epoch events.
func (*Engine) OnMaxDelegationsChanged ¶
OnMaxDelegationsChanged is called when the net param for max delegations per epoch has changed.
func (*Engine) OnMaxProposalsChanged ¶
OnMaxProposalsChanged is called when the net param for max proposals per epoch has changed.
func (*Engine) OnMaxTransfersChanged ¶
OnMaxTransfersChanged is called when the net param for max transfers per epoch changes.
func (*Engine) OnMaxVotesChanged ¶
OnMaxVotesChanged is called when the net param for max votes per epoch has changed.
func (*Engine) OnMinTokensForDelegationChanged ¶
OnMinTokensForDelegationChanged is called when the net param for min tokens requirement for voting has changed.
func (*Engine) OnMinTokensForProposalChanged ¶
OnMinTokensForProposalChanged is called when the net param for min tokens requirement for submitting a proposal has changed.
func (*Engine) OnMinTokensForVotingChanged ¶
OnMinTokensForVotingChanged is called when the net param for min tokens requirement for voting has changed.
func (*Engine) OnMinValidatorTokensChanged ¶
OnMinValidatorTokensChanged is called when the net param for min tokens for joining validator changes.
func (*Engine) PostBlockAccept ¶
PostBlockAccept is called from onDeliverTx before the block is processed returns false is rejected by spam engine with a corresponding error.
func (*Engine) PreBlockAccept ¶
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 ¶
ReloadConf updates the internal configuration of the spam engine.
type EpochEngine ¶
type Policy ¶ added in v0.55.0
type Policy interface { Reset(epoch types.Epoch) EndOfBlock(blockHeight uint64) 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 }
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)
EndOfBlock is called at the end of the processing of the block to carry over state and trigger bans if necessary.
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 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)
EndOfBlock is called at the end of the block to allow updating of the state for the next block.
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.