blockrecord

package
v0.15.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 23, 2024 License: ISC Imports: 11 Imported by: 0

Documentation

Overview

Package blockrecord - the structure of the block header

includes functions to pack/unpack []byte form

Index

Constants

View Source
const (
	Version                    = 5
	MinimumVersion             = 1
	MinimumBlockNumber         = 2 // 1 => genesis block
	MinimumDifficultyBaseBlock = 3
)

currently supported block version (used by proofer)

View Source
const (
	MinimumTransactions = 2
	MaximumTransactions = 10000
)

maximum transactions in a block limited by uint16 field

View Source
const (
	VersionSize          = 2                   // Block version number
	TransactionCountSize = 2                   // Count of transactions
	NumberSize           = 8                   // This block's number
	PreviousBlockSize    = blockdigest.Length  // 256-bit Argon2d hash of the previous block header
	MerkleRootSize       = merkle.DigestLength // 256-bit SHA3 hash based on all of the transactions in the block
	TimestampSize        = 8                   // Current timestamp as seconds since 1970-01-01T00:00 UTC
	DifficultySize       = 8                   // Current target difficulty in compact format
	NonceSize            = 8                   // 64-bit number (starts at 0)
)

byte sizes for various fields

Variables

This section is empty.

Functions

func AdjustDifficultyAtBlock added in v0.11.0

func AdjustDifficultyAtBlock(height uint64) (float64, float64, error)

AdjustDifficultyAtBlock - adjust difficulty at block, returns next difficulty, current difficulty, error make sure header version is correct before calling this function

func ComputeHeaderHash added in v0.11.0

func ComputeHeaderHash(block []byte) (blockdigest.Digest, error)

ComputeHeaderHash - return the hash of a block's header

func DifficultyByPreviousTimespanAtBlock added in v0.11.0

func DifficultyByPreviousTimespanAtBlock(height uint64) (float64, error)

DifficultyByPreviousTimespanAtBlock - next difficulty value by previous timespan

func DigestFromHashPool added in v0.11.1

func DigestFromHashPool(pool storage.Handle, blockNumber []byte) blockdigest.Digest

DigestFromHashPool - get digest from hash pool

func Finalise added in v0.11.0

func Finalise()

Finalise - shutdown blockrecord logger

func FoundationTxId added in v0.7.0

func FoundationTxId(blockNumber uint64, digest blockdigest.Digest) merkle.Digest

FoundationTxId - create the transaction id for a foundation record its TxId is sha3-256 . concat blockDigest leBlockNumberUint64

func Initialise added in v0.11.0

func Initialise(handle storage.Handle)

Initialise - initialize

func IsBlockToAdjustDifficulty added in v0.11.0

func IsBlockToAdjustDifficulty(height uint64, version uint16) bool

IsBlockToAdjustDifficulty - is block the one to adjust difficulty

func IsDifficultyAppliedVersion added in v0.11.0

func IsDifficultyAppliedVersion(version uint16) bool

IsDifficultyAppliedVersion - is difficulty rule applied at header version

func ResetDifficulty added in v0.11.0

func ResetDifficulty()

ResetDifficulty - reset difficulty to initial value

func ValidBlockLinkage added in v0.11.0

func ValidBlockLinkage(currentDigest blockdigest.Digest, incomingDigestOfPreviousBlock blockdigest.Digest) error

ValidBlockLinkage - valid incoming block linkage

func ValidBlockTimeSpacingAtVersion added in v0.11.0

func ValidBlockTimeSpacingAtVersion(version uint16, timeSpacing uint64) error

ValidBlockTimeSpacingAtVersion - valid block time spacing based on different version

func ValidHeaderVersion added in v0.11.0

func ValidHeaderVersion(currentVersion uint16, incomingVersion uint16) error

ValidHeaderVersion - valid incoming block version

func ValidIncomingDifficulty added in v0.13.0

func ValidIncomingDifficulty(header *Header, chainName string) error

ValidIncomingDifficulty - valid incoming difficulty

Types

type Header struct {
	Version          uint16                 `json:"version"`
	TransactionCount uint16                 `json:"transactionCount"`
	Number           uint64                 `json:"number,string"`
	PreviousBlock    blockdigest.Digest     `json:"previousBlock"`
	MerkleRoot       merkle.Digest          `json:"merkleRoot"`
	Timestamp        uint64                 `json:"timestamp,string"`
	Difficulty       *difficulty.Difficulty `json:"difficulty"`
	Nonce            NonceType              `json:"nonce"`
}

Header - the unpacked header structure

func (*Header) Pack

func (header *Header) Pack() PackedHeader

Pack - turn a record into an array of bytes

type NonceType

type NonceType uint64

NonceType - for header nonce field

func (NonceType) MarshalText

func (nonce NonceType) MarshalText() ([]byte, error)

MarshalText - convert a nonce to little endian hex for JSON

func (*NonceType) UnmarshalText

func (nonce *NonceType) UnmarshalText(b []byte) error

UnmarshalText - convert a nonce little endian hex string to nonce value

type PackedBlock

type PackedBlock []byte

PackedBlock - packed records are just a byte slice

type PackedHeader

type PackedHeader [totalBlockSize]byte

PackedHeader - use fixed size byte array for header to simplify validation

func (PackedHeader) Digest

func (record PackedHeader) Digest() blockdigest.Digest

Digest - digest for a packed header make sure to truncate bytes to correct length

func (PackedHeader) Unpack

func (record PackedHeader) Unpack() (*Header, error)

Unpack - turn a byte slice into a record

type Record added in v0.13.0

type Record interface {
	ExtractHeader([]byte, uint64, bool) (*Header, blockdigest.Digest, []byte, error)
}

Record - interface to extract header

func Get added in v0.13.0

func Get() Record

Get -return Record interface

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL