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
- func BatchSaver(batch []Block, db BlockSaver)
- func Batcher(blocks <-chan Block) <-chan []Block
- func BlocksToBlobs(blocks []Block) *network.Blobs
- func ByteToInt32(b []byte, st int) int32
- func ByteToInt64(b []byte, st int) int64
- func Generator(transactionsReceiver <-chan *Transactions, previousValue VDFValue, ...) <-chan Block
- func GeneratorWithTick(transactionsReceiver <-chan *Transactions, previousValue VDFValue, ...) <-chan Block
- func Saver(blocks <-chan Block, db BlockSaver) <-chan []Block
- func TransactionSetEqual(trSet1, trSet2 []Transaction) bool
- func TransactionSize() int
- type Block
- func BlobsToBlocks(blobs *network.Blobs) []Block
- func New(previousValue VDFValue, previousBlockNumber uint64, count uint64, ...) Block
- func NewEmpty(previousValue VDFValue, previousBlockNumber uint64, count uint64) Block
- func NextBlock(previousValue VDFValue, previousBlockNumber uint64, count uint64, ...) Block
- type BlockSaver
- type KeyPair
- type Transaction
- func (t *Transaction) Deserialize(b *[256]byte)
- func (t *Transaction) DeserializeFromSlice(b []byte)
- func (t *Transaction) Equals(tran Transaction) bool
- func (t *Transaction) Serialize() *[256]byte
- func (t *Transaction) Sign(keypair *KeyPair)
- func (t *Transaction) String() string
- func (t *Transaction) Verify() bool
- func (t *Transaction) VerifySignature() bool
- type Transactions
- func (ts *Transactions) Count() int32
- func (ts *Transactions) Equals(trs Transactions) bool
- func (ts *Transactions) FromPackets(packets *network.Packets)
- func (ts *Transactions) Size() int
- func (ts *Transactions) String() string
- func (ts *Transactions) ToBytes() []byte
- func (ts *Transactions) ToPackets(addr net.Addr) *network.Packets
- func (ts *Transactions) Verify() bool
- type VDFValue
Constants ¶
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 BlocksToBlobs ¶
BlocksToBlobs converts blocks to blobs. Assumes that block is no large then blob size.
func ByteToInt32 ¶
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 ¶
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
type BlockSaver ¶
type KeyPair ¶
type KeyPair struct { Public ed25519.PublicKey Private ed25519.PrivateKey }
KeyPair struct represents ed25519 PublicKey and PrivateKey
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 ¶
ExtendedVDF returns the SHA256 of the data + previous VDFValue