CovenantSQL: github.com/CovenantSQL/CovenantSQL/blockproducer Index | Files | Directories

package blockproducer

import "github.com/CovenantSQL/CovenantSQL/blockproducer"

Package blockproducer implements blockproducer node block genreation and database management logics.

Index

Package Files

blocknode.go bpinfo.go branch.go chain.go chain_gossip.go chain_io.go config.go doc.go errors.go metaindex.go metastate.go rpc.go storage.go

Variables

var (
    // ErrNoSuchDatabase defines database meta not exists error.
    ErrNoSuchDatabase = errors.New("no such database")
    // ErrParentNotFound defines that the parent block cannot be found.
    ErrParentNotFound = errors.New("previous block cannot be found")
    // ErrInvalidHash defines invalid hash error.
    ErrInvalidHash = errors.New("Hash is invalid")
    // ErrExistedTx defines existed tx error.
    ErrExistedTx = errors.New("Tx existed")
    // ErrParentNotMatch defines invalid parent hash.
    ErrParentNotMatch = errors.New("Block's parent hash cannot match best block")
    // ErrTooManyTransactionsInBlock defines error of too many transactions in a block.
    ErrTooManyTransactionsInBlock = errors.New("too many transactions in block")
    // ErrBalanceOverflow indicates that there will be an overflow after balance manipulation.
    ErrBalanceOverflow = errors.New("balance overflow")
    // ErrInsufficientBalance indicates that an account has insufficient balance for spending.
    ErrInsufficientBalance = errors.New("insufficient balance")
    // ErrInsufficientTransfer indicates that the transfer amount is insufficient for paying arrears.
    ErrInsufficientTransfer = errors.New("insufficient transfer")
    // ErrAccountNotFound indicates that an account is not found.
    ErrAccountNotFound = errors.New("account not found")
    // ErrAccountExists indicates that the an account already exists.
    ErrAccountExists = errors.New("account already exists")
    // ErrDatabaseNotFound indicates that a database is not found.
    ErrDatabaseNotFound = errors.New("database not found")
    // ErrDatabaseExists indicates that the database already exists.
    ErrDatabaseExists = errors.New("database already exists")
    // ErrDatabaseUserExists indicates that the database user already exists.
    ErrDatabaseUserExists = errors.New("database user already exists")
    // ErrInvalidAccountNonce indicates that a transaction has a invalid account nonce.
    ErrInvalidAccountNonce = errors.New("invalid account nonce")
    // ErrUnknownTransactionType indicates that a transaction has a unknown type and cannot be
    // further processed.
    ErrUnknownTransactionType = errors.New("unknown transaction type")
    // ErrInvalidSender indicates that tx.Signee != tx.Sender.
    ErrInvalidSender = errors.New("invalid sender")
    // ErrInvalidRange indicates that the billing range is invalid.
    ErrInvalidRange = errors.New("invalid billing range")
    // ErrNoSuchMiner indicates that this miner does not exist or register.
    ErrNoSuchMiner = errors.New("no such miner")
    // ErrNoEnoughMiner indicates that there is not enough miners
    ErrNoEnoughMiner = errors.New("can not get enough miners")
    // ErrAccountPermissionDeny indicates that the sender does not own admin permission to the sqlchain.
    ErrAccountPermissionDeny = errors.New("account permission deny")
    // ErrNoSuperUserLeft indicates there is no super user in sqlchain.
    ErrNoSuperUserLeft = errors.New("no super user left")
    // ErrInvalidPermission indicates that the permission is invalid.
    ErrInvalidPermission = errors.New("invalid permission")
    // ErrMinerUserNotMatch indicates that the miner and user do not match.
    ErrMinerUserNotMatch = errors.New("miner and user do not match")
    // ErrInsufficientAdvancePayment indicates that the advance payment is insufficient.
    ErrInsufficientAdvancePayment = errors.New("insufficient advance payment")
    // ErrNilGenesis indicates that the genesis block is nil in config.
    ErrNilGenesis = errors.New("nil genesis block")
    // ErrMultipleGenesis indicates that there're multiple genesis blocks while loading.
    ErrMultipleGenesis = errors.New("multiple genesis blocks")
    // ErrGenesisHashNotMatch indicates that the genesis block hash in config doesn't match
    // the persisted one.
    ErrGenesisHashNotMatch = errors.New("persisted genesis block hash not match")
    // ErrInvalidGasPrice indicates that the gas price is invalid.
    ErrInvalidGasPrice = errors.New("gas price is invalid")
    // ErrInvalidMinerCount indicates that the miner node count is invalid.
    ErrInvalidMinerCount = errors.New("miner node count is invalid")
    // ErrLocalNodeNotFound indicates that the local node id is not found in the given peer list.
    ErrLocalNodeNotFound = errors.New("local node id not found in peer list")
    // ErrNoAvailableBranch indicates that there is no available branch from the state storage.
    ErrNoAvailableBranch = errors.New("no available branch from state storage")
    // ErrWrongTokenType indicates that token type in transfer is wrong.
    ErrWrongTokenType = errors.New("wrong token type")
)

type Chain Uses

type Chain struct {
    sync.RWMutex // protects following fields
    // contains filtered or unexported fields
}

