module

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: Apache-2.0 Imports: 10 Imported by: 5

Documentation

Index

Constants

View Source
const (
	BlockVersion0 = iota
	BlockVersion1
	BlockVersion2
)
View Source
const (
	DirLeft = Dir(iota)
	DirRight
)
View Source
const (
	TransactionVersion2 = 2
	TransactionVersion3 = 3
)
View Source
const (
	FlagNextProofContext = 0x1
	FlagBTPBlockHeader   = 0x2
	FlagBTPBlockProof    = 0x4
)
View Source
const (
	DSTProposal = "proposal"
	DSTVote     = "vote"
)
View Source
const (
	FinalizeNormalTransaction = 1 << iota
	FinalizePatchTransaction
	FinalizeResult
	KeepingParent

	// TODO It's only necessary if storing receipt index is determined by
	// block manager. The current service manager determines by itself according
	// to version, so it doesn't use it.
	FinalizeWriteReceiptIndex
)

Options for finalize

View Source
const (
	ImportByForce = 0x1
)
View Source
const (
	PatchTypeSkipTransaction = "skip_txs"
)

Variables

This section is empty.

Functions

func BlockDataToBytes added in v0.9.10

func BlockDataToBytes(blk BlockData) ([]byte, error)

func GetSourceNetworkUID added in v1.3.0

func GetSourceNetworkUID(c interface{ NID() int }) []byte

func SourceNetworkUID added in v1.3.0

func SourceNetworkUID(nid int) []byte

Types

type APIInfo

type APIInfo interface {
	ToJSON(JSONVersion) (interface{}, error)
}

type Address

type Address interface {
	String() string
	Bytes() []byte
	ID() []byte
	IsContract() bool
	Equal(Address) bool
}

type AsyncProtocolHandler added in v1.3.13

type AsyncProtocolHandler interface {
	ProtocolHandler
	HandleInBackground() (OnResult, error)
}

type BTPBlockHeader added in v1.3.0

type BTPBlockHeader interface {
	MainHeight() int64
	Round() int32
	NextProofContextHash() []byte
	NetworkSectionToRoot() []MerkleNode
	NetworkID() int64
	UpdateNumber() int64
	FirstMessageSN() int64
	NextProofContextChanged() bool
	PrevNetworkSectionHash() []byte
	MessageCount() int64
	MessagesRoot() []byte
	NextProofContext() []byte
	HeaderBytes() []byte
}

type BTPDigest added in v1.3.0

type BTPDigest interface {
	Bytes() []byte
	Hash() []byte
	NetworkTypeDigests() []NetworkTypeDigest
	NetworkTypeDigestFor(ntid int64) NetworkTypeDigest

	// NetworkTypeIDFromNID returns ntid for nid in this digest. Returns
	// wrapped ErrNotFound if nid is not found in this digest.
	NetworkTypeIDFromNID(nid int64) (int64, error)

	// Flush writes this BTPDigest and its connected objects.
	// If a BTPDigest is created by a BTPSection and the BTPSection is created
	// by btp.SectionBuilder, the BTPDigest has all the BTPMessageList's and
	// the BTPMessage's in the section as its connected objects. Thus, they are
	// all written when Flush is called. In other cases, a BTPDigest has no
	// connected objects. Thus, only the BTPDigest itself is written when Flush
	// is called.
	Flush(dbase db.Database) error
	NetworkSectionFilter() BitSetFilter
	NTSHashEntryList

	// NTSVoteCount returns NTS vote count for this digest.
	// pcm is the nextPCM in block(h-1) where the digest is in block(h).
	NTSVoteCount(pcm BTPProofContextMap) (int, error)
}

type BTPMessage added in v1.3.0

type BTPMessage interface {
	Hash() []byte
	Bytes() []byte
}

type BTPMessageList added in v1.3.0

type BTPMessageList interface {
	Bytes() []byte
	MessagesRoot() []byte
	Len() int64
	Get(idx int) (BTPMessage, error)
}

type BTPNetwork added in v1.3.0

type BTPNetwork interface {
	StartHeight() int64
	Name() string
	Owner() Address
	NetworkTypeID() int64
	Open() bool
	NextMessageSN() int64
	NextProofContextChanged() bool
	PrevNetworkSectionHash() []byte
	LastNetworkSectionHash() []byte
	ToJSON() map[string]interface{}
}

type BTPNetworkType added in v1.3.0

type BTPNetworkType interface {
	UID() string
	NextProofContextHash() []byte
	NextProofContext() []byte
	OpenNetworkIDs() []int64
	ToJSON() map[string]interface{}
}

type BTPProof added in v1.3.0

type BTPProof interface {
	Bytes() []byte
	Add(pp BTPProofPart)
	ValidatorCount() int
	ProofPartAt(i int) BTPProofPart
}

type BTPProofContext added in v1.3.0

type BTPProofContext interface {
	Hash() []byte
	Bytes() []byte
	NewProofPart(decisionHash []byte, wp WalletProvider) (BTPProofPart, error)
	NewProofPartFromBytes(ppBytes []byte) (BTPProofPart, error)
	VerifyPart(decisionHash []byte, pp BTPProofPart) (int, error)
	NewProof() BTPProof
	NewProofFromBytes(proofBytes []byte) (BTPProof, error)
	Verify(decisionHash []byte, p BTPProof) error
	DSA() string
	UID() string
	NewDecision(
		srcNetworkUID []byte,
		ntid int64,
		height int64,
		round int32,
		ntsHash []byte,
	) BytesHasher
}

type BTPProofContextMap added in v1.3.0

type BTPProofContextMap interface {
	ProofContextFor(ntid int64) (BTPProofContext, error)
	Update(src BTPProofContextMapUpdateSource) (BTPProofContextMap, error)
	Verify(
		srcUID []byte, height int64, round int32, bd BTPDigest,
		ntsdProves NTSDProofList,
	) error
}

type BTPProofContextMapUpdateSource added in v1.3.0

type BTPProofContextMapUpdateSource interface {
	BTPSection() (BTPSection, error)
	NextProofContextMap() (BTPProofContextMap, error)
}

type BTPProofPart added in v1.3.0

type BTPProofPart interface {
	Bytes() []byte
}

type BTPSection added in v1.3.0

type BTPSection interface {
	Digest() BTPDigest
	NetworkTypeSections() []NetworkTypeSection
	NetworkTypeSectionFor(ntid int64) (NetworkTypeSection, error)
}

type BaseWallet added in v1.3.0

type BaseWallet interface {
	Sign(data []byte) ([]byte, error)
	PublicKey() []byte
}

type BitSetFilter added in v1.3.0

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

func BitSetFilterFromBytes added in v1.3.0

func BitSetFilterFromBytes(s []byte, capInBytes int) BitSetFilter

func MakeBitSetFilter added in v1.3.0

func MakeBitSetFilter(capInBytes int) BitSetFilter

func (BitSetFilter) Bytes added in v1.3.0

func (f BitSetFilter) Bytes() []byte

func (*BitSetFilter) Set added in v1.3.0

func (f *BitSetFilter) Set(idx int64)

func (BitSetFilter) Test added in v1.3.0

func (f BitSetFilter) Test(idx int64) bool

type Block

type Block interface {
	BlockData
	NextValidators() ValidatorList

	// Copy returns goroutine safe copy
	Copy() Block

	BTPDigest() (BTPDigest, error)
	BTPSection() (BTPSection, error)
	NextProofContextMap() (BTPProofContextMap, error)
}

type BlockCandidate

type BlockCandidate interface {
	Block
	Dup() BlockCandidate
	Dispose()
}

type BlockData

type BlockData interface {
	Version() int
	ID() []byte
	Height() int64
	PrevID() []byte
	NextValidatorsHash() []byte
	// Votes returns votes. Its voters are subset of previous-previous block's
	// next validators
	Votes() CommitVoteSet
	NormalTransactions() TransactionList
	PatchTransactions() TransactionList
	Timestamp() int64
	Proposer() Address // can be nil. e.g. in genesis block.
	LogsBloom() LogsBloom
	Result() []byte

	MarshalHeader(w io.Writer) error
	MarshalBody(w io.Writer) error
	Marshal(w io.Writer) error

	ToJSON(version JSONVersion) (interface{}, error)
	NewBlock(tr Transition) Block
	Hash() []byte
	NetworkSectionFilter() BitSetFilter
	NTSHashEntryList() (NTSHashEntryList, error)
	BTPDigest() (BTPDigest, error)
}

type BlockDataFactory added in v1.2.11

type BlockDataFactory interface {
	NewBlockDataFromReader(r io.Reader) (BlockData, error)
}

type BlockInfo

type BlockInfo interface {
	Height() int64
	Timestamp() int64
}

Block information used by service manager.

type BlockManager

type BlockManager interface {
	GetBlockByHeight(height int64) (Block, error)
	GetLastBlock() (Block, error)
	GetBlock(id []byte) (Block, error)

	// WaitForBlock returns a channel that receives the block with the given
	// height.
	WaitForBlock(height int64) (<-chan Block, error)

	// NewBlockDataFromReader creates a BlockData from reader. The returned block
	// shall be imported by ImportBlock before it is Committed or Finalized.
	NewBlockDataFromReader(r io.Reader) (BlockData, error)

	// Propose proposes a Block following the parent Block.
	// The result is asynchronously notified by cb. canceler cancels the
	// operation. canceler returns true and cb is not called if the
	// cancellation was successful. The proposed block can be Committed or
	// Finalized.
	Propose(
		parentID []byte,
		votes CommitVoteSet,
		cb func(BlockCandidate, error),
	) (canceler Canceler, err error)

	// Import creates a Block from blockBytes and verifies the block.
	// The result is asynchronously notified by cb. canceler cancels the
	// operation. canceler returns true and cb is not called if the
	// cancellation was successful. The imported block can be Committed or
	// Finalized.
	// Perform forced state sync if the transition's execution result and block
	// result does not match and flags' ImportByForce bit is on.
	Import(r io.Reader, flags int, cb func(BlockCandidate, error)) (canceler Canceler, err error)
	ImportBlock(blk BlockData, flags int, cb func(BlockCandidate, error)) (canceler Canceler, err error)

	// Finalize updates world state according to BlockCandidate and removes non-finalized committed blocks with the same height as block from persistent storage.
	Finalize(BlockCandidate) error

	GetTransactionInfo(id []byte) (TransactionInfo, error)
	Term()

	// WaitForTransaction waits for a transaction with timestamp between
	// bi.Timestamp() - TimestampThreshold and current time +
	// TimestampThreshold. If such a transaction is available now, the function
	// returns false and callback cb is not called.
	WaitForTransaction(parentID []byte, cb func()) (bool, error)

	// SendTransactionAndWait sends a transaction, and get a channel to
	// to wait for the result of it.
	SendTransactionAndWait(result []byte, height int64, txi interface{}) (tid []byte, rc <-chan interface{}, err error)

	// WaitTransactionResult check whether it knows about the transaction
	// and wait for the result.
	WaitTransactionResult(id []byte) (rc <-chan interface{}, err error)

	// ExportBlocks exports blocks assuring specified block ranges.
	ExportBlocks(from, to int64, dst db.Database, on ProgressCallback) error

	// ExportGenesis exports genesis to the writer based on the block.
	ExportGenesis(blk BlockData, votes CommitVoteSet, writer GenesisStorageWriter) error

	// GetGenesisData returns available votes from genesis storage.
	// They are available only when it starts from genesis.
	GetGenesisData() (Block, CommitVoteSet, error)

	// NewConsensusInfo returns a ConsensusInfo with proposer of previous block
	// of blk and votes in blk.
	NewConsensusInfo(blk Block) (ConsensusInfo, error)
}

type BroadcastType

type BroadcastType byte
const (
	BroadcastAll BroadcastType = iota
	BroadcastNeighbor
	BroadcastChildren
)

func (BroadcastType) ForceSend

func (b BroadcastType) ForceSend() bool

func (BroadcastType) TTL

func (b BroadcastType) TTL() byte

type BytesHasher added in v1.3.0

type BytesHasher interface {
	Bytes() []byte
	Hash() []byte
}

type BytesList added in v1.3.0

type BytesList interface {
	Len() int
	Get(i int) []byte
}

type BytesSlice added in v1.3.0

type BytesSlice [][]byte

func (*BytesSlice) Get added in v1.3.0

func (b *BytesSlice) Get(i int) []byte

func (*BytesSlice) Len added in v1.3.0

func (b *BytesSlice) Len() int

type Canceler

type Canceler interface {
	Cancel() bool
}

type Chain

type Chain interface {
	Database() db.Database
	DoDBTask(func(database db.Database))
	Wallet() Wallet
	NID() int
	CID() int
	NetID() int
	Channel() string
	ConcurrencyLevel() int
	NormalTxPoolSize() int
	PatchTxPoolSize() int
	MaxBlockTxBytes() int
	DefaultWaitTimeout() time.Duration
	MaxWaitTimeout() time.Duration
	TransactionTimeout() time.Duration
	ChildrenLimit() int
	NephewsLimit() int
	ValidateTxOnSend() bool
	Genesis() []byte
	GenesisStorage() GenesisStorage
	CommitVoteSetDecoder() CommitVoteSetDecoder
	PatchDecoder() PatchDecoder
	PlatformName() string

	BlockManager() BlockManager
	Consensus() Consensus
	ServiceManager() ServiceManager
	NetworkManager() NetworkManager
	GetLocatorManager() (LocatorManager, error)
	Regulator() Regulator

	Init() error
	Start() error
	Stop() error
	Import(src string, height int64) error
	Prune(gs string, dbt string, height int64) error
	Backup(file string, extra []string) error
	RunTask(task string, params json.RawMessage) error
	Term() error
	State() (string, int64, error)
	IsStarted() bool
	IsStopped() bool

	// Reset resets chain. height must be 0 or greater than 1.
	// If height == 0, blockHash shall be nil or zero length
	// bytes and the function cleans up database and file systems for the chain.
	// If height > 1, blockHash shall be the hash of correct block with the
	// height and the function cleans up database and file systems for the chain
	// and prepare pruned genesis block of the height.
	Reset(gs string, height int64, blockHash []byte) error
	Verify() error

	MetricContext() context.Context
	Logger() log.Logger
	WalletFor(dsa string) BaseWallet
}

type CommitVoteSet

type CommitVoteSet interface {
	// VerifyBlock verifies a block with block votes
	VerifyBlock(block BlockData, validators ValidatorList) ([]bool, error)
	BlockVoteSetBytes() []byte
	Bytes() []byte
	Hash() []byte
	Timestamp() int64

	// VoteRound returns vote round if it is for block version >= 2. In other
	// case, the value is ignored.
	VoteRound() int32
	NTSDProofList
}

type CommitVoteSetDecoder

type CommitVoteSetDecoder func([]byte) CommitVoteSet

type Consensus

type Consensus interface {
	Start() error
	Term()
	GetStatus() *ConsensusStatus
	GetVotesByHeight(height int64) (CommitVoteSet, error)

	// GetBTPBlockHeaderAndProof returns header and proof according to the given
	// flag.
	GetBTPBlockHeaderAndProof(
		blk Block, nid int64, flag uint,
	) (btpBlk BTPBlockHeader, proof []byte, err error)
}

type ConsensusInfo added in v0.9.4

type ConsensusInfo interface {
	Proposer() Address
	Voters() ValidatorList
	Voted() []bool
}

type ConsensusStatus

type ConsensusStatus struct {
	Height   int64
	Round    int32
	Proposer bool
}

type DSAModule added in v1.3.0

type DSAModule interface {
	Name() string

	// Verify verifies format of public key.
	Verify(pubKey []byte) error

	// Canonicalize returns canonical public key.
	Canonicalize(pubKey []byte) ([]byte, error)
}

type Dir added in v1.3.0

type Dir int

type DoubleSignContext added in v1.3.10

type DoubleSignContext interface {
	AddressOf(signer []byte) Address
	Hash() []byte
	Bytes() []byte
}

type DoubleSignContextRoot added in v1.3.13

type DoubleSignContextRoot interface {
	Hash() []byte
	ContextOf(tn string) (DoubleSignContext, error)
}

type DoubleSignData added in v1.3.10

