Skip to content

Commit

Permalink
Snapshots: allow stage_headers --unwind behind available snapshots (#…
Browse files Browse the repository at this point in the history
…3971)

* save

* save

* save
  • Loading branch information
AskAlexSharov authored Apr 26, 2022
1 parent dba9544 commit 3906d7e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cmd/integration/commands/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ func stageHeaders(db kv.RwDB, ctx context.Context) error {
return err
}
if err = tx.Put(kv.HeadHeaderKey, []byte(kv.HeadHeaderKey), hash[:]); err != nil {
log.Error("ReadHeadHeaderHash failed", "err", err)
return err
}
log.Info("Progress", "headers", progress)
return nil
Expand Down
18 changes: 3 additions & 15 deletions core/rawdb/accessors_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,18 +498,6 @@ func RawTransactionsRange(db kv.Getter, from, to uint64) (res [][]byte, err erro

// ResetSequence - allow set arbitrary value to sequence (for example to decrement it to exact value)
func ResetSequence(tx kv.RwTx, bucket string, newValue uint64) error {
c, err := tx.Cursor(bucket)
if err != nil {
return err
}
k, _, err := c.Last()
if err != nil {
return err
}
if k != nil && binary.BigEndian.Uint64(k) >= newValue {
panic(fmt.Sprintf("must not happen. ResetSequence: %s, %d < lastInDB: %d\n", bucket, newValue, binary.BigEndian.Uint64(k)))
}

newVBytes := make([]byte, 8)
binary.BigEndian.PutUint64(newVBytes, newValue)
if err := tx.Put(kv.Sequence, []byte(bucket), newVBytes); err != nil {
Expand Down Expand Up @@ -1111,13 +1099,13 @@ func DeleteAncientBlocks(db kv.RwTx, blockTo uint64, blocksDeleteLimit int) erro
}
defer c.Close()

var stopAtBlock uint64
var stopAtBlock, firstNonGenesisInDB uint64
{
k, _, err := c.First()
if err != nil {
return err
}
firstNonGenesisInDB := binary.BigEndian.Uint64(k)
firstNonGenesisInDB = binary.BigEndian.Uint64(k)
if firstNonGenesisInDB == 0 { // keep genesis in DB
k, _, err := c.Next()
if err != nil {
Expand All @@ -1133,7 +1121,7 @@ func DeleteAncientBlocks(db kv.RwTx, blockTo uint64, blocksDeleteLimit int) erro
}

n := binary.BigEndian.Uint64(k)
if n >= stopAtBlock {
if n >= stopAtBlock { // [from, to)
break
}

Expand Down
2 changes: 1 addition & 1 deletion turbo/snapshotsync/block_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,7 @@ func DumpTxs(ctx context.Context, db kv.RoDB, segmentFile, tmpDir string, blockF
var lastBody types.BodyForStorage
if err := kv.BigChunks(db, kv.HeaderCanonical, from, func(tx kv.Tx, k, v []byte) (bool, error) {
blockNum := binary.BigEndian.Uint64(k)
if blockNum >= blockTo {
if blockNum >= blockTo { // [from, to)
return false, nil
}

Expand Down

0 comments on commit 3906d7e

Please sign in to comment.