Move FilterID to types package

This commit is contained in:
Ian Davis 2022-12-07 18:34:19 +00:00
parent 067f08f092
commit 1afc32f650
6 changed files with 30 additions and 29 deletions

View File

@ -417,7 +417,6 @@ type EthFeeHistory struct {
Reward *[][]EthBigInt `json:"reward,omitempty"`
}
// An opaque identifier generated by the Lotus node to refer to an installed filter.
type EthFilterID EthHash
// An opaque identifier generated by the Lotus node to refer to an active subscription.

View File

@ -23,7 +23,7 @@ import (
const indexed uint8 = 0x01
type EventFilter struct {
id FilterID
id types.FilterID
minHeight abi.ChainEpoch // minimum epoch to apply filter or -1 if no minimum
maxHeight abi.ChainEpoch // maximum epoch to apply filter or -1 if no maximum
tipsetCid cid.Cid
@ -50,7 +50,7 @@ type CollectedEvent struct {
MsgCid cid.Cid // cid of message that produced event
}
func (f *EventFilter) ID() FilterID {
func (f *EventFilter) ID() types.FilterID {
return f.id
}
@ -289,7 +289,7 @@ type EventFilterManager struct {
EventIndex *EventIndex
mu sync.Mutex // guards mutations to filters
filters map[FilterID]*EventFilter
filters map[types.FilterID]*EventFilter
currentHeight abi.ChainEpoch
}
@ -388,7 +388,7 @@ func (m *EventFilterManager) Install(ctx context.Context, minHeight, maxHeight a
m.mu.Lock()
if m.filters == nil {
m.filters = make(map[FilterID]*EventFilter)
m.filters = make(map[types.FilterID]*EventFilter)
}
m.filters[id] = f
m.mu.Unlock()
@ -396,7 +396,7 @@ func (m *EventFilterManager) Install(ctx context.Context, minHeight, maxHeight a
return f, nil
}
func (m *EventFilterManager) Remove(ctx context.Context, id FilterID) error {
func (m *EventFilterManager) Remove(ctx context.Context, id types.FilterID) error {
m.mu.Lock()
defer m.mu.Unlock()
if _, found := m.filters[id]; !found {

View File

@ -13,7 +13,7 @@ import (
)
type MemPoolFilter struct {
id FilterID
id types.FilterID
maxResults int // maximum number of results to collect, 0 is unlimited
ch chan<- interface{}
@ -24,7 +24,7 @@ type MemPoolFilter struct {
var _ Filter = (*MemPoolFilter)(nil)
func (f *MemPoolFilter) ID() FilterID {
func (f *MemPoolFilter) ID() types.FilterID {
return f.id
}
@ -78,7 +78,7 @@ type MemPoolFilterManager struct {
MaxFilterResults int
mu sync.Mutex // guards mutations to filters
filters map[FilterID]*MemPoolFilter
filters map[types.FilterID]*MemPoolFilter
}
func (m *MemPoolFilterManager) WaitForMpoolUpdates(ctx context.Context, ch <-chan api.MpoolUpdate) {
@ -124,7 +124,7 @@ func (m *MemPoolFilterManager) Install(ctx context.Context) (*MemPoolFilter, err
m.mu.Lock()
if m.filters == nil {
m.filters = make(map[FilterID]*MemPoolFilter)
m.filters = make(map[types.FilterID]*MemPoolFilter)
}
m.filters[id] = f
m.mu.Unlock()
@ -132,7 +132,7 @@ func (m *MemPoolFilterManager) Install(ctx context.Context) (*MemPoolFilter, err
return f, nil
}
func (m *MemPoolFilterManager) Remove(ctx context.Context, id FilterID) error {
func (m *MemPoolFilterManager) Remove(ctx context.Context, id types.FilterID) error {
m.mu.Lock()
defer m.mu.Unlock()
if _, found := m.filters[id]; !found {

View File

@ -8,10 +8,12 @@ import (
"github.com/google/uuid"
"golang.org/x/xerrors"
"github.com/filecoin-project/lotus/chain/types"
)
type Filter interface {
ID() FilterID
ID() types.FilterID
LastTaken() time.Time
SetSubChannel(chan<- interface{})
ClearSubChannel()
@ -19,8 +21,8 @@ type Filter interface {
type FilterStore interface {
Add(context.Context, Filter) error
Get(context.Context, FilterID) (Filter, error)
Remove(context.Context, FilterID) error
Get(context.Context, types.FilterID) (Filter, error)
Remove(context.Context, types.FilterID) error
NotTakenSince(when time.Time) []Filter // returns a list of filters that have not had their collected results taken
}
@ -30,22 +32,20 @@ var (
ErrMaximumNumberOfFilters = errors.New("maximum number of filters registered")
)
type FilterID [32]byte // compatible with EthHash
func newFilterID() (FilterID, error) {
func newFilterID() (types.FilterID, error) {
rawid, err := uuid.NewRandom()
if err != nil {
return FilterID{}, xerrors.Errorf("new uuid: %w", err)
return types.FilterID{}, xerrors.Errorf("new uuid: %w", err)
}
id := FilterID{}
copy(id[:], rawid[:]) // uuid is 16 bytes
id := types.FilterID{}
copy(id[:], rawid[:]) // uuid is 16 bytes, the last 16 bytes are zeroed
return id, nil
}
type memFilterStore struct {
max int
mu sync.Mutex
filters map[FilterID]Filter
filters map[types.FilterID]Filter
}
var _ FilterStore = (*memFilterStore)(nil)
@ -53,7 +53,7 @@ var _ FilterStore = (*memFilterStore)(nil)
func NewMemFilterStore(maxFilters int) FilterStore {
return &memFilterStore{
max: maxFilters,
filters: make(map[FilterID]Filter),
filters: make(map[types.FilterID]Filter),
}
}
@ -72,7 +72,7 @@ func (m *memFilterStore) Add(_ context.Context, f Filter) error {
return nil
}
func (m *memFilterStore) Get(_ context.Context, id FilterID) (Filter, error) {
func (m *memFilterStore) Get(_ context.Context, id types.FilterID) (Filter, error) {
m.mu.Lock()
f, found := m.filters[id]
m.mu.Unlock()
@ -82,7 +82,7 @@ func (m *memFilterStore) Get(_ context.Context, id FilterID) (Filter, error) {
return f, nil
}
func (m *memFilterStore) Remove(_ context.Context, id FilterID) error {
func (m *memFilterStore) Remove(_ context.Context, id types.FilterID) error {
m.mu.Lock()
defer m.mu.Unlock()

View File

@ -11,7 +11,7 @@ import (
)
type TipSetFilter struct {
id FilterID
id types.FilterID
maxResults int // maximum number of results to collect, 0 is unlimited
ch chan<- interface{}
@ -22,7 +22,7 @@ type TipSetFilter struct {
var _ Filter = (*TipSetFilter)(nil)
func (f *TipSetFilter) ID() FilterID {
func (f *TipSetFilter) ID() types.FilterID {
return f.id
}
@ -76,7 +76,7 @@ type TipSetFilterManager struct {
MaxFilterResults int
mu sync.Mutex // guards mutations to filters
filters map[FilterID]*TipSetFilter
filters map[types.FilterID]*TipSetFilter
}
func (m *TipSetFilterManager) Apply(ctx context.Context, from, to *types.TipSet) error {
@ -111,7 +111,7 @@ func (m *TipSetFilterManager) Install(ctx context.Context) (*TipSetFilter, error
m.mu.Lock()
if m.filters == nil {
m.filters = make(map[FilterID]*TipSetFilter)
m.filters = make(map[types.FilterID]*TipSetFilter)
}
m.filters[id] = f
m.mu.Unlock()
@ -119,7 +119,7 @@ func (m *TipSetFilterManager) Install(ctx context.Context) (*TipSetFilter, error
return f, nil
}
func (m *TipSetFilterManager) Remove(ctx context.Context, id FilterID) error {
func (m *TipSetFilterManager) Remove(ctx context.Context, id types.FilterID) error {
m.mu.Lock()
defer m.mu.Unlock()
if _, found := m.filters[id]; !found {

View File

@ -22,3 +22,5 @@ type EventEntry struct {
// Any DAG-CBOR encodeable type.
Value []byte
}
type FilterID [32]byte // compatible with EthHash