mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-03 09:37:38 +00:00
Snapshots: allow stage_headers --unwind behind available snapshots (#3971)
* save * save * save
This commit is contained in:
parent
dba9544edc
commit
3906d7e51f
@ -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
|
||||
|
@ -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 {
|
||||
@ -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 {
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user