proposalanalysis

package
v0.84.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package proposalanalysis provides an engine for analyzing MCMS timelock proposals and rendering the analyzed output.

Overview

The engine workflow is:

  1. Create an engine with optional configuration.
  2. Register one or more analyzers.
  3. Register a renderer.
  4. Run analysis on a proposal.
  5. Render the analyzed proposal with RenderTo.

Usage

import (
	"context"
	"os"
	"time"

	"github.com/smartcontractkit/mcms"

	"github.com/smartcontractkit/chainlink-deployments-framework/deployment"
	cldfdomain "github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/domain"
	"github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/mcms/proposalanalysis"
	"github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/mcms/proposalanalysis/decoder"
	"github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/mcms/proposalanalysis/renderer"
)

func Example() error {
	ctx := context.Background()

	engine := proposalanalysis.NewAnalyzerEngine(
		proposalanalysis.WithAnalyzerTimeout(90*time.Second),
	)

	// Register your analyzers (implementations omitted for brevity).
	if err := engine.RegisterAnalyzer(newDependencyAnalyzer()); err != nil {
		return err
	}
	if err := engine.RegisterAnalyzer(newRiskAnalyzer()); err != nil {
		return err
	}

	mdRenderer, err := renderer.NewMarkdownRenderer()
	if err != nil {
		return err
	}
	if err := engine.RegisterRenderer(mdRenderer); err != nil {
		return err
	}

	domain := cldfdomain.NewDomain("/path/to/domains", "ccip")
	env := ...
	proposal := ...

	analyzed, err := engine.Run(ctx, proposalanalysis.RunRequest{
		Domain:        domain,
		Environment:   env,
		DecoderConfig: decoder.Config{},
	}, proposal)
	if err != nil {
		return err
	}

	return engine.RenderTo(
		os.Stdout,
		renderer.IDMarkdown,
		renderer.RenderRequest{
			Domain:          domain.Key(),
			EnvironmentName: env.Name,
		},
		analyzed,
	)
}

Index

Constants

View Source
const DefaultAnalyzerTimeout = 2 * time.Minute

DefaultAnalyzerTimeout is the default timeout budget for a single analyzer invocation, including both CanAnalyze and Analyze.

Variables

This section is empty.

Functions

func ApplyEngineOptions added in v0.84.0

func ApplyEngineOptions(opts ...EngineOption) *engineConfig

ApplyEngineOptions applies all engine options and returns the configuration This is used internally by the engine implementation

Types

type AnalyzerEngine

type AnalyzerEngine interface {
	Run(ctx context.Context, req RunRequest, proposal *mcms.TimelockProposal) (analyzer.AnalyzedProposal, error)

	RegisterAnalyzer(analyzer analyzer.BaseAnalyzer) error

	RegisterRenderer(renderer renderer.Renderer) error

	RenderTo(w io.Writer, rendererID string, renderReq renderer.RenderRequest, proposal analyzer.AnalyzedProposal) error
}

func NewAnalyzerEngine added in v0.84.0

func NewAnalyzerEngine(opts ...EngineOption) AnalyzerEngine

NewAnalyzerEngine creates a new AnalyzerEngine with the given options.

type Deps added in v0.84.0

type Deps struct {
	DecoderFactory func(cfg decoder.Config) (decoder.ProposalDecoder, error)
}

type EngineOption added in v0.84.0

type EngineOption func(*engineConfig)

EngineOption configures the analyzer engine using the functional options pattern

func WithAnalyzerTimeout added in v0.84.0

func WithAnalyzerTimeout(timeout time.Duration) EngineOption

WithAnalyzerTimeout allows configuring the timeout for analyzer execution Each analyzer will be given this amount of time to complete before being cancelled This is important for analyzers that make network calls or other long-running operations Default is 2 minutes if not specified

Example:

engine := proposalanalysis.NewAnalyzerEngine(
    proposalanalysis.WithAnalyzerTimeout(2 * time.Minute),
)

type RunRequest added in v0.84.0

type RunRequest struct {
	Domain        cldfdomain.Domain
	Environment   *deployment.Environment
	DecoderConfig decoder.Config
}

RunRequest encapsulates the domain, environment, and decoder configuration

Directories

Path Synopsis
Package analyzer defines analyzer interfaces used by the proposal analysis engine.
Package analyzer defines analyzer interfaces used by the proposal analysis engine.
Package renderer defines renderer interfaces used to format analyzed proposals.
Package renderer defines renderer interfaces used to format analyzed proposals.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL