protocol

package
v0.0.0-...-5e63da4 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HASH_LEN   = 32
	HEIGHT_LEN = 4
	//All fixed sizes form the Block struct are 254
	MIN_BLOCKSIZE           = 254 + crypto.COMM_PROOF_LENGTH + 1
	MIN_BLOCKHEADER_SIZE    = 104
	BLOOM_FILTER_ERROR_RATE = 0.1
)
View Source
const (
	CONFIGTX_SIZE = 83

	BLOCK_SIZE_ID           = 1
	DIFF_INTERVAL_ID        = 2
	FEE_MINIMUM_ID          = 3
	BLOCK_INTERVAL_ID       = 4
	BLOCK_REWARD_ID         = 5
	STAKING_MINIMUM_ID      = 6
	WAITING_MINIMUM_ID      = 7
	ACCEPTANCE_TIME_DIFF_ID = 8
	SLASHING_WINDOW_SIZE_ID = 9
	SLASHING_REWARD_ID      = 10

	MIN_BLOCK_SIZE = 1000      //1KB
	MAX_BLOCK_SIZE = 100000000 //100MB

	MIN_DIFF_INTERVAL = 3 //amount in seconds
	MAX_DIFF_INTERVAL = 9223372036854775807

	MIN_FEE_MINIMUM = 0
	MAX_FEE_MINIMUM = 9223372036854775807

	MIN_BLOCK_INTERVAL = 3     //30 seconds
	MAX_BLOCK_INTERVAL = 86400 //24 hours

	MIN_BLOCK_REWARD = 0
	MAX_BLOCK_REWARD = 1152921504606846976 //2^60

	MIN_STAKING_MINIMUM = 5                   //minimum number of coins for staking
	MAX_STAKING_MINIMUM = 9223372036854775807 //2^60

	MIN_WAITING_TIME = 0 //number of blocks that must a new validator must wait before it can start validating
	MAX_WAITING_TIME = 100000

	MIN_ACCEPTANCE_TIME_DIFF = 0  //semi-synchronous time difference between local clock of validators
	MAX_ACCEPTANCE_TIME_DIFF = 60 //1min

	MIN_SLASHING_WINDOW_SIZE = 0     //window size where a node has to commit itself to a competing branch in case of a fork
	MAX_SLASHING_WINDOW_SIZE = 10000 //1000 Blocks (totally random)

	MIN_SLASHING_REWARD = 0                   // reward for providing a valid slashing proof
	MAX_SLASHING_REWARD = 1152921504606846976 //2^60
)
View Source
const (
	ACCTX_SIZE = 169
)
View Source
const (
	AGGTX_SIZE = 53 //Only constant Values --> Without To & AggregatedTxSlice
)
View Source
const (
	FUNDSTX_SIZE = 213
)
View Source
const (
	STAKETX_SIZE = 106 + crypto.COMM_KEY_LENGTH
)

Variables

This section is empty.

Functions

func Decode

func Decode(encodedData []byte, sliceSize int) (data [][]byte)

func Encode

func Encode(data [][]byte, sliceSize int) []byte

func RandomBytes

func RandomBytes() []byte

func RandomBytesWithLength

func RandomBytesWithLength(length int) []byte

func SerializeHashContent

func SerializeHashContent(data interface{}) (hash [32]byte)

Serializes the input and returns the sha3 hash function applied on ths input

func SerializeHashContentIoT

func SerializeHashContentIoT(data [32]byte) (hash [32]byte)

Types

type AccTx

type AccTx struct {
	Header            byte
	Issuer            [32]byte
	Fee               uint64
	PubKey            [32]byte
	Sig               [64]byte
	Contract          []byte
	ContractVariables []ByteArray
}

func ConstrAccTx

func ConstrAccTx(header byte, fee uint64, address [32]byte, rootPrivKey ed25519.PrivateKey, contract []byte, contractVariables []ByteArray) (tx *AccTx, privKey ed25519.PrivateKey, err error)

func (*AccTx) Decode

func (*AccTx) Decode(encoded []byte) (tx *AccTx)

func (*AccTx) Encode

func (tx *AccTx) Encode() []byte

func (*AccTx) Hash

func (tx *AccTx) Hash() [32]byte

func (*AccTx) Receiver

func (tx *AccTx) Receiver() [32]byte

func (*AccTx) Sender

func (tx *AccTx) Sender() [32]byte

func (*AccTx) Size

func (tx *AccTx) Size() uint64

func (AccTx) String

func (tx AccTx) String() string

func (*AccTx) TxFee

