storage

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: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ERROR_MSG                   = "Initiate storage aborted: "
	CLOSEDEPOCHBLOCK_BUCKET     = "closedepochblocks"
	LASTCLOSEDEPOCHBLOCK_BUCKET = "lastclosedepochblocks"
	OPENEPOCHBLOCK_BUCKET       = "openepochblock"
	GENESIS_BUCKET              = "genesis"
)

Variables

View Source
var (

	//don't get confused with the key of the account.
	State = make(map[[32]byte]*protocol.Account)
	//This map keeps track of the relative account adjustments within a shard, such as balance, txcount and stakingheight
	RelativeState           = make(map[[32]byte]*protocol.RelativeAccount)
	OwnStateTransitionStash []*protocol.StateTransition
	RootKeys                = make(map[[32]byte]*protocol.Account)

	//designed a new mempool for this use case
	AssignedTxMempool = make(map[[32]byte]protocol.Transaction)

	//map of transaction assignments for a given height. Key: ShardID. Value: Assignment
	AssignedTxMap = make(map[int]*protocol.TransactionAssignment)

	OwnCommitteeCheck *protocol.CommitteeCheck

	DifferentSenders         = make(map[[32]byte]uint32)
	DifferentSendersData     = make(map[[32]byte]uint32)
	DifferentReceivers       = make(map[[32]byte]uint32)
	FundsTxBeforeAggregation = make([]*protocol.FundsTx, 0)
	DataTxBeforeAggregation  = make([]*protocol.DataTx, 0)
	ReceivedBlockStash       = make([]*protocol.Block, 0)
	TxcntToTxMap             = make(map[uint32][][32]byte)
	ValidatorAccAddress      [64]byte

	AllClosedBlocksAsc []*protocol.Block
	Bootstrap_Server   string

	ReceivedBlockStashMutex = &sync.Mutex{}
	//Added by Kürsat
	ThisShardID                        int // ID of the shard this validator is assigned to
	ThisShardIDDelayed                 int
	ThisShardMap                       = make(map[int]int)
	EpochLength                        int
	ReceivedStateStash                 = protocol.NewStateStash()
	ReceivedShardBlockStash            = protocol.NewShardBlockStash()
	ReceivedCommitteeCheckStash        = protocol.NewCommitteeCheckStash()
	ReceivedTransactionAssignmentStash = protocol.NewTransactionAssignmentStash()

	IsCommittee      bool
	AssignmentHeight int

	CommitteeLeader        [32]byte
	CommitteePrivKey       *rsa.PrivateKey
	CommitteeWalletPrivKey *ecdsa.PrivateKey
)

Functions

func ApplyRelativeState

func ApplyRelativeState(statePrev map[[32]byte]*protocol.Account, stateRel map[[32]byte]*protocol.RelativeAccount) (stateUpdated map[[32]byte]*protocol.Account)

From Kürsat

func BlockAlreadyInStash

func BlockAlreadyInStash(slice []*protocol.Block, newBlockHash [32]byte) bool

func BlockReadyToAggregate

func BlockReadyToAggregate(block *protocol.Block) bool
TODO UNCOMMENT

func UpdateBlocksToBlocksWithoutTx(block *protocol.Block) (err error){

	if BlockReadyToAggregate(block) {
		block.Aggregated = true
		WriteClosedBlockWithoutTx(block)
		DeleteClosedBlock(block.Hash)
		logger.Printf("UPDATE: Write (%x) into closedBlockWithoutTransactions-Bucket as (%x)", block.Hash[0:8], block.HashWithoutTx[0:8])
		return err
	}
	return
}

func DeleteAll

func DeleteAll()

func DeleteAllDataTxBeforeAggregation

func DeleteAllDataTxBeforeAggregation()

func DeleteAllFundsTxBeforeAggregation

func DeleteAllFundsTxBeforeAggregation()

func DeleteAllLastClosedBlock

func DeleteAllLastClosedBlock()

func DeleteAllLastClosedEpochBlock

func DeleteAllLastClosedEpochBlock() error

func DeleteAllOpenTxAndReturnAllNotIncludedTxHashes

func DeleteAllOpenTxAndReturnAllNotIncludedTxHashes(accTxs []*protocol.AccTx, stakeTxs []*protocol.StakeTx, committeeTxs []*protocol.CommitteeTx, fundsTxs []*protocol.FundsTx, aggTxs []*protocol.AggTx, dataTxs []*protocol.DataTx, aggDataTxs []*protocol.AggDataTx, fineTxs []*protocol.FineTx) (notIncludedTxHashes [][32]byte)

In this function, we detect whether the shard put a transaction in a block which wasn't part of the original TX assignment

func DeleteBootstrapReceivedMempool

func DeleteBootstrapReceivedMempool()

func DeleteClosedBlock

func DeleteClosedBlock(hash [32]byte)

func DeleteClosedBlockWithoutTx

func DeleteClosedBlockWithoutTx(hash [32]byte)

func DeleteClosedEpochBlock

