protocol

package
v0.0.0-...-363963d Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2020 License: Apache-2.0 Imports: 18 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           = 393 + crypto.COMM_PROOF_LENGTH + 1 // = 650 bytes
	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 (
	//TODO recalculate
	AGGDATATX_SIZE = 0 //Only constant Values --> Without To, From & AggregatedTxSlice
)
View Source
const (
	AGGTX_SIZE = 85 //Only constant Values --> Without To, From & AggregatedTxSlice
)
View Source
const (
	//TODO Recalculate
	COMMITTEETX_SIZE = 0
)
View Source
const (
	CONTRACTTX_SIZE = 201
)
View Source
const (
	//TODO calculate
	DATATX_SIZE = 0
)
View Source
const (
	FINETX_SIZE = 246 //Todo recalculate
)
View Source
const (
	FUNDSTX_SIZE = 246
)
View Source
const (
	STAKETX_SIZE = 106 + crypto.COMM_KEY_LENGTH
)

Variables

This section is empty.

Functions

func CheckForHeightBlock

func CheckForHeightBlock(blockStash *BlockStash, height uint32) int

This function counts how many blocks in the stash have some predefined height

func CheckForHeightCommitteeCheck

func CheckForHeightCommitteeCheck(committeeCheckStash *CommitteeCheckStash, height uint32) int

This function counts how many state transisitions in the stash have some predefined height

func CheckForHeightStateTransition

func CheckForHeightStateTransition(statestash *StateStash, height uint32) int

This function counts how many state transisitions in the stash have some predefined height

func CheckForHeightTransactionAssignment

func CheckForHeightTransactionAssignment(transactionAssignmentStash *TransactionAssignmentStash, height uint32) int

This function counts how many transaction assignments in the stash have some predefined height

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 ReturnBlockHashesForHeight

func ReturnBlockHashesForHeight(blockStash *BlockStash, height uint32) [][32]byte

func SerializeHashContent

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

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

Types

type AccTx

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

func ConstrAccTx

