Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG:can't freeze block error #592

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions database/rawdb/chain_freezer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package rawdb
import (
"fmt"
"github.com/Qitmeer/qng/meerdag"
"github.com/ethereum/go-ethereum/params"
"sync"
"sync/atomic"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/params"
)

const (
Expand Down Expand Up @@ -181,18 +181,24 @@ func (f *chainFreezer) freezeRange(nfdb *nofreezedb, id, limit uint64) ([]meerda

_, err := f.ModifyAncients(func(op ethdb.AncientWriteOp) error {
for ; id <= limit; id++ {
var header []byte
var block []byte
var dagbytes []byte
// Retrieve all the components of the canonical block.
mb := ReadDAGBlock(nfdb, id)
if mb == nil {
return fmt.Errorf("canonical hash missing, can't freeze block %d", id)
}
header := ReadHeaderRaw(nfdb, mb.GetHash())
if len(header) == 0 {
return fmt.Errorf("block header missing, can't freeze block %d %s", id, mb.GetHash().String())
}
block := ReadBodyRaw(nfdb, mb.GetHash())
if len(block) == 0 {
return fmt.Errorf("block body missing, can't freeze block %d %s", id, mb.GetHash().String())
log.Debug("Attempt to skip block freezing (possible cropping)", "id", id)
} else {
header = ReadHeaderRaw(nfdb, mb.GetHash())
if len(header) == 0 {
return fmt.Errorf("block header missing, can't freeze block %d %s", id, mb.GetHash().String())
}
block = ReadBodyRaw(nfdb, mb.GetHash())
if len(block) == 0 {
return fmt.Errorf("block body missing, can't freeze block %d %s", id, mb.GetHash().String())
}
dagbytes = mb.Bytes()
blocks = append(blocks, mb)
}

// Write to the batch.
Expand All @@ -202,10 +208,9 @@ func (f *chainFreezer) freezeRange(nfdb *nofreezedb, id, limit uint64) ([]meerda
if err := op.AppendRaw(ChainFreezerBlockTable, id, block); err != nil {
return fmt.Errorf("can't write hash to Freezer: %v", err)
}
if err := op.AppendRaw(ChainFreezerDAGBlockTable, id, mb.Bytes()); err != nil {
if err := op.AppendRaw(ChainFreezerDAGBlockTable, id, dagbytes); err != nil {
return fmt.Errorf("can't write header to Freezer: %v", err)
}
blocks = append(blocks, mb)
}
return nil
})
Expand Down
Loading