mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-31 17:51:33 +02:00
sweep: remove redundant error from Broadcast
This commit is contained in:
@@ -65,7 +65,7 @@ type Bumper interface {
|
|||||||
// and monitors its confirmation status for potential fee bumping. It
|
// and monitors its confirmation status for potential fee bumping. It
|
||||||
// returns a chan that the caller can use to receive updates about the
|
// returns a chan that the caller can use to receive updates about the
|
||||||
// broadcast result and potential RBF attempts.
|
// 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.
|
// 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.
|
// RBF-compliant unless the budget specified cannot cover the fee.
|
||||||
//
|
//
|
||||||
// NOTE: part of the Bumper interface.
|
// NOTE: part of the Bumper interface.
|
||||||
func (t *TxPublisher) Broadcast(req *BumpRequest) (<-chan *BumpResult, error) {
|
func (t *TxPublisher) Broadcast(req *BumpRequest) <-chan *BumpResult {
|
||||||
log.Tracef("Received broadcast request: %s", lnutils.SpewLogClosure(
|
log.Tracef("Received broadcast request: %s",
|
||||||
req))
|
lnutils.SpewLogClosure(req))
|
||||||
|
|
||||||
// Store the request.
|
// Store the request.
|
||||||
requestID, record := t.storeInitialRecord(req)
|
requestID, record := t.storeInitialRecord(req)
|
||||||
@@ -398,7 +398,7 @@ func (t *TxPublisher) Broadcast(req *BumpRequest) (<-chan *BumpResult, error) {
|
|||||||
t.handleInitialBroadcast(record, requestID)
|
t.handleInitialBroadcast(record, requestID)
|
||||||
}
|
}
|
||||||
|
|
||||||
return subscriber, nil
|
return subscriber
|
||||||
}
|
}
|
||||||
|
|
||||||
// storeInitialRecord initializes a monitor record and saves it in the map.
|
// 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.
|
// Send the req and expect no error.
|
||||||
resultChan, err := tp.Broadcast(req)
|
resultChan := tp.Broadcast(req)
|
||||||
require.NoError(t, err)
|
|
||||||
require.NotNil(t, resultChan)
|
require.NotNil(t, resultChan)
|
||||||
|
|
||||||
// Validate the record was stored.
|
// Validate the record was stored.
|
||||||
@@ -1029,8 +1028,7 @@ func TestBroadcastImmediate(t *testing.T) {
|
|||||||
chainfee.SatPerKWeight(0), errDummy).Once()
|
chainfee.SatPerKWeight(0), errDummy).Once()
|
||||||
|
|
||||||
// Send the req and expect no error.
|
// Send the req and expect no error.
|
||||||
resultChan, err := tp.Broadcast(req)
|
resultChan := tp.Broadcast(req)
|
||||||
require.NoError(t, err)
|
|
||||||
require.NotNil(t, resultChan)
|
require.NotNil(t, resultChan)
|
||||||
|
|
||||||
// Validate the record was removed due to an error returned in initial
|
// 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`.
|
// Register the testing record use `Broadcast`.
|
||||||
resultChan, err := tp.Broadcast(req)
|
resultChan := tp.Broadcast(req)
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// Grab the monitor record from the map.
|
// Grab the monitor record from the map.
|
||||||
rid := tp.requestCounter.Load()
|
rid := tp.requestCounter.Load()
|
||||||
@@ -1613,8 +1610,7 @@ func TestHandleInitialBroadcastFail(t *testing.T) {
|
|||||||
mock.Anything).Return(errDummy).Once()
|
mock.Anything).Return(errDummy).Once()
|
||||||
|
|
||||||
// Register the testing record use `Broadcast`.
|
// Register the testing record use `Broadcast`.
|
||||||
resultChan, err := tp.Broadcast(req)
|
resultChan := tp.Broadcast(req)
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// Grab the monitor record from the map.
|
// Grab the monitor record from the map.
|
||||||
rid := tp.requestCounter.Load()
|
rid := tp.requestCounter.Load()
|
||||||
@@ -1647,8 +1643,7 @@ func TestHandleInitialBroadcastFail(t *testing.T) {
|
|||||||
mock.Anything, mock.Anything).Return(errDummy).Once()
|
mock.Anything, mock.Anything).Return(errDummy).Once()
|
||||||
|
|
||||||
// Register the testing record use `Broadcast`.
|
// Register the testing record use `Broadcast`.
|
||||||
resultChan, err = tp.Broadcast(req)
|
resultChan = tp.Broadcast(req)
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// Grab the monitor record from the map.
|
// Grab the monitor record from the map.
|
||||||
rid = tp.requestCounter.Load()
|
rid = tp.requestCounter.Load()
|
||||||
|
@@ -284,14 +284,14 @@ type MockBumper struct {
|
|||||||
var _ Bumper = (*MockBumper)(nil)
|
var _ Bumper = (*MockBumper)(nil)
|
||||||
|
|
||||||
// Broadcast broadcasts the transaction to the network.
|
// 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)
|
args := m.Called(req)
|
||||||
|
|
||||||
if args.Get(0) == nil {
|
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.
|
// 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
|
// Broadcast will return a read-only chan that we will listen to for
|
||||||
// this publish result and future RBF attempt.
|
// this publish result and future RBF attempt.
|
||||||
resp, err := s.cfg.Publisher.Broadcast(req)
|
resp := 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
|
|
||||||
}
|
|
||||||
|
|
||||||
// Successfully sent the broadcast attempt, we now handle the result by
|
// Successfully sent the broadcast attempt, we now handle the result by
|
||||||
// subscribing to the result chan and listen for future updates about
|
// subscribing to the result chan and listen for future updates about
|
||||||
|
@@ -673,13 +673,8 @@ func TestSweepPendingInputs(t *testing.T) {
|
|||||||
setNeedWallet, normalSet,
|
setNeedWallet, normalSet,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Mock `Broadcast` to return an error. This should cause the
|
// Mock `Broadcast` to return a result.
|
||||||
// `createSweepTx` inside `sweep` to fail. This is done so we can
|
publisher.On("Broadcast", mock.Anything).Return(nil).Twice()
|
||||||
// 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()
|
|
||||||
|
|
||||||
// Call the method under test.
|
// Call the method under test.
|
||||||
s.sweepPendingInputs(pis)
|
s.sweepPendingInputs(pis)
|
||||||
|
Reference in New Issue
Block a user