-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exec NewReportingPlugin must not error (#894)
## Motivation Previously, any single error during the call to NewReportingPlugin for the Exec plugin would cause the OCR instance to not start. Even if the error was transient and would be resolved if NewReportingPlugin was called again, the OCR instance would remain down. ## Solution In order to be robust to transient errors, NewReportingPlugin is retried until it succeeds.
- Loading branch information
Showing
17 changed files
with
219 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"ccip": patch | ||
--- | ||
|
||
#bugfix Exec NewReportingPlugin retries until it succeeds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package ccipexec | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
"time" | ||
|
||
"github.com/smartcontractkit/libocr/offchainreporting2plus/types" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
|
||
"github.com/smartcontractkit/chainlink-common/pkg/types/ccip" | ||
"github.com/smartcontractkit/chainlink/v2/core/logger" | ||
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata" | ||
ccipdataprovidermocks "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata/ccipdataprovider/mocks" | ||
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata/mocks" | ||
) | ||
|
||
// Assert that NewReportingPlugin keeps retrying until it succeeds. | ||
// | ||
// NewReportingPlugin makes several calls (e.g. OffRampReader.ChangeConfig()) that can fail. We use mocks to cause the | ||
// first call to each of these functions to fail, then all subsequent calls succeed. We assert that NewReportingPlugin | ||
// retries a sufficient number of times to get through the transient errors and eventually succeed. | ||
func TestNewReportingPluginRetriesUntilSuccess(t *testing.T) { | ||
execConfig := ExecutionPluginStaticConfig{} | ||
|
||
// For this unit test, ensure that there is no delay between retries | ||
execConfig.newReportingPluginRetryConfig = ccipdata.RetryConfig{ | ||
InitialDelay: 0 * time.Nanosecond, | ||
MaxDelay: 0 * time.Nanosecond, | ||
} | ||
|
||
// Set up the OffRampReader mock | ||
mockOffRampReader := new(mocks.OffRampReader) | ||
|
||
// The first call is set to return an error, the following calls return a nil error | ||
mockOffRampReader.On("ChangeConfig", mock.Anything, mock.Anything, mock.Anything).Return(ccip.Address(""), ccip.Address(""), errors.New("")).Once() | ||
mockOffRampReader.On("ChangeConfig", mock.Anything, mock.Anything, mock.Anything).Return(ccip.Address("addr1"), ccip.Address("addr2"), nil).Times(5) | ||
|
||
mockOffRampReader.On("OffchainConfig", mock.Anything).Return(ccip.ExecOffchainConfig{}, errors.New("")).Once() | ||
mockOffRampReader.On("OffchainConfig", mock.Anything).Return(ccip.ExecOffchainConfig{}, nil).Times(3) | ||
|
||
mockOffRampReader.On("GasPriceEstimator", mock.Anything).Return(nil, errors.New("")).Once() | ||
mockOffRampReader.On("GasPriceEstimator", mock.Anything).Return(nil, nil).Times(2) | ||
|
||
mockOffRampReader.On("OnchainConfig", mock.Anything).Return(ccip.ExecOnchainConfig{}, errors.New("")).Once() | ||
mockOffRampReader.On("OnchainConfig", mock.Anything).Return(ccip.ExecOnchainConfig{}, nil).Times(1) | ||
|
||
execConfig.offRampReader = mockOffRampReader | ||
|
||
// Set up the PriceRegistry mock | ||
priceRegistryProvider := new(ccipdataprovidermocks.PriceRegistry) | ||
priceRegistryProvider.On("NewPriceRegistryReader", mock.Anything, mock.Anything).Return(nil, errors.New("")).Once() | ||
priceRegistryProvider.On("NewPriceRegistryReader", mock.Anything, mock.Anything).Return(nil, nil).Once() | ||
execConfig.priceRegistryProvider = priceRegistryProvider | ||
|
||
execConfig.lggr, _ = logger.NewLogger() | ||
|
||
factory := NewExecutionReportingPluginFactory(execConfig) | ||
reportingConfig := types.ReportingPluginConfig{} | ||
reportingConfig.OnchainConfig = []byte{1, 2, 3} | ||
reportingConfig.OffchainConfig = []byte{1, 2, 3} | ||
|
||
// Assert that NewReportingPlugin succeeds despite many transient internal failures (mocked out above) | ||
_, _, err := factory.NewReportingPlugin(reportingConfig) | ||
assert.Equal(t, nil, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
core/services/ocr2/plugins/ccip/internal/ccipdata/retry_config.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package ccipdata | ||
|
||
import "time" | ||
|
||
// RetryConfig configures an initial delay between retries and a max delay between retries | ||
type RetryConfig struct { | ||
InitialDelay time.Duration | ||
MaxDelay time.Duration | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.