Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Homogenise sqlite config #2134

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions go/enclave/storage/db_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -25,15 +25,15 @@ 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 {
// persistent but not secure in an enclave, we'll connect to a throwaway sqlite DB and test out persistence/sql implementations
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 {
Expand Down
7 changes: 5 additions & 2 deletions go/host/storage/db_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
Expand Down
14 changes: 1 addition & 13 deletions integration/simulation/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand All @@ -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))
}

Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions tools/walletextension/storage/database/sqlite/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Loading