Merge pull request #409 from nspcc-dev/bolt-sigsegv-logging-fixes

Bolt Put(), sigsegv and logging fixes
This commit is contained in:
Roman Khimov 2019-09-23 12:56:41 +03:00 committed by GitHub
commit facf34e821
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 5 deletions

View file

@ -169,7 +169,9 @@ func (bc *Blockchain) Run(ctx context.Context) {
case <-persistTimer.C:
go func() {
err := bc.Persist(ctx)
log.Warnf("failed to persist blockchain: %s", err)
if err != nil {
log.Warnf("failed to persist blockchain: %s", err)
}
}()
persistTimer.Reset(persistInterval)
}
@ -412,7 +414,6 @@ func (bc *Blockchain) Persist(ctx context.Context) (err error) {
hash := headerList.Get(int(bc.BlockHeight() + 1))
if block, ok := bc.blockCache.GetBlock(hash); ok {
if err = bc.persistBlock(block); err != nil {
log.Warnf("failed to persist blocks: %s", err)
return
}
bc.blockCache.Delete(hash)

View file

@ -36,7 +36,11 @@ func (b *BoltDBBatch) Len() int {
// Put implements the Batch interface.
func (b *BoltDBBatch) Put(k, v []byte) {
b.mem[&k] = v
vcopy := make([]byte, len(v))
copy(vcopy, v)
kcopy := make([]byte, len(k))
copy(kcopy, k)
b.mem[&kcopy] = vcopy
}
// NewBoltDBStore returns a new ready to use BoltDB storage with created bucket.

View file

@ -26,11 +26,17 @@ func TestBoltDBBatch_Len(t *testing.T) {
func TestBoltDBBatch_PutBatchAndGet(t *testing.T) {
key := []byte("foo")
keycopy := make([]byte, len(key))
copy(keycopy, key)
value := []byte("bar")
batch := &BoltDBBatch{mem: map[*[]byte][]byte{&key: value}}
valuecopy := make([]byte, len(value))
copy(valuecopy, value)
boltDBStore := openStore(t)
batch := boltDBStore.Batch()
batch.Put(keycopy, valuecopy)
copy(valuecopy, key)
copy(keycopy, value)
errPut := boltDBStore.PutBatch(batch)
assert.Nil(t, errPut, "Error while PutBatch")

View file

@ -3,6 +3,7 @@ package network
import (
"encoding/binary"
"errors"
"fmt"
"github.com/CityOfZion/neo-go/config"
"github.com/CityOfZion/neo-go/pkg/core"
@ -193,6 +194,8 @@ func (m *Message) decodePayload(br *io.BinReader) error {
p = &transaction.Transaction{}
case CMDMerkleBlock:
p = &payload.MerkleBlock{}
default:
return fmt.Errorf("can't decode command %s", cmdByteArrayToString(m.Command))
}
p.DecodeBinary(r)
if r.Err != nil {