func (tx *AccTx) TxFee() uint64

type Account

type Account struct {
	Address            [32]byte                     // 64 Byte
	Issuer             [32]byte                     // 32 Byte
	Balance            uint64                       // 8 Byte
	TxCnt              uint32                       // 4 Byte
	IsStaking          bool                         // 1 Byte
	CommitmentKey      [crypto.COMM_KEY_LENGTH]byte // represents the modulus N of the RSA public key
	StakingBlockHeight uint32                       // 4 Byte
	Contract           []byte                       // Arbitrary length
	ContractVariables  []ByteArray                  // Arbitrary length
}

func NewAccount

func NewAccount(address [32]byte,
	issuer [32]byte,
	balance uint64,
	isStaking bool,
	commitmentKey [crypto.COMM_KEY_LENGTH]byte,
	contract []byte,
	contractVariables []ByteArray) Account

func (*Account) Decode

func (*Account) Decode(encoded []byte) (acc *Account)

func (*Account) Encode

func (acc *Account) Encode() []byte

func (*Account) Hash

func (acc *Account) Hash() [32]byte

func (Account) String

func (acc Account) String() string

type AggTx

type AggTx struct {
	Amount            uint64
	Fee               uint64
	From              [][32]byte
	To                [][32]byte
	AggregatedTxSlice [][32]byte
}

func ConstrAggTx

func ConstrAggTx(amount uint64, fee uint64, from [][32]byte, to [][32]byte, transactions [][32]byte) (tx *AggTx, err error)

func (*AggTx) Decode

func (*AggTx) Decode(encodedTx []byte) *AggTx

func (*AggTx) Encode

func (tx *AggTx) Encode() (encodedTx []byte)

when we serialize the struct with binary.Write, unexported field get serialized as well, undesired behavior. Therefore, writing own encoder/decoder

func (*AggTx) Hash

func (tx *AggTx) Hash() (hash [32]byte)

func (*AggTx) Receiver

func (tx *AggTx) Receiver() [32]byte

func (*AggTx) Sender

func (tx *AggTx) Sender() [32]byte

func (*AggTx) Size

func (tx *AggTx) Size() uint64

func (AggTx) String

func (tx AggTx) String() string

func (*AggTx) TxFee

func (tx *AggTx) TxFee() uint64

type Block

type Block struct {
	//Header
	Header            byte
	Hash              [32]byte
	PrevHash          [32]byte
	HashWithoutTx     [32]byte //valid hash once all tx are aggregated
	PrevHashWithoutTx [32]byte //valid hash of ancestor once all tx are aggregated
	NrConfigTx        uint8
	NrElementsBF      uint16
	BloomFilter       *bloom.BloomFilter
	Height            uint32
	Beneficiary       [32]byte
	Aggregated        bool //Indicates if All transactions are aggregated with a boolean.

	//Body
	Nonce      [8]byte
	Timestamp  int64
	MerkleRoot [32]byte
	NrAccTx    uint16
	NrFundsTx  uint16
	NrStakeTx  uint16
	NrAggTx    uint16
	NrIoTTx    uint16

	SlashedAddress                 [32]byte
	CommitmentProof                [crypto.COMM_PROOF_LENGTH]byte
	ConflictingBlockHash1          [32]byte
	ConflictingBlockHash2          [32]byte
	ConflictingBlockHashWithoutTx1 [32]byte
	ConflictingBlockHashWithoutTx2 [32]byte
	StateCopy                      map[[32]byte]*Account //won't be serialized, just keeping track of local state changes

	AccTxData    [][32]byte
	FundsTxData  [][32]byte
	ConfigTxData [][32]byte
	StakeTxData  [][32]byte
	AggTxData    [][32]byte
	IoTTxData    [][32]byte
	SizeIoTData  uint64
}

func NewBlock

func NewBlock(prevHash [32]byte, height uint32) *Block

func (*Block) Decode

func (block *Block) Decode(encoded []byte) (b *Block)

func (*Block) Encode

func (block *Block) Encode() []byte

func (*Block) EncodeHeader

func (block *Block) EncodeHeader() []byte

func (*Block) GetBloomFilterSize

func (block *Block) GetBloomFilterSize() uint64

func (*Block) GetBodySize

func (block *Block) GetBodySize() uint64

func (*Block) GetHeaderSize

func (block *Block) GetHeaderSize() uint64

func (*Block) GetSize

func (block *Block) GetSize() uint64

func (*Block) GetTxDataSize

func (block *Block) GetTxDataSize() uint64

func (*Block) HashBlock

