bridgenode

package
v0.0.0-...-6ac58e8 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2022 License: MIT Imports: 30 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

View Source
var (
	ErrNoDataDir       = errors.New("No bitcoind datadir")
	ErrWrongForestType = errors.New("Invalid forest type of")
	ErrInvalidNetwork  = errors.New("Invalid/not supported net flag given")
	ErrBuildProofs     = errors.New("BuildProofs error")
	ErrArchiveServer   = errors.New("ArchiveServer error")
)
View Source
var HelpMsg = `` /* 1042-byte string literal not displayed */

Functions

func ArchiveServer

func ArchiveServer(cfg *Config, sig chan bool) error

func BNRTTLSpliter

func BNRTTLSpliter(
	bnrChan chan blockAndRev, ttlResultChan chan ttlResultBlock,
	utdir utreeDir)

BNRTTLSplit gets a block&rev and splits the input and output sides. it sends the output side to the txid sorter, and the input side to the ttl lookup worker

func BlockAndRevReader

func BlockAndRevReader(
	aChan, bChan chan blockAndRev, haltRequest chan bool, wg *sync.WaitGroup,
	cfg *Config, finishedHeight 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 BufferDBHeight

func BufferDBHeight(lvdb *leveldb.DB) map[[32]byte]int32

BufferDBHeight buffers the blockheaders to heights given the blocks/index/ leveldb generated by bitcoind

func BuildProofs

func BuildProofs(cfg *Config, sig chan bool) error

build the bridge node / proofs

func FetchBlockHeightFromBufDB

func FetchBlockHeightFromBufDB(header [32]byte, db map[[32]byte]int32) (int32, error)

FetchBlockHeightFromBufDB returns a height given a block header returns error if block header was not found

func FetchBlockHeightFromDB

func FetchBlockHeightFromDB(header [32]byte, db *leveldb.DB) (int32, error)

FetchBlockHeight returns a height given a block header returns error if block header was not found

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 GetUDataBytesFromFile

func GetUDataBytesFromFile(proofDir proofDir, height int32) (b []byte, err error)

GetUDataBytesFromFile reads the proof data from proof.dat and proofoffset.dat and gives the proof & utxo data back. Don't ask for block 0, there is no proof for that. But there is an offset for block 0, which is 0, so it collides with block 1

func InitBridgeNodeState

func InitBridgeNodeState(
	cfg *Config, offsetFinished chan bool) (forest *accumulator.Forest,
	height int32, err error)

initBridgeNodeState attempts to load and initialize the chain state from the disk. If a chain state is not present, chain is initialized to the genesis returns forest, height, lastIndexOffsetHeight, pOffset and error

func OpenIndexFile

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

OpenIndexFile returns the db with only read only option enabled

func Start

func Start(cfg *Config, sig chan bool) error

func TTLLookupWorker

func TTLLookupWorker(
	lChan chan ttlLookupBlock, ttlResultChan chan ttlResultBlock, goChan chan bool,
	txidFile, txidOffsetFile *os.File)

Lookup happens after sorterWriter; the sorterWriter gives the OK to the TTL lookup worker after its done writing to its files

func TxidSortWriterWorker

func TxidSortWriterWorker(
	tChan chan ttlWriteBlock, goChan chan bool, startOffset int64,
	miniTxidFile, txidOffsetFile io.Writer)

TxidSortWriterWorker takes miniTxids in, sorts them, and writes them into a flat file (also writes the offsets files. The offset file doesn't describe byte offsets, but rather 8 byte miniTxids

func VerifyProofs

func VerifyProofs(cfg *Config) error

go through all the proofs and just try to deserialize them

Types

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 Config

type Config struct {

	// the block path from bitcoind's datadir we'll be directly reading from
	BlockDir string

	// where will the bridgenode data be saved to?
	UtreeDir utreeDir

	// enable tracing
	TraceProf string

	// enable cpu profiling
	CpuProf string

	// enable memory profiling
	MemProf string

	// enable profiling http server
	ProfServer string
	// contains filtered or unexported fields
}

all the configs for utreexoserver

func Parse

func Parse(args []string) (*Config, error)

Parse parses the command line arguments and inits the server Config

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, offsetFile *os.File,
	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