mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-01-11 11:20:38 +00:00
core: store conflicting transactions in a separate method
(DAO).StoreConflictingTransactions will be reused from the state sync module.
This commit is contained in:
parent
72e654332e
commit
cb01f533c0
2 changed files with 25 additions and 9 deletions
|
@ -727,16 +727,11 @@ func (bc *Blockchain) storeBlock(block *block.Block, txpool *mempool.Pool) error
|
||||||
|
|
||||||
writeBuf.Reset()
|
writeBuf.Reset()
|
||||||
if bc.config.P2PSigExtensions {
|
if bc.config.P2PSigExtensions {
|
||||||
for _, attr := range tx.GetAttributes(transaction.ConflictsT) {
|
err := kvcache.StoreConflictingTransactions(tx, block.Index, writeBuf)
|
||||||
hash := attr.Value.(*transaction.Conflicts).Hash
|
if err != nil {
|
||||||
dummyTx := transaction.NewTrimmedTX(hash)
|
blockdone <- err
|
||||||
dummyTx.Version = transaction.DummyVersion
|
|
||||||
if err := kvcache.StoreAsTransaction(dummyTx, block.Index, writeBuf); err != nil {
|
|
||||||
blockdone <- fmt.Errorf("failed to store conflicting transaction %s for transaction %s: %w", hash.StringLE(), tx.Hash().StringLE(), err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
writeBuf.Reset()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if bc.config.RemoveUntraceableBlocks {
|
if bc.config.RemoveUntraceableBlocks {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
iocore "io"
|
iocore "io"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
|
@ -63,6 +64,7 @@ type DAO interface {
|
||||||
StoreAsBlock(block *block.Block, buf *io.BufBinWriter) error
|
StoreAsBlock(block *block.Block, buf *io.BufBinWriter) error
|
||||||
StoreAsCurrentBlock(block *block.Block, buf *io.BufBinWriter) error
|
StoreAsCurrentBlock(block *block.Block, buf *io.BufBinWriter) error
|
||||||
StoreAsTransaction(tx *transaction.Transaction, index uint32, buf *io.BufBinWriter) error
|
StoreAsTransaction(tx *transaction.Transaction, index uint32, buf *io.BufBinWriter) error
|
||||||
|
StoreConflictingTransactions(tx *transaction.Transaction, index uint32, buf *io.BufBinWriter) error
|
||||||
putNEP17TransferInfo(acc util.Uint160, bs *state.NEP17TransferInfo, buf *io.BufBinWriter) error
|
putNEP17TransferInfo(acc util.Uint160, bs *state.NEP17TransferInfo, buf *io.BufBinWriter) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -589,6 +591,25 @@ func (dao *Simple) StoreAsTransaction(tx *transaction.Transaction, index uint32,
|
||||||
return dao.Store.Put(key, buf.Bytes())
|
return dao.Store.Put(key, buf.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StoreConflictingTransactions stores transactions given tx has conflicts with
|
||||||
|
// as DataTransaction with dummy version. It can reuse given buffer for the
|
||||||
|
// purpose of value serialization.
|
||||||
|
func (dao *Simple) StoreConflictingTransactions(tx *transaction.Transaction, index uint32, buf *io.BufBinWriter) error {
|
||||||
|
if buf == nil {
|
||||||
|
buf = io.NewBufBinWriter()
|
||||||
|
}
|
||||||
|
for _, attr := range tx.GetAttributes(transaction.ConflictsT) {
|
||||||
|
hash := attr.Value.(*transaction.Conflicts).Hash
|
||||||
|
dummyTx := transaction.NewTrimmedTX(hash)
|
||||||
|
dummyTx.Version = transaction.DummyVersion
|
||||||
|
if err := dao.StoreAsTransaction(dummyTx, index, buf); err != nil {
|
||||||
|
return fmt.Errorf("failed to store conflicting transaction %s for transaction %s: %w", hash.StringLE(), tx.Hash().StringLE(), err)
|
||||||
|
}
|
||||||
|
buf.Reset()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Persist flushes all the changes made into the (supposedly) persistent
|
// Persist flushes all the changes made into the (supposedly) persistent
|
||||||
// underlying store.
|
// underlying store.
|
||||||
func (dao *Simple) Persist() (int, error) {
|
func (dao *Simple) Persist() (int, error) {
|
||||||
|
|
Loading…
Reference in a new issue