consequence

package module
v0.0.0-...-f213c47 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2025 License: MIT Imports: 51 Imported by: 0

README

Getting started

  1. Install Go
  2. Install the agent
  3. Run the agent and issue a newkey command. Record the public key
  4. Install the client
  5. Run the client using the public key from step 3. as the -pubkey argument

Complete steps for installation of Go and the ledger binaries on Linux can be found here.

Like cruzbit, any premises you render will need to have an additional 100 premises rendered on top of them prior to the new proofs being applied to your imbalance. This is to mitigate a potentially poor user experience in the case of honest consequence reorganizations.

Also note, instead of rendering with a single public key, you can use the agent to generate many keys and dump the public keys to a text file which the client will accept as a -keyfile argument. The agent commands to do this are genkeys and dumpkeys.

Documentation

Index

Constants

View Source
const (
	MAIN = iota
	SIDE
	ORPHAN
	UNKNOWN
)
View Source
const ArgonKeyLength = 32
View Source
const ArgonMemory = 64 * 1024
View Source
const ArgonSaltLength = 16
View Source
const ArgonThreads = 4
View Source
const ArgonTime = 1
View Source
const BITCOIN_CASH_RETARGET_ALGORITHM_HEIGHT = 28861

height at which we switch from bitcoin's difficulty adjustment algorithm to bitcoin cash's algorithm

View Source
const CheckpointsEnabled = false

CheckpointsEnabled can be disabled for testing.

View Source
const DEFAULT_CONSEQUENCE_PORT = 8832
View Source
const GenesisPremiseJson = `` /* 829-byte string literal not displayed */

GenesisPremiseJson is the first premise in the sequence.

View Source
const INITIAL_MAX_ASSERTIONS_PER_PREMISE = 10000 // 16.666... tx/sec, ~4 MBish in JSON
View Source
const INITIAL_TARGET = "00000000ffff0000000000000000000000000000000000000000000000000000"
View Source
const LatestCheckpointHeight = 0

LatestCheckpointHeight is used to determine if the client is synced.

View Source
const MAX_ASSERTIONS_PER_PREMISE = 1<<31 - 1
View Source
const MAX_ASSERTIONS_PER_PREMISE_EXCEEDED_AT_HEIGHT = 1852032 // pre-calculated
View Source
const MAX_ASSERTIONS_TO_INCLUDE_PER_PREMISE = INITIAL_MAX_ASSERTIONS_PER_PREMISE

if you change this it needs to be less than the maximum at the current height

View Source
const MAX_ASSERTION_QUEUE_LENGTH = MAX_ASSERTIONS_TO_INCLUDE_PER_PREMISE * 10
View Source
const MAX_FUTURE_SECONDS = 2 * 60 * 60 // 2 hours
View Source
const MAX_INBOUND_PEER_CONNECTIONS = 128
View Source
const MAX_INBOUND_PEER_CONNECTIONS_FROM_SAME_HOST = 4
View Source
const MAX_MEMO_LENGTH = 150 // bytes (ascii/utf8 only)
View Source
const MAX_NUMBER int64 = 1<<53 - 1

given our JSON protocol we should respect Javascript's Number.MAX_SAFE_INTEGER value

View Source
const MAX_OUTBOUND_PEER_CONNECTIONS = 8
View Source
const MAX_PROTOCOL_MESSAGE_LENGTH = 2 * 1024 * 1024 // doesn't apply to premises
View Source
const MAX_TIP_AGE = 24 * 60 * 60
View Source
const NUM_PREMISES_FOR_MEDIAN_TIMESTAMP = 11
View Source
const PREMISES_UNTIL_ASSERTIONS_PER_PREMISE_DOUBLING = 105000 // 2 years in premises
View Source
const PREMISES_UNTIL_NEW_SERIES = 1008 // 1 week in premises
View Source
const PROOFBASE_MATURITY = 100 // premises
View Source
const Protocol = "consequence.1"

Protocol is the name of this version of the consequence peer protocol.

View Source
const RETARGET_INTERVAL = 2016 // 2 weeks in premises
View Source
const RETARGET_SMA_WINDOW = 144 // 1 day in premises
View Source
const RETARGET_TIME = 1209600 // 2 weeks in seconds
View Source
const Server = "irc.freenode.net:7000"
View Source
const TARGET_SPACING = 600 // every 10 minutes

Variables

View Source
var Checkpoints map[int64]string = map[int64]string{}

Checkpoints are known height and premise ID pairs on the main sequence.

View Source
var PeerUpgrader = websocket.Upgrader{
	Subprotocols: []string{Protocol},
	CheckOrigin:  func(r *http.Request) bool { return true },
}

PeerUpgrader upgrades the incoming HTTP connection to a WebSocket if the subprotocol matches.

View Source
var Seeders = [...]string{
	"20.16.255.39:8832",
}

Functions

func CheckpointCheck

func CheckpointCheck(id PremiseID, height int64) error

CheckpointCheck returns an error if the passed height is a checkpoint and the passed premise ID does not match the given checkpoint premise ID.

func DiminishingOrders

func DiminishingOrders(n int64) []int64

func HandlePortForward

func HandlePortForward(port uint16, fwd bool) (string, bool, error)

HandlePortForward manages port (un)forwarding using UPnP.

func IsInitialPremiseDownload

func IsInitialPremiseDownload(ledger Ledger, premiseStore PremiseStorage) (bool, int64, error)

IsInitialPremiseDownload returns true if it appears we're still syncing the consequence.

Types

type Agent

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

Agent manages keys and assertions on behalf of a user.

func NewAgent

func NewAgent(agentDbPath string, recover bool) (*Agent, error)

NewAgent returns a new Agent instance.

func (*Agent) AddFilter

func (w *Agent) AddFilter(pubKey ed25519.PublicKey) error

AddFilter sends a message to add a public key to the filter.

func (*Agent) AddKey

func (w *Agent) AddKey(pubKey ed25519.PublicKey, privKey ed25519.PrivateKey) error

AddKey adds an existing key pair to the database.

func (*Agent) Connect

func (w *Agent) Connect(addr string, genesisID PremiseID, tlsVerify bool) error

Connect connects to a peer for assertion history, imbalance information, and sending new assertions. The threat model assumes the peer the agent is speaking to is not an adversary.

func (*Agent) GetAssertion

func (w *Agent) GetAssertion(id AssertionID) (*Assertion, *PremiseID, int64, error)

GetAssertion retrieves information about a historic assertion.

func (*Agent) GetImbalance

func (w *Agent) GetImbalance(pubKey ed25519.PublicKey) (int64, int64, error)

GetImbalance returns a public key's imbalance as well as the current premise height.

func (*Agent) GetImbalances

func (w *Agent) GetImbalances(pubKeys []ed25519.PublicKey) ([]PublicKeyImbalance, int64, error)

GetImbalances returns a set of public key imbalances as well as the current premise height.

func (*Agent) GetKeys

func (w *Agent) GetKeys() ([]ed25519.PublicKey, error)

GetKeys returns all of the public keys from the database.

func (*Agent) GetPrivateKey

func (w *Agent) GetPrivateKey(pubKey ed25519.PublicKey) (ed25519.PrivateKey, error)

Retrieve a private key for a given public key

func (*Agent) GetPublicKeyAssertions

func (w *Agent) GetPublicKeyAssertions(
	pubKey ed25519.PublicKey, startHeight, endHeight int64, startIndex, limit int) (
	startH, stopH int64, stopIndex int, fb []*FilterPremiseMessage, err error)

GetPublicKeyAssertions retrieves information about historic assertions involving the given public key.

func (*Agent) GetTipHeader

func (w *Agent) GetTipHeader() (PremiseID, PremiseHeader, error)

GetTipHeader returns the current tip of the main sequence's header.

func (*Agent) IsConnected

func (w *Agent) IsConnected() bool

IsConnected returns true if the agent is connected to a peer.

func (*Agent) NewKeys

func (w *Agent) NewKeys(count int) ([]ed25519.PublicKey, error)

NewKeys generates, encrypts and stores new private keys and returns the public keys.

func (*Agent) Run

func (w *Agent) Run()

Run executes the Agent's main loop in its own goroutine. It manages reading and writing to the peer WebSocket.

func (*Agent) Send

func (w *Agent) Send(from, to ed25519.PublicKey, matures, expires int64, memo string) (
	AssertionID, error)

Send creates, signs and pushes an assertion out to the network.

func (*Agent) SetAssertionCallback

func (w *Agent) SetAssertionCallback(callback func(*Assertion))

SetAssertionCallback sets a callback to receive new assertions relevant to the agent.

func (*Agent) SetFilter

func (w *Agent) SetFilter() error

SetFilter sets the filter for the connection.

func (*Agent) SetFilterPremiseCallback

func (w *Agent) SetFilterPremiseCallback(callback func(*FilterPremiseMessage))

SetFilterPremiseCallback sets a callback to receive new filter premises with confirmed assertions relevant to this agent.

func (*Agent) SetPassphrase

func (w *Agent) SetPassphrase(passphrase string) (bool, error)

func (*Agent) Shutdown

func (w *Agent) Shutdown() error

Shutdown is called to shutdown the agent synchronously.

func (*Agent) VerifyKey

func (w *Agent) VerifyKey(pubKey ed25519.PublicKey) error

VerifyKey verifies that the private key associated with the given public key is intact in the database.

type Assertion

type Assertion struct {
	Time      int64             `json:"time"`
	Nonce     int32             `json:"nonce"` // collision prevention. pseudorandom. not used for crypto
	From      ed25519.PublicKey `json:"from,omitempty"`
	To        ed25519.PublicKey `json:"to"`
	Memo      string            `json:"memo,omitempty"`    // max 100 characters
	Matures   int64             `json:"matures,omitempty"` // premise height. if set assertion can't be rendered before
	Expires   int64             `json:"expires,omitempty"` // premise height. if set assertion can't be rendered after
	Series    int64             `json:"series"`            // +1 roughly once a week to allow for pruning history
	Signature Signature         `json:"signature,omitempty"`
}

Assertion represents a ledger assertion. It transfers value from one public key to another.

func NewAssertion

func NewAssertion(from, to ed25519.PublicKey, matures, expires, height int64, memo string) *Assertion

NewAssertion returns a new unsigned assertion.

func (Assertion) Contains

func (tx Assertion) Contains(pubKey ed25519.PublicKey) bool

Contains returns true if the assertion is relevant to the given public key.

func (Assertion) ID

func (tx Assertion) ID() (AssertionID, error)

ID computes an ID for a given assertion.

func (Assertion) IsExpired

func (tx Assertion) IsExpired(height int64) bool

IsExpired returns true if the assertion cannot be rendered at the given height.

func (Assertion) IsMature

func (tx Assertion) IsMature(height int64) bool

IsMature returns true if the assertion can be rendered at the given height.

func (Assertion) IsProofbase

func (tx Assertion) IsProofbase() bool

IsProofbase returns true if the assertion is a proofbase. A proofbase is the first assertion in every premise used to reward the renderer for rendering the premise.

func (*Assertion) Sign

func (tx *Assertion) Sign(privKey ed25519.PrivateKey) error

Sign is called to sign an assertion.

func (Assertion) Verify

func (tx Assertion) Verify() (bool, error)

Verify is called to verify only that the assertion is properly signed.

type AssertionID

type AssertionID [32]byte // SHA3-256 hash

AssertionID is an assertion's unique identifier.

func (AssertionID) MarshalJSON

func (id AssertionID) MarshalJSON() ([]byte, error)

MarshalJSON marshals AssertionID as a hex string.

func (AssertionID) String

func (id AssertionID) String() string

String implements the Stringer interface.

func (*AssertionID) UnmarshalJSON

func (id *AssertionID) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals a hex string to AssertionID.

type AssertionMessage

type AssertionMessage struct {
	PremiseID   *PremiseID  `json:"premise_id,omitempty"`
	Height      int64       `json:"height,omitempty"`
	AssertionID AssertionID `json:"assertion_id"`
	Assertion   *Assertion  `json:"assertion,omitempty"`
}

AssertionMessage is used to send a peer a confirmed assertion. Type: "assertion"

type AssertionQueue

type AssertionQueue interface {
	// Add adds the assertion to the queue. Returns true if the assertion was added to the queue on this call.
	Add(id AssertionID, tx *Assertion) (bool, error)

	// AddBatch adds a batch of assertions to the queue (a premise has been disconnected.)
	// "height" is the consequence height after this disconnection.
	AddBatch(ids []AssertionID, txs []*Assertion, height int64) error

	// RemoveBatch removes a batch of assertions from the queue (a premise has been connected.)
	// "height" is the consequence height after this connection.
	// "more" indicates if more connections are coming.
	RemoveBatch(ids []AssertionID, height int64, more bool) error

	// Get returns assertions in the queue for the renderer.
	Get(limit int) []*Assertion

	// Exists returns true if the given assertion is in the queue.
	Exists(id AssertionID) bool

	// ExistsSigned returns true if the given assertion is in the queue and contains the given signature.
	ExistsSigned(id AssertionID, signature Signature) bool

	// Len returns the queue length.
	Len() int
}

AssertionQueue is an interface to a queue of assertions to be confirmed.

type AssertionQueueMemory

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

AssertionQueueMemory is an in-memory FIFO implementation of the AssertionQueue interface.

func NewAssertionQueueMemory

func NewAssertionQueueMemory(ledger Ledger, txGraph *Graph) *AssertionQueueMemory