type DoubleSignData interface {
	Type() string
	Height() int64
	Signer() []byte
	Bytes() []byte
	ValidateNetwork(nid int) bool
	IsConflictWith(other DoubleSignData) bool
}

type DoubleSignDataDecoder added in v1.3.10

type DoubleSignDataDecoder func(t string, d []byte) (DoubleSignData, error)

type EventLog

type EventLog interface {
	Address() Address
	Indexed() [][]byte
	Data() [][]byte
}

type EventLogIterator

type EventLogIterator interface {
	Has() bool
	Next() error
	Get() (EventLog, error)
}

type ExecutionPhase added in v1.2.13

type ExecutionPhase int
const (
	EPhaseTransaction ExecutionPhase = iota
	EPhaseExecutionEnd
)

type FeePayment added in v0.9.6

type FeePayment interface {
	Payer() Address
	Amount() *big.Int
}

type FeePaymentIterator added in v0.9.6

type FeePaymentIterator interface {
	Has() bool
	Next() error
	Get() (FeePayment, error)
}

type GenesisStorage

type GenesisStorage interface {
	CID() (int, error)
	NID() (int, error)
	Height() int64
	Type() (GenesisType, error)
	Genesis() []byte
	Get(key []byte) ([]byte, error)
}

type GenesisStorageWriter

type GenesisStorageWriter interface {
	WriteGenesis(gtx []byte) error
	WriteData(value []byte) ([]byte, error)
	Close() error
}

type GenesisType

type GenesisType int
const (
	GenesisUnknown GenesisType = iota
	GenesisNormal
	GenesisPruned
)

type JSONVersion

type JSONVersion int
const (
	JSONVersion2 JSONVersion = iota
	JSONVersion3
	JSONVersion3Raw
	JSONVersionLast = JSONVersion3Raw
)

type LocatorManager added in v1.3.10

type LocatorManager interface {
	GetLocator(id []byte) (*TransactionLocator, error)
	Has(group TransactionGroup, id []byte, ts int64) (bool, error)
	NewTracker(group TransactionGroup, height int64, ts int64, th int64) LocatorTracker
	Start()
	Term()
}

type LocatorTracker added in v1.3.10

type LocatorTracker interface {
	Has(id []byte, ts int64) (bool, error)
	Add(list TransactionList, force bool) (int, error)
	New(height int64, ts int64, th int64) LocatorTracker
	Commit() error

	Group() TransactionGroup
	Timestamp() int64
	Threshold() int64
}

type LogsBloom

type LogsBloom interface {
	String() string
	Bytes() []byte
	CompressedBytes() []byte
	LogBytes() []byte
	Contain(lb2 LogsBloom) bool
	Merge(lb2 LogsBloom)
	Equal(lb2 LogsBloom) bool
}

type MemberIterator

type MemberIterator interface {
	Has() bool
	Next() error
	Get() (Address, error)
}

type MemberList

type MemberList interface {
	IsEmpty() bool
	Equal(MemberList) bool
	Iterator() MemberIterator
}

type MerkleNode added in v1.3.0

type MerkleNode struct {
	Dir   Dir
	Value []byte
}

type NTSDProofList added in v1.3.0

type NTSDProofList interface {
	NTSDProofCount() int
	NTSDProofAt(i int) []byte
}

type NTSHashEntryFormat added in v1.3.0

type NTSHashEntryFormat struct {
	NetworkTypeID          int64
	NetworkTypeSectionHash []byte
}

type NTSHashEntryList added in v1.3.0

type NTSHashEntryList interface {
	NTSHashEntryListFormat() []NTSHashEntryFormat
	NTSHashEntryCount() int
	NTSHashEntryAt(i int) NTSHashEntryFormat
}

type NetworkDigest added in v1.3.0

type NetworkDigest interface {
	NetworkID() int64
	NetworkSectionHash() []byte
	MessagesRoot() []byte
	MessageList(dbase db.Database, mod NetworkTypeModule) (BTPMessageList, error)
}

type NetworkError

type NetworkError interface {
	error
	Temporary() bool // Is the error temporary?
}

type NetworkManager

type NetworkManager interface {
	Start() error
	Term()

	GetPeers() []PeerID

	RegisterReactor(name string, pi ProtocolInfo, reactor Reactor, piList []ProtocolInfo, priority uint8, policy NotRegisteredProtocolPolicy) (ProtocolHandler, error)
	RegisterReactorForStreams(name string, pi ProtocolInfo, reactor Reactor, piList []ProtocolInfo, priority uint8, policy NotRegisteredProtocolPolicy) (ProtocolHandler, error)
	UnregisterReactor(reactor Reactor) error

	SetRole(version int64, role Role, peers ...PeerID)
	GetPeersByRole(role Role) []PeerID
	AddRole(role Role, peers ...PeerID)
	RemoveRole(role Role, peers ...PeerID)
	HasRole(role Role, id PeerID) bool
	Roles(id PeerID) []Role

	SetTrustSeeds(seeds string)
	SetInitialRoles(roles ...Role)
}

type NetworkSection added in v1.3.0

type NetworkSection interface {
	Hash() []byte
	NetworkID() int64

	// UpdateNumber returns FirstMessageSN() << 1 | NextProofContextChanged()
	UpdateNumber() int64
	FirstMessageSN() int64
	NextProofContextChanged() bool
	PrevHash() []byte
	MessageCount() int64
	MessagesRoot() []byte
}

type NetworkTransport

