forked from TrueCloudLab/neoneo-go
Merge pull request #409 from nspcc-dev/bolt-sigsegv-logging-fixes
Bolt Put(), sigsegv and logging fixes
This commit is contained in:
commit
facf34e821
4 changed files with 19 additions and 5 deletions
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue