Documentation ¶
Index ¶
- Constants
- Variables
- type Blockchain
- func (bc *Blockchain) AddBlock(block *block.Block) error
- func (bc *Blockchain) AddHeaders(headers ...*block.Header) error
- func (bc *Blockchain) ApplyPolicyToTxSet(txes []*transaction.Transaction) []*transaction.Transaction
- func (bc *Blockchain) BlockHeight() uint32
- func (bc *Blockchain) Close()
- func (bc *Blockchain) Contracts() *native.Contracts
- func (bc *Blockchain) CurrentBlockHash() common.Hash
- func (bc *Blockchain) CurrentHeaderHash() common.Hash
- func (bc *Blockchain) FeePerByte() uint64
- func (bc *Blockchain) GetBlock(hash common.Hash, full bool) (*block.Block, *types.Receipt, error)
- func (bc *Blockchain) GetConfig() config.ProtocolConfiguration
- func (bc *Blockchain) GetConsensusAddress() (common.Address, error)
- func (bc *Blockchain) GetContractState(hash common.Address) *state.Contract
- func (bc *Blockchain) GetCurrentValidators() ([]*keys.PublicKey, error)
- func (bc *Blockchain) GetFeePerByte() uint64
- func (bc *Blockchain) GetGasPrice() *big.Int
- func (bc *Blockchain) GetHeader(hash common.Hash) (*block.Header, error)
- func (bc *Blockchain) GetHeaderHash(i int) common.Hash
- func (bc *Blockchain) GetLogs(filter *filters.LogFilter) ([]*types.Log, error)
- func (bc *Blockchain) GetMemPool() *mempool.Pool
- func (bc *Blockchain) GetMinted(id int64) (common.Hash, error)
- func (bc *Blockchain) GetNativeContractScriptHash(name string) (common.Address, error)
- func (bc *Blockchain) GetNatives() []state.NativeContract
- func (bc *Blockchain) GetNonce(addr common.Address) uint64
- func (bc *Blockchain) GetPendingNonce(addr common.Address) uint64
- func (bc *Blockchain) GetStateModule() blockchainer.StateRoot
- func (bc *Blockchain) GetStorageItem(hash common.Address, key []byte) state.StorageItem
- func (bc *Blockchain) GetStorageItems(hash common.Address) ([]state.StorageItemWithKey, error)
- func (bc *Blockchain) GetTestVM(tx *transaction.Transaction, b *block.Block, tracer vm.EVMLogger) (*interop.Context, error)
- func (bc *Blockchain) GetTransaction(hash common.Hash) (*transaction.Transaction, *types.Receipt, error)
- func (bc *Blockchain) GetUtilityTokenBalance(acc common.Address) *big.Int
- func (bc *Blockchain) GetValidators(index uint32) ([]*keys.PublicKey, error)
- func (bc *Blockchain) HasBlock(hash common.Hash) bool
- func (bc *Blockchain) HasTransaction(hash common.Hash) bool
- func (bc *Blockchain) HeaderHeight() uint32
- func (bc *Blockchain) IsBlocked(address common.Address) bool
- func (bc *Blockchain) IsExtensibleAllowed(u common.Address) bool
- func (bc *Blockchain) IsTxStillRelevant(t *transaction.Transaction, txpool *mempool.Pool, isPartialTx bool) bool
- func (bc *Blockchain) LastBatch() *storage.MemBatch
- func (bc *Blockchain) ManagementContractAddress() common.Address
- func (bc *Blockchain) PolicyCheck(t *transaction.Transaction) error
- func (bc *Blockchain) PoolTx(t *transaction.Transaction, pools ...*mempool.Pool) error
- func (bc *Blockchain) PoolTxWithData(t *transaction.Transaction, data interface{}, mp *mempool.Pool, ...) error
- func (bc *Blockchain) RegisterPostBlock(...)
- func (bc *Blockchain) Run()
- func (bc *Blockchain) SubscribeForBlocks(ch chan<- *block.Block)
- func (bc *Blockchain) SubscribeForExecutions(ch chan<- *types.Receipt)
- func (bc *Blockchain) SubscribeForNotifications(ch chan<- *types.Log)
- func (bc *Blockchain) SubscribeForTransactions(ch chan<- *transaction.Transaction)
- func (bc *Blockchain) UnsubscribeFromBlocks(ch chan<- *block.Block)
- func (bc *Blockchain) UnsubscribeFromExecutions(ch chan<- *types.Receipt)
- func (bc *Blockchain) UnsubscribeFromNotifications(ch chan<- *types.Log)
- func (bc *Blockchain) UnsubscribeFromTransactions(ch chan<- *transaction.Transaction)
- func (bc *Blockchain) UtilityTokenAddress() common.Address
- func (bc *Blockchain) VerifyTx(t *transaction.Transaction) error
- func (bc *Blockchain) VerifyWitness(h common.Address, c hash.Hashable, w *transaction.Witness) error
Constants ¶
const ( // HeaderVerificationGasLimit is the maximum amount of GAS for block header verification. HeaderVerificationGasLimit = 3_00000000 // 3 GAS )
Tuning parameters.
Variables ¶
var ( // ErrAlreadyExists is returned when trying to add some already existing // transaction into the pool (not specifying whether it exists in the // chain or mempool). ErrAlreadyExists = errors.New("already exists") // ErrOOM is returned when adding transaction to the memory pool because // it reached its full capacity. ErrOOM = errors.New("no space left in the memory pool") // ErrPolicy is returned on attempt to add transaction that doesn't // comply with node's configured policy into the mempool. ErrPolicy = errors.New("not allowed by policy") // ErrInvalidBlockIndex is returned when trying to add block with index // other than expected height of the blockchain. ErrInvalidBlockIndex = errors.New("invalid block index") // ErrHasConflicts is returned when trying to add some transaction which // conflicts with other transaction in the chain or pool according to // Conflicts attribute. ErrHasConflicts = errors.New("has conflicts") )
var ( ErrHdrHashMismatch = errors.New("previous header hash doesn't match") ErrHdrIndexMismatch = errors.New("previous header index doesn't match") ErrHdrInvalidTimestamp = errors.New("block is not newer than the previous one") ErrHdrStateRootSetting = errors.New("state root setting mismatch") ErrHdrInvalidStateRoot = errors.New("state root for previous block is invalid") )
Various errors that could be returns upon header verification.
var ( ErrTxExpired = errors.New("transaction has expired") ErrInsufficientFunds = errors.New("insufficient funds") ErrTxSmallNetworkFee = errors.New("too small network fee") ErrTxTooBig = errors.New("too big transaction") ErrMemPoolConflict = errors.New("invalid transaction due to conflicts with the memory pool") ErrInvalidScript = errors.New("invalid script") ErrInvalidAttribute = errors.New("invalid attribute") )
Various errors that could be returned upon verification.
var ( ErrWitnessHashMismatch = errors.New("witness address mismatch") ErrVerificationFailed = errors.New("signature check failed") ErrInvalidInvocation = errors.New("invalid invocation script") ErrInvalidSignature = fmt.Errorf("%w: invalid signature", ErrVerificationFailed) ErrInvalidVerification = errors.New("invalid verification script") )
Various witness verification errors.
Functions ¶
This section is empty.
Types ¶
type Blockchain ¶
type Blockchain struct {
// contains filtered or unexported fields
}
Blockchain represents the blockchain. It maintans internal state representing the state of the ledger that can be accessed in various ways and changed by adding new blocks or headers.
func NewBlockchain ¶
func NewBlockchain(s storage.Store, cfg config.ProtocolConfiguration, log *zap.Logger) (*Blockchain, error)
NewBlockchain returns a new blockchain object the will use the given Store as its underlying storage. For it to work correctly you need to spawn a goroutine for its Run method after this initialization.
func (*Blockchain) AddBlock ¶
func (bc *Blockchain) AddBlock(block *block.Block) error
AddBlock accepts successive block for the Blockchain, verifies it and stores internally. Eventually it will be persisted to the backing storage.
func (*Blockchain) AddHeaders ¶
func (bc *Blockchain) AddHeaders(headers ...*block.Header) error
AddHeaders processes the given headers and add them to the HeaderHashList. It expects headers to be sorted by index.
func (*Blockchain) ApplyPolicyToTxSet ¶
func (bc *Blockchain) ApplyPolicyToTxSet(txes []*transaction.Transaction) []*transaction.Transaction
ApplyPolicyToTxSet applies configured policies to given transaction set. It expects slice to be ordered by fee and returns a subslice of it.
func (*Blockchain) BlockHeight ¶
func (bc *Blockchain) BlockHeight() uint32
BlockHeight returns the height/index of the highest block.
func (*Blockchain) Close ¶
func (bc *Blockchain) Close()
Close stops Blockchain's internal loop, syncs changes to persistent storage and closes it. The Blockchain is no longer functional after the call to Close.
func (*Blockchain) Contracts ¶
func (bc *Blockchain) Contracts() *native.Contracts
func (*Blockchain) CurrentBlockHash ¶
func (bc *Blockchain) CurrentBlockHash() common.Hash
CurrentBlockHash returns the highest processed block hash.
func (*Blockchain) CurrentHeaderHash ¶
func (bc *Blockchain) CurrentHeaderHash() common.Hash
CurrentHeaderHash returns the hash of the latest known header.
func (*Blockchain) FeePerByte ¶
func (bc *Blockchain) FeePerByte() uint64
FeePerByte returns transaction network fee per byte.
func (*Blockchain) GetConfig ¶
func (bc *Blockchain) GetConfig() config.ProtocolConfiguration
GetConfig returns the config stored in the blockchain.
func (*Blockchain) GetConsensusAddress ¶
func (bc *Blockchain) GetConsensusAddress() (common.Address, error)
func (*Blockchain) GetContractState ¶
func (bc *Blockchain) GetContractState(hash common.Address) *state.Contract
GetContractState returns contract by its script hash.
func (*Blockchain) GetCurrentValidators ¶
func (bc *Blockchain) GetCurrentValidators() ([]*keys.PublicKey, error)
func (*Blockchain) GetFeePerByte ¶
func (bc *Blockchain) GetFeePerByte() uint64
func (*Blockchain) GetGasPrice ¶
func (bc *Blockchain) GetGasPrice() *big.Int
func (*Blockchain) GetHeader ¶
GetHeader returns data block header identified with the given hash value.
func (*Blockchain) GetHeaderHash ¶
func (bc *Blockchain) GetHeaderHash(i int) common.Hash
GetHeaderHash returns hash of the header/block with specified index, if Blockchain doesn't have a hash for this height, zero Uint256 value is returned.
func (*Blockchain) GetMemPool ¶
func (bc *Blockchain) GetMemPool() *mempool.Pool
GetMemPool returns the memory pool of the blockchain.
func (*Blockchain) GetNativeContractScriptHash ¶
func (bc *Blockchain) GetNativeContractScriptHash(name string) (common.Address, error)
GetNativeContractScriptHash returns native contract script hash by its name.
func (*Blockchain) GetNatives ¶
func (bc *Blockchain) GetNatives() []state.NativeContract
GetNatives returns list of native contracts.
func (*Blockchain) GetPendingNonce ¶
func (bc *Blockchain) GetPendingNonce(addr common.Address) uint64
func (*Blockchain) GetStateModule ¶
func (bc *Blockchain) GetStateModule() blockchainer.StateRoot
GetStateModule returns state root service instance.
func (*Blockchain) GetStorageItem ¶
func (bc *Blockchain) GetStorageItem(hash common.Address, key []byte) state.StorageItem
GetStorageItem returns an item from storage.
func (*Blockchain) GetStorageItems ¶
func (bc *Blockchain) GetStorageItems(hash common.Address) ([]state.StorageItemWithKey, error)
GetStorageItems returns all storage items for a given contract id.
func (*Blockchain) GetTestVM ¶
func (bc *Blockchain) GetTestVM(tx *transaction.Transaction, b *block.Block, tracer vm.EVMLogger) (*interop.Context, error)
GetTestVM returns an interop context with VM set up for a test run.
func (*Blockchain) GetTransaction ¶
func (bc *Blockchain) GetTransaction(hash common.Hash) (*transaction.Transaction, *types.Receipt, error)
GetTransaction returns a TX and its height by the given hash. The height is MaxUint32 if tx is in the mempool.
func (*Blockchain) GetUtilityTokenBalance ¶
func (bc *Blockchain) GetUtilityTokenBalance(acc common.Address) *big.Int
GetUtilityTokenBalance returns utility token (GAS) balance for the acc.
func (*Blockchain) GetValidators ¶
func (bc *Blockchain) GetValidators(index uint32) ([]*keys.PublicKey, error)
GetValidators returns current validators.
func (*Blockchain) HasBlock ¶
func (bc *Blockchain) HasBlock(hash common.Hash) bool
HasBlock returns true if the blockchain contains the given block hash.
func (*Blockchain) HasTransaction ¶
func (bc *Blockchain) HasTransaction(hash common.Hash) bool
HasTransaction returns true if the blockchain contains he given transaction hash.
func (*Blockchain) HeaderHeight ¶
func (bc *Blockchain) HeaderHeight() uint32
HeaderHeight returns the index/height of the highest header.
func (*Blockchain) IsExtensibleAllowed ¶
func (bc *Blockchain) IsExtensibleAllowed(u common.Address) bool
IsExtensibleAllowed determines if script hash is allowed to send extensible payloads.
func (*Blockchain) IsTxStillRelevant ¶
func (bc *Blockchain) IsTxStillRelevant(t *transaction.Transaction, txpool *mempool.Pool, isPartialTx bool) bool
IsTxStillRelevant is a callback for mempool transaction filtering after the new block addition. It returns false for transactions added by the new block (passed via txpool) and does witness reverification for non-standard contracts. It operates under the assumption that full transaction verification was already done so we don't need to check basic things like size, input/output correctness, presence in blocks before the new one, etc.
func (*Blockchain) LastBatch ¶
func (bc *Blockchain) LastBatch() *storage.MemBatch
LastBatch returns last persisted storage batch.
func (*Blockchain) ManagementContractAddress ¶
func (bc *Blockchain) ManagementContractAddress() common.Address
ManagementContractHash returns management contract's hash.
func (*Blockchain) PolicyCheck ¶
func (bc *Blockchain) PolicyCheck(t *transaction.Transaction) error
func (*Blockchain) PoolTx ¶
func (bc *Blockchain) PoolTx(t *transaction.Transaction, pools ...*mempool.Pool) error
PoolTx verifies and tries to add given transaction into the mempool. If not given, the default mempool is used. Passing multiple pools is not supported.
func (*Blockchain) PoolTxWithData ¶
func (bc *Blockchain) PoolTxWithData(t *transaction.Transaction, data interface{}, mp *mempool.Pool, feer mempool.Feer, verificationFunction func(tx *transaction.Transaction, data interface{}) error) error
PoolTxWithData verifies and tries to add given transaction with additional data into the mempool.
func (*Blockchain) RegisterPostBlock ¶
func (bc *Blockchain) RegisterPostBlock(f func(func(*transaction.Transaction, *mempool.Pool, bool) bool, *mempool.Pool, *block.Block))
RegisterPostBlock appends provided function to the list of functions which should be run after new block is stored.
func (*Blockchain) Run ¶
func (bc *Blockchain) Run()
Run runs chain loop, it needs to be run as goroutine and executing it is critical for correct Blockchain operation.
func (*Blockchain) SubscribeForBlocks ¶
func (bc *Blockchain) SubscribeForBlocks(ch chan<- *block.Block)
SubscribeForBlocks adds given channel to new block event broadcasting, so when there is a new block added to the chain you'll receive it via this channel. Make sure it's read from regularly as not reading these events might affect other Blockchain functions.
func (*Blockchain) SubscribeForExecutions ¶
func (bc *Blockchain) SubscribeForExecutions(ch chan<- *types.Receipt)
SubscribeForExecutions adds given channel to new transaction execution event broadcasting, so when an in-block transaction execution happens you'll receive the result of it via this channel. Make sure it's read from regularly as not reading these events might affect other Blockchain functions.
func (*Blockchain) SubscribeForNotifications ¶
func (bc *Blockchain) SubscribeForNotifications(ch chan<- *types.Log)
SubscribeForNotifications adds given channel to new notifications event broadcasting, so when an in-block transaction execution generates a notification you'll receive it via this channel. Only notifications from successful transactions are broadcasted, if you're interested in failed transactions use SubscribeForExecutions instead. Make sure this channel is read from regularly as not reading these events might affect other Blockchain functions.
func (*Blockchain) SubscribeForTransactions ¶
func (bc *Blockchain) SubscribeForTransactions(ch chan<- *transaction.Transaction)
SubscribeForTransactions adds given channel to new transaction event broadcasting, so when there is a new transaction added to the chain (in a block) you'll receive it via this channel. Make sure it's read from regularly as not reading these events might affect other Blockchain functions.
func (*Blockchain) UnsubscribeFromBlocks ¶
func (bc *Blockchain) UnsubscribeFromBlocks(ch chan<- *block.Block)
UnsubscribeFromBlocks unsubscribes given channel from new block notifications, you can close it afterwards. Passing non-subscribed channel is a no-op.
func (*Blockchain) UnsubscribeFromExecutions ¶
func (bc *Blockchain) UnsubscribeFromExecutions(ch chan<- *types.Receipt)
UnsubscribeFromExecutions unsubscribes given channel from new execution notifications, you can close it afterwards. Passing non-subscribed channel is a no-op.
func (*Blockchain) UnsubscribeFromNotifications ¶
func (bc *Blockchain) UnsubscribeFromNotifications(ch chan<- *types.Log)
UnsubscribeFromNotifications unsubscribes given channel from new execution-generated notifications, you can close it afterwards. Passing non-subscribed channel is a no-op.
func (*Blockchain) UnsubscribeFromTransactions ¶
func (bc *Blockchain) UnsubscribeFromTransactions(ch chan<- *transaction.Transaction)
UnsubscribeFromTransactions unsubscribes given channel from new transaction notifications, you can close it afterwards. Passing non-subscribed channel is a no-op.
func (*Blockchain) UtilityTokenAddress ¶
func (bc *Blockchain) UtilityTokenAddress() common.Address
UtilityTokenHash returns the utility token (GAS) native contract hash.
func (*Blockchain) VerifyTx ¶
func (bc *Blockchain) VerifyTx(t *transaction.Transaction) error
VerifyTx verifies whether transaction is bonafide or not relative to the current blockchain state. Note that this verification is completely isolated from the main node's mempool.
func (*Blockchain) VerifyWitness ¶
func (bc *Blockchain) VerifyWitness(h common.Address, c hash.Hashable, w *transaction.Witness) error
VerifyWitness checks that w is a correct witness for c signed by h. It returns the amount of GAS consumed during verification and an error.
Directories ¶
Path | Synopsis |
---|---|
Package mpt implements MPT (Merkle-Patricia Tree).
|
Package mpt implements MPT (Merkle-Patricia Tree). |