Documentation
¶
Overview ¶
Package analyzer defines analyzer interfaces used by the proposal analysis engine.
Implementing an Analyzer ¶
Every analyzer must implement one of the scope-specific analyzer interfaces:
- ProposalAnalyzer
- BatchOperationAnalyzer
- CallAnalyzer
- ParameterAnalyzer
Example proposal-level analyzer:
import (
"context"
"github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/mcms/proposalanalysis"
"github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/mcms/proposalanalysis/analyzer"
)
type RiskAnalyzer struct{}
func (RiskAnalyzer) ID() string {
return "risk-analyzer"
}
func (RiskAnalyzer) Dependencies() []string {
return []string{"dependency-analyzer"}
}
func (RiskAnalyzer) CanAnalyze(
ctx context.Context,
req analyzer.ProposalAnalyzeRequest,
proposal analyzer.DecodedTimelockProposal,
) bool {
_ = ctx
_ = req
_ = proposal
return true
}
func (RiskAnalyzer) Analyze(
ctx context.Context,
req analyzer.ProposalAnalyzeRequest,
proposal analyzer.DecodedTimelockProposal,
) (analyzer.Annotations, error) {
_ = ctx
_ = req
_ = proposal
return analyzer.Annotations{
analyzer.NewAnnotation("risk-level", "string", "medium"),
}, nil
}
Registering with the engine ¶
eng := proposalanalysis.NewAnalyzerEngine()
if err := eng.RegisterAnalyzer(RiskAnalyzer{}); err != nil {
return err
}
The engine resolves analyzer execution order using `Dependencies()` and passes dependency-scoped annotations through the request's `DependencyAnnotationStore`.
Index ¶
- Constants
- func CommaGroupBigInt(n *big.Int) string
- func FormatTokenAmount(amount *big.Int, decimals uint8) string
- type AnalyzeRequest
- type AnalyzedBatchOperation
- type AnalyzedBatchOperationNode
- type AnalyzedBatchOperations
- type AnalyzedCall
- type AnalyzedCallNode
- func (a *AnalyzedCallNode) AdditionalFields() map[string]any
- func (a *AnalyzedCallNode) ContractType() string
- func (a *AnalyzedCallNode) ContractVersion() string
- func (a *AnalyzedCallNode) Data() []byte
- func (a *AnalyzedCallNode) Inputs() AnalyzedParameters
- func (a *AnalyzedCallNode) Name() string
- func (a *AnalyzedCallNode) Outputs() AnalyzedParameters
- func (a *AnalyzedCallNode) To() string
- type AnalyzedCalls
- type AnalyzedParameter
- type AnalyzedParameterNode
- type AnalyzedParameters
- type AnalyzedProposal
- type AnalyzedProposalNode
- type Annotation
- type AnnotationLevel
- type Annotations
- type BaseAnalyzer
- type BatchOperationAnalyzer
- type BatchOperationAnalyzerContext
- type BatchOperationAnalyzerContextNode
- type CallAnalyzer
- type CallAnalyzerContext
- type CallAnalyzerContextNode
- type DecodeInstructionFn
- type DecodedBatchOperation
- type DecodedBatchOperations
- type DecodedCall
- type DecodedCalls
- type DecodedParameter
- type DecodedParameters
- type DecodedTimelockProposal
- type DecoderConfig
- type DependencyAnnotationPredicate
- type DependencyAnnotationStore
- type DiffValue
- type ExecutionContext
- type ExecutionContextNode
- type ParameterAnalyzer
- type ParameterAnalyzerContext
- type ParameterAnalyzerContextNode
- type ProposalAnalyzeRequest
- type ProposalAnalyzer
- type ProposalDecoder
- type Registry
- func (r *Registry) All() []BaseAnalyzer
- func (r *Registry) BatchOperationAnalyzers() []BatchOperationAnalyzer
- func (r *Registry) CallAnalyzers() []CallAnalyzer
- func (r *Registry) Get(id string) (BaseAnalyzer, bool)
- func (r *Registry) List() []string
- func (r *Registry) ParameterAnalyzers() []ParameterAnalyzer
- func (r *Registry) ProposalAnalyzers() []ProposalAnalyzer
- func (r *Registry) Register(baseAnalyzer BaseAnalyzer) error
- type Risk
- type Severity
Constants ¶
const ( AnnotationSeverityName = annotation.AnnotationSeverityName AnnotationSeverityType = annotation.AnnotationSeverityType AnnotationRiskName = annotation.AnnotationRiskName AnnotationRiskType = annotation.AnnotationRiskType AnnotationDiffName = annotation.AnnotationDiffName AnnotationDiffType = annotation.AnnotationDiffType SeverityError = annotation.SeverityError SeverityWarning = annotation.SeverityWarning SeverityInfo = annotation.SeverityInfo SeverityDebug = annotation.SeverityDebug RiskHigh = annotation.RiskHigh RiskMedium = annotation.RiskMedium RiskLow = annotation.RiskLow )
const ( AnnotationLevelProposal = annotationstore.AnnotationLevelProposal AnnotationLevelBatchOperation = annotationstore.AnnotationLevelBatchOperation AnnotationLevelCall = annotationstore.AnnotationLevelCall AnnotationLevelParameter = annotationstore.AnnotationLevelParameter )
Variables ¶
This section is empty.
Functions ¶
func CommaGroupBigInt ¶ added in v0.85.1
Formatting helpers commonly used by analyzers and renderers.
Types ¶
type AnalyzeRequest ¶
type AnalyzeRequest[T any] struct { AnalyzerContext T ExecutionContext ExecutionContext DependencyAnnotationStore DependencyAnnotationStore }
AnalyzeRequest encapsulates the analyzer context, execution context, and annotation store passed to analyzer.
type AnalyzedBatchOperation ¶
type AnalyzedBatchOperation interface {
annotated.Annotated
ChainSelector() uint64
Calls() AnalyzedCalls
}
type AnalyzedBatchOperationNode ¶ added in v0.84.0
type AnalyzedBatchOperationNode struct {
annotated.BaseAnnotated
// contains filtered or unexported fields
}
func NewAnalyzedBatchOperationNode ¶ added in v0.84.0
func NewAnalyzedBatchOperationNode(chainSelector uint64, calls AnalyzedCalls) *AnalyzedBatchOperationNode
func (*AnalyzedBatchOperationNode) Calls ¶ added in v0.84.0
func (a *AnalyzedBatchOperationNode) Calls() AnalyzedCalls
func (*AnalyzedBatchOperationNode) ChainSelector ¶ added in v0.84.0
func (a *AnalyzedBatchOperationNode) ChainSelector() uint64
type AnalyzedBatchOperations ¶
type AnalyzedBatchOperations []AnalyzedBatchOperation
type AnalyzedCall ¶
type AnalyzedCallNode ¶ added in v0.84.0
type AnalyzedCallNode struct {
annotated.BaseAnnotated
// contains filtered or unexported fields
}
func NewAnalyzedCallNode ¶ added in v0.84.0
func NewAnalyzedCallNode( to, name string, inputs, outputs AnalyzedParameters, data []byte, contractType, contractVersion string, additional map[string]any, ) *AnalyzedCallNode
func (*AnalyzedCallNode) AdditionalFields ¶ added in v0.84.0
func (a *AnalyzedCallNode) AdditionalFields() map[string]any
AdditionalFields returns a copy of the call's additional metadata. It returns an empty map when no additional metadata is set.
func (*AnalyzedCallNode) ContractType ¶ added in v0.84.0
func (a *AnalyzedCallNode) ContractType() string
func (*AnalyzedCallNode) ContractVersion ¶ added in v0.84.0
func (a *AnalyzedCallNode) ContractVersion() string
func (*AnalyzedCallNode) Data ¶ added in v0.84.0
func (a *AnalyzedCallNode) Data() []byte
func (*AnalyzedCallNode) Inputs ¶ added in v0.84.0
func (a *AnalyzedCallNode) Inputs() AnalyzedParameters
func (*AnalyzedCallNode) Name ¶ added in v0.84.0
func (a *AnalyzedCallNode) Name() string
func (*AnalyzedCallNode) Outputs ¶ added in v0.84.0
func (a *AnalyzedCallNode) Outputs() AnalyzedParameters
func (*AnalyzedCallNode) To ¶ added in v0.84.0
func (a *AnalyzedCallNode) To() string
type AnalyzedCalls ¶
type AnalyzedCalls []AnalyzedCall
type AnalyzedParameter ¶
type AnalyzedParameterNode ¶ added in v0.84.0
type AnalyzedParameterNode struct {
annotated.BaseAnnotated
// contains filtered or unexported fields
}
func NewAnalyzedParameterNode ¶ added in v0.84.0
func NewAnalyzedParameterNode(name, atype string, value any) *AnalyzedParameterNode
func (*AnalyzedParameterNode) Name ¶ added in v0.84.0
func (a *AnalyzedParameterNode) Name() string
func (*AnalyzedParameterNode) Type ¶ added in v0.84.0
func (a *AnalyzedParameterNode) Type() string
func (*AnalyzedParameterNode) Value ¶ added in v0.84.0
func (a *AnalyzedParameterNode) Value() any
type AnalyzedParameters ¶
type AnalyzedParameters []AnalyzedParameter
type AnalyzedProposal ¶
type AnalyzedProposal interface {
annotated.Annotated
BatchOperations() AnalyzedBatchOperations
}
type AnalyzedProposalNode ¶ added in v0.84.0
type AnalyzedProposalNode struct {
annotated.BaseAnnotated
// contains filtered or unexported fields
}
func NewAnalyzedProposalNode ¶ added in v0.84.0
func NewAnalyzedProposalNode(batchOps AnalyzedBatchOperations) *AnalyzedProposalNode
func (*AnalyzedProposalNode) BatchOperations ¶ added in v0.84.0
func (a *AnalyzedProposalNode) BatchOperations() AnalyzedBatchOperations
type Annotation ¶
type Annotation = annotation.Annotation
Annotation types and helpers for analyzers.
func DiffAnnotation ¶ added in v0.85.1
func DiffAnnotation(field string, oldVal, newVal any, valueType string) Annotation
func NewAnnotation ¶ added in v0.85.1
func NewAnnotation(name, atype string, value any) Annotation
func RiskAnnotation ¶ added in v0.85.1
func RiskAnnotation(level Risk) Annotation
func SeverityAnnotation ¶ added in v0.85.1
func SeverityAnnotation(level Severity) Annotation
type AnnotationLevel ¶ added in v0.85.1
type AnnotationLevel = annotationstore.AnnotationLevel
Dependency annotation store types and helpers.
type Annotations ¶
type Annotations = annotation.Annotations
Annotation types and helpers for analyzers.
type BaseAnalyzer ¶
type BaseAnalyzer interface {
ID() string
// Dependencies returns the IDs of analyzers that must run before this analyzer.
//
// The returned strings MUST correspond to the ID() values of other registered analyzers.
// Implementations MUST NOT introduce circular dependencies (directly or indirectly).
// The engine uses this list to:
// - schedule analyzers in dependency order
// - scope AnnotationStore reads to only these dependency IDs
Dependencies() []string
}
type BatchOperationAnalyzer ¶
type BatchOperationAnalyzer interface {
BaseAnalyzer
CanAnalyze(ctx context.Context, req AnalyzeRequest[BatchOperationAnalyzerContext], operation DecodedBatchOperation) bool
Analyze(ctx context.Context, req AnalyzeRequest[BatchOperationAnalyzerContext], operation DecodedBatchOperation) (Annotations, error)
}
type BatchOperationAnalyzerContext ¶ added in v0.84.0
type BatchOperationAnalyzerContext interface {
// Proposal returns the current proposal-level context.
Proposal() DecodedTimelockProposal
}
type BatchOperationAnalyzerContextNode ¶ added in v0.84.0
type BatchOperationAnalyzerContextNode struct {
// contains filtered or unexported fields
}
BatchOperationAnalyzerContextNode is the default implementation of BatchOperationAnalyzerContext.
func NewBatchOperationAnalyzerContextNode ¶ added in v0.84.0
func NewBatchOperationAnalyzerContextNode( proposal decoder.DecodedTimelockProposal, ) *BatchOperationAnalyzerContextNode
NewBatchOperationAnalyzerContextNode constructs a batch operation analyzer context for analyzer runs.
func (*BatchOperationAnalyzerContextNode) Proposal ¶ added in v0.84.0
func (c *BatchOperationAnalyzerContextNode) Proposal() decoder.DecodedTimelockProposal
type CallAnalyzer ¶
type CallAnalyzer interface {
BaseAnalyzer
CanAnalyze(ctx context.Context, req AnalyzeRequest[CallAnalyzerContext], call DecodedCall) bool
Analyze(ctx context.Context, req AnalyzeRequest[CallAnalyzerContext], call DecodedCall) (Annotations, error)
}
type CallAnalyzerContext ¶ added in v0.84.0
type CallAnalyzerContext interface {
// Proposal returns the current proposal-level context.
Proposal() DecodedTimelockProposal
// BatchOperation returns the current batch operation context.
BatchOperation() DecodedBatchOperation
}
type CallAnalyzerContextNode ¶ added in v0.84.0
type CallAnalyzerContextNode struct {
// contains filtered or unexported fields
}
CallAnalyzerContextNode is the default implementation of CallAnalyzerContext.
func NewCallAnalyzerContextNode ¶ added in v0.84.0
func NewCallAnalyzerContextNode( proposal decoder.DecodedTimelockProposal, batchOperation decoder.DecodedBatchOperation, ) *CallAnalyzerContextNode
NewCallAnalyzerContextNode constructs a call analyzer context for analyzer runs.
func (*CallAnalyzerContextNode) BatchOperation ¶ added in v0.84.0
func (c *CallAnalyzerContextNode) BatchOperation() decoder.DecodedBatchOperation
func (*CallAnalyzerContextNode) Proposal ¶ added in v0.84.0
func (c *CallAnalyzerContextNode) Proposal() decoder.DecodedTimelockProposal
type DecodeInstructionFn ¶ added in v0.85.1
type DecodeInstructionFn = decoder.DecodeInstructionFn
Decoded proposal types passed to analyzers.
type DecodedBatchOperation ¶ added in v0.85.1
type DecodedBatchOperation = decoder.DecodedBatchOperation
Decoded proposal types passed to analyzers.
type DecodedBatchOperations ¶ added in v0.85.1
type DecodedBatchOperations = decoder.DecodedBatchOperations
Decoded proposal types passed to analyzers.
type DecodedCall ¶ added in v0.85.1
type DecodedCall = decoder.DecodedCall
Decoded proposal types passed to analyzers.
type DecodedCalls ¶ added in v0.85.1
type DecodedCalls = decoder.DecodedCalls
Decoded proposal types passed to analyzers.
type DecodedParameter ¶ added in v0.85.1
type DecodedParameter = decoder.DecodedParameter
Decoded proposal types passed to analyzers.
type DecodedParameters ¶ added in v0.85.1
type DecodedParameters = decoder.DecodedParameters
Decoded proposal types passed to analyzers.
type DecodedTimelockProposal ¶ added in v0.85.1
type DecodedTimelockProposal = decoder.DecodedTimelockProposal
Decoded proposal types passed to analyzers.
type DecoderConfig ¶ added in v0.85.1
Decoded proposal types passed to analyzers.
type DependencyAnnotationPredicate ¶ added in v0.85.1
type DependencyAnnotationPredicate = annotationstore.DependencyAnnotationPredicate
Dependency annotation store types and helpers.
func ByAnnotationAnalyzer ¶ added in v0.85.1
func ByAnnotationAnalyzer(analyzerID string) DependencyAnnotationPredicate
func ByAnnotationLevel ¶ added in v0.85.1
func ByAnnotationLevel(level AnnotationLevel) DependencyAnnotationPredicate
func ByAnnotationName ¶ added in v0.85.1
func ByAnnotationName(name string) DependencyAnnotationPredicate
func ByAnnotationType ¶ added in v0.85.1
func ByAnnotationType(atype string) DependencyAnnotationPredicate
type DependencyAnnotationStore ¶ added in v0.85.1
type DependencyAnnotationStore = annotationstore.DependencyAnnotationStore
Dependency annotation store types and helpers.
type DiffValue ¶ added in v0.85.1
type DiffValue = annotation.DiffValue
Annotation types and helpers for analyzers.
type ExecutionContext ¶
type ExecutionContext interface {
Domain() cldfdomain.Domain
EnvironmentName() string
BlockChains() chain.BlockChains
DataStore() datastore.DataStore
}
ExecutionContext encapsulates the execution context passed to an analyzer.
type ExecutionContextNode ¶ added in v0.84.0
type ExecutionContextNode struct {
// contains filtered or unexported fields
}
ExecutionContextNode is the default implementation of ExecutionContext.
func NewExecutionContextNode ¶ added in v0.84.0
func NewExecutionContextNode( domain cldfdomain.Domain, environmentName string, blockChains chain.BlockChains, dataStore datastore.DataStore, ) *ExecutionContextNode
NewExecutionContextNode constructs an execution context for analyzer runs.
func (*ExecutionContextNode) BlockChains ¶ added in v0.84.0
func (c *ExecutionContextNode) BlockChains() chain.BlockChains
func (*ExecutionContextNode) DataStore ¶ added in v0.84.0
func (c *ExecutionContextNode) DataStore() datastore.DataStore
func (*ExecutionContextNode) Domain ¶ added in v0.84.0
func (c *ExecutionContextNode) Domain() cldfdomain.Domain
func (*ExecutionContextNode) EnvironmentName ¶ added in v0.84.0
func (c *ExecutionContextNode) EnvironmentName() string
type ParameterAnalyzer ¶
type ParameterAnalyzer interface {
BaseAnalyzer
CanAnalyze(ctx context.Context, req AnalyzeRequest[ParameterAnalyzerContext], param DecodedParameter) bool
Analyze(ctx context.Context, req AnalyzeRequest[ParameterAnalyzerContext], param DecodedParameter) (Annotations, error)
}
type ParameterAnalyzerContext ¶ added in v0.84.0
type ParameterAnalyzerContext interface {
// Proposal returns the current proposal-level context.
Proposal() DecodedTimelockProposal
// BatchOperation returns the current batch operation context.
BatchOperation() DecodedBatchOperation
// Call returns the current call-level context.
Call() DecodedCall
}
type ParameterAnalyzerContextNode ¶ added in v0.84.0
type ParameterAnalyzerContextNode struct {
// contains filtered or unexported fields
}
ParameterAnalyzerContextNode is the default implementation of ParameterAnalyzerContext.
func NewParameterAnalyzerContextNode ¶ added in v0.84.0
func NewParameterAnalyzerContextNode( proposal decoder.DecodedTimelockProposal, batchOperation decoder.DecodedBatchOperation, call decoder.DecodedCall, ) *ParameterAnalyzerContextNode
NewParameterAnalyzerContextNode constructs a parameter analyzer context for analyzer runs.
func (*ParameterAnalyzerContextNode) BatchOperation ¶ added in v0.84.0
func (c *ParameterAnalyzerContextNode) BatchOperation() decoder.DecodedBatchOperation
func (*ParameterAnalyzerContextNode) Call ¶ added in v0.84.0
func (c *ParameterAnalyzerContextNode) Call() decoder.DecodedCall
func (*ParameterAnalyzerContextNode) Proposal ¶ added in v0.84.0
func (c *ParameterAnalyzerContextNode) Proposal() decoder.DecodedTimelockProposal
type ProposalAnalyzeRequest ¶ added in v0.84.0
type ProposalAnalyzeRequest struct {
ExecutionContext ExecutionContext
DependencyAnnotationStore DependencyAnnotationStore
}
ProposalAnalyzeRequest encapsulates the execution context and annotation store passed to a proposal analyzer.
type ProposalAnalyzer ¶
type ProposalAnalyzer interface {
BaseAnalyzer
CanAnalyze(ctx context.Context, req ProposalAnalyzeRequest, proposal DecodedTimelockProposal) bool
Analyze(ctx context.Context, req ProposalAnalyzeRequest, proposal DecodedTimelockProposal) (Annotations, error)
}
type ProposalDecoder ¶ added in v0.85.1
type ProposalDecoder = decoder.ProposalDecoder
Decoded proposal types passed to analyzers.
type Registry ¶ added in v0.84.0
type Registry struct {
// contains filtered or unexported fields
}
Registry manages analyzer registration and lookup.
func NewRegistry ¶ added in v0.84.0
func NewRegistry() *Registry
NewRegistry creates a new analyzer registry.
func (*Registry) All ¶ added in v0.84.0
func (r *Registry) All() []BaseAnalyzer
All returns all registered analyzers in deterministic ID order.
func (*Registry) BatchOperationAnalyzers ¶ added in v0.84.0
func (r *Registry) BatchOperationAnalyzers() []BatchOperationAnalyzer
BatchOperationAnalyzers returns registered batch operation analyzers.
func (*Registry) CallAnalyzers ¶ added in v0.84.0
func (r *Registry) CallAnalyzers() []CallAnalyzer
CallAnalyzers returns registered call analyzers.
func (*Registry) Get ¶ added in v0.84.0
func (r *Registry) Get(id string) (BaseAnalyzer, bool)
Get retrieves an analyzer by ID.
func (*Registry) ParameterAnalyzers ¶ added in v0.84.0
func (r *Registry) ParameterAnalyzers() []ParameterAnalyzer
ParameterAnalyzers returns registered parameter analyzers.
func (*Registry) ProposalAnalyzers ¶ added in v0.84.0
func (r *Registry) ProposalAnalyzers() []ProposalAnalyzer
ProposalAnalyzers returns registered proposal analyzers.
func (*Registry) Register ¶ added in v0.84.0
func (r *Registry) Register(baseAnalyzer BaseAnalyzer) error
Register adds an analyzer to the registry. Returns an error if: - analyzer is nil - analyzer ID is empty - an analyzer with the same ID is already registered - analyzer type is unsupported
type Risk ¶ added in v0.85.1
type Risk = annotation.Risk
Annotation types and helpers for analyzers.
type Severity ¶ added in v0.85.1
type Severity = annotation.Severity
Annotation types and helpers for analyzers.