state

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AccountVersion1 = iota + 1
	AccountVersion2
	AccountVersion = AccountVersion1
)
View Source
const (
	ASDisabled = 1 << iota
	ASBlocked
	ASUseSystemDeposit
)
View Source
const (
	ExObjectGraph int = 1 << iota
	ExDepositInfo
)
View Source
const (
	ActiveNetworkTypeIDsKey = "activeNetworkTypeIDs"
	NetworkTypeIDKey        = "networkTypeID"
	NetworkTypeIDByUIDKey   = "networkTypeIDByUID"
	NetworkTypeByIDKey      = "networkTypeByID"
	NetworkIDKey            = "networkID"
	NetworkByIDKey          = "networkByID"
	PubKeyByNameKey         = "pubKeyByName"
	PubKeyOwner             = "pubKeyOwner"
	PubKeyMaskByNameKey     = "pubKeyMaskByName"
	DSAArrayKey             = "dsaArray"
	ActiveDSAMaskKey        = "activeDSAMask"
)
View Source
const (
	GIGA = 1000 * 1000 * 1000
	TERA = 1000 * GIGA
	PETA = 1000 * TERA
	EXA  = 1000 * PETA
)

TODO Check if everything here is adequate for state package.

View Source
const (
	StepTypeDefault          = "default"
	StepTypeContractCall     = "contractCall"
	StepTypeContractCreate   = "contractCreate"
	StepTypeContractUpdate   = "contractUpdate"
	StepTypeContractDestruct = "contractDestruct"
	StepTypeContractSet      = "contractSet"
	StepTypeGet              = "get"
	StepTypeSet              = "set"
	StepTypeReplace          = "replace"
	StepTypeDelete           = "delete"
	StepTypeInput            = "input"
	StepTypeEventLog         = "eventLog"
	StepTypeApiCall          = "apiCall"
	StepTypeSchema           = "schema"
	StepTypeGetBase          = "getBase"
	StepTypeSetBase          = "setBase"
	StepTypeDeleteBase       = "deleteBase"
	StepTypeLogBase          = "logBase"
	StepTypeLog              = "log"
)
View Source
const (
	StepLimitTypeInvoke = "invoke"
	StepLimitTypeQuery  = "query"
)
View Source
const (
	CTAppZip    = "application/zip"
	CTAppJava   = "application/java"
	CTAppSystem = "application/x.score.system"
)
View Source
const (
	DepositVersion1 int = iota
	DepositVersion2
)
View Source
const (
	VarStepPrice  = "step_price"
	VarStepCosts  = "step_costs"
	VarStepTypes  = "step_types"
	VarTreasury   = "treasury"
	VarGovernance = "governance"
	VarNetwork    = "network"
	VarChainID    = "chain_id"

	VarStepLimitTypes = "step_limit_types"
	VarStepLimit      = "step_limit"
	VarServiceConfig  = "serviceConfig"
	VarRevision       = "revision"
	VarMembers        = "members"
	VarDeployers      = "deployers"
	VarLicenses       = "licenses"
	VarTotalSupply    = "total_supply"

	VarTimestampThreshold = "timestamp_threshold"
	VarBlockInterval      = "block_interval"
	VarCommitTimeout      = "commit_timeout"
	VarRoundLimitFactor   = "round_limit_factor"
	VarMinimizeBlockGen   = "minimize_block_gen"
	VarTxHashToAddress    = "tx_to_address"
	VarDepositTerm        = "deposit_term"
	VarDepositIssueRate   = "deposit_issue_rate"
	VarNextBlockVersion   = "next_block_version"
	VarEnabledEETypes     = "enabled_ee_types"
	VarSystemDepositUsage = "system_deposit_usage"

	VarDSRContextHistory = "dsr_context_history"
)
View Source
const (
	SysConfigFee = 1 << iota
	SysConfigAudit
	SysConfigDeployerWhiteList
	SysConfigScorePackageValidator
	SysConfigMembership
	SysConfigFeeSharing
)
View Source
const (
	InfoBlockTimestamp = "B.timestamp"
	InfoBlockHeight    = "B.height"
	InfoTxHash         = "T.hash"
	InfoTxIndex        = "T.index"
	InfoTxTimestamp    = "T.timestamp"
	InfoTxNonce        = "T.nonce"
	InfoTxFrom         = "T.from"
	InfoRevision       = "Revision"
	InfoStepCosts      = "StepCosts"
	InfoContractOwner  = "C.owner"
)
View Source
const (
	AccountNoLock      = 0
	AccountReadLock    = 1
	AccountWriteLock   = 2
	AccountWriteUnlock = 3
)
View Source
const APIInfoCache = "cache.api_info"
View Source
const (
	AllEETypeString = "*"
)
View Source
const (
	DefaultNID = 1
)
View Source
const (
	LostIDStr = "\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
)
View Source
const (
	MissingGraphDataError = iota + errors.CodeService + 500
)
View Source
const (
	SystemIDStr = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
)
View Source
const (
	VarBlockedScores = "blocked_scores"
)
View Source
const (
	WorldIDStr = ""
)

