Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions deployment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rpc"
"github.com/smartcontractkit/chainlink-deployments-framework/experimental/exceptions"

"github.com/smartcontractkit/chainlink-deployments-framework/chain"
"github.com/smartcontractkit/chainlink-deployments-framework/chain/evm"
Expand Down Expand Up @@ -60,6 +61,8 @@ type Environment struct {
OperationsBundle operations.Bundle
// BlockChains is the container of all chains in the environment.
BlockChains chain.BlockChains

Exceptions *exceptions.Exceptions
}

// EnvironmentOption is a functional option for configuring an Environment
Expand Down
11 changes: 11 additions & 0 deletions engine/cld/domain/envdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/internal/fileutils"
"github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/internal/jsonutils"
"github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/nodes"
"github.com/smartcontractkit/chainlink-deployments-framework/experimental/exceptions"
)

// EnvDir represents a specific environment directory within a domain.
Expand Down Expand Up @@ -469,3 +470,13 @@ func (d EnvDir) CreateDurablePipelinesDir() error {
func (d EnvDir) SaveViewState(v json.Marshaler) error {
return SaveViewState(d.ViewStateFilePath(), v)
}

// ExceptionsFilePath returns the path to the exceptions file for the domain's environment directory.
func (d EnvDir) ExceptionsFilePath() string {
return filepath.Join(d.DirPath(), ExceptionsFileName)
}

// LoadExceptions loads the exceptions from the exceptions file for the domain's environment directory.
func (d EnvDir) LoadExceptions() (*exceptions.Exceptions, error) {
return exceptions.Load(d.ExceptionsFilePath())
}
4 changes: 4 additions & 0 deletions engine/cld/domain/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,8 @@ const (
// DurablePipelineInputsDirName is the name of the directory containing the inputs
// for the durable pipelines.
DurablePipelineInputsDirName = "inputs"

// ExceptionsFileName is the name of the file containing exceptions.
// At the moment, this is only used for CCIP domain.
ExceptionsFileName = "exceptions.yaml"
)
6 changes: 6 additions & 0 deletions engine/cld/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ func Load(
}
}

exceptions, err := envdir.LoadExceptions()
if err != nil {
return fdeployment.Environment{}, fmt.Errorf("failed to load exceptions: %w", err)
}

getCtx := func() context.Context { return ctx }

return fdeployment.Environment{
Expand All @@ -141,5 +146,6 @@ func Load(
OCRSecrets: sharedSecrets,
OperationsBundle: operations.NewBundle(getCtx, lggr, loadcfg.reporter, operations.WithOperationRegistry(loadcfg.operationRegistry)),
BlockChains: blockChains,
Exceptions: exceptions,
}, nil
}
62 changes: 62 additions & 0 deletions experimental/exceptions/exceptions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package exceptions

import (
"os"

"github.com/ethereum/go-ethereum/common"
"gopkg.in/yaml.v3"
)

// ExceptionType defines the type of exception.
type ExceptionType string

const (
ExceptionTypeRateLimit ExceptionType = "RateLimit"
ExceptionTypeDeprecated ExceptionType = "Deprecated"
)

// Exception represents a single exception entry.
type Exception struct {
Resource string `yaml:"resource"`
Address common.Address `yaml:"address"`
Reason string `yaml:"reason"`
Type ExceptionType `yaml:"type"`
}

// Exceptions holds a mapping of network names to their respective exceptions.
type Exceptions struct {
Exceptions map[string][]Exception `yaml:"exceptions"`
}

// Load loads exceptions from a YAML file at the specified path.
func Load(filePath string) (*Exceptions, error) {
d, err := os.ReadFile(filePath)
if err != nil {
return nil, err
}

var e Exceptions
if err := yaml.Unmarshal(d, &e); err != nil {
return nil, err
}

return &e, nil
}

// IsExpected checks if the given address on the specified network is an expected exception of the given type.
func (e *Exceptions) IsExpected(network string, address common.Address, exceptionType ExceptionType) (bool, string) {
if _, ok := e.Exceptions[network]; ok {
return e.isAddressExpected(network, address, exceptionType)
}
return false, ""
}

// isAddressExpected checks if the address is in the exceptions for the given network and type.
func (e *Exceptions) isAddressExpected(network string, address common.Address, exceptionType ExceptionType) (bool, string) {
for _, exception := range e.Exceptions[network] {
if exception.Address == address && exception.Type == exceptionType {
return true, exception.Reason
}
}
return false, ""
}
Loading