Version: v0.0.0-...-8aa4d74 Latest Latest

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

Go to latest
Published: Feb 13, 2019 License: GPL-3.0 Imports: 42 Imported by: 0



Package sebak is the node of blockchain, which implements "ISAAC" Consensus Protocol at first time. ISAAC is based on the FBA consensus protocol, but is totally different from SCP(Stellar Cosensus Protocol).

sebak is the old term of "SaeByeog" in Korean, which means dawn.

Struct that bridges together components of a node

NodeRunner bridges together the connection, storage and `LocalNode`. In this regard, it can be seen as a single node, and is used as such in unit tests.



View Source
const (
	NodeInfoHandlerPattern  string = "/"
	ConnectHandlerPattern   string = "/connect"
	DiscoveryHandlerPattern string = "/discovery"
	MessageHandlerPattern   string = "/message"
	BallotHandlerPattern    string = "/ballot"
View Source
const GetBallotPattern = "/ballots"
View Source
const GetBlocksPattern = "/blocks"
View Source
const GetTransactionPattern string = "/transactions"
View Source
const MaxLimitListOptions uint64 = 10000
View Source
const MaxSnapshots uint64 = 500


View Source
var DebugPProf bool = false
View Source
var NewBallotTransactionCheckerFuncs = []common.CheckerFunc{


func ACCEPTBallotBroadcast

func ACCEPTBallotBroadcast(c common.Checker, args ...interface{}) (err error)

ACCEPTBallotBroadcast will broadcast the confirmed ACCEPT ballot.

func BallotAlreadyVoted

func BallotAlreadyVoted(c common.Checker, args ...interface{}) (err error)

BallotAlreadyVoted checks the node of ballot voted.

func BallotCheckBasis

func BallotCheckBasis(c common.Checker, args ...interface{}) (err error)

BallotCheckBasis checks the incoming ballot in valid round.

func BallotCheckResult

func BallotCheckResult(c common.Checker, args ...interface{}) (err error)

BallotCheckResult checks the voting result.

func BallotCheckSYNC

func BallotCheckSYNC(c common.Checker, args ...interface{}) error

BallotCheckSYNC performs sync by considering sync condition. And to participate in the consensus, update the latestblock by referring to the database.

func BallotGetMissingTransaction

func BallotGetMissingTransaction(c common.Checker, args ...interface{}) (err error)

func BallotIsSameProposer

func BallotIsSameProposer(c common.Checker, args ...interface{}) (err error)

BallotIsSameProposer checks the incoming ballot has the same proposer with the current `RunningRound`.

func BallotNotFromKnownValidators

func BallotNotFromKnownValidators(c common.Checker, args ...interface{}) (err error)

BallotNotFromKnownValidators checks the incoming ballot is from the known validators.

func BallotRenewal

func BallotRenewal(c common.Checker, args ...interface{}) (err error)

BallotRenewal checks that the ballot confirmed and proposed time is valid and if the time is invalid, then it broadcasts expired ballot

func BallotTransactionsAllValid

func BallotTransactionsAllValid(c common.Checker, args ...interface{}) (err error)

BallotTransactionsAllValid checks all the transactions are valid or not.

func BallotTransactionsOperationBodyCollectTxFee

func BallotTransactionsOperationBodyCollectTxFee(c common.Checker, args ...interface{}) (err error)

BallotTransactionsOperationBodyCollectTxFee validates the `BallotTransactionsOperationBodyCollectTxFee.Amount` is matched with the collected fee of all transactions.

func BallotTransactionsOperationLimit

func BallotTransactionsOperationLimit(c common.Checker, args ...interface{}) error

BallotTransactionsOperationLimit checks the total number of operations is over `OpsInBallotLimit`.

func BallotTransactionsSameSource

func BallotTransactionsSameSource(c common.Checker, args ...interface{}) (err error)

BallotTransactionsSameSource checks there are transactions which has same source in the `Transactions`.

func BallotUnmarshal

func BallotUnmarshal(c common.Checker, args ...interface{}) (err error)

BallotUnmarshal makes `Ballot` from common.NetworkMessage.

func BallotValidateOperationBodyCollectTxFee

func BallotValidateOperationBodyCollectTxFee(c common.Checker, args ...interface{}) (err error)

BallotValidateOperationBodyCollectTxFee validates `CollectTxFee`.

func BallotValidateOperationBodyInflation

func BallotValidateOperationBodyInflation(c common.Checker, args ...interface{}) (err error)

BallotValidateOperationBodyInflation validates `Inflation`

func BallotVote

func BallotVote(c common.Checker, args ...interface{}) (err error)

BallotVote vote by incoming ballot; if the ballot is new and the round of ballot is not yet registered, this will make new `RunningRound`.

func BroadcastTransaction

func BroadcastTransaction(c common.Checker, args ...interface{}) (err error)

BroadcastTransaction broadcasts the incoming transaction to the other nodes.

func BroadcastTransactionFromWatcher

func BroadcastTransactionFromWatcher(c common.Checker, args ...interface{}) error

BroadcastTransactionFromWatcher is sending tx to one of validators. If all validators returns error, it returns error.

func CheckMissingTransaction

func CheckMissingTransaction(c common.Checker, args ...interface{}) (err error)

CheckMissingTransaction will get the missing tranactions, that is, not in `Pool` from proposer.

func ExpiredInSIGN

func ExpiredInSIGN(c common.Checker, args ...interface{}) (err error)

func FinishProposerTransaction

func FinishProposerTransaction(st *storage.LevelDBBackend, blk block.Block, ptx ballot.ProposerTransaction, log logging.Logger) (err error)

func FinishTransactions

func FinishTransactions(blk block.Block, transactions []*transaction.Transaction, st *storage.LevelDBBackend) (err error)

func FinishedBallotStore

func FinishedBallotStore(c common.Checker, args ...interface{}) error

FinishedBallotStore will store the confirmed ballot to `Block`.

func GenerateBallot

func GenerateBallot(proposer *node.LocalNode, basis voting.Basis, tx transaction.Transaction, ballotState ballot.State, sender *node.LocalNode, conf common.Config) *ballot.Ballot

func GenerateEmptyTxBallot

func GenerateEmptyTxBallot(proposer *node.LocalNode, basis voting.Basis, ballotState ballot.State, sender *node.LocalNode, conf common.Config) *ballot.Ballot

func GetCommonAccount

func GetCommonAccount(st *storage.LevelDBBackend) (account *block.BlockAccount, err error)

func GetCreateAccountTransaction

func GetCreateAccountTransaction(sequenceID uint64, amount uint64) (transaction.Transaction, []byte, *keypair.Full)

func GetGenesisAccount

func GetGenesisAccount(st *storage.LevelDBBackend) (account *block.BlockAccount, err error)

func GetGenesisBalance

func GetGenesisBalance(st *storage.LevelDBBackend) (balance common.Amount, err error)

func GetGenesisTransaction

func GetGenesisTransaction(st *storage.LevelDBBackend) (bt block.BlockTransaction, err error)

func GetPaymentTransaction

func GetPaymentTransaction(kpSource *keypair.Full, target string, sequenceID uint64, amount uint64) (transaction.Transaction, []byte)

func GetTransaction

func GetTransaction() (transaction.Transaction, []byte)

func HasTransaction

func HasTransaction(c common.Checker, args ...interface{}) (err error)

HasTransaction checks transaction is in `Pool` And `Block`

func INITBallotValidateTransactions

func INITBallotValidateTransactions(c common.Checker, args ...interface{}) (err error)

INITBallotValidateTransactions validates the transactions of newly added ballot.

func IsNew

func IsNew(c common.Checker, args ...interface{}) (err error)

IsNew checks the incoming transaction is already stored or not.

func MakeConsensusAndBlock

func MakeConsensusAndBlock(t *testing.T, tx transaction.Transaction, nr *NodeRunner, nodes []*node.LocalNode, proposer *node.LocalNode) (block.Block, error)

func MessageHasSameSource

func MessageHasSameSource(c common.Checker, args ...interface{}) (err error)

SameSource checks there are transactions which has same source in the `Pool`.

func MessageValidate

func MessageValidate(c common.Checker, args ...interface{}) (err error)

MessageValidate validates.

func NewNodeInfo

func NewNodeInfo(nr *NodeRunner) node.NodeInfo

func NodeInfoWithRequest

func NodeInfoWithRequest(localNode *node.LocalNode, r *http.Request) (b []byte, err error)

func ProcessProposerTransaction

func ProcessProposerTransaction(st *storage.LevelDBBackend, blk block.Block, ptx ballot.ProposerTransaction, log logging.Logger) (err error)

func PushIntoTransactionPool

func PushIntoTransactionPool(c common.Checker, args ...interface{}) error

PushIntoTransactionPool add the incoming transactions into `Pool`.

func PushIntoTransactionPoolFromClient

func PushIntoTransactionPoolFromClient(c common.Checker, args ...interface{}) error

PushIntoTransactionPoolFromClient add the incoming tx from client

func PushIntoTransactionPoolFromNode

func PushIntoTransactionPoolFromNode(c common.Checker, args ...interface{}) error

PushIntoTransactionPoolFromNode add the incoming tx from node

func ReceiveBallot

func ReceiveBallot(nodeRunner *NodeRunner, ballot *ballot.Ballot) error

func SIGNBallotBroadcast

func SIGNBallotBroadcast(c common.Checker, args ...interface{}) (err error)

SIGNBallotBroadcast will broadcast the validated SIGN ballot.

func SetLogging

func SetLogging(level logging.Lvl, handler logging.Handler)

func TransactionUnmarshal

func TransactionUnmarshal(c common.Checker, args ...interface{}) (err error)

TransactionUnmarshal makes `Transaction` from incoming `common.NetworkMessage`.

func TransitStateToACCEPT

func TransitStateToACCEPT(c common.Checker, args ...interface{}) (err error)

TransitStateToACCEPT changes ISAACState to ACCEPT

func TransitStateToSIGN

func TransitStateToSIGN(c common.Checker, args ...interface{}) (err error)

TransitStateToSIGN changes ISAACState to SIGN

func ValidateOp

func ValidateOp(st *storage.LevelDBBackend, config common.Config, source *block.BlockAccount, op operation.Operation) (err error)

Validate an operation

This function is critical for consensus, as it defines the validation rules for an operation, and by extension a transaction. It is called from ValidateTx.


st = Storage backend to use (e.g. to access the blocks)
     Only ever read from, never written to.
config = consist of configuration of the network. common address, congress address, etc.
source = Account from where the transaction (and ops) come from
tx = Transaction to check

func ValidateTx

func ValidateTx(st *storage.LevelDBBackend, config common.Config, tx transaction.Transaction) (err error)

Validate the entirety of a transaction

This function is critical for consensus, as it defines the validation rules for a transaction. It is executed whenever a transaction is received.

As it is run on every single transaction, it should be as fast as possible, thus any new code should carefully consider when it takes place. Consider putting cheap, frequent errors first.

Note that if we get to this function, it means the transaction is known to be well-formed (e.g. the signature is legit).


st = Storage backend to use (e.g. to access the blocks)
     Only ever read from, never written to.
config = consist of configuration of the network. common address, congress address, etc.
tx = Transaction to check


type BallotChecker

type BallotChecker struct {

	NodeRunner         *NodeRunner
	Conf               common.Config
	LocalNode          *node.LocalNode
	Message            common.NetworkMessage
	IsNew              bool
	IsMine             bool
	Ballot             ballot.Ballot
	VotingHole         voting.Hole
	Result             consensus.RoundVoteResult
	VotingFinished     bool
	FinishedVotingHole voting.Hole
	LatestBlockSources []string

	Log logging.Logger

type BallotTransactionChecker

type BallotTransactionChecker struct {

	NodeRunner *NodeRunner
	Conf       common.Config
	LocalNode  node.Node
	NetworkID  []byte

	Ballot            ballot.Ballot
	Transactions      []string
	VotingHole        voting.Hole
	ValidTransactions []string

	CheckTransactionsOnly bool
	// contains filtered or unexported fields

type CheckerStopCloseConsensus

type CheckerStopCloseConsensus struct {
	// contains filtered or unexported fields

func NewCheckerStopCloseConsensus

func NewCheckerStopCloseConsensus(checker *BallotChecker, message string) CheckerStopCloseConsensus

func (CheckerStopCloseConsensus) Checker

func (CheckerStopCloseConsensus) Error

type DBEchoArgs

type DBEchoArgs string

type DBEchoResult

type DBEchoResult string

type DBGetArgs

type DBGetArgs struct {
	Snapshot string `json:"snapshot"`
	Key      string `json:"key"`

type DBGetIteratorArgs

type DBGetIteratorArgs struct {
	Snapshot string             `json:"snapshot"`
	Prefix   string             `json:"prefix"`
	Options  GetIteratorOptions `json:"options"`

type DBGetIteratorResult

type DBGetIteratorResult struct {
	Limit uint64             `json:"limit"`
	Items []storage.IterItem `json:"items"`

type DBGetResult

type DBGetResult storage.IterItem

type DBHasArgs

type DBHasArgs struct {
	Snapshot string `json:"snapshot"`
	Key      string `json:"key"`

type DBHasResult

type DBHasResult bool

type DBOpenSnapshot

type DBOpenSnapshot struct{}

type DBOpenSnapshotResult

type DBOpenSnapshotResult struct {
	Snapshot string `json:"snapshot"`

type DBReleaseSnapshot

type DBReleaseSnapshot struct {
	Snapshot string `json:"snapshot"`

type DBReleaseSnapshotResult

type DBReleaseSnapshotResult bool

type FixedSelector

type FixedSelector struct {
	// contains filtered or unexported fields

func (FixedSelector) Select

func (s FixedSelector) Select(_ uint64, _ uint64) string

type GetBlocksOptions

type GetBlocksOptions struct {

	HeightRange [2]uint64
	Hashes      []string
	Mode        GetBlocksOptionsMode

func NewGetBlocksOptionsFromRequest

func NewGetBlocksOptionsFromRequest(r *http.Request) (options *GetBlocksOptions, err error)

func (GetBlocksOptions) Height

func (g GetBlocksOptions) Height() uint64

func (*GetBlocksOptions) SetHashes

func (g *GetBlocksOptions) SetHashes(h []string) *GetBlocksOptions

func (*GetBlocksOptions) SetHeightRange

func (g *GetBlocksOptions) SetHeightRange(h [2]uint64) *GetBlocksOptions

func (*GetBlocksOptions) SetMode

func (GetBlocksOptions) Template

func (g GetBlocksOptions) Template() string

func (GetBlocksOptions) URLValues

func (g GetBlocksOptions) URLValues() url.Values

type GetBlocksOptionsMode

type GetBlocksOptionsMode string
const (
	GetBlocksOptionsModeHeader GetBlocksOptionsMode = "header" // default
	GetBlocksOptionsModeBlock  GetBlocksOptionsMode = "block"
	GetBlocksOptionsModeFull   GetBlocksOptionsMode = "full"

type GetIteratorOptions

type GetIteratorOptions struct {
	Reverse bool   `json:"reverse"`
	Cursor  []byte `json:"cursor"`
	Limit   uint64 `json:"limit"`

type ISAACStateManager

type ISAACStateManager struct {

	Conf common.Config
	// contains filtered or unexported fields

ISAACStateManager manages the ISAACState. The most important function `Start()` is called in startStateManager() function in node_runner.go by goroutine.

func NewISAACStateManager

func NewISAACStateManager(nr *NodeRunner, conf common.Config) *ISAACStateManager

func (*ISAACStateManager) NextHeight

func (sm *ISAACStateManager) NextHeight()

func (*ISAACStateManager) NextRound

func (sm *ISAACStateManager) NextRound()

func (*ISAACStateManager) SetTransitSignal

func (sm *ISAACStateManager) SetTransitSignal(f func(consensus.ISAACState))

func (*ISAACStateManager) Start

func (sm *ISAACStateManager) Start()

In `Start()` method a node proposes ballot. Or it sets or resets timeout. If it is expired, it broadcasts B(`EXP`). And it manages the node round.

func (*ISAACStateManager) State

func (*ISAACStateManager) Stop

func (sm *ISAACStateManager) Stop()

func (*ISAACStateManager) TransitISAACState

func (sm *ISAACStateManager) TransitISAACState(height uint64, round uint64, ballotState ballot.State)

type MessageChecker

type MessageChecker struct {

	Conf            common.Config
	LocalNode       *node.LocalNode
	NetworkID       []byte
	Message         common.NetworkMessage
	Log             logging.Logger
	Consensus       *consensus.ISAAC
	TransactionPool *transaction.Pool
	Storage         *storage.LevelDBBackend
	Transaction     transaction.Transaction

type NetworkHandlerNode

type NetworkHandlerNode struct {
	// contains filtered or unexported fields

func NewNetworkHandlerNode

func NewNetworkHandlerNode(localNode *node.LocalNode, network network.Network, storage *storage.LevelDBBackend, consensus *consensus.ISAAC, transactionPool *transaction.Pool, urlPrefix string, conf common.Config) *NetworkHandlerNode

func (NetworkHandlerNode) BallotHandler

func (api NetworkHandlerNode) BallotHandler(w http.ResponseWriter, r *http.Request)

func (NetworkHandlerNode) ConnectHandler

func (api NetworkHandlerNode) ConnectHandler(w http.ResponseWriter, r *http.Request)

func (NetworkHandlerNode) DiscoveryHandler

func (nh NetworkHandlerNode) DiscoveryHandler(w http.ResponseWriter, r *http.Request)

DiscoveryHandler will receive the `DiscoveryMessage` and checks the undiscovered validators. If found, trying to update validator data.

func (NetworkHandlerNode) GetBallotHandler

func (nh NetworkHandlerNode) GetBallotHandler(w http.ResponseWriter, r *http.Request)

func (NetworkHandlerNode) GetBlocksHandler

func (nh NetworkHandlerNode) GetBlocksHandler(w http.ResponseWriter, r *http.Request)

func (NetworkHandlerNode) GetNodeTransactionsHandler

func (nh NetworkHandlerNode) GetNodeTransactionsHandler(w http.ResponseWriter, r *http.Request)

func (NetworkHandlerNode) HandlerURLPattern

func (api NetworkHandlerNode) HandlerURLPattern(pattern string) string

func (NetworkHandlerNode) MessageHandler

func (api NetworkHandlerNode) MessageHandler(w http.ResponseWriter, r *http.Request)

func (NetworkHandlerNode) NodeInfoHandler

func (api NetworkHandlerNode) NodeInfoHandler(w http.ResponseWriter, r *http.Request)

func (NetworkHandlerNode) ReceiveTransaction

func (api NetworkHandlerNode) ReceiveTransaction(body []byte, funcs []common.CheckerFunc) (transaction.Transaction, error)

type NodeRunner

type NodeRunner struct {

	TransactionPool *transaction.Pool

	Conf common.Config
	// contains filtered or unexported fields

func MakeNodeRunner

func MakeNodeRunner() (*NodeRunner, *node.LocalNode)

func NewNodeRunner

func NewNodeRunner(
	localNode *node.LocalNode,
	policy voting.ThresholdPolicy,
	n network.Network,
	c *consensus.ISAAC,
	storage *storage.LevelDBBackend,
	tp *transaction.Pool,
	conf common.Config,
) (nr *NodeRunner, err error)

func (*NodeRunner) BallotSendRecord

func (nr *NodeRunner) BallotSendRecord() *consensus.BallotSendRecord

func (*NodeRunner) BroadcastBallot

func (nr *NodeRunner) BroadcastBallot(b ballot.Ballot)

func (*NodeRunner) ConnectValidators

func (nr *NodeRunner) ConnectValidators()

func (*NodeRunner) ConnectionManager

func (nr *NodeRunner) ConnectionManager() network.ConnectionManager

func (*NodeRunner) Consensus

func (nr *NodeRunner) Consensus() *consensus.ISAAC

func (*NodeRunner) InitRound

func (nr *NodeRunner) InitRound()

func (*NodeRunner) InitSent

func (nr *NodeRunner) InitSent(state consensus.ISAACState)

func (*NodeRunner) Log

func (nr *NodeRunner) Log() logging.Logger

func (*NodeRunner) Network

func (nr *NodeRunner) Network() network.Network

func (*NodeRunner) NetworkID

func (nr *NodeRunner) NetworkID() []byte

func (*NodeRunner) NextHeight

func (nr *NodeRunner) NextHeight()

func (*NodeRunner) Node

func (nr *NodeRunner) Node() *node.LocalNode

func (*NodeRunner) NodeInfo

func (nr *NodeRunner) NodeInfo() node.NodeInfo

func (*NodeRunner) Policy

func (nr *NodeRunner) Policy() voting.ThresholdPolicy

func (*NodeRunner) Ready

func (nr *NodeRunner) Ready()

func (*NodeRunner) RemoveSendRecordsLowerThanOrEqualHeight

func (nr *NodeRunner) RemoveSendRecordsLowerThanOrEqualHeight(height uint64)

func (*NodeRunner) SavingBlockOperations

func (nr *NodeRunner) SavingBlockOperations() *SavingBlockOperations

func (*NodeRunner) SetHandleACCEPTBallotCheckerFuncs

func (nr *NodeRunner) SetHandleACCEPTBallotCheckerFuncs(f ...common.CheckerFunc)

func (*NodeRunner) SetHandleBaseBallotCheckerFuncs

func (nr *NodeRunner) SetHandleBaseBallotCheckerFuncs(f ...common.CheckerFunc)

func (*NodeRunner) SetHandleINITBallotCheckerFuncs

func (nr *NodeRunner) SetHandleINITBallotCheckerFuncs(f ...common.CheckerFunc)

func (*NodeRunner) SetHandleSIGNBallotCheckerFuncs

func (nr *NodeRunner) SetHandleSIGNBallotCheckerFuncs(f ...common.CheckerFunc)

func (*NodeRunner) Start

func (nr *NodeRunner) Start() (err error)

func (*NodeRunner) Stop

func (nr *NodeRunner) Stop()

func (*NodeRunner) StopStateManager

func (nr *NodeRunner) StopStateManager()

func (*NodeRunner) Storage

func (nr *NodeRunner) Storage() *storage.LevelDBBackend

func (*NodeRunner) TransitISAACState

func (nr *NodeRunner) TransitISAACState(basis voting.Basis, ballotState ballot.State)

type OtherSelector

type OtherSelector struct {
	// contains filtered or unexported fields

func (OtherSelector) Select

func (s OtherSelector) Select(_ uint64, _ uint64) string

type SavingBlockOperations

type SavingBlockOperations struct {
	// contains filtered or unexported fields

func NewSavingBlockOperations

func NewSavingBlockOperations(st *storage.LevelDBBackend, logger logging.Logger) *SavingBlockOperations

func (*SavingBlockOperations) Check

func (sb *SavingBlockOperations) Check() (err error)

func (*SavingBlockOperations) CheckByBlock

func (sb *SavingBlockOperations) CheckByBlock(st *storage.LevelDBBackend, blk block.Block) (err error)

func (*SavingBlockOperations) CheckTransactionByBlock

func (sb *SavingBlockOperations) CheckTransactionByBlock(st *storage.LevelDBBackend, blk block.Block, hash string) (err error)

func (*SavingBlockOperations) Save

func (sb *SavingBlockOperations) Save(blk block.Block)

func (*SavingBlockOperations) Start

func (sb *SavingBlockOperations) Start()

type SelfThenOtherSelector

type SelfThenOtherSelector struct {
	// contains filtered or unexported fields

func (SelfThenOtherSelector) Select

func (s SelfThenOtherSelector) Select(blockHeight uint64, round uint64) string

type TestConnectionManager

type TestConnectionManager struct {
	// contains filtered or unexported fields

func NewTestConnectionManager

func NewTestConnectionManager(
	localNode *node.LocalNode,
	n network.Network,
	policy voting.ThresholdPolicy,
	r chan struct{},
) *TestConnectionManager

func (*TestConnectionManager) Broadcast

func (c *TestConnectionManager) Broadcast(message common.Message)

func (*TestConnectionManager) IsReady

func (c *TestConnectionManager) IsReady() bool

func (*TestConnectionManager) Messages

func (c *TestConnectionManager) Messages() []common.Message

type TransactionCache

type TransactionCache struct {
	// contains filtered or unexported fields

func NewTransactionCache

func NewTransactionCache(st *storage.LevelDBBackend, pool *transaction.Pool) *TransactionCache

func (*TransactionCache) Get

func (b *TransactionCache) Get(hash string) (tx transaction.Transaction, found bool, err error)


Path Synopsis

Jump to

Keyboard shortcuts

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