core

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2020 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NumDelegate         = 10
	AccountDBNameFormat = "calculate_%d_%d_%d"
	BackupDBNamePrefix  = "backup_"
	BackupDBNameFormat  = BackupDBNamePrefix + "%d_%d" // backup_CalcBH_accountDBIndex

	Revision8   uint64 = 8
	RevisionMin        = Revision8
	RevisionMax        = Revision8
)
View Source
const (
	BlockHeightSize = 8
	BlockHashSize   = 32
	TXHashSize      = 32

	PreCommitIDSize = BlockHeightSize + BlockHashSize + common.AddressBytes

	ClaimBackupIDSize = BlockHeightSize + common.AddressBytes
	ClaimBackupPeriod = 43120*2 - 1
)
View Source
const (
	IISSDataVersion uint64 = 2

	IISSDataRevisionDefault uint64 = 0

	IISSDataDBPrefix = "iiss_rc_db_"
	IISSDataDBFormat = IISSDataDBPrefix + "%d" // $BH
)
View Source
const (
	TXDataTypeDelegate  = 0
	TXDataTypePrepReg   = 1
	TXDataTypePrepUnReg = 2
)
View Source
const (
	MaxDBCount int = 256

	NumMainPRep uint64 = 22
	NumSubPRep  uint64 = 78
)
View Source
const (
	IPCVersion uint64 = 2

	MsgVersion              uint = 0
	MsgClaim                     = 1
	MsgQuery                     = 2
	MsgCalculate                 = 3
	MsgCommitBlock               = 4
	MsgCommitClaim               = 5
	MsgQueryCalculateStatus      = 6
	MsgQueryCalculateResult      = 7
	MsgRollBack                  = 8
	MsgINIT                      = 9

	MsgNotify        = 100
	MsgReady         = MsgNotify + 0
	MsgCalculateDone = MsgNotify + 1

	MsgDebug = 1000
)
View Source
const (
	CalcRespStatusOK          uint16 = 0
	CalcRespStatusInvalidData uint16 = 1
	CalcRespStatusDoing       uint16 = 2
	CalcRespStatusInvalidBH   uint16 = 3
	CalcRespStatusDuplicateBH uint16 = 4
)
View Source
const (
	CalculationDone  uint64 = 0
	CalculationDoing uint64 = 1
)
View Source
const (
	DebugStatistics    uint64 = 0
	DebugDBInfo        uint64 = 1
	DebugPRep          uint64 = 2
	DebugPRepCandidate uint64 = 3
	DebugGV            uint64 = 4

	DebugLogCTX uint64 = 100
)
View Source
const (
	DebugAddress = "/tmp/.icon-rc-monitor.sock"
)
View Source
const (
	InvalidBH uint16 = 3
)
View Source
const (
	MinDelegation = blocksPerYear / iScoreMultiplier * (gvDivider / minRewardRep)
)

Variables

View Source
var BigInt100 = big.NewInt(100)
View Source
var BigIntClaimMinIScore = big.NewInt(claimMinIScore)
View Source
var BigIntIScoreMultiplier = big.NewInt(iScoreMultiplier)
View Source
var BigIntRewardDivider = big.NewInt(rewardDivider)
View Source
var BigIntTwo = big.NewInt(2)

Functions

func CalcRespStatusToString added in v1.1.1

func CalcRespStatusToString(status uint16) string

func ClaimBackupKey added in v1.2.1

func ClaimBackupKey(blockHeight uint64, address common.Address) []byte

func ClaimBackupKeyString added in v1.2.1

func ClaimBackupKeyString(key []byte) string

func CloseIScoreDB

func CloseIScoreDB(isDB *IScoreDB)

func DeleteCalculationResult added in v1.2.0

func DeleteCalculationResult(crDB db.Database, blockHeight uint64)

func DoClaim

func DoClaim(ctx *Context, req *ClaimMessage) (uint64, *common.HexInt)

DoClaim calculates the I-Score that the ICONist in ClaimMessage can get. Writes calculated I-Score and block height to claim DB. It returns the I-Score block height and I-Score. nil I-Score means zero I-Score. In error case, block height is zero and I-Score is nil.