func (block *Block) HashBlock() [32]byte

func (*Block) HashBlockWithoutMerkleRoot

func (block *Block) HashBlockWithoutMerkleRoot() [32]byte

func (*Block) InitBloomFilter

func (block *Block) InitBloomFilter(txPubKeys [][32]byte)

func (Block) String

func (block Block) String() string

type ByteArray

type ByteArray []byte

type Change

type Change struct {
	// contains filtered or unexported fields
}

func NewChange

func NewChange(index int, value []byte) Change

func (*Change) GetChange

func (c *Change) GetChange() (int, []byte)

type ConfigTx

type ConfigTx struct {
	Header  byte
	Id      uint8
	Payload uint64
	Fee     uint64
	TxCnt   uint8
	Sig     [64]byte
}

func ConstrConfigTx

func ConstrConfigTx(header byte, id uint8, payload uint64, fee uint64, txCnt uint8, rootPrivKey ed25519.PrivateKey) (tx *ConfigTx, err error)

func (*ConfigTx) Decode

func (*ConfigTx) Decode(encodedTx []byte) (tx *ConfigTx)

func (*ConfigTx) Encode

func (tx *ConfigTx) Encode() (encodedTx []byte)

func (*ConfigTx) Hash

func (tx *ConfigTx) Hash() (hash [32]byte)

func (*ConfigTx) Receiver

func (tx *ConfigTx) Receiver() [32]byte

func (*ConfigTx) Sender

func (tx *ConfigTx) Sender() [32]byte

func (*ConfigTx) Size

func (tx *ConfigTx) Size() uint64

func (ConfigTx) String

func (tx ConfigTx) String() string

func (*ConfigTx) TxFee

func (tx *ConfigTx) TxFee() uint64

type Context

type Context struct {
	Account

	FundsTx
	// contains filtered or unexported fields
}

func NewContext

func NewContext(account Account, fundsTx FundsTx) *Context

func (*Context) GetAddress

func (c *Context) GetAddress() [32]byte

func (*Context) GetAmount

func (c *Context) GetAmount() uint64

func (*Context) GetBalance

func (c *Context) GetBalance() uint64

func (*Context) GetContract

func (c *Context) GetContract() []byte

func (*Context) GetContractVariable

func (c *Context) GetContractVariable(index int) ([]byte, error)

func (*Context) GetFee

func (c *Context) GetFee() uint64

func (*Context) GetIssuer

func (c *Context) GetIssuer() [32]byte

func (*Context) GetSender

func (c *Context) GetSender() [32]byte

func (*Context) GetSig

func (c *Context) GetSig() [64]byte

func (*Context) GetTransactionData

func (c *Context) GetTransactionData() []byte

func (*Context) PersistChanges

func (c *Context) PersistChanges()

func (*Context) SetContractVariable

func (c *Context) SetContractVariable(index int, value []byte) error

type FundsTx

type FundsTx struct {
	Header     byte
	Amount     uint64
	Fee        uint64
	TxCnt      uint32
	From       [32]byte
	To         [32]byte
	Sig        [64]byte
	Aggregated bool
	Data       []byte
}

func ConstrFundsTx

func ConstrFundsTx(header byte, amount uint64, fee uint64, txCnt uint32, from, to [32]byte, sigKey ed25519.PrivateKey, data []byte) (tx *FundsTx, err error)

func (*FundsTx) Decode

func (*FundsTx) Decode(encodedTx []byte) *FundsTx

func (*FundsTx) Encode

func (tx *FundsTx) Encode() (encodedTx []byte)

when we serialize the struct with binary.Write, unexported field get serialized as well, undesired behavior. Therefore, writing own encoder/decoder

func (*FundsTx) Hash

func (tx *FundsTx) Hash() (hash [32]byte)

func (*FundsTx) Receiver

func (tx *FundsTx) Receiver() [32]byte

func (*FundsTx) Sender

func (tx *FundsTx) Sender() [32]byte

func (*FundsTx) Size

func (tx *FundsTx) Size() uint64

func (FundsTx) String

func (tx FundsTx) String() string

func (*FundsTx) TxFee

func (tx *FundsTx) TxFee() uint64

type Iot

type Iot interface {
	Hash() [32]byte
	Encode() []byte
	//Decoding is not listed here, because it returns a different type for each tx (return value Transaction itself
	//is apparently not allowed)
	TxFee() uint64
	Size() uint64
	Sender() [32]byte
	Receiver() [32]byte
}

type IotTx

