fraud

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 8 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OnProof

func OnProof[H header.Header[H]](ctx context.Context, sub Subscriber[H], p ProofType, handle func(proof Proof[H]))

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 WithMetrics

func WithMetrics[H header.Header[H]](store Getter[H], unmarshaler ProofUnmarshaler[H])

WithMetrics enables metrics to monitor fraud proofs.

Types

type Broadcaster

type Broadcaster[H header.Header[H]] 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[H]) error
}

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

type ErrFraudExists

type ErrFraudExists[H header.Header[H]] struct {
	Proof []Proof[H]
}

func (*ErrFraudExists[H]) Error

func (e *ErrFraudExists[H]) Error() string

type ErrNoUnmarshaler

type ErrNoUnmarshaler struct {
	ProofType ProofType
}

func (*ErrNoUnmarshaler) Error

func (e *ErrNoUnmarshaler) Error() string

type Getter

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

Getter encompasses the behavior to fetch stored fraud proofs.

type HeadGetter added in v0.2.1

type HeadGetter[H header.Header[H]] func(ctx context.Context) (H, error)

HeadGetter aliases a function that is used to get current network head.

type HeaderFetcher

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

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

type MultiUnmarshaler added in v0.2.0

type MultiUnmarshaler[H header.Header[H]] struct {
	Unmarshalers map[ProofType]func([]byte) (Proof[H], error)
}

MultiUnmarshaler contains a mapping of all registered proof types to their unmarshal functions.

func (MultiUnmarshaler[H]) List added in v0.2.0

func (d MultiUnmarshaler[H]) List() []ProofType

func (MultiUnmarshaler[H]) Unmarshal added in v0.2.0

func (d MultiUnmarshaler[H]) Unmarshal(proofType ProofType, data []byte) (Proof[H], error)

type Proof

type Proof[H header.Header[H]] 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(H) error

	encoding.BinaryMarshaler
	encoding.BinaryUnmarshaler
}

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

type ProofType

type ProofType string

ProofType type defines a unique proof type string.

func (ProofType) String

func (pt ProofType) String() string

String returns string representation of ProofType.

type ProofUnmarshaler

type ProofUnmarshaler[H header.Header[H]] interface {
	// List supported ProofTypes.
	List() []ProofType
	// Unmarshal decodes bytes into a Proof of a given ProofType.
	Unmarshal(ProofType, []byte) (Proof[H], error)
}

ProofUnmarshaler contains methods that allow an instance of ProofService to access unmarshalers for various ProofTypes.

type Service

type Service[H header.Header[H]] interface {
	Subscriber[H]
	Broadcaster[H]
	Getter[H]
}

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

type Subscriber

type Subscriber[H header.Header[H]] interface {
	// Subscribe allows to subscribe on a Proof pub sub topic by its type.
	Subscribe(ProofType) (Subscription[H], 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[H]) error
}

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

type Subscription

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

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

type Verifier added in v0.1.1

type Verifier[H header.Header[H]] func(fraud Proof[H]) (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