func ConstrAccTx(header byte, fee uint64, address [64]byte, rootPrivKey *ecdsa.PrivateKey, contract []byte, contractVariables []ByteArray) (tx *AccTx, newAccAddress *ecdsa.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            [64]byte                     // 64 Byte
	Issuer             [32]byte                     // 32 Byte
	Balance            uint64                       // 8 Byte
	TxCnt              uint32                       // 4 Byte
	IsStaking          bool                         // 1 Byte
	IsCommittee        bool                         // 1 Byte
	CommitmentKey      [crypto.COMM_KEY_LENGTH]byte // represents the modulus N of the RSA public key
	CommitteeKey       [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 [64]byte,
	issuer [32]byte,
	balance uint64,
	isStaking bool,
	isCommittee bool,
	commitmentKey [crypto.COMM_KEY_LENGTH]byte,
	committeeKey [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 AggDataTx

type AggDataTx struct {
	Fee uint64
	//only one sender for each aggregated data transaction
	From             [32]byte
	To               [][32]byte
	AggregatedDataTx [][32]byte
	Data             [][]byte
}

func ConstrAggDataTx

func ConstrAggDataTx(data [][]byte, fee uint64, from [32]byte, to [][32]byte, transactions [][32]byte) (tx *AggDataTx, err error)

func (*AggDataTx) Decode

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

func (*AggDataTx) Encode

func (tx *AggDataTx) 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 (*AggDataTx) Hash

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

func (*AggDataTx) Receiver

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

func (*AggDataTx) Sender

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

func (*AggDataTx) Size

func (tx *AggDataTx) Size() uint64

func (AggDataTx) String

func (tx AggDataTx) String() string

func (*AggDataTx) TxFee

func (tx *AggDataTx) TxFee() uint64

type AggTx

type AggTx struct {
	Amount            uint64
	Fee               uint64
	From              [][32]byte
	To                [][32]byte
	AggregatedTxSlice [][32]byte
	//says if the AggTx has been aggregated into another AggTx. not needed anymore.
	Aggregated bool
	Block      [32]byte //This saves the blockHashWithoutTransactions into which the transaction was usually validated. Needed for rollback.
	MerkleRoot [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
	ShardId  int
	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 //8 byte
	Height       uint32
	Beneficiary  [32]byte

	//Body
	Nonce                 [8]byte
	Timestamp             int64
	MerkleRoot            [32]byte
	NrAccTx               uint16
	NrFundsTx             uint16
	NrStakeTx             uint16
	NrCommitteeTx         uint16
	NrAggTx               uint16
	NrDataTx              uint16
	NrAggDataTx           uint16
	NrFineTx              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

	ContractTxData  [][32]byte
	AccTxData       [][32]byte
	FundsTxData     [][32]byte
	DataTxData      [][32]byte
	ConfigTxData    [][32]byte
	StakeTxData     [][32]byte
	CommitteeTxData [][32]byte
	AggTxData       [][32]byte
	AggDataTxData   [][32]byte
	FineTxData      [][32]byte
}

func NewBlock

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

func ReturnBlockForPosition

func ReturnBlockForPosition(blockStash *BlockStash, position int) (stateHash [32]byte, block *Block)

func ReturnBlockStashForHeight

func ReturnBlockStashForHeight(blockStash *BlockStash, 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 BlockStash

type BlockStash struct {
	M    map[KeyBlock]ValueBlock
	Keys []KeyBlock
}

func NewShardBlockStash

func NewShardBlockStash() *BlockStash

func (*BlockStash) BlockIncluded

func (m *BlockStash) BlockIncluded(k KeyBlock) bool

func (*BlockStash) DeleteFirstEntry

func (m *BlockStash) DeleteFirstEntry()

This function includes a key and tracks its order in the slice. No need to put the lock because it is used from the calling function

func (*BlockStash) Set

func (m *BlockStash) Set(k KeyBlock, v ValueBlock)

This function includes a key and tracks its order in the slice

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 CommitteeCheck

type CommitteeCheck struct {
	Height                    int
	Sender                    [32]byte
	CommitteeProof            [crypto.COMM_PROOF_LENGTH]byte
	SlashedAddressesCommittee [][32]byte
	SlashedAddressesShards    [][32]byte
}

func NewCommitteeCheck

func NewCommitteeCheck(height int, sender [32]byte, committeeProof [crypto.COMM_PROOF_LENGTH]byte, slashedAddressesCommittee [][32]byte, slashedAddressesShards [][32]byte) *CommitteeCheck

func ReturnCommitteeCheckForHeight

func ReturnCommitteeCheckForHeight(committeeCheckStash *CommitteeCheckStash, height uint32) []*CommitteeCheck

func ReturnCommitteeCheckForPosition

func ReturnCommitteeCheckForPosition(committeeCheckStash *CommitteeCheckStash, position int) (committeeCheckHash [32]byte, committeeCheck *CommitteeCheck)

func (*CommitteeCheck) DecodeCommitteeCheck

func (*CommitteeCheck) DecodeCommitteeCheck(encoded []byte) (ta *CommitteeCheck)

func (*CommitteeCheck) EncodeCommitteeCheck

func (cc *CommitteeCheck) EncodeCommitteeCheck() []byte

func (*CommitteeCheck) HashCommitteCheck

func (cc *CommitteeCheck) HashCommitteCheck() [32]byte

type CommitteeCheckStash

type CommitteeCheckStash struct {
	M    map[KeyCheck]ValueCheck
	Keys []KeyCheck
}

func NewCommitteeCheckStash

func NewCommitteeCheckStash() *CommitteeCheckStash

func (*CommitteeCheckStash) CommitteeCheckIncluded

func (m *CommitteeCheckStash) CommitteeCheckIncluded(k KeyCheck) bool

func (*CommitteeCheckStash) DeleteFirstEntry

func (m *CommitteeCheckStash) DeleteFirstEntry()

This function includes a key and tracks its order in the slice. No need to put the lock because it is used from the calling function

func (*CommitteeCheckStash) Set

This function includes a key and tracks its order in the slice

type CommitteeTx

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

func ConstrCommitteeTx

func ConstrCommitteeTx(header byte, fee uint64, isCommittee bool, account [64]byte, signKey *ecdsa.PrivateKey, commPubKey *rsa.PublicKey) (tx *CommitteeTx, err error)

func (*CommitteeTx) Decode

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

func (*CommitteeTx) Encode

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

func (*CommitteeTx) Hash

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

func (*CommitteeTx) Receiver

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

func (*CommitteeTx) Sender

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

func (*CommitteeTx) Size

func (tx *CommitteeTx) Size() uint64

func (CommitteeTx) String

func (tx CommitteeTx) String() string

func (*CommitteeTx) TxFee

func (tx *CommitteeTx) TxFee() uint64

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 *ecdsa.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() [64]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) GetSig1

func (c *Context) GetSig1() [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 ContractTx

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

func ConstrContractTx

func ConstrContractTx(header byte, fee uint64, issuerSigKey *ecdsa.PrivateKey, contract []byte, contractVariables []ByteArray) (tx *ContractTx, newContractKey *ecdsa.PrivateKey, err error)

func (*ContractTx) Decode

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

func (*ContractTx) Encode

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

func (*ContractTx) Hash

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

func (*ContractTx) Size

func (tx *ContractTx) Size() uint64

func (ContractTx) String

func (tx ContractTx) String() string

func (*ContractTx) TxFee

func (tx *ContractTx) TxFee() uint64

type DataSummary

type DataSummary struct {
	Address [32]byte
	Data    [][]byte
}

Seperate data type to keep it more expandable Data summary data type stores information about all data that has been sent from a particular address

func NewDataSummary

func NewDataSummary(address [32]byte) *DataSummary

func (*DataSummary) Decode

func (*DataSummary) Decode(encoded []byte) (ds *DataSummary)

func (*DataSummary) Encode

func (ds *DataSummary) Encode() []byte

func (*DataSummary) Hash

func (ds *DataSummary) Hash() [32]byte

Address is the unique identifier of a data summary

func (DataSummary) String

func (ds DataSummary) String() string

type DataTx

type DataTx struct {
	Header    byte
	Fee       uint64
	TxCnt     uint32
	TimeStamp int64
	From      [32]byte
	To        [32]byte
	Sig1      [64]byte
	Sig2      [64]byte
	Data      []byte
}

func ConstrDataTx

func ConstrDataTx(header byte, fee uint64, txCnt uint32, from, to [32]byte, sig1Key *ecdsa.PrivateKey, sig2Key *ecdsa.PrivateKey, data []byte) (tx *DataTx, err error)

func (*DataTx) Decode

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

func (*DataTx) Encode

func (tx *DataTx) 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 (*DataTx) Hash

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

func (*DataTx) Receiver

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

func (*DataTx) Sender

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

func (*DataTx) Size

func (tx *DataTx) Size() uint64

func (DataTx) String

func (tx DataTx) String() string

func (*DataTx) TxFee

func (tx *DataTx) TxFee() uint64

type EpochBlock

type EpochBlock struct {
	//Header
	Header          byte
	Hash            [32]byte
	PrevShardHashes [][32]byte
	Height          uint32

	//Body
	Timestamp          int64
	MerkleRoot         [32]byte
	MerklePatriciaRoot [32]byte
	CommitmentProof    [crypto.COMM_PROOF_LENGTH]byte
	State              map[[32]byte]*Account
	ValMapping         *ValShardMapping
	CommitteeLeader    [32]byte //hash of the wallet of the chosen committee leader
	NofShards          int
	Beneficiary        [32]byte
}

func NewEpochBlock

func NewEpochBlock(prevShardHashes [][32]byte, height uint32) *EpochBlock

func (*EpochBlock) Decode

func (epochBlock *EpochBlock) Decode(encoded []byte) (b *EpochBlock)

func (*EpochBlock) Encode

func (epochBlock *EpochBlock) Encode() []byte

func (*EpochBlock) EncodeHeader

func (epochBlock *EpochBlock) EncodeHeader() []byte

func (*EpochBlock) HashEpochBlock

func (epochBlock *EpochBlock) HashEpochBlock() [32]byte

func (EpochBlock) String

func (epochBlock EpochBlock) String() string

func (EpochBlock) StringPrevHashes

func (epochBlock EpochBlock) StringPrevHashes() (prevHashes string)

func (EpochBlock) StringState

func (epochBlock EpochBlock) StringState() (state string)

type FineTx

type FineTx struct {
	Header    byte
	Amount    uint64
	Fee       uint64
	From      [32]byte
	To        [32]byte
	Sig       [64]byte
	TimeStamp int64
}

func ConstrFineTx

func ConstrFineTx(header byte, amount uint64, fee uint64, from [32]byte, to [32]byte, sigKey *ecdsa.PrivateKey) (tx *FineTx, err error)

func (*FineTx) Decode

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

func (*FineTx) Encode

func (tx *FineTx) 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 (*FineTx) Hash

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

func (*FineTx) Receiver

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

func (*FineTx) Sender

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

func (*FineTx) Size

func (tx *FineTx) Size() uint64

func (FineTx) String

func (tx FineTx) String() string

func (*FineTx) TxFee

func (tx *FineTx) TxFee() uint64

type FundsTx

type FundsTx struct {
	Header    byte
	Amount    uint64
	Fee       uint64
	TxCnt     uint32
	TimeStamp int64
	From      [32]byte
	To        [32]byte
	Sig1      [64]byte
	Sig2      [64]byte
	//says if the fundsTx has been aggregated into an aggtx. This boolean isn't needed in the current version
	Aggregated bool
	Block      [32]byte //This saves the blockHashWithoutTransactions into which the transaction was usually validated. Needed for rollback.
	Data       []byte
}

func ConstrFundsTx

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

func (*FundsTx) Copy

func (tx *FundsTx) Copy() (newTx *FundsTx)

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 Genesis

type Genesis struct {
	RootAddress           [64]byte
	RootCommitment        [crypto.COMM_KEY_LENGTH]byte
	FirstCommitteeAddress [64]byte
	FirstCommitteeKey     [crypto.COMM_KEY_LENGTH]byte
}

func NewGenesis

func NewGenesis(rootAddress [64]byte,
	rootCommitment [crypto.COMM_KEY_LENGTH]byte,
	firstCommitteeAddress [64]byte,
	firstCommitteeKey [crypto.COMM_KEY_LENGTH]byte) Genesis

func (*Genesis) Decode

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

func (*Genesis) Encode

func (genesis *Genesis) Encode() []byte

func (*Genesis) Hash

func (genesis *Genesis) Hash() [32]byte

func (*Genesis) String

func (genesis *Genesis) String() string

type KeyAssignment

type KeyAssignment [32]byte // Key: Hash of the committee check

This datastructe maintains a map of the form int - *TransactionAssignment. It stores the committee checks received from other committee members. This datastructure will be queried at every blockheight to check if every one played according to the rules. Because we need to remove the first element of this datastructure and map access is random in Go, we additionally have a slice datastructure which keeps track of the order of the included transaction assignment. Such that, using the slice structure, we can remove the first received block once this stash gets full

type KeyBlock

type KeyBlock [32]byte // Key: Hash of the block

This datastructe maintains a map of the form [32]byte - *Block. It stores the blcoks received from the shards. This datastructure will be queried after every epoch block to check if we can continue to the next epoch. Because we need to remove the first element of this datastructure and map access is random in Go, we additionally have a slice datastructure which keeps track of the order of the included state transition. Such that, using the slice structure, we can remove the first received block once this stash gets full

type KeyCheck

type KeyCheck [32]byte // Key: Hash of the committee check

This datastructe maintains a map of the form [32]byte - *CommitteeCheck. It stores the committee checks received from other committee members. This datastructure will be queried at every blockheight to check if every one played according to the rules. Because we need to remove the first element of this datastructure and map access is random in Go, we additionally have a slice datastructure which keeps track of the order of the included commitee check. Such that, using the slice structure, we can remove the first received block once this stash gets full

type KeyState

type KeyState [32]byte // Key: Hash of the block

This datastructe maintains a map of the form [32]byte - *StateTransition. It stores the state transitions received from other shards. This datastructure will be queried at every blockheight to check if we can continue mining the next block. Because we need to remove the first element of this datastructure and map access is random in Go, we additionally have a slice datastructure which keeps track of the order of the included state transition. Such that, using the slice structure, we can remove the first received block once this stash gets full

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 BuildAggTxMerkleTree

func BuildAggTxMerkleTree(txHashes [][32]byte) *MerkleTree

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 RelativeAccount

type RelativeAccount struct {
	Address            [64]byte // 64 Byte
	Issuer             [32]byte // 32 Byte Changed to streamline
	Balance            int64    // 8 Byte
	TxCnt              int32    // 4 Byte
	IsStaking          bool     // 1 Byte
	IsCommittee        bool
	CommitmentKey      [crypto.COMM_KEY_LENGTH]byte // represents the modulus N of the RSA public key
	CommitteeKey       [crypto.COMM_KEY_LENGTH]byte // represents the modulus N of the RSA public key
	StakingBlockHeight int32                        // 4 Byte
	Contract           []byte                       // Arbitrary length
	ContractVariables  []ByteArray                  // Arbitrary length
}

*

This datastructure keeps track of relative change in the account information during the creation of a block

func NewRelativeAccount

func NewRelativeAccount(address [64]byte,
	issuer [32]byte,
	balance int64,
	isStaking bool,
	isCommittee bool,
	commitmentKey [crypto.COMM_KEY_LENGTH]byte,
	committeeKey [crypto.COMM_KEY_LENGTH]byte,
	contract []byte,
	contractVariables []ByteArray) RelativeAccount

func (*RelativeAccount) Decode

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

func (*RelativeAccount) Encode

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

func (*RelativeAccount) Hash

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

func (RelativeAccount) String

func (acc RelativeAccount) String() string

type RelativeState

type RelativeState struct {
	RelativeState map[[32]byte]*RelativeAccount
	ShardID       int
	//The beneficiary is the beneficiary of the block which was used as the basis to create this relative state
	Beneficiary [32]byte
}

This structure is very similar to the state transition. However, it only serves as a validation element. Therefore, it does not require a hash, serializer, deserializer or Commitment Proof.

func NewRelativeState

func NewRelativeState(stateChange map[[32]byte]*RelativeAccount, shardid int, beneficiary [32]byte) *RelativeState

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 *ecdsa.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 StateStash

type StateStash struct {
	M    map[KeyState]ValueState
	Keys []KeyState
}

func NewStateStash

func NewStateStash() *StateStash

func (*StateStash) DeleteFirstEntry

func (m *StateStash) DeleteFirstEntry()

This function includes a key and tracks its order in the slice. No need to put the lock because it is used from the calling function

func (*StateStash) Set

func (m *StateStash) Set(k KeyState, v ValueState)

This function includes a key and tracks its order in the slice

func (*StateStash) StateTransitionIncluded

func (m *StateStash) StateTransitionIncluded(k KeyState) bool

type StateTransition

type StateTransition struct {
	RelativeStateChange map[[32]byte]*RelativeAccount //changed to 32 Byte for streamlining
	Height              int
	ShardID             int
	CommitmentProof     [crypto.COMM_KEY_LENGTH]byte
}

*

The State Transition is the main data type needed in the synchronisation mechnism. It contains all data needed to update the local
state with the state of the other shards and free the Mempool from already validated transactions.

func NewStateTransition

func NewStateTransition(stateChange map[[32]byte]*RelativeAccount, height int, shardid int, commProof [crypto.COMM_KEY_LENGTH]byte) *StateTransition

func ReturnStateTransitionForHeight

func ReturnStateTransitionForHeight(statestash *StateStash, height uint32) []*StateTransition

func ReturnStateTransitionForPosition

func ReturnStateTransitionForPosition(stateStash *StateStash, position int) (stateHash [32]byte, stateTransition *StateTransition)

func (*StateTransition) DecodeTransition

func (*StateTransition) DecodeTransition(encoded []byte) (st *StateTransition)

func (*StateTransition) EncodeTransition

func (st *StateTransition) EncodeTransition() []byte

func (*StateTransition) HashTransition

func (st *StateTransition) HashTransition() [32]byte

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
}

type TransactionAssignment

type TransactionAssignment struct {
	Height         int
	ShardID        int
	CommitteeProof [crypto.COMM_PROOF_LENGTH]byte
	AccTxs         []*AccTx
	StakeTxs       []*StakeTx
	CommitteeTxs   []*CommitteeTx
	FundsTxs       []*FundsTx
	DataTxs        []*DataTx
	FineTxs        []*FineTx
}

func NewTransactionAssignment

func NewTransactionAssignment(height int, shardid int, committeeProof [crypto.COMM_PROOF_LENGTH]byte, accTxs []*AccTx, stakeTxs []*StakeTx, committeeTxs []*CommitteeTx, fundsTxs []*FundsTx, dataTxs []*DataTx, fineTxs []*FineTx) *TransactionAssignment

func ReturnTransactionAssignmentForHeight

func ReturnTransactionAssignmentForHeight(transactionAssignmentStash *TransactionAssignmentStash, height uint32) []*TransactionAssignment

func (*TransactionAssignment) DecodeTransactionAssignment

func (*TransactionAssignment) DecodeTransactionAssignment(encoded []byte) (ta *TransactionAssignment)

func (*TransactionAssignment) EncodeTransactionAssignment

func (ta *TransactionAssignment) EncodeTransactionAssignment() []byte

func (*TransactionAssignment) HashTransactionAssignment

func (ta *TransactionAssignment) HashTransactionAssignment() [32]byte

type TransactionAssignmentStash

type TransactionAssignmentStash struct {
	M    map[KeyAssignment]ValueAssignment
	Keys []KeyAssignment
}

func NewTransactionAssignmentStash

func NewTransactionAssignmentStash() *TransactionAssignmentStash

func (*TransactionAssignmentStash) DeleteFirstEntry

func (m *TransactionAssignmentStash) DeleteFirstEntry()

This function includes a key and tracks its order in the slice. No need to put the lock because it is used from the calling function

func (*TransactionAssignmentStash) Set

This function includes a key and tracks its order in the slice

func (*TransactionAssignmentStash) TransactionAssignmentIncluded

func (m *TransactionAssignmentStash) TransactionAssignmentIncluded(k KeyAssignment) bool

type ValShardMapping

type ValShardMapping struct {
	//Header
	ValMapping  map[[64]byte]int
	EpochHeight int
}

func NewMapping

func NewMapping() *ValShardMapping

func (*ValShardMapping) Decode

func (valMapping *ValShardMapping) Decode(encoded []byte) (valMappingDecoded *ValShardMapping)

func (*ValShardMapping) Encode

func (valMapping *ValShardMapping) Encode() []byte

func (*ValShardMapping) GetSize

func (valMapping *ValShardMapping) GetSize() int

func (*ValShardMapping) HashMapping

func (valMapping *ValShardMapping) HashMapping() [32]byte

func (ValShardMapping) String

func (valMapping ValShardMapping) String() string

type ValueAssignment

type ValueAssignment *TransactionAssignment // Value: Transaction Assignment

type ValueBlock

type ValueBlock *Block // Value: Block

type ValueCheck

type ValueCheck *CommitteeCheck // Value: CommitteeCheck

type ValueState

type ValueState *StateTransition // Value: Block

Jump to

Keyboard shortcuts

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