func DoCommitClaim

func DoCommitClaim(ctx *Context, req *CommitClaim) error

func DoInit added in v1.2.0

func DoInit(ctx *Context, blockHeight uint64) error

func DoQueryCalculateResult

func DoQueryCalculateResult(ctx *Context, blockHeight uint64, resp *QueryCalculateResultResponse)

func DoQueryCalculateStatus

func DoQueryCalculateStatus(ctx *Context, resp *QueryCalculateStatusResponse)

func DoRollBack added in v1.2.0

func DoRollBack(ctx *Context, req *RollBackRequest) error

func InitManager

func InitManager(cfg *RcConfig) (*manager, error)

func LoadIISSData

func LoadIISSData(iissDB db.Database) (*IISSHeader, []*IISSGovernanceVariable, []*PRep)

func LoadPRepCandidate

func LoadPRepCandidate(dbi db.Database) (map[common.Address]*PRepCandidate, error)

func MakeIteratorPrefix added in v1.2.1

func MakeIteratorPrefix(prefix db.BucketID, blockHeight uint64, data []byte, dataSize int) *util.Range

func MsgDataToString

func MsgDataToString(data interface{}) string

func MsgToString

func MsgToString(msg uint) string

func OpenIISSData added in v1.1.1

func OpenIISSData(path string) db.Database

func WriteCalculationResult

func WriteCalculationResult(crDB db.Database, blockHeight uint64, stats *Statistics, stateHash []byte)

Types

type BlockInfo added in v1.2.0

type BlockInfo struct {
	BlockHeight uint64
	BlockHash   [BlockHashSize]byte
}

type CRData

type CRData struct {
	Success   bool
	StateHash []byte
	IScore    common.HexInt
	Beta1     common.HexInt
	Beta2     common.HexInt
	Beta3     common.HexInt
}

type CalcCancelByRollbackError added in v1.2.0

type CalcCancelByRollbackError struct {
	BlockHeight uint64
}

func (*CalcCancelByRollbackError) Error added in v1.2.0

func (e *CalcCancelByRollbackError) Error() string

type CalculateDone

type CalculateDone struct {
	Success     bool
	BlockHeight uint64
	IScore      common.HexInt
	StateHash   []byte
}

func (*CalculateDone) String

func (cd *CalculateDone) String() string

type CalculateRequest

type CalculateRequest struct {
	Path        string
	BlockHeight uint64
	BlockHash   []byte
}

func (*CalculateRequest) String

func (cr *CalculateRequest) String() string

type CalculateResponse added in v1.1.1

type CalculateResponse struct {
	Status      uint16
	BlockHeight uint64
}

func (*CalculateResponse) String added in v1.1.1

func (cr *CalculateResponse) String() string

type CalculationResult

type CalculationResult struct {
	BlockHeight uint64
	CRData
}

func NewCalculationResultFromBytes

func NewCalculationResultFromBytes(bs []byte) (*CalculationResult, error)

func (*CalculationResult) Bytes

func (cr *CalculationResult) Bytes() ([]byte, error)

func (*CalculationResult) ID

func (cr *CalculationResult) ID() []byte

func (*CalculationResult) SetBytes

func (cr *CalculationResult) SetBytes(bs []byte) error

func (*CalculationResult) String

func (cr *CalculationResult) String() string

type Claim

type Claim struct {
	Address common.Address
	Data    ClaimData
}

func NewClaimFromBytes

func NewClaimFromBytes(bs []byte) (*Claim, error)

func (*Claim) BackupID added in v1.2.0

func (c *Claim) BackupID(blockHeight uint64) []byte

func (*Claim) Bytes

func (c *Claim) Bytes() []byte

func (*Claim) ID

func (c *Claim) ID() []byte

func (*Claim) SetBytes

func (c *Claim) SetBytes(bs []byte) error

func (*Claim) String

func (c *Claim) String() string

type ClaimBackupInfo added in v1.2.0

type ClaimBackupInfo struct {
	FirstBlockHeight uint64
	LastBlockHeight  uint64
}

func (*ClaimBackupInfo) Bytes added in v1.2.0

func (cb *ClaimBackupInfo) Bytes() []byte