type IotTx struct {
	Header byte
	TxCnt  uint32
	From   [32]byte
	To     [32]byte
	Sig    [64]byte
	Data   []byte
	Fee    uint64
}

func ConstrIotTx

func ConstrIotTx(header byte, fee uint64, txCnt uint32, from, to [32]byte, sigKey ed25519.PrivateKey, data []byte) (tx *IotTx, err error)

func (*IotTx) Decode

func (*IotTx) Decode(encodedTx []byte) *IotTx

func (*IotTx) Encode

func (tx *IotTx) Encode() (encodedTx []byte)

when we serialize the struct with binary.Write, unexported field get serialized as well, undesired behavior. Therefore, writing own encoder/decoder

func (*IotTx) Hash

func (tx *IotTx) Hash() (hash [32]byte)

func (*IotTx) Receiver

func (tx *IotTx) Receiver() [32]byte

func (*IotTx) Sender

func (tx *IotTx) Sender() [32]byte

func (*IotTx) Size

func (tx *IotTx) Size() uint64

func (IotTx) String

func (tx IotTx) String() string

func (*IotTx) TxFee

func (tx *IotTx) TxFee() uint64

type MerkleTree

type MerkleTree struct {
	Root *Node

	Leafs []*Node
	// contains filtered or unexported fields
}

MerkleTree is the container for the tree. It holds a pointer to the root of the tree, a list of pointers to the leaf nodes, and the merkle root.

func BuildMerkleTree

func BuildMerkleTree(b *Block) *MerkleTree

func (*MerkleTree) MerkleRoot

func (m *MerkleTree) MerkleRoot() [32]byte

MerkleRoot returns the unverified Merkle Root (hash of the root node) of the tree.

func (*MerkleTree) String

func (m *MerkleTree) String() string

String returns a string representation of the tree. Only leaf nodes are included in the output.

func (*MerkleTree) VerifyTree

func (m *MerkleTree) VerifyTree() bool

VerifyTree verify tree validates the hashes at each level of the tree and returns true if the resulting hash at the root of the tree matches the resulting root hash; returns false otherwise.

type Node

type Node struct {
	Parent *Node
	Left   *Node
	Right  *Node

	Hash [32]byte
	// contains filtered or unexported fields
}

Node represents a node, root, or leaf in the tree. It stores pointers to its immediate relationships, a hash, the content stored if it is a leaf, and other metadata.

func GetIntermediate

func GetIntermediate(leaf *Node) (intermediate []*Node, err error)

VerifyContent indicates whether a given content is in the tree and the hashes are valid for that content. Returns true if the expected Merkle Root is equivalent to the Merkle root calculated on the critical path for a given content. Returns true if valid and false otherwise.

func GetLeaf

func GetLeaf(merkleTree *MerkleTree, leafHash [32]byte) *Node

type StakeTx

type StakeTx struct {
	Header        byte                         // 1 Byte
	Fee           uint64                       // 8 Byte
	IsStaking     bool                         // 1 Byte
	Account       [32]byte                     // 32 Byte
	Sig           [64]byte                     // 64 Byte
	CommitmentKey [crypto.COMM_KEY_LENGTH]byte // the modulus N of the RSA public key
}

func ConstrStakeTx

func ConstrStakeTx(header byte, fee uint64, isStaking bool, account [32]byte, signKey ed25519.PrivateKey, commPubKey *rsa.PublicKey) (tx *StakeTx, err error)

func (*StakeTx) Decode

func (*StakeTx) Decode(encodedTx []byte) (tx *StakeTx)

func (*StakeTx) Encode

func (tx *StakeTx) Encode() (encodedTx []byte)

when we serialize the struct with binary.Write, unexported field get serialized as well, undesired behavior. Therefore, writing own encoder/decoder

func (*StakeTx) Hash

func (tx *StakeTx) Hash() (hash [32]byte)

func (*StakeTx) Receiver

func (tx *StakeTx) Receiver() [32]byte

func (*StakeTx) Sender

func (tx *StakeTx) Sender() [32]byte

func (*StakeTx) Size

func (tx *StakeTx) Size() uint64

func (StakeTx) String

func (tx StakeTx) String() string

func (*StakeTx) TxFee

func (tx *StakeTx) TxFee() uint64

type Transaction

type Transaction interface {
	Hash() [32]byte
	Encode() []byte
	//Decoding is not listed here, because it returns a different type for each tx (return value Transaction itself
	//is apparently not allowed)
	TxFee() uint64
	Size() uint64
	Sender() [32]byte
	Receiver() [32]byte
}

Jump to

Keyboard shortcuts

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