Skip to content

Commit

Permalink
fix logs
Browse files Browse the repository at this point in the history
  • Loading branch information
tudor-malene committed Sep 21, 2023
1 parent e1ccf10 commit 48c1c00
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 26 deletions.
11 changes: 5 additions & 6 deletions go/enclave/storage/enclavedb/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import (
)

const (
baseEventsQuerySelect = "select full_topic0, full_topic1, full_topic2, full_topic3, full_topic4, datablob, b.full_hash, b.height, tx.full_hash, tx.idx, log_idx, address"
baseDebugEventsQuerySelect = "select rel_address1, rel_address2, rel_address3, rel_address4, lifecycle_event, full_topic0, full_topic1, full_topic2, full_topic3, full_topic4, datablob, b.full_hash, b.height, tx.full_hash, tx.idx, log_idx, address"
baseEventsQuerySelect = "select topic0, topic1, topic2, topic3, topic4, datablob, b.full_hash, b.height, tx.full_hash, tx.idx, log_idx, address"
baseDebugEventsQuerySelect = "select rel_address1, rel_address2, rel_address3, rel_address4, lifecycle_event, topic0, topic1, topic2, topic3, topic4, datablob, b.full_hash, b.height, tx.full_hash, tx.idx, log_idx, address"
baseEventsJoin = "from events e join exec_tx extx on e.exec_tx_id=extx.id join tx on extx.tx=tx.hash join batch b on extx.batch=b.sequence where b.is_canonical=true "
insertEvent = "insert into events values "
insertEventValues = "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
insertEventValues = "(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
orderBy = " order by b.height, tx.idx asc"
)

Expand All @@ -27,7 +27,7 @@ func StoreEventLogs(dbtx DBTransaction, receipts []*types.Receipt, stateDB *stat
totalLogs := 0
for _, receipt := range receipts {
for _, l := range receipt.Logs {
logArgs, err := writeLog(dbtx.GetDB(), l, receipt, stateDB)
logArgs, err := logDBValues(dbtx.GetDB(), l, receipt, stateDB)
if err != nil {
return err
}
Expand All @@ -49,7 +49,7 @@ func StoreEventLogs(dbtx DBTransaction, receipts []*types.Receipt, stateDB *stat
// The other 4 topics are set by the programmer
// According to the data relevancy rules, an event is relevant to accounts referenced directly in topics
// If the event is not referring any user address, it is considered a "lifecycle event", and is relevant to everyone
func writeLog(db *sql.DB, l *types.Log, receipt *types.Receipt, stateDB *state.StateDB) ([]any, error) {
func logDBValues(db *sql.DB, l *types.Log, receipt *types.Receipt, stateDB *state.StateDB) ([]any, error) {
// The topics are stored in an array with a maximum of 5 entries, but usually less
var t0, t1, t2, t3, t4 []byte

Expand Down Expand Up @@ -122,7 +122,6 @@ func writeLog(db *sql.DB, l *types.Log, receipt *types.Receipt, stateDB *state.S
}

return []any{
truncBTo16(t0), truncBTo16(t1), truncBTo16(t2), truncBTo16(t3), truncBTo16(t4),
t0, t1, t2, t3, t4,
data, l.Index, l.Address.Bytes(),
isLifecycle, a1, a2, a3, a4,
Expand Down
15 changes: 5 additions & 10 deletions go/enclave/storage/init/edgelessdb/001_init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,11 @@ GRANT ALL ON obsdb.exec_tx TO obscuro;

create table if not exists obsdb.events
(
topic0 binary(16) NOT NULL,
topic1 binary(16),
topic2 binary(16),
topic3 binary(16),
topic4 binary(16),
full_topic0 binary(32) NOT NULL,
full_topic1 binary(32),
full_topic2 binary(32),
full_topic3 binary(32),
full_topic4 binary(32),
topic0 binary(32) NOT NULL,
topic1 binary(32),
topic2 binary(32),
topic3 binary(32),
topic4 binary(32),
datablob mediumblob,
log_idx int NOT NULL,
address binary(20) NOT NULL,
Expand Down
15 changes: 5 additions & 10 deletions go/enclave/storage/init/sqlite/001_init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,11 @@ create index IX_EX_TX1 on exec_tx (tx);
-- todo denormalize. Extract contract and user table and point topic0 and rel_addreses to it
create table if not exists events
(
topic0 binary(16) NOT NULL,
topic1 binary(16),
topic2 binary(16),
topic3 binary(16),
topic4 binary(16),
full_topic0 binary(32) NOT NULL,
full_topic1 binary(32),
full_topic2 binary(32),
full_topic3 binary(32),
full_topic4 binary(32),
topic0 binary(32) NOT NULL,
topic1 binary(32),
topic2 binary(32),
topic3 binary(32),
topic4 binary(32),
datablob mediumblob,
log_idx int NOT NULL,
address binary(20) NOT NULL,
Expand Down

0 comments on commit 48c1c00

Please sign in to comment.