Chain defines the main chain.

func NewChain Uses

func NewChain(cfg *Config) (c *Chain, err error)

NewChain creates a new blockchain.

func NewChainWithContext Uses

func NewChainWithContext(ctx context.Context, cfg *Config) (c *Chain, err error)

NewChainWithContext creates a new blockchain with context.

func (*Chain) Start Uses

func (c *Chain) Start()

Start starts the chain by step: 1. sync the chain 2. goroutine for getting blocks 3. goroutine for getting txes.

func (*Chain) Stop Uses

func (c *Chain) Stop() (err error)

Stop stops the main process of the sql-chain.

type ChainRPCService Uses

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

ChainRPCService defines a main chain RPC server.

func (*ChainRPCService) AddTx Uses

func (s *ChainRPCService) AddTx(req *types.AddTxReq, _ *types.AddTxResp) (err error)

AddTx is the RPC method to add a transaction.

func (*ChainRPCService) AdviseNewBlock Uses

func (s *ChainRPCService) AdviseNewBlock(req *types.AdviseNewBlockReq, resp *types.AdviseNewBlockResp) error

AdviseNewBlock is the RPC method to advise a new block to target server.

func (*ChainRPCService) FetchBlock Uses

func (s *ChainRPCService) FetchBlock(req *types.FetchBlockReq, resp *types.FetchBlockResp) error

FetchBlock is the RPC method to fetch a known block from the target server.

func (*ChainRPCService) FetchBlockByCount Uses

func (s *ChainRPCService) FetchBlockByCount(req *types.FetchBlockByCountReq, resp *types.FetchBlockResp) error

FetchBlockByCount is the RPC method to fetch a known block from the target server.

func (*ChainRPCService) FetchLastIrreversibleBlock Uses

func (s *ChainRPCService) FetchLastIrreversibleBlock(
    req *types.FetchLastIrreversibleBlockReq, resp *types.FetchLastIrreversibleBlockResp) error

FetchLastIrreversibleBlock fetches the last block irreversible block from block producer.

func (*ChainRPCService) FetchTxBilling Uses

func (s *ChainRPCService) FetchTxBilling(req *types.FetchTxBillingReq, resp *types.FetchTxBillingResp) error

FetchTxBilling is the RPC method to fetch a known billing tx from the target server.

func (*ChainRPCService) NextAccountNonce Uses

func (s *ChainRPCService) NextAccountNonce(
    req *types.NextAccountNonceReq, resp *types.NextAccountNonceResp) (err error,
)

NextAccountNonce is the RPC method to query the next nonce of an account.

func (*ChainRPCService) QueryAccountSQLChainProfiles Uses

func (s *ChainRPCService) QueryAccountSQLChainProfiles(
    req *types.QueryAccountSQLChainProfilesReq, resp *types.QueryAccountSQLChainProfilesResp) (err error,
)

QueryAccountSQLChainProfiles is the RPC method to query account sqlchain profiles.

func (*ChainRPCService) QueryAccountTokenBalance Uses

func (s *ChainRPCService) QueryAccountTokenBalance(
    req *types.QueryAccountTokenBalanceReq, resp *types.QueryAccountTokenBalanceResp) (err error,
)

QueryAccountTokenBalance is the RPC method to query account token balance.

func (*ChainRPCService) QuerySQLChainProfile Uses

func (s *ChainRPCService) QuerySQLChainProfile(req *types.QuerySQLChainProfileReq,
    resp *types.QuerySQLChainProfileResp) (err error)

QuerySQLChainProfile is the RPC method to query SQLChainProfile.

func (*ChainRPCService) QueryTxState Uses

func (s *ChainRPCService) QueryTxState(
    req *types.QueryTxStateReq, resp *types.QueryTxStateResp) (err error,
)

QueryTxState is the RPC method to query a transaction state.

type Config Uses

type Config struct {
    Mode    RunMode
    Genesis *types.BPBlock

    DataFile string

    Server *rpc.Server

    Peers            *proto.Peers
    NodeID           proto.NodeID
    ConfirmThreshold float64

    Period time.Duration
    Tick   time.Duration

    BlockCacheSize int
}

Config is the main chain configuration.

type MinerInfos Uses

type MinerInfos []*types.MinerInfo

MinerInfos is MinerInfo array.

func (MinerInfos) Len Uses

func (x MinerInfos) Len() int

Len returns the length of the uints array.

func (MinerInfos) Less Uses

func (x MinerInfos) Less(i, j int) bool

Less returns true if MinerInfo i is less than node j.

func (MinerInfos) Swap Uses

func (x MinerInfos) Swap(i, j int)

Swap exchanges MinerInfo i and j.

type RunMode Uses

type RunMode int

RunMode defines modes that a bp can run as.

const (
    // BPMode is the default and normal mode.
    BPMode RunMode = iota

    // APINodeMode makes the bp behaviour like an API gateway. It becomes an API
    // node, who syncs data from the bp network and exposes JSON-RPC API to users.
    APINodeMode
)

Directories

PathSynopsis
interfacesPackage interfaces defines commonly used interfaces for block producers.

Package blockproducer imports 31 packages (graph) and is imported by 2 packages. Updated 2019-08-12. Refresh now. Tools for package owners.