@@ -884,6 +884,82 @@ func TestPruneChannelGraphStaleEdges(t *testing.T) {
884884 }
885885}
886886
887+ // TestIsZombieByAge tests that we can properly determine if a channel with no
888+ // edge policies is a zombie or not using the block timestamp that the
889+ // transaction that opened the channel was included in.
890+ //
891+ //nolint:ll
892+ func TestIsZombieByAge (t * testing.T ) {
893+ t .Parallel ()
894+
895+ tests := []struct {
896+ name string
897+ blockTimestamp time.Time
898+ channelPruneExpiry time.Duration
899+ expectedPrune bool
900+ }{
901+ {
902+ name : "old chan" ,
903+ blockTimestamp : time .Now ().Add (- 30 * 24 * time .Hour ),
904+ channelPruneExpiry : 14 * 24 * time .Hour ,
905+ expectedPrune : true ,
906+ },
907+ {
908+ name : "recent channel" ,
909+ blockTimestamp : time .Now ().Add (- 7 * 24 * time .Hour ),
910+ channelPruneExpiry : 14 * 24 * time .Hour ,
911+ expectedPrune : false ,
912+ },
913+ {
914+ name : "chan at threshold" ,
915+ blockTimestamp : time .Now ().Add (- 14 * 24 * time .Hour ),
916+ channelPruneExpiry : 14 * 24 * time .Hour ,
917+ expectedPrune : true ,
918+ },
919+ }
920+
921+ for _ , tc := range tests {
922+ t .Run (tc .name , func (t * testing.T ) {
923+ // Create mock chain with a starting height.
924+ const startingHeight = 100
925+ mockChain := newMockChain (startingHeight )
926+
927+ // Create a block with the desired timestamp.
928+ block := & wire.MsgBlock {
929+ Header : wire.BlockHeader {
930+ Timestamp : tc .blockTimestamp ,
931+ },
932+ }
933+
934+ // Add the block at a specific height.
935+ const channelBlockHeight = 101
936+ mockChain .addBlock (block , channelBlockHeight , 0 )
937+
938+ scid := lnwire.ShortChannelID {
939+ BlockHeight : channelBlockHeight ,
940+ TxIndex : 0 ,
941+ TxPosition : 0 ,
942+ }
943+
944+ // Create a minimal builder config that consist the mock
945+ // chain and the channel prune expiry we set.
946+ cfg := & Config {
947+ Chain : mockChain ,
948+ ChannelPruneExpiry : tc .channelPruneExpiry ,
949+ }
950+ builder := & Builder {
951+ cfg : cfg ,
952+ }
953+
954+ // Test the method to see we are able to determine if
955+ // the channel is a zombie or not.
956+ isZombie , err := builder .IsZombieByAge (scid .ToUint64 ())
957+ require .NoError (t , err )
958+ require .Equal (t , tc .expectedPrune , isZombie )
959+ })
960+ }
961+ }
962+
887963// TestPruneChannelGraphDoubleDisabled test that we can properly prune channels
888964// with both edges disabled from our channel graph.
889965func TestPruneChannelGraphDoubleDisabled (t * testing.T ) {
0 commit comments