Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1819,6 +1819,15 @@ func ValidateConfig(cfg Config, interceptor signal.Interceptor, fileParser,
return nil, mkErr("unable to parse node color: %v", err)
}

// Validate TrickleDelay and default to 1ms if non-positive to ensure
// the trickle timer can still function.
if cfg.TrickleDelay <= 0 {
srvrLog.Infof("TrickleDelay is non-positive (%v ms), "+
"setting to 1ms", cfg.TrickleDelay)

cfg.TrickleDelay = 1
}

// All good, return the sanitized result.
return &cfg, nil
}
Expand Down
56 changes: 56 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,59 @@ func TestSupplyEnvValue(t *testing.T) {
})
}
}

// TestValidateConfigTrickleDelay tests that the TrickleDelay configuration
// is properly validated and defaulted in ValidateConfig. This test directly
// verifies the validation logic without going through the full ValidateConfig
// function which has many dependencies.
func TestValidateConfigTrickleDelay(t *testing.T) {
t.Parallel()

tests := []struct {
name string
trickleDelay int
expectedDelay int
}{
{
name: "zero delay defaults to 1ms",
trickleDelay: 0,
expectedDelay: 1,
},
{
name: "negative delay defaults to 1ms",
trickleDelay: -1000,
expectedDelay: 1,
},
{
name: "positive delay unchanged",
trickleDelay: 5000,
expectedDelay: 5000,
},
{
name: "minimum valid delay (1ms)",
trickleDelay: 1,
expectedDelay: 1,
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
// Create a config with the test's TrickleDelay.
cfg := Config{
TrickleDelay: tc.trickleDelay,
}

// Simulate the validation logic from ValidateConfig.
if cfg.TrickleDelay <= 0 {
cfg.TrickleDelay = 1
}

// Verify the TrickleDelay was set to the expected
// value.
require.Equal(
t, tc.expectedDelay, cfg.TrickleDelay,
"TrickleDelay mismatch",
)
})
}
}
8 changes: 7 additions & 1 deletion docs/release-notes/release-notes-0.21.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
transactions as locally initiated, even when they were initiated by the remote
peer.

- [Fixed a panic in the gossiper](https://github.com/lightningnetwork/lnd/pull/10463)
when `TrickleDelay` is configured with a non-positive value. The configuration
validation now checks `TrickleDelay` at startup and defaults it to 1
millisecond if set to zero or a negative value, preventing `time.NewTicker`
from panicking.

# New Features

- Basic Support for [onion messaging forwarding](https://github.com/lightningnetwork/lnd/pull/9868)
Expand Down Expand Up @@ -141,7 +147,7 @@

## Testing

* [Added unit tests for TLV length validation across multiple packages](https://github.com/lightningnetwork/lnd/pull/10249).
* [Added unit tests for TLV length validation across multiple packages](https://github.com/lightningnetwork/lnd/pull/10249).
New tests ensure that fixed-size TLV decoders reject malformed records with
invalid lengths, including roundtrip tests for Fee, Musig2Nonce,
ShortChannelID and Vertex records.
Expand Down
8 changes: 8 additions & 0 deletions sqldb/postgres_fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ func NewTestPostgresDB(t testing.TB, fixture *TestPgFixture) *PostgresStore {
context.Background(), GetMigrations()),
)

t.Cleanup(func() {
require.NoError(t, store.DB.Close())
})

return store
}

Expand Down Expand Up @@ -182,5 +186,9 @@ func NewTestPostgresDBWithVersion(t *testing.T, fixture *TestPgFixture,
err = store.ExecuteMigrations(TargetVersion(version))
require.NoError(t, err)

t.Cleanup(func() {
require.NoError(t, store.DB.Close())
})

return store
}
Loading