type NetworkTransport interface {
	Listen() error
	Close() error
	Dial(address string, channel string) error
	PeerID() PeerID
	Address() string
	SetListenAddress(address string) error
	GetListenAddress() string
	SetSecureSuites(channel string, secureSuites string) error
	GetSecureSuites(channel string) string
	SetSecureAeads(channel string, secureAeads string) error
	GetSecureAeads(channel string) string
}

type NetworkTypeDigest added in v1.3.0

type NetworkTypeDigest interface {
	NetworkTypeID() int64
	UID() string
	NetworkTypeSectionHash() []byte
	NetworkDigests() []NetworkDigest
	NetworkDigestFor(nid int64) NetworkDigest
	NetworkSectionsRootWithMod(mod NetworkTypeModule) []byte
	NetworkSectionToRootWithMod(mod NetworkTypeModule, nid int64) ([]MerkleNode, error)
}

type NetworkTypeModule added in v1.3.0

type NetworkTypeModule interface {
	UID() string
	Hash(data []byte) []byte
	AppendHash(out []byte, data []byte) []byte
	DSA() string
	NewProofContextFromBytes(bs []byte) (BTPProofContext, error)

	// NewProofContext returns a new proof context. The parameter keys is
	// a slice of networkType specific keys (usually a slice of addresses).
	NewProofContext(keys [][]byte) (BTPProofContext, error)
	MerkleRoot(bytesList BytesList) []byte
	MerkleProof(bytesList BytesList, idx int) []MerkleNode
	AddressFromPubKey(pubKey []byte) ([]byte, error)
	BytesByHashBucket() db.BucketID
	ListByMerkleRootBucket() db.BucketID
	NewProofFromBytes(bs []byte) (BTPProof, error)
	NetworkTypeKeyFromDSAKey(key []byte) ([]byte, error)
	DSAModule() DSAModule
}

type NetworkTypeSection added in v1.3.0

type NetworkTypeSection interface {
	NetworkTypeID() int64
	Hash() []byte
	NetworkSectionsRoot() []byte
	NetworkSectionToRoot(nid int64) ([]MerkleNode, error)
	NextProofContext() BTPProofContext
	NetworkSectionFor(nid int64) (NetworkSection, error)
	NewDecision(srcNetworkUID []byte, height int64, round int32) BytesHasher
}

type NotRegisteredProtocolPolicy added in v1.2.9

type NotRegisteredProtocolPolicy byte
const (
	NotRegisteredProtocolPolicyNone NotRegisteredProtocolPolicy = iota
	NotRegisteredProtocolPolicyDrop
	NotRegisteredProtocolPolicyClose
)

type OnResult added in v1.3.13

type OnResult func(isRelay bool, err error)

type OpType added in v1.2.13

type OpType int
const (
	Genesis OpType = iota
	Transfer
	Fee
	Issue
	Burn
	Lost
	FSDeposit
	FSWithdraw
	FSFee
	Stake
	Unstake
	Claim
	Ghost
	Reward
	RegPRep
)

type Patch

type Patch interface {
	Type() string
	Data() []byte
}

type PatchDecoder

type PatchDecoder func(t string, bs []byte) (Patch, error)

type PeerID

type PeerID interface {
	Bytes() []byte
	Equal(PeerID) bool
	String() string
}

type ProgressCallback added in v1.3.2

type ProgressCallback func(height int64, resolved, unresolved int) error

ProgressCallback is used to report progress of sync task. "height" is the height to the block to sync. "resolved" is number of already synced items. "unresolved" is number of known items to be synced. More items can be added to "unresolved" after syncing known items. Some of items may not be counted.

type ProtocolHandler

type ProtocolHandler interface {
	Broadcast(pi ProtocolInfo, b []byte, bt BroadcastType) error
	Multicast(pi ProtocolInfo, b []byte, role Role) error
	Unicast(pi ProtocolInfo, b []byte, id PeerID) error
	GetPeers() []PeerID
}

type ProtocolInfo

type ProtocolInfo uint16
const (
	ProtoP2P ProtocolInfo = iota << 8
	ProtoStateSync
	ProtoTransaction
	ProtoConsensus
	ProtoFastSync
	ProtoConsensusSync
	ProtoReserved
)

func NewProtocolInfo

func NewProtocolInfo(id byte, version byte) ProtocolInfo

func (ProtocolInfo) ID

func (pi ProtocolInfo) ID() byte

func (ProtocolInfo) String

func (pi ProtocolInfo) String() string

func (ProtocolInfo) Uint16

func (pi ProtocolInfo) Uint16() uint16

func (ProtocolInfo) Version

func (pi ProtocolInfo) Version() byte

type Reactor

type Reactor interface {
	//case broadcast and multicast, if return (true,nil) then rebroadcast
	OnReceive(pi ProtocolInfo, b []byte, id PeerID) (bool, error)
	OnJoin(id PeerID)
	OnLeave(id PeerID)
}

type Receipt

type Receipt interface {
	Bytes() []byte
	To() Address
	CumulativeStepUsed() *big.Int
	StepPrice() *big.Int
	StepUsed() *big.Int
	Status() Status
	SCOREAddress() Address
	Check(r Receipt) error
	ToJSON(version JSONVersion) (interface{}, error)
	LogsBloom() LogsBloom
	BTPMessages() *list.List
	EventLogIterator() EventLogIterator
	FeePaymentIterator() FeePaymentIterator
	LogsBloomDisabled() bool
	GetProofOfEvent(int) ([][]byte, error)
}

type ReceiptIterator

type ReceiptIterator interface {
	Has() bool
	Next() error
	Get() (Receipt, error)
}

