fraud

package
v0.4.8-dirty Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2022 License: Apache-2.0 Imports: 40 Imported by: 0

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 added in v0.4.0

func WithMetrics(store Getter)

WithMetrics enables metrics to monitor fraud proofs.

Types

type BadEncodingProof

type BadEncodingProof struct {
	BlockHeight uint64
	// ShareWithProof contains all shares from row or col.
	// Shares that did not pass verification in rsmt2d will be nil.
	// For non-nil shares MerkleProofs are computed.
	Shares []*ipld.ShareWithProof
	// Index represents the row/col index where ErrByzantineRow/ErrByzantineColl occurred.
	Index uint32
	// Axis represents the axis that verification failed on.
	Axis rsmt2d.Axis
	// contains filtered or unexported fields
}

func (*BadEncodingProof) HeaderHash

func (p *BadEncodingProof) HeaderHash() []byte

HeaderHash returns block hash.

func (*BadEncodingProof) Height

func (p *BadEncodingProof) Height() uint64

Height returns block height.

func (*BadEncodingProof) MarshalBinary

func (p *BadEncodingProof) MarshalBinary() ([]byte, error)

MarshalBinary converts BadEncodingProof to binary.

func (*BadEncodingProof) Type

func (p *BadEncodingProof) Type() ProofType

Type returns type of fraud proof.

func (*BadEncodingProof) UnmarshalBinary

func (p *BadEncodingProof) UnmarshalBinary(data []byte) error

UnmarshalBinary converts binary to BadEncodingProof.

func (*BadEncodingProof) Validate

func (p *BadEncodingProof) Validate(header *header.ExtendedHeader) error

Validate ensures that fraud proof is correct. Validate checks that provided Merkle Proofs correspond to the shares, rebuilds bad row or col from received shares, computes Merkle Root and compares it with block's Merkle Root.

type Broadcaster

type Broadcaster interface {
	// Broadcast takes a fraud `Proof` data structure that implements standard BinaryMarshal
	// interface and broadcasts it to all subscribed peers.
	Broadcast(context.Context, Proof) error
}

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

type DummyService

type DummyService struct {
}

func (*DummyService) Broadcast

func (d *DummyService) Broadcast(context.Context, Proof) error

func (*DummyService) Get

func (*DummyService) Subscribe

func (d *DummyService) Subscribe(ProofType) (Subscription, error)

type ErrFraudExists

type ErrFraudExists struct {
	Proof []Proof
}

func (*ErrFraudExists) Error

func (e *ErrFraudExists) 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 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.ExtendedHeader) error

	encoding.BinaryMarshaler
	encoding.BinaryUnmarshaler
}

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

func CreateBadEncodingProof

func CreateBadEncodingProof(
	hash []byte,
	height uint64,
	errByzantine *ipld.ErrByzantine,
) Proof

CreateBadEncodingProof creates a new Bad Encoding Fraud Proof that should be propagated through network. The fraud proof will contain shares that did not pass verification and their relevant Merkle proofs.

func Unmarshal

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

Unmarshal converts raw bytes into respective Proof type.

type ProofService

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

ProofService is responsible for validating and propagating Fraud Proofs. It implements the Service interface.

func NewProofService

func NewProofService(
	p *pubsub.PubSub,
	host host.Host,
	getter headerFetcher,
	ds datastore.Datastore,
	syncerEnabled bool,
) *ProofService

func (*ProofService) Broadcast

func (f *ProofService) Broadcast(ctx context.Context, p Proof) error

func (*ProofService) Get

func (f *ProofService) Get(ctx context.Context, proofType ProofType) ([]Proof, error)

func (*ProofService) Start

func (f *ProofService) Start(context.Context) error

Start joins fraud proofs topics, sets the stream handler for fraudProtocolID and starts syncing if syncer is enabled.

func (*ProofService) Stop

func (f *ProofService) Stop(context.Context) error

Stop removes the stream handler and cancels the underlying ProofService

func (*ProofService) Subscribe

func (f *ProofService) Subscribe(proofType ProofType) (_ Subscription, err error)

type ProofType

type ProofType string
const (
	BadEncoding ProofType = "badencoding"
)

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)
}

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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