Skip to content

Commit

Permalink
fix api by changing reward filename scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
wanwiset25 committed Nov 23, 2024
1 parent b0b2b7d commit 578f856
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion consensus/XDPoS/engines/engine_v2/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 4 additions & 10 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 578f856

Please sign in to comment.