func (*ClaimBackupInfo) ID added in v1.2.0

func (cb *ClaimBackupInfo) ID() []byte

func (*ClaimBackupInfo) SetBytes added in v1.2.0

func (cb *ClaimBackupInfo) SetBytes(bs []byte) error

func (*ClaimBackupInfo) String added in v1.2.0

func (cb *ClaimBackupInfo) String() string

type ClaimData

type ClaimData struct {
	BlockHeight uint64
	IScore      common.HexInt
}

func (*ClaimData) String added in v1.2.0

func (cd *ClaimData) String() string

type ClaimMessage

type ClaimMessage struct {
	Address     common.Address
	BlockHeight uint64
	BlockHash   []byte
	TXIndex     uint64
	TXHash      []byte
}

func (*ClaimMessage) String

func (cm *ClaimMessage) String() string

type CommitBlock

type CommitBlock struct {
	Success     bool
	BlockHeight uint64
	BlockHash   []byte
}

func (*CommitBlock) String

func (cb *CommitBlock) String() string

type CommitClaim

type CommitClaim struct {
	Success     bool
	Address     common.Address
	BlockHeight uint64
	BlockHash   []byte
	TXIndex     uint64
	TXHash      []byte
}

func (*CommitClaim) String

func (cc *CommitClaim) String() string

type Context

type Context struct {
	DB *IScoreDB

	Revision       uint64
	PRep           []*PRep
	PRepCandidates map[common.Address]*PRepCandidate
	GV             []*GovernanceVariable

	Rollback *Rollback
	// contains filtered or unexported fields
}

func NewContext

func NewContext(dbPath string, dbType string, dbName string, dbCount int) (*Context, error)

func (*Context) Print

func (ctx *Context) Print()

func (*Context) RollbackManagementDB added in v1.2.0

func (ctx *Context) RollbackManagementDB(blockHeight uint64)

func (*Context) UpdateGovernanceVariable

func (ctx *Context) UpdateGovernanceVariable(gvList []*IISSGovernanceVariable)

Update Governance variable with IISS data

func (*Context) UpdatePRep

func (ctx *Context) UpdatePRep(prepList []*PRep)

Update Main/Sub P-Rep list

func (*Context) UpdatePRepCandidate

func (ctx *Context) UpdatePRepCandidate(iissDB db.Database)

Update P-Rep candidate with IISS TX(P-Rep register/unregister)

type DBInfo

type DBInfo struct {
	DBRoot string
	DBType string
	DBInfoData
}

func NewDBInfo

func NewDBInfo(mngDB db.Database, dbPath string, dbType string, dbName string, dbCount int) (*DBInfo, error)

func (*DBInfo) Bytes

func (dbi *DBInfo) Bytes() ([]byte, error)

func (*DBInfo) ID

func (dbi *DBInfo) ID() []byte

func (*DBInfo) SetBytes

func (dbi *DBInfo) SetBytes(bs []byte) error

func (*DBInfo) String

func (dbi *DBInfo) String() string

type DBInfoData

type DBInfoData DBInfoDataV2

type DBInfoDataV1 added in v1.2.0

type DBInfoDataV1 struct {
	DBCount       int
	BlockHeight   uint64 // finish to calculate to this block height
	QueryDBIsZero bool
}

type DBInfoDataV2 added in v1.2.0

type DBInfoDataV2 struct {
	DBCount       int
	QueryDBIsZero bool
	Current       BlockInfo // Latest COMMIT_BLOCK block height and hash
	CalcDone      uint64    // Latest CALCULATE_DONE block height
	PrevCalcDone  uint64    // Previous CALCULATE_DONE block height
	Calculating   uint64    // Latest CALCULATE block height
	ToggleBH      uint64    // Latest account DB toggle block height
}

type DebugMessage

type DebugMessage struct {
	Cmd uint64
}

type DelegateData

type DelegateData struct {
	Address  common.Address
	Delegate common.HexInt
}

type GVData

type GVData struct {
	CalculatedIncentiveRep common.HexInt
	RewardRep              common.HexInt
	MainPRepCount          common.HexInt
	SubPRepCount           common.HexInt
}

