chain

package
v0.0.0-...-24e5678 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: LGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidVersion             = errors.New("invalid version")
	ErrInvalidHeight              = errors.New("invalid height")
	ErrInvalidPrevHash            = errors.New("invalid prev hash")
	ErrInvalidTimestamp           = errors.New("invalid timestamp")
	ErrInvalidGenerator           = errors.New("invalid generator")
	ErrApplicationIDMustBe255     = errors.New("application id must be 255")
	ErrAddBeforeChainInit         = errors.New("add before chain init")
	ErrReservedID                 = errors.New("reserved id")
	ErrNotExistService            = errors.New("not exist service")
	ErrExistServiceName           = errors.New("exist service name")
	ErrExistServiceID             = errors.New("exist service id")
	ErrChainClosed                = errors.New("chain closed")
	ErrInvalidContextHash         = errors.New("invalid context hash")
	ErrInvalidLevelRootHash       = errors.New("invalid level root hash")
	ErrInvalidReceiptHash         = errors.New("invalid receipt hash")
	ErrStoreClosed                = errors.New("store closed")
	ErrInvalidChainID             = errors.New("invalid chain id")
	ErrAlreadyGenesised           = errors.New("already genesised")
	ErrAlreadyInitialzed          = errors.New("already initialized")
	ErrExceedHashCount            = errors.New("exceed hash count")
	ErrInvalidHashCount           = errors.New("invalid hash count")
	ErrInvalidAdminAddress        = errors.New("invalid admin address")
	ErrInvalidSeqType             = errors.New("invalid sequence type")
	ErrUnknownTransactionMethod   = errors.New("unknown transaction method")
	ErrInvalidTopAddress          = errors.New("invalid top address")
	ErrInvalidTopSignature        = errors.New("invalid top signature")
	ErrInvalidSignatureCount      = errors.New("invalid signature count")
	ErrInsufficientCandidateCount = errors.New("insufficient candidate count")
	ErrInvalidPhase               = errors.New("invalid phase")
	ErrExistAddress               = errors.New("exist address")
	ErrExceedCandidateCount       = errors.New("exceed candidate count")
	ErrFoundForkedBlock           = errors.New("found forked block")
	ErrInvalidBasicFee            = errors.New("invalid basic fee")
	ErrNotExistContract           = errors.New("not exist contract")
)

errors

Functions

func BuildLevelRoot

func BuildLevelRoot(hashes []hash.Hash256) (hash.Hash256, error)

BuildLevelRoot returns the level root hash

func ChargeFee

func ChargeFee(ctx *types.Context, useGas uint64, signer common.Address) (*amount.Amount, error)

func ExecuteContractTx

func ExecuteContractTx(ctx *types.Context, tx *types.Transaction, signer common.Address, TXID string) error

func ExecuteContractTxWithEvent

func ExecuteContractTxWithEvent(ctx *types.Context, tx *types.Transaction, signer common.Address, TXID string) ([]*ctypes.Event, error)

func NewChainCommiter

func NewChainCommiter(cn *Chain) *chainCommiter

func SetVersion

func SetVersion(h uint32, v uint16)

func TestContractWithOutSeq

func TestContractWithOutSeq(ctx *types.Context, tx *types.Transaction, signer common.Address) error

Types

type BlockCreator

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

BlockCreator helps to create block

func NewBlockCreator

func NewBlockCreator(cn *Chain, ctx *types.Context, Generator common.Address, TimeoutCount uint32, Timestamp uint64, gasLv uint16) *BlockCreator

NewBlockCreator returns a BlockCreator

func (*BlockCreator) AddTx

AddTx validates, executes and adds transactions

func (*BlockCreator) Finalize

func (bc *BlockCreator) Finalize(gasLv uint16, receipts types.Receipts) (*types.Block, error)

Finalize generates block that has transactions adds by AddTx

func (*BlockCreator) UnsafeAddTx

func (bc *BlockCreator) UnsafeAddTx(TxHash hash.Hash256, tx *types.Transaction, sig common.Signature, signer common.Address) (receipt *etypes.Receipt, err error)

UnsafeAddTx adds transactions without signer validation if signers is not empty

type Chain

type Chain struct {
	sync.Mutex

	CallRootDump func()
	// contains filtered or unexported fields
}

Chain manages the chain data

func NewChain

func NewChain(ObserverKeys []common.PublicKey, store *Store, tag string) *Chain

NewChain returns a Chain

func (*Chain) ApplyEvmTransaction