type ReceiptList

type ReceiptList interface {
	Get(int) (Receipt, error)
	GetProof(n int) ([][]byte, error)
	Iterator() ReceiptIterator
	Hash() []byte
	Flush() error
}

type Regulator

type Regulator interface {
	MaxTxCount() int
	OnPropose(now time.Time)
	CommitTimeout() time.Duration
	MinCommitTimeout() time.Duration
	OnTxExecution(count int, ed time.Duration, fd time.Duration)
	SetBlockInterval(i time.Duration, d time.Duration)
}

type Revision added in v0.9.1

type Revision int64
const (
	InputCostingWithJSON Revision = 1 << (8 + iota)
	ExpandErrorCode
	UseChainID
	UseMPTOnEvents
	UseCompactAPIInfo
	AutoAcceptGovernance
	LegacyFeeCharge
	LegacyFallbackCheck
	LegacyContentCount
	LegacyBalanceCheck
	LegacyInputJSON
	LegacyNoTimeout
	FixLostFeeByDeposit
	MultipleFeePayers
	PurgeEnumCache
	ContractSetEvent
	FixMapValues
	ReportDoubleSign
	FixJCLSteps
	ReportConfigureEvents
	LastRevisionBit

	UseNIDInConsensusMessage = ReportDoubleSign
)

func (Revision) AutoAcceptGovernance added in v0.9.6

func (r Revision) AutoAcceptGovernance() bool

func (Revision) ExpandErrorCode added in v0.9.1

func (r Revision) ExpandErrorCode() bool

func (Revision) Has added in v0.9.6

func (r Revision) Has(flag Revision) bool

func (Revision) InputCostingWithJSON added in v0.9.1

func (r Revision) InputCostingWithJSON() bool

func (Revision) LegacyBalanceCheck added in v0.9.6

func (r Revision) LegacyBalanceCheck() bool

func (Revision) LegacyContentCount added in v0.9.6

func (r Revision) LegacyContentCount() bool

func (Revision) LegacyFallbackCheck added in v0.9.6

func (r Revision) LegacyFallbackCheck() bool

func (Revision) LegacyFeeCharge added in v0.9.10

func (r Revision) LegacyFeeCharge() bool

func (Revision) UseChainID added in v0.9.1

func (r Revision) UseChainID() bool

func (Revision) UseCompactAPIInfo added in v0.9.1

func (r Revision) UseCompactAPIInfo() bool

func (Revision) UseMPTOnEvents added in v0.9.1

func (r Revision) UseMPTOnEvents() bool

func (Revision) Value added in v0.9.1

func (r Revision) Value() int

type Role

type Role byte
const (
	RoleNormal Role = iota
	RoleSeed
	RoleValidator
	RoleReserved
)

type SCOREStatus added in v1.2.11

type SCOREStatus interface {
	ToJSON(height int64, version JSONVersion) (interface{}, error)
}

type ServiceManager

type ServiceManager interface {
	TransitionManager

	// Start starts service module.
	Start()
	// Term terminates serviceManager instance.
	Term()

	// TransactionFromBytes returns a Transaction instance from bytes.
	TransactionFromBytes(b []byte, blockVersion int) (Transaction, error)

	// GenesisTransactionFromBytes returns a Genesis Transaction instance from bytes.
	GenesisTransactionFromBytes(b []byte, blockVersion int) (Transaction, error)

	// TransactionListFromHash returns a TransactionList instance from
	// the hash of transactions or nil when no transactions exist.
	// It assumes it's called only by new version block, so it doesn't receive
	// version value.
	TransactionListFromHash(hash []byte) TransactionList

	// TransactionListFromSlice returns list of transactions.
	TransactionListFromSlice(txs []Transaction, version int) TransactionList

	// ReceiptListFromResult returns list of receipts from result.
	ReceiptListFromResult(result []byte, g TransactionGroup) (ReceiptList, error)

	// SendTransaction adds transaction to a transaction pool.
	SendTransaction(result []byte, height int64, tx interface{}) ([]byte, error)

	// SendPatch sends a patch
	SendPatch(patch Patch) error

	// Call handles read-only contract API call.
	Call(result []byte, vl ValidatorList, js []byte, bi BlockInfo) (interface{}, error)

	// ValidatorListFromHash returns ValidatorList from hash.
	ValidatorListFromHash(hash []byte) ValidatorList

	// GetBalance returns balance of the account
	GetBalance(result []byte, addr Address) (*big.Int, error)

	// GetTotalSupply returns total supplied coin
	GetTotalSupply(result []byte) (*big.Int, error)

	// GetNetworkID returns network ID of the state
	GetNetworkID(result []byte) (int64, error)

	// GetChainID returns chain ID of the state
	GetChainID(result []byte) (int64, error)

	// GetAPIInfo returns API info of the contract
	GetAPIInfo(result []byte, addr Address) (APIInfo, error)

	// GetSCOREStatus returns status of the contract
	GetSCOREStatus(result []byte, addr Address) (SCOREStatus, error)

	// GetMembers returns network member list
	GetMembers(result []byte) (MemberList, error)

	// GetRoundLimit returns round limit
	GetRoundLimit(result []byte, vl int) int64

	// GetStepPrice returns the step price of the state
	GetStepPrice(result []byte) (*big.Int, error)

	// GetMinimizeBlockGen returns minimize empty block generation flag
	GetMinimizeBlockGen(result []byte) bool

	// GetNextBlockVersion returns version of next block
	GetNextBlockVersion(result []byte) int

	// GetRevision returns revision
	GetRevision(result []byte) Revision

	// BTPSectionFromResult returns BTPSection for the result
	BTPSectionFromResult(result []byte) (BTPSection, error)

	// BTPDigestFromResult returns BTPDigest for the result
	BTPDigestFromResult(result []byte) (BTPDigest, error)

	// NextProofContextMapFromResult returns BTPProofContextMap for the result
	NextProofContextMapFromResult(result []byte) (BTPProofContextMap, error)

	BTPNetworkTypeFromResult(result []byte, ntid int64) (BTPNetworkType, error)

	BTPNetworkFromResult(result []byte, nid int64) (BTPNetwork, error)

	BTPNetworkTypeIDsFromResult(result []byte) ([]int64, error)

	// HasTransaction returns whether it has specified transaction in the pool
	HasTransaction(id []byte) bool

	// SendTransactionAndWait send transaction and return channel for result
	SendTransactionAndWait(result []byte, height int64, tx interface{}) ([]byte, <-chan interface{}, error)

	// WaitTransactionResult return channel for result.
	WaitTransactionResult(id []byte) (<-chan interface{}, error)

	// ExportResult exports all related entries related with the result
	// should be exported to the database
	ExportResult(result []byte, vh []byte, dst db.Database) error

	// ImportResult imports all related entries related with the result
	// should be imported from the database
	ImportResult(result []byte, vh []byte, src db.Database) error

	// ExecuteTransaction executes the transaction on the specified state.
	// Then it returns the expected result of the transaction.
	// It ignores supplied step limit.
	ExecuteTransaction(result []byte, vh []byte, js []byte, bi BlockInfo) (Receipt, error)

	// AddSyncRequest add sync request for specified data.
	AddSyncRequest(id db.BucketID, key []byte) error

	// SendDoubleSignReport sends double sign reports. result and vh represents base state of the data.
	// If the data has votes for the height H, then result is base state deciding whether it has double signs.
	// So, result and vh should come from previous block at the height H-1.
	SendDoubleSignReport(result []byte, vh []byte, data []DoubleSignData) error
}