type GovernanceVariable

type GovernanceVariable struct {
	BlockHeight uint64
	GVData
	BlockProduceReward common.HexInt
	PRepReward         common.HexInt
}

func LoadGovernanceVariable

func LoadGovernanceVariable(dbi db.Database) ([]*GovernanceVariable, error)

func NewGVFromIISS

func NewGVFromIISS(iiss *IISSGovernanceVariable) *GovernanceVariable

func (*GovernanceVariable) Bytes

func (gv *GovernanceVariable) Bytes() ([]byte, error)

func (*GovernanceVariable) ID

func (gv *GovernanceVariable) ID() []byte

func (*GovernanceVariable) SetBytes

func (gv *GovernanceVariable) SetBytes(bs []byte) error

func (*GovernanceVariable) String

func (gv *GovernanceVariable) String() string

type IISSBlockProduceInfo

type IISSBlockProduceInfo struct {
	BlockHeight uint64
	IISSBlockProduceInfoData
}

func (*IISSBlockProduceInfo) Bytes

func (bp *IISSBlockProduceInfo) Bytes() ([]byte, error)

func (*IISSBlockProduceInfo) ID

func (bp *IISSBlockProduceInfo) ID() []byte

func (*IISSBlockProduceInfo) SetBytes

func (bp *IISSBlockProduceInfo) SetBytes(bs []byte) error

func (*IISSBlockProduceInfo) String

func (bp *IISSBlockProduceInfo) String() string

type IISSBlockProduceInfoData

type IISSBlockProduceInfoData struct {
	Generator common.Address
	Validator []common.Address
}

type IISSGVData

type IISSGVData struct {
	IncentiveRep  uint64
	RewardRep     uint64
	MainPRepCount uint64
	SubPRepCount  uint64
}

type IISSGovernanceVariable

type IISSGovernanceVariable struct {
	BlockHeight uint64
	IISSGVData
}

func (*IISSGovernanceVariable) Bytes

func (gv *IISSGovernanceVariable) Bytes() ([]byte, error)

func (*IISSGovernanceVariable) ID

func (gv *IISSGovernanceVariable) ID() []byte

func (*IISSGovernanceVariable) SetBytes

func (gv *IISSGovernanceVariable) SetBytes(bs []byte, version uint64) error

func (*IISSGovernanceVariable) String

func (gv *IISSGovernanceVariable) String() string

type IISSHeader

type IISSHeader struct {
	Version     uint64 // version of RC data
	BlockHeight uint64
	Revision    uint64 // revision of ICON Service
}

func (*IISSHeader) Bytes

func (ih *IISSHeader) Bytes() ([]byte, error)

func (*IISSHeader) ID

func (ih *IISSHeader) ID() []byte

func (*IISSHeader) SetBytes

func (ih *IISSHeader) SetBytes(bs []byte) error

func (*IISSHeader) String

func (ih *IISSHeader) String() string

type IISSTX

type IISSTX struct {
	Index uint64
	IISSTXData
}

func (*IISSTX) Bytes

func (tx *IISSTX) Bytes() ([]byte, error)

func (*IISSTX) ID

func (tx *IISSTX) ID() []byte

func (*IISSTX) SetBytes

func (tx *IISSTX) SetBytes(bs []byte) error

func (*IISSTX) String

func (tx *IISSTX) String() string

type IISSTXData

type IISSTXData struct {
	Address     common.Address
	BlockHeight uint64
	DataType    uint64
	Data        *codec.TypedObj
}

type IScoreAccount

type IScoreAccount struct {
	Address common.Address
	IScoreData
}

func NewIScoreAccountFromBytes

func NewIScoreAccountFromBytes(bs []byte) (*IScoreAccount, error)

func NewIScoreAccountFromIISS

func NewIScoreAccountFromIISS(iisstx *IISSTX) *IScoreAccount

func (*IScoreAccount) Bytes

func (ia *IScoreAccount) Bytes() []byte

func (*IScoreAccount) BytesForHash

func (ia *IScoreAccount) BytesForHash() []byte

func (*IScoreAccount) Compare

func (ia *IScoreAccount) Compare(b *IScoreAccount) int