func (cn *Chain) ApplyEvmTransaction(ctx *types.Context, tx *types.Transaction, ti uint16, signer common.Address) ([]*ctypes.Event, *etypes.Receipt, error)

ethereum type transaction 실행

func (*Chain) Close

func (cn *Chain) Close()

Close terminates and cleans the chain

func (*Chain) ConnectBlock

func (cn *Chain) ConnectBlock(b *types.Block, SigMap map[hash.Hash256]common.Address) error

ConnectBlock try to connect block to the chain

func (*Chain) ExecuteTransaction

func (cn *Chain) ExecuteTransaction(ctx *types.Context, tx *types.Transaction, TXID string) ([]*ctypes.Event, error)

func (*Chain) GeneratorsInMap

func (cn *Chain) GeneratorsInMap(GeneratorMap map[common.Address]bool, Limit int) ([]common.Address, error)

GeneratorInMap returns current top generator

func (*Chain) GetCurrentDump

func (cn *Chain) GetCurrentDump() string

func (*Chain) Init

func (cn *Chain) Init(genesisContextData *types.ContextData) error

Init initializes the chain

func (*Chain) InitWith

func (cn *Chain) InitWith(InitGenesisHash hash.Hash256, initHash hash.Hash256, initHeight uint32, initTimestamp uint64) error

InitWith initializes the chain with snapshot informations

func (*Chain) MustAddService

func (cn *Chain) MustAddService(s types.Service)

MustAddService adds Service but panic when has the same name service

func (*Chain) NewContext

func (cn *Chain) NewContext() *types.Context

NewContext returns the context of the chain

func (*Chain) Provider

func (cn *Chain) Provider() types.Provider

Provider returns the context of the chain

func (*Chain) ServiceByName

func (cn *Chain) ServiceByName(name string) (types.Service, error)

ServiceByName returns the service by the name

func (*Chain) Services

func (cn *Chain) Services() []types.Service

Services returns services

func (*Chain) Store

func (cn *Chain) Store() *Store

Store returns the store of the chain

func (*Chain) TopGenerator

func (cn *Chain) TopGenerator(TimeoutCount uint32) (common.Address, error)

TopGenerator returns current top generator

func (*Chain) TopGeneratorInMap

func (cn *Chain) TopGeneratorInMap(GeneratorMap map[common.Address]bool) (common.Address, uint32, error)

TopRankInMap returns current top generator

func (*Chain) UpdateBlock

func (cn *Chain) UpdateBlock(b *types.Block, SigMap map[hash.Hash256]common.Address) error

ConnectBlock try to connect block to the chain

func (*Chain) UpdateExecuteBlockOnContext

func (cn *Chain) UpdateExecuteBlockOnContext(b *types.Block, ctx *types.Context, sm map[hash.Hash256]common.Address) (types.Receipts, error)

func (*Chain) UpdateInit

func (cn *Chain) UpdateInit(genesisContextData *types.ContextData) error

Init initializes the chain

func (*Chain) ValidateSignature

func (cn *Chain) ValidateSignature(bh *types.Header, sigs []common.Signature) error

func (*Chain) WaitConnectedBlock

func (cn *Chain) WaitConnectedBlock(targetBlock uint32)

WaitConnectedBlock is wait untile target block stored

type Committer

type Committer interface {
	Generators() ([]common.Address, error)
	ValidateHeader(bh *types.Header) error
	ExecuteBlockOnContext(b *types.Block, ctx *types.Context, SigMap map[hash.Hash256]common.Address) (types.Receipts, error)
	ConnectBlockWithContext(b *types.Block, ctx *types.Context, receipts types.Receipts) error
	NewContext() *types.Context
}

Committer enables to commit block with pre-executed context

type DeployContractData

type DeployContractData struct {
	Owner   common.Address
	ClassID uint64
	Args    []byte
}

DeployContractData defines data of deploy contract tx

func (*DeployContractData) ReadFrom

func (s *DeployContractData) ReadFrom(r io.Reader) (int64, error)

func (*DeployContractData) WriteTo

func (s *DeployContractData) WriteTo(w io.Writer) (int64, error)

type Rank

type Rank struct {
	Address common.Address
	// contains filtered or unexported fields
}

Rank represents the rank information of the formulator account

func InsertRankToList

func InsertRankToList(ranks []*Rank, s *Rank) []*Rank

InsertRankToList inserts the rank by the score to the rank list

func NewRank

func NewRank(Address common.Address, phase uint32, hashSpace hash.Hash256) *Rank

NewRank returns a Rank

func (*Rank) Clone

