block

package
v0.0.0-...-d1fccd7 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2019 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package block implements generation and maintenance of the Verifiable Delayed Function Values Ansiblock will be using VDFs for computational timestamping. Incremental VDFs can provide computational evidence that a given version of the state’s system is older (and therefore genuine) by proving that a long-running VDF computation has been performed on the genuine history just after the point of divergence with the fraudulent history. This potentially enables detecting long-range forks without relying on external timestamping mechanisms.

Index

Constants

View Source
const VDFSize int = sha256.Size

VDFSize represents size of vdf value in bytes

Variables

This section is empty.

Functions

func BatchSaver

func BatchSaver(batch []Block, db BlockSaver)

BatchSaver saves given batch to database. The database is used for api access

func Batcher

func Batcher(blocks <-chan Block) <-chan []Block

Batcher thread converts blocks to batches to convert to blobs and send to the socket

func BlocksToBlobs

func BlocksToBlobs(blocks []Block) *network.Blobs

BlocksToBlobs converts blocks to blobs. Assumes that block is no large then blob size.

func ByteToInt32

func ByteToInt32(b []byte, st int) int32

func ByteToInt64

func ByteToInt64(b []byte, st int) int64

TODO check on littleendian system

func Generator

func Generator(transactionsReceiver <-chan *Transactions, previousValue VDFValue, startNumber uint64) <-chan Block

Generator accepts three arguments, channel for reading transaction slices, last value of VDF and a starting number. This function creates a goroutine which creates blocks from transactions read from the input channel. The newly created blocks are sent through output channel. The output channel is created and returned to user by Generator.

func GeneratorWithTick

func GeneratorWithTick(transactionsReceiver <-chan *Transactions, previousValue VDFValue, startNumber uint64, tickDuration time.Duration) <-chan Block

GeneratorWithTick accept an input channel to read transactions and hash of previous block. It creates an output channel and returns to the user. The transactions slices are sent through the input channel and newly creates blocks are returned through the out channel. GeneratorWithTick creates new blocks from transactions, also it creates timestamping blocks at very 'tick'. The tick duration is defined by the user. The "tick block" is just the next block in blockchain without transactions.

func Saver

func Saver(blocks <-chan Block, db BlockSaver) <-chan []Block

Saver thread saves blocks in the file and creates slice of blocks to convert to blobs and send to the socket

func TransactionSetEqual

func TransactionSetEqual(trSet1, trSet2 []Transaction) bool

TransactionSetEqual is responsible for checking equality between transactions Note: Mainly for testing

func TransactionSize

func TransactionSize() int

TransactionSize returns size of transaction in bytes

Types

type Block

type Block struct {
	Number       uint64
	Count        uint64
	Val          VDFValue
	Transactions *Transactions
}

Block represents main struct of our blockchain It uses Verifiable Delayed Function for computational timestamping. VDF can be constructed using incrementally verifiable computation (IVC), in which a proof of correctness for a computation of length t can be computed in parallel to the computation with only polylog(t) processors. Block uses SHA256 as an Incremental VDF. val1 = VDF(val0) val2 = VDF(val1) ... valN = VDF(valN-1) `count` field in Block represents the number of iterations in Incremental VDF `val` field represents the final value after `count` iterations `transactions` is the slice of transactions incorporated in the Block if `transactions` is not empty then Block performes one additional iteration and adds transactions' data into the generated VDF value. This way we can timestamp the transactions. Note: application of VDFs is fragile as it requires precise bounds on the attacker’s computation speed.

func BlobsToBlocks

func BlobsToBlocks(blobs *network.Blobs) []Block

BlobsToBlocks will deserialize slice of blobs into slice of Blocks TODO should be optimized!!!

func New

func New(previousValue VDFValue, previousBlockNumber uint64, count uint64, trans *Transactions) Block

New returns a Block with transactions

func NewEmpty

func NewEmpty(previousValue VDFValue, previousBlockNumber uint64, count uint64) Block

NewEmpty returns an empty Block

func NextBlock

func NextBlock(previousValue VDFValue, previousBlockNumber uint64, count uint64, trans *Transactions) Block

NextBlock returns Block with increased VDFValue

func (*Block) Size

func (b *Block) Size() int

Size method returns size of the block

func (*Block) String

func (b *Block) String() string

String method of Block struct

func (*Block) Verify

func (b *Block) Verify(previousValue VDFValue) bool

Verify method verifies that block is legal TODO should be added transaction verification

type BlockSaver

type BlockSaver interface {
	SaveBlock(blk Block) error
}

