-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Commit NewReportingPlugin retries on error (#1160)
Previously, if there was an error when starting the Commit Pluging (i.e. calling NewReportingPlugin), the Commit Plugin would remain in a non-started state. Now, NewReportingPlugin will retry until the Commit Plugin successfully starts. Co-authored-by: dimitris <[email protected]>
- Loading branch information
1 parent
a6a501c
commit 1214c29
Showing
5 changed files
with
167 additions
and
34 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 | ||
--- | ||
|
||
Commit NewReportingPlugin retries on error |
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
100 changes: 100 additions & 0 deletions
100
core/services/ocr2/plugins/ccip/ccipcommit/factory_test.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,100 @@ | ||
package ccipcommit | ||
|
||
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" | ||
dbMocks "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdb/mocks" | ||
) | ||
|
||
// Assert that NewReportingPlugin keeps retrying until it succeeds. | ||
// | ||
// NewReportingPlugin makes several calls (e.g. CommitStoreReader.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) { | ||
commitConfig := CommitPluginStaticConfig{} | ||
|
||
// For this unit test, ensure that there is no delay between retries | ||
commitConfig.newReportingPluginRetryConfig = ccipdata.RetryConfig{ | ||
InitialDelay: 0 * time.Nanosecond, | ||
MaxDelay: 0 * time.Nanosecond, | ||
} | ||
|
||
// Set up the OffRampReader mock | ||
mockCommitStore := new(mocks.CommitStoreReader) | ||
|
||
// The first call is set to return an error, the following calls return a nil error | ||
mockCommitStore. | ||
On("ChangeConfig", mock.Anything, mock.Anything, mock.Anything). | ||
Return(ccip.Address(""), errors.New("")). | ||
Once() | ||
mockCommitStore. | ||
On("ChangeConfig", mock.Anything, mock.Anything, mock.Anything). | ||
Return(ccip.Address("0x7c6e4F0BDe29f83BC394B75a7f313B7E5DbD2d77"), nil). | ||
Times(5) | ||
|
||
mockCommitStore. | ||
On("OffchainConfig", mock.Anything). | ||
Return(ccip.CommitOffchainConfig{}, errors.New("")). | ||
Once() | ||
mockCommitStore. | ||
On("OffchainConfig", mock.Anything). | ||
Return(ccip.CommitOffchainConfig{}, nil). | ||
Times(3) | ||
|
||
mockCommitStore. | ||
On("GasPriceEstimator", mock.Anything). | ||
Return(nil, errors.New("")). | ||
Once() | ||
mockCommitStore. | ||
On("GasPriceEstimator", mock.Anything). | ||
Return(nil, nil). | ||
Times(2) | ||
|
||
commitConfig.commitStore = mockCommitStore | ||
|
||
mockPriceService := new(dbMocks.PriceService) | ||
|
||
mockPriceService. | ||
On("UpdateDynamicConfig", mock.Anything, mock.Anything, mock.Anything). | ||
Return(errors.New("")). | ||
Once() | ||
mockPriceService. | ||
On("UpdateDynamicConfig", mock.Anything, mock.Anything, mock.Anything). | ||
Return(nil) | ||
|
||
commitConfig.priceService = mockPriceService | ||
|
||
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() | ||
commitConfig.priceRegistryProvider = priceRegistryProvider | ||
|
||
commitConfig.lggr, _ = logger.NewLogger() | ||
|
||
factory := NewCommitReportingPluginFactory(commitConfig) | ||
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