statedb

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2022 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultCacheConfig = CacheConfig{
		AccountCacheSize: 2048,
		NftCacheSize:     2048,
	}
)

Functions

This section is empty.

Types

type CacheConfig

type CacheConfig struct {
	AccountCacheSize int
	NftCacheSize     int
}

type ChainDB

type ChainDB struct {
	DB *gorm.DB
	// Block Chain data
	BlockModel           block.BlockModel
	CompressedBlockModel compressedblock.CompressedBlockModel
	TxModel              tx.TxModel
	PriorityRequestModel priorityrequest.PriorityRequestModel

	// State DB
	AccountModel        account.AccountModel
	AccountHistoryModel account.AccountHistoryModel
	L2AssetInfoModel    asset.AssetModel
	L2NftModel          nft.L2NftModel
	L2NftHistoryModel   nft.L2NftHistoryModel
	TxPoolModel         tx.TxPoolModel

	// Sys config
	SysConfigModel sysconfig.SysConfigModel
}

func NewChainDB

func NewChainDB(db *gorm.DB) *ChainDB

func (*ChainDB) Close

func (c *ChainDB) Close()

type StateCache

type StateCache struct {
	StateRoot string
	// Updated in executor's GeneratePubData method.
	PubData                         []byte
	PriorityOperations              int64
	PubDataOffset                   []uint32
	PendingOnChainOperationsPubData [][]byte
	PendingOnChainOperationsHash    []byte
	Txs                             []*tx.Tx

	// Record the flat data that should be updated.
	PendingAccountMap map[int64]*types.AccountInfo
	PendingNftMap     map[int64]*nft.L2Nft
	PendingGasMap     map[int64]*big.Int //pending gas changes of a block
	// contains filtered or unexported fields
}

func NewStateCache

func NewStateCache(stateRoot string) *StateCache

func (*StateCache) AlignPubData

func (c *StateCache) AlignPubData(blockSize int)

func (*StateCache) GetPendingAccount

func (c *StateCache) GetPendingAccount(accountIndex int64) (*types.AccountInfo, bool)

func (*StateCache) GetPendingGas added in v0.0.5

func (c *StateCache) GetPendingGas(assetId int64) *big.Int

func (*StateCache) GetPendingNft

func (c *StateCache) GetPendingNft(nftIndex int64) (*nft.L2Nft, bool)

func (*StateCache) MarkAccountAssetsDirty

func (c *StateCache) MarkAccountAssetsDirty(accountIndex int64, assets []int64)

func (*StateCache) MarkNftDirty

func (c *StateCache) MarkNftDirty(nftIndex int64)

func (*StateCache) SetPendingAccount added in v0.0.4

func (c *StateCache) SetPendingAccount(accountIndex int64, account *types.AccountInfo)

func (*StateCache) SetPendingGas added in v0.0.5

func (c *StateCache) SetPendingGas(assetId int64, balanceDelta *big.Int)

func (*StateCache) SetPendingNft added in v0.0.4

func (c *StateCache) SetPendingNft(nftIndex int64, nft *nft.L2Nft)

type StateDB

type StateDB struct {

	// State cache
	*StateCache

	// Flat state
	AccountCache *lru.Cache
	NftCache     *lru.Cache

	// Tree state
	AccountTree       bsmt.SparseMerkleTree
	NftTree           bsmt.SparseMerkleTree
	AccountAssetTrees *tree.AssetTreeCache
	TreeCtx           *tree.Context
	// contains filtered or unexported fields
}

func NewStateDB

func NewStateDB(treeCtx *tree.Context, chainDb *ChainDB,
	redisCache dbcache.Cache, cacheConfig *CacheConfig, assetCacheSize int,
	stateRoot string, curHeight int64) (*StateDB, error)

func NewStateDBForDryRun

func NewStateDBForDryRun(redisCache dbcache.Cache, cacheConfig *CacheConfig, chainDb *ChainDB) (*StateDB, error)

func (*StateDB) Close

func (s *StateDB) Close()

func (*StateDB) DeepCopyAccounts

func (s *StateDB) DeepCopyAccounts(accountIds []int64) (map[int64]*types.AccountInfo, error)

func (*StateDB) GetAccount

func (s *StateDB) GetAccount(accountIndex int64) (*account.Account, error)

func (*StateDB) GetAccountByName added in v0.0.4

func (s *StateDB) GetAccountByName(accountName string) (*account.Account, error)

GetAccountByName get the account by its name. Firstly, try to find the account in the current state cache, it iterates the pending account map, not performance friendly, please take care when use this API. Secondly, if not found in the current state cache, then try to find the account from database.

func (*StateDB) GetAccountByNameHash added in v0.0.4

func (s *StateDB) GetAccountByNameHash(accountNameHash string) (*account.Account, error)

GetAccountByNameHash get the account by its name hash. Firstly, try to find the account in the current state cache, it iterates the pending account map, not performance friendly, please take care when use this API. Secondly, if not found in the current state cache, then try to find the account from database.

func (*StateDB) GetCommittedNonce

func (s *StateDB) GetCommittedNonce(accountIndex int64) (int64, error)

func (*StateDB) GetFormatAccount

func (s *StateDB) GetFormatAccount(accountIndex int64) (*types.AccountInfo, error)

func (*StateDB) GetGasAccountIndex

func (s *StateDB) GetGasAccountIndex() (int64, error)

func (*StateDB) GetGasConfig

func (s *StateDB) GetGasConfig() (map[uint32]map[int]int64, error)

func (*StateDB) GetNextAccountIndex

func (s *StateDB) GetNextAccountIndex() int64

func (*StateDB) GetNextNftIndex

func (s *StateDB) GetNextNftIndex() int64

func (*StateDB) GetNft

func (s *StateDB) GetNft(nftIndex int64) (*nft.L2Nft, error)

func (*StateDB) GetPendingAccount

func (s *StateDB) GetPendingAccount(blockHeight int64) ([]*account.Account, []*account.AccountHistory, error)

func (*StateDB) GetPendingNft

func (s *StateDB) GetPendingNft(blockHeight int64) ([]*nft.L2Nft, []*nft.L2NftHistory, error)

func (*StateDB) GetPendingNonce

func (s *StateDB) GetPendingNonce(accountIndex int64) (int64, error)

func (*StateDB) IntermediateRoot

func (s *StateDB) IntermediateRoot(cleanDirty bool) error

func (*StateDB) MarkGasAccountAsPending added in v0.0.5

func (s *StateDB) MarkGasAccountAsPending() error

MarkGasAccountAsPending will mark gas account as pending account. Putting gas account is pending account will unify many codes and remove some tricky logics.

func (*StateDB) PrepareAccountsAndAssets

func (s *StateDB) PrepareAccountsAndAssets(accountAssetsMap map[int64]map[int64]bool) error

func (*StateDB) PrepareNft

func (s *StateDB) PrepareNft(nftIndex int64) (*nft.L2Nft, error)

func (*StateDB) PurgeCache

func (s *StateDB) PurgeCache(stateRoot string)

func (*StateDB) SyncGasAccountToRedis added in v0.0.5

func (s *StateDB) SyncGasAccountToRedis() error

func (*StateDB) SyncStateCacheToRedis

func (s *StateDB) SyncStateCacheToRedis() error

Jump to

Keyboard shortcuts

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