leader

package
v0.0.0-...-bb876ca Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2017 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package leader implements leader election between cored processes of a Chain Core.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoLeader = errors.New("no leader process")

ErrNoLeader is returned from Address when no process is currently leader.

Functions

This section is empty.

Types

type Leader

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

Leader provides access to the Core leader process.

func Run

func Run(ctx context.Context, db pg.DB, addr string, lead func(context.Context)) *Leader

Run starts a goroutine, trying once every five seconds to become the leader for the core. If it succeeds, then it calls the function lead (for generating or fetching blocks, and for expiring reservations) and enters a leadership-keepalive loop.

Function lead is called when the local process becomes the leader. Its context is canceled when the process is deposed as leader.

Run returns a pointer to a Leader struct that can be queried to check the state of the process or find the current leader.

The Chain Core has up to a 1.5-second refractory period after shutdown, during which no process may be leader.

func (*Leader) Address

func (l *Leader) Address(ctx context.Context) (string, error)

Address retrieves a routable address of the current Core leader.

func (*Leader) State

func (l *Leader) State() ProcessState

State returns the current state of this process.

type ProcessState

type ProcessState int

ProcessState is an enum describing the current state of the process. A recovering process has become leader but is still recovering the blockchain state. Some functionality is not available until the process enters the Leading state.

const (
	Following ProcessState = iota
	Recovering
	Leading
)

func (ProcessState) String

func (ps ProcessState) String() string

Jump to

Keyboard shortcuts

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