See the comments in the script. See the optimized branch for a version with concurrent getblock calls that speeds up the execution time on larger ranges.