chain

package
v0.5.1-rc3 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: MIT Imports: 36 Imported by: 0

README

Chain Validator Design

Chain validators are organized by transaction type. The executor handles mundane tasks that are common to all chain validators, such as authentication and authorization.

In general, every transaction requires an origin record. Thus, the executor validates and loads the origin before delegating to the chain validator. However, certain transaction types, specifically synthetic transactions that create records, may not need an extant origin. The executor has a specific clause for these special cases.

Chain Validator Implementation

Chain validators must satisfy the TxExecutor interface:

type TxExecutor interface {
	Type() types.TxType
	Validate(*StateManager, *transactions.Envelope) error
}

All state manipulation (mutating and loading) must go through the state manager. There are three methods that can be used to modify records and/or create synthetic transactions:

  • Implementing a user transaction executor
    • Update(record) - Update one or more existing records. Cannot be used to create records.
    • Create(record) - Create one or more new records. Produces a synthetic chain create transaction.
    • Submit(url, body) - Submit a synthetic transaction.
  • Implementing a synthetic transaction executor
    • Update(record) - Create or update one or more existing records.
    • Create(record) - Cannot be used by synthetic transactions.
    • Submit(url, body) - Cannot be used by synthetic transactions.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddDirectoryEntry

func AddDirectoryEntry(getIndex func(*url.URL, ...interface{}) Value, u ...*url.URL) error

Types

type AcmeFaucet

type AcmeFaucet struct{}

func (AcmeFaucet) Type

func (AcmeFaucet) Type() types.TxType

func (AcmeFaucet) Validate

type AddCredits

type AddCredits struct{}

func (AddCredits) Type

func (AddCredits) Type() types.TxType

func (AddCredits) Validate

type BurnTokens

type BurnTokens struct{}

func (BurnTokens) Type

func (BurnTokens) Type() types.TxType

func (BurnTokens) Validate

type CreateDataAccount

type CreateDataAccount struct{}

func (CreateDataAccount) Type

func (CreateDataAccount) Validate

type CreateIdentity

type CreateIdentity struct{}

func (CreateIdentity) Type

func (CreateIdentity) Type() types.TxType

func (CreateIdentity) Validate

type CreateKeyBook

type CreateKeyBook struct{}

func (CreateKeyBook) Type

func (CreateKeyBook) Type() types.TxType

func (CreateKeyBook) Validate

type CreateKeyPage

type CreateKeyPage struct{}

func (CreateKeyPage) Type

func (CreateKeyPage) Type() types.TxType

func (CreateKeyPage) Validate

type CreateToken

type CreateToken struct{}

func (CreateToken) Type

func (CreateToken) Type() types.TxType

func (CreateToken) Validate

type CreateTokenAccount

type CreateTokenAccount struct{}

func (CreateTokenAccount) Type

func (CreateTokenAccount) Validate

type Executor

type Executor struct {
	ExecutorOptions
	// contains filtered or unexported fields
}

func NewGenesisExecutor

func NewGenesisExecutor(db *database.Database, logger log.Logger, network config.Network) (*Executor, error)

NewGenesisExecutor creates a transaction executor that can be used to set up the genesis state.

func NewNodeExecutor

func NewNodeExecutor(opts ExecutorOptions) (*Executor, error)

NewNodeExecutor creates a new Executor for a node.

func (*Executor) BeginBlock

func (m *Executor) BeginBlock(req abci.BeginBlockRequest) (resp abci.BeginBlockResponse, err error)

BeginBlock implements ./abci.Chain

func (*Executor) CheckTx

CheckTx implements ./abci.Chain

func (*Executor) Commit

func (m *Executor) Commit() ([]byte, error)

Commit implements ./abci.Chain

func (*Executor) DeliverTx

DeliverTx implements ./abci.Chain

func (*Executor) EndBlock

EndBlock implements ./abci.Chain

