Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Startup related fixes #1126

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,5 @@ require (
// We want to format raw bytes as hex instead of base64. The forked version
// allows us to specify that as an option.
replace google.golang.org/protobuf => github.com/lightninglabs/protobuf-go-hex-display v1.30.0-hex-display

replace github.com/lightningnetwork/lnd => github.com/GeorgeTsagk/lnd v0.0.0-20240917164552-0bb673fa9dc0
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg6
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/GeorgeTsagk/lnd v0.0.0-20240917164552-0bb673fa9dc0 h1:WOBPhGul4qW/pwrjw6C0a1XlUd1DiJQduB4rspu8Qv8=
github.com/GeorgeTsagk/lnd v0.0.0-20240917164552-0bb673fa9dc0/go.mod h1:/Uh0qCiU/oQls68spxpmP0kRjX/uGkLzt7P/uPpDofE=
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
github.com/Masterminds/semver/v3 v3.2.0 h1:3MEsd0SM6jqZojhjLWWeBY+Kcjy9i6MQAeY7YgDP83g=
github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
Expand Down Expand Up @@ -490,8 +492,6 @@ github.com/lightninglabs/protobuf-go-hex-display v1.30.0-hex-display h1:pRdza2wl
github.com/lightninglabs/protobuf-go-hex-display v1.30.0-hex-display/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
github.com/lightningnetwork/lightning-onion v1.2.1-0.20230823005744-06182b1d7d2f h1:Pua7+5TcFEJXIIZ1I2YAUapmbcttmLj4TTi786bIi3s=
github.com/lightningnetwork/lightning-onion v1.2.1-0.20230823005744-06182b1d7d2f/go.mod h1:c0kvRShutpj3l6B9WtTsNTBUtjSmjZXbJd9ZBRQOSKI=
github.com/lightningnetwork/lnd v0.18.0-beta.rc4.0.20240723043204-f09d4042aee4 h1:LPnz0JxnzXJvCro714eBanzO7FKx5HF0ldU++zIu9yY=
github.com/lightningnetwork/lnd v0.18.0-beta.rc4.0.20240723043204-f09d4042aee4/go.mod h1:0gen58n0DVnqJJqCMN3AXNtqWRT0KltQanlvehnhCq0=
github.com/lightningnetwork/lnd/cert v1.2.2 h1:71YK6hogeJtxSxw2teq3eGeuy4rHGKcFf0d0Uy4qBjI=
github.com/lightningnetwork/lnd/cert v1.2.2/go.mod h1:jQmFn/Ez4zhDgq2hnYSw8r35bqGVxViXhX6Cd7HXM6U=
github.com/lightningnetwork/lnd/clock v1.1.1 h1:OfR3/zcJd2RhH0RU+zX/77c0ZiOnIMsDIBjgjWdZgA0=
Expand Down
10 changes: 10 additions & 0 deletions rpcperms/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,12 @@
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo,
handler grpc.UnaryHandler) (interface{}, error) {

if info.Server == nil {
return nil, fmt.Errorf("server is nil, can't check " +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can probably be a bit less specific in the error message here, perhaps just "cannot handle call, server not ready"?

"RPC state")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: linter complains about superfluous empty line.

}

Check failure on line 420 in rpcperms/interceptor.go

View workflow job for this annotation

GitHub Actions / Lint check

unnecessary trailing newline (whitespace)

if err := r.checkRPCState(info.Server); err != nil {
return nil, err
}
Expand All @@ -427,6 +433,10 @@
return func(srv interface{}, ss grpc.ServerStream,
info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {

if srv == nil {
return fmt.Errorf("srv is nil, can't check RPC state")
}

if err := r.checkRPCState(srv); err != nil {
return err
}
Expand Down
27 changes: 20 additions & 7 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,11 +702,16 @@ func (s *Server) waitForReady() error {
// this part of the code, the called component will handle the quit
// signal.
select {
case <-s.ready:
return nil

case <-s.quit:
return fmt.Errorf("tapd is shutting down")

default:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix. This probably explains one class of potential errors we had.

select {
case <-s.ready:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe mention here that we now wait until the server becomes ready or shuts down (meaning this is blocking).

return nil
case <-s.quit:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this doesn't solve the tapd: don't set initialized=true when startup (StartAsSubserver) fails part of the issue. We don't close the quit channel when we fail to start there (which is the main entrypoint for litd).

return fmt.Errorf("tapd is shutting down")
}
}
}

Expand Down Expand Up @@ -819,17 +824,25 @@ func (s *Server) Name() protofsm.EndpointName {
// CanHandle returns true if the target message can be routed to this endpoint.
//
// NOTE: This method is part of the protofsm.MsgEndpoint interface.
func (s *Server) CanHandle(msg protofsm.PeerMsg) bool {
<-s.ready
func (s *Server) CanHandle(msg protofsm.PeerMsg) (bool, error) {
err := s.waitForReady()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on the discussion on the lnd PR it might be okay to just return false if s.waitForReady() returns an error. But calling s.waitForReady() should definitely be done so we don't block indefinitely.

if err != nil {
return false, err
}

return s.cfg.AuxFundingController.CanHandle(msg)
}

// SendMessage handles the target message, and returns true if the message was
// able to be processed.
//
// NOTE: This method is part of the protofsm.MsgEndpoint interface.
func (s *Server) SendMessage(msg protofsm.PeerMsg) bool {
<-s.ready
func (s *Server) SendMessage(msg protofsm.PeerMsg) (bool, error) {
err := s.waitForReady()
if err != nil {
return false, err
}

return s.cfg.AuxFundingController.SendMessage(msg)
}

Expand Down
18 changes: 9 additions & 9 deletions tapchannel/aux_funding_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1891,7 +1891,7 @@ func (f *FundingController) Name() string {
}

// CanHandle returns true if the target message can be routed to this endpoint.
func (f *FundingController) CanHandle(msg protofsm.PeerMsg) bool {
func (f *FundingController) CanHandle(msg protofsm.PeerMsg) (bool, error) {
log.Tracef("Request to handle: %T", msg.Message)
log.Tracef("Request to handle: %v", int64(msg.MsgType()))

Expand All @@ -1906,28 +1906,28 @@ func (f *FundingController) CanHandle(msg protofsm.PeerMsg) bool {
case cmsg.AssetFundingCreatedType:
fallthrough
case cmsg.AssetFundingAckType:
return true
return true, nil
}

case *cmsg.TxAssetInputProof:
return true
return true, nil
case *cmsg.TxAssetOutputProof:
return true
return true, nil
case *cmsg.AssetFundingCreated:
return true
return true, nil
case *cmsg.AssetFundingAck:
return true
return true, nil
}

log.Debugf("Failed to handle: %T", msg.Message)

return false
return false, nil
}

// SendMessage handles the target message, and returns true if the message was
// able being processed.
func (f *FundingController) SendMessage(msg protofsm.PeerMsg) bool {
return fn.SendOrQuit(f.msgs, msg, f.Quit)
func (f *FundingController) SendMessage(msg protofsm.PeerMsg) (bool, error) {
return fn.SendOrQuit(f.msgs, msg, f.Quit), nil
}

// TODO(roasbeef): try to protofsm it?
Expand Down
Loading