Documentation
¶
Index ¶
- Constants
- Variables
- func BlockLogTableNameForBlockHeight(num uint64) string
- func IOTrxTableNameForBlockHeight(num uint64) string
- type BlockLogRecord
- type DeprecatedBlockLogProgress
- type IConsensus
- type IDailyStats
- type IDatabaseBatch
- type IDatabasePatch
- type IDatabaseRW
- type IDatabaseService
- type IDatabaseServiceId
- type IGlobalPropRW
- type IGlobalPropReader
- type IGlobalPropWriter
- type IOTrxRecord
- type IP2P
- type IPrinter
- type IRPCServer
- type ITimer
- type ITrxPool
- type Progress
Constants ¶
View Source
const ( FastForwardStatus = 0 SyncForwardStatus = 1 MiddleStatus = 2 )
View Source
const BlockLogProcessServiceName = "block_log_proc_svc"
View Source
const BlockLogServiceName = "block_log_svc"
View Source
const BlockLogSplitSizeInMillion = 5
table splitting size in million records, set to 0 for no-splitting.
View Source
const BlockLogTable = "blocklogs"
View Source
const IOTrxServiceName = "iotrx_svc"
View Source
const IOTrxSplitSizeInMillion = 5
View Source
const IOTrxTable = "iotrx_record"
View Source
const ThresholdForFastConvertToSync = 10
Variables ¶
View Source
var ConsensusServerName = "consensus"
View Source
var DailyStatisticServiceName = "dailystatservice"
View Source
var DbServerName = "db"
View Source
var DbTrunk = ""
View Source
var P2PServerName = "p2p"
View Source
var RpcServerName = "rpc"
View Source
var TxPoolServerName = "ctrl"
Functions ¶
func BlockLogTableNameForBlockHeight ¶ added in v1.0.2
func IOTrxTableNameForBlockHeight ¶ added in v1.0.4
Types ¶
type BlockLogRecord ¶ added in v1.0.2
type BlockLogRecord struct {
ID uint64 `gorm:"primary_key;auto_increment"`
BlockId string `gorm:"not null;unique_index"`
BlockHeight uint64 `gorm:"not null;index"`
BlockTime time.Time `gorm:"not null"`
BlockProducer string `gorm:"index"`
Final bool `gorm:"not null;index"`
JsonLog string `gorm:"type:longtext"`
}
func (*BlockLogRecord) TableName ¶ added in v1.0.2
func (log *BlockLogRecord) TableName() string
type DeprecatedBlockLogProgress ¶ added in v1.0.4
type DeprecatedBlockLogProgress struct {
ID uint64 `gorm:"primary_key;auto_increment"`
BlockHeight uint64
FinishAt time.Time
}
func (DeprecatedBlockLogProgress) TableName ¶ added in v1.0.4
func (DeprecatedBlockLogProgress) TableName() string
type IConsensus ¶
type IConsensus interface {
// NOTE: producers should be maintained by the specific Consensus algorithm
// CurrentProducer returns current producer
CurrentProducer() string
// ActiveProducers returns a list of accounts that actively produce blocks
ActiveProducers() []string
ActiveValidators() []string
GetName() string
// SetBootstrap determines if the current node starts a new block chain
SetBootstrap(b bool)
//Add transaction to pending list,the transaction will be applied when generate a block
PushTransactionToPending(trx common.ISignedTransaction) error
// PushBlock adds b to the block fork DB, called if ValidateBlock returns true
PushBlock(b common.ISignedBlock)
// Push sends a user defined msg to consensus
Push(msg interface{}, p common.IPeer)
// GetLastBFTCommit get the last irreversible block info. @evidence
// is the information that can prove the id is indeed the last irreversible one.
// e.g. if user uses bft to achieve fast ack, @evidence can simply be the collection
// of the vote message
GetLastBFTCommit() (evidence interface{})
GetBFTCommitInfo(num uint64) interface{}
GetNextBFTCheckPoint(blockNum uint64) (evidence interface{})
// GetHeadBlockId returns the block id of the head block
GetHeadBlockId() common.BlockID
// GetIDs returns a list of block ids which remote peer may not have
GetIDs(start, end common.BlockID) ([]common.BlockID, error)
// FetchBlock returns the block whose id is the given param
FetchBlock(id common.BlockID) (common.ISignedBlock, error)
// HasBlock query the local blockchain whether it has the given block id
HasBlock(id common.BlockID) bool
// FetchBlocksSince returns blocks in the range of (id, max(headID, id+1024))
FetchBlocksSince(id common.BlockID) ([]common.ISignedBlock, error)
// FetchBlocks returns blocks in the range of [from, to]
FetchBlocks(from, to uint64) ([]common.ISignedBlock, error)
// NOTE: the following methods are testing methods and should only be called by multinodetester2
// ResetProdTimer reset the prodTimer in dpos
ResetProdTimer(t time.Duration)
// ResetTicker reset the Ticker in DPoS
ResetTicker(t time.Time)
GetLIB() common.BlockID
IsCommitted(id common.BlockID) bool
// MaybeProduceBlock check whether should produce a block
MaybeProduceBlock()
// check whether sync progress is finished
CheckSyncFinished() bool
// check whether the given id's signed block is on the main branch
IsOnMainBranch(id common.BlockID) (bool, error)
SetHook(key string, f func(args ...interface{}))
// for test only
EnableMockSignal()
MockMaliciousBehaviour(b bool)
}
type IDailyStats ¶ added in v1.0.2
type IDatabaseBatch ¶
type IDatabaseBatch interface {
// insert a new key-value pair, or update the value if the given key already exists
Put(key []byte, value []byte) error
// delete the given key and its value
// if the given key does not exist, just return nil, indicating a successful deletion without doing anything.
Delete(key []byte) error
// execute all batched operations
Write() error
// reset the batch to empty
Reset()
}
interface for transaction executor methods must be thread safe write operations must be executed atomically
type IDatabasePatch ¶ added in v1.0.2
type IDatabasePatch interface {
IDatabaseRW
// apply the patch
Apply() error
// patch on patch
NewPatch(branchId ...string) IDatabasePatch
}
type IDatabaseRW ¶ added in v1.0.2
type IDatabaseRW interface {
IDatabaseServiceId
// check existence of the given key
Has(key []byte) (bool, error)
// query the value of the given key
Get(key []byte) ([]byte, error)
// insert a new key-value pair, or update the value if the given key already exists
Put(key []byte, value []byte) error
// delete the given key and its value
// if the given key does not exist, just return nil, indicating a successful deletion without doing anything.
Delete(key []byte) error
// Iterate enumerates keys in range [start, limit) and calls callback with each enumerated key and its value.
// If callback returns false, the enumeration stops immediately, otherwise all matched keys will be enumerated.
// a nil start is the logical minimal key that is lesser than any existing keys
// a nil limit is the logical maximum key that is greater than any existing keys
Iterate(start, limit []byte, reverse bool, callback func(key, value []byte) bool)
// create a batch which can pack DatabasePutter & DatabaseDeleter operations and execute them atomically
NewBatch() IDatabaseBatch
// release a Batch
DeleteBatch(b IDatabaseBatch)
}
type IDatabaseService ¶
type IDatabaseService interface {
IDatabaseRW
// close a database
Close()
// start a new transaction session
BeginTransaction()
// end current transaction session, commit or discard changes
EndTransaction(commit bool) error
HashOfTopTransaction() uint32
// current transaction height
TransactionHeight() uint
BeginTransactionWithTag(tag string)
Squash(tag string) error
RollbackTag(tag string) error
// get current revision
GetRevision() uint64
// get current revision and base revision
GetRevisionAndBase() (current uint64, base uint64)
// revert to the given revision
// you can only revert to a revision that is less than or equal to current revision.
// after reverted to revision r, r will be the current revision.
RevertToRevision(r uint64) error
// rebase to the given revision
// after rebased to revision r, r will be the minimal revision you can revert to.
RebaseToRevision(r uint64) error
EnableReversion(b bool) error
ReversionEnabled() bool
// tag a revision
TagRevision(r uint64, tag string) error
// get revision of a tag
GetTagRevision(tag string) (uint64, error)
// get tag of a revision
GetRevisionTag(r uint64) string
// revert to a revision by its tag
RevertToTag(tag string) error
// rebase to a revision by its tag
RebaseToTag(tag string) error
// delete everything. make all data gone and unrecoverable.
// service will stop and restart if already started.
//
// this method is *NOT* thread safe. caller *MUST* guarantee that,
// - all iterators released by DeleteIterator() before calling DeleteAll()
// - no service calls before successful return of DeleteAll()
DeleteAll() error
// R/W locking
Lock()
Unlock()
RLock()
RUnlock()
NewPatch(branchId ...string) IDatabasePatch
}
Database Service
type IDatabaseServiceId ¶ added in v1.0.2
type IGlobalPropRW ¶ added in v1.0.2
type IGlobalPropRW interface {
IGlobalPropReader
IGlobalPropWriter
}
type IGlobalPropReader ¶ added in v1.0.2
type IGlobalPropReader interface {
GetProps() *prototype.DynamicProperties
HeadBlockTime() *prototype.TimePointSec
}
type IGlobalPropWriter ¶ added in v1.0.2
type IGlobalPropWriter interface {
TransferToVest(value *prototype.Coin)
TransferFromVest(value *prototype.Vest)
TransferToStakeVest(value *prototype.Coin)
TransferFromStakeVest(value *prototype.Vest)
ModifyProps(modifier func(oldProps *prototype.DynamicProperties))
UpdateTicketIncomeAndNum(income *prototype.Vest, count uint64)
}
type IOTrxRecord ¶ added in v1.0.4
type IOTrxRecord struct {
ID uint64 `gorm:"primary_key;auto_increment"`
TrxHash string `gorm:"index"`
BlockHeight uint64
BlockTime time.Time
Account string `gorm:"index"`
Action string `gorm:"index"`
}
func (*IOTrxRecord) TableName ¶ added in v1.0.4
func (log *IOTrxRecord) TableName() string
type IP2P ¶
type IP2P interface {
// Broadcast sigTrx or sigBlk msg
Broadcast(message interface{})
// trigger sync request remote peer the block hashes we do not have
TriggerSync(HeadId comn.BlockID)
// when got one unlinked block, to fetch its previous block
FetchUnlinkedBlock(prevId comn.BlockID)
// (localHeadID, targetID]
FetchMissingBlock(from, to comn.BlockID)
// Send message to a specific peer
SendToPeer(p *peer.Peer, message interface{})
// Send message to a random peer
RandomSend(message interface{})
// Request checkpoint batch [startNum, endNum)
RequestCheckpoint(startNum, endNum uint64)
GetNodeNeighbours() string
// for test only
SetMockLatency(t int)
GetMockLatency() int
}
IP2P represent the net interface of p2p package which can be called by other service
type IRPCServer ¶
type IRPCServer interface {
}
type ITrxPool ¶ added in v1.0.2
type ITrxPool interface {
IGlobalPropRW
PushTrx(trx *prototype.SignedTransaction) *prototype.TransactionReceiptWithInfo
PushBlock(blk *prototype.SignedBlock, skip prototype.SkipFlag) error
GenerateBlock(bpName string, pre *prototype.Sha256, timestamp uint32, priKey *prototype.PrivateKeyType, skip prototype.SkipFlag) (*prototype.SignedBlock, error)
GetBlockProducerTopN(n uint32) ([]string, []*prototype.PublicKeyType)
GetSigningPubKey(bpName string) *prototype.PublicKeyType
SetShuffledBpList(names []string, keys []*prototype.PublicKeyType, seq uint64)
GetShuffledBpList() ([]string, []*prototype.PublicKeyType, uint64)
SetShuffle(s common.ShuffleFunc)
// PreShuffle() must be called to notify ITrxPool that block producers shuffle is about to happen
PreShuffle() error
// PopBlock() rollbacks the state db to the moment just before applying block @num.
PopBlock(num uint64) error
// Commit() finalizes block @num.
Commit(num uint64)
// put trx into pending directly, no return value, so should be used by witness node to collect p2p trx
PushTrxToPending(trx *prototype.SignedTransaction) error
GenerateAndApplyBlock(bpName string, pre *prototype.Sha256, timestamp uint32, priKey *prototype.PrivateKeyType, skip prototype.SkipFlag) (*prototype.SignedBlock, error)
VerifySig(name *prototype.AccountName, digest []byte, sig []byte) bool
ValidateAddress(name string, pubKey *prototype.PublicKeyType) bool
Sign(priv *prototype.PrivateKeyType, digest []byte) []byte
//Fetch the latest pushed block number
GetHeadBlockNum() (uint64, error)
GetFinalizedNum() (uint64, error)
CalculateUserMaxStamina(db IDatabaseRW, name string) uint64
CheckNetForRPC(name string, db IDatabaseRW, sizeInBytes uint64) (bool, uint64, uint64)
EstimateStamina(trx *prototype.SignedTransaction) *prototype.TransactionReceiptWithInfo
HardFork() uint64
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.