|
| 1 | +package analyzer |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + "github.com/smartcontractkit/chainlink-deployments-framework/chain" |
| 7 | + "github.com/smartcontractkit/chainlink-deployments-framework/datastore" |
| 8 | + cldfdomain "github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/domain" |
| 9 | + "github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/mcms/proposalanalysis/decoder" |
| 10 | +) |
| 11 | + |
| 12 | +// AnalyzerContext provides access to the current stage of analysis within the proposal structure. |
| 13 | +// Only some accessor methods are relevant depending on which analyzer type is being executed. |
| 14 | +// Analysis proceeds from the most granular components (parameters), up through calls and batch operations, to the full proposal. |
| 15 | +// Therefore, context accessors are applicable for the current and higher (ancestor) analysis levels. |
| 16 | +// Accessors may return zero values when invoked at stages where corresponding context is not available. |
| 17 | +type AnalyzerContext interface { |
| 18 | + // Proposal returns the current proposal-level context. |
| 19 | + // This is primarily meaningful for ProposalAnalyzer execution. |
| 20 | + Proposal() AnalyzedProposal |
| 21 | + // BatchOperation returns the current batch operation context. |
| 22 | + // This is primarily meaningful for ProposalAnalyzer and BatchOperationAnalyzer execution. |
| 23 | + BatchOperation() AnalyzedBatchOperation |
| 24 | + // Call returns the current call-level context. |
| 25 | + // This is primarily meaningful for ProposalAnalyzer, BatchOperationAnalyzer and CallAnalyzer execution. |
| 26 | + Call() AnalyzedCall |
| 27 | + |
| 28 | + // GetAnnotationsFrom returns annotations from a specific analyzer. |
| 29 | + // This is useful for accessing results from dependency analyzers. |
| 30 | + // Returns empty slice if the analyzer ID is not found or no annotations exist. |
| 31 | + GetAnnotationsFrom(analyzerID string) Annotations |
| 32 | +} |
| 33 | + |
| 34 | +type ExecutionContext interface { |
| 35 | + Domain() cldfdomain.Domain |
| 36 | + EnvironmentName() string |
| 37 | + BlockChains() chain.BlockChains |
| 38 | + DataStore() datastore.DataStore |
| 39 | +} |
| 40 | + |
| 41 | +// AnalyzeRequest encapsulates the analyzer and execution contexts passed to analyzer methods. |
| 42 | +type AnalyzeRequest struct { |
| 43 | + AnalyzerContext AnalyzerContext |
| 44 | + ExecutionContext ExecutionContext |
| 45 | +} |
| 46 | + |
| 47 | +type BaseAnalyzer interface { |
| 48 | + ID() string |
| 49 | + // Dependencies returns the IDs of analyzers that must run before this analyzer. |
| 50 | + // |
| 51 | + // The returned strings MUST correspond to the ID() values of other registered analyzers. |
| 52 | + // Implementations MUST NOT introduce circular dependencies (directly or indirectly). |
| 53 | + // |
| 54 | + // Analyzers may depend only on other analyzers of the same type. |
| 55 | + // For example, a ProposalAnalyzer may only depend on other ProposalAnalyzer instances, |
| 56 | + // a BatchOperationAnalyzer may only depend on other BatchOperationAnalyzer instances, |
| 57 | + // and a CallAnalyzer may only depend on other CallAnalyzer instances. |
| 58 | + // This restriction exists because analyzers of different types are already executed in a fixed dependency order: |
| 59 | + // parameter analyzers run before call analyzers, which run before batch operation analyzers, which in turn run before proposal analyzers. |
| 60 | + Dependencies() []string |
| 61 | +} |
| 62 | + |
| 63 | +type ProposalAnalyzer interface { |
| 64 | + BaseAnalyzer |
| 65 | + CanAnalyze(ctx context.Context, req AnalyzeRequest, proposal decoder.DecodedTimelockProposal) bool |
| 66 | + Analyze(ctx context.Context, req AnalyzeRequest, proposal decoder.DecodedTimelockProposal) (Annotations, error) |
| 67 | +} |
| 68 | + |
| 69 | +type BatchOperationAnalyzer interface { |
| 70 | + BaseAnalyzer |
| 71 | + CanAnalyze(ctx context.Context, req AnalyzeRequest, operation decoder.DecodedBatchOperation) bool |
| 72 | + Analyze(ctx context.Context, req AnalyzeRequest, operation decoder.DecodedBatchOperation) (Annotations, error) |
| 73 | +} |
| 74 | + |
| 75 | +type CallAnalyzer interface { |
| 76 | + BaseAnalyzer |
| 77 | + CanAnalyze(ctx context.Context, req AnalyzeRequest, call decoder.DecodedCall) bool |
| 78 | + Analyze(ctx context.Context, req AnalyzeRequest, call decoder.DecodedCall) (Annotations, error) |
| 79 | +} |
| 80 | + |
| 81 | +type ParameterAnalyzer interface { |
| 82 | + BaseAnalyzer |
| 83 | + CanAnalyze(ctx context.Context, req AnalyzeRequest, param decoder.DecodedParameter) bool |
| 84 | + Analyze(ctx context.Context, req AnalyzeRequest, param decoder.DecodedParameter) (Annotations, error) |
| 85 | +} |
0 commit comments