From 7009263b306634aa2a256db4e1c030978694f4ee Mon Sep 17 00:00:00 2001 From: Will Hester Date: Thu, 7 Mar 2024 14:23:54 +0000 Subject: [PATCH] stashing --- .../storage/database/migration/db_migration.go | 3 --- go/host/enclave/guardian.go | 2 +- go/host/storage/hostdb/batch.go | 16 ++++++++++------ integration/common/utils.go | 2 +- integration/noderunner/in_memory_node.go | 2 -- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/go/common/storage/database/migration/db_migration.go b/go/common/storage/database/migration/db_migration.go index 4ab502acb9..bc15fcefc4 100644 --- a/go/common/storage/database/migration/db_migration.go +++ b/go/common/storage/database/migration/db_migration.go @@ -24,12 +24,10 @@ func CommonDBMigration(db *sql.DB, sqlFiles embed.FS, logger gethlog.Logger) err return err } - println("Migration files ", migrationFiles) maxMigration := int64(len(migrationFiles)) var maxDB int64 config, err := database.FetchConfig(db, currentMigrationVersionKey) - println("config ", config) if err != nil { // first time there is no entry, so 001 was executed already ( triggered at launch/manifest time ) if errors.Is(err, errutil.ErrNotFound) { @@ -84,7 +82,6 @@ func readMigrationFiles(sqlFiles embed.FS) ([]fs.DirEntry, error) { return nil, err } - println("HERE") // sort the migrationFiles based on the prefix (before "_") sort.Slice(migrationFiles, func(i, j int) bool { // Extract the number prefix and compare diff --git a/go/host/enclave/guardian.go b/go/host/enclave/guardian.go index 593d04bd8b..2ff765dac4 100644 --- a/go/host/enclave/guardian.go +++ b/go/host/enclave/guardian.go @@ -475,8 +475,8 @@ func (g *Guardian) processL1BlockTransactions(block *common.L1Block) { g.logger.Error("Could not fetch rollup metadata from enclave.", log.ErrKey, err) } err = hostdb.AddRollupHeader(g.db, r, metaData, block) - println("ROLLUP DATA start time", metaData.StartTime) println("ROLLUP DATA First batch", metaData.FirstBatchSequence.String()) + println("ROLLUP DATA Last batch", r.Header.LastBatchSeqNo) //FIXME need to store this data? //err = hostdb.AddBlock(g.db, block, r.Header.Hash()) if err != nil { diff --git a/go/host/storage/hostdb/batch.go b/go/host/storage/hostdb/batch.go index 4703debce6..21627a2287 100644 --- a/go/host/storage/hostdb/batch.go +++ b/go/host/storage/hostdb/batch.go @@ -37,14 +37,17 @@ const ( // AddBatch adds a batch and its header to the DB func AddBatch(db *sql.DB, batch *common.ExtBatch) error { + // Start a transaction + tx, err := db.Begin() + if err != nil { + return err + } // Check if the Batch is already stored - _, err := GetBatchBySequenceNumber(db, batch.Header.SequencerOrderNo.Uint64()) + _, err = GetBatchBySequenceNumber(db, batch.Header.SequencerOrderNo.Uint64()) if err == nil { - println("DUPLICATE BATCH SEQ", batch.Header.SequencerOrderNo.String()) return errutil.ErrAlreadyExists } // Encode batch data - println("[SQL] Adding batch with seq number: ", batch.SeqNo().Uint64()) batchBodyID := batch.SeqNo().Uint64() body, err := rlp.EncodeToBytes(batch.EncryptedTxBlob) if err != nil { @@ -57,10 +60,9 @@ func AddBatch(db *sql.DB, batch *common.ExtBatch) error { _, err = GetBatchBodyBySequenceNumber(db, batch.Header.SequencerOrderNo.Uint64()) if err == nil { - println("DUPLICATE BATCH BODY", batch.Header.SequencerOrderNo.String()) return errutil.ErrAlreadyExists } - _, err = db.Exec(insertBatchBody, batchBodyID, body) + _, err = tx.Exec(insertBatchBody, batchBodyID, body) if err != nil { return fmt.Errorf("failed to insert body: %w", err) } @@ -317,7 +319,9 @@ func fetchPublicBatch(db *sql.DB, whereQuery string, args ...any) (*common.Publi // Fetch batch_body from the database var encryptedTxBlob common.EncryptedTransactions encryptedTxBlob, err = fetchBatchBody(db, bodyID) - if err != nil { return nil, fmt.Errorf("failed to fetch batch body: %w", err) } + if err != nil { + return nil, fmt.Errorf("failed to fetch batch body: %w", err) + } // Construct the batch batch := &common.PublicBatch{ diff --git a/integration/common/utils.go b/integration/common/utils.go index f0ff1839ad..8b5eb9ef7b 100644 --- a/integration/common/utils.go +++ b/integration/common/utils.go @@ -99,7 +99,7 @@ func PrefundWallets(ctx context.Context, faucetWallet wallet.Wallet, faucetClien txHashes := make([]gethcommon.Hash, len(wallets)) for idx, w := range wallets { destAddr := w.Address() - fmt.Printf("L2 prefund: %s\n", destAddr.Hex()) + fmt.Printf("L2 prefund: %s\n", destAddr.String()) txData := &types.LegacyTx{ Nonce: startingNonce + uint64(idx), Value: alloc, diff --git a/integration/noderunner/in_memory_node.go b/integration/noderunner/in_memory_node.go index 0ef16364bc..ab6a49fe45 100644 --- a/integration/noderunner/in_memory_node.go +++ b/integration/noderunner/in_memory_node.go @@ -34,13 +34,11 @@ func (d *InMemNode) Start() error { err := d.startEnclave() if err != nil { - println("ENCLAVE ERROR") return err } err = d.startHost() if err != nil { - println("HOST ERROR") return err }