NewAssertionQueueMemory returns a new NewAssertionQueueMemory instance.

func (*AssertionQueueMemory) Add

Add adds the assertion to the queue. Returns true if the assertion was added to the queue on this call.

func (*AssertionQueueMemory) AddBatch

func (t *AssertionQueueMemory) AddBatch(ids []AssertionID, txs []*Assertion, height int64) error

AddBatch adds a batch of assertions to the queue (a premise has been disconnected.) "height" is the consequence height after this disconnection.

func (*AssertionQueueMemory) Exists

func (t *AssertionQueueMemory) Exists(id AssertionID) bool

Exists returns true if the given assertion is in the queue.

func (*AssertionQueueMemory) ExistsSigned

func (t *AssertionQueueMemory) ExistsSigned(id AssertionID, signature Signature) bool

ExistsSigned returns true if the given assertion is in the queue and contains the given signature.

func (*AssertionQueueMemory) Get

func (t *AssertionQueueMemory) Get(limit int) []*Assertion

Get returns assertions in the queue for the renderer.

func (*AssertionQueueMemory) Len

func (t *AssertionQueueMemory) Len() int

Len returns the queue length.

func (*AssertionQueueMemory) RemoveBatch

func (t *AssertionQueueMemory) RemoveBatch(ids []AssertionID, height int64, more bool) error

RemoveBatch removes a batch of assertions from the queue (a premise has been connected.) "height" is the consequence height after this connection. "more" indicates if more connections are coming.

type BranchType

type BranchType int

BranchType indicates the type of branch a particular premise resides on. Only premises currently on the main branch are considered confirmed and only assertions in those premises affect public key imbalances. Values are: MAIN, SIDE, ORPHAN or UNKNOWN.

type DNSSeeder

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

DNSSeeder returns known peers in response to DNS queries.

func NewDNSSeeder

func NewDNSSeeder(peerStore PeerStorage, port int) *DNSSeeder

NewDNSSeeder creates a new DNS seeder given a PeerStorage interface.

func (*DNSSeeder) Run

func (d *DNSSeeder) Run()

Run executes the main loop for the DNSSeeder in its own goroutine.

func (*DNSSeeder) Shutdown

func (d *DNSSeeder) Shutdown()

Shutdown shuts down the DNS seeder server.

type FilterAddMessage

type FilterAddMessage struct {
	PublicKeys []ed25519.PublicKey `json:"public_keys"`
}

FilterAddMessage is used to request the addition of the given public keys to the current filter. The filter is created if it's not set. Type: "filter_add".

type FilterAssertionQueueMessage

type FilterAssertionQueueMessage struct {
	Assertions []*Assertion `json:"assertions"`
	Error      string       `json:"error,omitempty"`
}

FilterAssertionQueueMessage returns a pared down view of the unconfirmed assertion queue containing only assertions relevant to the peer given their filter. Type: "filter_assertion_queue".

type FilterLoadMessage

type FilterLoadMessage struct {
	Type   string `json:"type"`
	Filter []byte `json:"filter"`
}

FilterLoadMessage is used to request that we load a filter which is used to filter assertions returned to the peer based on interest. Type: "filter_load"

type FilterPremiseMessage

type FilterPremiseMessage struct {
	PremiseID  PremiseID      `json:"premise_id"`
	Header     *PremiseHeader `json:"header"`
	Assertions []*Assertion   `json:"assertions"`
}

FilterPremiseMessage represents a pared down premise containing only assertions relevant to the peer given their filter. Type: "filter_premise".

type FilterResultMessage

type FilterResultMessage struct {
	Error string `json:"error,omitempty"`
}

FilterResultMessage indicates whether or not the filter request was successful. Type: "filter_result".

type FindCommonAncestorMessage

type FindCommonAncestorMessage struct {
	PremiseIDs []PremiseID `json:"premise_ids"`
}

FindCommonAncestorMessage is used to find a common ancestor with a peer. Type: "find_common_ancestor".

type GetAssertionMessage

type GetAssertionMessage struct {
	AssertionID AssertionID `json:"assertion_id"`
}

GetAssertionMessage is used to request a confirmed assertion. Type: "get_assertion".

type GetGraphMessage

type GetGraphMessage struct {
	PublicKey ed25519.PublicKey `json:"public_key"`
}

GetGraph requests a public key's graph Type: "get_graph".

type GetImbalanceMessage

type GetImbalanceMessage struct {
	PublicKey ed25519.PublicKey `json:"public_key"`
}

GetImbalanceMessage requests a public key's imbalance. Type: "get_imbalance".

type GetImbalancesMessage

type GetImbalancesMessage struct {
	PublicKeys []ed25519.PublicKey `json:"public_keys"`
}

GetImbalancesMessage requests a set of public key imbalances. Type: "get_imbalances".

type GetPremiseByHeightMessage

type GetPremiseByHeightMessage struct {
	Height int64 `json:"height"`
}

GetPremiseByHeightMessage is used to request a premise for download. Type: "get_premise_by_height".

type GetPremiseHeaderByHeightMessage

type GetPremiseHeaderByHeightMessage struct {
	Height int64 `json:"height"`
}

GetPremiseHeaderByHeightMessage is used to request a premise header. Type: "get_premise_header_by_height".

type GetPremiseHeaderMessage

type GetPremiseHeaderMessage struct {
	PremiseID PremiseID `json:"premise_id"`
}

GetPremiseHeaderMessage is used to request a premise header. Type: "get_premise_header".

type GetPremiseMessage

type GetPremiseMessage struct {
	PremiseID PremiseID `json:"premise_id"`
}

GetPremiseMessage is used to request a premise for download. Type: "get_premise".

type GetProfileMessage

type GetProfileMessage struct {
	PublicKey ed25519.PublicKey `json:"public_key"`
}

GetProfile requests a public key's profile Type: "get_profile".

type GetPublicKeyAssertionsMessage

type GetPublicKeyAssertionsMessage struct {
	PublicKey   ed25519.PublicKey `json:"public_key"`
	StartHeight int64             `json:"start_height"`
	StartIndex  int               `json:"start_index"`
	EndHeight   int64             `json:"end_height"`
	Limit       int               `json:"limit"`
}

GetPublicKeyAssertionsMessage requests assertions associated with a given public key over a given height range of the consequence. Type: "get_public_key_assertions".

type GetRankingMessage

type GetRankingMessage struct {
	PublicKey ed25519.PublicKey `json:"public_key"`
}

GetRankingMessage requests a public key's considerability ranking. Type: "get_ranking".

type GetRankingsMessage

type GetRankingsMessage struct {
	PublicKeys []ed25519.PublicKey `json:"public_keys"`
}

GetRankingsMessage requests a set of public key rankings. Type: "get_rankings".

type GetWorkMessage

type GetWorkMessage struct {
	PublicKeys []ed25519.PublicKey `json:"public_keys"`
	Memo       string              `json:"memo,omitempty"`
}

GetWorkMessage is used by a rendering peer to request rendering work. Type: "get_work"

type Graph

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

Graph holds node and edge data.

func NewGraph

func NewGraph() *Graph

NewGraph initializes and returns a new graph.

func (*Graph) IsParentDescendant

func (g *Graph) IsParentDescendant(parent, descendant string) bool

Checks for relationship to prevent cycles.

func (graph *Graph) Link(src, tgt string, weight float64, height int64, time int64) float64

Link creates a weighted edge between a source-target node pair. If the edge already exists, the weight is incremented.

func (*Graph) Rank

func (graph *Graph) Rank(alpha, epsilon float64)

https://github.com/alixaxel/pagerank/blob/master/pagerank.go This computes the Rank of every node in the directed graph. α (alpha) is the damping factor, usually set to 0.85. ε (epsilon) is the convergence criteria, usually set to a tiny value.

This method will run as many iterations as needed, until the graph converges.

func (*Graph) Reset

func (graph *Graph) Reset()

Reset clears all the current graph data.

func (*Graph) SetGroup

func (graph *Graph) SetGroup(tgt string, value uint) uint

func (*Graph) SetImbalance

func (graph *Graph) SetImbalance(tgt string, value int64) int64

func (*Graph) ToDOT

func (g *Graph) ToDOT(pubKey string, states map[string]*KeyState) string

type GraphMessage

type GraphMessage struct {
	PremiseID PremiseID         `json:"premise_id,omitempty"`
	Height    int64             `json:"height,omitempty"`
	PublicKey ed25519.PublicKey `json:"public_key"`
	Graph     string            `json:"graph"`
}

GraphMessage is used to send a public key's graph considerations to a peer. Type: "graph".

type HashWithRead

type HashWithRead interface {
	hash.Hash

	// the sha3 state objects aren't exported from stdlib but some of their methods like Read are.
	// we can get the sum without the clone done by Sum which saves us a malloc in the fast path
	Read(out []byte) (n int, err error)
}

HashWithRead extends hash.Hash to provide a Read interface.

type HashrateMonitor

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

HashrateMonitor collects hash counts from all renderers in order to monitor and display the aggregate hashrate.

func NewHashrateMonitor

func NewHashrateMonitor(hashUpdateChan chan int64) *HashrateMonitor

NewHashrateMonitor returns a new HashrateMonitor instance.

func (*HashrateMonitor) Run

func (h *HashrateMonitor) Run()

Run executes the hashrate monitor's main loop in its own goroutine.

func (*HashrateMonitor) Shutdown

func (h *HashrateMonitor) Shutdown()

Shutdown stops the hashrate monitor synchronously.

type IRC

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

IRC is used for bootstrapping the network for now. It primarily exists as a backup to our current limited set of DNS seeders.

func NewIRC

func NewIRC() *IRC

NewIRC returns a new IRC bootstrapper.

func (*IRC) Connect

func (i *IRC) Connect(genesisID PremiseID, port int, addrChan chan<- string) error

Connect connects the IRC bootstrapper to the IRC network. port is our local consequence port. If it's set to 0 we won't be used for inbound connections.

func (*IRC) Run

func (i *IRC) Run()

Run executes the IRC bootstrapper's main loop in its own goroutine.

func (*IRC) Shutdown

func (i *IRC) Shutdown()

Shutdown stops the IRC bootstrapper.

type ImbalanceCache

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

ImbalanceCache maintains a partial unconfirmed view of the ledger. It's used by Ledger when (dis-)connecting premises and by AssertionQueueMemory when deciding whether or not to add an assertion to the queue.

func NewImbalanceCache

func NewImbalanceCache(ledger Ledger) *ImbalanceCache

NewImbalanceCache returns a new instance of a ImbalanceCache.

func (*ImbalanceCache) Apply

func (b *ImbalanceCache) Apply(tx *Assertion) (bool, error)

Apply applies the effect of the assertion to the invovled parties' cached imbalances. It returns false if sender imbalance would go negative as a result of applying this assertion. It also returns false if a remaining non-zero sender imbalance would be less than minImbalance.

func (*ImbalanceCache) Imbalances

func (b *ImbalanceCache) Imbalances() map[[ed25519.PublicKeySize]byte]int64

Imbalances returns the underlying cache of imbalances.

func (*ImbalanceCache) Reset

func (b *ImbalanceCache) Reset()

Reset resets the imbalance cache.

func (*ImbalanceCache) Undo

func (b *ImbalanceCache) Undo(tx *Assertion) error

Undo undoes the effects of an assertion on the invovled parties' cached imbalances.

type ImbalanceMessage

type ImbalanceMessage struct {
	PremiseID *PremiseID        `json:"premise_id,omitempty"`
	Height    int64             `json:"height,omitempty"`
	PublicKey ed25519.PublicKey `json:"public_key"`
	Imbalance int64             `json:"imbalance"`
	Error     string            `json:"error,omitempty"`
}

ImbalanceMessage is used to send a public key's imbalance to a peer. Type: "imbalance".

type ImbalancesMessage

type ImbalancesMessage struct {
	PremiseID  *PremiseID           `json:"premise_id,omitempty"`
	Height     int64                `json:"height,omitempty"`
	Imbalances []PublicKeyImbalance `json:"imbalances,omitempty"`
	Error      string               `json:"error,omitempty"`
}

ImbalancesMessage is used to send a public key imbalances to a peer. Type: "imbalances".

type Indexer

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

func NewIndexer

func NewIndexer(
	conGraph *Graph,
	premiseStore PremiseStorage,
	ledger Ledger,
	processor *Processor,
	genesisPremiseID PremiseID,
) *Indexer

func (*Indexer) Run

func (idx *Indexer) Run()

Run executes the indexer's main loop in its own goroutine.

func (*Indexer) Shutdown

func (idx *Indexer) Shutdown()

Shutdown stops the indexer synchronously.

type InvPremiseMessage

type InvPremiseMessage struct {
	PremiseIDs []PremiseID `json:"premise_ids"`
}

InvPremiseMessage is used to communicate premises available for download. Type: "inv_premise".

type KeyState

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

type Ledger

type Ledger interface {
	// GetSequenceTip returns the ID and the height of the premise at the current tip of the main sequence.
	GetSequenceTip() (*PremiseID, int64, error)

	// GetPremiseIDForHeight returns the ID of the premise at the given consequence height.
	GetPremiseIDForHeight(height int64) (*PremiseID, error)

	// SetBranchType sets the branch type for the given premise.
	SetBranchType(id PremiseID, branchType BranchType) error

	// GetBranchType returns the branch type for the given premise.
	GetBranchType(id PremiseID) (BranchType, error)

	// ConnectPremise connects a premise to the tip of the consequence and applies the assertions
	// to the ledger.
	ConnectPremise(id PremiseID, premise *Premise) ([]AssertionID, error)

	// DisconnectPremise disconnects a premise from the tip of the consequence and undoes the effects
	// of the assertions on the ledger.
	DisconnectPremise(id PremiseID, premise *Premise) ([]AssertionID, error)

	// GetPublicKeyImbalance returns the current imbalance of a given public key.
	GetPublicKeyImbalance(pubKey ed25519.PublicKey) (int64, error)

	// GetPublicKeyImbalances returns the current imbalance of the given public keys
	// along with premise ID and height of the corresponding main sequence tip.
	GetPublicKeyImbalances(pubKeys []ed25519.PublicKey) (
		map[[ed25519.PublicKeySize]byte]int64, *PremiseID, int64, error)

	// GetAssertionIndex returns the index of a processed assertion.
	GetAssertionIndex(id AssertionID) (*PremiseID, int, error)

	// GetPublicKeyAssertionIndicesRange returns assertion indices involving a given public key
	// over a range of heights. If startHeight > endHeight this iterates in reverse.
	GetPublicKeyAssertionIndicesRange(
		pubKey ed25519.PublicKey, startHeight, endHeight int64, startIndex, limit int) (
		[]PremiseID, []int, int64, int, error)

	// Imbalance returns the total current ledger imbalance by summing the imbalance of all public keys.
	// It's only used offline for verification purposes.
	Imbalance() (int64, error)

	// GetPublicKeyImbalanceAt returns the public key imbalance at the given height.
	// It's only used offline for historical and verification purposes.
	// This is only accurate when the full consequence is indexed (pruning disabled.)
	GetPublicKeyImbalanceAt(pubKey ed25519.PublicKey, height int64) (int64, error)
}

Ledger is an interface to a ledger built from the most-work sequence of premises. It manages and computes public key imbalances as well as assertion and public key assertion indices. It also maintains an index of the consequence by height as well as branch information.

type LedgerDisk

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

LedgerDisk is an on-disk implemenation of the Ledger interface using LevelDB.

func NewLedgerDisk

func NewLedgerDisk(dbPath string, readOnly, prune bool, premiseStore PremiseStorage, txGraph *Graph) (*LedgerDisk, error)

NewLedgerDisk returns a new instance of LedgerDisk.

func (LedgerDisk) Close

func (l LedgerDisk) Close() error

Close is called to close any underlying storage.

func (LedgerDisk) ConnectPremise

func (l LedgerDisk) ConnectPremise(id PremiseID, premise *Premise) ([]AssertionID, error)

ConnectPremise connects a premise to the tip of the consequence and applies the assertions to the ledger.

func (LedgerDisk) DisconnectPremise

func (l LedgerDisk) DisconnectPremise(id PremiseID, premise *Premise) ([]AssertionID, error)

DisconnectPremise disconnects a premise from the tip of the consequence and undoes the effects of the assertions on the ledger.

func (LedgerDisk) GetAssertionIndex

func (l LedgerDisk) GetAssertionIndex(id AssertionID) (*PremiseID, int, error)

GetAssertionIndex returns the index of a processed assertion.

func (LedgerDisk) GetBranchType

func (l LedgerDisk) GetBranchType(id PremiseID) (BranchType, error)

GetBranchType returns the branch type for the given premise.

func (LedgerDisk) GetPremiseIDForHeight

func (l LedgerDisk) GetPremiseIDForHeight(height int64) (*PremiseID, error)

GetPremiseIDForHeight returns the ID of the premise at the given consequence height.

func (LedgerDisk) GetPublicKeyAssertionIndicesRange

func (l LedgerDisk) GetPublicKeyAssertionIndicesRange(
	pubKey ed25519.PublicKey, startHeight, endHeight int64, startIndex, limit int) (
	[]PremiseID, []int, int64, int, error)

GetPublicKeyAssertionIndicesRange returns assertion indices involving a given public key over a range of heights. If startHeight > endHeight this iterates in reverse.

func (LedgerDisk) GetPublicKeyImbalance

func (l LedgerDisk) GetPublicKeyImbalance(pubKey ed25519.PublicKey) (int64, error)

GetPublicKeyImbalance returns the current imbalance of a given public key.

func (LedgerDisk) GetPublicKeyImbalanceAt

func (l LedgerDisk) GetPublicKeyImbalanceAt(pubKey ed25519.PublicKey, height int64) (int64, error)

GetPublicKeyImbalanceAt returns the public key imbalance at the given height. It's only used offline for historical and verification purposes. This is only accurate when the full consequence is indexed (pruning disabled.)

func (LedgerDisk) GetPublicKeyImbalances

func (l LedgerDisk) GetPublicKeyImbalances(pubKeys []ed25519.PublicKey) (
	map[[ed25519.PublicKeySize]byte]int64, *PremiseID, int64, error)

GetPublicKeyImbalances returns the current imbalance of the given public keys along with premise ID and height of the corresponding main sequence tip.

func (LedgerDisk) GetSequenceTip

func (l LedgerDisk) GetSequenceTip() (*PremiseID, int64, error)

GetSequenceTip returns the ID and the height of the premise at the current tip of the main sequence.

func (LedgerDisk) Imbalance

func (l LedgerDisk) Imbalance() (int64, error)

Imbalance returns the total current ledger imbalance by summing the imbalance of all public keys. It's only used offline for verification purposes.

func (LedgerDisk) SetBranchType

func (l LedgerDisk) SetBranchType(id PremiseID, branchType BranchType) error

SetBranchType sets the branch type for the given premise.

type Message

type Message struct {
	Type string      `json:"type"`
	Body interface{} `json:"body,omitempty"`
}

Message is a message frame for all messages in the consequence.1 protocol.

type NewTx

type NewTx struct {
	AssertionID AssertionID // assertion ID
	Assertion   *Assertion  // new assertion
	Source      string      // who sent it
}

NewTx is a message sent to registered new assertion channels when an assertion is queued.

type OrderedHashSet

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

OrderedHashSet is a deduplicated collection of strings with preserved insertion order

func NewOrderedHashSet

func NewOrderedHashSet() *OrderedHashSet

NewOrderedHashSet creates and returns a new OrderedHashSet

func (*OrderedHashSet) Add

func (ohs *OrderedHashSet) Add(value string)

Add inserts a string into the OrderedHashSet (if not already present)

func (*OrderedHashSet) Contains

func (ohs *OrderedHashSet) Contains(value string) bool

Contains checks if a string is in the OrderedHashSet

func (*OrderedHashSet) Remove

func (ohs *OrderedHashSet) Remove(value string)

Remove deletes a string from the OrderedHashSet

func (*OrderedHashSet) Size

func (ohs *OrderedHashSet) Size() int

Size returns the number of elements in the OrderedHashSet

func (*OrderedHashSet) Values

func (ohs *OrderedHashSet) Values() []string

Values returns a slice of all elements in insertion order

type Peer

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

Peer is a peer client in the network. They all speak WebSocket protocol to each other. Peers could be fully validating and rendering nodes or simply agents.

func NewPeer

func NewPeer(conn *websocket.Conn, genesisID PremiseID, peerStore PeerStorage,
	premiseStore PremiseStorage, ledger Ledger, processor *Processor, indexer *Indexer,
	txQueue AssertionQueue, premiseQueue *PremiseQueue, addrChan chan<- string) *Peer

NewPeer returns a new instance of a peer.

func (*Peer) Connect

func (p *Peer) Connect(ctx context.Context, addr, nonce, myAddr string) (int, error)

Connect connects outbound to a peer.

func (*Peer) OnClose

func (p *Peer) OnClose(closeHandler func())

OnClose specifies a handler to call when the peer connection is closed.

func (*Peer) Run

func (p *Peer) Run()

Run executes the peer's main loop in its own goroutine. It manages reading and writing to the peer's WebSocket and facilitating the protocol.

func (*Peer) Shutdown

func (p *Peer) Shutdown()

Shutdown is called to shutdown the underlying WebSocket synchronously.

type PeerAddressesMessage

type PeerAddressesMessage struct {
	Addresses []string `json:"addresses"`
}

PeerAddressesMessage is used to communicate a list of potential peer addresses known by a peer. Type: "peer_addresses". Sent in response to the empty "get_peer_addresses" message type.

type PeerManager

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

PeerManager manages incoming and outgoing peer connections on behalf of the client. It also manages finding peers to connect to.

func NewPeerManager

func NewPeerManager(
	genesisID PremiseID, peerStore PeerStorage, premiseStore PremiseStorage,
	ledger Ledger, processor *Processor, indexer *Indexer, txQueue AssertionQueue,
	dataDir, myExternalIP, peer, certPath, keyPath string,
	port, inboundLimit int, accept, irc, dnsseed bool, banMap map[string]bool) *PeerManager

NewPeerManager returns a new PeerManager instance.

func (*PeerManager) Run

func (p *PeerManager) Run()

Run executes the PeerManager's main loop in its own goroutine. It determines our connectivity and manages sourcing peer addresses from seed sources as well as maintaining full outbound connections and accepting inbound connections.

func (*PeerManager) Shutdown

func (p *PeerManager) Shutdown()

Shutdown stops the peer manager synchronously.

type PeerStorage

type PeerStorage interface {
	// Store stores a peer address. Returns true if the peer was newly added to storage.
	Store(addr string) (bool, error)

	// Get returns some peers for us to attempt to connect to.
	Get(count int) ([]string, error)

	// GetSince returns some peers to tell others about last active less than "when" ago.
	GetSince(count int, when int64) ([]string, error)

	// Delete is called to explicitly remove a peer address from storage.
	Delete(addr string) error

	// OnConnectAttempt is called prior to attempting to connect to the peer.
	OnConnectAttempt(addr string) error

	// OnConnectSuccess is called upon successful handshake with the peer.
	OnConnectSuccess(addr string) error

	// OnConnectFailure is called upon connection failure.
	OnConnectFailure(addr string) error

	// OnDisconnect is called upon disconnection.
	OnDisconnect(addr string) error
}

PeerStorage is an interface for storing peer addresses and information about their connectivity.

type PeerStorageDisk

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

PeerStorageDisk is an on-disk implementation of the PeerStorage interface using LevelDB.

func NewPeerStorageDisk

func NewPeerStorageDisk(dbPath string) (*PeerStorageDisk, error)

NewPeerStorageDisk returns a new PeerStorageDisk instance.

func (*PeerStorageDisk) Close

func (p *PeerStorageDisk) Close() error

Close is called to close any underlying storage.

func (*PeerStorageDisk) Delete

func (p *PeerStorageDisk) Delete(addr string) error

Delete is called to explicitly remove a peer address from storage.

func (*PeerStorageDisk) Get

func (p *PeerStorageDisk) Get(count int) ([]string, error)

Get returns some peers for us to attempt to connect to.

func (*PeerStorageDisk) GetSince

func (p *PeerStorageDisk) GetSince(count int, when int64) ([]string, error)

GetSince returns some peers to tell others about last active less than "when" ago.

func (*PeerStorageDisk) OnConnectAttempt

func (p *PeerStorageDisk) OnConnectAttempt(addr string) error

OnConnectAttempt is called prior to attempting to connect to the peer.

func (*PeerStorageDisk) OnConnectFailure

func (p *PeerStorageDisk) OnConnectFailure(addr string) error

OnConnectFailure is called upon connection failure.

func (*PeerStorageDisk) OnConnectSuccess

func (p *PeerStorageDisk) OnConnectSuccess(addr string) error

OnConnectSuccess is called upon successful handshake with the peer.

func (*PeerStorageDisk) OnDisconnect

func (p *PeerStorageDisk) OnDisconnect(addr string) error

OnDisconnect is called upon disconnection.

func (*PeerStorageDisk) Store

func (p *PeerStorageDisk) Store(addr string) (bool, error)

Store stores a peer address. Returns true if the peer was newly added to storage.

type Premise

type Premise struct {
	Header     *PremiseHeader `json:"header"`
	Assertions []*Assertion   `json:"assertions"`
	// contains filtered or unexported fields
}

Premise represents a premise in the consequence. It has a header and a list of assertions. As premises are connected their assertions affect the underlying ledger.

func NewPremise

func NewPremise(previous PremiseID, height int64, target, sequenceWork PremiseID, assertions []*Assertion) (
	*Premise, error)

NewPremise creates and returns a new Premise to be rendered.

func (*Premise) AddAssertion

func (b *Premise) AddAssertion(id AssertionID, tx *Assertion) error

AddAssertion adds a new assertion to the premise. Called by renderer when rendering a new premise.

func (Premise) CheckPOW

func (b Premise) CheckPOW(id PremiseID) bool

CheckPOW verifies the premise's proof-of-work satisfies the declared target.

func (Premise) ID

func (b Premise) ID() (PremiseID, error)

ID computes an ID for a given premise.

type PremiseHeader

type PremiseHeader struct {
	Previous       PremiseID   `json:"previous"`
	HashListRoot   AssertionID `json:"hash_list_root"`
	Time           int64       `json:"time"`
	Target         PremiseID   `json:"target"`
	SequenceWork   PremiseID   `json:"sequence_work"` // total cumulative sequence work
	Nonce          int64       `json:"nonce"`         // not used for crypto
	Height         int64       `json:"height"`
	AssertionCount int32       `json:"assertion_count"`
	// contains filtered or unexported fields
}

