55 "context"
66 "encoding/binary"
77 "encoding/hex"
8+ "errors"
89 "fmt"
910 "time"
1011
@@ -14,6 +15,7 @@ import (
1415 "github.com/smartcontractkit/chainlink-common/pkg/capabilities"
1516 "github.com/smartcontractkit/chainlink-common/pkg/capabilities/consensus/ocr3/types"
1617 "github.com/smartcontractkit/chainlink-common/pkg/logger"
18+ "github.com/smartcontractkit/chainlink-common/pkg/services"
1719 commontypes "github.com/smartcontractkit/chainlink-common/pkg/types"
1820
1921 "github.com/smartcontractkit/chainlink-common/pkg/beholder/monitor"
@@ -118,8 +120,8 @@ type ReqConfig struct {
118120// NewWriteTargetID returns the capability ID for the write target
119121func NewWriteTargetID (chainFamilyName , networkName , chainID , version string ) (string , error ) {
120122 // Input args should not be empty
121- if chainFamilyName == "" || version == "" {
122- return "" , fmt .Errorf ("invalid input: chainFamilyName, and version must not be empty" )
123+ if version == "" {
124+ return "" , fmt .Errorf ("version must not be empty" )
123125 }
124126
125127 // Network ID: network name is optional, if not provided, use the chain ID
@@ -131,6 +133,11 @@ func NewWriteTargetID(chainFamilyName, networkName, chainID, version string) (st
131133 networkID = chainID
132134 }
133135
136+ // allow for chain family to be empty
137+ if chainFamilyName == "" {
138+ return fmt .Sprintf ("%s-%s@%s" , CapabilityName , networkID , version ), nil
139+ }
140+
134141 return fmt .Sprintf ("%s_%s-%s@%s" , CapabilityName , chainFamilyName , networkID , version ), nil
135142}
136143
@@ -346,12 +353,12 @@ func (c *writeTarget) acceptAndConfirmWrite(ctx context.Context, info requestInf
346353
347354 // Timeout for the confirmation process
348355 timeout := c .config .ConfirmerTimeout .Duration ()
349- ctx , cancel := context .WithTimeout (context .Background ( ), timeout )
356+ ctx , cancel := context .WithTimeout (context .WithoutCancel ( ctx ), timeout )
350357 defer cancel ()
351358
352359 // Retry interval for the confirmation process
353360 interval := c .config .ConfirmerPollPeriod .Duration ()
354- ticker := time .NewTicker (interval )
361+ ticker := services .NewTicker (interval )
355362 defer ticker .Stop ()
356363
357364 // Helper to build monitoring (Beholder) messages
@@ -400,35 +407,25 @@ func (c *writeTarget) acceptAndConfirmWrite(ctx context.Context, info requestInf
400407 continue
401408 }
402409
410+ // Check acceptance status
411+ status , accepted , statusErr := checkAcceptedStatus (ctx )
412+ if statusErr != nil {
413+ lggr .Errorw ("failed to check accepted status" , "txID" , txID , "err" , statusErr )
414+ continue
415+ }
416+
403417 if ! accepted {
404- // Check acceptance status
405- status , accepted , statusErr := checkAcceptedStatus (ctx )
406- if statusErr != nil {
407- lggr .Errorw ("failed to check accepted status" , "txID" , txID , "err" , statusErr )
408- continue
409- }
410-
411- if ! accepted {
412- lggr .Infow ("not accepted yet" , "txID" , txID , "status" , status )
413- continue
414- }
415-
416- lggr .Infow ("accepted" , "txID" , txID , "status" , status )
417- // Notice: report write confirmation is only possible after a tx is accepted without an error
418- // TODO: [Beholder] Emit 'platform.write-target.WriteAccepted' (useful to source tx hash, block number, and tx status/error)
419-
420- // TODO: check if accepted with an error (e.g., on-chain revert)
421- // Notice: this functionality is not available in the current CW/TXM API
422- acceptedWithErr := false
423- if acceptedWithErr {
424- err = c .beholder .ProtoEmitter .EmitWithLog (ctx , builder .buildWriteError (& info , 0 , "write error" , "accepted with error" ))
425- if err != nil {
426- lggr .Errorw ("failed to emit write error" , "err" , err )
427- }
428- // Notice: no return, we continue to check for confirmation (tx could be accepted by another node)
429- }
418+ lggr .Infow ("not accepted yet" , "txID" , txID , "status" , status )
419+ continue
430420 }
431421
422+ lggr .Infow ("accepted" , "txID" , txID , "status" , status )
423+ // Notice: report write confirmation is only possible after a tx is accepted without an error
424+ // TODO: [Beholder] Emit 'platform.write-target.WriteAccepted' (useful to source tx hash, block number, and tx status/error)
425+
426+ // TODO: check if accepted with an error (e.g., on-chain revert)
427+ // Notice: this functionality is not available in the current CW/TXM API
428+
432429 // Check confirmation status (transmission state)
433430 state , err := c .targetStrategy .QueryTransmissionState (ctx , info .reportInfo .reportID , info .request )
434431 if err != nil {
@@ -471,7 +468,7 @@ func (c *writeTarget) asEmittedError(ctx context.Context, e *wt.WriteError, attr
471468 // Notice: we always want to log the error
472469 err := c .beholder .ProtoEmitter .EmitWithLog (ctx , e , attrKVs ... )
473470 if err != nil {
474- return fmt .Errorf ("failed to emit error: %+w" , err )
471+ return errors . Join ( fmt .Errorf ("failed to emit error: %+w" , err ), e . AsError () )
475472 }
476473 return e .AsError ()
477474}
0 commit comments