Repository: ecadlabs/taquito (ts)

Issue:
confirmationPollingIntervalSecond needs to be updated for the Granada transition
**Is your feature request related to a problem and use case? Please describe.**
Currently, we calculate the `confirmationPollingIntervalSecond` based on the constants of the protocol. In order to reduce the number of calls made to the RPC, the value is calculated once and then it is set on the Context class. 
However, changes to the block time will happen in Granada.
We need to make sure that the `confirmationPollingIntervalSecond` will be updated during the transaction to Granada where the minimal block delay will become 30 seconds. 
Otherwise, Taquito might miss blocks during polling if the interval is too high.

Pull request:
Fix confirmationPollingIntervalSecond for transition to Granada
Closes #923
Thank you for your contribution to Taquito.

Before submitting this PR, please make sure:

- [ ] Your code builds cleanly without any errors or warnings
- [ ] You have added unit tests
- [ ] You have added integration tests (if relevant/appropriate)
- [ ] All public methods or types have TypeDoc coverage with a complete description, and ideally an @example
- [ ] You have added or updated corresponding documentation
- [ ] If relevant, you have written a first draft summary describing the change for inclusion in Release Notes. 

## Release Note Draft Snippet

__If relevant, please write a summary of your change that will be suitable for
inclusion in the Release Notes for the next Taquito release.__


Patch:
diff --git a/packages/taquito-rpc/src/types.ts b/packages/taquito-rpc/src/types.ts
index 1c4b334a7..726e48889 100644
--- a/packages/taquito-rpc/src/types.ts
+++ b/packages/taquito-rpc/src/types.ts
@@ -513,12 +513,6 @@ export type InternalOperationResultKindEnum =
   | OpKind.ORIGINATION
   | OpKind.DELEGATION;
 
-export type SuccessfulManagerOperationResultKindEnum =
-  | OpKind.REVEAL
-  | OpKind.TRANSACTION
-  | OpKind.ORIGINATION
-  | OpKind.DELEGATION;
-
 export type InternalOperationResultEnum =
   | OperationResultReveal
   | OperationResultTransaction
@@ -592,22 +586,9 @@ export interface InternalOperationResult {
   result: InternalOperationResultEnum;
 }
 
-export interface SuccessfulManagerOperationResult {
-  kind: SuccessfulManagerOperationResultKindEnum;
-  consumed_gas?: string;
-  consumed_milligas?: string;
-  storage?: MichelsonV1Expression;
-  big_map_diff?: ContractBigMapDiff;
-  balance_updates?: OperationBalanceUpdates;
-  originated_contracts?: string[];
-  storage_size?: string;
-  paid_storage_size_diff?: string;
-  lazy_storage_diff?: LazyStorageDiff[];
-}
-
 export type MetadataBalanceUpdatesKindEnum = 'contract' | 'freezer';
 export type MetadataBalanceUpdatesCategoryEnum = 'rewards' | 'fees' | 'deposits';
