Browse Source

lite2: batch save & delete operations in DB store (#4345)

Closes #4330
pull/4355/head
Anton Kaliaev 4 years ago
committed by GitHub
parent
commit
79b99f052b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 15 deletions
  1. +17
    -15
      lite2/store/db/db.go

+ 17
- 15
lite2/store/db/db.go View File

@ -1,11 +1,11 @@
package db
import (
"errors"
"fmt"
"regexp"
"strconv"
"github.com/pkg/errors"
"github.com/tendermint/go-amino"
dbm "github.com/tendermint/tm-db"
@ -38,20 +38,21 @@ func (s *dbs) SaveSignedHeaderAndNextValidatorSet(sh *types.SignedHeader, valSet
panic("negative or zero height")
}
// TODO: batch
bz, err := s.cdc.MarshalBinaryLengthPrefixed(sh)
shBz, err := s.cdc.MarshalBinaryLengthPrefixed(sh)
if err != nil {
return err
return errors.Wrap(err, "marshalling header")
}
s.db.Set(s.shKey(sh.Height), bz)
bz, err = s.cdc.MarshalBinaryLengthPrefixed(valSet)
valSetBz, err := s.cdc.MarshalBinaryLengthPrefixed(valSet)
if err != nil {
return err
return errors.Wrap(err, "marshalling validator set")
}
s.db.Set(s.vsKey(sh.Height+1), bz)
return nil
b := s.db.NewBatch()
b.Set(s.shKey(sh.Height), shBz)
b.Set(s.vsKey(sh.Height+1), valSetBz)
err = b.WriteSync()
b.Close()
return err
}
// DeleteSignedHeaderAndNextValidatorSet deletes SignedHeader and ValidatorSet
@ -61,11 +62,12 @@ func (s *dbs) DeleteSignedHeaderAndNextValidatorSet(height int64) error {
panic("negative or zero height")
}
// TODO: batch
s.db.Delete(s.shKey(height))
s.db.Delete(s.vsKey(height + 1))
return nil
b := s.db.NewBatch()
b.Delete(s.shKey(height))
b.Delete(s.vsKey(height + 1))
err := b.WriteSync()
b.Close()
return err
}
// SignedHeader loads SignedHeader at the given height.


Loading…
Cancel
Save