Browse Source

Fixed load_protocol_version for old blocks compatibility

PascalCoin 6 years ago
parent
commit
ca983d844c
1 changed files with 11 additions and 2 deletions
  1. 11 2
      src/core/UBlockChain.pas

+ 11 - 2
src/core/UBlockChain.pas

@@ -1555,6 +1555,7 @@ Var i : Integer;
   lastfee : UInt64;
   soob : Byte;
   raw: TRawBytes;
+  load_protocol_version : Word;
 begin
   Lock;
   Try
@@ -1579,12 +1580,15 @@ begin
     // - Value 2 and 3 means that contains protocol info prior to block number
     // - Value 4 means that is loading from storage using protocol v2 (so, includes always operations)
     // - Value 5 means that is loading from storage using TAccountPreviousBlockInfo
+    load_protocol_version := CT_PROTOCOL_1;
     if (soob in [0,2]) then FIsOnlyOperationBlock:=false
     else if (soob in [1,3]) then FIsOnlyOperationBlock:=true
     else if (soob in [4]) then begin
       FIsOnlyOperationBlock:=false;
+      load_protocol_version := CT_PROTOCOL_2;
     end else if (soob in [5]) then begin
       FIsOnlyOperationBlock:=False;
+      load_protocol_version := CT_PROTOCOL_3;
     end else begin
       errors := 'Invalid value in protocol header! Found:'+inttostr(soob)+' - Check if your application version is Ok';
       exit;
@@ -1616,17 +1620,22 @@ begin
       Result := true;
       exit;
     end;
+    //
+    if FOperationBlock.protocol_version>=CT_PROTOCOL_5 then begin
+      load_protocol_version := FOperationBlock.protocol_version;
+    end;
+
     // Fee will be calculated for each operation. Set it to 0 and check later for integrity
     lastfee := OperationBlock.fee;
     FOperationBlock.fee := 0;
     if FOperationBlock.protocol_version>=CT_PROTOCOL_4 then begin
       FOperationsHashTree.Max0feeOperationsBySigner := 1;
     end else FOperationsHashTree.Max0feeOperationsBySigner := -1;
-    Result := FOperationsHashTree.LoadOperationsHashTreeFromStream(Stream,LoadingFromStorage,FOperationBlock.protocol_version,FPreviousUpdatedBlocks,errors);
+    Result := FOperationsHashTree.LoadOperationsHashTreeFromStream(Stream,LoadingFromStorage,load_protocol_version,FPreviousUpdatedBlocks,errors);
     if not Result then begin
       exit;
     end;
-    If FOperationBlock.protocol_version>=CT_PROTOCOL_3 then begin
+    If load_protocol_version>=CT_PROTOCOL_3 then begin
       Result := FPreviousUpdatedBlocks.LoadFromStream(Stream);
       If Not Result then begin
         errors := 'Invalid PreviousUpdatedBlock stream';