Skip to content

Commit a5d1243

Browse files
Unheilbarcawthorne
authored andcommitted
update target strategy with biling related calls (#18448)
* update target strategy with biling related calls * fix test * fix decimal * fix decimal * bump framework * handle overflow
1 parent 8773c5e commit a5d1243

File tree

17 files changed

+101
-51
lines changed

17 files changed

+101
-51
lines changed

core/scripts/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ require (
453453
github.com/smartcontractkit/chainlink-aptos v0.0.0-20250626122206-319db248496a // indirect
454454
github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20250609091505-5c8cd74b92ed // indirect
455455
github.com/smartcontractkit/chainlink-feeds v0.1.2-0.20250227211209-7cd000095135 // indirect
456-
github.com/smartcontractkit/chainlink-framework/capabilities v0.0.0-20250618164021-9b34289a9502 // indirect
456+
github.com/smartcontractkit/chainlink-framework/capabilities v0.0.0-20250702183345-3f9ae622e391 // indirect
457457
github.com/smartcontractkit/chainlink-framework/chains v0.0.0-20250627121608-e7b52913fae2 // indirect
458458
github.com/smartcontractkit/chainlink-framework/metrics v0.0.0-20250618135814-7e3f79ab707e // indirect
459459
github.com/smartcontractkit/chainlink-framework/multinode v0.0.0-20250522110034-65c54665034a // indirect

core/scripts/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,8 +1525,8 @@ github.com/smartcontractkit/chainlink-evm v0.0.0-20250630192401-d6330473ec6e h1:
15251525
github.com/smartcontractkit/chainlink-evm v0.0.0-20250630192401-d6330473ec6e/go.mod h1:ZBbbFAkAxn4VQwW5YiQkBP5ng3uk8Dib7zI4a5rjqcs=
15261526
github.com/smartcontractkit/chainlink-feeds v0.1.2-0.20250227211209-7cd000095135 h1:8u9xUrC+yHrTDexOKDd+jrA6LCzFFHeX1G82oj2fsSI=
15271527
github.com/smartcontractkit/chainlink-feeds v0.1.2-0.20250227211209-7cd000095135/go.mod h1:NkvE4iQgiT7dMCP6U3xPELHhWhN5Xr6rHC0axRebyMU=
1528-
github.com/smartcontractkit/chainlink-framework/capabilities v0.0.0-20250618164021-9b34289a9502 h1:WLgEB8/lIfA1vI+7O4RE/PYitO57TRkKUqVllDIgJD4=
1529-
github.com/smartcontractkit/chainlink-framework/capabilities v0.0.0-20250618164021-9b34289a9502/go.mod h1:Kb8f+wt2YmBdD0PfbsC9bDhdUG/Y8sqUkzAvC2Dn8/M=
1528+
github.com/smartcontractkit/chainlink-framework/capabilities v0.0.0-20250702183345-3f9ae622e391 h1:4dUBtClcoG6QHY2JYqkpZ3GLL6DUX6pVP52wb7qVY48=
1529+
github.com/smartcontractkit/chainlink-framework/capabilities v0.0.0-20250702183345-3f9ae622e391/go.mod h1:GSz65mYV8hzb8LCRhbhoVn4i3el87nrXTBQE8KF1Qao=
15301530
github.com/smartcontractkit/chainlink-framework/chains v0.0.0-20250627121608-e7b52913fae2 h1:WRwVcv2IW59subaJDNl6B+N4OkZiAO7U2e9001XSw7c=
15311531
github.com/smartcontractkit/chainlink-framework/chains v0.0.0-20250627121608-e7b52913fae2/go.mod h1:+pRGfDej1r7cHMs1dYmuyPuOZzYB9Q+PKu0FvZOYlmw=
15321532
github.com/smartcontractkit/chainlink-framework/metrics v0.0.0-20250618135814-7e3f79ab707e h1:LRT+PltY99+hxZAJn+4nyTfqGVNEM1S6FJ675B9BtJo=

core/services/relay/evm/target_strategy.go

Lines changed: 73 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ import (
1111

1212
"github.com/ethereum/go-ethereum/common"
1313
"github.com/google/uuid"
14+
"github.com/shopspring/decimal"
1415

1516
"github.com/smartcontractkit/chainlink-common/pkg/capabilities"
1617
"github.com/smartcontractkit/chainlink-common/pkg/logger"
1718
commontypes "github.com/smartcontractkit/chainlink-common/pkg/types"
1819
"github.com/smartcontractkit/chainlink-common/pkg/types/query/primitives"
1920

21+
evmtxmgr "github.com/smartcontractkit/chainlink-evm/pkg/txmgr"
2022
"github.com/smartcontractkit/chainlink-framework/capabilities/writetarget"
2123
)
2224

@@ -26,9 +28,9 @@ var (
2628
)
2729

2830
type evmTargetStrategy struct {
29-
cr commontypes.ContractReader
30-
cw commontypes.ContractWriter
31-
31+
cr commontypes.ContractReader
32+
cw commontypes.ContractWriter
33+
txm evmtxmgr.TxManager
3234
lggr logger.Logger
3335
forwarder string
3436

@@ -65,11 +67,15 @@ type Config struct {
6567
GasLimit *uint64
6668
}
6769

68-
func NewEVMTargetStrategy(cr commontypes.ContractReader, cw commontypes.ContractWriter, forwarder string, gasLimitDefault uint64, lggr logger.Logger) *evmTargetStrategy {
70+
func NewEVMTargetStrategy(cr commontypes.ContractReader, cw commontypes.ContractWriter, txm evmtxmgr.TxManager, forwarder string, gasLimitDefault uint64, lggr logger.Logger) (*evmTargetStrategy, error) {
71+
if gasLimitDefault < ForwarderContractLogicGasCost {
72+
return nil, fmt.Errorf("default gas limit '%d' is lower than forwarder estimate '%d'", gasLimitDefault, ForwarderContractLogicGasCost)
73+
}
6974
bound := atomic.Bool{}
7075
return &evmTargetStrategy{
7176
cr: cr,
7277
cw: cw,
78+
txm: txm,
7379
lggr: lggr,
7480
forwarder: forwarder,
7581
receiverGasMinimum: gasLimitDefault - ForwarderContractLogicGasCost,
@@ -78,7 +84,7 @@ func NewEVMTargetStrategy(cr commontypes.ContractReader, cw commontypes.Contract
7884
Name: "forwarder",
7985
},
8086
bound: &bound,
81-
}
87+
}, nil
8288
}
8389

8490
func (t *evmTargetStrategy) QueryTransmissionState(ctx context.Context, reportID uint16, request capabilities.CapabilityRequest) (*writetarget.TransmissionState, error) {
@@ -171,6 +177,38 @@ func (t *evmTargetStrategy) QueryTransmissionState(ctx context.Context, reportID
171177
}, fmt.Errorf("unexpected transmission state: %v", transmissionInfo.State)
172178
}
173179

180+
func (t *evmTargetStrategy) GetEstimateFee(ctx context.Context, report []byte, reportContext []byte, signatures [][]byte,
181+
request capabilities.CapabilityRequest) (commontypes.EstimateFee, error) {
182+
r, err := getEVMRequest(request)
183+
if err != nil {
184+
return commontypes.EstimateFee{}, err
185+
}
186+
187+
req := getRawReport(r)
188+
t.lggr.Debugw("Transaction raw report", "report", hex.EncodeToString(req.RawReport))
189+
190+
meta := commontypes.TxMeta{WorkflowExecutionID: &request.Metadata.WorkflowExecutionID}
191+
if r.Config.GasLimit != nil {
192+
meta.GasLimit = new(big.Int).SetUint64(*r.Config.GasLimit)
193+
}
194+
195+
value := big.NewInt(0)
196+
return t.cw.GetEstimateFee(ctx, contractName, method, req, t.forwarder, &meta, value)
197+
}
198+
199+
func (t *evmTargetStrategy) GetTransactionFee(ctx context.Context, transactionID string) (decimal.Decimal, error) {
200+
fee, err := t.txm.GetTransactionFee(ctx, transactionID)
201+
if err != nil {
202+
return decimal.Decimal{}, err
203+
}
204+
return decimal.New(fee.TransactionFee.Int64(), -18), nil
205+
}
206+
207+
var (
208+
contractName = "forwarder"
209+
method = "report"
210+
)
211+
174212
// TransmitReport constructs the tx to transmit the report, and defines
175213
// any specific handling for sending the report via ChainWriter.
176214
func (t *evmTargetStrategy) TransmitReport(ctx context.Context, _ []byte, _ []byte, _ [][]byte, request capabilities.CapabilityRequest) (string, error) {
@@ -183,16 +221,39 @@ func (t *evmTargetStrategy) TransmitReport(ctx context.Context, _ []byte, _ []by
183221
if err != nil {
184222
return txID.String(), fmt.Errorf("failed to getEVMRequest: %w", err)
185223
}
224+
req := getRawReport(r)
225+
t.lggr.Debugw("Transaction raw report", "report", hex.EncodeToString(req.RawReport))
226+
227+
meta := commontypes.TxMeta{WorkflowExecutionID: &request.Metadata.WorkflowExecutionID}
228+
if r.Config.GasLimit != nil {
229+
meta.GasLimit = new(big.Int).SetUint64(*r.Config.GasLimit)
230+
}
186231

232+
value := big.NewInt(0)
233+
if err := t.cw.SubmitTransaction(ctx, contractName, method, req, txID.String(), t.forwarder, &meta, value); err != nil {
234+
if !commontypes.ErrSettingTransactionGasLimitNotSupported.Is(err) {
235+
return txID.String(), fmt.Errorf("failed to submit transaction: %w", err)
236+
}
237+
meta.GasLimit = nil
238+
if err := t.cw.SubmitTransaction(ctx, contractName, method, req, txID.String(), t.forwarder, &meta, value); err != nil {
239+
return txID.String(), fmt.Errorf("failed to submit transaction: %w", err)
240+
}
241+
}
242+
return txID.String(), nil
243+
}
244+
245+
type rawReport struct {
246+
Receiver string
247+
RawReport []byte
248+
ReportContext []byte
249+
Signatures [][]byte
250+
}
251+
252+
func getRawReport(r TargetRequest) rawReport {
187253
// Note: The codec that ChainWriter uses to encode the parameters for the contract ABI cannot handle
188254
// `nil` values, including for slices. Until the bug is fixed we need to ensure that there are no
189255
// `nil` values passed in the request.
190-
req := struct {
191-
Receiver string
192-
RawReport []byte
193-
ReportContext []byte
194-
Signatures [][]byte
195-
}{r.Config.Address, r.Inputs.SignedReport.Report, r.Inputs.SignedReport.Context, r.Inputs.SignedReport.Signatures}
256+
req := rawReport{r.Config.Address, r.Inputs.SignedReport.Report, r.Inputs.SignedReport.Context, r.Inputs.SignedReport.Signatures}
196257

197258
if req.RawReport == nil {
198259
req.RawReport = make([]byte, 0)
@@ -205,24 +266,8 @@ func (t *evmTargetStrategy) TransmitReport(ctx context.Context, _ []byte, _ []by
205266
if req.Signatures == nil {
206267
req.Signatures = make([][]byte, 0)
207268
}
208-
t.lggr.Debugw("Transaction raw report", "report", hex.EncodeToString(req.RawReport))
209269

210-
meta := commontypes.TxMeta{WorkflowExecutionID: &request.Metadata.WorkflowExecutionID}
211-
if r.Config.GasLimit != nil {
212-
meta.GasLimit = new(big.Int).SetUint64(*r.Config.GasLimit)
213-
}
214-
215-
value := big.NewInt(0)
216-
if err := t.cw.SubmitTransaction(ctx, "forwarder", "report", req, txID.String(), t.forwarder, &meta, value); err != nil {
217-
if !commontypes.ErrSettingTransactionGasLimitNotSupported.Is(err) {
218-
return txID.String(), fmt.Errorf("failed to submit transaction: %w", err)
219-
}
220-
meta.GasLimit = nil
221-
if err := t.cw.SubmitTransaction(ctx, "forwarder", "report", req, txID.String(), t.forwarder, &meta, value); err != nil {
222-
return txID.String(), fmt.Errorf("failed to submit transaction: %w", err)
223-
}
224-
}
225-
return txID.String(), nil
270+
return req
226271
}
227272

228273
func (t *evmTargetStrategy) GetTransactionStatus(ctx context.Context, transactionID string) (commontypes.TransactionStatus, error) {

core/services/relay/evm/write_target.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ func NewWriteTarget(ctx context.Context, relayer *Relayer, chain legacyevm.Chain
120120
if err != nil {
121121
return nil, fmt.Errorf("failed to create Aptos WT monitor client: %+w", err)
122122
}
123-
123+
ts, err := NewEVMTargetStrategy(cr, cw, relayer.chain.TxManager(), config.ForwarderAddress().String(), gasLimitDefault, lggr)
124+
if err != nil {
125+
return nil, fmt.Errorf("failed to create target strategy: %w", err)
126+
}
124127
opts := writetarget.WriteTargetOpts{
125128
ID: id,
126129
Logger: lggr,
@@ -139,7 +142,7 @@ func NewWriteTarget(ctx context.Context, relayer *Relayer, chain legacyevm.Chain
139142
ConfigValidateFn: evaluate,
140143
NodeAddress: config.FromAddress().String(),
141144
ForwarderAddress: config.ForwarderAddress().String(),
142-
TargetStrategy: NewEVMTargetStrategy(cr, cw, config.ForwarderAddress().String(), gasLimitDefault, lggr),
145+
TargetStrategy: ts,
143146
WriteAcceptanceState: *config.TxAcceptanceState(),
144147
}
145148

core/services/relay/evm/write_target_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/smartcontractkit/chainlink-common/pkg/capabilities"
2323
"github.com/smartcontractkit/chainlink-common/pkg/services/servicetest"
2424
commontypes "github.com/smartcontractkit/chainlink-common/pkg/types"
25+
commonevm "github.com/smartcontractkit/chainlink-common/pkg/types/chains/evm"
2526
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
2627
"github.com/smartcontractkit/chainlink-common/pkg/values"
2728

@@ -256,6 +257,7 @@ func TestEvmWrite(t *testing.T) {
256257
require.Equal(t, generateReportEncoded(reportType), payload["rawReport"])
257258
require.Equal(t, signatures, payload["signatures"])
258259
}).Once()
260+
txManager.On("GetTransactionFee", mock.Anything, mock.Anything).Return(&commonevm.TransactionFee{TransactionFee: big.NewInt(10)}, nil)
259261
}
260262

261263
generateValidInputs := func(reportType string) *values.Map {

deployment/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ require (
383383
github.com/smartcontractkit/chainlink-automation v0.8.1 // indirect
384384
github.com/smartcontractkit/chainlink-data-streams v0.1.1-0.20250604171706-a98fa6515eae // indirect
385385
github.com/smartcontractkit/chainlink-feeds v0.1.2-0.20250227211209-7cd000095135 // indirect
386-
github.com/smartcontractkit/chainlink-framework/capabilities v0.0.0-20250618164021-9b34289a9502 // indirect
386+
github.com/smartcontractkit/chainlink-framework/capabilities v0.0.0-20250702183345-3f9ae622e391 // indirect
387387
github.com/smartcontractkit/chainlink-framework/chains v0.0.0-20250627121608-e7b52913fae2 // indirect
388388
github.com/smartcontractkit/chainlink-framework/metrics v0.0.0-20250618135814-7e3f79ab707e // indirect
389389
github.com/smartcontractkit/chainlink-protos/billing/go v0.0.0-20250701181457-37bd0d618b58 // indirect

deployment/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,8 +1279,8 @@ github.com/smartcontractkit/chainlink-evm v0.0.0-20250630192401-d6330473ec6e h1:
12791279
github.com/smartcontractkit/chainlink-evm v0.0.0-20250630192401-d6330473ec6e/go.mod h1:ZBbbFAkAxn4VQwW5YiQkBP5ng3uk8Dib7zI4a5rjqcs=
12801280
github.com/smartcontractkit/chainlink-feeds v0.1.2-0.20250227211209-7cd000095135 h1:8u9xUrC+yHrTDexOKDd+jrA6LCzFFHeX1G82oj2fsSI=
12811281
github.com/smartcontractkit/chainlink-feeds v0.1.2-0.20250227211209-7cd000095135/go.mod h1:NkvE4iQgiT7dMCP6U3xPELHhWhN5Xr6rHC0axRebyMU=
1282-
github.com/smartcontractkit/chainlink-framework/capabilities v0.0.0-20250618164021-9b34289a9502 h1:WLgEB8/lIfA1vI+7O4RE/PYitO57TRkKUqVllDIgJD4=
1283-
github.com/smartcontractkit/chainlink-framework/capabilities v0.0.0-20250618164021-9b34289a9502/go.mod h1:Kb8f+wt2YmBdD0PfbsC9bDhdUG/Y8sqUkzAvC2Dn8/M=
1282+
github.com/smartcontractkit/chainlink-framework/capabilities v0.0.0-20250702183345-3f9ae622e391 h1:4dUBtClcoG6QHY2JYqkpZ3GLL6DUX6pVP52wb7qVY48=
1283+
github.com/smartcontractkit/chainlink-framework/capabilities v0.0.0-20250702183345-3f9ae622e391/go.mod h1:GSz65mYV8hzb8LCRhbhoVn4i3el87nrXTBQE8KF1Qao=
12841284
github.com/smartcontractkit/chainlink-framework/chains v0.0.0-20250627121608-e7b52913fae2 h1:WRwVcv2IW59subaJDNl6B+N4OkZiAO7U2e9001XSw7c=
12851285
github.com/smartcontractkit/chainlink-framework/chains v0.0.0-20250627121608-e7b52913fae2/go.mod h1:+pRGfDej1r7cHMs1dYmuyPuOZzYB9Q+PKu0FvZOYlmw=
12861286
github.com/smartcontractkit/chainlink-framework/metrics v0.0.0-20250618135814-7e3f79ab707e h1:LRT+PltY99+hxZAJn+4nyTfqGVNEM1S6FJ675B9BtJo=

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ require (
8585
github.com/smartcontractkit/chainlink-data-streams v0.1.1-0.20250604171706-a98fa6515eae
8686
github.com/smartcontractkit/chainlink-evm v0.0.0-20250630192401-d6330473ec6e
8787
github.com/smartcontractkit/chainlink-feeds v0.1.2-0.20250227211209-7cd000095135
88-
github.com/smartcontractkit/chainlink-framework/capabilities v0.0.0-20250618164021-9b34289a9502
88+
github.com/smartcontractkit/chainlink-framework/capabilities v0.0.0-20250702183345-3f9ae622e391
8989
github.com/smartcontractkit/chainlink-framework/chains v0.0.0-20250627121608-e7b52913fae2
9090
github.com/smartcontractkit/chainlink-framework/multinode v0.0.0-20250522110034-65c54665034a
9191
github.com/smartcontractkit/chainlink-protos/billing/go v0.0.0-20250701181457-37bd0d618b58

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,8 +1100,8 @@ github.com/smartcontractkit/chainlink-evm v0.0.0-20250630192401-d6330473ec6e h1:
11001100
github.com/smartcontractkit/chainlink-evm v0.0.0-20250630192401-d6330473ec6e/go.mod h1:ZBbbFAkAxn4VQwW5YiQkBP5ng3uk8Dib7zI4a5rjqcs=
11011101
github.com/smartcontractkit/chainlink-feeds v0.1.2-0.20250227211209-7cd000095135 h1:8u9xUrC+yHrTDexOKDd+jrA6LCzFFHeX1G82oj2fsSI=
11021102
github.com/smartcontractkit/chainlink-feeds v0.1.2-0.20250227211209-7cd000095135/go.mod h1:NkvE4iQgiT7dMCP6U3xPELHhWhN5Xr6rHC0axRebyMU=
1103-
github.com/smartcontractkit/chainlink-framework/capabilities v0.0.0-20250618164021-9b34289a9502 h1:WLgEB8/lIfA1vI+7O4RE/PYitO57TRkKUqVllDIgJD4=
1104-
github.com/smartcontractkit/chainlink-framework/capabilities v0.0.0-20250618164021-9b34289a9502/go.mod h1:Kb8f+wt2YmBdD0PfbsC9bDhdUG/Y8sqUkzAvC2Dn8/M=
1103+
github.com/smartcontractkit/chainlink-framework/capabilities v0.0.0-20250702183345-3f9ae622e391 h1:4dUBtClcoG6QHY2JYqkpZ3GLL6DUX6pVP52wb7qVY48=
1104+
github.com/smartcontractkit/chainlink-framework/capabilities v0.0.0-20250702183345-3f9ae622e391/go.mod h1:GSz65mYV8hzb8LCRhbhoVn4i3el87nrXTBQE8KF1Qao=
11051105
github.com/smartcontractkit/chainlink-framework/chains v0.0.0-20250627121608-e7b52913fae2 h1:WRwVcv2IW59subaJDNl6B+N4OkZiAO7U2e9001XSw7c=
11061106
github.com/smartcontractkit/chainlink-framework/chains v0.0.0-20250627121608-e7b52913fae2/go.mod h1:+pRGfDej1r7cHMs1dYmuyPuOZzYB9Q+PKu0FvZOYlmw=
11071107
github.com/smartcontractkit/chainlink-framework/metrics v0.0.0-20250618135814-7e3f79ab707e h1:LRT+PltY99+hxZAJn+4nyTfqGVNEM1S6FJ675B9BtJo=

integration-tests/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ require (
465465
github.com/smartcontractkit/chainlink-common/pkg/values v0.0.0-20250702175503-91331140edc3 // indirect
466466
github.com/smartcontractkit/chainlink-data-streams v0.1.1-0.20250604171706-a98fa6515eae // indirect
467467
github.com/smartcontractkit/chainlink-feeds v0.1.2-0.20250227211209-7cd000095135 // indirect
468-
github.com/smartcontractkit/chainlink-framework/capabilities v0.0.0-20250618164021-9b34289a9502 // indirect
468+
github.com/smartcontractkit/chainlink-framework/capabilities v0.0.0-20250702183345-3f9ae622e391 // indirect
469469
github.com/smartcontractkit/chainlink-framework/chains v0.0.0-20250627121608-e7b52913fae2 // indirect
470470
github.com/smartcontractkit/chainlink-framework/metrics v0.0.0-20250618135814-7e3f79ab707e // indirect
471471
github.com/smartcontractkit/chainlink-framework/multinode v0.0.0-20250522110034-65c54665034a // indirect

0 commit comments

Comments
 (0)