diff --git a/go/enclave/enclave.go b/go/enclave/enclave.go index db25c42088..7739e382a2 100644 --- a/go/enclave/enclave.go +++ b/go/enclave/enclave.go @@ -513,7 +513,7 @@ func (e *enclaveImpl) SubmitTx(tx common.EncryptedTx) (*responses.RawTx, common. } if err = e.service.SubmitTransaction(decryptedTx); err != nil { - e.logger.Warn("Could not submit transaction", log.TxKey, decryptedTx.Hash(), log.ErrKey, err) + e.logger.Debug("Could not submit transaction", log.TxKey, decryptedTx.Hash(), log.ErrKey, err) return responses.AsEncryptedError(err, vkHandler), nil } diff --git a/go/enclave/storage/enclavedb/batch.go b/go/enclave/storage/enclavedb/batch.go index dc52b39e0d..3237ca8bdb 100644 --- a/go/enclave/storage/enclavedb/batch.go +++ b/go/enclave/storage/enclavedb/batch.go @@ -23,9 +23,9 @@ import ( const ( bodyInsert = "replace into batch_body values (?,?)" txInsert = "replace into tx values " - txInsertValue = "(?,?,?,?,?,?)" + txInsertValue = "(?,?,?,?,?,?,?)" - bInsert = "insert into batch values (?,?,?,?,?,?,?,?,?)" + bInsert = "insert into batch values (?,?,?,?,?,?,?,?,?,?)" updateBatchExecuted = "update batch set is_executed=true where sequence=?" selectBatch = "select b.header, bb.content from batch b join batch_body bb on b.body=bb.hash" @@ -33,10 +33,10 @@ const ( txExecInsert = "insert into exec_tx values " txExecInsertValue = "(?,?,?,?,?)" - queryReceipts = "select exec_tx.receipt, tx.content, exec_tx.batch, batch.height from exec_tx join tx on tx.hash=exec_tx.tx join batch on batch.hash=exec_tx.batch " - queryReceiptsCount = "select count(1) from exec_tx join tx on tx.hash=exec_tx.tx join batch on batch.hash=exec_tx.batch " + queryReceipts = "select exec_tx.receipt, tx.content, batch.full_hash, batch.height from exec_tx join tx on tx.hash=exec_tx.tx join batch on batch.sequence=exec_tx.batch " + queryReceiptsCount = "select count(1) from exec_tx join tx on tx.hash=exec_tx.tx join batch on batch.sequence=exec_tx.batch " - selectTxQuery = "select tx.content, exec_tx.batch, batch.height, tx.idx from exec_tx join tx on tx.hash=exec_tx.tx join batch on batch.hash=exec_tx.batch where batch.is_canonical=true and tx.hash=?" + selectTxQuery = "select tx.content, batch.full_hash, batch.height, tx.idx from exec_tx join tx on tx.hash=exec_tx.tx join batch on batch.sequence=exec_tx.batch where batch.is_canonical=true and tx.hash=?" selectContractCreationTx = "select tx from exec_tx where created_contract_address=?" selectTotalCreatedContracts = "select count( distinct created_contract_address) from exec_tx " @@ -44,8 +44,8 @@ const ( isCanonQuery = "select is_canonical from block where hash=?" - queryTxList = "select exec_tx.tx, batch.height from exec_tx join batch on batch.hash=exec_tx.batch" - queryTxCountList = "select count(1) from exec_tx join batch on batch.hash=exec_tx.batch" + queryTxList = "select tx.full_hash, batch.height from exec_tx join batch on batch.sequence=exec_tx.batch join tx on tx.hash=exec_tx.tx" + queryTxCountList = "select count(1) from exec_tx join batch on batch.sequence=exec_tx.batch" ) // WriteBatchAndTransactions - persists the batch and the transactions @@ -78,7 +78,8 @@ func WriteBatchAndTransactions(dbtx DBTransaction, batch *core.Batch) error { dbtx.ExecuteSQL(bInsert, batch.Header.SequencerOrderNo.Uint64(), // sequence - truncTo16(batch.Hash()), // hash + batch.Hash(), // full hash + truncTo16(batch.Hash()), // index hash parentBytes, // parent batch.Header.Number.Uint64(), // height isCanon, // is_canonical @@ -105,7 +106,8 @@ func WriteBatchAndTransactions(dbtx DBTransaction, batch *core.Batch) error { return fmt.Errorf("unable to convert tx to message - %w", err) } - args = append(args, truncTo16(transaction.Hash())) // tx_hash + args = append(args, truncTo16(transaction.Hash())) // indexed tx_hash + args = append(args, transaction.Hash()) // full tx_hash args = append(args, txBytes) // content args = append(args, from.Bytes()) // sender_address args = append(args, transaction.Nonce()) // nonce diff --git a/go/enclave/storage/enclavedb/events.go b/go/enclave/storage/enclavedb/events.go index 7bd3d3baa0..882b42ce00 100644 --- a/go/enclave/storage/enclavedb/events.go +++ b/go/enclave/storage/enclavedb/events.go @@ -14,11 +14,11 @@ import ( ) const ( - baseEventsQuerySelect = "select topic0, topic1, topic2, topic3, topic4, datablob, b.hash, b.height, tx.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.hash, b.height, tx.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.hash where b.is_canonical=true " + 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, 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" ) @@ -123,6 +123,7 @@ 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, executedTransactionID(&receipt.BlockHash, &l.TxHash), diff --git a/go/enclave/storage/enclavedb/utils.go b/go/enclave/storage/enclavedb/utils.go index da27f38174..9b15744489 100644 --- a/go/enclave/storage/enclavedb/utils.go +++ b/go/enclave/storage/enclavedb/utils.go @@ -9,6 +9,9 @@ func truncTo16(hash gethcommon.Hash) []byte { } func truncBTo16(bytes []byte) []byte { + if len(bytes) == 0 { + return bytes + } b := bytes[0:truncHash] c := make([]byte, truncHash) copy(c, b) diff --git a/go/enclave/storage/init/edgelessdb/001_init.sql b/go/enclave/storage/init/edgelessdb/001_init.sql index 906cebc23e..8130bce5c7 100644 --- a/go/enclave/storage/init/edgelessdb/001_init.sql +++ b/go/enclave/storage/init/edgelessdb/001_init.sql @@ -74,31 +74,33 @@ GRANT ALL ON obsdb.batch_body TO obscuro; create table if not exists obsdb.batch ( - hash binary(16), + sequence int, + full_hash binary(32), + hash binary(16) NOT NULL, parent binary(16), - sequence int NOT NULL, height int NOT NULL, is_canonical boolean NOT NULL, header blob NOT NULL, body binary(16) NOT NULL, l1_proof binary(16) NOT NULL, is_executed boolean NOT NULL, - INDEX (parent), + primary key (sequence), +# INDEX (parent), + INDEX (hash), INDEX (body), - INDEX (l1_proof), INDEX (height), - INDEX (sequence), INDEX (is_canonical), INDEX (is_executed), + INDEX (l1_proof) # INDEX (is_canonical, is_executed), # INDEX (is_canonical, is_executed, height), - primary key (hash) ); GRANT ALL ON obsdb.batch TO obscuro; create table if not exists obsdb.tx ( hash binary(16), + full_hash binary(32) NOT NULL, content mediumblob NOT NULL, sender_address binary(20) NOT NULL, nonce int NOT NULL, @@ -115,7 +117,7 @@ create table if not exists obsdb.exec_tx created_contract_address binary(20), receipt mediumblob, tx binary(16) NOT NULL, - batch binary(16) NOT NULL, + batch int NOT NULL, INDEX (batch), INDEX (tx), primary key (id) @@ -129,6 +131,11 @@ create table if not exists obsdb.events 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), datablob mediumblob, log_idx int NOT NULL, address binary(20) NOT NULL, diff --git a/go/enclave/storage/init/sqlite/001_init.sql b/go/enclave/storage/init/sqlite/001_init.sql index da91880976..527dbfe111 100644 --- a/go/enclave/storage/init/sqlite/001_init.sql +++ b/go/enclave/storage/init/sqlite/001_init.sql @@ -57,6 +57,7 @@ create table if not exists batch_body create table if not exists batch ( sequence int primary key, + full_hash binary(32), hash binary(16) NOT NULL unique, parent binary(16), height int NOT NULL, @@ -75,6 +76,7 @@ create index IDX_BATCH_Block on batch (l1_proof); create table if not exists tx ( hash binary(16) primary key, + full_hash binary(32) NOT NULL, content mediumblob NOT NULL, sender_address binary(20) NOT NULL, nonce int NOT NULL, @@ -102,6 +104,11 @@ create table if not exists events 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), datablob mediumblob, log_idx int NOT NULL, address binary(20) NOT NULL, diff --git a/integration/simulation/transaction_injector.go b/integration/simulation/transaction_injector.go index 5a2d14f90e..f92dda9161 100644 --- a/integration/simulation/transaction_injector.go +++ b/integration/simulation/transaction_injector.go @@ -284,7 +284,7 @@ func (ti *TransactionInjector) issueInvalidL2Txs() { err := ti.rpcHandles.ObscuroWalletRndClient(fromWallet).SendTransaction(ti.ctx, signedTx) if err != nil { - ti.logger.Warn("Failed to issue withdrawal via RPC. ", log.ErrKey, err) + ti.logger.Info("Failed to issue withdrawal via RPC. ", log.ErrKey, err) } time.Sleep(testcommon.RndBtwTime(ti.avgBlockDuration/4, ti.avgBlockDuration)) }