chain

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2023 License: BSD-3-Clause Imports: 26 Imported by: 127

Documentation

Overview

Package chain is a generated GoMock package.

Package chain is a generated GoMock package.

Package chain is a generated GoMock package.

Package chain is a generated GoMock package.

Index

Constants

View Source
const (
	FutureBound = 10 * time.Second
)
View Source
const (
	// AvalancheGo imposes a limit of 2 MiB on the network, so we limit at
	// 2 MiB - ProposerVM header - Protobuf encoding overhead (we assume this is
	// no more than 50 KiB of overhead but is likely much less)
	NetworkSizeLimit = 2_044_723 // 1.95 MiB
)

Variables

View Source
var (
	// Parsing
	ErrInvalidObject = errors.New("invalid object")

	// Genesis Correctness
	ErrInvalidChainID   = errors.New("invalid chain ID")
	ErrInvalidBlockRate = errors.New("invalid block rate")

	// Block Correctness
	ErrTimestampTooEarly    = errors.New("timestamp too early")
	ErrTimestampTooLate     = errors.New("timestamp too late")
	ErrStateRootEmpty       = errors.New("state root empty")
	ErrNoTxs                = errors.New("no transactions")
	ErrInvalidUnitPrice     = errors.New("invalid unit price")
	ErrInvalidUnitWindow    = errors.New("invalid unit window")
	ErrInvalidBlockCost     = errors.New("invalid block cost")
	ErrInvalidBlockWindow   = errors.New("invalid block window")
	ErrInvalidUnitsConsumed = errors.New("invalid units consumed")
	ErrInsufficientSurplus  = errors.New("insufficient surplus fee")
	ErrInvalidSurplus       = errors.New("invalid surplus fee")
	ErrStateRootMismatch    = errors.New("state root mismatch")
	ErrInvalidResult        = errors.New("invalid result")

	// Tx Correctness
	ErrInvalidSignature     = errors.New("invalid signature")
	ErrDuplicateTx          = errors.New("duplicate transaction")
	ErrInsufficientPrice    = errors.New("insufficient price")
	ErrInvalidType          = errors.New("invalid tx type")
	ErrInvalidID            = errors.New("invalid content ID")
	ErrInvalidSchema        = errors.New("invalid schema")
	ErrInvalidContent       = errors.New("invalid content")
	ErrContentAlreadyExists = errors.New("content already exists")
	ErrContentMissing       = errors.New("content does not exist")
	ErrWrongOwner           = errors.New("wrong owner")
	ErrInsufficientTip      = errors.New("insufficient tip")
	ErrAccountNotEmpty      = errors.New("account not empty")
	ErrServicerMissing      = errors.New("servicer missing")
	ErrTooManyTxs           = errors.New("too many transactions")
	ErrActionNotActivated   = errors.New("action not activated")
	ErrAuthNotActivated     = errors.New("auth not activated")
	ErrAuthFailed           = errors.New("auth failed")

	// Execution Correctness
	ErrInvalidBalance  = errors.New("invalid balance")
	ErrBlockTooBig     = errors.New("block too big")
	ErrKeyNotSpecified = errors.New("key not specified")

	// Misc
	ErrNotImplemented    = errors.New("not implemented")
	ErrBlockNotProcessed = errors.New("block is not processed")
)

Functions

func BuildBlock

func BuildBlock(ctx context.Context, vm VM, preferred ids.ID) (snowman.Block, error)

func HandlePreExecute

func HandlePreExecute(
	err error,
) (bool, bool, bool)

func MarshalResults

func MarshalResults(src []*Result) ([]byte, error)

func MarshalTxs

func MarshalTxs(
	txs []*Transaction,
	actionRegistry ActionRegistry,
	authRegistry AuthRegistry,
) ([]byte, error)

Types

type Action

