Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

itests: add event matrix tests for realtime eth filters and subscriptions #10083

Merged
merged 5 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions chain/events/filter/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ import (
"github.com/filecoin-project/lotus/chain/types"
)

const indexed uint8 = 0x01
func isIndexedValue(b uint8) bool {
// currently we mark the full entry as indexed if either the key
// or the value are indexed; in the future we will need finer-grained
// management of indices
return b&(types.EventFlagIndexedKey|types.EventFlagIndexedValue) > 0
}

type EventFilter struct {
id types.FilterID
Expand Down Expand Up @@ -209,7 +214,7 @@ func (f *EventFilter) matchKeys(ees []types.EventEntry) bool {
matched := map[string]bool{}
for _, ee := range ees {
// Skip an entry that is not indexable
if ee.Flags&indexed != indexed {
if !isIndexedValue(ee.Flags) {
continue
}

Expand All @@ -221,12 +226,15 @@ func (f *EventFilter) matchKeys(ees []types.EventEntry) bool {
}

wantlist, ok := f.keys[keyname]
if !ok {
if !ok || len(wantlist) == 0 {
continue
}

for _, w := range wantlist {
if bytes.Equal(w, ee.Value) {
// TODO: remove this. Currently the filters use raw values but the value in the entry is cbor-encoded
// We want to make all internal values cbor-encoded as per https://github.com/filecoin-project/ref-fvm/issues/1345
value := leftpad32(decodeLogBytes(ee.Value))
if bytes.Equal(w, value) {
matched[keyname] = true
break
}
Expand Down Expand Up @@ -481,3 +489,13 @@ func (m *EventFilterManager) loadExecutedMessages(ctx context.Context, msgTs, rc

return ems, nil
}

func leftpad32(orig []byte) []byte {
needed := 32 - len(orig)
if needed <= 0 {
return orig
}
ret := make([]byte, 32)
copy(ret[needed:], orig)
return ret
}
7 changes: 0 additions & 7 deletions chain/events/filter/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,6 @@ func (ei *EventIndex) CollectEvents(ctx context.Context, te *TipSetEvents, rever
return xerrors.Errorf("prepare insert entry: %w", err)
}

isIndexedValue := func(b uint8) bool {
// currently we mark the full entry as indexed if either the key
// or the value are indexed; in the future we will need finer-grained
// management of indices
return b&(types.EventFlagIndexedKey|types.EventFlagIndexedValue) > 0
}

for msgIdx, em := range ems {
for evIdx, ev := range em.Events() {
addr, found := addressLookups[ev.Emitter]
Expand Down
Loading