Merge branch 'release/v1.20.0' into iand/eth-openrpc-validate
This commit is contained in:
commit
4500c02e49
@ -20,7 +20,12 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/types"
|
"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 {
|
type EventFilter struct {
|
||||||
id types.FilterID
|
id types.FilterID
|
||||||
@ -100,18 +105,18 @@ func (f *EventFilter) CollectEvents(ctx context.Context, te *TipSetEvents, rever
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
decodedEntries := make([]types.EventEntry, len(ev.Entries))
|
entries := make([]types.EventEntry, len(ev.Entries))
|
||||||
for i, entry := range ev.Entries {
|
for i, entry := range ev.Entries {
|
||||||
decodedEntries[i] = types.EventEntry{
|
entries[i] = types.EventEntry{
|
||||||
Flags: entry.Flags,
|
Flags: entry.Flags,
|
||||||
Key: entry.Key,
|
Key: entry.Key,
|
||||||
Value: decodeLogBytes(entry.Value),
|
Value: entry.Value,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// event matches filter, so record it
|
// event matches filter, so record it
|
||||||
cev := &CollectedEvent{
|
cev := &CollectedEvent{
|
||||||
Entries: decodedEntries,
|
Entries: entries,
|
||||||
EmitterAddr: addr,
|
EmitterAddr: addr,
|
||||||
EventIdx: evIdx,
|
EventIdx: evIdx,
|
||||||
Reverted: revert,
|
Reverted: revert,
|
||||||
@ -209,7 +214,7 @@ func (f *EventFilter) matchKeys(ees []types.EventEntry) bool {
|
|||||||
matched := map[string]bool{}
|
matched := map[string]bool{}
|
||||||
for _, ee := range ees {
|
for _, ee := range ees {
|
||||||
// Skip an entry that is not indexable
|
// Skip an entry that is not indexable
|
||||||
if ee.Flags&indexed != indexed {
|
if !isIndexedValue(ee.Flags) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,7 +226,7 @@ func (f *EventFilter) matchKeys(ees []types.EventEntry) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wantlist, ok := f.keys[keyname]
|
wantlist, ok := f.keys[keyname]
|
||||||
if !ok {
|
if !ok || len(wantlist) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package filter
|
package filter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
@ -11,7 +10,6 @@ import (
|
|||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
cbg "github.com/whyrusleeping/cbor-gen"
|
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
@ -153,13 +151,6 @@ func (ei *EventIndex) CollectEvents(ctx context.Context, te *TipSetEvents, rever
|
|||||||
return xerrors.Errorf("prepare insert entry: %w", err)
|
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 msgIdx, em := range ems {
|
||||||
for evIdx, ev := range em.Events() {
|
for evIdx, ev := range em.Events() {
|
||||||
addr, found := addressLookups[ev.Emitter]
|
addr, found := addressLookups[ev.Emitter]
|
||||||
@ -198,13 +189,12 @@ func (ei *EventIndex) CollectEvents(ctx context.Context, te *TipSetEvents, rever
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, entry := range ev.Entries {
|
for _, entry := range ev.Entries {
|
||||||
value := decodeLogBytes(entry.Value)
|
|
||||||
_, err := stmtEntry.Exec(
|
_, err := stmtEntry.Exec(
|
||||||
lastID, // event_id
|
lastID, // event_id
|
||||||
isIndexedValue(entry.Flags), // indexed
|
isIndexedValue(entry.Flags), // indexed
|
||||||
[]byte{entry.Flags}, // flags
|
[]byte{entry.Flags}, // flags
|
||||||
entry.Key, // key
|
entry.Key, // key
|
||||||
value, // value
|
entry.Value, // value
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("exec insert entry: %w", err)
|
return xerrors.Errorf("exec insert entry: %w", err)
|
||||||
@ -220,21 +210,6 @@ func (ei *EventIndex) CollectEvents(ctx context.Context, te *TipSetEvents, rever
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// decodeLogBytes decodes a CBOR-serialized array into its original form.
|
|
||||||
//
|
|
||||||
// This function swallows errors and returns the original array if it failed
|
|
||||||
// to decode.
|
|
||||||
func decodeLogBytes(orig []byte) []byte {
|
|
||||||
if len(orig) == 0 {
|
|
||||||
return orig
|
|
||||||
}
|
|
||||||
decoded, err := cbg.ReadByteArray(bytes.NewReader(orig), uint64(len(orig)))
|
|
||||||
if err != nil {
|
|
||||||
return orig
|
|
||||||
}
|
|
||||||
return decoded
|
|
||||||
}
|
|
||||||
|
|
||||||
// PrefillFilter fills a filter's collection of events from the historic index
|
// PrefillFilter fills a filter's collection of events from the historic index
|
||||||
func (ei *EventIndex) PrefillFilter(ctx context.Context, f *EventFilter) error {
|
func (ei *EventIndex) PrefillFilter(ctx context.Context, f *EventFilter) error {
|
||||||
clauses := []string{}
|
clauses := []string{}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1013,9 +1013,6 @@ func (e *EthEvent) EthNewFilter(ctx context.Context, filterSpec *ethtypes.EthFil
|
|||||||
|
|
||||||
return ethtypes.EthFilterID{}, err
|
return ethtypes.EthFilterID{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("REMOVEME: EthNewFilter.f=%+v\n", f)
|
|
||||||
|
|
||||||
return ethtypes.EthFilterID(f.ID()), nil
|
return ethtypes.EthFilterID(f.ID()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user