From 17ca1d78f03b21b69890f25ea1e7e669b0b2ac49 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Fri, 10 Apr 2020 18:26:31 -0700 Subject: [PATCH 1/2] rpcserver: include upfront shutdown script in ListChannels response This field could be omitted from the response if we were unable to calculate the channel's uptime. --- rpcserver.go | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/rpcserver.go b/rpcserver.go index 043373bf..0c0e1418 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -3299,6 +3299,25 @@ func createRPCOpenChannel(r *rpcServer, graph *channeldb.ChannelGraph, channel.PushAmountSat = uint64(localBalance.ToSatoshis()) } + if len(dbChannel.LocalShutdownScript) > 0 { + _, addresses, _, err := txscript.ExtractPkScriptAddrs( + dbChannel.LocalShutdownScript, activeNetParams.Params, + ) + if err != nil { + return nil, err + } + + // We only expect one upfront shutdown address for a channel. If + // LocalShutdownScript is non-zero, there should be one payout + // address set. + if len(addresses) != 1 { + return nil, fmt.Errorf("expected one upfront shutdown "+ + "address, got: %v", len(addresses)) + } + + channel.CloseAddress = addresses[0].String() + } + outpoint := dbChannel.FundingOutpoint // Get the lifespan observed by the channel event store. If the channel is @@ -3336,25 +3355,6 @@ func createRPCOpenChannel(r *rpcServer, graph *channeldb.ChannelGraph, } channel.Uptime = int64(uptime.Seconds()) - if len(dbChannel.LocalShutdownScript) > 0 { - _, addresses, _, err := txscript.ExtractPkScriptAddrs( - dbChannel.LocalShutdownScript, activeNetParams.Params, - ) - if err != nil { - return nil, err - } - - // We only expect one upfront shutdown address for a channel. If - // LocalShutdownScript is non-zero, there should be one payout address - // set. - if len(addresses) != 1 { - return nil, fmt.Errorf("expected one upfront shutdown address, "+ - "got: %v", len(addresses)) - } - - channel.CloseAddress = addresses[0].String() - } - return channel, nil } From 893c0cf843f8c6765574920a534bbc9ce0ff90fa Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Fri, 10 Apr 2020 18:31:46 -0700 Subject: [PATCH 2/2] rpcserver: omit uptime in ListChannels response if server not started If the server hasn't fully started yet, it's possible that the channel event store hasn't either, so it won't be able to consume any requests until then. To prevent blocking, we'll just omit the uptime related fields for now. --- rpcserver.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rpcserver.go b/rpcserver.go index 0c0e1418..b8934859 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -3318,11 +3318,18 @@ func createRPCOpenChannel(r *rpcServer, graph *channeldb.ChannelGraph, channel.CloseAddress = addresses[0].String() } - outpoint := dbChannel.FundingOutpoint + // If the server hasn't fully started yet, it's possible that the + // channel event store hasn't either, so it won't be able to consume any + // requests until then. To prevent blocking, we'll just omit the uptime + // related fields for now. + if !r.server.Started() { + return channel, nil + } // Get the lifespan observed by the channel event store. If the channel is // not known to the channel event store, return early because we cannot // calculate any further uptime information. + outpoint := dbChannel.FundingOutpoint startTime, endTime, err := r.server.chanEventStore.GetLifespan(outpoint) switch err { case chanfitness.ErrChannelNotFound: