mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-12 11:10:35 +00:00
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:
|
case <-persistTimer.C:
|
||||||
go func() {
|
go func() {
|
||||||
err := bc.Persist(ctx)
|
err := bc.Persist(ctx)
|
||||||
|
if err != nil {
|
||||||
log.Warnf("failed to persist blockchain: %s", err)
|
log.Warnf("failed to persist blockchain: %s", err)
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
persistTimer.Reset(persistInterval)
|
persistTimer.Reset(persistInterval)
|
||||||
}
|
}
|
||||||
|
@ -412,7 +414,6 @@ func (bc *Blockchain) Persist(ctx context.Context) (err error) {
|
||||||
hash := headerList.Get(int(bc.BlockHeight() + 1))
|
hash := headerList.Get(int(bc.BlockHeight() + 1))
|
||||||
if block, ok := bc.blockCache.GetBlock(hash); ok {
|
if block, ok := bc.blockCache.GetBlock(hash); ok {
|
||||||
if err = bc.persistBlock(block); err != nil {
|
if err = bc.persistBlock(block); err != nil {
|
||||||
log.Warnf("failed to persist blocks: %s", err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
bc.blockCache.Delete(hash)
|
bc.blockCache.Delete(hash)
|
||||||
|
|
|
@ -36,7 +36,11 @@ func (b *BoltDBBatch) Len() int {
|
||||||
|
|
||||||
// Put implements the Batch interface.
|
// Put implements the Batch interface.
|
||||||
func (b *BoltDBBatch) Put(k, v []byte) {
|
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.
|
// 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) {
|
func TestBoltDBBatch_PutBatchAndGet(t *testing.T) {
|
||||||
key := []byte("foo")
|
key := []byte("foo")
|
||||||
|
keycopy := make([]byte, len(key))
|
||||||
|
copy(keycopy, key)
|
||||||
value := []byte("bar")
|
value := []byte("bar")
|
||||||
batch := &BoltDBBatch{mem: map[*[]byte][]byte{&key: value}}
|
valuecopy := make([]byte, len(value))
|
||||||
|
copy(valuecopy, value)
|
||||||
boltDBStore := openStore(t)
|
boltDBStore := openStore(t)
|
||||||
|
batch := boltDBStore.Batch()
|
||||||
|
|
||||||
|
batch.Put(keycopy, valuecopy)
|
||||||
|
copy(valuecopy, key)
|
||||||
|
copy(keycopy, value)
|
||||||
errPut := boltDBStore.PutBatch(batch)
|
errPut := boltDBStore.PutBatch(batch)
|
||||||
assert.Nil(t, errPut, "Error while PutBatch")
|
assert.Nil(t, errPut, "Error while PutBatch")
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package network
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/CityOfZion/neo-go/config"
|
"github.com/CityOfZion/neo-go/config"
|
||||||
"github.com/CityOfZion/neo-go/pkg/core"
|
"github.com/CityOfZion/neo-go/pkg/core"
|
||||||
|
@ -193,6 +194,8 @@ func (m *Message) decodePayload(br *io.BinReader) error {
|
||||||
p = &transaction.Transaction{}
|
p = &transaction.Transaction{}
|
||||||
case CMDMerkleBlock:
|
case CMDMerkleBlock:
|
||||||
p = &payload.MerkleBlock{}
|
p = &payload.MerkleBlock{}
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("can't decode command %s", cmdByteArrayToString(m.Command))
|
||||||
}
|
}
|
||||||
p.DecodeBinary(r)
|
p.DecodeBinary(r)
|
||||||
if r.Err != nil {
|
if r.Err != nil {
|
||||||
|
|
Loading…
Reference in a new issue