consensus

package
v0.0.0-...-0a36b5b Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2019 License: MIT, MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const BlockPrepare_Done = 1
View Source
const BlockPrepare_Error = 0
View Source
const BlockPrepare_NoTransactions = 2
View Source
const BlockPrepare_NotGoodTime = 3

Variables

This section is empty.

Functions

This section is empty.

Types

type ConsensusInterface

type ConsensusInterface interface {
	SetDBManager(DB database.DBManager)
	SetLogManager(Logger *utils.LoggerMan)
	SetMinterAddress(minter string)
	PrepareNewBlock() (int, error)
	SetPreparedBlock(block *structures.Block) error
	IsBlockPrepared() bool
	CompleteBlock() (*structures.Block, error)
	VerifyBlock(block *structures.Block) error
}

func NewConsensusManager

func NewConsensusManager(minter string, DB database.DBManager, Logger *utils.LoggerMan) (ConsensusInterface, error)

type NodeBlockMaker

type NodeBlockMaker struct {
	DB            database.DBManager
	Logger        *utils.LoggerMan
	MinterAddress string // this is the wallet that will receive for mining
	PreparedBlock *structures.Block
}

func (*NodeBlockMaker) CompleteBlock

func (n *NodeBlockMaker) CompleteBlock() (*structures.Block, error)

finalise a block. in this place we do MIMING Block was prepared. Now do final work for this block. In our case it is PoW process

func (*NodeBlockMaker) IsBlockPrepared

func (n *NodeBlockMaker) IsBlockPrepared() bool

check if a block was prepared already

func (*NodeBlockMaker) PrepareNewBlock

func (n *NodeBlockMaker) PrepareNewBlock() (int, error)

func (*NodeBlockMaker) SetDBManager

func (n *NodeBlockMaker) SetDBManager(DB database.DBManager)

func (*NodeBlockMaker) SetLogManager

func (n *NodeBlockMaker) SetLogManager(Logger *utils.LoggerMan)

func (*NodeBlockMaker) SetMinterAddress

func (n *NodeBlockMaker) SetMinterAddress(minter string)

func (*NodeBlockMaker) SetPreparedBlock

func (n *NodeBlockMaker) SetPreparedBlock(block *structures.Block) error

func (*NodeBlockMaker) VerifyBlock

func (n *NodeBlockMaker) VerifyBlock(block *structures.Block) error

Verify the block. We check if it is correct agains previous block Verify a block against blockchain RULES

  1. Verification is done agains blockchain branch starting from prevblock, not current top branch
  2. There can be only 1 transaction make reward per block
  3. number of transactions must be in correct ranges (reward transaction is not calculated)
  4. transactions can have as input other transaction from this block and it must be listed BEFORE (output must be before input in same block)
  5. all inputs must be in blockchain (correct unspent inputs)
  6. Additionally verify each transaction agains signatures, total amount, balance etc
  7. Verify hash is correc agains rules

type ProofOfWork

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

ProofOfWork represents a proof-of-work

func NewProofOfWork

func NewProofOfWork(b *structures.Block) *ProofOfWork

NewProofOfWork builds and returns a ProofOfWork object The object can be used to find a hash for the block

func (*ProofOfWork) Run

func (pow *ProofOfWork) Run() (int, []byte, error)

Run performs a proof-of-work

func (*ProofOfWork) Validate

func (pow *ProofOfWork) Validate() (bool, error)

Validate validates block's PoW It calculates hash from same data and check if it is equal to block hash

Jump to

Keyboard shortcuts

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