forked from celestiaorg/go-fraud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterface.go
58 lines (48 loc) · 1.97 KB
/
interface.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package fraud
import (
"context"
"github.com/celestiaorg/go-header"
)
// HeaderFetcher aliases a function that is used to fetch an ExtendedHeader from store by height.
type HeaderFetcher func(context.Context, uint64) (header.Header, error)
// Verifier is a function that is executed as part of processing the incoming fraud proof
type Verifier func(fraud Proof) (bool, error)
// ProofUnmarshaler aliases a function that parses data to `Proof`.
type ProofUnmarshaler func([]byte) (Proof, error)
// Service encompasses the behavior necessary to subscribe and broadcast
// fraud proofs within the network.
type Service interface {
Subscriber
Broadcaster
Getter
}
// Broadcaster is a generic interface that sends a `Proof` to all nodes subscribed on the
// Broadcaster's topic.
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
}
// Subscriber encompasses the behavior necessary to
// subscribe/unsubscribe from new FraudProof events from the
// network.
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
}
// Getter encompasses the behavior to fetch stored fraud proofs.
type Getter interface {
// Get fetches fraud proofs from the disk by its type.
Get(context.Context, ProofType) ([]Proof, error)
}
// Subscription returns a valid proof if one is received on the topic.
type Subscription interface {
// Proof returns already verified valid proof.
Proof(context.Context) (Proof, error)
Cancel()
}