Variables

View Source
var (
	SystemID      = []byte(SystemIDStr)
	SystemAddress = common.NewContractAddress(SystemID)
	ZeroAddress   = common.NewAccountAddress(SystemID)
)
View Source
var (
	LostID      = []byte(LostIDStr)
	LostAddress = common.NewAccountAddress(LostID)
)
View Source
var AccountType = reflect.TypeOf((*accountSnapshotImpl)(nil))
View Source
var AllStepLimitTypes = []string{
	StepLimitTypeInvoke,
	StepLimitTypeQuery,
}

Functions

func AttachAPIInfoCache added in v1.3.12

func AttachAPIInfoCache(dbase db.Database, size int) (db.Database, error)

func GetAPIInfoFromBucket added in v1.3.12

func GetAPIInfoFromBucket(bk db.Bucket, hash []byte) (*scoreapi.Info, error)

func IsValidStepLimitType added in v1.4.0

func IsValidStepLimitType(s string) bool

func IsValidStepType added in v0.9.8

func IsValidStepType(s string) bool

func MustEncodeAPIInfo added in v1.3.12

func MustEncodeAPIInfo(info *scoreapi.Info) ([]byte, []byte)

func NewBTPMsg added in v1.3.0

func NewBTPMsg(nid int64, msg []byte) *bTPMsg

func NewNetwork added in v1.3.0

func NewNetwork(ntid int64, name string, owner module.Address, startHeight int64, nextProofContextChanged bool) *network

func NewNetworkFromBytes added in v1.3.0

func NewNetworkFromBytes(b []byte) *network

func NewNetworkType added in v1.3.0

func NewNetworkType(uid string, proofContext module.BTPProofContext) *networkType

func NewNetworkTypeFromBytes added in v1.3.0

func NewNetworkTypeFromBytes(b []byte) *networkType

func NewValidatorListFromBytes added in v1.3.10

func NewValidatorListFromBytes(bs []byte) (module.ValidatorList, error)

func ToSliceOfValidatorPtr added in v1.3.6

func ToSliceOfValidatorPtr(vl []module.Validator) ([]*validator, error)

func ToValidatorList added in v1.3.10

func ToValidatorList(list module.ValidatorList) (module.ValidatorList, error)

func ValidateEEType added in v0.9.10

func ValidateEEType(et EEType) bool

func ValidatorFromAddress

func ValidatorFromAddress(a module.Address) (module.Validator, error)

func ValidatorFromPublicKey

func ValidatorFromPublicKey(pk []byte) (module.Validator, error)

Types

type APIInfoBucket added in v1.3.12

