Skip to content

Commit 756863d

Browse files
committed
fix lint errors
1 parent ad9e3e9 commit 756863d

File tree

2 files changed

+51
-49
lines changed

2 files changed

+51
-49
lines changed

src/tools/block-eip1559-sim.ts

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ const main = async () => {
6969

7070
// collect block fullness data
7171
let bfData = {
72-
max:0,
73-
maxBlock:0,
74-
min:100,
75-
minBlock:0,
76-
sum:0,
72+
max: 0,
73+
maxBlock: 0,
74+
min: 100,
75+
minBlock: 0,
76+
sum: 0,
7777
values: [],
78-
}
78+
};
7979

8080
let txData = {
8181
max: 0,
@@ -84,13 +84,12 @@ const main = async () => {
8484
minBlock: 0,
8585
sum: 0,
8686
txPerBlock: [],
87-
}
88-
87+
};
8988

9089
type FeeData = {
9190
t: number; // target block fullness
92-
f: number; // baseFee
93-
}
91+
f: number; // baseFee
92+
};
9493
type BlockData = {
9594
h: number; // block number (height)
9695
d: Array<FeeData>; // fees data
@@ -101,37 +100,37 @@ const main = async () => {
101100
return;
102101
}
103102

104-
let blocks:BlockData[] = [];
103+
let blocks: BlockData[] = [];
105104
for (let i = fromBlockNumber; i <= toBlockNumber; i++) {
106-
blocks.push({ h: i, d: []});
105+
blocks.push({ h: i, d: [] });
107106
}
108107

109108
const minBaseFee = 1;
110109
const maxBaseFee = 10e75;
111110

112-
let currentFees: FeeData[] = argv.target.map((t:number) => ({t:t, f: minBaseFee}));
111+
let currentFees: FeeData[] = argv.target.map((t: number) => ({ t: t, f: minBaseFee }));
113112
await promiseConcurrent(
114113
20,
115-
async (block: BlockData, i:number) => {
114+
async (block: BlockData, i: number) => {
116115
const blockDetails = await api.rpc.chain
117116
.getBlockHash(block.h)
118117
.then((blockHash) => getBlockDetails(api, blockHash));
119-
118+
120119
currentFees = currentFees.map((feeData: FeeData) => {
121-
const eip1559 = 1 + ((blockDetails.weightPercentage - feeData.t)/feeData.t) * (1/8);
120+
const eip1559 = 1 + ((blockDetails.weightPercentage - feeData.t) / feeData.t) * (1 / 8);
122121
const newFee = Math.min(Math.max(feeData.f * eip1559, minBaseFee), maxBaseFee);
123-
return {t: feeData.t, f: newFee};
122+
return { t: feeData.t, f: newFee };
124123
});
125124
blocks[i].d = currentFees;
126125
},
127126
blocks,
128127
);
129128

130129
// write to file
131-
const fs = require('fs');
132-
const path = require('path');
130+
const fs = require("fs");
131+
const path = require("path");
133132
const fileName = `block-eip1559-sim-${fromBlockNumber}-${toBlockNumber}.json`;
134-
const filePath = path.join(__dirname,"..","..", "notebooks", "data", fileName);
133+
const filePath = path.join(__dirname, "..", "..", "notebooks", "data", fileName);
135134
fs.writeFileSync(filePath, JSON.stringify(blocks, null, 2));
136135

137136
console.log(`output written to ${filePath}`);

src/tools/block-fullness-stats.ts

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ const main = async () => {
6464

6565
// collect block fullness data
6666
let bfData = {
67-
max:0,
68-
maxBlock:0,
69-
min:100,
70-
minBlock:0,
71-
sum:0,
67+
max: 0,
68+
maxBlock: 0,
69+
min: 100,
70+
minBlock: 0,
71+
sum: 0,
7272
values: [],
73-
}
73+
};
7474

7575
let txData = {
7676
max: 0,
@@ -79,31 +79,30 @@ const main = async () => {
7979
minBlock: 0,
8080
sum: 0,
8181
txPerBlock: [],
82-
}
82+
};
8383

8484
type BlockData = {
8585
number: number;
8686
fill: number;
8787
};
8888

89-
let blocks:BlockData[] = [];
89+
let blocks: BlockData[] = [];
9090
for (let i = fromBlockNumber; i <= toBlockNumber; i++) {
9191
blocks.push({ number: i, fill: 0 });
9292
}
9393

9494
await promiseConcurrent(
9595
20,
96-
async (block: BlockData, i:number) => {
96+
async (block: BlockData, i: number) => {
9797
const blockHash = await api.rpc.chain.getBlockHash(block.number);
9898
const records = await api.query.system.events.at(blockHash);
9999

100-
101100
const blockDetails = await api.rpc.chain
102101
.getBlockHash(block.number)
103102
.then((blockHash) => getBlockDetails(api, blockHash));
104-
103+
105104
blocks[i].fill = blockDetails.weightPercentage;
106-
105+
107106
if (blockDetails.weightPercentage > bfData.max) {
108107
bfData.max = blockDetails.weightPercentage;
109108
bfData.maxBlock = block.number;
@@ -115,7 +114,6 @@ const main = async () => {
115114
bfData.sum += blockDetails.weightPercentage;
116115
bfData.values.push(blockDetails.weightPercentage);
117116

118-
119117
if (blockDetails.txWithEvents.length > txData.max) {
120118
txData.max = blockDetails.txWithEvents.length;
121119
txData.maxBlock = block.number;
@@ -130,43 +128,48 @@ const main = async () => {
130128
blocks,
131129
);
132130

133-
134131
await api.disconnect();
135132

136133
console.log(`Total blocks: ${toBlockNumber - fromBlockNumber}`);
137-
console.log(`Block Fullness Max ${bfData.maxBlock}: ${bfData.max} (whole block: ${(bfData.max+25).toFixed(2)})`);
138-
console.log(`Block Fullness Min ${bfData.minBlock}: ${bfData.min} (whole block: ${(bfData.min+25).toFixed(2)})`);
134+
console.log(
135+
`Block Fullness Max ${bfData.maxBlock}: ${bfData.max} (whole block: ${(bfData.max + 25).toFixed(2)})`,
136+
);
137+
console.log(
138+
`Block Fullness Min ${bfData.minBlock}: ${bfData.min} (whole block: ${(bfData.min + 25).toFixed(2)})`,
139+
);
139140
console.log(`Block Fullness Avg: ${(bfData.sum / blocks.length).toFixed(2)}`);
140141

141142
const percentiles = [90, 80, 70, 60, 50, 45, 40, 37.5, 35, 30, 20, 10];
142-
143-
for (let i of percentiles){
144-
const full75 = percentile(i, bfData.values)
143+
144+
for (let i of percentiles) {
145+
const full75 = percentile(i, bfData.values);
145146
const full = full75 + 25;
146147
console.log(`Block Fullness ${i}perc: ${full75.toFixed(2)} (whole block: ${full.toFixed(2)})`);
147148
}
148149

149150
// simulate EIP1559
150-
console.log(`------- Simulated EIP1559 -------`)
151-
let sim = percentiles.reduce((p, i) => ({...p, [i]:1}), {});
151+
console.log(`------- Simulated EIP1559 -------`);
152+
let sim = percentiles.reduce((p, i) => ({ ...p, [i]: 1 }), {});
152153
let targetFullness = percentiles.map((i) => ({
153-
p: i,
154-
target: percentile(i, bfData.values)
154+
p: i,
155+
target: percentile(i, bfData.values),
155156
}));
156157

157158
blocks.forEach((block) => {
158-
targetFullness.forEach(({p, target}) => {
159-
const eip1559 = 1 + (block.fill - target)/target * (1/8);
159+
targetFullness.forEach(({ p, target }) => {
160+
const eip1559 = 1 + ((block.fill - target) / target) * (1 / 8);
160161
sim[p] = sim[p] * eip1559;
161162
// sim[p] = Math.max(sim[p], eip1559);
162163
});
163164
});
164165

165-
Object.entries(sim).reverse().forEach(([p, price]) => {
166-
console.log(`Simulated ${p}perc, ${percentile(p, bfData.values).toFixed(2)}%: ${price}`);
167-
});
166+
Object.entries(sim)
167+
.reverse()
168+
.forEach(([p, price]) => {
169+
console.log(`Simulated ${p}perc, ${percentile(p, bfData.values).toFixed(2)}%: ${price}`);
170+
});
168171

169-
console.log(`=========== Tx stats ===========`)
172+
console.log(`=========== Tx stats ===========`);
170173
console.log(`Total tx: ${txData.sum}`);
171174
console.log(`Max TXs in a block: ${txData.max} in block ${txData.maxBlock}`);
172175
console.log(`Min TXs in a block: ${txData.min} in block ${txData.minBlock}`);

0 commit comments

Comments
 (0)