mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-23 13:41:37 +00:00
Revert "mpt: do not allocate new buffer when updating dirty node"
This reverts commit 168ba7960c
.
It seems, there are some problems with it:
`2020-12-25T18:13:07.476+0300 WARN blockQueue: failed adding block into the blockchain {"error": "error while trying to apply MPT changes: unexpected EOF", "blockHeight": 9729, "nextIndex": 9730}`
This commit is contained in:
parent
756785acd3
commit
c2f70a179b
3 changed files with 10 additions and 15 deletions
|
@ -63,7 +63,7 @@ func (b *BaseNode) updateHash(n Node) {
|
||||||
|
|
||||||
// updateCache updates hash and bytes fields for this BaseNode.
|
// updateCache updates hash and bytes fields for this BaseNode.
|
||||||
func (b *BaseNode) updateBytes(n Node) {
|
func (b *BaseNode) updateBytes(n Node) {
|
||||||
buf := io.NewBufBinWriterPreAlloc(b.bytes)
|
buf := io.NewBufBinWriter()
|
||||||
encodeNodeWithType(n, buf.BinWriter)
|
encodeNodeWithType(n, buf.BinWriter)
|
||||||
b.bytes = buf.Bytes()
|
b.bytes = buf.Bytes()
|
||||||
b.bytesValid = true
|
b.bytesValid = true
|
||||||
|
|
|
@ -418,29 +418,31 @@ func (t *Trie) updateRefCount(h util.Uint256) int32 {
|
||||||
func (t *Trie) addRef(h util.Uint256, bs []byte) {
|
func (t *Trie) addRef(h util.Uint256, bs []byte) {
|
||||||
node := t.refcount[h]
|
node := t.refcount[h]
|
||||||
if node == nil {
|
if node == nil {
|
||||||
data := make([]byte, len(bs))
|
|
||||||
copy(data, bs)
|
|
||||||
t.refcount[h] = &cachedNode{
|
t.refcount[h] = &cachedNode{
|
||||||
refcount: 1,
|
refcount: 1,
|
||||||
bytes: data,
|
bytes: bs,
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
node.refcount++
|
node.refcount++
|
||||||
|
if node.bytes == nil {
|
||||||
|
node.bytes = bs
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Trie) removeRef(h util.Uint256, bs []byte) {
|
func (t *Trie) removeRef(h util.Uint256, bs []byte) {
|
||||||
node := t.refcount[h]
|
node := t.refcount[h]
|
||||||
if node == nil {
|
if node == nil {
|
||||||
data := make([]byte, len(bs))
|
|
||||||
copy(data, bs)
|
|
||||||
t.refcount[h] = &cachedNode{
|
t.refcount[h] = &cachedNode{
|
||||||
refcount: -1,
|
refcount: -1,
|
||||||
bytes: data,
|
bytes: bs,
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
node.refcount--
|
node.refcount--
|
||||||
|
if node.bytes == nil {
|
||||||
|
node.bytes = bs
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Trie) getFromStore(h util.Uint256) (Node, error) {
|
func (t *Trie) getFromStore(h util.Uint256) (Node, error) {
|
||||||
|
@ -460,8 +462,7 @@ func (t *Trie) getFromStore(h util.Uint256) (Node, error) {
|
||||||
data = data[:len(data)-4]
|
data = data[:len(data)-4]
|
||||||
node := t.refcount[h]
|
node := t.refcount[h]
|
||||||
if node != nil {
|
if node != nil {
|
||||||
node.bytes = make([]byte, len(data))
|
node.bytes = data
|
||||||
copy(node.bytes, data)
|
|
||||||
node.initial = int32(r.ReadU32LE())
|
node.initial = int32(r.ReadU32LE())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,6 @@ func NewBufBinWriter() *BufBinWriter {
|
||||||
return &BufBinWriter{BinWriter: NewBinWriterFromIO(b), buf: b}
|
return &BufBinWriter{BinWriter: NewBinWriterFromIO(b), buf: b}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBufBinWriterPreAlloc makes a BufBinWriter using preallocated buffer.
|
|
||||||
func NewBufBinWriterPreAlloc(buf []byte) *BufBinWriter {
|
|
||||||
b := bytes.NewBuffer(buf[:0])
|
|
||||||
return &BufBinWriter{BinWriter: NewBinWriterFromIO(b), buf: b}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Len returns the number of bytes of the unread portion of the buffer.
|
// Len returns the number of bytes of the unread portion of the buffer.
|
||||||
func (bw *BufBinWriter) Len() int {
|
func (bw *BufBinWriter) Len() int {
|
||||||
return bw.buf.Len()
|
return bw.buf.Len()
|
||||||
|
|
Loading…
Reference in a new issue