type APIInfoBucket interface {
	Get(hash []byte) (*scoreapi.Info, error)
	Set(hash, bytes []byte, info *scoreapi.Info) error
}

func GetAPIInfoBucket added in v1.3.12

func GetAPIInfoBucket(dbase db.Database) (APIInfoBucket, error)

type AccountData added in v1.3.3

type AccountData interface {
	Version() int
	GetBalance() *big.Int
	IsContract() bool
	IsEmpty() bool
	IsDisabled() bool
	IsBlocked() bool
	UseSystemDeposit() bool
	GetValue(k []byte) ([]byte, error)
	IsContractOwner(owner module.Address) bool
	ContractOwner() module.Address
	APIInfo() (*scoreapi.Info, error)
	CanAcceptTx(pc PayContext) bool
	CheckDeposit(pc PayContext) bool
	GetObjGraph(hash []byte, flags bool) (int, []byte, []byte, error)
	GetDepositInfo(dc DepositContext, v module.JSONVersion) (map[string]interface{}, error)
}

type AccountSnapshot

type AccountSnapshot interface {
	AccountData
	trie.Object
	StorageChangedAfter(snapshot AccountSnapshot) bool
	Contract() ContractSnapshot
	ActiveContract() ContractSnapshot
	NextContract() ContractSnapshot
}

AccountSnapshot represents immutable account state It can be get from AccountState or WorldSnapshot.

type AccountState

type AccountState interface {
	AccountData
	MigrateForRevision(rev module.Revision) error
	SetBalance(v *big.Int)
	SetValue(k, v []byte) ([]byte, error)
	DeleteValue(k []byte) ([]byte, error)
	GetSnapshot() AccountSnapshot
	Reset(snapshot AccountSnapshot) error
	Clear()

	SetContractOwner(owner module.Address) error
	InitContractAccount(address module.Address) bool
	DeployContract(code []byte, eeType EEType, contentType string, params []byte, txHash []byte) ([]byte, error)
	SetAPIInfo(*scoreapi.Info)
	ActivateNextContract() error
	AcceptContract(txHash []byte, auditTxHash []byte) error
	RejectContract(txHash []byte, auditTxHash []byte) error
	Contract() ContractState
	ActiveContract() ContractState
	NextContract() ContractState
	SetDisable(b bool)
	SetBlock(b bool)
	SetUseSystemDeposit(yn bool) error
	SetObjGraph(id []byte, flags bool, nextHash int, objGraph []byte) error

	AddDeposit(dc DepositContext, value *big.Int) error
	WithdrawDeposit(dc DepositContext, id []byte, value *big.Int) (*big.Int, *big.Int, error)
	PaySteps(pc PayContext, steps *big.Int) (*big.Int, *big.Int, error)
}

AccountState represents mutable account state. You may change account state with this object. It can be get from WorldState. Changes in this object will be retrieved by WorldState. Of course, it also can be changed by WorldState.

type BTPContext added in v1.3.0

type BTPContext interface {
	btp.StateView
	Store() containerdb.BytesStoreState
	BlockHeight() int64
	GetValidatorState() ValidatorState
	GetNetworkTypeIDs() ([]int64, error)
	GetNetworkTypeIDByName(name string) int64
	GetNetworkType(ntid int64) (module.BTPNetworkType, error)
	GetNetwork(nid int64) (module.BTPNetwork, error)
	GetPublicKey(address module.Address, name string) []byte
	GetPublicKeyMask(address module.Address) int64
	GetDSAIndex(name string) int
	GetActiveDSAMask() int64
}

func NewBTPContext added in v1.3.0

func NewBTPContext(wc WorldContext, store containerdb.BytesStoreState) BTPContext

type BTPSnapshot added in v1.3.0

type BTPSnapshot interface {
	Bytes() []byte
	Flush() error
	NewState() BTPState
}

func NewBTPSnapshot added in v1.3.0

func NewBTPSnapshot(dbase db.Database, hash []byte) BTPSnapshot