type KeyPair

type KeyPair struct {
	Public  ed25519.PublicKey
	Private ed25519.PrivateKey
}

KeyPair struct represents ed25519 PublicKey and PrivateKey

func KeyPairs

func KeyPairs(n int) []KeyPair

KeyPairs generates n Keypair

func NewKeyPair

func NewKeyPair() KeyPair

NewKeyPair generates Public and Private Keypair

type Transaction

type Transaction struct {
	From          ed25519.PublicKey
	To            ed25519.PublicKey
	Token         int64
	Fee           int64
	ValidVDFValue VDFValue
	Signature     []byte
}

Transaction represents user transaction information For now we treat transaction as `token` transfer `from` user `to` another user. This transfer may have a `fee`.

func CreateDummyTransaction

func CreateDummyTransaction(tok int64) Transaction

CreateDummyTransaction responsible for creating dummy Transaction object NOTE: Mainly for testing

func CreateRealTransaction

func CreateRealTransaction(tok int64) Transaction

CreateRealTransaction responsible for creating real Transaction object NOTE: Mainly for testing

func CreateRealTransactionFrom

func CreateRealTransactionFrom(tok int64, from []byte) Transaction

CreateRealTransactionFrom responsible for creating real Transaction object NOTE: Mainly for testing

func NewTransaction

func NewTransaction(from *KeyPair, to ed25519.PublicKey, token int64, fee int64, validVDFValue VDFValue) Transaction

NewTransaction will create new Transaction object

func (*Transaction) Deserialize

func (t *Transaction) Deserialize(b *[256]byte)

Deserialize is responsible for creating Transaction object from byte array

func (*Transaction) DeserializeFromSlice

func (t *Transaction) DeserializeFromSlice(b []byte)

DeserializeFromSlice is responsible for creating Transaction object from byte slice

func (*Transaction) Equals

func (t *Transaction) Equals(tran Transaction) bool

Equals compares two transactions

func (*Transaction) Serialize

func (t *Transaction) Serialize() *[256]byte

Serialize is responsible converting Transaction to byte array

func (*Transaction) Sign

func (t *Transaction) Sign(keypair *KeyPair)

Sign method signs Transaction with ed25519

func (*Transaction) String

func (t *Transaction) String() string

String method of Transaction struct

func (*Transaction) Verify

func (t *Transaction) Verify() bool

Verify method verifies that transaction fee is correct

func (*Transaction) VerifySignature

func (t *Transaction) VerifySignature() bool

VerifySignature method verifies Transaction signature

type Transactions

type Transactions struct {
	Ts []Transaction
}

Transactions represents slice of Transaction-s

func CreateDummyTransactions

func CreateDummyTransactions(n int64) Transactions

CreateDummyTransactions responsible for creating dummy Transactions object NOTE: Mainly for testing

func CreateRealTransactions

func CreateRealTransactions(n int64) Transactions

CreateRealTransactions responsible for creating real Transactions object NOTE: Mainly for testing

func CreateRealTransactionsFrom

func CreateRealTransactionsFrom(n int64, from []byte) Transactions

CreateRealTransactionsFrom responsible for creating real Transactions object NOTE: Mainly for testing

func (*Transactions) Count

func (ts *Transactions) Count() int32

Count method returns number of transactions

func (*Transactions) Equals

func (ts *Transactions) Equals(trs Transactions) bool

Equals comapres two slices of transactions

func (*Transactions) FromPackets

func (ts *Transactions) FromPackets(packets *network.Packets)

FromPackets method creates Transactions from Packets

func (*Transactions) Size

func (ts *Transactions) Size() int

Size method returns size of transactions in bytes

func (*Transactions) String

func (ts *Transactions) String() string

String method of Transactions struct

func (*Transactions) ToBytes

func (ts *Transactions) ToBytes() []byte

ToBytes method converts slice of transactions to the slice of bytes

func (*Transactions) ToPackets

func (ts *Transactions) ToPackets(addr net.Addr) *network.Packets

ToPackets method creates Packets from Transactions

func (*Transactions) Verify

func (ts *Transactions) Verify() bool

Verify method verifies each transaction

type VDFValue

type VDFValue = []byte

VDFValue represents the value of Verifiable Delayed Function.

func ExtendedVDF

func ExtendedVDF(data []byte, val VDFValue) VDFValue

ExtendedVDF returns the SHA256 of the data + previous VDFValue

func VDF

func VDF(data []byte) VDFValue

VDF returns the SHA256 checksum of the data

Jump to

Keyboard shortcuts

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