[dumpdb] ensure each cross link is dumped (#4311)

pull/4316/head
Max 2 years ago committed by GitHub
parent f14d8401a1
commit fd008c95d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      cmd/harmony/dumpdb.go
  2. 2
      core/offchain.go

@ -15,12 +15,14 @@ import (
ethRawDB "github.com/ethereum/go-ethereum/core/rawdb" ethRawDB "github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/harmony-one/harmony/block" "github.com/harmony-one/harmony/block"
"github.com/harmony-one/harmony/core/rawdb" "github.com/harmony-one/harmony/core/rawdb"
"github.com/harmony-one/harmony/core/state" "github.com/harmony-one/harmony/core/state"
"github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/hmy" "github.com/harmony-one/harmony/hmy"
"github.com/harmony-one/harmony/internal/cli" "github.com/harmony-one/harmony/internal/cli"
"github.com/harmony-one/harmony/shard"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node" nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
shardingconfig "github.com/harmony-one/harmony/internal/configs/sharding" 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) latestNumber := block.NumberU64() - uint64(i)
latestBlock := db.GetBlockByNumber(latestNumber) latestBlock := db.GetBlockByNumber(latestNumber)
db.GetBlockByHash(latestBlock.Hash()) db.GetBlockByHash(latestBlock.Hash())
db.GetHeaderByHash(latestBlock.Hash()) header := db.GetHeaderByHash(latestBlock.Hash())
db.GetBlockByHash(latestBlock.Hash()) db.GetBlockByHash(latestBlock.Hash())
rawdb.ReadBlockRewardAccumulator(db, latestNumber) rawdb.ReadBlockRewardAccumulator(db, latestNumber)
rawdb.ReadBlockCommitSig(db, latestNumber) rawdb.ReadBlockCommitSig(db, latestNumber)
epoch := block.Epoch() // for each header, read (and write) the cross links in it
epochInstance := shardSchedule.InstanceForEpoch(epoch) if block.ShardID() == shard.BeaconChainShardID {
for shard := 0; shard < int(epochInstance.NumShards()); shard++ { crossLinks := &types.CrossLinks{}
rawdb.ReadCrossLinkShardBlock(db, uint32(shard), latestNumber) if err := rlp.DecodeBytes(header.CrossLinks(), crossLinks); err == nil {
for _, cl := range *crossLinks {
rawdb.ReadCrossLinkShardBlock(db, cl.ShardID(), cl.BlockNum())
}
}
} }
} }
headEpoch := block.Epoch() headEpoch := block.Epoch()

@ -167,6 +167,8 @@ func (bc *BlockChainImpl) CommitOffChainData(
cl0, _ := bc.ReadShardLastCrossLink(crossLink.ShardID()) cl0, _ := bc.ReadShardLastCrossLink(crossLink.ShardID())
if cl0 == nil { 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()) rawdb.WriteShardLastCrossLink(batch, crossLink.ShardID(), crossLink.Serialize())
} }
} }

Loading…
Cancel
Save