diff --git a/consensus/XDPoS/engines/engine_v2/engine.go b/consensus/XDPoS/engines/engine_v2/engine.go index b808a56236f1..8a855e2d2a82 100644 --- a/consensus/XDPoS/engines/engine_v2/engine.go +++ b/consensus/XDPoS/engines/engine_v2/engine.go @@ -393,7 +393,7 @@ func (x *XDPoS_v2) Finalize(chain consensus.ChainReader, header *types.Header, s if len(common.StoreRewardFolder) > 0 { data, err := json.Marshal(rewards) if err == nil { - err = os.WriteFile(filepath.Join(common.StoreRewardFolder, header.Number.String()+"."+header.Hash().Hex()), data, 0644) + err = os.WriteFile(filepath.Join(common.StoreRewardFolder, header.Number.String()), data, 0644) } if err != nil { log.Error("Error when save reward info ", "number", header.Number, "hash", header.Hash().Hex(), "err", err) diff --git a/eth/api_backend.go b/eth/api_backend.go index 183a0f1f4485..e549d7bd40ff 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -408,25 +408,19 @@ func (b *EthApiBackend) StateAtBlock(ctx context.Context, block *types.Block, re func (s *EthApiBackend) GetRewardByHash(hash common.Hash) map[string]map[string]map[string]*big.Int { header := s.eth.blockchain.GetHeaderByHash(hash) + err := errors.New("header hash not found") if header != nil { - data, err := os.ReadFile(filepath.Join(common.StoreRewardFolder, header.Number.String()+"."+header.Hash().Hex())) + data, err := os.ReadFile(filepath.Join(common.StoreRewardFolder, header.Number.String())) if err == nil { rewards := make(map[string]map[string]map[string]*big.Int) err = json.Unmarshal(data, &rewards) if err == nil { + log.Error("[GetRewardByHash] file found and returning rewards", "blocknum", header.Number.String()) return rewards } - } else { - data, err = os.ReadFile(filepath.Join(common.StoreRewardFolder, header.Number.String()+"."+header.HashNoValidator().Hex())) - if err == nil { - rewards := make(map[string]map[string]map[string]*big.Int) - err = json.Unmarshal(data, &rewards) - if err == nil { - return rewards - } - } } } + log.Error("[GetRewardByHash]", "err", err) return make(map[string]map[string]map[string]*big.Int) }