Skip to content

Commit

Permalink
fix(BlocksService): refactor api.derive for performance, and add hist…
Browse files Browse the repository at this point in the history
…oricApi to BlocksService (#699)

* fix: refactor api.derive.chain in /blocks

* add historicApi

* remove bench test

* tests: adjust tests to accept historicalApi

* refactor blocks to use historicApi

* fix: fetchevents bug

* fix: update historic kusama blocks e2e tests

* put back --silent

* fix: lint

* fix: tests for pallets staking progress

* cleanup

* optimize getWeights, remove expandMetadata

* fix: nexttFeeMultiplier get by parent hash

* add ? to nextFeeMultiplier

* lint
  • Loading branch information
TarikGul committed Oct 11, 2021
1 parent 35b7132 commit 5861cb1
Show file tree
Hide file tree
Showing 24 changed files with 132 additions and 116 deletions.
4 changes: 1 addition & 3 deletions e2e-tests/endpoints/kusama/blocks/2350438.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@
"tip": "0",
"hash": "0x3f5a8e3b5dae4e28252d98e8464f29b50b08a49a36cf71ac009c9a791c1ffa82",
"info": {
"weight": "195000000",
"class": "Normal",
"partialFee": "3333333"
"error": "Fee calculation not supported for 1062#kusama"
},
"era": {
"mortalEra": [
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/endpoints/kusama/blocks/2684767.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"info": {
"weight": "195000000",
"class": "Normal",
"partialFee": "3333333"
"partialFee": "1000000000"
},
"era": {
"mortalEra": [
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/endpoints/kusama/blocks/2713513.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"info": {
"weight": "195000000",
"class": "Normal",
"partialFee": "3333333"
"partialFee": "1000000000"
},
"era": {
"mortalEra": [
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/endpoints/kusama/blocks/2786879.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"info": {
"weight": "195000000",
"class": "Normal",
"partialFee": "3333333"
"partialFee": "166666666"
},
"era": {
"mortalEra": [
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/endpoints/kusama/blocks/2863649.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"info": {
"weight": "195000000",
"class": "Normal",
"partialFee": "51666183"
"partialFee": "2583332366"
},
"era": {
"mortalEra": [
Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/endpoints/kusama/blocks/3102680.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
"info": {
"weight": "30010000",
"class": "Normal",
"partialFee": "60666093"
"partialFee": "3033332186"
},
"era": {
"mortalEra": [
Expand Down Expand Up @@ -242,7 +242,7 @@
"info": {
"weight": "195000000",
"class": "Normal",
"partialFee": "51666183"
"partialFee": "2583332366"
},
"era": {
"mortalEra": [
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/endpoints/kusama/blocks/3305067.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"info": {
"weight": "195000000",
"class": "Normal",
"partialFee": "51999513"
"partialFee": "2599999026"
},
"era": {
"mortalEra": [
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/endpoints/kusama/blocks/3492347.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
"info": {
"weight": "195000000",
"class": "Normal",
"partialFee": "51666183"
"partialFee": "2583332366"
},
"era": {
"mortalEra": [
Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/endpoints/kusama/blocks/3573193.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"info": {
"weight": "190949000",
"class": "Normal",
"partialFee": "51666183"
"partialFee": "2583332366"
},
"era": {
"mortalEra": [
Expand Down Expand Up @@ -223,7 +223,7 @@
"info": {
"weight": "190949000",
"class": "Normal",
"partialFee": "50666193"
"partialFee": "2533332386"
},
"era": {
"mortalEra": [
Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/endpoints/kusama/blocks/4086065.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"info": {
"weight": "209392000",
"class": "Normal",
"partialFee": "52999503"
"partialFee": "2649999006"
},
"era": {
"mortalEra": [
Expand Down Expand Up @@ -206,7 +206,7 @@
"info": {
"weight": "190949000",
"class": "Normal",
"partialFee": "51999513"
"partialFee": "2599999026"
},
"era": {
"mortalEra": [
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/endpoints/kusama/blocks/4178606.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"info": {
"weight": "171665000",
"class": "Normal",
"partialFee": "51999513"
"partialFee": "2599999026"
},
"era": {
"mortalEra": [
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/endpoints/kusama/blocks/4542697.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"info": {
"weight": "215276000",
"class": "Normal",
"partialFee": "51666183"
"partialFee": "2583332366"
},
"era": {
"immortalEra": "0x00"
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/endpoints/kusama/blocks/5265416.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
"info": {
"weight": "647223827000",
"class": "Normal",
"partialFee": "165998390"
"partialFee": "8299997608"
},
"era": {
"mortalEra": [
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/endpoints/kusama/blocks/6065418.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
"info": {
"weight": "218087000",
"class": "Normal",
"partialFee": "51999513"
"partialFee": "2599999026"
},
"era": {
"mortalEra": [
Expand Down
6 changes: 3 additions & 3 deletions e2e-tests/endpoints/kusama/blocks/6396694.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"info": {
"weight": "218087000",
"class": "Normal",
"partialFee": "52332843"
"partialFee": "2616665686"
},
"era": {
"mortalEra": [
Expand Down Expand Up @@ -154,7 +154,7 @@
"info": {
"weight": "218087000",
"class": "Normal",
"partialFee": "52332843"
"partialFee": "2616665686"
},
"era": {
"mortalEra": [
Expand Down Expand Up @@ -224,7 +224,7 @@
"info": {
"weight": "218087000",
"class": "Normal",
"partialFee": "52332843"
"partialFee": "2616665686"
},
"era": {
"mortalEra": [
Expand Down
22 changes: 11 additions & 11 deletions e2e-tests/endpoints/kusama/blocks/6566865.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"info": {
"weight": "182428000",
"class": "Normal",
"partialFee": "51999517"
"partialFee": "2599999269"
},
"era": {
"mortalEra": [
Expand Down Expand Up @@ -152,7 +152,7 @@
"info": {
"weight": "63399913000",
"class": "Normal",
"partialFee": "51334543"
"partialFee": "2566750239"
},
"era": {
"mortalEra": [
Expand Down Expand Up @@ -251,7 +251,7 @@
"info": {
"weight": "627217000",
"class": "Normal",
"partialFee": "80665909"
"partialFee": "4033332622"
},
"era": {
"mortalEra": [
Expand Down Expand Up @@ -348,7 +348,7 @@
"info": {
"weight": "63399913000",
"class": "Normal",
"partialFee": "51334543"
"partialFee": "2566750239"
},
"era": {
"mortalEra": [
Expand Down Expand Up @@ -447,7 +447,7 @@
"info": {
"weight": "423471000",
"class": "Normal",
"partialFee": "80665904"
"partialFee": "4033332350"
},
"era": {
"mortalEra": [
Expand Down Expand Up @@ -510,7 +510,7 @@
"info": {
"weight": "63399913000",
"class": "Normal",
"partialFee": "51334543"
"partialFee": "2566750239"
},
"era": {
"mortalEra": [
Expand Down Expand Up @@ -597,7 +597,7 @@
"info": {
"weight": "423471000",
"class": "Normal",
"partialFee": "66999374"
"partialFee": "3349999290"
},
"era": {
"mortalEra": [
Expand Down Expand Up @@ -683,7 +683,7 @@
"info": {
"weight": "63399913000",
"class": "Normal",
"partialFee": "51334543"
"partialFee": "2566750239"
},
"era": {
"mortalEra": [
Expand Down Expand Up @@ -782,7 +782,7 @@
"info": {
"weight": "423471000",
"class": "Normal",
"partialFee": "80665904"
"partialFee": "4033332350"
},
"era": {
"mortalEra": [
Expand Down Expand Up @@ -845,7 +845,7 @@
"info": {
"weight": "63399913000",
"class": "Normal",
"partialFee": "51001213"
"partialFee": "2550083579"
},
"era": {
"mortalEra": [
Expand Down Expand Up @@ -932,7 +932,7 @@
"info": {
"weight": "423471000",
"class": "Normal",
"partialFee": "66666044"
"partialFee": "3333332630"
},
"era": {
"mortalEra": [
Expand Down
6 changes: 3 additions & 3 deletions e2e-tests/endpoints/kusama/blocks/6819725.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"info": {
"weight": "201727000",
"class": "Normal",
"partialFee": "52332848"
"partialFee": "2616665954"
},
"era": {
"mortalEra": [
Expand Down Expand Up @@ -173,7 +173,7 @@
"info": {
"weight": "201727000",
"class": "Normal",
"partialFee": "51999518"
"partialFee": "2599999294"
},
"era": {
"mortalEra": [
Expand Down Expand Up @@ -260,7 +260,7 @@
"info": {
"weight": "63399913000",
"class": "Normal",
"partialFee": "51001213"
"partialFee": "2550083579"
},
"era": {
"immortalEra": "0x00"
Expand Down
8 changes: 4 additions & 4 deletions e2e-tests/endpoints/kusama/blocks/7354817.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"info": {
"weight": "201217000",
"class": "Normal",
"partialFee": "52332848"
"partialFee": "2616665954"
},
"era": {
"mortalEra": [
Expand Down Expand Up @@ -154,7 +154,7 @@
"info": {
"weight": "201217000",
"class": "Normal",
"partialFee": "52332848"
"partialFee": "2616665954"
},
"era": {
"mortalEra": [
Expand Down Expand Up @@ -224,7 +224,7 @@
"info": {
"weight": "201217000",
"class": "Normal",
"partialFee": "52332848"
"partialFee": "2616665954"
},
"era": {
"mortalEra": [
Expand Down Expand Up @@ -294,7 +294,7 @@
"info": {
"weight": "201217000",
"class": "Normal",
"partialFee": "51999518"
"partialFee": "2599999294"
},
"era": {
"mortalEra": [
Expand Down
9 changes: 7 additions & 2 deletions src/controllers/blocks/BlocksController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,11 @@ export default class BlocksController extends AbstractController<BlocksService>
omitFinalizedTag,
};

const historicApi = await this.api.at(hash);

BlocksController.sanitizedSend(
res,
await this.service.fetchBlock(hash, options)
await this.service.fetchBlock(hash, historicApi, options)
);
};

Expand Down Expand Up @@ -172,10 +174,13 @@ export default class BlocksController extends AbstractController<BlocksService>
omitFinalizedTag,
};

// HistoricApi to fetch any historic information that doesnt include the current runtime
const historicApi = await this.api.at(hash);

// We set the last param to true because we haven't queried the finalizedHead
BlocksController.sanitizedSend(
res,
await this.service.fetchBlock(hash, options)
await this.service.fetchBlock(hash, historicApi, options)
);
};

Expand Down
4 changes: 3 additions & 1 deletion src/controllers/blocks/BlocksExtrinsicsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ export default class BlocksExtrinsicsController extends AbstractController<Block
omitFinalizedTag: true,
};

const block = await this.service.fetchBlock(hash, options);
const historicApi = await this.api.at(hash);

const block = await this.service.fetchBlock(hash, historicApi, options);

/**
* Verify our param `extrinsicIndex` is an integer represented as a string
Expand Down
Loading

0 comments on commit 5861cb1

Please sign in to comment.