Skip to content

Commit

Permalink
Fix Check for Existence of allowedtxs.txt File Before Applying Logic (
Browse files Browse the repository at this point in the history
#4731)

* Fix Check for Existence of allowedtxs.txt File Before Applying Logic
* add debug logs for setupAllowedTxs
* improve logs for setupAllowedTxs
  • Loading branch information
GheisMohammadi authored Aug 22, 2024
1 parent b33cbc3 commit 8c40804
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions cmd/harmony/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1104,12 +1104,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
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

0 comments on commit 8c40804

Please sign in to comment.