state

package
v0.0.0-...-ff6bfbe Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2019 License: Apache-2.0 Imports: 7 Imported by: 2

Documentation

Overview

Package state is a generated protocol buffer package.

It is generated from these files:

rawsnapshot.proto

It has these top-level messages:

RawSnapshot

Package state defines Snapshot, a data structure for holding a blockchain's state.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnfinalized means a transaction with no finalize instruction is being applied to a snapshot.
	ErrUnfinalized = errors.New("unfinalized transaction")

	// ErrEmptyState means ApplyTx was called on an uninitialized blockchain state.
	ErrEmptyState = errors.New("empty state")

	// ErrConflictingNonce means ApplyTx encountered a transaction with a nonce already in the blockchain state.
	ErrConflictingNonce = errors.New("conflicting nonce")

	// ErrNonceReference means a nonce referenced a non-recent, non-initial block ID.
	ErrNonceReference = errors.New("nonce must refer to the initial block, a recent block, or have a zero block ID")

	// ErrPrevout means a transaction tried to input a contract with an unknown ID.
	ErrPrevout = errors.New("invalid prevout")
)

Functions

This section is empty.

Types

type RawSnapshot

type RawSnapshot struct {
	// ContractNodes contains every leaf node within the contracts tree.
	// The nodes are ordered according to a pre-order traversal.
	ContractNodes  [][]byte        `protobuf:"bytes,1,rep,name=contract_nodes,json=contractNodes,proto3" json:"contract_nodes,omitempty"`
	NonceNodes     [][]byte        `protobuf:"bytes,2,rep,name=nonce_nodes,json=nonceNodes,proto3" json:"nonce_nodes,omitempty"`
	Header         *bc.BlockHeader `protobuf:"bytes,3,opt,name=header" json:"header,omitempty"`
	InitialBlockId *bc.Hash        `protobuf:"bytes,4,opt,name=initial_block_id,json=initialBlockId" json:"initial_block_id,omitempty"`
	RefIds         []*bc.Hash      `protobuf:"bytes,5,rep,name=ref_ids,json=refIds" json:"ref_ids,omitempty"`
}

Snapshot represents a snapshot of the blockchain, including the contracts tree and issuance memory.

func (*RawSnapshot) Descriptor

func (*RawSnapshot) Descriptor() ([]byte, []int)

func (*RawSnapshot) GetContractNodes

func (m *RawSnapshot) GetContractNodes() [][]byte

func (*RawSnapshot) GetHeader

func (m *RawSnapshot) GetHeader() *bc.BlockHeader

func (*RawSnapshot) GetInitialBlockId

func (m *RawSnapshot) GetInitialBlockId() *bc.Hash

func (*RawSnapshot) GetNonceNodes

func (m *RawSnapshot) GetNonceNodes() [][]byte

func (*RawSnapshot) GetRefIds

func (m *RawSnapshot) GetRefIds() []*bc.Hash

func (*RawSnapshot) ProtoMessage

func (*RawSnapshot) ProtoMessage()

func (*RawSnapshot) Reset

func (m *RawSnapshot) Reset()

func (*RawSnapshot) String

func (m *RawSnapshot) String() string

type Snapshot

type Snapshot struct {
	ContractsTree *patricia.Tree
	NonceTree     *patricia.Tree

	Header         *bc.BlockHeader
	InitialBlockID bc.Hash
	RefIDs         []bc.Hash
}

Snapshot contains a blockchain's state.

TODO: consider making type Snapshot truly immutable. We already handle it that way in many places (with explicit calls to Copy to get the right behavior). PruneNonces and the Apply functions would have to produce new Snapshots rather than updating Snapshots in place.

func Copy

func Copy(original *Snapshot) *Snapshot

Copy makes a copy of provided snapshot. Copying a snapshot is an O(n) operation where n is the number of nonces in the snapshot's nonce set.

func Empty

func Empty() *Snapshot

Empty returns an empty state snapshot.

func (*Snapshot) ApplyBlock

func (s *Snapshot) ApplyBlock(block *bc.UnsignedBlock) error

ApplyBlock updates s in place. It runs in three phases: PruneNonces, ApplyBlockHeader, and ApplyTx (the latter called in a loop for each transaction). Callers are free to invoke those phases separately.

func (*Snapshot) ApplyBlockHeader

func (s *Snapshot) ApplyBlockHeader(bh *bc.BlockHeader) error

ApplyBlockHeader is the header-specific phase of applying a block to the blockchain state. (See ApplyBlock.)

func (*Snapshot) ApplyTx

func (s *Snapshot) ApplyTx(p *bc.CommitmentsTx) error

ApplyTx updates s in place.

func (*Snapshot) Bytes

func (s *Snapshot) Bytes() ([]byte, error)

func (*Snapshot) FromBytes

func (s *Snapshot) FromBytes(b []byte) error

func (*Snapshot) Height

func (s *Snapshot) Height() uint64

Height returns the height from the stored latest header.

func (*Snapshot) PruneNonces

func (s *Snapshot) PruneNonces(timestampMS uint64)

PruneNonces modifies a Snapshot, removing all nonce IDs with expiration times earlier than the provided timestamp.

func (*Snapshot) TimestampMS

func (s *Snapshot) TimestampMS() uint64

TimestampMS returns the timestamp from the stored latest header.

Jump to

Keyboard shortcuts

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