Skip to content

Commit 47347f2

Browse files
authored
Merge pull request #132 from smartcontractkit/feat/stellar-service-tx-fee
map TXM FeeCharged to SubmitTransactionResponse.TransactionFee
2 parents 0e9836f + 39a180e commit 47347f2

7 files changed

Lines changed: 56 additions & 21 deletions

File tree

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
github.com/smartcontractkit/chainlink-ccv v0.0.2-0.20260518180919-4f70eba1dfd2
1515
github.com/smartcontractkit/chainlink-ccv/build/devenv v0.0.2-0.20260518180919-4f70eba1dfd2
1616
github.com/smartcontractkit/chainlink-ccv/deployment v0.0.2-0.20260518113836-b4e2fcbb6799
17-
github.com/smartcontractkit/chainlink-common v0.11.2-0.20260612151455-287bc497584e
17+
github.com/smartcontractkit/chainlink-common v0.11.2-0.20260618182632-7a1ff6408df5
1818
github.com/smartcontractkit/chainlink-common/keystore v1.0.2
1919
github.com/smartcontractkit/chainlink-deployments-framework v0.101.1
2020
github.com/smartcontractkit/chainlink-framework/metrics v0.0.0-20260423135514-5b1a7565a99c
@@ -422,7 +422,7 @@ require (
422422
github.com/smartcontractkit/chainlink-protos/chainlink-ccv/heartbeat v0.0.0-20260115142640-f6b99095c12e // indirect
423423
github.com/smartcontractkit/chainlink-protos/chainlink-ccv/message-discovery v0.0.0-20251211142334-5c3421fe2c8d // indirect
424424
github.com/smartcontractkit/chainlink-protos/chainlink-ccv/verifier v0.0.0-20251211142334-5c3421fe2c8d // indirect
425-
github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20260611123141-db97012a6c32 // indirect
425+
github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20260618082634-432eb85805e7 // indirect
426426
github.com/smartcontractkit/chainlink-protos/job-distributor v0.18.0 // indirect
427427
github.com/smartcontractkit/chainlink-protos/linking-service/go v0.0.0-20251002192024-d2ad9222409b // indirect
428428
github.com/smartcontractkit/chainlink-stellar/bindings v0.0.0-20260616123609-60ff67b1820a

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,8 +1166,8 @@ github.com/smartcontractkit/chainlink-ccv/build/devenv v0.0.2-0.20260518180919-4
11661166
github.com/smartcontractkit/chainlink-ccv/build/devenv v0.0.2-0.20260518180919-4f70eba1dfd2/go.mod h1:p2lpE7QJQ4/nI6ZGLmfNz0uAeSt2qKsQ2hRLegZ/HvI=
11671167
github.com/smartcontractkit/chainlink-ccv/deployment v0.0.2-0.20260518113836-b4e2fcbb6799 h1:zxkcX0vP0NMeptsGVmgMEI0ZBdYedsoaBfkP331whwc=
11681168
github.com/smartcontractkit/chainlink-ccv/deployment v0.0.2-0.20260518113836-b4e2fcbb6799/go.mod h1:bNMFRxwWdgVFdSsFZRmsUUPoBUncU3RM765K99svIKM=
1169-
github.com/smartcontractkit/chainlink-common v0.11.2-0.20260612151455-287bc497584e h1:PqEa0dqct7xEphFU/AMF7wuB2F5l+/kU6trYhy7Q8Dk=
1170-
github.com/smartcontractkit/chainlink-common v0.11.2-0.20260612151455-287bc497584e/go.mod h1:BCYSFxZTxZEGbyeodKCmfC1MydCEmIf+O29xrLBLnJI=
1169+
github.com/smartcontractkit/chainlink-common v0.11.2-0.20260618182632-7a1ff6408df5 h1:mfBz2dfl9kjrNYPY4y+Fmb5Mt+3csNp4GTU8fJrVsdA=
1170+
github.com/smartcontractkit/chainlink-common v0.11.2-0.20260618182632-7a1ff6408df5/go.mod h1:paOB/6dy57owHtOGzhgaRBWRDT5BEWfnJF5M7sgkcro=
11711171
github.com/smartcontractkit/chainlink-common/keystore v1.0.2 h1:AWisx4JT3QV8tcgh6J5NCrex+wAgTYpWyHsyNPSXzsQ=
11721172
github.com/smartcontractkit/chainlink-common/keystore v1.0.2/go.mod h1:rSkIHdomyak3YnUtXLenl6poIq8q0V3UZPiiyYqPdGA=
11731173
github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20260528204832-58c7145c53f8 h1:5O2qAtvBLzTHBeSIPcxt9i9BCqqOyeroVxN0xbXwoS0=
@@ -1194,8 +1194,8 @@ github.com/smartcontractkit/chainlink-protos/chainlink-ccv/message-rules v0.0.0-
11941194
github.com/smartcontractkit/chainlink-protos/chainlink-ccv/message-rules v0.0.0-20260505131349-78e491b80735/go.mod h1:zAJq6Tpkx5AdFUwW67dIYnW+Bdf50drCCpMR81Qxb4E=
11951195
github.com/smartcontractkit/chainlink-protos/chainlink-ccv/verifier v0.0.0-20251211142334-5c3421fe2c8d h1:AJy55QJ/pBhXkZjc7N+ATnWfxrcjq9BI9DmdtdjwDUQ=
11961196
github.com/smartcontractkit/chainlink-protos/chainlink-ccv/verifier v0.0.0-20251211142334-5c3421fe2c8d/go.mod h1:5JdppgngCOUS76p61zCinSCgOhPeYQ+OcDUuome5THQ=
1197-
github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20260611123141-db97012a6c32 h1:GNl+lLK0QCakqA1J1i7FoOai2JrOGOzNzSniMijaCjA=
1198-
github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20260611123141-db97012a6c32/go.mod h1:vTFHTCbLui4Vn8fTmAadfE3rdnvfrDwOmMujmW857D0=
1197+
github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20260618082634-432eb85805e7 h1:iRFmfMFQtcnhGDjCuARQG4MPbcmbbJDDw7MUH3GcGy8=
1198+
github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20260618082634-432eb85805e7/go.mod h1:vTFHTCbLui4Vn8fTmAadfE3rdnvfrDwOmMujmW857D0=
11991199
github.com/smartcontractkit/chainlink-protos/job-distributor v0.18.0 h1:q+VDPcxWrj5k9QizSYfUOSMnDH3Sd5HvbPguZOgfXTY=
12001200
github.com/smartcontractkit/chainlink-protos/job-distributor v0.18.0/go.mod h1:/dVVLXrsp+V0AbcYGJo3XMzKg3CkELsweA/TTopCsKE=
12011201
github.com/smartcontractkit/chainlink-protos/linking-service/go v0.0.0-20251002192024-d2ad9222409b h1:QuI6SmQFK/zyUlVWEf0GMkiUYBPY4lssn26nKSd/bOM=

relayer/stellar_service.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,14 @@ func (s *stellarService) SubmitTransaction(ctx context.Context, req stellartypes
241241
ResultXDR: result.ResultXDR,
242242
ResultMetaXDR: result.ResultMetaXDR,
243243
}
244+
if result.Fee != nil && result.Fee.IsUint64() {
245+
fee := result.Fee.Uint64()
246+
reply.TransactionFee = &fee
247+
}
248+
if result.LedgerCloseTime > 0 {
249+
ts := uint64(result.LedgerCloseTime) * 1_000_000
250+
reply.BlockTimestamp = &ts
251+
}
244252

245253
switch result.Status {
246254
case relaytypes.Finalized:

relayer/stellar_service_test.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package relayer
33
import (
44
"context"
55
"errors"
6+
"math/big"
67
"testing"
78

89
protocol "github.com/stellar/go-stellar-sdk/protocols/rpc"
@@ -365,11 +366,13 @@ func TestStellarService_SubmitTransaction(t *testing.T) {
365366
require.Len(t, req.Operations, 1)
366367
require.Equal(t, uint32(2), req.LedgerBoundsOffset)
367368
return &txm.TxResult{
368-
ID: "idem-1",
369-
Hash: "txhash123",
370-
Status: commontypes.Finalized,
371-
ResultXDR: "resultXDR",
372-
ResultMetaXDR: "metaXDR",
369+
ID: "idem-1",
370+
Hash: "txhash123",
371+
Status: commontypes.Finalized,
372+
Fee: big.NewInt(42_000),
373+
LedgerCloseTime: 1_700_000_000,
374+
ResultXDR: "resultXDR",
375+
ResultMetaXDR: "metaXDR",
373376
}, nil
374377
})
375378

@@ -381,6 +384,10 @@ func TestStellarService_SubmitTransaction(t *testing.T) {
381384
require.Equal(t, "idem-1", reply.TxIdempotencyKey)
382385
require.Equal(t, "resultXDR", reply.ResultXDR)
383386
require.Equal(t, "metaXDR", reply.ResultMetaXDR)
387+
require.NotNil(t, reply.TransactionFee)
388+
require.Equal(t, uint64(42_000), *reply.TransactionFee)
389+
require.NotNil(t, reply.BlockTimestamp)
390+
require.Equal(t, uint64(1_700_000_000_000_000), *reply.BlockTimestamp)
384391
})
385392

386393
t.Run("Failed_OnChain", func(t *testing.T) {

relayer/txm/tx.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ type StellarTx struct {
2222
Attempt uint64
2323
Status commontypes.TransactionStatus
2424
TxHash string
25-
Fee *big.Int // total fee in stroops; updated to actual FeeCharged on confirmation
26-
ResultXDR string // XDR-encoded transaction result from GetTransaction
25+
Fee *big.Int // total fee in stroops; updated to actual FeeCharged on confirmation
26+
LedgerCloseTime int64 // unix seconds when tx was included in a ledger; from GetTransaction
27+
ResultXDR string // XDR-encoded transaction result from GetTransaction
2728
ResultCode string // result code from GetTransaction (for diagnostics)
2829
ResultMetaXDR string // XDR-encoded result meta from GetTransaction SUCCESS
2930
MaxLedger uint32 // ledger bounds set during broadcast
@@ -48,8 +49,9 @@ type TxResult struct {
4849
ID string
4950
Hash string
5051
Status commontypes.TransactionStatus
51-
Fee *big.Int // total fee charged in stroops
52-
ResultXDR string // XDR-encoded transaction result from GetTransaction
52+
Fee *big.Int // total fee charged in stroops
53+
LedgerCloseTime int64 // unix seconds when tx was included in a ledger; 0 if unknown
54+
ResultXDR string // XDR-encoded transaction result from GetTransaction
5355
ResultMetaXDR string // XDR-encoded result meta from GetTransaction
5456
Error error
5557
}

relayer/txm/txm.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,13 @@ func (s *StellarTxm) txResult(tx *StellarTx) *TxResult {
224224

225225
func (s *StellarTxm) txResultLocked(tx *StellarTx) *TxResult {
226226
result := &TxResult{
227-
ID: tx.ID,
228-
Hash: tx.TxHash,
229-
Status: tx.Status,
230-
Fee: tx.Fee,
231-
ResultXDR: tx.ResultXDR,
232-
ResultMetaXDR: tx.ResultMetaXDR,
227+
ID: tx.ID,
228+
Hash: tx.TxHash,
229+
Status: tx.Status,
230+
Fee: tx.Fee,
231+
LedgerCloseTime: tx.LedgerCloseTime,
232+
ResultXDR: tx.ResultXDR,
233+
ResultMetaXDR: tx.ResultMetaXDR,
233234
}
234235
if tx.ResultCode != "" {
235236
result.Error = fmt.Errorf("transaction result: %s", tx.ResultCode)
@@ -435,6 +436,15 @@ func (s *StellarTxm) updateTransactionFee(tx *StellarTx, fee *big.Int) {
435436
tx.Fee = fee
436437
}
437438

439+
func (s *StellarTxm) updateTransactionLedgerCloseTime(tx *StellarTx, ledgerCloseTime int64) {
440+
if ledgerCloseTime <= 0 {
441+
return
442+
}
443+
s.transactionsLock.Lock()
444+
defer s.transactionsLock.Unlock()
445+
tx.LedgerCloseTime = ledgerCloseTime
446+
}
447+
438448
func (s *StellarTxm) updateTransactionResultXDR(tx *StellarTx, resultXDR string) {
439449
s.transactionsLock.Lock()
440450
defer s.transactionsLock.Unlock()
@@ -881,6 +891,7 @@ func (s *StellarTxm) checkUnconfirmed(ctx context.Context) {
881891
if resp.ResultMetaXDR != "" {
882892
s.updateTransactionResultMeta(utx.Tx, resp.ResultMetaXDR)
883893
}
894+
s.updateTransactionLedgerCloseTime(utx.Tx, resp.LedgerCloseTime)
884895

885896
ctxLogger.Infow("confirmed tx: successful", "hash", hash)
886897
s.metrics.IncrementSuccessTxs(ctx)
@@ -895,6 +906,7 @@ func (s *StellarTxm) checkUnconfirmed(ctx context.Context) {
895906
s.updateTransactionResultXDR(utx.Tx, resp.ResultXDR)
896907
classification := classifyFailedTransactionResult(resp.ResultXDR)
897908
s.updateTransactionResultCode(utx.Tx, classification.resultCode)
909+
s.updateTransactionLedgerCloseTime(utx.Tx, resp.LedgerCloseTime)
898910

899911
ctxLogger.Infow("confirmed tx: failed on-chain", "hash", hash, "resultCode", classification.resultCode, "retryable", classification.retryable)
900912
s.metrics.IncrementErrorTxs(ctx, classification.resultCode)

relayer/txm/txm_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,7 @@ func TestStellarTxm_ConfirmLoop_UpdatesFeeAndMetaFromXDR(t *testing.T) {
12351235
getLatestLedgerResp: protocolrpc.GetLatestLedgerResponse{Sequence: 1000},
12361236
sendTransactionResp: protocolrpc.SendTransactionResponse{Status: stellarcore.TXStatusPending, Hash: "test-hash"},
12371237
getTransactionResp: protocolrpc.GetTransactionResponse{
1238+
LedgerCloseTime: 1_700_000_000,
12381239
TransactionDetails: protocolrpc.TransactionDetails{
12391240
Status: protocolrpc.TransactionStatusSuccess,
12401241
ResultXDR: resultB64,
@@ -1271,6 +1272,7 @@ func TestStellarTxm_ConfirmLoop_UpdatesFeeAndMetaFromXDR(t *testing.T) {
12711272
txm.transactionsLock.RUnlock()
12721273
require.NotNil(t, tracked)
12731274
assert.Equal(t, big.NewInt(40_200), tracked.Fee)
1275+
assert.Equal(t, int64(1_700_000_000), tracked.LedgerCloseTime)
12741276
assert.Equal(t, resultB64, tracked.ResultXDR)
12751277
assert.Equal(t, metaB64, tracked.ResultMetaXDR)
12761278

@@ -1279,6 +1281,7 @@ func TestStellarTxm_ConfirmLoop_UpdatesFeeAndMetaFromXDR(t *testing.T) {
12791281
assert.Equal(t, "test-hash", result.Hash)
12801282
assert.Equal(t, commontypes.Finalized, result.Status)
12811283
assert.Equal(t, big.NewInt(40_200), result.Fee)
1284+
assert.Equal(t, int64(1_700_000_000), result.LedgerCloseTime)
12821285
assert.Equal(t, resultB64, result.ResultXDR)
12831286
assert.Equal(t, metaB64, result.ResultMetaXDR)
12841287
assert.NoError(t, result.Error)
@@ -1294,6 +1297,7 @@ func TestStellarTxm_ConfirmLoop_TerminalContractFailureDoesNotRetry(t *testing.T
12941297
sendTransactionResp: protocolrpc.SendTransactionResponse{Status: stellarcore.TXStatusPending, Hash: "test-hash"},
12951298
simulateResp: protocolrpc.SimulateTransactionResponse{MinResourceFee: 10_000},
12961299
getTransactionResp: protocolrpc.GetTransactionResponse{
1300+
LedgerCloseTime: 1_700_000_001,
12971301
TransactionDetails: protocolrpc.TransactionDetails{
12981302
Status: protocolrpc.TransactionStatusFailed,
12991303
ResultXDR: resultB64,
@@ -1318,13 +1322,15 @@ func TestStellarTxm_ConfirmLoop_TerminalContractFailureDoesNotRetry(t *testing.T
13181322
txm.transactionsLock.RUnlock()
13191323
require.NotNil(t, tracked)
13201324
assert.Equal(t, uint64(0), tracked.Attempt)
1325+
assert.Equal(t, int64(1_700_000_001), tracked.LedgerCloseTime)
13211326
assert.Equal(t, resultB64, tracked.ResultXDR)
13221327
assert.Equal(t, xdr.InvokeHostFunctionResultCodeInvokeHostFunctionTrapped.String(), tracked.ResultCode)
13231328

13241329
result, err := txm.GetTransactionResult(txID)
13251330
require.NoError(t, err)
13261331
assert.Equal(t, "test-hash", result.Hash)
13271332
assert.Equal(t, commontypes.Failed, result.Status)
1333+
assert.Equal(t, int64(1_700_000_001), result.LedgerCloseTime)
13281334
assert.Equal(t, resultB64, result.ResultXDR)
13291335
require.Error(t, result.Error)
13301336
assert.Contains(t, result.Error.Error(), xdr.InvokeHostFunctionResultCodeInvokeHostFunctionTrapped.String())

0 commit comments

Comments
 (0)