Version: v0.0.0-...-020e20f Latest Latest

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

Go to latest
Published: Jun 1, 2022 License: Apache-2.0 Imports: 31 Imported by: 0



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



This section is empty.


View Source
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")


This section is empty.


type Chain

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

Chain defines the main chain.

func NewChain

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

NewChain creates a new blockchain.

func NewChainWithContext

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

NewChainWithContext creates a new blockchain with context.

func (*Chain) Start

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

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

Stop stops the main process of the sql-chain.

type ChainRPCService

type ChainRPCService struct {
	// contains filtered or unexported fields

ChainRPCService defines a main chain RPC server.

func (*ChainRPCService) AddTx

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

AddTx is the RPC method to add a transaction.

func (*ChainRPCService) AdviseNewBlock

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

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

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

FetchLastIrreversibleBlock fetches the last block irreversible block from block producer.

func (*ChainRPCService) FetchTxBilling

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

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

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

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

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

QuerySQLChainProfile is the RPC method to query SQLChainProfile.

func (*ChainRPCService) QueryTxState

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

QueryTxState is the RPC method to query a transaction state.

type Config

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

type MinerInfos []*types.MinerInfo

MinerInfos is MinerInfo array.

func (MinerInfos) Len

func (x MinerInfos) Len() int

Len returns the length of the uints array.

func (MinerInfos) Less

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

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

func (MinerInfos) Swap

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

Swap exchanges MinerInfo i and j.

type RunMode

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.


Path Synopsis
Package interfaces defines commonly used interfaces for block producers.
Package interfaces defines commonly used interfaces for block producers.

Jump to

Keyboard shortcuts

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