in the past I made a video explaining
how block chains work and in it I also
explained what - in a nutshell mining is
the process of creating a new block for
a block chain and filling that block
with transactions but what I didn't
explain is the mining difficulty to
understand what it is let's look again
at the problem that block chains trying
to solve creating consensus amongst a
bunch of computers or nodes on the
Internet in the case of a cryptocurrency
that is agreeing about how individual
users have spent their points it might
not seem like it but this is a
challenging problem to solve nodes on
this network aren't always honest and
they can appear or disappear whenever
they like now imagine you want to join
the Bitcoin network your computer goes
out on the internet and looks for other
nodes that are participating but how
does your computer know which one to
trust every one of these nodes could be
trying to game the system and make
themselves rich the solution proposed by
the creator of Bitcoin was simple the
longest valid chain is the one to pick
but this alone isn't enough if you are
an attacker you could fabricate a very
long chain but false transactions and
everyone will think that yours contains
the truth yikes to solve this problem
Satoshi slowed down the process of
creating new blocks with the
proof-of-work algorithm this is almost
like a lottery where your computer is
doing a bunch of random calculations to
try and be the first to solve a
cryptographic puzzle your chances of
solving it are actually quite low it's
almost like all miners in the world are
trying to pick the same complex lock
everyone tries a bunch of combinations
but in the end only one can solve it
first and when that happens
you have to start all over again to
create the next block on average there
is one computer every 10 minutes that
solves the puzzle and gets the mining
rewards for creating a new block this
time delay of 10 minutes makes it
impossible to artificially create along
this chain because the probability that
your computer alone can pick this lock
is highly unlikely you need many people
trying many random combinations to get
it done within the time frame awesome
problem solved
but hold on there is one more issue our
computers get faster over time so newer
computers could perform more
calculations and potentially create
blocks in under 10 minutes meaning an
attacker could purchase a bunch of
really fast computers and trying to get
ahead of everyone else
luckily Satoshi thought of this as well
and this brings us finally to the mining
difficulty this is a number that
controls how hard your computer has to
work to create a new block and this
isn't a fixed number it's automatically
adjusted every 2000 16th Lok the system
looks at how fast these blocks were
created normally this should take
exactly two weeks if more blocks were
created in that time period the
difficulty is increased and if less
blocks were created the difficulty is
reduced that seems simple enough but why
would the difficulty have to be adjusted
every two weeks we don't get massive
computer upgrades every two weeks right
while the system also has to compensate
for the amount of people that are mining
more miners mean that there is a higher
chance of someone solving the puzzle in
a shorter time frame which means the
difficulties should be increased to
maintain it and the opposite is true as
well if a lot of people stopped mining
the creation of blocks will be longer
and does the difficulty has to be
reduced so in summary the difficulty
adjustments make sure that mining new
blocks always takes around 10 minutes no
matter how fast our computers are and no
matter how many people are mining great
system but it has one big drawback it
tends to lead to centralization see the
main reason why people are mining is
because of the profits as long as your
mining operation is profitable you keep
it going
however an increase in difficulty could
mean that your mining operation now
consumes more electricity than it
generates in rewards at which point
you're forced to stop your mining
operation and this means that only
bigger miners remain active because they
have economies of scale in the case of
Bitcoin we see a few big mining farms
and mining pools taking a significant
portion of this mining market not only
does this centralize a technology that
was meant to be completely distributed
but it also opens the door for these law
mining forms to run attacks against the
network solutions for this problem are
being discussed though but that's for
another video fun side fact if you're a
developer like me you might be thinking
that this Satoshi guy is brilliant
because he thought of all of this but
he's not perfect and also makes mistakes
there's a small bug in the difficulty
adjustment code of Bitcoin after 2016
blocks the difficulty is recalculated
but the code only looks at the first
2015 blocks so if all blocks took
exactly ten minutes to mine and the last
block took 100 days to mine it wouldn't
affect the difficulty at all cool what a
rookie mistake so don't feel too bad
about your own coding skills thank you
so much for watching and as always
subscribe if you like this video until
next time
you