Skip to content

Commit

Permalink
fix naming
Browse files Browse the repository at this point in the history
  • Loading branch information
aarshkshah1992 committed Jun 14, 2024
1 parent 2421644 commit 67fbe6a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
36 changes: 18 additions & 18 deletions chain/events/filter/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,18 @@ type EventIndex struct {
stmtRevertEventSeen *sql.Stmt
stmtRestoreEventSeen *sql.Stmt

mu sync.Mutex
subIdCounter uint64
subscribedTipsets map[uint64]*tipsetSub
mu sync.Mutex
subIdCounter uint64
updateSubs map[uint64]*updateSub
}

type tipsetSub struct {
type updateSub struct {
ctx context.Context
ch chan *TipsetUpdate
ch chan *EventIndexUpdate
cancel context.CancelFunc
}

type TipsetUpdate struct {
type EventIndexUpdate struct {
Height uint64
TipsetCid cid.Cid
Reverted bool
Expand Down Expand Up @@ -628,7 +628,7 @@ func NewEventIndex(ctx context.Context, path string, chainStore *store.ChainStor
return nil, xerrors.Errorf("error preparing eventIndex database statements: %w", err)
}

eventIndex.subscribedTipsets = make(map[uint64]*tipsetSub)
eventIndex.updateSubs = make(map[uint64]*updateSub)

return &eventIndex, nil
}
Expand All @@ -640,11 +640,11 @@ func (ei *EventIndex) Close() error {
return ei.db.Close()
}

func (ei *EventIndex) SubscribeTipsetUpdates() (uint64, chan *TipsetUpdate) {
func (ei *EventIndex) SubscribeUpdates() (uint64, chan *EventIndexUpdate) {
subCtx, subCancel := context.WithCancel(context.Background())
ch := make(chan *TipsetUpdate)
ch := make(chan *EventIndexUpdate)

tSub := &tipsetSub{
tSub := &updateSub{
ctx: subCtx,
cancel: subCancel,
ch: ch,
Expand All @@ -653,20 +653,20 @@ func (ei *EventIndex) SubscribeTipsetUpdates() (uint64, chan *TipsetUpdate) {
ei.mu.Lock()
subId := ei.subIdCounter
ei.subIdCounter++
ei.subscribedTipsets[subId] = tSub
ei.updateSubs[subId] = tSub
ei.mu.Unlock()

return subId, tSub.ch
}

func (ei *EventIndex) UnsubscribeTipsetUpdates(subId uint64) {
func (ei *EventIndex) UnsubscribeUpdates(subId uint64) {
ei.mu.Lock()
tSub, ok := ei.subscribedTipsets[subId]
tSub, ok := ei.updateSubs[subId]
if !ok {
ei.mu.Unlock()
return
}
delete(ei.subscribedTipsets, subId)
delete(ei.updateSubs, subId)
ei.mu.Unlock()

// cancel the subscription
Expand Down Expand Up @@ -726,13 +726,13 @@ func (ei *EventIndex) CollectEvents(ctx context.Context, te *TipSetEvents, rever
}

ei.mu.Lock()
tSubs := ei.subscribedTipsets
tSubs := ei.updateSubs
ei.mu.Unlock()

for _, tSub := range tSubs {
tSub := tSub
select {
case tSub.ch <- &TipsetUpdate{
case tSub.ch <- &EventIndexUpdate{
Height: uint64(te.msgTs.Height()),
TipsetCid: tsKeyCid,
Reverted: true,
Expand Down Expand Up @@ -886,13 +886,13 @@ func (ei *EventIndex) CollectEvents(ctx context.Context, te *TipSetEvents, rever
}

ei.mu.Lock()
tSubs := ei.subscribedTipsets
tSubs := ei.updateSubs
ei.mu.Unlock()

for _, tSub := range tSubs {
tSub := tSub
select {
case tSub.ch <- &TipsetUpdate{
case tSub.ch <- &EventIndexUpdate{
Height: uint64(te.msgTs.Height()),
TipsetCid: tsKeyCid,
Reverted: false,
Expand Down
8 changes: 4 additions & 4 deletions chain/events/filter/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func TestEventIndexPrefillFilter(t *testing.T) {
ei, err := NewEventIndex(context.Background(), dbPath, nil)
require.NoError(t, err, "create event index")

_, subCh := ei.SubscribeTipsetUpdates()
out := make(chan *TipsetUpdate, 1)
_, subCh := ei.SubscribeUpdates()
out := make(chan *EventIndexUpdate, 1)
go func() {
tu := <-subCh
out <- tu
Expand Down Expand Up @@ -435,8 +435,8 @@ func TestEventIndexPrefillFilterExcludeReverted(t *testing.T) {
ei, err := NewEventIndex(context.Background(), dbPath, nil)
require.NoError(t, err, "create event index")

tCh := make(chan *TipsetUpdate, 3)
_, subCh := ei.SubscribeTipsetUpdates()
tCh := make(chan *EventIndexUpdate, 3)
_, subCh := ei.SubscribeUpdates()
go func() {
cnt := 0
for tu := range subCh {
Expand Down
4 changes: 2 additions & 2 deletions node/impl/full/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -1321,8 +1321,8 @@ func (e *EthEventHandler) waitForHeightProcessed(ctx context.Context, height abi
return xerrors.New("height is in the future")
}

subId, subCh := ei.SubscribeTipsetUpdates()
defer ei.UnsubscribeTipsetUpdates(subId)
subId, subCh := ei.SubscribeUpdates()
defer ei.UnsubscribeUpdates(subId)

for {
select {
Expand Down

0 comments on commit 67fbe6a

Please sign in to comment.