func (*IScoreAccount) ID

func (ia *IScoreAccount) ID() []byte

func (*IScoreAccount) SetBytes

func (ia *IScoreAccount) SetBytes(bs []byte) error

func (*IScoreAccount) String

func (ia *IScoreAccount) String() string

type IScoreDB

type IScoreDB struct {
	Account0 []db.Database
	Account1 []db.Database
	// contains filtered or unexported fields
}

func (*IScoreDB) CloseAccountDB added in v1.2.0

func (idb *IScoreDB) CloseAccountDB()

func (*IScoreDB) GetCalcDBList

func (idb *IScoreDB) GetCalcDBList() []db.Database

func (*IScoreDB) OpenAccountDB added in v1.2.0

func (idb *IScoreDB) OpenAccountDB()

type IScoreData

type IScoreData struct {
	IScore      common.HexInt
	BlockHeight uint64
	Delegations []*DelegateData
}

type Manager

type Manager interface {
	Loop() error
	Close() error
}

type PRep

type PRep struct {
	BlockHeight uint64
	PRepData
}

func LoadPRep

func LoadPRep(dbi db.Database) ([]*PRep, error)

func (*PRep) Bytes

func (bp *PRep) Bytes() ([]byte, error)

func (*PRep) ID

func (bp *PRep) ID() []byte

func (*PRep) SetBytes

func (bp *PRep) SetBytes(bs []byte) error

func (*PRep) String

func (bp *PRep) String() string

type PRepCandidate

type PRepCandidate struct {
	Address common.Address
	PRepCandidateData
}

func (*PRepCandidate) Bytes

func (prep *PRepCandidate) Bytes() ([]byte, error)

func (*PRepCandidate) ID

func (prep *PRepCandidate) ID() []byte

func (*PRepCandidate) SetBytes

func (prep *PRepCandidate) SetBytes(bs []byte) error

func (*PRepCandidate) String

func (prep *PRepCandidate) String() string

type PRepCandidateData

type PRepCandidateData struct {
	Start uint64
	End   uint64 // 0 means that did not unregister
}

type PRepData

type PRepData struct {
	TotalDelegation common.HexInt
	List            []PRepDelegationInfo
}

func (*PRepData) String

func (pd *PRepData) String() string

type PRepDelegationInfo

type PRepDelegationInfo struct {
	Address         common.Address
	DelegatedAmount common.HexInt
}

func (*PRepDelegationInfo) String

func (di *PRepDelegationInfo) String() string

type PreCommit added in v1.1.1

type PreCommit struct {
	BlockHeight uint64
	BlockHash   []byte
	PreCommitData
}

func (*PreCommit) Bytes added in v1.1.1

func (pc *PreCommit) Bytes() ([]byte, error)

func (*PreCommit) ID added in v1.1.1

func (pc *PreCommit) ID() []byte

func (*PreCommit) SetBytes added in v1.1.1

func (pc *PreCommit) SetBytes(bs []byte) error

func (*PreCommit) SetID added in v1.2.0

func (pc *PreCommit) SetID(id []byte)

func (*PreCommit) String added in v1.1.1

func (pc *PreCommit) String() string

type PreCommitData added in v1.1.1

type PreCommitData struct {
	Confirmed bool
	TXIndex   uint64
	TXHash    []byte
	Claim
}

func (*PreCommitData) String added in v1.2.0

func (pc *PreCommitData) String() string

type QueryCalculateResultResponse

type QueryCalculateResultResponse struct {
	Status      uint16
	BlockHeight uint64
	IScore      common.HexInt
	StateHash   []byte
}

func (*QueryCalculateResultResponse) StatusString

func (cr *QueryCalculateResultResponse) StatusString() string

func (*QueryCalculateResultResponse) String

func (cr *QueryCalculateResultResponse) String() string

type QueryCalculateStatusResponse

type QueryCalculateStatusResponse struct {
	Status      uint64
	BlockHeight uint64
}

func (*QueryCalculateStatusResponse) StatusString

func (cs *QueryCalculateStatusResponse) StatusString() string

func (*QueryCalculateStatusResponse) String

func (cs *QueryCalculateStatusResponse) String() string