func DeleteClosedEpochBlock(hash [32]byte) error

func DeleteClosedTx

func DeleteClosedTx(transaction protocol.Transaction)

func DeleteINVALIDOpenTx

func DeleteINVALIDOpenTx(transaction protocol.Transaction)

func DeleteLastClosedBlock

func DeleteLastClosedBlock(hash [32]byte)

func DeleteOpenBlock

func DeleteOpenBlock(hash [32]byte)

There exist open/closed buckets and closed tx buckets for all types (open txs are in volatile storage)

func DeleteOpenEpochBlock

func DeleteOpenEpochBlock(hash [32]byte) error

func DeleteOpenTx

func DeleteOpenTx(transaction protocol.Transaction)

func GetAccTxPubKeys

func GetAccTxPubKeys(accTxData [][32]byte) (accTxPubKeys [][32]byte)

Get all pubKey involved in AccTx

func GetAccount

func GetAccount(hash [32]byte) (acc *protocol.Account, err error)

Needed by miner and p2p package

func GetFundsTxPubKeys

func GetFundsTxPubKeys(fundsTxData [][32]byte) (fundsTxPubKeys [][32]byte)

Get all pubKey involved in FundsTx

func GetMemPoolSize

func GetMemPoolSize() int

func GetRelativeState

func GetRelativeState(statePrev map[[32]byte]protocol.Account, stateNow map[[32]byte]*protocol.Account) (stateRel map[[32]byte]*protocol.RelativeAccount)

func GetRelativeStateForCommittee

func GetRelativeStateForCommittee(statePrev map[[32]byte]protocol.Account, stateNow map[[32]byte]protocol.Account) (stateRel map[[32]byte]*protocol.RelativeAccount)

