statedb

package
v2.3.7 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

README

状态数据库

简介

KV状态数据库

SQL状态数据库

关于用户合约的状态数据库
  1. 每个合约对应一个SQL数据库,数据库的名字就是:chainId+"_合约的名字"。
  2. 每个数据库中都有一个默认的表state_infos,用于存储PutState的KV数据
  3. 每个数据库中有一个表state_record_sql,用于存储合约在创建和升级的时候用到的DDL,这个表主要是为了防止DDL执行到一半宕机或者报错的情况,下次再次执行时,知道哪些DDL已经执行了,哪些DDL还没有执行。
关于系统合约的状态数据库

所有系统合约都共用同一个状态数据库chainId+"_statedb" 这个数据库中有表:

  • state_infos 用于保存系统合约中用到的KV信息
  • member_extra_infos 用于保存用户的扩展信息
  • save_points 用于保存当前最新区块高度

关于Sqlite这种不支持多个database的处理

Sqlite主要用于测试的环境,不建议在生产使用, 因为Sqlite中没有多个数据库的概念,所以没办法创建多个数据库,那么就会导致所有合约都共用同一个数据库和表state_infos, 所以在测试的时候不要在多个合约中使用同名的key。

Documentation

Overview

Package statedb package

Package statedb is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MockStateDB added in v2.3.0

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

MockStateDB is a mock of StateDB interface.

func NewMockStateDB added in v2.3.0

func NewMockStateDB(ctrl *gomock.Controller) *MockStateDB

NewMockStateDB creates a new mock instance.

func (*MockStateDB) BeginDbTransaction added in v2.3.0

func (m *MockStateDB) BeginDbTransaction(txName string) (protocol.SqlDBTransaction, error)

BeginDbTransaction mocks base method.

func (*MockStateDB) Close added in v2.3.0

func (m *MockStateDB) Close()

Close mocks base method.

func (*MockStateDB) CommitBlock added in v2.3.0

func (m *MockStateDB) CommitBlock(blockWithRWSet *serialization.BlockWithSerializedInfo, isCache bool) error

CommitBlock mocks base method.

func (*MockStateDB) CommitDbTransaction added in v2.3.0

func (m *MockStateDB) CommitDbTransaction(txName string) error

CommitDbTransaction mocks base method.

func (*MockStateDB) CreateDatabase added in v2.3.0

func (m *MockStateDB) CreateDatabase(contractName string) error

CreateDatabase mocks base method.

func (*MockStateDB) DropDatabase added in v2.3.0

func (m *MockStateDB) DropDatabase(contractName string) error

DropDatabase mocks base method.

func (*MockStateDB) EXPECT added in v2.3.0

func (m *MockStateDB) EXPECT() *MockStateDBMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockStateDB) ExecDdlSql added in v2.3.0

func (m *MockStateDB) ExecDdlSql(contractName, sql, version string) error

ExecDdlSql mocks base method.

func (*MockStateDB) GetChainConfig added in v2.3.0

func (m *MockStateDB) GetChainConfig() (*config.ChainConfig, error)

GetChainConfig mocks base method.

func (*MockStateDB) GetContractDbName added in v2.3.0

func (m *MockStateDB) GetContractDbName(contractName string) string

GetContractDbName mocks base method.

func (*MockStateDB) GetDbTransaction added in v2.3.0

func (m *MockStateDB) GetDbTransaction(txName string) (protocol.SqlDBTransaction, error)

GetDbTransaction mocks base method.

func (*MockStateDB) GetLastSavepoint added in v2.3.0

func (m *MockStateDB) GetLastSavepoint() (uint64, error)

GetLastSavepoint mocks base method.

func (*MockStateDB) GetMemberExtraData added in v2.3.0

func (m *MockStateDB) GetMemberExtraData(member *accesscontrol.Member) (*accesscontrol.MemberExtraData, error)

GetMemberExtraData mocks base method.

func (*MockStateDB) InitGenesis added in v2.3.0

func (m *MockStateDB) InitGenesis(genesisBlock *serialization.BlockWithSerializedInfo) error

InitGenesis mocks base method.

func (*MockStateDB) QueryMulti added in v2.3.0

func (m *MockStateDB) QueryMulti(contractName, sql string, values ...interface{}) (protocol.SqlRows, error)

QueryMulti mocks base method.

func (*MockStateDB) QuerySingle added in v2.3.0

func (m *MockStateDB) QuerySingle(contractName, sql string, values ...interface{}) (protocol.SqlRow, error)

QuerySingle mocks base method.

func (*MockStateDB) ReadObject added in v2.3.0

func (m *MockStateDB) ReadObject(contractName string, key []byte) ([]byte, error)

ReadObject mocks base method.

