Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # R script to simulate chain length during a UASF chain split
- # 0. Variables
- t <- 60 # time in minutes when to calculate the likelihood of a reorg
- n <- 1000 # number of times the simulation runs
- p <- 20 # minority UASF chain in percentage points
- # 1. Create vectors
- chaina <- 1:n
- chainb <- 1:n
- # 2.1 Minority chain length simulation
- for (i in 1:length(chaina)) {
- observationa <- rexp(n,1/(1000/p)) # exponential function to calculate block arrive intervals
- cumulativea <- 1:n # create vector
- for (j in 1:length(observationa)){
- cumulativea[j] <- sum(observationa[1:j])
- } # sum up block arrival intervals
- chaina[i] <- min(which(cumulativea[] > t))
- } # check how long the chain is at time t
- # 2.2 Majority chain length simulation
- for (i in 1:length(chainb)) {
- observationb <- rexp(n,1/(1000/(100-p)))
- cumulativeb <- 1:n
- for (j in 1:length(observationb)){
- cumulativeb[j] <- sum(observationb[1:j])
- }
- chainb[i] <- min(which(cumulativeb[] > t))
- }
- # 3. Compare the two chains
- all <- data.frame(chaina, chainb)
- all$x <- ifelse(chaina > chainb, TRUE, FALSE)
- sum(all$x == TRUE)
- # Notes:
- # The script only compares the chain lengths.
- # There is also the chance that a chain re-organized well before time t
- # Therefore this script systematically UNDERESTIMATES the chance of a re-org
- # @LeoAW https://liongrass.hk
Advertisement
Add Comment
Please, Sign In to add comment