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

chore: update fvm #5704

Merged
merged 6 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
53 changes: 9 additions & 44 deletions app/submodule/eth/eth_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1248,11 +1248,6 @@ func newEthTxReceipt(ctx context.Context, tx types.EthTx, lookup *types.MsgLooku
}

if len(events) > 0 {
// TODO return a dummy non-zero bloom to signal that there are logs
// need to figure out how worth it is to populate with a real bloom
// should be feasible here since we are iterating over the logs anyway
receipt.LogsBloom[255] = 0x01

receipt.Logs = make([]types.EthLog, 0, len(events))
for i, evt := range events {
l := types.EthLog{
Expand All @@ -1265,14 +1260,15 @@ func newEthTxReceipt(ctx context.Context, tx types.EthTx, lookup *types.MsgLooku
}

for _, entry := range evt.Entries {
value, err := cborDecodeTopicValue(entry.Value)
if err != nil {
return types.EthTxReceipt{}, fmt.Errorf("failed to decode event log value: %w", err)
// Ignore any non-raw values/keys.
if entry.Codec != cid.Raw {
continue
}
if entry.Key == types.EthTopic1 || entry.Key == types.EthTopic2 || entry.Key == types.EthTopic3 || entry.Key == types.EthTopic4 {
l.Topics = append(l.Topics, value)
types.EthBloomSet(receipt.LogsBloom, entry.Value)
l.Topics = append(l.Topics, entry.Value)
} else {
l.Data = value
l.Data = entry.Value
}
}

Expand All @@ -1286,6 +1282,7 @@ func newEthTxReceipt(ctx context.Context, tx types.EthTx, lookup *types.MsgLooku
return types.EthTxReceipt{}, fmt.Errorf("failed to resolve Ethereum address: %w", err)
}

types.EthBloomSet(receipt.LogsBloom, l.Address[:])
receipt.Logs = append(receipt.Logs, l)
}
}
Expand Down Expand Up @@ -1371,35 +1368,6 @@ func ethTxHashGC(ctx context.Context, retentionDays int, manager *ethTxHashManag
}
}

func trimLeadingZeros(b []byte) []byte {
for i := range b {
if b[i] != 0 {
return b[i:]
}
}
return []byte{}
}

func cborEncodeTopicValue(orig []byte) ([]byte, error) {
var buf bytes.Buffer
err := cbg.WriteByteArray(&buf, trimLeadingZeros(orig))
if err != nil {
return nil, err
}
return buf.Bytes(), nil
}

func cborDecodeTopicValue(orig []byte) ([]byte, error) {
if len(orig) == 0 {
return orig, nil
}
decoded, err := cbg.ReadByteArray(bytes.NewReader(orig), uint64(len(orig)))
if err != nil {
return nil, err
}
return leftpad32(decoded), nil
}

func parseEthTopics(topics types.EthTopicSpec) (map[string][][]byte, error) {
keys := map[string][][]byte{}
for idx, vals := range topics {
Expand All @@ -1409,11 +1377,8 @@ func parseEthTopics(topics types.EthTopicSpec) (map[string][][]byte, error) {
// Ethereum topics are emitted using `LOG{0..4}` opcodes resulting in topics1..4
key := fmt.Sprintf("t%d", idx+1)
for _, v := range vals {
encodedVal, err := cborEncodeTopicValue(v[:])
if err != nil {
return nil, fmt.Errorf("failed to encode topic value")
}
keys[key] = append(keys[key], encodedVal)
v := v // copy the ethhash to avoid repeatedly referencing the same one.
keys[key] = append(keys[key], v[:])
}
}
return keys, nil
Expand Down
22 changes: 6 additions & 16 deletions app/submodule/eth/eth_event_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func newEthEventAPI(ctx context.Context, em *EthSubModule) (*ethEventAPI, error)

ee.SubManager = &EthSubscriptionManager{
ChainAPI: chainAPI,
messageStore: ee.SubManager.messageStore,
messageStore: ee.em.chainModule.MessageStore,
}
ee.FilterStore = filter.NewMemFilterStore(cfg.Event.MaxFilters)

Expand Down Expand Up @@ -557,14 +557,14 @@ func ethFilterResultFromEvents(evs []*filter.CollectedEvent, ms *chain.MessageSt
var err error

for _, entry := range ev.Entries {
value, err := cborDecodeTopicValue(entry.Value)
if err != nil {
return nil, err
// Skip all events that aren't "raw" data.
if entry.Codec != cid.Raw {
continue
}
if entry.Key == types.EthTopic1 || entry.Key == types.EthTopic2 || entry.Key == types.EthTopic3 || entry.Key == types.EthTopic4 {
log.Topics = append(log.Topics, value)
log.Topics = append(log.Topics, entry.Value)
} else {
log.Data = value
log.Data = entry.Value
}
}

Expand Down Expand Up @@ -753,13 +753,3 @@ func (e *ethSubscription) stop() {
e.quit = 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
}
2 changes: 1 addition & 1 deletion fixtures/networks/butterfly.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func ButterflySnapNet() *NetworkConf {
Network: config.NetworkParamsConfig{
DevNet: true,
NetworkType: types.NetworkButterfly,
GenesisNetworkVersion: network.Version16,
GenesisNetworkVersion: network.Version17,
ReplaceProofTypes: []abi.RegisteredSealProof{
abi.RegisteredSealProof_StackedDrg512MiBV1,
abi.RegisteredSealProof_StackedDrg32GiBV1,
Expand Down
11 changes: 1 addition & 10 deletions pkg/events/filter/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,9 @@ func (f *EventFilter) CollectEvents(ctx context.Context, te *TipSetEvents, rever
continue
}

entries := make([]types.EventEntry, len(ev.Entries))
for i, entry := range ev.Entries {
entries[i] = types.EventEntry{
Flags: entry.Flags,
Key: entry.Key,
Value: entry.Value,
}
}

// event matches filter, so record it
cev := &CollectedEvent{
Entries: entries,
Entries: ev.Entries,
EmitterAddr: addr,
EventIdx: evIdx,
Reverted: revert,
Expand Down
2 changes: 2 additions & 0 deletions pkg/events/filter/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ func fakeEvent(emitter abi.ActorID, indexed []kv, unindexed []kv) *types.Event {
ev.Entries = append(ev.Entries, types.EventEntry{
Flags: 0x01,
Key: in.k,
Codec: cid.Raw,
Value: in.v,
})
}
Expand All @@ -294,6 +295,7 @@ func fakeEvent(emitter abi.ActorID, indexed []kv, unindexed []kv) *types.Event {
ev.Entries = append(ev.Entries, types.EventEntry{
Flags: 0x00,
Key: in.k,
Codec: cid.Raw,
Value: in.v,
})
}
Expand Down
21 changes: 9 additions & 12 deletions pkg/events/filter/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var ddls = []string{
indexed INTEGER NOT NULL,
flags BLOB NOT NULL,
key TEXT NOT NULL,
codec INTEGER,
value BLOB NOT NULL
)`,

Expand All @@ -65,8 +66,8 @@ const (
VALUES(?, ?, ?, ?, ?, ?, ?, ?)`

insertEntry = `INSERT OR IGNORE INTO event_entry
(event_id, indexed, flags, key, value)
VALUES(?, ?, ?, ?, ?)`
(event_id, indexed, flags, key, codec, value)
VALUES(?, ?, ?, ?, ?, ?)`
)

type EventIndex struct {
Expand Down Expand Up @@ -192,6 +193,7 @@ func (ei *EventIndex) CollectEvents(ctx context.Context, te *TipSetEvents, rever
isIndexedValue(entry.Flags), // indexed
[]byte{entry.Flags}, // flags
entry.Key, // key
entry.Codec, // codec
entry.Value, // value
)
if err != nil {
Expand Down Expand Up @@ -249,7 +251,7 @@ func (ei *EventIndex) PrefillFilter(ctx context.Context, f *EventFilter) error {
subclauses := []string{}
for _, val := range vals {
subclauses = append(subclauses, fmt.Sprintf("%s.value=?", joinAlias))
values = append(values, trimLeadingZeros(val))
values = append(values, val)
}
clauses = append(clauses, "("+strings.Join(subclauses, " OR ")+")")
}
Expand All @@ -268,6 +270,7 @@ func (ei *EventIndex) PrefillFilter(ctx context.Context, f *EventFilter) error {
event.reverted,
event_entry.flags,
event_entry.key,
event_entry.codec,
event_entry.value
FROM event JOIN event_entry ON event.id=event_entry.event_id`

Expand Down Expand Up @@ -317,6 +320,7 @@ func (ei *EventIndex) PrefillFilter(ctx context.Context, f *EventFilter) error {
reverted bool
flags []byte
key string
codec uint64
value []byte
}

Expand All @@ -332,6 +336,7 @@ func (ei *EventIndex) PrefillFilter(ctx context.Context, f *EventFilter) error {
&row.reverted,
&row.flags,
&row.key,
&row.codec,
&row.value,
); err != nil {
return fmt.Errorf("read prefill row: %w", err)
Expand Down Expand Up @@ -376,6 +381,7 @@ func (ei *EventIndex) PrefillFilter(ctx context.Context, f *EventFilter) error {
ce.Entries = append(ce.Entries, types.EventEntry{
Flags: row.flags[0],
Key: row.key,
Codec: row.codec,
Value: row.value,
})

Expand All @@ -396,12 +402,3 @@ func (ei *EventIndex) PrefillFilter(ctx context.Context, f *EventFilter) error {

return nil
}

func trimLeadingZeros(b []byte) []byte {
for i := range b {
if b[i] != 0 {
return b[i:]
}
}
return []byte{}
}
Binary file modified venus-shared/actors/builtin-actors-code/v10.tar.zst
Binary file not shown.
Loading