forked from ethereum/rig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exploreJuly21.Rmd
259 lines (211 loc) · 8.58 KB
/
exploreJuly21.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
---
title: "Gas weather report: July 21st - July 27th"
description: |
Do gas limit increases decrease gas prices?
author:
- name: Barnabé Monnot
url: https://twitter.com/barnabemonnot
affiliation: Robust Incentives Group, Ethereum Foundation
affiliation_url: https://github.com/ethereum/rig
date: "`r Sys.Date()`"
output:
distill::distill_article:
toc: true
toc_depth: 3
---
The data includes all blocks produced between July 21st, 2020, 02:00:17 UTC (block 10500001) and July 27th, 2020, 06:37:09 UTC (block 10540000). It was obtained from [Geth](https://geth.ethereum.org/) using a [DAppNode](https://dappnode.io) full node with the wonderful [ethereum-etl](https://github.com/blockchain-etl/ethereum-etl) package from Evgeny Medvedev to extract transaction and block details.
<aside>
You can check the source for this notebook [here (R notebook)](https://github.com/ethereum/rig/tree/master/ethdata/notebooks/gas_weather_reports/exploreJuly21.Rmd). See a previous report [here](https://ethereum.github.io/rig/ethdata/notebooks/explore_data.html).
</aside>
```{r setup, message = FALSE}
library(tidyverse)
library(here)
library(glue)
library(lubridate)
library(forecast)
library(infer)
library(matrixStats)
library(rmarkdown)
library(knitr)
library(skimr)
options(digits=10)
options(scipen = 999)
# Make the plots a bit less pixellated
knitr::opts_chunk$set(dpi = 300)
# A minimal theme I like (zero bonus point for using it though!)
newtheme <- theme_grey() + theme(
axis.text = element_text(size = 9),
axis.title = element_text(size = 12),
axis.line = element_line(colour = "#000000"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
legend.title = element_text(size = 12),
legend.text = element_text(size = 10),
legend.box.background = element_blank(),
legend.key = element_blank(),
strip.text.x = element_text(size = 10),
strip.background = element_rect(fill = "white")
)
theme_set(newtheme)
```
```{r}
start_block <- 10500001
end_block <- 10540000
suffix <- glue("-", start_block, "-", end_block)
```
```{r message = FALSE, eval=FALSE}
txs <- read_csv(here::here(glue("data/txs", suffix, ".csv")))
txs %>% glimpse()
```
```{r message=FALSE, eval=FALSE}
txs_receipts <- txs %>%
left_join(
read_csv(here::here(glue("data/rxs", suffix, ".csv"))),
by = c("hash" = "transaction_hash")) %>%
arrange(block_number)
saveRDS(txs_receipts, here::here(glue("data/txs", suffix, ".rds")))
```
```{r message=FALSE, cache=TRUE}
txs_receipts <- readRDS(here::here(glue("data/txs", suffix, ".rds"))) %>%
mutate(gas_fee = gas_price * gas_used) %>%
mutate(gas_price = gas_price / (10 ^ 9),
gas_fee = gas_fee / (10 ^ 9),
value = value / (10 ^ 18))
```
```{r message=FALSE, cache=TRUE}
blocks <- read_csv(here::here(glue("data/bxs", suffix, ".csv"))) %>%
mutate(block_date = as_datetime(timestamp),
prop_used = gas_used / gas_limit) %>%
rename(block_number = number) %>%
arrange(block_number)
gas_prices_per_block <- blocks %>%
select(block_number) %>%
left_join(
txs_receipts %>%
group_by(block_number) %>%
summarise(
min_gas_price = min(gas_price),
total_gas_used = sum(gas_used),
avg_gas_price = sum(gas_fee) / total_gas_used,
med_gas_price = weightedMedian(gas_price, w = gas_used),
max_gas_price = max(gas_price)
)
) %>%
select(-total_gas_used)
blocks <- blocks %>%
left_join(gas_prices_per_block)
```
```{r message=FALSE, cache=TRUE}
# To get all blocks
date_sample <- interval(min(blocks$block_date), max(blocks$block_date))
# To get a sample
# date_sample <- interval(ymd("2020-05-13"), ymd("2020-05-20"))
blocks_sample <- blocks %>%
filter(block_date %within% date_sample)
txs_sample <- txs_receipts %>%
semi_join(blocks_sample)
```
## Block properties
### Gas used by a block
Miners have some control over the gas limit of a block, but how much gas do blocks generally use?
```{r}
blocks %>%
ggplot() +
geom_histogram(aes(x = gas_used), bins = 1000, fill = "steelblue") +
scale_y_log10() +
xlab("Gas used") +
ylab("Number of blocks")
```
The gas limit was increased from the previous limit of 10M gas, and gas used in blocks soon followed. We notice two peaks. Let's zoom in.
```{r}
blocks %>%
filter(gas_used >= 10.05 * 10^6) %>%
ggplot() +
geom_histogram(aes(x = gas_used), fill = "steelblue", bins = 60) +
xlab("Gas used") +
ylab("Number of blocks")
```
How did the gas limit evolve over time?
```{r}
blocks %>%
ggplot() +
geom_line(aes(x = block_date, y = gas_limit), color = "#FED152") +
xlab("Block date") +
ylab("Gas limit")
```
We have a shift in the middle of the week from about 12M gas limit to 12.5M. Did this release some pressure from transaction fees?
## Gas prices
### Distribution of gas prices
First, some descriptive stats for the distribution of gas prices.
```{r}
quarts = c(0, 0.25, 0.5, 0.75, 1)
tibble(
`Quartile` = quarts,
) %>%
add_column(`Value` = quantile(txs_receipts$gas_price, quarts)) %>%
kable()
```
75% of included transactions post a gas price less than or equal to 90 Gwei. This is much higher than in our last [gas weather report in May](https://ethereum.github.io/rig/ethdata/notebooks/explore_data.html).
### Evolution of gas prices
To compute the average gas price in a block, I do a weighted mean using `gas_used` as weight. I then compute the average gas price over 100 blocks by doing another weighted mean using the total gas used in the blocks.
```{r}
chunk_size <- 100
blocks_sample %>%
mutate(block_chunk = block_number %/% chunk_size) %>%
replace_na(list(
avg_gas_price = 0, gas_used = 0)) %>%
mutate(block_num = gas_used * avg_gas_price) %>%
group_by(block_chunk) %>%
summarise(avg_prop_used = mean(prop_used),
gas_used_chunk = sum(gas_used),
num_chunk = sum(block_num),
avg_gas_price = num_chunk / gas_used_chunk,
block_date = min(block_date)) %>%
ggplot() +
geom_line(aes(x = block_date, y = avg_gas_price), colour = "#F05431") +
xlab("Block timestamp") +
ylab("Average gas price")
```
We see a daily seasonality, with peaks and troughs corresponding to high congestion and low congestion hours of the day.
Did increasing the gas limit reduce the prices overall? We can take a look visually.
```{r}
chunk_size <- 200
blocks_sample %>%
mutate(block_chunk = block_number %/% chunk_size) %>%
replace_na(list(
avg_gas_price = 0, gas_used = 0)) %>%
mutate(block_num = gas_used * avg_gas_price) %>%
group_by(block_chunk) %>%
summarise(gas_limit_chunk = sum(gas_limit),
gas_used_chunk = sum(gas_used),
num_chunk = sum(block_num),
avg_gas_price = num_chunk / gas_used_chunk,
block_date = min(block_date),
prop_used = gas_used_chunk / gas_limit_chunk,
avg_gas_limit_chunk = mean(gas_limit),
avg_gas_used_chunk = mean(gas_used)) %>%
select(block_date, `Gas limit` = avg_gas_limit_chunk, `Average gas price` = avg_gas_price, `Gas used` = avg_gas_used_chunk) %>%
pivot_longer(-block_date, names_to = "Series") %>%
ggplot() +
geom_line(aes(x = block_date, y = value, color = Series)) +
scale_color_manual(values = c("#F05431", "#FED152", "steelblue")) +
facet_grid(rows = vars(Series), scales = "free") +
xlab("Block timestamp")
```
It doesn't seem like it did to me, even though the average gas used in blocks increased in concert with the gas limit. We can look at average prices for transactions in blocks with gas limit lesser than 12.25M gas ("small blocks") vs. blocks with gas limit greater than 12.25M ("big blocks").
```{r cache=TRUE}
big_blocks <- blocks %>%
mutate(big_block = if_else(gas_limit > 12.25 * 10^6, "Big block", "Small block")) %>%
replace_na(list(gas_used = 0, avg_gas_price = 0)) %>%
drop_na()
```
```{r fig.cap="Mean gas price in \"big\" and \"small\" blocks"}
kable(big_blocks %>%
group_by(big_block) %>%
summarise(avg_gas_price = mean(avg_gas_price)))
```
The two averages are mighty close to each other, with big blocks posting even slightly higher gas prices than small ones (a negligible difference however).
<aside>
**Addendum:** Vitalik performed a thorough analysis two years ago looking at [demand elasticity to the block size (on ethresear.ch)](https://ethresear.ch/t/estimating-cryptocurrency-transaction-demand-elasticity-from-natural-experiments/2330). You can also check [his tweet](https://twitter.com/VitalikButerin/status/1288082095051546624) mentioning elasticity close to 1. With gas limit upped from 12M to 12.5M (a mere 4% increase), the result we observe here is not suprising.
</aside>