func (*Executor) Genesis

func (m *Executor) Genesis(time time.Time, callback func(st *StateManager) error) ([]byte, error)

func (*Executor) InitChain

func (m *Executor) InitChain(data []byte, time time.Time, blockIndex int64) ([]byte, error)

func (*Executor) Query

func (m *Executor) Query(q *query.Query, _ int64, prove bool) (k, v []byte, err *protocol.Error)

func (*Executor) Start

func (m *Executor) Start() error

func (*Executor) Stop

func (m *Executor) Stop() error

type ExecutorOptions

type ExecutorOptions struct {
	DB      *database.Database
	Logger  log.Logger
	Key     ed25519.PrivateKey
	Router  routing.Router
	Network config.Network
	// contains filtered or unexported fields
}

type InternalSendTransactions

type InternalSendTransactions struct{}

func (InternalSendTransactions) Type

func (InternalSendTransactions) Validate

type InternalTransactionsSent

type InternalTransactionsSent struct{}

func (InternalTransactionsSent) Type

func (InternalTransactionsSent) Validate

type InternalTransactionsSigned

type InternalTransactionsSigned struct{}

func (InternalTransactionsSigned) Type

func (InternalTransactionsSigned) Validate

type IssueTokens

type IssueTokens struct{}

func (IssueTokens) Type

func (IssueTokens) Type() types.TxType

func (IssueTokens) Validate

type RemoveManager

type RemoveManager struct{}

func (RemoveManager) Type

func (RemoveManager) Validate

type SendTokens

type SendTokens struct{}

func (SendTokens) Type

func (SendTokens) Type() types.TxType

func (SendTokens) Validate

type StateManager

type StateManager struct {
	Origin        state.Chain
	OriginUrl     *url.URL
	OriginChainId [32]byte

	Signator    creditChain
	SignatorUrl *url.URL
	// contains filtered or unexported fields
}

func NewStateManager

func NewStateManager(batch *database.Batch, nodeUrl *url.URL, env *transactions.Envelope) (*StateManager, error)

NewStateManager creates a new state manager and loads the transaction's origin. If the origin is not found, NewStateManager returns a valid state manager along with a not-found error.

func (*StateManager) AddChainEntry

func (m *StateManager) AddChainEntry(u *url.URL, name string, typ protocol.ChainType, entry []byte, sourceIndex, sourceBlock uint64) error

func (*StateManager) AddDirectoryAnchor

func (m *StateManager) AddDirectoryAnchor(anchor *protocol.SyntheticAnchor)

func (*StateManager) AddDirectoryEntry

func (c *StateManager) AddDirectoryEntry(u ...*url.URL) error

func (*StateManager) AddSyntheticTxns

func (m *StateManager) AddSyntheticTxns(txid []byte, synth [][32]byte)

func (*StateManager) AddValidator

func (m *StateManager) AddValidator(pubKey ed25519.PubKey)

func (*StateManager) Commit

func (m *StateManager) Commit() ([]*submission, error)

commit writes pending records to the database.

func (*StateManager) Create

func (m *StateManager) Create(record ...state.Chain)

Create queues a record for a synthetic chain create transaction. Will panic if called by a synthetic transaction. Will panic if the record is a transaction.

func (*StateManager) DisableValidator added in v0.5.1

func (m *StateManager) DisableValidator(pubKey ed25519.PubKey)

func (*StateManager) GetHeight

func (c *StateManager) GetHeight(u *url.URL) (uint64, error)

GetHeight loads the height of the chain

func (*StateManager) LoadTxn

func (c *StateManager) LoadTxn(txid [32]byte) (*state.Transaction, *protocol.TransactionStatus, []protocol.Signature, error)

LoadTxn loads and unmarshals a saved transaction

func (*StateManager) LoadUrl

func (c *StateManager) LoadUrl(u *url.URL) (state.Chain, error)

LoadUrl loads a chain by URL and unmarshals it.

