Skip to content

Commit

Permalink
improve debug_logs
Browse files Browse the repository at this point in the history
  • Loading branch information
tudor-malene committed Sep 24, 2024
1 parent ff1b1ba commit 5919cd5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 26 deletions.
45 changes: 27 additions & 18 deletions go/common/tracers/debug_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ import (

// DebugLogs are the logs returned when using the DebugGetLogs endpoint
type DebugLogs struct {
RelAddress1 *gethcommon.Address `json:"relAddress1"`
RelAddress2 *gethcommon.Address `json:"relAddress2"`
RelAddress3 *gethcommon.Address `json:"relAddress3"`
LifecycleEvent bool `json:"lifecycleEvent"`
RelAddress1 *gethcommon.Address `json:"relAddress1"`
RelAddress2 *gethcommon.Address `json:"relAddress2"`
RelAddress3 *gethcommon.Address `json:"relAddress3"`
ConfigPublic bool `json:"configPublic"`
AutoPublic bool `json:"autoPublic"`
AutoContract bool `json:"autoContract"`
TransparentContract bool `json:"transparentContract"`

gethtypes.Log
}
Expand All @@ -23,19 +26,22 @@ type DebugLogs struct {
// this holds a copy of the gethtypes.Log log marshaller
func (l DebugLogs) MarshalJSON() ([]byte, error) {
return json.Marshal(struct {
Address string `json:"address" gencodec:"required"`
Topics []gethcommon.Hash `json:"topics" gencodec:"required"`
Data hexutil.Bytes `json:"data" gencodec:"required"`
BlockNumber uint64 `json:"blockNumber"`
TxHash gethcommon.Hash `json:"transactionHash" gencodec:"required"`
TxIndex uint `json:"transactionIndex"`
BlockHash gethcommon.Hash `json:"blockHash"`
Index uint `json:"logIndex"`
Removed bool `json:"removed"`
LifecycleEvent bool `json:"lifecycleEvent"`
RelAddress1 *gethcommon.Address `json:"relAddress1"`
RelAddress2 *gethcommon.Address `json:"relAddress2"`
RelAddress3 *gethcommon.Address `json:"relAddress3"`
Address string `json:"address" gencodec:"required"`
Topics []gethcommon.Hash `json:"topics" gencodec:"required"`
Data hexutil.Bytes `json:"data" gencodec:"required"`
BlockNumber uint64 `json:"blockNumber"`
TxHash gethcommon.Hash `json:"transactionHash" gencodec:"required"`
TxIndex uint `json:"transactionIndex"`
BlockHash gethcommon.Hash `json:"blockHash"`
Index uint `json:"logIndex"`
Removed bool `json:"removed"`
ConfigPublic bool `json:"configPublic"`
AutoPublic bool `json:"autoPublic"`
AutoContract bool `json:"autoContract"`
TransparentContract bool `json:"transparentContract"`
RelAddress1 *gethcommon.Address `json:"relAddress1"`
RelAddress2 *gethcommon.Address `json:"relAddress2"`
RelAddress3 *gethcommon.Address `json:"relAddress3"`
}{
l.Address.Hex(),
l.Topics,
Expand All @@ -46,7 +52,10 @@ func (l DebugLogs) MarshalJSON() ([]byte, error) {
l.BlockHash,
l.Index,
l.Removed,
l.LifecycleEvent,
l.ConfigPublic,
l.AutoPublic,
l.AutoContract,
l.TransparentContract,
l.RelAddress1,
l.RelAddress2,
l.RelAddress3,
Expand Down
11 changes: 5 additions & 6 deletions go/enclave/storage/enclavedb/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func DebugGetLogs(ctx context.Context, db *sql.DB, txHash common.TxHash) ([]*tra
var queryParams []any

// todo - should we return the config here?
query := "select eoa1.address, eoa2.address, eoa3.address, et.config_public, et.auto_public, et.event_sig, t1.topic, t2.topic, t3.topic, datablob, b.hash, b.height, tx.hash, tx.idx, log_idx, c.address " +
query := "select eoa1.address, eoa2.address, eoa3.address, et.config_public, et.auto_public, et.event_sig, t1.topic, t2.topic, t3.topic, datablob, b.hash, b.height, tx.hash, tx.idx, log_idx, c.address, c.auto_visibility, c.transparent " +
baseEventsJoin +
" AND tx.hash = ? "

Expand All @@ -182,18 +182,16 @@ func DebugGetLogs(ctx context.Context, db *sql.DB, txHash common.TxHash) ([]*tra
Log: types.Log{
Topics: []gethcommon.Hash{},
},
LifecycleEvent: false,
}

var t0, t1, t2, t3 sql.NullString
var relAddress1, relAddress2, relAddress3 []byte
var config_public, autoPublic bool
err = rows.Scan(
&relAddress1,
&relAddress2,
&relAddress3,
&config_public,
&autoPublic,
&l.ConfigPublic,
&l.AutoPublic,
&t0, &t1, &t2, &t3,
&l.Data,
&l.BlockHash,
Expand All @@ -202,8 +200,9 @@ func DebugGetLogs(ctx context.Context, db *sql.DB, txHash common.TxHash) ([]*tra
&l.TxIndex,
&l.Index,
&l.Address,
&l.AutoContract,
&l.TransparentContract,
)
l.LifecycleEvent = config_public || autoPublic
if err != nil {
return nil, fmt.Errorf("could not load log entry from db: %w", err)
}
Expand Down
15 changes: 13 additions & 2 deletions go/enclave/storage/events_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ func (es *eventsStorage) storeEventLog(ctx context.Context, dbTX *sql.Tx, execTx
return fmt.Errorf("could not write event log. Cause: %w", err)
}

// event types that were not configured explicitly can be "Public events" as well.
// based on the topics, this logic determines whether the event type has any relevant addresses
// this is called only the first time an event is emitted
err = es.setAutoVisibilityWhenEventFirstEmitted(ctx, dbTX, eventType, topicIds)
if err != nil {
return fmt.Errorf("could not update the auto visibility. Cause: %w", err)
}

return nil
}

func (es *eventsStorage) setAutoVisibilityWhenEventFirstEmitted(ctx context.Context, dbTX *sql.Tx, eventType *enclavedb.EventType, topicIds []*uint64) error {
if !eventType.ConfigPublic && eventType.AutoVisibility && eventType.AutoPublic == nil {
isPublic := true
for _, topicId := range topicIds {
Expand All @@ -154,12 +166,11 @@ func (es *eventsStorage) storeEventLog(ctx context.Context, dbTX *sql.Tx, execTx
}
}
// for private events with autovisibility, the first time we need to determine whether they are public
err = enclavedb.UpdateEventTypeAutoPublic(ctx, dbTX, eventType.Id, isPublic)
err := enclavedb.UpdateEventTypeAutoPublic(ctx, dbTX, eventType.Id, isPublic)
if err != nil {
return fmt.Errorf("could not update event type. cause: %w", err)
}
}

return nil
}

Expand Down

0 comments on commit 5919cd5

Please sign in to comment.