Skip to content

Commit

Permalink
Finality violation detection. (#387)
Browse files Browse the repository at this point in the history
  • Loading branch information
winder authored Dec 19, 2024
1 parent f9157a7 commit 8c8e37e
Show file tree
Hide file tree
Showing 10 changed files with 472 additions and 12 deletions.
7 changes: 5 additions & 2 deletions commit/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,17 @@ func (p *PluginFactory) NewReportingPlugin(ctx context.Context, config ocr3types
oracleIDToP2PID[commontypes.OracleID(oracleID)] = node.P2pID
}

// map types to the facade.
// Map contract readers to ContractReaderFacade:
// - Extended reader adds finality violation and contract binding management.
// - Observed reader adds metric reporting.
readers := make(map[cciptypes.ChainSelector]contractreader.ContractReaderFacade, len(p.contractReaders))
for chain, cr := range p.contractReaders {
chainID, err1 := sel.GetChainIDFromSelector(uint64(chain))
if err1 != nil {
return nil, ocr3types.ReportingPluginInfo{}, fmt.Errorf("failed to get chain id from selector: %w", err1)
}
readers[chain] = contractreader.NewObserverReader(cr, lggr, chainID)
readers[chain] = contractreader.NewExtendedContractReader(
contractreader.NewObserverReader(cr, lggr, chainID))
}

// Bind the RMNHome contract
Expand Down
7 changes: 5 additions & 2 deletions execute/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,17 @@ func (p PluginFactory) NewReportingPlugin(
oracleIDToP2PID[commontypes.OracleID(oracleID)] = node.P2pID
}

// map types to the facade.
// Map contract readers to ContractReaderFacade:
// - Extended reader adds finality violation and contract binding management.
// - Observed reader adds metric reporting.
readers := make(map[cciptypes.ChainSelector]contractreader.ContractReaderFacade)
for chain, cr := range p.contractReaders {
chainID, err1 := sel.GetChainIDFromSelector(uint64(chain))
if err1 != nil {
return nil, ocr3types.ReportingPluginInfo{}, fmt.Errorf("failed to get chain id from selector: %w", err1)
}
readers[chain] = contractreader.NewObserverReader(cr, lggr, chainID)
readers[chain] = contractreader.NewExtendedContractReader(
contractreader.NewObserverReader(cr, lggr, chainID))
}

ccipReader := readerpkg.NewCCIPChainReader(
Expand Down
47 changes: 47 additions & 0 deletions mocks/pkg/contractreader/contract_reader_facade.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

265 changes: 265 additions & 0 deletions mocks/pkg/contractreader/extended.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion pkg/contractreader/contractreader_facade.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

// ContractReaderFacade wraps the public functions of ContractReader in chainlink-common so that we can mock it.
// See types.ContractReader in chainlink-common/pkg/types/contract_reader.go for details.
//
//nolint:lll // don't read this interface.
type ContractReaderFacade interface {
Expand All @@ -17,5 +18,11 @@ type ContractReaderFacade interface {
Bind(ctx context.Context, bindings []types.BoundContract) error
Unbind(ctx context.Context, bindings []types.BoundContract) error
QueryKey(ctx context.Context, contract types.BoundContract, filter query.KeyFilter, limitAndSort query.LimitAndSort, sequenceDataType any) ([]types.Sequence, error)
//mustEmbedUnimplementedContractReaderServer()

// HealthReport returns a full health report of the callee including its dependencies.
// Keys are based on Name(), with nil values when healthy or errors otherwise.
// Use CopyHealth to collect reports from sub-services.
// This should run very fast, so avoid doing computation and instead prefer reporting pre-calculated state.
// On finality violation report must contain at least one ErrFinalityViolation.
HealthReport() map[string]error
}
Loading

0 comments on commit 8c8e37e

Please sign in to comment.