-
Notifications
You must be signed in to change notification settings - Fork 459
/
events.go
44 lines (33 loc) · 1.07 KB
/
events.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
package events
import (
"context"
"github.com/filecoin-project/go-state-types/abi"
logging "github.com/ipfs/go-log/v2"
"github.com/filecoin-project/venus/pkg/constants"
"github.com/filecoin-project/venus/pkg/types"
)
var log = logging.Logger("events")
// HeightHandler `curH`-`ts.Height` = `confidence`
type (
HeightHandler func(ctx context.Context, ts *types.TipSet, curH abi.ChainEpoch) error
RevertHandler func(ctx context.Context, ts *types.TipSet) error
)
type Events struct {
*observer
*heightEvents
*hcEvents
}
func NewEventsWithConfidence(ctx context.Context, api IEvent, gcConfidence abi.ChainEpoch) (*Events, error) {
cache := newCache(api, gcConfidence)
ob := newObserver(cache, gcConfidence)
if err := ob.start(ctx); err != nil {
return nil, err
}
he := newHeightEvents(cache, ob, gcConfidence)
headChange := newHCEvents(cache, ob)
return &Events{ob, he, headChange}, nil
}
func NewEvents(ctx context.Context, api IEvent) (*Events, error) {
gcConfidence := 2 * constants.ForkLengthThreshold
return NewEventsWithConfidence(ctx, api, gcConfidence)
}