Browse Source

Fix: relay orphaned operations properly when disconnecting blocks

Herman Schoenfeld 8 years ago
parent
commit
8de78e32e1
1 changed files with 5 additions and 1 deletions
  1. 5 1
      Units/PascalCoin/UNetProtocol.pas

+ 5 - 1
Units/PascalCoin/UNetProtocol.pas

@@ -1155,6 +1155,7 @@ Const CT_LogSender = 'GetNewBlockChainFromClient';
                 for start:=start_c to TNode.Node.Bank.BlocksCount-1 do begin
                 for start:=start_c to TNode.Node.Bank.BlocksCount-1 do begin
                   If TNode.Node.Bank.LoadOperations(OpExecute,start) then begin
                   If TNode.Node.Bank.LoadOperations(OpExecute,start) then begin
                     for i:=0 to OpExecute.Count-1 do begin
                     for i:=0 to OpExecute.Count-1 do begin
+                      // TODO: NEED TO EXCLUDE OPERATIONS ALREADY INCLUDED IN BLOCKCHAIN?
                       oldBlockchainOperations.AddOperationToHashTree(OpExecute.Operation[i]);
                       oldBlockchainOperations.AddOperationToHashTree(OpExecute.Operation[i]);
                     end;
                     end;
                     TLog.NewLog(ltInfo,CT_LogSender,'Recovered '+IntToStr(OpExecute.Count)+' operations from block '+IntToStr(start));
                     TLog.NewLog(ltInfo,CT_LogSender,'Recovered '+IntToStr(OpExecute.Count)+' operations from block '+IntToStr(start));
@@ -1179,7 +1180,10 @@ Const CT_LogSender = 'GetNewBlockChainFromClient';
              [oldBlockchainOperations.OperationsCount,start_c,TNode.Node.Bank.BlocksCount-1]));
              [oldBlockchainOperations.OperationsCount,start_c,TNode.Node.Bank.BlocksCount-1]));
             opsResume := TOperationsResumeList.Create;
             opsResume := TOperationsResumeList.Create;
             Try
             Try
-              i := TNode.Node.AddOperations(Connection,oldBlockchainOperations,opsResume,errors);
+              // Re-add orphaned operations back into the pending pool.
+              // NIL is passed as senderConnection since localnode is considered
+              // the origin, and current sender needs these operations.
+              i := TNode.Node.AddOperations(NIL,oldBlockchainOperations,opsResume,errors);
               TLog.NewLog(ltInfo,CT_LogSender,Format('Executed %d/%d operations. Returned errors: %s',[i,oldBlockchainOperations.OperationsCount,errors]));
               TLog.NewLog(ltInfo,CT_LogSender,Format('Executed %d/%d operations. Returned errors: %s',[i,oldBlockchainOperations.OperationsCount,errors]));
             finally
             finally
               opsResume.Free;
               opsResume.Free;