type Action interface {
	MaxUnits(Rules) uint64                     // max units that could be charged via execute
	ValidRange(Rules) (start int64, end int64) // -1 means no start/end

	// Auth may contain an [Actor] that performs a transaction
	//
	// if attempt to reference missing key, error...it is ok to not use all keys (conditional logic based on state)
	StateKeys(Auth) [][]byte

	// Key distinction with "Auth" is the payment of fees. All non-fee payments
	// occur in Execute but Auth handles fees.
	//
	// The weird part of this is that they both need a shared understanding of
	// balance tracking. Is it weird Auth then needs an understanding of storage
	// structure? Not sure there is an easier way.
	//
	// It is also odd because we may pull some aspect of the transaction from
	// auth (like where to pull balance from on a transfer).
	Execute(
		ctx context.Context,
		r Rules,
		db Database,
		timestamp int64,
		auth Auth,
		txID ids.ID,
	) (result *Result, err error) // err should only be returned if fatal

	Marshal(p *codec.Packer)
}

type ActionRegistry

type ActionRegistry *codec.TypeParser[Action]

type Auth

type Auth interface {
	MaxUnits(Rules) uint64
	ValidRange(Rules) (start int64, end int64) // -1 means no start/end

	StateKeys() [][]byte

	// will be run concurrently, optimistically start crypto ops (may not complete before [Verify])
	AsyncVerify(msg []byte) error

	// Is Auth able to execute [Action], assuming [AsyncVerify] passes?
	Verify(
		ctx context.Context,
		r Rules,
		db Database,
		action Action,
	) (units uint64, err error) // if there is account abstraction, may need to pull from state some mapping

	// TODO: identifier->may be used to send to in action as well?
	Payer() []byte // need to track mempool + charge fees -> used to clear related accounts if balance check fails
	CanDeduct(ctx context.Context, db Database, amount uint64) error
	Deduct(ctx context.Context, db Database, amount uint64) error
	Refund(ctx context.Context, db Database, amount uint64) error // only invoked if amount > 0

	Marshal(p *codec.Packer)
}

type AuthFactory

type AuthFactory interface {
	// used by helpers, auth object should store internally to be ready for marshaling
	Sign(msg []byte, action Action) (Auth, error)
}

type AuthRegistry

type AuthRegistry *codec.TypeParser[Auth]

type Base

type Base struct {
	// Timestamp is the expiry of the transaction. Once this time passes and the
	// transaction is not included in a block, it is safe to regenerate it.
	Timestamp int64 `json:"nonce"`

	// ChainID protects against replay attacks on different VM instances.
	ChainID ids.ID `json:"chainId"`

	// Unit price is the value per unit to spend on this transaction.
	UnitPrice uint64 `json:"unitPrice"`
}

func UnmarshalBase

func UnmarshalBase(p *codec.Packer) (*Base, error)

func (*Base) Execute

func (b *Base) Execute(r Rules, timestamp int64) error

func (*Base) Marshal

func (b *Base) Marshal(p *codec.Packer)

type Database

type Database interface {
	GetValue(ctx context.Context, key []byte) ([]byte, error)
	Insert(ctx context.Context, key []byte, value []byte) error
	Remove(ctx context.Context, key []byte) error
}

type ExecutionContext

type ExecutionContext struct {
	NextUnitPrice  uint64
	NextUnitWindow window.Window

	NextBlockCost   uint64
	NextBlockWindow window.Window
}

func GenerateExecutionContext

func GenerateExecutionContext(
	ctx context.Context,
	currTime int64,
	parent *StatelessBlock,
	tracer trace.Tracer,
	r Rules,
) (*ExecutionContext, error)

type Mempool

type Mempool interface {
	Len(context.Context) int
	Add(context.Context, []*Transaction)
	Build(
		context.Context,
		func(context.Context, *Transaction) (bool, bool, bool, error),
	) error
}

type MockAction

type MockAction struct {
	// contains filtered or unexported fields
}

MockAction is a mock of Action interface.

func NewMockAction

func NewMockAction(ctrl *gomock.Controller) *MockAction

NewMockAction creates a new mock instance.

func (*MockAction) EXPECT

func (m *MockAction) EXPECT() *MockActionMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockAction) Execute

func (m *MockAction) Execute(arg0 context.Context, arg1 Rules, arg2 Database, arg3 int64, arg4 Auth, arg5 ids.ID) (*Result, error)

Execute mocks base method.

func (*MockAction) Marshal

func (m *MockAction) Marshal(arg0 *codec.Packer)

Marshal mocks base method.

func (*MockAction) MaxUnits

func (m *MockAction) MaxUnits(arg0 Rules) uint64

MaxUnits mocks base method.