func (*MockStateDB) ReadObjects added in v2.3.0

func (m *MockStateDB) ReadObjects(contractName string, keys [][]byte) ([][]byte, error)

ReadObjects mocks base method.

func (*MockStateDB) RollbackDbTransaction added in v2.3.0

func (m *MockStateDB) RollbackDbTransaction(txName string) error

RollbackDbTransaction mocks base method.

func (*MockStateDB) SelectObject added in v2.3.0

func (m *MockStateDB) SelectObject(contractName string, startKey, limit []byte) (protocol.StateIterator, error)

SelectObject mocks base method.

type MockStateDBMockRecorder added in v2.3.0

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

MockStateDBMockRecorder is the mock recorder for MockStateDB.

func (*MockStateDBMockRecorder) BeginDbTransaction added in v2.3.0

func (mr *MockStateDBMockRecorder) BeginDbTransaction(txName interface{}) *gomock.Call

BeginDbTransaction indicates an expected call of BeginDbTransaction.

func (*MockStateDBMockRecorder) Close added in v2.3.0

func (mr *MockStateDBMockRecorder) Close() *gomock.Call

Close indicates an expected call of Close.

func (*MockStateDBMockRecorder) CommitBlock added in v2.3.0

func (mr *MockStateDBMockRecorder) CommitBlock(blockWithRWSet, isCache interface{}) *gomock.Call

CommitBlock indicates an expected call of CommitBlock.

func (*MockStateDBMockRecorder) CommitDbTransaction added in v2.3.0

func (mr *MockStateDBMockRecorder) CommitDbTransaction(txName interface{}) *gomock.Call

CommitDbTransaction indicates an expected call of CommitDbTransaction.

func (*MockStateDBMockRecorder) CreateDatabase added in v2.3.0

func (mr *MockStateDBMockRecorder) CreateDatabase(contractName interface{}) *gomock.Call

CreateDatabase indicates an expected call of CreateDatabase.

func (*MockStateDBMockRecorder) DropDatabase added in v2.3.0

func (mr *MockStateDBMockRecorder) DropDatabase(contractName interface{}) *gomock.Call

DropDatabase indicates an expected call of DropDatabase.

func (*MockStateDBMockRecorder) ExecDdlSql added in v2.3.0

func (mr *MockStateDBMockRecorder) ExecDdlSql(contractName, sql, version interface{}) *gomock.Call

ExecDdlSql indicates an expected call of ExecDdlSql.

func (*MockStateDBMockRecorder) GetChainConfig added in v2.3.0

func (mr *MockStateDBMockRecorder) GetChainConfig() *gomock.Call

GetChainConfig indicates an expected call of GetChainConfig.

func (*MockStateDBMockRecorder) GetContractDbName added in v2.3.0

func (mr *MockStateDBMockRecorder) GetContractDbName(contractName interface{}) *gomock.Call

GetContractDbName indicates an expected call of GetContractDbName.

func (*MockStateDBMockRecorder) GetDbTransaction added in v2.3.0

func (mr *MockStateDBMockRecorder) GetDbTransaction(txName interface{}) *gomock.Call

GetDbTransaction indicates an expected call of GetDbTransaction.

func (*MockStateDBMockRecorder) GetLastSavepoint added in v2.3.0

func (mr *MockStateDBMockRecorder) GetLastSavepoint() *gomock.Call

GetLastSavepoint indicates an expected call of GetLastSavepoint.

func (*MockStateDBMockRecorder) GetMemberExtraData added in v2.3.0

func (mr *MockStateDBMockRecorder) GetMemberExtraData(member interface{}) *gomock.Call

GetMemberExtraData indicates an expected call of GetMemberExtraData.

func (*MockStateDBMockRecorder) InitGenesis added in v2.3.0

func (mr *MockStateDBMockRecorder) InitGenesis(genesisBlock interface{}) *gomock.Call

InitGenesis indicates an expected call of InitGenesis.

func (*MockStateDBMockRecorder) QueryMulti added in v2.3.0

func (mr *MockStateDBMockRecorder) QueryMulti(contractName, sql interface{}, values ...interface{}) *gomock.Call

QueryMulti indicates an expected call of QueryMulti.

func (*MockStateDBMockRecorder) QuerySingle added in v2.3.0

func (mr *MockStateDBMockRecorder) QuerySingle(contractName, sql interface{}, values ...interface{}) *gomock.Call

QuerySingle indicates an expected call of QuerySingle.

func (*MockStateDBMockRecorder) ReadObject added in v2.3.0

func (mr *MockStateDBMockRecorder) ReadObject(contractName, key interface{}) *gomock.Call

ReadObject indicates an expected call of ReadObject.

func (*MockStateDBMockRecorder) ReadObjects added in v2.3.0

