Skip to content

Commit

Permalink
T3 merge2 (#2731)
Browse files Browse the repository at this point in the history
* [validator] Hide one field from JSON (#2705)

* [rpc] Show both latest header of beacon chain and shard chain (#2714)

* change explorer node storage folder (#2720)

* [state] ValidatorWrapper div zero panic fix -  (#2724)

* [state] Error on div zero

* [state] Do not pay out commit when commit is 0%

* [state] Put whole commission in guarded block

* [core] Reward cannot be zero

* [state] return nil, not hard error

* make validator snapshot consistent with election (#2726)

* make validator snapshot consistent with election

* fix condition with only beacon chain

* Fix epoch number

* Fix stats update nil epoch issue

* [node.sh] use rclone to fast sync harmony_db_0 (#2709)

Signed-off-by: Leo Chen <leo@harmony.one>

* fix validator snapshot cache

Co-authored-by: Edgar Aroutiounian <edgar.factorial@gmail.com>
Co-authored-by: Minh Doan <40258599+mikedoan@users.noreply.github.com>
Co-authored-by: Leo Chen <leo@harmony.one>
  • Loading branch information
4 people authored Apr 5, 2020
1 parent 9013069 commit d64bcfa
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2229,7 +2229,8 @@ func (bc *BlockChain) ReadValidatorSnapshotAtEpoch(
func (bc *BlockChain) ReadValidatorSnapshot(
addr common.Address,
) (*staking.ValidatorWrapper, error) {
if cached, ok := bc.validatorCache.Get("validator-snapshot-" + string(addr.Bytes())); ok {
epoch := bc.CurrentBlock().Epoch()
if cached, ok := bc.validatorCache.Get("validator-snapshot-" + string(addr.Bytes()) + epoch.String()); ok {
by := cached.([]byte)
v := staking.ValidatorWrapper{}
if err := rlp.DecodeBytes(by, &v); err != nil {
Expand All @@ -2238,7 +2239,7 @@ func (bc *BlockChain) ReadValidatorSnapshot(
return &v, nil
}

return rawdb.ReadValidatorSnapshot(bc.db, addr, bc.CurrentBlock().Epoch())
return rawdb.ReadValidatorSnapshot(bc.db, addr, epoch)
}

// writeValidatorSnapshots writes the snapshot of provided list of validators
Expand Down Expand Up @@ -2266,7 +2267,7 @@ func (bc *BlockChain) writeValidatorSnapshots(
for i := range validators {
by, err := rlp.EncodeToBytes(validators[i])
if err == nil {
key := "validator-snapshot-" + string(validators[i].Address.Bytes())
key := "validator-snapshot-" + string(validators[i].Address.Bytes()) + epoch.String()
bc.validatorCache.Add(key, by)
}
}
Expand Down

0 comments on commit d64bcfa

Please sign in to comment.