type SkipTransactionPatch

type SkipTransactionPatch interface {
	Patch
	Height() int64 // height of the block to skip execution of

	// Verify check internal data is correct
	Verify(vl ValidatorList, roundLimit int64, nid int) error
}

type Status

type Status int
const (
	StatusSuccess Status = iota
	StatusUnknownFailure
	StatusContractNotFound
	StatusMethodNotFound
	StatusMethodNotPayable
	StatusIllegalFormat
	StatusInvalidParameter
	StatusInvalidInstance
	StatusInvalidContainerAccess
	StatusAccessDenied
	StatusOutOfStep
	StatusOutOfBalance
	StatusTimeout
	StatusStackOverflow
	StatusSkipTransaction
	StatusInvalidPackage
	StatusReverted Status = 32

	StatusLimitRev5 Status = 99
	StatusLimit     Status = 999
)

func (Status) String

func (s Status) String() string

type Timestamper

type Timestamper interface {
	GetVoteTimestamp(h, ts int64) int64
	GetBlockTimestamp(h, ts int64) int64
}

type TraceBlock added in v1.2.13

type TraceBlock interface {
	ID() []byte
	GetReceipt(txIndex int) Receipt
}

type TraceCallback

type TraceCallback interface {
	OnLog(level TraceLevel, msg string)
	OnEnd(e error)

	OnTransactionStart(txIndex int, txHash []byte, isBlockTx bool) error
	OnTransactionReset() error
	OnTransactionEnd(txIndex int, txHash []byte) error
	OnFrameEnter() error
	OnFrameExit(success bool) error
	OnBalanceChange(opType OpType, from, to Address, amount *big.Int) error
}

type TraceInfo

type TraceInfo struct {
	TraceMode  TraceMode
	TraceBlock TraceBlock

	Range TraceRange
	// Group and Index are valid only if Range is TraceRangeTransaction
	Group TransactionGroup
	Index int

	Callback TraceCallback
}

type TraceLevel

type TraceLevel int
const (
	TDebugLevel TraceLevel = iota
	TTraceLevel
	TSystemLevel
)

type TraceMode added in v1.2.13

type TraceMode int
const (
	TraceModeNone TraceMode = iota
	TraceModeInvoke
	TraceModeBalanceChange
)

type TraceRange added in v1.2.13

type TraceRange int
const (
	TraceRangeBlock TraceRange = iota
	TraceRangeTransaction
	TraceRangeBlockTransaction
)

type Transaction

type Transaction interface {
	Group() TransactionGroup
	ID() []byte
	From() Address
	Bytes() []byte
	Hash() []byte
	Verify() error
	Version() int
	ToJSON(version JSONVersion) (interface{}, error)
	ValidateNetwork(nid int) bool
}

type TransactionGroup

type TransactionGroup int
const (
	TransactionGroupPatch TransactionGroup = iota
	TransactionGroupNormal
)

type TransactionInfo

type TransactionInfo interface {
	Block() Block
	Index() int
	Group() TransactionGroup
	Transaction() (Transaction, error)
	GetReceipt() (Receipt, error)
}

type TransactionIterator

type TransactionIterator interface {
	Has() bool
	Next() error
	Get() (Transaction, int, error)
}

type TransactionList

type TransactionList interface {
	Get(int) (Transaction, error)
	Iterator() TransactionIterator

	// length if Hash() is 0 iff empty
	Hash() []byte

	Equal(TransactionList) bool
	Flush() error
}

