From 52fdf7c9a4554acadca3409e1d886879fda9025d Mon Sep 17 00:00:00 2001 From: simlecode <69969590+simlecode@users.noreply.github.com> Date: Wed, 16 Oct 2024 18:18:15 +0800 Subject: [PATCH] chore: fix lint --- app/submodule/eth/eth_api.go | 4 +-- app/submodule/eth/eth_event_api.go | 2 +- app/submodule/eth/eth_utils.go | 4 +-- pkg/events/filter/event.go | 26 ++++++++-------- pkg/events/filter/event_test.go | 14 ++++----- pkg/events/filter/index.go | 34 ++++++++++----------- pkg/events/filter/index_migrations.go | 32 +++++++++---------- pkg/events/filter/index_test.go | 26 ++++++++-------- venus-shared/compatible-checks/api-diff.txt | 2 -- 9 files changed, 71 insertions(+), 73 deletions(-) diff --git a/app/submodule/eth/eth_api.go b/app/submodule/eth/eth_api.go index 2bc871f763..85bbfab788 100644 --- a/app/submodule/eth/eth_api.go +++ b/app/submodule/eth/eth_api.go @@ -486,12 +486,12 @@ func (a *ethAPI) EthGetTransactionReceiptLimited(ctx context.Context, txHash typ } // The tx is located in the parent tipset - parentTs, err := a.em.chainModule.ChainReader.GetTipSet(ctx, ts.Parents()) + parentTS, err := a.em.chainModule.ChainReader.GetTipSet(ctx, ts.Parents()) if err != nil { return nil, fmt.Errorf("failed to lookup tipset %s when constructing the eth txn receipt: %w", ts.Parents(), err) } - baseFee := parentTs.Blocks()[0].ParentBaseFee + baseFee := parentTS.Blocks()[0].ParentBaseFee receipt, err := newEthTxReceipt(ctx, tx, baseFee, msgLookup.Receipt, a.EthEventHandler) if err != nil { diff --git a/app/submodule/eth/eth_event_api.go b/app/submodule/eth/eth_event_api.go index d6cc46f4df..d5d6176a39 100644 --- a/app/submodule/eth/eth_event_api.go +++ b/app/submodule/eth/eth_event_api.go @@ -817,7 +817,7 @@ func ethLogFromEvent(entries []types.EventEntry) (data []byte, topics []types.Et } // func ethFilterResultFromEvents(evs []*filter.CollectedEvent, ms *chain.MessageStore) (*types.EthFilterResult, error) { -func ethFilterLogsFromEvents(ctx context.Context, evs []*filter.CollectedEvent, ms *chain.MessageStore) ([]types.EthLog, error) { +func ethFilterLogsFromEvents(_ context.Context, evs []*filter.CollectedEvent, ms *chain.MessageStore) ([]types.EthLog, error) { var logs []types.EthLog for _, ev := range evs { log := types.EthLog{ diff --git a/app/submodule/eth/eth_utils.go b/app/submodule/eth/eth_utils.go index f08ea2841c..a95219d16a 100644 --- a/app/submodule/eth/eth_utils.go +++ b/app/submodule/eth/eth_utils.go @@ -659,7 +659,7 @@ func newEthTxFromMessageLookup(ctx context.Context, msgLookup *types.MsgLookup, func newEthTx(ctx context.Context, state tree.Tree, blockHeight abi.ChainEpoch, - msgTsCid cid.Cid, + msgTSCid cid.Cid, msgCid cid.Cid, txIdx int, ms *chain.MessageStore, @@ -679,7 +679,7 @@ func newEthTx(ctx context.Context, ti = types.EthUint64(txIdx) ) - blkHash, err := types.EthHashFromCid(msgTsCid) + blkHash, err := types.EthHashFromCid(msgTSCid) if err != nil { return types.EthTx{}, err } diff --git a/pkg/events/filter/event.go b/pkg/events/filter/event.go index af13f832cd..f80bd4fec3 100644 --- a/pkg/events/filter/event.go +++ b/pkg/events/filter/event.go @@ -104,7 +104,7 @@ func (f *eventFilter) CollectEvents(ctx context.Context, te *TipSetEvents, rever addr, found := addressLookups[ev.Emitter] if !found { var ok bool - addr, ok = resolver(ctx, ev.Emitter, te.rctTs) + addr, ok = resolver(ctx, ev.Emitter, te.rctTS) if !ok { // not an address we will be able to match against continue @@ -125,8 +125,8 @@ func (f *eventFilter) CollectEvents(ctx context.Context, te *TipSetEvents, rever EmitterAddr: addr, EventIdx: eventCount, Reverted: revert, - Height: te.msgTs.Height(), - TipSetKey: te.msgTs.Key(), + Height: te.msgTS.Height(), + TipSetKey: te.msgTS.Key(), MsgCid: em.Message().Cid(), MsgIdx: msgIdx, } @@ -254,10 +254,10 @@ func (f *eventFilter) matchKeys(ees []types.EventEntry) bool { } type TipSetEvents struct { - rctTs *types.TipSet // rctTs is the tipset containing the receipts of executed messages - msgTs *types.TipSet // msgTs is the tipset containing the messages that have been executed + rctTS *types.TipSet // rctTS is the tipset containing the receipts of executed messages + msgTS *types.TipSet // msgTS is the tipset containing the messages that have been executed - load func(ctx context.Context, msgTs, rctTs *types.TipSet) ([]executedMessage, error) + load func(ctx context.Context, msgTS, rctTS *types.TipSet) ([]executedMessage, error) once sync.Once // for lazy population of ems ems []executedMessage @@ -265,17 +265,17 @@ type TipSetEvents struct { } func (te *TipSetEvents) Height() abi.ChainEpoch { - return te.msgTs.Height() + return te.msgTS.Height() } func (te *TipSetEvents) Cid() (cid.Cid, error) { - return te.msgTs.Key().Cid() + return te.msgTS.Key().Cid() } func (te *TipSetEvents) messages(ctx context.Context) ([]executedMessage, error) { te.once.Do(func() { // populate executed message list - ems, err := te.load(ctx, te.msgTs, te.rctTs) + ems, err := te.load(ctx, te.msgTS, te.rctTS) if err != nil { te.err = err return @@ -326,8 +326,8 @@ func (m *EventFilterManager) Apply(ctx context.Context, from, to *types.TipSet) } tse := &TipSetEvents{ - msgTs: from, - rctTs: to, + msgTS: from, + rctTS: to, load: m.loadExecutedMessages, } @@ -357,8 +357,8 @@ func (m *EventFilterManager) Revert(ctx context.Context, from, to *types.TipSet) } tse := &TipSetEvents{ - msgTs: to, - rctTs: from, + msgTS: to, + rctTS: from, load: m.loadExecutedMessages, } diff --git a/pkg/events/filter/event_test.go b/pkg/events/filter/event_test.go index 36c6e20997..d23dd4c414 100644 --- a/pkg/events/filter/event_test.go +++ b/pkg/events/filter/event_test.go @@ -66,7 +66,7 @@ func TestEventFilterCollectEvents(t *testing.T) { } events14000 := buildTipSetEvents(t, rng, 14000, em) - cid14000, err := events14000.msgTs.Key().Cid() + cid14000, err := events14000.msgTS.Key().Cid() require.NoError(t, err, "tipset cid") noCollectedEvents := []*CollectedEvent{} @@ -77,7 +77,7 @@ func TestEventFilterCollectEvents(t *testing.T) { EventIdx: 0, Reverted: false, Height: 14000, - TipSetKey: events14000.msgTs.Key(), + TipSetKey: events14000.msgTS.Key(), MsgIdx: 0, MsgCid: em.msg.Cid(), }, @@ -421,13 +421,13 @@ func newStore() adt.Store { func buildTipSetEvents(tb testing.TB, rng *pseudo.Rand, h abi.ChainEpoch, em executedMessage) *TipSetEvents { tb.Helper() - msgTs := fakeTipSet(tb, rng, h, []cid.Cid{}) - rctTs := fakeTipSet(tb, rng, h+1, msgTs.Cids()) + msgTS := fakeTipSet(tb, rng, h, []cid.Cid{}) + rctTS := fakeTipSet(tb, rng, h+1, msgTS.Cids()) return &TipSetEvents{ - msgTs: msgTs, - rctTs: rctTs, - load: func(ctx context.Context, msgTs, rctTs *types.TipSet) ([]executedMessage, error) { + msgTS: msgTS, + rctTS: rctTS, + load: func(ctx context.Context, msgTS, rctTS *types.TipSet) ([]executedMessage, error) { return []executedMessage{em}, nil }, } diff --git a/pkg/events/filter/index.go b/pkg/events/filter/index.go index 6020965390..6bd161dbb0 100644 --- a/pkg/events/filter/index.go +++ b/pkg/events/filter/index.go @@ -20,7 +20,7 @@ import ( "github.com/filecoin-project/venus/venus-shared/types" ) -const DefaultDbFilename = "events.db" +const DefaultDBFilename = "events.db" // Any changes to this schema should be matched for the `lotus-shed indexes backfill-events` command @@ -51,7 +51,7 @@ var ddls = []string{ createTableEventsSeen, - createIndexEventEntryEventId, + createIndexEventEntryEventID, createIndexEventsSeenHeight, createIndexEventsSeenTipsetKeyCid, } @@ -101,7 +101,7 @@ const ( createIndexEventTipsetKeyCid = `CREATE INDEX IF NOT EXISTS event_tipset_key_cid ON event (tipset_key_cid);` createIndexEventHeight = `CREATE INDEX IF NOT EXISTS event_height ON event (height);` - createIndexEventEntryEventId = `CREATE INDEX IF NOT EXISTS event_entry_event_id ON event_entry(event_id);` + createIndexEventEntryEventID = `CREATE INDEX IF NOT EXISTS event_entry_event_id ON event_entry(event_id);` createIndexEventsSeenHeight = `CREATE INDEX IF NOT EXISTS events_seen_height ON events_seen (height);` createIndexEventsSeenTipsetKeyCid = `CREATE INDEX IF NOT EXISTS events_seen_tipset_key_cid ON events_seen (tipset_key_cid);` @@ -148,7 +148,7 @@ type EventIndex struct { stmt *preparedStatements mu sync.Mutex - subIdCounter uint64 + subIDCounter uint64 updateSubs map[uint64]*updateSub } @@ -225,8 +225,8 @@ func (ei *EventIndex) SubscribeUpdates() (chan EventIndexUpdated, func()) { } ei.mu.Lock() - subId := ei.subIdCounter - ei.subIdCounter++ + subId := ei.subIDCounter + ei.subIDCounter++ ei.updateSubs[subId] = tSub ei.mu.Unlock() @@ -277,19 +277,19 @@ func (ei *EventIndex) CollectEvents(ctx context.Context, te *TipSetEvents, rever // rollback the transaction (a no-op if the transaction was already committed) defer func() { _ = tx.Rollback() }() - tsKeyCid, err := te.msgTs.Key().Cid() + tsKeyCid, err := te.msgTS.Key().Cid() if err != nil { return fmt.Errorf("tipset key cid: %w", err) } // lets handle the revert case first, since its simpler and we can simply mark all events in this tipset as reverted and return if revert { - _, err = tx.Stmt(ei.stmt.revertEventsInTipset).Exec(te.msgTs.Height(), te.msgTs.Key().Bytes()) + _, err = tx.Stmt(ei.stmt.revertEventsInTipset).Exec(te.msgTS.Height(), te.msgTS.Key().Bytes()) if err != nil { return fmt.Errorf("revert event: %w", err) } - _, err = tx.Stmt(ei.stmt.revertEventSeen).Exec(te.msgTs.Height(), tsKeyCid.Bytes()) + _, err = tx.Stmt(ei.stmt.revertEventSeen).Exec(te.msgTS.Height(), tsKeyCid.Bytes()) if err != nil { return fmt.Errorf("revert event seen: %w", err) } @@ -336,7 +336,7 @@ func (ei *EventIndex) CollectEvents(ctx context.Context, te *TipSetEvents, rever addr, found := addressLookups[ev.Emitter] if !found { var ok bool - addr, ok = resolver(ctx, ev.Emitter, te.rctTs) + addr, ok = resolver(ctx, ev.Emitter, te.rctTS) if !ok { // not an address we will be able to match against continue @@ -347,8 +347,8 @@ func (ei *EventIndex) CollectEvents(ctx context.Context, te *TipSetEvents, rever // check if this event already exists in the database var entryID sql.NullInt64 err = tx.Stmt(ei.stmt.eventExists).QueryRow( - te.msgTs.Height(), // height - te.msgTs.Key().Bytes(), // tipset_key + te.msgTS.Height(), // height + te.msgTS.Key().Bytes(), // tipset_key tsKeyCid.Bytes(), // tipset_key_cid addr.Bytes(), // emitter_addr eventCount, // event_index @@ -362,8 +362,8 @@ func (ei *EventIndex) CollectEvents(ctx context.Context, te *TipSetEvents, rever if !entryID.Valid { // event does not exist, lets insert it res, err := tx.Stmt(ei.stmt.insertEvent).Exec( - te.msgTs.Height(), // height - te.msgTs.Key().Bytes(), // tipset_key + te.msgTS.Height(), // height + te.msgTS.Key().Bytes(), // tipset_key tsKeyCid.Bytes(), // tipset_key_cid addr.Bytes(), // emitter_addr eventCount, // event_index @@ -397,8 +397,8 @@ func (ei *EventIndex) CollectEvents(ctx context.Context, te *TipSetEvents, rever } else { // event already exists, lets mark it as not reverted res, err := tx.Stmt(ei.stmt.restoreEvent).Exec( - te.msgTs.Height(), // height - te.msgTs.Key().Bytes(), // tipset_key + te.msgTS.Height(), // height + te.msgTS.Key().Bytes(), // tipset_key tsKeyCid.Bytes(), // tipset_key_cid addr.Bytes(), // emitter_addr eventCount, // event_index @@ -426,7 +426,7 @@ func (ei *EventIndex) CollectEvents(ctx context.Context, te *TipSetEvents, rever // this statement will mark the tipset as processed and will insert a new row if it doesn't exist // or update the reverted field to false if it does _, err = tx.Stmt(ei.stmt.upsertEventsSeen).Exec( - te.msgTs.Height(), + te.msgTS.Height(), tsKeyCid.Bytes(), ) if err != nil { diff --git a/pkg/events/filter/index_migrations.go b/pkg/events/filter/index_migrations.go index dc942a639e..19454f4f1a 100644 --- a/pkg/events/filter/index_migrations.go +++ b/pkg/events/filter/index_migrations.go @@ -49,34 +49,34 @@ func migrationVersion2(db *sql.DB, chainStore *chain.Store) sqlite.MigrationFunc } log.Infof("Migrating events from head to %d", minHeight.Int64) - currTs := chainStore.GetHead() + currTS := chainStore.GetHead() - for int64(currTs.Height()) >= minHeight.Int64 { - if currTs.Height()%1000 == 0 { - log.Infof("Migrating height %d (remaining %d)", currTs.Height(), int64(currTs.Height())-minHeight.Int64) + for int64(currTS.Height()) >= minHeight.Int64 { + if currTS.Height()%1000 == 0 { + log.Infof("Migrating height %d (remaining %d)", currTS.Height(), int64(currTS.Height())-minHeight.Int64) } - tsKey := currTs.Parents() - currTs, err = chainStore.GetTipSet(ctx, tsKey) + tsKey := currTS.Parents() + currTS, err = chainStore.GetTipSet(ctx, tsKey) if err != nil { return fmt.Errorf("get tipset from key: %w", err) } - log.Debugf("Migrating height %d", currTs.Height()) + log.Debugf("Migrating height %d", currTS.Height()) - tsKeyCid, err := currTs.Key().Cid() + tsKeyCid, err := currTS.Key().Cid() if err != nil { return fmt.Errorf("tipset key cid: %w", err) } // delete all events that are not in the canonical chain - _, err = stmtDeleteOffChainEvent.Exec(tsKeyCid.Bytes(), currTs.Height()) + _, err = stmtDeleteOffChainEvent.Exec(tsKeyCid.Bytes(), currTS.Height()) if err != nil { return fmt.Errorf("delete off chain event: %w", err) } - // find the first eventId from the last time the tipset was applied - var eventId sql.NullInt64 - err = stmtSelectEvent.QueryRow(tsKeyCid.Bytes()).Scan(&eventId) + // find the first eventID from the last time the tipset was applied + var eventID sql.NullInt64 + err = stmtSelectEvent.QueryRow(tsKeyCid.Bytes()).Scan(&eventID) if err != nil { if errors.Is(err, sql.ErrNoRows) { continue @@ -85,12 +85,12 @@ func migrationVersion2(db *sql.DB, chainStore *chain.Store) sqlite.MigrationFunc } // this tipset might not have any events which is ok - if !eventId.Valid { + if !eventID.Valid { continue } - log.Debugf("Deleting all events with id < %d at height %d", eventId.Int64, currTs.Height()) + log.Debugf("Deleting all events with id < %d at height %d", eventID.Int64, currTS.Height()) - res, err := stmtDeleteEvent.Exec(tsKeyCid.Bytes(), eventId.Int64) + res, err := stmtDeleteEvent.Exec(tsKeyCid.Bytes(), eventID.Int64) if err != nil { return fmt.Errorf("delete event: %w", err) } @@ -168,7 +168,7 @@ func migrationVersion4(ctx context.Context, tx *sql.Tx) error { {"drop index event_entry_key_index", "DROP INDEX IF EXISTS event_entry_key_index;"}, {"create index event_tipset_key_cid", createIndexEventTipsetKeyCid}, {"create index event_height", createIndexEventHeight}, - {"create index event_entry_event_id", createIndexEventEntryEventId}, + {"create index event_entry_event_id", createIndexEventEntryEventID}, } { if _, err := tx.ExecContext(ctx, create.query); err != nil { return fmt.Errorf("%s: %w", create.desc, err) diff --git a/pkg/events/filter/index_test.go b/pkg/events/filter/index_test.go index b8b8c042ea..0d545db257 100644 --- a/pkg/events/filter/index_test.go +++ b/pkg/events/filter/index_test.go @@ -49,7 +49,7 @@ func TestEventIndexPrefillFilter(t *testing.T) { } events14000 := buildTipSetEvents(t, rng, 14000, em) - cid14000, err := events14000.msgTs.Key().Cid() + cid14000, err := events14000.msgTS.Key().Cid() require.NoError(t, err, "tipset cid") noCollectedEvents := []*CollectedEvent{} @@ -60,7 +60,7 @@ func TestEventIndexPrefillFilter(t *testing.T) { EventIdx: 0, Reverted: false, Height: 14000, - TipSetKey: events14000.msgTs.Key(), + TipSetKey: events14000.msgTS.Key(), MsgIdx: 0, MsgCid: em.msg.Cid(), }, @@ -108,7 +108,7 @@ func TestEventIndexPrefillFilter(t *testing.T) { require.NoError(t, err) require.True(t, b) - tsKey := events14000.msgTs.Key() + tsKey := events14000.msgTS.Key() tsKeyCid, err := tsKey.Cid() require.NoError(t, err, "tipset key cid") @@ -120,7 +120,7 @@ func TestEventIndexPrefillFilter(t *testing.T) { require.NoError(t, err) require.False(t, seen, "tipset key should not be seen") - _ = <-out + <-out testCases := []struct { name string @@ -374,9 +374,9 @@ func TestEventIndexPrefillFilterExcludeReverted(t *testing.T) { events14000 := buildTipSetEvents(t, rng, 14000, em) revertedEvents14000 := buildTipSetEvents(t, rng, 14000, revertedEm) - cid14000, err := events14000.msgTs.Key().Cid() + cid14000, err := events14000.msgTS.Key().Cid() require.NoError(t, err, "tipset cid") - reveredCID14000, err := revertedEvents14000.msgTs.Key().Cid() + reveredCID14000, err := revertedEvents14000.msgTS.Key().Cid() require.NoError(t, err, "tipset cid") noCollectedEvents := []*CollectedEvent{} @@ -387,7 +387,7 @@ func TestEventIndexPrefillFilterExcludeReverted(t *testing.T) { EventIdx: 0, Reverted: false, Height: 14000, - TipSetKey: events14000.msgTs.Key(), + TipSetKey: events14000.msgTS.Key(), MsgIdx: 0, MsgCid: em.msg.Cid(), }, @@ -399,7 +399,7 @@ func TestEventIndexPrefillFilterExcludeReverted(t *testing.T) { EventIdx: 0, Reverted: false, Height: 14000, - TipSetKey: events14000.msgTs.Key(), + TipSetKey: events14000.msgTS.Key(), MsgIdx: 0, MsgCid: em.msg.Cid(), }, @@ -409,7 +409,7 @@ func TestEventIndexPrefillFilterExcludeReverted(t *testing.T) { EventIdx: 0, Reverted: true, Height: 14000, - TipSetKey: revertedEvents14000.msgTs.Key(), + TipSetKey: revertedEvents14000.msgTS.Key(), MsgIdx: 0, MsgCid: revertedEm.msg.Cid(), }, @@ -421,7 +421,7 @@ func TestEventIndexPrefillFilterExcludeReverted(t *testing.T) { EventIdx: 0, Reverted: true, Height: 14000, - TipSetKey: revertedEvents14000.msgTs.Key(), + TipSetKey: revertedEvents14000.msgTS.Key(), MsgIdx: 0, MsgCid: revertedEm.msg.Cid(), }, @@ -465,9 +465,9 @@ func TestEventIndexPrefillFilterExcludeReverted(t *testing.T) { require.NoError(t, err, "collect events") } - _ = <-tCh - _ = <-tCh - _ = <-tCh + <-tCh + <-tCh + <-tCh inclusiveTestCases := []struct { name string diff --git a/venus-shared/compatible-checks/api-diff.txt b/venus-shared/compatible-checks/api-diff.txt index 4d839cac2c..77a2e4c456 100644 --- a/venus-shared/compatible-checks/api-diff.txt +++ b/venus-shared/compatible-checks/api-diff.txt @@ -104,8 +104,6 @@ github.com/filecoin-project/venus/venus-shared/api/chain/v1.FullNode <> github.c + Concurrent - CreateBackup - Discover - - EthGetBlockReceipts - - EthGetBlockReceiptsLimited - EthSendRawTransactionUntrusted - EthTraceFilter > EthTraceReplayBlockTransactions {[func(context.Context, string, []string) ([]*types.EthTraceReplayBlockTransaction, error) <> func(context.Context, string, []string) ([]*ethtypes.EthTraceReplayBlockTransaction, error)] base=func out type: #0 input; nested={[[]*types.EthTraceReplayBlockTransaction <> []*ethtypes.EthTraceReplayBlockTransaction] base=slice element; nested={[*types.EthTraceReplayBlockTransaction <> *ethtypes.EthTraceReplayBlockTransaction] base=pointed type; nested={[types.EthTraceReplayBlockTransaction <> ethtypes.EthTraceReplayBlockTransaction] base=struct field; nested={[types.EthTraceReplayBlockTransaction <> ethtypes.EthTraceReplayBlockTransaction] base=exported field name: #4 field, VMTrace != VmTrace; nested=nil}}}}}