Support for Firo ProgPow blocks

This commit is contained in:
Ara 2021-09-07 23:19:18 +04:00 committed by Martin
parent 15f6bd5b37
commit 6bbb81ec10
2 changed files with 47 additions and 23 deletions

View File

@ -28,6 +28,8 @@ const (
GenesisBlockTime = 1414776286 GenesisBlockTime = 1414776286
SwitchToMTPBlockHeader = 1544443200 SwitchToMTPBlockHeader = 1544443200
SwitchToProgPowBlockHeaderTestnet = 1630069200
SwitchToProgPowBlockHeaderMainnet = 1635228000
MTPL = 64 MTPL = 64
SpendTxID = "0000000000000000000000000000000000000000000000000000000000000000" SpendTxID = "0000000000000000000000000000000000000000000000000000000000000000"
@ -156,39 +158,49 @@ func (p *FiroParser) ParseBlock(b []byte) (*bchain.Block, error) {
return nil, err return nil, err
} }
// then MTP header // then ProgPow or MTP header
if isMTP(header) { if(isProgPow(header, p.Params.Net == TestnetMagic)){
mtpHeader := MTPBlockHeader{} progPowHeader := ProgPowBlockHeader{}
mtpHashData := MTPHashData{}
// header // header
err = binary.Read(reader, binary.LittleEndian, &mtpHeader) err = binary.Read(reader, binary.LittleEndian, &progPowHeader)
if err != nil { if err != nil {
return nil, err return nil, err
} }
} else {
if isMTP(header) {
mtpHeader := MTPBlockHeader{}
mtpHashData := MTPHashData{}
// hash data // header
err = binary.Read(reader, binary.LittleEndian, &mtpHashData) err = binary.Read(reader, binary.LittleEndian, &mtpHeader)
if err != nil {
return nil, err
}
// proof
for i := 0; i < MTPL*3; i++ {
var numberProofBlocks uint8
err = binary.Read(reader, binary.LittleEndian, &numberProofBlocks)
if err != nil { if err != nil {
return nil, err return nil, err
} }
for j := uint8(0); j < numberProofBlocks; j++ { // hash data
var mtpData [16]uint8 err = binary.Read(reader, binary.LittleEndian, &mtpHashData)
if err != nil {
return nil, err
}
err = binary.Read(reader, binary.LittleEndian, mtpData[:]) // proof
for i := 0; i < MTPL*3; i++ {
var numberProofBlocks uint8
err = binary.Read(reader, binary.LittleEndian, &numberProofBlocks)
if err != nil { if err != nil {
return nil, err return nil, err
} }
for j := uint8(0); j < numberProofBlocks; j++ {
var mtpData [16]uint8
err = binary.Read(reader, binary.LittleEndian, mtpData[:])
if err != nil {
return nil, err
}
}
} }
} }
} }
@ -299,6 +311,13 @@ func isMTP(h *wire.BlockHeader) bool {
return epoch > GenesisBlockTime && epoch >= SwitchToMTPBlockHeader return epoch > GenesisBlockTime && epoch >= SwitchToMTPBlockHeader
} }
func isProgPow(h *wire.BlockHeader, isTestNet bool) bool {
epoch := h.Timestamp.Unix()
// the genesis block never be MTP block
return isTestNet && epoch >= SwitchToProgPowBlockHeaderTestnet || !isTestNet && epoch >= SwitchToProgPowBlockHeaderMainnet
}
type MTPHashData struct { type MTPHashData struct {
HashRootMTP [16]uint8 HashRootMTP [16]uint8
BlockMTP [128][128]uint64 BlockMTP [128][128]uint64
@ -310,3 +329,8 @@ type MTPBlockHeader struct {
Reserved1 chainhash.Hash Reserved1 chainhash.Hash
Reserved2 chainhash.Hash Reserved2 chainhash.Hash
} }
type ProgPowBlockHeader struct {
Nonce64 int64
MixHash chainhash.Hash
}

View File

@ -22,10 +22,10 @@
"package_name": "backend-firo", "package_name": "backend-firo",
"package_revision": "satoshilabs-1", "package_revision": "satoshilabs-1",
"system_user": "firo", "system_user": "firo",
"version": "0.14.1.2", "version": "0.14.9.1",
"binary_url": "https://github.com/firoorg/firo/releases/download/v0.14.1.2/firo-0.14.1.2-linux64.tar.gz", "binary_url": "https://github.com/firoorg/firo/releases/download/v0.14.9.1/firo-0.14.9.1-linux64.tar.gz",
"verification_type": "sha256", "verification_type": "sha256",
"verification_source": "f2f3e92d891cfcea3b9232bdaf104fd1c7b6d21997a4e2c1297c7e8130c2e3e3", "verification_source": "6384cc13ba193df3d44d2923b20fa562061b4e204ff8e0180147575fc3a1a588",
"extract_command": "tar -C backend --strip 1 -xf", "extract_command": "tar -C backend --strip 1 -xf",
"exclude_files": [ "exclude_files": [
"bin/tor", "bin/tor",