coordinator

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2020 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoTipsGiven is returned when no tips were given to issue a checkpoint.
	ErrNoTipsGiven = errors.New("no tips given")
	// ErrNetworkBootstrapped is returned when the flag for bootstrap network was given, but a state file already exists.
	ErrNetworkBootstrapped = errors.New("network already bootstrapped")
	// ErrInvalidSiblingsTrytesLength is returned when the computed siblings trytes do not fit into the signature message fragment.
	ErrInvalidSiblingsTrytesLength = errors.New("siblings trytes too long")
)

Functions

func CheckpointCaller

func CheckpointCaller(handler interface{}, params ...interface{})

CheckpointCaller is used to signal issued checkpoints.

func MilestoneCaller

func MilestoneCaller(handler interface{}, params ...interface{})

MilestoneCaller is used to signal issued milestones.

func MilestoneMerkleTreeHashFuncWithName added in v0.5.0

func MilestoneMerkleTreeHashFuncWithName(name string) crypto.Hash

MilestoneMerkleTreeHashFuncWithName maps the passed name to one of the supported crypto.Hash hashing functions. Also verifies that the available function is available or else panics.

Types

type Coordinator

type Coordinator struct {

	// events of the coordinator
	Events *CoordinatorEvents
	// contains filtered or unexported fields
}

Coordinator is used to issue signed transactions, called "milestones" to secure an IOTA network and prevent double spends.

func New

func New(seed trinary.Hash, securityLvl consts.SecurityLevel, merkleTreeDepth int, minWeightMagnitude int, stateFilePath string, milestoneIntervalSec int, powHandler *pow.Handler, sendBundleFunc SendBundleFunc, milestoneMerkleHashFunc crypto.Hash) *Coordinator

New creates a new coordinator instance.

func (*Coordinator) Bootstrap added in v0.5.0

func (coo *Coordinator) Bootstrap() (hornet.Hash, error)

Bootstrap creates the first milestone, if the network was not bootstrapped yet. Returns critical errors.

func (*Coordinator) GetInterval

func (coo *Coordinator) GetInterval() time.Duration

GetInterval returns the interval milestones should be issued.

func (*Coordinator) InitMerkleTree

func (coo *Coordinator) InitMerkleTree(filePath string, cooAddress trinary.Hash) error

InitMerkleTree loads the Merkle tree file and checks the coordinator address.

func (*Coordinator) InitState

func (coo *Coordinator) InitState(bootstrap bool, startIndex milestone.Index) error

InitState loads an existing state file or bootstraps the network.

func (*Coordinator) IssueCheckpoint added in v0.5.0

func (coo *Coordinator) IssueCheckpoint(checkpointIndex int, lastCheckpointHash hornet.Hash, tips hornet.Hashes) (hornet.Hash, error)

IssueCheckpoint tries to create and send a "checkpoint" to the network. a checkpoint can contain multiple chained transactions to reference big parts of the unconfirmed cone. this is done to keep the confirmation rate as high as possible, even if there is an attack ongoing. new checkpoints always reference the last checkpoint or the last milestone if it is the first checkpoint after a new milestone.

func (*Coordinator) IssueMilestone added in v0.5.0

func (coo *Coordinator) IssueMilestone(trunkHash hornet.Hash, branchHash hornet.Hash) (hornet.Hash, error, error)

IssueMilestone creates the next milestone. Returns non-critical and critical errors.

func (*Coordinator) State added in v0.5.0

func (coo *Coordinator) State() *State

State returns the current state of the coordinator.

type CoordinatorEvents added in v0.5.0

type CoordinatorEvents struct {
	// Fired when a checkpoint transaction is issued.
	IssuedCheckpointTransaction *events.Event
	// Fired when a milestone is issued.
	IssuedMilestone *events.Event
}

CoordinatorEvents are the events issued by the coordinator.

type SendBundleFunc

type SendBundleFunc = func(b bundle.Bundle, isMilestone bool) error

SendBundleFunc is a function which sends a bundle to the network.

type State

type State struct {
	encoding.BinaryMarshaler
	encoding.BinaryUnmarshaler

	LatestMilestoneIndex milestone.Index
	LatestMilestoneHash  hornet.Hash
	LatestMilestoneTime  int64

	// LatestMilestoneTransactions are the transaction hashes of the latest milestone
	LatestMilestoneTransactions hornet.Hashes
}

State stores the latest state of the coordinator.

func (*State) MarshalBinary

func (cs *State) MarshalBinary() (data []byte, err error)

MarshalBinary returns the binary representation of the coordinator state.

func (*State) UnmarshalBinary

func (cs *State) UnmarshalBinary(data []byte) error

UnmarshalBinary parses the binary encoded representation of the coordinator state.

Jump to

Keyboard shortcuts

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