mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-23 23:25:22 +00:00
dao: store blocks/txransactions by big-endian hash
There is no need for additional allocations.
This commit is contained in:
parent
619b6d4132
commit
54b177cf40
3 changed files with 7 additions and 7 deletions
|
@ -531,7 +531,7 @@ func (bc *Blockchain) addHeaders(verify bool, headers ...*block.Header) error {
|
||||||
return buf.Err
|
return buf.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
key := storage.AppendPrefix(storage.DataBlock, h.Hash().BytesLE())
|
key := storage.AppendPrefix(storage.DataBlock, h.Hash().BytesBE())
|
||||||
batch.Put(key, buf.Bytes())
|
batch.Put(key, buf.Bytes())
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
lastHeader = h
|
lastHeader = h
|
||||||
|
|
|
@ -114,7 +114,7 @@ func TestAddBlock(t *testing.T) {
|
||||||
require.NoError(t, bc.persist())
|
require.NoError(t, bc.persist())
|
||||||
|
|
||||||
for _, block := range blocks {
|
for _, block := range blocks {
|
||||||
key := storage.AppendPrefix(storage.DataBlock, block.Hash().BytesLE())
|
key := storage.AppendPrefix(storage.DataBlock, block.Hash().BytesBE())
|
||||||
_, err := bc.dao.Store.Get(key)
|
_, err := bc.dao.Store.Get(key)
|
||||||
require.NoErrorf(t, err, "block %s not persisted", block.Hash())
|
require.NoErrorf(t, err, "block %s not persisted", block.Hash())
|
||||||
}
|
}
|
||||||
|
|
|
@ -510,7 +510,7 @@ func makeStorageItemKey(id int32, key []byte) []byte {
|
||||||
|
|
||||||
// GetBlock returns Block by the given hash if it exists in the store.
|
// GetBlock returns Block by the given hash if it exists in the store.
|
||||||
func (dao *Simple) GetBlock(hash util.Uint256) (*block.Block, error) {
|
func (dao *Simple) GetBlock(hash util.Uint256) (*block.Block, error) {
|
||||||
key := storage.AppendPrefix(storage.DataBlock, hash.BytesLE())
|
key := storage.AppendPrefix(storage.DataBlock, hash.BytesBE())
|
||||||
b, err := dao.Store.Get(key)
|
b, err := dao.Store.Get(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -586,7 +586,7 @@ func (dao *Simple) GetHeaderHashes() ([]util.Uint256, error) {
|
||||||
// GetTransaction returns Transaction and its height by the given hash
|
// GetTransaction returns Transaction and its height by the given hash
|
||||||
// if it exists in the store. It does not return dummy transactions.
|
// if it exists in the store. It does not return dummy transactions.
|
||||||
func (dao *Simple) GetTransaction(hash util.Uint256) (*transaction.Transaction, uint32, error) {
|
func (dao *Simple) GetTransaction(hash util.Uint256) (*transaction.Transaction, uint32, error) {
|
||||||
key := storage.AppendPrefix(storage.DataTransaction, hash.BytesLE())
|
key := storage.AppendPrefix(storage.DataTransaction, hash.BytesBE())
|
||||||
b, err := dao.Store.Get(key)
|
b, err := dao.Store.Get(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
|
@ -637,7 +637,7 @@ func read2000Uint256Hashes(b []byte) ([]util.Uint256, error) {
|
||||||
// Transaction hash. It returns an error in case if transaction is in chain
|
// Transaction hash. It returns an error in case if transaction is in chain
|
||||||
// or in the list of conflicting transactions.
|
// or in the list of conflicting transactions.
|
||||||
func (dao *Simple) HasTransaction(hash util.Uint256) error {
|
func (dao *Simple) HasTransaction(hash util.Uint256) error {
|
||||||
key := storage.AppendPrefix(storage.DataTransaction, hash.BytesLE())
|
key := storage.AppendPrefix(storage.DataTransaction, hash.BytesBE())
|
||||||
bytes, err := dao.Store.Get(key)
|
bytes, err := dao.Store.Get(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -656,7 +656,7 @@ func (dao *Simple) HasTransaction(hash util.Uint256) error {
|
||||||
// the purpose of value serialization.
|
// the purpose of value serialization.
|
||||||
func (dao *Simple) StoreAsBlock(block *block.Block, buf *io.BufBinWriter) error {
|
func (dao *Simple) StoreAsBlock(block *block.Block, buf *io.BufBinWriter) error {
|
||||||
var (
|
var (
|
||||||
key = storage.AppendPrefix(storage.DataBlock, block.Hash().BytesLE())
|
key = storage.AppendPrefix(storage.DataBlock, block.Hash().BytesBE())
|
||||||
)
|
)
|
||||||
if buf == nil {
|
if buf == nil {
|
||||||
buf = io.NewBufBinWriter()
|
buf = io.NewBufBinWriter()
|
||||||
|
@ -688,7 +688,7 @@ func (dao *Simple) StoreAsCurrentBlock(block *block.Block, buf *io.BufBinWriter)
|
||||||
// StoreAsTransaction stores given TX as DataTransaction. It can reuse given
|
// StoreAsTransaction stores given TX as DataTransaction. It can reuse given
|
||||||
// buffer for the purpose of value serialization.
|
// buffer for the purpose of value serialization.
|
||||||
func (dao *Simple) StoreAsTransaction(tx *transaction.Transaction, index uint32, buf *io.BufBinWriter) error {
|
func (dao *Simple) StoreAsTransaction(tx *transaction.Transaction, index uint32, buf *io.BufBinWriter) error {
|
||||||
key := storage.AppendPrefix(storage.DataTransaction, tx.Hash().BytesLE())
|
key := storage.AppendPrefix(storage.DataTransaction, tx.Hash().BytesBE())
|
||||||
if buf == nil {
|
if buf == nil {
|
||||||
buf = io.NewBufBinWriter()
|
buf = io.NewBufBinWriter()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue