chain

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2023 License: AGPL-3.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewChain

func NewChain(
	name string,
	ctx *snow.Context,
	cfg *config.Config,
	gs *genesis.Genesis,
	baseDB database.Database,
	toEngine chan<- common.Message,
	transport http.RoundTripper,
) *blockChain

Types

type Block

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

Block is a possible decision that dictates the next canonical block.

Blocks are guaranteed to be Verified, Accepted, and Rejected in topological order. Specifically, if Verify is called, then the parent has already been verified. If Accept is called, then the parent has already been accepted. If Reject is called, the parent has already been accepted or rejected.

If the status of the block is Unknown, ID is assumed to be able to be called. If the status of the block is Accepted or Rejected; Parent, Verify, Accept, and Reject will never be called.

func NewBlock

func NewBlock(b *ld.Block, ctx *Context) *Block

func NewGenesisBlock

func NewGenesisBlock(ctx *Context, txs ld.Txs) (*Block, error)

func (*Block) Accept

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

Accept implements the snowman.Block choices.Decidable Accept interface This element will be accepted by every correct node in the network. Accept sets this block's status to Accepted and sets lastAccepted to this block's ID and saves this info to stateDB.

func (*Block) AncestorBlocks

func (b *Block) AncestorBlocks(ancestorHeight uint64) ([]*Block, error)

AncestorBlocks returns this block's ancestors, from ancestorHeight to block' height, not including this block. The ancestorHeight must >= LastAcceptedBlock's height.

func (*Block) BuildState

func (b *Block) BuildState(vbs BlockState) error

func (*Block) BuildTxs

func (b *Block) BuildTxs(vbs BlockState, txs ...*ld.Transaction) choices.Status

func (*Block) Builder

func (b *Block) Builder() ids.Address

func (*Block) Bytes

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

Bytes implements the snowman.Block Bytes interface Bytes returns the binary representation of this block. This is used for sending blocks to peers. The bytes should be able to be parsed into the same block on another node.

func (*Block) ChainConfig

func (b *Block) ChainConfig() *genesis.ChainConfig

func (*Block) Context

func (b *Block) Context() *Context

func (*Block) FeeConfig

func (b *Block) FeeConfig() *genesis.FeeConfig

func (*Block) Free

func (b *Block) Free()

func (*Block) Gas

func (b *Block) Gas() *big.Int

func (*Block) GasPrice

func (b *Block) GasPrice() *big.Int

func (*Block) GasRebate20

func (b *Block) GasRebate20() *big.Int

Regard to pareto 80/20 Rule 20% to block builder, 80% to block shares, GasRebate20 = Gas * GasPrice * (GasRebateRate / 100) * 20%

func (*Block) Hash

func (b *Block) Hash() ids.ID32

func (*Block) Height

func (b *Block) Height() uint64

Height implements the snowman.Block Height interface Height returns this block's height. The genesis block has height 0.

func (*Block) ID

func (b *Block) ID() avaids.ID

ID implements the snowman.Block choices.Decidable ID interface ID returns a unique ID for this element.

func (*Block) InitState

func (b *Block) InitState(parent *Block, db database.Database)

func (*Block) LD

func (b *Block) LD() *ld.Block

func (*Block) MarshalJSON

func (b *Block) MarshalJSON() ([]byte, error)

func (*Block) NextGasPrice

func (b *Block) NextGasPrice() uint64

NextGasPrice returns the next block's gas price. It should be called after the block is verified.

func (*Block) Parent

func (b *Block) Parent() avaids.ID

Parent implements the snowman.Block Parent interface Parent returns the ID of this block's parent.

func (*Block) Reject

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

Reject implements the snowman.Block choices.Decidable Reject interface This element will not be accepted by any correct node in the network.

func (*Block) SetBuilder

func (b *Block) SetBuilder(builder ids.Address)

func (*Block) SetBuilderFee

func (b *Block) SetBuilderFee(vbs BlockState) error

func (*Block) SetContext

func (b *Block) SetContext(ctx *Context)

func (*Block) SetStatus

func (b *Block) SetStatus(s choices.Status)

func (*Block) State

func (b *Block) State() BlockState

func (*Block) Status

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

Status implements the snowman.Block choices.Decidable Status interface Status returns this element's current status. If Accept has been called on an element with this ID, Accepted should be returned. Similarly, if Reject has been called on an element with this ID, Rejected should be returned. If the contents of this element are unknown, then Unknown should be returned. Otherwise, Processing should be returned.

func (*Block) Timestamp

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

Timestamp implements the snowman.Block Timestamp interface Timestamp returns this block's time. The genesis block has timestamp 0.

func (*Block) Timestamp2

func (b *Block) Timestamp2() uint64

func (*Block) TryBuildTxs

func (b *Block) TryBuildTxs(txs ...*ld.Transaction) error

func (*Block) Unmarshal

