fraud

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: Apache-2.0 Imports: 10 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OnProof

func OnProof(ctx context.Context, subscriber Subscriber, p ProofType, handle func(proof Proof))

OnProof subscribes to the given Fraud Proof topic via the given Subscriber. In case a Fraud Proof is received, then the given handle function will be invoked.

func Register

func Register(p Proof)

Register adds a string representation and unmarshaller for the provided ProofType.

func WithMetrics

func WithMetrics(store Getter)

WithMetrics enables metrics to monitor fraud proofs.

Types

type Broadcaster

type Broadcaster interface {
	// Broadcast takes a fraud `Proof` data structure interface and broadcasts it to local
	// subscriptions and peers. It may additionally cache/persist Proofs for future
	// access via Getter and to serve Proof requests to peers in the network.
	Broadcast(context.Context, Proof) error
}

Broadcaster is a generic interface that sends a `Proof` to all nodes subscribed on the Broadcaster's topic.

type ErrFraudExists

type ErrFraudExists struct {
	Proof []Proof
}

func (*ErrFraudExists) Error

func (e *ErrFraudExists) Error() string

type ErrNoUnmarshaler

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

func (*ErrNoUnmarshaler) Error

func (e *ErrNoUnmarshaler) Error() string

type Getter

type Getter interface {
	// Get fetches fraud proofs from the disk by its type.
	Get(context.Context, ProofType) ([]Proof, error)
}

Getter encompasses the behavior to fetch stored fraud proofs.

type HeaderFetcher

type HeaderFetcher func(context.Context, uint64) (header.Header, error)

HeaderFetcher aliases a function that is used to fetch an ExtendedHeader from store by height.

type Proof

type Proof interface {
	// Type returns the exact type of fraud proof.
	Type() ProofType
	// HeaderHash returns the block hash.
	HeaderHash() []byte
	// Height returns the block height corresponding to the Proof.
	Height() uint64
	// Validate check the validity of fraud proof.
	// Validate throws an error if some conditions don't pass and thus fraud proof is not valid.
	// NOTE: header.ExtendedHeader should pass basic validation otherwise it will panic if it's
	// malformed.
	Validate(header.Header) error

	encoding.BinaryMarshaler
	encoding.BinaryUnmarshaler
}

Proof is a generic interface that will be used for all types of fraud proofs in the network.

func Unmarshal

func Unmarshal(proofType ProofType, msg []byte) (Proof, error)

Unmarshal converts raw bytes into respective Proof type.

type ProofType

type ProofType string

ProofType type defines a unique proof type string.

func Registered

func Registered() []ProofType

Registered reports a set of registered proof types by Register.

func (ProofType) String

func (pt ProofType) String() string

String returns string representation of ProofType.

type ProofUnmarshaler

type ProofUnmarshaler func([]byte) (Proof, error)

ProofUnmarshaler aliases a function that parses data to `Proof`.

type Service

type Service interface {
	Subscriber
	Broadcaster
	Getter
}

Service encompasses the behavior necessary to subscribe and broadcast fraud proofs within the network.

type Subscriber

type Subscriber interface {
	// Subscribe allows to subscribe on a Proof pub sub topic by its type.
	Subscribe(ProofType) (Subscription, error)
	// AddVerifier allows for supplying additional verification logic which
	// will be run as part of processing the incoming fraud proof.
	// This only supplements the main validation done by Proof.Validate
	AddVerifier(ProofType, Verifier) error
}

Subscriber encompasses the behavior necessary to subscribe/unsubscribe from new FraudProof events from the network.

type Subscription

type Subscription interface {
	// Proof returns already verified valid proof.
	Proof(context.Context) (Proof, error)
	Cancel()
}

Subscription returns a valid proof if one is received on the topic.

type Verifier added in v0.1.1

type Verifier func(fraud Proof) (bool, error)

Verifier is a function that is executed as part of processing the incoming fraud proof

Directories

Path Synopsis
pb

Jump to

Keyboard shortcuts

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