mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-23 06:35:07 +01:00
sweep: remove redundant error from Broadcast
This commit is contained in:
parent
77ff2c0585
commit
719ca5b229
5 changed files with 16 additions and 35 deletions
|
@ -65,7 +65,7 @@ type Bumper interface {
|
|||
// and monitors its confirmation status for potential fee bumping. It
|
||||
// returns a chan that the caller can use to receive updates about the
|
||||
// broadcast result and potential RBF attempts.
|
||||
Broadcast(req *BumpRequest) (<-chan *BumpResult, error)
|
||||
Broadcast(req *BumpRequest) <-chan *BumpResult
|
||||
}
|
||||
|
||||
// BumpEvent represents the event of a fee bumping attempt.
|
||||
|
@ -382,9 +382,9 @@ func (t *TxPublisher) isNeutrinoBackend() bool {
|
|||
// RBF-compliant unless the budget specified cannot cover the fee.
|
||||
//
|
||||
// NOTE: part of the Bumper interface.
|
||||
func (t *TxPublisher) Broadcast(req *BumpRequest) (<-chan *BumpResult, error) {
|
||||
log.Tracef("Received broadcast request: %s", lnutils.SpewLogClosure(
|
||||
req))
|
||||
func (t *TxPublisher) Broadcast(req *BumpRequest) <-chan *BumpResult {
|
||||
log.Tracef("Received broadcast request: %s",
|
||||
lnutils.SpewLogClosure(req))
|
||||
|
||||
// Store the request.
|
||||
requestID, record := t.storeInitialRecord(req)
|
||||
|
@ -398,7 +398,7 @@ func (t *TxPublisher) Broadcast(req *BumpRequest) (<-chan *BumpResult, error) {
|
|||
t.handleInitialBroadcast(record, requestID)
|
||||
}
|
||||
|
||||
return subscriber, nil
|
||||
return subscriber
|
||||
}
|
||||
|
||||
// storeInitialRecord initializes a monitor record and saves it in the map.
|
||||
|
|
|
@ -978,8 +978,7 @@ func TestBroadcast(t *testing.T) {
|
|||
}
|
||||
|
||||
// Send the req and expect no error.
|
||||
resultChan, err := tp.Broadcast(req)
|
||||
require.NoError(t, err)
|
||||
resultChan := tp.Broadcast(req)
|
||||
require.NotNil(t, resultChan)
|
||||
|
||||
// Validate the record was stored.
|
||||
|
@ -1029,8 +1028,7 @@ func TestBroadcastImmediate(t *testing.T) {
|
|||
chainfee.SatPerKWeight(0), errDummy).Once()
|
||||
|
||||
// Send the req and expect no error.
|
||||
resultChan, err := tp.Broadcast(req)
|
||||
require.NoError(t, err)
|
||||
resultChan := tp.Broadcast(req)
|
||||
require.NotNil(t, resultChan)
|
||||
|
||||
// Validate the record was removed due to an error returned in initial
|
||||
|
@ -1541,8 +1539,7 @@ func TestHandleInitialBroadcastSuccess(t *testing.T) {
|
|||
}
|
||||
|
||||
// Register the testing record use `Broadcast`.
|
||||
resultChan, err := tp.Broadcast(req)
|
||||
require.NoError(t, err)
|
||||
resultChan := tp.Broadcast(req)
|
||||
|
||||
// Grab the monitor record from the map.
|
||||
rid := tp.requestCounter.Load()
|
||||
|
@ -1613,8 +1610,7 @@ func TestHandleInitialBroadcastFail(t *testing.T) {
|
|||
mock.Anything).Return(errDummy).Once()
|
||||
|
||||
// Register the testing record use `Broadcast`.
|
||||
resultChan, err := tp.Broadcast(req)
|
||||
require.NoError(t, err)
|
||||
resultChan := tp.Broadcast(req)
|
||||
|
||||
// Grab the monitor record from the map.
|
||||
rid := tp.requestCounter.Load()
|
||||
|
@ -1647,8 +1643,7 @@ func TestHandleInitialBroadcastFail(t *testing.T) {
|
|||
mock.Anything, mock.Anything).Return(errDummy).Once()
|
||||
|
||||
// Register the testing record use `Broadcast`.
|
||||
resultChan, err = tp.Broadcast(req)
|
||||
require.NoError(t, err)
|
||||
resultChan = tp.Broadcast(req)
|
||||
|
||||
// Grab the monitor record from the map.
|
||||
rid = tp.requestCounter.Load()
|
||||
|
|
|
@ -284,14 +284,14 @@ type MockBumper struct {
|
|||
var _ Bumper = (*MockBumper)(nil)
|
||||
|
||||
// Broadcast broadcasts the transaction to the network.
|
||||
func (m *MockBumper) Broadcast(req *BumpRequest) (<-chan *BumpResult, error) {
|
||||
func (m *MockBumper) Broadcast(req *BumpRequest) <-chan *BumpResult {
|
||||
args := m.Called(req)
|
||||
|
||||
if args.Get(0) == nil {
|
||||
return nil, args.Error(1)
|
||||
return nil
|
||||
}
|
||||
|
||||
return args.Get(0).(chan *BumpResult), args.Error(1)
|
||||
return args.Get(0).(chan *BumpResult)
|
||||
}
|
||||
|
||||
// MockFeeFunction is a mock implementation of the FeeFunction interface.
|
||||
|
|
|
@ -838,16 +838,7 @@ func (s *UtxoSweeper) sweep(set InputSet) error {
|
|||
|
||||
// Broadcast will return a read-only chan that we will listen to for
|
||||
// this publish result and future RBF attempt.
|
||||
resp, err := s.cfg.Publisher.Broadcast(req)
|
||||
if err != nil {
|
||||
log.Errorf("Initial broadcast failed: %v, inputs=\n%v", err,
|
||||
inputTypeSummary(set.Inputs()))
|
||||
|
||||
// TODO(yy): find out which input is causing the failure.
|
||||
s.markInputsPublishFailed(set)
|
||||
|
||||
return err
|
||||
}
|
||||
resp := s.cfg.Publisher.Broadcast(req)
|
||||
|
||||
// Successfully sent the broadcast attempt, we now handle the result by
|
||||
// subscribing to the result chan and listen for future updates about
|
||||
|
|
|
@ -673,13 +673,8 @@ func TestSweepPendingInputs(t *testing.T) {
|
|||
setNeedWallet, normalSet,
|
||||
})
|
||||
|
||||
// Mock `Broadcast` to return an error. This should cause the
|
||||
// `createSweepTx` inside `sweep` to fail. This is done so we can
|
||||
// terminate the method early as we are only interested in testing the
|
||||
// workflow in `sweepPendingInputs`. We don't need to test `sweep` here
|
||||
// as it should be tested in its own unit test.
|
||||
dummyErr := errors.New("dummy error")
|
||||
publisher.On("Broadcast", mock.Anything).Return(nil, dummyErr).Twice()
|
||||
// Mock `Broadcast` to return a result.
|
||||
publisher.On("Broadcast", mock.Anything).Return(nil).Twice()
|
||||
|
||||
// Call the method under test.
|
||||
s.sweepPendingInputs(pis)
|
||||
|
|
Loading…
Add table
Reference in a new issue