-
Notifications
You must be signed in to change notification settings - Fork 913
/
constructors.go
64 lines (51 loc) · 1.82 KB
/
constructors.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
59
60
61
62
63
64
package das
import (
"context"
"fmt"
"time"
"github.com/ipfs/go-datastore"
"github.com/celestiaorg/go-fraud"
libhead "github.com/celestiaorg/go-header"
"github.com/celestiaorg/celestia-node/das"
"github.com/celestiaorg/celestia-node/header"
modfraud "github.com/celestiaorg/celestia-node/nodebuilder/fraud"
"github.com/celestiaorg/celestia-node/pruner"
"github.com/celestiaorg/celestia-node/share"
"github.com/celestiaorg/celestia-node/share/eds/byzantine"
"github.com/celestiaorg/celestia-node/share/p2p/shrexsub"
)
var _ Module = (*daserStub)(nil)
var errStub = fmt.Errorf("module/das: stubbed: dasing is not available on bridge nodes")
// daserStub is a stub implementation of the DASer that is used on bridge nodes, so that we can
// provide a friendlier error when users try to access the daser over the API.
type daserStub struct{}
func (d daserStub) SamplingStats(context.Context) (das.SamplingStats, error) {
return das.SamplingStats{}, errStub
}
func (d daserStub) WaitCatchUp(context.Context) error {
return errStub
}
func newDaserStub() Module {
return &daserStub{}
}
func newDASer(
da share.Availability,
hsub libhead.Subscriber[*header.ExtendedHeader],
store libhead.Store[*header.ExtendedHeader],
batching datastore.Batching,
fraudServ fraud.Service[*header.ExtendedHeader],
bFn shrexsub.BroadcastFn,
availWindow pruner.AvailabilityWindow,
options ...das.Option,
) (*das.DASer, *modfraud.ServiceBreaker[*das.DASer, *header.ExtendedHeader], error) {
options = append(options, das.WithSamplingWindow(time.Duration(availWindow)))
ds, err := das.NewDASer(da, hsub, store, batching, fraudServ, bFn, options...)
if err != nil {
return nil, nil, err
}
return ds, &modfraud.ServiceBreaker[*das.DASer, *header.ExtendedHeader]{
Service: ds,
FraudServ: fraudServ,
FraudType: byzantine.BadEncoding,
}, nil
}