Estoy tratando de calcular el nuevo objetivo para el Bloque 32256, pero no obtengo el resultado esperado. Esto es lo que hice:
1262152739
1261130161
1262152739 - 1261130161 = 1022578
1022578
< 8 semanas)26959535291011309493156476344723991336010898738574164086137773096960
1022578 * 26959535291011309493156476344723991336010898738574164086137773096960
27568227678811762838892963267635169612395352810293691562874591737943162880
27568227678811762838892963267635169612395352810293691562874591737943162880 / 1209600
22791193517536179595645637622052884930882401463536451358196587084939
Por lo que entiendo, este debería ser el nuevo objetivo para el bloque 32256 y los siguientes bloques de 2015. Sin embargo, no lo es: el nuevo objetivo correcto como se indica en blockexplorer es:
22791060871177364286867400663010583169263383106957897897309909286912
Como puede ver, mi resultado fue un poco aproximado, pero no correcto. ¿Que me estoy perdiendo aqui?
Preguntas relacionadas:
El objetivo real (y, por lo tanto, la dificultad) está determinado por su codificación compacta de 32 bits.
Después del cálculo que realizó anteriormente, debe redondearlo al objetivo representable de forma compacta más cercano (precisión de 24 bits, múltiplo de 256). Ese es el objetivo codificado dentro de los bloques, y el que importa.
como dice pieter, debe convertir el objetivo en su valor de "bits", que es un valor comprimido de 4 bytes para el objetivo. el siguiente código de python convierte su valor original en (7) en el valor dado en blockexplorer.com :
import binascii
def target_int2bits(target):
# comprehensive explanation here: bitcoin.stackexchange.com/a/2926/2116
# get in base 256 as a hex string
target_hex = int2hex(target)
bits = "00" if (hex2int(target_hex[: 2]) > 127) else ""
bits += target_hex # append
bits = hex2bin(bits)
length = int2bin(len(bits), 1)
# the bits value could be zero (0x00) so make sure it is at least 3 bytes
bits += hex2bin("0000")
# the bits value could be bigger than 3 bytes, so cut it down to size
bits = bits[: 3]
return length + bits
def bits2target_int(bits_bytes):
exp = bin2int(bits_bytes[: 1]) # exponent is the first byte
mult = bin2int(bits_bytes[1:]) # multiplier is all but the first byte
return mult * (2 ** (8 * (exp - 3)))
def int2hex(intval):
hex_str = hex(intval)[2:]
if hex_str[-1] == "L":
hex_str = hex_str[: -1]
if len(hex_str) % 2:
hex_str = "0" + hex_str
return hex_str
def hex2int(hex_str):
return int(hex_str, 16)
def hex2bin(hex_str):
return binascii.a2b_hex(hex_str)
def int2bin(val, pad_length = False):
hexval = int2hex(val)
if pad_length: # specified in bytes
hexval = hexval.zfill(2 * pad_length)
return hex2bin(hexval)
def bin2hex(binary):
# convert raw binary data to a hex string. also accepts ascii chars (0 - 255)
return binascii.b2a_hex(binary)
def bin2int(binary):
return hex2int(bin2hex(binary))
>>> bits_bytes = target_int2bits(22791193517536179595645637622052884930882401463536451358196587084939)
>>> bin2hex(bits_bytes)
'1d00d86a'
>>> # this ^^ is the value in blockexplorer.com in brackets.
>>> # display the "bits" as an integer:
>>> bits2target_int(bits_bytes)
22791060871177364286867400663010583169263383106957897897309909286912L
>>> # this ^^ is the value at the end of your answer.
Felipe Remy
mullhausen