func (rank *Rank) Clone() *Rank

Clone returns the clonend value of it

func (*Rank) Equal

func (rank *Rank) Equal(b *Rank) bool

Equal checks that two values is same or not

func (*Rank) HashSpace

func (rank *Rank) HashSpace() hash.Hash256

HashSpace returns the hash space of the rank

func (*Rank) IsZero

func (rank *Rank) IsZero() bool

IsZero returns a == 0

func (*Rank) Key

func (rank *Rank) Key() string

Key returns unique key of the rank

func (*Rank) Less

func (rank *Rank) Less(b *Rank) bool

Less returns a < b

func (*Rank) Phase

func (rank *Rank) Phase() uint32

Phase returns the phase of the rank

func (*Rank) ReadFrom

func (s *Rank) ReadFrom(r io.Reader) (int64, error)

func (*Rank) Score

func (rank *Rank) Score() uint64

Score returns the score of the rank

func (*Rank) Set

func (rank *Rank) Set(phase uint32, hashSpace hash.Hash256)

Set updates rank's properties and update the score

func (*Rank) SetHashSpace

func (rank *Rank) SetHashSpace(hashSpace hash.Hash256)

SetHashSpace set the hash space and update the score

func (*Rank) SetPhase

func (rank *Rank) SetPhase(phase uint32)

SetPhase set the phase and update the score

func (*Rank) String

func (rank *Rank) String() string

String returns the string of the rank using the byte array of rank value

func (*Rank) WriteTo

func (s *Rank) WriteTo(w io.Writer) (int64, error)

type RankTable

type RankTable struct {
	sync.Mutex
	// contains filtered or unexported fields
}

RankTable implements the proof of Generator algorithm

func NewRankTable

func NewRankTable() *RankTable

NewRankTable returns a RankTable

func (*RankTable) CandidateCount

func (rt *RankTable) CandidateCount() int

CandidateCount returns a count of the rank table

func (*RankTable) Candidates

func (rt *RankTable) Candidates() []*Rank

Candidates returns a candidates

func (*RankTable) GeneratorsInMap

func (rt *RankTable) GeneratorsInMap(GeneratorMap map[common.Address]bool, Limit int) ([]common.Address, error)

RanksInMap returns the ranks in the map

func (*RankTable) IsGenerator

func (rt *RankTable) IsGenerator(addr common.Address) bool

IsGenerator returns the given information is correct or not

func (*RankTable) ReadFrom

func (s *RankTable) ReadFrom(r io.Reader) (int64, error)

func (*RankTable) TopGeneratorInMap

func (rt *RankTable) TopGeneratorInMap(GeneratorMap map[common.Address]bool) (common.Address, uint32, error)

TopRankInMap returns the top rank by the given timeout count in the given map

func (*RankTable) TopRank

func (rt *RankTable) TopRank(TimeoutCount uint32) (*Rank, error)

TopRank returns the top rank by Timeoutcount

func (*RankTable) WriteTo

func (s *RankTable) WriteTo(w io.Writer) (int64, error)

type Store

type Store struct {
	sync.Mutex

	AddrSeqMapLock sync.Mutex
	AddrSeqMap     map[common.Address]uint64
	// contains filtered or unexported fields
}

Store saves the target chain state All updates are executed in one transaction with FileSync option

func NewStore

func NewStore(keydbPath string, cdb *piledb.DB, ChainID *big.Int, version uint16) (*Store, error)

NewStore returns a Store

func (*Store) AddrSeq

func (st *Store) AddrSeq(addr common.Address) uint64

Seq returns the sequence of the transaction

func (*Store) Admins

func (st *Store) Admins() ([]common.Address, error)

Admins returns all Admins of the target chain

func (*Store) BasicFee

func (st *Store) BasicFee() *amount.Amount

BasicFee returns basic fee

func (*Store) Block

func (st *Store) Block(height uint32) (*types.Block, error)

Block returns the block by height

func (*Store) BlockGenMap

func (st *Store) BlockGenMap() (map[common.Address]uint32, error)

BlockGenMap returns current block gen map

func (*Store) ChainID

func (st *Store) ChainID() *big.Int

ChainID returns the chain id of the target chain

func (*Store) Close

func (st *Store) Close()

Close terminate and clean store

func (*Store) Contract

func (st *Store) Contract(addr common.Address) (types.Contract, error)

Contract returns the contract form the store

func (*Store) Contracts

func (st *Store) Contracts() ([]types.Contract, error)

Contracts returns the contract form the store

func (*Store) CopyContext