type BTPState added in v1.3.0

type BTPState interface {
	GetSnapshot() BTPSnapshot
	Reset(snapshot BTPSnapshot)
	StoreValidators(vs ValidatorState)
	BuildAndApplySection(bc BTPContext, btpMsgs *list.List) (module.BTPSection, error)
}

func NewBTPState added in v1.3.0

func NewBTPState(dbase db.Database, hash []byte) BTPState

type BTPStateImpl added in v1.3.0

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

func (*BTPStateImpl) BuildAndApplySection added in v1.3.0

func (bs *BTPStateImpl) BuildAndApplySection(bc BTPContext, btpMsgs *list.List) (module.BTPSection, error)

func (*BTPStateImpl) CheckPublicKey added in v1.3.0

func (bs *BTPStateImpl) CheckPublicKey(bc BTPContext, from module.Address) error

func (*BTPStateImpl) Clone added in v1.3.0

func (bd *BTPStateImpl) Clone() btpData

func (*BTPStateImpl) CloseNetwork added in v1.3.0

func (bs *BTPStateImpl) CloseNetwork(bc BTPContext, nid int64) (int64, error)

func (*BTPStateImpl) GetSnapshot added in v1.3.0

func (bs *BTPStateImpl) GetSnapshot() BTPSnapshot

func (*BTPStateImpl) HandleMessage added in v1.3.0

func (bs *BTPStateImpl) HandleMessage(bc BTPContext, from module.Address, nid int64) (int64, error)

func (*BTPStateImpl) OpenNetwork added in v1.3.0

func (bs *BTPStateImpl) OpenNetwork(
	bc BTPContext, networkTypeName string, name string, owner module.Address,
) (ntid int64, nid int64, err error)

func (*BTPStateImpl) Reset added in v1.3.0

func (bs *BTPStateImpl) Reset(snapshot BTPSnapshot)

func (*BTPStateImpl) SetPublicKey added in v1.3.0

func (bs *BTPStateImpl) SetPublicKey(bc BTPContext, from module.Address, name string, pubKey []byte) error

func (*BTPStateImpl) StoreValidators added in v1.3.0

func (bs *BTPStateImpl) StoreValidators(vs ValidatorState)

type ContractInfo

type ContractInfo struct {
	Owner module.Address
}

type ContractSnapshot

type ContractSnapshot interface {
	CodeID() []byte
	CodeHash() []byte
	Code() ([]byte, error)
	EEType() EEType
	ContentType() string
	DeployTxHash() []byte
	AuditTxHash() []byte
	Params() []byte
	Status() ContractStatus
	Equal(s ContractSnapshot) bool
}

type ContractState

type ContractState interface {
	ContractSnapshot
	SetCode([]byte) error
}

type ContractStatus added in v1.2.9

type ContractStatus int
const (
	CSInactive ContractStatus = 1 << iota
	CSActive
	CSPending
	CSRejected
)

func (ContractStatus) String added in v1.2.9

func (cs ContractStatus) String() string

type DepositContext added in v0.9.3

type DepositContext interface {
	StepPrice() *big.Int
	BlockHeight() int64
	DepositTerm() int64
	DepositIssueRate() *big.Int
	TransactionID() []byte
}

type EEType

type EEType string
const (
	NullEE   EEType = ""
	PythonEE EEType = "python"
	JavaEE   EEType = "java"
	SystemEE EEType = "system"
)

func EETypeFromContentType

func EETypeFromContentType(ct string) (EEType, bool)

func MustEETypeFromContentType added in v0.9.4

func MustEETypeFromContentType(ct string) EEType

func (EEType) AbleToUpdate added in v0.9.10

func (e EEType) AbleToUpdate(org EEType) bool

func (EEType) InstallMethod

func (e EEType) InstallMethod() (string, bool)

func (EEType) IsInternalMethod

func (e EEType) IsInternalMethod(s string) bool

