bridgenode

package
v0.0.0-...-77c8a84 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2020 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//! Unused.
	BlockValidUnknown int32 = 0
	// Reserved
	BlockValidReserved int32 = 1

	//! All parent headers found, difficulty matches, timestamp >= median previous, checkpoint. Implies all parents
	//! are also at least TREE.
	BlockValidTree int32 = 2

	/**
	 * Only first tx is coinbase, 2 <= coinbase input script length <= 100, transactions valid, no duplicate txids,
	 * sigops, size, merkle root. Implies all parents are at least TREE but not necessarily TRANSACTIONS. When all
	 * parent blocks also have TRANSACTIONS, CBlockIndex::nChainTx will be set.
	 */
	BlockValidTransactions int32 = 3

	//! Outputs do not overspend inputs, no double spends, coinbase output ok, no immature coinbase spends, BIP30.
	//! Implies all parents are also at least CHAIN.
	BlockValidChain int32 = 4

	//! Scripts & signatures ok. Implies all parents are also at least SCRIPTS.
	BlockValidScripts int32 = 5

	//! All validity bits.
	BlockValidMask int32 = BlockValidReserved | BlockValidTree | BlockValidTransactions |
		BlockValidChain | BlockValidScripts

	BlockHaveData int32 = 8  //!< full block available in blk*.dat
	BlockHaveUndo int32 = 16 //!< undo data available in rev*.dat
	BlockHaveMask int32 = BlockHaveData | BlockHaveUndo

	BlockFailedValid int32 = 32 //!< stage after last reached validness failed
	BlockFailedChild int32 = 64 //!< descends from failed block
	BlockFailedMask  int32 = BlockFailedValid | BlockFailedChild

	BlockOptWitness int32 = 128 //!< block data in blk*.data was received with a witness-enforcing client
)

Block status bits

View Source
const MaxMessagePayload = (1024 * 1024 * 32) // 32MB

MaxMessagePayload is the maximum bytes a message can be regardless of other individual limits imposed by messages themselves.

Variables

This section is empty.

Functions

func BlockAndRevReader

func BlockAndRevReader(
	blockChan chan BlockAndRev, dataDir, cOffsetFile string,
	maxHeight, curHeight int32)

BlockAndRevReader is a wrapper around GetRawBlockFromFile so that the process can be made into a goroutine. As long as it's running, it keeps sending the entire blocktxs and height to bchan with TxToWrite type. It also puts in the proofs. This will run on the archive server, and the data will be sent over the network to the CSN.

func BufferDB

func BufferDB(lvdb *leveldb.DB) map[[32]byte]uint32

BufferDB buffers the leveldb key values into map in memory

func BuildProofs

func BuildProofs(
	param chaincfg.Params, dataDir string,
	forestInRam, forestCached bool, sig chan bool) error

build the bridge node / proofs

func DbWorker

func DbWorker(
	bChan chan *leveldb.Batch, lvdb *leveldb.DB, wg *sync.WaitGroup)

DbWorker writes everything to the db. It's it's own goroutine so it can work at the same time that the reads are happening

func GetBlockBytesFromFile

func GetBlockBytesFromFile(
	height int32, offsetFileName string, blockDir string) (b []byte, err error)

GetBlockBytesFromFile reads a block from the right .dat file and returns the bytes without deserializing the block If you ask for block 0, it will give you an error. If you ask for block 1, it gives you the block at offset 0 which is consensus height 1.

func OpenIndexFile

func OpenIndexFile(dataDir string) (*leveldb.DB, error)

OpenIndexFile returns the db with only read only option enabled

func WriteBlock

func WriteBlock(bnr BlockAndRev,
	batchan chan *leveldb.Batch, wg *sync.WaitGroup)

WriteBlock sends off ttl info to dbWorker to be written to ttldb

Types

type BlockAndRev

type BlockAndRev struct {
	Height int32
	Rev    RevBlock
	Blk    wire.MsgBlock
}

BlockAndRev is a regular block and a rev block stuck together

type CBlockFileIndex

type CBlockFileIndex struct {
	Version int32  // nVersion info of the block
	Height  int32  // Height of the block
	Status  int32  // validation status of the block in Bitcoin Core
	TxCount int32  // tx count in the block
	File    int32  // file num
	DataPos uint32 // blk*.dat file offset
	UndoPos uint32 // rev*.dat file offset
}

CBlockFileIndex is a reimplementation of the Bitcoin Core class CBlockFileIndex

func ReadCBlockFileIndex

func ReadCBlockFileIndex(r io.ReadSeeker) (cbIdx CBlockFileIndex)

type DeathInfo

type DeathInfo struct {
	// DeathHeight is where the TxOs are spent
	// TxPos is the index within the TX
	DeathHeight, TxPos int32
	Txid               [32]byte
}

DeathInfo is needed to asynchronously read from the leveldb Insures that the TxOs are in order

type RawHeaderData

type RawHeaderData struct {
	// CurrentHeaderHash is the double hashed 32 byte header
	CurrentHeaderHash [32]byte
	// Prevhash is the 32 byte previous header included in the 80byte header.
	// Needed for ordering
	Prevhash [32]byte
	// FileNum is the blk*.dat file number
	FileNum [4]byte
	// Offset is where it is in the .dat file.
	Offset [4]byte
	// revblock position
	UndoPos uint32
}

RawHeaderData is used for blk*.dat offsetfile building Used for ordering blocks as they aren't stored in order in the blk files. Includes 32 bytes of sha256 hash along with other variables needed for offsetfile building.

type RevBlock

type RevBlock struct {
	Magic [4]byte   // Network magic bytes
	Size  [4]byte   // size of the BlockUndo record
	Txs   []*TxUndo // actual undo record
	Hash  [32]byte  // 32 byte double sha256 hash of the block
}

RevBlock is the structure of how a block is stored in the rev*.dat file the Bitcoin Core generates

func GetRawBlocksFromDisk

func GetRawBlocksFromDisk(startAt int32, count int32, offsetFileName string,
	blockDir string) (blocks []wire.MsgBlock, revs []RevBlock, err error)

GetRawBlocksFromDisk retrives multiple consecutive blocks starting at height `startAt`. `count` is a upper limit for the number of blocks read. Only blocks that are contained in the same blk file are returned.

func (*RevBlock) Deserialize

func (rb *RevBlock) Deserialize(r io.Reader) error

Deserialize takes a reader and reads a single block Only initializes the Block var in RevBlock

type TxInUndo

type TxInUndo struct {
	Height int32

	// Version of the original tx that created this tx
	Varint uint64

	// scriptPubKey of the spent UTXO
	PKScript []byte

	// Value of the spent UTXO
	Amount int64

	// Whether if the TxInUndo is a coinbase or not
	// Not actually included in the rev*.dat files
	Coinbase bool
}

TxInUndo is the structure of the undo transaction Everything is uncompressed here see github.com/bitcoin/bitcoin/src/undo.h

type TxUndo

type TxUndo struct {
	TxIn []*TxInUndo
}

TxUndo contains the TxInUndo records. see github.com/bitcoin/bitcoin/src/undo.h

func (*TxUndo) Deserialize

func (tx *TxUndo) Deserialize(r io.Reader) error

Deserialize takes a reader and reads all the TxUndo data

Jump to

Keyboard shortcuts

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