type RcConfig

type RcConfig struct {
	IISSDataDir   string `json:"IISSData"`
	DBDir         string `json:"IScoreDB"`
	IpcNet        string `json:"IPCNet"`
	IpcAddr       string `json:"IPCAddress"`
	ClientMode    bool   `json:"ClientMode"`
	DBCount       int    `json:"DBCount"`
	Monitor       bool   `json:"Monitor"`
	LogFile       string `json:"LogFile"`
	LogMaxSize    int    `json:"LogMaxSize"`
	LogMaxBackups int    `json:"LogMaxBackups"`
	FileName      string
}

func (*RcConfig) Print

func (cfg *RcConfig) Print()

type ResponseClaim

type ResponseClaim struct {
	ClaimMessage
	IScore common.HexInt
}

func (*ResponseClaim) String

func (rc *ResponseClaim) String() string

type ResponseDebugDBInfo

type ResponseDebugDBInfo struct {
	DebugMessage
	DBInfo DBInfo
}

type ResponseDebugGV

type ResponseDebugGV struct {
	DebugMessage
	GV []GovernanceVariable
}

type ResponseDebugPRep

type ResponseDebugPRep struct {
	DebugMessage
	PReps []PRep
}

type ResponseDebugPRepCandidate

type ResponseDebugPRepCandidate struct {
	DebugMessage
	PRepCandidates []PRepCandidate
}

type ResponseDebugStats

type ResponseDebugStats struct {
	DebugMessage
	BlockHeight uint64
	Stats       Statistics
}

type ResponseInit added in v1.2.0

type ResponseInit struct {
	Success     bool
	BlockHeight uint64
}

func (*ResponseInit) String added in v1.2.0

func (resp *ResponseInit) String() string

type ResponseQuery

type ResponseQuery struct {
	Address     common.Address
	IScore      common.HexInt
	BlockHeight uint64
}

func DoQuery

func DoQuery(ctx *Context, addr common.Address) *ResponseQuery

func (*ResponseQuery) String

func (rq *ResponseQuery) String() string

type ResponseVersion

type ResponseVersion struct {
	Version     uint64
	BlockHeight uint64
	BlockHash   [BlockHashSize]byte
}

func (*ResponseVersion) String added in v1.1.1

func (rv *ResponseVersion) String() string

type RollBackRequest added in v1.2.0

type RollBackRequest struct {
	BlockHeight uint64
	BlockHash   []byte
}

func (*RollBackRequest) String added in v1.2.0

func (rb *RollBackRequest) String() string

type RollBackResponse added in v1.2.0

type RollBackResponse struct {
	Success bool
	RollBackRequest
}

func (*RollBackResponse) String added in v1.2.0

func (rb *RollBackResponse) String() string

type Rollback added in v1.2.0

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

func NewRollback added in v1.2.0

func NewRollback() *Rollback

func (*Rollback) GetChannel added in v1.2.0

func (rb *Rollback) GetChannel() chan struct{}

type RollbackLowBlockHeightError added in v1.2.0

type RollbackLowBlockHeightError struct {
	Comparison  uint64
	BlockHeight uint64
}

func (*RollbackLowBlockHeightError) Error added in v1.2.0

type Statistics

type Statistics struct {
	Accounts    uint64
	TotalReward common.HexInt
	Beta1       common.HexInt
	Beta2       common.HexInt
	Beta3       common.HexInt
}

func DoCalculate

func DoCalculate(quit <-chan struct{}, ctx *Context, req *CalculateRequest, c ipc.Connection, id uint32) (error, uint64, *Statistics, []byte)

func (*Statistics) Bytes

func (stats *Statistics) Bytes() []byte

func (*Statistics) Decrease

func (stats *Statistics) Decrease(field string, value interface{}) error

func (*Statistics) Increase

func (stats *Statistics) Increase(field string, value interface{}) error

func (*Statistics) Set

func (stats *Statistics) Set(field string, value interface{}) error

func (*Statistics) SetBytes

func (stats *Statistics) SetBytes(bs []byte) error

func (*Statistics) String

func (stats *Statistics) String() string

Jump to

Keyboard shortcuts

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