diff --git a/protocol/txsubmission/client.go b/protocol/txsubmission/client.go index 43a21649..e2dd18e3 100644 --- a/protocol/txsubmission/client.go +++ b/protocol/txsubmission/client.go @@ -124,7 +124,17 @@ func (c *Client) handleRequestTxIds(msg protocol.Message) error { msgRequestTxIds.Req, ) if err != nil { - return err + if !errors.Is(err, ErrStopServerProcess) { + return err + } + if !msgRequestTxIds.Blocking { + return errors.New("cannot stop server process during a non-blocking operation") + } + resp := NewMsgDone() + if err := c.SendMessage(resp); err != nil { + return err + } + return nil } resp := NewMsgReplyTxIds(txIds) if err := c.SendMessage(resp); err != nil { diff --git a/protocol/txsubmission/error.go b/protocol/txsubmission/error.go new file mode 100644 index 00000000..9b681890 --- /dev/null +++ b/protocol/txsubmission/error.go @@ -0,0 +1,21 @@ +// Copyright 2025 Blink Labs Software +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package txsubmission + +import "errors" + +// ErrStopServerProcess is used as a special return value from a RequestTxIds handler function to signify +// that the server should stop asking for transactions. This should only be used when the request is blocking +var ErrStopServerProcess = errors.New("stop server process")