Documentation ¶
Index ¶
- Variables
- type Config
- type Engine
- func (e *Engine) BeginBlock(txs []abci.Tx)
- func (e *Engine) CheckBlockTx(tx abci.Tx) error
- func (e *Engine) DisableSpamProtection()
- func (e *Engine) EndPrepareProposal()
- func (e *Engine) GetSpamStatistics(partyID string) *protoapi.SpamStatistics
- func (e *Engine) GetState(k string) ([]byte, []types.StateProvider, error)
- func (e *Engine) Keys() []string
- func (e *Engine) LoadState(_ 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) OnMaxApplyReferralCode(ctx context.Context, max int64) error
- func (e *Engine) OnMaxCreateReferralSet(ctx context.Context, max int64) error
- func (e *Engine) OnMaxDelegationsChanged(ctx context.Context, maxDelegations int64) error
- func (e *Engine) OnMaxMultisigUpdatesChanged(_ context.Context, maxUpdates int64) error
- func (e *Engine) OnMaxPartyProfile(ctx context.Context, max int64) error
- func (e *Engine) OnMaxProposalsChanged(ctx context.Context, maxProposals int64) error
- func (e *Engine) OnMaxTransfersChanged(_ context.Context, maxTransfers int64) error
- func (e *Engine) OnMaxUpdateReferralSet(ctx context.Context, max 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) OnMinTokensForMultisigUpdatesChanged(_ context.Context, minTokens num.Decimal) error
- func (e *Engine) OnMinTokensForProposalChanged(ctx context.Context, minTokens num.Decimal) error
- func (e *Engine) OnMinTokensForReferral(ctx context.Context, minTokens *num.Uint) 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) PreBlockAccept(tx abci.Tx) error
- func (e *Engine) ProcessProposal(txs []abci.Tx) bool
- func (e *Engine) ReloadConf(cfg Config)
- func (e *Engine) Stopped() bool
- type EpochEngine
- type Policy
- type SimpleSpamPolicy
- func (ssp *SimpleSpamPolicy) CheckBlockTx(tx abci.Tx) error
- func (ssp *SimpleSpamPolicy) Deserialise(p *types.Payload) error
- func (ssp *SimpleSpamPolicy) GetSpamStats(party string) *protoapi.SpamStatistic
- func (ssp *SimpleSpamPolicy) GetVoteSpamStats(_ string) *protoapi.VoteSpamStatistics
- func (ssp *SimpleSpamPolicy) PreBlockAccept(tx abci.Tx) error
- func (ssp *SimpleSpamPolicy) Reset(epoch types.Epoch)
- func (ssp *SimpleSpamPolicy) RollbackProposal()
- func (ssp *SimpleSpamPolicy) Serialise() ([]byte, error)
- func (ssp *SimpleSpamPolicy) UpdateIntParam(name string, value int64) error
- func (ssp *SimpleSpamPolicy) UpdateTx(tx abci.Tx)
- func (ssp *SimpleSpamPolicy) UpdateUintParam(name string, value *num.Uint) error
- type StakingAccounts
- type Statistic
- type Statistics
- type VoteSpamPolicy
- func (vsp *VoteSpamPolicy) CheckBlockTx(tx abci.Tx) error
- func (vsp *VoteSpamPolicy) Deserialise(p *types.Payload) error
- func (vsp *VoteSpamPolicy) GetSpamStats(_ string) *protoapi.SpamStatistic
- func (vsp *VoteSpamPolicy) GetVoteSpamStats(partyID string) *protoapi.VoteSpamStatistics
- func (vsp *VoteSpamPolicy) PreBlockAccept(tx abci.Tx) error
- func (vsp *VoteSpamPolicy) Reset(epoch types.Epoch)
- func (vsp *VoteSpamPolicy) RollbackProposal()
- func (vsp *VoteSpamPolicy) Serialise() ([]byte, error)
- func (vsp *VoteSpamPolicy) UpdateIntParam(name string, value int64) error
- func (vsp *VoteSpamPolicy) UpdateTx(tx abci.Tx)
- func (vsp *VoteSpamPolicy) UpdateUintParam(name string, value *num.Uint) error
- type VoteStatistic
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 (*Engine) CheckBlockTx ¶ added in v0.74.0
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) 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) OnMaxApplyReferralCode ¶ added in v0.73.0
OnMaxApplyReferralCode is called when the net param for max update referral set per epoch has changed.
func (*Engine) OnMaxCreateReferralSet ¶ added in v0.73.0
OnCreateReferralSet is called when the net param for max create referral set per epoch has changed.
func (*Engine) OnMaxDelegationsChanged ¶
OnMaxDelegationsChanged is called when the net param for max delegations per epoch has changed.
func (*Engine) OnMaxMultisigUpdatesChanged ¶ added in v0.76.0
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
OnMaxPartyProfileUpdate is called when the net param for max update party profile 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) OnMaxUpdateReferralSet ¶ added in v0.73.0
OnMaxUpdateReferralSet is called when the net param for max update referral set per epoch has changed.
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) 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 ¶
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
OnMinTokensForReferral is called when the net param for min staked tokens requirement for referral set create/update 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) 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) ProcessProposal ¶ added in v0.74.0
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) 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 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.