func (*MockAction) StateKeys

func (m *MockAction) StateKeys(arg0 Auth) [][]byte

StateKeys mocks base method.

func (*MockAction) ValidRange

func (m *MockAction) ValidRange(arg0 Rules) (int64, int64)

ValidRange mocks base method.

type MockActionMockRecorder

type MockActionMockRecorder struct {
	// contains filtered or unexported fields
}

MockActionMockRecorder is the mock recorder for MockAction.

func (*MockActionMockRecorder) Execute

func (mr *MockActionMockRecorder) Execute(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call

Execute indicates an expected call of Execute.

func (*MockActionMockRecorder) Marshal

func (mr *MockActionMockRecorder) Marshal(arg0 interface{}) *gomock.Call

Marshal indicates an expected call of Marshal.

func (*MockActionMockRecorder) MaxUnits

func (mr *MockActionMockRecorder) MaxUnits(arg0 interface{}) *gomock.Call

MaxUnits indicates an expected call of MaxUnits.

func (*MockActionMockRecorder) StateKeys

func (mr *MockActionMockRecorder) StateKeys(arg0 interface{}) *gomock.Call

StateKeys indicates an expected call of StateKeys.

func (*MockActionMockRecorder) ValidRange

func (mr *MockActionMockRecorder) ValidRange(arg0 interface{}) *gomock.Call

ValidRange indicates an expected call of ValidRange.

type MockAuth

type MockAuth struct {
	// contains filtered or unexported fields
}

MockAuth is a mock of Auth interface.

func NewMockAuth

func NewMockAuth(ctrl *gomock.Controller) *MockAuth

NewMockAuth creates a new mock instance.

func (*MockAuth) AsyncVerify

func (m *MockAuth) AsyncVerify(arg0 []byte) error

AsyncVerify mocks base method.

func (*MockAuth) CanDeduct

func (m *MockAuth) CanDeduct(arg0 context.Context, arg1 Database, arg2 uint64) error

CanDeduct mocks base method.

func (*MockAuth) Deduct

func (m *MockAuth) Deduct(arg0 context.Context, arg1 Database, arg2 uint64) error

Deduct mocks base method.

func (*MockAuth) EXPECT

func (m *MockAuth) EXPECT() *MockAuthMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockAuth) Marshal

func (m *MockAuth) Marshal(arg0 *codec.Packer)

Marshal mocks base method.

func (*MockAuth) MaxUnits

func (m *MockAuth) MaxUnits(arg0 Rules) uint64

MaxUnits mocks base method.

func (*MockAuth) Payer

func (m *MockAuth) Payer() []byte

Payer mocks base method.

func (*MockAuth) Refund

func (m *MockAuth) Refund(arg0 context.Context, arg1 Database, arg2 uint64) error

Refund mocks base method.

func (*MockAuth) StateKeys

func (m *MockAuth) StateKeys() [][]byte

StateKeys mocks base method.

func (*MockAuth) ValidRange

func (m *MockAuth) ValidRange(arg0 Rules) (int64, int64)

ValidRange mocks base method.

func (*MockAuth) Verify

func (m *MockAuth) Verify(arg0 context.Context, arg1 Rules, arg2 Database, arg3 Action) (uint64, error)

Verify mocks base method.

type MockAuthFactory

type MockAuthFactory struct {
	// contains filtered or unexported fields
}

MockAuthFactory is a mock of AuthFactory interface.

func NewMockAuthFactory

func NewMockAuthFactory(ctrl *gomock.Controller) *MockAuthFactory

NewMockAuthFactory creates a new mock instance.

func (*MockAuthFactory) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockAuthFactory) Sign

func (m *MockAuthFactory) Sign(arg0 []byte, arg1 Action) (Auth, error)

Sign mocks base method.

type MockAuthFactoryMockRecorder

type MockAuthFactoryMockRecorder struct {
	// contains filtered or unexported fields
}

MockAuthFactoryMockRecorder is the mock recorder for MockAuthFactory.

func (*MockAuthFactoryMockRecorder) Sign

func (mr *MockAuthFactoryMockRecorder) Sign(arg0, arg1 interface{}) *gomock.Call

Sign indicates an expected call of Sign.

type MockAuthMockRecorder