type TransactionLocator added in v1.3.10

type TransactionLocator struct {
	BlockHeight      int64
	TransactionGroup TransactionGroup
	IndexInGroup     int
}

type Transition

type Transition interface {
	PatchTransactions() TransactionList
	NormalTransactions() TransactionList

	PatchReceipts() ReceiptList
	NormalReceipts() ReceiptList
	// Execute executes this transition.
	// The result is asynchronously notified by cb. canceler can be used
	// to cancel it after calling Execute. After canceler returns true,
	// all succeeding cb functions may not be called back.
	// REMARK: It is assumed to be called once. Any additional call returns
	// error.
	Execute(cb TransitionCallback) (canceler func() bool, err error)

	// ExecuteForTrace executes this transition until it executes the transaction
	// at offset `n` of normal transactions. If it fails, then OnValidate or
	// OnExecute will be called with an error.
	ExecuteForTrace(ti TraceInfo) (canceler func() bool, err error)

	// Result returns service manager defined result bytes.
	// For example, it can be "[world_state_hash][patch_tx_hash][normal_tx_hash]".
	Result() []byte

	// NextValidators returns the addresses of validators as a result of
	// transaction processing.
	// It may return nil before cb.OnExecute is called back by Execute.
	NextValidators() ValidatorList

	// LogsBloom returns log bloom filter for this transition.
	// It may return nil before cb.OnExecute is called back by Execute.
	LogsBloom() LogsBloom

	// BlockInfo returns block information for the normal transaction.
	BlockInfo() BlockInfo

	// Equal check equality of inputs of transition.
	Equal(Transition) bool

	// BTPSection returns the BTPSection as a result of transaction processing.
	// It may return empty one before cb.OnExecute is called back by Execute.
	BTPSection() BTPSection
}

type TransitionCallback

type TransitionCallback interface {
	// Called if validation is done.
	OnValidate(Transition, error)

	// Called if execution is done.
	OnExecute(Transition, error)
}

TransitionCallback provides transition change notifications. All functions are called back with the same Transition instance for the convenience.

type TransitionManager

type TransitionManager interface {
	// ProposeTransition proposes a Transition following the parent Transition.
	// Returned Transition always passes validation.
	ProposeTransition(parent Transition, bi BlockInfo, csi ConsensusInfo) (Transition, error)
	// CreateInitialTransition creates an initial Transition.
	CreateInitialTransition(result []byte, nextValidators ValidatorList) (Transition, error)
	// CreateTransition creates a Transition following parent Transition.
	CreateTransition(parent Transition, txs TransactionList, bi BlockInfo, csi ConsensusInfo, validated bool) (Transition, error)
	// GetPatches returns all patch transactions based on the parent transition.
	// bi is the block info of the block that will contain the patches
	GetPatches(parent Transition, bi BlockInfo) TransactionList
	// PatchTransition creates a Transition by overwriting patches on the transition.
	// bi is the block info of the block that contains the patches,
	// or nil if the patches are already prevalidated.
	PatchTransition(transition Transition, patches TransactionList, bi BlockInfo) Transition
	CreateSyncTransition(transition Transition, result []byte, vlHash []byte, noBuffer bool) Transition
	// Finalize finalizes data related to the transition. It usually stores
	// data to a persistent storage. opt indicates which data are finalized.
	// It should be called for every transition.
	Finalize(transition Transition, opt int) error
	// WaitTransaction waits for a transaction with timestamp between
	// bi.Timestamp() - TimestampThreshold and current time +
	// TimestampThreshold. If such a transaction is available now, the function
	// returns false and callback cb is not called.
	WaitForTransaction(parent Transition, bi BlockInfo, cb func()) bool
}

TransitionManager provides Transition APIs. For a block proposal, it is usually called as follows:

  1. GetPatches
  2. if any changes of patches exist from GetPatches 2.1 PatchTransaction 2.2 Transition.Execute
  3. ProposeTransition
  4. Transition.Execute

For a block validation,

  1. if any changes of patches are detected from a new block 1.1 PatchTransition 1.2 Transition.Execute
  2. create Transaction instances by TransactionFromBytes
  3. CreateTransition with TransactionList
  4. Transition.Execute

type Validator

type Validator interface {
	Address() Address

	// PublicKey returns public key of the validator.
	// If it doesn't have, then it return nil
	PublicKey() []byte

	Bytes() []byte
}

type ValidatorList

type ValidatorList interface {
	Hash() []byte
	Bytes() []byte
	IndexOf(Address) int
	Len() int
	Get(i int) (Validator, bool)
}

type Wallet

type Wallet interface {
	BaseWallet
	Address() Address
}

type WalletProvider added in v1.3.0

type WalletProvider interface {
	// WalletFor returns public key for dsa.
	WalletFor(dsa string) BaseWallet
}

type ZeroNTSHashEntryList added in v1.3.0

type ZeroNTSHashEntryList struct {
}

func (ZeroNTSHashEntryList) NTSHashEntryAt added in v1.3.0

func (z ZeroNTSHashEntryList) NTSHashEntryAt(i int) NTSHashEntryFormat

func (ZeroNTSHashEntryList) NTSHashEntryCount added in v1.3.0

func (z ZeroNTSHashEntryList) NTSHashEntryCount() int

func (ZeroNTSHashEntryList) NTSHashEntryListFormat added in v1.3.0

func (z ZeroNTSHashEntryList) NTSHashEntryListFormat() []NTSHashEntryFormat

Jump to

Keyboard shortcuts

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