func (st *Store) CopyContext(zipContextPath string) error

func (*Store) Data

func (st *Store) Data(cont common.Address, addr common.Address, name []byte) []byte

Data returns the account data from the store

func (*Store) GenHash

func (st *Store) GenHash() hash.Hash256

Height returns the current height of the target chain

func (*Store) Generators

func (st *Store) Generators() ([]common.Address, error)

Generators returns all generators of the target chain

func (*Store) GeneratorsInMap

func (st *Store) GeneratorsInMap(GeneratorMap map[common.Address]bool, Limit int) ([]common.Address, error)

RanksInMap returns current top generator

func (*Store) Hash

func (st *Store) Hash(height uint32) (hash.Hash256, error)

Hash returns the hash of the data by height

func (*Store) Header

func (st *Store) Header(height uint32) (*types.Header, error)

Header returns the header of the data by height

func (*Store) Height

func (st *Store) Height() uint32

Height returns the current height of the target chain

func (*Store) InitHeight

func (st *Store) InitHeight() uint32

InitHeight returns the initial height of the target chain

func (*Store) InitTimeSlot

func (st *Store) InitTimeSlot() error

func (*Store) InitTimestamp

func (st *Store) InitTimestamp() uint64

InitTimestamp returns the initial timestamp of the target chain

func (*Store) IsAdmin

func (st *Store) IsAdmin(addr common.Address) bool

IsAdmin returns the account is Admin or not

func (*Store) IsContract

func (st *Store) IsContract(addr common.Address) bool

IsContract returns is the contract

func (*Store) IsGenerator

func (st *Store) IsGenerator(addr common.Address) bool

IsGenerator returns the account is generator or not

func (*Store) IsUsedTimeSlot

func (st *Store) IsUsedTimeSlot(slot uint32, key string) bool

IsUsedTimeSlot returns timeslot is used or not

func (*Store) IterBlockAfterContext

func (st *Store) IterBlockAfterContext(fn func(b *types.Block) error) error

func (*Store) LastHash

func (st *Store) LastHash() hash.Hash256

LastHash returns the last hash of the chain

func (*Store) LastStatus

func (st *Store) LastStatus() (uint32, hash.Hash256)

LastStatus returns the recored target height, prev hash and timestamp

func (*Store) LastTimestamp

func (st *Store) LastTimestamp() uint64

LastTimestamp returns the prev timestamp of the chain

func (*Store) MainToken

func (st *Store) MainToken() *common.Address

MainToken returns the account MainToken

func (*Store) Prepare

func (st *Store) Prepare() error

Prepare loads the initial data

func (*Store) PrevHash

func (st *Store) PrevHash() hash.Hash256

PrevHash returns the prev hash of the chain

func (*Store) ProcessReward

func (st *Store) ProcessReward(ctx *types.Context, b *types.Block) (map[common.Address][]byte, error)

func (*Store) Receipts

func (st *Store) Receipts(height uint32) (types.Receipts, error)

Block returns the block by height

func (*Store) StoreBlock

func (st *Store) StoreBlock(b *types.Block, ctx *types.Context, receipts types.Receipts) error

StoreBlock stores the block

func (*Store) StoreGenesis

func (st *Store) StoreGenesis(genHash hash.Hash256, ctd *types.ContextData) error

StoreGenesis stores the genesis data

func (*Store) StoreInit

func (st *Store) StoreInit(genHash hash.Hash256, initHash hash.Hash256, initHeight uint32, initTimestamp uint64) error

StoreInit stores the init data

func (*Store) TargetHeight

func (st *Store) TargetHeight() uint32

TargetHeight returns the target height of the target chain

func (*Store) TopGenerator

func (st *Store) TopGenerator(TimeoutCount uint32) (common.Address, error)

TopGenerator returns current top generator

func (*Store) TopGeneratorInMap

func (st *Store) TopGeneratorInMap(GeneratorMap map[common.Address]bool) (common.Address, uint32, error)

TopRankInMap returns current top generator

func (*Store) UpdateContext

func (st *Store) UpdateContext(b *types.Block, ctx *types.Context, receipts types.Receipts) error

StoreBlock stores the block

func (*Store) UpdatePrepare

func (st *Store) UpdatePrepare() error

Prepare loads the initial data

func (*Store) UpdateStoreGenesis

func (st *Store) UpdateStoreGenesis(genHash hash.Hash256, ctd *types.ContextData) error

StoreGenesis stores the genesis data

func (*Store) Version

func (st *Store) Version(h uint32) uint16

Version returns the version of the target chain

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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