type MockAuthMockRecorder struct {
	// contains filtered or unexported fields
}

MockAuthMockRecorder is the mock recorder for MockAuth.

func (*MockAuthMockRecorder) AsyncVerify

func (mr *MockAuthMockRecorder) AsyncVerify(arg0 interface{}) *gomock.Call

AsyncVerify indicates an expected call of AsyncVerify.

func (*MockAuthMockRecorder) CanDeduct

func (mr *MockAuthMockRecorder) CanDeduct(arg0, arg1, arg2 interface{}) *gomock.Call

CanDeduct indicates an expected call of CanDeduct.

func (*MockAuthMockRecorder) Deduct

func (mr *MockAuthMockRecorder) Deduct(arg0, arg1, arg2 interface{}) *gomock.Call

Deduct indicates an expected call of Deduct.

func (*MockAuthMockRecorder) Marshal

func (mr *MockAuthMockRecorder) Marshal(arg0 interface{}) *gomock.Call

Marshal indicates an expected call of Marshal.

func (*MockAuthMockRecorder) MaxUnits

func (mr *MockAuthMockRecorder) MaxUnits(arg0 interface{}) *gomock.Call

MaxUnits indicates an expected call of MaxUnits.

func (*MockAuthMockRecorder) Payer

func (mr *MockAuthMockRecorder) Payer() *gomock.Call

Payer indicates an expected call of Payer.

func (*MockAuthMockRecorder) Refund

func (mr *MockAuthMockRecorder) Refund(arg0, arg1, arg2 interface{}) *gomock.Call

Refund indicates an expected call of Refund.

func (*MockAuthMockRecorder) StateKeys

func (mr *MockAuthMockRecorder) StateKeys() *gomock.Call

StateKeys indicates an expected call of StateKeys.

func (*MockAuthMockRecorder) ValidRange

func (mr *MockAuthMockRecorder) ValidRange(arg0 interface{}) *gomock.Call

ValidRange indicates an expected call of ValidRange.

func (*MockAuthMockRecorder) Verify

func (mr *MockAuthMockRecorder) Verify(arg0, arg1, arg2, arg3 interface{}) *gomock.Call

Verify indicates an expected call of Verify.

type MockRules

type MockRules struct {
	// contains filtered or unexported fields
}

MockRules is a mock of Rules interface.

func NewMockRules

func NewMockRules(ctrl *gomock.Controller) *MockRules

NewMockRules creates a new mock instance.

func (*MockRules) EXPECT

func (m *MockRules) EXPECT() *MockRulesMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockRules) FetchCustom

func (m *MockRules) FetchCustom(arg0 string) (interface{}, bool)

FetchCustom mocks base method.

func (*MockRules) GetBaseUnits

func (m *MockRules) GetBaseUnits() uint64

GetBaseUnits mocks base method.

func (*MockRules) GetBlockCostChangeDenominator

func (m *MockRules) GetBlockCostChangeDenominator() uint64

GetBlockCostChangeDenominator mocks base method.

func (*MockRules) GetChainID

func (m *MockRules) GetChainID() ids.ID

GetChainID mocks base method.

func (*MockRules) GetMaxBlockTxs

func (m *MockRules) GetMaxBlockTxs() int

GetMaxBlockTxs mocks base method.

func (*MockRules) GetMaxBlockUnits

func (m *MockRules) GetMaxBlockUnits() uint64

GetMaxBlockUnits mocks base method.

func (*MockRules) GetMinBlockCost

func (m *MockRules) GetMinBlockCost() uint64

GetMinBlockCost mocks base method.

func (*MockRules) GetMinUnitPrice

func (m *MockRules) GetMinUnitPrice() uint64

GetMinUnitPrice mocks base method.

func (*MockRules) GetUnitPriceChangeDenominator

func (m *MockRules) GetUnitPriceChangeDenominator() uint64

GetUnitPriceChangeDenominator mocks base method.

func (*MockRules) GetValidityWindow

func (m *MockRules) GetValidityWindow() int64

GetValidityWindow mocks base method.

func (*MockRules) GetWindowTargetBlocks

func (m *MockRules) GetWindowTargetBlocks() uint64

GetWindowTargetBlocks mocks base method.

func (*MockRules) GetWindowTargetUnits

