mirror of
https://github.com/lightninglabs/pool.git
synced 2026-08-14 12:43:03 +02:00
rpcserver+order: remove funding shim on subsequent prepare
Because we have to always expect an OrderMatchPrepare to be sent multiple times, we need to make sure we clean up our funding shims from the previous pending batch.
This commit is contained in:
parent
e42497a4c6
commit
75bf4e020a
2 changed files with 27 additions and 1 deletions
|
|
@ -275,13 +275,15 @@ func (m *Manager) OrderMatchValidate(batch *Batch) error {
|
|||
// it in case it ends up being the final version.
|
||||
err := m.batchVerifier.Verify(batch)
|
||||
if err != nil {
|
||||
// This error will lead to us sending an OrderMatchReject
|
||||
// message and canceling all funding shims we might already have
|
||||
// set up.
|
||||
return fmt.Errorf("error validating batch: %v", err)
|
||||
}
|
||||
|
||||
m.pendingBatch = batch
|
||||
atomic.StoreUint32(&m.hasPendingBatch, 1)
|
||||
|
||||
// TODO: cancel funding shim of previous pending batch if not nil
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
24
rpcserver.go
24
rpcserver.go
|
|
@ -753,6 +753,30 @@ func (s *rpcServer) handleServerMessage(rpcMsg *clmrpc.ServerAuctionMessage) err
|
|||
rpcLog.Infof("Received PrepareMsg for batch=%x, num_orders=%v",
|
||||
batch.ID[:], len(batch.MatchedOrders))
|
||||
|
||||
// The prepare message can be sent over and over again if the
|
||||
// batch needs adjustment. Clear all previous shims.
|
||||
if s.orderManager.HasPendingBatch() {
|
||||
pendingBatch := s.orderManager.PendingBatch()
|
||||
err := pendingBatch.CancelPendingFundingShims(
|
||||
s.lndClient,
|
||||
func(o order.Nonce) (order.Order, error) {
|
||||
return s.server.db.GetOrder(o)
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
// We can't accept the batch, something went
|
||||
// wrong.
|
||||
rpcLog.Errorf("Error clearing previous batch: "+
|
||||
"%v", err)
|
||||
return s.sendRejectBatch(batch, err)
|
||||
}
|
||||
|
||||
// TODO(guggero): Also abandon any channels that might
|
||||
// still be pending from a previous round of the same
|
||||
// batch or a previous batch that we didn't make it into
|
||||
// the final round.
|
||||
}
|
||||
|
||||
// Do an in-depth verification of the batch.
|
||||
err = s.orderManager.OrderMatchValidate(batch)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue