Skip to content

Commit

Permalink
tweaking
Browse files Browse the repository at this point in the history
  • Loading branch information
tudor-malene committed May 10, 2024
1 parent eff485b commit a209f99
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 58 deletions.
3 changes: 2 additions & 1 deletion go/enclave/storage/enclavedb/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ func StoreEventLogs(ctx context.Context, dbtx *sql.Tx, receipts []*types.Receipt
}
}
if totalLogs > 0 {
query := "insert into events values " + repeat("(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", ",", totalLogs)
query := "insert into events (topic0,topic1,topic2,topic3,topic4,datablob,log_idx,address,lifecycle_event,rel_address1,rel_address2,rel_address3,rel_address4,tx,batch) values " +
repeat("(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", ",", totalLogs)
_, err := dbtx.ExecContext(ctx, query, args...)
if err != nil {
return err
Expand Down
86 changes: 43 additions & 43 deletions go/enclave/storage/init/edgelessdb/001_init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ CREATE DATABASE obsdb;

create table if not exists obsdb.keyvalue
(
id INTEGER AUTO_INCREMENT,
ky varbinary(64),
val mediumblob NOT NULL,
id INTEGER AUTO_INCREMENT,
ky varbinary(64) NOT NULL,
val mediumblob NOT NULL,
primary key (id),
INDEX USING HASH (ky)
);
Expand All @@ -32,13 +32,13 @@ GRANT ALL ON obsdb.attestation_key TO obscuro;
create table if not exists obsdb.block
(
id INTEGER AUTO_INCREMENT,
hash binary(32),
is_canonical boolean NOT NULL,
header blob NOT NULL,
height int NOT NULL,
hash binary(32) NOT NULL,
is_canonical boolean NOT NULL,
header blob NOT NULL,
height int NOT NULL,
primary key (id),
INDEX (height),
INDEX USING HASH (hash(16))
INDEX USING HASH (hash(8))
);
GRANT ALL ON obsdb.block TO obscuro;

Expand All @@ -56,31 +56,31 @@ GRANT ALL ON obsdb.l1_msg TO obscuro;
create table if not exists obsdb.rollup
(
id INTEGER AUTO_INCREMENT,
hash binary(32),
start_seq int NOT NULL,
end_seq int NOT NULL,
time_stamp int NOT NULL,
header blob NOT NULL,
compression_block INTEGER NOT NULL,
hash binary(32) NOT NULL,
start_seq int NOT NULL,
end_seq int NOT NULL,
time_stamp int NOT NULL,
header blob NOT NULL,
compression_block INTEGER NOT NULL,
INDEX (compression_block),
INDEX USING HASH (hash(16)),
INDEX USING HASH (hash(8)),
primary key (id)
);
GRANT ALL ON obsdb.rollup TO obscuro;

create table if not exists obsdb.batch_body
(
id int NOT NULL,
id INTEGER,
content mediumblob NOT NULL,
primary key (id)
);
GRANT ALL ON obsdb.batch_body TO obscuro;

create table if not exists obsdb.batch
(
sequence int,
sequence INTEGER,
converted_hash binary(32) NOT NULL,
hash binary(32) NOT NULL,
hash binary(32) NOT NULL,
height int NOT NULL,
is_canonical boolean NOT NULL,
header blob NOT NULL,
Expand All @@ -89,43 +89,42 @@ create table if not exists obsdb.batch
l1_proof INTEGER,
is_executed boolean NOT NULL,
primary key (sequence),
INDEX USING HASH (hash(16)),
INDEX (body),
INDEX (height, is_canonical),
INDEX (l1_proof)
INDEX USING HASH (hash(8)),
INDEX (body, l1_proof),
INDEX (height)
);
GRANT ALL ON obsdb.batch TO obscuro;

create table if not exists obsdb.tx
(
id INTEGER AUTO_INCREMENT,
hash binary(32),
hash binary(32) NOT NULL,
content mediumblob NOT NULL,
sender_address binary(20) NOT NULL,
nonce int NOT NULL,
idx int NOT NULL,
body int NOT NULL,
INDEX (body),
INDEX USING HASH (hash(16)),
INDEX USING HASH (hash(8)),
primary key (id)
);
GRANT ALL ON obsdb.tx TO obscuro;

create table if not exists obsdb.exec_tx
(
id INTEGER AUTO_INCREMENT,
created_contract_address binary(20),
receipt mediumblob,
tx int,
batch int NOT NULL,
INDEX (batch,tx),
id INTEGER AUTO_INCREMENT,
created_contract_address binary(20),
receipt mediumblob,
tx int,
batch int NOT NULL,
INDEX (batch),
INDEX (tx, created_contract_address(4)),
primary key (id)
);
GRANT ALL ON obsdb.exec_tx TO obscuro;

create table if not exists obsdb.events
(
id INTEGER AUTO_INCREMENT,
topic0 binary(32) NOT NULL,
topic1 binary(32),
topic2 binary(32),
Expand All @@ -139,18 +138,19 @@ create table if not exists obsdb.events
rel_address2 binary(20),
rel_address3 binary(20),
rel_address4 binary(20),
tx int,
tx int NOT NULL,
batch int NOT NULL,
INDEX (batch, tx),
INDEX USING HASH (address(16)),
INDEX USING HASH (rel_address1(16)),
INDEX USING HASH (rel_address2(16)),
INDEX USING HASH (rel_address3(16)),
INDEX USING HASH (rel_address4(16)),
INDEX USING HASH (topic0(16)),
INDEX USING HASH (topic1(16)),
INDEX USING HASH (topic2(16)),
INDEX USING HASH (topic3(16)),
INDEX USING HASH (topic4(16))
primary key (id),
INDEX (tx, batch),
INDEX USING HASH (address(8)),
INDEX USING HASH (rel_address1(8)),
INDEX USING HASH (rel_address2(8)),
INDEX USING HASH (rel_address3(8)),
INDEX USING HASH (rel_address4(8)),
INDEX USING HASH (topic0(8)),
INDEX USING HASH (topic1(8)),
INDEX USING HASH (topic2(8)),
INDEX USING HASH (topic3(8)),
INDEX USING HASH (topic4(8))
);
GRANT ALL ON obsdb.events TO obscuro;
29 changes: 15 additions & 14 deletions go/enclave/storage/init/sqlite/001_init.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
create table if not exists keyvalue
(
id INTEGER PRIMARY KEY AUTOINCREMENT,
ky varbinary(64),
val mediumblob NOT NULL
id INTEGER PRIMARY KEY AUTOINCREMENT,
ky varbinary(64),
val mediumblob NOT NULL
);
create index IDX_KV on keyvalue (ky);

Expand Down Expand Up @@ -68,13 +68,13 @@ create table if not exists batch
sequence int primary key,
converted_hash binary(32),
hash binary(32) NOT NULL,
height int NOT NULL,
is_canonical boolean NOT NULL,
header blob NOT NULL,
body int NOT NULL REFERENCES batch_body,
height int NOT NULL,
is_canonical boolean NOT NULL,
header blob NOT NULL,
body int NOT NULL REFERENCES batch_body,
l1_proof_hash binary(32),
l1_proof INTEGER, -- normally this would be a FK, but there is a weird edge case where an L2 node might not have the block used to create this batch
is_executed boolean NOT NULL
is_executed boolean NOT NULL
-- the unique constraint is commented for now because there might be multiple non-canonical batches for the same height
-- unique (height, is_canonical, is_executed)
);
Expand All @@ -98,19 +98,20 @@ create index IDX_TX_BODY on tx (body);

create table if not exists exec_tx
(
id INTEGER PRIMARY KEY AUTOINCREMENT,
created_contract_address binary(20),
receipt mediumblob,
id INTEGER PRIMARY KEY AUTOINCREMENT,
created_contract_address binary(20),
receipt mediumblob,
-- commenting out the fk until synthetic transactions are also stored
tx INTEGER,
batch INTEGER NOT NULL REFERENCES batch
tx INTEGER,
batch INTEGER NOT NULL REFERENCES batch
);
create index IDX_EX_TX_BATCH on exec_tx (batch,tx);
create index IDX_EX_TX_BATCH on exec_tx (batch, tx);
create index IDX_EX_TX_CCA on exec_tx (created_contract_address);

-- todo denormalize. Extract contract and user table and point topic0 and rel_addreses to it
create table if not exists events
(
id INTEGER PRIMARY KEY AUTOINCREMENT,
topic0 binary(32) NOT NULL,
topic1 binary(32),
topic2 binary(32),
Expand Down

0 comments on commit a209f99

Please sign in to comment.