Skip to content

Commit

Permalink
Logs failed transactions into beholder
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzaldysanchez committed Nov 11, 2024
1 parent 340a6bf commit e791f21
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
37 changes: 36 additions & 1 deletion core/capabilities/targets/write_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import (
"encoding/hex"
"fmt"
"math/big"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/google/uuid"

"github.com/smartcontractkit/chainlink-common/pkg/capabilities"
"github.com/smartcontractkit/chainlink-common/pkg/capabilities/consensus/ocr3/types"
"github.com/smartcontractkit/chainlink-common/pkg/custmsg"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
commontypes "github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/query/primitives"
Expand All @@ -22,6 +24,8 @@ var (
_ capabilities.TargetCapability = &WriteTarget{}
)

const transactionStatusCheckInterval = 2 * time.Second

type WriteTarget struct {
cr ContractValueGetter
cw commontypes.ChainWriter
Expand All @@ -31,6 +35,9 @@ type WriteTarget struct {
receiverGasMinimum uint64
capabilities.CapabilityInfo

// emitter is used to emit messages from the WASM module to a configured collector.
emitter custmsg.MessageEmitter

lggr logger.Logger

bound bool
Expand Down Expand Up @@ -79,6 +86,7 @@ func NewWriteTarget(
forwarderAddress,
txGasLimit - ForwarderContractLogicGasCost,
info,
custmsg.NewLabeler(),
logger.Named(lggr, "WriteTarget"),
false,
}
Expand Down Expand Up @@ -309,7 +317,34 @@ func (cap *WriteTarget) Execute(ctx context.Context, rawRequest capabilities.Cap
}

cap.lggr.Debugw("Transaction submitted", "request", request, "transaction", txID)
return capabilities.CapabilityResponse{}, nil

tick := time.NewTicker(transactionStatusCheckInterval)
defer tick.Stop()
for {
select {
case <-ctx.Done():
return capabilities.CapabilityResponse{}, nil
case <-tick.C:
txStatus, err := cap.cw.GetTransactionStatus(ctx, txID.String())
if err != nil {

Check failure on line 329 in core/capabilities/targets/write_target.go

View workflow job for this annotation

GitHub Actions / lint

empty-block: this block is empty, you can remove it (revive)

}
switch txStatus {
case commontypes.Finalized:
cap.lggr.Debugw("Transaction finalized", "request", request, "transaction", txID)
return capabilities.CapabilityResponse{}, nil
case commontypes.Failed, commontypes.Fatal:
cap.lggr.Error("Transaction failed", "request", request, "transaction", txID)
msg := "failed to submit transaction with ID: " + txID.String()
err = cap.emitter.Emit(ctx, msg)
if err != nil {
cap.lggr.Errorf("failed to send custom message with msg: %s, err: %v", msg, err)
}
return capabilities.CapabilityResponse{}, fmt.Errorf("submitted transaction failed: %w", err)
default:
}
}
}
}

func (cap *WriteTarget) RegisterToWorkflow(ctx context.Context, request capabilities.RegisterToWorkflowRequest) error {
Expand Down
1 change: 1 addition & 0 deletions core/capabilities/targets/write_target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func TestWriteTarget(t *testing.T) {
Config: config,
Inputs: validInputs,
}
cw.On("GetTransactionStatus", mock.Anything, mock.Anything).Return(types.Finalized, nil).Once()

response, err2 := writeTarget.Execute(ctx, req)
require.NoError(t, err2)
Expand Down

0 comments on commit e791f21

Please sign in to comment.