func (m *MockRules) GetWindowTargetUnits() uint64

GetWindowTargetUnits mocks base method.

type MockRulesMockRecorder

type MockRulesMockRecorder struct {
	// contains filtered or unexported fields
}

MockRulesMockRecorder is the mock recorder for MockRules.

func (*MockRulesMockRecorder) FetchCustom

func (mr *MockRulesMockRecorder) FetchCustom(arg0 interface{}) *gomock.Call

FetchCustom indicates an expected call of FetchCustom.

func (*MockRulesMockRecorder) GetBaseUnits

func (mr *MockRulesMockRecorder) GetBaseUnits() *gomock.Call

GetBaseUnits indicates an expected call of GetBaseUnits.

func (*MockRulesMockRecorder) GetBlockCostChangeDenominator

func (mr *MockRulesMockRecorder) GetBlockCostChangeDenominator() *gomock.Call

GetBlockCostChangeDenominator indicates an expected call of GetBlockCostChangeDenominator.

func (*MockRulesMockRecorder) GetChainID

func (mr *MockRulesMockRecorder) GetChainID() *gomock.Call

GetChainID indicates an expected call of GetChainID.

func (*MockRulesMockRecorder) GetMaxBlockTxs

func (mr *MockRulesMockRecorder) GetMaxBlockTxs() *gomock.Call

GetMaxBlockTxs indicates an expected call of GetMaxBlockTxs.

func (*MockRulesMockRecorder) GetMaxBlockUnits

func (mr *MockRulesMockRecorder) GetMaxBlockUnits() *gomock.Call

GetMaxBlockUnits indicates an expected call of GetMaxBlockUnits.

func (*MockRulesMockRecorder) GetMinBlockCost

func (mr *MockRulesMockRecorder) GetMinBlockCost() *gomock.Call

GetMinBlockCost indicates an expected call of GetMinBlockCost.

func (*MockRulesMockRecorder) GetMinUnitPrice

func (mr *MockRulesMockRecorder) GetMinUnitPrice() *gomock.Call

GetMinUnitPrice indicates an expected call of GetMinUnitPrice.

func (*MockRulesMockRecorder) GetUnitPriceChangeDenominator

func (mr *MockRulesMockRecorder) GetUnitPriceChangeDenominator() *gomock.Call

GetUnitPriceChangeDenominator indicates an expected call of GetUnitPriceChangeDenominator.

func (*MockRulesMockRecorder) GetValidityWindow

func (mr *MockRulesMockRecorder) GetValidityWindow() *gomock.Call

GetValidityWindow indicates an expected call of GetValidityWindow.

func (*MockRulesMockRecorder) GetWindowTargetBlocks

func (mr *MockRulesMockRecorder) GetWindowTargetBlocks() *gomock.Call

GetWindowTargetBlocks indicates an expected call of GetWindowTargetBlocks.

func (*MockRulesMockRecorder) GetWindowTargetUnits

func (mr *MockRulesMockRecorder) GetWindowTargetUnits() *gomock.Call

GetWindowTargetUnits indicates an expected call of GetWindowTargetUnits.

type Parser

type Parser interface {
	Rules(int64) Rules

	Registry() (ActionRegistry, AuthRegistry)
}

type Processor

type Processor struct {
	// contains filtered or unexported fields
}

func NewProcessor

func NewProcessor(tracer trace.Tracer, b *StatelessBlock) *Processor

Only prepare for population if above last accepted height

func (*Processor) Execute

func (p *Processor) Execute(
	ctx context.Context,
	ectx *ExecutionContext,
	r Rules,
) (uint64, uint64, []*Result, error)

func (*Processor) Prefetch

func (p *Processor) Prefetch(ctx context.Context, db Database)

type Result

type Result struct {
	Success bool
	Units   uint64
	Output  []byte
}

func UnmarshalResult

func UnmarshalResult(p *codec.Packer) (*Result, error)

func UnmarshalResults

func UnmarshalResults(src []byte) ([]*Result, error)

func (*Result) Marshal

func (r *Result) Marshal(p *codec.Packer)

type Rules

