Skip to content

Commit

Permalink
[dumpdb] ensure each cross link is dumped (harmony-one#4311)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxMustermann2 authored Dec 25, 2022
1 parent f14d840 commit fd008c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 11 additions & 5 deletions cmd/harmony/dumpdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ import (
ethRawDB "github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/harmony-one/harmony/block"
"github.com/harmony-one/harmony/core/rawdb"
"github.com/harmony-one/harmony/core/state"
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/hmy"
"github.com/harmony-one/harmony/internal/cli"
"github.com/harmony-one/harmony/shard"

nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
shardingconfig "github.com/harmony-one/harmony/internal/configs/sharding"
Expand Down Expand Up @@ -276,14 +278,18 @@ func (db *KakashiDB) offchainDataDump(block *types.Block) {
latestNumber := block.NumberU64() - uint64(i)
latestBlock := db.GetBlockByNumber(latestNumber)
db.GetBlockByHash(latestBlock.Hash())
db.GetHeaderByHash(latestBlock.Hash())
header := db.GetHeaderByHash(latestBlock.Hash())
db.GetBlockByHash(latestBlock.Hash())
rawdb.ReadBlockRewardAccumulator(db, latestNumber)
rawdb.ReadBlockCommitSig(db, latestNumber)
epoch := block.Epoch()
epochInstance := shardSchedule.InstanceForEpoch(epoch)
for shard := 0; shard < int(epochInstance.NumShards()); shard++ {
rawdb.ReadCrossLinkShardBlock(db, uint32(shard), latestNumber)
// for each header, read (and write) the cross links in it
if block.ShardID() == shard.BeaconChainShardID {
crossLinks := &types.CrossLinks{}
if err := rlp.DecodeBytes(header.CrossLinks(), crossLinks); err == nil {
for _, cl := range *crossLinks {
rawdb.ReadCrossLinkShardBlock(db, cl.ShardID(), cl.BlockNum())
}
}
}
}
headEpoch := block.Epoch()
Expand Down
2 changes: 2 additions & 0 deletions core/offchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ func (bc *BlockChainImpl) CommitOffChainData(

cl0, _ := bc.ReadShardLastCrossLink(crossLink.ShardID())
if cl0 == nil {
// make sure it is written at least once, so that it is overwritten below
// under "Roll up latest crosslinks"
rawdb.WriteShardLastCrossLink(batch, crossLink.ShardID(), crossLink.Serialize())
}
}
Expand Down

0 comments on commit fd008c9

Please sign in to comment.