-
Notifications
You must be signed in to change notification settings - Fork 108
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
feat(zetaclient): add support for EIP-1559 outbound transactions #2387
Changes from all commits
f2199a6
be500e1
67560c4
0bfe518
f576733
398ae1a
87b2f41
9ad5692
3bc0394
250fbd4
84df3ca
c7cfb73
d01b3b3
95955fe
ef4b58c
f4a31f8
07999ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -266,7 +266,7 @@ | |||||
|
||||||
// WithLogger attaches a new logger to the observer. | ||||||
func (ob *Observer) WithLogger(logger Logger) *Observer { | ||||||
chainLogger := logger.Std.With().Int64("chain", ob.chain.ChainId).Logger() | ||||||
chainLogger := logger.With().Int64("chain", ob.chain.ChainId).Logger() | ||||||
ob.logger = ObserverLogger{ | ||||||
Chain: chainLogger, | ||||||
Inbound: chainLogger.With().Str("module", "inbound").Logger(), | ||||||
|
@@ -290,27 +290,26 @@ | |||||
|
||||||
// OpenDB open sql database in the given path. | ||||||
func (ob *Observer) OpenDB(dbPath string, dbName string) error { | ||||||
// create db path if not exist | ||||||
if _, err := os.Stat(dbPath); os.IsNotExist(err) { | ||||||
err := os.MkdirAll(dbPath, os.ModePerm) | ||||||
if err != nil { | ||||||
return errors.Wrapf(err, "error creating db path: %s", dbPath) | ||||||
var dial gorm.Dialector | ||||||
|
||||||
// SQLite in-mem db | ||||||
if strings.Contains(dbPath, ":memory:") { | ||||||
dial = sqlite.Open(dbPath) | ||||||
} else { | ||||||
if err := ensureDirectory(dbPath); err != nil { | ||||||
return errors.Wrapf(err, "unable to ensure dbPath %q", dbPath) | ||||||
} | ||||||
} | ||||||
|
||||||
// use custom dbName or chain name if not provided | ||||||
if dbName == "" { | ||||||
dbName = ob.chain.ChainName.String() | ||||||
} | ||||||
path := fmt.Sprintf("%s/%s", dbPath, dbName) | ||||||
// use custom dbName or chain name if not provided | ||||||
if dbName == "" { | ||||||
dbName = ob.chain.ChainName.String() | ||||||
} | ||||||
|
||||||
// use memory db if specified | ||||||
if strings.Contains(dbPath, ":memory:") { | ||||||
path = dbPath | ||||||
dial = sqlite.Open(fmt.Sprintf("%s/%s", dbPath, dbName)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Consider moving this statement to a function that standardizes how we expect the db paths.
Suggested change
|
||||||
} | ||||||
|
||||||
// open db | ||||||
db, err := gorm.Open(sqlite.Open(path), &gorm.Config{Logger: logger.Default.LogMode(logger.Silent)}) | ||||||
db, err := gorm.Open(dial, &gorm.Config{Logger: logger.Default.LogMode(logger.Silent)}) | ||||||
if err != nil { | ||||||
return errors.Wrap(err, "error opening db") | ||||||
} | ||||||
|
@@ -320,11 +319,24 @@ | |||||
if err != nil { | ||||||
return errors.Wrap(err, "error migrating db") | ||||||
} | ||||||
|
||||||
ob.db = db | ||||||
|
||||||
return nil | ||||||
} | ||||||
|
||||||
func ensureDirectory(path string) error { | ||||||
_, err := os.Stat(path) | ||||||
switch { | ||||||
case os.IsNotExist(err): | ||||||
return os.MkdirAll(path, os.ModePerm) | ||||||
case err != nil: | ||||||
return err | ||||||
default: | ||||||
return nil | ||||||
} | ||||||
} | ||||||
|
||||||
// CloseDB close the database. | ||||||
func (ob *Observer) CloseDB() error { | ||||||
dbInst, err := ob.db.DB() | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -276,7 +276,7 @@ func TestOpenCloseDB(t *testing.T) { | |
}) | ||
t.Run("should return error on invalid db path", func(t *testing.T) { | ||
err := ob.OpenDB("/invalid/123db", "") | ||
require.ErrorContains(t, err, "error creating db path") | ||
require.ErrorContains(t, err, "unable to ensure dbPath") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "unable to ensure dbPath" is used a few times across the codebase, consider creating a const for it and reuse whenever needed. |
||
}) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: is there any reason we use zerolog instead of the standard library slog? Maybe we could start that conversation on a parallel discussion to eventually migrate and reduce the amount of dependencies on the core node.