From ae791b437ad61129e18731b5183cde8c08983533 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Tue, 12 Jan 2021 14:19:57 -0800 Subject: [PATCH] rpc: delete previous pending batch after receiving replacement This change was mostly motivated by the following scenario: 1. Trader accepts and signs a batch proposal, and stores it to disk. 2. Auctioneer send a new batch proposal due to another trader within the batch bailing out. 3. The trader who signed above rejects the new batch proposal. 4. The same trader attempts an account modification (deposit, withdrawal, renewal, etc.). 5. The spend handling logic as part of the account modification commits the staged batch proposal which was replaced, leaving the account state invalid. This is addressed by removing the staged batch proposal upon any replacements, regardless of whether they are accepted or not. This change also falls in line with the existing work done to clear any artifacts as the result of a previously accepted batch proposal. --- rpcserver.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rpcserver.go b/rpcserver.go index 6f5d6da..da3df7c 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -377,6 +377,16 @@ func (s *rpcServer) handleServerMessage(rpcMsg *poolrpc.ServerAuctionMessage) er "artifacts: %v", err) return s.sendRejectBatch(batch, err) } + + // Clear our staging area for the new batch proposal. We + // consider any errors as a hard failure and reject the + // batch. + err = s.server.fundingManager.DeletePendingBatch() + if err != nil { + rpcLog.Errorf("Error clearing previous "+ + "pending batch: %v", err) + return s.sendRejectBatch(batch, err) + } } // Do an in-depth verification of the batch.