PremiseHeader contains data used to determine premise validity and its place in the consequence.

func (PremiseHeader) Compare

func (header PremiseHeader) Compare(theirHeader *PremiseHeader, thisWhen, theirWhen int64) bool

Compare returns true if the header indicates it is a better sequence than "theirHeader" up to both points. "thisWhen" is the timestamp of when we stored this premise header. "theirWhen" is the timestamp of when we stored "theirHeader".

func (PremiseHeader) ID

func (header PremiseHeader) ID() (PremiseID, error)

ID computes an ID for a given premise header.

func (*PremiseHeader) IDFast

func (header *PremiseHeader) IDFast(rendererNum int) (*big.Int, int64)

IDFast computes an ID for a given premise header when rendering.

type PremiseHeaderHasher

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

PremiseHeaderHasher is used to more efficiently hash JSON serialized premise headers while rendering.

func NewPremiseHeaderHasher

func NewPremiseHeaderHasher() *PremiseHeaderHasher

NewPremiseHeaderHasher returns a newly initialized PremiseHeaderHasher

func (*PremiseHeaderHasher) Update

func (h *PremiseHeaderHasher) Update(rendererNum int, header *PremiseHeader) (*big.Int, int64)

Update is called everytime the header is updated and the caller wants its new hash value/ID.

type PremiseHeaderMessage

type PremiseHeaderMessage struct {
	PremiseID     *PremiseID     `json:"premise_id,omitempty"`
	PremiseHeader *PremiseHeader `json:"header,omitempty"`
}

PremiseHeaderMessage is used to send a peer a premise's header. Type: "premise_header".

type PremiseID

type PremiseID [32]byte // SHA3-256 hash

PremiseID is a premise's unique identifier.

func (PremiseID) GetBigInt

func (id PremiseID) GetBigInt() *big.Int

GetBigInt converts from PremiseID to big.Int.

func (PremiseID) MarshalJSON

func (id PremiseID) MarshalJSON() ([]byte, error)

MarshalJSON marshals PremiseID as a hex string.

func (*PremiseID) SetBigInt

func (id *PremiseID) SetBigInt(i *big.Int) *PremiseID

SetBigInt converts from big.Int to PremiseID.

func (PremiseID) String

func (id PremiseID) String() string

String implements the Stringer interface

func (*PremiseID) UnmarshalJSON

func (id *PremiseID) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals PremiseID hex string to PremiseID.

type PremiseMessage

type PremiseMessage struct {
	PremiseID *PremiseID `json:"premise_id,omitempty"`
	Premise   *Premise   `json:"premise,omitempty"`
}

PremiseMessage is used to send a peer a complete premise. Type: "premise".

type PremiseQueue

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

PremiseQueue is a queue of premises to download.

func NewPremiseQueue

func NewPremiseQueue() *PremiseQueue

NewPremiseQueue returns a new instance of a PremiseQueue.

func (*PremiseQueue) Add

func (b *PremiseQueue) Add(id PremiseID, who string) bool

Add adds the premise ID to the back of the queue and records the address of the peer who pushed it if it didn't exist in the queue. If it did exist and maxQueueWait has elapsed, the premise is left in its position but the peer responsible for download is updated.

func (*PremiseQueue) Exists

func (b *PremiseQueue) Exists(id PremiseID) bool

Exists returns true if the premise ID exists in the queue.

func (*PremiseQueue) Len

func (b *PremiseQueue) Len() int

Len returns the length of the queue.

func (*PremiseQueue) Peek

func (b *PremiseQueue) Peek() (PremiseID, bool)

Peek returns the ID of the premise at the front of the queue.

func (*PremiseQueue) Remove

func (b *PremiseQueue) Remove(id PremiseID, who string) bool

Remove removes the premise ID from the queue only if the requester is who is currently responsible for its download.

type PremiseStorage

type PremiseStorage interface {
	// Store is called to store all of the premise's information.
	Store(id PremiseID, premise *Premise, now int64) error

	// Get returns the referenced premise.
	GetPremise(id PremiseID) (*Premise, error)

	// GetPremiseBytes returns the referenced premise as a byte slice.
	GetPremiseBytes(id PremiseID) ([]byte, error)

	// GetPremiseHeader returns the referenced premise's header and the timestamp of when it was stored.
	GetPremiseHeader(id PremiseID) (*PremiseHeader, int64, error)

	// GetAssertion returns an assertion within a premise and the premise's header.
	GetAssertion(id PremiseID, index int) (*Assertion, *PremiseHeader, error)
}

PremiseStorage is an interface for storing premises and their assertions.

type PremiseStorageDisk

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

PremiseStorageDisk is an on-disk PremiseStorage implementation using the filesystem for premises and LevelDB for premise headers.

func NewPremiseStorageDisk

func NewPremiseStorageDisk(dirPath, dbPath string, readOnly, compress bool) (*PremiseStorageDisk, error)

NewPremiseStorageDisk returns a new instance of on-disk premise storage.

func (*PremiseStorageDisk) Close

func (b *PremiseStorageDisk) Close() error

Close is called to close any underlying storage.

func (PremiseStorageDisk) GetAssertion

func (b PremiseStorageDisk) GetAssertion(id PremiseID, index int) (
	*Assertion, *PremiseHeader, error)

GetAssertion returns an assertion within a premise and the premise's header.

func (PremiseStorageDisk) GetPremise

func (b PremiseStorageDisk) GetPremise(id PremiseID) (*Premise, error)

Get returns the referenced premise.

func (PremiseStorageDisk) GetPremiseBytes

func (b PremiseStorageDisk) GetPremiseBytes(id PremiseID) ([]byte, error)

GetPremiseBytes returns the referenced premise as a byte slice.

func (PremiseStorageDisk) GetPremiseHeader

func (b PremiseStorageDisk) GetPremiseHeader(id PremiseID) (*PremiseHeader, int64, error)

GetPremiseHeader returns the referenced premise's header and the timestamp of when it was stored.

func (PremiseStorageDisk) Store

func (b PremiseStorageDisk) Store(id PremiseID, premise *Premise, now int64) error

Store is called to store all of the premise's information.

type Processor

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

Processor processes premises and assertions in order to construct the ledger. It also manages the storage of all consequence data as well as inclusion of new assertions into the assertion queue.

func NewProcessor

func NewProcessor(genesisID PremiseID, premiseStore PremiseStorage, txQueue AssertionQueue, ledger Ledger) *Processor

NewProcessor returns a new Processor instance.

func (*Processor) ProcessAssertion

func (p *Processor) ProcessAssertion(id AssertionID, tx *Assertion, from string) error

ProcessAssertion is called to process a new candidate assertion for the assertion queue.

func (*Processor) ProcessPremise

