Skip to content

Commit f4227ad

Browse files
authored
Merge branch 'main' into PLEX-1579-cleanup-wt-metrics-types
2 parents 6b0bd45 + e7b5291 commit f4227ad

File tree

3 files changed

+52
-18
lines changed

3 files changed

+52
-18
lines changed

chains/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/jpillora/backoff v1.0.0
88
github.com/prometheus/client_golang v1.21.1
99
github.com/shopspring/decimal v1.4.0
10-
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250521163734-723cad356d85
10+
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250627002929-2cbb7418aaa5
1111
github.com/smartcontractkit/chainlink-framework/multinode v0.0.0-20250115203616-a2ea5e50b260
1212
github.com/stretchr/testify v1.10.0
1313
go.uber.org/multierr v1.11.0
@@ -42,7 +42,7 @@ require (
4242
github.com/prometheus/client_model v0.6.1 // indirect
4343
github.com/prometheus/common v0.63.0 // indirect
4444
github.com/prometheus/procfs v0.16.0 // indirect
45-
github.com/smartcontractkit/freeport v0.1.0 // indirect
45+
github.com/smartcontractkit/freeport v0.1.1 // indirect
4646
github.com/smartcontractkit/libocr v0.0.0-20250220133800-f3b940c4f298 // indirect
4747
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
4848
go.opentelemetry.io/otel v1.35.0 // indirect

chains/go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ github.com/sasha-s/go-deadlock v0.3.5 h1:tNCOEEDG6tBqrNDOX35j/7hL5FcFViG6awUGROb
9090
github.com/sasha-s/go-deadlock v0.3.5/go.mod h1:bugP6EGbdGYObIlx7pUZtWqlvo8k9H6vCBBsiChJQ5U=
9191
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
9292
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
93-
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250521163734-723cad356d85 h1:EMnHaq7rzuB4m8Ebd+/C/yBVBz088OSrV5JbZV+An04=
94-
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250521163734-723cad356d85/go.mod h1:TF9ZqBV0QA3X1T4BoLGp0FfJpOQOcQ+ggKu1MlsWKYw=
93+
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250627002929-2cbb7418aaa5 h1:ZadFXdmkBFJz3GYPAF20IvtNSHbcRFoLrhCU/LKS9oQ=
94+
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250627002929-2cbb7418aaa5/go.mod h1:mRKPMPyJhg1RBjxtRTL2gHvRhTcZ+nk2Upu/u97Y16M=
9595
github.com/smartcontractkit/chainlink-framework/multinode v0.0.0-20250115203616-a2ea5e50b260 h1:See2isL6KdrTJDlVKWv8qiyYqWhYUcubU2e5yKXV1oY=
9696
github.com/smartcontractkit/chainlink-framework/multinode v0.0.0-20250115203616-a2ea5e50b260/go.mod h1:4JqpgFy01LaqG1yM2iFTzwX3ZgcAvW9WdstBZQgPHzU=
97-
github.com/smartcontractkit/freeport v0.1.0 h1:3MZHeti5m+tSTBCq5R8rhawFHxrnQZYBZVL+xgS1sPo=
98-
github.com/smartcontractkit/freeport v0.1.0/go.mod h1:T4zH9R8R8lVWKfU7tUvYz2o2jMv1OpGCdpY2j2QZXzU=
97+
github.com/smartcontractkit/freeport v0.1.1 h1:B5fhEtmgomdIhw03uPVbVTP6oPv27fBhZsoZZMSIS8I=
98+
github.com/smartcontractkit/freeport v0.1.1/go.mod h1:T4zH9R8R8lVWKfU7tUvYz2o2jMv1OpGCdpY2j2QZXzU=
9999
github.com/smartcontractkit/libocr v0.0.0-20250220133800-f3b940c4f298 h1:PKiqnVOTChlH4a4ljJKL3OKGRgYfIpJS4YD1daAIKks=
100100
github.com/smartcontractkit/libocr v0.0.0-20250220133800-f3b940c4f298/go.mod h1:Mb7+/LC4edz7HyHxX4QkE42pSuov4AV68+AxBXAap0o=
101101
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

chains/txmgr/txmgr.go

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ type TxManager[CID chains.ID, HEAD chains.Head[BHASH], ADDR chains.Hashable, THA
5959
CountTransactionsByState(ctx context.Context, state txmgrtypes.TxState) (count uint32, err error)
6060
GetTransactionStatus(ctx context.Context, transactionID string) (state commontypes.TransactionStatus, err error)
6161
GetTransactionFee(ctx context.Context, transactionID string) (fee *evmtypes.TransactionFee, err error)
62+
GetTransactionReceipt(ctx context.Context, transactionID string) (receipt *txmgrtypes.ChainReceipt[THASH, BHASH], err error)
63+
CalculateFee(feeParts FeeParts) *big.Int
6264
}
6365

6466
type TxmV2Wrapper[CID chains.ID, HEAD chains.Head[BHASH], ADDR chains.Hashable, THASH chains.Hashable, BHASH chains.Hashable, SEQ chains.Sequence, FEE fees.Fee] interface {
@@ -733,33 +735,57 @@ func (b *Txm[CID, HEAD, ADDR, THASH, BHASH, R, SEQ, FEE]) GetTransactionStatus(c
733735
}
734736

735737
func (b *Txm[CID, HEAD, ADDR, THASH, BHASH, R, SEQ, FEE]) GetTransactionFee(ctx context.Context, transactionID string) (fee *evmtypes.TransactionFee, err error) {
736-
receipt, err := b.txStore.FindReceiptWithIdempotencyKey(ctx, transactionID, b.chainID)
738+
receipt, err := b.GetTransactionReceipt(ctx, transactionID)
739+
737740
if err != nil {
738-
return fee, fmt.Errorf("failed to find receipt with IdempotencyKey %s: %w", transactionID, err)
741+
return nil, err
739742
}
740743

744+
r := *receipt
745+
746+
txFee := b.CalculateFee(FeeParts{
747+
GasUsed: r.GetFeeUsed(),
748+
EffectiveGasPrice: r.GetEffectiveGasPrice(),
749+
L1Fee: r.GetL1Fee(),
750+
})
751+
752+
return &evmtypes.TransactionFee{
753+
TransactionFee: txFee,
754+
}, nil
755+
}
756+
757+
func (b *Txm[CID, HEAD, ADDR, THASH, BHASH, R, SEQ, FEE]) GetTransactionReceipt(ctx context.Context, transactionID string) (receipt *txmgrtypes.ChainReceipt[THASH, BHASH], err error) {
758+
foundReceipt, err := b.txStore.FindReceiptWithIdempotencyKey(ctx, transactionID, b.chainID)
759+
if err != nil {
760+
return nil, fmt.Errorf("failed to find receipt with IdempotencyKey %q: %w", transactionID, err)
761+
}
741762
// This check is required since a no-rows error returns nil err
742-
if receipt == nil {
743-
return fee, fmt.Errorf("failed to find receipt with IdempotencyKey %s", transactionID)
763+
if foundReceipt == nil {
764+
return nil, fmt.Errorf("failed to find receipt with IdempotencyKey %q", transactionID)
744765
}
766+
return &foundReceipt, nil
767+
}
745768

769+
type FeeParts struct {
770+
GasUsed uint64
771+
EffectiveGasPrice *big.Int
772+
L1Fee *big.Int
773+
}
774+
775+
func (b *Txm[CID, HEAD, ADDR, THASH, BHASH, R, SEQ, FEE]) CalculateFee(feeParts FeeParts) *big.Int {
746776
totalFee := new(big.Int)
747777

748-
gasUsed := new(big.Int).SetUint64(receipt.GetFeeUsed())
749-
price := receipt.GetEffectiveGasPrice()
778+
gasUsed := new(big.Int).SetUint64(feeParts.GasUsed)
779+
price := feeParts.EffectiveGasPrice
750780
if price != nil {
751781
totalFee.Mul(gasUsed, price)
752782
}
753-
l1Fee := receipt.GetL1Fee()
783+
l1Fee := feeParts.L1Fee
754784
if l1Fee != nil {
755785
totalFee.Add(totalFee, l1Fee)
756786
}
757787

758-
fee = &evmtypes.TransactionFee{
759-
TransactionFee: totalFee,
760-
}
761-
762-
return fee, nil
788+
return totalFee
763789
}
764790

765791
// Deprecated: use txmgrtest.ErrTxManager
@@ -847,6 +873,14 @@ func (n *NullTxManager[CID, HEAD, ADDR, THASH, BHASH, SEQ, FEE]) GetTransactionF
847873
return
848874
}
849875

876+
func (n *NullTxManager[CID, HEAD, ADDR, THASH, BHASH, SEQ, FEE]) CalculateFee(feeParts FeeParts) *big.Int {
877+
return nil
878+
}
879+
880+
func (n *NullTxManager[CID, HEAD, ADDR, THASH, BHASH, SEQ, FEE]) GetTransactionReceipt(ctx context.Context, transactionID string) (receipt *txmgrtypes.ChainReceipt[THASH, BHASH], err error) {
881+
return
882+
}
883+
850884
func (b *Txm[CID, HEAD, ADDR, THASH, BHASH, R, SEQ, FEE]) pruneQueueAndCreateTxn(
851885
ctx context.Context,
852886
txRequest txmgrtypes.TxRequest[ADDR, THASH],

0 commit comments

Comments
 (0)