ead39153af
Fix #303 by changing the addrindex key prefix to 3 characters so that it's easy to check length when dropping the index. To drop the old index, check to make sure we aren't dropping any entries that end in "sx" or "tx" as those aren't part of the addrindex. Update test to deal with the new prefix length. Fix #346 by changing the pointers in the mempool's addrindex map to wire.ShaHash 32-byte values. This lets them be deleted even if the transaction data changes places in memory upon expanding the maps. Change the way addrindex uint32s are stored to big-endian in order to sort the transactions on disk in chronological/dependency order. Change the "searchrawtransactions" RPC call to return transactions from the database before the memory pool so that they're returned in order. This commit DOES NOT do topological sorting of the memory pool transactions to ensure they're returned in dependency order. This may be a good idea for a future enhancement. Add addrindex versioning to automatically drop the old/incompatible version of the index and rebuild with the new sort method and key prefix.
66 lines
1.7 KiB
Go
66 lines
1.7 KiB
Go
// Copyright (c) 2013-2014 Conformal Systems LLC.
|
|
// Use of this source code is governed by an ISC
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package ldb
|
|
|
|
import (
|
|
"bytes"
|
|
|
|
"testing"
|
|
|
|
"github.com/btcsuite/btcutil"
|
|
"github.com/btcsuite/golangcrypto/ripemd160"
|
|
)
|
|
|
|
func TestAddrIndexKeySerialization(t *testing.T) {
|
|
var hash160Bytes [ripemd160.Size]byte
|
|
var packedIndex [12]byte
|
|
|
|
fakeHash160 := btcutil.Hash160([]byte("testing"))
|
|
copy(fakeHash160, hash160Bytes[:])
|
|
|
|
fakeIndex := txAddrIndex{
|
|
hash160: hash160Bytes,
|
|
blkHeight: 1,
|
|
txoffset: 5,
|
|
txlen: 360,
|
|
}
|
|
|
|
serializedKey := addrIndexToKey(&fakeIndex)
|
|
copy(packedIndex[:], serializedKey[23:35])
|
|
unpackedIndex := unpackTxIndex(packedIndex)
|
|
|
|
if unpackedIndex.blkHeight != fakeIndex.blkHeight {
|
|
t.Errorf("Incorrect block height. Unpack addr index key"+
|
|
"serialization failed. Expected %d, received %d",
|
|
1, unpackedIndex.blkHeight)
|
|
}
|
|
|
|
if unpackedIndex.txoffset != fakeIndex.txoffset {
|
|
t.Errorf("Incorrect tx offset. Unpack addr index key"+
|
|
"serialization failed. Expected %d, received %d",
|
|
5, unpackedIndex.txoffset)
|
|
}
|
|
|
|
if unpackedIndex.txlen != fakeIndex.txlen {
|
|
t.Errorf("Incorrect tx len. Unpack addr index key"+
|
|
"serialization failed. Expected %d, received %d",
|
|
360, unpackedIndex.txlen)
|
|
}
|
|
}
|
|
|
|
func TestBytesPrefix(t *testing.T) {
|
|
testKey := []byte("a")
|
|
|
|
prefixRange := bytesPrefix(testKey)
|
|
if !bytes.Equal(prefixRange.Start, []byte("a")) {
|
|
t.Errorf("Wrong prefix start, got %d, expected %d", prefixRange.Start,
|
|
[]byte("a"))
|
|
}
|
|
|
|
if !bytes.Equal(prefixRange.Limit, []byte("b")) {
|
|
t.Errorf("Wrong prefix end, got %d, expected %d", prefixRange.Limit,
|
|
[]byte("b"))
|
|
}
|
|
}
|