Skip to content

Commit f9bc6a7

Browse files
committed
Added accepted status config
1 parent 40e1bd0 commit f9bc6a7

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

capabilities/writetarget/write_target.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ type TargetStrategy interface {
6060
}
6161

6262
var (
63-
_ capabilities.TargetCapability = &writeTarget{}
63+
_ capabilities.ExecutableCapability = &writeTarget{}
6464
)
6565

6666
// chain-agnostic consts
@@ -98,7 +98,8 @@ type writeTarget struct {
9898
nodeAddress string
9999
forwarderAddress string
100100

101-
targetStrategy TargetStrategy
101+
targetStrategy TargetStrategy
102+
writeAcceptanceState commontypes.TransactionStatus
102103
}
103104
type WriteTargetOpts struct {
104105
ID string
@@ -120,7 +121,8 @@ type WriteTargetOpts struct {
120121
NodeAddress string
121122
ForwarderAddress string
122123

123-
TargetStrategy TargetStrategy
124+
TargetStrategy TargetStrategy
125+
WriteAcceptanceState commontypes.TransactionStatus
124126
}
125127

126128
// Capability-specific configuration
@@ -170,6 +172,7 @@ func NewWriteTarget(opts WriteTargetOpts) capabilities.ExecutableCapability {
170172
opts.NodeAddress,
171173
opts.ForwarderAddress,
172174
opts.TargetStrategy,
175+
opts.WriteAcceptanceState,
173176
}
174177
}
175178

@@ -467,18 +470,21 @@ func (c *writeTarget) waitTxReachesTerminalStatus(ctx context.Context, lggr logg
467470
lggr.Debugw("txm - tx status", "txID", txID, "status", status)
468471

469472
switch status {
470-
case commontypes.Finalized:
471-
// Notice: report write confirmation is only possible after a tx is accepted without an error
472-
// TODO: [Beholder] Emit 'platform.write-target.WriteAccepted' (useful to source tx hash, block number, and tx status/error)
473-
lggr.Infow("accepted", "txID", txID, "status", status)
474-
return true, nil
475473
case commontypes.Failed, commontypes.Fatal:
476474
// TODO: [Beholder] Emit 'platform.write-target.WriteError' if accepted with an error (surface specific on-chain error)
477475
lggr.Infow("transaction failed", "txID", txID, "status", status)
478476
return false, nil
479477
default:
480-
lggr.Infow("not accepted yet", "txID", txID, "status", status)
481-
continue
478+
// Notice: On slower chains we can accept a non-finalized state, but on faster chains we should always wait for finalization.
479+
if status >= c.writeAcceptanceState {
480+
// Notice: report write confirmation is only possible after a tx is accepted without an error
481+
// TODO: [Beholder] Emit 'platform.write-target.WriteAccepted' (useful to source tx hash, block number, and tx status/error)
482+
lggr.Infow("accepted", "txID", txID, "status", status)
483+
return true, nil
484+
} else {
485+
lggr.Infow("not accepted yet", "txID", txID, "status", status)
486+
continue
487+
}
482488
}
483489
}
484490
}

capabilities/writetarget/write_target_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,17 @@ func setupWriteTarget(
5959
ConfirmerPollPeriod: pollPeriod,
6060
ConfirmerTimeout: timeout,
6161
},
62-
ChainInfo: monitor.ChainInfo{},
63-
Logger: lggr,
64-
Beholder: monClient,
65-
ChainService: chainSvc,
66-
ContractReader: nil,
67-
EVMService: nil,
68-
ConfigValidateFn: func(_ capabilities.CapabilityRequest) (string, error) { return "0xreceiver", nil },
69-
NodeAddress: "0xnode",
70-
ForwarderAddress: "0xforwarder",
71-
TargetStrategy: strategy,
62+
ChainInfo: monitor.ChainInfo{},
63+
Logger: lggr,
64+
Beholder: monClient,
65+
ChainService: chainSvc,
66+
ContractReader: nil,
67+
EVMService: nil,
68+
ConfigValidateFn: func(_ capabilities.CapabilityRequest) (string, error) { return "0xreceiver", nil },
69+
NodeAddress: "0xnode",
70+
ForwarderAddress: "0xforwarder",
71+
TargetStrategy: strategy,
72+
WriteAcceptanceState: commontypes.Finalized,
7273
}
7374
wt := writetarget.NewWriteTarget(opts)
7475

0 commit comments

Comments
 (0)