type Rules interface {
	GetChainID() ids.ID

	GetMaxBlockTxs() int
	GetMaxBlockUnits() uint64 // should ensure can't get above block max size

	GetValidityWindow() int64
	GetBaseUnits() uint64

	GetMinUnitPrice() uint64
	GetUnitPriceChangeDenominator() uint64
	GetWindowTargetUnits() uint64

	GetMinBlockCost() uint64
	GetBlockCostChangeDenominator() uint64
	GetWindowTargetBlocks() uint64

	FetchCustom(string) (any, bool)
}

type StatefulBlock

type StatefulBlock struct {
	Prnt   ids.ID `json:"parent"`
	Tmstmp int64  `json:"timestamp"`
	Hght   uint64 `json:"height"`

	UnitPrice  uint64        `json:"unitPrice"`
	UnitWindow window.Window `json:"unitWindow"`

	BlockCost   uint64        `json:"blockCost"`
	BlockWindow window.Window `json:"blockWindow"`

	Txs []*Transaction `json:"txs"`

	StateRoot     ids.ID `json:"stateRoot"`
	UnitsConsumed uint64 `json:"unitsConsumed"`
	SurplusFee    uint64 `json:"surplusFee"`
}

func NewGenesisBlock

func NewGenesisBlock(root ids.ID, minUnit uint64, minBlock uint64) *StatefulBlock

func UnmarshalBlock

func UnmarshalBlock(raw []byte, parser Parser) (*StatefulBlock, error)

func (*StatefulBlock) Marshal

func (b *StatefulBlock) Marshal(
	actionRegistry ActionRegistry,
	authRegistry AuthRegistry,
) ([]byte, error)

type StatelessBlock

type StatelessBlock struct {
	*StatefulBlock `json:"block"`
	// contains filtered or unexported fields
}

Stateless is defined separately from "Block" in case external packages needs use the stateful block without mocking VM or parent block

func NewBlock

func NewBlock(ectx *ExecutionContext, vm VM, parent snowman.Block, tmstp int64) *StatelessBlock

func ParseBlock

func ParseBlock(
	ctx context.Context,
	source []byte,
	status choices.Status,
	vm VM,
) (*StatelessBlock, error)

func ParseStatefulBlock

func ParseStatefulBlock(
	ctx context.Context,
	blk *StatefulBlock,
	source []byte,
	status choices.Status,
	vm VM,
) (*StatelessBlock, error)

func (*StatelessBlock) Accept

func (b *StatelessBlock) Accept(ctx context.Context) error

implements "snowman.Block.choices.Decidable"

func (*StatelessBlock) Bytes

func (b *StatelessBlock) Bytes() []byte

implements "snowman.Block"

func (*StatelessBlock) GetTimestamp

func (b *StatelessBlock) GetTimestamp() int64

func (*StatelessBlock) GetTxs

func (b *StatelessBlock) GetTxs() []*Transaction

func (*StatelessBlock) GetUnitPrice

func (b *StatelessBlock) GetUnitPrice() uint64

func (*StatelessBlock) Height

func (b *StatelessBlock) Height() uint64

implements "snowman.Block"

func (*StatelessBlock) ID

func (b *StatelessBlock) ID() ids.ID

implements "snowman.Block.choices.Decidable"

func (*StatelessBlock) IsRepeat

func (b *StatelessBlock) IsRepeat(
	ctx context.Context,
	oldestAllowed int64,
	txs []*Transaction,
) (bool, error)

func (*StatelessBlock) Parent

func (b *StatelessBlock) Parent() ids.ID

implements "snowman.Block"

func (*StatelessBlock) Processed

func (b *StatelessBlock) Processed() bool

Used to determine if should notify listeners and/or pass to controller

func (*StatelessBlock) Reject

func (b *StatelessBlock) Reject(ctx context.Context) error

implements "snowman.Block.choices.Decidable"

func (*StatelessBlock) Results

func (b *StatelessBlock) Results() []*Result

func (*StatelessBlock) SetLastAccepted

func (b *StatelessBlock) SetLastAccepted(ctx context.Context) error

SetLastAccepted is called during [Accept] and at the start and end of state sync.

func (*StatelessBlock) State

func (b *StatelessBlock) State() (Database, error)

State is used to verify txs in the mempool. It should never be written to.

TODO: we should modify the interface here to only allow read-like messages

func (*StatelessBlock) Status