func (mr *MockStateDBMockRecorder) ReadObjects(contractName, keys interface{}) *gomock.Call

ReadObjects indicates an expected call of ReadObjects.

func (*MockStateDBMockRecorder) RollbackDbTransaction added in v2.3.0

func (mr *MockStateDBMockRecorder) RollbackDbTransaction(txName interface{}) *gomock.Call

RollbackDbTransaction indicates an expected call of RollbackDbTransaction.

func (*MockStateDBMockRecorder) SelectObject added in v2.3.0

func (mr *MockStateDBMockRecorder) SelectObject(contractName, startKey, limit interface{}) *gomock.Call

SelectObject indicates an expected call of SelectObject.

type StateDB

type StateDB interface {

	// InitGenesis 创世块写入
	// @Description:
	// @param genesisBlock
	// @return error
	InitGenesis(genesisBlock *serialization.BlockWithSerializedInfo) error

	// CommitBlock commits the state in an atomic operation
	// @Description:
	// @param blockWithRWSet
	// @param isCache
	// @return error
	CommitBlock(blockWithRWSet *serialization.BlockWithSerializedInfo, isCache bool) error

	// GetChainConfig  get last chain config
	// @Description:
	// @return *configPb.ChainConfig
	// @return error
	GetChainConfig() (*configPb.ChainConfig, error)

	// ReadObject returns the state value for given contract name and key, or returns nil if none exists.
	// @Description:
	// @param contractName
	// @param key
	// @return []byte
	// @return error
	ReadObject(contractName string, key []byte) ([]byte, error)

	// ReadObjects returns the state values for given contract name and keys
	ReadObjects(contractName string, keys [][]byte) ([][]byte, error)

	// SelectObject returns an iterator that contains all the key-values between given key ranges.
	// @Description:
	// startKey is included in the results and limit is excluded.
	// @param contractName
	// @param startKey
	// @param limit
	// @return protocol.StateIterator
	// @return error
	SelectObject(contractName string, startKey []byte, limit []byte) (protocol.StateIterator, error)

	// GetLastSavepoint returns the last block height
	// @Description:
	// @return uint64
	// @return error
	GetLastSavepoint() (uint64, error)

	// Close Close is used to close database
	// @Description:
	Close()

	// QuerySingle 不在事务中,直接查询状态数据库,返回一行结果
	// @Description:
	// @param contractName
	// @param sql
	// @param values
	// @return protocol.SqlRow
	// @return error
	QuerySingle(contractName, sql string, values ...interface{}) (protocol.SqlRow, error)

	// QueryMulti  不在事务中,直接查询状态数据库,返回多行结果
	// @Description:
	// @param contractName
	// @param sql
	// @param values
	// @return protocol.SqlRows
	// @return error
	QueryMulti(contractName, sql string, values ...interface{}) (protocol.SqlRows, error)

	// ExecDdlSql
	// @Description: 执行DDL语句
	// @param contractName
	// @param sql
	// @param version
	// @return error
	ExecDdlSql(contractName, sql, version string) error

	// BeginDbTransaction
	// @Description: 启用一个事务
	// @param txName
	// @return protocol.SqlDBTransaction
	// @return error
	BeginDbTransaction(txName string) (protocol.SqlDBTransaction, error)

	// GetDbTransaction
	// @Description: 根据事务名,获得一个已经启用的事务
	// @param txName
	// @return protocol.SqlDBTransaction
	// @return error
	GetDbTransaction(txName string) (protocol.SqlDBTransaction, error)

	// CommitDbTransaction
	// @Description: 提交一个事务
	// @param txName
	// @return error
	CommitDbTransaction(txName string) error

	// RollbackDbTransaction
	// @Description: 回滚一个事务
	// @param txName
	// @return error
	RollbackDbTransaction(txName string) error

	// CreateDatabase
	// @Description: 创建database
	// @param contractName
	// @return error
	CreateDatabase(contractName string) error

	// DropDatabase
	// @Description: 删除一个合约对应的数据库
	// @param contractName
	// @return error
	DropDatabase(contractName string) error

	// GetContractDbName
	// @Description:  获得一个合约对应的状态数据库名
	// @param contractName
	// @return string
	GetContractDbName(contractName string) string

	// GetMemberExtraData
	// @Description:
	// @param member
	// @return *accesscontrol.MemberExtraData
	// @return error
	GetMemberExtraData(member *accesscontrol.Member) (*accesscontrol.MemberExtraData, error)
}

StateDB provides handle to world state instances @Description:

Directories

Path Synopsis
Package bloom package
Package bloom package
Package statekvdb package
Package statekvdb package
Package statesqldb package
Package statesqldb package

Jump to

Keyboard shortcuts

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