Deliver envelopes in forward order (#1437)
This commit is contained in:
parent
056bf367a7
commit
64188f0702
|
@ -53,13 +53,3 @@ func NewDBKeyFromBytes(b []byte) (*DBKey, error) {
|
|||
hash: common.BytesToHash(b[4:]),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// mustNewDBKeyFromBytes panics if creating a key from a byte slice fails.
|
||||
// Check if a byte slice has DBKeyLength length before using it.
|
||||
func mustNewDBKeyFromBytes(b []byte) *DBKey {
|
||||
k, err := NewDBKeyFromBytes(b)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return k
|
||||
}
|
||||
|
|
|
@ -479,17 +479,14 @@ func (s *WMailServer) createIterator(lower, upper uint32, cursor []byte) iterato
|
|||
ku, kl *DBKey
|
||||
)
|
||||
|
||||
kl = NewDBKey(lower, emptyHash)
|
||||
if len(cursor) == DBKeyLength {
|
||||
ku = mustNewDBKeyFromBytes(cursor)
|
||||
} else {
|
||||
ku = NewDBKey(upper+1, emptyHash)
|
||||
}
|
||||
kl = NewDBKey(lower, emptyHash)
|
||||
|
||||
i := s.db.NewIterator(&util.Range{Start: kl.Bytes(), Limit: ku.Bytes()}, nil)
|
||||
// seek to the end as we want to return envelopes in a descending order
|
||||
i.Seek(ku.Bytes())
|
||||
|
||||
if len(cursor) == DBKeyLength {
|
||||
i.Seek(cursor)
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
|
@ -524,7 +521,7 @@ func (s *WMailServer) processRequestInBundles(
|
|||
// append and continue.
|
||||
// Otherwise publish what you have so far, reset the bundle to the
|
||||
// current envelope, and leave if we hit the limit
|
||||
for iter.Prev() {
|
||||
for iter.Next() {
|
||||
var envelope whisper.Envelope
|
||||
|
||||
decodeErr := rlp.DecodeBytes(iter.Value(), &envelope)
|
||||
|
|
|
@ -300,7 +300,7 @@ func (s *MailserverSuite) TestRequestPaginationLimit() {
|
|||
|
||||
var (
|
||||
sentEnvelopes []*whisper.Envelope
|
||||
reverseSentHashes []common.Hash
|
||||
sentHashes []common.Hash
|
||||
receivedHashes []common.Hash
|
||||
archiveKeys []string
|
||||
)
|
||||
|
@ -316,7 +316,7 @@ func (s *MailserverSuite) TestRequestPaginationLimit() {
|
|||
key := NewDBKey(env.Expiry-env.TTL, env.Hash())
|
||||
archiveKeys = append(archiveKeys, fmt.Sprintf("%x", key.Bytes()))
|
||||
sentEnvelopes = append(sentEnvelopes, env)
|
||||
reverseSentHashes = append([]common.Hash{env.Hash()}, reverseSentHashes...)
|
||||
sentHashes = append(sentHashes, env.Hash())
|
||||
}
|
||||
|
||||
reqLimit := uint32(6)
|
||||
|
@ -334,11 +334,11 @@ func (s *MailserverSuite) TestRequestPaginationLimit() {
|
|||
// 10 envelopes sent
|
||||
s.Equal(count, uint32(len(sentEnvelopes)))
|
||||
// 6 envelopes received
|
||||
s.Equal(int(limit), len(receivedHashes))
|
||||
// the 6 envelopes received should be in descending order
|
||||
s.Equal(reverseSentHashes[:limit], receivedHashes)
|
||||
s.Len(receivedHashes, int(limit))
|
||||
// the 6 envelopes received should be in forward order
|
||||
s.Equal(sentHashes[:limit], receivedHashes)
|
||||
// cursor should be the key of the last envelope of the last page
|
||||
s.Equal(archiveKeys[count-limit], fmt.Sprintf("%x", cursor))
|
||||
s.Equal(archiveKeys[limit-1], fmt.Sprintf("%x", cursor))
|
||||
|
||||
// second page
|
||||
receivedHashes, cursor, _ = processRequestAndCollectHashes(
|
||||
|
|
Loading…
Reference in New Issue