This function is needed because the state has a different role in the code now (it's not changed after block validation directly).

func GetRootAccount

func GetRootAccount(hash [32]byte) (acc *protocol.Account, err error)

func GetTxPubKeys

func GetTxPubKeys(block *protocol.Block) (txPubKeys [][32]byte)

Get all pubKeys involved in AccTx, FundsTx of a given block

func Init

func Init(dbname string, bootstrapIpport string)

Entry function for the storage package

func InitLogger

func InitLogger() *log.Logger

func IsRootKey

func IsRootKey(hash [32]byte) bool

func ReadAccount

func ReadAccount(pubKey [64]byte) (acc *protocol.Account, err error)

func ReadAllAssignedTx

func ReadAllAssignedTx() (allAssignedTxs []protocol.Transaction)

func ReadAllBootstrapReceivedTransactions

func ReadAllBootstrapReceivedTransactions() (allOpenTxs []protocol.Transaction)

func ReadAllClosedBlocks

func ReadAllClosedBlocks() (allClosedBlocks []*protocol.Block)

This method does read all blocks in closedBlocks & closedblockswithouttx.

func ReadAllClosedBlocksWithTransactions

func ReadAllClosedBlocksWithTransactions() (allClosedBlocks []*protocol.Block)

func ReadAllClosedFundsAndAggTransactions

func ReadAllClosedFundsAndAggTransactions() (allClosedTransactions []protocol.Transaction)

func ReadAllDataSummary

func ReadAllDataSummary() []*protocol.DataSummary

func ReadAllINVALIDOpenTx

func ReadAllINVALIDOpenTx() (allOpenInvalidTxs []protocol.Transaction)

func ReadAllOpenTxs

func ReadAllOpenTxs() (allOpenTxs []protocol.Transaction)

Needed for the miner to prepare a new block

func ReadAssignedTx

func ReadAssignedTx(hash [32]byte) (transaction protocol.Transaction)

func ReadClosedBlock

func ReadClosedBlock(hash [32]byte) (block *protocol.Block)

func ReadClosedBlockWithoutTx

func ReadClosedBlockWithoutTx(hash [32]byte) (block *protocol.Block)

This function does read all blocks without transactions inside.

func ReadClosedEpochBlock

func ReadClosedEpochBlock(hash [32]byte) (epochBlock *protocol.EpochBlock)

func ReadClosedTx

func ReadClosedTx(hash [32]byte) (transaction protocol.Transaction)

Personally I like it better to test (which tx type it is) here, and get returned the interface. Simplifies the code

func ReadDataTxBeforeAggregation

func ReadDataTxBeforeAggregation() []*protocol.DataTx

func ReadFirstEpochBlock

func ReadFirstEpochBlock() (firstEpochBlock *protocol.EpochBlock, err error)

func ReadFundsTxBeforeAggregation

func ReadFundsTxBeforeAggregation() []*protocol.FundsTx

func ReadGenesis

func ReadGenesis() (genesis *protocol.Genesis, err error)

func ReadINVALIDOpenTx

func ReadINVALIDOpenTx(hash [32]byte) (transaction protocol.Transaction)

func ReadLastClosedBlock

func ReadLastClosedBlock() (block *protocol.Block)

func ReadLastClosedEpochBlock

func ReadLastClosedEpochBlock() (epochBlock *protocol.EpochBlock)

func ReadOpenBlock

func ReadOpenBlock(hash [32]byte) (block *protocol.Block)

Always return nil if requested hash is not in the storage. This return value is then checked against by the caller

func ReadOpenEpochBlock

func ReadOpenEpochBlock(hash [32]byte) (epochBlock *protocol.EpochBlock)

func ReadOpenTx

func ReadOpenTx(hash [32]byte) (transaction protocol.Transaction)

func ReadOpenTxHashToDelete

func ReadOpenTxHashToDelete(hash [32]byte) (contains bool)

func ReadReceivedBlockStash

func ReadReceivedBlockStash() (receivedBlocks []*protocol.Block)

func ReadStateTransitionFromOwnStash

func ReadStateTransitionFromOwnStash(height int) *protocol.StateTransition

func ReadTxcntToTx

func ReadTxcntToTx(txCnt uint32) (transactions [][32]byte)

func ResetOpenTxHashToDeleteMempool

func ResetOpenTxHashToDeleteMempool()

func TearDown

func TearDown()

func UpdateDataSummary

func UpdateDataSummary(dataTxs []*protocol.DataTx) (err error)

func WriteAllClosedTxAndReturnAlreadyClosedTxHashes

func WriteAllClosedTxAndReturnAlreadyClosedTxHashes(accTxs []*protocol.AccTx, stakeTxs []*protocol.StakeTx, committeeTxs []*protocol.CommitteeTx, fundsTxs []*protocol.FundsTx, aggTxs []*protocol.AggTx, dataTxs []*protocol.DataTx, aggDataTxs []*protocol.AggDataTx, fineTxs []*protocol.FineTx) (alreadyIncludedTxHashes [][32]byte, err error)

In this method, we can detect whether the transaction included in the block is already in closed storage. If it is already there, there are 2 options. Either the committee or the shard was malicious If bespoke transaction was in the transaction assignment, the committee leader was malicious If bespoke transaction was not in the transaction assignment, the shard was malicious To make the code more efficient and performant, the check of who is actually malicious will be conducted at a different part of the code

func WriteBootstrapTxReceived

func WriteBootstrapTxReceived(transaction protocol.Transaction)

func WriteClosedBlock

func WriteClosedBlock(block *protocol.Block) (err error)

func WriteClosedEpochBlock

func WriteClosedEpochBlock(epochBlock *protocol.EpochBlock) error

func WriteClosedFundsTxFromAggTxSlice

func WriteClosedFundsTxFromAggTxSlice(transactions []protocol.FundsTx) (err error)

func WriteClosedTx

func WriteClosedTx(transaction protocol.Transaction) (err error)

func WriteDataSummary

func WriteDataSummary(ds *protocol.DataSummary) (err error)

func WriteDataTxBeforeAggregation

func WriteDataTxBeforeAggregation(transaction *protocol.DataTx)

func WriteFirstEpochBlock

func WriteFirstEpochBlock(epochBlock *protocol.EpochBlock) error

func WriteFundsTxBeforeAggregation

func WriteFundsTxBeforeAggregation(transaction *protocol.FundsTx)

func WriteGenesis

func WriteGenesis(genesis *protocol.Genesis) error

func WriteINVALIDOpenTx

func WriteINVALIDOpenTx(transaction protocol.Transaction)

func WriteLastClosedBlock

func WriteLastClosedBlock(block *protocol.Block) (err error)
TODO UNCOMMENT

func WriteClosedBlockWithoutTx(block *protocol.Block) (err error) {

	err = db.Update(func(tx *bolt.Tx) error {
		b := tx.Bucket([]byte("closedblockswithouttx"))
		err := b.Put(block.HashWithoutTx[:], block.Encode())
		return err
	})

	return err
}

func WriteLastClosedEpochBlock

func WriteLastClosedEpochBlock(epochBlock *protocol.EpochBlock) (err error)

func WriteOpenBlock

func WriteOpenBlock(block *protocol.Block) (err error)

func WriteOpenTx

func WriteOpenTx(transaction protocol.Transaction)

Changing the "tx" shortcut here and using "transaction" to distinguish between bolt's transactions write open tx doesnt allow for a tx to be added twice

func WriteOpenTxHashToDelete

func WriteOpenTxHashToDelete(hash [32]byte)

func WriteToOwnStateTransitionkStash

func WriteToOwnStateTransitionkStash(st *protocol.StateTransition)

func WriteToReceivedStash

func WriteToReceivedStash(block *protocol.Block)

func WriteTxcntToTx

func WriteTxcntToTx(transaction *protocol.FundsTx)

Types

type ByHeight

type ByHeight []*protocol.Block

The three functions and the type below are used to order the gathered closed blocks from below according to their block height.

func (ByHeight) Len

func (a ByHeight) Len() int

func (ByHeight) Less

func (a ByHeight) Less(i, j int) bool

func (ByHeight) Swap

func (a ByHeight) Swap(i, j int)

Jump to

Keyboard shortcuts

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