Snapshots: allow stage_headers --unwind behind available snapshots (#3971)

* save

* save

* save
This commit is contained in:
Alex Sharov 2022-04-26 12:04:38 +07:00 committed by GitHub
parent dba9544edc
commit 3906d7e51f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 17 deletions

View File

@ -477,7 +477,7 @@ func stageHeaders(db kv.RwDB, ctx context.Context) error {
return err return err
} }
if err = tx.Put(kv.HeadHeaderKey, []byte(kv.HeadHeaderKey), hash[:]); err != nil { 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) log.Info("Progress", "headers", progress)
return nil return nil

View File

@ -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) // 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 { 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) newVBytes := make([]byte, 8)
binary.BigEndian.PutUint64(newVBytes, newValue) binary.BigEndian.PutUint64(newVBytes, newValue)
if err := tx.Put(kv.Sequence, []byte(bucket), newVBytes); err != nil { if err := tx.Put(kv.Sequence, []byte(bucket), newVBytes); err != nil {
@ -1111,13 +1099,13 @@ func DeleteAncientBlocks(db kv.RwTx, blockTo uint64, blocksDeleteLimit int) erro
} }
defer c.Close() defer c.Close()
var stopAtBlock uint64 var stopAtBlock, firstNonGenesisInDB uint64
{ {
k, _, err := c.First() k, _, err := c.First()
if err != nil { if err != nil {
return err return err
} }
firstNonGenesisInDB := binary.BigEndian.Uint64(k) firstNonGenesisInDB = binary.BigEndian.Uint64(k)
if firstNonGenesisInDB == 0 { // keep genesis in DB if firstNonGenesisInDB == 0 { // keep genesis in DB
k, _, err := c.Next() k, _, err := c.Next()
if err != nil { if err != nil {
@ -1133,7 +1121,7 @@ func DeleteAncientBlocks(db kv.RwTx, blockTo uint64, blocksDeleteLimit int) erro
} }
n := binary.BigEndian.Uint64(k) n := binary.BigEndian.Uint64(k)
if n >= stopAtBlock { if n >= stopAtBlock { // [from, to)
break break
} }

View File

@ -1265,7 +1265,7 @@ func DumpTxs(ctx context.Context, db kv.RoDB, segmentFile, tmpDir string, blockF
var lastBody types.BodyForStorage var lastBody types.BodyForStorage
if err := kv.BigChunks(db, kv.HeaderCanonical, from, func(tx kv.Tx, k, v []byte) (bool, error) { if err := kv.BigChunks(db, kv.HeaderCanonical, from, func(tx kv.Tx, k, v []byte) (bool, error) {
blockNum := binary.BigEndian.Uint64(k) blockNum := binary.BigEndian.Uint64(k)
if blockNum >= blockTo { if blockNum >= blockTo { // [from, to)
return false, nil return false, nil
} }