diff --git a/chains/go.mod b/chains/go.mod index e7dafcd..cd3b712 100644 --- a/chains/go.mod +++ b/chains/go.mod @@ -7,7 +7,7 @@ require ( github.com/jpillora/backoff v1.0.0 github.com/prometheus/client_golang v1.21.1 github.com/shopspring/decimal v1.4.0 - github.com/smartcontractkit/chainlink-common v0.7.1-0.20250521163734-723cad356d85 + github.com/smartcontractkit/chainlink-common v0.7.1-0.20250627002929-2cbb7418aaa5 github.com/smartcontractkit/chainlink-framework/multinode v0.0.0-20250115203616-a2ea5e50b260 github.com/stretchr/testify v1.10.0 go.uber.org/multierr v1.11.0 @@ -42,7 +42,7 @@ require ( github.com/prometheus/client_model v0.6.1 // indirect github.com/prometheus/common v0.63.0 // indirect github.com/prometheus/procfs v0.16.0 // indirect - github.com/smartcontractkit/freeport v0.1.0 // indirect + github.com/smartcontractkit/freeport v0.1.1 // indirect github.com/smartcontractkit/libocr v0.0.0-20250220133800-f3b940c4f298 // indirect go.opentelemetry.io/auto/sdk v1.1.0 // indirect go.opentelemetry.io/otel v1.35.0 // indirect diff --git a/chains/go.sum b/chains/go.sum index 96e458e..7343f51 100644 --- a/chains/go.sum +++ b/chains/go.sum @@ -90,12 +90,12 @@ github.com/sasha-s/go-deadlock v0.3.5 h1:tNCOEEDG6tBqrNDOX35j/7hL5FcFViG6awUGROb github.com/sasha-s/go-deadlock v0.3.5/go.mod h1:bugP6EGbdGYObIlx7pUZtWqlvo8k9H6vCBBsiChJQ5U= github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k= github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME= -github.com/smartcontractkit/chainlink-common v0.7.1-0.20250521163734-723cad356d85 h1:EMnHaq7rzuB4m8Ebd+/C/yBVBz088OSrV5JbZV+An04= -github.com/smartcontractkit/chainlink-common v0.7.1-0.20250521163734-723cad356d85/go.mod h1:TF9ZqBV0QA3X1T4BoLGp0FfJpOQOcQ+ggKu1MlsWKYw= +github.com/smartcontractkit/chainlink-common v0.7.1-0.20250627002929-2cbb7418aaa5 h1:ZadFXdmkBFJz3GYPAF20IvtNSHbcRFoLrhCU/LKS9oQ= +github.com/smartcontractkit/chainlink-common v0.7.1-0.20250627002929-2cbb7418aaa5/go.mod h1:mRKPMPyJhg1RBjxtRTL2gHvRhTcZ+nk2Upu/u97Y16M= github.com/smartcontractkit/chainlink-framework/multinode v0.0.0-20250115203616-a2ea5e50b260 h1:See2isL6KdrTJDlVKWv8qiyYqWhYUcubU2e5yKXV1oY= github.com/smartcontractkit/chainlink-framework/multinode v0.0.0-20250115203616-a2ea5e50b260/go.mod h1:4JqpgFy01LaqG1yM2iFTzwX3ZgcAvW9WdstBZQgPHzU= -github.com/smartcontractkit/freeport v0.1.0 h1:3MZHeti5m+tSTBCq5R8rhawFHxrnQZYBZVL+xgS1sPo= -github.com/smartcontractkit/freeport v0.1.0/go.mod h1:T4zH9R8R8lVWKfU7tUvYz2o2jMv1OpGCdpY2j2QZXzU= +github.com/smartcontractkit/freeport v0.1.1 h1:B5fhEtmgomdIhw03uPVbVTP6oPv27fBhZsoZZMSIS8I= +github.com/smartcontractkit/freeport v0.1.1/go.mod h1:T4zH9R8R8lVWKfU7tUvYz2o2jMv1OpGCdpY2j2QZXzU= github.com/smartcontractkit/libocr v0.0.0-20250220133800-f3b940c4f298 h1:PKiqnVOTChlH4a4ljJKL3OKGRgYfIpJS4YD1daAIKks= github.com/smartcontractkit/libocr v0.0.0-20250220133800-f3b940c4f298/go.mod h1:Mb7+/LC4edz7HyHxX4QkE42pSuov4AV68+AxBXAap0o= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/chains/txmgr/txmgr.go b/chains/txmgr/txmgr.go index 249abce..2a3f7dd 100644 --- a/chains/txmgr/txmgr.go +++ b/chains/txmgr/txmgr.go @@ -59,6 +59,8 @@ type TxManager[CID chains.ID, HEAD chains.Head[BHASH], ADDR chains.Hashable, THA CountTransactionsByState(ctx context.Context, state txmgrtypes.TxState) (count uint32, err error) GetTransactionStatus(ctx context.Context, transactionID string) (state commontypes.TransactionStatus, err error) GetTransactionFee(ctx context.Context, transactionID string) (fee *evmtypes.TransactionFee, err error) + GetTransactionReceipt(ctx context.Context, transactionID string) (receipt *txmgrtypes.ChainReceipt[THASH, BHASH], err error) + CalculateFee(feeParts FeeParts) *big.Int } 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,55 @@ func (b *Txm[CID, HEAD, ADDR, THASH, BHASH, R, SEQ, FEE]) GetTransactionStatus(c } func (b *Txm[CID, HEAD, ADDR, THASH, BHASH, R, SEQ, FEE]) GetTransactionFee(ctx context.Context, transactionID string) (fee *evmtypes.TransactionFee, err error) { - receipt, err := b.txStore.FindReceiptWithIdempotencyKey(ctx, transactionID, b.chainID) + receipt, err := b.GetTransactionReceipt(ctx, transactionID) + if err != nil { - return fee, fmt.Errorf("failed to find receipt with IdempotencyKey %s: %w", transactionID, err) + return nil, err } + txFee := b.CalculateFee(FeeParts{ + GasUsed: receipt.GetFeeUsed(), + EffectiveGasPrice: receipt.GetEffectiveGasPrice(), + L1Fee: receipt.GetL1Fee(), + }) + + return &evmtypes.TransactionFee{ + TransactionFee: txFee, + }, nil +} + +func (b *Txm[CID, HEAD, ADDR, THASH, BHASH, R, SEQ, FEE]) GetTransactionReceipt(ctx context.Context, transactionID string) (receipt txmgrtypes.ChainReceipt[THASH, BHASH], err error) { + foundReceipt, err := b.txStore.FindReceiptWithIdempotencyKey(ctx, transactionID, b.chainID) + if err != nil { + return nil, fmt.Errorf("failed to find receipt with IdempotencyKey %q: %w", transactionID, err) + } // This check is required since a no-rows error returns nil err - if receipt == nil { - return fee, fmt.Errorf("failed to find receipt with IdempotencyKey %s", transactionID) + if foundReceipt == nil { + return nil, fmt.Errorf("failed to find receipt with IdempotencyKey %q", transactionID) } + return foundReceipt, nil +} + +type FeeParts struct { + GasUsed uint64 + EffectiveGasPrice *big.Int + L1Fee *big.Int +} +func (b *Txm[CID, HEAD, ADDR, THASH, BHASH, R, SEQ, FEE]) CalculateFee(feeParts FeeParts) *big.Int { totalFee := new(big.Int) - gasUsed := new(big.Int).SetUint64(receipt.GetFeeUsed()) - price := receipt.GetEffectiveGasPrice() + gasUsed := new(big.Int).SetUint64(feeParts.GasUsed) + price := feeParts.EffectiveGasPrice if price != nil { totalFee.Mul(gasUsed, price) } - l1Fee := receipt.GetL1Fee() + l1Fee := feeParts.L1Fee if l1Fee != nil { totalFee.Add(totalFee, l1Fee) } - fee = &evmtypes.TransactionFee{ - TransactionFee: totalFee, - } - - return fee, nil + return totalFee } // Deprecated: use txmgrtest.ErrTxManager @@ -847,6 +871,14 @@ func (n *NullTxManager[CID, HEAD, ADDR, THASH, BHASH, SEQ, FEE]) GetTransactionF return } +func (n *NullTxManager[CID, HEAD, ADDR, THASH, BHASH, SEQ, FEE]) CalculateFee(feeParts FeeParts) *big.Int { + return nil +} + +func (n *NullTxManager[CID, HEAD, ADDR, THASH, BHASH, SEQ, FEE]) GetTransactionReceipt(ctx context.Context, transactionID string) (receipt *txmgrtypes.ChainReceipt[THASH, BHASH], err error) { + return +} + func (b *Txm[CID, HEAD, ADDR, THASH, BHASH, R, SEQ, FEE]) pruneQueueAndCreateTxn( ctx context.Context, txRequest txmgrtypes.TxRequest[ADDR, THASH],