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

Fix Check for Existence of allowedtxs.txt File Before Applying Logic #4731

Merged
merged 3 commits into from
Aug 22, 2024
Merged
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
22 changes: 18 additions & 4 deletions cmd/harmony/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1101,12 +1101,26 @@ func parseAllowedTxs(data []byte) (map[ethCommon.Address][]core.AllowedTxData, e
}

func setupAllowedTxs(hc harmonyconfig.HarmonyConfig) (map[ethCommon.Address][]core.AllowedTxData, error) {
utils.Logger().Debug().Msgf("Using AllowedTxs file at `%s`", hc.TxPool.AllowedTxsFile)
data, err := os.ReadFile(hc.TxPool.AllowedTxsFile)
if err != nil {
// check if the file exists
if _, err := os.Stat(hc.TxPool.AllowedTxsFile); err == nil {
// read the file and parse allowed transactions
utils.Logger().Debug().Msgf("Using AllowedTxs file at `%s`", hc.TxPool.AllowedTxsFile)
data, err := os.ReadFile(hc.TxPool.AllowedTxsFile)
if err != nil {
return nil, err
}
return parseAllowedTxs(data)
} else if errors.Is(err, os.ErrNotExist) {
// file path does not exist
utils.Logger().Debug().
Str("AllowedTxsFile", hc.TxPool.AllowedTxsFile).
Msg("AllowedTxs file doesn't exist")
return make(map[ethCommon.Address][]core.AllowedTxData), nil
} else {
// some other errors happened
sophoah marked this conversation as resolved.
Show resolved Hide resolved
utils.Logger().Error().Err(err).Msg("setup allowedTxs failed")
return nil, err
}
return parseAllowedTxs(data)
}

func setupLocalAccounts(hc harmonyconfig.HarmonyConfig, blacklist map[ethCommon.Address]struct{}) ([]ethCommon.Address, error) {
Expand Down