diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 4fc630860..068401b03 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -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) diff --git a/pkg/core/storage/boltdb_store.go b/pkg/core/storage/boltdb_store.go index e63ec95e0..ffa1d4ecb 100644 --- a/pkg/core/storage/boltdb_store.go +++ b/pkg/core/storage/boltdb_store.go @@ -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. diff --git a/pkg/core/storage/boltdb_store_test.go b/pkg/core/storage/boltdb_store_test.go index 51128b749..ac23d136a 100644 --- a/pkg/core/storage/boltdb_store_test.go +++ b/pkg/core/storage/boltdb_store_test.go @@ -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") diff --git a/pkg/network/message.go b/pkg/network/message.go index 1f702fc9f..187c7c9d9 100644 --- a/pkg/network/message.go +++ b/pkg/network/message.go @@ -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 {