Documentation
¶
Index ¶
Constants ¶
const ( // Default values. // Cache parameters. // 500 MiB. DefaultCacheSize = 500 * 1024 * 1024 // Bloom filter parameters. // Number of elements in Bloom Filter. DefaultBloomFilterSize = 2e8 // Acceptable false positive for Bloom Filter (0.01%). DefaultBloomFilterFalsePositiveProbability = 0.0001 // Db parameters. DefaultWriteBuffer = 32 * 1024 * 1024 DefaultCompactionTableSize = 8 * 1024 * 1024 DefaultCompactionTotalSize = 10 * 1024 * 1024 // Block storage parameters. // DefaultOffsetLen is the amount of bytes needed to store offset of transactions in blockchain file. DefaultOffsetLen = 8 // DefaultHeaderOffsetLen is the amount of bytes needed to store offset of headers in headers file. DefaultHeaderOffsetLen = 8 )
const (
FeeUnit = 100000
)
const (
KiB = 1024
)
const KnownPeerKeyLength = proto.IpPortLength + 1
Variables ¶
This section is empty.
Functions ¶
func IsNotFound ¶ added in v0.3.0
Types ¶
type ErrorType ¶ added in v0.3.0
type ErrorType byte
const ( // Unmarshal error of block or transaction. DeserializationError ErrorType = iota + 1 NotFoundError SerializationError TxValidationError ValidationError RollbackError // Errors occurring while getting data from database. RetrievalError // Errors occurring while updating/modifying state data. ModificationError InvalidInputError // DB or block storage Close() error. ClosureError // Minor technical errors which shouldn't ever happen. Other )
type State ¶
type State interface {
StateModifier
StateStable
StateNewest
IsNotFound(err error) bool
}
State represents overall Node's state.
func NewState ¶ added in v0.3.0
func NewState(dataDir string, params StateParams, settings *settings.BlockchainSettings) (State, error)
NewState() creates State. dataDir is path to directory to store all data, it's also possible to provide folder with existing data, and state will try to sync and use it in this case. params are state parameters (see below). settings are blockchain settings (settings.MainNetSettings, settings.TestNetSettings or custom settings).
type StateError ¶ added in v0.3.0
type StateError struct {
// contains filtered or unexported fields
}
func NewStateError ¶ added in v0.3.0
func NewStateError(errorType ErrorType, originalError error) StateError
func (StateError) Error ¶ added in v0.3.0
func (err StateError) Error() string
type StateModifier ¶ added in v0.3.0
type StateModifier interface {
// Global mutex of state.
Mutex() *lock.RwMutex
// AddBlock adds single block to state.
// It's not recommended to use this function when you are able to accumulate big blocks batch,
// since it's much more efficient to add many blocks at once.
AddBlock(block []byte) (*proto.Block, error)
AddDeserializedBlock(block *proto.Block) (*proto.Block, error)
// AddNewBlocks adds batch of new blocks to state.
// Use it when blocks are logically new.
AddNewBlocks(blocks [][]byte) error
// AddNewDeserializedBlocks marshals blocks to binary and calls AddNewBlocks().
AddNewDeserializedBlocks(blocks []*proto.Block) error
// AddOldBlocks adds batch of old blocks to state.
// Use it when importing historical blockchain.
// It is faster than AddNewBlocks but it is only safe when importing from scratch when no rollbacks are possible at all.
AddOldBlocks(blocks [][]byte) error
// AddOldDeserializedBlocks marshals blocks to binary and calls AddOldBlocks().
AddOldDeserializedBlocks(blocks []*proto.Block) error
// Rollback functionality.
RollbackToHeight(height proto.Height) error
RollbackTo(removalEdge crypto.Signature) error
// -------------------------
// Validation functionality (for UTX).
// -------------------------
// ValidateNextTx() validates transaction against state, taking into account all the previous changes from transactions
// that were added using ValidateNextTx() until you call ResetValidationList().
// Does not change state.
// Returns TxValidationError or nil.
ValidateNextTx(tx proto.Transaction, currentTimestamp, parentTimestamp uint64, blockVersion proto.BlockVersion) error
// ResetValidationList() resets the validation list, so you can ValidateNextTx() from scratch after calling it.
ResetValidationList()
// Create or replace Peers.
SavePeers([]proto.TCPAddr) error
Close() error
}
StateModifier contains all the methods needed to modify node's state.
type StateNewest ¶ added in v0.3.0
type StateNewest interface {
AddingBlockHeight() (proto.Height, error)
NewestHeight() (proto.Height, error)
// Effective balance by account in given height range.
// WARNING: this function takes into account newest blocks (which are currently being added)
// and works correctly for height ranges exceeding current Height() if there are such blocks.
// It does not work for heights older than rollbackMax blocks before the current block.
EffectiveBalance(account proto.Recipient, startHeight, endHeight proto.Height) (uint64, error)
NewestAccountBalance(account proto.Recipient, asset []byte) (uint64, error)
// Aliases.
NewestAddrByAlias(alias proto.Alias) (proto.Address, error)
// Accounts data storage.
RetrieveNewestEntry(account proto.Recipient, key string) (proto.DataEntry, error)
RetrieveNewestIntegerEntry(account proto.Recipient, key string) (*proto.IntegerDataEntry, error)
RetrieveNewestBooleanEntry(account proto.Recipient, key string) (*proto.BooleanDataEntry, error)
RetrieveNewestStringEntry(account proto.Recipient, key string) (*proto.StringDataEntry, error)
RetrieveNewestBinaryEntry(account proto.Recipient, key string) (*proto.BinaryDataEntry, error)
// Transactions.
NewestTransactionByID(id []byte) (proto.Transaction, error)
NewestTransactionHeightByID(id []byte) (uint64, error)
// Asset fee sponsorship.
NewestAssetIsSponsored(assetID crypto.Digest) (bool, error)
NewestAssetInfo(assetID crypto.Digest) (*proto.AssetInfo, error)
NewestHeaderByHeight(height proto.Height) (*proto.BlockHeader, error)
}
StateNewest returns information that takes into account any intermediate changes occurring during applying block. This state corresponds to the latest validated transaction, and for now is only needed for Ride and Consensus modules, which are both called during the validation.
type StateParams ¶ added in v0.3.0
type StateParams struct {
StorageParams
ValidationParams
}
func DefaultStateParams ¶ added in v0.3.0
func DefaultStateParams() StateParams
func DefaultTestingStateParams ¶ added in v0.3.0
func DefaultTestingStateParams() StateParams
type StateStable ¶ added in v0.3.0
type StateStable interface {
// Block getters.
Block(blockID crypto.Signature) (*proto.Block, error)
BlockByHeight(height proto.Height) (*proto.Block, error)
BlockBytes(blockID crypto.Signature) ([]byte, error)
BlockBytesByHeight(height proto.Height) ([]byte, error)
// Header getters.
Header(blockID crypto.Signature) (*proto.BlockHeader, error)
HeaderByHeight(height proto.Height) (*proto.BlockHeader, error)
HeaderBytes(blockID crypto.Signature) ([]byte, error)
HeaderBytesByHeight(height proto.Height) ([]byte, error)
// Height returns current blockchain height.
Height() (proto.Height, error)
// Height <---> blockID converters.
BlockIDToHeight(blockID crypto.Signature) (proto.Height, error)
HeightToBlockID(height proto.Height) (crypto.Signature, error)
// AccountBalance retrieves balance of account in specific currency, asset is asset's ID.
// nil asset = Waves.
AccountBalance(account proto.Recipient, asset []byte) (uint64, error)
// WavesAddressesNumber returns total number of Waves addresses in state.
// It is extremely slow, so it is recommended to only use for testing purposes.
WavesAddressesNumber() (uint64, error)
// Get cumulative blocks score at given height.
ScoreAtHeight(height proto.Height) (*big.Int, error)
// Get current blockchain score (at top height).
CurrentScore() (*big.Int, error)
// Retrieve current blockchain settings.
BlockchainSettings() (*settings.BlockchainSettings, error)
Peers() ([]proto.TCPAddr, error)
// Features.
IsActivated(featureID int16) (bool, error)
ActivationHeight(featureID int16) (proto.Height, error)
IsApproved(featureID int16) (bool, error)
ApprovalHeight(featureID int16) (proto.Height, error)
// Aliases.
AddrByAlias(alias proto.Alias) (proto.Address, error)
// Accounts data storage.
RetrieveEntry(account proto.Recipient, key string) (proto.DataEntry, error)
RetrieveIntegerEntry(account proto.Recipient, key string) (*proto.IntegerDataEntry, error)
RetrieveBooleanEntry(account proto.Recipient, key string) (*proto.BooleanDataEntry, error)
RetrieveStringEntry(account proto.Recipient, key string) (*proto.StringDataEntry, error)
RetrieveBinaryEntry(account proto.Recipient, key string) (*proto.BinaryDataEntry, error)
// Transactions.
TransactionByID(id []byte) (proto.Transaction, error)
TransactionHeightByID(id []byte) (uint64, error)
// Asset fee sponsorship.
AssetIsSponsored(assetID crypto.Digest) (bool, error)
AssetInfo(assetID crypto.Digest) (*proto.AssetInfo, error)
}
StateStable returns information that corresponds to latest fully applied block. This should be used for APIs and other modules where stable, fully verified state is needed.
type StorageParams ¶ added in v0.3.0
type StorageParams struct {
OffsetLen int
HeaderOffsetLen int
DbParams keyvalue.KeyValParams
}
func DefaultStorageParams ¶ added in v0.3.0
func DefaultStorageParams() StorageParams
func DefaultTestingStorageParams ¶ added in v0.3.0
func DefaultTestingStorageParams() StorageParams
type ValidationParams ¶ added in v0.3.0
type ValidationParams struct {
VerificationGoroutinesNum int
}
ValidationParams are validation parameters. VerificationGoroutinesNum specifies how many goroutines will be run for verification of transactions and blocks signatures.
Source Files
¶
- accounts_data_storage.go
- aliases.go
- api.go
- assets.go
- balances.go
- block_differ.go
- blockreadwriter.go
- blocksinfo.go
- constants.go
- database.go
- diff_applier.go
- diff_storage.go
- errors.go
- features.go
- fee_validation.go
- history_formatter.go
- history_storage.go
- invoke_applier.go
- keys.go
- known_peer.go
- leases.go
- local_history_storage.go
- monetary_policy.go
- orders_volume.go
- peer_storage.go
- score.go
- script_caller.go
- scripts_cache.go
- scripts_complexity.go
- scripts_storage.go
- sponsored_assets.go
- state.go
- transaction_checker.go
- transaction_differ.go
- transaction_fee_counter.go
- transaction_handler.go
- transaction_performer.go
- verifier.go