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

Don't reverse seek in handleSnapshotCompleted #89

Merged
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion deso/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ func (node *Node) GetTransactionsForConvertBlock(block *lib.MsgDeSoBlock) []*typ
transactions := []*types.Transaction{}

// Fetch the Utxo ops for this block
utxoOpsForBlock, _ := node.Index.GetUtxoOps(block)
utxoOpsForBlock, err := node.Index.GetUtxoOps(block)
if err != nil {
glog.Error(errors.Wrapf(err, "GetTransactionsForConvertBlock: Problem fetching utxo ops for block"))
}

// TODO: Can we be smarter about this size somehow?
// 2x number of transactions feels like a good enough proxy for now
Expand Down
17 changes: 2 additions & 15 deletions deso/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/dgraph-io/badger/v4"
"github.com/golang/glog"
"github.com/pkg/errors"
"math"
"time"
)

Expand Down Expand Up @@ -155,8 +154,6 @@ func (node *Node) handleSnapshotCompleted() {
dbPrefixx := append([]byte{}, lib.Prefixes.PrefixCreatorDeSoLockedNanosCreatorPKID...)
opts := badger.DefaultIteratorOptions
opts.PrefetchValues = false
// Go in reverse order since a larger count is better.
opts.Reverse = true

// Set the prefix on the iterator options
opts.Prefix = dbPrefixx
Expand All @@ -178,12 +175,8 @@ func (node *Node) handleSnapshotCompleted() {
}
currentCounter := uint64(0)
currentTime := time.Now()
// Since we iterate backwards, the prefix must be bigger than all possible
// counts that could actually exist. We use eight bytes since the count is
// encoded as a 64-bit big-endian byte slice, which will be eight bytes long.
maxBigEndianUint64Bytes := []byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
prefix := append(dbPrefixx, maxBigEndianUint64Bytes...)
for it.Seek(prefix); it.ValidForPrefix(dbPrefixx); it.Next() {
for it.Seek(dbPrefixx); it.ValidForPrefix(dbPrefixx); it.Next() {
rawKey := it.Item().Key()

// Strip the prefix off the key and check its length. If it contains
Expand Down Expand Up @@ -273,8 +266,6 @@ func (node *Node) handleSnapshotCompleted() {
dbPrefixx := append([]byte{}, lib.Prefixes.PrefixValidatorByStatusAndStakeAmount...)
opts := badger.DefaultIteratorOptions
opts.PrefetchValues = false
// Go in reverse order since a larger count is better.
opts.Reverse = true

// Set prefix on iterator
opts.Prefix = dbPrefixx
Expand Down Expand Up @@ -302,9 +293,7 @@ func (node *Node) handleSnapshotCompleted() {
// this: Prefix, <Status uint8>, <TotalStakeAmountNanos *uint256.Int>, <ValidatorPKID [33]byte> -> nil
// So we need to chop off the status to pull out the total stake amount nanos and the validator PKID
maxUint256 := lib.FixedWidthEncodeUint256(lib.MaxUint256)
prefix := append(dbPrefixx, lib.EncodeUint8(math.MaxUint8)...)
prefix = append(prefix, maxUint256...)
for it.Seek(prefix); it.ValidForPrefix(dbPrefixx); it.Next() {
for it.Seek(dbPrefixx); it.ValidForPrefix(dbPrefixx); it.Next() {
rawKey := it.Item().Key()

// Strip the prefix and status off the key and check its length. It
Expand Down Expand Up @@ -396,8 +385,6 @@ func (node *Node) handleSnapshotCompleted() {
dbPrefixx := append([]byte{}, lib.Prefixes.PrefixLockedStakeByValidatorAndStakerAndLockedAt...)
opts := badger.DefaultIteratorOptions
opts.PrefetchValues = true
// Go in reverse order since a larger count is better.
opts.Reverse = true

// Set prefix on iterator
opts.Prefix = dbPrefixx
Expand Down