func (b *Block) Unmarshal(data []byte) error

func (*Block) Verify

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

Verify implements the snowman.Block Verify interface Verify that the state transition this block would make if accepted is valid. It is guaranteed that the Parent has been successfully verified.

type BlockBuilder

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

func NewBlockBuilder

func NewBlockBuilder(txPool *TxPool, toEngine chan<- common.Message) *BlockBuilder

func (*BlockBuilder) Build

func (b *BlockBuilder) Build(ctx context.Context, builder ids.Address) (*Block, error)

func (*BlockBuilder) HandlePreferenceBlock

func (b *BlockBuilder) HandlePreferenceBlock(ctx context.Context, height uint64)

HandlePreferenceBlock should be called immediately after [VM.SetPreference].

func (*BlockBuilder) SignalTxsReady

func (b *BlockBuilder) SignalTxsReady()

SignalTxsReady should be called immediately when a new tx incoming

type BlockChain

type BlockChain interface {
	// global context
	Context() *Context
	Info() map[string]any
	DB() database.Database

	// global state
	HealthCheck(context.Context) (any, error)
	Bootstrap(context.Context) error
	State() snow.State
	SetState(context.Context, snow.State) error
	TotalSupply(context.Context) *big.Int

	// blocks state
	IsBuilder() bool
	BuildBlock(context.Context) (*Block, error)
	ParseBlock(context.Context, []byte) (*Block, error)
	GetBlockIDAtHeight(context.Context, uint64) (ids.ID32, error)
	GetBlockAtHeight(context.Context, uint64) (*Block, error)
	GetBlock(context.Context, ids.ID32) (*Block, error)
	LastAcceptedBlock(context.Context) *Block
	SetLastAccepted(context.Context, *Block) error
	PreferredBlock() *Block
	SetPreference(context.Context, ids.ID32) error
	AddVerifiedBlock(*Block)
	GetVerifiedBlock(ids.ID32) *Block

	// txs
	GetGenesisTxs() ld.Txs
	PreVerifyPOSTxs(context.Context, ...*ld.Transaction) error
	LoadTxsByIDsFromPOS(context.Context, uint64, []ids.ID32) (ld.Txs, error)

	LoadAccount(context.Context, ids.Address) (*ld.Account, error)
	LoadModel(context.Context, ids.ModelID) (*ld.ModelInfo, error)
	LoadData(context.Context, ids.DataID) (*ld.DataInfo, error)
	LoadPrevData(context.Context, ids.DataID, uint64) (*ld.DataInfo, error)
	LoadRawData(context.Context, string, []byte) ([]byte, error)
}

BlockChain defines methods to manage state with Blocks and LastAcceptedIDs.

type BlockState

type BlockState interface {
	VersionDB() *versiondb.Database
	DeriveState() (BlockState, error)
	LoadValidatorAccountByNodeID(avaids.NodeID) (ids.StakeSymbol, *acct.Account)
	GetBlockIDAtHeight(uint64) (ids.ID32, error)
	SaveBlock(*ld.Block) error
	Commit() error
	Free()

	txn.ChainState
}

type Context

type Context struct {
	*snow.Context
	// contains filtered or unexported fields
}

func NewContext

func NewContext(
	name string,
	ctx *snow.Context,
	bc BlockChain,
	config *config.Config,
	genesis *genesis.Genesis,
) *Context

func (*Context) Builder added in v0.1.1

func (c *Context) Builder() ids.Address

func (*Context) BuilderSigner added in v0.1.1

func (c *Context) BuilderSigner() key.Signer

func (*Context) Chain

func (c *Context) Chain() BlockChain

func (*Context) ChainConfig

func (c *Context) ChainConfig() *genesis.ChainConfig

func (*Context) Config

func (c *Context) Config() *config.Config

func (*Context) Name

func (c *Context) Name() string

type TxPool

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

func NewTxPool

func NewTxPool(ctx *Context, posEndpoint string, rt http.RoundTripper) *TxPool

func (*TxPool) AcceptByBlock added in v0.1.1

func (p *TxPool) AcceptByBlock(ctx context.Context, blk *ld.Block) error

func (*TxPool) FetchToBuild

func (p *TxPool) FetchToBuild(ctx context.Context, height uint64) (ld.Txs, error)

func (*TxPool) LoadByIDs

func (p *TxPool) LoadByIDs(ctx context.Context, height uint64, txIDs ids.IDList[ids.ID32]) (ld.Txs, error)

func (*TxPool) SetCache

func (p *TxPool) SetCache(height uint64, txs ld.Txs)

func (*TxPool) SizeToBuild

func (p *TxPool) SizeToBuild(ctx context.Context, height uint64) int

func (*TxPool) UpdateBuildStatus

func (p *TxPool) UpdateBuildStatus(ctx context.Context, height uint64, tbs *txpool.TxsBuildStatus)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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