Skip to content

Commit

Permalink
use GetTransactionStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
0xnogo committed Jul 25, 2024
1 parent 0adfda8 commit 6d75048
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion core/services/ocr2/plugins/ccip/ccipexec/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (rf *ExecutionReportingPluginFactory) NewReportingPluginFn(config types.Rep
return reportingPluginAndInfo{}, fmt.Errorf("get onchain config from offramp: %w", err)
}

batchingStrategy, err := NewBatchingStrategy(offchainConfig.BatchingStrategyID, statuschecker.NewTxmStatusChecker(rf.config.txManager))
batchingStrategy, err := NewBatchingStrategy(offchainConfig.BatchingStrategyID, statuschecker.NewTxmStatusChecker(rf.config.getTransactionStatus))
if err != nil {
return reportingPluginAndInfo{}, fmt.Errorf("get batching strategy: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion core/services/ocr2/plugins/ccip/ccipexec/initializers.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func NewExecServices(ctx context.Context, lggr logger.Logger, jb job.Job, srcPro
metricsCollector: metricsCollector,
chainHealthcheck: chainHealthcheck,
newReportingPluginRetryConfig: defaultNewReportingPluginRetryConfig,
txManager: dstChain.TxManager(),
getTransactionStatus: dstProvider.GetTransactionStatus,
})

argsNoPlugin.ReportingPluginFactory = promwrapper.NewPromFactory(wrappedPluginFactory, "CCIPExecution", jb.OCR2OracleSpec.Relay, big.NewInt(0).SetInt64(dstChainID))
Expand Down
7 changes: 4 additions & 3 deletions core/services/ocr2/plugins/ccip/ccipexec/ocr2.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ import (
"github.com/smartcontractkit/libocr/offchainreporting2plus/types"

"github.com/smartcontractkit/chainlink-common/pkg/hashutil"
commontypes "github.com/smartcontractkit/chainlink-common/pkg/types"
cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccip"

"github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/cache"
Expand Down Expand Up @@ -50,6 +49,8 @@ var (
_ types.ReportingPlugin = &ExecutionReportingPlugin{}
)

type GetTransactionStatusFunc func(ctx context.Context, transactionID string) (commontypes.TransactionStatus, error)

type ExecutionPluginStaticConfig struct {
lggr logger.Logger
onRampReader ccipdata.OnRampReader
Expand All @@ -64,7 +65,7 @@ type ExecutionPluginStaticConfig struct {
metricsCollector ccip.PluginMetricsCollector
chainHealthcheck cache.ChainHealthcheck
newReportingPluginRetryConfig ccipdata.RetryConfig
txManager txmgr.TxManager
getTransactionStatus GetTransactionStatusFunc
}

type ExecutionReportingPlugin struct {
Expand Down
2 changes: 1 addition & 1 deletion core/services/relay/evm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ func generateTransmitterFrom(ctx context.Context, rargs commontypes.RelayArgs, e
checker,
configWatcher.chain.ID(),
ethKeystore,
statuschecker.NewTxmStatusChecker(configWatcher.chain.TxManager()),
statuschecker.NewTxmStatusChecker(configWatcher.chain.TxManager().GetTransactionStatus),
)
default:
transmitter, err = ocrcommon.NewTransmitter(
Expand Down
9 changes: 4 additions & 5 deletions core/services/relay/evm/statuschecker/txm_status_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strings"

"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr"
)

// CCIPTransactionStatusChecker is an interface that defines the method for checking the status of a transaction.
Expand All @@ -19,11 +18,11 @@ type CCIPTransactionStatusChecker interface {
}

type TxmStatusChecker struct {
txManager txmgr.TxManager
getTransactionStatus func(ctx context.Context, transactionID string) (types.TransactionStatus, error)
}

func NewTxmStatusChecker(txManager txmgr.TxManager) *TxmStatusChecker {
return &TxmStatusChecker{txManager: txManager}
func NewTxmStatusChecker(getTransactionStatus func(ctx context.Context, transactionID string) (types.TransactionStatus, error)) *TxmStatusChecker {
return &TxmStatusChecker{getTransactionStatus: getTransactionStatus}
}

// CheckMessageStatus checks the status of a message by checking the status of all transactions associated with the message ID.
Expand All @@ -37,7 +36,7 @@ func (tsc *TxmStatusChecker) CheckMessageStatus(ctx context.Context, msgID strin

for {
transactionID := fmt.Sprintf("%s-%d", msgID, counter)
status, err := tsc.txManager.GetTransactionStatus(ctx, transactionID)
status, err := tsc.getTransactionStatus(ctx, transactionID)
if err != nil {
if strings.Contains(err.Error(), fmt.Sprintf("failed to find transaction with IdempotencyKey %s", transactionID)) {
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func Test_CheckMessageStatus(t *testing.T) {
testutils.SkipShort(t, "")
ctx := context.Background()
mockTxManager := mocks.NewMockEvmTxManager(t)
checker := NewTxmStatusChecker(mockTxManager)
checker := NewTxmStatusChecker(mockTxManager.GetTransactionStatus)

msgID := "test-message-id"

Expand Down Expand Up @@ -111,7 +111,7 @@ func Test_CheckMessageStatus(t *testing.T) {
func Test_FailForMoreThan1000Retries(t *testing.T) {
ctx := context.Background()
mockTxManager := mocks.NewMockEvmTxManager(t)
checker := NewTxmStatusChecker(mockTxManager)
checker := NewTxmStatusChecker(mockTxManager.GetTransactionStatus)

for i := 0; i < 1000; i++ {
mockTxManager.On("GetTransactionStatus", ctx, fmt.Sprintf("test-message-id-%d", i)).Return(types.Finalized, nil)
Expand Down

0 comments on commit 6d75048

Please sign in to comment.