func (EEType) NeedAudit added in v0.9.4

func (e EEType) NeedAudit() bool

func (EEType) String

func (e EEType) String() string

func (EEType) UpdateMethod

func (e EEType) UpdateMethod(from EEType) (string, bool)

type EETypeFilter added in v0.9.10

type EETypeFilter map[EEType]bool

func (EETypeFilter) Contains added in v0.9.10

func (ets EETypeFilter) Contains(et EEType) bool

func (EETypeFilter) String added in v0.9.10

func (ets EETypeFilter) String() string

type EETypes added in v0.9.10

type EETypes interface {
	Contains(et EEType) bool
	String() string
}
var AllEETypes EETypes = allEETypes{}

func ParseEETypes added in v0.9.10

func ParseEETypes(s string) (EETypes, error)

type ExtensionSnapshot added in v0.9.1

type ExtensionSnapshot interface {
	Bytes() []byte
	Flush() error
	NewState(readonly bool) ExtensionState
}

type ExtensionState added in v0.9.1

type ExtensionState interface {
	GetSnapshot() ExtensionSnapshot
	Reset(snapshot ExtensionSnapshot)
	ClearCache()
}

type LockRequest

type LockRequest struct {
	ID   string
	Lock int
}

type PayContext added in v0.9.4

type PayContext interface {
	FeeSharingEnabled() bool
	StepPrice() *big.Int
	FeeLimit() *big.Int
	BlockHeight() int64
}

type Platform added in v0.9.1

type Platform interface {
	ToRevision(value int) module.Revision
}

type PlatformWithDoubleSignDataDecoder added in v1.3.13

type PlatformWithDoubleSignDataDecoder interface {
	Platform
	DoubleSignDataDecoder() module.DoubleSignDataDecoder
}

type StepType

type StepType string

type TransactionInfo

type TransactionInfo struct {
	Group     module.TransactionGroup
	Index     int32
	Hash      []byte
	From      module.Address
	Timestamp int64
	Nonce     *big.Int
}

type ValidatorSnapshot

type ValidatorSnapshot interface {
	module.ValidatorList
	Flush() error
}

func NewValidatorSnapshotWithBuilder

func NewValidatorSnapshotWithBuilder(builder merkle.Builder, h []byte) (ValidatorSnapshot, error)

func ValidatorSnapshotFromHash

func ValidatorSnapshotFromHash(database db.Database, h []byte) (ValidatorSnapshot, error)

func ValidatorSnapshotFromList added in v1.3.10

func ValidatorSnapshotFromList(database db.Database, vl module.ValidatorList) (ValidatorSnapshot, error)

func ValidatorSnapshotFromSlice

func ValidatorSnapshotFromSlice(database db.Database, vl []module.Validator) (ValidatorSnapshot, error)

type ValidatorState

type ValidatorState interface {
	IndexOf(module.Address) int
	Len() int
	Get(i int) (module.Validator, bool)
	Set([]module.Validator) error
	Add(v module.Validator) error
	Remove(v module.Validator) bool
	Replace(ov, nv module.Validator) error
	SetAt(i int, v module.Validator) error
	GetSnapshot() ValidatorSnapshot
	Reset(ValidatorSnapshot)
}

func ValidatorStateFromHash

func ValidatorStateFromHash(database db.Database, h []byte) (ValidatorState, error)

func ValidatorStateFromSnapshot

func ValidatorStateFromSnapshot(vss ValidatorSnapshot) ValidatorState

type WorldContext

