Skip to content

Commit 1c5c8e4

Browse files
authored
Fix TXM stack overflow trigged by new logger (#77)
1 parent 139a324 commit 1c5c8e4

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

chains/txmgr/types/tx.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ type TxAttempt[
188188
IsPurgeAttempt bool
189189
}
190190

191-
func (a *TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) String() string {
192-
return fmt.Sprintf("TxAttempt(ID:%d,TxID:%d,Fee:%s,TxType:%d", a.ID, a.TxID, a.TxFee, a.TxType)
191+
func (a TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) String() string {
192+
return fmt.Sprintf("TxAttempt(ID:%d,TxID:%d,Fee:%s,TxType:%d,CreatedAt:%s)", a.ID, a.TxID, a.TxFee, a.TxType, a.CreatedAt.Format(time.RFC3339))
193193
}
194194

195195
type Tx[

chains/txmgr/types/tx_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package types
22

33
import (
44
"fmt"
5+
"math/big"
56
"testing"
67

78
"github.com/stretchr/testify/assert"
@@ -48,3 +49,21 @@ func TestTxAttemptState(t *testing.T) {
4849
}
4950
})
5051
}
52+
53+
func TestTxLogging(t *testing.T) {
54+
tx := Tx[*big.Int, *big.Int, *big.Int, *big.Int, *big.Int, *big.Int]{
55+
ID: 1,
56+
TxAttempts: []TxAttempt[*big.Int, *big.Int, *big.Int, *big.Int, *big.Int, *big.Int]{
57+
{
58+
ID: 2,
59+
},
60+
},
61+
}
62+
63+
attempt := &tx.TxAttempts[0]
64+
// set recursive reference
65+
attempt.Tx = tx
66+
// ensure that in both cases we prevent fmt from stacking in a loop attempt->tx->attempt by defining String method on attempt.
67+
println(fmt.Sprintf("%+v", *attempt))
68+
println(fmt.Sprintf("%+v", attempt))
69+
}

0 commit comments

Comments
 (0)