func (b *StatelessBlock) Status() choices.Status

implements "snowman.Block.choices.Decidable"

func (*StatelessBlock) Timestamp

func (b *StatelessBlock) Timestamp() time.Time

implements "snowman.Block"

func (*StatelessBlock) Verify

func (b *StatelessBlock) Verify(ctx context.Context) error

implements "snowman.Block"

type SyncableBlock

type SyncableBlock struct {
	*StatelessBlock
}

func NewSyncableBlock

func NewSyncableBlock(sb *StatelessBlock) *SyncableBlock

func (*SyncableBlock) Accept

func (*SyncableBlock) String

func (sb *SyncableBlock) String() string

type Transaction

type Transaction struct {
	Base   *Base  `json:"base"`
	Action Action `json:"action"`
	Auth   Auth   `json:"auth"`
	// contains filtered or unexported fields
}

func NewTx

func NewTx(base *Base, act Action) *Transaction

func UnmarshalTx

func UnmarshalTx(
	p *codec.Packer,
	actionRegistry *codec.TypeParser[Action],
	authRegistry *codec.TypeParser[Auth],
) (*Transaction, error)

func UnmarshalTxs

func UnmarshalTxs(
	raw []byte,
	maxCount int,
	actionRegistry ActionRegistry,
	authRegistry AuthRegistry,
) ([]*Transaction, error)

func (*Transaction) Bytes

func (t *Transaction) Bytes() []byte

func (*Transaction) Digest

func (t *Transaction) Digest() ([]byte, error)

func (*Transaction) Execute

func (t *Transaction) Execute(
	ctx context.Context,
	r Rules,
	tdb *tstate.TState,
	timestamp int64,
) (*Result, error)

Execute after knowing a transaction can pay a fee

func (*Transaction) Expiry

func (t *Transaction) Expiry() int64

func (*Transaction) ID

func (t *Transaction) ID() ids.ID

func (*Transaction) Init

func (t *Transaction) Init(
	_ context.Context,
	actionRegistry ActionRegistry,
	authRegistry AuthRegistry,
) (func() error, error)

func (*Transaction) Marshal

func (t *Transaction) Marshal(
	p *codec.Packer,
	actionRegistry *codec.TypeParser[Action],
	authRegistry *codec.TypeParser[Auth],
) error

func (*Transaction) MaxUnits

func (t *Transaction) MaxUnits(r Rules) uint64

Units is charged whether or not a transaction is successful because state lookup is not free.

func (*Transaction) Payer

func (t *Transaction) Payer() string

Used by mempool

func (*Transaction) PreExecute

func (t *Transaction) PreExecute(
	ctx context.Context,
	ectx *ExecutionContext,
	r Rules,
	db Database,
	timestamp int64,
) error

PreExecute must not modify state

func (*Transaction) Sign

func (t *Transaction) Sign(factory AuthFactory) error

func (*Transaction) Size

func (t *Transaction) Size() uint64

func (*Transaction) StateKeys

func (t *Transaction) StateKeys() [][]byte

It is ok to have duplicate ReadKeys...the processor will skip them

func (*Transaction) UnitPrice

func (t *Transaction) UnitPrice() uint64

type VM

type VM interface {
	Parser

	HRP() string

	Workers() *workers.Workers
	Tracer() trace.Tracer
	Logger() logging.Logger

	IsBootstrapped() bool
	LastAcceptedBlock() *StatelessBlock
	SetLastAccepted(*StatelessBlock) error
	GetStatelessBlock(context.Context, ids.ID) (*StatelessBlock, error)

	State() (*merkledb.Database, error)

	Mempool() Mempool
	IsRepeat(context.Context, []*Transaction) bool

	Verified(context.Context, *StatelessBlock)
	Rejected(context.Context, *StatelessBlock)
	Accepted(context.Context, *StatelessBlock)
	AcceptedSyncableBlock(context.Context, *SyncableBlock) (block.StateSyncMode, error)

	// UpdateSyncTarget returns a bool that is true if the root
	// was updated and the sync is continuing with the new specified root
	// and false if the sync completed with the previous root.
	UpdateSyncTarget(*StatelessBlock) (bool, error)
	StateReady() bool
}

Jump to

Keyboard shortcuts

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