type WorldContext interface {
	WorldState
	Revision() module.Revision
	ToRevision(v int) module.Revision
	StepsFor(t StepType, n int) int64
	StepPrice() *big.Int
	BlockTimeStamp() int64
	GetStepLimit(t string) *big.Int
	BlockHeight() int64
	ConsensusInfo() module.ConsensusInfo
	Treasury() module.Address
	Governance() module.Address
	GetInfo() map[string]interface{}
	WorldStateChanged(ws WorldState) WorldContext
	WorldVirtualState() WorldVirtualState
	GetFuture(lq []LockRequest) WorldContext
	SetTransactionInfo(ti *TransactionInfo)
	TransactionInfo() *TransactionInfo
	TransactionID() []byte
	NextTransactionSalt() *big.Int
	SetContractInfo(si *ContractInfo)
	DepositIssueRate() *big.Int
	FeeLimit() *big.Int
	DepositTerm() int64
	UpdateSystemInfo()

	IsDeployer(addr string) bool
	FeeEnabled() bool
	AuditEnabled() bool
	FeeSharingEnabled() bool
	DeployerWhiteListEnabled() bool
	PackageValidatorEnabled() bool
	MembershipEnabled() bool
	TransactionTimestampThreshold() int64

	EnableSkipTransaction()
	SkipTransactionEnabled() bool

	DecodeDoubleSignContext(t string, d []byte) (module.DoubleSignContext, error)
	DecodeDoubleSignData(t string, d []byte) (module.DoubleSignData, error)
	GetDoubleSignContextRoot() (module.DoubleSignContextRoot, error)
}

func NewWorldContext

func NewWorldContext(ws WorldState, bi module.BlockInfo, csi module.ConsensusInfo, plt Platform) WorldContext

type WorldSnapshot

type WorldSnapshot interface {
	GetAccountSnapshot(id []byte) AccountSnapshot
	GetValidatorSnapshot() ValidatorSnapshot
	GetExtensionSnapshot() ExtensionSnapshot
	GetBTPSnapshot() BTPSnapshot
	Flush() error
	StateHash() []byte
	ExtensionData() []byte
	BTPData() []byte
	Database() db.Database
}

WorldSnapshot represents snapshot of WorldState. It can be use to WorldState recover state of WorldState to at some point.

func NewWorldSnapshot

func NewWorldSnapshot(
	dbase db.Database, stateHash []byte, vs ValidatorSnapshot, es ExtensionSnapshot, btpData []byte,
) WorldSnapshot

func NewWorldSnapshotWithBuilder

func NewWorldSnapshotWithBuilder(
	builder merkle.Builder, sh []byte, vh []byte, ess ExtensionSnapshot, bh []byte,
) (WorldSnapshot, error)

func NewWorldSnapshotWithNewValidators

func NewWorldSnapshotWithNewValidators(dbase db.Database, snapshot WorldSnapshot, vss ValidatorSnapshot) WorldSnapshot

type WorldState

type WorldState interface {
	GetAccountState(id []byte) AccountState
	GetAccountSnapshot(id []byte) AccountSnapshot
	GetSnapshot() WorldSnapshot
	GetValidatorState() ValidatorState
	GetExtensionState() ExtensionState
	GetBTPState() BTPState
	Reset(snapshot WorldSnapshot) error
	ClearCache()
	EnableNodeCache()
	NodeCacheEnabled() bool
	Database() db.Database
	EnableAccountNodeCache(id []byte) bool
}

WorldState represents world state. You may change

func NewReadOnlyWorldState

func NewReadOnlyWorldState(wss WorldSnapshot) WorldState

func NewWorldState

func NewWorldState(
	database db.Database, stateHash []byte, vs ValidatorSnapshot, es ExtensionSnapshot, btpHash []byte,
) WorldState

func WorldStateFromSnapshot

func WorldStateFromSnapshot(wss WorldSnapshot) (WorldState, error)

type WorldVirtualState

type WorldVirtualState interface {
	WorldState
	GetFuture(reqs []LockRequest) WorldVirtualState
	Ensure()
	Commit()
	Realize()
}

func NewWorldVirtualState

func NewWorldVirtualState(ws WorldState, reqs []LockRequest) WorldVirtualState

Jump to

Keyboard shortcuts

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