From fd008c95d968a731aeee72d66bda2f64697e524d Mon Sep 17 00:00:00 2001 From: Max <82761650+MaxMustermann2@users.noreply.github.com> Date: Sun, 25 Dec 2022 05:11:33 +0000 Subject: [PATCH] [dumpdb] ensure each cross link is dumped (#4311) --- cmd/harmony/dumpdb.go | 16 +++++++++++----- core/offchain.go | 2 ++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cmd/harmony/dumpdb.go b/cmd/harmony/dumpdb.go index 7a4c41440..e66d3617b 100644 --- a/cmd/harmony/dumpdb.go +++ b/cmd/harmony/dumpdb.go @@ -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" @@ -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() diff --git a/core/offchain.go b/core/offchain.go index 244b757c1..3f08b4f81 100644 --- a/core/offchain.go +++ b/core/offchain.go @@ -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()) } }