-export type MetadataBalanceUpdatesOriginEnum = 'block' | 'migration' | 'subsidy';
+export type MetadataBalanceUpdatesOriginEnum = 'block' | 'migration';
 
 export interface OperationMetadataBalanceUpdates {
   kind: MetadataBalanceUpdatesKindEnum;
@@ -823,8 +804,6 @@ export interface BlockMetadata {
   consumed_gas: string;
   deactivated: any[];
   balance_updates: OperationBalanceUpdates;
-  liquidity_baking_escape_ema?: number;
-  implicit_operations_results?: SuccessfulManagerOperationResult[];
 }
 
 export type RPCRunOperationParam = {
diff --git a/packages/taquito/src/context.ts b/packages/taquito/src/context.ts
index a2ee49f29..d81e381d9 100644
--- a/packages/taquito/src/context.ts
+++ b/packages/taquito/src/context.ts
@@ -180,6 +180,9 @@ export class Context {
   }
 
   async getConfirmationPollingInterval() {
+    // Granada will generally halve the time between blocks, from 60 seconds to 30 seconds (mainnet).
+    // We reduce the default value in the same proportion, from 10 to 5.
+    const defaultInterval = 5;
     try {
       const constants = await this.rpc.getConstants();
       let blockTime = constants.time_between_blocks[0];
@@ -195,15 +198,21 @@ export class Context {
       // to improvise for polling time to work in prod,
       // testnet and sandbox enviornment.   
       confirmationPollingInterval = confirmationPollingInterval.dividedBy(3);  
-      this.config.confirmationPollingIntervalSecond = confirmationPollingInterval.toNumber() === 0 ?
-                                                      0.1 :
-                                                      confirmationPollingInterval.toNumber();
+
+      if (confirmationPollingInterval.toNumber() > defaultInterval) {
+        // Fix for the transistion from Florence to Granada
+        this.config.confirmationPollingIntervalSecond = defaultInterval;
+      } else {
+        this.config.confirmationPollingIntervalSecond = confirmationPollingInterval.toNumber() === 0 ?
+          0.1 :
+          confirmationPollingInterval.toNumber();
+      }
       return this.config.confirmationPollingIntervalSecond;
     } catch (exception) {
       // Return default value if there is
       // an issue returning from constants
       // file.
-      return 10;
+      return defaultInterval;
     }
   }
 


Test patch:
diff --git a/packages/taquito-rpc/test/taquito-rpc.spec.ts b/packages/taquito-rpc/test/taquito-rpc.spec.ts
index dff5f1db8..f7a598584 100644
--- a/packages/taquito-rpc/test/taquito-rpc.spec.ts
+++ b/packages/taquito-rpc/test/taquito-rpc.spec.ts
@@ -1,14 +1,6 @@
 import { RpcClient } from '../src/taquito-rpc';
 import BigNumber from 'bignumber.js';
-import { 
-  LazyStorageDiffBigMap, 
-  OperationContentsAndResultEndorsement, 
-  OperationContentsAndResultEndorsementWithSlot, 
-  OperationContentsAndResultOrigination, 
-  OperationResultTransaction, 
-  OperationContentsAndResultTransaction, 
-  LazyStorageDiffSaplingState
-} from '../src/types';
+import { LazyStorageDiffBigMap, OperationContentsAndResultEndorsement, OperationContentsAndResultEndorsementWithSlot, OperationContentsAndResultOrigination, OperationResultTransaction, OperationContentsAndResultTransaction, LazyStorageDiffSaplingState } from '../src/types';
 
 /**
  * RpcClient test
@@ -1835,123 +1827,6 @@ describe('RpcClient test', () => {
       done();
     });
 
-
-    it('Access new properties "liquidity_baking_escape_ema", "implicit_operations_results" and "subsidy" in block metadata, proto 10', async done => {
-      httpBackend.createRequest.mockReturnValue(
-        Promise.resolve(
-          {
-            "protocol": "PtGRANADsDU8R9daYKAgWnQYAJ64omN1o3KMGVCykShA97vQbvV",
-            "chain_id": "NetXz969SFaFn8k",
-            "hash": "BMUN7Jt6hv7pVwnVSULxujYXy6qVaFLVoUbd6sQXsagjXpH4iWw",
-            "header": {
-              "level": 218022,
-              "proto": 2,
-              "predecessor": "BKovSSUyqB2dfs5RtrVfFLDugyYavpQ4ULi5KexV8r6HPXA6QL3",
-              "timestamp": "2021-07-19T23:41:07Z",
-              "validation_pass": 4,
-              "operations_hash": "LLoasnx73KY1xekuqN6qnG7GQUrdr6MsuRxJB5S6rqphsR2oX7sDc",
-              "fitness": [ "01", "00000000000353a5" ],
-              "context": "CoWYkYRZg8KswUR8eq9CcXNUuUiqjnck1enWRXmtPRocSg4kPXo4",
-              "priority": 0,
-              "proof_of_work_nonce": "bc2cc86f02c40200",
-              "liquidity_baking_escape_vote": false,
-              "signature": "sigiHpzCAzTLxdSmuD8c3Tn4yHxfhbKErnZwrW8VGr2Q4Y848RNWfLhRrmp9FQExZtXc9ESQab3trtckRdukrvXd7ruBsL4n"
-            },
-            "metadata": {
-              "protocol": "PtGRANADsDU8R9daYKAgWnQYAJ64omN1o3KMGVCykShA97vQbvV",
-              "next_protocol": "PtGRANADsDU8R9daYKAgWnQYAJ64omN1o3KMGVCykShA97vQbvV",
-              "test_chain_status": { "status": "not_running" },
-              "max_operations_ttl": 120,
-              "max_operation_data_length": 32768,
-              "max_block_header_length": 239,
-              "max_operation_list_length": [
-                { "max_size": 4194304, "max_op": 2048 },
-                { "max_size": 32768 },
-                { "max_size": 135168, "max_op": 132 },
-                { "max_size": 524288 }
-              ],
-              "baker": "tz1aWXP237BLwNHJcCD4b3DutCevhqq2T1Z9",
-              "level_info": {
-                "level": 218022,
-                "level_position": 218021,
-                "cycle": 54,
-                "cycle_position": 933,
-                "expected_commitment": false
-              },
-              "voting_period_info": {
-                "voting_period": { "index": 10, "kind": "proposal", "start_position": 204801 },
-                "position": 13220,
-                "remaining": 7259
-              },
-              "nonce_hash": null,
-              "consumed_gas": "0",
-              "deactivated": [],
-              "balance_updates": [],
-              "liquidity_baking_escape_ema": 283204,
-              "implicit_operations_results": [
-                {
-                  "kind": "transaction",
-                  "storage": [
-                    { "int": "104" },
-                    { "int": "177311484916" },
-                    { "int": "118" },
-                    { "bytes": "01e927f00ef734dfc85919635e9afc9166c83ef9fc00" },
-                    { "bytes": "0115eb0104481a6d7921160bc982c5e0a561cd8a3a00" }
-                  ],
-                  "balance_updates": [
-                    {
-                      "kind": "contract",
-                      "contract": "KT1TxqZ8QtKvLu3V3JH7Gx58n7Co8pgtpQU5",
-                      "change": "2500000",
-                      "origin": "subsidy"
-                    }
-                  ],
-                  "consumed_gas": "2118",
-                  "consumed_milligas": "2117037",
-                  "storage_size": "4633"
-                }
-              ]
-            },
-            "operations": []
-          }
-        )
-      );
-
-      const response = await client.getBlock();
-
-      expect(response.metadata.liquidity_baking_escape_ema).toEqual(283204);
-      expect(typeof response.metadata.liquidity_baking_escape_ema).toBe("number");
-
-      expect(response.metadata.implicit_operations_results).toBeDefined();
-      expect(response.metadata.implicit_operations_results!).toBeInstanceOf(Array);
-      expect(response.metadata.implicit_operations_results!.length).toEqual(1);
-
-      expect(response.metadata.implicit_operations_results![0].kind).toEqual('transaction');
-
-      expect(response.metadata.implicit_operations_results![0].consumed_gas).toBeDefined();
-      expect(response.metadata.implicit_operations_results![0].consumed_gas).toEqual('2118');
-
-      expect(response.metadata.implicit_operations_results![0].consumed_milligas).toBeDefined();
-      expect(response.metadata.implicit_operations_results![0].consumed_milligas).toEqual('2117037');
-
-      expect(response.metadata.implicit_operations_results![0].storage).toBeDefined();
-      expect(response.metadata.implicit_operations_results![0].big_map_diff).toBeUndefined();
-
-      expect(response.metadata.implicit_operations_results![0].balance_updates).toBeDefined();
-      expect(response.metadata.implicit_operations_results![0].balance_updates![0].origin).toBeDefined();
-      expect(response.metadata.implicit_operations_results![0].balance_updates![0].origin).toEqual('subsidy');
-
-      expect(response.metadata.implicit_operations_results![0].originated_contracts).toBeUndefined();
-
-      expect(response.metadata.implicit_operations_results![0].storage_size).toBeDefined();
-      expect(response.metadata.implicit_operations_results![0].storage_size).toEqual('4633');
-
-      expect(response.metadata.implicit_operations_results![0].paid_storage_size_diff).toBeUndefined();
-      expect(response.metadata.implicit_operations_results![0].lazy_storage_diff).toBeUndefined();
-
-      done();
-    });
-
   });
 
   describe('getBakingRights', () => {
diff --git a/packages/taquito/test/context.spec.ts b/packages/taquito/test/context.spec.ts
index 1047cc13e..75bd3705a 100644
--- a/packages/taquito/test/context.spec.ts
+++ b/packages/taquito/test/context.spec.ts
@@ -112,6 +112,6 @@ describe('Taquito context class', () => {
             throw new Error();
         });
         const pollingInterval = await new Context(mockRpcClient).getConfirmationPollingInterval();
-        expect(pollingInterval).toBe(10);
+        expect(pollingInterval).toBe(5);
     });
 });