diff --git a/go/enclave/storage/db_init.go b/go/enclave/storage/db_init.go index 65aae1e4a2..d989dcebe8 100644 --- a/go/enclave/storage/db_init.go +++ b/go/enclave/storage/db_init.go @@ -15,7 +15,7 @@ import ( // _journal_mode=wal - The recommended running mode: "Write-ahead logging": https://www.sqlite.org/draft/matrix/wal.html // _txlock=immediate - db transactions start as soon as "BeginTx()" is called. Avoids deadlocks. https://www.sqlite.org/lang_transaction.html // _synchronous=normal - not exactly sure if we actually need this. It was recommended somewhere. https://www.sqlite.org/pragma.html#pragma_synchronous -const sqliteCfg = "_foreign_keys=on&_journal_mode=wal&_txlock=immediate&_synchronous=normal" +const SqliteCfg = "_foreign_keys=on&_journal_mode=wal&_txlock=immediate&_synchronous=normal" // CreateDBFromConfig creates an appropriate ethdb.Database instance based on your config func CreateDBFromConfig(cfg *enclaveconfig.EnclaveConfig, logger gethlog.Logger) (enclavedb.EnclaveDB, error) { @@ -25,7 +25,7 @@ func CreateDBFromConfig(cfg *enclaveconfig.EnclaveConfig, logger gethlog.Logger) if cfg.UseInMemoryDB { logger.Info("UseInMemoryDB flag is true, data will not be persisted. Creating temporary sqlite database...") // this creates a temporary sqlite sqldb - return sqlite.CreateTemporarySQLiteDB("", sqliteCfg, *cfg, logger) + return sqlite.CreateTemporarySQLiteDB("", SqliteCfg, *cfg, logger) } if !cfg.WillAttest && len(cfg.SqliteDBPath) > 0 { @@ -33,7 +33,7 @@ func CreateDBFromConfig(cfg *enclaveconfig.EnclaveConfig, logger gethlog.Logger) logger.Warn("Attestation is disabled, using a basic sqlite DB for persistence") // when we want to test persistence after node restart the SqliteDBPath should be set // (if empty string then a temp sqldb file will be created for the lifetime of the enclave) - return sqlite.CreateTemporarySQLiteDB(cfg.SqliteDBPath, sqliteCfg, *cfg, logger) + return sqlite.CreateTemporarySQLiteDB(cfg.SqliteDBPath, SqliteCfg, *cfg, logger) } if !cfg.WillAttest && len(cfg.EdgelessDBHost) > 0 { diff --git a/go/host/storage/db_init.go b/go/host/storage/db_init.go index b2ed319b8b..1f1abd1d28 100644 --- a/go/host/storage/db_init.go +++ b/go/host/storage/db_init.go @@ -11,7 +11,10 @@ import ( "github.com/ten-protocol/go-ten/go/host/storage/init/postgres" ) -const HOST = "HOST_" +const ( + HOST = "HOST_" + sqliteHostCfg = "mode=memory&cache=shared&_foreign_keys=on&_journal_mode=wal&_txlock=immediate&_synchronous=normal" +) // CreateDBFromConfig creates an appropriate ethdb.Database instance based on your config func CreateDBFromConfig(cfg *hostconfig.HostConfig, logger gethlog.Logger) (hostdb.HostDB, error) { @@ -21,7 +24,7 @@ func CreateDBFromConfig(cfg *hostconfig.HostConfig, logger gethlog.Logger) (host } if cfg.UseInMemoryDB { logger.Info("UseInMemoryDB flag is true, data will not be persisted. Creating in-memory database...") - sqliteDB, err := sqlite.CreateTemporarySQLiteHostDB(dbName, "mode=memory&cache=shared&_foreign_keys=on") + sqliteDB, err := sqlite.CreateTemporarySQLiteHostDB(dbName, sqliteHostCfg) if err != nil { return nil, fmt.Errorf("could not create in memory sqlite DB: %w", err) } diff --git a/integration/simulation/simulation.go b/integration/simulation/simulation.go index d1dd200804..6ebdf6961c 100644 --- a/integration/simulation/simulation.go +++ b/integration/simulation/simulation.go @@ -55,7 +55,6 @@ func (s *Simulation) Start() { testlog.Logger().Info(fmt.Sprintf("Genesis block: b_%d.", common.ShortHash(ethereummock.MockGenesisBlock.Hash()))) s.ctx = context.Background() // use injected context for graceful shutdowns - fmt.Printf("Waiting for TEN genesis on L1\n") s.waitForTenGenesisOnL1() // Arbitrary sleep to wait for RPC clients to get up and running @@ -69,32 +68,24 @@ func (s *Simulation) Start() { } jsonCfg, err := json.Marshal(cfg) if err == nil { - fmt.Printf("Config: %v\n", string(jsonCfg)) + testlog.Logger().Error("Config: %v\n", string(jsonCfg)) } - fmt.Printf("Funding the bridge to TEN\n") s.bridgeFundingToTen() - fmt.Printf("Deploying ZenBase contract\n") s.deployTenZen() // Deploy the ZenBase contract - fmt.Printf("Creating log subscriptions\n") s.trackLogs() // Create log subscriptions, to validate that they're working correctly later. - fmt.Printf("Prefunding L2 wallets\n") s.prefundTenAccounts() // Prefund every L2 wallet - fmt.Printf("Deploying TEN ERC20 contracts\n") s.deployTenERC20s() // Deploy the TEN HOC and POC ERC20 contracts - fmt.Printf("Prefunding L1 wallets\n") s.prefundL1Accounts() // Prefund every L1 wallet - fmt.Printf("Checking health status\n") s.checkHealthStatus() // Checks the nodes health status timer := time.Now() - fmt.Printf("Starting injection\n") testlog.Logger().Info("Starting injection") go s.TxInjector.Start() @@ -103,14 +94,12 @@ func (s *Simulation) Start() { // Wait for the simulation time time.Sleep(s.SimulationTime - s.Params.StoppingDelay) - fmt.Printf("Stopping injection\n") testlog.Logger().Info("Stopping injection") s.TxInjector.Stop() time.Sleep(s.Params.StoppingDelay) - fmt.Printf("Ran simulation for %f secs, configured to run for: %s ... \n", time.Since(timer).Seconds(), s.SimulationTime) testlog.Logger().Info(fmt.Sprintf("Ran simulation for %f secs, configured to run for: %s ... \n", time.Since(timer).Seconds(), s.SimulationTime)) } @@ -336,7 +325,6 @@ func (s *Simulation) deployTenERC20s() { } contractBytes := erc20contract.L2BytecodeWithDefaultSupply(string(token), cfg.L2MessageBusAddress) - fmt.Printf("Deploy contract from: %s\n", owner.Address().Hex()) deployContractTxData := types.DynamicFeeTx{ Nonce: NextNonce(s.ctx, s.RPCHandles, owner), Gas: 5_000_000, diff --git a/tools/walletextension/storage/database/sqlite/sqlite.go b/tools/walletextension/storage/database/sqlite/sqlite.go index 57ce320a92..b4dedf98c1 100644 --- a/tools/walletextension/storage/database/sqlite/sqlite.go +++ b/tools/walletextension/storage/database/sqlite/sqlite.go @@ -14,6 +14,8 @@ import ( "os" "path/filepath" + "github.com/ten-protocol/go-ten/go/enclave/storage" + dbcommon "github.com/ten-protocol/go-ten/tools/walletextension/storage/database/common" "github.com/ten-protocol/go-ten/go/common/viewingkey" @@ -28,8 +30,6 @@ type SqliteDB struct { db *sql.DB } -const sqliteCfg = "_foreign_keys=on&_journal_mode=wal&_txlock=immediate&_synchronous=normal" - func NewSqliteDatabase(dbPath string) (*SqliteDB, error) { // load the db file dbFilePath, err := createOrLoad(dbPath) @@ -38,7 +38,7 @@ func NewSqliteDatabase(dbPath string) (*SqliteDB, error) { } // open the db - path := fmt.Sprintf("file:%s?%s", dbFilePath, sqliteCfg) + path := fmt.Sprintf("file:%s?%s", dbFilePath, storage.SqliteCfg) db, err := sql.Open("sqlite3", path) if err != nil { fmt.Println("Error opening database: ", err)