From 8891346cb29725bec51e77aef696021937265518 Mon Sep 17 00:00:00 2001 From: tyzbit <3319104+tyzbit@users.noreply.github.com> Date: Thu, 3 Oct 2019 18:12:21 -0400 Subject: [PATCH 1/2] rpcserver: startTime defaults to the unix epoch Fixes https://github.com/lightningnetwork/lnd/issues/3357. When start_time isn't specified, its default value is 0. This meant when users explicitly specified a start_time of 0, we would incorrectly set start_time to 24 hours in the past. Now, n0 means n0. --- cmd/lncli/commands.go | 2 +- rpcserver.go | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/cmd/lncli/commands.go b/cmd/lncli/commands.go index 45e06a51..ad7f751e 100644 --- a/cmd/lncli/commands.go +++ b/cmd/lncli/commands.go @@ -3532,7 +3532,7 @@ var forwardingHistoryCommand = cli.Command{ payment circuits (HTLCs) over a particular time range (--start_time and --end_time). The start and end times are meant to be expressed in seconds since the Unix epoch. If --start_time isn't provided, - then 24 hours ago is used. If --end_time isn't provided, + then the Unix epoch (01-01-1970) is used. If --end_time isn't provided, then the current time is used. The max number of events returned is 50k. The default number is 100, diff --git a/rpcserver.go b/rpcserver.go index 99234497..c42e5696 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -4637,13 +4637,8 @@ func (r *rpcServer) ForwardingHistory(ctx context.Context, numEvents uint32 ) - // If the start time wasn't specified, we'll default to 24 hours ago. - if req.StartTime == 0 { - now := time.Now() - startTime = now.Add(-time.Hour * 24) - } else { - startTime = time.Unix(int64(req.StartTime), 0) - } + // startTime defaults to the Unix epoch (0 unixtime, or midnight 01-01-1970). + startTime = time.Unix(int64(req.StartTime), 0) // If the end time wasn't specified, assume a default end time of now. if req.EndTime == 0 { From be989a85ff089155eca34d464555f2bc857ef6d2 Mon Sep 17 00:00:00 2001 From: tyzbit <3319104+tyzbit@users.noreply.github.com> Date: Thu, 3 Oct 2019 18:12:39 -0400 Subject: [PATCH 2/2] lncli: start_time defaults to 24 hours ago Here we set start_time to 24 hours prior if it's not provided on the CLI. The effect of this is when you don't provide a start_time: CLI: -24h RPC: Unix Epoch --- cmd/lncli/commands.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/lncli/commands.go b/cmd/lncli/commands.go index ad7f751e..4dd7b1ed 100644 --- a/cmd/lncli/commands.go +++ b/cmd/lncli/commands.go @@ -15,6 +15,7 @@ import ( "strings" "sync" "syscall" + "time" "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/wire" @@ -3532,7 +3533,7 @@ var forwardingHistoryCommand = cli.Command{ payment circuits (HTLCs) over a particular time range (--start_time and --end_time). The start and end times are meant to be expressed in seconds since the Unix epoch. If --start_time isn't provided, - then the Unix epoch (01-01-1970) is used. If --end_time isn't provided, + then 24 hours ago is used. If --end_time isn't provided, then the current time is used. The max number of events returned is 50k. The default number is 100, @@ -3586,6 +3587,9 @@ func forwardingHistory(ctx *cli.Context) error { return fmt.Errorf("unable to decode start_time %v", err) } args = args.Tail() + default: + now := time.Now() + startTime = uint64(now.Add(-time.Hour * 24).Unix()) } switch {