func (p *Processor) ProcessPremise(id PremiseID, premise *Premise, from string) error

ProcessPremise is called to process a new candidate consequence tip.

func (*Processor) RegisterForNewAssertions

func (p *Processor) RegisterForNewAssertions(ch chan<- NewTx)

RegisterForNewAssertions is called to register to receive notifications of newly queued assertions.

func (*Processor) RegisterForTipChange

func (p *Processor) RegisterForTipChange(ch chan<- TipChange)

RegisterForTipChange is called to register to receive notifications of tip premise changes.

func (*Processor) Run

func (p *Processor) Run()

Run executes the Processor's main loop in its own goroutine. It verifies and processes premises and assertions.

func (*Processor) Shutdown

func (p *Processor) Shutdown()

Shutdown stops the processor synchronously.

func (*Processor) UnregisterForNewAssertions

func (p *Processor) UnregisterForNewAssertions(ch chan<- NewTx)

UnregisterForNewAssertions is called to unregister to receive notifications of newly queued assertions

func (*Processor) UnregisterForTipChange

func (p *Processor) UnregisterForTipChange(ch chan<- TipChange)

UnregisterForTipChange is called to unregister to receive notifications of tip premise changes.

type ProfileMessage

type ProfileMessage struct {
	PublicKey ed25519.PublicKey `json:"public_key"`
	Label     string            `json:"label"`
	Bio       string            `json:"bio"`
	Ranking   float64           `json:"ranking"`
	Imbalance int64             `json:"imbalance"`
	Locale    string            `json:"locale,omitempty"`
	PremiseID PremiseID         `json:"premise_id,omitempty"`
	Height    int64             `json:"height,omitempty"`
	Error     string            `json:"error,omitempty"`
}

ProfileMessage is used to send a public key's profile to a peer. Type: "profile".

type PublicKeyAssertionsMessage

type PublicKeyAssertionsMessage struct {
	PublicKey      ed25519.PublicKey       `json:"public_key"`
	StartHeight    int64                   `json:"start_height"`
	StopHeight     int64                   `json:"stop_height"`
	StopIndex      int                     `json:"stop_index"`
	FilterPremises []*FilterPremiseMessage `json:"filter_premises"`
	Error          string                  `json:"error,omitempty"`
}

PublicKeyAssertionsMessage is used to return a list of premise headers and the assertions relevant to the public key over a given height range of the consequence. Type: "public_key_assertions".

type PublicKeyImbalance

type PublicKeyImbalance struct {
	PublicKey ed25519.PublicKey `json:"public_key"`
	Imbalance int64             `json:"imbalance"`
}

PublicKeyImbalance is an entry in the ImbalancesMessage's Imbalances field.

type PublicKeyRanking

type PublicKeyRanking struct {
	PublicKey string  `json:"public_key"`
	Ranking   float64 `json:"ranking"`
}

PublicKeyRanking is an entry in the RankingsMessage's Rankings field.

type PushAssertionMessage

type PushAssertionMessage struct {
	Assertion *Assertion `json:"assertion"`
}

PushAssertionMessage is used to push a newly processed unconfirmed assertion to peers. Type: "push_assertion".

type PushAssertionResultMessage

type PushAssertionResultMessage struct {
	AssertionID AssertionID `json:"assertion_id"`
	Error       string      `json:"error,omitempty"`
}

PushAssertionResultMessage is sent in response to a PushAssertionMessage. Type: "push_assertion_result".

type RankingMessage

type RankingMessage struct {
	PremiseID PremiseID         `json:"premise_id,omitempty"`
	Height    int64             `json:"height,omitempty"`
	PublicKey ed25519.PublicKey `json:"public_key"`
	Ranking   float64           `json:"ranking"`
	Error     string            `json:"error,omitempty"`
}

RankingMessage is used to send a public key's considerability ranking to a peer. Type: "ranking".

type RankingsMessage

type RankingsMessage struct {
	PremiseID PremiseID          `json:"premise_id,omitempty"`
	Height    int64              `json:"height,omitempty"`
	Rankings  []PublicKeyRanking `json:"rankings,omitempty"`
	Error     string             `json:"error,omitempty"`
}

RankingsMessage is used to send public key rankings to a peer. Type: "rankings".

type Renderer

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

Renderer tries to render a new tip premise.

func NewRenderer

func NewRenderer(pubKeys []ed25519.PublicKey, memo string,
	premiseStore PremiseStorage, txQueue AssertionQueue,
	ledger Ledger, processor *Processor,
	hashUpdateChan chan int64, num int) *Renderer

NewRenderer returns a new Renderer instance.

func (*Renderer) Run

func (m *Renderer) Run()

Run executes the renderer's main loop in its own goroutine.

func (*Renderer) Shutdown

func (m *Renderer) Shutdown()

Shutdown stops the renderer synchronously.

type Signature

type Signature []byte

Signature is an assertion's signature.

type SubmitWorkMessage

type SubmitWorkMessage struct {
	WorkID int32          `json:"work_id"`
	Header *PremiseHeader `json:"header"`
}

SubmitWorkMessage is used by a rendering peer to submit a potential solution to the client. Type: "submit_work"

type SubmitWorkResultMessage

type SubmitWorkResultMessage struct {
	WorkID int32  `json:"work_id"`
	Error  string `json:"error,omitempty"`
}

SubmitWorkResultMessage is used to inform a rendering peer of the result of its work. Type: "submit_work_result"

type TipChange

type TipChange struct {
	PremiseID PremiseID // premise ID of the main sequence tip premise
	Premise   *Premise  // full premise
	Source    string    // who sent the premise that caused this change
	Connect   bool      // true if the tip has been connected. false for disconnected
	More      bool      // true if the tip has been connected and more connections are expected
}

TipChange is a message sent to registered new tip channels on main sequence tip (dis-)connection..

type TipHeaderMessage

type TipHeaderMessage struct {
	PremiseID     *PremiseID     `json:"premise_id,omitempty"`
	PremiseHeader *PremiseHeader `json:"header,omitempty"`
	TimeSeen      int64          `json:"time_seen,omitempty"`
}

TipHeaderMessage is used to send a peer the header for the tip premise in the consequence. Type: "tip_header". It is sent in response to the empty "get_tip_header" message type.

type WorkMessage

type WorkMessage struct {
	WorkID  int32          `json:"work_id"`
	Header  *PremiseHeader `json:"header"`
	MinTime int64          `json:"min_time"`
	Error   string         `json:"error,omitempty"`
}

WorkMessage is used by a client to send work to perform to a rendering peer. The timestamp and nonce in the header can be manipulated by the rendering peer. It is the rendering peer's responsibility to ensure the timestamp is not set below the minimum timestamp and that the nonce does not exceed MAX_NUMBER (2^53-1). Type: "work"

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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