func (*StateManager) LoadUrlAs

func (c *StateManager) LoadUrlAs(u *url.URL, v interface{}) error

LoadUrlAs loads a chain by URL and unmarshals it as a specific type.

func (*StateManager) ReadChain

func (c *StateManager) ReadChain(u *url.URL, name string) (*database.Chain, error)

ReadChain loads an account's chain by URL and name.

func (*StateManager) RecordIndex

func (c *StateManager) RecordIndex(u *url.URL, key ...interface{}) *writeIndex

func (*StateManager) Reset

func (m *StateManager) Reset()

func (*StateManager) SignTransaction

func (m *StateManager) SignTransaction(txid []byte, signature protocol.Signature)

func (*StateManager) Submit

func (m *StateManager) Submit(url *url.URL, body protocol.TransactionPayload)

Submit queues a synthetic transaction for submission.

func (*StateManager) TxnExists

func (c *StateManager) TxnExists(txid []byte) bool

TxnExists checks if the transaction already exists

func (*StateManager) TxnIndex

func (c *StateManager) TxnIndex(id []byte, key ...interface{}) *writeIndex

func (*StateManager) Update

func (m *StateManager) Update(record ...state.Chain)

Update queues a record for storage in the database. The queued update will fail if the record does not already exist, unless it is created by a synthetic transaction, or the record is a transaction.

func (*StateManager) UpdateData

func (m *StateManager) UpdateData(record state.Chain, entryHash []byte, dataEntry *protocol.DataEntry)

UpdateData will cache a data associated with a DataAccount chain. the cache data will not be stored directly in the state but can be used upstream for storing a chain in the state database.

func (*StateManager) UpdateSignator

func (m *StateManager) UpdateSignator(record state.Chain) error

type SyntheticAnchor

type SyntheticAnchor struct {
	Network *config.Network
}

func (SyntheticAnchor) Type

func (SyntheticAnchor) Validate

type SyntheticBurnTokens

type SyntheticBurnTokens struct{}

func (SyntheticBurnTokens) Type

func (SyntheticBurnTokens) Validate

type SyntheticCreateChain

type SyntheticCreateChain struct{}

func (SyntheticCreateChain) Type

func (SyntheticCreateChain) Validate

type SyntheticDepositCredits

type SyntheticDepositCredits struct{}

func (SyntheticDepositCredits) Type

func (SyntheticDepositCredits) Validate

type SyntheticDepositTokens

type SyntheticDepositTokens struct{}

func (SyntheticDepositTokens) Type

func (SyntheticDepositTokens) Validate

type SyntheticMirror

type SyntheticMirror struct{}

func (SyntheticMirror) Type

func (SyntheticMirror) Type() types.TxType

func (SyntheticMirror) Validate

type SyntheticWriteData

type SyntheticWriteData struct{}

func (SyntheticWriteData) Type

func (SyntheticWriteData) Validate

type TxExecutor

type TxExecutor interface {
	// Type is the transaction type the executor can execute.
	Type() types.TransactionType

	// Validate fully validates and executes the transaction.
	Validate(*StateManager, *transactions.Envelope) (protocol.TransactionResult, error)
}

TxExecutor executes a specific type of transaction.

type UpdateKeyPage

type UpdateKeyPage struct{}

func (UpdateKeyPage) Type

func (UpdateKeyPage) Type() types.TxType

func (UpdateKeyPage) Validate

type UpdateManager

type UpdateManager struct{}

func (UpdateManager) Type

func (UpdateManager) Validate

type Value

type Value interface {
	Get() ([]byte, error)
	Put([]byte)
}

type WriteData

type WriteData struct{}

func (WriteData) Type

func (WriteData) Validate

type WriteDataTo

type WriteDataTo struct{}

func (WriteDataTo) Type

func (WriteDataTo) Validate

Jump to

Keyboard shortcuts

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